@pixerate/editor-react 0.3.13 → 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/dist/index.cjs +295 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -5
- package/dist/index.d.ts +98 -5
- package/dist/index.js +286 -48
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -31,10 +31,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BubbleMenu: () => BubbleMenu,
|
|
34
|
+
DirtyTracker: () => import_editor7.DirtyTracker,
|
|
34
35
|
EditorContent: () => EditorContent,
|
|
36
|
+
HistoryManager: () => import_editor7.HistoryManager,
|
|
35
37
|
SpreadsheetEditor: () => SpreadsheetEditor,
|
|
36
38
|
TemplateRenderer: () => TemplateRenderer,
|
|
39
|
+
createDirtyTracker: () => import_editor7.createDirtyTracker,
|
|
40
|
+
createHistoryManager: () => import_editor7.createHistoryManager,
|
|
41
|
+
defaultIsEqual: () => import_editor7.defaultIsEqual,
|
|
42
|
+
useDismissGuard: () => useDismissGuard,
|
|
37
43
|
useEditor: () => useEditor2,
|
|
44
|
+
useHistory: () => useHistory,
|
|
45
|
+
useHistoryShortcuts: () => useHistoryShortcuts,
|
|
46
|
+
useNavigationGuard: () => useNavigationGuard,
|
|
38
47
|
usePromptEditor: () => usePromptEditor,
|
|
39
48
|
useSpreadsheetEditor: () => useSpreadsheetEditor
|
|
40
49
|
});
|
|
@@ -263,19 +272,236 @@ function useEditor2(options = {}) {
|
|
|
263
272
|
});
|
|
264
273
|
}
|
|
265
274
|
|
|
275
|
+
// src/hooks/useNavigationGuard.ts
|
|
276
|
+
var import_react4 = require("react");
|
|
277
|
+
function useNavigationGuard({
|
|
278
|
+
isDirty,
|
|
279
|
+
enabled = true,
|
|
280
|
+
onNavigate,
|
|
281
|
+
onBlocked
|
|
282
|
+
}) {
|
|
283
|
+
const [showConfirm, setShowConfirm] = (0, import_react4.useState)(false);
|
|
284
|
+
const [pendingUrl, setPendingUrl] = (0, import_react4.useState)(null);
|
|
285
|
+
const onNavigateRef = (0, import_react4.useRef)(onNavigate);
|
|
286
|
+
onNavigateRef.current = onNavigate;
|
|
287
|
+
const onBlockedRef = (0, import_react4.useRef)(onBlocked);
|
|
288
|
+
onBlockedRef.current = onBlocked;
|
|
289
|
+
(0, import_react4.useEffect)(() => {
|
|
290
|
+
if (typeof window === "undefined") return;
|
|
291
|
+
if (!enabled || !isDirty) return;
|
|
292
|
+
const handleBeforeUnload = (e) => {
|
|
293
|
+
e.preventDefault();
|
|
294
|
+
e.returnValue = "";
|
|
295
|
+
};
|
|
296
|
+
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
297
|
+
return () => {
|
|
298
|
+
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
299
|
+
};
|
|
300
|
+
}, [enabled, isDirty]);
|
|
301
|
+
(0, import_react4.useEffect)(() => {
|
|
302
|
+
if (typeof document === "undefined" || typeof window === "undefined")
|
|
303
|
+
return;
|
|
304
|
+
if (!enabled || !isDirty) return;
|
|
305
|
+
const handleClick = (e) => {
|
|
306
|
+
const target = e.target;
|
|
307
|
+
const anchor = target?.closest?.("a");
|
|
308
|
+
if (!anchor) return;
|
|
309
|
+
if (anchor.target === "_blank") return;
|
|
310
|
+
const isInternal = anchor.host === window.location.host;
|
|
311
|
+
if (!isInternal) return;
|
|
312
|
+
if (anchor.pathname === window.location.pathname && anchor.search === window.location.search) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
e.preventDefault();
|
|
316
|
+
e.stopPropagation();
|
|
317
|
+
const href = anchor.href;
|
|
318
|
+
setPendingUrl(href);
|
|
319
|
+
setShowConfirm(true);
|
|
320
|
+
onBlockedRef.current?.(href);
|
|
321
|
+
};
|
|
322
|
+
document.addEventListener("click", handleClick, { capture: true });
|
|
323
|
+
return () => {
|
|
324
|
+
document.removeEventListener("click", handleClick, { capture: true });
|
|
325
|
+
};
|
|
326
|
+
}, [enabled, isDirty]);
|
|
327
|
+
const confirmLeave = (0, import_react4.useCallback)(() => {
|
|
328
|
+
setShowConfirm(false);
|
|
329
|
+
if (pendingUrl) {
|
|
330
|
+
if (onNavigateRef.current) {
|
|
331
|
+
onNavigateRef.current(pendingUrl);
|
|
332
|
+
} else if (typeof window !== "undefined") {
|
|
333
|
+
window.location.href = pendingUrl;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}, [pendingUrl]);
|
|
337
|
+
const cancelLeave = (0, import_react4.useCallback)(() => {
|
|
338
|
+
setShowConfirm(false);
|
|
339
|
+
setPendingUrl(null);
|
|
340
|
+
}, []);
|
|
341
|
+
return {
|
|
342
|
+
showConfirm,
|
|
343
|
+
setShowConfirm,
|
|
344
|
+
pendingUrl,
|
|
345
|
+
confirmLeave,
|
|
346
|
+
cancelLeave
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/hooks/useDismissGuard.ts
|
|
351
|
+
var import_react5 = require("react");
|
|
352
|
+
function useDismissGuard({
|
|
353
|
+
isDirty,
|
|
354
|
+
enabled = true,
|
|
355
|
+
onDismiss
|
|
356
|
+
}) {
|
|
357
|
+
const [showConfirm, setShowConfirm] = (0, import_react5.useState)(false);
|
|
358
|
+
const onDismissRef = (0, import_react5.useRef)(onDismiss);
|
|
359
|
+
onDismissRef.current = onDismiss;
|
|
360
|
+
const requestDismiss = (0, import_react5.useCallback)(() => {
|
|
361
|
+
if (enabled && isDirty) {
|
|
362
|
+
setShowConfirm(true);
|
|
363
|
+
} else {
|
|
364
|
+
onDismissRef.current?.();
|
|
365
|
+
}
|
|
366
|
+
}, [enabled, isDirty]);
|
|
367
|
+
const confirmDismiss = (0, import_react5.useCallback)(() => {
|
|
368
|
+
setShowConfirm(false);
|
|
369
|
+
onDismissRef.current?.();
|
|
370
|
+
}, []);
|
|
371
|
+
const cancelDismiss = (0, import_react5.useCallback)(() => {
|
|
372
|
+
setShowConfirm(false);
|
|
373
|
+
}, []);
|
|
374
|
+
const handleKeyDown = (0, import_react5.useCallback)(
|
|
375
|
+
(event) => {
|
|
376
|
+
if (event.key === "Escape") {
|
|
377
|
+
if (event.defaultPrevented) return false;
|
|
378
|
+
event.preventDefault();
|
|
379
|
+
requestDismiss();
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
},
|
|
384
|
+
[requestDismiss]
|
|
385
|
+
);
|
|
386
|
+
return {
|
|
387
|
+
showConfirm,
|
|
388
|
+
setShowConfirm,
|
|
389
|
+
requestDismiss,
|
|
390
|
+
confirmDismiss,
|
|
391
|
+
cancelDismiss,
|
|
392
|
+
handleKeyDown
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/hooks/useHistory.ts
|
|
397
|
+
var import_react6 = require("react");
|
|
398
|
+
var import_editor3 = require("@pixerate/editor");
|
|
399
|
+
function useHistory(managerOrOptions) {
|
|
400
|
+
const manager = (0, import_react6.useMemo)(() => {
|
|
401
|
+
if (managerOrOptions instanceof import_editor3.HistoryManager) {
|
|
402
|
+
return managerOrOptions;
|
|
403
|
+
}
|
|
404
|
+
return (0, import_editor3.createHistoryManager)(managerOrOptions);
|
|
405
|
+
}, [managerOrOptions]);
|
|
406
|
+
const state = (0, import_react6.useSyncExternalStore)(
|
|
407
|
+
(0, import_react6.useCallback)(
|
|
408
|
+
(onStoreChange) => manager.subscribe(onStoreChange),
|
|
409
|
+
[manager]
|
|
410
|
+
),
|
|
411
|
+
() => manager.getState(),
|
|
412
|
+
() => manager.getState()
|
|
413
|
+
);
|
|
414
|
+
const undo = (0, import_react6.useCallback)(() => manager.undo(), [manager]);
|
|
415
|
+
const redo = (0, import_react6.useCallback)(() => manager.redo(), [manager]);
|
|
416
|
+
const clear = (0, import_react6.useCallback)(() => manager.clear(), [manager]);
|
|
417
|
+
const execute = (0, import_react6.useCallback)(
|
|
418
|
+
(cmd) => manager.execute(cmd),
|
|
419
|
+
[manager]
|
|
420
|
+
);
|
|
421
|
+
const executeMerged = (0, import_react6.useCallback)(
|
|
422
|
+
(cmd, opts) => manager.executeMerged(cmd, opts),
|
|
423
|
+
[manager]
|
|
424
|
+
);
|
|
425
|
+
const batch = (0, import_react6.useCallback)(
|
|
426
|
+
(name, fn) => manager.batch(name, fn),
|
|
427
|
+
[manager]
|
|
428
|
+
);
|
|
429
|
+
return {
|
|
430
|
+
...state,
|
|
431
|
+
manager,
|
|
432
|
+
undo,
|
|
433
|
+
redo,
|
|
434
|
+
clear,
|
|
435
|
+
execute,
|
|
436
|
+
executeMerged,
|
|
437
|
+
batch
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/hooks/useHistoryShortcuts.ts
|
|
442
|
+
var import_react7 = require("react");
|
|
443
|
+
function useHistoryShortcuts(manager, options = {}) {
|
|
444
|
+
const {
|
|
445
|
+
enabled = true,
|
|
446
|
+
target,
|
|
447
|
+
ignoreEditableElements = true
|
|
448
|
+
} = options;
|
|
449
|
+
(0, import_react7.useEffect)(() => {
|
|
450
|
+
if (!enabled) return;
|
|
451
|
+
const eventTarget = target ?? (typeof window !== "undefined" ? window : null);
|
|
452
|
+
if (!eventTarget) return;
|
|
453
|
+
const handleKeyDown = (event) => {
|
|
454
|
+
const e = event;
|
|
455
|
+
const isMac = typeof navigator !== "undefined" && /Mac|iPod|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
456
|
+
const modifier = isMac ? e.metaKey : e.ctrlKey;
|
|
457
|
+
if (!modifier) return;
|
|
458
|
+
if (ignoreEditableElements && typeof document !== "undefined") {
|
|
459
|
+
const targetEl = e.target || document.activeElement;
|
|
460
|
+
if (targetEl && targetEl.tagName) {
|
|
461
|
+
const tagName = targetEl.tagName.toLowerCase();
|
|
462
|
+
const isInput = tagName === "input" || tagName === "textarea";
|
|
463
|
+
const isContentEditable = targetEl.isContentEditable || targetEl.getAttribute?.("contenteditable") === "true";
|
|
464
|
+
if (isInput || isContentEditable) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const key = e.key.toLowerCase();
|
|
470
|
+
if (key === "z" && !e.shiftKey) {
|
|
471
|
+
if (manager.getState().canUndo) {
|
|
472
|
+
e.preventDefault();
|
|
473
|
+
manager.undo();
|
|
474
|
+
}
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const isRedoKey = key === "z" && e.shiftKey || !isMac && key === "y" && !e.shiftKey;
|
|
478
|
+
if (isRedoKey) {
|
|
479
|
+
if (manager.getState().canRedo) {
|
|
480
|
+
e.preventDefault();
|
|
481
|
+
manager.redo();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
eventTarget.addEventListener("keydown", handleKeyDown);
|
|
486
|
+
return () => {
|
|
487
|
+
eventTarget.removeEventListener("keydown", handleKeyDown);
|
|
488
|
+
};
|
|
489
|
+
}, [manager, enabled, target, ignoreEditableElements]);
|
|
490
|
+
}
|
|
491
|
+
|
|
266
492
|
// src/components/EditorContent.tsx
|
|
267
|
-
var
|
|
493
|
+
var import_react8 = require("@tiptap/react");
|
|
268
494
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
269
495
|
var EditorContent = ({
|
|
270
496
|
className,
|
|
271
497
|
editor,
|
|
272
498
|
...props
|
|
273
499
|
}) => {
|
|
274
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
500
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react8.EditorContent, { editor, ...props }) });
|
|
275
501
|
};
|
|
276
502
|
|
|
277
503
|
// src/components/BubbleMenu.tsx
|
|
278
|
-
var
|
|
504
|
+
var import_react9 = require("react");
|
|
279
505
|
var import_react_dom = require("react-dom");
|
|
280
506
|
var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
|
|
281
507
|
var BubbleMenu = ({
|
|
@@ -287,12 +513,12 @@ var BubbleMenu = ({
|
|
|
287
513
|
pluginKey = "bubbleMenu",
|
|
288
514
|
updateDelay
|
|
289
515
|
}) => {
|
|
290
|
-
const menuEl = (0,
|
|
291
|
-
const [mounted, setMounted] = (0,
|
|
516
|
+
const menuEl = (0, import_react9.useRef)(null);
|
|
517
|
+
const [mounted, setMounted] = (0, import_react9.useState)(false);
|
|
292
518
|
if (!menuEl.current && typeof document !== "undefined") {
|
|
293
519
|
menuEl.current = document.createElement("div");
|
|
294
520
|
}
|
|
295
|
-
(0,
|
|
521
|
+
(0, import_react9.useEffect)(() => {
|
|
296
522
|
if (!editor || !menuEl.current || editor.isDestroyed) {
|
|
297
523
|
return;
|
|
298
524
|
}
|
|
@@ -323,8 +549,8 @@ var BubbleMenu = ({
|
|
|
323
549
|
};
|
|
324
550
|
|
|
325
551
|
// src/components/TemplateRenderer.tsx
|
|
326
|
-
var
|
|
327
|
-
var
|
|
552
|
+
var import_react10 = require("react");
|
|
553
|
+
var import_editor4 = require("@pixerate/editor");
|
|
328
554
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
329
555
|
var TemplateRenderer = ({
|
|
330
556
|
content,
|
|
@@ -335,12 +561,12 @@ var TemplateRenderer = ({
|
|
|
335
561
|
onTemplateClick,
|
|
336
562
|
onVariableClick
|
|
337
563
|
}) => {
|
|
338
|
-
const displayText = (0,
|
|
564
|
+
const displayText = (0, import_react10.useMemo)(() => {
|
|
339
565
|
if (!resolve || templates.length === 0) return content;
|
|
340
|
-
return (0,
|
|
566
|
+
return (0, import_editor4.resolveTemplates)(content, templates);
|
|
341
567
|
}, [content, templates, resolve]);
|
|
342
|
-
const tokens = (0,
|
|
343
|
-
return (0,
|
|
568
|
+
const tokens = (0, import_react10.useMemo)(() => {
|
|
569
|
+
return (0, import_editor4.tokenizePrompt)(displayText);
|
|
344
570
|
}, [displayText]);
|
|
345
571
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, children: tokens.map((token, index) => {
|
|
346
572
|
if (token.type === "template") {
|
|
@@ -391,11 +617,14 @@ var TemplateRenderer = ({
|
|
|
391
617
|
}) });
|
|
392
618
|
};
|
|
393
619
|
|
|
620
|
+
// src/index.ts
|
|
621
|
+
var import_editor7 = require("@pixerate/editor");
|
|
622
|
+
|
|
394
623
|
// src/spreadsheet/useSpreadsheetEditor.ts
|
|
395
|
-
var
|
|
396
|
-
var
|
|
624
|
+
var import_react11 = require("react");
|
|
625
|
+
var import_editor5 = require("@pixerate/editor");
|
|
397
626
|
function useSpreadsheetEditor(options = {}) {
|
|
398
|
-
const [doc, setDoc] = (0,
|
|
627
|
+
const [doc, setDoc] = (0, import_react11.useState)(() => ({
|
|
399
628
|
id: options.document?.id || `sheet_${Date.now()}`,
|
|
400
629
|
name: options.document?.name || "Sheet 1",
|
|
401
630
|
columns: options.document?.columns || [],
|
|
@@ -404,12 +633,12 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
404
633
|
createdAt: options.document?.createdAt || Date.now(),
|
|
405
634
|
updatedAt: options.document?.updatedAt || Date.now()
|
|
406
635
|
}));
|
|
407
|
-
const [activeCell, setActiveCell] = (0,
|
|
408
|
-
const [selectedRange, setSelectedRange] = (0,
|
|
409
|
-
const [editingCell, setEditingCell] = (0,
|
|
410
|
-
const [draftValue, setDraftValue] = (0,
|
|
411
|
-
const controller = (0,
|
|
412
|
-
return new
|
|
636
|
+
const [activeCell, setActiveCell] = (0, import_react11.useState)(null);
|
|
637
|
+
const [selectedRange, setSelectedRange] = (0, import_react11.useState)(null);
|
|
638
|
+
const [editingCell, setEditingCell] = (0, import_react11.useState)(null);
|
|
639
|
+
const [draftValue, setDraftValue] = (0, import_react11.useState)("");
|
|
640
|
+
const controller = (0, import_react11.useMemo)(() => {
|
|
641
|
+
return new import_editor5.SpreadsheetController({
|
|
413
642
|
...options,
|
|
414
643
|
onDocumentChange: (updated) => {
|
|
415
644
|
setDoc({ ...updated });
|
|
@@ -425,82 +654,82 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
425
654
|
}
|
|
426
655
|
});
|
|
427
656
|
}, []);
|
|
428
|
-
const setCellValue = (0,
|
|
657
|
+
const setCellValue = (0, import_react11.useCallback)((rowId, colId, raw) => {
|
|
429
658
|
controller.setCellValue(rowId, colId, raw);
|
|
430
659
|
setDoc({ ...controller.document });
|
|
431
660
|
}, [controller]);
|
|
432
|
-
const selectCell = (0,
|
|
661
|
+
const selectCell = (0, import_react11.useCallback)((row, col, extendSelection = false) => {
|
|
433
662
|
controller.selectCell(row, col, extendSelection);
|
|
434
663
|
setActiveCell(controller.activeCell);
|
|
435
664
|
setSelectedRange(controller.selectedRange);
|
|
436
665
|
}, [controller]);
|
|
437
|
-
const selectRange = (0,
|
|
666
|
+
const selectRange = (0, import_react11.useCallback)((range) => {
|
|
438
667
|
controller.selectRange(range);
|
|
439
668
|
setSelectedRange(controller.selectedRange);
|
|
440
669
|
}, [controller]);
|
|
441
|
-
const startEditing = (0,
|
|
670
|
+
const startEditing = (0, import_react11.useCallback)((row, col, initialVal) => {
|
|
442
671
|
controller.startEditing(row, col, initialVal);
|
|
443
672
|
setActiveCell(controller.activeCell);
|
|
444
673
|
setEditingCell(controller.editingCell);
|
|
445
674
|
setDraftValue(controller.draftValue);
|
|
446
675
|
}, [controller]);
|
|
447
|
-
const commitEditing = (0,
|
|
676
|
+
const commitEditing = (0, import_react11.useCallback)((val) => {
|
|
448
677
|
controller.commitEditing(val);
|
|
449
678
|
setEditingCell(null);
|
|
450
679
|
setDraftValue("");
|
|
451
680
|
setDoc({ ...controller.document });
|
|
452
681
|
}, [controller]);
|
|
453
|
-
const cancelEditing = (0,
|
|
682
|
+
const cancelEditing = (0, import_react11.useCallback)(() => {
|
|
454
683
|
controller.cancelEditing();
|
|
455
684
|
setEditingCell(null);
|
|
456
685
|
setDraftValue("");
|
|
457
686
|
}, [controller]);
|
|
458
|
-
const moveCursor = (0,
|
|
687
|
+
const moveCursor = (0, import_react11.useCallback)((dir, extend = false) => {
|
|
459
688
|
controller.moveCursor(dir, extend);
|
|
460
689
|
setActiveCell(controller.activeCell);
|
|
461
690
|
setSelectedRange(controller.selectedRange);
|
|
462
691
|
}, [controller]);
|
|
463
|
-
const insertColumn = (0,
|
|
692
|
+
const insertColumn = (0, import_react11.useCallback)((index, config) => {
|
|
464
693
|
controller.insertColumn(index, config);
|
|
465
694
|
setDoc({ ...controller.document });
|
|
466
695
|
}, [controller]);
|
|
467
|
-
const deleteColumn = (0,
|
|
696
|
+
const deleteColumn = (0, import_react11.useCallback)((colId) => {
|
|
468
697
|
controller.deleteColumn(colId);
|
|
469
698
|
setDoc({ ...controller.document });
|
|
470
699
|
}, [controller]);
|
|
471
|
-
const insertRow = (0,
|
|
700
|
+
const insertRow = (0, import_react11.useCallback)((index, config) => {
|
|
472
701
|
controller.insertRow(index, config);
|
|
473
702
|
setDoc({ ...controller.document });
|
|
474
703
|
}, [controller]);
|
|
475
|
-
const deleteRow = (0,
|
|
704
|
+
const deleteRow = (0, import_react11.useCallback)((rowId) => {
|
|
476
705
|
controller.deleteRow(rowId);
|
|
477
706
|
setDoc({ ...controller.document });
|
|
478
707
|
}, [controller]);
|
|
479
|
-
const setColumnWidth = (0,
|
|
708
|
+
const setColumnWidth = (0, import_react11.useCallback)((colId, width) => {
|
|
480
709
|
controller.setColumnWidth(colId, width);
|
|
481
710
|
setDoc({ ...controller.document });
|
|
482
711
|
}, [controller]);
|
|
483
|
-
const autoFitColumnWidth = (0,
|
|
712
|
+
const autoFitColumnWidth = (0, import_react11.useCallback)((colId, customWidth) => {
|
|
484
713
|
controller.autoFitColumnWidth(colId, customWidth);
|
|
485
714
|
setDoc({ ...controller.document });
|
|
486
715
|
}, [controller]);
|
|
487
|
-
const registerDataSource = (0,
|
|
716
|
+
const registerDataSource = (0, import_react11.useCallback)((ds) => {
|
|
488
717
|
controller.registerDataSource(ds);
|
|
489
718
|
setDoc({ ...controller.document });
|
|
490
719
|
}, [controller]);
|
|
491
|
-
const setPrimaryDataSource = (0,
|
|
720
|
+
const setPrimaryDataSource = (0, import_react11.useCallback)((id) => {
|
|
492
721
|
controller.setPrimaryDataSource(id);
|
|
493
722
|
setDoc({ ...controller.document });
|
|
494
723
|
}, [controller]);
|
|
495
|
-
const recalculateAll = (0,
|
|
724
|
+
const recalculateAll = (0, import_react11.useCallback)(() => {
|
|
496
725
|
controller.recalculateAll();
|
|
497
726
|
setDoc({ ...controller.document });
|
|
498
727
|
}, [controller]);
|
|
499
|
-
const undo = (0,
|
|
728
|
+
const undo = (0, import_react11.useCallback)(() => {
|
|
500
729
|
controller.undo();
|
|
501
730
|
setDoc({ ...controller.document });
|
|
502
731
|
}, [controller]);
|
|
503
|
-
const redo = (0,
|
|
732
|
+
const redo = (0, import_react11.useCallback)(() => {
|
|
504
733
|
controller.redo();
|
|
505
734
|
setDoc({ ...controller.document });
|
|
506
735
|
}, [controller]);
|
|
@@ -553,8 +782,8 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
553
782
|
}
|
|
554
783
|
|
|
555
784
|
// src/spreadsheet/SpreadsheetEditor.tsx
|
|
556
|
-
var
|
|
557
|
-
var
|
|
785
|
+
var import_react12 = require("react");
|
|
786
|
+
var import_editor6 = require("@pixerate/editor");
|
|
558
787
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
559
788
|
var SpreadsheetEditor = ({
|
|
560
789
|
state: externalState,
|
|
@@ -566,36 +795,36 @@ var SpreadsheetEditor = ({
|
|
|
566
795
|
}) => {
|
|
567
796
|
const defaultState = useSpreadsheetEditor();
|
|
568
797
|
const state = externalState || defaultState;
|
|
569
|
-
const gridRef = (0,
|
|
570
|
-
const [resizingColId, setResizingColId] = (0,
|
|
571
|
-
const [hoveredColId, setHoveredColId] = (0,
|
|
572
|
-
const [resizeStartX, setResizeStartX] = (0,
|
|
573
|
-
const [resizeStartWidth, setResizeStartWidth] = (0,
|
|
574
|
-
const activeRawValue = (0,
|
|
798
|
+
const gridRef = (0, import_react12.useRef)(null);
|
|
799
|
+
const [resizingColId, setResizingColId] = (0, import_react12.useState)(null);
|
|
800
|
+
const [hoveredColId, setHoveredColId] = (0, import_react12.useState)(null);
|
|
801
|
+
const [resizeStartX, setResizeStartX] = (0, import_react12.useState)(0);
|
|
802
|
+
const [resizeStartWidth, setResizeStartWidth] = (0, import_react12.useState)(0);
|
|
803
|
+
const activeRawValue = (0, import_react12.useMemo)(() => {
|
|
575
804
|
if (!state.activeCell) return "";
|
|
576
805
|
const row = state.document.rows[state.activeCell.row];
|
|
577
806
|
const col = state.document.columns[state.activeCell.col];
|
|
578
807
|
if (!row || !col) return "";
|
|
579
808
|
return state.getCell(row.id, col.id).raw;
|
|
580
809
|
}, [state.activeCell, state.document]);
|
|
581
|
-
const coordLabel = (0,
|
|
810
|
+
const coordLabel = (0, import_react12.useMemo)(() => {
|
|
582
811
|
if (!state.activeCell) return "--";
|
|
583
|
-
const colName = (0,
|
|
812
|
+
const colName = (0, import_editor6.indexToColName)(state.activeCell.col);
|
|
584
813
|
return `${colName}${state.activeCell.row + 1}`;
|
|
585
814
|
}, [state.activeCell]);
|
|
586
|
-
const handleCellClick = (0,
|
|
815
|
+
const handleCellClick = (0, import_react12.useCallback)((rIdx, cIdx, e) => {
|
|
587
816
|
if (state.editingCell && (state.editingCell.row !== rIdx || state.editingCell.col !== cIdx)) {
|
|
588
817
|
state.commitEditing();
|
|
589
818
|
}
|
|
590
819
|
state.selectCell(rIdx, cIdx, e.shiftKey);
|
|
591
820
|
}, [state]);
|
|
592
|
-
const handleCellDblClick = (0,
|
|
821
|
+
const handleCellDblClick = (0, import_react12.useCallback)((rIdx, cIdx) => {
|
|
593
822
|
if (readOnly) return;
|
|
594
823
|
const col = state.document.columns[cIdx];
|
|
595
824
|
if (col?.readOnly) return;
|
|
596
825
|
state.startEditing(rIdx, cIdx);
|
|
597
826
|
}, [readOnly, state]);
|
|
598
|
-
const handleKeyDown = (0,
|
|
827
|
+
const handleKeyDown = (0, import_react12.useCallback)((e) => {
|
|
599
828
|
if (state.editingCell) {
|
|
600
829
|
if (e.key === "Enter") {
|
|
601
830
|
e.preventDefault();
|
|
@@ -659,7 +888,7 @@ var SpreadsheetEditor = ({
|
|
|
659
888
|
}
|
|
660
889
|
}
|
|
661
890
|
}, [readOnly, state]);
|
|
662
|
-
(0,
|
|
891
|
+
(0, import_react12.useEffect)(() => {
|
|
663
892
|
if (!resizingColId) return;
|
|
664
893
|
if (typeof document !== "undefined") {
|
|
665
894
|
document.body.style.cursor = "col-resize";
|
|
@@ -713,7 +942,7 @@ var SpreadsheetEditor = ({
|
|
|
713
942
|
window.removeEventListener("mouseup", handleMouseUp);
|
|
714
943
|
};
|
|
715
944
|
}, [resizingColId, resizeStartX, resizeStartWidth, state, onColumnResize]);
|
|
716
|
-
const measureElementContentWidth = (0,
|
|
945
|
+
const measureElementContentWidth = (0, import_react12.useCallback)((el, container) => {
|
|
717
946
|
if (typeof document === "undefined") return 0;
|
|
718
947
|
let maxW = el.scrollWidth || 0;
|
|
719
948
|
const firstChild = el.firstElementChild;
|
|
@@ -761,7 +990,7 @@ var SpreadsheetEditor = ({
|
|
|
761
990
|
}
|
|
762
991
|
return maxW;
|
|
763
992
|
}, []);
|
|
764
|
-
const autoFitColumn = (0,
|
|
993
|
+
const autoFitColumn = (0, import_react12.useCallback)((colId, colIndex) => {
|
|
765
994
|
const col = state.document.columns.find((c) => c.id === colId);
|
|
766
995
|
if (!col) return;
|
|
767
996
|
let calculatedWidth = 0;
|
|
@@ -798,12 +1027,12 @@ var SpreadsheetEditor = ({
|
|
|
798
1027
|
onColumnResize(updatedCol.id, updatedCol.width || 130);
|
|
799
1028
|
}
|
|
800
1029
|
}, [state, measureElementContentWidth, onColumnResize]);
|
|
801
|
-
const handleResizeDblClick = (0,
|
|
1030
|
+
const handleResizeDblClick = (0, import_react12.useCallback)((colId, colIndex, e) => {
|
|
802
1031
|
e.preventDefault();
|
|
803
1032
|
e.stopPropagation();
|
|
804
1033
|
autoFitColumn(colId, colIndex);
|
|
805
1034
|
}, [autoFitColumn]);
|
|
806
|
-
const handleHeaderDblClick = (0,
|
|
1035
|
+
const handleHeaderDblClick = (0, import_react12.useCallback)((colId, colIndex, e) => {
|
|
807
1036
|
const target = e.currentTarget;
|
|
808
1037
|
if (target) {
|
|
809
1038
|
const rect = target.getBoundingClientRect();
|
|
@@ -989,10 +1218,19 @@ var SpreadsheetEditor = ({
|
|
|
989
1218
|
// Annotate the CommonJS export names for ESM import in node:
|
|
990
1219
|
0 && (module.exports = {
|
|
991
1220
|
BubbleMenu,
|
|
1221
|
+
DirtyTracker,
|
|
992
1222
|
EditorContent,
|
|
1223
|
+
HistoryManager,
|
|
993
1224
|
SpreadsheetEditor,
|
|
994
1225
|
TemplateRenderer,
|
|
1226
|
+
createDirtyTracker,
|
|
1227
|
+
createHistoryManager,
|
|
1228
|
+
defaultIsEqual,
|
|
1229
|
+
useDismissGuard,
|
|
995
1230
|
useEditor,
|
|
1231
|
+
useHistory,
|
|
1232
|
+
useHistoryShortcuts,
|
|
1233
|
+
useNavigationGuard,
|
|
996
1234
|
usePromptEditor,
|
|
997
1235
|
useSpreadsheetEditor
|
|
998
1236
|
});
|