@volvel/ui 0.0.0-stage → 0.7.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.
Files changed (137) hide show
  1. package/LICENSE +202 -0
  2. package/THIRD_PARTY_NOTICES.md +23036 -0
  3. package/dist/Badge.d.ts +20 -0
  4. package/dist/Badge.js +35 -0
  5. package/dist/Button.d.ts +56 -0
  6. package/dist/Button.js +52 -0
  7. package/dist/Chart.d.ts +23 -0
  8. package/dist/Chart.js +98 -0
  9. package/dist/Combobox.d.ts +45 -0
  10. package/dist/Combobox.js +42 -0
  11. package/dist/ContextMenu.d.ts +16 -0
  12. package/dist/ContextMenu.js +38 -0
  13. package/dist/DateInput.d.ts +31 -0
  14. package/dist/DateInput.js +329 -0
  15. package/dist/Details.d.ts +12 -0
  16. package/dist/Details.js +9 -0
  17. package/dist/Dialog.d.ts +44 -0
  18. package/dist/Dialog.js +95 -0
  19. package/dist/Dialogs.d.ts +56 -0
  20. package/dist/Dialogs.js +95 -0
  21. package/dist/Doc.d.ts +25 -0
  22. package/dist/Doc.js +118 -0
  23. package/dist/DocServed.d.ts +6 -0
  24. package/dist/DocServed.js +154 -0
  25. package/dist/DocZoom.d.ts +11 -0
  26. package/dist/DocZoom.js +133 -0
  27. package/dist/Facts.d.ts +12 -0
  28. package/dist/Facts.js +10 -0
  29. package/dist/Fields.d.ts +184 -0
  30. package/dist/Fields.js +249 -0
  31. package/dist/Form.d.ts +47 -0
  32. package/dist/Form.js +189 -0
  33. package/dist/Grid.d.ts +118 -0
  34. package/dist/Grid.js +475 -0
  35. package/dist/HeadingSlot.d.ts +13 -0
  36. package/dist/HeadingSlot.js +19 -0
  37. package/dist/JsonView.d.ts +11 -0
  38. package/dist/JsonView.js +68 -0
  39. package/dist/LogViewer.d.ts +45 -0
  40. package/dist/LogViewer.js +299 -0
  41. package/dist/Markdown.d.ts +21 -0
  42. package/dist/Markdown.js +27 -0
  43. package/dist/MarkdownBody.d.ts +6 -0
  44. package/dist/MarkdownBody.js +14 -0
  45. package/dist/Menu.d.ts +29 -0
  46. package/dist/Menu.js +8 -0
  47. package/dist/MoveButtons.d.ts +19 -0
  48. package/dist/MoveButtons.js +22 -0
  49. package/dist/Notice.d.ts +47 -0
  50. package/dist/Notice.js +50 -0
  51. package/dist/PageShell.d.ts +42 -0
  52. package/dist/PageShell.js +14 -0
  53. package/dist/Pagination.d.ts +13 -0
  54. package/dist/Pagination.js +9 -0
  55. package/dist/Panel.d.ts +31 -0
  56. package/dist/Panel.js +33 -0
  57. package/dist/Pickers.d.ts +37 -0
  58. package/dist/Pickers.js +44 -0
  59. package/dist/Popover.d.ts +24 -0
  60. package/dist/Popover.js +12 -0
  61. package/dist/ResultView.d.ts +28 -0
  62. package/dist/ResultView.js +140 -0
  63. package/dist/SchemaForm.d.ts +45 -0
  64. package/dist/SchemaForm.js +626 -0
  65. package/dist/SideSheet.d.ts +31 -0
  66. package/dist/SideSheet.js +136 -0
  67. package/dist/Sparkline.d.ts +14 -0
  68. package/dist/Sparkline.js +23 -0
  69. package/dist/Surfaces.d.ts +30 -0
  70. package/dist/Surfaces.js +34 -0
  71. package/dist/Switch.d.ts +18 -0
  72. package/dist/Switch.js +11 -0
  73. package/dist/Table.d.ts +15 -0
  74. package/dist/Table.js +6 -0
  75. package/dist/Tabs.d.ts +32 -0
  76. package/dist/Tabs.js +11 -0
  77. package/dist/Term.d.ts +82 -0
  78. package/dist/Term.js +153 -0
  79. package/dist/Timeline.d.ts +29 -0
  80. package/dist/Timeline.js +39 -0
  81. package/dist/Toast.d.ts +43 -0
  82. package/dist/Toast.js +140 -0
  83. package/dist/Tooltip.d.ts +34 -0
  84. package/dist/Tooltip.js +70 -0
  85. package/dist/Tree.d.ts +51 -0
  86. package/dist/Tree.js +233 -0
  87. package/dist/chartEngine.d.ts +32 -0
  88. package/dist/chartEngine.js +72 -0
  89. package/dist/chartTheme.d.ts +41 -0
  90. package/dist/chartTheme.js +131 -0
  91. package/dist/contrast.d.ts +27 -0
  92. package/dist/contrast.js +110 -0
  93. package/dist/dates.d.ts +61 -0
  94. package/dist/dates.js +294 -0
  95. package/dist/drawer/Chips.d.ts +37 -0
  96. package/dist/drawer/Chips.js +32 -0
  97. package/dist/drawer/Choices.d.ts +47 -0
  98. package/dist/drawer/Choices.js +81 -0
  99. package/dist/drawer/Drawer.d.ts +125 -0
  100. package/dist/drawer/Drawer.js +150 -0
  101. package/dist/drawer/EditorBodies.d.ts +95 -0
  102. package/dist/drawer/EditorBodies.js +169 -0
  103. package/dist/drawer/NumberFormat.d.ts +36 -0
  104. package/dist/drawer/NumberFormat.js +98 -0
  105. package/dist/drawer/SortableRows.d.ts +35 -0
  106. package/dist/drawer/SortableRows.js +23 -0
  107. package/dist/drawer/edgeShadows.d.ts +7 -0
  108. package/dist/drawer/edgeShadows.js +17 -0
  109. package/dist/drawer/index.d.ts +8 -0
  110. package/dist/drawer/index.js +8 -0
  111. package/dist/drawer/useSortable.d.ts +53 -0
  112. package/dist/drawer/useSortable.js +323 -0
  113. package/dist/format.d.ts +6 -0
  114. package/dist/format.js +17 -0
  115. package/dist/icons.d.ts +20 -0
  116. package/dist/icons.js +16 -0
  117. package/dist/index.d.ts +48 -0
  118. package/dist/index.js +48 -0
  119. package/dist/markdownKnowledge.d.ts +45 -0
  120. package/dist/markdownKnowledge.js +37 -0
  121. package/dist/overlay.d.ts +7 -0
  122. package/dist/overlay.js +10 -0
  123. package/dist/pageIcons.d.ts +12 -0
  124. package/dist/pageIcons.js +32 -0
  125. package/dist/presence.d.ts +41 -0
  126. package/dist/presence.js +108 -0
  127. package/dist/returnFocus.d.ts +9 -0
  128. package/dist/returnFocus.js +44 -0
  129. package/dist/tokens.css +437 -0
  130. package/dist/type-scale.css +34 -0
  131. package/dist/useFlip.d.ts +32 -0
  132. package/dist/useFlip.js +118 -0
  133. package/fonts/OFL.txt +193 -0
  134. package/fonts/geist-latin.woff2 +0 -0
  135. package/fonts/geist-mono-latin.woff2 +0 -0
  136. package/package.json +52 -3
  137. package/README.md +0 -3
