git.iko.soy/purestack-dev/purescript-plum
on master help sign in
Restructured
commit9dcff729c90d60232c57768aa3f4e9d55f79603e authoriko <mail@iko.soy> dateWed 21 May 2025, 14:08 (1 year ago) parent55621cc
2 files changed+45−39
plum/src/Plum.purs+1−1 plum/src/Plum/View.purs+44−38
plum/src/Plum.purs+1−1
@@ -7,7 +7,7 @@ import Data.Maybe (Maybe(..))
77import Effect (Effect)
88import Effect.Ref as Ref
99import Maquette as Maquette
10−import Plum.View (UI, UIWith(..), grow)
10+import Plum.View (GenericUI(..), UI, grow)
1111import Web.DOM.NonElementParentNode (getElementById) as Web
1212import Web.HTML (window) as Web
1313import Web.HTML.HTMLDocument (toNonElementParentNode) as Web
plum/src/Plum/View.purs+44−38
@@ -1,6 +1,5 @@
11module Plum.View
22 ( View
3− , view
43 , Nerve(..)
54 , Meat(..)
65 , Bones(..)
@@ -36,16 +35,21 @@ import Data.Array as Array
3635import Data.Int as Int
3736import Data.Maybe (Maybe(..))
3837import Data.Maybe as Maybe
39−import Data.Tuple.Nested ((/\))
38+import Data.Tuple.Nested (type (/\), (/\))
4039import Effect (Effect)
4140import Foreign.Object (Object)
4241import Foreign.Object as Object
4342import Maquette (VNode, string)
4443import Maquette as Maquette
45−import Record as Record
4644import Record.Unsafe.Union as Record
4745
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+ }
4953
5054type UIView msg = GenericUIView (Array (View msg)) msg
5155
@@ -78,83 +82,88 @@ instance Monoid children => Bind (GenericUI children msg) where
7882instance Monoid children => Monad (GenericUI children msg)
7983
8084column :: forall msg a. UI msg a -> UI msg a
81−column (UI { nerves, meat, children } a) =
82− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Column children } ] } a
85+column (UI { nerves, meat, hover, down, children } a) =
86+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Column children ] } a
8387
8488row :: forall msg a. UI msg a -> UI msg a
85−row (UI { nerves, meat, children } a) =
86− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Row children } ] } a
89+row (UI { nerves, meat, hover, down, children } a) =
90+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Row children ] } a
8791
8892stack :: forall msg a. UI msg a -> UI msg a
89−stack (UI { nerves, meat, children } a) =
90− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Stack children } ] } a
93+stack (UI { nerves, meat, hover, down, children } a) =
94+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Stack children ] } a
9195
9296text :: 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
9498
9599link :: 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
97101 (mempty :: UIView msg)
98102 { children =
99103 [ { meat
100104 , nerves
101− , bones: Link url { newTab: false } (Maybe.fromMaybe none $ Array.head children)
102− }
105+ , hover
106+ , down
107+ } /\ Link url { newTab: false } (Maybe.fromMaybe none $ Array.head children)
103108 ]
104109 }
105110 a
106111
107112el :: 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
109114 (mempty :: UIView msg)
110115 { children =
111116 [ { meat
112117 , nerves
113− , bones: Wrapper (Maybe.fromMaybe none $ Array.head children)
114− }
118+ , hover
119+ , down
120+ } /\ Wrapper (Maybe.fromMaybe none $ Array.head children)
115121 ]
116122 }
117123 a
118124
119125newTabLink :: 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
121127 (mempty :: UIView msg)
122128 { children =
123129 [ { meat
124130 , nerves
125− , bones: Link url { newTab: true } (Maybe.fromMaybe none $ Array.head children)
126− }
131+ , hover
132+ , down
133+ } /\ Link url { newTab: true } (Maybe.fromMaybe none $ Array.head children)
127134 ]
128135 }
129136 a
130137
131138download :: 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
133140 (mempty :: UIView msg)
134141 { children =
135142 [ { meat
136143 , nerves
137− , bones: Download url { filename: Nothing } (Maybe.fromMaybe none $ Array.head children)
138− }
144+ , down
145+ , hover
146+ } /\ Download url { filename: Nothing } (Maybe.fromMaybe none $ Array.head children)
139147 ]
140148 }
141149 a
142150
143151downloadAs :: 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
145153 (mempty :: UIView msg)
146154 { children =
147155 [ { meat
148156 , nerves
149− , bones: Download url { filename: Just filename } (Maybe.fromMaybe none $ Array.head children)
150− }
157+ , hover
158+ , down
159+ } /\ Download url { filename: Just filename } (Maybe.fromMaybe none $ Array.head children)
151160 ]
152161 }
153162 a
154163
155164image :: forall msg a. String -> { description :: String } -> GenericUI Unit msg a -> UI msg a
156−image url description (UI { nerves, meat } a) =
157− UI (mempty :: UIView msg) { children = [ { meat, nerves, bones: Image url description } ] } a
165+image url description (UI { nerves, meat, hover, down } a) =
166+ UI (mempty :: UIView msg) { children = [ { meat, nerves, hover, down } /\ Image url description ] } a
158167
159168h :: String -> Skin -> Array VNode -> VNode
160169h elem (Skin styles) children = Maquette.h elem { styles } children
@@ -168,14 +177,14 @@ data Alignment = Start | Center | End
168177
169178data Direction = X | Y
170179
171−meat :: forall ch msg a. Monoid ch => Monoid a => Meat -> GenericUI ch msg a
172−meat m = UI (mempty :: GenericUIView ch msg) { meat = [ m ] } mempty
180+m :: forall ch msg a. Monoid ch => Monoid a => Meat -> GenericUI ch msg a
181+m meat = UI (mempty :: GenericUIView ch msg) { meat = [ meat ] } mempty
173182
174183spacing :: 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
176185
177186explain :: forall ch msg a. Monoid ch => Monoid a => GenericUI ch msg a
178−explain = meat Explain
187+explain = m Explain
179188
180189data Meat
181190 = Spacing Int Int
@@ -194,13 +203,10 @@ data Meat
194203
195204data Nerve msg = OnClick msg
196205
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
198207
199208none :: forall msg. View msg
200−none = { nerves: [], meat: [], bones: None }
201−
202−view :: forall msg. Array (Nerve msg) -> Array Meat -> Bones msg -> View msg
203−view nerves meat bones = { nerves, meat, bones }
209+none = mempty /\ None
204210
205211newtype Skin = Skin (Object String)
206212
@@ -311,7 +317,7 @@ instance Monoid Mutation where
311317 mempty = Mutation { extraSkin: mempty }
312318
313319growSkin :: 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) =
315321 let
316322 alignCenter = [ Align X Center, Align Y Center ]
317323 widthFill = [ Width Fill, Height Fill ]