@pixerate/editor-react 0.101.0 → 0.102.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.
@@ -5,10 +5,11 @@ import {
5
5
  } from "./chunk-GNO54NFG.js";
6
6
 
7
7
  // src/spreadsheet/useSpreadsheetEditor.ts
8
- import { useState, useRef, useCallback, useMemo } from "react";
8
+ import { useState, useRef, useCallback, useMemo, useEffect } from "react";
9
9
  import {
10
10
  SpreadsheetController,
11
- bindSpreadsheetTableActions
11
+ bindSpreadsheetTableActions,
12
+ createSpreadsheetEditorDocument
12
13
  } from "@pixerate/editor/spreadsheet";
13
14
  function useSpreadsheetEditor(options = {}) {
14
15
  const optionsRef = useRef(options);
@@ -183,6 +184,8 @@ function useSpreadsheetEditor(options = {}) {
183
184
  [controller, afterSheetSwitch]
184
185
  );
185
186
  const conditionalFormatOverlay = useMemo(() => controller.getConditionalFormatOverlay(), [controller, doc]);
187
+ const editorDocument = useMemo(() => createSpreadsheetEditorDocument(controller), [controller]);
188
+ useEffect(() => () => editorDocument.destroy(), [editorDocument]);
186
189
  return {
187
190
  document: doc,
188
191
  activeCell,
@@ -194,6 +197,8 @@ function useSpreadsheetEditor(options = {}) {
194
197
  resolveValidationPrompt,
195
198
  commitCellInput,
196
199
  controller,
200
+ /** The save / load / undo contract (for `useEditorAutosave` or `createDocumentToolProvider`). */
201
+ editorDocument,
197
202
  getCell: (rowId, colId) => controller.getCell(rowId, colId),
198
203
  setCellValue,
199
204
  selectCell,
@@ -244,7 +249,7 @@ function useSpreadsheetEditor(options = {}) {
244
249
  }
245
250
 
246
251
  // src/spreadsheet/SpreadsheetEditor.tsx
247
- import { useRef as useRef8, useState as useState8, useMemo as useMemo5, useEffect as useEffect6, useCallback as useCallback4 } from "react";
252
+ import { useRef as useRef8, useState as useState8, useMemo as useMemo5, useEffect as useEffect7, useCallback as useCallback4 } from "react";
248
253
  import {
249
254
  indexToColName,
250
255
  getSpreadsheetMenuItems,
@@ -259,7 +264,7 @@ import {
259
264
  } from "@pixerate/editor/spreadsheet";
260
265
 
261
266
  // src/spreadsheet/SpreadsheetContextMenu.tsx
262
- import React, { useEffect, useLayoutEffect, useRef as useRef2, useState as useState2 } from "react";
267
+ import React, { useEffect as useEffect2, useLayoutEffect, useRef as useRef2, useState as useState2 } from "react";
263
268
  import { clampMenuPosition, runSpreadsheetMenuItem } from "@pixerate/editor/spreadsheet";
264
269
  import { jsx, jsxs } from "react/jsx-runtime";
265
270
  var VIEWPORT_MARGIN = 4;
@@ -280,7 +285,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
280
285
  );
281
286
  setPosition((prev) => prev.x === next.x && prev.y === next.y ? prev : next);
282
287
  }, [x, y, items]);
283
- useEffect(() => {
288
+ useEffect2(() => {
284
289
  const handlePointer = (e) => {
285
290
  if (!menuRef.current?.contains(e.target)) onCloseRef.current();
286
291
  };
@@ -389,7 +394,7 @@ var SpreadsheetGroupRow = ({
389
394
  };
390
395
 
391
396
  // src/spreadsheet/useSpreadsheetTableInteractions.ts
392
- import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef3, useState as useState3 } from "react";
397
+ import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
393
398
  import {
394
399
  computeFillTarget,
395
400
  normalizeRange
@@ -406,7 +411,7 @@ function useSpreadsheetClipboard(gridRef, state, readOnly) {
406
411
  const readOnlyRef = useRef3(readOnly);
407
412
  readOnlyRef.current = readOnly;
408
413
  const copiedRef = useRef3(false);
409
- useEffect2(() => {
414
+ useEffect3(() => {
410
415
  if (typeof document === "undefined") return;
411
416
  const handleCopy = (e) => {
412
417
  const s = stateRef.current;
@@ -447,7 +452,7 @@ function useFillHandle(state) {
447
452
  const stateRef = useRef3(state);
448
453
  stateRef.current = state;
449
454
  const dragging = drag !== null;
450
- useEffect2(() => {
455
+ useEffect3(() => {
451
456
  if (!dragging) return;
452
457
  const handleMouseUp = () => {
453
458
  const current = dragRef.current;
@@ -472,12 +477,12 @@ function useFillHandle(state) {
472
477
  }
473
478
 
474
479
  // src/spreadsheet/SpreadsheetValidationDialog.tsx
475
- import { useEffect as useEffect3, useRef as useRef4 } from "react";
480
+ import { useEffect as useEffect4, useRef as useRef4 } from "react";
476
481
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
477
482
  var SpreadsheetValidationDialog = ({ prompt, onResolve }) => {
478
483
  const style = prompt.result.errorStyle ?? "stop";
479
484
  const firstButton = useRef4(null);
480
- useEffect3(() => {
485
+ useEffect4(() => {
481
486
  firstButton.current?.focus();
482
487
  }, [prompt]);
483
488
  const buttons = style === "stop" ? [
@@ -788,7 +793,7 @@ var SpreadsheetDataValidationPanel = ({ state, onClose }) => {
788
793
  };
789
794
 
790
795
  // src/spreadsheet/useSpreadsheetViewport.ts
791
- import { useCallback as useCallback3, useEffect as useEffect4, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useRef as useRef5, useState as useState5 } from "react";
796
+ import { useCallback as useCallback3, useEffect as useEffect5, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useRef as useRef5, useState as useState5 } from "react";
792
797
  import {
793
798
  fullSpreadsheetViewWindow,
794
799
  getSpreadsheetScrollToCell,
@@ -797,7 +802,7 @@ import {
797
802
  sameSpreadsheetViewWindow,
798
803
  shouldVirtualizeSpreadsheet
799
804
  } from "@pixerate/editor/spreadsheet";
800
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect2 : useEffect4;
805
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect2 : useEffect5;
801
806
  function useSpreadsheetViewport(scrollRef, view, options = {}) {
802
807
  const metrics = useMemo3(() => measureSpreadsheetView(view), [view]);
803
808
  const virtual = shouldVirtualizeSpreadsheet(view, options.virtualize ?? "auto");
@@ -859,7 +864,7 @@ function useSpreadsheetViewport(scrollRef, view, options = {}) {
859
864
  }
860
865
 
861
866
  // src/spreadsheet/FormulaHints.tsx
862
- import { useEffect as useEffect5, useLayoutEffect as useLayoutEffect3, useMemo as useMemo4, useRef as useRef6, useState as useState6 } from "react";
867
+ import { useEffect as useEffect6, useLayoutEffect as useLayoutEffect3, useMemo as useMemo4, useRef as useRef6, useState as useState6 } from "react";
863
868
  import { applyFormulaSuggestion, getFormulaHints } from "@pixerate/editor/spreadsheet";
864
869
  import { Fragment, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
865
870
  var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
@@ -886,7 +891,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
886
891
  pendingCaret.current = next.caret;
887
892
  commit(next.value);
888
893
  };
889
- useEffect5(() => {
894
+ useEffect6(() => {
890
895
  const input = inputRef.current;
891
896
  if (!input) return;
892
897
  const syncCaret = () => setCaret(input.selectionStart ?? input.value.length);
@@ -1344,7 +1349,7 @@ var SpreadsheetEditor = ({
1344
1349
  const [formulaDraft, setFormulaDraft] = useState8(null);
1345
1350
  const activeColumn = state.activeCell ? state.document.columns[state.activeCell.col] : void 0;
1346
1351
  const formulaBarReadOnly = readOnly || !state.activeCell || !!activeColumn?.readOnly;
1347
- useEffect6(() => {
1352
+ useEffect7(() => {
1348
1353
  setFormulaDraft(null);
1349
1354
  }, [state.activeCell?.row, state.activeCell?.col]);
1350
1355
  const commitFormulaBar = () => {
@@ -1463,7 +1468,7 @@ var SpreadsheetEditor = ({
1463
1468
  const rect = td?.getBoundingClientRect();
1464
1469
  setListMenu({ x: rect ? rect.left : 0, y: rect ? rect.bottom : 0, row, col, values });
1465
1470
  }
1466
- useEffect6(() => {
1471
+ useEffect7(() => {
1467
1472
  if (!listMenu) return;
1468
1473
  const close = (e) => {
1469
1474
  if (!e.target?.closest?.('[aria-label="Allowed values"], .spreadsheet-list-arrow')) setListMenu(null);
@@ -1490,7 +1495,7 @@ var SpreadsheetEditor = ({
1490
1495
  stateRef.current = state;
1491
1496
  const onColumnResizeRef = useRef8(onColumnResize);
1492
1497
  onColumnResizeRef.current = onColumnResize;
1493
- useEffect6(() => {
1498
+ useEffect7(() => {
1494
1499
  if (!resizingColId) return;
1495
1500
  if (typeof document !== "undefined") {
1496
1501
  document.body.style.cursor = "col-resize";
@@ -0,0 +1,8 @@
1
+ import type { Editor, JSONContent } from "@tiptap/core";
2
+ import type { EditorDocument } from "@pixerate/editor/persistence";
3
+ /**
4
+ * The save / load / undo contract for a TipTap editor (kind `rich_text`; see
5
+ * `createRichTextEditorDocument`), for `useEditorAutosave` or `createDocumentToolProvider`.
6
+ * `null` until the editor exists (e.g. the first render of `useEditor`).
7
+ */
8
+ export declare function useRichTextEditorDocument(editor: Editor | null | undefined): EditorDocument<JSONContent> | null;
@@ -0,0 +1,8 @@
1
+ import type { Editor, JSONContent } from "@tiptap/core";
2
+ import type { EditorDocument } from "@pixerate/editor/persistence";
3
+ /**
4
+ * The save / load / undo contract for a TipTap editor (kind `rich_text`; see
5
+ * `createRichTextEditorDocument`), for `useEditorAutosave` or `createDocumentToolProvider`.
6
+ * `null` until the editor exists (e.g. the first render of `useEditor`).
7
+ */
8
+ export declare function useRichTextEditorDocument(editor: Editor | null | undefined): EditorDocument<JSONContent> | null;