package/dist/Grid.js ADDED
@@ -0,0 +1,475 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronDown, ChevronUp } from "lucide-react";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import { TermText, Toggletip, useGlossaryMatch } from "./Term.js";
5
+ /**
6
+ * The ⓘ beside a column's heading that says what the column holds. Pressing it
7
+ * does not sort. `term` is for a heading that is itself a button and so cannot
8
+ * underline a word: a term of the glossary it uses is then explained here.
9
+ */
10
+ function About({ column, term = false }) {
11
+ const name = column.label ?? column.name;
12
+ const found = useGlossaryMatch(name);
13
+ const meaning = term && found ? found : undefined;
14
+ if (!column.description && !meaning)
15
+ return null;
16
+ return (_jsx("span", { className: "ml-1 inline-flex align-middle font-normal normal-case",
17
+ // Only the press: a key pressed here still reaches the page, so F1 and ⌘K work from it.
18
+ onClick: (event) => event.stopPropagation(), children: _jsxs(Toggletip, { label: `About ${name}`, title: name, children: [column.description, meaning ? (_jsxs("p", { className: column.description ? "m-0 mt-2" : "m-0", children: [_jsxs("span", { className: "font-medium text-ink", children: [meaning.term, ":"] }), " ", meaning.short] })) : null] }) }));
19
+ }
20
+ const NUMERIC = new Set(["integer", "number"]);
21
+ /** The sort as a list, whether it was given as one column or several. */
22
+ const sortsOf = (sort) => sort === undefined ? [] : Array.isArray(sort) ? sort : [sort];
23
+ /**
24
+ * Whether a key typed into a field of the grid stays there. The grid's own keys do;
25
+ * the page's, F1 for help and ⌘K for the palette, go on to the shortcuts above.
26
+ */
27
+ export function keepsKey(event) {
28
+ if (event.key === "F1")
29
+ return false;
30
+ return !((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k");
31
+ }
32
+ const pad2 = (n) => String(n).padStart(2, "0");
33
+ /**
34
+ * A stored moment as the reader's own clock shows it, `2026-06-01 09:00` (with seconds when it
35
+ * has some). The same text is shown in a cell being edited and in the row's inspector, and
36
+ * read back by `instantFromText`: a time is shown, typed and filtered in one zone (D21).
37
+ */
38
+ export function localWall(instant, separator = " ") {
39
+ const at = new Date(instant);
40
+ if (Number.isNaN(at.getTime()))
41
+ return instant;
42
+ const day = `${at.getFullYear()}-${pad2(at.getMonth() + 1)}-${pad2(at.getDate())}`;
43
+ const time = `${pad2(at.getHours())}:${pad2(at.getMinutes())}`;
44
+ return `${day}${separator}${time}${at.getSeconds() === 0 ? "" : `:${pad2(at.getSeconds())}`}`;
45
+ }
46
+ /** What hovering a time says: the moment in UTC, so a time is never only the reader's guess. */
47
+ export const utcOf = (instant) => {
48
+ const at = new Date(instant);
49
+ return Number.isNaN(at.getTime()) ? undefined : `${at.toISOString()} (UTC)`;
50
+ };
51
+ /**
52
+ * Text typed for a moment, as the instant it means: with a zone (`2026-06-01T09:00:00Z`,
53
+ * `+02:00`) as written, and without one in the reader's own zone. A moment that does not exist
54
+ * (31 February, 25:00) is refused, not moved to another.
55
+ */
56
+ export function instantFromText(text) {
57
+ const said = "Enter a date and time that exists, such as 2026-06-01 09:00.";
58
+ const zoned = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})$/i.test(text);
59
+ const local = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/.exec(text);
60
+ if (zoned) {
61
+ const at = new Date(text.replace(" ", "T"));
62
+ if (Number.isNaN(at.getTime()))
63
+ throw new Error(said);
64
+ return at.toISOString();
65
+ }
66
+ if (!local)
67
+ throw new Error(said);
68
+ const [year, month, day, hour = 0, minute = 0, second = 0] = local
69
+ .slice(1)
70
+ .map((part) => (part === undefined ? undefined : Number(part)));
71
+ const at = new Date(year, month - 1, day, hour, minute, second);
72
+ // A day or hour that does not exist comes out as another: the text must read back as it was.
73
+ if (Number.isNaN(at.getTime()) ||
74
+ at.getFullYear() !== year ||
75
+ at.getMonth() !== month - 1 ||
76
+ at.getDate() !== day ||
77
+ at.getHours() !== hour ||
78
+ at.getMinutes() !== minute)
79
+ throw new Error(said);
80
+ return at.toISOString();
81
+ }
82
+ /** A stored value as text a person can read and edit. */
83
+ export function showValue(type, value) {
84
+ if (value === null || value === undefined)
85
+ return "";
86
+ // Several of a column's values, as they are typed: with commas between.
87
+ if (type === "enum_list" && Array.isArray(value))
88
+ return value.join(", ");
89
+ if (type === "json" || typeof value === "object")
90
+ return JSON.stringify(value);
91
+ if (type === "boolean")
92
+ return value ? "Yes" : "No";
93
+ if (type === "timestamp" && typeof value === "string") {
94
+ const at = new Date(value);
95
+ if (!Number.isNaN(at.getTime())) {
96
+ return at.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
97
+ }
98
+ }
99
+ return String(value);
100
+ }
101
+ /** The text a cell is edited as: the stored value, not its friendly form. */
102
+ function editText(type, value) {
103
+ if (value === null || value === undefined)
104
+ return "";
105
+ // Several of a column's values, as they are typed: with commas between.
106
+ if (type === "enum_list" && Array.isArray(value))
107
+ return value.join(", ");
108
+ if (type === "json" || typeof value === "object")
109
+ return JSON.stringify(value);
110
+ if (type === "timestamp" && typeof value === "string")
111
+ return localWall(value);
112
+ return String(value);
113
+ }
114
+ /**
115
+ * Turns typed text into a value of the column's type. Empty text means no value.
116
+ * Throws with a message for text that cannot be that type.
117
+ */
118
+ export function parseValue(type, text) {
119
+ const trimmed = text.trim();
120
+ if (trimmed === "")
121
+ return null;
122
+ if (NUMERIC.has(type)) {
123
+ const number = Number(trimmed);
124
+ if (Number.isNaN(number))
125
+ throw new Error("Enter a number.");
126
+ if (type === "integer" && !Number.isInteger(number))
127
+ throw new Error("Enter a whole number.");
128
+ return number;
129
+ }
130
+ if (type === "boolean") {
131
+ if (/^(true|yes|y|1)$/i.test(trimmed))
132
+ return true;
133
+ if (/^(false|no|n|0)$/i.test(trimmed))
134
+ return false;
135
+ throw new Error("Enter yes or no.");
136
+ }
137
+ if (type === "enum_list") {
138
+ return trimmed
139
+ .split(",")
140
+ .map((one) => one.trim())
141
+ .filter(Boolean);
142
+ }
143
+ if (type === "json") {
144
+ try {
145
+ return JSON.parse(trimmed);
146
+ }
147
+ catch {
148
+ throw new Error("Enter valid JSON.");
149
+ }
150
+ }
151
+ if (type === "timestamp")
152
+ return instantFromText(trimmed);
153
+ if (type === "date") {
154
+ const day = /^(\d{4})-(\d{2})-(\d{2})$/.exec(trimmed);
155
+ const at = day ? new Date(Date.UTC(Number(day[1]), Number(day[2]) - 1, Number(day[3]))) : null;
156
+ if (!day ||
157
+ !at ||
158
+ at.getUTCFullYear() !== Number(day[1]) ||
159
+ at.getUTCMonth() !== Number(day[2]) - 1 ||
160
+ at.getUTCDate() !== Number(day[3]))
161
+ throw new Error("Enter a day that exists, such as 2026-06-01.");
162
+ return trimmed;
163
+ }
164
+ return type === "text" ? text : trimmed;
165
+ }
166
+ function EditableCell({ row, column, shown, onEdit, editing, onEnd, editor, }) {
167
+ const [own, setText] = useState();
168
+ // Set by Escape: the blur that follows as the input goes must not save what was typed.
169
+ const cancelled = useRef(false);
170
+ const controlled = editing !== undefined;
171
+ const text = controlled
172
+ ? editing && column.type !== "boolean"
173
+ ? (own ?? editText(column.type, row[column.name]))
174
+ : undefined
175
+ : own;
176
+ const [error, setError] = useState();
177
+ const [busy, setBusy] = useState(false);
178
+ const value = row[column.name];
179
+ const save = async (next) => {
180
+ setBusy(true);
181
+ setError(undefined);
182
+ try {
183
+ await onEdit(row, column.name, next);
184
+ setText(undefined);
185
+ onEnd?.(true);
186
+ }
187
+ catch (caught) {
188
+ setError(caught.message);
189
+ }
190
+ finally {
191
+ setBusy(false);
192
+ }
193
+ };
194
+ // In a navigable grid, a yes/no cell is not typed into: Enter, F2 and a double-click all toggle
195
+ // it here, and a refusal is said in the cell instead of being dropped.
196
+ const toggling = useRef(() => { });
197
+ toggling.current = () => {
198
+ onEnd?.(false);
199
+ // A cell that may be empty goes round: empty, yes, no, empty.
200
+ void save(column.clearable ? (value === true ? false : value === false ? null : true) : value !== true);
201
+ };
202
+ const flipping = controlled && editing === true && column.type === "boolean";
203
+ useEffect(() => {
204
+ if (flipping)
205
+ toggling.current();
206
+ }, [flipping]);
207
+ if (column.type === "boolean" && !controlled) {
208
+ return (_jsxs("span", { className: "flex flex-col gap-0.5", children: [_jsx("input", { type: "checkbox", className: "size-4 accent-(--vx-action)", checked: value === true, disabled: busy, "aria-label": column.name, onChange: (event) => save(event.currentTarget.checked) }), error ? (_jsx("span", { role: "alert", className: "text-meta text-danger", children: error })) : null] }));
209
+ }
210
+ const control = controlled && editing === true && column.control && editor
211
+ ? editor({
212
+ row,
213
+ column,
214
+ value,
215
+ save: async (next) => {
216
+ setBusy(true);
217
+ setError(undefined);
218
+ try {
219
+ await onEdit(row, column.name, next);
220
+ onEnd?.(true);
221
+ }
222
+ catch (caught) {
223
+ setError(caught.message);
224
+ throw caught;
225
+ }
226
+ finally {
227
+ setBusy(false);
228
+ }
229
+ },
230
+ cancel: () => onEnd?.(true),
231
+ })
232
+ : undefined;
233
+ if (control !== undefined) {
234
+ return (_jsxs("span", { className: "flex min-w-0 flex-col gap-0.5", "aria-busy": busy || undefined, children: [control, error ? (_jsx("span", { role: "alert", className: "text-meta text-danger", children: error })) : null] }));
235
+ }
236
+ if (text === undefined && controlled) {
237
+ return (_jsxs("span", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("span", { className: "block truncate", children: shown }), error ? (_jsx("span", { role: "alert", className: "text-meta text-danger", children: error })) : null] }));
238
+ }
239
+ if (text === undefined) {
240
+ return (_jsx("button", { type: "button", title: "Change this value", className: `-mx-1.5 block min-h-6 w-[calc(100%+0.75rem)] cursor-text rounded-inner px-1.5 text-inherit hover:bg-sunken ${NUMERIC.has(column.type) ? "text-right" : "text-left"}`, onClick: () => setText(editText(column.type, value)), children: shown }));
241
+ }
242
+ const commit = () => {
243
+ if (cancelled.current) {
244
+ cancelled.current = false;
245
+ return;
246
+ }
247
+ if (text === editText(column.type, value)) {
248
+ setText(undefined);
249
+ onEnd?.(false);
250
+ return;
251
+ }
252
+ try {
253
+ return save(parseValue(column.type, text));
254
+ }
255
+ catch (caught) {
256
+ setError(caught.message);
257
+ }
258
+ };
259
+ return (_jsxs("span", { className: "flex flex-col gap-0.5", children: [_jsx("input", {
260
+ // biome-ignore lint/a11y/noAutofocus: the person just asked to edit this cell
261
+ autoFocus: true, "aria-label": column.name, "aria-invalid": error !== undefined, value: text, disabled: busy, className: "-mx-1.5 h-7 w-[calc(100%+0.75rem)] min-w-24 rounded-inner border border-action bg-surface px-1.5 text-ink", onChange: (event) => setText(event.currentTarget.value), onFocus: () => {
262
+ cancelled.current = false;
263
+ }, onBlur: commit, onKeyDown: (event) => {
264
+ // The grid's own keys are not for a cell being edited. The page's are: F1 and ⌘K go on.
265
+ if (keepsKey(event))
266
+ event.stopPropagation();
267
+ if (event.key === "Enter")
268
+ event.currentTarget.blur();
269
+ if (event.key === "Escape") {
270
+ // What was there before is put back, and the cell keeps focus.
271
+ cancelled.current = true;
272
+ setError(undefined);
273
+ setText(undefined);
274
+ onEnd?.(true);
275
+ }
276
+ } }), error ? (_jsx("span", { role: "alert", className: "text-meta text-danger", children: error })) : null] }));
277
+ }
278
+ /**
279
+ * The grid of `navigation="grid"`: one tab stop, cells reached by the keys of
280
+ * the WAI-ARIA grid pattern, a header that stays in view and a first column
281
+ * that stays put.
282
+ *
283
+ * | Key | Does |
284
+ * | Arrows | Move one cell |
285
+ * | Home, End | The row's first or last cell; with Ctrl, the grid's |
286
+ * | Page Up, Page Down | Ten rows |
287
+ * | Enter, F2 | Edit the cell; on a heading, sort by it; on a cell that cannot be edited, choose the row |
288
+ * | Escape | Leave an edit and put back what was there |
289
+ * | Space | Check or uncheck the row |
290
+ */
291
+ function NavigableGrid(props) {
292
+ const { columns, rows, filters, onFilter, onEdit, checked, onCheck } = props;
293
+ const sorts = sortsOf(props.sort);
294
+ const checking = checked !== undefined && onCheck !== undefined;
295
+ const filterable = onFilter !== undefined && columns.some((column) => column.filterable);
296
+ const offset = checking ? 1 : 0;
297
+ const width = columns.length + offset;
298
+ // Row 0 is the headings; rows 1 to n are the data. Column 0 is the checkbox when there is one.
299
+ const [active, setActive] = useState({ r: 1, c: offset });
300
+ const [editing, setEditing] = useState();
301
+ const table = useRef(null);
302
+ const last = { r: rows.length, c: width - 1 };
303
+ const at = {
304
+ r: Math.min(active.r, last.r),
305
+ c: Math.min(active.c, last.c),
306
+ };
307
+ const focus = (r, c) => {
308
+ const next = { r: Math.max(0, Math.min(r, last.r)), c: Math.max(0, Math.min(c, last.c)) };
309
+ setActive(next);
310
+ requestAnimationFrame(() => table.current?.querySelector(`[data-cell="${next.r}:${next.c}"]`)?.focus());
311
+ };
312
+ const pad = props.density === "compact" ? "py-1" : "py-1.5";
313
+ const lockFirst = props.lockFirst ?? true;
314
+ const head = `border-b border-line-strong bg-sunken px-3 text-meta font-medium text-ink-subtle`;
315
+ const all = rows.map((row) => props.rowKey(row));
316
+ // The heading's box is checked when every row shown is, whatever else is checked.
317
+ const everyChecked = checking && all.length > 0 && all.every((key) => checked.has(key));
318
+ const toggle = (key) => {
319
+ if (!checking)
320
+ return;
321
+ const next = new Set(checked);
322
+ if (next.has(key))
323
+ next.delete(key);
324
+ else
325
+ next.add(key);
326
+ onCheck(next);
327
+ };
328
+ const onKeyDown = (event) => {
329
+ if (editing !== undefined)
330
+ return;
331
+ const { r, c } = at;
332
+ const to = (() => {
333
+ switch (event.key) {
334
+ case "ArrowRight":
335
+ return [r, c + 1];
336
+ case "ArrowLeft":
337
+ return [r, c - 1];
338
+ case "ArrowDown":
339
+ return [r + 1, c];
340
+ case "ArrowUp":
341
+ return [r - 1, c];
342
+ case "Home":
343
+ return [event.ctrlKey || event.metaKey ? 1 : r, 0];
344
+ case "End":
345
+ return [event.ctrlKey || event.metaKey ? last.r : r, last.c];
346
+ case "PageDown":
347
+ return [r + 10, c];
348
+ case "PageUp":
349
+ return [Math.max(1, r - 10), c];
350
+ default:
351
+ return undefined;
352
+ }
353
+ })();
354
+ if (to) {
355
+ event.preventDefault();
356
+ focus(to[0], to[1]);
357
+ return;
358
+ }
359
+ const column = columns[c - offset];
360
+ const row = r > 0 ? rows[r - 1] : undefined;
361
+ if (event.key === " " && row && checking) {
362
+ event.preventDefault();
363
+ toggle(props.rowKey(row));
364
+ return;
365
+ }
366
+ if (event.key !== "Enter" && event.key !== "F2")
367
+ return;
368
+ event.preventDefault();
369
+ if (r === 0) {
370
+ if (column?.sortable)
371
+ props.onSort?.(column.name, event.shiftKey);
372
+ else if (c === 0 && checking)
373
+ onCheck(everyChecked ? new Set() : new Set(all));
374
+ return;
375
+ }
376
+ if (!row)
377
+ return;
378
+ if (column?.editable && onEdit && (column.control || props.cell?.(row, column) === undefined)) {
379
+ setEditing(`${r}:${c}`);
380
+ return;
381
+ }
382
+ if (event.key === "Enter")
383
+ props.onSelect?.(row);
384
+ };
385
+ const cellProps = (r, c) => ({
386
+ "data-cell": `${r}:${c}`,
387
+ tabIndex: at.r === r && at.c === c ? 0 : -1,
388
+ onFocus: () => {
389
+ if (at.r !== r || at.c !== c)
390
+ setActive({ r, c });
391
+ },
392
+ });
393
+ return (_jsx("div", { className: `scroll-pt-12 overflow-auto rounded-panel border border-line bg-surface ${props.fill ? "min-h-0 flex-1" : "max-h-[70vh]"}`, children: _jsxs("table", { ref: table,
394
+ // biome-ignore lint/a11y/noNoninteractiveElementToInteractiveRole: a table navigated cell by cell is a grid (WAI-ARIA grid pattern)
395
+ role: "grid", "aria-label": props.label, "aria-rowcount": rows.length + (filterable ? 2 : 1), "aria-multiselectable": checking || undefined, className: "w-full border-separate border-spacing-0 text-left", onKeyDown: onKeyDown, children: [_jsxs("thead", { className: "sticky top-0 layer-sticky", children: [_jsxs("tr", { children: [checking ? (_jsx("th", { scope: "col", className: `${head} sticky left-0 w-8 py-1`, ...cellProps(0, 0), children: _jsx("input", { type: "checkbox", tabIndex: -1, "aria-label": "Check every row on this page",
396
+ // Centred on the line, not set on its baseline: the heading row is as tall as its words, not as a box standing on their baseline.
397
+ className: "align-middle size-4 accent-(--vx-action)", checked: everyChecked, onChange: () => onCheck(everyChecked ? new Set() : new Set(all)) }) })) : null, columns.map((column, index) => {
398
+ const place = sorts.findIndex((one) => one.column === column.name);
399
+ const sorted = place >= 0 ? sorts[place] : undefined;
400
+ const pinned = lockFirst && index === 0 ? `sticky ${checking ? "left-8" : "left-0"}` : "";
401
+ return (_jsxs("th", { scope: "col", "aria-sort": sorted ? (sorted.descending ? "descending" : "ascending") : undefined, className: `${head} py-1 whitespace-nowrap ${pinned} ${NUMERIC.has(column.type) ? "text-right" : ""} ${column.sortable && props.onSort ? "cursor-pointer hover:text-ink" : ""}`, onClick: (event) => column.sortable && props.onSort?.(column.name, event.shiftKey), ...cellProps(0, index + offset), children: [_jsx(TermText, { children: column.label ?? column.name }), _jsx(About, { column: column }), sorted ? (_jsxs("span", { "aria-hidden": "true", className: "ml-1 inline-flex align-middle text-action", children: [sorted.descending ? _jsx(ChevronDown, { size: 14 }) : _jsx(ChevronUp, { size: 14 }), sorts.length > 1 ? _jsx("span", { className: "text-meta", children: place + 1 }) : null] })) : null] }, column.name));
402
+ })] }), filterable ? (_jsxs("tr", { children: [checking ? _jsx("td", { className: `${head} sticky left-0 pb-0.5` }) : null, columns.map((column, index) => (_jsx("td", { className: `${head} pb-0.5 font-normal ${lockFirst && index === 0 ? `sticky ${checking ? "left-8" : "left-0"}` : ""}`, children: column.filterable ? (_jsx("input", { "aria-label": `Filter by ${column.label ?? column.name}`, "aria-invalid": props.filterErrors?.[column.name] !== undefined ? true : undefined, placeholder: "Filter", value: filters?.[column.name] ?? "", className: "h-6 w-full min-w-20 rounded-inner border border-line-control bg-surface px-1.5 text-ink placeholder:text-ink-muted/60 aria-[invalid=true]:border-danger", onChange: (event) => onFilter?.(column.name, event.currentTarget.value), onKeyDown: (event) => {
403
+ if (keepsKey(event))
404
+ event.stopPropagation();
405
+ if (event.key === "Enter")
406
+ event.currentTarget.blur();
407
+ } })) : null }, column.name)))] })) : null] }), _jsx("tbody", { children: rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: width, className: "px-3 py-6 text-ink-muted", children: props.empty }) })) : (rows.map((row, rowIndex) => {
408
+ const r = rowIndex + 1;
409
+ const key = props.rowKey(row);
410
+ const chosen = props.selectedKey === key;
411
+ const ticked = checking && checked.has(key);
412
+ const ground = chosen ? "bg-selected" : ticked ? "bg-action-soft/40" : "bg-surface";
413
+ return (_jsxs("tr", { "aria-rowindex": rowIndex + (filterable ? 3 : 2), "aria-selected": checking ? ticked : chosen, className: `${ground} hover:bg-sunken/60`, onClick: (event) => {
414
+ if (event.target.closest("input, a, button"))
415
+ return;
416
+ props.onSelect?.(row);
417
+ }, children: [checking ? (_jsx("td", { className: `sticky left-0 w-8 border-line border-b px-3 ${pad} ${ground}`, ...cellProps(r, 0), children: _jsx("input", { type: "checkbox", tabIndex: -1, "aria-label": `Check row ${key}`, className: "size-4 accent-(--vx-action)", checked: ticked, onChange: () => toggle(key) }) })) : null, columns.map((column, index) => {
418
+ const c = index + offset;
419
+ const value = row[column.name];
420
+ const custom = props.cell?.(row, column);
421
+ const shown = custom !== undefined ? (custom) : value === null || value === undefined ? (_jsx("span", { className: "text-ink-muted/60", children: "empty" })) : column.type === "timestamp" && typeof value === "string" ? (_jsx("span", { title: utcOf(value), children: showValue(column.type, value) })) : (showValue(column.type, value));
422
+ const here = `${r}:${c}`;
423
+ return (_jsx("td", { className: `max-w-80 truncate border-line border-b px-3 align-middle ${pad} ${NUMERIC.has(column.type) ? "text-right tabular-nums" : ""} ${lockFirst && index === 0 ? `sticky ${checking ? "left-8" : "left-0"} ${ground}` : ""}`, onDoubleClick: () => {
424
+ if (column.editable &&
425
+ onEdit &&
426
+ (column.control || custom === undefined)) {
427
+ setActive({ r, c });
428
+ setEditing(here);
429
+ }
430
+ }, ...cellProps(r, c), children: column.editable && onEdit && (column.control || custom === undefined) ? (_jsx(EditableCell, { row: row, column: column, shown: shown, onEdit: onEdit, ...(props.editor ? { editor: props.editor } : {}), editing: editing === here, onEnd: (back) => {
431
+ setEditing(undefined);
432
+ if (back)
433
+ focus(r, c);
434
+ } })) : (shown) }, column.name));
435
+ })] }, key));
436
+ })) })] }) }));
437
+ }
438
+ /** Rows and columns of data, with sorting, a filter under each heading and editing in place. */
439
+ export function Grid(props) {
440
+ return props.navigation === "grid" ? _jsx(NavigableGrid, { ...props }) : _jsx(PlainGrid, { ...props });
441
+ }
442
+ /** The grid tenant apps have had: each value to change is a button of its own. */
443
+ function PlainGrid(props) {
444
+ const { columns, rows, filters, onFilter, onEdit } = props;
445
+ // This grid sorts by one column: of several, the first.
446
+ const sort = sortsOf(props.sort)[0];
447
+ const filterable = onFilter !== undefined && columns.some((column) => column.filterable);
448
+ const choosing = props.onSelect !== undefined;
449
+ const group = useId();
450
+ const width = columns.length + (props.rowActions ? 1 : 0) + (choosing ? 1 : 0);
451
+ const head = "border-b border-line bg-sunken/50 px-3 text-body-sm font-medium text-ink-muted";
452
+ return (_jsx("div", { className: "overflow-x-auto rounded-panel border border-line bg-surface", children: _jsxs("table", { className: "w-full border-collapse text-left", "aria-label": props.label, children: [_jsxs("thead", { children: [_jsxs("tr", { children: [choosing ? _jsx("th", { className: `${head} w-8 py-1` }) : null, columns.map((column) => {
453
+ const sorted = sort?.column === column.name ? sort : undefined;
454
+ const end = NUMERIC.has(column.type) ? "text-right" : "";
455
+ return (_jsxs("th", { scope: "col", "aria-sort": sorted ? (sorted.descending ? "descending" : "ascending") : undefined, className: `${head} py-1 whitespace-nowrap ${end}`, children: [column.sortable && props.onSort ? (_jsxs("button", { type: "button", className: "inline-flex items-center gap-1 font-medium text-inherit hover:text-ink", onClick: (event) => props.onSort?.(column.name, event.shiftKey), children: [column.label ?? column.name, _jsx("span", { "aria-hidden": "true", className: `inline-flex ${sorted ? "text-action" : "opacity-0"}`, children: sorted?.descending ? _jsx(ChevronDown, { size: 14 }) : _jsx(ChevronUp, { size: 14 }) })] })) : (_jsx(TermText, { children: column.label ?? column.name })), _jsx(About, { column: column, term: Boolean(column.sortable && props.onSort) })] }, column.name));
456
+ }), props.rowActions ? _jsx("th", { className: `${head} py-1` }) : null] }), filterable ? (_jsxs("tr", { children: [choosing ? _jsx("th", { className: `${head} pb-2` }) : null, columns.map((column) => (_jsx("th", { className: `${head} pb-2 font-normal`, children: column.filterable ? (_jsx("input", { "aria-label": `Filter by ${column.label ?? column.name}`, "aria-invalid": props.filterErrors?.[column.name] !== undefined ? true : undefined, placeholder: "Filter", value: filters?.[column.name] ?? "", className: "h-7 w-full min-w-20 rounded-inner border border-line-control bg-surface px-1.5 text-ink placeholder:text-ink-muted/60 aria-[invalid=true]:border-danger", onChange: (event) => onFilter?.(column.name, event.currentTarget.value), onKeyDown: (event) => {
457
+ if (event.key === "Enter")
458
+ event.currentTarget.blur();
459
+ } })) : null }, column.name))), props.rowActions ? _jsx("th", { className: `${head} pb-2` }) : null] })) : null] }), _jsx("tbody", { children: rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: width, className: "px-3 py-6 text-ink-muted", children: props.empty }) })) : (rows.map((row) => {
460
+ const key = props.rowKey(row);
461
+ const chosen = choosing && props.selectedKey === key;
462
+ return (_jsxs("tr", { "aria-selected": choosing ? chosen : undefined, className: `border-b border-line last:border-b-0 ${chosen ? "bg-action-soft/50" : ""} ${choosing ? "cursor-pointer" : ""}`, onClick: (event) => {
463
+ // A press on something in the row that does its own thing is not a choice of the row.
464
+ if (event.target.closest("button, input, a, select, textarea")) {
465
+ return;
466
+ }
467
+ props.onSelect?.(row);
468
+ }, children: [choosing ? (_jsx("td", { className: "w-8 px-3 py-1.5 align-middle", children: _jsx("input", { type: "radio", name: group, "aria-label": "Choose this row", checked: chosen, onChange: () => props.onSelect?.(row) }) })) : null, columns.map((column) => {
469
+ const value = row[column.name];
470
+ const custom = props.cell?.(row, column);
471
+ const shown = custom !== undefined ? (custom) : value === null || value === undefined ? (_jsx("span", { className: "text-ink-muted/60", children: "empty" })) : column.type === "timestamp" && typeof value === "string" ? (_jsx("span", { title: utcOf(value), children: showValue(column.type, value) })) : (showValue(column.type, value));
472
+ return (_jsx("td", { className: `max-w-80 truncate px-3 py-1.5 align-middle ${NUMERIC.has(column.type) ? "text-right tabular-nums" : ""}`, children: column.editable && onEdit && custom === undefined ? (_jsx(EditableCell, { row: row, column: column, shown: shown, onEdit: onEdit })) : (shown) }, column.name));
473
+ }), props.rowActions ? (_jsx("td", { className: "px-3 py-1.5 text-right align-middle whitespace-nowrap", children: props.rowActions(row) })) : null] }, key));
474
+ })) })] }) }));
475
+ }
@@ -0,0 +1,13 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * The place on a widget's heading row, at its right, that a view may put controls in: a table's
4
+ * "New invoice" button sits beside its title, so on a phone it is not alone on a line of its own.
5
+ * The frame around the widget gives it; a view drawn with no frame (a test, a modal) gets none.
6
+ */
7
+ export declare const HeadingSlot: import("react").Context<HTMLElement | null>;
8
+ /** What a view puts on its widget's heading row. With no heading row to put it in, it is drawn where it is. */
9
+ export declare function OnHeading({ children }: {
10
+ children: ReactNode;
11
+ }): import("react").JSX.Element;
12
+ /** Whether a widget's configuration has controls for its heading row, so that the frame keeps the row for them. */
13
+ export declare function hasHeadingControls(config: Readonly<Record<string, unknown>> | undefined): boolean;
@@ -0,0 +1,19 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { createPortal } from "react-dom";
4
+ /**
5
+ * The place on a widget's heading row, at its right, that a view may put controls in: a table's
6
+ * "New invoice" button sits beside its title, so on a phone it is not alone on a line of its own.
7
+ * The frame around the widget gives it; a view drawn with no frame (a test, a modal) gets none.
8
+ */
9
+ export const HeadingSlot = createContext(null);
10
+ /** What a view puts on its widget's heading row. With no heading row to put it in, it is drawn where it is. */
11
+ export function OnHeading({ children }) {
12
+ const slot = useContext(HeadingSlot);
13
+ return slot ? createPortal(children, slot) : _jsx(_Fragment, { children: children });
14
+ }
15
+ /** Whether a widget's configuration has controls for its heading row, so that the frame keeps the row for them. */
16
+ export function hasHeadingControls(config) {
17
+ const buttons = config?.buttons;
18
+ return Array.isArray(buttons) && buttons.length > 0;
19
+ }
@@ -0,0 +1,11 @@
1
+ export interface JsonViewProps {
2
+ /** Any value that JSON can hold. `undefined` shows as a dash. */
3
+ value: unknown;
4
+ /** Names the block for screen readers: "Input". */
5
+ label: string;
6
+ tone?: "plain" | "danger";
7
+ /** The tallest the block grows before it scrolls, as a CSS length. */
8
+ maxHeight?: string;
9
+ }
10
+ /** A value shown as indented, colored JSON, with a button to copy it. */
11
+ export declare function JsonView({ value, label, tone, maxHeight }: JsonViewProps): import("react").JSX.Element;
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ const TONES = {
4
+ key: "text-action",
5
+ string: "text-success",
6
+ number: "text-attention",
7
+ literal: "text-ink-muted",
8
+ };
9
+ /** Splits pretty-printed JSON into colored pieces. Text that is not JSON is left as it is. */
10
+ function paint(text) {
11
+ const pieces = [];
12
+ const token = /("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g;
13
+ let last = 0;
14
+ let index = 0;
15
+ for (const match of text.matchAll(token)) {
16
+ const at = match.index ?? 0;
17
+ if (at > last)
18
+ pieces.push(text.slice(last, at));
19
+ const [whole, quoted, colon, literal] = match;
20
+ const tone = quoted
21
+ ? colon
22
+ ? TONES.key
23
+ : TONES.string
24
+ : literal
25
+ ? TONES.literal
26
+ : TONES.number;
27
+ pieces.push(_jsx("span", { className: tone, children: quoted ?? whole }, index++));
28
+ if (colon)
29
+ pieces.push(colon);
30
+ last = at + whole.length;
31
+ }
32
+ if (last < text.length)
33
+ pieces.push(text.slice(last));
34
+ return pieces;
35
+ }
36
+ /**
37
+ * What the server sends in place of a payload too large to send (`{ stored: "runs/…/output.json" }`):
38
+ * the one key and a path under a run's folder.
39
+ */
40
+ function keptApart(value) {
41
+ if (typeof value !== "object" || value === null || Array.isArray(value))
42
+ return undefined;
43
+ const keys = Object.keys(value);
44
+ const stored = value.stored;
45
+ return keys.length === 1 &&
46
+ typeof stored === "string" &&
47
+ /^(runs|flow-runs)\/.+\.json$/.test(stored)
48
+ ? stored
49
+ : undefined;
50
+ }
51
+ /** A value shown as indented, colored JSON, with a button to copy it. */
52
+ export function JsonView({ value, label, tone = "plain", maxHeight = "18rem" }) {
53
+ const [copied, setCopied] = useState(false);
54
+ const kept = keptApart(value);
55
+ const text = value === undefined || kept ? "" : JSON.stringify(value, null, 2);
56
+ return (_jsxs("div", { "data-well": true, className: `group relative rounded-control border ${tone === "danger" ? "border-danger/40 bg-danger-soft" : "border-line bg-sunken"}`, children: [text ? (_jsx("button", { type: "button", className: "absolute top-1.5 right-1.5 rounded-inner border border-line bg-surface px-1.5 py-0.5 text-meta text-ink-muted opacity-0 hover:text-ink focus:opacity-100 group-hover:opacity-100", onClick: async () => {
57
+ try {
58
+ await navigator.clipboard.writeText(text);
59
+ setCopied(true);
60
+ setTimeout(() => setCopied(false), 1500);
61
+ }
62
+ catch {
63
+ // No clipboard here: the text can still be selected.
64
+ }
65
+ }, children: copied ? "Copied" : "Copy" })) : null, _jsx("section", { "aria-label": label,
66
+ // biome-ignore lint/a11y/noNoninteractiveTabindex: a block that scrolls must be reachable by keyboard
67
+ tabIndex: 0, style: { maxHeight }, className: "overflow-auto", children: _jsx("pre", { className: "m-0 p-3 font-mono text-code-sm leading-relaxed break-words whitespace-pre-wrap", children: kept ? (_jsxs("span", { className: "text-ink-muted", children: ["Too large to show here. It is kept with the run, as ", kept, ". A script can read it."] })) : text ? (paint(text)) : (_jsx("span", { className: "text-ink-muted", children: "\u2014" })) }) })] }));
68
+ }
@@ -0,0 +1,45 @@
1
+ export interface LogLine {
2
+ /** Orders the lines and identifies each one. */
3
+ seq: number;
4
+ /** When it was written, as an ISO date and time. */
5
+ time: string;
6
+ level: string;
7
+ message: string;
8
+ fields?: Record<string, unknown>;
9
+ /** The attempt that wrote it, for a run that was tried more than once. */
10
+ attempt?: number;
11
+ }
12
+ export interface LogViewerProps {
13
+ lines: readonly LogLine[];
14
+ /** Whether more lines may still arrive. The view then keeps to the newest line. */
15
+ live?: boolean;
16
+ /** What to say when there are no lines at all. */
17
+ empty?: string;
18
+ /** The file name offered when the log is downloaded. */
19
+ fileName?: string;
20
+ /** The tallest the list grows before it scrolls, as a CSS length. */
21
+ maxHeight?: string;
22
+ /** Fills the height of a flex container instead, for a viewer that is the page's main content. */
23
+ fill?: boolean;
24
+ /**
25
+ * The number of the first line given, for a log whose earlier lines were left
26
+ * out. Line numbers, and `#L42` links, then count from the start of the whole log.
27
+ */
28
+ firstLine?: number;
29
+ /**
30
+ * Replaces the download of the lines given, for a log that has more lines
31
+ * than it was given, such as one whose oldest lines were left out.
32
+ */
33
+ onDownload?: (() => void) | undefined;
34
+ }
35
+ /** Log lines as a text file has them: one per line, time, level, message and fields. */
36
+ export declare function logText(lines: readonly LogLine[]): string;
37
+ /** Offers text to the person as a file to save. */
38
+ export declare function saveText(text: string, fileName: string): void;
39
+ /**
40
+ * A run's log: search that finds and steps through matches, levels to show,
41
+ * line numbers that can be linked to, copy, structured fields that open in
42
+ * place, a mark where each attempt begins, and following new lines until the
43
+ * reader scrolls up. Long logs draw only the lines in view.
44
+ */
45
+ export declare function LogViewer({ lines, live, empty, fileName, maxHeight, fill, firstLine, onDownload, }: LogViewerProps): import("react").JSX.Element;