3
3
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_components.ipynb.
4
4
5
5
# %% auto 0
6
- __all__ = ['named' , 'html_attrs' , 'hx_attrs' , 'hx_attrs_annotations' , 'attrmap_x' , 'ft_html' , 'ft_hx' , 'File' , 'show' ,
7
- 'fill_form' , 'fill_dataclass' , 'find_inputs' , 'html2ft' , 'sse_message' , 'A' , 'Abbr' , 'Address' , 'Area' ,
8
- 'Article' , 'Aside' , 'Audio' , 'B' , 'Base' , 'Bdi' , 'Bdo' , 'Blockquote' , 'Body' , 'Br' , 'Button' , 'Canvas' ,
9
- 'Caption' , 'Cite' , 'Code' , 'Col' , 'Colgroup' , 'Data' , 'Datalist' , 'Dd' , 'Del' , 'Details' , 'Dfn' , 'Dialog' ,
10
- 'Div' , 'Dl' , 'Dt' , 'Em' , 'Embed' , 'Fencedframe' , 'Fieldset' , 'Figcaption' , 'Figure' , 'Footer' , 'Form' , 'H1' ,
11
- 'H2' , 'H3' , 'H4' , 'H5' , 'H6' , 'Head' , 'Header' , 'Hgroup' , 'Hr' , 'I' , 'Iframe' , 'Img' , 'Input' , 'Ins' , 'Kbd' ,
12
- 'Label' , 'Legend' , 'Li' , 'Link' , 'Main' , 'Map' , 'Mark' , 'Menu' , 'Meta' , 'Meter' , 'Nav' , 'Noscript' , 'Object' ,
13
- 'Ol' , 'Optgroup' , 'Option' , 'Output' , 'P' , 'Picture' , 'PortalExperimental' , 'Pre' , 'Progress' , 'Q' , 'Rp' ,
14
- 'Rt' , 'Ruby' , 'S' , 'Samp' , 'Script' , 'Search' , 'Section' , 'Select' , 'Slot' , 'Small' , 'Source' , 'Span' ,
15
- 'Strong' , 'Style' , 'Sub' , 'Summary' , 'Sup' , 'Table' , 'Tbody' , 'Td' , 'Template' , 'Textarea' , 'Tfoot' , 'Th' ,
16
- 'Thead' , 'Time' , 'Title' , 'Tr' , 'Track' , 'U' , 'Ul' , 'Var' , 'Video' , 'Wbr' ]
6
+ __all__ = ['named' , 'html_attrs' , 'hx_attrs' , 'hx_evts' , 'js_evts' , 'hx_attrs_annotations' , 'hx_evt_attrs' , 'js_evt_attrs' ,
7
+ 'evt_attrs' , 'attrmap_x' , 'ft_html' , 'ft_hx' , 'File' , 'show' , 'fill_form' , 'fill_dataclass' , 'find_inputs' ,
8
+ 'html2ft' , 'sse_message' , 'A' , 'Abbr' , 'Address' , 'Area' , 'Article' , 'Aside' , 'Audio' , 'B' , 'Base' , 'Bdi' ,
9
+ 'Bdo' , 'Blockquote' , 'Body' , 'Br' , 'Button' , 'Canvas' , 'Caption' , 'Cite' , 'Code' , 'Col' , 'Colgroup' , 'Data' ,
10
+ 'Datalist' , 'Dd' , 'Del' , 'Details' , 'Dfn' , 'Dialog' , 'Div' , 'Dl' , 'Dt' , 'Em' , 'Embed' , 'Fencedframe' ,
11
+ 'Fieldset' , 'Figcaption' , 'Figure' , 'Footer' , 'Form' , 'H1' , 'H2' , 'H3' , 'H4' , 'H5' , 'H6' , 'Head' , 'Header' ,
12
+ 'Hgroup' , 'Hr' , 'I' , 'Iframe' , 'Img' , 'Input' , 'Ins' , 'Kbd' , 'Label' , 'Legend' , 'Li' , 'Link' , 'Main' , 'Map' ,
13
+ 'Mark' , 'Menu' , 'Meta' , 'Meter' , 'Nav' , 'Noscript' , 'Object' , 'Ol' , 'Optgroup' , 'Option' , 'Output' , 'P' ,
14
+ 'Picture' , 'PortalExperimental' , 'Pre' , 'Progress' , 'Q' , 'Rp' , 'Rt' , 'Ruby' , 'S' , 'Samp' , 'Script' , 'Search' ,
15
+ 'Section' , 'Select' , 'Slot' , 'Small' , 'Source' , 'Span' , 'Strong' , 'Style' , 'Sub' , 'Summary' , 'Sup' , 'Table' ,
16
+ 'Tbody' , 'Td' , 'Template' , 'Textarea' , 'Tfoot' , 'Th' , 'Thead' , 'Time' , 'Title' , 'Tr' , 'Track' , 'U' , 'Ul' ,
17
+ 'Var' , 'Video' , 'Wbr' ]
17
18
18
19
# %% ../nbs/api/01_components.ipynb
19
20
from dataclasses import dataclass , asdict , is_dataclass , make_dataclass , replace , astuple , MISSING
@@ -47,6 +48,9 @@ def __add__(self:FT, b): return f'{self}{b}'
47
48
named = set ('a button form frame iframe img input map meta object param select textarea' .split ())
48
49
html_attrs = 'id cls title style accesskey contenteditable dir draggable enterkeyhint hidden inert inputmode lang popover spellcheck tabindex translate' .split ()
49
50
hx_attrs = 'get post put delete patch trigger target swap swap_oob include select select_oob indicator push_url confirm disable replace_url vals disabled_elt ext headers history history_elt indicator inherit params preserve prompt replace_url request sync validate'
51
+
52
+ hx_evts = 'abort afterOnLoad afterProcessNode afterRequest afterSettle afterSwap beforeCleanupElement beforeOnLoad beforeProcessNode beforeRequest beforeSwap beforeSend beforeTransition configRequest confirm historyCacheError historyCacheMiss historyCacheMissError historyCacheMissLoad historyRestore beforeHistorySave load noSSESourceError onLoadError oobAfterSwap oobBeforeSwap oobErrorNoTarget prompt pushedIntoHistory replacedInHistory responseError sendAbort sendError sseError sseOpen swapError targetError timeout validation:validate validation:failed validation:halted xhr:abort xhr:loadend xhr:loadstart xhr:progress'
53
+ js_evts = "blur change contextmenu focus input invalid reset select submit keydown keypress keyup click dblclick mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup wheel"
50
54
hx_attrs = [f'hx_{ o } ' for o in hx_attrs .split ()]
51
55
hx_attrs_annotations = {
52
56
"hx_swap" : Literal ["innerHTML" , "outerHTML" , "afterbegin" , "beforebegin" , "beforeend" , "afterend" , "delete" , "none" ] | str ,
@@ -62,6 +66,10 @@ def __add__(self:FT, b): return f'{self}{b}'
62
66
hx_attrs_annotations = {k : Optional [v ] for k ,v in hx_attrs_annotations .items ()}
63
67
hx_attrs = html_attrs + hx_attrs
64
68
69
+ hx_evt_attrs = ['hx_on__' + camel2snake (o ).replace (':' ,'_' ) for o in hx_evts .split ()]
70
+ js_evt_attrs = ['hx_on_' + o for o in js_evts .split ()]
71
+ evt_attrs = js_evt_attrs + hx_evt_attrs
72
+
65
73
# %% ../nbs/api/01_components.ipynb
66
74
def attrmap_x (o ):
67
75
if o .startswith ('_at_' ): o = '@' + o [4 :]
@@ -90,7 +98,7 @@ def ft_html(tag: str, *c, id=None, cls=None, title=None, style=None, attrmap=Non
90
98
return ft_cls (tag ,c ,kw , void_ = tag in voids )
91
99
92
100
# %% ../nbs/api/01_components.ipynb
93
- @use_kwargs (hx_attrs , keep = True )
101
+ @use_kwargs (hx_attrs + evt_attrs , keep = True )
94
102
def ft_hx (tag : str , * c , target_id = None , hx_vals = None , hx_target = None , ** kwargs ):
95
103
if hx_vals : kwargs ['hx_vals' ] = json .dumps (hx_vals ) if isinstance (hx_vals ,dict ) else hx_vals
96
104
if hx_target : kwargs ['hx_target' ] = '#' + hx_target .id if isinstance (hx_target ,FT ) else hx_target
0 commit comments