@fileverse-dev/dsheet 4.1.22 → 4.1.23-stabilise-package-3

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.
Files changed (106) hide show
  1. package/README.md +10 -0
  2. package/dist/editor/components/editor-workbook.d.ts +6 -0
  3. package/dist/editor/components/sidebar/editor-right-sidebar.d.ts +3 -1
  4. package/dist/editor/components/sidebar/sidebar-offsets.d.ts +12 -0
  5. package/dist/editor/components/sidebar/sidebar-offsets.test.d.ts +1 -0
  6. package/dist/editor/contexts/editor-context.d.ts +7 -0
  7. package/dist/editor/hooks/use-editor-data.d.ts +1 -0
  8. package/dist/editor/hooks/use-editor-sync.d.ts +5 -1
  9. package/dist/editor/types.d.ts +54 -1
  10. package/dist/editor/utils/activate-sheet-for-link.d.ts +3 -0
  11. package/dist/editor/utils/active-sheet-keeper.d.ts +21 -0
  12. package/dist/editor/utils/after-update-cell.d.ts +6 -0
  13. package/dist/editor/utils/after-update-cell.test.d.ts +1 -0
  14. package/dist/editor/utils/apply-comment-markers.d.ts +3 -1
  15. package/dist/editor/utils/apply-comment-markers.test.d.ts +1 -0
  16. package/dist/editor/utils/calc-chain-ydoc-update.test.d.ts +1 -0
  17. package/dist/editor/utils/content-change.d.ts +48 -0
  18. package/dist/editor/utils/content-change.test.d.ts +1 -0
  19. package/dist/editor/utils/content-fingerprint.d.ts +37 -0
  20. package/dist/editor/utils/content-fingerprint.test.d.ts +1 -0
  21. package/dist/editor/utils/editor-handle.d.ts +1 -1
  22. package/dist/editor/utils/format-gate.d.ts +27 -0
  23. package/dist/editor/utils/format-gate.test.d.ts +1 -0
  24. package/dist/editor/utils/legacy-on-change.d.ts +20 -0
  25. package/dist/editor/utils/legacy-on-change.test.d.ts +1 -0
  26. package/dist/editor/utils/navigate-to-sheet.d.ts +22 -0
  27. package/dist/editor/utils/patch-plain-celldata.d.ts +19 -0
  28. package/dist/editor/utils/patch-plain-celldata.test.d.ts +1 -0
  29. package/dist/editor/utils/rebuild-indexeddb-store.d.ts +19 -0
  30. package/dist/editor/utils/rebuild-indexeddb-store.failure.test.d.ts +1 -0
  31. package/dist/editor/utils/rebuild-indexeddb-store.test.d.ts +1 -0
  32. package/dist/editor/utils/remote-apply-guard.d.ts +48 -0
  33. package/dist/editor/utils/remote-apply-guard.test.d.ts +1 -0
  34. package/dist/editor/utils/sheet-ydoc-sync-utils.d.ts +13 -4
  35. package/dist/editor/utils/sheet-ydoc-sync-utils.test.d.ts +1 -0
  36. package/dist/editor/utils/structural-edit-formula-sync.test.d.ts +1 -0
  37. package/dist/editor/utils/update-ydoc.d.ts +9 -1
  38. package/dist/editor/utils/wait-for-sync.d.ts +35 -0
  39. package/dist/editor/utils/wait-for-sync.test.d.ts +1 -0
  40. package/dist/{es-S4GKlN-t.js → es-BlDQ6jCL.js} +1 -0
  41. package/dist/{executeStringFunction-CQ922vEp.js → executeStringFunction-D5BTPrXL.js} +10265 -9843
  42. package/dist/formula.js +1 -1
  43. package/dist/{hi-DMMTDTxZ.js → hi-CP0ta0Yk.js} +1 -0
  44. package/dist/{index-DhQTrCQd.js → index-BXNWi7s5.js} +22557 -21465
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.es.js +31 -31
  47. package/dist/persistence-utils-CSKBobX8.js +151 -0
  48. package/dist/persistence-utils.d.ts +2 -0
  49. package/dist/persistence.append.test.d.ts +1 -0
  50. package/dist/persistence.d.ts +13 -0
  51. package/dist/persistence.fingerprint.test.d.ts +1 -0
  52. package/dist/persistence.js +122 -74
  53. package/dist/sheet-engine/core/api/cell.d.ts +20 -1
  54. package/dist/sheet-engine/core/api/remote-apply.test.d.ts +1 -0
  55. package/dist/sheet-engine/core/api/sheet-flowdata-lifecycle.d.ts +1 -0
  56. package/dist/sheet-engine/core/api/sheet-flowdata-lifecycle.test.d.ts +1 -0
  57. package/dist/sheet-engine/core/index.d.ts +1 -1
  58. package/dist/sheet-engine/core/locale/en.d.ts +1 -0
  59. package/dist/sheet-engine/core/locale/es.d.ts +1 -0
  60. package/dist/sheet-engine/core/locale/hi.d.ts +1 -0
  61. package/dist/sheet-engine/core/locale/zh.d.ts +1 -0
  62. package/dist/sheet-engine/core/locale/zh_tw.d.ts +1 -0
  63. package/dist/sheet-engine/core/modules/b6-ydoc-writes.test.d.ts +1 -0
  64. package/dist/sheet-engine/core/modules/border.d.ts +9 -0
  65. package/dist/sheet-engine/core/modules/cell-shift.d.ts +11 -0
  66. package/dist/sheet-engine/core/modules/cell.commit-ydoc.test.d.ts +1 -0
  67. package/dist/sheet-engine/core/modules/dataVerification.d.ts +15 -0
  68. package/dist/sheet-engine/core/modules/engine-hot-spots.test.d.ts +1 -0
  69. package/dist/sheet-engine/core/modules/formula-async-eval.d.ts +5 -0
  70. package/dist/sheet-engine/core/modules/formula-narrowing.test.d.ts +1 -0
  71. package/dist/sheet-engine/core/modules/formula-snapshot-eval.d.ts +2 -0
  72. package/dist/sheet-engine/core/modules/formula-transitive-deps.d.ts +5 -1
  73. package/dist/sheet-engine/core/modules/formula-warmup.d.ts +37 -0
  74. package/dist/sheet-engine/core/modules/formula-warmup.test.d.ts +1 -0
  75. package/dist/sheet-engine/core/modules/formula.d.ts +57 -1
  76. package/dist/sheet-engine/core/modules/formula.dep-graph.test.d.ts +1 -0
  77. package/dist/sheet-engine/core/modules/formula.str-change.test.d.ts +1 -0
  78. package/dist/sheet-engine/core/modules/formula.wide-seed.test.d.ts +1 -0
  79. package/dist/sheet-engine/core/modules/history-calc-chain.d.ts +39 -0
  80. package/dist/sheet-engine/core/modules/history-calc-chain.test.d.ts +1 -0
  81. package/dist/sheet-engine/core/modules/history-grid-size.d.ts +16 -0
  82. package/dist/sheet-engine/core/modules/history-grid-size.test.d.ts +1 -0
  83. package/dist/sheet-engine/core/modules/index.d.ts +3 -2
  84. package/dist/sheet-engine/core/paste/paste-dep-graph.test.d.ts +1 -0
  85. package/dist/sheet-engine/core/paste-helpers/calculate-range-cell-size.d.ts +14 -0
  86. package/dist/sheet-engine/core/paste-helpers/calculate-range-cell-size.test.d.ts +1 -0
  87. package/dist/sheet-engine/core/settings.d.ts +15 -1
  88. package/dist/sheet-engine/core/utils/ydoc-celldata-changes.d.ts +29 -2
  89. package/dist/sheet-engine/react/components/ContextMenu/sheet-tab-menu-items.d.ts +15 -0
  90. package/dist/sheet-engine/react/components/Workbook/api.d.ts +4 -0
  91. package/dist/sheet-engine/react/components/Workbook/denomination-scan.d.ts +16 -0
  92. package/dist/sheet-engine/react/components/Workbook/denomination-scan.test.d.ts +1 -0
  93. package/dist/sheet-engine/react/components/Workbook/index.d.ts +2 -0
  94. package/dist/style.css +1 -1
  95. package/dist/sync-local/SyncManager.d.ts +2 -2
  96. package/dist/sync-local/SyncManager.remote-apply.test.d.ts +1 -0
  97. package/dist/sync-local/types/index.d.ts +2 -1
  98. package/dist/{template-data-list-BYOIK_Nd.js → template-data-list-apgmwRAT.js} +18 -10
  99. package/dist/{use-xlsx-import-impl-xphBNZu3.js → use-xlsx-import-impl-gsG9w9qV.js} +120 -119
  100. package/dist/{xlsx-defined-names-3g5n40BA.js → xlsx-defined-names-dZveijsB.js} +2 -2
  101. package/dist/{xlsx-export-impl-DXyQpmMi.js → xlsx-export-impl-B10lK_L2.js} +4 -4
  102. package/dist/{xlsx-hyperlink-inline-Cl9CbP5N.js → xlsx-hyperlink-inline-BFbPe75M.js} +2 -2
  103. package/dist/{zh-Bv4KIDiJ.js → zh-CmOCFd5t.js} +1 -0
  104. package/dist/{zh_tw-BdpsK45h.js → zh_tw-BqyRw1gX.js} +1 -0
  105. package/package.json +2 -2
  106. package/dist/persistence-utils-BXFajzvq.js +0 -98
