@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,126 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
2
+ import { ChevronDownIcon, RefreshCwIcon } from "@sdxc/icons";
3
+ import { bg, fg, outline } from "@sdxc/u/color";
4
+ import { rounded, shadow } from "@sdxc/u/effects";
5
+ import { mergeMix } from "@sdxc/u/general";
6
+ import { flex, flexWrap, gap, inlineFlex, items, justify, shrink } from "@sdxc/u/layout";
7
+ import { bs, minIs, p, pi } from "@sdxc/u/size";
8
+ import { focusVisible, hover, when } from "@sdxc/u/state";
9
+ import { nowrap, tabularNums, text, textDecoration, truncate, weight } from "@sdxc/u/typography";
10
+ import { clientEntry } from "remix/component";
11
+ import { Button } from "../components/button.js";
12
+ import { Menu } from "../components/menu.js";
13
+ import { interactiveTransition } from "../styles/interactive-transition.js";
14
+ import { autoRefresh } from "./mixins/auto-refresh.js";
15
+ import { paramValues, setParamHref } from "./utils/search-params.js";
16
+ /** The search parameter holding the interval, in seconds, when `name` is unset. */
17
+ const DEFAULT_PARAM = "refresh";
18
+ /** The interval in seconds while the URL names none: off. */
19
+ const DEFAULT_VALUE = 0;
20
+ /** The intervals offered when `options` is unset: none, leaving the last-updated time. */
21
+ const DEFAULT_OPTIONS = [];
22
+ /** What the control draws when `show` is unset: the interval menu and the time. */
23
+ const DEFAULT_SHOW = "all";
24
+ /** The URL read when `url` is unset: a page with nothing chosen. */
25
+ const DEFAULT_URL = "/";
26
+ /** The placeholder in `labels.updated` that the refreshed-at time replaces. */
27
+ const TIME_SLOT = "{time}";
28
+ /**
29
+ * Renders the interval menu and the last-updated time. Each menu item is a link, so a choice
30
+ * works without script and lands in the URL; the time island does the reloading.
31
+ *
32
+ * @param handle Runtime handle carrying the host `<div>`'s props.
33
+ * @returns The render function producing the control.
34
+ * @example
35
+ * <AutoRefresh
36
+ * id="monitors-refresh"
37
+ * url={request.url}
38
+ * frame="monitor-list"
39
+ * refreshedAt={new Date()}
40
+ * options={[{ value: 0, label: "Off" }, { value: 30, label: "30s" }, { value: 60, label: "1m" }]}
41
+ * labels={{ trigger: "Auto-refresh", updated: "Updated {time}" }}
42
+ * />
43
+ */
44
+ export function AutoRefresh(handle) {
45
+ return () => {
46
+ let { id, url = DEFAULT_URL, name = DEFAULT_PARAM, value, defaultValue = DEFAULT_VALUE, options = DEFAULT_OPTIONS, hrefFor, frame, refreshedAt, locale, timeZone, show = DEFAULT_SHOW, labels, mix, ...rest } = handle.props;
47
+ let menuId = `${id}-menu`;
48
+ let fromUrl = Number(paramValues(url, name)[0]);
49
+ let current = value ?? (options.some((option) => option.value === fromUrl) ? fromUrl : defaultValue);
50
+ let currentLabel = options.find((option) => option.value === current)?.label ?? "";
51
+ let linkFor = hrefFor ??
52
+ ((seconds) => setParamHref(url, name, seconds === defaultValue ? null : String(seconds), []));
53
+ let time = refreshedAt ?? new Date();
54
+ let status = (_jsx(AutoRefreshStatus, { every: current * 1000, frame: frame, label: labels.updated, refreshedAt: time.toISOString(), text: new Intl.DateTimeFormat(locale, { timeStyle: "medium", timeZone }).format(time), locale: locale }));
55
+ if (show === "status") {
56
+ return (_jsx("div", { ...rest, "data-slot": "auto-refresh", "data-interval": current, mix: mergeMix([minIs(0), truncate()], mix), children: status }));
57
+ }
58
+ if (show === "choices") {
59
+ return (_jsx("div", { ...rest, "data-slot": "auto-refresh", "data-interval": current, mix: mergeMix([], mix), children: _jsxs("div", { role: "group", "aria-label": labels.trigger, "data-slot": "auto-refresh-choices", mix: [flex(), items("center"), justify("between"), gap(3), text("sm")], children: [_jsx("span", { "aria-hidden": "true", mix: [fg("neutral"), nowrap()], children: labels.trigger }), _jsx("span", { mix: [
60
+ inlineFlex(),
61
+ p(0.5),
62
+ gap(0.5),
63
+ rounded("md"),
64
+ bg("neutral.bg-tint-hover"),
65
+ minIs(0),
66
+ ], children: options.map((option) => (_jsx("a", { href: linkFor(option.value), "aria-current": option.value === current ? "true" : undefined, mix: [
67
+ interactiveTransition(),
68
+ inlineFlex(),
69
+ items("center"),
70
+ bs(7),
71
+ pi(2),
72
+ rounded("sm"),
73
+ fg("neutral"),
74
+ textDecoration("none"),
75
+ tabularNums(),
76
+ nowrap(),
77
+ hover(fg("neutral.emphasis")),
78
+ focusVisible(outline({ color: "brand.ring", offset: 1 })),
79
+ when('&[aria-current="true"]', [
80
+ bg("neutral.tint"),
81
+ fg("neutral.emphasis"),
82
+ shadow("sm"),
83
+ ]),
84
+ ], children: option.label }))) })] }) }));
85
+ }
86
+ return (_jsxs("div", { ...rest, "data-slot": "auto-refresh", "data-interval": current, mix: mergeMix([flex(), flexWrap(), items("center"), gap(2), text("sm")], mix), children: [_jsxs(Button, { variant: "ghost", size: "sm", commandfor: menuId, command: "toggle-popover", "data-slot": "auto-refresh-trigger", mix: [fg("neutral"), weight(400), shrink(0), when("& > svg", fg("neutral.muted"))], children: [_jsx(RefreshCwIcon, { size: 16, "aria-hidden": "true" }), labels.trigger, _jsx("span", { "data-slot": "value", mix: [fg("neutral.emphasis"), weight(500), tabularNums()], children: currentLabel }), _jsx(ChevronDownIcon, { size: 14, "aria-hidden": "true" })] }), _jsx(Menu, { id: menuId, placement: "bottom-end", "aria-label": labels.trigger, children: options.map((option) => (_jsx(Menu.Item, { href: linkFor(option.value), role: "menuitemradio", "aria-checked": option.value === current ? "true" : "false", children: option.label }))) }), status] }));
87
+ };
88
+ }
89
+ /**
90
+ * The island naming when the list was fetched. Once hydrated it reloads the `frame` it names,
91
+ * or the page, every `every` milliseconds while the tab is visible, and rewrites the time after
92
+ * each reload. Load `@sdxc/ui/app/auto-refresh` in the browser entry.
93
+ *
94
+ * @example <AutoRefreshStatus every={30_000} label="Updated {time}" refreshedAt={iso} text="10:42:07" />
95
+ */
96
+ export const AutoRefreshStatus = clientEntry("@sdxc/ui/app/auto-refresh#AutoRefreshStatus", function AutoRefreshStatus(handle) {
97
+ /** Reloads the named frame, or the page when none is named; a named frame not on the page is left alone. */
98
+ let reload = async () => {
99
+ let name = handle.props.frame;
100
+ if (name === undefined)
101
+ await handle.frames.top.reload();
102
+ else
103
+ await handle.frames.get(name)?.reload();
104
+ };
105
+ return () => {
106
+ let { every, label, refreshedAt, text: written, locale } = handle.props;
107
+ let [before, after] = aroundTime(label);
108
+ return (_jsxs("span", { "data-slot": "auto-refresh-status", mix: [fg("neutral.muted"), nowrap(), tabularNums()], children: [before, _jsx("time", { dateTime: refreshedAt, mix: [autoRefresh({ every, reload, locale })], children: written }), after] }));
109
+ };
110
+ });
111
+ /**
112
+ * Splits the status template at its first `{time}` into the text before and after the time, so
113
+ * a translation can put the time anywhere; a template without `{time}` reads "<text> <time>",
114
+ * and an unset one shows the time alone.
115
+ *
116
+ * @param label The `labels.updated` template.
117
+ * @returns The text before the time and the text after it.
118
+ */
119
+ function aroundTime(label) {
120
+ if (label === undefined)
121
+ return ["", ""];
122
+ let at = label.indexOf(TIME_SLOT);
123
+ if (at === -1)
124
+ return [`${label} `, ""];
125
+ return [label.slice(0, at), label.slice(at + TIME_SLOT.length)];
126
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The timer behind a list that refreshes itself: it runs a reload every interval, one at a
3
+ * time, waits while paused, and on resume reloads at once when an interval has passed. It
4
+ * holds no DOM, so the island adapter decides what pauses it and what a reload is.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { TypedEventTarget } from "remix/component";
10
+ /** Types for {@link RefreshSchedule}. */
11
+ export declare namespace RefreshSchedule {
12
+ /** Construction options. */
13
+ interface Init {
14
+ /** Milliseconds from the end of one reload to the start of the next; 0 or less never reloads. */
15
+ every: number;
16
+ /** Reloads what the schedule keeps current; a rejection leaves the schedule running. */
17
+ reload: () => Promise<unknown>;
18
+ /** When the content on screen was last fetched. Defaults to construction time. */
19
+ refreshedAt?: Date;
20
+ }
21
+ /** Events dispatched by {@link RefreshSchedule}. */
22
+ interface Events {
23
+ /** A reload finished; read `refreshedAt` for when. */
24
+ refresh: Event;
25
+ }
26
+ }
27
+ /**
28
+ * Reloads on an interval measured from the last finished reload, so a slow reload never
29
+ * stacks a second one behind it, and a resume after a long pause catches up with one reload.
30
+ *
31
+ * @example let schedule = new RefreshSchedule({ every: 30_000, reload: () => frame.reload() }); schedule.start();
32
+ */
33
+ export declare class RefreshSchedule extends TypedEventTarget<RefreshSchedule.Events> {
34
+ #private;
35
+ /** Milliseconds between reloads. */
36
+ readonly every: number;
37
+ /**
38
+ * @param init The interval and the reload to run.
39
+ */
40
+ constructor(init: RefreshSchedule.Init);
41
+ /** When the last reload finished, or the initial content was fetched. */
42
+ get refreshedAt(): Date;
43
+ /** Whether the schedule is waiting to be resumed. */
44
+ get paused(): boolean;
45
+ /** Starts counting toward the next reload from the last refresh. */
46
+ start(): void;
47
+ /** Holds the next reload until {@link resume}; a reload already running finishes. */
48
+ pause(): void;
49
+ /** Continues the schedule, reloading at once when a full interval passed while paused. */
50
+ resume(): void;
51
+ /** Ends the schedule for good. */
52
+ stop(): void;
53
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The timer behind a list that refreshes itself: it runs a reload every interval, one at a
3
+ * time, waits while paused, and on resume reloads at once when an interval has passed. It
4
+ * holds no DOM, so the island adapter decides what pauses it and what a reload is.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { TypedEventTarget } from "remix/component";
10
+ /**
11
+ * Reloads on an interval measured from the last finished reload, so a slow reload never
12
+ * stacks a second one behind it, and a resume after a long pause catches up with one reload.
13
+ *
14
+ * @example let schedule = new RefreshSchedule({ every: 30_000, reload: () => frame.reload() }); schedule.start();
15
+ */
16
+ export class RefreshSchedule extends TypedEventTarget {
17
+ /** Milliseconds between reloads. */
18
+ every;
19
+ #reload;
20
+ #refreshedAt;
21
+ /** When the last reload attempt ended, failed or not, which the next interval counts from. */
22
+ #attemptedAt;
23
+ #timer;
24
+ #running = false;
25
+ #paused = true;
26
+ #stopped = false;
27
+ /**
28
+ * @param init The interval and the reload to run.
29
+ */
30
+ constructor(init) {
31
+ super();
32
+ this.every = init.every;
33
+ this.#reload = init.reload;
34
+ this.#refreshedAt = init.refreshedAt ?? new Date();
35
+ this.#attemptedAt = this.#refreshedAt.getTime();
36
+ }
37
+ /** When the last reload finished, or the initial content was fetched. */
38
+ get refreshedAt() {
39
+ return this.#refreshedAt;
40
+ }
41
+ /** Whether the schedule is waiting to be resumed. */
42
+ get paused() {
43
+ return this.#paused;
44
+ }
45
+ /** Starts counting toward the next reload from the last refresh. */
46
+ start() {
47
+ this.resume();
48
+ }
49
+ /** Holds the next reload until {@link resume}; a reload already running finishes. */
50
+ pause() {
51
+ this.#paused = true;
52
+ clearTimeout(this.#timer);
53
+ this.#timer = undefined;
54
+ }
55
+ /** Continues the schedule, reloading at once when a full interval passed while paused. */
56
+ resume() {
57
+ if (this.#stopped || this.every <= 0)
58
+ return;
59
+ this.#paused = false;
60
+ this.#schedule();
61
+ }
62
+ /** Ends the schedule for good. */
63
+ stop() {
64
+ this.pause();
65
+ this.#stopped = true;
66
+ }
67
+ /** Arms the timer for whatever remains of the interval since the last refresh. */
68
+ #schedule() {
69
+ clearTimeout(this.#timer);
70
+ if (this.#paused || this.#running || this.#stopped)
71
+ return;
72
+ let remaining = this.every - (Date.now() - this.#attemptedAt);
73
+ this.#timer = setTimeout(() => void this.#run(), Math.max(0, remaining));
74
+ }
75
+ /** Runs one reload, then arms the next. */
76
+ async #run() {
77
+ this.#timer = undefined;
78
+ if (this.#paused || this.#stopped)
79
+ return;
80
+ this.#running = true;
81
+ try {
82
+ await this.#reload();
83
+ this.#refreshedAt = new Date();
84
+ this.dispatchEvent(new Event("refresh"));
85
+ }
86
+ catch {
87
+ /** A failed reload keeps the old content and its time; the next interval tries again. */
88
+ }
89
+ finally {
90
+ this.#running = false;
91
+ this.#attemptedAt = Date.now();
92
+ }
93
+ this.#schedule();
94
+ }
95
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * One keyboard-shortcut system for an app page: single keys, chords and `g`+key sequences
3
+ * registered from script or declared in server HTML with `data-shortcut`, resolved by layer so
4
+ * the topmost open modal answers before a sheet and a sheet before the page.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { TypedEventTarget } from "remix/component";
10
+ /**
11
+ * Attribute a link, button or field declares its shortcut on, as `"g m"`, `"c"` or
12
+ * `"s, /"` (comma-separated alternatives). Pressing it clicks the element, or focuses it
13
+ * when it is a field.
14
+ */
15
+ export declare const SHORTCUT_ATTRIBUTE = "data-shortcut";
16
+ /** Attribute naming a declared shortcut in the help sheet; an empty value keeps it unlisted. */
17
+ export declare const SHORTCUT_LABEL_ATTRIBUTE = "data-shortcut-label";
18
+ /** Attribute naming the help-sheet group of every shortcut declared on or inside its element. */
19
+ export declare const SHORTCUT_GROUP_ATTRIBUTE = "data-shortcut-group";
20
+ /**
21
+ * Attribute marking an element as a shortcut layer, `"sheet"` or `"modal"`, for a panel built
22
+ * from something other than `<dialog>` or `[popover]`. The layer counts as open while it and
23
+ * its ancestors are free of `hidden` and `inert`.
24
+ */
25
+ export declare const SHORTCUT_SCOPE_ATTRIBUTE = "data-shortcut-scope";
26
+ /** Milliseconds a sequence waits for its next key before the keys typed so far are dropped. */
27
+ export declare const SHORTCUT_SEQUENCE_TIMEOUT_MS = 1200;
28
+ /**
29
+ * Priorities for the Escape ladder: with every handler declining when it has nothing to undo,
30
+ * one press clears the selection, the next clears the filters, and only then does a panel close.
31
+ */
32
+ export declare const ESCAPE_PRIORITY: {
33
+ readonly selection: 30;
34
+ readonly filters: 20;
35
+ readonly close: 10;
36
+ };
37
+ /**
38
+ * Types for {@link ShortcutRegistry}.
39
+ */
40
+ export declare namespace Shortcuts {
41
+ /** The layers a shortcut can belong to, from lowest to highest. */
42
+ type Layer = "page" | "sheet" | "modal";
43
+ /** A shortcut registered from script. */
44
+ interface Registration {
45
+ /**
46
+ * The keys that run it: a combo (`"mod+k"`, `"?"`, `"escape"`), a space-separated
47
+ * sequence (`"g m"`), or several of either as alternatives.
48
+ */
49
+ keys: string | readonly string[];
50
+ /**
51
+ * Runs the shortcut. Returning `false` declines the keystroke, which then reaches the
52
+ * next candidate, so an Escape handler with nothing to clear lets the next one act.
53
+ */
54
+ run(event: KeyboardEvent): boolean | void;
55
+ /** What it does, as the help sheet lists it; unlabelled shortcuts stay unlisted. */
56
+ label?: string;
57
+ /** The help-sheet heading it lists under. */
58
+ group?: string;
59
+ /**
60
+ * An element inside the layer it belongs to: its nearest open `<dialog>`, `[popover]`
61
+ * or `[data-shortcut-scope]`. Omitted, it belongs to the page.
62
+ */
63
+ scope?: Element | null;
64
+ /** Breaks a tie within one layer; the higher number answers first. @default 0 */
65
+ priority?: number;
66
+ /** Answers while focus is in a text field, as Escape and `mod+k` do. @default false */
67
+ whileTyping?: boolean;
68
+ /**
69
+ * Answers while a modal above its layer is open, below that modal's own shortcuts:
70
+ * the key that toggles a palette closes it again. @default false
71
+ */
72
+ global?: boolean;
73
+ /** Takes the shortcut out of the registry. */
74
+ signal?: AbortSignal;
75
+ }
76
+ /** One row of the help sheet. */
77
+ interface Entry {
78
+ /** The alternatives that run it, each a combo or sequence as registered. */
79
+ keys: string[];
80
+ label: string;
81
+ group?: string;
82
+ }
83
+ /** Options for {@link ShortcutRegistry}. */
84
+ interface Options {
85
+ /** Milliseconds a sequence waits for its next key. @default SHORTCUT_SEQUENCE_TIMEOUT_MS */
86
+ sequenceTimeout?: number;
87
+ }
88
+ /** Events a {@link ShortcutRegistry} dispatches. */
89
+ interface Events {
90
+ /** A shortcut was registered or removed, so a help sheet lists it anew. */
91
+ change: Event;
92
+ }
93
+ }
94
+ /**
95
+ * Splits `keys` into its alternatives: an array as given, a string at its commas. A lone
96
+ * `","` stays the comma key.
97
+ *
98
+ * @param keys The keys as registered.
99
+ * @returns Each alternative, trimmed.
100
+ */
101
+ export declare function shortcutAlternatives(keys: string | readonly string[]): string[];
102
+ /**
103
+ * The key caps a hint prints for one alternative, sequence steps in press order, with arrows
104
+ * and the space bar as their symbols. A letter prints as its cap, upper-cased, and a capital
105
+ * letter, which only Shift types, prints with the Shift cap before it.
106
+ *
107
+ * @param alternative A combo or sequence, e.g. `"g m"`, `"mod+k"`, `"arrowdown"`.
108
+ * @param apple Whether the reader's keyboard carries the Apple modifier glyphs.
109
+ * @returns The caps to render.
110
+ * @example shortcutGlyphs("g m", true) // ["G", "M"]
111
+ */
112
+ export declare function shortcutGlyphs(alternative: string, apple: boolean): string[];
113
+ /**
114
+ * Whether the reader's keyboard prints the Apple modifier glyphs, read from the platform the
115
+ * browser reports. On a server it answers `true`, the glyphs most readers see.
116
+ *
117
+ * @returns Whether to print ⌘ for `mod`.
118
+ */
119
+ export declare function isApplePlatform(): boolean;
120
+ /**
121
+ * Holds every shortcut on a page and answers keystrokes: the candidates a keystroke completes
122
+ * are ranked by layer (topmost open modal, then open sheets, then the page), then priority,
123
+ * then the latest registered, and the first that runs without declining claims the key.
124
+ *
125
+ * @example
126
+ * let registry = shortcutRegistry(document);
127
+ * registry.register({ keys: "g m", label: "Go to Monitors", group: "Navigation", run: () => location.assign("/monitors"), signal });
128
+ */
129
+ export declare class ShortcutRegistry extends TypedEventTarget<Shortcuts.Events> {
130
+ #private;
131
+ /**
132
+ * @param options How long a sequence waits for its next key.
133
+ */
134
+ constructor(options?: Shortcuts.Options);
135
+ /**
136
+ * Adds a shortcut until `signal` aborts or the returned function runs.
137
+ *
138
+ * @param registration The keys, what they run, and where they belong.
139
+ * @returns A function that removes the shortcut.
140
+ */
141
+ register(registration: Shortcuts.Registration): () => void;
142
+ /**
143
+ * Every labelled shortcut, registered or declared in `document`, in registration then
144
+ * document order, one row per distinct keys and label.
145
+ *
146
+ * @param document The document whose `data-shortcut` elements are listed too.
147
+ * @returns The rows a help sheet shows.
148
+ */
149
+ list(document?: Document): Shortcuts.Entry[];
150
+ /**
151
+ * Answers keystrokes on `document` until `signal` aborts, in the bubble phase so a handler
152
+ * nearer the target that claims a key keeps it.
153
+ *
154
+ * @param document The document to listen on.
155
+ * @param signal Removes the listener.
156
+ */
157
+ listen(document: Document, signal?: AbortSignal): void;
158
+ /**
159
+ * Runs the shortcut a keystroke completes, default-preventing the keystroke when one ran or
160
+ * a sequence is waiting for its next key.
161
+ *
162
+ * @param event The keystroke as it reached the document.
163
+ * @returns Whether the keystroke was claimed.
164
+ */
165
+ handle(event: KeyboardEvent): boolean;
166
+ }
167
+ /**
168
+ * The registry every part on a page shares, created and bound to `document` on first use, so
169
+ * a palette, a help sheet and a list's row keys resolve against one another.
170
+ *
171
+ * @param document The page's document.
172
+ * @returns The page's registry.
173
+ * @example shortcutRegistry(document).register({ keys: "?", label: "Show shortcuts", run: open, signal });
174
+ */
175
+ export declare function shortcutRegistry(document: Document): ShortcutRegistry;