4import CSS (Color, Key(..), Rule(..), StyleM, Value(..), cssStringRGBA, plain, runS)
5import Data.Foldable (foldMap)
6import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
7import Debug.Trace (spy)
8import Foreign (unsafeToForeign)
9import Foreign.Object (Object)
10import Foreign.Object as Object
11import Partial.Unsafe (unsafeCrashWith)
12import Prim.RowList (class RowToList, Nil, kind RowList)
13import Record as Record
14import Record.Builder (Builder)
15import Record.Builder as Builder
16import Simple.JSON (class WriteForeign, write, writeImpl)
17import Type.Prelude (RLProxy, Proxy(..))
19import Type.Row.Homogeneous (class Homogeneous)
20import Type.RowList as RL
21import Untagged.Coercible (coerce)
22import Untagged.Union (type (|+|))
24newtype JSSClasses theme props r
25 = JSSClasses ({ | theme } -> { | r })
28 ∀ theme props row rowRL to.
29 JSSAbleFields props rowRL row () to =>
30 RowToList row rowRL =>
31 Homogeneous to (JSSElem props) =>
32 JSSAble props (Record row) =>
33 ({ | theme } -> { | row }) -> JSSClasses theme props to
34jssClasses f = JSSClasses f'
40 built = Builder.build builder {}
41 rlp = RL.RLProxy ∷ RL.RLProxy rowRL
42 propsy = Proxy ∷ Proxy props
43 builder ∷ Builder.Builder (Record ()) (Record to)
44 builder = jssifyFields propsy rlp rec
47 = PrimitiveJss (String |+| Int |+| Number)
48 | ArrayJss (Array (JSSElem props))
49 | PropsJss (props -> JSSElem props)
50 | NestedJss (Object (JSSElem props))
52instance semigroupJssElem ∷ Semigroup (JSSElem props) where
54 NestedJss n1, NestedJss n2 -> NestedJss (n1 <> n2)
55 ArrayJss a1, ArrayJss a2 -> ArrayJss (a1 <> a2)
56 NestedJss n1, PropsJss fn ->
57 PropsJss \props -> case fn props of
58 NestedJss n2 -> NestedJss (n1 <> n2)
62 unsafeCrashWith "Untreated branch, fix me"
63 PropsJss fn1, PropsJss fn2 ->
65 case fn1 props, fn2 props of
66 n1@(NestedJss _), n2@(NestedJss _) -> n1 <> n2
72 unsafeCrashWith "Untreated branch second, fix me"
78 unsafeCrashWith "Untreated branch second, fix me"
80instance wfJSSElem ∷ WriteForeign (JSSElem props) where
82 PrimitiveJss p -> unsafeToForeign p
83 ArrayJss proper -> write (map writeImpl proper)
84 PropsJss proper -> unsafeToForeign (map writeImpl proper)
85 NestedJss proper -> writeImpl (map writeImpl proper)
87class JSSAble p a | a -> p where
90instance jssAbleJssElem ∷ JSSAble p (JSSElem p) where
93instance jssAbleColor ∷ JSSAble p Color where
94 jss c = PrimitiveJss (coerce (cssStringRGBA c))
96instance jssAbleString ∷ JSSAble p String where
97 jss = coerce >>> PrimitiveJss
99instance jssAbleInt ∷ JSSAble p Int where
100 jss = coerce >>> PrimitiveJss
102instance jssAbleNumber ∷ JSSAble p Number where
103 jss = coerce >>> PrimitiveJss
105instance jssAbleArray ∷ JSSAble p a => JSSAble p (Array a) where
106 jss arr = ArrayJss (jss <$> arr)
108instance jssAbleWithProps ∷ JSSAble p jss => JSSAble p (p -> jss) where
111instance jssAbleNested ∷ JSSAble p jss => JSSAble p (Object jss) where
112 jss = map jss >>> NestedJss
114instance jssAbleCss ∷ JSSAble p (StyleM Unit) where
115 jss someCss = NestedJss (foldMap ruleToObject rules)
118 ruleToObject = case _ of
119 Property (Key k) (Value v) -> Object.singleton (plain k) (jss (plain v))
123 _ = spy "Unsupported CSS" x
124 "tried to create CSS that I couldn't understand"
126instance jssAbleRecord ∷
127 ( JSSAbleFields props rowRL row () to
128 , RowToList row rowRL
129 , Homogeneous to (JSSElem props)
131 JSSAble props (Record row) where
132 jss rec = NestedJss <<< Object.fromHomogeneous $ built
135 built = Builder.build builder {}
136 rlp = RL.RLProxy ∷ RL.RLProxy rowRL
137 propsy = Proxy ∷ Proxy props
138 builder ∷ Builder.Builder (Record ()) (Record to)
139 builder = jssifyFields propsy rlp rec
141propsJss ∷ ∀ p a. JSSAble p a => (p -> a) -> JSSElem p
142propsJss fn = PropsJss (map jss fn)
144class JSSAbleFields props (xs ∷ RowList) (row ∷ #Type) (from ∷ #Type) (to ∷ #Type) | xs -> props row from to where
145 jssifyFields ∷ Proxy props -> RLProxy xs -> Record row -> Builder (Record from) (Record to)
147instance jssAbleFieldsNil ∷ JSSAbleFields props Nil row () () where
148 jssifyFields _ _ _ = identity
150instance jssAbleFieldsCons ∷
154 , R.Cons name a trash row
155 , R.Cons name (JSSElem props) from' to
156 , JSSAbleFields props tail row from from'
158 JSSAbleFields props (RL.Cons name a tail) row from to where
159 jssifyFields _ _ r = first <<< rest
161 first = Builder.insert nameP (jss val)
162 val = Record.get nameP r
163 rest = jssifyFields propsP tailP r
164 nameP = SProxy ∷ SProxy name
165 tailP = RL.RLProxy ∷ RL.RLProxy tail
166 propsP = Proxy ∷ Proxy props
167 name = reflectSymbol nameP
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list