python-fasthtml 0.14.16__tar.gz → 0.14.18__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.16/python_fasthtml.egg-info → python_fasthtml-0.14.18}/PKG-INFO +1 -1
  2. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/__init__.py +1 -1
  3. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/_modidx.py +1 -0
  4. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/components.py +17 -11
  5. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/core.py +7 -7
  6. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/toaster.py +10 -3
  7. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18/python_fasthtml.egg-info}/PKG-INFO +1 -1
  8. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/CONTRIBUTING.md +0 -0
  9. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/LICENSE +0 -0
  10. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/MANIFEST.in +0 -0
  11. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/README.md +0 -0
  12. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/authmw.py +0 -0
  13. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/basics.py +0 -0
  14. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/cli.py +0 -0
  15. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/common.py +0 -0
  16. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/components.pyi +0 -0
  17. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/core.pyi +0 -0
  18. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/fastapp.py +0 -0
  19. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/ft.py +0 -0
  20. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/js.py +0 -0
  21. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/jupyter.py +0 -0
  22. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/katex.js +0 -0
  23. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/live_reload.py +0 -0
  24. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/oauth.py +0 -0
  25. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/pico.py +0 -0
  26. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/starlette.py +0 -0
  27. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/stripe_otp.py +0 -0
  28. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/svg.py +0 -0
  29. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/xtend.py +0 -0
  30. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/fasthtml/xtend.pyi +0 -0
  31. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/pyproject.toml +0 -0
  32. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/python_fasthtml.egg-info/SOURCES.txt +0 -0
  33. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/python_fasthtml.egg-info/dependency_links.txt +0 -0
  34. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/python_fasthtml.egg-info/entry_points.txt +0 -0
  35. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/python_fasthtml.egg-info/requires.txt +0 -0
  36. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/python_fasthtml.egg-info/top_level.txt +0 -0
  37. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/setup.cfg +0 -0
  38. {python_fasthtml-0.14.16 → python_fasthtml-0.14.18}/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.16
3
+ Version: 0.14.18
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.16"
7
+ __version__ = "0.14.18"
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'),
@@ -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"
@@ -569,16 +569,16 @@ htmx_exts = {
569
569
  "remove-me": "https://cdn.jsdelivr.net/npm/htmx-ext-remove-me@2.0.0/remove-me.js",
570
570
  "debug": "https://unpkg.com/htmx.org@1.9.12/dist/ext/debug.js",
571
571
  "ws": "https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.3/ws.js",
572
- "ws4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/ext/hx-ws.min.js",
572
+ "ws4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-ws.min.js",
573
573
  "chunked-transfer": "https://cdn.jsdelivr.net/npm/htmx-ext-transfer-encoding-chunked@0.4.0/transfer-encoding-chunked.js",
574
- "sse4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/ext/hx-sse.min.js",
575
- "live": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/ext/hx-live.min.js",
576
- "multipart": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/ext/hx-multipart.min.js"
574
+ "sse4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-sse.min.js",
575
+ "live": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-live.min.js",
576
+ "multipart": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-multipart.min.js"
577
577
  }
578
578
 
579
579
  # %% ../nbs/api/00_core.ipynb #60cb52ea
580
580
  htmxsrc = Script(src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js")
581
- htmx4src = Script(src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/htmx.min.js")
581
+ htmx4src = Script(src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/htmx.min.js")
582
582
  fhjsscr = Script(src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.13/fasthtml.js")
583
583
  surrsrc = Script(src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js")
584
584
  scopesrc = Script(src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js")
@@ -627,7 +627,7 @@ def def_hdrs(htmx=True, htmx4=False, surreal=True):
627
627
  "Default headers for a FastHTML app"
628
628
  hdrs = []
629
629
  if surreal: hdrs = [surrsrc,scopesrc] + hdrs
630
- if htmx4:
630
+ if htmx and htmx4:
631
631
  # metaCharacter="-" makes htmx4 use dashes instead of colons
632
632
  meta_cfg = Meta(name="htmx-config", content=json.dumps({"metaCharacter": "-"}))
633
633
  hdrs = [meta_cfg, htmx4src,fhjsscr] + hdrs
@@ -698,7 +698,7 @@ class FastHTML(Starlette):
698
698
  same_site='lax', sess_https_only=False, sess_domain=None, key_fname='.sesskey',
699
699
  body_wrap=noop_body, htmlkw=None, nb_hdrs=False, canonical=True, max_part_size=DEF_MAXPART, **bodykw):
700
700
  middleware,before,after = map(_list, (middleware,before,after))
701
- 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
702
702
  hdrs,ftrs,exts = map(listify, (hdrs,ftrs,exts))
703
703
  if htmx4 and exts: exts = ['ws4' if e in ('ws', 'ws4') else e for e in exts]
704
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.16
3
+ Version: 0.14.18
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