hstream-webawesome 0.1.0__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.
- hstream_webawesome-0.1.0/.gitignore +172 -0
- hstream_webawesome-0.1.0/PKG-INFO +142 -0
- hstream_webawesome-0.1.0/README.md +133 -0
- hstream_webawesome-0.1.0/examples/showcase.py +46 -0
- hstream_webawesome-0.1.0/pyproject.toml +31 -0
- hstream_webawesome-0.1.0/scripts/generate.py +434 -0
- hstream_webawesome-0.1.0/src/hstream_webawesome/__init__.py +171 -0
- hstream_webawesome-0.1.0/src/hstream_webawesome/_base.py +292 -0
- hstream_webawesome-0.1.0/src/hstream_webawesome/_generated.py +6586 -0
- hstream_webawesome-0.1.0/src/hstream_webawesome/_wa_version.py +3 -0
- hstream_webawesome-0.1.0/tests/conftest.py +57 -0
- hstream_webawesome-0.1.0/tests/test_browser.py +161 -0
- hstream_webawesome-0.1.0/tests/test_components.py +214 -0
- hstream_webawesome-0.1.0/tests/test_http.py +44 -0
- hstream_webawesome-0.1.0/uv.lock +340 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# files sometimes used for local testing
|
|
2
|
+
/Dockerfile
|
|
3
|
+
/example.py
|
|
4
|
+
test-env/
|
|
5
|
+
|
|
6
|
+
# Auto-generated version file
|
|
7
|
+
|
|
8
|
+
# Byte-compiled / optimized / DLL files
|
|
9
|
+
__pycache__/
|
|
10
|
+
*.py[cod]
|
|
11
|
+
*$py.class
|
|
12
|
+
|
|
13
|
+
# C extensions
|
|
14
|
+
*.so
|
|
15
|
+
|
|
16
|
+
# Distribution / packaging
|
|
17
|
+
.Python
|
|
18
|
+
build/
|
|
19
|
+
develop-eggs/
|
|
20
|
+
dist/
|
|
21
|
+
downloads/
|
|
22
|
+
eggs/
|
|
23
|
+
.eggs/
|
|
24
|
+
lib/
|
|
25
|
+
lib64/
|
|
26
|
+
parts/
|
|
27
|
+
sdist/
|
|
28
|
+
var/
|
|
29
|
+
wheels/
|
|
30
|
+
share/python-wheels/
|
|
31
|
+
*.egg-info/
|
|
32
|
+
.installed.cfg
|
|
33
|
+
*.egg
|
|
34
|
+
MANIFEST
|
|
35
|
+
|
|
36
|
+
# PyInstaller
|
|
37
|
+
# Usually these files are written by a python script from a template
|
|
38
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
39
|
+
*.manifest
|
|
40
|
+
*.spec
|
|
41
|
+
|
|
42
|
+
# Installer logs
|
|
43
|
+
pip-log.txt
|
|
44
|
+
pip-delete-this-directory.txt
|
|
45
|
+
|
|
46
|
+
# Unit test / coverage reports
|
|
47
|
+
htmlcov/
|
|
48
|
+
.tox/
|
|
49
|
+
.nox/
|
|
50
|
+
.coverage
|
|
51
|
+
.coverage.*
|
|
52
|
+
.cache
|
|
53
|
+
nosetests.xml
|
|
54
|
+
coverage.xml
|
|
55
|
+
*.cover
|
|
56
|
+
*.py,cover
|
|
57
|
+
.hypothesis/
|
|
58
|
+
.pytest_cache/
|
|
59
|
+
cover/
|
|
60
|
+
|
|
61
|
+
# Translations
|
|
62
|
+
*.mo
|
|
63
|
+
*.pot
|
|
64
|
+
|
|
65
|
+
# Django stuff:
|
|
66
|
+
*.log
|
|
67
|
+
local_settings.py
|
|
68
|
+
db.sqlite3
|
|
69
|
+
db.sqlite3-journal
|
|
70
|
+
|
|
71
|
+
# Flask stuff:
|
|
72
|
+
instance/
|
|
73
|
+
.webassets-cache
|
|
74
|
+
|
|
75
|
+
# Scrapy stuff:
|
|
76
|
+
.scrapy
|
|
77
|
+
|
|
78
|
+
# Sphinx documentation
|
|
79
|
+
docs/_build/
|
|
80
|
+
|
|
81
|
+
# PyBuilder
|
|
82
|
+
.pybuilder/
|
|
83
|
+
target/
|
|
84
|
+
|
|
85
|
+
# Jupyter Notebook
|
|
86
|
+
.ipynb_checkpoints
|
|
87
|
+
|
|
88
|
+
# IPython
|
|
89
|
+
profile_default/
|
|
90
|
+
ipython_config.py
|
|
91
|
+
|
|
92
|
+
# pyenv
|
|
93
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
94
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
95
|
+
# .python-version
|
|
96
|
+
|
|
97
|
+
# pipenv
|
|
98
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
99
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
100
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
101
|
+
# install all needed dependencies.
|
|
102
|
+
#Pipfile.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
#poetry.lock
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
#pdm.lock
|
|
114
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
115
|
+
# in version control.
|
|
116
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
117
|
+
.pdm.toml
|
|
118
|
+
|
|
119
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
120
|
+
__pypackages__/
|
|
121
|
+
|
|
122
|
+
# Celery stuff
|
|
123
|
+
celerybeat-schedule
|
|
124
|
+
celerybeat.pid
|
|
125
|
+
|
|
126
|
+
# SageMath parsed files
|
|
127
|
+
*.sage.py
|
|
128
|
+
|
|
129
|
+
# Environments
|
|
130
|
+
.env
|
|
131
|
+
.venv
|
|
132
|
+
env/
|
|
133
|
+
venv/
|
|
134
|
+
ENV/
|
|
135
|
+
env.bak/
|
|
136
|
+
venv.bak/
|
|
137
|
+
|
|
138
|
+
# Spyder project settings
|
|
139
|
+
.spyderproject
|
|
140
|
+
.spyproject
|
|
141
|
+
|
|
142
|
+
# Rope project settings
|
|
143
|
+
.ropeproject
|
|
144
|
+
|
|
145
|
+
# mkdocs documentation
|
|
146
|
+
/site
|
|
147
|
+
|
|
148
|
+
# mypy
|
|
149
|
+
.mypy_cache/
|
|
150
|
+
.dmypy.json
|
|
151
|
+
dmypy.json
|
|
152
|
+
|
|
153
|
+
# Pyre type checker
|
|
154
|
+
.pyre/
|
|
155
|
+
|
|
156
|
+
# pytype static type analyzer
|
|
157
|
+
.pytype/
|
|
158
|
+
|
|
159
|
+
# Cython debug symbols
|
|
160
|
+
cython_debug/
|
|
161
|
+
|
|
162
|
+
# PyCharm
|
|
163
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
164
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
165
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
166
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
167
|
+
#.idea/
|
|
168
|
+
.aider*
|
|
169
|
+
test_strategy_logs.txt
|
|
170
|
+
|
|
171
|
+
# hs.file_upload saves uploads here
|
|
172
|
+
tmp/
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: hstream-webawesome
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Every Web Awesome component for HStream apps, as hs.wa.* (generated from Web Awesome's custom-elements.json).
|
|
5
|
+
Project-URL: Repository, https://github.com/conradbez/hstream
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: hstream>=0.9.0
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# hstream-webawesome
|
|
11
|
+
|
|
12
|
+
Every [Web Awesome](https://webawesome.com) component (78 of them, Web Awesome
|
|
13
|
+
3.15.0) for [HStream](../README.md) apps, as `wa.*`.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install "hstream[webawesome]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from hstream import hs, wa
|
|
21
|
+
|
|
22
|
+
name = wa.input("Your name", placeholder="Ada")
|
|
23
|
+
if wa.switch("Shout"):
|
|
24
|
+
name = name.upper()
|
|
25
|
+
|
|
26
|
+
with wa.card():
|
|
27
|
+
wa.callout(f"Hello, {name or 'stranger'}!", variant="brand")
|
|
28
|
+
if wa.button("Save", variant="brand", slot="footer"):
|
|
29
|
+
wa.badge("Saved", variant="success")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`from hstream import wa` finds the package through its `hstream.components`
|
|
33
|
+
entry point (no `import hstream_webawesome` needed). `hs.wa` is the same
|
|
34
|
+
object, so `hs.wa.input(...)` works too, and so does `p.wa.input(...)` on a
|
|
35
|
+
placeholder. Web Awesome's theme and loader come from its CDN, and only on
|
|
36
|
+
pages that use a `wa` component. A fuller demo is in
|
|
37
|
+
[`examples/showcase.py`](examples/showcase.py)
|
|
38
|
+
(`hstream run examples/showcase.py`).
|
|
39
|
+
|
|
40
|
+
## Form controls
|
|
41
|
+
|
|
42
|
+
Form controls work like HStream's built-ins: they return their current value,
|
|
43
|
+
and every change reruns the script. Each is its own element (`<wa-input
|
|
44
|
+
id="container_for_<key>">`, with no wrapping `<div>`), so it can sit directly
|
|
45
|
+
in a `wa-button-group` or take `slot="footer"`.
|
|
46
|
+
|
|
47
|
+
| Component | Returns |
|
|
48
|
+
| :--- | :--- |
|
|
49
|
+
| `wa.input(label, default_value=None)`, `textarea`, `color_picker`, `time_input`, `known_date`, `otp_input` | `str` (`""` when empty) |
|
|
50
|
+
| `wa.number_input(label, default_value=None)`, `rating` | `int`/`float` |
|
|
51
|
+
| `wa.slider(label, default_value=None, min=, max=, step=)` | number; `range=True` returns `(low, high)` |
|
|
52
|
+
| `wa.checkbox(label, default_value=False)`, `switch` | `bool` |
|
|
53
|
+
| `wa.select(label, options, default_value=None)`, `radio_group` | the chosen option (the original object); `select(..., multiple=True)` returns a list |
|
|
54
|
+
| `wa.tag_input(label, default_value=None)` | `list` of tags |
|
|
55
|
+
| `wa.button(label)` | `True` on the run its click triggers, else `False` |
|
|
56
|
+
| `wa.menu(label, items)` | the picked item on the run the pick triggers, else `None` |
|
|
57
|
+
|
|
58
|
+
`options`/`items` are a list of values, `(value, label)` pairs, or a
|
|
59
|
+
`{value: label}` dict. Pass `key="..."` to pin a control's session key, as
|
|
60
|
+
with any HStream component.
|
|
61
|
+
|
|
62
|
+
Every Web Awesome attribute is a keyword argument with its Python name and
|
|
63
|
+
type (`with_clear=True`, `appearance="filled"`, `size="s"`); the docstrings
|
|
64
|
+
come from Web Awesome's own docs. Anything else (`klass="..."`, `style=`,
|
|
65
|
+
`data_dialog="open d1"`) becomes an attribute, `_` turned into `-`.
|
|
66
|
+
|
|
67
|
+
## Everything else
|
|
68
|
+
|
|
69
|
+
The other components render plain elements. Use the result with `with` for
|
|
70
|
+
children, or pass text (or a function that renders) as the first argument:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
with wa.tab_group():
|
|
74
|
+
wa.tab("General", panel="general", slot="nav")
|
|
75
|
+
wa.tab("Advanced", panel="advanced", slot="nav")
|
|
76
|
+
with wa.tab_panel(name="general"):
|
|
77
|
+
hs.markdown("General settings")
|
|
78
|
+
wa.tab_panel("Advanced settings", name="advanced")
|
|
79
|
+
|
|
80
|
+
with wa.details(summary="More"):
|
|
81
|
+
wa.icon(name="star")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
State the browser owns stays put across reruns: a `wa-details` the user
|
|
85
|
+
opened stays open, and so does the tab they picked, even though each
|
|
86
|
+
interaction re-renders the page. (HStream's page applies a changed attribute
|
|
87
|
+
to a custom element only when the *server's* value changed since it last sent
|
|
88
|
+
it; see "Custom elements" in HStream's architecture.md.)
|
|
89
|
+
|
|
90
|
+
Also on `wa`:
|
|
91
|
+
|
|
92
|
+
- `wa.raw.<name>(...)`: any component as a plain element without session
|
|
93
|
+
state, e.g. a button the browser handles alone:
|
|
94
|
+
`wa.raw.button("Open", data_dialog="open settings")` next to
|
|
95
|
+
`with wa.dialog(id="settings", label="Settings"): ...`.
|
|
96
|
+
- `wa.element(tag, content=None, **attrs)`: a tag this package doesn't
|
|
97
|
+
know (a newer Web Awesome release, Pro components).
|
|
98
|
+
- `wa.theme("awesome")`: another free theme (`default`, `awesome`,
|
|
99
|
+
`shoelace`), called at the top of the script.
|
|
100
|
+
|
|
101
|
+
## Over plain HTTP (agents, curl)
|
|
102
|
+
|
|
103
|
+
Controls carry the same contract as HStream's built-ins: an `hx-post` URL and
|
|
104
|
+
`name="new_value"`. To set one, `POST /set_component_value?component_id=<key>`
|
|
105
|
+
with `new_value=...`; buttons carry `&new_value=true` in their URL. Lists
|
|
106
|
+
(`multiple` selects, tag inputs) send each value as `new_value` plus
|
|
107
|
+
`hs_multiple=1`; a range slider sends `new_value=low,high`; a menu sends the
|
|
108
|
+
picked item as `new_value`. The browser computes the last two with htmx
|
|
109
|
+
`js:` values, which an HTTP client doesn't run: it just sends the value.
|
|
110
|
+
|
|
111
|
+
## In the browser build
|
|
112
|
+
|
|
113
|
+
`hstream build app.py` bundles installed component packages into the site, so
|
|
114
|
+
`wa` works under Pyodide too.
|
|
115
|
+
|
|
116
|
+
## How it's made: generated, then tuned
|
|
117
|
+
|
|
118
|
+
[`scripts/generate.py`](scripts/generate.py) reads Web Awesome's
|
|
119
|
+
`custom-elements.json` (from the npm release) and writes
|
|
120
|
+
[`_generated.py`](src/hstream_webawesome/_generated.py): one method per
|
|
121
|
+
component with typed keyword arguments and a docstring. A component with a
|
|
122
|
+
`name` attribute and a `change` event is a form control; its value type comes
|
|
123
|
+
from a short table in the generator (or is guessed for a control the table
|
|
124
|
+
doesn't list yet; the script prints those). Hand-written code does the rest:
|
|
125
|
+
|
|
126
|
+
- [`_base.py`](src/hstream_webawesome/_base.py): how elements and each kind
|
|
127
|
+
of control render and parse values, assets, stable ids.
|
|
128
|
+
- [`__init__.py`](src/hstream_webawesome/__init__.py): components that need
|
|
129
|
+
more than the generic treatment (range slider, `menu`).
|
|
130
|
+
|
|
131
|
+
To move to a new Web Awesome release:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
cd hstream-webawesome
|
|
135
|
+
python scripts/generate.py --version 3.16.0 # downloads it, rewrites _generated.py and _wa_version.py
|
|
136
|
+
pytest # the browser test needs network access
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
CI regenerates from the pinned version and fails if `_generated.py` differs.
|
|
140
|
+
|
|
141
|
+
Web Awesome is MIT licensed (Pro components and themes are paid and not
|
|
142
|
+
included).
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# hstream-webawesome
|
|
2
|
+
|
|
3
|
+
Every [Web Awesome](https://webawesome.com) component (78 of them, Web Awesome
|
|
4
|
+
3.15.0) for [HStream](../README.md) apps, as `wa.*`.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install "hstream[webawesome]"
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from hstream import hs, wa
|
|
12
|
+
|
|
13
|
+
name = wa.input("Your name", placeholder="Ada")
|
|
14
|
+
if wa.switch("Shout"):
|
|
15
|
+
name = name.upper()
|
|
16
|
+
|
|
17
|
+
with wa.card():
|
|
18
|
+
wa.callout(f"Hello, {name or 'stranger'}!", variant="brand")
|
|
19
|
+
if wa.button("Save", variant="brand", slot="footer"):
|
|
20
|
+
wa.badge("Saved", variant="success")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`from hstream import wa` finds the package through its `hstream.components`
|
|
24
|
+
entry point (no `import hstream_webawesome` needed). `hs.wa` is the same
|
|
25
|
+
object, so `hs.wa.input(...)` works too, and so does `p.wa.input(...)` on a
|
|
26
|
+
placeholder. Web Awesome's theme and loader come from its CDN, and only on
|
|
27
|
+
pages that use a `wa` component. A fuller demo is in
|
|
28
|
+
[`examples/showcase.py`](examples/showcase.py)
|
|
29
|
+
(`hstream run examples/showcase.py`).
|
|
30
|
+
|
|
31
|
+
## Form controls
|
|
32
|
+
|
|
33
|
+
Form controls work like HStream's built-ins: they return their current value,
|
|
34
|
+
and every change reruns the script. Each is its own element (`<wa-input
|
|
35
|
+
id="container_for_<key>">`, with no wrapping `<div>`), so it can sit directly
|
|
36
|
+
in a `wa-button-group` or take `slot="footer"`.
|
|
37
|
+
|
|
38
|
+
| Component | Returns |
|
|
39
|
+
| :--- | :--- |
|
|
40
|
+
| `wa.input(label, default_value=None)`, `textarea`, `color_picker`, `time_input`, `known_date`, `otp_input` | `str` (`""` when empty) |
|
|
41
|
+
| `wa.number_input(label, default_value=None)`, `rating` | `int`/`float` |
|
|
42
|
+
| `wa.slider(label, default_value=None, min=, max=, step=)` | number; `range=True` returns `(low, high)` |
|
|
43
|
+
| `wa.checkbox(label, default_value=False)`, `switch` | `bool` |
|
|
44
|
+
| `wa.select(label, options, default_value=None)`, `radio_group` | the chosen option (the original object); `select(..., multiple=True)` returns a list |
|
|
45
|
+
| `wa.tag_input(label, default_value=None)` | `list` of tags |
|
|
46
|
+
| `wa.button(label)` | `True` on the run its click triggers, else `False` |
|
|
47
|
+
| `wa.menu(label, items)` | the picked item on the run the pick triggers, else `None` |
|
|
48
|
+
|
|
49
|
+
`options`/`items` are a list of values, `(value, label)` pairs, or a
|
|
50
|
+
`{value: label}` dict. Pass `key="..."` to pin a control's session key, as
|
|
51
|
+
with any HStream component.
|
|
52
|
+
|
|
53
|
+
Every Web Awesome attribute is a keyword argument with its Python name and
|
|
54
|
+
type (`with_clear=True`, `appearance="filled"`, `size="s"`); the docstrings
|
|
55
|
+
come from Web Awesome's own docs. Anything else (`klass="..."`, `style=`,
|
|
56
|
+
`data_dialog="open d1"`) becomes an attribute, `_` turned into `-`.
|
|
57
|
+
|
|
58
|
+
## Everything else
|
|
59
|
+
|
|
60
|
+
The other components render plain elements. Use the result with `with` for
|
|
61
|
+
children, or pass text (or a function that renders) as the first argument:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
with wa.tab_group():
|
|
65
|
+
wa.tab("General", panel="general", slot="nav")
|
|
66
|
+
wa.tab("Advanced", panel="advanced", slot="nav")
|
|
67
|
+
with wa.tab_panel(name="general"):
|
|
68
|
+
hs.markdown("General settings")
|
|
69
|
+
wa.tab_panel("Advanced settings", name="advanced")
|
|
70
|
+
|
|
71
|
+
with wa.details(summary="More"):
|
|
72
|
+
wa.icon(name="star")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
State the browser owns stays put across reruns: a `wa-details` the user
|
|
76
|
+
opened stays open, and so does the tab they picked, even though each
|
|
77
|
+
interaction re-renders the page. (HStream's page applies a changed attribute
|
|
78
|
+
to a custom element only when the *server's* value changed since it last sent
|
|
79
|
+
it; see "Custom elements" in HStream's architecture.md.)
|
|
80
|
+
|
|
81
|
+
Also on `wa`:
|
|
82
|
+
|
|
83
|
+
- `wa.raw.<name>(...)`: any component as a plain element without session
|
|
84
|
+
state, e.g. a button the browser handles alone:
|
|
85
|
+
`wa.raw.button("Open", data_dialog="open settings")` next to
|
|
86
|
+
`with wa.dialog(id="settings", label="Settings"): ...`.
|
|
87
|
+
- `wa.element(tag, content=None, **attrs)`: a tag this package doesn't
|
|
88
|
+
know (a newer Web Awesome release, Pro components).
|
|
89
|
+
- `wa.theme("awesome")`: another free theme (`default`, `awesome`,
|
|
90
|
+
`shoelace`), called at the top of the script.
|
|
91
|
+
|
|
92
|
+
## Over plain HTTP (agents, curl)
|
|
93
|
+
|
|
94
|
+
Controls carry the same contract as HStream's built-ins: an `hx-post` URL and
|
|
95
|
+
`name="new_value"`. To set one, `POST /set_component_value?component_id=<key>`
|
|
96
|
+
with `new_value=...`; buttons carry `&new_value=true` in their URL. Lists
|
|
97
|
+
(`multiple` selects, tag inputs) send each value as `new_value` plus
|
|
98
|
+
`hs_multiple=1`; a range slider sends `new_value=low,high`; a menu sends the
|
|
99
|
+
picked item as `new_value`. The browser computes the last two with htmx
|
|
100
|
+
`js:` values, which an HTTP client doesn't run: it just sends the value.
|
|
101
|
+
|
|
102
|
+
## In the browser build
|
|
103
|
+
|
|
104
|
+
`hstream build app.py` bundles installed component packages into the site, so
|
|
105
|
+
`wa` works under Pyodide too.
|
|
106
|
+
|
|
107
|
+
## How it's made: generated, then tuned
|
|
108
|
+
|
|
109
|
+
[`scripts/generate.py`](scripts/generate.py) reads Web Awesome's
|
|
110
|
+
`custom-elements.json` (from the npm release) and writes
|
|
111
|
+
[`_generated.py`](src/hstream_webawesome/_generated.py): one method per
|
|
112
|
+
component with typed keyword arguments and a docstring. A component with a
|
|
113
|
+
`name` attribute and a `change` event is a form control; its value type comes
|
|
114
|
+
from a short table in the generator (or is guessed for a control the table
|
|
115
|
+
doesn't list yet; the script prints those). Hand-written code does the rest:
|
|
116
|
+
|
|
117
|
+
- [`_base.py`](src/hstream_webawesome/_base.py): how elements and each kind
|
|
118
|
+
of control render and parse values, assets, stable ids.
|
|
119
|
+
- [`__init__.py`](src/hstream_webawesome/__init__.py): components that need
|
|
120
|
+
more than the generic treatment (range slider, `menu`).
|
|
121
|
+
|
|
122
|
+
To move to a new Web Awesome release:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
cd hstream-webawesome
|
|
126
|
+
python scripts/generate.py --version 3.16.0 # downloads it, rewrites _generated.py and _wa_version.py
|
|
127
|
+
pytest # the browser test needs network access
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
CI regenerates from the pinned version and fails if `_generated.py` differs.
|
|
131
|
+
|
|
132
|
+
Web Awesome is MIT licensed (Pro components and themes are paid and not
|
|
133
|
+
included).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Web Awesome components in an HStream app: `hstream run showcase.py`."""
|
|
2
|
+
|
|
3
|
+
from hstream import hs, wa
|
|
4
|
+
|
|
5
|
+
hs.markdown("# Web Awesome in HStream")
|
|
6
|
+
|
|
7
|
+
with wa.card(appearance="filled"):
|
|
8
|
+
name = wa.input("Your name", placeholder="Ada", key="name")
|
|
9
|
+
shout = wa.switch("Shout", key="shout")
|
|
10
|
+
greeting = f"Hello, {name or 'stranger'}!"
|
|
11
|
+
wa.callout(greeting.upper() if shout else greeting, variant="brand")
|
|
12
|
+
|
|
13
|
+
pet = wa.select("Favourite pet", ["Cat", "Dog", "Fish"], "Dog", key="pet")
|
|
14
|
+
size = wa.radio_group(
|
|
15
|
+
"Size", ["S", "M", "L"], "M", key="size", orientation="horizontal"
|
|
16
|
+
)
|
|
17
|
+
volume = wa.slider("Volume", min=0, max=11, key="volume", with_tooltip=True)
|
|
18
|
+
low, high = wa.slider("Price range", range=True, min=0, max=100, key="price")
|
|
19
|
+
stars = wa.rating("Rating", 3, key="stars")
|
|
20
|
+
tags = wa.tag_input("Tags", ["htmx"], key="tags")
|
|
21
|
+
agree = wa.checkbox("I agree", key="agree")
|
|
22
|
+
toppings = wa.select(
|
|
23
|
+
"Toppings", ["Olives", "Peppers", "Onions"], key="toppings", multiple=True
|
|
24
|
+
)
|
|
25
|
+
action = wa.menu("Actions", ["Copy", "Share"], key="menu")
|
|
26
|
+
clicked = wa.button("Click me", variant="brand", key="click")
|
|
27
|
+
|
|
28
|
+
with wa.details(summary="Current values"):
|
|
29
|
+
hs.markdown(
|
|
30
|
+
f"pet={pet} size={size} volume={volume} price={low}-{high} stars={stars} "
|
|
31
|
+
f"tags={tags} agree={agree} toppings={toppings} action={action} "
|
|
32
|
+
f"clicked={clicked}"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
with wa.tab_group():
|
|
36
|
+
wa.tab("General", panel="general", slot="nav")
|
|
37
|
+
wa.tab("Advanced", panel="advanced", slot="nav")
|
|
38
|
+
wa.tab_panel("General settings live here.", name="general")
|
|
39
|
+
wa.tab_panel("Advanced settings live here.", name="advanced")
|
|
40
|
+
|
|
41
|
+
# A dialog the browser opens and closes; the input inside still posts.
|
|
42
|
+
wa.raw.button("Settings", data_dialog="open settings")
|
|
43
|
+
with wa.dialog(id="settings", label="Settings"):
|
|
44
|
+
nickname = wa.input("Nickname", key="nickname")
|
|
45
|
+
hs.markdown(f"nickname={nickname}")
|
|
46
|
+
wa.raw.button("Close", slot="footer", data_dialog="close")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "hstream-webawesome"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Every Web Awesome component for HStream apps, as hs.wa.* (generated from Web Awesome's custom-elements.json)."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = ["hstream>=0.9.0"]
|
|
8
|
+
|
|
9
|
+
[project.urls]
|
|
10
|
+
Repository = "https://github.com/conradbez/hstream"
|
|
11
|
+
|
|
12
|
+
# HStream imports this the first time a script uses hs.wa.
|
|
13
|
+
[project.entry-points."hstream.components"]
|
|
14
|
+
webawesome = "hstream_webawesome"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = ["pytest>=8"]
|
|
18
|
+
|
|
19
|
+
[tool.pytest.ini_options]
|
|
20
|
+
testpaths = ["tests"]
|
|
21
|
+
markers = ["e2e: real browser against the Web Awesome CDN"]
|
|
22
|
+
|
|
23
|
+
[tool.hatch.build.targets.wheel]
|
|
24
|
+
packages = ["src/hstream_webawesome"]
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["hatchling"]
|
|
28
|
+
build-backend = "hatchling.build"
|
|
29
|
+
|
|
30
|
+
[tool.uv.sources]
|
|
31
|
+
hstream = { path = "..", editable = true }
|