@volvel/ui 0.0.0-stage → 0.6.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 +23018 -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 +11 -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 +47 -3
  137. package/README.md +0 -3
@@ -0,0 +1,299 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { observeElementRect, useVirtualizer } from "@tanstack/react-virtual";
3
+ import { ArrowDown, ArrowUp, ChevronDown, ChevronRight } from "lucide-react";
4
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
5
+ const LEVEL = {
6
+ error: "text-danger",
7
+ warn: "text-attention",
8
+ debug: "text-ink-muted",
9
+ };
10
+ const LEVELS = ["error", "warn", "info", "debug"];
11
+ const LEVEL_NAME = {
12
+ error: "Errors",
13
+ warn: "Warnings",
14
+ info: "Info",
15
+ debug: "Debug",
16
+ };
17
+ /** Below this many rows every line is drawn, so the browser's own find still works. */
18
+ const VIRTUAL_AFTER = 500;
19
+ const clock = (iso) => {
20
+ const date = new Date(iso);
21
+ const pad = (n, width = 2) => String(n).padStart(width, "0");
22
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}`;
23
+ };
24
+ const fieldsText = (line) => line.fields && Object.keys(line.fields).length > 0 ? JSON.stringify(line.fields) : "";
25
+ const levelOf = (line) => (LEVELS.includes(line.level) ? line.level : "info");
26
+ const lineText = (line) => `${line.time} ${line.level.padEnd(5)} ${line.message} ${fieldsText(line)}`.trimEnd();
27
+ /** Log lines as a text file has them: one per line, time, level, message and fields. */
28
+ export function logText(lines) {
29
+ return `${lines.map(lineText).join("\n")}\n`;
30
+ }
31
+ /** Offers text to the person as a file to save. */
32
+ export function saveText(text, fileName) {
33
+ const link = document.createElement("a");
34
+ link.href = URL.createObjectURL(new Blob([text], { type: "text/plain" }));
35
+ link.download = fileName;
36
+ link.click();
37
+ URL.revokeObjectURL(link.href);
38
+ }
39
+ async function copy(text) {
40
+ try {
41
+ await navigator.clipboard.writeText(text);
42
+ return true;
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ /** The line a `#L42` address points at, if any. */
49
+ function linkedLine() {
50
+ if (typeof location !== "object")
51
+ return undefined;
52
+ const found = /^#L(\d+)$/.exec(location.hash);
53
+ return found ? Number(found[1]) : undefined;
54
+ }
55
+ /** The text with each match of `needle` marked; the current match marked more strongly. */
56
+ function marked(text, needle, current) {
57
+ if (!needle)
58
+ return text;
59
+ const lower = text.toLowerCase();
60
+ const parts = [];
61
+ let from = 0;
62
+ let at = lower.indexOf(needle);
63
+ while (at !== -1) {
64
+ if (at > from)
65
+ parts.push(text.slice(from, at));
66
+ parts.push(_jsx("mark", { className: `rounded-inner text-ink ${current ? "bg-attention" : "bg-attention-soft"}`, children: text.slice(at, at + needle.length) }, at));
67
+ from = at + needle.length;
68
+ at = lower.indexOf(needle, from);
69
+ }
70
+ if (from < text.length)
71
+ parts.push(text.slice(from));
72
+ return parts;
73
+ }
74
+ /**
75
+ * A run's log: search that finds and steps through matches, levels to show,
76
+ * line numbers that can be linked to, copy, structured fields that open in
77
+ * place, a mark where each attempt begins, and following new lines until the
78
+ * reader scrolls up. Long logs draw only the lines in view.
79
+ */
80
+ export function LogViewer({ lines, live = false, empty = "Nothing was logged.", fileName = "log.txt", maxHeight = "min(70vh, 48rem)", fill = false, firstLine = 1, onDownload, }) {
81
+ const [query, setQuery] = useState("");
82
+ const [onlyMatching, setOnlyMatching] = useState(false);
83
+ const [hidden, setHidden] = useState(new Set());
84
+ const [wrap, setWrap] = useState(true);
85
+ const [follow, setFollow] = useState(true);
86
+ const [open, setOpen] = useState(new Set());
87
+ const [current, setCurrent] = useState(0);
88
+ const [marked_, setMarked] = useState(() => linkedLine());
89
+ const [said, setSaid] = useState("");
90
+ const root = useRef(null);
91
+ const list = useRef(null);
92
+ const search = useRef(null);
93
+ const needle = query.trim().toLowerCase();
94
+ const counts = useMemo(() => {
95
+ const by = { error: 0, warn: 0, info: 0, debug: 0 };
96
+ for (const line of lines)
97
+ by[levelOf(line)] = (by[levelOf(line)] ?? 0) + 1;
98
+ return by;
99
+ }, [lines]);
100
+ const matches = useCallback((line) => needle !== "" &&
101
+ (line.message.toLowerCase().includes(needle) ||
102
+ fieldsText(line).toLowerCase().includes(needle)), [needle]);
103
+ const shown = useMemo(() => lines
104
+ .map((line, index) => ({ line, number: firstLine + index }))
105
+ .filter(({ line }) => !hidden.has(levelOf(line)) && (!onlyMatching || needle === "" || matches(line))), [lines, hidden, onlyMatching, needle, firstLine, matches]);
106
+ const rows = useMemo(() => {
107
+ const out = [];
108
+ let attempt;
109
+ for (const { line, number } of shown) {
110
+ if (line.attempt !== undefined && attempt !== undefined && line.attempt !== attempt) {
111
+ out.push({ kind: "attempt", attempt: line.attempt, key: `attempt-${number}` });
112
+ }
113
+ if (line.attempt !== undefined)
114
+ attempt = line.attempt;
115
+ out.push({ kind: "line", line, number });
116
+ }
117
+ return out;
118
+ }, [shown]);
119
+ /** Rows that match the search, by their place in `rows`. */
120
+ const found = useMemo(() => needle === ""
121
+ ? []
122
+ : rows.flatMap((row, index) => (row.kind === "line" && matches(row.line) ? [index] : [])), [rows, needle, matches]);
123
+ // A new search starts again at its first match.
124
+ const [searched, setSearched] = useState(needle);
125
+ if (searched !== needle) {
126
+ setSearched(needle);
127
+ setCurrent(0);
128
+ }
129
+ const virtual = rows.length > VIRTUAL_AFTER;
130
+ const virtualizer = useVirtualizer({
131
+ count: virtual ? rows.length : 0,
132
+ getScrollElement: () => list.current,
133
+ estimateSize: () => 22,
134
+ // A row that measures nothing, as where nothing is laid out, keeps its estimated height.
135
+ measureElement: (element) => element.getBoundingClientRect().height || 22,
136
+ // Draws a first screenful before the list has been measured, or where it measures nothing.
137
+ initialRect: { width: 800, height: 600 },
138
+ observeElementRect: (instance, report) => observeElementRect(instance, (rect) => report(rect.height > 0 ? rect : { width: rect.width || 800, height: 600 })),
139
+ overscan: 20,
140
+ });
141
+ const scrollTo = useCallback((index) => {
142
+ if (virtual) {
143
+ // Rows are measured as they are drawn: a second go lands where the first aimed.
144
+ virtualizer.scrollToIndex(index, { align: "center" });
145
+ requestAnimationFrame(() => virtualizer.scrollToIndex(index, { align: "center" }));
146
+ }
147
+ else
148
+ list.current?.querySelector(`[data-row="${index}"]`)?.scrollIntoView?.({ block: "center" });
149
+ }, [virtual, virtualizer]);
150
+ // A new search shows its first match.
151
+ const shownFor = useRef("");
152
+ useEffect(() => {
153
+ if (needle === shownFor.current)
154
+ return;
155
+ shownFor.current = needle;
156
+ const first = found[0];
157
+ if (first === undefined)
158
+ return;
159
+ setFollow(false);
160
+ scrollTo(first);
161
+ }, [needle, found, scrollTo]);
162
+ const step = (by) => {
163
+ if (found.length === 0)
164
+ return;
165
+ const next = (current + by + found.length) % found.length;
166
+ setCurrent(next);
167
+ setFollow(false);
168
+ scrollTo(found[next]);
169
+ };
170
+ // A `#L42` address opens with that line in view and marked.
171
+ const opened = useRef(false);
172
+ useEffect(() => {
173
+ if (opened.current || marked_ === undefined || rows.length === 0)
174
+ return;
175
+ const index = rows.findIndex((row) => row.kind === "line" && row.number === marked_);
176
+ if (index === -1)
177
+ return;
178
+ opened.current = true;
179
+ setFollow(false);
180
+ requestAnimationFrame(() => scrollTo(index));
181
+ }, [rows, marked_, scrollTo]);
182
+ // Following keeps the newest line in view while lines arrive, and through the last
183
+ // ones, which may come just after the log stops being live.
184
+ const count = rows.length;
185
+ const followed = useRef(false);
186
+ if (live)
187
+ followed.current = follow;
188
+ useEffect(() => {
189
+ const element = list.current;
190
+ if (!(live ? follow : followed.current) || !element || count === 0)
191
+ return;
192
+ if (virtual)
193
+ virtualizer.scrollToIndex(count - 1, { align: "end" });
194
+ // And to the very bottom once the rows there are measured.
195
+ requestAnimationFrame(() => {
196
+ element.scrollTop = element.scrollHeight;
197
+ });
198
+ }, [live, follow, count, virtual, virtualizer]);
199
+ // Scrolling up to read stops following; reaching the end again picks it up.
200
+ const onScroll = () => {
201
+ const element = list.current;
202
+ if (!element)
203
+ return;
204
+ const atEnd = element.scrollHeight - element.scrollTop - element.clientHeight < 24;
205
+ if (!live) {
206
+ // A finished log that followed to its end stops following once read upward.
207
+ if (!atEnd)
208
+ followed.current = false;
209
+ return;
210
+ }
211
+ if (!atEnd && follow)
212
+ setFollow(false);
213
+ if (atEnd && !follow)
214
+ setFollow(true);
215
+ };
216
+ const download = onDownload ?? (() => saveText(logText(lines), fileName));
217
+ const copyShown = async () => {
218
+ const selection = typeof getSelection === "function" ? getSelection() : null;
219
+ const picked = selection && !selection.isCollapsed && root.current?.contains(selection.anchorNode)
220
+ ? selection.toString()
221
+ : "";
222
+ const ok = await copy(picked || logText(shown.map((one) => one.line)));
223
+ setSaid(ok
224
+ ? picked
225
+ ? "Selection copied."
226
+ : `${shown.length} ${shown.length === 1 ? "line" : "lines"} copied.`
227
+ : "The clipboard could not be reached.");
228
+ };
229
+ const linkTo = (number) => {
230
+ history.replaceState(history.state, "", `${location.pathname}${location.search}#L${number}`);
231
+ setMarked(number);
232
+ void copy(`${location.origin}${location.pathname}${location.search}#L${number}`).then((ok) => setSaid(ok ? `A link to line ${number} was copied.` : `Line ${number} is in the address.`));
233
+ };
234
+ const onKeyDown = (event) => {
235
+ // ⌘F or Ctrl+F inside the log finds in the log: long logs draw only the lines in view,
236
+ // where the browser's own find cannot reach.
237
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "f") {
238
+ event.preventDefault();
239
+ search.current?.focus();
240
+ search.current?.select();
241
+ }
242
+ };
243
+ const control = "h-7 rounded-control border border-line-control bg-surface px-2 text-body-sm";
244
+ const toggle = (on) => `${control} ${on ? "border-action bg-action-soft text-action" : "text-ink-muted hover:text-ink"}`;
245
+ const drawRow = (row, index) => {
246
+ if (row.kind === "attempt") {
247
+ return (_jsxs("div", { className: "my-1 flex items-center gap-2 font-sans text-meta text-ink-muted", children: [_jsx("span", { className: "h-px flex-1 bg-line" }), "Attempt ", row.attempt, _jsx("span", { className: "h-px flex-1 bg-line" })] }));
248
+ }
249
+ const { line, number } = row;
250
+ const fields = fieldsText(line);
251
+ const expanded = open.has(line.seq);
252
+ const isCurrent = found[current] === index;
253
+ const here = marked_ === number;
254
+ return (_jsxs("div", { className: `group flex gap-3 rounded-inner ${wrap ? "whitespace-pre-wrap break-words" : "whitespace-pre"} ${LEVEL[line.level] ?? ""} ${here ? "bg-action-soft" : ""}`, children: [_jsx("button", { type: "button", onClick: () => linkTo(number), "aria-label": `Link to line ${number}`, className: "w-12 shrink-0 text-right text-ink-subtle tabular-nums hover:text-action", children: number }), _jsx("span", { className: "shrink-0 text-ink-muted", children: clock(line.time) }), _jsx("span", { className: "w-10 shrink-0 uppercase", children: line.level }), _jsxs("span", { className: "min-w-0 flex-1", children: [marked(line.message, needle, isCurrent), fields ? (_jsxs(_Fragment, { children: [" ", _jsx("button", { type: "button", "aria-expanded": expanded, "aria-label": expanded ? "Fold the fields" : "Open the fields", onClick: () => {
255
+ const next = new Set(open);
256
+ if (expanded)
257
+ next.delete(line.seq);
258
+ else
259
+ next.add(line.seq);
260
+ setOpen(next);
261
+ }, className: "text-ink-muted hover:text-ink", children: expanded ? (_jsx(ChevronDown, { "aria-hidden": "true", size: 14 })) : (_jsx(ChevronRight, { "aria-hidden": "true", size: 14 })) }), expanded ? (_jsx("span", { className: "mt-0.5 block rounded-inner bg-surface px-2 py-1 whitespace-pre text-ink-muted", children: JSON.stringify(line.fields, null, 2) })) : (_jsxs("span", { className: "text-ink-muted", children: [" ", marked(fields, needle, isCurrent)] }))] })) : null] }), _jsx("button", { type: "button", "aria-label": `Copy line ${number}`, onClick: () => void copy(lineText(line)).then((ok) => setSaid(ok ? `Line ${number} copied.` : "The clipboard could not be reached.")), className: "shrink-0 font-sans text-meta text-ink-subtle opacity-0 group-hover:opacity-100 focus:opacity-100", children: "Copy" })] }));
262
+ };
263
+ const items = virtual
264
+ ? virtualizer.getVirtualItems()
265
+ : rows.map((_, index) => ({ index, start: 0, key: index }));
266
+ return (_jsxs("div", { ref: root, onKeyDown: onKeyDown, className: `flex flex-col gap-2 ${fill ? "min-h-0 flex-1" : ""}`, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("input", { ref: search, type: "search", "aria-label": "Search the log", placeholder: "Search the log", value: query, onChange: (event) => setQuery(event.currentTarget.value), onKeyDown: (event) => {
267
+ if (event.key === "Enter") {
268
+ event.preventDefault();
269
+ step(event.shiftKey ? -1 : 1);
270
+ }
271
+ }, className: `${control} min-w-40 flex-1` }), needle ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-meta text-ink-muted tabular-nums", children: found.length === 0
272
+ ? "No match"
273
+ : `${current + 1} of ${found.length} ${found.length === 1 ? "match" : "matches"}` }), _jsx("button", { type: "button", className: toggle(false), "aria-label": "Previous match", disabled: found.length === 0, onClick: () => step(-1), children: _jsx(ArrowUp, { "aria-hidden": "true", size: 14 }) }), _jsx("button", { type: "button", className: toggle(false), "aria-label": "Next match", disabled: found.length === 0, onClick: () => step(1), children: _jsx(ArrowDown, { "aria-hidden": "true", size: 14 }) }), _jsx("button", { type: "button", "aria-pressed": onlyMatching, className: toggle(onlyMatching), onClick: () => setOnlyMatching(!onlyMatching), children: "Only matching" })] })) : null, _jsxs("fieldset", { className: "m-0 flex flex-wrap items-center gap-1 border-0 p-0", children: [_jsx("legend", { className: "sr-only", children: "Levels to show" }), LEVELS.filter((level) => (counts[level] ?? 0) > 0).map((level) => {
274
+ const on = !hidden.has(level);
275
+ return (_jsxs("button", { type: "button", "aria-pressed": on, className: toggle(on), onClick: () => {
276
+ const next = new Set(hidden);
277
+ if (on)
278
+ next.add(level);
279
+ else
280
+ next.delete(level);
281
+ setHidden(next);
282
+ }, children: [LEVEL_NAME[level], " ", _jsx("span", { className: "tabular-nums opacity-80", children: counts[level] })] }, level));
283
+ })] }), _jsx("button", { type: "button", "aria-pressed": wrap, className: toggle(wrap), onClick: () => setWrap(!wrap), children: "Wrap" }), live ? (_jsx("button", { type: "button", "aria-pressed": follow, className: toggle(follow), onClick: () => setFollow(!follow), children: "Follow" })) : null, _jsx("button", { type: "button", className: `${control} text-ink-muted hover:text-ink disabled:opacity-50`, disabled: shown.length === 0, onClick: () => void copyShown(), children: "Copy" }), _jsx("button", { type: "button", className: `${control} text-ink-muted hover:text-ink disabled:opacity-50`, disabled: lines.length === 0, onClick: download, children: "Download" }), _jsx("span", { className: "text-meta text-ink-muted", "aria-live": "polite", children: shown.length === lines.length
284
+ ? `${lines.length} ${lines.length === 1 ? "line" : "lines"}`
285
+ : `${shown.length} of ${lines.length} lines` }), _jsx("span", { className: "sr-only", role: "status", children: said })] }), shown.length === 0 ? (_jsx("p", { className: "m-0 rounded-control border border-line bg-sunken p-3 text-ink-muted", children: lines.length === 0 ? empty : "No line matches." })) : (_jsxs("div", { className: `relative ${fill ? "flex min-h-0 flex-1 flex-col" : ""}`, children: [_jsx("section", { ref: list, "aria-label": "Log lines",
286
+ // biome-ignore lint/a11y/noNoninteractiveTabindex: a list that scrolls must be reachable by keyboard
287
+ tabIndex: 0, onScroll: onScroll, style: fill ? undefined : { maxHeight }, className: `overflow-auto rounded-control border border-line bg-sunken p-3 font-mono text-code-sm leading-relaxed ${fill ? "min-h-64 flex-1" : ""}`, children: _jsx("ol", { className: "m-0 list-none p-0", style: virtual ? { height: virtualizer.getTotalSize(), position: "relative" } : undefined, children: items.map((item) => {
288
+ const row = rows[item.index];
289
+ return (_jsx("li", { "data-row": item.index, "data-index": item.index, ref: virtual ? virtualizer.measureElement : undefined, style: virtual
290
+ ? {
291
+ position: "absolute",
292
+ top: 0,
293
+ left: 0,
294
+ right: 0,
295
+ transform: `translateY(${item.start}px)`,
296
+ }
297
+ : undefined, children: drawRow(row, item.index) }, row.kind === "line" ? row.line.seq : row.key));
298
+ }) }) }), live && !follow ? (_jsx("button", { type: "button", onClick: () => setFollow(true), className: "absolute right-4 bottom-3 rounded-control border border-line bg-surface px-3 py-1 font-sans text-body-sm shadow-overlay hover:bg-sunken", children: "Jump to latest \u2193" })) : null] }))] }));
299
+ }
@@ -0,0 +1,21 @@
1
+ import { type ProfileName } from "@volvel/markup";
2
+ /**
3
+ * Markdown, drawn as a page of documentation is and by the same reader:
4
+ * headings, lists, quotes, code, and links. Text is never read as HTML, so a
5
+ * value cannot put markup or script on the page.
6
+ *
7
+ * `profile` says what the text may hold. The default, `result`, is what a
8
+ * script gave back: tables too, links to http, https or mailto, and no
9
+ * component. `page` is the text of a widget on a page: small headings, and the
10
+ * documentation's alerts, steps, tabs, details, terms and keys.
11
+ *
12
+ * The reader is loaded when it is first needed, so an app that never shows
13
+ * Markdown never downloads it. Until it arrives a result is shown as written; a
14
+ * page's text, whose alerts and steps would read as code, is drawn as loading.
15
+ */
16
+ export declare function Markdown({ text, profile }: {
17
+ text: string;
18
+ profile?: ProfileName;
19
+ }): import("react").JSX.Element;
20
+ /** Whether a link may be followed from the page: one to http, https or mailto. */
21
+ export declare function safeHref(href: string): string | undefined;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { linkKind } from "@volvel/markup";
3
+ import { lazy, Suspense } from "react";
4
+ import { Skeleton } from "./Surfaces.js";
5
+ const Body = lazy(() => import("./MarkdownBody.js"));
6
+ /**
7
+ * Markdown, drawn as a page of documentation is and by the same reader:
8
+ * headings, lists, quotes, code, and links. Text is never read as HTML, so a
9
+ * value cannot put markup or script on the page.
10
+ *
11
+ * `profile` says what the text may hold. The default, `result`, is what a
12
+ * script gave back: tables too, links to http, https or mailto, and no
13
+ * component. `page` is the text of a widget on a page: small headings, and the
14
+ * documentation's alerts, steps, tabs, details, terms and keys.
15
+ *
16
+ * The reader is loaded when it is first needed, so an app that never shows
17
+ * Markdown never downloads it. Until it arrives a result is shown as written; a
18
+ * page's text, whose alerts and steps would read as code, is drawn as loading.
19
+ */
20
+ export function Markdown({ text, profile = "result" }) {
21
+ return (_jsx(Suspense, { fallback: profile === "page" ? (_jsx(Skeleton, { lines: Math.min(6, Math.max(2, text.split("\n").length)), label: "Loading the text" })) : (_jsx("pre", { className: "m-0 whitespace-pre-wrap font-sans", children: text })), children: _jsx(Body, { text: text, profile: profile }) }));
22
+ }
23
+ /** Whether a link may be followed from the page: one to http, https or mailto. */
24
+ export function safeHref(href) {
25
+ const kind = linkKind(href);
26
+ return kind === "http" || kind === "mailto" ? href.trim() : undefined;
27
+ }
@@ -0,0 +1,6 @@
1
+ import { type ProfileName } from "@volvel/markup";
2
+ /** The part of `Markdown` that reads the text. It is loaded when there is Markdown to show. */
3
+ export default function MarkdownBody({ text, profile, }: {
4
+ text: string;
5
+ profile?: ProfileName;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { parse } from "@volvel/markup";
3
+ import { useMemo } from "react";
4
+ import { Doc } from "./Doc.js";
5
+ import { useMarkdownKnowledge } from "./markdownKnowledge.js";
6
+ /** The part of `Markdown` that reads the text. It is loaded when there is Markdown to show. */
7
+ export default function MarkdownBody({ text, profile = "result", }) {
8
+ const tree = useMemo(() => parse(text), [text]);
9
+ // What the host around it knows: a term's meaning, a field's description.
10
+ const { term, field } = useMarkdownKnowledge();
11
+ // The text sits under its widget's title, or inside a page that has headings of its own: the
12
+ // highest heading it uses is drawn as a level 3.
13
+ return (_jsx(Doc, { tree: tree, profile: profile, headingTop: 3, ...(term ? { term } : {}), ...(field ? { field } : {}) }));
14
+ }
package/dist/Menu.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from "react";
2
+ export interface MenuItem {
3
+ label: string;
4
+ onSelect: () => void;
5
+ /** Drawn before the label. */
6
+ icon?: ReactNode;
7
+ /** Marks an action that removes or ends something. */
8
+ danger?: boolean;
9
+ /** Draws a line above this item, to set a group apart. */
10
+ separated?: boolean;
11
+ /** Marks the item that is the current one, in a menu that switches between things. */
12
+ current?: boolean;
13
+ /** The shortcut that does the same, written for people: `⌘D`. */
14
+ keys?: string | undefined;
15
+ /** Drawn after the label, such as a tag that says what kind the item is. */
16
+ detail?: ReactNode;
17
+ }
18
+ export interface MenuProps {
19
+ /** What the trigger button shows. */
20
+ label: ReactNode;
21
+ items: MenuItem[];
22
+ /** Names the trigger for screen readers when its label is only an icon. */
23
+ ariaLabel?: string;
24
+ /** Replaces the trigger's own look, for a trigger that is part of a bar or a header. */
25
+ triggerClassName?: string;
26
+ /** Which edge of the trigger the menu lines up with. */
27
+ align?: "start" | "end";
28
+ }
29
+ export declare function Menu({ label, items, ariaLabel, triggerClassName, align }: MenuProps): import("react").JSX.Element;
package/dist/Menu.js ADDED
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Menu as Base } from "@base-ui/react/menu";
3
+ import { Check } from "lucide-react";
4
+ import { Kbd } from "./Tooltip.js";
5
+ export function Menu({ label, items, ariaLabel, triggerClassName, align = "start" }) {
6
+ return (_jsxs(Base.Root, { children: [_jsx(Base.Trigger, { ...(ariaLabel ? { "aria-label": ariaLabel } : {}), className: triggerClassName ??
7
+ "flex w-full items-center justify-between gap-2 rounded-control px-2 py-1.5 text-left hover:bg-hover", children: label }), _jsx(Base.Portal, { children: _jsx(Base.Positioner, { sideOffset: 6, align: align, className: "layer-popover", children: _jsx(Base.Popup, { className: "max-h-[70vh] min-w-48 overflow-y-auto rounded-panel border border-line-strong bg-raised p-1.5 shadow-overlay transition-[opacity,translate] motion-base data-[ending-style]:opacity-0 data-[starting-style]:-translate-y-1 data-[starting-style]:opacity-0", children: items.map((item) => (_jsxs("div", { children: [item.separated ? _jsx(Base.Separator, { className: "my-1.5 h-px bg-line" }) : null, _jsxs(Base.Item, { onClick: item.onSelect, className: `flex cursor-default items-center gap-2 rounded-inner px-3 py-1.5 text-body-sm data-[highlighted]:bg-hover ${item.danger ? "text-danger data-[highlighted]:bg-danger-soft" : ""} ${item.current ? "font-medium" : ""}`, children: [item.icon ? _jsx("span", { className: "flex w-4 justify-center", children: item.icon }) : null, _jsx("span", { className: "min-w-0 flex-1 truncate", children: item.label }), item.detail, item.current ? _jsx(Check, { "aria-hidden": "true", size: 14 }) : null, item.keys ? _jsx(Kbd, { children: item.keys }) : null] })] }, item.label))) }) }) })] }));
8
+ }
@@ -0,0 +1,19 @@
1
+ export interface MoveButtonsProps {
2
+ /** What is moved, as its buttons name it: "Move Status up". */
3
+ label: string;
4
+ /** Where it is among the others, from 0, and how many there are. */
5
+ at: number;
6
+ count: number;
7
+ onMove: (by: -1 | 1) => void;
8
+ /** A list runs down the page; things placed along a row are moved earlier and later. */
9
+ along?: "list" | "row";
10
+ disabled?: boolean;
11
+ }
12
+ /**
13
+ * The two buttons that move one thing a place among the others, for whoever
14
+ * does not drag. They say aloud where it went. The things they move are held
15
+ * by an element with `useFlip`'s ref and carry a `data-flip-key`, so the move
16
+ * is seen as a move: every reordering by button in the console and in apps is
17
+ * these two together.
18
+ */
19
+ export declare function MoveButtons({ label, at, count, onMove, along, disabled, }: MoveButtonsProps): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp } from "lucide-react";
3
+ import { useState } from "react";
4
+ import { Button } from "./Button.js";
5
+ /**
6
+ * The two buttons that move one thing a place among the others, for whoever
7
+ * does not drag. They say aloud where it went. The things they move are held
8
+ * by an element with `useFlip`'s ref and carry a `data-flip-key`, so the move
9
+ * is seen as a move: every reordering by button in the console and in apps is
10
+ * these two together.
11
+ */
12
+ export function MoveButtons({ label, at, count, onMove, along = "list", disabled, }) {
13
+ const [said, setSaid] = useState("");
14
+ const [back, forth] = along === "row" ? ["earlier", "later"] : ["up", "down"];
15
+ const Back = along === "row" ? ArrowLeft : ArrowUp;
16
+ const Forth = along === "row" ? ArrowRight : ArrowDown;
17
+ const move = (by) => {
18
+ onMove(by);
19
+ setSaid(`${label} is now ${at + by + 1} of ${count}.`);
20
+ };
21
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "small", variant: "quiet", "aria-label": `Move ${label} ${back}`, disabled: disabled || at <= 0, onClick: () => move(-1), children: _jsx(Back, { "aria-hidden": "true", size: 14 }) }), _jsx(Button, { size: "small", variant: "quiet", "aria-label": `Move ${label} ${forth}`, disabled: disabled || at >= count - 1, onClick: () => move(1), children: _jsx(Forth, { "aria-hidden": "true", size: 14 }) }), _jsx("span", { role: "status", className: "sr-only", children: said })] }));
22
+ }
@@ -0,0 +1,47 @@
1
+ import { type ReactNode } from "react";
2
+ /** What a failure's words can lead to: a label and where it goes. */
3
+ export interface FailureHelp {
4
+ label: string;
5
+ onClick: () => void;
6
+ /**
7
+ * What to show under the notice when it sits inside a dialog or sheet, where the help panel
8
+ * would open behind the modal: the explanation itself, and where the whole of it is read.
9
+ */
10
+ inline?: {
11
+ body: () => ReactNode;
12
+ href: string;
13
+ };
14
+ }
15
+ /**
16
+ * The host says, once, which words it knows a way to explain (the words of a failure the API gave
17
+ * a code for). A danger `Notice` of those words offers the way, as a toast does, so that a failure
18
+ * shown in a dialog and one shown in a corner are told alike.
19
+ */
20
+ export declare function setFailureExplainer(find: ((words: string) => FailureHelp | undefined) | undefined): void;
21
+ declare const tones: {
22
+ info: string;
23
+ attention: string;
24
+ danger: string;
25
+ success: string;
26
+ plain: string;
27
+ };
28
+ /**
29
+ * A message that needs to be seen: an error, a state the person must not miss, or that something worked.
30
+ * Inside a `Panel` it drops its border and keeps its tint (07 §7.5), so no box sits in another.
31
+ */
32
+ export declare function Notice({ tone, children, action, bare, }: {
33
+ tone: keyof typeof tones;
34
+ children: ReactNode;
35
+ action?: ReactNode;
36
+ /** Without its border: where it sits inside a container that is not a `Panel`. */
37
+ bare?: boolean;
38
+ }): import("react").JSX.Element;
39
+ /** What an empty list shows: what belongs here, and the way to add the first one. */
40
+ export declare function EmptyState({ title, children, action, inCard, }: {
41
+ title: string;
42
+ children?: ReactNode;
43
+ action?: ReactNode;
44
+ /** In a card that is already a box (a widget's): no box of its own, and centered in the room the card has. */
45
+ inCard?: boolean;
46
+ }): import("react").JSX.Element;
47
+ export {};
package/dist/Notice.js ADDED
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useState } from "react";
3
+ import { Button } from "./Button.js";
4
+ import { useInOverlay } from "./overlay.js";
5
+ import { useContained } from "./Panel.js";
6
+ let explainer;
7
+ /**
8
+ * The host says, once, which words it knows a way to explain (the words of a failure the API gave
9
+ * a code for). A danger `Notice` of those words offers the way, as a toast does, so that a failure
10
+ * shown in a dialog and one shown in a corner are told alike.
11
+ */
12
+ export function setFailureExplainer(find) {
13
+ explainer = find;
14
+ }
15
+ const tones = {
16
+ info: "bg-action-soft text-ink",
17
+ attention: "bg-attention-soft text-ink",
18
+ danger: "bg-danger-soft text-ink",
19
+ success: "bg-success-soft text-ink",
20
+ plain: "bg-surface text-ink",
21
+ };
22
+ const edges = {
23
+ info: "border border-action/30",
24
+ attention: "border border-attention/30",
25
+ danger: "border border-danger/30",
26
+ success: "border border-success/30",
27
+ plain: "border border-line",
28
+ };
29
+ /**
30
+ * A message that needs to be seen: an error, a state the person must not miss, or that something worked.
31
+ * Inside a `Panel` it drops its border and keeps its tint (07 §7.5), so no box sits in another.
32
+ */
33
+ export function Notice({ tone, children, action, bare, }) {
34
+ const contained = useContained();
35
+ const edge = (bare ?? contained) ? "" : edges[tone];
36
+ const help = action === undefined && tone === "danger" && typeof children === "string"
37
+ ? explainer?.(children)
38
+ : undefined;
39
+ const inOverlay = useInOverlay();
40
+ const [open, setOpen] = useState(false);
41
+ const region = useId();
42
+ const inline = inOverlay ? help?.inline : undefined;
43
+ return (_jsxs("div", { role: tone === "danger" ? "alert" : "status", className: `flex flex-wrap items-center justify-between gap-3 rounded-control px-3 py-2 ${tones[tone]} ${edge}`, children: [_jsx("div", { children: children }), action, help ? (_jsx(Button, { size: "small", variant: "quiet", onClick: inline ? () => setOpen((now) => !now) : help.onClick, ...(inline ? { "aria-expanded": open, "aria-controls": region } : {}), children: help.label })) : null, inline && open ? (_jsxs("section", { id: region, "aria-label": "What this means", className: "basis-full", children: [_jsx("div", { className: "text-ink-muted", children: inline.body() }), _jsx("a", { href: inline.href, target: "_blank", rel: "noreferrer", className: "mt-2 inline-block text-action underline", children: "Open in documentation" })] })) : null] }));
44
+ }
45
+ /** What an empty list shows: what belongs here, and the way to add the first one. */
46
+ export function EmptyState({ title, children, action, inCard, }) {
47
+ return (_jsxs("div", { "data-empty-state": "", className: inCard
48
+ ? "flex min-h-32 flex-1 flex-col items-center justify-center px-3 py-6 text-center"
49
+ : "rounded-panel border border-dashed border-line px-5 py-8", children: [_jsx("p", { className: "m-0 font-medium", children: title }), children ? _jsx("p", { className: "mt-1 mb-0 max-w-measure text-ink-muted", children: children }) : null, action ? _jsx("div", { className: "mt-4", children: action }) : null] }));
50
+ }
@@ -0,0 +1,42 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * One entry in an app's navigation. With `href` it is a link to another page.
4
+ * With `onSelect` it switches the screen in the browser, for an app that keeps
5
+ * its screens in one page; mark the one showing with `current`.
6
+ */
7
+ export type PageNavItem = {
8
+ label: string;
9
+ /** Marks the page or screen the person is on. */
10
+ current?: boolean;
11
+ /** A count shown after the label, such as how many wait. */
12
+ count?: number;
13
+ } & ({
14
+ href: string;
15
+ onSelect?: undefined;
16
+ } | {
17
+ onSelect: () => void;
18
+ href?: undefined;
19
+ });
20
+ export interface PageShellProps {
21
+ /** The app's name, shown in the header. */
22
+ title: string;
23
+ /** A second line under the name: a place, a team. */
24
+ subtitle?: ReactNode;
25
+ /** Address of a logo image, shown before the title. Nothing is shown for null. */
26
+ logo?: string | null;
27
+ nav?: PageNavItem[];
28
+ /** What sits at the right-hand end of the header: an account menu, say. */
29
+ actions?: ReactNode;
30
+ /**
31
+ * How wide the page may grow. `regular`, the default, keeps lines readable;
32
+ * `full` gives boards and tables the whole window.
33
+ */
34
+ width?: "regular" | "full";
35
+ children: ReactNode;
36
+ }
37
+ /**
38
+ * The frame of an app page: a header with the app's name, its navigation and
39
+ * a place for the account menu, then the page itself. On a narrow screen the
40
+ * navigation moves to a row of its own that scrolls sideways.
41
+ */
42
+ export declare function PageShell({ title, subtitle, logo, nav, actions, width, children, }: PageShellProps): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { LucideProvider } from "lucide-react";
3
+ /**
4
+ * The frame of an app page: a header with the app's name, its navigation and
5
+ * a place for the account menu, then the page itself. On a narrow screen the
6
+ * navigation moves to a row of its own that scrolls sideways.
7
+ */
8
+ export function PageShell({ title, subtitle, logo, nav, actions, width = "regular", children, }) {
9
+ return (_jsx(LucideProvider, { strokeWidth: 1.75, children: _jsxs("div", { className: "min-h-screen bg-canvas text-ink", children: [_jsxs("header", { className: "flex flex-wrap items-center gap-x-6 gap-y-1 border-b border-line bg-surface px-4 py-2 sm:px-6", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [logo ? _jsx("img", { src: logo, alt: "", className: "size-7 shrink-0 rounded-control" }) : null, _jsxs("div", { className: "flex min-w-0 flex-col", children: [_jsx("span", { className: "truncate text-title font-semibold", children: title }), subtitle ? (_jsx("span", { className: "truncate text-body-sm text-ink-muted", children: subtitle })) : null] })] }), nav && nav.length > 0 ? (_jsx("nav", { "aria-label": "Main", className: "order-last -mx-1 flex w-full gap-1 overflow-x-auto px-1 pb-1 sm:order-none sm:mx-0 sm:w-auto sm:px-0 sm:pb-0", children: nav.map((item) => {
10
+ const classes = `inline-flex shrink-0 items-center gap-1.5 rounded-control px-3 py-1.5 font-medium whitespace-nowrap no-underline ${item.current ? "bg-action-soft text-action" : "text-ink-muted hover:bg-sunken"}`;
11
+ const content = (_jsxs(_Fragment, { children: [item.label, item.count !== undefined && item.count > 0 ? (_jsx("span", { className: "rounded-full bg-attention-soft px-1.5 text-meta text-attention tabular-nums", children: item.count })) : null] }));
12
+ return item.href !== undefined ? (_jsx("a", { href: item.href, "aria-current": item.current ? "page" : undefined, className: classes, children: content }, item.label)) : (_jsx("button", { type: "button", onClick: item.onSelect, "aria-current": item.current ? "page" : undefined, className: classes, children: content }, item.label));
13
+ }) })) : null, actions ? (_jsx("div", { className: "ml-auto flex shrink-0 items-center gap-2", children: actions })) : null] }), _jsx("main", { className: `mx-auto w-full px-4 py-5 sm:px-6 ${width === "full" ? "max-w-none" : "max-w-[calc(72rem*var(--vx-type-growth,1))]"}`, children: children })] }) }));
14
+ }
@@ -0,0 +1,13 @@
1
+ export interface PaginationProps {
2
+ hasPrevious: boolean;
3
+ hasNext: boolean;
4
+ onPrevious: () => void;
5
+ onNext: () => void;
6
+ /** Shown between the two buttons: "Page 2", "51 to 100". */
7
+ label?: string;
8
+ }
9
+ /**
10
+ * Moves through a list one page at a time. It asks only whether there is more
11
+ * each way, which is all a cursor can say: there are no page numbers.
12
+ */
13
+ export declare function Pagination({ hasPrevious, hasNext, onPrevious, onNext, label }: PaginationProps): import("react").JSX.Element;