@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.
- package/README.md +1 -1
- package/dist/app/app-shell-toggle.d.ts +31 -0
- package/dist/app/app-shell-toggle.js +43 -0
- package/dist/app/app-shell.d.ts +131 -0
- package/dist/app/app-shell.js +542 -0
- package/dist/app/auto-refresh.d.ts +104 -0
- package/dist/app/auto-refresh.js +126 -0
- package/dist/app/behaviors/refresh-schedule.d.ts +53 -0
- package/dist/app/behaviors/refresh-schedule.js +95 -0
- package/dist/app/behaviors/shortcuts.d.ts +175 -0
- package/dist/app/behaviors/shortcuts.js +401 -0
- package/dist/app/behaviors/toaster.d.ts +31 -2
- package/dist/app/behaviors/toaster.js +62 -5
- package/dist/app/chart.d.ts +62 -8
- package/dist/app/chart.js +207 -9
- package/dist/app/command-palette.d.ts +132 -0
- package/dist/app/command-palette.js +181 -0
- package/dist/app/danger-zone.d.ts +66 -0
- package/dist/app/danger-zone.js +66 -0
- package/dist/app/detail-sheet.d.ts +119 -0
- package/dist/app/detail-sheet.js +173 -0
- package/dist/app/drop-zone.d.ts +2 -1
- package/dist/app/drop-zone.js +6 -3
- package/dist/app/editor-layout.d.ts +69 -0
- package/dist/app/editor-layout.js +143 -0
- package/dist/app/empty.d.ts +56 -19
- package/dist/app/empty.js +129 -22
- package/dist/app/filter-bar.d.ts +169 -0
- package/dist/app/filter-bar.js +346 -0
- package/dist/app/index.d.ts +51 -0
- package/dist/app/index.js +51 -0
- package/dist/app/keyboard-help.d.ts +66 -0
- package/dist/app/keyboard-help.js +56 -0
- package/dist/app/mixins/app-shell-controls.d.ts +46 -0
- package/dist/app/mixins/app-shell-controls.js +131 -0
- package/dist/app/mixins/auto-refresh.d.ts +29 -0
- package/dist/app/mixins/auto-refresh.js +66 -0
- package/dist/app/mixins/command-palette.d.ts +56 -0
- package/dist/app/mixins/command-palette.js +297 -0
- package/dist/app/mixins/copy-permalink.d.ts +26 -0
- package/dist/app/mixins/copy-permalink.js +54 -0
- package/dist/app/mixins/detail-sheet-keys.d.ts +28 -0
- package/dist/app/mixins/detail-sheet-keys.js +88 -0
- package/dist/app/mixins/escape-link.d.ts +17 -0
- package/dist/app/mixins/escape-link.js +35 -0
- package/dist/app/mixins/keyboard-help.d.ts +38 -0
- package/dist/app/mixins/keyboard-help.js +51 -0
- package/dist/app/mixins/optimistic-toggle-sync.d.ts +80 -0
- package/dist/app/mixins/optimistic-toggle-sync.js +153 -0
- package/dist/app/mixins/range-picker-keys.d.ts +18 -0
- package/dist/app/mixins/range-picker-keys.js +94 -0
- package/dist/app/mixins/row-navigation.d.ts +85 -0
- package/dist/app/mixins/row-navigation.js +208 -0
- package/dist/app/mixins/save-bar-sync.d.ts +27 -0
- package/dist/app/mixins/save-bar-sync.js +106 -0
- package/dist/app/mixins/save-shortcut.d.ts +47 -0
- package/dist/app/mixins/save-shortcut.js +101 -0
- package/dist/app/mixins/save-status-sync.d.ts +77 -0
- package/dist/app/mixins/save-status-sync.js +159 -0
- package/dist/app/mixins/selection-bar-sync.d.ts +32 -0
- package/dist/app/mixins/selection-bar-sync.js +151 -0
- package/dist/app/mixins/split-view.d.ts +66 -0
- package/dist/app/mixins/split-view.js +319 -0
- package/dist/app/mixins/status-strip-keys.d.ts +17 -0
- package/dist/app/mixins/status-strip-keys.js +79 -0
- package/dist/app/mixins/submit-on-change.d.ts +16 -0
- package/dist/app/mixins/submit-on-change.js +28 -0
- package/dist/app/mixins/table-selection.d.ts +39 -0
- package/dist/app/mixins/table-selection.js +272 -0
- package/dist/app/mixins/toast-queue.d.ts +36 -0
- package/dist/app/mixins/toast-queue.js +77 -0
- package/dist/app/mixins/toast-stack.d.ts +20 -0
- package/dist/app/mixins/toast-stack.js +55 -0
- package/dist/app/optimistic-toggle.d.ts +48 -0
- package/dist/app/optimistic-toggle.js +38 -0
- package/dist/app/page-header.d.ts +71 -0
- package/dist/app/page-header.js +249 -0
- package/dist/app/range-picker.d.ts +102 -0
- package/dist/app/range-picker.js +118 -0
- package/dist/app/save-bar.d.ts +54 -0
- package/dist/app/save-bar.js +64 -0
- package/dist/app/save-status.d.ts +50 -0
- package/dist/app/save-status.js +54 -0
- package/dist/app/selection-bar.d.ts +101 -0
- package/dist/app/selection-bar.js +157 -0
- package/dist/app/settings-layout.d.ts +70 -0
- package/dist/app/settings-layout.js +112 -0
- package/dist/app/settings-section.d.ts +140 -0
- package/dist/app/settings-section.js +182 -0
- package/dist/app/skeleton.d.ts +47 -4
- package/dist/app/skeleton.js +149 -2
- package/dist/app/sparkline.d.ts +61 -0
- package/dist/app/sparkline.js +145 -0
- package/dist/app/split-view.d.ts +154 -0
- package/dist/app/split-view.js +272 -0
- package/dist/app/stat-card.d.ts +109 -0
- package/dist/app/stat-card.js +379 -0
- package/dist/app/status-strip.d.ts +70 -0
- package/dist/app/status-strip.js +155 -0
- package/dist/app/styles/action-row.d.ts +41 -0
- package/dist/app/styles/action-row.js +59 -0
- package/dist/app/styles/stat-delta.d.ts +29 -0
- package/dist/app/styles/stat-delta.js +36 -0
- package/dist/app/styles/toast-stack.d.ts +21 -0
- package/dist/app/styles/toast-stack.js +54 -0
- package/dist/app/table.d.ts +199 -24
- package/dist/app/table.js +640 -36
- package/dist/app/toast.d.ts +105 -5
- package/dist/app/toast.js +89 -17
- package/dist/app/toasts.d.ts +49 -0
- package/dist/app/toasts.js +103 -0
- package/dist/app/utils/app-shell-cookie.d.ts +21 -0
- package/dist/app/utils/app-shell-cookie.js +33 -0
- package/dist/app/utils/chart-marker-indices.d.ts +9 -5
- package/dist/app/utils/chart-marker-indices.js +9 -8
- package/dist/app/utils/chart-path.d.ts +14 -10
- package/dist/app/utils/chart-path.js +46 -18
- package/dist/app/utils/edited-time.d.ts +19 -0
- package/dist/app/utils/edited-time.js +35 -0
- package/dist/app/utils/key-target.d.ts +23 -0
- package/dist/app/utils/key-target.js +48 -0
- package/dist/app/utils/search-params.d.ts +69 -0
- package/dist/app/utils/search-params.js +132 -0
- package/dist/app/utils/shortcut-groups.d.ts +21 -0
- package/dist/app/utils/shortcut-groups.js +53 -0
- package/dist/app/utils/split-view-layout.d.ts +48 -0
- package/dist/app/utils/split-view-layout.js +71 -0
- package/dist/app/view-options.d.ts +99 -0
- package/dist/app/view-options.js +182 -0
- package/dist/components/banner.d.ts +61 -0
- package/dist/components/banner.js +101 -0
- package/dist/components/confirm.d.ts +54 -5
- package/dist/components/confirm.js +44 -5
- package/dist/components/group.d.ts +14 -0
- package/dist/components/group.js +66 -11
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/input.js +9 -3
- package/dist/components/link-button.js +8 -2
- package/dist/components/property-list.d.ts +76 -0
- package/dist/components/property-list.js +175 -0
- package/dist/components/relative-time.d.ts +72 -0
- package/dist/components/relative-time.js +45 -0
- package/dist/components/status-dot.d.ts +62 -0
- package/dist/components/status-dot.js +99 -0
- package/dist/components/text-field.d.ts +17 -2
- package/dist/components/text-field.js +13 -4
- package/dist/components/timeline.d.ts +67 -0
- package/dist/components/timeline.js +159 -0
- package/dist/components/typeset.d.ts +2 -1
- package/dist/components/typeset.js +4 -1
- package/dist/docs/code-tabs-sync.d.ts +1 -1
- package/dist/docs/code-tabs-sync.js +2 -2
- package/dist/docs/copy-button.d.ts +1 -1
- package/dist/docs/copy-button.js +2 -2
- package/dist/docs/docs-feedback.d.ts +12 -0
- package/dist/docs/docs-feedback.js +4 -2
- package/dist/docs/docs-hub.js +4 -4
- package/dist/docs/docs-layout.d.ts +1 -1
- package/dist/docs/docs-layout.js +1 -1
- package/dist/docs/docs-nav-tools.d.ts +1 -1
- package/dist/docs/docs-nav-tools.js +2 -2
- package/dist/docs/docs-nav.d.ts +6 -2
- package/dist/docs/docs-nav.js +2 -2
- package/dist/docs/docs-pager.d.ts +5 -1
- package/dist/docs/docs-pager.js +7 -6
- package/dist/docs/mixins/docs-nav-tools.d.ts +2 -2
- package/dist/docs/mixins/docs-nav-tools.js +32 -5
- package/dist/docs/next-steps.js +3 -2
- package/dist/docs/page-actions.d.ts +1 -1
- package/dist/docs/page-actions.js +2 -2
- package/dist/docs/table-of-contents.d.ts +1 -1
- package/dist/docs/table-of-contents.js +2 -2
- package/dist/mixins/confirm-phrase.d.ts +19 -0
- package/dist/mixins/confirm-phrase.js +56 -0
- package/dist/mixins/index.d.ts +2 -0
- package/dist/mixins/index.js +2 -0
- package/dist/mixins/viewer-time.d.ts +20 -0
- package/dist/mixins/viewer-time.js +40 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +1 -0
- package/dist/styles/segmented-control.d.ts +49 -0
- package/dist/styles/segmented-control.js +71 -0
- package/dist/test/table.d.ts +65 -0
- package/dist/test/table.js +108 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/relative-time.d.ts +44 -0
- package/dist/utils/relative-time.js +69 -0
- package/package.json +6 -6
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: a form post replaces the page, so script is what flips a toggle the moment it is
|
|
3
|
+
* pressed, posts the same form data in the background, and puts the toggle back on failure.
|
|
4
|
+
* No-JS baseline: the form posts the next state as a plain submission.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { MixinFactory } from "remix/component";
|
|
10
|
+
/** Event a toggle's form dispatches, bubbling, whenever its state changes. */
|
|
11
|
+
declare const OPTIMISTIC_TOGGLE_EVENT: "ui:optimistic-toggle";
|
|
12
|
+
/** Header a background post carries, so the server can answer with a status instead of a redirect. */
|
|
13
|
+
export declare const OPTIMISTIC_TOGGLE_HEADER = "x-optimistic-toggle";
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementEventMap {
|
|
16
|
+
[OPTIMISTIC_TOGGLE_EVENT]: OptimisticToggleEvent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Types for {@link optimisticToggleSync}. */
|
|
20
|
+
export declare namespace OptimisticToggleSync {
|
|
21
|
+
/** Configuration for {@link optimisticToggleSync}. */
|
|
22
|
+
interface Options {
|
|
23
|
+
/** What the form's live region says once the server refuses a change, such as "Failed". */
|
|
24
|
+
failed: string;
|
|
25
|
+
/** What it says instead for a refusal with one of these statuses, such as a full shelf's 507. */
|
|
26
|
+
refused?: Record<number, string>;
|
|
27
|
+
/** The button's title and, when it has one, `aria-label` while off; left as rendered when omitted. */
|
|
28
|
+
label?: string;
|
|
29
|
+
/** The button's title and `aria-label` while on; `label` when omitted. */
|
|
30
|
+
pressedLabel?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Where a press stands, as {@link OptimisticToggleEvent} reports it. */
|
|
33
|
+
interface Outcome {
|
|
34
|
+
/** The server refused the change. */
|
|
35
|
+
failed?: boolean;
|
|
36
|
+
/** The server answered, with success or a refusal. */
|
|
37
|
+
settled?: boolean;
|
|
38
|
+
/** The answer's HTTP status; `null` before the answer and for a network error. */
|
|
39
|
+
status?: number | null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Dispatched, bubbling, from a toggle's form at the press and again once the server answers,
|
|
44
|
+
* so a row can restyle at once and reload server-derived counts only when `settled` is true.
|
|
45
|
+
*/
|
|
46
|
+
export declare class OptimisticToggleEvent extends Event {
|
|
47
|
+
readonly pressed: boolean;
|
|
48
|
+
/** Whether the server refused the last change, which put the toggle back. */
|
|
49
|
+
readonly failed: boolean;
|
|
50
|
+
/** Whether the server has answered the press: false for the optimistic flip, true after. */
|
|
51
|
+
readonly settled: boolean;
|
|
52
|
+
/** The answer's HTTP status, for picking copy; `null` before the answer and for a network error. */
|
|
53
|
+
readonly status: number | null;
|
|
54
|
+
/**
|
|
55
|
+
* @param pressed Whether the toggle is now on.
|
|
56
|
+
* @param outcome How the press stands: answered at all, refused, and with which status.
|
|
57
|
+
*/
|
|
58
|
+
constructor(pressed: boolean, outcome?: OptimisticToggleSync.Outcome);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Applied to the toggle's `<form>`: on submit it flips `data-pressed`, the button's
|
|
62
|
+
* `aria-pressed`, tone and name, and the hidden next-state field, then posts the form as it stood.
|
|
63
|
+
* A refused post flips it back, sets `data-failed` and writes the `refused` copy for its status,
|
|
64
|
+
* or `failed`, into the live region.
|
|
65
|
+
* The newest press wins over a slow answer to an older one, and only its answer is reported.
|
|
66
|
+
*
|
|
67
|
+
* @example <form method="post" action={url} mix={[optimisticToggleSync({ failed: "Failed" })]}>…</form>
|
|
68
|
+
*/
|
|
69
|
+
export declare const optimisticToggleSync: MixinFactory<HTMLFormElement, [
|
|
70
|
+
options: OptimisticToggleSync.Options
|
|
71
|
+
]>;
|
|
72
|
+
/**
|
|
73
|
+
* Picks the button's tone: danger after a refusal, brand while on, neutral while off.
|
|
74
|
+
*
|
|
75
|
+
* @param pressed Whether the toggle is on.
|
|
76
|
+
* @param failed Whether the last change was refused.
|
|
77
|
+
* @returns The semantic color role the button wears.
|
|
78
|
+
*/
|
|
79
|
+
export declare function toneOf(pressed: boolean, failed: boolean): "danger" | "brand" | "neutral";
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: a form post replaces the page, so script is what flips a toggle the moment it is
|
|
3
|
+
* pressed, posts the same form data in the background, and puts the toggle back on failure.
|
|
4
|
+
* No-JS baseline: the form posts the next state as a plain submission.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createMixin } from "remix/component";
|
|
10
|
+
/** Event a toggle's form dispatches, bubbling, whenever its state changes. */
|
|
11
|
+
const OPTIMISTIC_TOGGLE_EVENT = "ui:optimistic-toggle";
|
|
12
|
+
/** Header a background post carries, so the server can answer with a status instead of a redirect. */
|
|
13
|
+
export const OPTIMISTIC_TOGGLE_HEADER = "x-optimistic-toggle";
|
|
14
|
+
/**
|
|
15
|
+
* Dispatched, bubbling, from a toggle's form at the press and again once the server answers,
|
|
16
|
+
* so a row can restyle at once and reload server-derived counts only when `settled` is true.
|
|
17
|
+
*/
|
|
18
|
+
export class OptimisticToggleEvent extends Event {
|
|
19
|
+
pressed;
|
|
20
|
+
/** Whether the server refused the last change, which put the toggle back. */
|
|
21
|
+
failed;
|
|
22
|
+
/** Whether the server has answered the press: false for the optimistic flip, true after. */
|
|
23
|
+
settled;
|
|
24
|
+
/** The answer's HTTP status, for picking copy; `null` before the answer and for a network error. */
|
|
25
|
+
status;
|
|
26
|
+
/**
|
|
27
|
+
* @param pressed Whether the toggle is now on.
|
|
28
|
+
* @param outcome How the press stands: answered at all, refused, and with which status.
|
|
29
|
+
*/
|
|
30
|
+
constructor(pressed, outcome = {}) {
|
|
31
|
+
super(OPTIMISTIC_TOGGLE_EVENT, { bubbles: true });
|
|
32
|
+
this.pressed = pressed;
|
|
33
|
+
this.failed = outcome.failed ?? false;
|
|
34
|
+
this.settled = outcome.settled ?? false;
|
|
35
|
+
this.status = outcome.status ?? null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Applied to the toggle's `<form>`: on submit it flips `data-pressed`, the button's
|
|
40
|
+
* `aria-pressed`, tone and name, and the hidden next-state field, then posts the form as it stood.
|
|
41
|
+
* A refused post flips it back, sets `data-failed` and writes the `refused` copy for its status,
|
|
42
|
+
* or `failed`, into the live region.
|
|
43
|
+
* The newest press wins over a slow answer to an older one, and only its answer is reported.
|
|
44
|
+
*
|
|
45
|
+
* @example <form method="post" action={url} mix={[optimisticToggleSync({ failed: "Failed" })]}>…</form>
|
|
46
|
+
*/
|
|
47
|
+
export const optimisticToggleSync = createMixin((handle) => {
|
|
48
|
+
let options;
|
|
49
|
+
let controller;
|
|
50
|
+
handle.addEventListener("insert", (event) => {
|
|
51
|
+
controller?.abort();
|
|
52
|
+
controller = new AbortController();
|
|
53
|
+
connect(event.node, () => options, controller.signal);
|
|
54
|
+
});
|
|
55
|
+
handle.addEventListener("remove", () => {
|
|
56
|
+
controller?.abort();
|
|
57
|
+
controller = undefined;
|
|
58
|
+
});
|
|
59
|
+
return (next) => {
|
|
60
|
+
options = next;
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Handles `form`'s submissions until `signal` aborts.
|
|
65
|
+
*
|
|
66
|
+
* @param form The toggle's form.
|
|
67
|
+
* @param read Reads the latest options.
|
|
68
|
+
* @param signal Ends the listener once the form leaves the document.
|
|
69
|
+
*/
|
|
70
|
+
function connect(form, read, signal) {
|
|
71
|
+
let button = form.querySelector('button[type="submit"]');
|
|
72
|
+
let next = form.querySelector("input[data-toggle-next]");
|
|
73
|
+
let status = form.querySelector('[role="status"]');
|
|
74
|
+
let latest = 0;
|
|
75
|
+
/** Draws `pressed` and the outcome onto the form and tells the page. */
|
|
76
|
+
let show = (pressed, outcome) => {
|
|
77
|
+
let failed = outcome.failed ?? false;
|
|
78
|
+
form.toggleAttribute("data-pressed", pressed);
|
|
79
|
+
form.toggleAttribute("data-failed", failed);
|
|
80
|
+
if (next)
|
|
81
|
+
next.value = pressed ? "false" : "true";
|
|
82
|
+
if (button) {
|
|
83
|
+
button.setAttribute("aria-pressed", pressed ? "true" : "false");
|
|
84
|
+
button.dataset.color = toneOf(pressed, failed);
|
|
85
|
+
name(button, pressed, read());
|
|
86
|
+
}
|
|
87
|
+
if (status)
|
|
88
|
+
status.textContent = failed ? refusal(read(), outcome.status ?? null) : "";
|
|
89
|
+
form.dispatchEvent(new OptimisticToggleEvent(pressed, outcome));
|
|
90
|
+
};
|
|
91
|
+
form.addEventListener("submit", async (event) => {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
let body = new FormData(form);
|
|
94
|
+
let previous = form.hasAttribute("data-pressed");
|
|
95
|
+
let token = ++latest;
|
|
96
|
+
show(!previous, {});
|
|
97
|
+
let answer = await fetch(form.action, {
|
|
98
|
+
method: "POST",
|
|
99
|
+
credentials: "same-origin",
|
|
100
|
+
headers: { [OPTIMISTIC_TOGGLE_HEADER]: "1" },
|
|
101
|
+
body,
|
|
102
|
+
}).then((response) => ({ ok: response.ok, status: response.status }), () => ({ ok: false, status: null }));
|
|
103
|
+
if (token !== latest || signal.aborted)
|
|
104
|
+
return;
|
|
105
|
+
if (answer.ok)
|
|
106
|
+
show(!previous, { settled: true, status: answer.status });
|
|
107
|
+
else
|
|
108
|
+
show(previous, { failed: true, settled: true, status: answer.status });
|
|
109
|
+
}, { signal });
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Renames `button` for its state, so its title and accessible name follow a flip; a button
|
|
113
|
+
* named by its content keeps its content as the name, with no `aria-label` added.
|
|
114
|
+
*
|
|
115
|
+
* @param button The toggle's button.
|
|
116
|
+
* @param pressed Whether the toggle is on.
|
|
117
|
+
* @param options The toggle's latest options.
|
|
118
|
+
*/
|
|
119
|
+
function name(button, pressed, options) {
|
|
120
|
+
if (options?.label === undefined)
|
|
121
|
+
return;
|
|
122
|
+
let label = pressed ? (options.pressedLabel ?? options.label) : options.label;
|
|
123
|
+
button.title = label;
|
|
124
|
+
if (button.hasAttribute("aria-label"))
|
|
125
|
+
button.setAttribute("aria-label", label);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Picks the live region's copy for a refusal: the `refused` entry for its status when one is
|
|
129
|
+
* listed, `failed` for any other status and for a network error.
|
|
130
|
+
*
|
|
131
|
+
* @param options The toggle's latest options.
|
|
132
|
+
* @param status The refusal's HTTP status, or `null` when the request never got an answer.
|
|
133
|
+
* @returns The text the live region shows.
|
|
134
|
+
*/
|
|
135
|
+
function refusal(options, status) {
|
|
136
|
+
if (!options)
|
|
137
|
+
return "";
|
|
138
|
+
if (status !== null && options.refused?.[status] !== undefined)
|
|
139
|
+
return options.refused[status];
|
|
140
|
+
return options.failed;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Picks the button's tone: danger after a refusal, brand while on, neutral while off.
|
|
144
|
+
*
|
|
145
|
+
* @param pressed Whether the toggle is on.
|
|
146
|
+
* @param failed Whether the last change was refused.
|
|
147
|
+
* @returns The semantic color role the button wears.
|
|
148
|
+
*/
|
|
149
|
+
export function toneOf(pressed, failed) {
|
|
150
|
+
if (failed)
|
|
151
|
+
return "danger";
|
|
152
|
+
return pressed ? "brand" : "neutral";
|
|
153
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: a letter key that picks a range from anywhere on the page, and a select that
|
|
3
|
+
* submits as soon as it changes, both need a listener HTML does not provide.
|
|
4
|
+
* No-JS baseline: every preset is a submit button and the narrow select has an Apply button.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Adds the picker's keyboard layer and live select: a preset's letter picks it from anywhere
|
|
11
|
+
* on the page outside a text field, and changing the narrow select submits it, hiding its
|
|
12
|
+
* Apply button. Keys with Ctrl, Alt or Meta held pass through to the browser.
|
|
13
|
+
*
|
|
14
|
+
* @returns A mixin descriptor for {@link RangePicker}'s `mix` prop, inside a hydrated island.
|
|
15
|
+
* @example
|
|
16
|
+
* <RangePicker presets={presets} value={range} labels={labels} mix={rangePickerKeys()} />
|
|
17
|
+
*/
|
|
18
|
+
export declare const rangePickerKeys: import("remix/component").MixinFactory<HTMLElement, [], import("remix/component").ElementProps>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: a letter key that picks a range from anywhere on the page, and a select that
|
|
3
|
+
* submits as soon as it changes, both need a listener HTML does not provide.
|
|
4
|
+
* No-JS baseline: every preset is a submit button and the narrow select has an Apply button.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createElement, createMixin, on } from "remix/component";
|
|
10
|
+
import { whileLive } from "../../mixins/while-live.js";
|
|
11
|
+
import { RANGE_PICKER_ENHANCED_ATTRIBUTE, RANGE_PICKER_KEY_ATTRIBUTE } from "../range-picker.js";
|
|
12
|
+
/**
|
|
13
|
+
* Reports whether a key press belongs to the element that received it: a text field, a
|
|
14
|
+
* select, or editable content keeps its letters, so typing never changes the range.
|
|
15
|
+
*
|
|
16
|
+
* @param target The key event's target.
|
|
17
|
+
* @returns `true` when the target takes typed text.
|
|
18
|
+
*/
|
|
19
|
+
function isTyping(target) {
|
|
20
|
+
if (!(target instanceof HTMLElement))
|
|
21
|
+
return false;
|
|
22
|
+
if (target.isContentEditable)
|
|
23
|
+
return true;
|
|
24
|
+
return target.matches("input, textarea, select");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Picks the control `key` names inside `host`: the visible segment or Custom entry, or, when
|
|
28
|
+
* the select stands in for the segments, the select's option, which it selects and submits.
|
|
29
|
+
*
|
|
30
|
+
* @param host The picker's root.
|
|
31
|
+
* @param key The pressed letter, lowercased.
|
|
32
|
+
* @returns `true` when a control took the key.
|
|
33
|
+
*/
|
|
34
|
+
function pick(host, key) {
|
|
35
|
+
let selector = `[${RANGE_PICKER_KEY_ATTRIBUTE}="${CSS.escape(key)}"]`;
|
|
36
|
+
for (let control of host.querySelectorAll(selector)) {
|
|
37
|
+
if (control instanceof HTMLOptionElement) {
|
|
38
|
+
let select = control.closest("select");
|
|
39
|
+
if (!select?.checkVisibility())
|
|
40
|
+
continue;
|
|
41
|
+
select.value = control.value;
|
|
42
|
+
select.form?.requestSubmit();
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (!control.checkVisibility())
|
|
46
|
+
continue;
|
|
47
|
+
control.click();
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Adds the picker's keyboard layer and live select: a preset's letter picks it from anywhere
|
|
54
|
+
* on the page outside a text field, and changing the narrow select submits it, hiding its
|
|
55
|
+
* Apply button. Keys with Ctrl, Alt or Meta held pass through to the browser.
|
|
56
|
+
*
|
|
57
|
+
* @returns A mixin descriptor for {@link RangePicker}'s `mix` prop, inside a hydrated island.
|
|
58
|
+
* @example
|
|
59
|
+
* <RangePicker presets={presets} value={range} labels={labels} mix={rangePickerKeys()} />
|
|
60
|
+
*/
|
|
61
|
+
export const rangePickerKeys = createMixin((handle) => {
|
|
62
|
+
let host;
|
|
63
|
+
let follow = whileLive(handle, (target, signal) => {
|
|
64
|
+
target.addEventListener("keydown", (event) => {
|
|
65
|
+
if (!host || event.defaultPrevented || event.repeat)
|
|
66
|
+
return;
|
|
67
|
+
if (event.ctrlKey || event.altKey || event.metaKey)
|
|
68
|
+
return;
|
|
69
|
+
if (event.key.length !== 1 || isTyping(event.target))
|
|
70
|
+
return;
|
|
71
|
+
if (pick(host, event.key.toLowerCase()))
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
}, { signal });
|
|
74
|
+
});
|
|
75
|
+
handle.addEventListener("insert", (event) => {
|
|
76
|
+
host = event.node;
|
|
77
|
+
host.setAttribute(RANGE_PICKER_ENHANCED_ATTRIBUTE, "");
|
|
78
|
+
});
|
|
79
|
+
handle.addEventListener("remove", () => {
|
|
80
|
+
host = undefined;
|
|
81
|
+
});
|
|
82
|
+
return () => {
|
|
83
|
+
if (typeof document !== "undefined")
|
|
84
|
+
follow(document);
|
|
85
|
+
return createElement(handle.element, {
|
|
86
|
+
mix: [
|
|
87
|
+
on("change", (event) => {
|
|
88
|
+
if (event.target instanceof HTMLSelectElement)
|
|
89
|
+
event.target.form?.requestSubmit();
|
|
90
|
+
}),
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard row navigation for a list or table: `j`/`k` and the arrows move one roving focus
|
|
3
|
+
* stop through the rows, Enter or `o` opens a row, `x` toggles its selection checkbox, Space
|
|
4
|
+
* can ask for a peek, and `/` jumps to the page's search field.
|
|
5
|
+
* Why JS: HTML has no keystroke-to-row wiring or roving focus. No-JS baseline: every row's
|
|
6
|
+
* link and checkbox stay reachable by Tab and the pointer.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { MixinFactory } from "remix/component";
|
|
12
|
+
import type { Announcer } from "../../behaviors/announcer.js";
|
|
13
|
+
/** Rows the mixin walks when its options name none: marked rows, table body rows, list items. */
|
|
14
|
+
export declare const ROW_NAVIGATION_ROW_SELECTOR = "[data-row], tbody > tr, :scope > li";
|
|
15
|
+
/** The control opening a row: one marked `data-row-primary`, else its first link. */
|
|
16
|
+
export declare const ROW_NAVIGATION_PRIMARY_SELECTOR = "[data-row-primary], a[href]";
|
|
17
|
+
/** Attribute every row the mixin has indexed carries, which its focus ring is drawn on. */
|
|
18
|
+
export declare const ROW_NAVIGATION_ATTRIBUTE = "data-row-navigation";
|
|
19
|
+
/** Event a row dispatches when Space asks to peek at it. */
|
|
20
|
+
export declare const ROW_PEEK_EVENT: "ui:row-peek";
|
|
21
|
+
declare global {
|
|
22
|
+
interface HTMLElementEventMap {
|
|
23
|
+
[ROW_PEEK_EVENT]: RowPeekEvent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Dispatched, bubbling, on the focused row when Space asks to peek at it, so a page opens the
|
|
28
|
+
* row's detail beside the list while focus stays on the row.
|
|
29
|
+
*/
|
|
30
|
+
export declare class RowPeekEvent extends Event {
|
|
31
|
+
/** The row asked about. */
|
|
32
|
+
readonly row: HTMLElement;
|
|
33
|
+
/**
|
|
34
|
+
* @param row The row asked about.
|
|
35
|
+
*/
|
|
36
|
+
constructor(row: HTMLElement);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Types for {@link rowNavigation}.
|
|
40
|
+
*/
|
|
41
|
+
export declare namespace RowNavigation {
|
|
42
|
+
/** The copy each key lists under in the help sheet; an omitted label keeps that key unlisted. */
|
|
43
|
+
interface Labels {
|
|
44
|
+
/** The help-sheet heading the keys list under. */
|
|
45
|
+
group?: string;
|
|
46
|
+
next?: string;
|
|
47
|
+
previous?: string;
|
|
48
|
+
open?: string;
|
|
49
|
+
toggle?: string;
|
|
50
|
+
peek?: string;
|
|
51
|
+
search?: string;
|
|
52
|
+
/** Announced when `x` checks the row's checkbox. */
|
|
53
|
+
selected?: string;
|
|
54
|
+
/** Announced when `x` clears the row's checkbox. */
|
|
55
|
+
deselected?: string;
|
|
56
|
+
}
|
|
57
|
+
/** Options for {@link rowNavigation}. */
|
|
58
|
+
interface Options {
|
|
59
|
+
/** Rows to walk, matched inside the host. @default ROW_NAVIGATION_ROW_SELECTOR */
|
|
60
|
+
rows?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The nearest ancestor matching this selector becomes the host whose rows are walked, for
|
|
63
|
+
* a mixin carried by a marker element inside the list rather than the list itself.
|
|
64
|
+
*/
|
|
65
|
+
within?: string;
|
|
66
|
+
/** The control Enter and `o` press inside a row. @default ROW_NAVIGATION_PRIMARY_SELECTOR */
|
|
67
|
+
primary?: string;
|
|
68
|
+
/** The `id` of the search field `/` focuses; omitted, `/` stays unbound. */
|
|
69
|
+
search?: string;
|
|
70
|
+
/** Binds Space to dispatch {@link RowPeekEvent} on the focused row. @default false */
|
|
71
|
+
peek?: boolean;
|
|
72
|
+
labels?: Labels;
|
|
73
|
+
/** Says what `x` did, for a reader who cannot see the checkbox change. */
|
|
74
|
+
announcer?: Announcer;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Walks a list's rows from the keyboard, registering its keys in the page's shortcut registry
|
|
79
|
+
* under the host's layer, so a list inside a sheet answers above the page's. Rows receive a
|
|
80
|
+
* 2px focus ring drawn inside their edge, so a scrolling container never clips it.
|
|
81
|
+
*
|
|
82
|
+
* @param options Which rows to walk, what opens one, and the copy each key lists under.
|
|
83
|
+
* @example <ul mix={[rowNavigation({ search: "q", labels: { group: "List", next: "Next", previous: "Previous" } })]}>…</ul>
|
|
84
|
+
*/
|
|
85
|
+
export declare const rowNavigation: MixinFactory<HTMLElement, [options?: RowNavigation.Options]>;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard row navigation for a list or table: `j`/`k` and the arrows move one roving focus
|
|
3
|
+
* stop through the rows, Enter or `o` opens a row, `x` toggles its selection checkbox, Space
|
|
4
|
+
* can ask for a peek, and `/` jumps to the page's search field.
|
|
5
|
+
* Why JS: HTML has no keystroke-to-row wiring or roving focus. No-JS baseline: every row's
|
|
6
|
+
* link and checkbox stay reachable by Tab and the pointer.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import { outline } from "@sdxc/u/color";
|
|
12
|
+
import { when } from "@sdxc/u/state";
|
|
13
|
+
import { createElement, createMixin } from "remix/component";
|
|
14
|
+
import { shortcutRegistry } from "../behaviors/shortcuts.js";
|
|
15
|
+
/** Rows the mixin walks when its options name none: marked rows, table body rows, list items. */
|
|
16
|
+
export const ROW_NAVIGATION_ROW_SELECTOR = "[data-row], tbody > tr, :scope > li";
|
|
17
|
+
/** The control opening a row: one marked `data-row-primary`, else its first link. */
|
|
18
|
+
export const ROW_NAVIGATION_PRIMARY_SELECTOR = "[data-row-primary], a[href]";
|
|
19
|
+
/** Attribute every row the mixin has indexed carries, which its focus ring is drawn on. */
|
|
20
|
+
export const ROW_NAVIGATION_ATTRIBUTE = "data-row-navigation";
|
|
21
|
+
/** Event a row dispatches when Space asks to peek at it. */
|
|
22
|
+
export const ROW_PEEK_EVENT = "ui:row-peek";
|
|
23
|
+
/**
|
|
24
|
+
* Dispatched, bubbling, on the focused row when Space asks to peek at it, so a page opens the
|
|
25
|
+
* row's detail beside the list while focus stays on the row.
|
|
26
|
+
*/
|
|
27
|
+
export class RowPeekEvent extends Event {
|
|
28
|
+
/** The row asked about. */
|
|
29
|
+
row;
|
|
30
|
+
/**
|
|
31
|
+
* @param row The row asked about.
|
|
32
|
+
*/
|
|
33
|
+
constructor(row) {
|
|
34
|
+
super(ROW_PEEK_EVENT, { bubbles: true });
|
|
35
|
+
this.row = row;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** The selection checkbox the selection column renders in each row. */
|
|
39
|
+
const SELECTION_ITEM_SELECTOR = "input[type='checkbox'][data-selection-item]";
|
|
40
|
+
/** The rows under `host`, each marked so the focus ring draws on it. */
|
|
41
|
+
function queryRows(host, selector) {
|
|
42
|
+
let rows = [...host.querySelectorAll(selector)].filter((row) => !row.hidden && row.closest("[hidden]") === null);
|
|
43
|
+
for (let row of rows)
|
|
44
|
+
row.setAttribute(ROW_NAVIGATION_ATTRIBUTE, "");
|
|
45
|
+
return rows;
|
|
46
|
+
}
|
|
47
|
+
/** The row holding focus, or `null` when focus sits outside every row. */
|
|
48
|
+
function focusedRow(host, rows) {
|
|
49
|
+
let active = host.ownerDocument.activeElement;
|
|
50
|
+
if (active === null || !host.contains(active))
|
|
51
|
+
return null;
|
|
52
|
+
return rows.find((row) => row.contains(active)) ?? null;
|
|
53
|
+
}
|
|
54
|
+
/** Makes `row` the list's one Tab stop. */
|
|
55
|
+
function rove(rows, row) {
|
|
56
|
+
for (let other of rows)
|
|
57
|
+
other.tabIndex = other === row ? 0 : -1;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The row to start from when nothing is focused: the first whose top is on screen going
|
|
61
|
+
* down, the last whose bottom is on screen going up.
|
|
62
|
+
*/
|
|
63
|
+
function rowInView(rows, direction) {
|
|
64
|
+
let height = rows[0]?.ownerDocument.defaultView?.innerHeight ?? 0;
|
|
65
|
+
if (direction === 1) {
|
|
66
|
+
return rows.find((row) => row.getBoundingClientRect().top >= 0) ?? rows.at(-1);
|
|
67
|
+
}
|
|
68
|
+
return [...rows].reverse().find((row) => row.getBoundingClientRect().bottom <= height) ?? rows[0];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Walks a list's rows from the keyboard, registering its keys in the page's shortcut registry
|
|
72
|
+
* under the host's layer, so a list inside a sheet answers above the page's. Rows receive a
|
|
73
|
+
* 2px focus ring drawn inside their edge, so a scrolling container never clips it.
|
|
74
|
+
*
|
|
75
|
+
* @param options Which rows to walk, what opens one, and the copy each key lists under.
|
|
76
|
+
* @example <ul mix={[rowNavigation({ search: "q", labels: { group: "List", next: "Next", previous: "Previous" } })]}>…</ul>
|
|
77
|
+
*/
|
|
78
|
+
export const rowNavigation = createMixin((handle) => {
|
|
79
|
+
let options = {};
|
|
80
|
+
handle.addEventListener("insert", (event) => {
|
|
81
|
+
let host = options.within === undefined
|
|
82
|
+
? event.node
|
|
83
|
+
: (event.node.parentElement?.closest(options.within) ?? event.node);
|
|
84
|
+
let registry = shortcutRegistry(host.ownerDocument);
|
|
85
|
+
let signal = handle.signal;
|
|
86
|
+
let rows = () => queryRows(host, options.rows ?? ROW_NAVIGATION_ROW_SELECTOR);
|
|
87
|
+
let labels = () => options.labels ?? {};
|
|
88
|
+
let initial = rows();
|
|
89
|
+
if (initial[0] !== undefined)
|
|
90
|
+
rove(initial, initial[0]);
|
|
91
|
+
host.addEventListener("focusin", (focus) => {
|
|
92
|
+
let all = rows();
|
|
93
|
+
let row = all.find((candidate) => focus.target instanceof Node && candidate.contains(focus.target));
|
|
94
|
+
if (row !== undefined)
|
|
95
|
+
rove(all, row);
|
|
96
|
+
}, { signal });
|
|
97
|
+
/** Focuses the row one step from the focused one, or the row on screen. */
|
|
98
|
+
let move = (direction, event) => {
|
|
99
|
+
let all = rows();
|
|
100
|
+
let current = focusedRow(host, all);
|
|
101
|
+
if (current === null && event.key.startsWith("Arrow"))
|
|
102
|
+
return false;
|
|
103
|
+
let next = current === null ? rowInView(all, direction) : all[all.indexOf(current) + direction];
|
|
104
|
+
if (next === undefined)
|
|
105
|
+
return current !== null;
|
|
106
|
+
rove(all, next);
|
|
107
|
+
next.focus();
|
|
108
|
+
next.scrollIntoView({ block: "nearest" });
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
/** The focused row, only when the row itself holds focus rather than a control in it. */
|
|
112
|
+
let rowItself = () => {
|
|
113
|
+
let row = focusedRow(host, rows());
|
|
114
|
+
return row !== null && host.ownerDocument.activeElement === row ? row : null;
|
|
115
|
+
};
|
|
116
|
+
registry.register({
|
|
117
|
+
keys: ["j", "arrowdown"],
|
|
118
|
+
label: labels().next,
|
|
119
|
+
group: labels().group,
|
|
120
|
+
scope: host,
|
|
121
|
+
run: (event) => move(1, event),
|
|
122
|
+
signal,
|
|
123
|
+
});
|
|
124
|
+
registry.register({
|
|
125
|
+
keys: ["k", "arrowup"],
|
|
126
|
+
label: labels().previous,
|
|
127
|
+
group: labels().group,
|
|
128
|
+
scope: host,
|
|
129
|
+
run: (event) => move(-1, event),
|
|
130
|
+
signal,
|
|
131
|
+
});
|
|
132
|
+
registry.register({
|
|
133
|
+
keys: ["o", "enter"],
|
|
134
|
+
label: labels().open,
|
|
135
|
+
group: labels().group,
|
|
136
|
+
scope: host,
|
|
137
|
+
run: (event) => {
|
|
138
|
+
let row = event.key === "Enter" ? rowItself() : focusedRow(host, rows());
|
|
139
|
+
let primary = row?.querySelector(options.primary ?? ROW_NAVIGATION_PRIMARY_SELECTOR);
|
|
140
|
+
if (primary == null)
|
|
141
|
+
return false;
|
|
142
|
+
primary.click();
|
|
143
|
+
return true;
|
|
144
|
+
},
|
|
145
|
+
signal,
|
|
146
|
+
});
|
|
147
|
+
registry.register({
|
|
148
|
+
keys: "x",
|
|
149
|
+
label: labels().toggle,
|
|
150
|
+
group: labels().group,
|
|
151
|
+
scope: host,
|
|
152
|
+
run: () => {
|
|
153
|
+
let checkbox = focusedRow(host, rows())?.querySelector(SELECTION_ITEM_SELECTOR);
|
|
154
|
+
if (checkbox == null || checkbox.disabled)
|
|
155
|
+
return false;
|
|
156
|
+
checkbox.click();
|
|
157
|
+
let said = checkbox.checked ? labels().selected : labels().deselected;
|
|
158
|
+
if (said !== undefined)
|
|
159
|
+
options.announcer?.announce(said);
|
|
160
|
+
return true;
|
|
161
|
+
},
|
|
162
|
+
signal,
|
|
163
|
+
});
|
|
164
|
+
if (options.peek === true) {
|
|
165
|
+
registry.register({
|
|
166
|
+
keys: "space",
|
|
167
|
+
label: labels().peek,
|
|
168
|
+
group: labels().group,
|
|
169
|
+
scope: host,
|
|
170
|
+
run: () => {
|
|
171
|
+
let row = rowItself();
|
|
172
|
+
if (row === null)
|
|
173
|
+
return false;
|
|
174
|
+
row.dispatchEvent(new RowPeekEvent(row));
|
|
175
|
+
return true;
|
|
176
|
+
},
|
|
177
|
+
signal,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (options.search !== undefined) {
|
|
181
|
+
let id = options.search;
|
|
182
|
+
registry.register({
|
|
183
|
+
keys: "/",
|
|
184
|
+
label: labels().search,
|
|
185
|
+
group: labels().group,
|
|
186
|
+
scope: host,
|
|
187
|
+
run: () => {
|
|
188
|
+
let field = host.ownerDocument.getElementById(id);
|
|
189
|
+
if (field === null)
|
|
190
|
+
return false;
|
|
191
|
+
field.focus();
|
|
192
|
+
if (field instanceof HTMLInputElement)
|
|
193
|
+
field.select();
|
|
194
|
+
return true;
|
|
195
|
+
},
|
|
196
|
+
signal,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return (next = {}) => {
|
|
201
|
+
options = next;
|
|
202
|
+
return createElement(handle.element, {
|
|
203
|
+
mix: [
|
|
204
|
+
when(`& [${ROW_NAVIGATION_ATTRIBUTE}]:focus-visible`, outline({ color: "brand.ring", width: 2, offset: -2 })),
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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 type { MixinFactory } from "remix/component";
|
|
10
|
+
/** Types for {@link saveBarSync}. */
|
|
11
|
+
export declare namespace SaveBarSync {
|
|
12
|
+
/** Configuration for {@link saveBarSync}. */
|
|
13
|
+
interface Options {
|
|
14
|
+
/** The `id` of the watched form; omit when the bar sits inside it. */
|
|
15
|
+
form?: string;
|
|
16
|
+
/** What the bar's live region announces once the form changes, such as "Unsaved changes". */
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Applied to the bar (`[data-slot="save-bar"]`): unhides it while the form's values differ
|
|
22
|
+
* from their baseline, which a submission moves to the submitted values, and ⌘S saves them
|
|
23
|
+
* unless the form's own primary save answers it. `[role="status"]` announces `message`.
|
|
24
|
+
*
|
|
25
|
+
* @example <div hidden mix={[saveBarSync({ message: "Unsaved changes" })]}>…</div>
|
|
26
|
+
*/
|
|
27
|
+
export declare const saveBarSync: MixinFactory<HTMLElement, [options: SaveBarSync.Options]>;
|