python-fasthtml 0.14.15__tar.gz → 0.14.17__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {python_fasthtml-0.14.15/python_fasthtml.egg-info → python_fasthtml-0.14.17}/PKG-INFO +1 -1
  2. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/__init__.py +1 -1
  3. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/_modidx.py +2 -0
  4. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/components.py +17 -11
  5. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/core.py +10 -4
  6. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/toaster.py +10 -3
  7. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/xtend.py +3 -2
  8. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17/python_fasthtml.egg-info}/PKG-INFO +1 -1
  9. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/CONTRIBUTING.md +0 -0
  10. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/LICENSE +0 -0
  11. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/MANIFEST.in +0 -0
  12. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/README.md +0 -0
  13. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/authmw.py +0 -0
  14. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/basics.py +0 -0
  15. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/cli.py +0 -0
  16. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/common.py +0 -0
  17. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/components.pyi +0 -0
  18. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/core.pyi +0 -0
  19. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/fastapp.py +0 -0
  20. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/ft.py +0 -0
  21. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/js.py +0 -0
  22. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/jupyter.py +0 -0
  23. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/katex.js +0 -0
  24. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/live_reload.py +0 -0
  25. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/oauth.py +0 -0
  26. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/pico.py +0 -0
  27. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/starlette.py +0 -0
  28. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/stripe_otp.py +0 -0
  29. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/svg.py +0 -0
  30. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/fasthtml/xtend.pyi +0 -0
  31. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/pyproject.toml +0 -0
  32. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/python_fasthtml.egg-info/SOURCES.txt +0 -0
  33. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/python_fasthtml.egg-info/dependency_links.txt +0 -0
  34. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/python_fasthtml.egg-info/entry_points.txt +0 -0
  35. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/python_fasthtml.egg-info/requires.txt +0 -0
  36. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/python_fasthtml.egg-info/top_level.txt +0 -0
  37. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/setup.cfg +0 -0
  38. {python_fasthtml-0.14.15 → python_fasthtml-0.14.17}/tests/test_toaster.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.15
3
+ Version: 0.14.17
4
4
  Summary: The fastest way to create an HTML app
5
5
  Author-email: Jeremy Howard and contributors <github@jhoward.fastmail.fm>
6
6
  License-Expression: Apache-2.0
@@ -4,5 +4,5 @@ Modules:
4
4
 
5
5
  - `fasthtml.core`: The `FastHTML` subclass of `Starlette`."""
6
6
 
7
- __version__ = "0.14.15"
7
+ __version__ = "0.14.17"
8
8
  from .core import *
@@ -12,6 +12,7 @@ d = { 'settings': { 'branch': 'main',
12
12
  'fasthtml.components.FT.__radd__': ('api/components.html#ft.__radd__', 'fasthtml/components.py'),
13
13
  'fasthtml.components.FT.__str__': ('api/components.html#ft.__str__', 'fasthtml/components.py'),
14
14
  'fasthtml.components.File': ('api/components.html#file', 'fasthtml/components.py'),
15
+ 'fasthtml.components.Partial': ('api/components.html#partial', 'fasthtml/components.py'),
15
16
  'fasthtml.components._fill_item': ('api/components.html#_fill_item', 'fasthtml/components.py'),
16
17
  'fasthtml.components.attrmap_x': ('api/components.html#attrmap_x', 'fasthtml/components.py'),
17
18
  'fasthtml.components.fill_dataclass': ('api/components.html#fill_dataclass', 'fasthtml/components.py'),
@@ -115,6 +116,7 @@ d = { 'settings': { 'branch': 'main',
115
116
  'fasthtml.core._form_arg': ('api/core.html#_form_arg', 'fasthtml/core.py'),
116
117
  'fasthtml.core._formitem': ('api/core.html#_formitem', 'fasthtml/core.py'),
117
118
  'fasthtml.core._from_body': ('api/core.html#_from_body', 'fasthtml/core.py'),
119
+ 'fasthtml.core._get_header': ('api/core.html#_get_header', 'fasthtml/core.py'),
118
120
  'fasthtml.core._get_htmx': ('api/core.html#_get_htmx', 'fasthtml/core.py'),
119
121
  'fasthtml.core._handle': ('api/core.html#_handle', 'fasthtml/core.py'),
120
122
  'fasthtml.core._is_body': ('api/core.html#_is_body', 'fasthtml/core.py'),
@@ -6,17 +6,17 @@ Docs: https://www.fastht.ml/docs/api/components.html.md"""
6
6
 
