@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.
- package/LICENSE +202 -0
- package/THIRD_PARTY_NOTICES.md +23036 -0
- package/dist/Badge.d.ts +20 -0
- package/dist/Badge.js +35 -0
- package/dist/Button.d.ts +56 -0
- package/dist/Button.js +52 -0
- package/dist/Chart.d.ts +23 -0
- package/dist/Chart.js +98 -0
- package/dist/Combobox.d.ts +45 -0
- package/dist/Combobox.js +42 -0
- package/dist/ContextMenu.d.ts +16 -0
- package/dist/ContextMenu.js +38 -0
- package/dist/DateInput.d.ts +31 -0
- package/dist/DateInput.js +329 -0
- package/dist/Details.d.ts +12 -0
- package/dist/Details.js +9 -0
- package/dist/Dialog.d.ts +44 -0
- package/dist/Dialog.js +95 -0
- package/dist/Dialogs.d.ts +56 -0
- package/dist/Dialogs.js +95 -0
- package/dist/Doc.d.ts +25 -0
- package/dist/Doc.js +118 -0
- package/dist/DocServed.d.ts +6 -0
- package/dist/DocServed.js +154 -0
- package/dist/DocZoom.d.ts +11 -0
- package/dist/DocZoom.js +133 -0
- package/dist/Facts.d.ts +12 -0
- package/dist/Facts.js +10 -0
- package/dist/Fields.d.ts +184 -0
- package/dist/Fields.js +249 -0
- package/dist/Form.d.ts +47 -0
- package/dist/Form.js +189 -0
- package/dist/Grid.d.ts +118 -0
- package/dist/Grid.js +475 -0
- package/dist/HeadingSlot.d.ts +13 -0
- package/dist/HeadingSlot.js +19 -0
- package/dist/JsonView.d.ts +11 -0
- package/dist/JsonView.js +68 -0
- package/dist/LogViewer.d.ts +45 -0
- package/dist/LogViewer.js +299 -0
- package/dist/Markdown.d.ts +21 -0
- package/dist/Markdown.js +27 -0
- package/dist/MarkdownBody.d.ts +6 -0
- package/dist/MarkdownBody.js +14 -0
- package/dist/Menu.d.ts +29 -0
- package/dist/Menu.js +8 -0
- package/dist/MoveButtons.d.ts +19 -0
- package/dist/MoveButtons.js +22 -0
- package/dist/Notice.d.ts +47 -0
- package/dist/Notice.js +50 -0
- package/dist/PageShell.d.ts +42 -0
- package/dist/PageShell.js +14 -0
- package/dist/Pagination.d.ts +13 -0
- package/dist/Pagination.js +9 -0
- package/dist/Panel.d.ts +31 -0
- package/dist/Panel.js +33 -0
- package/dist/Pickers.d.ts +37 -0
- package/dist/Pickers.js +44 -0
- package/dist/Popover.d.ts +24 -0
- package/dist/Popover.js +12 -0
- package/dist/ResultView.d.ts +28 -0
- package/dist/ResultView.js +140 -0
- package/dist/SchemaForm.d.ts +45 -0
- package/dist/SchemaForm.js +626 -0
- package/dist/SideSheet.d.ts +31 -0
- package/dist/SideSheet.js +136 -0
- package/dist/Sparkline.d.ts +14 -0
- package/dist/Sparkline.js +23 -0
- package/dist/Surfaces.d.ts +30 -0
- package/dist/Surfaces.js +34 -0
- package/dist/Switch.d.ts +18 -0
- package/dist/Switch.js +11 -0
- package/dist/Table.d.ts +15 -0
- package/dist/Table.js +6 -0
- package/dist/Tabs.d.ts +32 -0
- package/dist/Tabs.js +11 -0
- package/dist/Term.d.ts +82 -0
- package/dist/Term.js +153 -0
- package/dist/Timeline.d.ts +29 -0
- package/dist/Timeline.js +39 -0
- package/dist/Toast.d.ts +43 -0
- package/dist/Toast.js +140 -0
- package/dist/Tooltip.d.ts +34 -0
- package/dist/Tooltip.js +70 -0
- package/dist/Tree.d.ts +51 -0
- package/dist/Tree.js +233 -0
- package/dist/chartEngine.d.ts +32 -0
- package/dist/chartEngine.js +72 -0
- package/dist/chartTheme.d.ts +41 -0
- package/dist/chartTheme.js +131 -0
- package/dist/contrast.d.ts +27 -0
- package/dist/contrast.js +110 -0
- package/dist/dates.d.ts +61 -0
- package/dist/dates.js +294 -0
- package/dist/drawer/Chips.d.ts +37 -0
- package/dist/drawer/Chips.js +32 -0
- package/dist/drawer/Choices.d.ts +47 -0
- package/dist/drawer/Choices.js +81 -0
- package/dist/drawer/Drawer.d.ts +125 -0
- package/dist/drawer/Drawer.js +150 -0
- package/dist/drawer/EditorBodies.d.ts +95 -0
- package/dist/drawer/EditorBodies.js +169 -0
- package/dist/drawer/NumberFormat.d.ts +36 -0
- package/dist/drawer/NumberFormat.js +98 -0
- package/dist/drawer/SortableRows.d.ts +35 -0
- package/dist/drawer/SortableRows.js +23 -0
- package/dist/drawer/edgeShadows.d.ts +7 -0
- package/dist/drawer/edgeShadows.js +17 -0
- package/dist/drawer/index.d.ts +8 -0
- package/dist/drawer/index.js +8 -0
- package/dist/drawer/useSortable.d.ts +53 -0
- package/dist/drawer/useSortable.js +323 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +17 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +16 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +48 -0
- package/dist/markdownKnowledge.d.ts +45 -0
- package/dist/markdownKnowledge.js +37 -0
- package/dist/overlay.d.ts +7 -0
- package/dist/overlay.js +10 -0
- package/dist/pageIcons.d.ts +12 -0
- package/dist/pageIcons.js +32 -0
- package/dist/presence.d.ts +41 -0
- package/dist/presence.js +108 -0
- package/dist/returnFocus.d.ts +9 -0
- package/dist/returnFocus.js +44 -0
- package/dist/tokens.css +437 -0
- package/dist/type-scale.css +34 -0
- package/dist/useFlip.d.ts +32 -0
- package/dist/useFlip.js +118 -0
- package/fonts/OFL.txt +193 -0
- package/fonts/geist-latin.woff2 +0 -0
- package/fonts/geist-mono-latin.woff2 +0 -0
- package/package.json +52 -3
- package/README.md +0 -3
package/dist/Timeline.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { duration } from "./format.js";
|
|
3
|
+
const FILL = {
|
|
4
|
+
wait: "bg-ink-muted/50",
|
|
5
|
+
run: "bg-action",
|
|
6
|
+
hold: "bg-attention",
|
|
7
|
+
};
|
|
8
|
+
/** Things that took time, on one axis: what ran side by side, what waited, and for how long. */
|
|
9
|
+
export function Timeline({ rows, now = Date.now(), selected, onSelect, legend }) {
|
|
10
|
+
if (rows.length === 0)
|
|
11
|
+
return null;
|
|
12
|
+
const from = Math.min(...rows.map((row) => row.start));
|
|
13
|
+
const to = Math.max(...rows.map((row) => row.end ?? now), from + 1);
|
|
14
|
+
const span = to - from;
|
|
15
|
+
const at = (time) => `${(Math.min(Math.max(time - from, 0), span) / span) * 100}%`;
|
|
16
|
+
const ticks = [0, 0.25, 0.5, 0.75, 1];
|
|
17
|
+
const names = { wait: "Waiting", run: "Running", hold: "On hold", ...legend };
|
|
18
|
+
const used = new Set(rows.flatMap((row) => row.segments?.map((segment) => segment.kind) ?? ["run"]));
|
|
19
|
+
return (_jsxs("div", { className: "@container flex w-full flex-col gap-2", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 text-meta text-ink-muted", children: [_jsx("span", { className: "flex flex-wrap gap-3", children: ["wait", "run", "hold"]
|
|
20
|
+
.filter((kind) => used.has(kind))
|
|
21
|
+
.map((kind) => (_jsxs("span", { className: "inline-flex items-center gap-1.5", children: [_jsx("span", { "aria-hidden": "true", className: `size-2.5 rounded-inner ${FILL[kind]}` }), names[kind]] }, kind))) }), _jsx("span", { className: "font-mono text-ink", children: duration(span) })] }), _jsx("ol", { className: "m-0 flex list-none flex-col p-0", children: rows.map((row) => {
|
|
22
|
+
const end = row.end ?? now;
|
|
23
|
+
const parts = row.segments?.length
|
|
24
|
+
? row.segments
|
|
25
|
+
: [{ kind: "run", until: end }];
|
|
26
|
+
let cursor = row.start;
|
|
27
|
+
const chosen = selected === row.id;
|
|
28
|
+
const bar = (_jsxs("span", { className: "relative block h-5 min-w-0 flex-1", children: [ticks.map((tick) => (_jsx("span", { "aria-hidden": "true", className: "absolute inset-y-[-4px] w-px bg-line", style: { left: `${tick * 100}%` } }, tick))), parts.map((part) => {
|
|
29
|
+
const left = cursor;
|
|
30
|
+
cursor = Math.max(cursor, part.until);
|
|
31
|
+
if (part.until <= left)
|
|
32
|
+
return null;
|
|
33
|
+
return (_jsx("span", { className: `absolute inset-y-0 min-w-[3px] first-of-type:rounded-l-inner last-of-type:rounded-r-inner ${row.tone === "danger" && part.kind === "run" ? "bg-danger" : FILL[part.kind]} ${row.tone === "muted" ? "opacity-50" : ""}`, style: { left: at(left), width: `calc(${at(part.until)} - ${at(left)})` } }, `${part.kind}-${part.until}`));
|
|
34
|
+
}), _jsxs("span", { className: "absolute top-0 pl-1.5 font-mono text-code-sm leading-5 whitespace-nowrap text-ink-muted", style: { left: at(end) }, children: [duration(end - row.start), row.end === undefined ? "…" : ""] })] }));
|
|
35
|
+
const inner = (_jsxs(_Fragment, { children: [_jsx("span", { className: "w-full shrink-0 truncate text-left font-mono text-code-sm @lg:w-40", children: row.label }), _jsxs("span", { className: "flex w-full min-w-0 items-center gap-3 @lg:flex-1", children: [bar, _jsx("span", { "aria-hidden": "true", className: "w-16 shrink-0" })] })] }));
|
|
36
|
+
const shape = `flex w-full flex-col items-start gap-1 @lg:flex-row @lg:items-center @lg:gap-3 rounded-control px-2 py-1.5 ${chosen ? "bg-action-soft" : ""}`;
|
|
37
|
+
return (_jsx("li", { children: onSelect ? (_jsx("button", { type: "button", "aria-pressed": chosen, className: `${shape} hover:bg-sunken`, onClick: () => onSelect(row.id), children: inner })) : (_jsx("div", { className: shape, children: inner })) }, row.id));
|
|
38
|
+
}) }), _jsxs("div", { "aria-hidden": "true", className: "flex gap-3 px-2 text-meta text-ink-muted", children: [_jsx("span", { className: "hidden w-40 shrink-0 @lg:block" }), _jsx("span", { className: "relative block h-4 min-w-0 flex-1", children: ticks.map((tick) => (_jsx("span", { className: `absolute -translate-x-1/2 whitespace-nowrap first:translate-x-0 last:-translate-x-full ${tick === 0 || tick === 1 ? "" : "hidden @lg:block"}`, style: { left: `${tick * 100}%` }, children: duration(span * tick) }, tick))) }), _jsx("span", { className: "w-16 shrink-0" })] })] }));
|
|
39
|
+
}
|
package/dist/Toast.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type ToastTone = "plain" | "info" | "success" | "danger";
|
|
3
|
+
export interface ToastOptions {
|
|
4
|
+
/** A few words above the message, such as what was done: "Deployed". */
|
|
5
|
+
title?: string;
|
|
6
|
+
/** Something to do about what just happened, such as Undo. Pressing it also closes the toast. */
|
|
7
|
+
action?: {
|
|
8
|
+
label: string;
|
|
9
|
+
onClick: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** Where the result is, such as the thing just made: "Open orders/sync". */
|
|
12
|
+
link?: {
|
|
13
|
+
label: string;
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface Toasts {
|
|
18
|
+
/** Shows a message. Returns its ID, for `dismiss`. */
|
|
19
|
+
show: (message: string, tone?: ToastTone, options?: ToastOptions) => number;
|
|
20
|
+
success: (message: string, options?: ToastOptions) => number;
|
|
21
|
+
/** Something worth knowing that is neither a success nor a failure. */
|
|
22
|
+
info: (message: string, options?: ToastOptions) => number;
|
|
23
|
+
/** A failure. It stays until it is dismissed, so it can be read at any pace. */
|
|
24
|
+
danger: (message: string, options?: ToastOptions) => number;
|
|
25
|
+
dismiss: (id: number) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Holds the short messages that confirm what just happened, in a corner of
|
|
29
|
+
* the page. Put one around the app.
|
|
30
|
+
*
|
|
31
|
+
* A message leaves by itself, except a failure, which stays until dismissed.
|
|
32
|
+
* Pointing at the messages, or moving focus into them, holds them until the
|
|
33
|
+
* pointer or focus leaves. Each is read out by screen readers once.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ToastProvider({ duration, navigate, children, }: {
|
|
36
|
+
/** How long a message stays, in milliseconds. A message with an action or a link stays twice as long. */
|
|
37
|
+
duration?: number;
|
|
38
|
+
/** Follows a toast's link inside the app, where the app has its own router. */
|
|
39
|
+
navigate?: (href: string) => void;
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
}): import("react").JSX.Element;
|
|
42
|
+
/** The way to show a toast from anywhere under a `ToastProvider`. */
|
|
43
|
+
export declare function useToast(): Toasts;
|
package/dist/Toast.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CircleCheck, CircleX, Info, X } from "lucide-react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
4
|
+
const tones = {
|
|
5
|
+
plain: "border-line bg-raised",
|
|
6
|
+
info: "border-line bg-raised",
|
|
7
|
+
success: "border-success/40 bg-success-soft",
|
|
8
|
+
danger: "border-danger/40 bg-danger-soft",
|
|
9
|
+
};
|
|
10
|
+
const icons = {
|
|
11
|
+
plain: null,
|
|
12
|
+
info: _jsx(Info, { "aria-hidden": "true", size: 16, className: "mt-0.5 shrink-0 text-action" }),
|
|
13
|
+
success: _jsx(CircleCheck, { "aria-hidden": "true", size: 16, className: "mt-0.5 shrink-0 text-success" }),
|
|
14
|
+
danger: _jsx(CircleX, { "aria-hidden": "true", size: 16, className: "mt-0.5 shrink-0 text-danger" }),
|
|
15
|
+
};
|
|
16
|
+
/** How many messages are on screen at once. Newer ones wait their turn. */
|
|
17
|
+
const VISIBLE = 3;
|
|
18
|
+
const ToastContext = createContext(undefined);
|
|
19
|
+
/**
|
|
20
|
+
* Holds the short messages that confirm what just happened, in a corner of
|
|
21
|
+
* the page. Put one around the app.
|
|
22
|
+
*
|
|
23
|
+
* A message leaves by itself, except a failure, which stays until dismissed.
|
|
24
|
+
* Pointing at the messages, or moving focus into them, holds them until the
|
|
25
|
+
* pointer or focus leaves. Each is read out by screen readers once.
|
|
26
|
+
*/
|
|
27
|
+
export function ToastProvider({ duration = 5000, navigate, children, }) {
|
|
28
|
+
const [shown, setShown] = useState([]);
|
|
29
|
+
// The messages on screen, kept here as well so that `show` can look at them as it is called.
|
|
30
|
+
const list = useRef([]);
|
|
31
|
+
const commit = useCallback((next) => {
|
|
32
|
+
list.current = next;
|
|
33
|
+
setShown(next);
|
|
34
|
+
}, []);
|
|
35
|
+
const next = useRef(1);
|
|
36
|
+
// Each timed message: when it is due to leave, or how long it has left while held.
|
|
37
|
+
const timers = useRef(new Map());
|
|
38
|
+
const held = useRef(false);
|
|
39
|
+
const dismiss = useCallback((id) => {
|
|
40
|
+
clearTimeout(timers.current.get(id)?.timer);
|
|
41
|
+
timers.current.delete(id);
|
|
42
|
+
commit(list.current.filter((toast) => toast.id !== id));
|
|
43
|
+
}, [commit]);
|
|
44
|
+
const start = useCallback((id, ms) => {
|
|
45
|
+
timers.current.set(id, {
|
|
46
|
+
timer: held.current ? undefined : setTimeout(() => dismiss(id), ms),
|
|
47
|
+
due: Date.now() + ms,
|
|
48
|
+
left: ms,
|
|
49
|
+
});
|
|
50
|
+
}, [dismiss]);
|
|
51
|
+
const toasts = useMemo(() => {
|
|
52
|
+
const show = (message, tone = "plain", options = {}) => {
|
|
53
|
+
// The same message again replaces the one shown rather than stacking a copy. It is
|
|
54
|
+
// a new element, so a screen reader says it again.
|
|
55
|
+
const twin = list.current.find((toast) => toast.message === message && toast.tone === tone);
|
|
56
|
+
if (twin) {
|
|
57
|
+
clearTimeout(timers.current.get(twin.id)?.timer);
|
|
58
|
+
timers.current.delete(twin.id);
|
|
59
|
+
}
|
|
60
|
+
const id = next.current++;
|
|
61
|
+
const toast = { id, message, tone, ...options };
|
|
62
|
+
commit([...list.current.filter((one) => one !== twin), toast]);
|
|
63
|
+
return id;
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
show,
|
|
67
|
+
success: (message, options) => show(message, "success", options),
|
|
68
|
+
info: (message, options) => show(message, "info", options),
|
|
69
|
+
danger: (message, options) => show(message, "danger", options),
|
|
70
|
+
dismiss,
|
|
71
|
+
};
|
|
72
|
+
}, [commit, dismiss]);
|
|
73
|
+
// A message's time starts when it is shown: those waiting for room keep theirs.
|
|
74
|
+
const visible = shown.slice(0, VISIBLE);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
for (const toast of visible) {
|
|
77
|
+
if (toast.tone === "danger" || timers.current.has(toast.id))
|
|
78
|
+
continue;
|
|
79
|
+
start(toast.id, toast.action || toast.link ? duration * 2 : duration);
|
|
80
|
+
}
|
|
81
|
+
}, [visible, duration, start]);
|
|
82
|
+
/** Holds every timed message while the pointer or focus is on them. */
|
|
83
|
+
const hold = useCallback(() => {
|
|
84
|
+
if (held.current)
|
|
85
|
+
return;
|
|
86
|
+
held.current = true;
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
for (const entry of timers.current.values()) {
|
|
89
|
+
clearTimeout(entry.timer);
|
|
90
|
+
entry.timer = undefined;
|
|
91
|
+
entry.left = Math.max(entry.due - now, 0);
|
|
92
|
+
}
|
|
93
|
+
}, []);
|
|
94
|
+
const release = useCallback(() => {
|
|
95
|
+
if (!held.current)
|
|
96
|
+
return;
|
|
97
|
+
held.current = false;
|
|
98
|
+
const now = Date.now();
|
|
99
|
+
for (const [id, entry] of timers.current) {
|
|
100
|
+
entry.due = now + entry.left;
|
|
101
|
+
entry.timer = setTimeout(() => dismiss(id), entry.left);
|
|
102
|
+
}
|
|
103
|
+
}, [dismiss]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const pending = timers.current;
|
|
106
|
+
return () => {
|
|
107
|
+
for (const entry of pending.values())
|
|
108
|
+
clearTimeout(entry.timer);
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
const card = (toast) => (_jsxs("div", { role: toast.tone === "danger" ? "alert" : undefined, "data-tone": toast.tone, onKeyDown: (event) => {
|
|
112
|
+
if (event.key === "Escape") {
|
|
113
|
+
event.stopPropagation();
|
|
114
|
+
dismiss(toast.id);
|
|
115
|
+
}
|
|
116
|
+
}, className: `pointer-events-auto flex max-w-full items-start gap-3 rounded-panel border px-3 py-2 text-ink shadow-overlay sm:max-w-96 ${tones[toast.tone]}`, children: [icons[toast.tone], _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [toast.title ? _jsx("span", { className: "font-medium", children: toast.title }) : null, _jsx("span", { className: toast.title ? "text-body-sm text-ink-muted" : "", children: toast.message }), toast.link || toast.action ? (_jsxs("span", { className: "flex flex-wrap items-center gap-3 pt-0.5", children: [toast.link ? (_jsx("a", { href: toast.link.href, className: "font-medium text-action", onClick: (event) => {
|
|
117
|
+
if (!navigate || event.metaKey || event.ctrlKey || event.shiftKey)
|
|
118
|
+
return;
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
navigate(toast.link?.href ?? "");
|
|
121
|
+
dismiss(toast.id);
|
|
122
|
+
}, children: toast.link.label })) : null, toast.action ? (_jsx("button", { type: "button", className: "cursor-pointer rounded-inner font-medium text-action hover:underline", onClick: () => {
|
|
123
|
+
toast.action?.onClick();
|
|
124
|
+
dismiss(toast.id);
|
|
125
|
+
}, children: toast.action.label })) : null] })) : null] }), _jsx("button", { type: "button", "aria-label": "Dismiss", className: "flex size-6 shrink-0 items-center justify-center rounded-inner text-ink-muted hover:bg-sunken hover:text-ink", onClick: () => dismiss(toast.id), children: _jsx(X, { "aria-hidden": "true", size: 14 }) })] }, toast.id));
|
|
126
|
+
return (_jsxs(ToastContext.Provider, { value: toasts, children: [children, _jsxs("div", {
|
|
127
|
+
// A panel docked at the right edge says how much room it takes (`--vx-toast-inset`): a
|
|
128
|
+
// message never covers the buttons of what it is about.
|
|
129
|
+
style: { right: "calc(1rem + var(--vx-toast-inset, 0px))" }, className: "pointer-events-none fixed bottom-4 left-4 layer-toast flex flex-col items-end gap-2 md:items-center", onMouseEnter: hold, onMouseLeave: release, onFocus: hold, onBlur: (event) => {
|
|
130
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
131
|
+
release();
|
|
132
|
+
}, children: [_jsx("div", { "aria-live": "polite", className: "flex flex-col items-end gap-2 md:items-center", children: visible.filter((toast) => toast.tone !== "danger").map(card) }), _jsx("div", { className: "flex flex-col items-end gap-2 md:items-center", children: visible.filter((toast) => toast.tone === "danger").map(card) })] })] }));
|
|
133
|
+
}
|
|
134
|
+
/** The way to show a toast from anywhere under a `ToastProvider`. */
|
|
135
|
+
export function useToast() {
|
|
136
|
+
const toasts = useContext(ToastContext);
|
|
137
|
+
if (!toasts)
|
|
138
|
+
throw new Error("useToast needs a ToastProvider above it.");
|
|
139
|
+
return toasts;
|
|
140
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/** A key or combination, as a person presses it: `⌘K`, `Esc`, `g then r`. */
|
|
3
|
+
export declare function Kbd({ children }: {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
/**
|
|
7
|
+
* Gives a group of tooltips one delay: once one is showing, moving to the next
|
|
8
|
+
* shows it at once. Put once around the app.
|
|
9
|
+
*/
|
|
10
|
+
export declare function TooltipProvider({ children }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* Says what a control does, and its shortcut, when it is pointed at or
|
|
15
|
+
* focused (08 §3.17). For an icon-only control or one whose shortcut is worth
|
|
16
|
+
* learning; a control whose words say it all needs none. The control keeps
|
|
17
|
+
* its own accessible name: the tooltip repeats it for sighted people.
|
|
18
|
+
*
|
|
19
|
+
* A disabled button takes no pointer or focus, so to say why it is disabled
|
|
20
|
+
* the tooltip goes around a focusable wrapper: pass `disabledReason`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function Tooltip({ label, keys, children, side, tapToShow, }: {
|
|
23
|
+
label: ReactNode;
|
|
24
|
+
/** The shortcut, written for people: `⌘Z`. */
|
|
25
|
+
keys?: string | undefined;
|
|
26
|
+
/** One element that takes focus: a button or a link. */
|
|
27
|
+
children: ReactElement;
|
|
28
|
+
side?: "top" | "bottom" | "left" | "right";
|
|
29
|
+
/**
|
|
30
|
+
* A touch screen has no pointing: a tap shows the words for a few seconds. For the reason a
|
|
31
|
+
* button is disabled, which a person on a phone would otherwise never be told.
|
|
32
|
+
*/
|
|
33
|
+
tapToShow?: boolean;
|
|
34
|
+
}): import("react").JSX.Element;
|
package/dist/Tooltip.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip as Base } from "@base-ui/react/tooltip";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
/** A key or combination, as a person presses it: `⌘K`, `Esc`, `g then r`. */
|
|
5
|
+
export function Kbd({ children }) {
|
|
6
|
+
return (_jsx("kbd", { className: "inline-flex h-5 min-w-5 items-center justify-center rounded-inner border border-line-strong bg-track px-1.5 font-mono text-code-sm leading-none whitespace-nowrap text-ink-muted", children: children }));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Gives a group of tooltips one delay: once one is showing, moving to the next
|
|
10
|
+
* shows it at once. Put once around the app.
|
|
11
|
+
*/
|
|
12
|
+
export function TooltipProvider({ children }) {
|
|
13
|
+
return (_jsx(Base.Provider, { delay: 500, closeDelay: 0, children: children }));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Says what a control does, and its shortcut, when it is pointed at or
|
|
17
|
+
* focused (08 §3.17). For an icon-only control or one whose shortcut is worth
|
|
18
|
+
* learning; a control whose words say it all needs none. The control keeps
|
|
19
|
+
* its own accessible name: the tooltip repeats it for sighted people.
|
|
20
|
+
*
|
|
21
|
+
* A disabled button takes no pointer or focus, so to say why it is disabled
|
|
22
|
+
* the tooltip goes around a focusable wrapper: pass `disabledReason`.
|
|
23
|
+
*/
|
|
24
|
+
export function Tooltip({ label, keys, children, side = "top", tapToShow = false, }) {
|
|
25
|
+
const [open, setOpen] = useState(false);
|
|
26
|
+
const timer = useRef(undefined);
|
|
27
|
+
// Shown by a tap: the finger lifting is not the pointer leaving, so hover's close is ignored.
|
|
28
|
+
const tapped = useRef(false);
|
|
29
|
+
const hide = useCallback(() => {
|
|
30
|
+
clearTimeout(timer.current);
|
|
31
|
+
tapped.current = false;
|
|
32
|
+
setOpen(false);
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
35
|
+
// A tap anywhere else puts it away.
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!open || !tapped.current)
|
|
38
|
+
return;
|
|
39
|
+
const away = () => hide();
|
|
40
|
+
const soon = setTimeout(() => document.addEventListener("pointerdown", away, { once: true }), 50);
|
|
41
|
+
return () => {
|
|
42
|
+
clearTimeout(soon);
|
|
43
|
+
document.removeEventListener("pointerdown", away);
|
|
44
|
+
};
|
|
45
|
+
}, [open, hide]);
|
|
46
|
+
const touch = tapToShow
|
|
47
|
+
? {
|
|
48
|
+
onPointerUp: (event) => {
|
|
49
|
+
if (event.pointerType !== "touch")
|
|
50
|
+
return;
|
|
51
|
+
clearTimeout(timer.current);
|
|
52
|
+
tapped.current = true;
|
|
53
|
+
setOpen(true);
|
|
54
|
+
timer.current = setTimeout(hide, 5000);
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
: {};
|
|
58
|
+
return (_jsxs(Base.Root, { ...(tapToShow
|
|
59
|
+
? {
|
|
60
|
+
open,
|
|
61
|
+
onOpenChange: (next, details) => {
|
|
62
|
+
if (!next && tapped.current && details?.reason !== "escape-key")
|
|
63
|
+
return;
|
|
64
|
+
if (!next)
|
|
65
|
+
tapped.current = false;
|
|
66
|
+
setOpen(next);
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
: {}), children: [_jsx(Base.Trigger, { render: children, ...touch }), _jsx(Base.Portal, { children: _jsx(Base.Positioner, { side: side, sideOffset: 6, className: "layer-popover", children: _jsxs(Base.Popup, { className: "flex max-w-xs items-center gap-2 rounded-control border border-line-strong bg-raised px-2 py-1.5 text-meta text-ink shadow-overlay transition-[opacity,translate] motion-base data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 data-[starting-style]:translate-y-1", children: [_jsx("span", { children: label }), keys ? _jsx(Kbd, { children: keys }) : null] }) }) })] }));
|
|
70
|
+
}
|
package/dist/Tree.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface TreeNode {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
/** Drawn before the label. */
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
/** Drawn right after the label, on its line: a state, such as a draft. */
|
|
8
|
+
badge?: ReactNode;
|
|
9
|
+
/** A second, quieter line under the label: a file's name. */
|
|
10
|
+
detail?: ReactNode;
|
|
11
|
+
/** Drawn after the label: a tag or a count. */
|
|
12
|
+
trailing?: ReactNode;
|
|
13
|
+
/** Buttons for the row, shown while it is pointed at or holds the focus, and always on a touch screen. */
|
|
14
|
+
actions?: ReactNode;
|
|
15
|
+
/** Drawn in place of the label and the detail while the row is being edited, such as renamed. */
|
|
16
|
+
editing?: ReactNode;
|
|
17
|
+
/** Set, even if empty, on a node that opens and closes. */
|
|
18
|
+
children?: TreeNode[];
|
|
19
|
+
}
|
|
20
|
+
/** Where a dragged row is let go: before a row, after it, or into it when it holds others. */
|
|
21
|
+
export type DropPosition = "before" | "after" | "inside";
|
|
22
|
+
/**
|
|
23
|
+
* Things inside things: folders and their pages. One row holds the keyboard.
|
|
24
|
+
* Up and Down move between the rows that show, Right opens a row or steps
|
|
25
|
+
* into it, Left closes it or steps out, Home and End go to the ends, Enter or
|
|
26
|
+
* Space chooses, and F2 renames when the tree says how.
|
|
27
|
+
*
|
|
28
|
+
* With `onMove`, a row can be dragged by its grip: before or after another,
|
|
29
|
+
* or into one that holds others. A line says "between", a filled row says
|
|
30
|
+
* "into", and a closed row held over for a moment opens. A drag is a
|
|
31
|
+
* pointer's way only, so whoever gives `onMove` gives the same move another
|
|
32
|
+
* way too, for the keyboard and for a touch screen.
|
|
33
|
+
*/
|
|
34
|
+
export declare function Tree({ label, nodes, selected, onSelect, defaultExpanded, canDrag, canDrop, onMove, onRename, }: {
|
|
35
|
+
/** Names the tree for screen readers: "Pages". */
|
|
36
|
+
label: string;
|
|
37
|
+
nodes: TreeNode[];
|
|
38
|
+
/** The id of the chosen node. */
|
|
39
|
+
selected?: string;
|
|
40
|
+
onSelect?: (id: string) => void;
|
|
41
|
+
/** The ids open to begin with. Left out, every node is open. */
|
|
42
|
+
defaultExpanded?: string[];
|
|
43
|
+
/** Which rows can be picked up. Left out, with `onMove`, every row can. */
|
|
44
|
+
canDrag?: (id: string) => boolean;
|
|
45
|
+
/** Whether a row can be let go there. Left out, with `onMove`, anywhere but on itself. */
|
|
46
|
+
canDrop?: (dragged: string, target: string, position: DropPosition) => boolean;
|
|
47
|
+
/** A row was let go before, after or into another. */
|
|
48
|
+
onMove?: (dragged: string, target: string, position: DropPosition) => void;
|
|
49
|
+
/** F2 on a row. */
|
|
50
|
+
onRename?: (id: string) => void;
|
|
51
|
+
}): import("react").JSX.Element;
|
package/dist/Tree.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronRight, GripVertical } from "lucide-react";
|
|
3
|
+
import { useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { ICON, STROKE } from "./icons.js";
|
|
5
|
+
/** How long a closed folder must be held over before it opens. */
|
|
6
|
+
const OPEN_AFTER_MS = 600;
|
|
7
|
+
/**
|
|
8
|
+
* Things inside things: folders and their pages. One row holds the keyboard.
|
|
9
|
+
* Up and Down move between the rows that show, Right opens a row or steps
|
|
10
|
+
* into it, Left closes it or steps out, Home and End go to the ends, Enter or
|
|
11
|
+
* Space chooses, and F2 renames when the tree says how.
|
|
12
|
+
*
|
|
13
|
+
* With `onMove`, a row can be dragged by its grip: before or after another,
|
|
14
|
+
* or into one that holds others. A line says "between", a filled row says
|
|
15
|
+
* "into", and a closed row held over for a moment opens. A drag is a
|
|
16
|
+
* pointer's way only, so whoever gives `onMove` gives the same move another
|
|
17
|
+
* way too, for the keyboard and for a touch screen.
|
|
18
|
+
*/
|
|
19
|
+
export function Tree({ label, nodes, selected, onSelect, defaultExpanded, canDrag, canDrop, onMove, onRename, }) {
|
|
20
|
+
const base = useId();
|
|
21
|
+
// The row being dragged, and where it would go if it were let go now.
|
|
22
|
+
const [dragged, setDragged] = useState();
|
|
23
|
+
const [over, setOver] = useState();
|
|
24
|
+
const opening = useRef(undefined);
|
|
25
|
+
const takes = (target, position) => onMove !== undefined &&
|
|
26
|
+
dragged !== undefined &&
|
|
27
|
+
dragged !== target &&
|
|
28
|
+
(canDrop ? canDrop(dragged, target, position) : true);
|
|
29
|
+
const everyBranch = useMemo(() => {
|
|
30
|
+
const ids = [];
|
|
31
|
+
const visit = (list) => {
|
|
32
|
+
for (const node of list) {
|
|
33
|
+
if (node.children) {
|
|
34
|
+
ids.push(node.id);
|
|
35
|
+
visit(node.children);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
visit(nodes);
|
|
40
|
+
return ids;
|
|
41
|
+
}, [nodes]);
|
|
42
|
+
const [closed, setClosed] = useState(() => new Set(defaultExpanded ? everyBranch.filter((id) => !defaultExpanded.includes(id)) : []));
|
|
43
|
+
const rows = useMemo(() => {
|
|
44
|
+
const out = [];
|
|
45
|
+
const visit = (list, level, parent) => {
|
|
46
|
+
for (const node of list) {
|
|
47
|
+
out.push(parent === undefined ? { node, level } : { node, level, parent });
|
|
48
|
+
if (node.children && !closed.has(node.id))
|
|
49
|
+
visit(node.children, level + 1, node.id);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
visit(nodes, 1);
|
|
53
|
+
return out;
|
|
54
|
+
}, [nodes, closed]);
|
|
55
|
+
const [focused, setFocused] = useState(undefined);
|
|
56
|
+
const current = rows.some((row) => row.node.id === focused)
|
|
57
|
+
? focused
|
|
58
|
+
: rows.some((row) => row.node.id === selected)
|
|
59
|
+
? selected
|
|
60
|
+
: rows[0]?.node.id;
|
|
61
|
+
const list = useRef(null);
|
|
62
|
+
useEffect(() => () => clearTimeout(opening.current?.timer), []);
|
|
63
|
+
const focus = (id) => {
|
|
64
|
+
if (id === undefined)
|
|
65
|
+
return;
|
|
66
|
+
setFocused(id);
|
|
67
|
+
list.current?.querySelector(`[data-tree-id="${CSS.escape(id)}"]`)?.focus();
|
|
68
|
+
};
|
|
69
|
+
const toggle = (id, open) => {
|
|
70
|
+
setClosed((before) => {
|
|
71
|
+
const next = new Set(before);
|
|
72
|
+
if (open)
|
|
73
|
+
next.delete(id);
|
|
74
|
+
else
|
|
75
|
+
next.add(id);
|
|
76
|
+
return next;
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const stopOpening = () => {
|
|
80
|
+
clearTimeout(opening.current?.timer);
|
|
81
|
+
opening.current = undefined;
|
|
82
|
+
};
|
|
83
|
+
const endDrag = () => {
|
|
84
|
+
stopOpening();
|
|
85
|
+
setDragged(undefined);
|
|
86
|
+
setOver(undefined);
|
|
87
|
+
};
|
|
88
|
+
const onKeyDown = (event, row) => {
|
|
89
|
+
// Keys typed into what a row holds while it is edited are that field's.
|
|
90
|
+
if (event.target !== event.currentTarget)
|
|
91
|
+
return;
|
|
92
|
+
const at = rows.indexOf(row);
|
|
93
|
+
const branch = row.node.children !== undefined;
|
|
94
|
+
const open = branch && !closed.has(row.node.id);
|
|
95
|
+
switch (event.key) {
|
|
96
|
+
case "ArrowDown":
|
|
97
|
+
focus(rows[at + 1]?.node.id);
|
|
98
|
+
break;
|
|
99
|
+
case "ArrowUp":
|
|
100
|
+
focus(rows[at - 1]?.node.id);
|
|
101
|
+
break;
|
|
102
|
+
case "ArrowRight":
|
|
103
|
+
if (branch && !open)
|
|
104
|
+
toggle(row.node.id, true);
|
|
105
|
+
else if (open)
|
|
106
|
+
focus(rows[at + 1]?.node.id);
|
|
107
|
+
break;
|
|
108
|
+
case "ArrowLeft":
|
|
109
|
+
if (open)
|
|
110
|
+
toggle(row.node.id, false);
|
|
111
|
+
else
|
|
112
|
+
focus(row.parent);
|
|
113
|
+
break;
|
|
114
|
+
case "Home":
|
|
115
|
+
focus(rows[0]?.node.id);
|
|
116
|
+
break;
|
|
117
|
+
case "End":
|
|
118
|
+
focus(rows.at(-1)?.node.id);
|
|
119
|
+
break;
|
|
120
|
+
case "Enter":
|
|
121
|
+
case " ":
|
|
122
|
+
onSelect?.(row.node.id);
|
|
123
|
+
break;
|
|
124
|
+
case "F2":
|
|
125
|
+
if (!onRename)
|
|
126
|
+
return;
|
|
127
|
+
onRename(row.node.id);
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
};
|
|
134
|
+
/** Where a row would go, from where the pointer is over another: its top, its middle or its bottom. */
|
|
135
|
+
const positionAt = (event, branch) => {
|
|
136
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
137
|
+
const at = box.height > 0 ? (event.clientY - box.top) / box.height : 0.5;
|
|
138
|
+
if (!branch)
|
|
139
|
+
return at < 0.5 ? "before" : "after";
|
|
140
|
+
return at < 0.25 ? "before" : at > 0.75 ? "after" : "inside";
|
|
141
|
+
};
|
|
142
|
+
return (_jsx("div", { ref: list, role: "tree", "aria-label": label, className: "flex flex-col", children: rows.map((row, index) => {
|
|
143
|
+
const { node, level } = row;
|
|
144
|
+
const branch = node.children !== undefined;
|
|
145
|
+
const open = branch && !closed.has(node.id);
|
|
146
|
+
const chosen = node.id === selected;
|
|
147
|
+
const grabbable = onMove !== undefined && (canDrag ? canDrag(node.id) : true);
|
|
148
|
+
const here = over?.id === node.id ? over.position : undefined;
|
|
149
|
+
// A row is named by everything it shows, the badge, the detail and what trails included,
|
|
150
|
+
// so that what is heard holds what is seen (WCAG 2.5.3). Its buttons have names of their own.
|
|
151
|
+
const part = (name) => `${base}-${index}-${name}`;
|
|
152
|
+
const named = node.editing !== undefined
|
|
153
|
+
? { "aria-label": node.label }
|
|
154
|
+
: {
|
|
155
|
+
"aria-labelledby": [
|
|
156
|
+
part("name"),
|
|
157
|
+
...(node.detail !== undefined ? [part("detail")] : []),
|
|
158
|
+
...(node.trailing !== undefined && here !== "inside" ? [part("trailing")] : []),
|
|
159
|
+
].join(" "),
|
|
160
|
+
};
|
|
161
|
+
return (_jsxs("div", { role: "treeitem", ...named, "data-tree-id": node.id, "aria-level": level, "aria-selected": chosen, ...(branch ? { "aria-expanded": open } : {}), tabIndex: node.id === current ? 0 : -1, onKeyDown: (event) => onKeyDown(event, row), onFocus: (event) => {
|
|
162
|
+
if (event.target === event.currentTarget)
|
|
163
|
+
setFocused(node.id);
|
|
164
|
+
}, onClick: (event) => {
|
|
165
|
+
if (node.editing !== undefined)
|
|
166
|
+
return;
|
|
167
|
+
if (event.target.closest("[data-tree-action]"))
|
|
168
|
+
return;
|
|
169
|
+
setFocused(node.id);
|
|
170
|
+
onSelect?.(node.id);
|
|
171
|
+
}, ...(grabbable && node.editing === undefined
|
|
172
|
+
? {
|
|
173
|
+
draggable: true,
|
|
174
|
+
onDragStart: (event) => {
|
|
175
|
+
event.dataTransfer.effectAllowed = "move";
|
|
176
|
+
event.dataTransfer.setData("text/plain", node.label);
|
|
177
|
+
setDragged(node.id);
|
|
178
|
+
},
|
|
179
|
+
onDragEnd: endDrag,
|
|
180
|
+
}
|
|
181
|
+
: {}), ...(onMove
|
|
182
|
+
? {
|
|
183
|
+
onDragOver: (event) => {
|
|
184
|
+
const position = positionAt(event, branch);
|
|
185
|
+
if (!takes(node.id, position)) {
|
|
186
|
+
if (over?.id === node.id)
|
|
187
|
+
setOver(undefined);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
event.dataTransfer.dropEffect = "move";
|
|
192
|
+
if (over?.id !== node.id || over.position !== position) {
|
|
193
|
+
setOver({ id: node.id, position });
|
|
194
|
+
}
|
|
195
|
+
// A closed folder held over for a moment opens, so a row can go deeper.
|
|
196
|
+
if (position === "inside" && branch && !open) {
|
|
197
|
+
if (opening.current?.id !== node.id) {
|
|
198
|
+
stopOpening();
|
|
199
|
+
opening.current = {
|
|
200
|
+
id: node.id,
|
|
201
|
+
timer: setTimeout(() => toggle(node.id, true), OPEN_AFTER_MS),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (opening.current?.id === node.id)
|
|
206
|
+
stopOpening();
|
|
207
|
+
},
|
|
208
|
+
onDragLeave: (event) => {
|
|
209
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
210
|
+
return;
|
|
211
|
+
if (over?.id === node.id)
|
|
212
|
+
setOver(undefined);
|
|
213
|
+
if (opening.current?.id === node.id)
|
|
214
|
+
stopOpening();
|
|
215
|
+
},
|
|
216
|
+
onDrop: (event) => {
|
|
217
|
+
const position = positionAt(event, branch);
|
|
218
|
+
if (!takes(node.id, position) || dragged === undefined)
|
|
219
|
+
return;
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
const moved = dragged;
|
|
222
|
+
endDrag();
|
|
223
|
+
onMove(moved, node.id, position);
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
: {}), style: { paddingLeft: `${(level - 1) * 18 + 2}px` }, className: `group relative flex min-h-control cursor-pointer items-center gap-1.5 rounded-control py-1 pr-1.5 ${chosen ? "bg-selected text-ink" : "text-ink hover:bg-sunken"} ${here === "inside" ? "bg-action-soft outline outline-1 outline-action -outline-offset-1" : ""} ${dragged === node.id ? "opacity-50" : ""}`, children: [Array.from({ length: level - 1 }, (_, depth) => (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 w-px bg-line", style: { left: `${depth * 18 + (onMove ? 32 : 13)}px` } }, depth))), chosen ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-1.5 w-0.5 rounded-full bg-action", style: { left: `${(level - 1) * 18 + (onMove ? 22 : 3)}px` } })) : null, here === "before" || here === "after" ? (_jsx("span", { "aria-hidden": true, className: `pointer-events-none absolute right-1 h-0.5 rounded-full bg-action ${here === "before" ? "-top-px" : "-bottom-px"}`, style: { left: `${(level - 1) * 18 + 8}px` }, children: _jsx("span", { className: "absolute -top-[3px] -left-1 size-2 rounded-full border-2 border-action bg-surface" }) })) : null, onMove ? (_jsx("span", { "aria-hidden": true, className: `inline-flex w-4 shrink-0 justify-center ${grabbable
|
|
227
|
+
? "cursor-grab text-ink-subtle opacity-40 group-hover:opacity-100"
|
|
228
|
+
: "opacity-0"}`, children: _jsx(GripVertical, { size: ICON.sm, strokeWidth: STROKE }) })) : null, branch ? (_jsx("button", { type: "button", tabIndex: -1, "data-tree-action": true, "aria-label": open ? `Close ${node.label}` : `Open ${node.label}`, onClick: (event) => {
|
|
229
|
+
event.stopPropagation();
|
|
230
|
+
toggle(node.id, !open);
|
|
231
|
+
}, className: "inline-flex size-5 shrink-0 items-center justify-center rounded-inner text-ink-muted hover:text-ink", children: _jsx(ChevronRight, { size: ICON.sm, strokeWidth: STROKE, "aria-hidden": true, className: `transition-transform motion-fast ${open ? "rotate-90" : ""}` }) })) : (_jsx("span", { className: "size-5 shrink-0", "aria-hidden": true })), node.icon, node.editing !== undefined ? (_jsx("div", { className: "min-w-0 flex-1", children: node.editing })) : (_jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("span", { id: part("name"), className: `flex min-w-0 items-center gap-1.5 ${chosen ? "font-medium" : ""}`, children: [_jsx("span", { className: "truncate", children: node.label }), node.badge !== undefined ? _jsxs(_Fragment, { children: [" ", node.badge] }) : null] }), node.detail !== undefined ? " " : null, node.detail !== undefined ? (_jsx("span", { id: part("detail"), className: "truncate font-mono text-code-sm text-ink-subtle", children: node.detail })) : null] })), here === "inside" ? (_jsx("span", { className: "shrink-0 text-meta text-action", children: "Move into" })) : node.trailing !== undefined ? (_jsxs("span", { id: part("trailing"), className: "contents", children: [" ", node.trailing] })) : null, node.actions !== undefined && node.editing === undefined ? (_jsx("span", { "data-tree-action": true, className: "flex shrink-0 items-center gap-0.5 opacity-0 group-focus-within:opacity-100 group-hover:opacity-100 pointer-coarse:opacity-100", children: node.actions })) : null] }, node.id));
|
|
232
|
+
}) }));
|
|
233
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { View } from "vega";
|
|
2
|
+
import type { Config } from "vega-lite";
|
|
3
|
+
/** The three libraries that draw a chart. */
|
|
4
|
+
export interface ChartEngine {
|
|
5
|
+
vega: typeof import("vega");
|
|
6
|
+
lite: typeof import("vega-lite");
|
|
7
|
+
interpreter: typeof import("vega-interpreter");
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Fetches the chart engine the first time a chart needs it. It is large, so
|
|
11
|
+
* it stays out of the page's main script: a page with no chart never loads it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadChartEngine(): Promise<ChartEngine>;
|
|
14
|
+
/**
|
|
15
|
+
* The spec as it is drawn: with the rows put in as its data when there are
|
|
16
|
+
* any, as wide as its container and of the given height unless it says otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export declare function chartSpec(spec: object, data: readonly Record<string, unknown>[] | undefined, height: number): object;
|
|
19
|
+
/** What d3 needs to write numbers the way a locale does, read from Intl so no table is kept. */
|
|
20
|
+
export declare function numberLocale(locale: string): {
|
|
21
|
+
decimal: string;
|
|
22
|
+
thousands: string;
|
|
23
|
+
grouping: number[];
|
|
24
|
+
currency: [string, string];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Compiles a Vega-Lite spec and builds its view. Expressions are parsed to a
|
|
28
|
+
* syntax tree and run by the interpreter, so nothing is evaluated from a
|
|
29
|
+
* string and the page needs no `unsafe-eval` in its content security policy.
|
|
30
|
+
* Throws when the spec does not compile.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createChartView(engine: ChartEngine, spec: object, config: Config, container?: Element, locale?: string): View;
|