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