fjkit 0.1.0.dev0__py3-none-any.whl

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 (127) hide show
  1. fjkit/__init__.py +49 -0
  2. fjkit/auth/__init__.py +54 -0
  3. fjkit/auth/csrf.py +88 -0
  4. fjkit/auth/errors.py +31 -0
  5. fjkit/auth/plugin.py +496 -0
  6. fjkit/auth/sources.py +24 -0
  7. fjkit/auth/stores.py +141 -0
  8. fjkit/auth/types.py +141 -0
  9. fjkit/cli/__init__.py +67 -0
  10. fjkit/cli/build_css.py +135 -0
  11. fjkit/cli/check.py +193 -0
  12. fjkit/cli/eject.py +562 -0
  13. fjkit/cli/ejected.py +202 -0
  14. fjkit/cli/vocabulary.py +85 -0
  15. fjkit/config.py +130 -0
  16. fjkit/errors.py +156 -0
  17. fjkit/flash.py +189 -0
  18. fjkit/forms.py +145 -0
  19. fjkit/htmx.py +76 -0
  20. fjkit/icons.py +60 -0
  21. fjkit/messages.py +227 -0
  22. fjkit/mounting.py +72 -0
  23. fjkit/plugins.py +223 -0
  24. fjkit/py.typed +0 -0
  25. fjkit/rendering.py +554 -0
  26. fjkit/signing.py +63 -0
  27. fjkit/static/brand/torii-bolt.png +0 -0
  28. fjkit/static/dist/fjkit-luma.css +2 -0
  29. fjkit/static/dist/fjkit-lyra.css +2 -0
  30. fjkit/static/dist/fjkit-maia.css +2 -0
  31. fjkit/static/dist/fjkit-mira.css +2 -0
  32. fjkit/static/dist/fjkit-nova.css +2 -0
  33. fjkit/static/dist/fjkit-rhea.css +2 -0
  34. fjkit/static/dist/fjkit-sera.css +2 -0
  35. fjkit/static/dist/fjkit-vega.css +2 -0
  36. fjkit/static/icons/lucide.json +1 -0
  37. fjkit/static/js/errors.js +117 -0
  38. fjkit/static/js/multiselect.js +126 -0
  39. fjkit/static/js/reveal.js +51 -0
  40. fjkit/static/js/select.js +113 -0
  41. fjkit/static/src/fjkit.css +385 -0
  42. fjkit/static/vendor/basecoat/base/base.css +136 -0
  43. fjkit/static/vendor/basecoat/basecoat-base.css +2 -0
  44. fjkit/static/vendor/basecoat/basecoat-components.css +39 -0
  45. fjkit/static/vendor/basecoat/basecoat-luma.css +2 -0
  46. fjkit/static/vendor/basecoat/basecoat-lyra.css +2 -0
  47. fjkit/static/vendor/basecoat/basecoat-maia.css +2 -0
  48. fjkit/static/vendor/basecoat/basecoat-mira.css +2 -0
  49. fjkit/static/vendor/basecoat/basecoat-nova.css +2 -0
  50. fjkit/static/vendor/basecoat/basecoat-rhea.css +2 -0
  51. fjkit/static/vendor/basecoat/basecoat-sera.css +2 -0
  52. fjkit/static/vendor/basecoat/basecoat-vega.css +2 -0
  53. fjkit/static/vendor/basecoat/basecoat.all.css +1 -0
  54. fjkit/static/vendor/basecoat/basecoat.css +1 -0
  55. fjkit/static/vendor/basecoat/components/accordion.css +27 -0
  56. fjkit/static/vendor/basecoat/components/alert.css +38 -0
  57. fjkit/static/vendor/basecoat/components/avatar.css +47 -0
  58. fjkit/static/vendor/basecoat/components/badge.css +6 -0
  59. fjkit/static/vendor/basecoat/components/breadcrumb.css +30 -0
  60. fjkit/static/vendor/basecoat/components/button-group.css +54 -0
  61. fjkit/static/vendor/basecoat/components/button.css +6 -0
  62. fjkit/static/vendor/basecoat/components/card.css +26 -0
  63. fjkit/static/vendor/basecoat/components/chart.css +56 -0
  64. fjkit/static/vendor/basecoat/components/checkbox.css +12 -0
  65. fjkit/static/vendor/basecoat/components/collapsible.css +21 -0
  66. fjkit/static/vendor/basecoat/components/combobox.css +99 -0
  67. fjkit/static/vendor/basecoat/components/command.css +140 -0
  68. fjkit/static/vendor/basecoat/components/dialog.css +101 -0
  69. fjkit/static/vendor/basecoat/components/drawer.css +89 -0
  70. fjkit/static/vendor/basecoat/components/dropdown-menu.css +56 -0
  71. fjkit/static/vendor/basecoat/components/empty.css +26 -0
  72. fjkit/static/vendor/basecoat/components/field.css +82 -0
  73. fjkit/static/vendor/basecoat/components/form.css +9 -0
  74. fjkit/static/vendor/basecoat/components/input-group.css +74 -0
  75. fjkit/static/vendor/basecoat/components/input.css +32 -0
  76. fjkit/static/vendor/basecoat/components/item.css +50 -0
  77. fjkit/static/vendor/basecoat/components/kbd.css +6 -0
  78. fjkit/static/vendor/basecoat/components/label.css +13 -0
  79. fjkit/static/vendor/basecoat/components/native-select.css +12 -0
  80. fjkit/static/vendor/basecoat/components/popover.css +107 -0
  81. fjkit/static/vendor/basecoat/components/progress.css +14 -0
  82. fjkit/static/vendor/basecoat/components/radio.css +11 -0
  83. fjkit/static/vendor/basecoat/components/range.css +50 -0
  84. fjkit/static/vendor/basecoat/components/scrollbar.css +46 -0
  85. fjkit/static/vendor/basecoat/components/select.css +64 -0
  86. fjkit/static/vendor/basecoat/components/sidebar.css +101 -0
  87. fjkit/static/vendor/basecoat/components/skeleton.css +6 -0
  88. fjkit/static/vendor/basecoat/components/switch.css +8 -0
  89. fjkit/static/vendor/basecoat/components/table.css +34 -0
  90. fjkit/static/vendor/basecoat/components/tabs.css +31 -0
  91. fjkit/static/vendor/basecoat/components/textarea.css +7 -0
  92. fjkit/static/vendor/basecoat/components/toast.css +57 -0
  93. fjkit/static/vendor/basecoat/components/tooltip.css +82 -0
  94. fjkit/static/vendor/basecoat/js/all.min.js +1 -0
  95. fjkit/static/vendor/basecoat/styles/luma.css +1376 -0
  96. fjkit/static/vendor/basecoat/styles/lyra.css +1379 -0
  97. fjkit/static/vendor/basecoat/styles/maia.css +1364 -0
  98. fjkit/static/vendor/basecoat/styles/mira.css +1373 -0
  99. fjkit/static/vendor/basecoat/styles/nova.css +1387 -0
  100. fjkit/static/vendor/basecoat/styles/rhea.css +1381 -0
  101. fjkit/static/vendor/basecoat/styles/sera.css +1397 -0
  102. fjkit/static/vendor/basecoat/styles/vega.css +1386 -0
  103. fjkit/static/vendor/htmx/htmx.min.js +1 -0
  104. fjkit/static/vendor/htmx/json-enc.js +38 -0
  105. fjkit/styles.py +30 -0
  106. fjkit/templates/errors/page.html +92 -0
  107. fjkit/templates/ui/attrs.html +18 -0
  108. fjkit/templates/ui/button.html +64 -0
  109. fjkit/templates/ui/data.html +362 -0
  110. fjkit/templates/ui/disclosure.html +89 -0
  111. fjkit/templates/ui/feedback.html +313 -0
  112. fjkit/templates/ui/form.html +595 -0
  113. fjkit/templates/ui/icon.html +13 -0
  114. fjkit/templates/ui/layout.html +189 -0
  115. fjkit/templates/ui/nav.html +110 -0
  116. fjkit/templates/ui/overlay.html +624 -0
  117. fjkit/templates/ui/shell.html +170 -0
  118. fjkit/templates/ui/sidebar.html +170 -0
  119. fjkit/templates/ui/table.html +427 -0
  120. fjkit/templates/ui/tabs.html +133 -0
  121. fjkit/templating.py +365 -0
  122. fjkit/vendored.py +46 -0
  123. fjkit-0.1.0.dev0.dist-info/METADATA +119 -0
  124. fjkit-0.1.0.dev0.dist-info/RECORD +127 -0
  125. fjkit-0.1.0.dev0.dist-info/WHEEL +4 -0
  126. fjkit-0.1.0.dev0.dist-info/entry_points.txt +2 -0
  127. fjkit-0.1.0.dev0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,624 @@