7
7
  # %% auto #0
8
8
  __all__ = ['named', 'html_attrs', 'hx_attrs', 'hx_attrs_4only', 'hx_evts', 'hx_evts_4only', 'js_evts', 'hx_attrs_annotations',
9
- 'hx_evt_attrs', 'js_evt_attrs', 'evt_attrs', 'HxPartial', 'attrmap_x', 'ft_html', 'ft_hx', 'File', 'show',
10
- 'fill_form', 'fill_dataclass', 'find_inputs', 'html2ft', 'sse_message', 'A', 'Abbr', 'Address', 'Area',
11
- 'Article', 'Aside', 'Audio', 'B', 'Base', 'Bdi', 'Bdo', 'Blockquote', 'Body', 'Br', 'Button', 'Canvas',
12
- 'Caption', 'Cite', 'Code', 'Col', 'Colgroup', 'Data', 'Datalist', 'Dd', 'Del', 'Details', 'Dfn', 'Dialog',
13
- 'Div', 'Dl', 'Dt', 'Em', 'Embed', 'Fencedframe', 'Fieldset', 'Figcaption', 'Figure', 'Footer', 'Form', 'H1',
14
- 'H2', 'H3', 'H4', 'H5', 'H6', 'Head', 'Header', 'Hgroup', 'Hr', 'I', 'Iframe', 'Img', 'Input', 'Ins', 'Kbd',
15
- 'Label', 'Legend', 'Li', 'Link', 'Main', 'Map', 'Mark', 'Menu', 'Meta', 'Meter', 'Nav', 'Noscript', 'Object',
16
- 'Ol', 'Optgroup', 'Option', 'Output', 'P', 'Picture', 'PortalExperimental', 'Pre', 'Progress', 'Q', 'Rp',
17
- 'Rt', 'Ruby', 'S', 'Samp', 'Script', 'Search', 'Section', 'Select', 'Slot', 'Small', 'Source', 'Span',
18
- 'Strong', 'Style', 'Sub', 'Summary', 'Sup', 'Table', 'Tbody', 'Td', 'Template', 'Textarea', 'Tfoot', 'Th',
19
- 'Thead', 'Time', 'Title', 'Tr', 'Track', 'U', 'Ul', 'Var', 'Video', 'Wbr']
9
+ 'hx_evt_attrs', 'js_evt_attrs', 'evt_attrs', 'HxPartial', 'attrmap_x', 'ft_html', 'ft_hx', 'Partial', 'File',
10
+ 'show', 'fill_form', 'fill_dataclass', 'find_inputs', 'html2ft', 'sse_message', 'A', 'Abbr', 'Address',
11
+ 'Area', 'Article', 'Aside', 'Audio', 'B', 'Base', 'Bdi', 'Bdo', 'Blockquote', 'Body', 'Br', 'Button',
12
+ 'Canvas', 'Caption', 'Cite', 'Code', 'Col', 'Colgroup', 'Data', 'Datalist', 'Dd', 'Del', 'Details', 'Dfn',
13
+ 'Dialog', 'Div', 'Dl', 'Dt', 'Em', 'Embed', 'Fencedframe', 'Fieldset', 'Figcaption', 'Figure', 'Footer',
14
+ 'Form', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Head', 'Header', 'Hgroup', 'Hr', 'I', 'Iframe', 'Img', 'Input',
15
+ 'Ins', 'Kbd', 'Label', 'Legend', 'Li', 'Link', 'Main', 'Map', 'Mark', 'Menu', 'Meta', 'Meter', 'Nav',
16
+ 'Noscript', 'Object', 'Ol', 'Optgroup', 'Option', 'Output', 'P', 'Picture', 'PortalExperimental', 'Pre',
17
+ 'Progress', 'Q', 'Rp', 'Rt', 'Ruby', 'S', 'Samp', 'Script', 'Search', 'Section', 'Select', 'Slot', 'Small',
18
+ 'Source', 'Span', 'Strong', 'Style', 'Sub', 'Summary', 'Sup', 'Table', 'Tbody', 'Td', 'Template', 'Textarea',
19
+ 'Tfoot', 'Th', 'Thead', 'Time', 'Title', 'Tr', 'Track', 'U', 'Ul', 'Var', 'Video', 'Wbr']
20
20
 