package/README.md CHANGED
@@ -86,6 +86,7 @@ function App() {
86
86
  | `isCollaborative` | `boolean` | `false` | Enable collaborative features |
87
87
  | `enableWebrtc` | `boolean` | `true` | Enable WebRTC for P2P collaboration |
88
88
  | `enableIndexeddbSync` | `boolean` | `true` | Enable local IndexedDB persistence |
89
+ | `onIndexedDbError` | `(error: Error) => void` | - | Called when local persistence fails, or when the first read of the local store does not finish within 15 s. The editor continues with the in-memory document; call `rebuildLocalStore()` to recreate the store |
89
90
  | `isTemplateOpen` | `boolean` | - | Template sidebar state |
90
91
  | `selectedTemplate` | `string` | - | Selected template identifier |
91
92
  | `onboardingComplete` | `boolean` | - | Onboarding completion status |
@@ -115,6 +116,15 @@ function App() {
115
116
  | `setInputFetchURLDataBlock` | `Dispatch<SetStateAction<string>>` | URL input state setter |
116
117
  | `setForceSheetRender` | `Dispatch<SetStateAction<number>>` | Force re-render trigger |
117
118
 
119
+ ### Editor handle methods
120
+
121
+ `sheetEditorRef` is a `DSheetEditorHandle`: the workbook instance plus these methods.
122
+
123
+ | Method | Description |
124
+ |--------|-------------|
125
+ | `rebuildLocalStore()` | `Promise<void>`. Deletes this sheet's IndexedDB database and rewrites it from the live document, so local edits are kept. A no-op when read-only or when `enableIndexeddbSync` is off. Rejects if the rebuild fails, the new store does not sync within 15 s, or a refresh or unmount supersedes it. Concurrent calls share one rebuild. |
126
+ | `getContentFingerprint()` | `string \| null`. Changes on every document change, deletes included; compare with `===` only. `null` until local persistence has synced. |
127
+
118
128
  ## Examples
119
129
 
120
130
  ### Read-Only Viewer
@@ -21,6 +21,10 @@ interface EditorWorkbookProps {
21
21
  dsheetId: string;
22
22
  onDuneChartEmbed?: () => void;
23
23
  onSheetCountChange?: (sheetCount: number) => void;
24
+ onCopySheetLink?: (args: {
25
+ sheetId: string;
26
+ sheetName: string;
27
+ }) => void;
24
28
  sidebarActivePanel?: string | null;
25
29
  sidebarPortalRegistry?: SidebarPortalRegistryHandle | null;
26
30
  sidebarPortalRenderers?: Record<string, SidebarPortalRenderer>;
@@ -29,6 +33,8 @@ interface EditorWorkbookProps {
29
33
  onSignInToComment?: () => void;
30
34
  onViewerModeChange?: (mode: 'comment' | 'view') => void;
31
35
  theme?: ThemeKey;
36
+ showToolbar?: boolean;
37
+ showFormulaBar?: boolean;
32
38
  }
33
39
  export declare const EditorWorkbook: React.NamedExoticComponent<EditorWorkbookProps>;
34
40
  export {};
@@ -15,6 +15,8 @@ interface EditorRightSidebarProps {
15
15
  onClose: () => void;
16
16
  /** Read/preview mode hides the toolbar, so the sidebar starts higher. */
17
17
  isReadOnly?: boolean;
18
+ showNavbar?: boolean;
19
+ showToolbar?: boolean;
18
20
  }
19
- export declare const EditorRightSidebar: ({ isOpen, activePanelConfig, onClose, isReadOnly, }: EditorRightSidebarProps) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const EditorRightSidebar: ({ isOpen, activePanelConfig, onClose, isReadOnly, showNavbar, showToolbar, }: EditorRightSidebarProps) => import("react/jsx-runtime").JSX.Element;
20
22
  export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Right sidebar position below the editor chrome. Read/preview mode keeps
3
+ * its existing offsets (the sidebar overlays the toolbar there).
4
+ */
5
+ export declare const getRightSidebarOffsets: ({ isReadOnly, showNavbar, showToolbar, }: {
6
+ isReadOnly?: boolean;
7
+ showNavbar?: boolean;
8
+ showToolbar?: boolean;
9
+ }) => {
10
+ top: string;
11
+ height: string;
12
+ };
@@ -10,6 +10,7 @@ import { UseSmartContractReturn } from '../hooks/use-smart-contract';
10
10
  import { CollaborationProps, CollabState, CollabUser } from '../../sync-local/types';
11
11
  import { Awareness } from 'y-protocols/awareness';
12
12
  import { DSheetContentSnapshot } from '../../persistence';
13
+ import { DSheetContentChange } from '../utils/content-change';
13
14
 
14
15
  import * as Y from 'yjs';
15
16
  export interface EditorContextType {
@@ -20,6 +21,8 @@ export interface EditorContextType {
20
21
  getDocumentTitle?: (dsheetId: string) => Promise<string>;
21
22
  updateDocumentTitle?: (title: string) => void;
22
23
  isAuthorized: boolean;
24
+ /** True once the sheet's meta.format is above what this client supports. */
25
+ formatLocked?: boolean;
23
26
  dataBlockCalcFunction: {
24
27
  [key: string]: {
25
28
  [key: string]: any;
@@ -31,6 +34,7 @@ export interface EditorContextType {
31
34
  };
32
35
  }>>;
33
36
  refreshIndexedDB: () => Promise<void>;
37
+ rebuildLocalStore: () => Promise<void>;
34
38
  sheetEditorRef: React.MutableRefObject<WorkbookInstance | null>;
35
39
  setSheetEditorRef: React.RefCallback<WorkbookInstance>;
36
40
  ydocRef: React.MutableRefObject<Y.Doc | null>;
@@ -39,6 +43,8 @@ export interface EditorContextType {
39
43
  setSheetData: React.Dispatch<React.SetStateAction<Sheet[]>>;
40
44
  currentDataRef: React.MutableRefObject<Sheet[]>;
41
45
  remoteUpdateRef: React.MutableRefObject<boolean>;
46
+ /** True while a peer's structural edit waits to remount the grid. */
47
+ structuralRemountPendingRef: React.MutableRefObject<boolean>;
42
48
  handleChange: (data: Sheet[]) => void;
43
49
  initialiseLiveQueryData: (data: Sheet[]) => void;
44
50
  loading: boolean;
@@ -80,6 +86,7 @@ interface EditorProviderProps {
80
86
  enableIndexeddbSync?: boolean;
81
87
  isReadOnly?: boolean;
82
88
  onContentUpdate?: () => void;
89
+ onContentChange?: (change: DSheetContentChange) => void;
83
90
  onChange?: (data: SheetUpdateData, encodedUpdate?: string) => void;
84
91
  collaboration?: CollaborationProps;
85
92
  externalEditorRef?: React.Ref<DSheetEditorHandle>;
@@ -21,6 +21,7 @@ export declare const useEditorData: (ydocRef: React.MutableRefObject<Y.Doc | nul
21
21
  setSheetData: import('react').Dispatch<import('react').SetStateAction<Sheet[]>>;
22
22
  currentDataRef: import('react').MutableRefObject<Sheet[]>;
23
23
  remoteUpdateRef: import('react').MutableRefObject<boolean>;
24
+ structuralRemountPendingRef: import('react').MutableRefObject<boolean>;
24
25
  isDataLoaded: boolean;
25
26
  setIsDataLoaded: import('react').Dispatch<import('react').SetStateAction<boolean>>;
26
27
  handleChange: (_data: Sheet[]) => void;
@@ -1,13 +1,17 @@
1
1
  import { IndexeddbPersistence } from 'y-indexeddb';
2
2
  import { CollaborationProps } from '../../sync-local/types';
3
+ import { DSheetContentChange } from '../utils/content-change';
3
4
  import * as Y from 'yjs';
4
- export declare const useEditorSync: (dsheetId: string, enableIndexeddbSync?: boolean, isReadOnly?: boolean, portalContent?: string, collaboration?: CollaborationProps, onCollabUpdate?: (fullState: string, updateChunk: string) => void, onIndexedDbError?: (error: Error) => void) => {
5
+ export declare const useEditorSync: (dsheetId: string, enableIndexeddbSync?: boolean, isReadOnly?: boolean, portalContent?: string, collaboration?: CollaborationProps, onRemoteApplied?: (update: Uint8Array) => void, onIndexedDbError?: (error: Error) => void) => {
5
6
  ydocRef: import('react').MutableRefObject<Y.Doc | null>;
6
7
  persistenceRef: import('react').MutableRefObject<IndexeddbPersistence | null>;
7
8
  syncStatus: "error" | "syncing" | "initializing" | "synced";
8
9
  isContentBootstrapReady: boolean;
9
10
  refreshIndexedDB: () => Promise<void>;
11
+ rebuildLocalStore: () => Promise<void>;
10
12
  getContentSnapshot: () => import('../../persistence-utils').DSheetContentSnapshot;
13
+ getContentFingerprint: () => string | null;
14
+ getContentChange: () => DSheetContentChange;
11
15
  mergeContent: (encodedState: string) => import('../../persistence-utils').DSheetContentSnapshot;
12
16
  collabState: import('../..').CollabState;
13
17
  isCollabReady: boolean;
@@ -5,10 +5,13 @@ import { CollaborationProps } from '../sync-local/types';
5
5
  import { CommentsConfig } from './types/comments';
6
6
  import { SmartContractConfig } from './types/smart-contract';
7
7
  import { ApiKeyStorage } from './utils/api-key-storage';
8
+ import { DSheetContentChange } from './utils/content-change';
8
9
  import { ThemeKey } from '../sheet-engine/core/theme';
9
10
  import { DSheetContentSnapshot } from '../persistence';
11
+ import { NavigateToSheetOptions } from './utils/navigate-to-sheet';
10
12
 
11
13
  import * as Y from 'yjs';
14
+ export type { DSheetContentChange } from './utils/content-change';
12
15
  export type { ThemeKey } from '../sheet-engine/core/theme';
13
16
  export type DSheetPermissionMode = 'view' | 'comment' | 'edit';
14
17
  export type { CommentThread, CommentReply, CommentActionParams, CommentsConfig, CommentAnchorMove, } from './types/comments';
@@ -25,12 +28,34 @@ export interface EditorValues {
25
28
  }
26
29
  export type DSheetEditorHandle = WorkbookInstance & {
27
30
  refreshIndexedDB: () => Promise<void>;
31
+ /**
32
+ * Delete this sheet's IndexedDB database and rewrite it from the live
33
+ * document (same Y.Doc, never replaced), so local edits are kept. Resolves
34
+ * once the new store has synced. Resolves as a no-op when the editor is
35
+ * read-only, local persistence is disabled or there is no sheet id. Rejects
36
+ * if the rebuild fails, if the new store does not sync within 15 s, or if a
37
+ * refresh/unmount supersedes it. Concurrent calls share one rebuild.
38
+ *
39
+ * A bootstrap that is still waiting on an unreadable store (the case this
40
+ * heals) is abandoned after 3 s: the rebuild then finishes the bootstrap
41
+ * itself, merging the published content into the document, so the editor
42
+ * leaves "syncing" once the rebuild resolves.
43
+ */
44
+ rebuildLocalStore: () => Promise<void>;
28
45
  terminateSession: () => void;
29
46
  updateCollaboratorName: (name: string) => void;
30
47
  updateSessionTitle: (args: {
31
48
  encryptedTitle: string;
32
49
  documentTitle: string;
33
50
  }) => void;
51
+ navigateToSheet: (sheetId: string, opts?: NavigateToSheetOptions) => Promise<boolean>;
52
+ /**
53
+ * Content fingerprint: base64 state vector + ":" + deleted count. Changes
54
+ * on every change, deletes included; compare with === only. null until
55
+ * y-indexeddb is attached and synced; use fingerprintFromUpdate of the
56
+ * IndexedDB body then.
57
+ */
58
+ getContentFingerprint: () => string | null;
34
59
  };
35
60
  export interface PanelConfig {
36
61
  id: string;
@@ -68,6 +93,13 @@ export interface DsheetProps {
68
93
  setFetchingURLData?: (fetching: boolean) => void;
69
94
  setInputFetchURLDataBlock?: React.Dispatch<React.SetStateAction<string>>;
70
95
  renderNavbar?: (editorValues?: EditorValues) => JSX.Element;
96
+ /** Mount the navbar slot. `renderNavbar` still runs when hidden, so host
97
+ * side effects inside it keep working. Default true. */
98
+ showNavbar?: boolean;
99
+ /** Show the sheet toolbar. Default true. */
100
+ showToolbar?: boolean;
101
+ /** Show the formula bar. Default true. */
102
+ showFormulaBar?: boolean;
71
103
  enableIndexeddbSync?: boolean;
72
104
  dsheetId: string;
73
105
  /**
@@ -75,10 +107,27 @@ export interface DsheetProps {
75
107
  * Unlike `onChange`, this does not build a plain sheet or encode the Y.Doc.
76
108
  */
77
109
  onContentUpdate?: () => void;
110
+ /**
111
+ * Cheap change signal (Stabilize A1): `hasContent`, `userEdited` and the
112
+ * content `fingerprint`, computed without encoding the Y.Doc. At most one
113
+ * call per second (trailing), flushed on pagehide, beforeunload and unmount.
114
+ * Read full state on demand with `editorStateRef.getContentSnapshot()`.
115
+ */
116
+ onContentChange?: (change: DSheetContentChange) => void;
117
+ /**
118
+ * @deprecated Encodes the whole Y.Doc and rebuilds a plain workbook per
119
+ * call. Use `onContentChange` and read full state on demand. Called at most
120
+ * once per second (trailing), flushed only on unload and unmount. The latest
121
+ * `onChange` you pass is the one called, so an inline function is safe: a new
122
+ * identity does not cancel a pending call.
123
+ */
78
124
  onChange?: (updateData: SheetUpdateData, encodedUpdate?: string) => void;
79
125
  collaboration?: CollaborationProps;
80
126
  /** Called when local IndexedDB persistence fails. The editor and durable
81
- * collaboration continue using the in-memory Y.Doc, matching dDoc. */
127
+ * collaboration continue using the in-memory Y.Doc, matching dDoc. Also
128
+ * called when the first read of the local store does not finish within 15 s
129
+ * (the editor then continues without local persistence, and
130
+ * `rebuildLocalStore()` can recreate the store). */
82
131
  onIndexedDbError?: (error: Error) => void;
83
132
  username?: string;
84
133
  portalContent?: string;
@@ -112,6 +161,10 @@ export interface DsheetProps {
112
161
  onDataBlockEvent?: (event: DataBlockEvent) => void;
113
162
  onDuneChartEmbed?: () => void;
114
163
  onSheetCountChange?: (sheetCount: number) => void;
164
+ onCopySheetLink?: (args: {
165
+ sheetId: string;
166
+ sheetName: string;
167
+ }) => void;
115
168
  /** Fires whenever local content-sync status changes. Host apps should gate
116
169
  * collab start/resume on 'synced' — starting before local content is fully
117
170
  * synced is what let the RTC layer bind to a stale doc in the past. */
@@ -0,0 +1,3 @@
1
+ import { Context } from '../../sheet-engine/core';
2
+
3
+ export declare function activateSheetForLink(draft: Context, sheetId: string): void;
@@ -0,0 +1,21 @@
1
+ import { WorkbookInstance } from '../../sheet-engine/react';
2
+
3
+ export type ActiveSheetKeeper = {
4
+ /**
5
+ * Call on every Workbook ref attach. `mountKey` must change whenever the
6
+ * Workbook is remounted (i.e. mirror the Workbook's React `key`).
7
+ */
8
+ onAttach: (workbook: WorkbookInstance | null, mountKey: unknown) => void;
9
+ };
10
+ /**
11
+ * Fortune remounts the Workbook whenever the editor bumps its render key
12
+ * (collab rehydration, template apply, imports), and a fresh mount resets the
13
+ * active sheet to the first visible one. Remember the active sheet across
14
+ * attaches and restore it once per mount, as soon as the new mount has sheets.
15
+ *
16
+ * The restore runs synchronously inside the ref callback (React commit phase).
17
+ * That only enqueues a Workbook state update (same as setState in
18
+ * useLayoutEffect), and it goes through the same setContext path as clicking a
19
+ * sheet tab.
20
+ */
21
+ export declare function createActiveSheetKeeper(): ActiveSheetKeeper;
@@ -50,7 +50,13 @@ interface AfterUpdateCellParams {
50
50
  collabEnabled?: boolean;
51
51
  collabIsOwner?: boolean;
52
52
  remoteUpdateRef?: React.MutableRefObject<boolean>;
53
+ /** True while a peer's structural edit waits to remount the grid. */
54
+ structuralRemountPendingRef?: React.MutableRefObject<boolean>;
53
55
  localUserEditRef?: React.MutableRefObject<boolean>;
56
+ /** Sheet that held the cell at commit time; falls back to the current sheet. */
57
+ sheetId?: string;
58
+ /** The caller writes the cell to Yjs itself (paste and fill batch writes). */
59
+ skipPersist?: boolean;
54
60
  }
55
61
  /** True when data-block formulas (API / smart contract) should run for this edit. */
56
62
  export declare const shouldExecuteDataBlocks: (params: {
@@ -0,0 +1 @@
1
+ export {};
@@ -8,7 +8,9 @@ type CommentData = object | null | undefined;
8
8
  * `null`, so a tiny `{ ps }` object is created in the live view only so the
9
9
  * triangle can render. Row/column drag still owns real cell data.
10
10
  *
11
- * Mutates in place and returns the same array.
11
+ * Updates the given arrays in place and returns them. Sparse celldata entries
12
+ * are replaced with copies, never written into, because they may be Yjs
13
+ * content (see ySheetArrayToPlain).
12
14
  */
13
15
  export declare const applyCommentMarkers: <T>(sheets: T | null | undefined, commentData: CommentData, allowComments: boolean | undefined) => T | null | undefined;
14
16
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import * as Y from 'yjs';
2
+ /**
3
+ * Cheap change signal for hosts (Stabilize A1). Built from the live Y.Doc
4
+ * without encoding it; full state stays available through
5
+ * editorStateRef.getContentSnapshot().
6
+ */
7
+ export type DSheetContentChange = {
8
+ /** Same meaning as dsheets.new `isEmptySheet(...) === false`. */
9
+ hasContent: boolean;
10
+ /** A local user edit has happened since this editor mounted. */
11
+ userEdited: boolean;
12
+ /**
13
+ * base64 state vector + ":" + deleted count. Changes on every change,
14
+ * deletes included; compare with === only. null until y-indexeddb is
15
+ * attached and synced.
16
+ */
17
+ fingerprint: string | null;
18
+ };
19
+ /** Default-workbook seed and legacy migration: content, but not a user edit. */
20
+ export declare const INIT_ORIGIN = "init";
21
+ /** Idle celldata compaction: rewrites storage, not a user edit. */
22
+ export declare const COMPACTION_ORIGIN = "compaction";
23
+ /**
24
+ * Mirrors dsheets.new `isEmptySheet` (components/dsheet-editor/editor-utils.ts):
25
+ * no sheets → empty; more than one sheet → content; otherwise content when
26
+ * sheet 0 has any config key or any celldata entry. Stops at the first live
27
+ * entry, so it does not walk the sheet.
28
+ */
29
+ export declare function computeHasContent(doc: Y.Doc, dsheetId: string): boolean;
30
+ export type UserEditTracker = {
31
+ userEdited(): boolean;
32
+ dispose(): void;
33
+ };
34
+ /**
35
+ * Turns on at the first transaction that changes the document and whose
36
+ * origin is not a known non-user origin or the IndexedDB provider.
37
+ */
38
+ export declare function attachUserEditTracker(doc: Y.Doc, getIndexeddbOrigin: () => unknown): UserEditTracker;
39
+ export declare const CONTENT_CHANGE_WAIT_MS = 1000;
40
+ /**
41
+ * At most one host call per second (trailing only); local and remote changes
42
+ * share the throttle. The change is built when the call fires, never per edit.
43
+ */
44
+ export declare function createContentChangeNotifier(getChange: () => DSheetContentChange, getHandler: () => ((change: DSheetContentChange) => void) | undefined, waitMs?: number): {
45
+ notify: () => void;
46
+ flush: () => void;
47
+ cancel: () => any;
48
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import * as Y from 'yjs';
2
+ /**
3
+ * Cheap "did the document change" signal (Stabilize A1 / D6).
4
+ *
5
+ * fingerprint = base64(state vector) + ":" + deletedCount
6
+ *
7
+ * A state vector alone misses delete-only transactions (clearing a filter,
8
+ * dropdown, conditional format, sub-sheet or named range; undo of a typed
9
+ * value), because a Yjs delete adds no item. deletedCount is the total length
10
+ * of all deleted ranges in the document, kept as a running count so no full
11
+ * scan is needed per check. Compare fingerprints with === only.
12
+ */
13
+ export type ContentFingerprintTracker = {
14
+ getFingerprint(): string;
15
+ getDeletedCount(): number;
16
+ dispose(): void;
17
+ };
18
+ /**
19
+ * Attach when the Y.Doc is created, before any provider writes to it, so the
20
+ * count is built from transactions. Attaching later costs one full scan.
21
+ */
22
+ export declare function attachContentFingerprint(doc: Y.Doc): ContentFingerprintTracker;
23
+ /**
24
+ * Same value as a live tracker, for a stored body or a merge of raw rows.
25
+ * Builds a temporary document and scans its delete set, as getDsheetStateVector
26
+ * builds one. Reading the delete ranges from the encoded update instead
27
+ * (Y.decodeUpdate) misses GC structs that arrive without a delete range, e.g.
28
+ * a row written when the document received a compacted body.
29
+ */
30
+ export declare function fingerprintFromUpdate(update: Uint8Array): string;
31
+ /**
32
+ * Same value as a live tracker, computed from a document by one scan of its
33
+ * delete set (under 1.5 ms at 100k cells). Used by the body reads, which
34
+ * already build a document from every IndexedDB row, so GC structs that
35
+ * arrived without a delete range are counted.
36
+ */
37
+ export declare function fingerprintFromDocument(doc: Y.Doc): string;
@@ -2,7 +2,7 @@ import { Ref } from 'react';
2
2
  import { WorkbookInstance } from '../../sheet-engine/react';
3
3
  import { DSheetEditorHandle } from '../types';
4
4
 
5
- export type DSheetEditorMethods = Pick<DSheetEditorHandle, "refreshIndexedDB" | "terminateSession" | "updateCollaboratorName" | "updateSessionTitle">;
5
+ export type DSheetEditorMethods = Pick<DSheetEditorHandle, "refreshIndexedDB" | "rebuildLocalStore" | "terminateSession" | "updateCollaboratorName" | "updateSessionTitle" | "navigateToSheet" | "getContentFingerprint">;
6
6
  /**
7
7
  * Compose Fortune's regenerated imperative handle with dSheet lifecycle methods.
8
8
  * React callback refs invoke this again after every Workbook remount, so both
@@ -0,0 +1,27 @@
1
+ import * as Y from 'yjs';
2
+ /** Highest `meta.format` this client can write. */
3
+ export declare const SUPPORTED_FORMAT = 1;
4
+ /** Shown to the user once the sheet is locked. */
5
+ export declare const FORMAT_LOCKED_MESSAGE = "This sheet was updated. Reload to continue.";
6
+ /**
7
+ * Format of the sheet in `doc`. A missing map or key means 1, and so does a
8
+ * value that is not a number. Does not create the map when it is absent.
9
+ */
10
+ export declare function readFormatVersion(doc: Y.Doc, dsheetId: string): number;
11
+ /**
12
+ * True once a watched sheet of `doc` has shown a format above SUPPORTED_FORMAT.
13
+ * With `dsheetId` it answers for that sheet only, and also reads the doc, so
14
+ * it holds before the watch starts. Without it, true if any sheet is locked.
15
+ */
16
+ export declare function isFormatLocked(doc: Y.Doc | null | undefined, dsheetId?: string): boolean;
17
+ /**
18
+ * Make the grid read-only in the same tick the lock is seen. The Yjs writers
19
+ * stop at once (isFormatLocked), but the grid became read-only only after the
20
+ * workbook data changed identity and the Workbook init effect ran: a commit in
21
+ * between showed in the grid, never reached Yjs, and was gone on reload.
22
+ * The Workbook init effect sets the same flag from the prop afterwards.
23
+ */
24
+ export declare function lockWorkbookReadOnly(workbook: {
25
+ getWorkbookSetContext?: () => unknown;
26
+ } | null | undefined): boolean;
27
+ export declare function watchFormatGate(doc: Y.Doc, dsheetId: string, onLocked: (format: number) => void): () => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ /** The legacy `onChange` argument pair: plain sheet data and the encoded doc. */
2
+ export type LegacyOnChangeArgs = {
3
+ data: unknown;
4
+ update: string;
5
+ };
6
+ export declare const LEGACY_ON_CHANGE_WAIT_MS = 1000;
7
+ /**
8
+ * Trailing-only throttle for the host's legacy `onChange`.
9
+ *
10
+ * The host's handler is read when the throttle fires, not when it is created.
11
+ * A host that passes a new inline `onChange` on every render must not rebuild
12
+ * this throttle: rebuilding cancels the pending call, so an edit followed
13
+ * within the wait by a re-render never reached the host's save.
14
+ * `buildArgs` runs only when there is a handler, because it encodes the whole
15
+ * document.
16
+ */
17
+ export declare function createLegacyOnChangeThrottle<TData>(getOnChange: () => ((data: TData, update: string) => void) | undefined, buildArgs: () => {
18
+ data: TData;
19
+ update: string;
20
+ } | null, waitMs?: number): any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ export type NavigableContext = {
2
+ currentSheetId?: string;
3
+ luckysheetfile?: Array<{
4
+ id?: string;
5
+ hide?: number;
6
+ } | null | undefined>;
7
+ };
8
+ export type NavigableEditor = {
9
+ getWorkbookContext?: () => NavigableContext | null | undefined;
10
+ getWorkbookSetContext?: () => ((recipe: (draft: unknown) => void) => void) | null | undefined;
11
+ };
12
+ export type NavigateToSheetOptions = {
13
+ /** How long to wait for the workbook and sheet to load. Default 10s. */
14
+ timeoutMs?: number;
15
+ };
16
+ /**
17
+ * Wait until the workbook has loaded a sheet with `sheetId`, then switch to it.
18
+ * Resolves `false` (never throws) when the sheet is missing after the timeout,
19
+ * hidden, or the switch fails. `getEditor` must return the latest instance on
20
+ * every call because Fortune regenerates its handle on each context change.
21
+ */
22
+ export declare function navigateToSheet<TDraft>(getEditor: () => NavigableEditor | null | undefined, sheetId: string, activate: (draft: TDraft, sheetId: string) => void, { timeoutMs }?: NavigateToSheetOptions): Promise<boolean>;
@@ -0,0 +1,19 @@
1
+ export type PlainCelldataEntry = {
2
+ r: number;
3
+ c: number;
4
+ v: unknown;
5
+ };
6
+ export type CelldataPatch = {
7
+ key: string;
8
+ action: 'delete' | 'update';
9
+ v?: unknown;
10
+ };
11
+ /**
12
+ * Apply a remote batch of cell changes to a sheet's plain celldata array in
13
+ * place. Keys are `r_c` and unique within a batch.
14
+ *
15
+ * One pass over celldata finds every patched cell (A5): O(entries + changes)
16
+ * instead of a findIndex per changed key. The lookup is by row then column
17
+ * number, so the pass allocates nothing per entry.
18
+ */
19
+ export declare function patchPlainCelldata(celldata: PlainCelldataEntry[], patches: Iterable<CelldataPatch>): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { IndexeddbPersistence } from 'y-indexeddb';
2
+ import type * as Y from 'yjs';
3
+ /**
4
+ * D3: rebuild the local IndexedDB store from the live document.
5
+ *
6
+ * Destroys `current`, deletes the database, then attaches a new provider to
7
+ * the SAME live Y.Doc, so y-indexeddb writes the full current state as one
8
+ * fresh row. `onCreated` runs right after the new provider is constructed,
9
+ * before it has synced, so the caller can track it and attach listeners. The Y.Doc is never replaced or cleared. Unlike delete-and-reopen
10
+ * (heal), edits that exist only in the live doc are kept.
11
+ *
12
+ * The wait for the new provider is bounded: `whenSynced` never rejects, and a
13
+ * provider destroyed before its first read (a bootstrap restarting meanwhile)
14
+ * never syncs. It rejects on `timeoutMs` or once `isCurrent()` is false.
15
+ */
16
+ export declare function rebuildIndexedDbStore(dsheetId: string, doc: Y.Doc, current: IndexeddbPersistence | null, onCreated?: (provider: IndexeddbPersistence) => void, syncOptions?: {
17
+ timeoutMs?: number;
18
+ isCurrent?: () => boolean;
19
+ }): Promise<IndexeddbPersistence>;
@@ -11,9 +11,57 @@ export type RemoteApplyGuardRefs = {
11
11
  remoteApplyDepthRef: MutableRefObject<number>;
12
12
  remoteUpdateRef: MutableRefObject<boolean>;
13
13
  };
14
+ /**
15
+ * True when an engine → Yjs echo hook (calcChain, conditional formats, ...)
16
+ * must stay quiet: a remote apply is running, or a structural remount is
17
+ * pending. While one is pending the engine still has the grid from before the
18
+ * peer's insert or delete, so a diff of its metadata against Yjs would write
19
+ * the old coordinates over the peer's (and delete the peer's calcChain
20
+ * entries). Cell commits are not echo hooks and are not held back by this.
21
+ */
22
+ export declare function shouldSkipEchoWrite(refs: {
23
+ remoteUpdateRef: MutableRefObject<boolean>;
24
+ structuralRemountPendingRef?: MutableRefObject<boolean>;
25
+ }): boolean;
14
26
  export declare function syncRemoteUpdateFlag(refs: RemoteApplyGuardRefs): void;
15
27
  export declare function beginRemoteApply(refs: RemoteApplyGuardRefs): void;
16
28
  export declare function endRemoteApply(refs: RemoteApplyGuardRefs): void;
17
29
  export declare function runUnderRemoteApply(refs: RemoteApplyGuardRefs, fn: () => void): void;
30
+ export type StructuralRemountRefs = RemoteApplyGuardRefs & {
31
+ pendingRef: MutableRefObject<boolean>;
32
+ timerRef: MutableRefObject<number | null>;
33
+ };
34
+ /**
35
+ * Debounced structural remount under the remote-apply guard.
36
+ *
37
+ * The guard is begun once, right before `run`, and ended after paint, so each
38
+ * remount owns exactly one begin and one end. It is NOT held while the timer
39
+ * is merely pending or deferred by a cell edit: `remoteUpdateRef` makes
40
+ * handleChange and the data-block work in afterUpdateCell drop local work, so
41
+ * holding it across an edit would drop the user's typed edit. (The cell write
42
+ * in afterUpdateCell and the commit-time write do not check it.) What must not
43
+ * run while a remount is pending is the engine → Yjs echo hooks, which diff
44
+ * the old grid against Yjs: they check `shouldSkipEchoWrite`. Events that
45
+ * land while one is pending only re-arm its timer.
46
+ *
47
+ * While `isEditing()` is true at fire time the timer re-arms (250 ms) and the
48
+ * pending flag is kept; the remount runs once the edit ends.
49
+ */
50
+ export declare function scheduleStructuralRemount(refs: StructuralRemountRefs, run: () => void, delayMs?: number, isEditing?: () => boolean): void;
51
+ /** Re-arm interval while a cell edit blocks the remount. */
52
+ export declare const STRUCTURAL_REMOUNT_EDIT_RETRY_MS = 250;
53
+ /**
54
+ * Drop a pending structural remount (observer teardown). The guard is only
55
+ * held while `run` executes and until paint afterwards, so there is nothing
56
+ * to release here.
57
+ */
58
+ export declare function cancelStructuralRemount(refs: StructuralRemountRefs): void;
59
+ /**
60
+ * Run `fn` under the guard and keep it until paint (a remount follows). If
61
+ * `fn` throws, the guard is ended at once and the error is rethrown: a begin
62
+ * with no matching end leaves the depth above zero, and `handleChange` then
63
+ * drops every local write until reload.
64
+ */
65
+ export declare function runRemoteApplyUntilPaint<T>(refs: RemoteApplyGuardRefs, fn: () => T): T;
18
66
  /** End after Workbook remount hooks have flushed (2 rAF ≈ one paint). */
19
67
  export declare function endRemoteApplyAfterPaint(refs: RemoteApplyGuardRefs): void;
@@ -0,0 +1 @@
1
+ export {};