@zonsh/ui 0.2.0 → 0.5.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 +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { LibraryBigIcon, PlusIcon, SearchIcon, XIcon } from "lucide-react";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { cn } from "../lib/cn.js";
|
|
6
|
-
import { modKey, modPressed } from "../lib/platform.js";
|
|
7
|
-
import { Button } from "./button.js";
|
|
8
|
-
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "./input-group.js";
|
|
9
|
-
import { Skeleton } from "./skeleton.js";
|
|
10
|
-
/**
|
|
11
|
-
* Excalidraw's font ids, and the Licht face `excalidrawAssets()` draws each in. Text starts in
|
|
12
|
-
* Licht Soft (Excalidraw's "Normal").
|
|
13
|
-
*/
|
|
14
|
-
const LICHT_SOFT = 6;
|
|
15
|
-
const LICHT_NAMES = {
|
|
16
|
-
"1": "Licht Soft",
|
|
17
|
-
"2": "Licht Sans",
|
|
18
|
-
"3": "Licht Mono",
|
|
19
|
-
"5": "Licht Serif",
|
|
20
|
-
"6": "Licht Soft",
|
|
21
|
-
"7": "Licht Sans",
|
|
22
|
-
"8": "Licht Mono",
|
|
23
|
-
"9": "Licht Sans",
|
|
24
|
-
};
|
|
25
|
-
const LICHT_BUTTONS = {
|
|
26
|
-
"font-family-hand-drawn": "Licht Serif",
|
|
27
|
-
"font-family-normal": "Licht Soft",
|
|
28
|
-
"font-family-code": "Licht Mono",
|
|
29
|
-
};
|
|
30
|
-
/** The drawing style a look starts new elements with. */
|
|
31
|
-
function lookOf(look) {
|
|
32
|
-
return look === "clean"
|
|
33
|
-
? { roughness: 0, strokeWidth: 1, fontFamily: LICHT_SOFT }
|
|
34
|
-
: { roughness: 1, strokeWidth: 2, fontFamily: LICHT_SOFT };
|
|
35
|
-
}
|
|
36
|
-
/** Excalidraw is large: loaded the first time a whiteboard is drawn, then shared. */
|
|
37
|
-
let loading = null;
|
|
38
|
-
function load(assetPath) {
|
|
39
|
-
window.EXCALIDRAW_ASSET_PATH = assetPath;
|
|
40
|
-
loading ??= Promise.all([
|
|
41
|
-
import("@excalidraw/excalidraw"),
|
|
42
|
-
import("@excalidraw/excalidraw/index.css"),
|
|
43
|
-
]).then(([module]) => module);
|
|
44
|
-
return loading;
|
|
45
|
-
}
|
|
46
|
-
/** Light or dark, as the whiteboard's surroundings are: a forced scheme, or the page's. */
|
|
47
|
-
function useDark(frame) {
|
|
48
|
-
const [dark, setDark] = React.useState(false);
|
|
49
|
-
React.useEffect(() => {
|
|
50
|
-
const read = () => {
|
|
51
|
-
const el = frame.current;
|
|
52
|
-
if (!el)
|
|
53
|
-
return;
|
|
54
|
-
const forced = el.closest(".theme-dark, .theme-night, .theme-light");
|
|
55
|
-
setDark(forced
|
|
56
|
-
? !forced.classList.contains("theme-light")
|
|
57
|
-
: document.documentElement.classList.contains("dark"));
|
|
58
|
-
};
|
|
59
|
-
read();
|
|
60
|
-
const watch = new MutationObserver(read);
|
|
61
|
-
watch.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
|
|
62
|
-
return () => watch.disconnect();
|
|
63
|
-
}, [frame]);
|
|
64
|
-
return dark;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Whiteboard — a canvas to draw on: shapes, arrows, text, freehand lines and images, in
|
|
68
|
-
* Excalidraw's hand-drawn style, its interface set in the zon material and following light and
|
|
69
|
-
* dark. Pan with a drag on empty space or the wheel, zoom with a pinch or Ctrl/⌘ and the wheel.
|
|
70
|
-
*
|
|
71
|
-
* Excalidraw is large, so it is loaded only when a whiteboard first appears; until then a
|
|
72
|
-
* skeleton holds its place. It needs `@excalidraw/excalidraw` and is imported from
|
|
73
|
-
* `@zonsh/ui/whiteboard`; serve its fonts from your own origin with `excalidrawAssets()`.
|
|
74
|
-
* The rule people break: putting it on a page that does not need drawing, where it only costs
|
|
75
|
-
* the download.
|
|
76
|
-
*/
|
|
77
|
-
export function Whiteboard({ ref, initialData, onChange, onLibraryChange, readOnly = false, grid = false, name, assetPath = "/excalidraw/", variant = "region", look = "clean", className, ...props }) {
|
|
78
|
-
const frame = React.useRef(null);
|
|
79
|
-
const [module, setModule] = React.useState(null);
|
|
80
|
-
const [failed, setFailed] = React.useState(false);
|
|
81
|
-
const api = React.useRef(null);
|
|
82
|
-
const dark = useDark(frame);
|
|
83
|
-
// The board's height, for menus that must not run past it (the right-click menu scrolls).
|
|
84
|
-
React.useEffect(() => {
|
|
85
|
-
const el = frame.current;
|
|
86
|
-
if (!el)
|
|
87
|
-
return;
|
|
88
|
-
const size = new ResizeObserver(() => el.style.setProperty("--whiteboard-height", `${el.clientHeight}px`));
|
|
89
|
-
size.observe(el);
|
|
90
|
-
return () => size.disconnect();
|
|
91
|
-
}, []);
|
|
92
|
-
React.useEffect(() => {
|
|
93
|
-
let alive = true;
|
|
94
|
-
load(assetPath).then((m) => alive && setModule(m), () => alive && setFailed(true));
|
|
95
|
-
return () => {
|
|
96
|
-
alive = false;
|
|
97
|
-
};
|
|
98
|
-
}, [assetPath]);
|
|
99
|
-
// Names Excalidraw does not give, again whenever it redraws: its menu button is only an icon,
|
|
100
|
-
// and its font picker names the fonts Licht stands in for.
|
|
101
|
-
React.useEffect(() => {
|
|
102
|
-
const el = frame.current;
|
|
103
|
-
if (!el || !module)
|
|
104
|
-
return;
|
|
105
|
-
const name = () => {
|
|
106
|
-
for (const button of el.querySelectorAll(".main-menu-trigger:not([aria-label])"))
|
|
107
|
-
button.setAttribute("aria-label", "Menu");
|
|
108
|
-
for (const button of el.querySelectorAll("[data-testid^='font-family-']")) {
|
|
109
|
-
const label = LICHT_BUTTONS[button.dataset.testid];
|
|
110
|
-
if (label && button.title !== label) {
|
|
111
|
-
button.title = label;
|
|
112
|
-
button.setAttribute("aria-label", label);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (const item of el.querySelectorAll(".dropdown-menu.fonts .dropdown-menu-item")) {
|
|
116
|
-
const label = LICHT_NAMES[item.getAttribute("value") ?? ""];
|
|
117
|
-
const text = item.querySelector(".dropdown-menu-item__text");
|
|
118
|
-
if (label && text && text.textContent !== label)
|
|
119
|
-
text.textContent = label;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
name();
|
|
123
|
-
const watch = new MutationObserver(name);
|
|
124
|
-
watch.observe(el, { childList: true, subtree: true });
|
|
125
|
-
return () => watch.disconnect();
|
|
126
|
-
}, [module]);
|
|
127
|
-
/* Find and Library are our own panels. Whatever opens Excalidraw's sidebar (Ctrl+F, "Add to
|
|
128
|
-
library") opens ours instead, and its sidebar never shows. */
|
|
129
|
-
const [panel, setPanel] = React.useState(null);
|
|
130
|
-
const showing = React.useRef(panel);
|
|
131
|
-
showing.current = panel;
|
|
132
|
-
const [items, setItems] = React.useState(initialData?.libraryItems ?? []);
|
|
133
|
-
const [selection, setSelection] = React.useState(0);
|
|
134
|
-
const [tick, setTick] = React.useState(0);
|
|
135
|
-
const close = React.useCallback(() => {
|
|
136
|
-
setPanel(null);
|
|
137
|
-
// Back to the canvas, so its shortcuts work again.
|
|
138
|
-
frame.current?.querySelector(".excalidraw")?.focus({ preventScroll: true });
|
|
139
|
-
}, []);
|
|
140
|
-
// Report a change only when the drawing changed: Excalidraw calls back on every pointer move.
|
|
141
|
-
const version = React.useRef(-1);
|
|
142
|
-
const handleChange = React.useCallback((elements, appState, files) => {
|
|
143
|
-
if (!module)
|
|
144
|
-
return;
|
|
145
|
-
if (appState.openSidebar) {
|
|
146
|
-
const tab = appState.openSidebar.tab;
|
|
147
|
-
queueMicrotask(() => api.current?.updateScene({ appState: { openSidebar: null } }));
|
|
148
|
-
setPanel(tab === "search" ? "search" : "library");
|
|
149
|
-
}
|
|
150
|
-
if (showing.current === "library")
|
|
151
|
-
setSelection(Object.keys(appState.selectedElementIds).length);
|
|
152
|
-
const next = module.getSceneVersion(elements) + Object.keys(files).length;
|
|
153
|
-
if (next === version.current)
|
|
154
|
-
return;
|
|
155
|
-
version.current = next;
|
|
156
|
-
if (showing.current === "search")
|
|
157
|
-
setTick((t) => t + 1);
|
|
158
|
-
onChange?.({ elements, appState, files });
|
|
159
|
-
}, [module, onChange]);
|
|
160
|
-
const handleLibraryChange = React.useCallback((next) => {
|
|
161
|
-
setItems(next);
|
|
162
|
-
onLibraryChange?.(next);
|
|
163
|
-
}, [onLibraryChange]);
|
|
164
|
-
// A library item lands where a drop puts it: Excalidraw's own drop, aimed at the open canvas.
|
|
165
|
-
const place = React.useCallback((item) => {
|
|
166
|
-
const container = frame.current?.querySelector(".excalidraw");
|
|
167
|
-
if (!module || !container)
|
|
168
|
-
return;
|
|
169
|
-
const box = container.getBoundingClientRect();
|
|
170
|
-
const data = new DataTransfer();
|
|
171
|
-
data.setData(module.MIME_TYPES.excalidrawlib, module.serializeLibraryAsJSON([item]));
|
|
172
|
-
container.dispatchEvent(new DragEvent("drop", {
|
|
173
|
-
bubbles: true,
|
|
174
|
-
cancelable: true,
|
|
175
|
-
dataTransfer: data,
|
|
176
|
-
// The middle of what the panel leaves open.
|
|
177
|
-
clientX: box.left + Math.max(box.width - 320, box.width / 2) / 2,
|
|
178
|
-
clientY: box.top + box.height / 2,
|
|
179
|
-
}));
|
|
180
|
-
}, [module]);
|
|
181
|
-
const keepSelection = React.useCallback(() => {
|
|
182
|
-
const a = api.current;
|
|
183
|
-
if (!a)
|
|
184
|
-
return;
|
|
185
|
-
const state = a.getAppState();
|
|
186
|
-
const chosen = a
|
|
187
|
-
.getSceneElements()
|
|
188
|
-
.filter((e) => state.selectedElementIds[e.id] ||
|
|
189
|
-
(e.type === "text" && e.containerId && state.selectedElementIds[e.containerId]) ||
|
|
190
|
-
e.groupIds.some((g) => state.selectedGroupIds[g]));
|
|
191
|
-
if (!chosen.length)
|
|
192
|
-
return;
|
|
193
|
-
void a.updateLibrary({
|
|
194
|
-
libraryItems: [
|
|
195
|
-
{ id: crypto.randomUUID(), status: "unpublished", elements: chosen, created: Date.now() },
|
|
196
|
-
],
|
|
197
|
-
merge: true,
|
|
198
|
-
});
|
|
199
|
-
}, []);
|
|
200
|
-
const forget = React.useCallback((id) => void api.current?.updateLibrary({ libraryItems: items.filter((i) => i.id !== id), merge: false }), [items]);
|
|
201
|
-
React.useImperativeHandle(ref, () => ({
|
|
202
|
-
get api() {
|
|
203
|
-
return api.current;
|
|
204
|
-
},
|
|
205
|
-
getScene: () => ({
|
|
206
|
-
elements: api.current?.getSceneElements() ?? [],
|
|
207
|
-
appState: api.current?.getAppState(),
|
|
208
|
-
files: api.current?.getFiles(),
|
|
209
|
-
}),
|
|
210
|
-
toPng: async ({ scale = 2, background = true } = {}) => {
|
|
211
|
-
const m = module ?? (await load(assetPath));
|
|
212
|
-
const a = api.current;
|
|
213
|
-
if (!a)
|
|
214
|
-
throw new Error("Whiteboard is not ready yet.");
|
|
215
|
-
return m.exportToBlob({
|
|
216
|
-
elements: a.getSceneElements(),
|
|
217
|
-
appState: { ...a.getAppState(), exportBackground: background, exportWithDarkMode: dark },
|
|
218
|
-
files: a.getFiles(),
|
|
219
|
-
mimeType: "image/png",
|
|
220
|
-
getDimensions: (width, height) => ({
|
|
221
|
-
width: width * scale,
|
|
222
|
-
height: height * scale,
|
|
223
|
-
scale,
|
|
224
|
-
}),
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
toSvg: async ({ background = true } = {}) => {
|
|
228
|
-
const m = module ?? (await load(assetPath));
|
|
229
|
-
const a = api.current;
|
|
230
|
-
if (!a)
|
|
231
|
-
throw new Error("Whiteboard is not ready yet.");
|
|
232
|
-
return m.exportToSvg({
|
|
233
|
-
elements: a.getSceneElements(),
|
|
234
|
-
appState: { ...a.getAppState(), exportBackground: background, exportWithDarkMode: dark },
|
|
235
|
-
files: a.getFiles(),
|
|
236
|
-
});
|
|
237
|
-
},
|
|
238
|
-
clear: () => api.current?.resetScene(),
|
|
239
|
-
}), [module, assetPath, dark]);
|
|
240
|
-
// Skeletons (anything without Excalidraw's `version`) become full elements, drawn in the look
|
|
241
|
-
// unless they say otherwise; a saved scene keeps its own style.
|
|
242
|
-
const scene = React.useMemo(() => {
|
|
243
|
-
if (!module || !initialData)
|
|
244
|
-
return null;
|
|
245
|
-
const style = lookOf(look);
|
|
246
|
-
const skeletons = initialData.elements.some((e) => !("version" in e));
|
|
247
|
-
const filled = initialData.elements.map((e) => {
|
|
248
|
-
const el = e;
|
|
249
|
-
return {
|
|
250
|
-
roughness: style.roughness,
|
|
251
|
-
strokeWidth: style.strokeWidth,
|
|
252
|
-
...(el.type === "text" ? { fontFamily: style.fontFamily } : {}),
|
|
253
|
-
...(look === "clean" && (el.type === "rectangle" || el.type === "diamond")
|
|
254
|
-
? { roundness: { type: 3 } }
|
|
255
|
-
: {}),
|
|
256
|
-
...el,
|
|
257
|
-
...(el.label ? { label: { fontFamily: style.fontFamily, ...el.label } } : {}),
|
|
258
|
-
};
|
|
259
|
-
});
|
|
260
|
-
return {
|
|
261
|
-
...initialData,
|
|
262
|
-
elements: skeletons
|
|
263
|
-
? module.convertToExcalidrawElements(filled, { regenerateIds: false })
|
|
264
|
-
: initialData.elements,
|
|
265
|
-
};
|
|
266
|
-
}, [module, initialData, look]);
|
|
267
|
-
const style = lookOf(look);
|
|
268
|
-
// Read once, when Excalidraw mounts: a stable object, so the editor is not redrawn for it.
|
|
269
|
-
const start = React.useMemo(() => ({
|
|
270
|
-
...scene,
|
|
271
|
-
libraryItems: initialData?.libraryItems,
|
|
272
|
-
appState: {
|
|
273
|
-
viewBackgroundColor: "transparent",
|
|
274
|
-
currentItemRoughness: style.roughness,
|
|
275
|
-
currentItemStrokeWidth: style.strokeWidth,
|
|
276
|
-
currentItemFontFamily: style.fontFamily,
|
|
277
|
-
currentItemRoundness: "round",
|
|
278
|
-
...scene?.appState,
|
|
279
|
-
},
|
|
280
|
-
scrollToContent: true,
|
|
281
|
-
}), [scene]);
|
|
282
|
-
const topRight = React.useCallback(() => readOnly ? null : (_jsxs(Button, { variant: "secondary", size: "sm", "data-slot": "whiteboard-library-trigger", "aria-expanded": panel === "library", onClick: () => setPanel((p) => (p === "library" ? null : "library")), children: [_jsx(LibraryBigIcon, {}), "Library"] })), [panel, readOnly]);
|
|
283
|
-
const Draw = module?.Excalidraw;
|
|
284
|
-
const Menu = module?.MainMenu;
|
|
285
|
-
const Welcome = module?.WelcomeScreen;
|
|
286
|
-
return (_jsxs("div", { ref: frame, "data-slot": "whiteboard", "data-state": module ? "ready" : failed ? "error" : "loading", "aria-busy": !module && !failed ? true : undefined, className: cn("relative h-[min(40rem,80svh)] w-full overflow-hidden", variant === "card" ? "surface-card [--card-padding:0]" : "surface-container", className), ...props, children: [Draw && Menu && Welcome ? (_jsxs(Draw, { excalidrawAPI: (a) => {
|
|
287
|
-
api.current = a;
|
|
288
|
-
}, initialData: start, onChange: handleChange, onLibraryChange: handleLibraryChange, renderTopRightUI: topRight, theme: dark ? "dark" : "light", viewModeEnabled: readOnly, gridModeEnabled: grid, name: name, aiEnabled: false, UIOptions: { canvasActions: { toggleTheme: false } }, children: [_jsxs(Menu, { children: [_jsx(Menu.DefaultItems.LoadScene, {}), _jsx(Menu.DefaultItems.Export, {}), _jsx(Menu.DefaultItems.SaveAsImage, {}), _jsx(Menu.Item, { icon: _jsx(SearchIcon, {}), shortcut: `${mod}+F`, onSelect: () => setPanel("search"), children: "Find on canvas" }), _jsx(Menu.DefaultItems.Help, {}), _jsx(Menu.DefaultItems.ClearCanvas, {}), _jsx(Menu.Separator, {}), _jsx(Menu.DefaultItems.ChangeCanvasBackground, {})] }), _jsx(Welcome, { children: _jsxs(Welcome.Center, { children: [_jsx(Welcome.Center.Heading, { children: "Draw, sketch and think out loud." }), _jsx("p", { className: "m-0 font-mono text-[11px] tracking-[0.04em] text-muted-foreground uppercase", children: "Pick a tool above \u00B7 press ? for shortcuts" })] }) })] })) : failed ? (_jsx("p", { className: "absolute inset-0 m-0 grid place-items-center p-6 text-center text-sm text-muted-foreground", children: "The whiteboard could not load. Check that @excalidraw/excalidraw is installed." })) : (_jsxs("div", { className: "absolute inset-0 flex flex-col gap-3 p-4", children: [_jsx("span", { className: "sr-only", children: "Loading the whiteboard" }), _jsx(Skeleton, { className: "h-11 w-80 max-w-full self-center" }), _jsx(Skeleton, { className: "w-full flex-1" })] })), module && panel === "search" && _jsx(FindPanel, { api: api.current, tick: tick, onClose: close }), module && panel === "library" && (_jsx(LibraryPanel, { module: module, items: items, dark: dark, canKeep: selection > 0, onKeep: keepSelection, onPlace: place, onForget: forget, onClose: close }))] }));
|
|
289
|
-
}
|
|
290
|
-
/** The platform's modifier, as shortcuts are written on it. */
|
|
291
|
-
const mod = modKey();
|
|
292
|
-
/** A panel floating at the right of the canvas: the menu material at 12px. */
|
|
293
|
-
function Panel({ label, onClose, children, }) {
|
|
294
|
-
return (_jsx("div", { role: "dialog", "aria-label": label, "data-slot": "whiteboard-panel", className: "absolute top-16 right-4 z-10 flex max-h-[calc(100%-8.5rem)] w-72 max-w-[calc(100%-2rem)] flex-col rounded-button material-menu", onKeyDown: (event) => {
|
|
295
|
-
if (event.key !== "Escape")
|
|
296
|
-
return;
|
|
297
|
-
event.stopPropagation();
|
|
298
|
-
onClose();
|
|
299
|
-
}, children: children }));
|
|
300
|
-
}
|
|
301
|
-
const eyebrow = "font-mono text-[11px] tracking-[0.04em] text-muted-foreground uppercase";
|
|
302
|
-
/** Find on canvas: every text that holds the query, as a list to step through. */
|
|
303
|
-
function FindPanel({ api, tick, onClose, }) {
|
|
304
|
-
const [query, setQuery] = React.useState("");
|
|
305
|
-
const [active, setActive] = React.useState(0);
|
|
306
|
-
const input = React.useRef(null);
|
|
307
|
-
const matches = React.useMemo(() => {
|
|
308
|
-
const q = query.trim().toLowerCase();
|
|
309
|
-
if (!q || !api)
|
|
310
|
-
return [];
|
|
311
|
-
const found = [];
|
|
312
|
-
for (const e of api.getSceneElements()) {
|
|
313
|
-
if (e.type !== "text" || e.isDeleted)
|
|
314
|
-
continue;
|
|
315
|
-
const text = e.text.replace(/\s+/g, " ");
|
|
316
|
-
const at = text.toLowerCase().indexOf(q);
|
|
317
|
-
if (at < 0)
|
|
318
|
-
continue;
|
|
319
|
-
found.push({
|
|
320
|
-
element: e,
|
|
321
|
-
before: (at > 24 ? "…" : "") + text.slice(Math.max(0, at - 24), at),
|
|
322
|
-
hit: text.slice(at, at + q.length),
|
|
323
|
-
after: text.slice(at + q.length, at + q.length + 40),
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
return found;
|
|
327
|
-
}, [api, query, tick]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
328
|
-
const show = (i) => {
|
|
329
|
-
const match = matches[i];
|
|
330
|
-
if (!api || !match)
|
|
331
|
-
return;
|
|
332
|
-
setActive(i);
|
|
333
|
-
const all = api.getSceneElements();
|
|
334
|
-
const target = (match.element.containerId && all.find((e) => e.id === match.element.containerId)) || match.element;
|
|
335
|
-
api.scrollToContent(target, { animate: true, duration: 300 });
|
|
336
|
-
api.updateScene({ appState: { selectedElementIds: { [target.id]: true } } });
|
|
337
|
-
};
|
|
338
|
-
React.useEffect(() => setActive(0), [query]);
|
|
339
|
-
return (_jsxs(Panel, { label: "Find on canvas", onClose: onClose, children: [_jsx("div", { className: "p-2", children: _jsxs(InputGroup, { children: [_jsx(InputGroupAddon, { children: _jsx(SearchIcon, {}) }), _jsx(InputGroupInput, { ref: input, autoFocus: true, "aria-label": "Find on canvas", placeholder: "Find on canvas", value: query, onChange: (event) => setQuery(event.currentTarget.value), onKeyDown: (event) => {
|
|
340
|
-
// ⌘F (Ctrl+F off a Mac) again selects the query rather than opening the browser's
|
|
341
|
-
// find; a Mac's Ctrl+F moves the caret, as in any text field.
|
|
342
|
-
if (modPressed(event) && event.key.toLowerCase() === "f") {
|
|
343
|
-
event.preventDefault();
|
|
344
|
-
input.current?.select();
|
|
345
|
-
}
|
|
346
|
-
// Enter steps to the next match, Shift+Enter to the one before.
|
|
347
|
-
if (event.key === "Enter" && matches.length) {
|
|
348
|
-
event.preventDefault();
|
|
349
|
-
show((active + (event.shiftKey ? matches.length - 1 : 1)) % matches.length);
|
|
350
|
-
}
|
|
351
|
-
} }), _jsx(InputGroupAddon, { align: "inline-end", children: _jsx(InputGroupButton, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: onClose, children: _jsx(XIcon, {}) }) })] }) }), query.trim() && (_jsxs(_Fragment, { children: [_jsx("p", { "aria-live": "polite", className: cn(eyebrow, "m-0 px-4 pt-1 pb-2"), children: matches.length === 0
|
|
352
|
-
? "No matches"
|
|
353
|
-
: `${matches.length} ${matches.length === 1 ? "match" : "matches"}` }), matches.length > 0 && (_jsx("ul", { className: "m-0 min-h-0 flex-1 list-none overflow-y-auto p-1 pt-0", children: matches.map((m, i) => (_jsx("li", { children: _jsx("button", { type: "button", "data-current": i === active ? "" : undefined, className: "flex w-full cursor-pointer rounded-item material-row px-3 py-2 text-left text-[13px] leading-snug focus-ring", onClick: () => show(i), children: _jsxs("span", { className: "min-w-0 truncate", children: [m.before, _jsx("mark", { className: "rounded-checkbox bg-control-hover text-foreground", children: m.hit }), m.after] }) }) }, m.element.id))) }))] }))] }));
|
|
354
|
-
}
|
|
355
|
-
/** The library: shapes kept to place again — click one to place it, or drag it onto the canvas. */
|
|
356
|
-
function LibraryPanel({ module, items, dark, canKeep, onKeep, onPlace, onForget, onClose, }) {
|
|
357
|
-
return (_jsxs(Panel, { label: "Library", onClose: onClose, children: [_jsxs("div", { className: "flex items-center gap-2 py-2 pr-2 pl-4", children: [_jsxs("span", { className: cn(eyebrow, "flex-1"), children: ["Library \u00B7 ", items.length] }), _jsxs(Button, { variant: "secondary", size: "sm", disabled: !canKeep, onClick: onKeep, children: [_jsx(PlusIcon, {}), "Add selection"] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", autoFocus: true, onClick: onClose, children: _jsx(XIcon, {}) })] }), _jsx("div", { className: "h-px bg-border/60" }), items.length === 0 ? (_jsx("p", { className: "m-0 px-4 py-6 text-center text-[13px] leading-relaxed text-muted-foreground", children: "Select shapes and add them here to place them again." })) : (_jsx("ul", { className: "m-0 grid min-h-0 flex-1 list-none grid-cols-3 gap-2 overflow-y-auto p-3", children: items.map((item, i) => (_jsxs("li", { className: "group relative", children: [_jsx("button", { type: "button", draggable: true, "aria-label": item.name || `Library shape ${i + 1}`, className: "block aspect-square w-full material-field cursor-grab overflow-hidden rounded-(--radius-control) p-2 focus-ring", onClick: () => onPlace(item), onDragStart: (event) => {
|
|
358
|
-
event.dataTransfer.setData(module.MIME_TYPES.excalidrawlib, module.serializeLibraryAsJSON([item]));
|
|
359
|
-
event.dataTransfer.effectAllowed = "copy";
|
|
360
|
-
}, children: _jsx(Preview, { module: module, item: item, dark: dark }) }), _jsx("button", { type: "button", "aria-label": "Remove from library", className: "absolute top-1 right-1 grid size-5 cursor-pointer place-items-center rounded-full material-raised opacity-0 focus-ring group-focus-within:opacity-100 group-hover:opacity-100", onClick: () => onForget(item.id), children: _jsx(XIcon, { className: "size-3" }) })] }, item.id))) }))] }));
|
|
361
|
-
}
|
|
362
|
-
/** A library item drawn small, as it will look on the canvas. */
|
|
363
|
-
function Preview({ module, item, dark }) {
|
|
364
|
-
const box = React.useRef(null);
|
|
365
|
-
React.useEffect(() => {
|
|
366
|
-
let alive = true;
|
|
367
|
-
void module
|
|
368
|
-
.exportToSvg({
|
|
369
|
-
elements: item.elements,
|
|
370
|
-
appState: { exportBackground: false, exportWithDarkMode: dark, viewBackgroundColor: "transparent" },
|
|
371
|
-
files: null,
|
|
372
|
-
exportPadding: 4,
|
|
373
|
-
})
|
|
374
|
-
.then((svg) => {
|
|
375
|
-
if (!alive || !box.current)
|
|
376
|
-
return;
|
|
377
|
-
svg.removeAttribute("width");
|
|
378
|
-
svg.removeAttribute("height");
|
|
379
|
-
svg.setAttribute("aria-hidden", "true");
|
|
380
|
-
svg.style.width = "100%";
|
|
381
|
-
svg.style.height = "100%";
|
|
382
|
-
box.current.replaceChildren(svg);
|
|
383
|
-
});
|
|
384
|
-
return () => {
|
|
385
|
-
alive = false;
|
|
386
|
-
};
|
|
387
|
-
}, [module, item, dark]);
|
|
388
|
-
return _jsx("span", { ref: box, className: "pointer-events-none block size-full" });
|
|
389
|
-
}
|