21
21
  # %% ../nbs/api/01_components.ipynb #8e2d405b
22
22
  from dataclasses import dataclass, asdict, is_dataclass, make_dataclass, replace, astuple, MISSING
@@ -124,6 +124,12 @@ for o in _all_: _g[o] = partial(ft_hx, o.lower())
124
124
  HxPartial = partial(ft_hx, 'hx-partial') # For hx v4, manually mapping because Python doesn't allow hyphens
125
125
 
126
126
 
127
+ # %% ../nbs/api/01_components.ipynb #2b0d9197
128
+ @delegates(HxPartial, keep=True, but='hx_target,hx_swap')
129
+ def Partial(target, *c, swap=None, **kwargs)->FT:
130
+ "Wrap content in an HTMX4 partial update."
131
+ return HxPartial(*c, hx_target=target, hx_swap=swap, **kwargs)
132
+
127
133
  # %% ../nbs/api/01_components.ipynb #fab04fb3
128
134
  def File(fname):
129
135
  "Use the unescaped text in file `fname` directly"
@@ -119,8 +119,14 @@ class HtmxHeaders:
119
119
  trigger_name:str|None=None; trigger:str|None=None
120
120
  def __bool__(self): return any(hasattr(self,o) for o in htmx_hdrs)
121
121
 
122
+ def _get_header(h, k):
123
+ k = k.lower()
124
+ res = h.get(k)
125
+ encoded = h.get(k+'-uri-autoencoded')=='true' or (k=='hx-prompt' and h.get('hx-request-type'))
126
+ return unquote(res) if res is not None and encoded else res
127
+
122
128
  def _get_htmx(h):
123
- res = {k:h.get(v.lower(), None) for k,v in htmx_hdrs.items()}
129
+ res = {k:_get_header(h, v) for k,v in htmx_hdrs.items()}
124
130
  return HtmxHeaders(**res)
125
131
 
126
132
  # %% ../nbs/api/00_core.ipynb #1d53e8e7
@@ -293,7 +299,7 @@ async def _find_p(conn, data, hdrs, arg:str, p:Parameter):
293
299
  # Not a special name or a special annotation
294
300
  res = conn.path_params.get(arg, None)
295
301
  if res in (empty,None): res = conn.cookies.get(arg, None)
296
- if res in (empty,None): res = hdrs.get(snake2hyphens(arg), None)
302
+ if res in (empty,None): res = _get_header(hdrs, snake2hyphens(arg))
297
303
  if res in (empty,None): res = _formitem(conn.query_params, arg)
298
304
  if res in (empty,None): res = _formitem(data, arg)
299
305
  if res in (empty,None) and isinstance(vals := data.get('values'), dict): res = _formitem(vals, arg) # htmx v4 nests form data under `values`
@@ -621,7 +627,7 @@ def def_hdrs(htmx=True, htmx4=False, surreal=True):
621
627
  "Default headers for a FastHTML app"
622
628
  hdrs = []
623
629
  if surreal: hdrs = [surrsrc,scopesrc] + hdrs
624
- if htmx4:
630
+ if htmx and htmx4:
625
631
  # metaCharacter="-" makes htmx4 use dashes instead of colons
