0 | module Text.HTML.DomID
2 | import Data.Linear.Unique
3 | import Data.List.Quantifiers
4 | import Derive.Prelude
8 | %language ElabReflection
19 | %runElab derive "DomID" [Show,Eq,Ord,FromString]
23 | toID : Cast t DomID => t -> DomID
29 | withDomID : Cast t DomID => t -> HTMLNode -> HTMLNode
30 | withDomID = withId . value . toID
34 | forID : Cast t DomID => t -> Attribute x
35 | forID = for . value . toID
42 | Interpolation DomID where interpolate = value
45 | Semigroup DomID where
46 | D x <+> D y = D $
x ++ "-" ++ y
49 | Cast Nat DomID where cast = D . show
52 | Cast x DomID => Cast (SnocList x) DomID where
54 | cast (sx :< x) = cast sx <+> cast x
57 | Cast x DomID => Cast (List x) DomID where
59 | cast (x::xs) = cast x <+> cast xs
62 | (prf : All (\x => Cast (f x) DomID) ks) => Cast (List.Quantifiers.All.All f ks) DomID where
64 | cast @{_::_} (x::xs) = cast x <+> cast xs
71 | tagRef : {s : _} -> (0 tag : HTMLTag s) -> Cast t DomID => t -> Ref tag
72 | tagRef _ v = Id (value $
cast v)
75 | elemRef : Cast t DomID => t -> Ref Void
76 | elemRef v = Elem (value $
cast v)
80 | btnRef : Cast t DomID => t -> Ref Tag.Button
85 | divRef : Cast t DomID => t -> Ref Tag.Div
90 | inpRef : Cast t DomID => t -> Ref Tag.Input
95 | canvasRef : Cast t DomID => t -> Ref Tag.Canvas
96 | canvasRef = tagRef _
100 | ref : {s : _} -> {0 tag : HTMLTag s} -> Cast t DomID => t -> Attribute tag
101 | ref = Id . tagRef tag
105 | uniqueID : LIO io => io DomID
106 | uniqueID = map (D . ("uid" ++) . show) token
110 | uniqueRef : {s : _} -> LIO io => (0 t : HTMLTag s) -> io (Ref t)
111 | uniqueRef tag = tagRef tag <$> uniqueID