@sdxc/ui 2026.11.1 → 2026.11.3

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 (190) hide show
  1. package/README.md +1 -1
  2. package/dist/app/app-shell-toggle.d.ts +31 -0
  3. package/dist/app/app-shell-toggle.js +43 -0
  4. package/dist/app/app-shell.d.ts +131 -0
  5. package/dist/app/app-shell.js +542 -0
  6. package/dist/app/auto-refresh.d.ts +104 -0
  7. package/dist/app/auto-refresh.js +126 -0
  8. package/dist/app/behaviors/refresh-schedule.d.ts +53 -0
  9. package/dist/app/behaviors/refresh-schedule.js +95 -0
  10. package/dist/app/behaviors/shortcuts.d.ts +175 -0
  11. package/dist/app/behaviors/shortcuts.js +401 -0
  12. package/dist/app/behaviors/toaster.d.ts +31 -2
  13. package/dist/app/behaviors/toaster.js +62 -5
  14. package/dist/app/chart.d.ts +62 -8
  15. package/dist/app/chart.js +207 -9
  16. package/dist/app/command-palette.d.ts +132 -0
  17. package/dist/app/command-palette.js +181 -0
  18. package/dist/app/danger-zone.d.ts +66 -0
  19. package/dist/app/danger-zone.js +66 -0
  20. package/dist/app/detail-sheet.d.ts +119 -0
  21. package/dist/app/detail-sheet.js +173 -0
  22. package/dist/app/drop-zone.d.ts +2 -1
  23. package/dist/app/drop-zone.js +6 -3
  24. package/dist/app/editor-layout.d.ts +69 -0
  25. package/dist/app/editor-layout.js +143 -0
  26. package/dist/app/empty.d.ts +56 -19
  27. package/dist/app/empty.js +129 -22
  28. package/dist/app/filter-bar.d.ts +169 -0
  29. package/dist/app/filter-bar.js +346 -0
  30. package/dist/app/index.d.ts +51 -0
  31. package/dist/app/index.js +51 -0
  32. package/dist/app/keyboard-help.d.ts +66 -0
  33. package/dist/app/keyboard-help.js +56 -0
  34. package/dist/app/mixins/app-shell-controls.d.ts +46 -0
  35. package/dist/app/mixins/app-shell-controls.js +131 -0
  36. package/dist/app/mixins/auto-refresh.d.ts +29 -0
  37. package/dist/app/mixins/auto-refresh.js +66 -0
  38. package/dist/app/mixins/command-palette.d.ts +56 -0
  39. package/dist/app/mixins/command-palette.js +297 -0
  40. package/dist/app/mixins/copy-permalink.d.ts +26 -0
  41. package/dist/app/mixins/copy-permalink.js +54 -0
  42. package/dist/app/mixins/detail-sheet-keys.d.ts +28 -0
  43. package/dist/app/mixins/detail-sheet-keys.js +88 -0
  44. package/dist/app/mixins/escape-link.d.ts +17 -0
  45. package/dist/app/mixins/escape-link.js +35 -0
  46. package/dist/app/mixins/keyboard-help.d.ts +38 -0
  47. package/dist/app/mixins/keyboard-help.js +51 -0
  48. package/dist/app/mixins/optimistic-toggle-sync.d.ts +80 -0
  49. package/dist/app/mixins/optimistic-toggle-sync.js +153 -0
  50. package/dist/app/mixins/range-picker-keys.d.ts +18 -0
  51. package/dist/app/mixins/range-picker-keys.js +94 -0
  52. package/dist/app/mixins/row-navigation.d.ts +85 -0
  53. package/dist/app/mixins/row-navigation.js +208 -0
  54. package/dist/app/mixins/save-bar-sync.d.ts +27 -0
  55. package/dist/app/mixins/save-bar-sync.js +106 -0
  56. package/dist/app/mixins/save-shortcut.d.ts +47 -0
  57. package/dist/app/mixins/save-shortcut.js +101 -0
  58. package/dist/app/mixins/save-status-sync.d.ts +77 -0
  59. package/dist/app/mixins/save-status-sync.js +159 -0
  60. package/dist/app/mixins/selection-bar-sync.d.ts +32 -0
  61. package/dist/app/mixins/selection-bar-sync.js +151 -0
  62. package/dist/app/mixins/split-view.d.ts +66 -0
  63. package/dist/app/mixins/split-view.js +319 -0
  64. package/dist/app/mixins/status-strip-keys.d.ts +17 -0
  65. package/dist/app/mixins/status-strip-keys.js +79 -0
  66. package/dist/app/mixins/submit-on-change.d.ts +16 -0
  67. package/dist/app/mixins/submit-on-change.js +28 -0
  68. package/dist/app/mixins/table-selection.d.ts +39 -0
  69. package/dist/app/mixins/table-selection.js +272 -0
  70. package/dist/app/mixins/toast-queue.d.ts +36 -0
  71. package/dist/app/mixins/toast-queue.js +77 -0
  72. package/dist/app/mixins/toast-stack.d.ts +20 -0
  73. package/dist/app/mixins/toast-stack.js +55 -0
  74. package/dist/app/optimistic-toggle.d.ts +48 -0
  75. package/dist/app/optimistic-toggle.js +38 -0
  76. package/dist/app/page-header.d.ts +71 -0
  77. package/dist/app/page-header.js +249 -0
  78. package/dist/app/range-picker.d.ts +102 -0
  79. package/dist/app/range-picker.js +118 -0
  80. package/dist/app/save-bar.d.ts +54 -0
  81. package/dist/app/save-bar.js +64 -0
  82. package/dist/app/save-status.d.ts +50 -0
  83. package/dist/app/save-status.js +54 -0
  84. package/dist/app/selection-bar.d.ts +101 -0
  85. package/dist/app/selection-bar.js +157 -0
  86. package/dist/app/settings-layout.d.ts +70 -0
  87. package/dist/app/settings-layout.js +112 -0
  88. package/dist/app/settings-section.d.ts +140 -0
  89. package/dist/app/settings-section.js +182 -0
  90. package/dist/app/skeleton.d.ts +47 -4
  91. package/dist/app/skeleton.js +149 -2
  92. package/dist/app/sparkline.d.ts +61 -0
  93. package/dist/app/sparkline.js +145 -0
  94. package/dist/app/split-view.d.ts +154 -0
  95. package/dist/app/split-view.js +272 -0
  96. package/dist/app/stat-card.d.ts +109 -0
  97. package/dist/app/stat-card.js +379 -0
  98. package/dist/app/status-strip.d.ts +70 -0
  99. package/dist/app/status-strip.js +155 -0
  100. package/dist/app/styles/action-row.d.ts +41 -0
  101. package/dist/app/styles/action-row.js +59 -0
  102. package/dist/app/styles/stat-delta.d.ts +29 -0
  103. package/dist/app/styles/stat-delta.js +36 -0
  104. package/dist/app/styles/toast-stack.d.ts +21 -0
  105. package/dist/app/styles/toast-stack.js +54 -0
  106. package/dist/app/table.d.ts +199 -24
  107. package/dist/app/table.js +640 -36
  108. package/dist/app/toast.d.ts +105 -5
  109. package/dist/app/toast.js +89 -17
  110. package/dist/app/toasts.d.ts +49 -0
  111. package/dist/app/toasts.js +103 -0
  112. package/dist/app/utils/app-shell-cookie.d.ts +21 -0
  113. package/dist/app/utils/app-shell-cookie.js +33 -0
  114. package/dist/app/utils/chart-marker-indices.d.ts +9 -5
  115. package/dist/app/utils/chart-marker-indices.js +9 -8
  116. package/dist/app/utils/chart-path.d.ts +14 -10
  117. package/dist/app/utils/chart-path.js +46 -18
  118. package/dist/app/utils/edited-time.d.ts +19 -0
  119. package/dist/app/utils/edited-time.js +35 -0
  120. package/dist/app/utils/key-target.d.ts +23 -0
  121. package/dist/app/utils/key-target.js +48 -0
  122. package/dist/app/utils/search-params.d.ts +69 -0
  123. package/dist/app/utils/search-params.js +132 -0
  124. package/dist/app/utils/shortcut-groups.d.ts +21 -0
  125. package/dist/app/utils/shortcut-groups.js +53 -0
  126. package/dist/app/utils/split-view-layout.d.ts +48 -0
  127. package/dist/app/utils/split-view-layout.js +71 -0
  128. package/dist/app/view-options.d.ts +99 -0
  129. package/dist/app/view-options.js +182 -0
  130. package/dist/components/banner.d.ts +61 -0
  131. package/dist/components/banner.js +101 -0
  132. package/dist/components/confirm.d.ts +54 -5
  133. package/dist/components/confirm.js +44 -5
  134. package/dist/components/group.d.ts +14 -0
  135. package/dist/components/group.js +66 -11
  136. package/dist/components/index.d.ts +5 -0
  137. package/dist/components/index.js +5 -0
  138. package/dist/components/input.js +9 -3
  139. package/dist/components/link-button.js +8 -2
  140. package/dist/components/property-list.d.ts +76 -0
  141. package/dist/components/property-list.js +175 -0
  142. package/dist/components/relative-time.d.ts +72 -0
  143. package/dist/components/relative-time.js +45 -0
  144. package/dist/components/status-dot.d.ts +62 -0
  145. package/dist/components/status-dot.js +99 -0
  146. package/dist/components/text-field.d.ts +17 -2
  147. package/dist/components/text-field.js +13 -4
  148. package/dist/components/timeline.d.ts +67 -0
  149. package/dist/components/timeline.js +159 -0
  150. package/dist/components/typeset.d.ts +2 -1
  151. package/dist/components/typeset.js +4 -1
  152. package/dist/docs/code-tabs-sync.d.ts +1 -1
  153. package/dist/docs/code-tabs-sync.js +2 -2
  154. package/dist/docs/copy-button.d.ts +1 -1
  155. package/dist/docs/copy-button.js +2 -2
  156. package/dist/docs/docs-feedback.d.ts +12 -0
  157. package/dist/docs/docs-feedback.js +4 -2
  158. package/dist/docs/docs-hub.js +4 -4
  159. package/dist/docs/docs-layout.d.ts +1 -1
  160. package/dist/docs/docs-layout.js +1 -1
  161. package/dist/docs/docs-nav-tools.d.ts +1 -1
  162. package/dist/docs/docs-nav-tools.js +2 -2
  163. package/dist/docs/docs-nav.d.ts +6 -2
  164. package/dist/docs/docs-nav.js +2 -2
  165. package/dist/docs/docs-pager.d.ts +5 -1
  166. package/dist/docs/docs-pager.js +7 -6
  167. package/dist/docs/mixins/docs-nav-tools.d.ts +2 -2
  168. package/dist/docs/mixins/docs-nav-tools.js +32 -5
  169. package/dist/docs/next-steps.js +3 -2
  170. package/dist/docs/page-actions.d.ts +1 -1
  171. package/dist/docs/page-actions.js +2 -2
  172. package/dist/docs/table-of-contents.d.ts +1 -1
  173. package/dist/docs/table-of-contents.js +2 -2
  174. package/dist/mixins/confirm-phrase.d.ts +19 -0
  175. package/dist/mixins/confirm-phrase.js +56 -0
  176. package/dist/mixins/index.d.ts +2 -0
  177. package/dist/mixins/index.js +2 -0
  178. package/dist/mixins/viewer-time.d.ts +20 -0
  179. package/dist/mixins/viewer-time.js +40 -0
  180. package/dist/styles/index.d.ts +1 -0
  181. package/dist/styles/index.js +1 -0
  182. package/dist/styles/segmented-control.d.ts +49 -0
  183. package/dist/styles/segmented-control.js +71 -0
  184. package/dist/test/table.d.ts +65 -0
  185. package/dist/test/table.js +108 -0
  186. package/dist/utils/index.d.ts +1 -0
  187. package/dist/utils/index.js +1 -0
  188. package/dist/utils/relative-time.d.ts +44 -0
  189. package/dist/utils/relative-time.js +69 -0
  190. package/package.json +6 -6
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Why JS: a form cannot tell when its values differ from how it loaded, so script shows
3
+ * the save bar while it does, binds ⌘S/Ctrl+S to submitting it, and guards leaving the page.
4
+ * No-JS baseline: the bar stays hidden and the form submits through its own Save button.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { createMixin } from "remix/component";
10
+ import { bindSaveShortcut } from "./save-shortcut.js";
11
+ /**
12
+ * Applied to the bar (`[data-slot="save-bar"]`): unhides it while the form's values differ
13
+ * from their baseline, which a submission moves to the submitted values, and ⌘S saves them
14
+ * unless the form's own primary save answers it. `[role="status"]` announces `message`.
15
+ *
16
+ * @example <div hidden mix={[saveBarSync({ message: "Unsaved changes" })]}>…</div>
17
+ */
18
+ export const saveBarSync = createMixin((handle) => {
19
+ let options;
20
+ let controller;
21
+ handle.addEventListener("insert", (event) => {
22
+ controller?.abort();
23
+ controller = new AbortController();
24
+ if (options)
25
+ connect(event.node, options, controller.signal);
26
+ });
27
+ handle.addEventListener("remove", () => {
28
+ controller?.abort();
29
+ controller = undefined;
30
+ });
31
+ return (next) => {
32
+ options = next;
33
+ };
34
+ });
35
+ /**
36
+ * Reads a form's current values as one string, so two moments compare in one step. A
37
+ * file contributes its name and size, which is what changes when another is picked.
38
+ *
39
+ * @param form The form to read.
40
+ * @returns The form's entries, serialized in document order.
41
+ */
42
+ function snapshot(form) {
43
+ let entries = [];
44
+ for (let [name, value] of new FormData(form)) {
45
+ entries.push([name, typeof value === "string" ? value : `${value.name}:${value.size}`]);
46
+ }
47
+ return JSON.stringify(entries);
48
+ }
49
+ /**
50
+ * Asks before the page unloads; attached only while the form has unsaved changes.
51
+ *
52
+ * @param event The unload the browser is about to perform.
53
+ */
54
+ function guard(event) {
55
+ event.preventDefault();
56
+ }
57
+ /**
58
+ * Connects `bar` to its form until `signal` aborts.
59
+ *
60
+ * @param bar The save bar.
61
+ * @param options The form and the message to announce.
62
+ * @param signal Ends every listener once the bar leaves the document.
63
+ */
64
+ function connect(bar, options, signal) {
65
+ let doc = bar.ownerDocument;
66
+ let view = doc.defaultView;
67
+ let form = options.form
68
+ ? doc.getElementById(options.form)
69
+ : bar.closest("form");
70
+ if (!form)
71
+ return;
72
+ let status = bar.querySelector('[role="status"]');
73
+ let baseline = snapshot(form);
74
+ let dirty = false;
75
+ /** Shows or hides the bar and the leave guard to match `next`. */
76
+ let show = (next) => {
77
+ if (next === dirty)
78
+ return;
79
+ dirty = next;
80
+ bar.hidden = !next;
81
+ if (status)
82
+ status.textContent = next ? options.message : "";
83
+ if (next)
84
+ view?.addEventListener("beforeunload", guard);
85
+ else
86
+ view?.removeEventListener("beforeunload", guard);
87
+ };
88
+ /** Compares the form with its baseline. */
89
+ let compare = () => show(snapshot(form) !== baseline);
90
+ form.addEventListener("input", compare, { signal });
91
+ form.addEventListener("change", compare, { signal });
92
+ form.addEventListener("reset", () => setTimeout(compare), { signal });
93
+ form.addEventListener("submit", () => {
94
+ baseline = snapshot(form);
95
+ show(false);
96
+ }, { signal });
97
+ bindSaveShortcut({
98
+ form,
99
+ fallback: true,
100
+ save: () => {
101
+ if (dirty)
102
+ form.requestSubmit();
103
+ },
104
+ }, signal);
105
+ signal.addEventListener("abort", () => view?.removeEventListener("beforeunload", guard));
106
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Why JS: a page has no key binding for submitting a form, so script binds ⌘S/Ctrl+S to the
3
+ * form a person is editing, in place of the browser's own save-page dialog.
4
+ * No-JS baseline: every form keeps its Save button, and ⌘S saves the page as the browser does.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { MixinFactory } from "remix/component";
10
+ /** The keys that save, as the shortcut registry spells them. */
11
+ export declare const SAVE_SHORTCUT = "mod+s";
12
+ /** Types for {@link saveShortcut} and {@link bindSaveShortcut}. */
13
+ export declare namespace SaveShortcuts {
14
+ /** Configuration for {@link saveShortcut}. */
15
+ interface Options {
16
+ /** The `id` of the form ⌘S submits; omit to submit the form the host sits in. */
17
+ form?: string;
18
+ }
19
+ /** One form's answer to ⌘S. */
20
+ interface Binding {
21
+ form: HTMLFormElement;
22
+ /** Saves the form once ⌘S chose it. */
23
+ save(): void;
24
+ /**
25
+ * Yields to every other binding of the same form, so a save bar steps aside for the
26
+ * form's own primary save and one keystroke submits once.
27
+ */
28
+ fallback?: boolean;
29
+ }
30
+ }
31
+ /**
32
+ * Applied to any element in or beside a form: ⌘S (Ctrl+S elsewhere) submits that form through
33
+ * `requestSubmit`, while typing included. With several bound forms on a page, the one holding
34
+ * focus saves; with focus outside them all, the only bound form saves.
35
+ *
36
+ * @example <span hidden mix={[saveShortcut({ form: "post-form" })]} />
37
+ */
38
+ export declare const saveShortcut: MixinFactory<HTMLElement, [options?: SaveShortcuts.Options]>;
39
+ /**
40
+ * Binds ⌘S to `binding.form` until `signal` aborts, through the page's shortcut registry. Every
41
+ * binding on the page agrees on one form per keystroke, so exactly one saves; a keystroke that
42
+ * chooses none is still held back from the browser's save-page dialog.
43
+ *
44
+ * @param binding The form and how it saves.
45
+ * @param signal Removes the binding.
46
+ */
47
+ export declare function bindSaveShortcut(binding: SaveShortcuts.Binding, signal: AbortSignal): void;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Why JS: a page has no key binding for submitting a form, so script binds ⌘S/Ctrl+S to the
3
+ * form a person is editing, in place of the browser's own save-page dialog.
4
+ * No-JS baseline: every form keeps its Save button, and ⌘S saves the page as the browser does.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { createMixin } from "remix/component";
10
+ import { shortcutRegistry } from "../behaviors/shortcuts.js";
11
+ /** The keys that save, as the shortcut registry spells them. */
12
+ export const SAVE_SHORTCUT = "mod+s";
13
+ /** Every form bound to ⌘S on each document, for choosing the one a keystroke saves. */
14
+ const BINDINGS = new WeakMap();
15
+ /**
16
+ * Applied to any element in or beside a form: ⌘S (Ctrl+S elsewhere) submits that form through
17
+ * `requestSubmit`, while typing included. With several bound forms on a page, the one holding
18
+ * focus saves; with focus outside them all, the only bound form saves.
19
+ *
20
+ * @example <span hidden mix={[saveShortcut({ form: "post-form" })]} />
21
+ */
22
+ export const saveShortcut = createMixin((handle) => {
23
+ let options;
24
+ let controller;
25
+ handle.addEventListener("insert", (event) => {
26
+ controller?.abort();
27
+ controller = new AbortController();
28
+ let node = event.node;
29
+ let form = options?.form
30
+ ? node.ownerDocument.getElementById(options.form)
31
+ : node.closest("form");
32
+ if (!(form instanceof HTMLFormElement))
33
+ return;
34
+ bindSaveShortcut({ form, save: () => form.requestSubmit() }, controller.signal);
35
+ });
36
+ handle.addEventListener("remove", () => {
37
+ controller?.abort();
38
+ controller = undefined;
39
+ });
40
+ return (next) => {
41
+ options = next;
42
+ };
43
+ });
44
+ /**
45
+ * Binds ⌘S to `binding.form` until `signal` aborts, through the page's shortcut registry. Every
46
+ * binding on the page agrees on one form per keystroke, so exactly one saves; a keystroke that
47
+ * chooses none is still held back from the browser's save-page dialog.
48
+ *
49
+ * @param binding The form and how it saves.
50
+ * @param signal Removes the binding.
51
+ */
52
+ export function bindSaveShortcut(binding, signal) {
53
+ let doc = binding.form.ownerDocument;
54
+ let bindings = BINDINGS.get(doc) ?? new Set();
55
+ BINDINGS.set(doc, bindings);
56
+ bindings.add(binding);
57
+ signal.addEventListener("abort", () => bindings.delete(binding), { once: true });
58
+ shortcutRegistry(doc).register({
59
+ keys: SAVE_SHORTCUT,
60
+ whileTyping: true,
61
+ scope: binding.form,
62
+ signal,
63
+ run: () => {
64
+ let chosen = chosenForm(doc, bindings);
65
+ if (chosen === null)
66
+ return true;
67
+ if (chosen !== binding.form)
68
+ return false;
69
+ if (binding.fallback && hasPrimary(bindings, binding.form))
70
+ return false;
71
+ binding.save();
72
+ return true;
73
+ },
74
+ });
75
+ }
76
+ /**
77
+ * The form a ⌘S saves: the bound form holding focus, or with focus in no form, the only bound
78
+ * form on the page. Focus in a form nothing bound chooses none.
79
+ */
80
+ function chosenForm(doc, bindings) {
81
+ let forms = [
82
+ ...new Set([...bindings].map((binding) => binding.form).filter((form) => form.isConnected)),
83
+ ];
84
+ let focused = formOf(doc.activeElement);
85
+ if (focused !== null)
86
+ return forms.includes(focused) ? focused : null;
87
+ return forms.length === 1 ? forms[0] : null;
88
+ }
89
+ /** The form `element` submits with: its `form` owner, or the form it sits in. */
90
+ function formOf(element) {
91
+ if (element === null)
92
+ return null;
93
+ let owner = element.form;
94
+ if (owner instanceof HTMLFormElement)
95
+ return owner;
96
+ return element.closest("form");
97
+ }
98
+ /** Whether `form` has a binding that saves it outright, which a fallback binding yields to. */
99
+ function hasPrimary(bindings, form) {
100
+ return [...bindings].some((binding) => binding.form === form && !binding.fallback);
101
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Why JS: an autosave's progress and the age of the last edit change after the page has
3
+ * rendered, so script moves a save status through Saving…, Saved and the edit time.
4
+ * No-JS baseline: the status shows the state the server rendered, and Retry submits its form.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { MixinFactory } from "remix/component";
10
+ /** Event an app dispatches on a save status, through {@link setSaveStatus}, to report a save. */
11
+ declare const SAVE_STATUS_EVENT: "ui:save-status";
12
+ /** Event a save status dispatches, bubbling, when Retry is pressed. */
13
+ declare const SAVE_STATUS_RETRY_EVENT: "ui:save-status-retry";
14
+ declare global {
15
+ interface HTMLElementEventMap {
16
+ [SAVE_STATUS_EVENT]: SaveStatusEvent;
17
+ [SAVE_STATUS_RETRY_EVENT]: SaveStatusRetryEvent;
18
+ }
19
+ }
20
+ /** Types for {@link saveStatusSync}. */
21
+ export declare namespace SaveStatusSync {
22
+ /** Where a save stands; `"idle"` shows the last edit time, or nothing without one. */
23
+ type State = "idle" | "saving" | "saved" | "failed";
24
+ /** Configuration for {@link saveStatusSync}. */
25
+ interface Options {
26
+ /** The state the server rendered. */
27
+ state: State;
28
+ /** When the content was last edited, as an ISO string. */
29
+ editedAt?: string;
30
+ labels: {
31
+ saving: string;
32
+ saved: string;
33
+ failed: string;
34
+ edited: string;
35
+ };
36
+ locale?: string;
37
+ holdMs: number;
38
+ savedMs: number;
39
+ decayMs: number;
40
+ }
41
+ }
42
+ /** Reports a save to a save status: dispatched on it by {@link setSaveStatus}. */
43
+ export declare class SaveStatusEvent extends Event {
44
+ readonly state: SaveStatusSync.State;
45
+ /** When the content was saved; the moment the event arrives when omitted. */
46
+ readonly at: Date | undefined;
47
+ /**
48
+ * @param state Where the save stands.
49
+ * @param at When the content was saved.
50
+ */
51
+ constructor(state: SaveStatusSync.State, at?: Date);
52
+ }
53
+ /** Dispatched, bubbling, from a save status when its Retry is pressed, for an autosave to try again. */
54
+ export declare class SaveStatusRetryEvent extends Event {
55
+ constructor();
56
+ }
57
+ /**
58
+ * Reports a save to a save status, which is how an autosave drives it.
59
+ *
60
+ * @param target The status element or its `id`.
61
+ * @param state Where the save stands.
62
+ * @param at When the content was saved.
63
+ * @example
64
+ * setSaveStatus("post-status", "saving");
65
+ * let response = await fetch(url, { method: "POST", body });
66
+ * setSaveStatus("post-status", response.ok ? "saved" : "failed");
67
+ */
68
+ export declare function setSaveStatus(target: Element | string, state: SaveStatusSync.State, at?: Date): void;
69
+ /**
70
+ * Applied to a save status (`[data-slot="save-status"]`): "Saving…" holds for `holdMs`
71
+ * however fast the save, "Saved" shows for `savedMs`, then the edit time shows and keeps
72
+ * its age current. It writes `data-state` and the texts of its `save-status-*` parts.
73
+ *
74
+ * @example <span data-slot="save-status" mix={[saveStatusSync({ state: "idle", labels, holdMs: 1000, savedMs: 3000, decayMs: 86_400_000 })]}>…</span>
75
+ */
76
+ export declare const saveStatusSync: MixinFactory<HTMLElement, [options: SaveStatusSync.Options]>;
77
+ export {};
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Why JS: an autosave's progress and the age of the last edit change after the page has
3
+ * rendered, so script moves a save status through Saving…, Saved and the edit time.
4
+ * No-JS baseline: the status shows the state the server rendered, and Retry submits its form.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { createMixin } from "remix/component";
10
+ import { formatEditedTime } from "../utils/edited-time.js";
11
+ /** Event an app dispatches on a save status, through {@link setSaveStatus}, to report a save. */
12
+ const SAVE_STATUS_EVENT = "ui:save-status";
13
+ /** Event a save status dispatches, bubbling, when Retry is pressed. */
14
+ const SAVE_STATUS_RETRY_EVENT = "ui:save-status-retry";
15
+ /** How often the relative edit time redraws. */
16
+ const TICK_MS = 30_000;
17
+ /** Reports a save to a save status: dispatched on it by {@link setSaveStatus}. */
18
+ export class SaveStatusEvent extends Event {
19
+ state;
20
+ /** When the content was saved; the moment the event arrives when omitted. */
21
+ at;
22
+ /**
23
+ * @param state Where the save stands.
24
+ * @param at When the content was saved.
25
+ */
26
+ constructor(state, at) {
27
+ super(SAVE_STATUS_EVENT);
28
+ this.state = state;
29
+ this.at = at;
30
+ }
31
+ }
32
+ /** Dispatched, bubbling, from a save status when its Retry is pressed, for an autosave to try again. */
33
+ export class SaveStatusRetryEvent extends Event {
34
+ constructor() {
35
+ super(SAVE_STATUS_RETRY_EVENT, { bubbles: true });
36
+ }
37
+ }
38
+ /**
39
+ * Reports a save to a save status, which is how an autosave drives it.
40
+ *
41
+ * @param target The status element or its `id`.
42
+ * @param state Where the save stands.
43
+ * @param at When the content was saved.
44
+ * @example
45
+ * setSaveStatus("post-status", "saving");
46
+ * let response = await fetch(url, { method: "POST", body });
47
+ * setSaveStatus("post-status", response.ok ? "saved" : "failed");
48
+ */
49
+ export function setSaveStatus(target, state, at) {
50
+ let element = typeof target === "string" ? document.getElementById(target) : target;
51
+ element?.dispatchEvent(new SaveStatusEvent(state, at));
52
+ }
53
+ /**
54
+ * Applied to a save status (`[data-slot="save-status"]`): "Saving…" holds for `holdMs`
55
+ * however fast the save, "Saved" shows for `savedMs`, then the edit time shows and keeps
56
+ * its age current. It writes `data-state` and the texts of its `save-status-*` parts.
57
+ *
58
+ * @example <span data-slot="save-status" mix={[saveStatusSync({ state: "idle", labels, holdMs: 1000, savedMs: 3000, decayMs: 86_400_000 })]}>…</span>
59
+ */
60
+ export const saveStatusSync = createMixin((handle) => {
61
+ let options;
62
+ let controller;
63
+ handle.addEventListener("insert", (event) => {
64
+ controller?.abort();
65
+ controller = new AbortController();
66
+ if (options)
67
+ connect(event.node, () => options, controller.signal);
68
+ });
69
+ handle.addEventListener("remove", () => {
70
+ controller?.abort();
71
+ controller = undefined;
72
+ });
73
+ return (next) => {
74
+ options = next;
75
+ };
76
+ });
77
+ /**
78
+ * Runs `root`'s state machine until `signal` aborts.
79
+ *
80
+ * @param root The status element.
81
+ * @param read Reads the latest options.
82
+ * @param signal Ends every timer and listener once the status leaves the document.
83
+ */
84
+ function connect(root, read, signal) {
85
+ let text = root.querySelector('[data-slot="save-status-text"]');
86
+ let edited = root.querySelector('[data-slot="save-status-edited"]');
87
+ let retry = root.querySelector('[data-slot="save-status-retry"]');
88
+ let initial = read();
89
+ let shown = initial.state;
90
+ let editedAt = initial.editedAt ? new Date(initial.editedAt) : null;
91
+ let savingSince = shown === "saving" ? Date.now() : 0;
92
+ let pending;
93
+ /** Writes `shown` and the edit time into the element's parts. */
94
+ let draw = () => {
95
+ let { labels, locale, decayMs } = read();
96
+ root.dataset.state = shown;
97
+ if (text)
98
+ text.textContent = shown === "idle" ? "" : labels[shown];
99
+ if (retry)
100
+ retry.hidden = shown !== "failed";
101
+ if (!edited)
102
+ return;
103
+ edited.hidden = shown !== "idle" || editedAt === null;
104
+ if (!editedAt)
105
+ return;
106
+ edited.dateTime = editedAt.toISOString();
107
+ edited.title = editedAt.toLocaleString(locale);
108
+ edited.textContent = labels.edited.replace("{time}", formatEditedTime(editedAt, new Date(), decayMs, locale));
109
+ };
110
+ /** Shows `next` now. */
111
+ let show = (next) => {
112
+ shown = next;
113
+ draw();
114
+ };
115
+ /** Shows "Saved", then decays to the edit time. */
116
+ let settleSaved = (at) => {
117
+ editedAt = at;
118
+ show("saved");
119
+ pending = setTimeout(() => show("idle"), read().savedMs);
120
+ };
121
+ root.addEventListener(SAVE_STATUS_EVENT, (event) => {
122
+ clearTimeout(pending);
123
+ if (event.state === "saving") {
124
+ if (shown !== "saving")
125
+ savingSince = Date.now();
126
+ show("saving");
127
+ return;
128
+ }
129
+ let held = shown === "saving" ? Date.now() - savingSince : Infinity;
130
+ let wait = Math.max(0, read().holdMs - held);
131
+ let settle = () => {
132
+ if (event.state === "saved")
133
+ return settleSaved(event.at ?? new Date());
134
+ if (event.at)
135
+ editedAt = event.at;
136
+ show(event.state);
137
+ };
138
+ if (wait > 0)
139
+ pending = setTimeout(settle, wait);
140
+ else
141
+ settle();
142
+ }, { signal });
143
+ retry
144
+ ?.querySelector("button")
145
+ ?.addEventListener("click", () => root.dispatchEvent(new SaveStatusRetryEvent()), {
146
+ signal,
147
+ });
148
+ let tick = setInterval(() => {
149
+ if (shown === "idle")
150
+ draw();
151
+ }, TICK_MS);
152
+ if (shown === "saved")
153
+ pending = setTimeout(() => show("idle"), initial.savedMs);
154
+ signal.addEventListener("abort", () => {
155
+ clearInterval(tick);
156
+ clearTimeout(pending);
157
+ });
158
+ draw();
159
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Why JS: counting checked rows elsewhere on the page, announcing the count and the Escape and
3
+ * action keys need script. No-JS baseline: the bar shows pagination and its page links; rows
4
+ * stay checkable and their form submits as usual.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { MixinFactory } from "remix/component";
10
+ /** Types for {@link selectionBarSync}. */
11
+ export declare namespace SelectionBarSync {
12
+ /** Configuration for {@link selectionBarSync}. */
13
+ interface Options {
14
+ /** The `id` of the region holding the rows' checkboxes. */
15
+ target: string;
16
+ /** The visible and announced count, with `{count}` replaced, such as "{count} selected". */
17
+ selected: string;
18
+ /** What is announced once the selection empties, such as "Selection cleared". */
19
+ cleared: string;
20
+ /** Locale for the count. Defaults to the runtime's. */
21
+ locale?: string;
22
+ }
23
+ }
24
+ /**
25
+ * Wires the bar around its host (`[data-slot="selection-bar"]`) to the target region; the
26
+ * host itself is the polite live region. The bar shows `data-state="selecting"` while any
27
+ * row is checked, its hidden layer is `inert`, and the count stays on the last non-zero value
28
+ * so the bar fades out still naming what was selected.
29
+ *
30
+ * @example <span role="status" mix={[selectionBarSync({ target: "monitors", selected: "{count} selected", cleared: "Selection cleared" })]} />
31
+ */
32
+ export declare const selectionBarSync: MixinFactory<HTMLElement, [options: SelectionBarSync.Options]>;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Why JS: counting checked rows elsewhere on the page, announcing the count and the Escape and
3
+ * action keys need script. No-JS baseline: the bar shows pagination and its page links; rows
4
+ * stay checkable and their form submits as usual.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { createMixin } from "remix/component";
10
+ import { isListKey } from "../utils/key-target.js";
11
+ import { keepSelection } from "./table-selection.js";
12
+ /** The rows a selection counts: checked item boxes, never the select-all box. */
13
+ const CHECKED_ITEM_SELECTOR = "[data-selection-item]:checked";
14
+ /**
15
+ * Wires the bar around its host (`[data-slot="selection-bar"]`) to the target region; the
16
+ * host itself is the polite live region. The bar shows `data-state="selecting"` while any
17
+ * row is checked, its hidden layer is `inert`, and the count stays on the last non-zero value
18
+ * so the bar fades out still naming what was selected.
19
+ *
20
+ * @example <span role="status" mix={[selectionBarSync({ target: "monitors", selected: "{count} selected", cleared: "Selection cleared" })]} />
21
+ */
22
+ export const selectionBarSync = createMixin((handle) => {
23
+ let options;
24
+ let controller;
25
+ handle.addEventListener("insert", (event) => {
26
+ controller?.abort();
27
+ controller = new AbortController();
28
+ if (options)
29
+ connect(event.node, options, controller.signal);
30
+ });
31
+ handle.addEventListener("remove", () => {
32
+ controller?.abort();
33
+ controller = undefined;
34
+ });
35
+ return (next) => {
36
+ options = next;
37
+ };
38
+ });
39
+ /**
40
+ * Connects `live`'s bar to its target until `signal` aborts.
41
+ *
42
+ * @param live The status element the island renders inside the bar.
43
+ * @param options The target and the strings to show.
44
+ * @param signal Ends every listener once the host leaves the document.
45
+ */
46
+ function connect(live, options, signal) {
47
+ let bar = live.closest('[data-slot="selection-bar"]');
48
+ let doc = live.ownerDocument;
49
+ let target = doc.getElementById(options.target);
50
+ if (!bar || !target)
51
+ return;
52
+ let numbers = new Intl.NumberFormat(options.locale);
53
+ let pagination = bar.querySelector('[data-slot="selection-bar-pagination"]');
54
+ let selection = bar.querySelector('[data-slot="selection-bar-selection"]');
55
+ let summary = bar.querySelector('[data-slot="selection-count"]');
56
+ let previous = 0;
57
+ let pending = false;
58
+ let repaint = new MutationObserver(() => schedule());
59
+ /**
60
+ * Reads the count off the target and moves the bar to match, announcing a change. It runs
61
+ * again whenever a re-render from server HTML puts the bar's own state back.
62
+ */
63
+ let sync = () => {
64
+ pending = false;
65
+ let count = target.querySelectorAll(CHECKED_ITEM_SELECTOR).length;
66
+ let selecting = count > 0;
67
+ bar.dataset.state = selecting ? "selecting" : "idle";
68
+ if (selection)
69
+ selection.inert = !selecting;
70
+ if (pagination)
71
+ pagination.inert = selecting;
72
+ if (selecting && summary)
73
+ summary.textContent = format(options.selected, numbers, count);
74
+ if (count !== previous) {
75
+ live.textContent = selecting ? format(options.selected, numbers, count) : options.cleared;
76
+ }
77
+ previous = count;
78
+ repaint.takeRecords();
79
+ };
80
+ /** Coalesces the burst of `change` events a select-all or range pick dispatches into one sync. */
81
+ let schedule = () => {
82
+ if (pending)
83
+ return;
84
+ pending = true;
85
+ queueMicrotask(sync);
86
+ };
87
+ /** Unchecks every row and select-all box, firing `change` on each as a click would. */
88
+ let clear = () => {
89
+ for (let box of target.querySelectorAll(CHECKED_ITEM_SELECTOR)) {
90
+ box.checked = false;
91
+ box.dispatchEvent(new Event("change", { bubbles: true }));
92
+ }
93
+ for (let all of target.querySelectorAll("[data-selection-all]")) {
94
+ if (!all.checked && !all.indeterminate)
95
+ continue;
96
+ all.checked = false;
97
+ all.indeterminate = false;
98
+ all.dispatchEvent(new Event("change", { bubbles: true }));
99
+ }
100
+ if (bar.contains(doc.activeElement)) {
101
+ target.querySelector("[data-selection-item]")?.focus();
102
+ }
103
+ sync();
104
+ };
105
+ keepSelection(target, signal, schedule);
106
+ repaint.observe(bar, { attributeFilter: ["data-state"] });
107
+ signal.addEventListener("abort", () => repaint.disconnect());
108
+ target.addEventListener("change", schedule, { signal });
109
+ target.addEventListener("reset", () => setTimeout(sync), { signal });
110
+ bar.querySelector('[data-slot="selection-clear"]')?.addEventListener("click", clear, { signal });
111
+ doc.defaultView?.addEventListener("keydown", (event) => {
112
+ if (bar.dataset.state !== "selecting" || event.shiftKey || !isListKey(event))
113
+ return;
114
+ let escape = event.key === "Escape";
115
+ let action = escape ? undefined : actionFor(bar, event.key);
116
+ if (!escape && !action)
117
+ return;
118
+ event.preventDefault();
119
+ event.stopPropagation();
120
+ if (action)
121
+ action.click();
122
+ else
123
+ clear();
124
+ }, { capture: true, signal });
125
+ sync();
126
+ }
127
+ /**
128
+ * The enabled action button in `bar` whose key is `key`, matched without case so the printed
129
+ * capital and the typed lowercase letter agree.
130
+ *
131
+ * @param bar The selection bar.
132
+ * @param key The pressed key.
133
+ * @returns The button to click, if one claims the key.
134
+ */
135
+ function actionFor(bar, key) {
136
+ if (key.length !== 1)
137
+ return undefined;
138
+ let wanted = key.toLowerCase();
139
+ return [...bar.querySelectorAll("button[data-selection-key]")].find((button) => !button.disabled && button.dataset.selectionKey?.toLowerCase() === wanted);
140
+ }
141
+ /**
142
+ * Writes `count` into `template`'s `{count}` placeholder.
143
+ *
144
+ * @param template The string with a `{count}` placeholder.
145
+ * @param numbers The formatter for the reader's locale.
146
+ * @param count How many rows are selected.
147
+ * @returns The finished string.
148
+ */
149
+ function format(template, numbers, count) {
150
+ return template.replaceAll("{count}", numbers.format(count));
151
+ }