@@ -1,6 +1,5 @@
1module Plum.View
1module Plum.View
4 , Nerve(..)
3 , Nerve(..)
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
48−type GenericUIView children msg = { nerves :: Array (Nerve msg), meat :: Array Meat, children :: children }
46+type GenericUIView children msg =
47+ { nerves :: Array (Nerve msg)
49+ , hover :: Array Meat
51+ , children :: children
50type UIView msg = GenericUIView (Array (View msg)) msg
54type UIView msg = GenericUIView (Array (View msg)) msg
@@ -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)
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
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
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
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
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 =
101− , bones: Link url { newTab: false } (Maybe.fromMaybe none $ Array.head children)
107+ } /\ Link url { newTab: false } (Maybe.fromMaybe none $ Array.head children)
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 =
113− , bones: Wrapper (Maybe.fromMaybe none $ Array.head children)
120+ } /\ Wrapper (Maybe.fromMaybe none $ Array.head children)
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 =
125− , bones: Link url { newTab: true } (Maybe.fromMaybe none $ Array.head children)
133+ } /\ Link url { newTab: true } (Maybe.fromMaybe none $ Array.head children)
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 =
137− , bones: Download url { filename: Nothing } (Maybe.fromMaybe none $ Array.head children)
146+ } /\ Download url { filename: Nothing } (Maybe.fromMaybe none $ Array.head children)
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 =
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)
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
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
169data Direction = X | Y
178data Direction = X | Y
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
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
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
181 = Spacing Int Int
190 = Spacing Int Int
@@ -194,13 +203,10 @@ data Meat
195data Nerve msg = OnClick msg
204data Nerve msg = OnClick msg
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
199none :: forall msg. View msg
208none :: forall msg. View msg
200−none = { nerves: [], meat: [], bones: None }
209+none = mempty /\ None
202−view :: forall msg. Array (Nerve msg) -> Array Meat -> Bones msg -> View msg
203−view nerves meat bones = { nerves, meat, bones }
205newtype Skin = Skin (Object String)
211newtype Skin = Skin (Object String)
@@ -311,7 +317,7 @@ instance Monoid Mutation where
311 mempty = Mutation { extraSkin: mempty }
317 mempty = Mutation { extraSkin: mempty }
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) =
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 ]