1
+ {#
2
+ The components that float above the page.
3
+
4
+ Basecoat's own JavaScript drives all four, and it is already vendored and
5
+ mounted: it scans for `.popover`, `.dropdown-menu`, `.select` and `.combobox`
6
+ on load and again on `htmx:afterSwap`, so a swapped-in overlay works with
7
+ nothing extra. No macro below registers a handler.
8
+
9
+ What they share is id wiring: a trigger and its panel find each other through
10
+ four related ids, and one wrong id fails silently — the panel opens but is
11
+ never announced, or never opens at all. Every macro here takes one `id` and
12
+ derives the rest, which is why they are macros and not snippets to copy.
13
+
14
+ `drawer` is the exception: a native `<dialog>` that needs no JS from
15
+ Basecoat, only `showModal()`.
16
+
17
+ `multiselect_scripts()` is the one macro here that adds a file to the page,
18
+ and only a page using `multiple=true` calls it. It fixes the wire format
19
+ rather than the widget — see its own comment.
20
+ #}
21
+ {% from "ui/attrs.html" import attrs %}
22
+ {% from "ui/icon.html" import icon %}
23
+
24
+ {#
25
+ _message(field_id, hint, error) — the paragraph under a scripted control.
26
+
27
+ A second copy of the macro `ui/form.html` calls under every field, written
28
+ out here rather than imported. Jinja refuses to import a name beginning with
29
+ an underscore, and renaming that one to make it importable would publish a
30
+ helper no app template should call. It would also change what `fjkit eject`
31
+ does with it: a private helper is copied into the file you own, while a
32
+ public one is re-exported and keeps moving under you. `_GAP` is written out
33
+ twice for the same reason.
34
+
35
+ It differs from that copy in one way, and the difference is the point: it
36
+ always renders the paragraph, empty and hidden when there is nothing to say.
37
+ `js/errors.js` reuses the `<p>` a control names in `aria-describedby` and
38
+ creates one where it finds none, inserting it directly after the control. For
39
+ the two macros below, the control carrying `name` is a hidden input at the
40
+ end of a wrapper div, so "after" is inside that wrapper and the 422 would
41
+ draw its red text inside the select box. Reserving the paragraph gives it a
42
+ target in the right place.
43
+ #}
44
+ {% macro _message(field_id, hint=none, error=none) -%}
45
+ {%- if error %}<p class="text-destructive text-xs" id="{{ field_id }}-hint">{{ error }}</p>
46
+ {%- elif hint %}<p class="text-muted-foreground text-xs" id="{{ field_id }}-hint">{{ hint }}</p>
47
+ {%- else %}<p class="text-muted-foreground text-xs" id="{{ field_id }}-hint" hidden></p>
48
+ {%- endif -%}
49
+ {%- endmacro %}
50
+
51
+ {#
52
+ Panel widths. A popover has to be told how wide to be — its content is out
53
+ of flow, so it has no column to fill — and upstream does that with a utility
54
+ at the call site. A closed lookup instead, for the usual two reasons: an app
55
+ template may not write `w-72` (A2), and an interpolated width renders while
56
+ missing from the stylesheet.
57
+ #}
58
+ {% set _PANEL_WIDTHS = {
59
+ "auto": "",
60
+ "sm": "w-40",
61
+ "default": "w-56",
62
+ "lg": "w-72",
63
+ "xl": "w-96",
64
+ } %}
65
+
66
+ {#
67
+ popover(id, label, …) — a panel of arbitrary content, anchored to a button.
68
+
69
+ Content arrives through `{% call %}`. The trigger is a `button` macro's worth
70
+ of parameters rather than a second slot, because a popover whose trigger is
71
+ not a button is nearly always a `dropdown_menu` or a `tooltip`.
72
+
73
+ `aria-expanded` starts false and Basecoat's JS flips it; `aria-hidden` on the
74
+ panel works the same way. Both are written here rather than left off: first
75
+ paint is the state before any JS has run, and a trigger with no
76
+ `aria-expanded` is announced as a plain button.
77
+ #}
78
+ {% macro popover(id, label, variant="outline", size="", side="bottom", align="center", width="lg", icon_name=none) -%}
79
+ <div id="{{ id }}" class="popover"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
80
+ <button type="button" id="{{ id }}-trigger" class="btn"
81
+ data-variant="{{ variant }}"{% if size %} data-size="{{ size }}"{% endif %}
82
+ aria-expanded="false" aria-controls="{{ id }}-popover">
83
+ {%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
84
+ {{- label -}}
85
+ </button>
86
+ <div id="{{ id }}-popover" data-popover aria-hidden="true"
87
+ data-side="{{ side }}" data-align="{{ align }}"
88
+ {%- set panel_width = _PANEL_WIDTHS.get(width, "w-72") %}
89
+ {%- if panel_width %} class="{{ panel_width }}"{% endif %}>
90
+ {{- caller() -}}
91
+ </div>
92
+ </div>
93
+ {%- endmacro %}
94
+
95
+ {#
96
+ dropdown_menu(id, label, …) — a menu of commands.
97
+
98
+ The panel holds a `role="menu"` labelled by the trigger, and the items are
99
+ `menu_item` / `menu_group` / `menu_separator` below. Four ids have to line
100
+ up for that: trigger, popover, menu, and the group headings. All derived.
101
+
102
+ A menu is not a `<select>`. If the items set a value rather than run a
103
+ command, `select_menu` or `select_field` is the component — this one leaves
104
+ nothing behind in a form submission.
105
+ #}
106
+ {% macro dropdown_menu(id, label, variant="outline", size="", side="bottom", align="start", width="default", icon_name=none) -%}
107
+ <div id="{{ id }}" class="dropdown-menu"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
108
+ <button type="button" id="{{ id }}-trigger" class="btn"
109
+ data-variant="{{ variant }}"{% if size %} data-size="{{ size }}"{% endif %}
110
+ aria-haspopup="menu" aria-controls="{{ id }}-menu" aria-expanded="false">
111
+ {%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
112
+ {{- label -}}
113
+ </button>
114
+ <div id="{{ id }}-popover" data-popover aria-hidden="true"
115
+ data-side="{{ side }}" data-align="{{ align }}"
116
+ {%- set panel_width = _PANEL_WIDTHS.get(width, "w-56") %}
117
+ {%- if panel_width %} class="{{ panel_width }}"{% endif %}>
118
+ <div role="menu" id="{{ id }}-menu" aria-labelledby="{{ id }}-trigger">
119
+ {{- caller() -}}
120
+ </div>
121
+ </div>
122
+ </div>
123
+ {%- endmacro %}
124
+
125
+ {#
126
+ menu_item(label, …) — one row of a dropdown menu.
127
+
128
+ `checked` switches the role from `menuitem` to `menuitemcheckbox`, because
129
+ an item that reports a checked state under the plain role is a contradiction
130
+ a screen reader has no way to resolve. `radio=true` makes it
131
+ `menuitemradio` — same rule, one choice out of several.
132
+
133
+ `shortcut` renders a `<kbd>` inside the item. It is decoration: printing
134
+ "⌘S" does not bind ⌘S. Bind it yourself, or leave it out.
135
+ #}
136
+ {% macro menu_item(label, shortcut=none, variant="", disabled=false, checked=none, radio=false, href=none) -%}
137
+ {%- set role = "menuitemradio" if radio else ("menuitemcheckbox" if checked is not none else "menuitem") -%}
138
+ <{{ "a" if href else "div" }} role="{{ role }}"
139
+ {%- if href %} href="{{ href }}"{% endif %}
140
+ {%- if variant %} data-variant="{{ variant }}"{% endif %}
141
+ {%- if disabled %} aria-disabled="true"{% endif %}
142
+ {%- if checked is not none %} aria-checked="{{ "true" if checked else "false" }}"{% endif %}
143
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
144
+ {%- if shortcut %}<span>{{ label }}</span><kbd>{{ shortcut }}</kbd>{% else %}{{ label }}{% endif -%}
145
+ </{{ "a" if href else "div" }}>
146
+ {%- endmacro %}
147
+
148
+ {#
149
+ menu_group(heading) — a labelled run of items.
150
+
151
+ The heading is a `role="heading"` referenced by the group's
152
+ `aria-labelledby`, so it is announced as the group's name rather than read
153
+ as a menu item nobody can activate.
154
+ #}
155
+ {% macro menu_group(heading=none, id=none) -%}
156
+ {%- set heading_id = id or ("h-" ~ (heading | replace(" ", "-") | lower) if heading else none) -%}
157
+ <div role="group"{% if heading %} aria-labelledby="{{ heading_id }}"{% endif %}>
158
+ {%- if heading %}<div role="heading" id="{{ heading_id }}">{{ heading }}</div>{% endif %}
159
+ {{- caller() -}}
160
+ </div>
161
+ {%- endmacro %}
162
+
163
+ {% macro menu_separator() -%}
164
+ <hr role="separator">
165
+ {%- endmacro %}
166
+
167
+ {#
168
+ Multiple selection, shared by `select_menu` and `combobox`.
169
+
170
+ Basecoat drives both off one attribute — `aria-multiselectable="true"` on the
171
+ listbox — so `multiple=true` is the whole switch. What it changes here:
172
+
173
+ - `selected` becomes a list. It stays a scalar when `multiple` is false, so
174
+ the two are not interchangeable and the macro does not guess.
175
+ - the hidden input carries a JSON array and is marked `data-fjkit-multi`,
176
+ which is what `multiselect_scripts()` looks for.
177
+ - the panel stops closing on each pick. `data-close-on-select` is Basecoat's
178
+ knob and its absence means "stay open", the right default for a control
179
+ whose point is picking more than one thing. `close_on_select` covers the
180
+ list short enough that one pick is the usual case.
181
+
182
+ The page must load `multiselect_scripts()`. Without it the field posts
183
+ `labels=["bug","ui"]` — one string, JSON-shaped — instead of `labels=bug&
184
+ labels=ui`, and a route declaring `list[str]` answers 422 while the page
185
+ looks correctly filled in. That is the failure this pair of parameters is
186
+ most likely to produce, so it is stated twice: here and on the script macro.
187
+
188
+ An empty selection posts the field zero times, exactly as an untouched
189
+ checkbox group does. Declare `Form([])`, not `Form(...)`, if choosing nothing
190
+ is allowed — otherwise "I cleared it" and "I never opened it" are both a 422.
191
+ #}
192
+ {#
193
+ select_menu(name, options, …) — the scripted listbox.
194
+
195
+ Prefer `select_field`. A native `<select>` is keyboard- and screen-reader-
196
+ correct for free and costs one element; this one costs ~30 and depends on JS
197
+ being present. Use it only when the rows need markup a native option cannot
198
+ hold — an icon, two lines, a swatch — or when you need `multiple`, which a
199
+ native `<select multiple>` renders as a scrolling box nobody has ever found
200
+ by accident.
201
+
202
+ The value reaches the server through the hidden input, which carries `name`;
203
+ the visible trigger is a button and submits nothing. That is why `name` is
204
+ the first parameter and the button has none: a form that posts the button
205
+ posts nothing at all.
206
+
207
+ {{ select_menu("labels", options=label_options,
208
+ selected=task.labels, multiple=true) }}
209
+
210
+ `label` is an `aria-label` on the trigger and draws nothing. Pass
211
+ `visible_label` where the control sits in a form beside `text_field` and has
212
+ to look like one: it renders the `.field` wrapper, a real `<label for>` and
213
+ the message paragraph, so the field lines up with its neighbours and a
214
+ rejected submit has somewhere to put red text. `hint` and `error` work as
215
+ they do on every other field, and any one of the three alone is enough to
216
+ make this a field — a hint with no label is still a field.
217
+
218
+ {{ select_menu("phase", options=phases, multiple=true,
219
+ visible_label="Trial phase", hint="Post-filter") }}
220
+ #}
221
+ {% macro select_menu(name, options=(), selected=none, id=none, placeholder="Select…", width="lg", label=none,
222
+ multiple=false, close_on_select=false, visible_label=none, hint=none, error=none) -%}
223
+ {%- set field_id = id or ("s-" ~ name) -%}
224
+ {#
225
+ Any one of the three turns this into a field: the `.field` wrapper, a
226
+ visible `<label>` and the message paragraph, exactly as `text_field`
227
+ renders them. Without them the macro emits the bare control it always did.
228
+ #}
229
+ {%- set as_field = visible_label is not none or hint is not none or error is not none -%}
230
+ {#
231
+ A list either way, so one expression marks the options. `selectattr("0",
232
+ "in", …)` rather than `equalto`: the same test covers both, and for a
233
+ single select it runs over a one-element list.
234
+ #}
235
+ {%- set values = (selected or []) | list if multiple else ([selected] if selected is not none else []) -%}
236
+ {%- set chosen = options | selectattr("0", "in", values) | map(attribute=1) | list -%}
237
+ {%- if as_field %}<div class="field">
238
+ {%- if visible_label %}<label class="label" for="{{ field_id }}-trigger">{{ visible_label }}</label>{% endif %}
239
+ {%- endif %}
240
+ <div id="{{ field_id }}" class="select" data-placeholder="{{ placeholder }}"
241
+ {%- if multiple and close_on_select %} data-close-on-select="true"{% endif %}
242
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
243
+ <button type="button" id="{{ field_id }}-trigger"
244
+ {%- set trigger_width = _PANEL_WIDTHS.get(width, "w-72") %}
245
+ {%- if trigger_width %} class="{{ trigger_width }}"{% endif %}
246
+ aria-haspopup="listbox" aria-expanded="false" aria-controls="{{ field_id }}-listbox"
247
+ {#
248
+ Only when nothing visible names the control: a visible `<label
249
+ for>` already names it, and an `aria-label` beside one overrides
250
+ the text on screen with the text in the attribute.
251
+ #}
252
+ {%- if label and not visible_label %} aria-label="{{ label }}"{% endif %}
253
+ {%- if as_field %} aria-describedby="{{ field_id }}-hint"{% endif %}
254
+ {%- if error %} aria-invalid="true"{% endif %}>
255
+ {#
256
+ Comma-joined, which is what Basecoat's JS writes the moment it runs.
257
+ Anything else here would be a visible change at first paint.
258
+ #}
259
+ <span class="truncate">{{ chosen | join(", ") if chosen else placeholder }}</span>
260
+ {{ icon("chevron-down", 16, "text-muted-foreground shrink-0 opacity-50") }}
261
+ </button>
262
+ <div id="{{ field_id }}-popover" data-popover aria-hidden="true">
263
+ <div role="listbox" id="{{ field_id }}-listbox" aria-orientation="vertical"
264
+ {%- if multiple %} aria-multiselectable="true"{% endif %}
265
+ aria-labelledby="{{ field_id }}-trigger">
266
+ {%- for value, option_label in options %}
267
+ <div role="option" data-value="{{ value }}"
268
+ {%- if value in values %} aria-selected="true"{% endif %}>{{ option_label }}</div>
269
+ {%- endfor %}
270
+ </div>
271
+ </div>
272
+ {#
273
+ Pre-filled rather than empty: upstream's example ships `value=""` and
274
+ lets its JS write the value on first interaction, so a form submitted
275
+ without touching the select posts nothing — and the round trip that
276
+ re-renders this partial would lose the selection it was given.
277
+
278
+ Single-quoted in the multiple case because `tojson` escapes `<`, `>`, `&`
279
+ and `'` but not `"`, and `["a","b"]` inside a double-quoted attribute is
280
+ a truncated value rather than an error.
281
+ #}
282
+ {#
283
+ `aria-describedby` on the hidden input as well as the trigger, and it is
284
+ not for a screen reader — a hidden input is not exposed to one. It is for
285
+ `js/errors.js`, which finds the control a 422 names by `[name]`, and that
286
+ is this input. Pointed at the reserved paragraph, a rejected `continents`
287
+ draws red text under the field; unpointed, the script builds its own
288
+ paragraph and inserts it here, inside the `.select` box.
289
+ #}
290
+ {%- if multiple %}
291
+ <input type="hidden" name="{{ name }}" data-fjkit-multi value='{{ values | tojson }}'
292
+ {%- if as_field %} aria-describedby="{{ field_id }}-hint"{% endif %}>
293
+ {%- else %}
294
+ <input type="hidden" name="{{ name }}" value="{{ selected if selected is not none else "" }}"
295
+ {%- if as_field %} aria-describedby="{{ field_id }}-hint"{% endif %}>
296
+ {%- endif %}
297
+ </div>
298
+ {%- if as_field %}
299
+ {{ _message(field_id, hint, error) }}
300
+ </div>
301
+ {%- endif %}
302
+ {%- endmacro %}
303
+
304
+ {#
305
+ combobox(name, options, …) — a select you can type into.
306
+
307
+ Same contract as `select_menu` — the hidden input carries the value — with a
308
+ text input in place of the button. `empty` is the message the listbox shows
309
+ when the filter matches nothing. It rides in a `data-empty` attribute because
310
+ Basecoat's JS renders it, and a blank one leaves a filtered-to-nothing list
311
+ looking broken.
312
+
313
+ Filtering is client-side over the options rendered here, until `search` is
314
+ given a URL. Then it is the server's: the input carries `hx-get`, the reply
315
+ replaces the listbox, and the root carries `data-filter="manual"`, which is
316
+ the switch in Basecoat's own JS that stops it filtering a second time. Both
317
+ halves of that are load-bearing. Without the swap there is nothing new to
318
+ show; without `manual`, Basecoat re-filters the server's rows against the
319
+ same box and hides every one that matched on a field the label does not
320
+ print — search by email, list by name, see nothing.
321
+
322
+ The route is handed `?<search_param>=<what was typed>` and returns option
323
+ rows and nothing else:
324
+
325
+ <div role="option" data-value="7">Ada Lovelace</div>
326
+
327
+ which is what `innerHTML` on the listbox expects. It is a fragment, so it
328
+ extends no shell, and the empty result is an empty response — `data-empty`
329
+ already draws the message.
330
+
331
+ The visible input is deliberately not given a `name`, because a named input
332
+ inside a `<form>` is submitted with it, and the box holds a label while the
333
+ hidden input holds the value. So the typed text reaches the route through
334
+ `hx-vals` instead of through the element's own value.
335
+
336
+ `refresh()` is Basecoat's, put on the root when it initialises, and it is
337
+ what re-reads the options after a swap. Nothing calls it for us: htmx fires
338
+ `htmx:afterSwap` on the listbox, and it reaches the root by bubbling, which
339
+ is why the attribute is on the root and not on the input that made the
340
+ request.
341
+
342
+ To act on a pick — with or without `search` — listen on the root:
343
+
344
+ hx_trigger="change target:#c-jump"
345
+
346
+ Basecoat dispatches its own `change` on the root, not on the hidden input,
347
+ carrying `detail.value`. The markup does not say so, and the obvious guess
348
+ (`change from:find input[type=hidden]`) silently never fires. `target:` is
349
+ worth the characters because a native `change` bubbles out of the text box on
350
+ blur as well, and without the filter a pick costs two identical requests.
351
+
352
+ `multiple` works here too, and reads better than on `select_menu`: Basecoat
353
+ wraps the text input in a `.combobox-chips` div and renders one chip per
354
+ pick, so a long selection stays legible instead of becoming a comma-joined
355
+ line that truncates. That JS draws the chips, so at first paint a pre-filled
356
+ multiple combobox shows an empty box. Use `select_menu(multiple=true)` where
357
+ the selection has to be visible with JavaScript off, and read the note on
358
+ `multiselect_scripts()` either way.
359
+
360
+ `visible_label`, `hint` and `error` behave as on `select_menu`: any one of
361
+ them wraps the control in a `.field` and gives it the label and the message
362
+ paragraph an ordinary field has.
363
+ #}
364
+ {% macro combobox(name, options=(), selected=none, id=none, placeholder="Select…", empty="No results found.", label=none,
365
+ multiple=false, close_on_select=false, visible_label=none, hint=none, error=none,
366
+ search=none, search_param="q", search_delay=250) -%}
367
+ {%- set field_id = id or ("c-" ~ name) -%}
368
+ {# Same three parameters as `select_menu`, same rule — see its comment. #}
369
+ {%- set as_field = visible_label is not none or hint is not none or error is not none -%}
370
+ {#
371
+ Same normalisation as `select_menu`, and the same reason: `equalto` against
372
+ a list would never match, so the shape of `selected` follows `multiple`.
373
+ #}
374
+ {%- set values = (selected or []) | list if multiple else ([selected] if selected is not none else []) -%}
375
+ {%- set chosen = options | selectattr("0", "in", values) | map(attribute=1) | list -%}
376
+ {%- if as_field %}<div class="field">
377
+ {%- if visible_label %}<label class="label" for="{{ field_id }}-input">{{ visible_label }}</label>{% endif %}
378
+ {%- endif %}
379
+ <div id="{{ field_id }}" class="combobox"
380
+ {%- if multiple and close_on_select %} data-close-on-select="true"{% endif %}
381
+ {%- if search %} data-filter="manual"
382
+ hx-on::after-swap="this.refresh()"{% endif %}
383
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
384
+ {#
385
+ Empty when `multiple`: this input is the filter box, not the display. The
386
+ selection lives in the chips beside it, and pre-filling it with a label
387
+ would filter the list down to that one option before anybody typed.
388
+ #}
389
+ <input type="text" role="combobox" id="{{ field_id }}-input" placeholder="{{ placeholder }}"
390
+ value="{{ "" if multiple else (chosen | join(", ")) }}"
391
+ {#
392
+ Off, all three: a combobox filters a list the page already holds,
393
+ so the browser's own history dropdown would cover the listbox with
394
+ a competing set of suggestions.
395
+ #}
396
+ autocomplete="off" autocorrect="off" spellcheck="false"
397
+ {#
398
+ `changed` so arrow keys and Tab do not re-ask for what is already
399
+ on screen, and a delay so a typed word is one request rather than
400
+ one per letter.
401
+ #}
402
+ {#
403
+ `hx-push-url="false"` because htmx attributes inherit, and a
404
+ caller who put `hx-push-url` on the root — to make picking an
405
+ option a history entry, which is a reasonable thing to want —
406
+ would otherwise have every keystroke's options request push
407
+ `…/options?q=cac` as well. The back button would then walk the
408
+ letters of a word instead of the searches.
409
+ #}
410
+ {%- if search %} hx-get="{{ search }}"
411
+ hx-trigger="input changed delay:{{ search_delay }}ms"
412
+ hx-target="#{{ field_id }}-listbox" hx-swap="innerHTML"
413
+ hx-push-url="false"
414
+ hx-vals='js:{"{{ search_param }}": this.value}'{% endif %}
415
+ aria-autocomplete="list" aria-expanded="false" aria-controls="{{ field_id }}-listbox"
416
+ {%- if label and not visible_label %} aria-label="{{ label }}"{% endif %}
417
+ {%- if as_field %} aria-describedby="{{ field_id }}-hint"{% endif %}
418
+ {%- if error %} aria-invalid="true"{% endif %}>
419
+ {{ icon("chevron-down", 16, "combobox-trigger-icon") }}
420
+ <div id="{{ field_id }}-popover" data-popover aria-hidden="true">
421
+ <div role="listbox" id="{{ field_id }}-listbox" aria-orientation="vertical" data-empty="{{ empty }}"
422
+ {%- if multiple %} aria-multiselectable="true"{% endif %}>
423
+ {%- for value, option_label in options %}
424
+ <div role="option" data-value="{{ value }}"
425
+ {%- if value in values %} aria-selected="true"{% endif %}>{{ option_label }}</div>
426
+ {%- endfor %}
427
+ </div>
428
+ </div>
429
+ {# The hidden input carries the 422, same as in `select_menu`. #}
430
+ {%- if multiple %}
431
+ <input type="hidden" name="{{ name }}" data-fjkit-multi value='{{ values | tojson }}'
432
+ {%- if as_field %} aria-describedby="{{ field_id }}-hint"{% endif %}>
433
+ {%- else %}
434
+ <input type="hidden" name="{{ name }}" value="{{ selected if selected is not none else "" }}"
435
+ {%- if as_field %} aria-describedby="{{ field_id }}-hint"{% endif %}>
436
+ {%- endif %}
437
+ </div>
438
+ {%- if as_field %}
439
+ {{ _message(field_id, hint, error) }}
440
+ </div>
441
+ {%- endif %}
442
+ {%- endmacro %}
443
+
444
+ {#
445
+ multiselect_scripts() — what a page loads to be allowed `multiple=true`.
446
+
447
+ {% block scripts %}{{ multiselect_scripts() }}{% endblock %}
448
+
449
+ Per page, never from the shell, for the reason `form_scripts()` is: CHARTER
450
+ §7 budgets what a page downloads by default, and the answer has to stay
451
+ "htmx and Basecoat".
452
+
453
+ It buys one line of wire format. Basecoat serialises a multiple selection as
454
+ `JSON.stringify(values)` in a single hidden input, so without this script the
455
+ route is handed one string:
456
+
457
+ labels=%5B%22bug%22%2C%22ui%22%5D -> labels: str == '["bug","ui"]'
458
+
459
+ With it, the selection is re-emitted the way HTML has always carried a
460
+ repeated field, and the FastAPI signature is the ordinary one:
461
+
462
+ labels=bug&labels=ui -> labels: list[str] = Form([])
463
+
464
+ It covers both halves of `form()`: htmx submits are rewritten in
465
+ `htmx:configRequest`, browser submits in a capture-phase `submit` handler,
466
+ and one form is only ever handled by one of the two.
467
+
468
+ `encoding="json"` composes, in one direction: this runs first and json-enc
469
+ collects the repeats into an array. One caveat — json-enc collects repeats,
470
+ so a one-item selection arrives as `"bug"`, not `["bug"]`. Give the model a
471
+ `mode="before"` validator that wraps a bare string in a list; `TaskUpdate` in
472
+ `examples/fjkit-demo` is the worked example.
473
+
474
+ A page that forgets this macro fails the way every missing-script failure in
475
+ this kit does: no console error, no visual difference, and a 422 naming a
476
+ field that looks correctly filled in.
477
+ #}
478
+ {% macro multiselect_scripts() -%}
479
+ <script defer src="{{ fjkit_static("js/multiselect.js") }}"></script>
480
+ {%- endmacro %}
481
+
482
+ {#
483
+ drawer(id, …) — a panel that slides in from an edge.
484
+
485
+ A native `<dialog>` opened with `showModal()`, not a popover: a drawer is
486
+ modal, and `showModal()` gives it the top layer, the backdrop, the focus trap
487
+ and Esc-to-close without a line of script. `dialog` in this kit is the
488
+ non-modal one, which is why the two do not share a macro.
489
+
490
+ Opening one needs `showModal()`, so the trigger carries the only inline
491
+ handler in the kit besides the theme toggle. `drawer_trigger` writes it.
492
+ #}
493
+ {% macro drawer(id, title=none, description=none, side="bottom", footer=none, dismissible=true) -%}
494
+ <dialog id="{{ id }}" class="drawer" data-side="{{ side }}"
495
+ {%- if title %} aria-labelledby="{{ id }}-title"{% endif %}
496
+ {%- if description %} aria-describedby="{{ id }}-description"{% endif %}
497
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
498
+ {#
499
+ Basecoat styles `.drawer > article`, so the wrapper is load-bearing the
500
+ same way the dialog's inner div is: the <dialog> itself is the backdrop
501
+ owner and the positioning context, the <article> is the panel that
502
+ slides.
503
+ #}
504
+ <article>
505
+ {%- if title or description %}
506
+ <header>
507
+ {% if title %}<h2 id="{{ id }}-title">{{ title }}</h2>{% endif %}
508
+ {% if description %}<p id="{{ id }}-description">{{ description }}</p>{% endif %}
509
+ </header>
510
+ {%- endif %}
511
+ <section>{{ caller() }}</section>
512
+ {%- if footer or dismissible %}
513
+ <footer>
514
+ {%- if footer %}{{ footer }}{% endif %}
515
+ {%- if dismissible %}
516
+ {#
517
+ `closest('dialog').close()` rather than the id: the button is
518
+ inside the dialog it closes, so the relationship is structural and
519
+ cannot be broken by a rename.
520
+ #}
521
+ <button type="button" class="btn" data-variant="outline"
522
+ onclick="this.closest('dialog').close()">Close</button>
523
+ {%- endif %}
524
+ </footer>
525
+ {%- endif %}
526
+ </article>
527
+ </dialog>
528
+ {%- endmacro %}
529
+
530
+ {#
531
+ drawer_trigger(label, target) — the button that opens one.
532
+
533
+ Separate from `drawer` because the two live in different places on the page:
534
+ the drawer is usually at the end of the document, the button wherever it
535
+ belongs. Passing the id twice is the price of that — `drawer` takes it as
536
+ `id`, this macro as `target`.
537
+ #}
538
+ {% macro drawer_trigger(label, target, variant="outline", size="", icon_name=none) -%}
539
+ <button type="button" class="btn" data-variant="{{ variant }}"
540
+ {%- if size %} data-size="{{ size }}"{% endif %}
541
+ aria-haspopup="dialog" aria-controls="{{ target }}"
542
+ onclick="document.getElementById('{{ target }}').showModal()"
543
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
544
+ {%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
545
+ {{- label -}}
546
+ </button>
547
+ {%- endmacro %}
548
+
549
+ {#
550
+ command(id, …) — a filterable command list, and its ⌘K dialog form.
551
+
552
+ `dialog=true` swaps the root for a `<dialog class="command-dialog">`,
553
+ upstream's own variant rather than a second component. Everything else — the
554
+ header input, the `role="menu"`, the ids that tie them together — is
555
+ identical, so this is one macro with a flag rather than two that would drift.
556
+
557
+ Two things it deliberately does not do:
558
+
559
+ * It does not bind ⌘K. A keystroke is application policy — which key, on
560
+ which pages, and whether it beats the browser's own — and a UI kit that
561
+ claims a global shortcut fights the app. Open it with `showModal()` from
562
+ your own listener.
563
+ * It does not search the server. The filter is Basecoat's, over the items
564
+ rendered here. For server-side search this is the wrong component: use an
565
+ `input` with `hx-get` and swap the listbox from the response.
566
+ #}
567
+ {% macro command(id, placeholder="Type a command or search…", empty="No results found.", label="Command menu", dialog=false, bordered=true) -%}
568
+ <{{ "dialog" if dialog else "div" }} id="{{ id }}"
569
+ class="{{ "command-dialog" if dialog else ("command border" if bordered else "command") }}"
570
+ aria-label="{{ label }}"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
571
+ <header>
572
+ {{ icon("search", 16) }}
573
+ {#
574
+ `aria-expanded="true"` is not a mistake: the list below is always
575
+ showing whenever this is on screen, so the combobox is permanently
576
+ expanded. It is the dialog that opens and closes, not the listbox.
577
+ #}
578
+ <input type="text" id="{{ id }}-input" placeholder="{{ placeholder }}"
579
+ autocomplete="off" autocorrect="off" spellcheck="false"
580
+ role="combobox" aria-autocomplete="list" aria-expanded="true"
581
+ aria-controls="{{ id }}-menu">
582
+ </header>
583
+ <div role="menu" id="{{ id }}-menu" aria-orientation="vertical" data-empty="{{ empty }}">
584
+ {{- caller() -}}
585
+ </div>
586
+ </{{ "dialog" if dialog else "div" }}>
587
+ {%- endmacro %}
588
+
589
+ {#
590
+ command_item(label, …) — one row of a command list.
591
+
592
+ `data-filter` is what Basecoat matches the typed text against, and it
593
+ defaults to the label. `keywords` extends that with words that are not on
594
+ screen — "date event schedule" for a Calendar row — which is the difference
595
+ between a palette that finds things and one that only confirms what you
596
+ already typed.
597
+ #}
598
+ {% macro command_item(label, keywords=none, icon_name=none, shortcut=none, disabled=false, filter=none, href=none) -%}
599
+ <{{ "a" if href else "div" }} role="menuitem"
600
+ data-filter="{{ filter if filter is not none else label }}"
601
+ {%- if keywords %} data-keywords="{{ keywords }}"{% endif %}
602
+ {%- if href %} href="{{ href }}"{% endif %}
603
+ {%- if disabled %} aria-disabled="true"{% endif %}
604
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
605
+ {%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
606
+ <span>{{ label }}</span>
607
+ {%- if shortcut %}<kbd>{{ shortcut }}</kbd>{% endif -%}
608
+ </{{ "a" if href else "div" }}>
609
+ {%- endmacro %}
610
+
611
+ {#
612
+ command_group(heading) — a labelled run of command items.
613
+
614
+ A `<span role="heading">`, not the `<div>` `menu_group` uses: that is what
615
+ upstream's command markup does, and its CSS selects on it. Otherwise the
616
+ same shape.
617
+ #}
618
+ {% macro command_group(heading=none, id=none) -%}
619
+ {%- set heading_id = id or ("ch-" ~ (heading | replace(" ", "-") | lower) if heading else none) -%}
620
+ <div role="group"{% if heading %} aria-labelledby="{{ heading_id }}"{% endif %}>
621
+ {%- if heading %}<span role="heading" id="{{ heading_id }}">{{ heading }}</span>{% endif %}
622
+ {{- caller() -}}
623
+ </div>
624
+ {%- endmacro %}