@haklex/rich-ext-excalidraw 0.0.82 → 0.0.84

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/dist/index.mjs CHANGED
@@ -1,87 +1,576 @@
1
- import { A as ExcalidrawConfigProvider, j as useExcalidrawConfig, n as parseSnapshot, r as serializeSnapshot } from "./useExcalidrawData-DcXa8vqV.js";
2
- import { r as _defineProperty, t as ExcalidrawDisplayRenderer } from "./ExcalidrawDisplayRenderer-C4fbKYqL.js";
3
- import { a as ExcalidrawSSRRenderer, i as ExcalidrawNode, n as $createExcalidrawNode, r as $isExcalidrawNode, t as EXCALIDRAW_BLOCK_TRANSFORMER } from "./transformer-DxW-N9IJ.js";
4
- import { t as ExcalidrawEditRenderer } from "./ExcalidrawEditRenderer-CSchoC4Y.js";
5
- import { Suspense, createElement, lazy, useEffect } from "react";
6
- import { ViewportGate } from "@haklex/rich-editor-ui";
7
- import { PenTool } from "lucide-react";
8
- import { $getNodeByKey, $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from "lexical";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { c as ExcalidrawNode, s as serializeSnapshot, p as parseSnapshot, u as useExcalidrawConfig, e as useExcalidrawData, f as excalidrawFullscreenPopup, g as excalidrawEditorContainer, h as excalidrawLoading, i as excalidrawError, r as readonlyUIOptions, j as excalidrawEditOverlay, k as excalidrawEditLabel, l as excalidrawConfirmActions, m as excalidrawConfirmBtn, n as excalidrawConfirmBtnDanger, o as excalidrawConfirmBtnPrimary, q as excalidrawDialogHeader, t as excalidrawStatusDot, v as excalidrawDialogTitle, w as excalidrawDialogMeta, x as excalidrawHeaderActions, y as excalidrawActionBarSep, z as excalidrawActionBarBtn, A as excalidrawActionBarUrl, B as excalidrawHeaderClose, C as excalidrawDialogCanvas } from "./ExcalidrawNode-DEcONli3.js";
5
+ import { $, a, E, b, b as b2, d, b as b3 } from "./ExcalidrawNode-DEcONli3.js";
6
+ import { ViewportGate, presentDialog, SegmentedControl, dismissTopDialog } from "@haklex/rich-editor-ui";
7
+ import { $insertNodes, $getNodeByKey, createCommand, COMMAND_PRIORITY_EDITOR } from "lexical";
8
+ import { PenTool, Pencil, Save, Download, Clipboard, X } from "lucide-react";
9
+ import { lazy, createElement, Suspense, useState, useRef, useEffect, useCallback } from "react";
10
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
11
+ import { useColorScheme } from "@haklex/rich-editor";
12
+ import { usePortalTheme } from "@haklex/rich-style-token";
9
13
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
10
- //#region src/ExcalidrawEditNode.ts
11
- var LazyEditRenderer = lazy(() => import("./ExcalidrawEditRenderer-CSchoC4Y.js").then((n) => n.n).then((m) => ({ default: m.ExcalidrawEditRenderer })));
12
- var ExcalidrawEditNode = class ExcalidrawEditNode extends ExcalidrawNode {
13
- static clone(node) {
14
- return new ExcalidrawEditNode(node.__snapshot, node.__key);
15
- }
16
- constructor(snapshot, key) {
17
- super(snapshot, key);
18
- }
19
- static importJSON(serializedNode) {
20
- return new ExcalidrawEditNode(serializedNode.snapshot);
21
- }
22
- decorate(editor, config) {
23
- if (!editor.isEditable()) return super.decorate(editor, config);
24
- const nodeKey = this.__key;
25
- const fallback = createElement("div", {
26
- className: "rich-excalidraw-loading",
27
- style: {
28
- position: "relative",
29
- width: "100%",
30
- aspectRatio: "16 / 10",
31
- margin: "1rem 0"
32
- }
33
- });
34
- return createElement(ViewportGate, {
35
- fallback,
36
- children: createElement(Suspense, { fallback }, createElement(LazyEditRenderer, {
37
- snapshot: parseSnapshot(this.__snapshot),
38
- onSnapshotChange: (snapshot) => {
39
- editor.update(() => {
40
- const node = $getNodeByKey(nodeKey);
41
- if (node) node.setSnapshot(serializeSnapshot(snapshot));
42
- });
43
- }
44
- }))
45
- });
46
- }
14
+ import { EXCALIDRAW_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
15
+ const LazyEditRenderer = lazy(
16
+ () => Promise.resolve().then(() => ExcalidrawEditRenderer$1).then((m) => ({
17
+ default: m.ExcalidrawEditRenderer
18
+ }))
19
+ );
20
+ const _ExcalidrawEditNode = class _ExcalidrawEditNode extends ExcalidrawNode {
21
+ static clone(node) {
22
+ return new _ExcalidrawEditNode(node.__snapshot, node.__key);
23
+ }
24
+ constructor(snapshot, key) {
25
+ super(snapshot, key);
26
+ }
27
+ static importJSON(serializedNode) {
28
+ return new _ExcalidrawEditNode(serializedNode.snapshot);
29
+ }
30
+ decorate(editor, config) {
31
+ const isEditable = editor.isEditable();
32
+ if (!isEditable) {
33
+ return super.decorate(editor, config);
34
+ }
35
+ const nodeKey = this.__key;
36
+ const fallback = createElement("div", {
37
+ className: "rich-excalidraw-loading",
38
+ style: {
39
+ position: "relative",
40
+ width: "100%",
41
+ aspectRatio: "16 / 10",
42
+ margin: "1rem 0"
43
+ }
44
+ });
45
+ return createElement(ViewportGate, {
46
+ fallback,
47
+ children: createElement(
48
+ Suspense,
49
+ { fallback },
50
+ createElement(LazyEditRenderer, {
51
+ snapshot: parseSnapshot(this.__snapshot),
52
+ onSnapshotChange: (snapshot) => {
53
+ editor.update(() => {
54
+ const node = $getNodeByKey(nodeKey);
55
+ if (node) {
56
+ node.setSnapshot(serializeSnapshot(snapshot));
57
+ }
58
+ });
59
+ }
60
+ })
61
+ )
62
+ });
63
+ }
47
64
  };
48
- _defineProperty(ExcalidrawEditNode, "commandItems", [{
49
- title: "Whiteboard",
50
- icon: createElement(PenTool, { size: 20 }),
51
- description: "Excalidraw whiteboard canvas",
52
- keywords: [
53
- "excalidraw",
54
- "whiteboard",
55
- "draw",
56
- "canvas"
57
- ],
58
- section: "MEDIA",
59
- placement: ["slash", "toolbar"],
60
- group: "insert",
61
- onSelect: (editor) => {
62
- editor.update(() => {
63
- $insertNodes([$createExcalidrawEditNode("{}")]);
64
- });
65
- }
66
- }]);
65
+ __publicField(_ExcalidrawEditNode, "commandItems", [
66
+ {
67
+ title: "Whiteboard",
68
+ icon: createElement(PenTool, { size: 20 }),
69
+ description: "Excalidraw whiteboard canvas",
70
+ keywords: ["excalidraw", "whiteboard", "draw", "canvas"],
71
+ section: "MEDIA",
72
+ placement: ["slash", "toolbar"],
73
+ group: "insert",
74
+ onSelect: (editor) => {
75
+ editor.update(() => {
76
+ $insertNodes([$createExcalidrawEditNode("{}")]);
77
+ });
78
+ }
79
+ }
80
+ ]);
81
+ let ExcalidrawEditNode = _ExcalidrawEditNode;
67
82
  function $createExcalidrawEditNode(snapshot) {
68
- return new ExcalidrawEditNode(snapshot);
83
+ return new ExcalidrawEditNode(snapshot);
69
84
  }
70
85
  function $isExcalidrawEditNode(node) {
71
- return node instanceof ExcalidrawEditNode;
86
+ return node instanceof ExcalidrawEditNode;
72
87
  }
73
- //#endregion
74
- //#region src/ExcalidrawPlugin.tsx
75
- var INSERT_EXCALIDRAW_COMMAND = createCommand("INSERT_EXCALIDRAW");
88
+ const SAVE_DEBOUNCE_MS = 2e3;
89
+ const ExcalidrawEditorDialogContent = ({
90
+ dismiss,
91
+ ExcalidrawComponent,
92
+ initialData,
93
+ initialSnapshot,
94
+ theme,
95
+ onSave,
96
+ saveSnapshot,
97
+ onClose,
98
+ baseRef,
99
+ baseData
100
+ }) => {
101
+ const { className: portalClassName } = usePortalTheme();
102
+ const apiRef = useRef(null);
103
+ const saveTimerRef = useRef(void 0);
104
+ const [isDirty, setIsDirty] = useState(false);
105
+ const isDirtyRef = useRef(false);
106
+ const confirmDialogOpenRef = useRef(false);
107
+ const initializedRef = useRef(false);
108
+ const baseRefRef = useRef(baseRef);
109
+ const baseDataRef = useRef(baseData);
110
+ const [storageMode, setStorageMode] = useState(() => {
111
+ if (!saveSnapshot || !initialSnapshot) return "inline";
112
+ return initialSnapshot.type === "delta" ? "delta" : initialSnapshot.type === "remote" ? "remote" : "inline";
113
+ });
114
+ const storageModeRef = useRef(storageMode);
115
+ const [savedRef, setSavedRef] = useState(() => {
116
+ if (!saveSnapshot || !initialSnapshot) return "";
117
+ if (initialSnapshot.type === "remote") return initialSnapshot.url;
118
+ if (initialSnapshot.type === "delta") return initialSnapshot.baseUrl;
119
+ return "";
120
+ });
121
+ const [isSaving, setIsSaving] = useState(false);
122
+ useEffect(() => {
123
+ return () => {
124
+ if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
125
+ };
126
+ }, []);
127
+ const getSnapshot = useCallback(() => {
128
+ const api = apiRef.current;
129
+ if (!api) return;
130
+ const appState = api.getAppState();
131
+ return {
132
+ elements: api.getSceneElements(),
133
+ appState: {
134
+ viewBackgroundColor: appState.viewBackgroundColor,
135
+ gridSize: appState.gridSize
136
+ },
137
+ files: api.getFiles()
138
+ };
139
+ }, []);
140
+ const performSave = useCallback(() => {
141
+ if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
142
+ const doc = getSnapshot();
143
+ if (!doc) return Promise.resolve();
144
+ const mode = storageModeRef.current;
145
+ if (mode === "delta" && saveSnapshot) {
146
+ setIsSaving(true);
147
+ return (async () => {
148
+ try {
149
+ const currentBaseUrl = baseRefRef.current;
150
+ const currentBaseData = baseDataRef.current;
151
+ if (!currentBaseUrl || !currentBaseData) {
152
+ const ref = await saveSnapshot(doc, baseRefRef.current || void 0);
153
+ baseRefRef.current = ref;
154
+ baseDataRef.current = doc;
155
+ setSavedRef(ref);
156
+ }
157
+ isDirtyRef.current = false;
158
+ setIsDirty(false);
159
+ } finally {
160
+ setIsSaving(false);
161
+ }
162
+ })();
163
+ }
164
+ if (mode === "remote" && saveSnapshot) {
165
+ if (baseRefRef.current && baseDataRef.current && JSON.stringify(doc) === JSON.stringify(baseDataRef.current)) {
166
+ isDirtyRef.current = false;
167
+ setIsDirty(false);
168
+ return Promise.resolve();
169
+ }
170
+ setIsSaving(true);
171
+ return saveSnapshot(doc, baseRefRef.current || void 0).then(
172
+ (ref) => {
173
+ baseRefRef.current = ref;
174
+ baseDataRef.current = doc;
175
+ isDirtyRef.current = false;
176
+ setIsDirty(false);
177
+ setIsSaving(false);
178
+ setSavedRef(ref);
179
+ },
180
+ () => {
181
+ setIsSaving(false);
182
+ }
183
+ );
184
+ }
185
+ isDirtyRef.current = false;
186
+ setIsDirty(false);
187
+ return Promise.resolve();
188
+ }, [saveSnapshot, getSnapshot]);
189
+ const emitSnapshot = useCallback(async () => {
190
+ const doc = getSnapshot();
191
+ if (!doc) return;
192
+ const mode = storageModeRef.current;
193
+ if (mode === "delta" && saveSnapshot) {
194
+ const currentBaseUrl = baseRefRef.current;
195
+ const currentBaseData = baseDataRef.current;
196
+ if (currentBaseUrl && currentBaseData) {
197
+ const { diff } = await import("jsondiffpatch");
198
+ const delta = diff(currentBaseData, structuredClone(doc));
199
+ onSave(
200
+ delta ? { type: "delta", baseUrl: currentBaseUrl, delta } : { type: "remote", url: currentBaseUrl }
201
+ );
202
+ } else {
203
+ const ref = await saveSnapshot(doc, baseRefRef.current || void 0);
204
+ onSave({ type: "remote", url: ref });
205
+ }
206
+ return;
207
+ }
208
+ if (mode === "remote") {
209
+ const ref = baseRefRef.current;
210
+ if (ref) {
211
+ onSave({ type: "remote", url: ref });
212
+ } else if (saveSnapshot) {
213
+ const newRef = await saveSnapshot(doc);
214
+ onSave({ type: "remote", url: newRef });
215
+ }
216
+ return;
217
+ }
218
+ onSave({ type: "inline", data: doc });
219
+ }, [onSave, saveSnapshot, getSnapshot]);
220
+ const handleChange = useCallback(
221
+ (elements) => {
222
+ if (!initializedRef.current) {
223
+ initializedRef.current = true;
224
+ return;
225
+ }
226
+ if (elements.length === 0) return;
227
+ if (!isDirtyRef.current) {
228
+ isDirtyRef.current = true;
229
+ setIsDirty(true);
230
+ }
231
+ if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
232
+ saveTimerRef.current = setTimeout(() => performSave(), SAVE_DEBOUNCE_MS);
233
+ },
234
+ [performSave]
235
+ );
236
+ const handleSaveAndClose = useCallback(() => {
237
+ void performSave().then(async () => {
238
+ await emitSnapshot();
239
+ onClose(getSnapshot());
240
+ dismiss();
241
+ });
242
+ }, [performSave, emitSnapshot, getSnapshot, onClose, dismiss]);
243
+ const handleDiscard = useCallback(() => {
244
+ if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
245
+ dismiss();
246
+ }, [dismiss]);
247
+ const showConfirmDialog = useCallback(() => {
248
+ if (confirmDialogOpenRef.current) return;
249
+ confirmDialogOpenRef.current = true;
250
+ presentDialog({
251
+ title: "Unsaved Changes",
252
+ description: "You have unsaved changes that will be lost if you close now.",
253
+ content: ({ dismiss: dismissConfirm }) => {
254
+ const wrappedDismiss = () => {
255
+ confirmDialogOpenRef.current = false;
256
+ dismissConfirm();
257
+ };
258
+ return /* @__PURE__ */ jsxs("div", { className: excalidrawConfirmActions, children: [
259
+ /* @__PURE__ */ jsx("button", { className: excalidrawConfirmBtn, type: "button", onClick: wrappedDismiss, children: "Continue Editing" }),
260
+ /* @__PURE__ */ jsx(
261
+ "button",
262
+ {
263
+ className: excalidrawConfirmBtnDanger,
264
+ type: "button",
265
+ onClick: () => {
266
+ wrappedDismiss();
267
+ handleDiscard();
268
+ },
269
+ children: "Discard"
270
+ }
271
+ ),
272
+ /* @__PURE__ */ jsx(
273
+ "button",
274
+ {
275
+ className: excalidrawConfirmBtnPrimary,
276
+ type: "button",
277
+ onClick: () => {
278
+ wrappedDismiss();
279
+ handleSaveAndClose();
280
+ },
281
+ children: "Save & Close"
282
+ }
283
+ )
284
+ ] });
285
+ },
286
+ portalClassName,
287
+ theme,
288
+ showCloseButton: false,
289
+ clickOutsideToDismiss: false
290
+ });
291
+ }, [handleDiscard, handleSaveAndClose, portalClassName, theme]);
292
+ const attemptClose = useCallback(() => {
293
+ if (isDirtyRef.current) {
294
+ showConfirmDialog();
295
+ } else {
296
+ void emitSnapshot().then(() => {
297
+ onClose(getSnapshot());
298
+ dismiss();
299
+ });
300
+ }
301
+ }, [dismiss, showConfirmDialog, emitSnapshot, getSnapshot, onClose]);
302
+ useEffect(() => {
303
+ const handleKeyDown = (e) => {
304
+ if (e.key === "Escape") {
305
+ e.preventDefault();
306
+ e.stopImmediatePropagation();
307
+ if (confirmDialogOpenRef.current) {
308
+ confirmDialogOpenRef.current = false;
309
+ dismissTopDialog();
310
+ } else {
311
+ attemptClose();
312
+ }
313
+ }
314
+ };
315
+ document.addEventListener("keydown", handleKeyDown, true);
316
+ return () => document.removeEventListener("keydown", handleKeyDown, true);
317
+ }, [attemptClose]);
318
+ const handleManualUpload = useCallback(() => {
319
+ performSave();
320
+ }, [performSave]);
321
+ const handleExportJson = useCallback(() => {
322
+ const doc = getSnapshot();
323
+ if (!doc) return;
324
+ const blob = new Blob([JSON.stringify(doc, null, 2)], {
325
+ type: "application/json"
326
+ });
327
+ const url = URL.createObjectURL(blob);
328
+ const a2 = document.createElement("a");
329
+ a2.href = url;
330
+ a2.download = "excalidraw-snapshot.json";
331
+ a2.click();
332
+ URL.revokeObjectURL(url);
333
+ }, [getSnapshot]);
334
+ const handleCopyJson = useCallback(() => {
335
+ const doc = getSnapshot();
336
+ if (!doc) return;
337
+ void navigator.clipboard.writeText(JSON.stringify(doc));
338
+ }, [getSnapshot]);
339
+ const handleRefChange = useCallback((e) => {
340
+ const { value } = e.target;
341
+ setSavedRef(value);
342
+ baseRefRef.current = value;
343
+ baseDataRef.current = void 0;
344
+ }, []);
345
+ const handleStorageModeChange = useCallback(
346
+ (newMode) => {
347
+ setStorageMode(newMode);
348
+ storageModeRef.current = newMode;
349
+ if (newMode === "inline") setSavedRef("");
350
+ performSave();
351
+ },
352
+ [performSave]
353
+ );
354
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
355
+ /* @__PURE__ */ jsxs("div", { className: excalidrawDialogHeader, children: [
356
+ /* @__PURE__ */ jsx(
357
+ "span",
358
+ {
359
+ className: excalidrawStatusDot,
360
+ style: { backgroundColor: isDirty ? "#f59e0b" : "#22c55e" }
361
+ }
362
+ ),
363
+ /* @__PURE__ */ jsx("span", { className: excalidrawDialogTitle, children: "Canvas Editor" }),
364
+ /* @__PURE__ */ jsx("span", { className: excalidrawDialogMeta, children: "excalidraw" }),
365
+ /* @__PURE__ */ jsxs("div", { className: excalidrawHeaderActions, children: [
366
+ saveSnapshot && /* @__PURE__ */ jsxs(Fragment, { children: [
367
+ /* @__PURE__ */ jsx(
368
+ SegmentedControl,
369
+ {
370
+ value: storageMode,
371
+ items: [
372
+ { value: "inline", label: "Inline" },
373
+ { value: "remote", label: "Remote" },
374
+ { value: "delta", label: "Delta" }
375
+ ],
376
+ onChange: handleStorageModeChange
377
+ }
378
+ ),
379
+ /* @__PURE__ */ jsx("div", { className: excalidrawActionBarSep }),
380
+ /* @__PURE__ */ jsxs(
381
+ "button",
382
+ {
383
+ className: excalidrawActionBarBtn,
384
+ disabled: isSaving,
385
+ type: "button",
386
+ onClick: handleManualUpload,
387
+ children: [
388
+ /* @__PURE__ */ jsx(Save, { size: 14 }),
389
+ /* @__PURE__ */ jsx("span", { children: isSaving ? "Saving..." : "Save" })
390
+ ]
391
+ }
392
+ ),
393
+ /* @__PURE__ */ jsx("div", { className: excalidrawActionBarSep })
394
+ ] }),
395
+ /* @__PURE__ */ jsxs("button", { className: excalidrawActionBarBtn, type: "button", onClick: handleExportJson, children: [
396
+ /* @__PURE__ */ jsx(Download, { size: 14 }),
397
+ "JSON"
398
+ ] }),
399
+ /* @__PURE__ */ jsxs("button", { className: excalidrawActionBarBtn, type: "button", onClick: handleCopyJson, children: [
400
+ /* @__PURE__ */ jsx(Clipboard, { size: 14 }),
401
+ "Copy"
402
+ ] }),
403
+ storageMode !== "inline" && /* @__PURE__ */ jsxs(Fragment, { children: [
404
+ /* @__PURE__ */ jsx("div", { className: excalidrawActionBarSep }),
405
+ /* @__PURE__ */ jsx(
406
+ "input",
407
+ {
408
+ className: excalidrawActionBarUrl,
409
+ placeholder: "base URL / ref",
410
+ spellCheck: false,
411
+ type: "text",
412
+ value: savedRef,
413
+ onChange: handleRefChange
414
+ }
415
+ )
416
+ ] })
417
+ ] }),
418
+ /* @__PURE__ */ jsx("button", { className: excalidrawHeaderClose, type: "button", onClick: attemptClose, children: /* @__PURE__ */ jsx(X, { size: 18 }) })
419
+ ] }),
420
+ /* @__PURE__ */ jsx("div", { className: excalidrawDialogCanvas, children: /* @__PURE__ */ jsx(
421
+ ExcalidrawComponent,
422
+ {
423
+ initialData,
424
+ theme,
425
+ excalidrawAPI: (api) => {
426
+ apiRef.current = api;
427
+ },
428
+ onChange: handleChange
429
+ }
430
+ ) })
431
+ ] });
432
+ };
433
+ const ExcalidrawEditRenderer = ({
434
+ snapshot,
435
+ onSnapshotChange
436
+ }) => {
437
+ const theme = useColorScheme();
438
+ const { saveSnapshot } = useExcalidrawConfig();
439
+ const {
440
+ snapshot: initialData,
441
+ loading: dataLoading,
442
+ error: dataError,
443
+ baseRef,
444
+ baseData
445
+ } = useExcalidrawData(snapshot);
446
+ const [ExcalidrawComponent, setExcalidrawComponent] = useState(null);
447
+ const [libLoading, setLibLoading] = useState(true);
448
+ const previewApiRef = useRef(null);
449
+ const initialDataRef = useRef(void 0);
450
+ const [previewKey, setPreviewKey] = useState(0);
451
+ const onSnapshotChangeRef = useRef(onSnapshotChange);
452
+ onSnapshotChangeRef.current = onSnapshotChange;
453
+ const saveSnapshotRef = useRef(saveSnapshot);
454
+ saveSnapshotRef.current = saveSnapshot;
455
+ const snapshotRef = useRef(snapshot);
456
+ snapshotRef.current = snapshot;
457
+ const { className: portalClassName } = usePortalTheme();
458
+ useEffect(() => {
459
+ if (initialData && !initialDataRef.current) {
460
+ initialDataRef.current = initialData;
461
+ }
462
+ }, [initialData]);
463
+ useEffect(() => {
464
+ import("@excalidraw/excalidraw").then((mod) => {
465
+ const Comp = mod.Excalidraw || mod.default?.Excalidraw;
466
+ if (Comp) setExcalidrawComponent(() => Comp);
467
+ setLibLoading(false);
468
+ }).catch(() => setLibLoading(false));
469
+ }, []);
470
+ const baseRefRef = useRef(baseRef);
471
+ const baseDataRefOuter = useRef(baseData);
472
+ useEffect(() => {
473
+ if (baseRef) baseRefRef.current = baseRef;
474
+ }, [baseRef]);
475
+ useEffect(() => {
476
+ if (baseData) baseDataRefOuter.current = baseData;
477
+ }, [baseData]);
478
+ const handleOpenEditor = useCallback(() => {
479
+ if (!ExcalidrawComponent || dataLoading) return;
480
+ presentDialog({
481
+ content: ({ dismiss }) => /* @__PURE__ */ jsx(
482
+ ExcalidrawEditorDialogContent,
483
+ {
484
+ ExcalidrawComponent,
485
+ baseData: baseDataRefOuter.current,
486
+ baseRef: baseRefRef.current,
487
+ dismiss,
488
+ initialData: initialDataRef.current,
489
+ initialSnapshot: snapshotRef.current,
490
+ saveSnapshot: saveSnapshotRef.current,
491
+ theme,
492
+ onSave: (ref) => onSnapshotChangeRef.current(ref),
493
+ onClose: (doc) => {
494
+ if (doc) {
495
+ initialDataRef.current = doc;
496
+ setPreviewKey((k) => k + 1);
497
+ }
498
+ }
499
+ }
500
+ ),
501
+ className: excalidrawFullscreenPopup,
502
+ portalClassName,
503
+ theme,
504
+ showCloseButton: false,
505
+ clickOutsideToDismiss: false
506
+ });
507
+ }, [ExcalidrawComponent, dataLoading, theme, portalClassName]);
508
+ const loading = dataLoading || libLoading;
509
+ if (loading || !ExcalidrawComponent) {
510
+ return /* @__PURE__ */ jsx("div", { className: excalidrawEditorContainer, children: /* @__PURE__ */ jsx("div", { className: excalidrawLoading, children: "Loading excalidraw editor..." }) });
511
+ }
512
+ if (dataError) {
513
+ return /* @__PURE__ */ jsx("div", { className: excalidrawEditorContainer, children: /* @__PURE__ */ jsx("div", { className: excalidrawError, children: dataError }) });
514
+ }
515
+ return /* @__PURE__ */ jsxs("div", { className: excalidrawEditorContainer, children: [
516
+ /* @__PURE__ */ jsx(
517
+ ExcalidrawComponent,
518
+ {
519
+ viewModeEnabled: true,
520
+ zenModeEnabled: true,
521
+ UIOptions: readonlyUIOptions,
522
+ initialData: initialDataRef.current,
523
+ theme,
524
+ excalidrawAPI: (api) => {
525
+ previewApiRef.current = api;
526
+ setTimeout(() => api.scrollToContent(), 100);
527
+ }
528
+ },
529
+ previewKey
530
+ ),
531
+ /* @__PURE__ */ jsx("button", { className: excalidrawEditOverlay, type: "button", onClick: handleOpenEditor, children: /* @__PURE__ */ jsxs("span", { className: excalidrawEditLabel, children: [
532
+ /* @__PURE__ */ jsx(Pencil, { size: 16 }),
533
+ "Edit Whiteboard"
534
+ ] }) })
535
+ ] });
536
+ };
537
+ const ExcalidrawEditRenderer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
538
+ __proto__: null,
539
+ ExcalidrawEditRenderer
540
+ }, Symbol.toStringTag, { value: "Module" }));
541
+ const INSERT_EXCALIDRAW_COMMAND = createCommand("INSERT_EXCALIDRAW");
76
542
  function ExcalidrawPlugin() {
77
- const [editor] = useLexicalComposerContext();
78
- useEffect(() => {
79
- return editor.registerCommand(INSERT_EXCALIDRAW_COMMAND, (snapshot) => {
80
- $insertNodes([$createExcalidrawEditNode(snapshot)]);
81
- return true;
82
- }, COMMAND_PRIORITY_EDITOR);
83
- }, [editor]);
84
- return null;
543
+ const [editor] = useLexicalComposerContext();
544
+ useEffect(() => {
545
+ return editor.registerCommand(
546
+ INSERT_EXCALIDRAW_COMMAND,
547
+ (snapshot) => {
548
+ const node = $createExcalidrawEditNode(snapshot);
549
+ $insertNodes([node]);
550
+ return true;
551
+ },
552
+ COMMAND_PRIORITY_EDITOR
553
+ );
554
+ }, [editor]);
555
+ return null;
85
556
  }
