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,427 @@
1
+ {#
2
+ The data table: structure, sortable headers, batch selection and the
3
+ pagination that goes under it.
4
+
5
+ {% call table(
6
+ columns=[{"label": "Task", "sort": "asc", "sort_url": "/tasks?o=-title"},
7
+ {"label": "Owner"},
8
+ {"width": "min"}],
9
+ rows=tasks,
10
+ target="#board",
11
+ empty_title="Nothing here",
12
+ empty_description="No task matches this filter.") %}
13
+ {% for task in tasks %}{{ task_row(request, task) }}{% endfor %}
14
+ {% endcall %}
15
+ {{ pagination(page, pages, url_for(request, "tasks_page"), target="#board") }}
16
+
17
+ Passing `rows` gives the macro the empty case, so no caller repeats the
18
+ "if there are rows … else …" branch. Pass `rows=none` to always render the
19
+ body yourself.
20
+
21
+ Rows are a macro call in the caller's loop, never `{% include %}`: include
22
+ costs a template lookup plus a fresh context object per iteration, and the
23
+ gap widens linearly with row count.
24
+ #}
25
+ {% from "ui/attrs.html" import attrs %}
26
+ {% from "ui/button.html" import button %}
27
+ {% from "ui/data.html" import empty_state %}
28
+ {% from "ui/icon.html" import icon %}
29
+
30
+ {% set _ALIGN = {"start": "text-left", "center": "text-center", "end": "text-right"} %}
31
+ {% set _WIDTH = {"min": "w-px", "narrow": "w-16", "auto": ""} %}
32
+
33
+ {#
34
+ `aria-sort` is what a screen reader reads out of the header; the glyph is
35
+ what everyone else reads. Both are keyed off one value, so they cannot
36
+ disagree — an arrow pointing up over `aria-sort="descending"` is the usual
37
+ way this component goes wrong.
38
+
39
+ A third state is in neither table: sortable, but not the column currently
40
+ sorted. It falls through to `aria-sort="none"` and the two-headed chevron.
41
+ Without that chevron a sortable column looks exactly like a fixed one.
42
+ #}
43
+ {% set _ARIA_SORT = {"asc": "ascending", "desc": "descending"} %}
44
+ {% set _SORT_ICON = {"asc": "arrow-up", "desc": "arrow-down"} %}
45
+
46
+ {#
47
+ table(columns, rows, …) — the <table> and its header row.
48
+
49
+ A column is a dict, and every key is optional:
50
+
51
+ label header text
52
+ align start | center | end
53
+ width min | narrow | auto
54
+ sort asc | desc | none this column's current state
55
+ sort_url where clicking the header goes; its presence is what makes
56
+ the column sortable
57
+ select true, for the batch-selection column
58
+
59
+ `sort_url` is a URL the caller built, not a column key the macro turns into
60
+ one. The router already owns the query string — it is the thing that knows
61
+ which parameter carries the order, what the other filters are, and that
62
+ clicking the sorted column reverses it rather than re-applying it. A macro
63
+ that guessed would be wrong on the first page with two filters on it.
64
+
65
+ `target` decides how the header links travel, and decides it once for the
66
+ whole table:
67
+
68
+ table(columns, target="#board") -> href + hx-get + hx-target + hx-swap
69
+ table(columns) -> href
70
+
71
+ Both render an `<a href>`, so sorting works with JavaScript off and a sorted
72
+ view is a URL somebody can send to a colleague. `target` adds the swap on
73
+ top, and `hx-push-url` keeps the address bar honest about which one is shown
74
+ — without it the browser's back button leaves the page and the URL describes
75
+ a sort order nobody is looking at.
76
+ #}
77
+ {% macro table(columns, rows=none, empty_title="Nothing here", empty_description=none, empty_icon="list",
78
+ target=none, swap="outerHTML", push_url=true,
79
+ select_name="selected", select_label="Select all rows") -%}
80
+ {% if rows is none or rows %}
81
+ <div class="table-container">
82
+ <table class="table"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
83
+ <thead>
84
+ <tr>
85
+ {% for column in columns %}
86
+ {{- _header(column, target, swap, push_url, select_name, select_label) }}
87
+ {% endfor %}
88
+ </tr>
89
+ </thead>
90
+ <tbody>{{ caller() }}</tbody>
91
+ </table>
92
+ </div>
93
+ {% else %}
94
+ {{ empty_state(empty_title, empty_description, empty_icon) }}
95
+ {% endif %}
96
+ {%- endmacro %}
97
+
98
+ {#
99
+ One `<th>`. Private, and not because the file is tidier that way: a header
100
+ cell is only ever correct in the company of the rest of its row, and a caller
101
+ who could reach this one would be able to build a table whose header count
102
+ and column count disagree.
103
+ #}
104
+ {% macro _header(column, target, swap, push_url, select_name, select_label) -%}
105
+ {%- if column.get("select") -%}
106
+ {#
107
+ `role="checkbox"` is the implicit role of the element already. It is
108
+ written out because Basecoat's table rules select on it —
109
+ `[&:has([role=checkbox])]:pe-0` — to take the trailing padding off a
110
+ column that holds nothing but a tick box.
111
+ #}
112
+ <th class="w-px">
113
+ <input class="input" type="checkbox" role="checkbox"
114
+ data-fjkit-select-all="{{ select_name }}" aria-label="{{ select_label }}">
115
+ </th>
116
+ {%- else -%}
117
+ {%- set sort = column.get("sort") -%}
118
+ {%- set sort_url = column.get("sort_url") -%}
119
+ <th class="{{ _WIDTH.get(column.get("width"), "") }} {{ _ALIGN.get(column.get("align"), "") }}"
120
+ {%- if sort_url %} aria-sort="{{ _ARIA_SORT.get(sort, "none") }}"{% endif %}
121
+ {#
122
+ An unlabelled cell is invisible to a screen reader reading out the
123
+ column of a focused button, so the actions column gets a name. Only
124
+ an unlabelled one: `aria-label` replaces the text rather than adding
125
+ to it, so a narrow column that does have a heading — a row number,
126
+ say — would be announced as "Actions" instead of as itself.
127
+ #}
128
+ {%- if column.get("width") == "min" and not column.get("label") %} aria-label="Actions"{% endif %}>
129
+ {%- if sort_url -%}
130
+ {#
131
+ `-mx-2` cancels the cell's own padding, so a sortable header's text
132
+ starts on the same pixel as a fixed one's. Without it a table reads
133
+ as two ragged columns of headings.
134
+ #}
135
+ <a class="-mx-2 inline-flex items-center gap-1 rounded-md px-2 py-1
136
+ hover:text-foreground focus-visible:outline-ring focus-visible:-outline-offset-2 focus-visible:outline-2"
137
+ href="{{ sort_url }}"
138
+ {%- if target %} hx-get="{{ sort_url }}" hx-target="{{ target }}" hx-swap="{{ swap }}"
139
+ {%- if push_url %} hx-push-url="true"{% endif %}{% endif %}>
140
+ {{- column.get("label", "") }}
141
+ {#
142
+ aria-hidden: `aria-sort` on the cell has already said this, and a
143
+ screen reader that reads the glyph too says "ascending" twice.
144
+ #}
145
+ <span aria-hidden="true"{% if not sort %} class="text-muted-foreground"{% endif %}>
146
+ {{- icon(_SORT_ICON.get(sort, "chevrons-up-down"), 14) -}}
147
+ </span>
148
+ </a>
149
+ {%- else -%}
150
+ {{ column.get("label", "") }}
151
+ {%- endif -%}
152
+ </th>
153
+ {%- endif -%}
154
+ {%- endmacro %}
155
+
156
+ {#
157
+ cell(value, tone, numeric, align) — one <td>.
158
+
159
+ Exists so a row macro never writes `class="text-muted-foreground"`. `tone` is
160
+ a closed lookup, and no colour can be passed through it.
161
+ #}
162
+ {% set _TONES = {
163
+ "strong": "font-medium",
164
+ "muted": "text-muted-foreground",
165
+ "success": "text-success",
166
+ "warning": "text-warning",
167
+ "destructive": "text-destructive",
168
+ } %}
169
+
170
+ {% macro cell(value=none, tone=none, numeric=false, align=none) -%}
171
+ <td class="{{ _TONES.get(tone, "") }}{{ " tabular-nums" if numeric }}{{ " " ~ _ALIGN.get(align, "") if align }}"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
172
+ {%- if value is not none %}{{ value }}{% else %}{{ caller() }}{% endif -%}
173
+ </td>
174
+ {%- endmacro %}
175
+
176
+ {#
177
+ select_cell(value, name, checked, label) — the row half of the batch-selection
178
+ column, matching a `{"select": true}` header.
179
+
180
+ <tr{% if task.id in picked %} data-state="selected"{% endif %}>
181
+ {{ select_cell(task.id, label="Select " ~ task.title) }}
182
+ …
183
+ </tr>
184
+
185
+ It is an ordinary checkbox with an ordinary `name`, so the selection reaches
186
+ the server the way a checkbox group always has — `selected=3&selected=7` —
187
+ and a route reads it as `selected: list[int] = Query([])`. Nothing here
188
+ invents a wire format.
189
+
190
+ Delivering it is the caller's job: either the table sits inside a `form()`,
191
+ or a bulk-action button carries `hx_include="[data-fjkit-select]"`. One
192
+ attribute either way.
193
+
194
+ Always pass `label`. Without one, a column of tick boxes announces itself as
195
+ "checkbox, checkbox, checkbox", and the row is the only thing that tells them
196
+ apart. It falls back to the value, which is an id rather than a label.
197
+
198
+ `data-state="selected"` on the `<tr>` tints a picked row; Basecoat's table
199
+ rules carry it. `js/select.js` maintains it after the first click. Write it
200
+ yourself on a row the server renders as already picked.
201
+ #}
202
+ {% macro select_cell(value, name="selected", checked=false, label=none) -%}
203
+ <td class="w-px">
204
+ <input class="input" type="checkbox" role="checkbox"
205
+ name="{{ name }}" value="{{ value }}" data-fjkit-select="{{ name }}"
206
+ {%- if checked %} checked{% endif %}
207
+ aria-label="{{ label if label is not none else "Select " ~ value }}"
208
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
209
+ </td>
210
+ {%- endmacro %}
211
+
212
+ {#
213
+ select_scripts() — the script behind `{"select": true}` and `select_cell`.
214
+
215
+ Per page, never from the shell, for the reason `form_scripts()` and
216
+ `reveal_scripts()` are: CHARTER §7 budgets what a page downloads by default,
217
+ and the answer has to stay "htmx and Basecoat". A page with a batch-select
218
+ table is one page.
219
+
220
+ The row boxes work without it — they are checkboxes, and a form posts them.
221
+ It adds the header box that ticks and clears the column, the dash for a
222
+ partial selection, and the tint on picked rows.
223
+
224
+ A page that forgets it gets a header checkbox that ticks only itself, which
225
+ reads as a bug in the kit rather than a missing script.
226
+ #}
227
+ {% macro select_scripts() -%}
228
+ <script defer src="{{ fjkit_static("js/select.js") }}"></script>
229
+ {%- endmacro %}
230
+
231
+ {#
232
+ select_count(name, label, zero) — the live "3 selected" readout for a toolbar.
233
+
234
+ `js/select.js` writes the number, keyed by the same `name` the checkboxes
235
+ carry, so a page with two independent selections gets two independent counts.
236
+
237
+ Both strings travel in the markup, so the script contains no English. `{n}`
238
+ in `label` is where the number goes. `zero` stands there before anything is
239
+ picked; pass `none` and the readout hides itself instead, so a control that
240
+ only makes sense with a selection needs no second mechanism to hide it.
241
+
242
+ It needs `select_scripts()`. Without it the readout stays frozen on `zero`.
243
+ #}
244
+ {% macro select_count(name="selected", label="{n} selected", zero="None selected") -%}
245
+ <span class="text-muted-foreground text-sm"
246
+ data-fjkit-select-count="{{ name }}" data-fjkit-select-label="{{ label }}"
247
+ {%- if zero is not none %} data-fjkit-select-zero="{{ zero }}"{% else %} hidden{% endif %}
248
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ zero if zero is not none }}</span>
249
+ {%- endmacro %}
250
+
251
+ {#
252
+ page_size(url, per_page, options, …) — the "Rows per page" control that sits
253
+ opposite `pagination`.
254
+
255
+ {{ page_size(url_for(request, "records_page"), per_page,
256
+ options=[12, 25, 50, 100],
257
+ keep={"o": sort}, target="#records") }}
258
+
259
+ A `<form method="get">`, because a `<select>` cannot act on its own change.
260
+ Both paths send the same request:
261
+
262
+ target="#records" -> hx-get, fired by the select's change event
263
+ no target -> an ordinary GET with a submit button
264
+
265
+ Both produce `GET {url}?o=-updated&per_page=25`: htmx serialises a form the
266
+ way a browser does. `hx-trigger="change"` fires the first one — a form's
267
+ default trigger is `submit`, and nothing submits it on that path.
268
+
269
+ The submit button sits inside `<noscript>` when there is a target. It is
270
+ absent while htmx runs and is the only working control when htmx does not, so
271
+ this macro ships no JavaScript.
272
+
273
+ `url` must carry no query string. A native GET submit replaces the whole
274
+ query with the form's fields, so anything in `action=` survives the htmx path
275
+ and vanishes on the other. Pass what must survive in `keep`; both paths
276
+ serialise it as hidden fields.
277
+
278
+ Never put the page number in `keep`. Page 12 of 12 at twelve rows is page 3
279
+ of 3 at fifty.
280
+
281
+ `per_page` is the size the server used, not the one the query string asked
282
+ for. The router has already clamped it to `options`.
283
+ #}
284
+ {% macro page_size(url, per_page, options=(10, 25, 50, 100), param="per_page", keep=none,
285
+ target=none, swap="outerHTML", push_url=true,
286
+ label="Rows per page", apply_label="Apply", id=none) -%}
287
+ {%- set field_id = id or ("f-" ~ param) -%}
288
+ <form class="flex items-center gap-2" method="get" action="{{ url }}"
289
+ {%- if target %} hx-get="{{ url }}" hx-target="{{ target }}" hx-swap="{{ swap }}" hx-trigger="change"
290
+ {%- if push_url %} hx-push-url="true"{% endif %}{% endif %}
291
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
292
+ {%- for name, value in (keep or {}).items() if value is not none %}
293
+ <input type="hidden" name="{{ name }}" value="{{ value }}">
294
+ {%- endfor %}
295
+ <label class="label" for="{{ field_id }}">{{ label }}</label>
296
+ <select class="select" data-size="sm" id="{{ field_id }}" name="{{ param }}">
297
+ {%- for option in options %}
298
+ <option value="{{ option }}"{% if option == per_page %} selected{% endif %}>{{ option }}</option>
299
+ {%- endfor %}
300
+ </select>
301
+ {%- if target %}
302
+ <noscript>{{ button(apply_label, variant="outline", size="sm", type="submit") }}</noscript>
303
+ {%- else %}
304
+ {{ button(apply_label, variant="outline", size="sm", type="submit") }}
305
+ {%- endif %}
306
+ </form>
307
+ {%- endmacro %}
308
+
309
+ {#
310
+ row_actions() — the trailing cell of per-row buttons.
311
+
312
+ Right-aligned and tight, because a column of actions that drifts left of the
313
+ table edge reads as a data column.
314
+ #}
315
+ {% macro row_actions() -%}
316
+ <td>
317
+ <div class="flex justify-end gap-1">{{ caller() }}</div>
318
+ </td>
319
+ {%- endmacro %}
320
+
321
+ {#
322
+ pagination(page, pages, url, …) — the page strip that goes under a table.
323
+
324
+ {{ pagination(page, pages, url_for(request, "records_page"),
325
+ total=total, per_page=per_page, target="#records") }}
326
+
327
+ `url` is the address of the list *without* a page parameter; the macro
328
+ appends one. Same division of labour as `sort_url` above: the router owns the
329
+ query string, because it is the only thing that knows which filters are on.
330
+ Passing a URL that already carries `page=` produces a link with two of them,
331
+ and which one wins is the framework's business, not this macro's.
332
+
333
+ `target` works exactly as it does on `table()`: every link is a real `href`,
334
+ and a target adds `hx-get` on top. A paginated list has to survive JavaScript
335
+ being off, because "page 4 of the results" is a thing people bookmark and
336
+ send to each other.
337
+
338
+ It renders **nothing** when there is one page or fewer. A strip reading "1"
339
+ with both arrows greyed out is chrome that says nothing, and the alternative
340
+ is every caller writing the same `{% if pages > 1 %}` around it — the same
341
+ reason `table()` owns its empty state.
342
+
343
+ `window` is how many pages sit either side of the current one. First and last
344
+ are always shown, and the jump between them and the window is an ellipsis, so
345
+ the strip is a fixed width whether there are nine pages or nine thousand.
346
+
347
+ `total` and `per_page` are optional and travel together: given both, the
348
+ strip grows the "1–25 of 312" line that tells a person whether paging further
349
+ is worth it. Given neither, the buttons sit alone at the trailing edge.
350
+ #}
351
+ {% macro pagination(page, pages, url, param="page", total=none, per_page=none,
352
+ target=none, swap="outerHTML", push_url=true, window=1, label="Pagination") -%}
353
+ {%- if pages > 1 -%}
354
+ {#
355
+ Clamped rather than trusted. `page` arrives from a query string, and a
356
+ strip built around page 0 or page 900 of 9 renders links to nowhere with
357
+ no error anywhere.
358
+ #}
359
+ {%- set current = [[page, 1] | max, pages] | min -%}
360
+ {%- set lo = [2, current - window] | max -%}
361
+ {%- set hi = [pages - 1, current + window] | min -%}
362
+ {%- set summary = total is not none and per_page is not none -%}
363
+ <nav class="flex flex-wrap items-center gap-3 {{ "justify-between" if summary else "justify-end" }}"
364
+ aria-label="{{ label }}"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
365
+ {%- if summary %}
366
+ <p class="text-muted-foreground text-sm">
367
+ {{- (current - 1) * per_page + 1 }}–{{ [current * per_page, total] | min }} of {{ total -}}
368
+ </p>
369
+ {%- endif %}
370
+ <div class="flex flex-wrap items-center gap-1">
371
+ {{- _step(current - 1, current > 1, "Previous", "chevron-left", "prev", url, param, target, swap, push_url) }}
372
+ {{- _page(1, current, url, param, target, swap, push_url) }}
373
+ {%- if lo > 2 %}{{ _gap() }}{% endif %}
374
+ {%- for n in range(lo, hi + 1) %}{{ _page(n, current, url, param, target, swap, push_url) }}{% endfor %}
375
+ {%- if hi < pages - 1 %}{{ _gap() }}{% endif %}
376
+ {{- _page(pages, current, url, param, target, swap, push_url) }}
377
+ {{- _step(current + 1, current < pages, "Next", "chevron-right", "next", url, param, target, swap, push_url) }}
378
+ </div>
379
+ </nav>
380
+ {%- endif -%}
381
+ {%- endmacro %}
382
+
383
+ {#
384
+ The three pieces a strip is made of. Private for the same reason `_header` is:
385
+ a page link is only meaningful inside the strip that counted the pages.
386
+ #}
387
+ {#
388
+ The htmx half of every link in the strip is `none` when there is no target,
389
+ and `attrs()` drops a `none`, so one call site covers both kinds of link
390
+ without a branch around the markup.
391
+ #}
392
+ {% macro _page(n, current, url, param, target, swap, push_url) -%}
393
+ {%- set href = url ~ ("&" if "?" in url else "?") ~ param ~ "=" ~ n -%}
394
+ {{ button(n, variant="secondary" if n == current else "ghost", size="icon-sm",
395
+ href=href,
396
+ aria_current="page" if n == current else none,
397
+ hx_get=href if target else none,
398
+ hx_target=target,
399
+ hx_swap=swap if target else none,
400
+ hx_push_url="true" if target and push_url else none) }}
401
+ {%- endmacro %}
402
+
403
+ {#
404
+ A step that has nowhere to go renders as a disabled `<button>`, not a dead
405
+ `<a>`. `href` is what makes an anchor focusable and clickable, and an anchor
406
+ without one is skipped by the keyboard entirely — so the arrow at the end of
407
+ the list would vanish from tab order instead of announcing that it is
408
+ unavailable.
409
+ #}
410
+ {% macro _step(n, enabled, label, icon_name, rel, url, param, target, swap, push_url) -%}
411
+ {%- if enabled -%}
412
+ {%- set href = url ~ ("&" if "?" in url else "?") ~ param ~ "=" ~ n -%}
413
+ {{ button(label, variant="ghost", size="sm", icon_name=icon_name,
414
+ icon_end=(rel == "next"), href=href, rel=rel,
415
+ hx_get=href if target else none,
416
+ hx_target=target,
417
+ hx_swap=swap if target else none,
418
+ hx_push_url="true" if target and push_url else none) }}
419
+ {%- else -%}
420
+ {{ button(label, variant="ghost", size="sm", icon_name=icon_name,
421
+ icon_end=(rel == "next"), disabled=true) }}
422
+ {%- endif -%}
423
+ {%- endmacro %}
424
+
425
+ {% macro _gap() -%}
426
+ <span class="text-muted-foreground px-1 text-sm" aria-hidden="true">…</span>
427
+ {%- endmacro %}
@@ -0,0 +1,133 @@
1
+ {#
2
+ Tabs — roadmap 0.7, pulled forward.
3
+
4
+ Basecoat already ships `.tabs` and its behaviour: its vendored script owns
5
+ the selection, the `hidden` on the other panels, and the
6
+ ArrowLeft/Right/Home/End keys. What `components/tabs.css` does not ship is a
7
+ skin — that file is flex direction and `outline-none`, nothing else. The
8
+ style pack does ship one, a pill strip; fjkit draws underline tabs, so
9
+ `fjkit.css` turns the pack's geometry off before painting its own. Read that
10
+ block before changing anything here: the two skins overlapping already put a
11
+ phantom scrollbar on the card's edge once.
12
+
13
+ This macro carries the aria wiring the script needs, and nothing else.
14
+
15
+ The contract Basecoat's JS reads:
16
+
17
+ .tabs > [role="tablist"] > [role="tab"][aria-controls="<panel id>"]
18
+ .tabs > [role="tabpanel"][id="<panel id>"]
19
+
20
+ Getting that pairing right by hand is what a component should remove.
21
+
22
+ {% call tabs([{"id": "main", "label": "main.py"},
23
+ {"id": "router", "label": "router.py"}], label="File") %}
24
+ {% call tab_panel("main") %}…{% endcall %}
25
+ {% call tab_panel("router") %}…{% endcall %}
26
+ {% endcall %}
27
+
28
+ `items` is a list of dicts, the shape `table` takes its columns in, and extra
29
+ keys are ignored — so a caller already holding a list of files passes it
30
+ straight through instead of building a parallel one. It is the light half, so
31
+ it is a parameter while the panels are the body: the same trade as `card`'s
32
+ `actions`, because a two-slot call block renders its body once per slot and
33
+ the body here is every panel's content.
34
+
35
+ Ids are page-unique, like any id. A page with two tab groups over the same
36
+ subject prefixes them ("file-main", "diff-main"), as it would for any other
37
+ pair of elements.
38
+ #}
39
+ {% from "ui/attrs.html" import attrs %}
40
+
41
+ {#
42
+ tabs(items, label, selected, orientation)
43
+
44
+ orientation: horizontal | vertical — the value Basecoat's key handler reads to
45
+ decide whether Left/Right or Up/Down moves between tabs, so it is a closed
46
+ lookup rather than interpolated: `aria-orientation="sideways"` would leave the
47
+ arrow keys dead with no other symptom.
48
+
49
+ `selected` names the item that starts open; the first one by default. The
50
+ server knows which tab the request was for, so this is a parameter and not
51
+ something a script decides after paint.
52
+ #}
53
+ {% macro tabs(items, label="Tabs", selected=none, orientation="horizontal") -%}
54
+ {%- set body = caller() -%}
55
+ {%- set orientations = {"horizontal": "horizontal", "vertical": "vertical"} -%}
56
+ {%- set active = selected if selected is not none else (items[0].id if items else none) -%}
57
+ <div class="tabs"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
58
+ <nav role="tablist" aria-label="{{ label }}"
59
+ aria-orientation="{{ orientations.get(orientation, "horizontal") }}">
60
+ {% for item in items %}
61
+ <button type="button" role="tab" aria-controls="{{ item.id }}"
62
+ aria-selected="{{ "true" if item.id == active else "false" }}">{{ item.label }}</button>
63
+ {% endfor %}
64
+ </nav>
65
+ {{- body -}}
66
+ </div>
67
+ {%- endmacro %}
68
+
69
+ {#
70
+ tab_panel(id, lazy, on, include) — the body for one tab. The id is the one
71
+ the tab's `aria-controls` named; Basecoat hides and reveals it from there.
72
+
73
+ No `hidden` is rendered here: Basecoat's script sets it on init, and a panel
74
+ that arrived pre-hidden would be invisible to a reader with JavaScript off.
75
+ This way the panels stack and every one is legible.
76
+
77
+ `lazy` is a URL, and it is all a panel needs to fetch its own body when it is
78
+ shown rather than when the page loads. The block's body then stands in until
79
+ the answer arrives — usually a `skeleton`. Without `lazy` the panel is inert
80
+ markup, and `on` and `include` are read only alongside it because neither
81
+ means anything on its own.
82
+
83
+ Three decisions are baked in here so that no app template has to remember
84
+ them. Each is a way this goes silently wrong when written by hand:
85
+
86
+ * `intersect`, never `revealed`. htmx tests `revealed` with
87
+ `getBoundingClientRect`, and an element hidden by `display:none` — which is
88
+ what the `hidden` Basecoat sets means — reports an all-zero rect. `top <
89
+ innerHeight` and `bottom >= 0` both hold for that rect, so every panel on
90
+ the page counts as revealed and fetches at load. There is no error and no
91
+ empty panel to notice; the page is simply not lazy. `intersect` uses an
92
+ `IntersectionObserver`, which reports a `display:none` element as not
93
+ intersecting and fires when the tab is chosen.
94
+ * A filter on every broadcast. The events in `on` are raised on `<body>`, and
95
+ a hidden panel hears them as well as the open one does. Four tabs would
96
+ mean four requests per broadcast, three of them for markup nobody is
97
+ looking at. `[!this.hidden]` is the whole fix, and it is this short only
98
+ because the trigger sits on the panel — the element carrying the `hidden` —
99
+ rather than on something inside it.
100
+ * `innerHTML` onto the panel. An element carrying `intersect` has to survive
101
+ its own reply. A panel replaced by markup that asked for `intersect` again
102
+ would be processed while on screen, fire immediately, and loop.
103
+
104
+ `include` is a selector for what the panel has to send: the id it is about,
105
+ the query it is filtered by. A selector rather than a value carried in the
106
+ event, because the two paths into this panel disagree on what an event is —
107
+ `intersect` has none. A panel hidden when the pick happened never heard
108
+ `task-selected` and has only the page to read, so the id has to be on the
109
+ page and the route that changes it has to say so **after** its own swap:
110
+ `@render(..., hx_trigger_after_swap=...)`. See `fjkit.rendering.render`.
111
+
112
+ A lazy panel refetches every time it is shown, not only the first time. That
113
+ is the trade for not tracking which panels went stale while hidden; tracking
114
+ that would need a listener on `<body>` — a script, for a page that otherwise
115
+ has none.
116
+
117
+ {% call tab_panel("tab-detail", lazy=url_for(request, "search_detail"),
118
+ on=["task-selected"], include="[name=task_id]") %}
119
+ {{ skeleton(lines=4, label="Loading the detail") }}
120
+ {% endcall %}
121
+ #}
122
+ {% macro tab_panel(id, lazy=none, on=none, include=none) -%}
123
+ {%- set trigger %}intersect
124
+ {%- for event in on or [] %}, {{ event }}[!this.hidden] from:body{% endfor %}
125
+ {%- endset -%}
126
+ <div id="{{ id }}" role="tabpanel"
127
+ {%- if lazy %} hx-get="{{ lazy }}" hx-trigger="{{ trigger }}"
128
+ {%- if include %} hx-include="{{ include }}"{% endif %} hx-target="this" hx-swap="innerHTML"
129
+ {%- endif %}
130
+ {#- `attrs` last, so a caller's own attribute sits beside these. A caller
131
+ that needs a different swap is not describing this component. -#}
132
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ caller() }}</div>
133
+ {%- endmacro %}