strata-react 0.1.16 → 1.0.0
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 +14 -11
- package/dist/components/async-button.d.ts +15 -3
- package/dist/components/button.d.ts +17 -7
- package/dist/components/checkbox.d.ts +3 -3
- package/dist/components/commands.d.ts +104 -0
- package/dist/components/composition.d.ts +1 -1
- package/dist/components/data-table.d.ts +16 -3
- package/dist/components/data-view.d.ts +12 -1
- package/dist/components/dialog.d.ts +45 -0
- package/dist/components/field.d.ts +3 -1
- package/dist/components/infinite-list.d.ts +35 -2
- package/dist/components/job-status.d.ts +36 -0
- package/dist/components/popover.d.ts +20 -0
- package/dist/components/selection.d.ts +1 -1
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/thumbnail.d.ts +17 -7
- package/dist/components/toggle.d.ts +43 -0
- package/dist/components/toolbar.d.ts +15 -0
- package/dist/components/tooltip.d.ts +19 -0
- package/dist/index.d.ts +17 -7
- package/dist/index.js +1380 -355
- package/dist/index.js.map +1 -1
- package/dist/lib/chords.d.ts +20 -0
- package/dist/lib/errors.d.ts +28 -4
- package/dist/lib/format.d.ts +57 -6
- package/dist/lib/overlay.d.ts +1 -0
- package/dist/lib/utils.d.ts +1 -1
- package/dist/query/index.d.ts +13 -4
- package/dist/query/job.d.ts +22 -0
- package/dist/{query-BlPgaCBG.js → query-BVh4zv7Y.js} +146 -41
- package/dist/query-BVh4zv7Y.js.map +1 -0
- package/dist/{run-N6Juz-kN.js → run-DFf1BBA3.js} +13 -3
- package/dist/run-DFf1BBA3.js.map +1 -0
- package/dist/strata.css +17 -0
- package/dist/testing/buttons.d.ts +7 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing.js +31 -2
- package/dist/testing.js.map +1 -1
- package/dist/visual-cli.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +8 -7
- package/dist/query-BlPgaCBG.js.map +0 -1
- package/dist/run-N6Juz-kN.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { S as typeSteps, _ as Textarea, a as toLoad, b as describeHttpError, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as NativeSelect, h as Input, i as staleOf, l as ThemeProvider, m as Field, n as createQueryClient, o as useLoad, p as ChoiceGroup, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as HttpError,
|
|
1
|
+
import { C as Tooltip, S as readErrorBody, T as typeSteps, _ as Textarea, a as toLoad, b as describeHttpError, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as NativeSelect, h as Input, i as staleOf, l as ThemeProvider, m as Field, n as createQueryClient, o as useLoad, p as ChoiceGroup, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as HttpError, w as cn, x as fieldErrorsOf, y as describeActionError } from "./query-BVh4zv7Y.js";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, SearchField, Separator, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, useFilter } from "react-aria-components";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Check, ChevronRight, CircleAlert, History, ImageOff, LoaderCircle, RotateCcw, X } from "lucide-react";
|
|
6
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Check, ChevronRight, CircleAlert, History, ImageOff, LoaderCircle, Minus, RotateCcw, Search, Trash2, TriangleAlert, X } from "lucide-react";
|
|
7
7
|
import { Link, NavLink, useSearchParams } from "react-router";
|
|
8
|
-
import { flexRender,
|
|
8
|
+
import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
9
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
10
|
-
import { hashKey, useInfiniteQuery } from "@tanstack/react-query";
|
|
10
|
+
import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
11
11
|
// src/lib/format.ts
|
|
12
12
|
var NBSP = "\xA0";
|
|
13
|
+
/** The placeholder printed for a value that is not known: an en dash. */
|
|
14
|
+
var MISSING = "–";
|
|
13
15
|
var BYTE_UNITS = [
|
|
14
16
|
"B",
|
|
15
17
|
"kB",
|
|
@@ -25,8 +27,8 @@ function toDate(value) {
|
|
|
25
27
|
if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
|
|
26
28
|
return date;
|
|
27
29
|
}
|
|
28
|
-
function callableDate(df) {
|
|
29
|
-
const format = (value) => df.format(toDate(value));
|
|
30
|
+
function callableDate(df, missing) {
|
|
31
|
+
const format = (value) => value == null ? missing : df.format(toDate(value));
|
|
30
32
|
return Object.assign(format, {
|
|
31
33
|
format,
|
|
32
34
|
formatToParts: (value) => df.formatToParts(toDate(value)),
|
|
@@ -34,27 +36,42 @@ function callableDate(df) {
|
|
|
34
36
|
resolvedOptions: () => df.resolvedOptions()
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
|
-
function callable(nf) {
|
|
38
|
-
const format = (value) => nf.format(value);
|
|
39
|
+
function callable(nf, missing) {
|
|
40
|
+
const format = (value) => value == null ? missing : nf.format(value);
|
|
39
41
|
return Object.assign(format, {
|
|
40
42
|
format,
|
|
41
43
|
formatToParts: (value) => nf.formatToParts(value),
|
|
42
44
|
resolvedOptions: () => nf.resolvedOptions()
|
|
43
45
|
});
|
|
44
46
|
}
|
|
47
|
+
var DAY = 864e5;
|
|
48
|
+
var AGO_STEPS = [
|
|
49
|
+
["year", 365 * DAY],
|
|
50
|
+
["month", 30 * DAY],
|
|
51
|
+
["week", 7 * DAY],
|
|
52
|
+
["day", DAY],
|
|
53
|
+
["hour", 36e5],
|
|
54
|
+
["minute", 6e4]
|
|
55
|
+
];
|
|
45
56
|
/** Intl formatters for one locale (and optionally one time zone): integers, decimals, percent, dates, times, units with a non-breaking space, byte sizes, and counted nouns. */
|
|
46
57
|
function createFormat(locale, options = {}) {
|
|
47
|
-
const { timeZone } = options;
|
|
58
|
+
const { timeZone, missing = "–" } = options;
|
|
48
59
|
const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
|
|
49
60
|
...opts,
|
|
50
61
|
timeZone
|
|
51
|
-
}));
|
|
52
|
-
const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }));
|
|
53
|
-
const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }));
|
|
62
|
+
}), missing);
|
|
63
|
+
const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }), missing);
|
|
64
|
+
const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }), missing);
|
|
54
65
|
const percent = callable(new Intl.NumberFormat(locale, {
|
|
55
66
|
style: "percent",
|
|
56
67
|
maximumFractionDigits: 0
|
|
57
|
-
}));
|
|
68
|
+
}), missing);
|
|
69
|
+
const compact = callable(new Intl.NumberFormat(locale, {
|
|
70
|
+
notation: "compact",
|
|
71
|
+
maximumFractionDigits: 1
|
|
72
|
+
}), missing);
|
|
73
|
+
const relative = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
74
|
+
const plurals = new Intl.PluralRules(locale);
|
|
58
75
|
const clock = dates({
|
|
59
76
|
hour: "2-digit",
|
|
60
77
|
minute: "2-digit"
|
|
@@ -85,6 +102,43 @@ function createFormat(locale, options = {}) {
|
|
|
85
102
|
decimal,
|
|
86
103
|
/** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
|
|
87
104
|
percent,
|
|
105
|
+
/**
|
|
106
|
+
* A part's share of a whole, as `percent` but never misleading at the ends: a part above 0 that
|
|
107
|
+
* rounds to 0 is "<1%", and one short of the whole that rounds to 100 is ">99%".
|
|
108
|
+
* `format.share(2.4 / 512)` is "<1%".
|
|
109
|
+
*/
|
|
110
|
+
share: (value) => {
|
|
111
|
+
if (value == null || Number.isNaN(value)) return missing;
|
|
112
|
+
if (value > 0 && value < .005) return `<${percent.format(.01)}`;
|
|
113
|
+
if (value >= .995 && value < 1) return `>${percent.format(.99)}`;
|
|
114
|
+
return percent.format(value);
|
|
115
|
+
},
|
|
116
|
+
/** A figure in short form for counts that run to thousands: `format.compact(1234)` is "1.2k" in en-GB, "1.2K" in en-US. */
|
|
117
|
+
compact,
|
|
118
|
+
/**
|
|
119
|
+
* How long ago (or how far ahead) a time is, in the largest unit it reaches:
|
|
120
|
+
* "3 weeks ago", "yesterday", "in 2 hours", "now" under a minute. Pass `now` in tests.
|
|
121
|
+
*/
|
|
122
|
+
ago: (value, now = /* @__PURE__ */ new Date()) => {
|
|
123
|
+
if (value == null) return missing;
|
|
124
|
+
const diff = toDate(value).getTime() - toDate(now).getTime();
|
|
125
|
+
const span = Math.abs(diff);
|
|
126
|
+
for (const [unit, size] of AGO_STEPS) if (span >= size) return relative.format(Math.sign(diff) * Math.floor(span / size), unit);
|
|
127
|
+
return relative.format(0, "second");
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* A media running time from seconds, as a player shows it: "4:05", "1:02:09". Unknown
|
|
131
|
+
* (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
|
|
132
|
+
*/
|
|
133
|
+
runningTime: (seconds) => {
|
|
134
|
+
if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
|
|
135
|
+
const s = Math.floor(seconds);
|
|
136
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
137
|
+
const [h, m] = [Math.floor(s / 3600), Math.floor(s % 3600 / 60)];
|
|
138
|
+
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
139
|
+
},
|
|
140
|
+
/** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */
|
|
141
|
+
missing,
|
|
88
142
|
/** A time of day: `format.clock(at)` is "06:05". */
|
|
89
143
|
clock,
|
|
90
144
|
/** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
|
|
@@ -116,11 +170,50 @@ function createFormat(locale, options = {}) {
|
|
|
116
170
|
* joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
|
|
117
171
|
* call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
|
|
118
172
|
*/
|
|
119
|
-
count: (value, one, many = `${one}s
|
|
173
|
+
count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)} ${plurals.select(value) === "one" ? one : many}`
|
|
120
174
|
};
|
|
121
175
|
}
|
|
122
176
|
/** The en-GB formatters. */
|
|
123
177
|
var format = createFormat("en-GB");
|
|
178
|
+
// src/lib/in-view.ts
|
|
179
|
+
/**
|
|
180
|
+
* Whether an element is within `rootMargin` of its scroll region (the nearest
|
|
181
|
+
* `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the
|
|
182
|
+
* element as it mounts and unmounts.
|
|
183
|
+
*/
|
|
184
|
+
function useInView({ active = true, rootMargin = "0px", once = false, unsupported = false } = {}) {
|
|
185
|
+
const [inView, setInView] = React.useState(false);
|
|
186
|
+
const [el, setEl] = React.useState(null);
|
|
187
|
+
const seen = once && inView;
|
|
188
|
+
React.useEffect(() => {
|
|
189
|
+
if (seen) return;
|
|
190
|
+
if (!active || !el) {
|
|
191
|
+
setInView(false);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
195
|
+
setInView(unsupported);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
|
|
199
|
+
const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
|
|
200
|
+
root,
|
|
201
|
+
rootMargin
|
|
202
|
+
});
|
|
203
|
+
observer.observe(el);
|
|
204
|
+
return () => observer.disconnect();
|
|
205
|
+
}, [
|
|
206
|
+
active,
|
|
207
|
+
el,
|
|
208
|
+
rootMargin,
|
|
209
|
+
seen,
|
|
210
|
+
unsupported
|
|
211
|
+
]);
|
|
212
|
+
return {
|
|
213
|
+
ref: setEl,
|
|
214
|
+
inView
|
|
215
|
+
};
|
|
216
|
+
}
|
|
124
217
|
// src/components/button.tsx
|
|
125
218
|
var buttonVariants = cva("inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control type-label transition-state press disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", {
|
|
126
219
|
variants: {
|
|
@@ -143,10 +236,17 @@ var buttonVariants = cva("inline-flex shrink-0 cursor-pointer items-center justi
|
|
|
143
236
|
size: "default"
|
|
144
237
|
}
|
|
145
238
|
});
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
239
|
+
/**
|
|
240
|
+
* A button with shadcn's variant names, built on React Aria's `Button` (press handling that behaves
|
|
241
|
+
* the same for mouse, touch, pen and keyboard, focus-visible and hover state). The default variant is
|
|
242
|
+
* `outline`; ask for the filled accent (`variant="default"`) once per view. `type` defaults to `button`.
|
|
243
|
+
* `onClick` and `disabled` are the DOM names and keep working; `onPress` is also accepted.
|
|
244
|
+
*/
|
|
245
|
+
function Button({ className, variant, size, type = "button", disabled, ...props }) {
|
|
246
|
+
return /* @__PURE__ */ jsx(Button$1, {
|
|
247
|
+
type,
|
|
248
|
+
isDisabled: disabled,
|
|
249
|
+
"data-variant": variant ?? "outline",
|
|
150
250
|
className: cn(buttonVariants({
|
|
151
251
|
variant,
|
|
152
252
|
size
|
|
@@ -154,15 +254,18 @@ function Button({ className, variant, size, asChild = false, type = "button", ..
|
|
|
154
254
|
...props
|
|
155
255
|
});
|
|
156
256
|
}
|
|
157
|
-
/** An icon-only button. `label` is required and becomes the accessible name and tooltip. */
|
|
158
|
-
function IconButton({ icon: Icon, label, variant = "ghost", ...props }) {
|
|
159
|
-
return /* @__PURE__ */ jsx(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
257
|
+
/** An icon-only button. `label` is required and becomes the accessible name and the tooltip (hover and keyboard focus); `hint` adds a muted aside to it, such as a shortcut. */
|
|
258
|
+
function IconButton({ icon: Icon, label, hint, variant = "ghost", ...props }) {
|
|
259
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
260
|
+
label,
|
|
261
|
+
hint,
|
|
262
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
263
|
+
size: "icon",
|
|
264
|
+
variant,
|
|
265
|
+
"aria-label": label,
|
|
266
|
+
...props,
|
|
267
|
+
children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": true })
|
|
268
|
+
})
|
|
166
269
|
});
|
|
167
270
|
}
|
|
168
271
|
/** A small ghost action for one table row: shows `label`, and is named "`label` `subject`" so every row's action has its own name. */
|
|
@@ -176,28 +279,617 @@ function RowAction({ label, subject, icon: Icon, variant = "ghost", size = "sm",
|
|
|
176
279
|
children: [Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), label]
|
|
177
280
|
});
|
|
178
281
|
}
|
|
179
|
-
// src/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
282
|
+
// src/lib/overlay.ts
|
|
283
|
+
var overlaySurface = "rounded-overlay border border-border bg-popover text-popover-foreground shadow-overlay enter-overlay";
|
|
284
|
+
// src/lib/chords.ts
|
|
285
|
+
/** The platform this page runs on, read from the browser (`mac` for macOS and iOS). Server and test default: `other`. */
|
|
286
|
+
function detectPlatform() {
|
|
287
|
+
if (typeof navigator === "undefined") return "other";
|
|
288
|
+
const nav = navigator;
|
|
289
|
+
const text = nav.userAgentData?.platform ?? nav.platform ?? "";
|
|
290
|
+
return /mac|iphone|ipad|ipod/i.test(text) ? "mac" : "other";
|
|
291
|
+
}
|
|
292
|
+
/** Splits "Mod+Shift+Z" into modifiers and key for a platform. A bare "+" key is written "Mod++". */
|
|
293
|
+
function parseChord(chord, platform = detectPlatform()) {
|
|
294
|
+
const parts = chord.endsWith("++") ? [...chord.slice(0, -2).split("+").filter(Boolean), "+"] : chord.split("+");
|
|
295
|
+
const key = parts.pop() ?? "";
|
|
296
|
+
const mods = new Set(parts.map((p) => p.toLowerCase()));
|
|
297
|
+
const mod = mods.has("mod");
|
|
298
|
+
return {
|
|
299
|
+
ctrl: mods.has("ctrl") || mod && platform !== "mac",
|
|
300
|
+
meta: mods.has("meta") || mod && platform === "mac",
|
|
301
|
+
alt: mods.has("alt"),
|
|
302
|
+
shift: mods.has("shift"),
|
|
303
|
+
key
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
var symbol = (key) => key.length === 1 && key.toUpperCase() === key.toLowerCase();
|
|
307
|
+
/** Whether a key event is this chord. Exact on Ctrl, Meta and Alt; Shift is exact for letters and named keys. */
|
|
308
|
+
function matchesChord(e, chord, platform = detectPlatform()) {
|
|
309
|
+
const c = parseChord(chord, platform);
|
|
310
|
+
if (e.ctrlKey !== c.ctrl || e.metaKey !== c.meta || e.altKey !== c.alt) return false;
|
|
311
|
+
if (!symbol(c.key) && e.shiftKey !== c.shift) return false;
|
|
312
|
+
if (symbol(c.key) && c.shift && !e.shiftKey) return false;
|
|
313
|
+
if (e.key.toLowerCase() === c.key.toLowerCase()) return true;
|
|
314
|
+
return c.alt && /^[a-z]$/i.test(c.key) && e.code === `Key${c.key.toUpperCase()}`;
|
|
315
|
+
}
|
|
316
|
+
var NAMES = {
|
|
317
|
+
ArrowUp: {
|
|
318
|
+
mac: "↑",
|
|
319
|
+
other: "↑"
|
|
320
|
+
},
|
|
321
|
+
ArrowDown: {
|
|
322
|
+
mac: "↓",
|
|
323
|
+
other: "↓"
|
|
324
|
+
},
|
|
325
|
+
ArrowLeft: {
|
|
326
|
+
mac: "←",
|
|
327
|
+
other: "←"
|
|
328
|
+
},
|
|
329
|
+
ArrowRight: {
|
|
330
|
+
mac: "→",
|
|
331
|
+
other: "→"
|
|
332
|
+
},
|
|
333
|
+
Escape: {
|
|
334
|
+
mac: "⎋",
|
|
335
|
+
other: "Esc"
|
|
336
|
+
},
|
|
337
|
+
Enter: {
|
|
338
|
+
mac: "↩",
|
|
339
|
+
other: "Enter"
|
|
340
|
+
},
|
|
341
|
+
Backspace: {
|
|
342
|
+
mac: "⌫",
|
|
343
|
+
other: "Backspace"
|
|
344
|
+
},
|
|
345
|
+
Delete: {
|
|
346
|
+
mac: "⌦",
|
|
347
|
+
other: "Delete"
|
|
348
|
+
},
|
|
349
|
+
" ": {
|
|
350
|
+
mac: "Space",
|
|
351
|
+
other: "Space"
|
|
352
|
+
},
|
|
353
|
+
Tab: {
|
|
354
|
+
mac: "⇥",
|
|
355
|
+
other: "Tab"
|
|
356
|
+
},
|
|
357
|
+
Home: {
|
|
358
|
+
mac: "↖",
|
|
359
|
+
other: "Home"
|
|
360
|
+
},
|
|
361
|
+
End: {
|
|
362
|
+
mac: "↘",
|
|
363
|
+
other: "End"
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
/** A chord as a person reads it on this platform: "⌘⇧Z" on macOS, "Ctrl+Shift+Z" elsewhere. */
|
|
367
|
+
function formatChord(chord, platform = detectPlatform()) {
|
|
368
|
+
const c = parseChord(chord, platform);
|
|
369
|
+
const key = NAMES[c.key]?.[platform] ?? (c.key.length === 1 ? c.key.toUpperCase() : c.key);
|
|
370
|
+
if (platform === "mac") return `${c.ctrl ? "⌃" : ""}${c.alt ? "⌥" : ""}${c.shift ? "⇧" : ""}${c.meta ? "⌘" : ""}${key}`;
|
|
371
|
+
return [
|
|
372
|
+
c.ctrl && "Ctrl",
|
|
373
|
+
c.meta && "Meta",
|
|
374
|
+
c.alt && "Alt",
|
|
375
|
+
c.shift && "Shift",
|
|
376
|
+
key
|
|
377
|
+
].filter(Boolean).join("+");
|
|
378
|
+
}
|
|
379
|
+
var RESERVED = [
|
|
380
|
+
"Mod+S",
|
|
381
|
+
"Mod+P",
|
|
382
|
+
"Mod+F",
|
|
383
|
+
"Mod+G",
|
|
384
|
+
"Mod+O",
|
|
385
|
+
"Mod+N",
|
|
386
|
+
"Mod+T",
|
|
387
|
+
"Mod+W",
|
|
388
|
+
"Mod+R",
|
|
389
|
+
"Mod+L",
|
|
390
|
+
"Mod+D",
|
|
391
|
+
"Mod+Q",
|
|
392
|
+
"Mod+H",
|
|
393
|
+
"Mod+J",
|
|
394
|
+
"Mod+U",
|
|
395
|
+
"Mod+Shift+T",
|
|
396
|
+
"Mod+Shift+N",
|
|
397
|
+
"Mod+Shift+W",
|
|
398
|
+
"Alt+ArrowLeft",
|
|
399
|
+
"Alt+ArrowRight",
|
|
400
|
+
"F5",
|
|
401
|
+
"F11",
|
|
402
|
+
"F12"
|
|
403
|
+
];
|
|
404
|
+
/** Whether the browser uses this chord for itself, so a command may take it only with `claim`. */
|
|
405
|
+
function isReservedChord(chord, platform = detectPlatform()) {
|
|
406
|
+
const c = parseChord(chord, platform);
|
|
407
|
+
return RESERVED.some((r) => {
|
|
408
|
+
const p = parseChord(r, platform);
|
|
409
|
+
return p.ctrl === c.ctrl && p.meta === c.meta && p.alt === c.alt && p.shift === c.shift && p.key.toLowerCase() === c.key.toLowerCase();
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
// src/components/hotkeys.tsx
|
|
413
|
+
var TEXT_INPUTS_EXEMPT = /* @__PURE__ */ new Set([
|
|
414
|
+
"checkbox",
|
|
415
|
+
"radio",
|
|
416
|
+
"button",
|
|
417
|
+
"submit",
|
|
418
|
+
"reset",
|
|
419
|
+
"range",
|
|
420
|
+
"color",
|
|
421
|
+
"file"
|
|
422
|
+
]);
|
|
423
|
+
/** True when a key pressed on this element is the person typing, so single-key shortcuts must leave it alone. */
|
|
424
|
+
function isTypingTarget(target) {
|
|
425
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
426
|
+
if (target.isContentEditable || target.closest("[contenteditable=''],[contenteditable='true']")) return true;
|
|
427
|
+
if (target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return true;
|
|
428
|
+
if (target instanceof HTMLInputElement) return !TEXT_INPUTS_EXEMPT.has(target.type);
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
function toShortcuts(input) {
|
|
432
|
+
return Array.isArray(input) ? input : Object.entries(input).map(([key, run]) => ({
|
|
433
|
+
keys: [key],
|
|
434
|
+
label: key,
|
|
435
|
+
run
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Binds single-key shortcuts on the window, ignoring keys typed into fields, chords with Ctrl, Meta
|
|
440
|
+
* or Alt, IME composition and (unless `repeat`) held keys. Pass the same list to `KeysLegend`.
|
|
441
|
+
*/
|
|
442
|
+
function useHotkeys(shortcuts, { enabled = true } = {}) {
|
|
443
|
+
const latest = React.useRef([]);
|
|
444
|
+
latest.current = toShortcuts(shortcuts);
|
|
184
445
|
React.useEffect(() => {
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
446
|
+
if (!enabled) return;
|
|
447
|
+
const onKeyDown = (e) => {
|
|
448
|
+
if (e.defaultPrevented || e.isComposing || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
449
|
+
if (isTypingTarget(e.target)) return;
|
|
450
|
+
const hit = latest.current.find((s) => !s.disabled && s.keys.includes(e.key));
|
|
451
|
+
if (!hit || e.repeat && !hit.repeat) return;
|
|
452
|
+
e.preventDefault();
|
|
453
|
+
hit.run();
|
|
454
|
+
};
|
|
455
|
+
window.addEventListener("keydown", onKeyDown);
|
|
456
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
457
|
+
}, [enabled]);
|
|
458
|
+
}
|
|
459
|
+
var KEY_NAMES = {
|
|
460
|
+
ArrowDown: "↓",
|
|
461
|
+
ArrowUp: "↑",
|
|
462
|
+
ArrowLeft: "←",
|
|
463
|
+
ArrowRight: "→",
|
|
464
|
+
Escape: "Esc",
|
|
465
|
+
Enter: "Enter",
|
|
466
|
+
Backspace: "Backspace",
|
|
467
|
+
Delete: "Delete",
|
|
468
|
+
" ": "Space"
|
|
469
|
+
};
|
|
470
|
+
/** A quiet legend of the screen's shortcuts, from the same list `useHotkeys` binds. Hidden on touch screens. */
|
|
471
|
+
function KeysLegend({ shortcuts, label = "Keyboard shortcuts", className }) {
|
|
472
|
+
return /* @__PURE__ */ jsx("dl", {
|
|
473
|
+
"aria-label": label,
|
|
474
|
+
className: cn("flex flex-wrap gap-x-4 gap-y-1 type-caption text-muted-foreground pointer-coarse:hidden", className),
|
|
475
|
+
children: shortcuts.map((s) => /* @__PURE__ */ jsxs("div", {
|
|
476
|
+
className: cn("flex items-center gap-1.5", s.disabled && "opacity-50"),
|
|
477
|
+
children: [/* @__PURE__ */ jsx("dt", {
|
|
478
|
+
className: "flex items-center gap-1",
|
|
479
|
+
children: s.keys.map((k, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("span", {
|
|
480
|
+
className: "sr-only",
|
|
481
|
+
children: " or "
|
|
482
|
+
}), /* @__PURE__ */ jsx("kbd", {
|
|
483
|
+
className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono text-foreground",
|
|
484
|
+
children: KEY_NAMES[k] ?? k
|
|
485
|
+
})] }, k))
|
|
486
|
+
}), /* @__PURE__ */ jsx("dd", { children: s.label })]
|
|
487
|
+
}, s.keys.join(" ")))
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
// src/components/commands.tsx
|
|
491
|
+
/** The text of a command's label, whether it is a string or a function. */
|
|
492
|
+
var labelOf = (c) => typeof c.label === "function" ? c.label() : c.label;
|
|
493
|
+
var isDisabled = (c) => Boolean(c.disabled);
|
|
494
|
+
var reasonOf = (c) => typeof c.disabled === "string" ? c.disabled : void 0;
|
|
495
|
+
var isCommand = (e) => typeof e === "object" && "run" in e;
|
|
496
|
+
/**
|
|
497
|
+
* Binds every command's chords on the window. Never while typing (unless the command says
|
|
498
|
+
* `inFields`), never during IME composition, not on a held key (unless `repeat`), not for a disabled
|
|
499
|
+
* command, and not for a chord the browser uses unless the command `claim`s it. A command's chord
|
|
500
|
+
* that clashes with another's is a mistake: the first in the list wins, and a dev warning names both.
|
|
501
|
+
*/
|
|
502
|
+
function useCommands(commands, { enabled = true, platform } = {}) {
|
|
503
|
+
const latest = React.useRef([]);
|
|
504
|
+
latest.current = commands;
|
|
505
|
+
const where = platform ?? detectPlatform();
|
|
506
|
+
React.useEffect(() => {
|
|
507
|
+
if (!enabled) return;
|
|
508
|
+
const onKeyDown = (e) => {
|
|
509
|
+
if (e.defaultPrevented || e.isComposing) return;
|
|
510
|
+
for (const c of latest.current) {
|
|
511
|
+
const chord = c.keys?.find((k) => matchesChord(e, k, where));
|
|
512
|
+
if (!chord) continue;
|
|
513
|
+
if (isReservedChord(chord, where) && !c.claim) continue;
|
|
514
|
+
if (isTypingTarget(e.target) && !c.inFields) continue;
|
|
515
|
+
if (isDisabled(c) || e.repeat && !c.repeat) return;
|
|
516
|
+
e.preventDefault();
|
|
517
|
+
c.run();
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
window.addEventListener("keydown", onKeyDown);
|
|
522
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
523
|
+
}, [enabled, where]);
|
|
524
|
+
}
|
|
525
|
+
/** The shortcut a command shows in menus and legends ("⌘Z", "Ctrl+Z"), or undefined. */
|
|
526
|
+
function commandShortcut(c, platform = detectPlatform()) {
|
|
527
|
+
return c.keys?.[0] ? formatChord(c.keys[0], platform) : void 0;
|
|
528
|
+
}
|
|
529
|
+
/** A quiet legend built from the same commands the key handler runs: only commands with keys, disabled ones muted. */
|
|
530
|
+
function CommandLegend({ commands, platform, label = "Keyboard shortcuts", className }) {
|
|
531
|
+
const where = platform ?? detectPlatform();
|
|
532
|
+
const shown = commands.filter((c) => c.keys?.length);
|
|
533
|
+
return /* @__PURE__ */ jsx("dl", {
|
|
534
|
+
"aria-label": label,
|
|
535
|
+
className: cn("flex flex-wrap gap-x-4 gap-y-1 type-caption text-muted-foreground pointer-coarse:hidden", className),
|
|
536
|
+
children: shown.map((c) => /* @__PURE__ */ jsxs("div", {
|
|
537
|
+
className: cn("flex items-center gap-1.5", isDisabled(c) && "opacity-50"),
|
|
538
|
+
children: [/* @__PURE__ */ jsx("dt", { children: /* @__PURE__ */ jsx("kbd", {
|
|
539
|
+
className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono text-foreground",
|
|
540
|
+
children: commandShortcut(c, where)
|
|
541
|
+
}) }), /* @__PURE__ */ jsx("dd", { children: labelOf(c) })]
|
|
542
|
+
}, c.id))
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
var itemClass = cn("flex min-h-(--control-h-sm) cursor-pointer items-center gap-2 rounded-control px-2 type-body-sm outline-none", "data-[focused]:bg-muted data-[disabled]:cursor-not-allowed data-[disabled]:text-muted-foreground data-[disabled]:opacity-70", "data-[open]:bg-muted");
|
|
546
|
+
function Item({ command, platform }) {
|
|
547
|
+
const Icon = command.icon ?? (command.destructive ? Trash2 : void 0);
|
|
548
|
+
const shortcut = commandShortcut(command, platform);
|
|
549
|
+
const reason = reasonOf(command);
|
|
550
|
+
return /* @__PURE__ */ jsx(MenuItem, {
|
|
551
|
+
id: command.id,
|
|
552
|
+
textValue: labelOf(command),
|
|
553
|
+
isDisabled: isDisabled(command),
|
|
554
|
+
onAction: command.run,
|
|
555
|
+
className: cn(itemClass, command.destructive && !isDisabled(command) && "text-danger", "flex-wrap"),
|
|
556
|
+
children: ({ isSelected, selectionMode }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
557
|
+
selectionMode !== "none" ? /* @__PURE__ */ jsx("span", {
|
|
558
|
+
"aria-hidden": true,
|
|
559
|
+
className: "grid size-4 shrink-0 place-items-center",
|
|
560
|
+
children: isSelected && /* @__PURE__ */ jsx(Check, { className: "size-4" })
|
|
561
|
+
}) : Icon && /* @__PURE__ */ jsx(Icon, {
|
|
562
|
+
"aria-hidden": true,
|
|
563
|
+
className: "size-4 shrink-0"
|
|
564
|
+
}),
|
|
565
|
+
/* @__PURE__ */ jsx(Text, {
|
|
566
|
+
slot: "label",
|
|
567
|
+
className: "min-w-0 flex-1 truncate",
|
|
568
|
+
children: labelOf(command)
|
|
569
|
+
}),
|
|
570
|
+
shortcut && /* @__PURE__ */ jsx(Keyboard, {
|
|
571
|
+
className: "ml-6 shrink-0 font-mono type-caption text-muted-foreground",
|
|
572
|
+
children: shortcut
|
|
573
|
+
}),
|
|
574
|
+
reason && /* @__PURE__ */ jsx(Text, {
|
|
575
|
+
slot: "description",
|
|
576
|
+
className: "w-full pl-6 type-caption text-muted-foreground",
|
|
577
|
+
children: reason
|
|
578
|
+
})
|
|
579
|
+
] })
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
function Entries({ entries, platform }) {
|
|
583
|
+
return /* @__PURE__ */ jsx(Fragment, { children: entries.map((entry, i) => {
|
|
584
|
+
if (entry === "separator") return /* @__PURE__ */ jsx(Separator, { className: "my-1 h-px border-0 bg-border" }, `sep-${i}`);
|
|
585
|
+
if (isCommand(entry)) return /* @__PURE__ */ jsx(Item, {
|
|
586
|
+
command: entry,
|
|
587
|
+
platform
|
|
588
|
+
}, entry.id);
|
|
589
|
+
if ("group" in entry) {
|
|
590
|
+
const checkable = entry.items.length > 0 && entry.items.every((c) => c.checked !== void 0);
|
|
591
|
+
return /* @__PURE__ */ jsxs(MenuSection, {
|
|
592
|
+
selectionMode: checkable ? "multiple" : void 0,
|
|
593
|
+
selectedKeys: checkable ? entry.items.filter((c) => c.checked).map((c) => c.id) : void 0,
|
|
594
|
+
children: [/* @__PURE__ */ jsx(Header, {
|
|
595
|
+
className: "px-2 pt-1 type-caption text-muted-foreground",
|
|
596
|
+
children: entry.group
|
|
597
|
+
}), entry.items.map((c) => /* @__PURE__ */ jsx(Item, {
|
|
598
|
+
command: c,
|
|
599
|
+
platform
|
|
600
|
+
}, c.id))]
|
|
601
|
+
}, `group-${entry.group}`);
|
|
602
|
+
}
|
|
603
|
+
return /* @__PURE__ */ jsxs(SubmenuTrigger, { children: [/* @__PURE__ */ jsxs(MenuItem, {
|
|
604
|
+
textValue: entry.submenu,
|
|
605
|
+
className: itemClass,
|
|
606
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
607
|
+
slot: "label",
|
|
608
|
+
className: "min-w-0 flex-1 truncate",
|
|
609
|
+
children: entry.submenu
|
|
610
|
+
}), /* @__PURE__ */ jsx(ChevronRight, {
|
|
611
|
+
"aria-hidden": true,
|
|
612
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
613
|
+
})]
|
|
614
|
+
}), /* @__PURE__ */ jsx(Popover$1, {
|
|
615
|
+
offset: 0,
|
|
616
|
+
crossOffset: -4,
|
|
617
|
+
className: cn("layer-overlay min-w-48 p-1", overlaySurface),
|
|
618
|
+
children: /* @__PURE__ */ jsx(Menu$1, {
|
|
619
|
+
"aria-label": entry.submenu,
|
|
620
|
+
className: "outline-none",
|
|
621
|
+
children: /* @__PURE__ */ jsx(Entries, {
|
|
622
|
+
entries: entry.items,
|
|
623
|
+
platform
|
|
624
|
+
})
|
|
625
|
+
})
|
|
626
|
+
})] }, `sub-${entry.submenu}`);
|
|
627
|
+
}) });
|
|
628
|
+
}
|
|
629
|
+
var surface = cn("layer-overlay min-w-48 p-1", overlaySurface);
|
|
630
|
+
/** A dropdown menu of commands: the menu roles and keyboard model, shortcuts shown per platform, unavailable items with their reason, separators, groups, checkable groups and submenus. */
|
|
631
|
+
function Menu({ label, trigger, items, open, onOpenChange, platform, className }) {
|
|
632
|
+
const where = platform ?? detectPlatform();
|
|
633
|
+
return /* @__PURE__ */ jsxs(MenuTrigger, {
|
|
634
|
+
isOpen: open,
|
|
635
|
+
onOpenChange,
|
|
636
|
+
children: [trigger, /* @__PURE__ */ jsx(Popover$1, {
|
|
637
|
+
placement: "bottom start",
|
|
638
|
+
offset: 4,
|
|
639
|
+
className: cn(surface, className),
|
|
640
|
+
children: /* @__PURE__ */ jsx(Menu$1, {
|
|
641
|
+
"aria-label": label,
|
|
642
|
+
className: "outline-none",
|
|
643
|
+
children: /* @__PURE__ */ jsx(Entries, {
|
|
644
|
+
entries: items,
|
|
645
|
+
platform: where
|
|
646
|
+
})
|
|
647
|
+
})
|
|
648
|
+
})]
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* A context menu for an object: opens on right-click at the pointer, and from the keyboard (the
|
|
653
|
+
* context-menu key or Shift+F10) beside the focused object, with the same items and shortcuts as
|
|
654
|
+
* every other menu. The child gets the handlers, so it should be focusable (a row, a clip).
|
|
655
|
+
*/
|
|
656
|
+
function ContextMenu({ label, items, children, platform, disabled }) {
|
|
657
|
+
const where = platform ?? detectPlatform();
|
|
658
|
+
const [at, setAt] = React.useState(null);
|
|
659
|
+
const anchor = React.useRef(null);
|
|
660
|
+
const open = (x, y) => setAt({
|
|
661
|
+
x,
|
|
662
|
+
y
|
|
663
|
+
});
|
|
664
|
+
const child = React.Children.only(children);
|
|
665
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
666
|
+
React.cloneElement(child, {
|
|
667
|
+
onContextMenu: (e) => {
|
|
668
|
+
child.props.onContextMenu?.(e);
|
|
669
|
+
if (disabled || e.defaultPrevented) return;
|
|
670
|
+
e.preventDefault();
|
|
671
|
+
open(e.clientX, e.clientY);
|
|
672
|
+
},
|
|
673
|
+
onKeyDown: (e) => {
|
|
674
|
+
child.props.onKeyDown?.(e);
|
|
675
|
+
if (disabled || e.defaultPrevented) return;
|
|
676
|
+
if (e.key === "ContextMenu" || e.key === "F10" && e.shiftKey) {
|
|
677
|
+
e.preventDefault();
|
|
678
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
679
|
+
open(r.left + 8, r.bottom);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}),
|
|
683
|
+
at && /* @__PURE__ */ jsx("span", {
|
|
684
|
+
ref: anchor,
|
|
685
|
+
"aria-hidden": true,
|
|
686
|
+
style: {
|
|
687
|
+
position: "fixed",
|
|
688
|
+
left: at.x,
|
|
689
|
+
top: at.y,
|
|
690
|
+
width: 0,
|
|
691
|
+
height: 0
|
|
692
|
+
}
|
|
693
|
+
}),
|
|
694
|
+
/* @__PURE__ */ jsx(Popover$1, {
|
|
695
|
+
triggerRef: anchor,
|
|
696
|
+
isOpen: at !== null,
|
|
697
|
+
onOpenChange: (o) => !o && setAt(null),
|
|
698
|
+
placement: "bottom start",
|
|
699
|
+
offset: 0,
|
|
700
|
+
className: surface,
|
|
701
|
+
children: /* @__PURE__ */ jsx(Menu$1, {
|
|
702
|
+
"aria-label": label,
|
|
703
|
+
autoFocus: "first",
|
|
704
|
+
onAction: () => setAt(null),
|
|
705
|
+
className: "outline-none",
|
|
706
|
+
children: /* @__PURE__ */ jsx(Entries, {
|
|
707
|
+
entries: items,
|
|
708
|
+
platform: where
|
|
709
|
+
})
|
|
710
|
+
})
|
|
711
|
+
})
|
|
712
|
+
] });
|
|
713
|
+
}
|
|
714
|
+
function flatten(entries) {
|
|
715
|
+
return entries.flatMap((e) => e === "separator" ? [] : isCommand(e) ? [e] : flatten(e.items));
|
|
716
|
+
}
|
|
717
|
+
/** A searchable list of every command, opened by a chord (default Mod+K). Choosing one closes it and runs it; an unavailable command is shown with its reason and does nothing. */
|
|
718
|
+
function CommandMenu({ commands, open, onOpenChange, shortcut = "Mod+K", label = "Search commands", platform }) {
|
|
719
|
+
const where = platform ?? detectPlatform();
|
|
720
|
+
const [own, setOwn] = React.useState(false);
|
|
721
|
+
const isOpen = open ?? own;
|
|
722
|
+
const set = (next) => {
|
|
723
|
+
setOwn(next);
|
|
724
|
+
onOpenChange?.(next);
|
|
725
|
+
};
|
|
726
|
+
React.useEffect(() => {
|
|
727
|
+
if (!shortcut) return;
|
|
728
|
+
const onKeyDown = (e) => {
|
|
729
|
+
if (e.defaultPrevented || e.isComposing || !matchesChord(e, shortcut, where)) return;
|
|
730
|
+
e.preventDefault();
|
|
731
|
+
if (e.repeat) return;
|
|
732
|
+
set(!isOpen);
|
|
733
|
+
};
|
|
734
|
+
window.addEventListener("keydown", onKeyDown);
|
|
735
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
736
|
+
});
|
|
737
|
+
const { contains } = useFilter({ sensitivity: "base" });
|
|
738
|
+
const all = flatten(commands);
|
|
739
|
+
return /* @__PURE__ */ jsx(ModalOverlay, {
|
|
740
|
+
isOpen,
|
|
741
|
+
onOpenChange: set,
|
|
742
|
+
isDismissable: true,
|
|
743
|
+
className: "layer-overlay fixed inset-0 grid justify-items-center overflow-hidden bg-foreground/40 p-4 pt-24",
|
|
744
|
+
children: /* @__PURE__ */ jsxs(Modal, {
|
|
745
|
+
className: cn("flex max-h-full w-full max-w-lg flex-col self-start outline-none", overlaySurface),
|
|
746
|
+
children: [/* @__PURE__ */ jsx(Dialog$1, {
|
|
747
|
+
"aria-label": label,
|
|
748
|
+
className: "flex min-h-0 flex-col outline-none",
|
|
749
|
+
children: /* @__PURE__ */ jsxs(Autocomplete, {
|
|
750
|
+
filter: contains,
|
|
751
|
+
children: [/* @__PURE__ */ jsxs(SearchField, {
|
|
752
|
+
"aria-label": label,
|
|
753
|
+
autoFocus: true,
|
|
754
|
+
className: "flex items-center gap-2 border-b border-border px-3",
|
|
755
|
+
children: [/* @__PURE__ */ jsx(Search, {
|
|
756
|
+
"aria-hidden": true,
|
|
757
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
758
|
+
}), /* @__PURE__ */ jsx(Input$1, {
|
|
759
|
+
placeholder: label,
|
|
760
|
+
className: "h-(--control-h) min-w-0 flex-1 bg-transparent type-body outline-none placeholder:text-muted-foreground"
|
|
761
|
+
})]
|
|
762
|
+
}), /* @__PURE__ */ jsx(Menu$1, {
|
|
763
|
+
"aria-label": "Commands",
|
|
764
|
+
className: "min-h-0 overflow-y-auto overscroll-contain p-1 outline-none",
|
|
765
|
+
renderEmptyState: () => /* @__PURE__ */ jsx("p", {
|
|
766
|
+
className: "px-3 py-4 type-body-sm text-muted-foreground",
|
|
767
|
+
children: "No command matches."
|
|
768
|
+
}),
|
|
769
|
+
onAction: () => set(false),
|
|
770
|
+
children: all.map((c) => /* @__PURE__ */ jsx(Item, {
|
|
771
|
+
command: c,
|
|
772
|
+
platform: where
|
|
773
|
+
}, c.id))
|
|
774
|
+
})]
|
|
775
|
+
})
|
|
776
|
+
}), /* @__PURE__ */ jsx(Heading, {
|
|
777
|
+
slot: "title",
|
|
778
|
+
className: "sr-only",
|
|
779
|
+
children: label
|
|
780
|
+
})]
|
|
781
|
+
})
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
// src/components/toolbar.tsx
|
|
785
|
+
/** A group of controls with one tab stop and arrow-key movement (the WAI-ARIA toolbar pattern). Needs a `label`. */
|
|
786
|
+
function Toolbar({ label, orientation = "horizontal", children, className }) {
|
|
787
|
+
const jump = (e) => {
|
|
788
|
+
if (e.key !== "Home" && e.key !== "End" || isTypingTarget(e.target) || !e.currentTarget.contains(e.target)) return;
|
|
789
|
+
const items = [...e.currentTarget.querySelectorAll("button, input, select, textarea, a[href], [tabindex]")].filter((el) => !el.hasAttribute("disabled") && el.getAttribute("aria-disabled") !== "true" && el.tabIndex >= -1 && el.getAttribute("role") !== "separator");
|
|
790
|
+
const target = e.key === "Home" ? items[0] : items[items.length - 1];
|
|
791
|
+
if (!target) return;
|
|
792
|
+
e.preventDefault();
|
|
793
|
+
e.stopPropagation();
|
|
794
|
+
target.focus();
|
|
795
|
+
};
|
|
796
|
+
return /* @__PURE__ */ jsx("div", {
|
|
797
|
+
className: "contents",
|
|
798
|
+
onKeyDownCapture: jump,
|
|
799
|
+
children: /* @__PURE__ */ jsx(Toolbar$1, {
|
|
800
|
+
"aria-label": label,
|
|
801
|
+
orientation,
|
|
802
|
+
className: cn("flex flex-wrap items-center gap-1", orientation === "vertical" && "flex-col items-stretch", className),
|
|
803
|
+
children
|
|
804
|
+
})
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
/** A hairline between groups of controls inside a `Toolbar`. */
|
|
808
|
+
function ToolbarSeparator({ className }) {
|
|
809
|
+
return /* @__PURE__ */ jsx(Separator, { className: cn("mx-1 h-5 w-px self-center border-0 bg-border", className) });
|
|
810
|
+
}
|
|
811
|
+
// src/components/toggle.tsx
|
|
812
|
+
var base = "inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control border type-label transition-state press [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 border-input bg-background text-muted-foreground data-[hovered]:bg-muted data-[hovered]:text-foreground data-[selected]:border-foreground data-[selected]:bg-muted data-[selected]:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50";
|
|
813
|
+
var sizes$1 = {
|
|
814
|
+
default: "h-(--control-h)",
|
|
815
|
+
sm: "h-(--control-h-sm)"
|
|
816
|
+
};
|
|
817
|
+
function Face({ label, icon: Icon, iconOnly, pad }) {
|
|
818
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), !iconOnly && /* @__PURE__ */ jsx("span", {
|
|
819
|
+
className: pad,
|
|
820
|
+
children: label
|
|
821
|
+
})] });
|
|
822
|
+
}
|
|
823
|
+
/** A button that is pressed or not (`aria-pressed`). Chosen reads as an ink border on a tint, never as the filled primary. */
|
|
824
|
+
function Toggle({ label, icon, iconOnly = false, pressed, defaultPressed, onChange, disabled, size = "default", className }) {
|
|
825
|
+
const button = /* @__PURE__ */ jsx(ToggleButton, {
|
|
826
|
+
isSelected: pressed,
|
|
827
|
+
defaultSelected: defaultPressed,
|
|
828
|
+
onChange,
|
|
829
|
+
isDisabled: disabled,
|
|
830
|
+
"aria-label": icon && iconOnly ? label : void 0,
|
|
831
|
+
className: cn(base, sizes$1[size], icon && iconOnly ? size === "sm" ? "size-(--control-h-sm)" : "size-(--control-h)" : "px-3", className),
|
|
832
|
+
children: /* @__PURE__ */ jsx(Face, {
|
|
833
|
+
label,
|
|
834
|
+
icon,
|
|
835
|
+
iconOnly: iconOnly && Boolean(icon),
|
|
836
|
+
pad: ""
|
|
837
|
+
})
|
|
838
|
+
});
|
|
839
|
+
return icon && iconOnly ? /* @__PURE__ */ jsx(Tooltip, {
|
|
840
|
+
label,
|
|
841
|
+
children: button
|
|
842
|
+
}) : button;
|
|
843
|
+
}
|
|
844
|
+
/** A single-choice set of toggle buttons for 2 to 7 short options that switch a view. One is always chosen; arrow keys move between them. */
|
|
845
|
+
function ToggleGroup({ label, options, value, onChange, size = "default", className }) {
|
|
846
|
+
return /* @__PURE__ */ jsx(ToggleButtonGroup, {
|
|
847
|
+
"aria-label": label,
|
|
848
|
+
selectionMode: "single",
|
|
849
|
+
disallowEmptySelection: true,
|
|
850
|
+
selectedKeys: [value],
|
|
851
|
+
onSelectionChange: (keys) => {
|
|
852
|
+
const next = [...keys][0];
|
|
853
|
+
if (next !== void 0) onChange(String(next));
|
|
854
|
+
},
|
|
855
|
+
className: cn("inline-flex gap-0.5 rounded-surface border border-border bg-background p-0.5", className),
|
|
856
|
+
children: options.map((o) => {
|
|
857
|
+
const iconOnly = Boolean(o.icon && o.iconOnly);
|
|
858
|
+
const item = /* @__PURE__ */ jsx(ToggleButton, {
|
|
859
|
+
id: o.value,
|
|
860
|
+
"aria-label": iconOnly ? o.label : void 0,
|
|
861
|
+
className: cn(base, "border-transparent bg-transparent data-[selected]:border-foreground", sizes$1[size], iconOnly ? size === "sm" ? "size-(--control-h-sm)" : "size-(--control-h)" : "px-3"),
|
|
862
|
+
children: /* @__PURE__ */ jsx(Face, {
|
|
863
|
+
label: o.label,
|
|
864
|
+
icon: o.icon,
|
|
865
|
+
iconOnly,
|
|
866
|
+
pad: ""
|
|
867
|
+
})
|
|
868
|
+
});
|
|
869
|
+
return iconOnly ? /* @__PURE__ */ jsx(Tooltip, {
|
|
870
|
+
label: o.label,
|
|
871
|
+
children: item
|
|
872
|
+
}, o.value) : React.cloneElement(item, { key: o.value });
|
|
873
|
+
})
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
// src/components/switch.tsx
|
|
877
|
+
/** An on/off setting that applies at once, its label and control one target. */
|
|
878
|
+
function Switch({ label, detail, on, defaultOn, onChange, disabled, className }) {
|
|
879
|
+
return /* @__PURE__ */ jsxs(Switch$1, {
|
|
880
|
+
isSelected: on,
|
|
881
|
+
defaultSelected: defaultOn,
|
|
882
|
+
onChange,
|
|
883
|
+
isDisabled: disabled,
|
|
884
|
+
className: cn("group inline-flex min-h-6 cursor-pointer items-start gap-3 data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50", className),
|
|
885
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
886
|
+
"aria-hidden": true,
|
|
887
|
+
className: cn("mt-0.5 flex h-5 w-9 shrink-0 items-center rounded-pill border border-input bg-muted p-0.5 transition-state", "group-data-[selected]:border-primary group-data-[selected]:bg-primary", "group-data-[focus-visible]:outline-2 group-data-[focus-visible]:outline-offset-2 group-data-[focus-visible]:outline-ring"),
|
|
888
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
889
|
+
className: "grid size-3.5 place-items-center rounded-pill bg-background text-primary group-data-[selected]:translate-x-4",
|
|
890
|
+
children: /* @__PURE__ */ jsx("span", { className: "hidden size-1.5 rounded-pill bg-primary group-data-[selected]:block" })
|
|
891
|
+
})
|
|
892
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
201
893
|
className: "grid",
|
|
202
894
|
children: [/* @__PURE__ */ jsx("span", {
|
|
203
895
|
className: "type-body",
|
|
@@ -209,6 +901,208 @@ function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange,
|
|
|
209
901
|
})]
|
|
210
902
|
});
|
|
211
903
|
}
|
|
904
|
+
// src/components/dialog.tsx
|
|
905
|
+
var sizes = {
|
|
906
|
+
sm: "max-w-sm",
|
|
907
|
+
md: "max-w-lg",
|
|
908
|
+
lg: "max-w-3xl"
|
|
909
|
+
};
|
|
910
|
+
var overlayClass = "layer-overlay fixed inset-0 grid overflow-hidden bg-foreground/40";
|
|
911
|
+
/** A modal dialog with a required title; focus goes in and returns, Escape and a close control dismiss it. `placement="end"` makes it a sheet. */
|
|
912
|
+
function Dialog({ title, description, trigger, open, onOpenChange, className, children, actions, hideTitle, closable = true, placement = "center", size = "md" }) {
|
|
913
|
+
const descriptionId = React.useId();
|
|
914
|
+
return /* @__PURE__ */ jsxs(DialogTrigger, {
|
|
915
|
+
isOpen: open,
|
|
916
|
+
onOpenChange,
|
|
917
|
+
children: [trigger, /* @__PURE__ */ jsx(ModalOverlay, {
|
|
918
|
+
isDismissable: closable,
|
|
919
|
+
isKeyboardDismissDisabled: !closable,
|
|
920
|
+
className: cn(overlayClass, placement === "end" ? "justify-items-end" : "place-items-center p-4"),
|
|
921
|
+
children: /* @__PURE__ */ jsx(Modal, {
|
|
922
|
+
className: cn("flex max-h-full min-h-0 w-full flex-col outline-none", overlaySurface, placement === "end" ? "h-full max-w-md rounded-r-none" : sizes[size], className),
|
|
923
|
+
children: /* @__PURE__ */ jsx(Dialog$1, {
|
|
924
|
+
"aria-describedby": description != null ? descriptionId : void 0,
|
|
925
|
+
className: "flex min-h-0 flex-1 flex-col gap-4 p-4 outline-none",
|
|
926
|
+
children: ({ close }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
927
|
+
/* @__PURE__ */ jsxs("div", {
|
|
928
|
+
className: "flex items-start justify-between gap-4",
|
|
929
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
930
|
+
className: "grid gap-1",
|
|
931
|
+
children: [/* @__PURE__ */ jsx(Heading, {
|
|
932
|
+
slot: "title",
|
|
933
|
+
className: cn("type-heading", hideTitle && "sr-only"),
|
|
934
|
+
children: title
|
|
935
|
+
}), description != null && /* @__PURE__ */ jsx("p", {
|
|
936
|
+
id: descriptionId,
|
|
937
|
+
className: "type-body-sm text-muted-foreground",
|
|
938
|
+
children: description
|
|
939
|
+
})]
|
|
940
|
+
}), closable && /* @__PURE__ */ jsx(IconButton, {
|
|
941
|
+
icon: X,
|
|
942
|
+
label: "Close",
|
|
943
|
+
onPress: close,
|
|
944
|
+
className: "-mr-2 -mt-2 shrink-0"
|
|
945
|
+
})]
|
|
946
|
+
}),
|
|
947
|
+
children != null && /* @__PURE__ */ jsx("div", {
|
|
948
|
+
className: "min-h-0 flex-1 overflow-y-auto overscroll-contain",
|
|
949
|
+
children
|
|
950
|
+
}),
|
|
951
|
+
actions != null && /* @__PURE__ */ jsx("div", {
|
|
952
|
+
className: "flex flex-wrap justify-end gap-2",
|
|
953
|
+
children: typeof actions === "function" ? actions(close) : actions
|
|
954
|
+
})
|
|
955
|
+
] })
|
|
956
|
+
})
|
|
957
|
+
})
|
|
958
|
+
})]
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* A confirm for what cannot be undone. Names the object and the consequence in `title`, repeats the
|
|
963
|
+
* verb on the confirm button, focuses Cancel first and ignores outside presses.
|
|
964
|
+
*/
|
|
965
|
+
function AlertDialog({ title, description, trigger, open, onOpenChange, className, confirm, onConfirm, cancel = "Cancel", tone = "destructive" }) {
|
|
966
|
+
const [busy, setBusy] = React.useState(false);
|
|
967
|
+
const [error, setError] = React.useState();
|
|
968
|
+
const [inner, setInner] = React.useState(false);
|
|
969
|
+
const descriptionId = React.useId();
|
|
970
|
+
const isOpen = open ?? inner;
|
|
971
|
+
const change = (next) => {
|
|
972
|
+
if (busy) return;
|
|
973
|
+
setError(void 0);
|
|
974
|
+
setInner(next);
|
|
975
|
+
onOpenChange?.(next);
|
|
976
|
+
};
|
|
977
|
+
const run = async () => {
|
|
978
|
+
try {
|
|
979
|
+
const result = onConfirm();
|
|
980
|
+
if (result && typeof result.then === "function") {
|
|
981
|
+
setBusy(true);
|
|
982
|
+
await result;
|
|
983
|
+
}
|
|
984
|
+
setBusy(false);
|
|
985
|
+
change(false);
|
|
986
|
+
} catch (thrown) {
|
|
987
|
+
setBusy(false);
|
|
988
|
+
setError(describeActionError(thrown) ?? "That did not go through. Nothing was confirmed; try again.");
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
return /* @__PURE__ */ jsxs(DialogTrigger, {
|
|
992
|
+
isOpen,
|
|
993
|
+
onOpenChange: change,
|
|
994
|
+
children: [trigger, /* @__PURE__ */ jsx(ModalOverlay, {
|
|
995
|
+
isDismissable: false,
|
|
996
|
+
isKeyboardDismissDisabled: busy,
|
|
997
|
+
className: cn(overlayClass, "place-items-center p-4"),
|
|
998
|
+
children: /* @__PURE__ */ jsx(Modal, {
|
|
999
|
+
className: cn("flex max-h-full w-full max-w-sm flex-col outline-none", overlaySurface, className),
|
|
1000
|
+
children: /* @__PURE__ */ jsx(Dialog$1, {
|
|
1001
|
+
role: "alertdialog",
|
|
1002
|
+
"aria-describedby": description != null ? descriptionId : void 0,
|
|
1003
|
+
className: "flex min-h-0 flex-1 flex-col gap-4 p-4 outline-none",
|
|
1004
|
+
children: ({ close }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1005
|
+
className: "grid min-h-0 gap-3 overflow-y-auto overscroll-contain",
|
|
1006
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1007
|
+
className: "grid gap-1",
|
|
1008
|
+
children: [/* @__PURE__ */ jsx(Heading, {
|
|
1009
|
+
slot: "title",
|
|
1010
|
+
className: "type-heading",
|
|
1011
|
+
children: title
|
|
1012
|
+
}), description != null && /* @__PURE__ */ jsx("p", {
|
|
1013
|
+
id: descriptionId,
|
|
1014
|
+
className: "type-body-sm text-muted-foreground",
|
|
1015
|
+
children: description
|
|
1016
|
+
})]
|
|
1017
|
+
}), error && /* @__PURE__ */ jsx("p", {
|
|
1018
|
+
role: "alert",
|
|
1019
|
+
className: "rounded-control bg-danger-subtle px-3 py-2 type-body-sm text-danger",
|
|
1020
|
+
children: error
|
|
1021
|
+
})]
|
|
1022
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1023
|
+
className: "flex flex-wrap justify-end gap-2",
|
|
1024
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1025
|
+
autoFocus: true,
|
|
1026
|
+
disabled: busy,
|
|
1027
|
+
onPress: close,
|
|
1028
|
+
children: cancel
|
|
1029
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1030
|
+
variant: tone === "destructive" ? "destructive" : "default",
|
|
1031
|
+
disabled: busy,
|
|
1032
|
+
"aria-busy": busy || void 0,
|
|
1033
|
+
onPress: run,
|
|
1034
|
+
children: busy ? `${confirm}…` : confirm
|
|
1035
|
+
})]
|
|
1036
|
+
})] })
|
|
1037
|
+
})
|
|
1038
|
+
})
|
|
1039
|
+
})]
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
// src/components/popover.tsx
|
|
1043
|
+
var widths = {
|
|
1044
|
+
sm: "w-52",
|
|
1045
|
+
md: "w-72",
|
|
1046
|
+
lg: "w-96"
|
|
1047
|
+
};
|
|
1048
|
+
/** A floating panel anchored to its trigger, for a small form or choice. Requires a `label`; closes on Escape and outside press, and returns focus. */
|
|
1049
|
+
function Popover({ label, trigger, children, side = "bottom", align = "start", open, onOpenChange, size = "md", className }) {
|
|
1050
|
+
const placement = align === "center" ? side : `${side} ${align}`;
|
|
1051
|
+
return /* @__PURE__ */ jsxs(DialogTrigger, {
|
|
1052
|
+
isOpen: open,
|
|
1053
|
+
onOpenChange,
|
|
1054
|
+
children: [trigger, /* @__PURE__ */ jsx(Popover$1, {
|
|
1055
|
+
placement,
|
|
1056
|
+
offset: 6,
|
|
1057
|
+
className: cn("layer-overlay p-3", widths[size], overlaySurface, className),
|
|
1058
|
+
children: /* @__PURE__ */ jsx(Dialog$1, {
|
|
1059
|
+
"aria-label": label,
|
|
1060
|
+
className: "outline-none",
|
|
1061
|
+
children
|
|
1062
|
+
})
|
|
1063
|
+
})]
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
// src/components/checkbox.tsx
|
|
1067
|
+
/** A checkbox and its label as one target. `label` is required; `hideLabel` keeps it as the accessible name only. */
|
|
1068
|
+
function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange, className, disabled, required, ...props }) {
|
|
1069
|
+
const shift = useShiftNote();
|
|
1070
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1071
|
+
className: "contents",
|
|
1072
|
+
onMouseDownCapture: shift.handlers.onMouseDown,
|
|
1073
|
+
onKeyDownCapture: shift.handlers.onKeyDown,
|
|
1074
|
+
children: /* @__PURE__ */ jsx(Checkbox$1, {
|
|
1075
|
+
isSelected: checked === true,
|
|
1076
|
+
isIndeterminate: checked === "mixed",
|
|
1077
|
+
isDisabled: disabled,
|
|
1078
|
+
isRequired: required,
|
|
1079
|
+
onChange: (selected) => onCheckedChange(selected, shift.take()),
|
|
1080
|
+
"aria-label": hideLabel ? label : void 0,
|
|
1081
|
+
...props,
|
|
1082
|
+
className: cn("group inline-flex min-h-6 min-w-6 items-start gap-3", hideLabel && "items-center justify-center", disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer", className),
|
|
1083
|
+
children: ({ isSelected, isIndeterminate }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
1084
|
+
"aria-hidden": true,
|
|
1085
|
+
className: cn("grid size-4.5 shrink-0 place-items-center rounded-control border border-input bg-background transition-state", "group-data-[focus-visible]:outline-2 group-data-[focus-visible]:outline-offset-2 group-data-[focus-visible]:outline-ring", (isSelected || isIndeterminate) && "border-primary bg-primary text-primary-foreground", !hideLabel && "mt-0.5"),
|
|
1086
|
+
children: isIndeterminate ? /* @__PURE__ */ jsx(Minus, {
|
|
1087
|
+
className: "size-3.5",
|
|
1088
|
+
strokeWidth: 3
|
|
1089
|
+
}) : isSelected ? /* @__PURE__ */ jsx(Check, {
|
|
1090
|
+
className: "size-3.5",
|
|
1091
|
+
strokeWidth: 3
|
|
1092
|
+
}) : null
|
|
1093
|
+
}), !hideLabel && /* @__PURE__ */ jsxs("span", {
|
|
1094
|
+
className: "grid",
|
|
1095
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1096
|
+
className: "type-body",
|
|
1097
|
+
children: label
|
|
1098
|
+
}), detail && /* @__PURE__ */ jsx("span", {
|
|
1099
|
+
className: "type-body-sm text-muted-foreground",
|
|
1100
|
+
children: detail
|
|
1101
|
+
})]
|
|
1102
|
+
})] })
|
|
1103
|
+
})
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
212
1106
|
/** Notes Shift on the press that leads to a checkbox's change event, which has no modifier keys of its own. */
|
|
213
1107
|
function useShiftNote() {
|
|
214
1108
|
const held = React.useRef(false);
|
|
@@ -243,6 +1137,7 @@ function AsyncButton({ phase, labels, error, disabled, ...props }) {
|
|
|
243
1137
|
const announcement = phase === "done" ? labels.done : phase === "error" ? error ? `${error} ${errorLabel}` : errorLabel : "";
|
|
244
1138
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Button, {
|
|
245
1139
|
...props,
|
|
1140
|
+
"data-phase": phase,
|
|
246
1141
|
disabled: disabled || phase === "pending",
|
|
247
1142
|
"aria-disabled": phase === "pending" || void 0,
|
|
248
1143
|
children: [Icon && /* @__PURE__ */ jsx(Icon, {
|
|
@@ -267,65 +1162,103 @@ function AsyncButton({ phase, labels, error, disabled, ...props }) {
|
|
|
267
1162
|
children: announcement
|
|
268
1163
|
})] });
|
|
269
1164
|
}
|
|
270
|
-
/** Runs an async action and reports its phase and
|
|
271
|
-
function useAsyncAction(action, { settleMs = 2e3, onError, describeError = describeActionError } = {}) {
|
|
272
|
-
const [state, setState] = React.useState(
|
|
273
|
-
phase: "idle",
|
|
274
|
-
error: void 0
|
|
275
|
-
});
|
|
1165
|
+
/** Runs an async action and reports its phase, its error and any field messages. `done` returns to `idle` after `settleMs`; `run` never changes identity. */
|
|
1166
|
+
function useAsyncAction(action, { settleMs = 2e3, onError, describeError = describeActionError, validate, onInvalid } = {}) {
|
|
1167
|
+
const [state, setState] = React.useState(idle);
|
|
276
1168
|
const timer = React.useRef(void 0);
|
|
277
1169
|
const unreported = React.useRef(void 0);
|
|
278
1170
|
const latest = React.useRef({
|
|
279
1171
|
action,
|
|
280
1172
|
onError,
|
|
281
1173
|
settleMs,
|
|
282
|
-
describeError
|
|
1174
|
+
describeError,
|
|
1175
|
+
validate,
|
|
1176
|
+
onInvalid
|
|
283
1177
|
});
|
|
284
1178
|
React.useLayoutEffect(() => {
|
|
285
1179
|
latest.current = {
|
|
286
1180
|
action,
|
|
287
1181
|
onError,
|
|
288
1182
|
settleMs,
|
|
289
|
-
describeError
|
|
1183
|
+
describeError,
|
|
1184
|
+
validate,
|
|
1185
|
+
onInvalid
|
|
290
1186
|
};
|
|
291
1187
|
});
|
|
292
1188
|
React.useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
293
1189
|
const run = React.useCallback(async (...args) => {
|
|
294
1190
|
window.clearTimeout(timer.current);
|
|
1191
|
+
const invalid = messages(latest.current.validate?.(...args));
|
|
1192
|
+
if (invalid) {
|
|
1193
|
+
unreported.current = { invalid };
|
|
1194
|
+
setState({
|
|
1195
|
+
...idle,
|
|
1196
|
+
fieldErrors: invalid
|
|
1197
|
+
});
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
295
1200
|
setState({
|
|
296
|
-
|
|
297
|
-
|
|
1201
|
+
...idle,
|
|
1202
|
+
phase: "pending"
|
|
298
1203
|
});
|
|
299
1204
|
try {
|
|
300
1205
|
await latest.current.action(...args);
|
|
301
1206
|
setState({
|
|
302
|
-
|
|
303
|
-
|
|
1207
|
+
...idle,
|
|
1208
|
+
phase: "done"
|
|
304
1209
|
});
|
|
305
|
-
timer.current = window.setTimeout(() => setState(
|
|
306
|
-
phase: "idle",
|
|
307
|
-
error: void 0
|
|
308
|
-
}), latest.current.settleMs);
|
|
1210
|
+
timer.current = window.setTimeout(() => setState(idle), latest.current.settleMs);
|
|
309
1211
|
} catch (thrown) {
|
|
310
1212
|
unreported.current = { thrown };
|
|
311
1213
|
setState({
|
|
312
1214
|
phase: "error",
|
|
313
|
-
error: latest.current.describeError(thrown)
|
|
1215
|
+
error: latest.current.describeError(thrown),
|
|
1216
|
+
thrown,
|
|
1217
|
+
fieldErrors: fieldErrorsOf(thrown)
|
|
314
1218
|
});
|
|
315
1219
|
}
|
|
316
1220
|
}, []);
|
|
317
1221
|
React.useEffect(() => {
|
|
318
|
-
|
|
319
|
-
|
|
1222
|
+
const note = unreported.current;
|
|
1223
|
+
if (!note) return;
|
|
1224
|
+
if ("thrown" in note && state.phase === "error") latest.current.onError?.(note.thrown);
|
|
1225
|
+
else if ("invalid" in note) latest.current.onInvalid?.(note.invalid);
|
|
1226
|
+
else return;
|
|
320
1227
|
unreported.current = void 0;
|
|
321
|
-
latest.current.onError?.(thrown);
|
|
322
1228
|
}, [state]);
|
|
1229
|
+
const clearFieldError = React.useCallback((field) => setState((s) => {
|
|
1230
|
+
if (field === void 0) return Object.keys(s.fieldErrors).length ? {
|
|
1231
|
+
...s,
|
|
1232
|
+
fieldErrors: {}
|
|
1233
|
+
} : s;
|
|
1234
|
+
if (!(field in s.fieldErrors)) return s;
|
|
1235
|
+
const { [field]: _gone, ...rest } = s.fieldErrors;
|
|
1236
|
+
return {
|
|
1237
|
+
...s,
|
|
1238
|
+
fieldErrors: rest
|
|
1239
|
+
};
|
|
1240
|
+
}), []);
|
|
323
1241
|
return {
|
|
324
1242
|
phase: state.phase,
|
|
325
1243
|
run,
|
|
326
|
-
error: state.error
|
|
1244
|
+
error: state.error,
|
|
1245
|
+
thrown: state.thrown,
|
|
1246
|
+
fieldErrors: state.fieldErrors,
|
|
1247
|
+
clearFieldError
|
|
327
1248
|
};
|
|
328
1249
|
}
|
|
1250
|
+
var idle = {
|
|
1251
|
+
phase: "idle",
|
|
1252
|
+
error: void 0,
|
|
1253
|
+
thrown: void 0,
|
|
1254
|
+
fieldErrors: {}
|
|
1255
|
+
};
|
|
1256
|
+
/** The messages `validate` returned, without the empty ones; undefined when there are none. */
|
|
1257
|
+
function messages(found) {
|
|
1258
|
+
if (!found) return void 0;
|
|
1259
|
+
const kept = Object.fromEntries(Object.entries(found).filter((e) => Boolean(e[1])));
|
|
1260
|
+
return Object.keys(kept).length ? kept : void 0;
|
|
1261
|
+
}
|
|
329
1262
|
// src/components/status.tsx
|
|
330
1263
|
var tones = {
|
|
331
1264
|
neutral: "bg-muted text-muted-foreground",
|
|
@@ -392,7 +1325,7 @@ function Meter({ label, value, max = 1, valueText, detail, thresholds, worseWhen
|
|
|
392
1325
|
const detailId = React.useId();
|
|
393
1326
|
const share = max > 0 ? Math.min(1, Math.max(0, value / max)) : 0;
|
|
394
1327
|
const crossed = crossedThreshold(share, thresholds, worseWhen);
|
|
395
|
-
const text = valueText ?? `${format.
|
|
1328
|
+
const text = valueText ?? `${format.share(share)} used`;
|
|
396
1329
|
const hasNote = Boolean(crossed || detail);
|
|
397
1330
|
const describedBy = [crossed && statusId, detail && detailId].filter(Boolean).join(" ") || void 0;
|
|
398
1331
|
const bar = /* @__PURE__ */ jsxs("div", {
|
|
@@ -471,7 +1404,7 @@ function colourFor(part, index) {
|
|
|
471
1404
|
return `var(--chart-${index + 1})`;
|
|
472
1405
|
}
|
|
473
1406
|
/** What a whole is made of: a stacked bar for proportion and a table that names every part, its amount and its share, so colour is never the only cue. */
|
|
474
|
-
function CompositionBar({ label, parts, formatValue, formatShare = format.
|
|
1407
|
+
function CompositionBar({ label, parts, formatValue, formatShare = format.share, partHeader = "Part", valueHeader = "Amount", shareHeader = "Share", className, ...whole }) {
|
|
475
1408
|
const captionId = React.useId();
|
|
476
1409
|
const sum = parts.reduce((n, p) => n + Math.max(0, p.value), 0);
|
|
477
1410
|
const total = Math.max(whole.total ?? sum, sum);
|
|
@@ -494,7 +1427,7 @@ function CompositionBar({ label, parts, formatValue, formatShare = format.percen
|
|
|
494
1427
|
"aria-hidden": true,
|
|
495
1428
|
className: "flex h-3 gap-0.5 overflow-hidden rounded-pill bg-muted",
|
|
496
1429
|
children: [rows.filter((r) => r.value > 0).map((r) => /* @__PURE__ */ jsx("div", {
|
|
497
|
-
className: "h-full min-w-
|
|
1430
|
+
className: "h-full min-w-1",
|
|
498
1431
|
style: {
|
|
499
1432
|
flex: `${r.share} 1 0`,
|
|
500
1433
|
background: r.colour
|
|
@@ -627,31 +1560,41 @@ function LinkCardList({ label, children, className }) {
|
|
|
627
1560
|
});
|
|
628
1561
|
}
|
|
629
1562
|
// src/components/data-view.tsx
|
|
1563
|
+
/** The default failed-read panel: the reason on the danger tint, with Try again. Its parent carries `role="alert"`. */
|
|
1564
|
+
function LoadError({ message, retry, className }) {
|
|
1565
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1566
|
+
className: cn("flex flex-wrap items-start gap-3 rounded-surface bg-danger-subtle p-4 text-danger", className),
|
|
1567
|
+
children: [
|
|
1568
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
1569
|
+
"aria-hidden": true,
|
|
1570
|
+
className: "mt-0.5 size-5 shrink-0"
|
|
1571
|
+
}),
|
|
1572
|
+
/* @__PURE__ */ jsx("p", {
|
|
1573
|
+
className: "min-w-0 flex-1 type-body",
|
|
1574
|
+
children: message
|
|
1575
|
+
}),
|
|
1576
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
1577
|
+
size: "sm",
|
|
1578
|
+
onClick: retry,
|
|
1579
|
+
children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), "Try again"]
|
|
1580
|
+
})
|
|
1581
|
+
]
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
var defaultError = (failure) => /* @__PURE__ */ jsx(LoadError, { ...failure });
|
|
630
1585
|
/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`, under a `StaleNotice` when a refresh failed. The skeleton and empty state are required. */
|
|
631
|
-
function DataView({ state, isEmpty, skeleton, empty, children, staleNotice = (stale) => /* @__PURE__ */ jsx(StaleNotice, { stale }), className }) {
|
|
1586
|
+
function DataView({ state, isEmpty, skeleton, empty, children, staleNotice = (stale) => /* @__PURE__ */ jsx(StaleNotice, { stale }), error = defaultError, className }) {
|
|
632
1587
|
return /* @__PURE__ */ jsxs("div", {
|
|
633
1588
|
className: cn("min-w-0", className),
|
|
634
1589
|
"aria-busy": state.status === "loading" || void 0,
|
|
635
1590
|
children: [
|
|
636
1591
|
state.status === "loading" && skeleton,
|
|
637
|
-
state.status === "error" && /* @__PURE__ */
|
|
1592
|
+
state.status === "error" && /* @__PURE__ */ jsx("div", {
|
|
638
1593
|
role: "alert",
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
className: "mt-0.5 size-5 shrink-0"
|
|
644
|
-
}),
|
|
645
|
-
/* @__PURE__ */ jsx("p", {
|
|
646
|
-
className: "min-w-0 flex-1 type-body",
|
|
647
|
-
children: state.message
|
|
648
|
-
}),
|
|
649
|
-
/* @__PURE__ */ jsxs(Button, {
|
|
650
|
-
size: "sm",
|
|
651
|
-
onClick: state.retry,
|
|
652
|
-
children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), "Try again"]
|
|
653
|
-
})
|
|
654
|
-
]
|
|
1594
|
+
children: error({
|
|
1595
|
+
message: state.message,
|
|
1596
|
+
retry: state.retry
|
|
1597
|
+
})
|
|
655
1598
|
}),
|
|
656
1599
|
state.status === "ready" && /* @__PURE__ */ jsxs(Fragment, { children: [state.stale && staleNotice(state.stale), isEmpty(state.data) ? empty : children(state.data)] })
|
|
657
1600
|
]
|
|
@@ -715,49 +1658,96 @@ function Skeleton({ className }) {
|
|
|
715
1658
|
className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
|
|
716
1659
|
});
|
|
717
1660
|
}
|
|
718
|
-
// src/
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
*/
|
|
724
|
-
function
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}
|
|
738
|
-
const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
|
|
739
|
-
const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
|
|
740
|
-
root,
|
|
741
|
-
rootMargin
|
|
742
|
-
});
|
|
743
|
-
observer.observe(el);
|
|
744
|
-
return () => observer.disconnect();
|
|
745
|
-
}, [
|
|
746
|
-
active,
|
|
747
|
-
el,
|
|
748
|
-
rootMargin,
|
|
749
|
-
seen,
|
|
750
|
-
unsupported
|
|
751
|
-
]);
|
|
752
|
-
return {
|
|
753
|
-
ref: setEl,
|
|
754
|
-
inView
|
|
1661
|
+
// src/components/job-status.tsx
|
|
1662
|
+
var Spinner = ({ className, ...props }) => /* @__PURE__ */ jsx(LoaderCircle, {
|
|
1663
|
+
...props,
|
|
1664
|
+
className: cn(className, "motion-safe:animate-spin")
|
|
1665
|
+
});
|
|
1666
|
+
/** A long-running server job: its state as a required word beside the app's sentence, a progress bar when the total is known, each failure named with its reason, and a polite announcement only when the item changes or the job ends. */
|
|
1667
|
+
function JobStatus({ label, running, words, summary, current, total, failures = [], failed = false, failuresLabel = "Failures", className }) {
|
|
1668
|
+
const ended = failed ? {
|
|
1669
|
+
tone: "danger",
|
|
1670
|
+
icon: CircleAlert,
|
|
1671
|
+
word: words.failed
|
|
1672
|
+
} : failures.length ? {
|
|
1673
|
+
tone: "warning",
|
|
1674
|
+
icon: TriangleAlert,
|
|
1675
|
+
word: words.failed
|
|
1676
|
+
} : {
|
|
1677
|
+
tone: "success",
|
|
1678
|
+
icon: Check,
|
|
1679
|
+
word: words.finished
|
|
755
1680
|
};
|
|
1681
|
+
const { tone, icon, word } = running ? {
|
|
1682
|
+
tone: "info",
|
|
1683
|
+
icon: Spinner,
|
|
1684
|
+
word: words.running
|
|
1685
|
+
} : ended;
|
|
1686
|
+
const moment = running ? `running:${current ?? ""}` : `ended:${word}`;
|
|
1687
|
+
const [said, setSaid] = React.useState({
|
|
1688
|
+
moment,
|
|
1689
|
+
text: ""
|
|
1690
|
+
});
|
|
1691
|
+
if (said.moment !== moment) setSaid({
|
|
1692
|
+
moment,
|
|
1693
|
+
text: `${word}. ${summary}`
|
|
1694
|
+
});
|
|
1695
|
+
const bar = running && total !== void 0 && total > 0 && current !== void 0;
|
|
1696
|
+
const done = Math.min(total ?? 0, Math.max(0, current ?? 0));
|
|
1697
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1698
|
+
"aria-label": label,
|
|
1699
|
+
className: cn("grid min-w-0 gap-3", className),
|
|
1700
|
+
children: [
|
|
1701
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1702
|
+
className: "flex flex-wrap items-center gap-x-3 gap-y-1",
|
|
1703
|
+
children: [/* @__PURE__ */ jsx(Status, {
|
|
1704
|
+
tone,
|
|
1705
|
+
icon,
|
|
1706
|
+
children: word
|
|
1707
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1708
|
+
className: "min-w-0 flex-1 type-body-sm text-foreground",
|
|
1709
|
+
children: summary
|
|
1710
|
+
})]
|
|
1711
|
+
}),
|
|
1712
|
+
bar && /* @__PURE__ */ jsx("div", {
|
|
1713
|
+
role: "progressbar",
|
|
1714
|
+
"aria-label": label,
|
|
1715
|
+
"aria-valuemin": 0,
|
|
1716
|
+
"aria-valuemax": total,
|
|
1717
|
+
"aria-valuenow": done,
|
|
1718
|
+
"aria-valuetext": `${format.integer(done)} of ${format.integer(total)}`,
|
|
1719
|
+
className: "relative h-2 overflow-hidden rounded-pill bg-muted",
|
|
1720
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1721
|
+
className: "absolute inset-y-0 left-0",
|
|
1722
|
+
style: {
|
|
1723
|
+
width: `${done / total * 100}%`,
|
|
1724
|
+
background: "var(--chart-1)"
|
|
1725
|
+
}
|
|
1726
|
+
})
|
|
1727
|
+
}),
|
|
1728
|
+
!running && failures.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
1729
|
+
"aria-label": failuresLabel,
|
|
1730
|
+
className: "grid gap-1 border-l-2 border-warning pl-3 type-body-sm",
|
|
1731
|
+
children: failures.map((f) => /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("span", {
|
|
1732
|
+
className: "type-label",
|
|
1733
|
+
children: f.label
|
|
1734
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
1735
|
+
className: "text-muted-foreground",
|
|
1736
|
+
children: [": ", f.reason]
|
|
1737
|
+
})] }, f.key))
|
|
1738
|
+
}),
|
|
1739
|
+
/* @__PURE__ */ jsx("p", {
|
|
1740
|
+
role: "status",
|
|
1741
|
+
className: "sr-only",
|
|
1742
|
+
children: said.text
|
|
1743
|
+
})
|
|
1744
|
+
]
|
|
1745
|
+
});
|
|
756
1746
|
}
|
|
757
1747
|
// src/components/thumbnail.tsx
|
|
758
1748
|
var ratio = (aspect) => typeof aspect === "number" ? String(aspect) : aspect.replace("/", " / ");
|
|
759
|
-
/** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words if it cannot,
|
|
760
|
-
function Thumbnail({ src, alt, missing, aspect = 1, fit = "cover", srcSet, sizes, eager = false, rootMargin = "200px", className }) {
|
|
1749
|
+
/** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words (or a `fallback`) if it cannot, a request only when it nears the screen, and `children` overlaid in its corners. `alt` and `missing` or `fallback` are required. */
|
|
1750
|
+
function Thumbnail({ src, alt, missing, aspect = 1, fit = "cover", srcSet, sizes, eager = false, rootMargin = "200px", className, fallback, children }) {
|
|
761
1751
|
const request = src ? `${src} ${srcSet ?? ""}` : null;
|
|
762
1752
|
const [result, setResult] = React.useState(null);
|
|
763
1753
|
const phase = !request ? "missing" : result?.request === request ? result.ok ? "loaded" : "missing" : "loading";
|
|
@@ -791,18 +1781,23 @@ function Thumbnail({ src, alt, missing, aspect = 1, fit = "cover", srcSet, sizes
|
|
|
791
1781
|
}),
|
|
792
1782
|
className: cn("absolute inset-0 size-full", fit === "cover" ? "object-cover" : "object-contain", phase === "loading" && "opacity-0")
|
|
793
1783
|
}, request),
|
|
794
|
-
phase === "missing" && /* @__PURE__ */
|
|
1784
|
+
phase === "missing" && /* @__PURE__ */ jsx("div", {
|
|
795
1785
|
role: "img",
|
|
796
|
-
"aria-label": alt
|
|
797
|
-
className: "absolute inset-0 grid content-center justify-items-center gap-0.5 p-1 text-center text-muted-foreground",
|
|
798
|
-
children: [/* @__PURE__ */ jsx(ImageOff, {
|
|
1786
|
+
"aria-label": [alt, missing].filter(Boolean).join(": "),
|
|
1787
|
+
className: cn("absolute inset-0 grid", fallback === void 0 && "content-center justify-items-center gap-0.5 p-1 text-center text-muted-foreground"),
|
|
1788
|
+
children: fallback === void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ImageOff, {
|
|
799
1789
|
"aria-hidden": true,
|
|
800
1790
|
className: "size-4 shrink-0"
|
|
801
1791
|
}), /* @__PURE__ */ jsx("span", {
|
|
802
1792
|
className: "type-caption text-balance",
|
|
803
1793
|
children: missing
|
|
804
|
-
})]
|
|
805
|
-
|
|
1794
|
+
})] }) : /* @__PURE__ */ jsx("div", {
|
|
1795
|
+
"aria-hidden": true,
|
|
1796
|
+
className: "grid size-full min-h-0 min-w-0",
|
|
1797
|
+
children: fallback
|
|
1798
|
+
})
|
|
1799
|
+
}),
|
|
1800
|
+
children
|
|
806
1801
|
]
|
|
807
1802
|
});
|
|
808
1803
|
}
|
|
@@ -1041,6 +2036,36 @@ function BulkBar({ count, noun, onClear, children, format: format$1 = format, cl
|
|
|
1041
2036
|
});
|
|
1042
2037
|
}
|
|
1043
2038
|
// src/components/data-table.tsx
|
|
2039
|
+
var collator = new Intl.Collator(void 0, {
|
|
2040
|
+
numeric: true,
|
|
2041
|
+
sensitivity: "base"
|
|
2042
|
+
});
|
|
2043
|
+
var kind = (v) => typeof v === "number" ? 0 : typeof v === "string" ? 1 : 2;
|
|
2044
|
+
/** Orders two present values: numbers, then text (locale order, numbers in text read as numbers), then dates. */
|
|
2045
|
+
function compareValues(a, b) {
|
|
2046
|
+
if (kind(a) !== kind(b)) return kind(a) - kind(b);
|
|
2047
|
+
if (typeof a === "string") return collator.compare(a, b);
|
|
2048
|
+
return Number(a) - Number(b);
|
|
2049
|
+
}
|
|
2050
|
+
/** A cell with no value: the column's word, or an en dash named "No value" for a screen reader. */
|
|
2051
|
+
function Missing({ word }) {
|
|
2052
|
+
return word ? /* @__PURE__ */ jsx("span", {
|
|
2053
|
+
className: "text-muted-foreground",
|
|
2054
|
+
children: word
|
|
2055
|
+
}) : /* @__PURE__ */ jsxs("span", {
|
|
2056
|
+
className: "text-muted-foreground",
|
|
2057
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2058
|
+
"aria-hidden": true,
|
|
2059
|
+
children: format.missing
|
|
2060
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2061
|
+
className: "sr-only",
|
|
2062
|
+
children: "No value"
|
|
2063
|
+
})]
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
function drawValue(v) {
|
|
2067
|
+
return typeof v === "number" ? format.decimal(v) : v instanceof Date ? format.date(v) : v;
|
|
2068
|
+
}
|
|
1044
2069
|
function useLocalSort(initial) {
|
|
1045
2070
|
const [sort, setSort] = React.useState(initial);
|
|
1046
2071
|
return [sort, setSort];
|
|
@@ -1086,33 +2111,54 @@ function UrlSortedTable(props) {
|
|
|
1086
2111
|
sortState: useUrlSort(props.sortParam, props.initialSort)
|
|
1087
2112
|
});
|
|
1088
2113
|
}
|
|
2114
|
+
var features = tableFeatures({
|
|
2115
|
+
rowSortingFeature,
|
|
2116
|
+
sortedRowModel: createSortedRowModel()
|
|
2117
|
+
});
|
|
1089
2118
|
function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, selection, expansion, className }) {
|
|
1090
2119
|
const baseId = React.useId();
|
|
1091
|
-
const defs = React.useMemo(() => columns.map((c) =>
|
|
1092
|
-
|
|
1093
|
-
accessorFn: (row) => row,
|
|
1094
|
-
header: c.header,
|
|
1095
|
-
cell: (info) => c.cell(info.row.original),
|
|
1096
|
-
enableSorting: Boolean(c.sort),
|
|
1097
|
-
sortingFn: c.sort ? (a, b) => c.sort(a.original, b.original) : void 0,
|
|
1098
|
-
meta: {
|
|
2120
|
+
const defs = React.useMemo(() => columns.map((c) => {
|
|
2121
|
+
const meta = {
|
|
1099
2122
|
numeric: c.numeric,
|
|
1100
2123
|
truncate: c.truncate,
|
|
1101
2124
|
hideHeader: c.hideHeader,
|
|
1102
2125
|
className: c.className
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
|
|
2126
|
+
};
|
|
2127
|
+
const { value, sort } = c;
|
|
2128
|
+
if (!value) return {
|
|
2129
|
+
id: c.key,
|
|
2130
|
+
accessorFn: (row) => row,
|
|
2131
|
+
header: c.header,
|
|
2132
|
+
cell: (info) => c.cell?.(info.row.original),
|
|
2133
|
+
enableSorting: Boolean(sort),
|
|
2134
|
+
sortFn: sort ? (a, b) => sort(a.original, b.original) : void 0,
|
|
2135
|
+
meta
|
|
2136
|
+
};
|
|
2137
|
+
return {
|
|
2138
|
+
id: c.key,
|
|
2139
|
+
accessorFn: (row) => value(row) ?? void 0,
|
|
2140
|
+
header: c.header,
|
|
2141
|
+
cell: (info) => {
|
|
2142
|
+
const v = value(info.row.original);
|
|
2143
|
+
if (v == null) return /* @__PURE__ */ jsx(Missing, { word: c.missing });
|
|
2144
|
+
return c.cell ? c.cell(info.row.original) : drawValue(v);
|
|
2145
|
+
},
|
|
2146
|
+
enableSorting: sort !== false,
|
|
2147
|
+
sortUndefined: "last",
|
|
2148
|
+
sortFn: sort ? (a, b) => sort(a.original, b.original) : (a, b) => compareValues(a.getValue(c.key), b.getValue(c.key)),
|
|
2149
|
+
meta
|
|
2150
|
+
};
|
|
2151
|
+
}), [columns]);
|
|
2152
|
+
const sorting = sort && columns.some((c) => c.key === sort.key && (c.value ? c.sort !== false : c.sort)) ? [{
|
|
1106
2153
|
id: sort.key,
|
|
1107
2154
|
desc: sort.dir === "descending"
|
|
1108
2155
|
}] : [];
|
|
1109
|
-
const table =
|
|
2156
|
+
const table = useTable({
|
|
2157
|
+
features,
|
|
1110
2158
|
data: rows,
|
|
1111
2159
|
columns: defs,
|
|
1112
2160
|
state: { sorting },
|
|
1113
2161
|
getRowId: (row) => rowKey(row),
|
|
1114
|
-
getCoreRowModel: getCoreRowModel(),
|
|
1115
|
-
getSortedRowModel: getSortedRowModel(),
|
|
1116
2162
|
autoResetAll: false
|
|
1117
2163
|
});
|
|
1118
2164
|
const toggle = (key) => setSort({
|
|
@@ -1278,7 +2324,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
|
|
|
1278
2324
|
children: /* @__PURE__ */ jsx(Chevron, { open })
|
|
1279
2325
|
})
|
|
1280
2326
|
}),
|
|
1281
|
-
row.
|
|
2327
|
+
row.getAllCells().map((cell) => {
|
|
1282
2328
|
const meta = cell.column.columnDef.meta;
|
|
1283
2329
|
return /* @__PURE__ */ jsx("td", {
|
|
1284
2330
|
className: cn("py-2.5 pr-4 align-middle last:pr-0", meta?.numeric && "text-right tabular-nums", meta?.truncate && "max-w-48 truncate", meta?.className),
|
|
@@ -1433,31 +2479,39 @@ function VirtualTiles({ label, rows, rowKey, tile, aspect, tileSize, maxHeight }
|
|
|
1433
2479
|
}
|
|
1434
2480
|
function Tile({ name, chosen, disabled, onChange, aspect, image, detail, index }) {
|
|
1435
2481
|
const shift = useShiftNote();
|
|
1436
|
-
return /* @__PURE__ */
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
children:
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
"
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
className:
|
|
2482
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2483
|
+
className: "contents",
|
|
2484
|
+
onMouseDownCapture: shift.handlers.onMouseDown,
|
|
2485
|
+
onKeyDownCapture: shift.handlers.onKeyDown,
|
|
2486
|
+
children: /* @__PURE__ */ jsxs(Checkbox$1, {
|
|
2487
|
+
isSelected: chosen,
|
|
2488
|
+
isDisabled: disabled,
|
|
2489
|
+
"aria-label": name,
|
|
2490
|
+
onChange: (on) => onChange(on, shift.take()),
|
|
2491
|
+
"data-index": index,
|
|
2492
|
+
className: cn("group relative grid min-w-0 gap-1.5 rounded-surface border border-transparent p-1.5 select-none transition-state", "data-[focus-visible]:outline-2 data-[focus-visible]:outline-offset-2 data-[focus-visible]:outline-ring", chosen && "border-primary bg-surface-sunken", disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer hover:bg-surface-sunken"),
|
|
2493
|
+
children: [
|
|
2494
|
+
/* @__PURE__ */ jsx("span", {
|
|
2495
|
+
className: cn("block overflow-hidden rounded-control bg-muted *:size-full *:object-cover", aspectClass[aspect]),
|
|
2496
|
+
children: image
|
|
2497
|
+
}),
|
|
2498
|
+
/* @__PURE__ */ jsx("span", {
|
|
2499
|
+
className: "absolute top-3 left-3 grid size-7 place-items-center rounded-control bg-background",
|
|
2500
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2501
|
+
"aria-hidden": true,
|
|
2502
|
+
className: cn("grid size-4.5 place-items-center rounded-control border border-input bg-background", chosen && "border-primary bg-primary text-primary-foreground"),
|
|
2503
|
+
children: chosen && /* @__PURE__ */ jsx(Check, {
|
|
2504
|
+
className: "size-3.5",
|
|
2505
|
+
strokeWidth: 3
|
|
2506
|
+
})
|
|
2507
|
+
})
|
|
2508
|
+
}),
|
|
2509
|
+
detail != null && /* @__PURE__ */ jsx("span", {
|
|
2510
|
+
className: "truncate type-body-sm text-muted-foreground",
|
|
2511
|
+
children: detail
|
|
1454
2512
|
})
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
className: "truncate type-body-sm text-muted-foreground",
|
|
1458
|
-
children: detail
|
|
1459
|
-
})
|
|
1460
|
-
]
|
|
2513
|
+
]
|
|
2514
|
+
})
|
|
1461
2515
|
});
|
|
1462
2516
|
}
|
|
1463
2517
|
// src/components/virtual-list.tsx
|
|
@@ -1516,21 +2570,48 @@ function VirtualList({ label, items, itemKey, children, estimateSize = 48, heigh
|
|
|
1516
2570
|
});
|
|
1517
2571
|
}
|
|
1518
2572
|
// src/components/infinite-list.tsx
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
2573
|
+
function MoreFailed({ message, retry }) {
|
|
2574
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2575
|
+
className: "flex flex-wrap items-start gap-3 border-t border-border bg-danger-subtle px-3 py-2 text-danger",
|
|
2576
|
+
children: [
|
|
2577
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
2578
|
+
"aria-hidden": true,
|
|
2579
|
+
className: "mt-0.5 size-4 shrink-0"
|
|
2580
|
+
}),
|
|
2581
|
+
/* @__PURE__ */ jsx("p", {
|
|
2582
|
+
className: "min-w-0 flex-1 type-body-sm",
|
|
2583
|
+
children: message
|
|
2584
|
+
}),
|
|
2585
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
2586
|
+
size: "sm",
|
|
2587
|
+
onClick: retry,
|
|
2588
|
+
children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), "Try again"]
|
|
2589
|
+
})
|
|
2590
|
+
]
|
|
2591
|
+
});
|
|
2592
|
+
}
|
|
2593
|
+
var defaultMoreError = (failure) => /* @__PURE__ */ jsx(MoreFailed, { ...failure });
|
|
2594
|
+
/**
|
|
2595
|
+
* The row after a cursor-paged list or grid: loads the next page as it nears the screen, shows
|
|
2596
|
+
* `moreSkeleton` while it comes, says why it failed with Try again, offers Show more for the
|
|
2597
|
+
* keyboard, and `end` after the last page. After Show more it focuses the first new item: mark
|
|
2598
|
+
* each item with `data-index` and put this row beside the list, in the same parent.
|
|
2599
|
+
*/
|
|
2600
|
+
function LoadMore({ state, moreLabel, moreSkeleton, end, rootMargin = "400px", keepAtLeast = 0, error: drawError = defaultMoreError, className }) {
|
|
2601
|
+
const { more } = state;
|
|
2602
|
+
const ready = state.status === "ready";
|
|
2603
|
+
const held = ready ? state.data.length : 0;
|
|
1523
2604
|
const box = React.useRef(null);
|
|
1524
2605
|
const near = useInView({
|
|
1525
|
-
active:
|
|
2606
|
+
active: ready && more.hasMore,
|
|
1526
2607
|
rootMargin
|
|
1527
2608
|
});
|
|
1528
2609
|
const { hasMore, loadingMore, error, loadMore } = more;
|
|
1529
2610
|
React.useEffect(() => {
|
|
1530
|
-
if (
|
|
2611
|
+
if (!ready || !hasMore || loadingMore || error) return;
|
|
1531
2612
|
if (near.inView || held < keepAtLeast) loadMore();
|
|
1532
2613
|
}, [
|
|
1533
|
-
|
|
2614
|
+
ready,
|
|
1534
2615
|
hasMore,
|
|
1535
2616
|
loadingMore,
|
|
1536
2617
|
error,
|
|
@@ -1548,10 +2629,10 @@ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, more
|
|
|
1548
2629
|
const from = focusFrom.current;
|
|
1549
2630
|
if (from === null || loadingMore) return;
|
|
1550
2631
|
if (held > from) {
|
|
1551
|
-
const
|
|
1552
|
-
if (
|
|
1553
|
-
|
|
1554
|
-
|
|
2632
|
+
const item = box.current?.parentElement?.querySelector(`[data-index="${from}"]`);
|
|
2633
|
+
if (item) {
|
|
2634
|
+
item.tabIndex = -1;
|
|
2635
|
+
item.focus();
|
|
1555
2636
|
}
|
|
1556
2637
|
focusFrom.current = null;
|
|
1557
2638
|
} else if (error || !hasMore) focusFrom.current = null;
|
|
@@ -1561,60 +2642,78 @@ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, more
|
|
|
1561
2642
|
error,
|
|
1562
2643
|
hasMore
|
|
1563
2644
|
]);
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
/* @__PURE__ */
|
|
2645
|
+
if (!ready) return null;
|
|
2646
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2647
|
+
ref: box,
|
|
2648
|
+
className,
|
|
2649
|
+
children: [
|
|
2650
|
+
hasMore && !error && /* @__PURE__ */ jsx("div", {
|
|
2651
|
+
ref: near.ref,
|
|
2652
|
+
"aria-hidden": true,
|
|
2653
|
+
className: "h-px"
|
|
2654
|
+
}),
|
|
2655
|
+
loadingMore ? /* @__PURE__ */ jsx("div", {
|
|
2656
|
+
"aria-hidden": true,
|
|
2657
|
+
className: "border-t border-border",
|
|
2658
|
+
children: moreSkeleton
|
|
2659
|
+
}) : error ? /* @__PURE__ */ jsx("div", {
|
|
2660
|
+
role: "alert",
|
|
2661
|
+
children: drawError({
|
|
2662
|
+
message: error,
|
|
2663
|
+
retry: loadByHand
|
|
2664
|
+
})
|
|
2665
|
+
}) : hasMore ? /* @__PURE__ */ jsx("div", {
|
|
2666
|
+
className: "border-t border-border py-3",
|
|
2667
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1587
2668
|
size: "sm",
|
|
1588
2669
|
onClick: loadByHand,
|
|
1589
|
-
children:
|
|
2670
|
+
children: moreLabel
|
|
1590
2671
|
})
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
2672
|
+
}) : end && /* @__PURE__ */ jsx("div", {
|
|
2673
|
+
className: "border-t border-border py-3 type-body-sm text-muted-foreground",
|
|
2674
|
+
children: end
|
|
2675
|
+
}),
|
|
2676
|
+
/* @__PURE__ */ jsx("p", {
|
|
2677
|
+
role: "status",
|
|
2678
|
+
className: "sr-only",
|
|
2679
|
+
children: loadingMore ? "Loading more" : ""
|
|
1598
2680
|
})
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
2681
|
+
]
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
/** A cursor-paged list for `useInfiniteLoad`: DataView's first-page states, virtual rows (or a page-scrolled grid), and a `LoadMore` row that loads on approach, shows a skeleton, or says why it failed with Try again. */
|
|
2685
|
+
function InfiniteList({ state, label, children, skeleton, empty, moreLabel, moreSkeleton = skeleton, end, rootMargin = "400px", keepAtLeast = 0, scroll = "region", listClassName, error, moreError, estimateSize, height = 480, virtualizeFrom, className }) {
|
|
2686
|
+
const { more, itemKey } = state;
|
|
2687
|
+
const footer = /* @__PURE__ */ jsx(LoadMore, {
|
|
2688
|
+
className: scroll === "page" ? "mt-4" : void 0,
|
|
2689
|
+
state,
|
|
2690
|
+
moreLabel,
|
|
2691
|
+
moreSkeleton,
|
|
2692
|
+
end,
|
|
2693
|
+
rootMargin,
|
|
2694
|
+
keepAtLeast,
|
|
2695
|
+
error: moreError
|
|
2696
|
+
});
|
|
1609
2697
|
return /* @__PURE__ */ jsx(DataView, {
|
|
1610
2698
|
state,
|
|
1611
|
-
isEmpty: (items) => items.length === 0 && !hasMore,
|
|
2699
|
+
isEmpty: (items) => items.length === 0 && !more.hasMore,
|
|
1612
2700
|
skeleton,
|
|
1613
2701
|
empty,
|
|
2702
|
+
error,
|
|
1614
2703
|
className,
|
|
1615
|
-
children: (items) => /* @__PURE__ */
|
|
1616
|
-
|
|
1617
|
-
|
|
2704
|
+
children: (items) => scroll === "page" ? /* @__PURE__ */ jsxs("div", {
|
|
2705
|
+
"aria-busy": more.loadingMore || void 0,
|
|
2706
|
+
children: [/* @__PURE__ */ jsx("ul", {
|
|
2707
|
+
"aria-label": label,
|
|
2708
|
+
className: cn("min-w-0", listClassName ?? "grid"),
|
|
2709
|
+
children: items.map((item, i) => /* @__PURE__ */ jsx("li", {
|
|
2710
|
+
"data-index": i,
|
|
2711
|
+
className: "min-w-0",
|
|
2712
|
+
children: children(item, i)
|
|
2713
|
+
}, itemKey(item)))
|
|
2714
|
+
}), footer]
|
|
2715
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
2716
|
+
"aria-busy": more.loadingMore || void 0,
|
|
1618
2717
|
children: /* @__PURE__ */ jsx(VirtualList, {
|
|
1619
2718
|
label,
|
|
1620
2719
|
items,
|
|
@@ -2088,7 +3187,7 @@ function UndoBar({ undoable, inline = false }) {
|
|
|
2088
3187
|
const ghost = "text-background hover:bg-neutral-11";
|
|
2089
3188
|
return /* @__PURE__ */ jsx("div", {
|
|
2090
3189
|
"aria-live": "polite",
|
|
2091
|
-
className: inline ? "flex" : "pointer-events-none fixed inset-x-0 bottom-4
|
|
3190
|
+
className: inline ? "flex" : "layer-bar pointer-events-none fixed inset-x-0 bottom-4 flex justify-center px-4",
|
|
2092
3191
|
children: (pending || failed) && /* @__PURE__ */ jsx("div", {
|
|
2093
3192
|
className: "pointer-events-auto flex max-w-lg items-center gap-4 rounded-overlay bg-foreground py-2 pr-2 pl-4 text-background shadow-overlay",
|
|
2094
3193
|
children: pending ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
|
|
@@ -2245,135 +3344,31 @@ function Tabs({ param, items, label, children, className }) {
|
|
|
2245
3344
|
const fallback = items[0]?.value ?? "";
|
|
2246
3345
|
const raw = params.get(param);
|
|
2247
3346
|
const value = items.some((i) => i.value === raw) ? raw : fallback;
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
if (focus) refs.current[items.findIndex((i) => i.value === next)]?.focus();
|
|
2258
|
-
};
|
|
2259
|
-
const onKeyDown = (e, index) => {
|
|
2260
|
-
const last = items.length - 1;
|
|
2261
|
-
const to = e.key === "ArrowRight" ? index === last ? 0 : index + 1 : e.key === "ArrowLeft" ? index === 0 ? last : index - 1 : e.key === "Home" ? 0 : e.key === "End" ? last : void 0;
|
|
2262
|
-
if (to === void 0) return;
|
|
2263
|
-
e.preventDefault();
|
|
2264
|
-
select(items[to].value, true);
|
|
2265
|
-
};
|
|
2266
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
3347
|
+
const select = (next) => setParams((p) => {
|
|
3348
|
+
const out = new URLSearchParams(p);
|
|
3349
|
+
if (next === fallback) out.delete(param);
|
|
3350
|
+
else out.set(param, next);
|
|
3351
|
+
return out;
|
|
3352
|
+
}, { replace: true });
|
|
3353
|
+
return /* @__PURE__ */ jsxs(Tabs$1, {
|
|
3354
|
+
selectedKey: value,
|
|
3355
|
+
onSelectionChange: (key) => select(String(key)),
|
|
2267
3356
|
className: cn("grid gap-4", className),
|
|
2268
|
-
children: [/* @__PURE__ */ jsx(
|
|
2269
|
-
role: "tablist",
|
|
3357
|
+
children: [/* @__PURE__ */ jsx(TabList, {
|
|
2270
3358
|
"aria-label": label,
|
|
2271
3359
|
className: "flex gap-4 overflow-x-auto border-b border-border",
|
|
2272
|
-
children: items.map((item
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
id: `${baseId}-tab-${item.value}`,
|
|
2281
|
-
"aria-selected": selected,
|
|
2282
|
-
"aria-controls": `${baseId}-panel`,
|
|
2283
|
-
tabIndex: selected ? 0 : -1,
|
|
2284
|
-
onClick: () => select(item.value),
|
|
2285
|
-
onKeyDown: (e) => onKeyDown(e, i),
|
|
2286
|
-
className: cn("-mb-px cursor-pointer border-b-2 py-2 type-label whitespace-nowrap transition-state", selected ? "border-foreground font-semibold text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"),
|
|
2287
|
-
children: item.label
|
|
2288
|
-
}, item.value);
|
|
2289
|
-
})
|
|
2290
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
2291
|
-
role: "tabpanel",
|
|
2292
|
-
id: `${baseId}-panel`,
|
|
2293
|
-
"aria-labelledby": `${baseId}-tab-${value}`,
|
|
2294
|
-
tabIndex: 0,
|
|
3360
|
+
children: items.map((item) => /* @__PURE__ */ jsx(Tab, {
|
|
3361
|
+
id: item.value,
|
|
3362
|
+
className: cn("-mb-px cursor-pointer border-b-2 py-2 type-label whitespace-nowrap transition-state", "border-transparent text-muted-foreground hover:text-foreground", "data-[selected]:border-foreground data-[selected]:font-semibold data-[selected]:text-foreground"),
|
|
3363
|
+
children: item.label
|
|
3364
|
+
}, item.value))
|
|
3365
|
+
}), /* @__PURE__ */ jsx(TabPanel, {
|
|
3366
|
+
id: value,
|
|
3367
|
+
shouldForceMount: false,
|
|
2295
3368
|
children: children(value)
|
|
2296
3369
|
})]
|
|
2297
3370
|
});
|
|
2298
3371
|
}
|
|
2299
|
-
// src/components/hotkeys.tsx
|
|
2300
|
-
var TEXT_INPUTS_EXEMPT = /* @__PURE__ */ new Set([
|
|
2301
|
-
"checkbox",
|
|
2302
|
-
"radio",
|
|
2303
|
-
"button",
|
|
2304
|
-
"submit",
|
|
2305
|
-
"reset",
|
|
2306
|
-
"range",
|
|
2307
|
-
"color",
|
|
2308
|
-
"file"
|
|
2309
|
-
]);
|
|
2310
|
-
/** True when a key pressed on this element is the person typing, so single-key shortcuts must leave it alone. */
|
|
2311
|
-
function isTypingTarget(target) {
|
|
2312
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
2313
|
-
if (target.isContentEditable || target.closest("[contenteditable=''],[contenteditable='true']")) return true;
|
|
2314
|
-
if (target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return true;
|
|
2315
|
-
if (target instanceof HTMLInputElement) return !TEXT_INPUTS_EXEMPT.has(target.type);
|
|
2316
|
-
return false;
|
|
2317
|
-
}
|
|
2318
|
-
function toShortcuts(input) {
|
|
2319
|
-
return Array.isArray(input) ? input : Object.entries(input).map(([key, run]) => ({
|
|
2320
|
-
keys: [key],
|
|
2321
|
-
label: key,
|
|
2322
|
-
run
|
|
2323
|
-
}));
|
|
2324
|
-
}
|
|
2325
|
-
/**
|
|
2326
|
-
* Binds single-key shortcuts on the window, ignoring keys typed into fields, chords with Ctrl, Meta
|
|
2327
|
-
* or Alt, IME composition and (unless `repeat`) held keys. Pass the same list to `KeysLegend`.
|
|
2328
|
-
*/
|
|
2329
|
-
function useHotkeys(shortcuts, { enabled = true } = {}) {
|
|
2330
|
-
const latest = React.useRef([]);
|
|
2331
|
-
latest.current = toShortcuts(shortcuts);
|
|
2332
|
-
React.useEffect(() => {
|
|
2333
|
-
if (!enabled) return;
|
|
2334
|
-
const onKeyDown = (e) => {
|
|
2335
|
-
if (e.defaultPrevented || e.isComposing || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
2336
|
-
if (isTypingTarget(e.target)) return;
|
|
2337
|
-
const hit = latest.current.find((s) => !s.disabled && s.keys.includes(e.key));
|
|
2338
|
-
if (!hit || e.repeat && !hit.repeat) return;
|
|
2339
|
-
e.preventDefault();
|
|
2340
|
-
hit.run();
|
|
2341
|
-
};
|
|
2342
|
-
window.addEventListener("keydown", onKeyDown);
|
|
2343
|
-
return () => window.removeEventListener("keydown", onKeyDown);
|
|
2344
|
-
}, [enabled]);
|
|
2345
|
-
}
|
|
2346
|
-
var KEY_NAMES = {
|
|
2347
|
-
ArrowDown: "↓",
|
|
2348
|
-
ArrowUp: "↑",
|
|
2349
|
-
ArrowLeft: "←",
|
|
2350
|
-
ArrowRight: "→",
|
|
2351
|
-
Escape: "Esc",
|
|
2352
|
-
Enter: "Enter",
|
|
2353
|
-
Backspace: "Backspace",
|
|
2354
|
-
Delete: "Delete",
|
|
2355
|
-
" ": "Space"
|
|
2356
|
-
};
|
|
2357
|
-
/** A quiet legend of the screen's shortcuts, from the same list `useHotkeys` binds. Hidden on touch screens. */
|
|
2358
|
-
function KeysLegend({ shortcuts, label = "Keyboard shortcuts", className }) {
|
|
2359
|
-
return /* @__PURE__ */ jsx("dl", {
|
|
2360
|
-
"aria-label": label,
|
|
2361
|
-
className: cn("flex flex-wrap gap-x-4 gap-y-1 type-caption text-muted-foreground pointer-coarse:hidden", className),
|
|
2362
|
-
children: shortcuts.map((s) => /* @__PURE__ */ jsxs("div", {
|
|
2363
|
-
className: cn("flex items-center gap-1.5", s.disabled && "opacity-50"),
|
|
2364
|
-
children: [/* @__PURE__ */ jsx("dt", {
|
|
2365
|
-
className: "flex items-center gap-1",
|
|
2366
|
-
children: s.keys.map((k, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("span", {
|
|
2367
|
-
className: "sr-only",
|
|
2368
|
-
children: " or "
|
|
2369
|
-
}), /* @__PURE__ */ jsx("kbd", {
|
|
2370
|
-
className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono text-foreground",
|
|
2371
|
-
children: KEY_NAMES[k] ?? k
|
|
2372
|
-
})] }, k))
|
|
2373
|
-
}), /* @__PURE__ */ jsx("dd", { children: s.label })]
|
|
2374
|
-
}, s.keys.join(" ")))
|
|
2375
|
-
});
|
|
2376
|
-
}
|
|
2377
3372
|
// src/components/active-list.tsx
|
|
2378
3373
|
/** Tracks the active item in a list worked through from the keyboard: moving, roving focus, and moving on when the active item is removed. */
|
|
2379
3374
|
function useActiveItem(items, getKey, { initial, noun } = {}) {
|
|
@@ -2615,6 +3610,36 @@ function nextAfter(pages, items, itemKey, hidden) {
|
|
|
2615
3610
|
if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
|
|
2616
3611
|
return held[held.length - 1];
|
|
2617
3612
|
}
|
|
2618
|
-
|
|
3613
|
+
// src/query/job.ts
|
|
3614
|
+
/** A long-running job's status: polled every `every` ms while `isRunning`, with the `invalidates` queries read again once when it ends. */
|
|
3615
|
+
function useJob({ isRunning, every = 2e3, invalidates = [], describeError, ...options }) {
|
|
3616
|
+
const client = useQueryClient();
|
|
3617
|
+
const query = useQuery({
|
|
3618
|
+
...options,
|
|
3619
|
+
refetchInterval: (q) => q.state.data !== void 0 && isRunning(q.state.data) ? every : false
|
|
3620
|
+
});
|
|
3621
|
+
const running = query.data !== void 0 && isRunning(query.data);
|
|
3622
|
+
const queryHash = hashKey(options.queryKey);
|
|
3623
|
+
const seen = query.data === void 0 ? void 0 : running;
|
|
3624
|
+
const was = React.useRef(void 0);
|
|
3625
|
+
React.useEffect(() => {
|
|
3626
|
+
if (seen === void 0) return;
|
|
3627
|
+
const before = was.current;
|
|
3628
|
+
if (before && before.query === queryHash && before.running && !seen) for (const queryKey of before.invalidates) client.invalidateQueries({ queryKey });
|
|
3629
|
+
was.current = {
|
|
3630
|
+
query: queryHash,
|
|
3631
|
+
running: seen,
|
|
3632
|
+
invalidates
|
|
3633
|
+
};
|
|
3634
|
+
});
|
|
3635
|
+
const { refetch } = query;
|
|
3636
|
+
const poll = React.useCallback(() => void refetch(), [refetch]);
|
|
3637
|
+
return {
|
|
3638
|
+
...toLoad(query, describeError),
|
|
3639
|
+
running,
|
|
3640
|
+
poll
|
|
3641
|
+
};
|
|
3642
|
+
}
|
|
3643
|
+
export { ActiveList, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CommandLegend, CommandMenu, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, StaleNotice, Status, StrataQueryProvider, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
2619
3644
|
|
|
2620
3645
|
//# sourceMappingURL=index.js.map
|