git.iko.soy/purestack-dev/purescript-plum
on master help sign in
Restructured
9dcff72iko
plum/src/Plum.purs+1−1
@@ -7,7 +7,7 @@ import Data.Maybe (Maybe(..))
7import Effect (Effect)
7import Effect (Effect)
8import Effect.Ref as Ref
8import Effect.Ref as Ref
9import Maquette as Maquette
9import Maquette as Maquette
10−import Plum.View (UI, UIWith(..), grow)
10+import Plum.View (GenericUI(..), UI, grow)
11import Web.DOM.NonElementParentNode (getElementById) as Web
11import Web.DOM.NonElementParentNode (getElementById) as Web
12import Web.HTML (window) as Web
12import Web.HTML (window) as Web
13import Web.HTML.HTMLDocument (toNonElementParentNode) as Web
13import Web.HTML.HTMLDocument (toNonElementParentNode) as Web
plum/src/Plum/View.purs+44−38
@@ -1,6 +1,5 @@
1module Plum.View
1module Plum.View
2 ( View
2 ( View
3− , view
4 , Nerve(..)
3 , Nerve(..)
5 , Meat(..)
4 , Meat(..)
6 , Bones(..)
5 , Bones(..)
@@ -36,16 +35,21 @@ import Data.Array as Array
36import Data.Int as Int
35import Data.Int as Int
37import Data.Maybe (Maybe(..))
36import Data.Maybe (Maybe(..))
38import Data.Maybe as Maybe
37import Data.Maybe as Maybe
39−import Data.Tuple.Nested ((/\))
38+import Data.Tuple.Nested (type (/\), (/\))
40import Effect (Effect)
39import Effect (Effect)
41import Foreign.Object (Object)
40import Foreign.Object (Object)
42import Foreign.Object as Object
41import Foreign.Object as Object
43import Maquette (VNode, string)
42import Maquette (VNode, string)
44import Maquette as Maquette
43import Maquette as Maquette
45−import Record as Record
46import Record.Unsafe.Union as Record
44import Record.Unsafe.Union as Record
47
45
48−type GenericUIView children msg = { nerves :: Array (Nerve msg), meat :: Array Meat, children :: children }
46+type GenericUIView children msg =
47+ { nerves :: Array (Nerve msg)
48+ , meat :: Array Meat
49+ , hover :: Array Meat
50+ , down :: Array Meat
51+ , children :: children
52+ }
49
53
50type UIView msg = GenericUIView (Array (View msg)) msg
54type UIView msg = GenericUIView (Array (View msg)) msg
51
55
@@ -78,83 +82,88 @@ instance Monoid children => Bind (GenericUI children msg) where
78instance Monoid children => Monad (GenericUI children msg)
82instance Monoid children => Monad (GenericUI children msg)
79
83
80column :: forall msg a. UI msg a -> UI msg a
84column :: forall msg a. UI msg a -> UI msg a
81−column (UI { nerves, meat, children } a) =
85+column (UI { nerves, meat, hover, down, children } a) =
82− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Column children } ] } a
86+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Column children ] } a
83
87
84row :: forall msg a. UI msg a -> UI msg a
88row :: forall msg a. UI msg a -> UI msg a
85−row (UI { nerves, meat, children } a) =
89+row (UI { nerves, meat, hover, down, children } a) =
86− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Row children } ] } a
90+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Row children ] } a
87
91
88stack :: forall msg a. UI msg a -> UI msg a
92stack :: forall msg a. UI msg a -> UI msg a
89−stack (UI { nerves, meat, children } a) =
93+stack (UI { nerves, meat, hover, down, children } a) =
90− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Stack children } ] } a
94+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Stack children ] } a
91
95
92text :: forall msg. String -> GenericUI Unit msg Unit -> UI msg Unit
96text :: forall msg. String -> GenericUI Unit msg Unit -> UI msg Unit
93−text s (UI { nerves, meat } a) = UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Text s } ] } a
97+text s (UI { nerves, meat, hover, down } a) = UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Text s ] } a
94
98
95link :: forall msg a. String -> UI msg a -> UI msg a
99link :: forall msg a. String -> UI msg a -> UI msg a
96−link url (UI { nerves, meat, children } a) = UI
100+link url (UI { nerves, meat, hover, down, children } a) = UI
97 (mempty :: UIView msg)
101 (mempty :: UIView msg)
98 { children =
102 { children =
99 [ { meat
103 [ { meat
100 , nerves
104 , nerves
105+ , hover
106+ , down
101− , bones: Link url { newTab: false } (Maybe.fromMaybe none $ Array.head children)
107+ } /\ Link url { newTab: false } (Maybe.fromMaybe none $ Array.head children)
102− }
103 ]
108 ]
104 }
109 }
105 a
110 a
106
111
107el :: forall msg a. UI msg a -> UI msg a
112el :: forall msg a. UI msg a -> UI msg a
108−el (UI { nerves, meat, children } a) = UI
113+el (UI { nerves, meat, down, hover, children } a) = UI
109 (mempty :: UIView msg)
114 (mempty :: UIView msg)
110 { children =
115 { children =
111 [ { meat
116 [ { meat
112 , nerves
117 , nerves
118+ , hover
119+ , down
113− , bones: Wrapper (Maybe.fromMaybe none $ Array.head children)
120+ } /\ Wrapper (Maybe.fromMaybe none $ Array.head children)
114− }
115 ]
121 ]
116 }
122 }
117 a
123 a
118
124
119newTabLink :: forall msg a. String -> UI msg a -> UI msg a
125newTabLink :: forall msg a. String -> UI msg a -> UI msg a
120−newTabLink url (UI { nerves, meat, children } a) = UI
126+newTabLink url (UI { nerves, meat, hover, down, children } a) = UI
121 (mempty :: UIView msg)
127 (mempty :: UIView msg)
122 { children =
128 { children =
123 [ { meat
129 [ { meat
124 , nerves
130 , nerves
131+ , hover
132+ , down
125− , bones: Link url { newTab: true } (Maybe.fromMaybe none $ Array.head children)
133+ } /\ Link url { newTab: true } (Maybe.fromMaybe none $ Array.head children)
126− }
127 ]
134 ]
128 }
135 }
129 a
136 a
130
137
131download :: forall msg a. String -> UI msg a -> UI msg a
138download :: forall msg a. String -> UI msg a -> UI msg a
132−download url (UI { nerves, meat, children } a) = UI
139+download url (UI { nerves, meat, children, down, hover } a) = UI
133 (mempty :: UIView msg)
140 (mempty :: UIView msg)
134 { children =
141 { children =
135 [ { meat
142 [ { meat
136 , nerves
143 , nerves
144+ , down
145+ , hover
137− , bones: Download url { filename: Nothing } (Maybe.fromMaybe none $ Array.head children)
146+ } /\ Download url { filename: Nothing } (Maybe.fromMaybe none $ Array.head children)
138− }
139 ]
147 ]
140 }
148 }
141 a
149 a
142
150
143downloadAs :: forall msg a. String -> { filename :: String } -> UI msg a -> UI msg a
151downloadAs :: forall msg a. String -> { filename :: String } -> UI msg a -> UI msg a
144−downloadAs url { filename } (UI { nerves, meat, children } a) = UI
152+downloadAs url { filename } (UI { nerves, meat, hover, down, children } a) = UI
145 (mempty :: UIView msg)
153 (mempty :: UIView msg)
146 { children =
154 { children =
147 [ { meat
155 [ { meat
148 , nerves
156 , nerves
157+ , hover
158+ , down
149− , bones: Download url { filename: Just filename } (Maybe.fromMaybe none $ Array.head children)
159+ } /\ Download url { filename: Just filename } (Maybe.fromMaybe none $ Array.head children)
150− }
151 ]
160 ]
152 }
161 }
153 a
162 a
154
163
155image :: forall msg a. String -> { description :: String } -> GenericUI Unit msg a -> UI msg a
164image :: forall msg a. String -> { description :: String } -> GenericUI Unit msg a -> UI msg a
156−image url description (UI { nerves, meat } a) =
165+image url description (UI { nerves, meat, hover, down } a) =
157− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Image url description } ] } a
166+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Image url description ] } a
158
167
159h :: String -> Skin -> Array VNode -> VNode
168h :: String -> Skin -> Array VNode -> VNode
160h elem (Skin styles) children = Maquette.h elem { styles } children
169h elem (Skin styles) children = Maquette.h elem { styles } children
@@ -168,14 +177,14 @@ data Alignment = Start | Center | End
168
177
169data Direction = X | Y
178data Direction = X | Y
170
179
171−meat :: forall ch msg a. Monoid ch => Monoid a => Meat -> GenericUI ch msg a
180+m :: forall ch msg a. Monoid ch => Monoid a => Meat -> GenericUI ch msg a
172−meat m = UI (mempty :: GenericUIView ch msg) { meat = [ m ] } mempty
181+m meat = UI (mempty :: GenericUIView ch msg) { meat = [ meat ] } mempty
173
182
174spacing :: forall ch msg a. Monoid ch => Monoid a => { x :: Int, y :: Int } -> GenericUI ch msg a
183spacing :: forall ch msg a. Monoid ch => Monoid a => { x :: Int, y :: Int } -> GenericUI ch msg a
175−spacing { x, y } = meat $ Spacing x y
184+spacing { x, y } = m $ Spacing x y
176
185
177explain :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
186explain :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
178−explain = meat Explain
187+explain = m Explain
179
188
180data Meat
189data Meat
181 = Spacing Int Int
190 = Spacing Int Int
@@ -194,13 +203,10 @@ data Meat
194
203
195data Nerve msg = OnClick msg
204data Nerve msg = OnClick msg
196
205
197−type View msg = { nerves :: Array (Nerve msg), meat :: Array Meat, bones :: Bones msg }
206+type View msg = { nerves :: Array (Nerve msg), meat :: Array Meat, hover :: Array Meat, down :: Array Meat } /\ Bones msg
198
207
199none :: forall msg. View msg
208none :: forall msg. View msg
200−none = { nerves: [], meat: [], bones: None }
209+none = mempty /\ None
201−
202−view :: forall msg. Array (Nerve msg) -> Array Meat -> Bones msg -> View msg
203−view nerves meat bones = { nerves, meat, bones }
204
210
205newtype Skin = Skin (Object String)
211newtype Skin = Skin (Object String)
206
212
@@ -311,7 +317,7 @@ instance Monoid Mutation where
311 mempty = Mutation { extraSkin: mempty }
317 mempty = Mutation { extraSkin: mempty }
312
318
313growSkin :: forall msg. (msg -> Effect Unit) -> Mutation -> View msg -> VNode
319growSkin :: forall msg. (msg -> Effect Unit) -> Mutation -> View msg -> VNode
314−growSkin fire (Mutation mutation) { meat, bones } =
320+growSkin fire (Mutation mutation) ({ meat, hover, down, nerves } /\ bones) =
315 let
321 let
316 alignCenter = [ Align X Center, Align Y Center ]
322 alignCenter = [ Align X Center, Align Y Center ]
317 widthFill = [ Width Fill, Height Fill ]
323 widthFill = [ Width Fill, Height Fill ]