626
632
  meta_cfg = Meta(name="htmx-config", content=json.dumps({"metaCharacter": "-"}))
627
633
  hdrs = [meta_cfg, htmx4src,fhjsscr] + hdrs
@@ -692,7 +698,7 @@ class FastHTML(Starlette):
692
698
  same_site='lax', sess_https_only=False, sess_domain=None, key_fname='.sesskey',
693
699
  body_wrap=noop_body, htmlkw=None, nb_hdrs=False, canonical=True, max_part_size=DEF_MAXPART, **bodykw):
694
700
  middleware,before,after = map(_list, (middleware,before,after))
695
- self.title,self.canonical,self.session_cookie,self.key_fname = title,canonical,session_cookie,key_fname
701
+ self.htmx4,self.title,self.canonical,self.session_cookie,self.key_fname = htmx4,title,canonical,session_cookie,key_fname
696
702
  hdrs,ftrs,exts = map(listify, (hdrs,ftrs,exts))
697
703
  if htmx4 and exts: exts = ['ws4' if e in ('ws', 'ws4') else e for e in exts]
698
704
  exts = {k:htmx_exts[k] for k in exts}
@@ -49,14 +49,21 @@ def add_toast(sess, message: str, typ: str = "info", dismiss: bool = False):
49
49
  assert typ in ("info", "success", "warning", "error"), '`typ` not in ("info", "success", "warning", "error")'
50
50
  sess.setdefault(sk, []).append((message, typ, dismiss))
51
51
 
52
+ def _toast_content(sess):
53
+ return [Toast(msg, typ, dismiss, sess['toast_duration']) for msg, typ, dismiss in sess.pop(sk, [])]
54
+
52
55
  def render_toasts(sess):
53
- toasts = [Toast(msg, typ, dismiss, sess['toast_duration']) for msg, typ, dismiss in sess.pop(sk, [])]
54
- return Div(*toasts, id=tcid, hx_swap_oob=f'beforeend:#{tcid}')
56
+ return Div(*_toast_content(sess), id=tcid, hx_swap_oob=f'beforeend:#{tcid}')
55
57
 
56
58
  def toast_after(resp, req, sess):
57
59
  if sk in sess and (not resp or isinstance(resp, (tuple,FT,FtResponse))):
58
60
  sess['toast_duration'] = req.app.state.toast_duration
59
- req.injects.append(render_toasts(sess))
61
+ if req.app.htmx4:
62
+ content = _toast_content(sess)
63
+ fragment = 'hx-request' in req.headers and 'hx-history-restore-request' not in req.headers
64
+ res = Partial(f'#{tcid}', *content, swap='beforeend') if fragment else Div(*content, id=tcid)
65
+ else: res = render_toasts(sess)
66
+ req.injects.append(res)
60
67
 
61
68
  def setup_toasts(app, duration=5000):
62
69
  app.state.toast_duration = duration
@@ -353,8 +353,9 @@ def sitemap_xml(app, urls, loc_base=""):
353
353
  return Urlset(*urlset, xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
354
354
 
355
355
  # %% ../nbs/api/02_xtend.ipynb #6a1990ed
356
- def upload_pb_attrs(id='uploadprog'):
357
- "Form `hx_on` progress attr that reveals and updates a hidden `upload_pb` of matching `id`"
356
+ def upload_pb_attrs(id='uploadprog', htmx4=False):
357
+ "Form attrs for an upload progress bar (htmx2) or request indicator (htmx4)"
358
+ if htmx4: return {'hx-indicator': f'#{id}'}
358
359
  js = """{ const p=document.getElementById('%s');
359
360
  if(event.detail.total) {p.classList.remove('hidden'); p.value=event.detail.loaded/event.detail.total*100} }""" % id
360
361
  return {'hx-on::xhr:progress': js}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.15
3
+ Version: 0.14.17
4
4
  Summary: The fastest way to create an HTML app
5
5
  Author-email: Jeremy Howard and contributors <github@jhoward.fastmail.fm>
6
6
  License-Expression: Apache-2.0