86
- //#endregion
87
- export { $createExcalidrawEditNode, $createExcalidrawNode, $isExcalidrawEditNode, $isExcalidrawNode, EXCALIDRAW_BLOCK_TRANSFORMER, ExcalidrawConfigProvider, ExcalidrawDisplayRenderer, ExcalidrawDisplayRenderer as ExcalidrawRenderer, ExcalidrawDisplayRenderer as ExcalidrawStaticRenderer, ExcalidrawEditNode, ExcalidrawEditRenderer, ExcalidrawNode, ExcalidrawPlugin, ExcalidrawSSRRenderer, INSERT_EXCALIDRAW_COMMAND, parseSnapshot, serializeSnapshot, useExcalidrawConfig };
557
+ export {
558
+ $createExcalidrawEditNode,
559
+ $ as $createExcalidrawNode,
560
+ $isExcalidrawEditNode,
561
+ a as $isExcalidrawNode,
562
+ EXCALIDRAW_BLOCK_TRANSFORMER,
563
+ E as ExcalidrawConfigProvider,
564
+ b as ExcalidrawDisplayRenderer,
565
+ ExcalidrawEditNode,
566
+ ExcalidrawEditRenderer,
567
+ ExcalidrawNode,
568
+ ExcalidrawPlugin,
569
+ b2 as ExcalidrawRenderer,
570
+ d as ExcalidrawSSRRenderer,
571
+ b3 as ExcalidrawStaticRenderer,
572
+ INSERT_EXCALIDRAW_COMMAND,
573
+ parseSnapshot,
574
+ serializeSnapshot,
575
+ useExcalidrawConfig
576
+ };