@tita-agent/dsh-data-table 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +172 -2
- package/cordis.patch.yml +7 -0
- package/lib/client.js +16766 -0
- package/lib/contract-envelope.d.ts +91 -0
- package/lib/contract-envelope.js +106 -0
- package/lib/contract-layout.d.ts +130 -0
- package/lib/contract-layout.js +138 -0
- package/lib/contract-refs.d.ts +39 -0
- package/lib/contract-refs.js +9 -0
- package/lib/contract-version.d.ts +311 -0
- package/lib/contract-version.js +270 -0
- package/lib/contract-wire.d.ts +147 -0
- package/lib/contract-wire.js +99 -0
- package/lib/contracts.d.ts +12 -0
- package/lib/contracts.js +12 -0
- package/lib/types/audit.d.ts +42 -0
- package/lib/types/audit.js +39 -0
- package/lib/types/client/ProjectImportMenu.d.ts +30 -0
- package/lib/types/client/ProjectImportMenu.js +70 -0
- package/lib/types/client/SheetPanel.d.ts +33 -0
- package/lib/types/client/SheetPanel.js +1766 -0
- package/lib/types/client/SheetToggle.d.ts +18 -0
- package/lib/types/client/SheetToggle.js +26 -0
- package/lib/types/client/index.d.ts +15 -0
- package/lib/types/client/index.js +110 -0
- package/lib/types/client/persistence/changes.d.ts +15 -0
- package/lib/types/client/persistence/changes.js +51 -0
- package/lib/types/client/persistence/ids.d.ts +34 -0
- package/lib/types/client/persistence/ids.js +48 -0
- package/lib/types/client/persistence/merge.d.ts +35 -0
- package/lib/types/client/persistence/merge.js +362 -0
- package/lib/types/client/store.d.ts +61 -0
- package/lib/types/client/store.js +152 -0
- package/lib/types/client/surface-context.d.ts +27 -0
- package/lib/types/client/surface-context.js +104 -0
- package/lib/types/client/surface-control.d.ts +2 -0
- package/lib/types/client/surface-control.js +12 -0
- package/lib/types/client/transport/workbookApi.d.ts +159 -0
- package/lib/types/client/transport/workbookApi.js +246 -0
- package/lib/types/client/univer/StandaloneWorkbookPage.d.ts +5 -0
- package/lib/types/client/univer/StandaloneWorkbookPage.js +7 -0
- package/lib/types/client/univer/WorkbookCanvas.d.ts +40 -0
- package/lib/types/client/univer/WorkbookCanvas.js +87 -0
- package/lib/types/client/univer/WorkbookView.d.ts +3 -0
- package/lib/types/client/univer/WorkbookView.js +2 -0
- package/lib/types/client/univer/loader.d.ts +18 -0
- package/lib/types/client/univer/loader.js +81 -0
- package/lib/types/client/univer/standalone-entry.d.ts +1 -0
- package/lib/types/client/univer/standalone-entry.js +19 -0
- package/lib/types/client/versions/VersionChrome.d.ts +33 -0
- package/lib/types/client/versions/VersionChrome.js +21 -0
- package/lib/types/client/versions/inspect.d.ts +70 -0
- package/lib/types/client/versions/inspect.js +88 -0
- package/lib/types/client/versions/preview-decoration.d.ts +11 -0
- package/lib/types/client/versions/preview-decoration.js +54 -0
- package/lib/types/client/versions/records.d.ts +19 -0
- package/lib/types/client/versions/records.js +70 -0
- package/lib/types/client/workspace-host.d.ts +61 -0
- package/lib/types/client/workspace-host.js +124 -0
- package/lib/types/collaboration-hub.d.ts +31 -0
- package/lib/types/collaboration-hub.js +69 -0
- package/lib/types/contract/ids.d.ts +24 -0
- package/lib/types/contract/ids.js +46 -0
- package/lib/types/contract/mutations.d.ts +25 -0
- package/lib/types/contract/mutations.js +782 -0
- package/lib/types/contract/operations.d.ts +54 -0
- package/lib/types/contract/operations.js +203 -0
- package/lib/types/contract/snapshots.d.ts +176 -0
- package/lib/types/contract/snapshots.js +351 -0
- package/lib/types/contract/univer-api-catalog.d.ts +29 -0
- package/lib/types/contract/univer-api-catalog.js +264 -0
- package/lib/types/errors.d.ts +8 -0
- package/lib/types/errors.js +12 -0
- package/lib/types/http/assets-routes.d.ts +3 -0
- package/lib/types/http/assets-routes.js +169 -0
- package/lib/types/http/collaboration.d.ts +10 -0
- package/lib/types/http/collaboration.js +154 -0
- package/lib/types/http/history.d.ts +15 -0
- package/lib/types/http/history.js +134 -0
- package/lib/types/http/project-files.d.ts +79 -0
- package/lib/types/http/project-files.js +206 -0
- package/lib/types/http/project-scope.d.ts +50 -0
- package/lib/types/http/project-scope.js +52 -0
- package/lib/types/http/routes.d.ts +98 -0
- package/lib/types/http/routes.js +323 -0
- package/lib/types/http/standalone.d.ts +9 -0
- package/lib/types/http/standalone.js +31 -0
- package/lib/types/http/trunk.d.ts +10 -0
- package/lib/types/http/trunk.js +322 -0
- package/lib/types/http/worktree.d.ts +9 -0
- package/lib/types/http/worktree.js +145 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/index.js +156 -0
- package/lib/types/invariant.d.ts +15 -0
- package/lib/types/invariant.js +15 -0
- package/lib/types/request-params.d.ts +21 -0
- package/lib/types/request-params.js +76 -0
- package/lib/types/store/paths.d.ts +68 -0
- package/lib/types/store/paths.js +148 -0
- package/lib/types/store/project.d.ts +88 -0
- package/lib/types/store/project.js +120 -0
- package/lib/types/store/read.d.ts +110 -0
- package/lib/types/store/read.js +404 -0
- package/lib/types/store/retention.d.ts +27 -0
- package/lib/types/store/retention.js +111 -0
- package/lib/types/store/write.d.ts +22 -0
- package/lib/types/store/write.js +210 -0
- package/lib/types/tools/arguments.d.ts +40 -0
- package/lib/types/tools/arguments.js +130 -0
- package/lib/types/tools/cells.d.ts +50 -0
- package/lib/types/tools/cells.js +298 -0
- package/lib/types/tools/index.d.ts +2 -0
- package/lib/types/tools/index.js +250 -0
- package/lib/types/tools/render.d.ts +47 -0
- package/lib/types/tools/render.js +290 -0
- package/lib/types/tools/univer-api.d.ts +18 -0
- package/lib/types/tools/univer-api.js +198 -0
- package/lib/types/tools/workbook-catalog.d.ts +3 -0
- package/lib/types/tools/workbook-catalog.js +83 -0
- package/lib/types/tools/workbook-edit.d.ts +192 -0
- package/lib/types/tools/workbook-edit.js +912 -0
- package/lib/types/tools/workbook-find.d.ts +11 -0
- package/lib/types/tools/workbook-find.js +89 -0
- package/lib/types/tools/workbook-history.d.ts +2 -0
- package/lib/types/tools/workbook-history.js +59 -0
- package/lib/types/tools/workbook-read.d.ts +21 -0
- package/lib/types/tools/workbook-read.js +204 -0
- package/lib/types/types.d.ts +377 -0
- package/lib/types/types.js +34 -0
- package/lib/types/univer/apply-operation.d.ts +14 -0
- package/lib/types/univer/apply-operation.js +398 -0
- package/lib/types/univer/chunk.d.ts +68 -0
- package/lib/types/univer/chunk.js +16 -0
- package/lib/types/univer/decoration.d.ts +34 -0
- package/lib/types/univer/decoration.js +88 -0
- package/lib/types/univer/diagnostics.d.ts +31 -0
- package/lib/types/univer/diagnostics.js +141 -0
- package/lib/types/univer/engine.d.ts +33 -0
- package/lib/types/univer/engine.js +338 -0
- package/lib/types/univer/entry.d.ts +8 -0
- package/lib/types/univer/entry.js +11 -0
- package/lib/types/univer/facade.d.ts +107 -0
- package/lib/types/univer/facade.js +1 -0
- package/lib/types/univer/fonts.d.ts +202 -0
- package/lib/types/univer/fonts.js +140 -0
- package/lib/types/univer/plugins/collaboration.d.ts +23 -0
- package/lib/types/univer/plugins/collaboration.js +47 -0
- package/lib/types/univer/plugins/export.d.ts +39 -0
- package/lib/types/univer/plugins/export.js +246 -0
- package/lib/types/univer/plugins/history.d.ts +24 -0
- package/lib/types/univer/plugins/history.js +50 -0
- package/lib/types/univer/plugins/version.d.ts +13 -0
- package/lib/types/univer/plugins/version.js +13 -0
- package/lib/types/version/diff.d.ts +36 -0
- package/lib/types/version/diff.js +156 -0
- package/lib/types/version/grouping.d.ts +7 -0
- package/lib/types/version/grouping.js +94 -0
- package/lib/types/version/records.d.ts +17 -0
- package/lib/types/version/records.js +102 -0
- package/lib/types/version/session.d.ts +36 -0
- package/lib/types/version/session.js +89 -0
- package/lib/types/version/summary.d.ts +24 -0
- package/lib/types/version/summary.js +111 -0
- package/lib/types/workbook-manager.d.ts +191 -0
- package/lib/types/workbook-manager.js +935 -0
- package/lib/types/xlsx-export-worker.d.ts +5 -0
- package/lib/types/xlsx-export-worker.js +24 -0
- package/lib/types/xlsx-export.d.ts +21 -0
- package/lib/types/xlsx-export.js +371 -0
- package/lib/types/xlsx-import-worker.d.ts +1 -0
- package/lib/types/xlsx-import-worker.js +19 -0
- package/lib/univer-client.js +690 -0
- package/lib/workbook-page.js +23826 -0
- package/lib/xlsx-export-worker.js +104 -0
- package/lib/xlsx-import-worker.js +46 -0
- package/package.json +106 -3
- package/src/audit.ts +58 -0
- package/src/client/ProjectImportMenu.tsx +100 -0
- package/src/client/SheetPanel.module.css +1578 -0
- package/src/client/SheetPanel.tsx +1934 -0
- package/src/client/SheetToggle.module.css +73 -0
- package/src/client/SheetToggle.tsx +65 -0
- package/src/client/contract.d.ts +19 -0
- package/src/client/index.ts +131 -0
- package/src/client/persistence/changes.ts +58 -0
- package/src/client/persistence/ids.ts +60 -0
- package/src/client/persistence/merge.ts +392 -0
- package/src/client/store.ts +188 -0
- package/src/client/surface-context.ts +123 -0
- package/src/client/surface-control.ts +13 -0
- package/src/client/transport/workbookApi.ts +355 -0
- package/src/client/univer/SheetView.module.css +110 -0
- package/src/client/univer/StandaloneWorkbookPage.module.css +8 -0
- package/src/client/univer/StandaloneWorkbookPage.tsx +15 -0
- package/src/client/univer/WorkbookCanvas.tsx +128 -0
- package/src/client/univer/WorkbookView.module.css +30 -0
- package/src/client/univer/WorkbookView.tsx +3 -0
- package/src/client/univer/loader.ts +90 -0
- package/src/client/univer/react-dom-client.d.ts +10 -0
- package/src/client/univer/standalone-entry.tsx +19 -0
- package/src/client/univer/standalone.css +12 -0
- package/src/client/univer/univer-locales.d.ts +89 -0
- package/src/client/univer/univer-modules.d.ts +26 -0
- package/src/client/versions/VersionChrome.tsx +114 -0
- package/src/client/versions/inspect.ts +138 -0
- package/src/client/versions/preview-decoration.ts +54 -0
- package/src/client/versions/records.ts +78 -0
- package/src/client/workspace-host.ts +147 -0
- package/src/collaboration-hub.ts +83 -0
- package/src/contract/ids.ts +50 -0
- package/src/contract/mutations.ts +791 -0
- package/src/contract/operations.ts +221 -0
- package/src/contract/snapshots.ts +383 -0
- package/src/contract/univer-api-catalog.ts +289 -0
- package/src/css-modules.d.ts +6 -0
- package/src/errors.ts +25 -0
- package/src/http/assets-routes.ts +177 -0
- package/src/http/collaboration.ts +144 -0
- package/src/http/history.ts +151 -0
- package/src/http/project-files.ts +227 -0
- package/src/http/project-scope.ts +77 -0
- package/src/http/routes.ts +364 -0
- package/src/http/standalone.ts +32 -0
- package/src/http/trunk.ts +322 -0
- package/src/http/worktree.ts +119 -0
- package/src/index.ts +165 -0
- package/src/invariant.ts +17 -0
- package/src/request-params.ts +92 -0
- package/src/store/paths.ts +165 -0
- package/src/store/project.ts +137 -0
- package/src/store/read.ts +454 -0
- package/src/store/retention.ts +106 -0
- package/src/store/write.ts +230 -0
- package/src/tools/arguments.ts +128 -0
- package/src/tools/cells.ts +298 -0
- package/src/tools/index.ts +274 -0
- package/src/tools/render.ts +301 -0
- package/src/tools/univer-api.ts +243 -0
- package/src/tools/workbook-catalog.ts +94 -0
- package/src/tools/workbook-edit.ts +987 -0
- package/src/tools/workbook-find.ts +80 -0
- package/src/tools/workbook-history.ts +63 -0
- package/src/tools/workbook-read.ts +210 -0
- package/src/types.ts +432 -0
- package/src/univer/apply-operation.ts +369 -0
- package/src/univer/chunk.ts +77 -0
- package/src/univer/decoration.ts +111 -0
- package/src/univer/diagnostics.ts +136 -0
- package/src/univer/engine.ts +370 -0
- package/src/univer/entry.ts +14 -0
- package/src/univer/facade.ts +91 -0
- package/src/univer/fonts.ts +148 -0
- package/src/univer/overrides.css +33 -0
- package/src/univer/plugins/collaboration.ts +47 -0
- package/src/univer/plugins/export.ts +236 -0
- package/src/univer/plugins/history.ts +49 -0
- package/src/univer/plugins/version.ts +13 -0
- package/src/version/diff.ts +169 -0
- package/src/version/grouping.ts +96 -0
- package/src/version/records.ts +113 -0
- package/src/version/session.ts +90 -0
- package/src/version/summary.ts +117 -0
- package/src/workbook-manager.ts +1111 -0
- package/src/xlsx-export-worker.ts +34 -0
- package/src/xlsx-export.ts +373 -0
- package/src/xlsx-import-worker.ts +30 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operations: their shape, their expansion into Steps, and which Univer
|
|
3
|
+
* commands may become one (docs/issue/0022 P0).
|
|
4
|
+
*
|
|
5
|
+
* The mutation whitelist lives here rather than beside the engine because it is
|
|
6
|
+
* a policy about the *version model* — which canvas commands are durable
|
|
7
|
+
* content and which are derived UI state — not an engine detail. The engine
|
|
8
|
+
* asks; this module decides.
|
|
9
|
+
*/
|
|
10
|
+
import type { WorkbookOperation } from '../types.ts';
|
|
11
|
+
/**
|
|
12
|
+
* The v3 tier of the Version these operations make up.
|
|
13
|
+
*
|
|
14
|
+
* Explicit when the log carries one. Operations written before v3 carry no
|
|
15
|
+
* `versionKind`, so the tier is derived from the facts that already separated a
|
|
16
|
+
* deliberate Version from editing-session churn — a summary, an Agent actor, a
|
|
17
|
+
* restore. Reading a missing tier as its schema default (`named`) instead is what
|
|
18
|
+
* once made every legacy Version unprunable.
|
|
19
|
+
*
|
|
20
|
+
* It is here because two layers need it and neither may import the other: the
|
|
21
|
+
* projection in `version/grouping.ts` and the retention policy in
|
|
22
|
+
* `store/retention.ts`, which the directory guard keeps below `version/`. Same
|
|
23
|
+
* reason `operationSummary` is here. It was written out twice, in different
|
|
24
|
+
* words that happened to agree.
|
|
25
|
+
*/
|
|
26
|
+
export declare function versionKindOfOperations(operations: WorkbookOperation[]): 'named' | 'auto';
|
|
27
|
+
/**
|
|
28
|
+
* How many proposals a workbook keeps.
|
|
29
|
+
*
|
|
30
|
+
* One constant because the bound was applied in two layers — the manager when it
|
|
31
|
+
* created a proposal, and the store on every write — which is two policies for
|
|
32
|
+
* one array, and the layer that runs less often is the one that gets forgotten.
|
|
33
|
+
* The store owns it now, since it runs on every write.
|
|
34
|
+
*/
|
|
35
|
+
export declare const PROPOSAL_LOG_LIMIT = 20;
|
|
36
|
+
/**
|
|
37
|
+
* What `append_rows` says when its columns do not match the sheet's header.
|
|
38
|
+
*
|
|
39
|
+
* It lives here, not in `contract/mutations.ts` where the check is made, because
|
|
40
|
+
* the canvas applier raises the same error and `mutations.ts` imports
|
|
41
|
+
* `node:crypto` — the moment a browser-bundled module reached it, esbuild failed
|
|
42
|
+
* on a built-in Node module. This module is the one both halves already share.
|
|
43
|
+
*/
|
|
44
|
+
export declare const APPEND_HEADER_MISMATCH = "\u8FFD\u52A0\u6570\u636E\u7684\u5217\u7ED3\u6784\u4E0E\u73B0\u6709\u8868\u5934\u4E0D\u4E00\u81F4\uFF1B\u82E5\u771F\u5B9E\u5217\u5934\u4E0D\u5728\u7B2C 0 \u884C\uFF0C\u8BF7\u7528 headerRowIndex \u6307\u5411\u5B83\uFF0C\u6216\u6539\u7528 workbook_edit \u7684 update_cells command";
|
|
45
|
+
export type UniverMutationPersistence = 'ignore' | 'snapshot';
|
|
46
|
+
/** Classify a Univer command before it is allowed to dirty a workbook. */
|
|
47
|
+
export declare function classifyUniverMutation(commandId: string): UniverMutationPersistence;
|
|
48
|
+
/** Return whether a Univer mutation represents durable workbook state. */
|
|
49
|
+
export declare function shouldPersistUniverMutation(commandId: string): boolean;
|
|
50
|
+
/** Expand a persisted operation into the ordered steps of one Version. A
|
|
51
|
+
* normal operation is one step; a batch keeps each child visible for history
|
|
52
|
+
* and replay without introducing a second persistence model. */
|
|
53
|
+
export declare function workbookOperationSteps(operation: WorkbookOperation): WorkbookOperation[];
|
|
54
|
+
export declare function operationSummary(operation: WorkbookOperation): string;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Univer emits a small number of mutation commands for derived layout or UI
|
|
3
|
+
* state. They are useful inside the live canvas, but must not become DSH
|
|
4
|
+
* workbook revisions: they are either no-ops, recalculation markers, or state
|
|
5
|
+
* that is reconstructed when the workbook is mounted again. In particular,
|
|
6
|
+
* selection, focus, scrolling, and editor-panel commands are emitted while a
|
|
7
|
+
* user is merely navigating the canvas and must not dirty the workbook.
|
|
8
|
+
*/
|
|
9
|
+
const NON_PERSISTED_MUTATION_IDS = new Set([
|
|
10
|
+
'sheet.mutation.empty',
|
|
11
|
+
'sheet.mutation.mark-dirty-filter-change',
|
|
12
|
+
'sheet.mutation.re-calc-filter',
|
|
13
|
+
'sheet.mutation.set-worksheet-row-auto-height',
|
|
14
|
+
'sheet.mutation.toggle-note-popup',
|
|
15
|
+
'sheet.mutation.update-note-position',
|
|
16
|
+
// View-only operations emitted by clicks, keyboard navigation, and panels.
|
|
17
|
+
'sheet.operation.set-selections',
|
|
18
|
+
'sheet.operation.set-worksheet-active',
|
|
19
|
+
'sheet.operation.set-scroll',
|
|
20
|
+
'sheet.operation.scroll-to-cell',
|
|
21
|
+
'sheet.operation.scroll-to-range',
|
|
22
|
+
'sheet.operation.set-zoom-ratio',
|
|
23
|
+
'sheet.operation.set-activate-cell-edit',
|
|
24
|
+
'sheet.operation.set-cell-edit-visible',
|
|
25
|
+
'sheet.operation.set-cell-edit-visible-arrow',
|
|
26
|
+
'sheet.operation.set-cell-edit-visible-f2',
|
|
27
|
+
'sheet.operation.set-format-painter',
|
|
28
|
+
'sheet.operation.open.numfmt.panel',
|
|
29
|
+
'sheet.operation.close.numfmt.panel',
|
|
30
|
+
'sheet.command.apply-format-painter',
|
|
31
|
+
'sheet.command.set-infinite-format-painter',
|
|
32
|
+
'sheet.command.set-once-format-painter',
|
|
33
|
+
'sheet.command.move-selection',
|
|
34
|
+
'sheet.command.move-selection-enter-tab',
|
|
35
|
+
'sheet.command.expand-selection',
|
|
36
|
+
'sheet.command.select-range',
|
|
37
|
+
'sheet.command.select-all',
|
|
38
|
+
'sheet.command.set-selection-frozen',
|
|
39
|
+
'sheet.command.scroll-to-cell',
|
|
40
|
+
'sheet.command.scroll-view',
|
|
41
|
+
'sheet.command.scroll-view-reset',
|
|
42
|
+
'sheet.command.set-scroll-relative',
|
|
43
|
+
'sheet.command.change-zoom-ratio',
|
|
44
|
+
'sheet.command.set-zoom-ratio',
|
|
45
|
+
'sheet.command.set-worksheet-activate',
|
|
46
|
+
]);
|
|
47
|
+
const NON_PERSISTED_MUTATION_PREFIXES = [
|
|
48
|
+
// Univer appends editor-specific suffixes to these UI operations.
|
|
49
|
+
'sheet.operation.editor-',
|
|
50
|
+
];
|
|
51
|
+
// Only these command ids are known to describe durable workbook state. The
|
|
52
|
+
// previous deny-list treated every new Univer command as a save candidate;
|
|
53
|
+
// that made a navigation command capable of setting the dirty bit and caused
|
|
54
|
+
// an unnecessary full snapshot request. Unknown commands are deliberately
|
|
55
|
+
// ignored until they have an explicit persistence contract and a parser.
|
|
56
|
+
const PERSISTED_MUTATION_IDS = new Set([
|
|
57
|
+
'sheet.mutation.set-range-values',
|
|
58
|
+
'sheet.mutation.set-row-data',
|
|
59
|
+
'sheet.mutation.set-col-data',
|
|
60
|
+
'sheet.mutation.set-gridlines-color',
|
|
61
|
+
'sheet.mutation.set-worksheet-name',
|
|
62
|
+
'sheet.mutation.add-worksheet-merge',
|
|
63
|
+
'sheet.mutation.remove-worksheet-merge',
|
|
64
|
+
'sheet.mutation.set-style',
|
|
65
|
+
'sheet.mutation.set-number-format',
|
|
66
|
+
'sheet.command.clear-selection-content',
|
|
67
|
+
'sheet.command.set-bold',
|
|
68
|
+
'sheet.command.set-italic',
|
|
69
|
+
'sheet.command.set-underline',
|
|
70
|
+
'sheet.command.set-strikethrough',
|
|
71
|
+
'sheet.command.set-style',
|
|
72
|
+
'sheet.command.set-range-values',
|
|
73
|
+
'sheet.command.set-number-format',
|
|
74
|
+
'sheet.command.set-font-color',
|
|
75
|
+
'sheet.command.set-font-family',
|
|
76
|
+
'sheet.command.set-font-size',
|
|
77
|
+
'sheet.command.set-font-weight',
|
|
78
|
+
'sheet.command.set-font-style',
|
|
79
|
+
'sheet.command.set-horizontal-alignment',
|
|
80
|
+
'sheet.command.set-vertical-alignment',
|
|
81
|
+
]);
|
|
82
|
+
/**
|
|
83
|
+
* The v3 tier of the Version these operations make up.
|
|
84
|
+
*
|
|
85
|
+
* Explicit when the log carries one. Operations written before v3 carry no
|
|
86
|
+
* `versionKind`, so the tier is derived from the facts that already separated a
|
|
87
|
+
* deliberate Version from editing-session churn — a summary, an Agent actor, a
|
|
88
|
+
* restore. Reading a missing tier as its schema default (`named`) instead is what
|
|
89
|
+
* once made every legacy Version unprunable.
|
|
90
|
+
*
|
|
91
|
+
* It is here because two layers need it and neither may import the other: the
|
|
92
|
+
* projection in `version/grouping.ts` and the retention policy in
|
|
93
|
+
* `store/retention.ts`, which the directory guard keeps below `version/`. Same
|
|
94
|
+
* reason `operationSummary` is here. It was written out twice, in different
|
|
95
|
+
* words that happened to agree.
|
|
96
|
+
*/
|
|
97
|
+
export function versionKindOfOperations(operations) {
|
|
98
|
+
const explicit = operations.map(operation => operation.versionKind).find(kind => kind !== undefined);
|
|
99
|
+
if (explicit !== undefined)
|
|
100
|
+
return explicit;
|
|
101
|
+
const first = operations[0];
|
|
102
|
+
const last = operations.at(-1);
|
|
103
|
+
const deliberate = first?.versionSummary !== undefined || last?.versionSummary !== undefined
|
|
104
|
+
|| first?.actor === 'agent'
|
|
105
|
+
|| first?.restoredFromRevision !== undefined || last?.restoredFromRevision !== undefined;
|
|
106
|
+
return deliberate ? 'named' : 'auto';
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* How many proposals a workbook keeps.
|
|
110
|
+
*
|
|
111
|
+
* One constant because the bound was applied in two layers — the manager when it
|
|
112
|
+
* created a proposal, and the store on every write — which is two policies for
|
|
113
|
+
* one array, and the layer that runs less often is the one that gets forgotten.
|
|
114
|
+
* The store owns it now, since it runs on every write.
|
|
115
|
+
*/
|
|
116
|
+
export const PROPOSAL_LOG_LIMIT = 20;
|
|
117
|
+
/**
|
|
118
|
+
* What `append_rows` says when its columns do not match the sheet's header.
|
|
119
|
+
*
|
|
120
|
+
* It lives here, not in `contract/mutations.ts` where the check is made, because
|
|
121
|
+
* the canvas applier raises the same error and `mutations.ts` imports
|
|
122
|
+
* `node:crypto` — the moment a browser-bundled module reached it, esbuild failed
|
|
123
|
+
* on a built-in Node module. This module is the one both halves already share.
|
|
124
|
+
*/
|
|
125
|
+
export const APPEND_HEADER_MISMATCH = '追加数据的列结构与现有表头不一致;若真实列头不在第 0 行,请用 headerRowIndex 指向它,或改用 workbook_edit 的 update_cells command';
|
|
126
|
+
/** Classify a Univer command before it is allowed to dirty a workbook. */
|
|
127
|
+
export function classifyUniverMutation(commandId) {
|
|
128
|
+
// Three rules, in order, each written as its own statement.
|
|
129
|
+
//
|
|
130
|
+
// It used to be two, the second of which read
|
|
131
|
+
// `A || B && !PERSISTED.has(id)`. `&&` binds tighter than `||`, so that was
|
|
132
|
+
// `A || (B && !has)`, not `(A || B) && !has` — and since the last line is an
|
|
133
|
+
// allow-list, the `B && !has` half could never change an answer. It is still
|
|
134
|
+
// unreachable today (no `sheet.operation.*` id is in the allow-list), but it
|
|
135
|
+
// would have flipped the moment one was added, in a file whose whole purpose
|
|
136
|
+
// is to say which commands may dirty a workbook.
|
|
137
|
+
if (NON_PERSISTED_MUTATION_IDS.has(commandId)
|
|
138
|
+
|| NON_PERSISTED_MUTATION_PREFIXES.some(prefix => commandId.startsWith(prefix)))
|
|
139
|
+
return 'ignore';
|
|
140
|
+
// The `sheet.operation.*` namespace is view state — selections, scrolling,
|
|
141
|
+
// panel visibility. It is ignored *whatever* the allow-list later says, which
|
|
142
|
+
// is what the accidental `A ||` did and what is meant here.
|
|
143
|
+
if (commandId.startsWith('sheet.operation.'))
|
|
144
|
+
return 'ignore';
|
|
145
|
+
// Everything else is durable only with an explicit contract. Unknown commands
|
|
146
|
+
// are ignored on purpose: treating a new Univer command as a save candidate is
|
|
147
|
+
// how a navigation keystroke marks a workbook dirty.
|
|
148
|
+
return PERSISTED_MUTATION_IDS.has(commandId) ? 'snapshot' : 'ignore';
|
|
149
|
+
}
|
|
150
|
+
/** Return whether a Univer mutation represents durable workbook state. */
|
|
151
|
+
export function shouldPersistUniverMutation(commandId) {
|
|
152
|
+
return classifyUniverMutation(commandId) !== 'ignore';
|
|
153
|
+
}
|
|
154
|
+
/** Expand a persisted operation into the ordered steps of one Version. A
|
|
155
|
+
* normal operation is one step; a batch keeps each child visible for history
|
|
156
|
+
* and replay without introducing a second persistence model. */
|
|
157
|
+
export function workbookOperationSteps(operation) {
|
|
158
|
+
if (operation.type !== 'batch')
|
|
159
|
+
return [operation];
|
|
160
|
+
return (operation.payload.operations ?? []).map((child, index) => ({
|
|
161
|
+
opId: `${operation.opId}:${index + 1}`,
|
|
162
|
+
workbookId: operation.workbookId,
|
|
163
|
+
revision: operation.revision,
|
|
164
|
+
parentRevision: operation.parentRevision,
|
|
165
|
+
baseRevision: operation.baseRevision,
|
|
166
|
+
versionId: operation.versionId,
|
|
167
|
+
versionStatus: operation.versionStatus,
|
|
168
|
+
versionSummary: operation.versionSummary,
|
|
169
|
+
versionKind: operation.versionKind,
|
|
170
|
+
stepSummary: operation.stepSummary,
|
|
171
|
+
versionIntent: operation.versionIntent,
|
|
172
|
+
agentRunId: operation.agentRunId,
|
|
173
|
+
lineage: operation.lineage,
|
|
174
|
+
restoredFromRevision: operation.restoredFromRevision,
|
|
175
|
+
actor: operation.actor,
|
|
176
|
+
type: child.type,
|
|
177
|
+
timestamp: operation.timestamp,
|
|
178
|
+
payload: child.payload,
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
export function operationSummary(operation) {
|
|
182
|
+
// A derived summary wins: the server knows what a generic operation changed
|
|
183
|
+
// (see `describeSnapshotReplace`). This used to exist twice — here and in
|
|
184
|
+
// `index.ts` — under a comment asking the two copies to stay in step.
|
|
185
|
+
if (operation.stepSummary !== undefined)
|
|
186
|
+
return operation.stepSummary;
|
|
187
|
+
const payload = operation.payload;
|
|
188
|
+
switch (operation.type) {
|
|
189
|
+
case 'update_cells': return `更新 ${payload.cells?.length ?? 0} 个单元格`;
|
|
190
|
+
case 'append_rows': return `追加 ${payload.rows?.length ?? 0} 行`;
|
|
191
|
+
case 'set_hyperlink': return '设置超链接';
|
|
192
|
+
case 'remove_hyperlink': return '移除超链接';
|
|
193
|
+
case 'create_sheet': return `新增 sheet${payload.name === undefined ? '' : `:${payload.name}`}`;
|
|
194
|
+
case 'delete_sheet': return '删除 sheet';
|
|
195
|
+
case 'rename_sheet': return `重命名 sheet${payload.name === undefined ? '' : `:${payload.name}`}`;
|
|
196
|
+
case 'batch': return `批量操作(${payload.operations?.length ?? 0} 个 step)`;
|
|
197
|
+
// Only pre-v3.1 records reach this: their payload was compacted away, so
|
|
198
|
+
// the change they made can no longer be derived. Say so, instead of a
|
|
199
|
+
// neutral label that reads like a normal save.
|
|
200
|
+
case 'snapshot_replace': return '保存整表内容(旧记录)';
|
|
201
|
+
default: return operation.type;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot vocabulary: the workbook snapshot shape, the matrix tools, and the
|
|
3
|
+
* one range reader (docs/issue/0022 P0).
|
|
4
|
+
*
|
|
5
|
+
* The readers here are pure functions of their arguments. The two **accessors**
|
|
6
|
+
* are not, and the distinction is worth stating because the module used to claim
|
|
7
|
+
* otherwise:
|
|
8
|
+
*
|
|
9
|
+
* - `asWorkbookSnapshot` fills in a missing `sheetOrder` by writing it into the
|
|
10
|
+
* object it was handed. That is how a caller's `payload.snapshot` could be
|
|
11
|
+
* modified as a side effect of reading it, which is what made a stored
|
|
12
|
+
* operation's payload accumulate later revisions. `applyWorkbookOperation`
|
|
13
|
+
* now clones before returning, so the write lands on a copy — but this
|
|
14
|
+
* function still writes to its argument, and a caller must not assume
|
|
15
|
+
* otherwise.
|
|
16
|
+
* - `resolveSheet` materializes `cellData` on the sheet it returns. That is
|
|
17
|
+
* load-bearing, not incidental: writers mutate the returned sheet and expect
|
|
18
|
+
* the change to land in the snapshot, so handing back a copy would silently
|
|
19
|
+
* drop every edit.
|
|
20
|
+
*
|
|
21
|
+
* `cloneSnapshot` is the point of the move: it existed twice — once in the model
|
|
22
|
+
* layer and once again inside `client/SheetPanel.tsx` — which is exactly the
|
|
23
|
+
* drift a contract module exists to prevent.
|
|
24
|
+
*/
|
|
25
|
+
import { type SheetSchema, type WorkbookCellStyle, type WorkbookCellValue, type WorkbookRange } from '../types.ts';
|
|
26
|
+
/**
|
|
27
|
+
* The snapshot shape. It is declared here rather than in `types.ts` because it
|
|
28
|
+
* is the *input* of these functions and of nothing else on the wire; the
|
|
29
|
+
* tool-facing types stay in `types.ts`.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The font family a blank sheet is created with.
|
|
33
|
+
*
|
|
34
|
+
* It lives in the contract because it is part of the stored snapshot's default
|
|
35
|
+
* style: the model, the xlsx reader and the engine all have to agree on it.
|
|
36
|
+
* Before the 0022 refactor it lived in the engine's font module, which made the
|
|
37
|
+
* model layer import *upward* into the engine (docs/issue/0022 §2).
|
|
38
|
+
*/
|
|
39
|
+
export declare const DEFAULT_SHEET_FONT_FAMILY = "PingFang SC";
|
|
40
|
+
/**
|
|
41
|
+
* The grid a new sheet starts with.
|
|
42
|
+
*
|
|
43
|
+
* One constant because *two* layers create sheets — the snapshot mutator and the
|
|
44
|
+
* Univer canvas — and a sheet's declared extent has to match the grid the user
|
|
45
|
+
* is looking at. It was written out as `1000` and `26` in seven places across
|
|
46
|
+
* five files, which is how the two drift apart without anyone editing either
|
|
47
|
+
* number. It is also a *starting* size, not a read limit: writes grow the sheet
|
|
48
|
+
* (`SHEET_MAX_ROWS` is the ceiling), and reads take the range they are given.
|
|
49
|
+
*/
|
|
50
|
+
export declare const DEFAULT_SHEET_ROWS = 1000;
|
|
51
|
+
export declare const DEFAULT_SHEET_COLUMNS = 26;
|
|
52
|
+
export interface WorkbookSnapshot {
|
|
53
|
+
sheetOrder: string[];
|
|
54
|
+
sheets: Record<string, WorkbookSheet>;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface WorkbookSheet {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
rowCount: number;
|
|
61
|
+
columnCount: number;
|
|
62
|
+
cellData: Record<string, Record<string, StoredCell>>;
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
}
|
|
65
|
+
export interface StoredCell {
|
|
66
|
+
v?: unknown;
|
|
67
|
+
f?: unknown;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Deterministic JSON, so two equal values serialize identically.
|
|
72
|
+
*
|
|
73
|
+
* Object keys are sorted, which `JSON.stringify` does not do: it follows
|
|
74
|
+
* insertion order, so two snapshots holding the same content in a different
|
|
75
|
+
* order would compare unequal. Used for content hashes and for deciding whether
|
|
76
|
+
* a merge actually changed anything.
|
|
77
|
+
*
|
|
78
|
+
* It lived in the model layer *and* in the browser's merge code, byte for byte.
|
|
79
|
+
*/
|
|
80
|
+
export declare function stableJson(value: unknown): string;
|
|
81
|
+
/** Deep copy through JSON; snapshots are plain JSON by construction. */
|
|
82
|
+
export declare function cloneSnapshot<T>(value: T): T;
|
|
83
|
+
/**
|
|
84
|
+
* Narrow `value` to a snapshot, defaulting `sheetOrder` from `sheets`.
|
|
85
|
+
*
|
|
86
|
+
* **Writes to its argument** when `sheetOrder` is absent (see the module note).
|
|
87
|
+
* Every caller here uses the return value, and `applyWorkbookOperation` clones,
|
|
88
|
+
* but a new caller should not read a snapshot *and* hand the same object
|
|
89
|
+
* somewhere else without knowing that.
|
|
90
|
+
*/
|
|
91
|
+
export declare function asWorkbookSnapshot(value: unknown): WorkbookSnapshot;
|
|
92
|
+
export declare function resolveSheet(root: WorkbookSnapshot, ref: string | undefined): WorkbookSheet;
|
|
93
|
+
export declare function validateIndex(value: number, label: string): void;
|
|
94
|
+
export declare function validateRange(range: WorkbookRange | undefined): asserts range is WorkbookRange;
|
|
95
|
+
/**
|
|
96
|
+
* A cell's formula in the one form this repository stores.
|
|
97
|
+
*
|
|
98
|
+
* `=SUM(A1:A2)` and `SUM(A1:A2)` are the same formula — the leading `=` is how a
|
|
99
|
+
* spreadsheet *displays* it, not part of it — and the whitespace around it is not
|
|
100
|
+
* part of it either. An input that reduces to nothing is not a formula at all.
|
|
101
|
+
*
|
|
102
|
+
* Four places wrote cells and each decided this for itself, so they disagreed:
|
|
103
|
+
* `update_cells` with `formula: '=SUM(A1:A2)'` stored `SUM(A1:A2)` in the
|
|
104
|
+
* snapshot and drew `=SUM(A1:A2)` on the canvas; `formula: ''` deleted the cell
|
|
105
|
+
* in the snapshot and left `{v:null,f:''}` on the canvas; `'='` was dropped by
|
|
106
|
+
* the snapshot and kept by the browser's merge. The snapshot and the canvas are
|
|
107
|
+
* two views of one workbook, so they cannot disagree about what is in it.
|
|
108
|
+
*/
|
|
109
|
+
export declare function normalizeCellFormula(formula: unknown): string | undefined;
|
|
110
|
+
export declare function toCellValue(cell: StoredCell | undefined): WorkbookCellValue | null;
|
|
111
|
+
export declare function cellType(value: WorkbookCellValue | null): string;
|
|
112
|
+
/**
|
|
113
|
+
* The last row and column that actually carry something, or `-1` when the sheet
|
|
114
|
+
* is empty.
|
|
115
|
+
*
|
|
116
|
+
* A whole-sheet read needs this: the caller asking for "the sheet" must get the
|
|
117
|
+
* sheet, and the only way to know how big that is, is to look. A hard-coded
|
|
118
|
+
* window cannot know, and a window that is too small loses data silently.
|
|
119
|
+
*
|
|
120
|
+
* A cell that holds only a style is skipped — formatting an empty range writes
|
|
121
|
+
* style ids into every cell it covers, and those must not stretch a read.
|
|
122
|
+
*/
|
|
123
|
+
export declare function usedExtent(snapshot: unknown, sheetRef: string | undefined): {
|
|
124
|
+
endRow: number;
|
|
125
|
+
endColumn: number;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The style a cell actually paints with: the sheet's default under the cell's
|
|
129
|
+
* own, field by field.
|
|
130
|
+
*
|
|
131
|
+
* The sheet default is load-bearing, not decoration. `DEFAULT_SHEET_FONT_FAMILY`
|
|
132
|
+
* lives in every sheet's `defaultStyle` and is the **only** place a font family
|
|
133
|
+
* is recorded for a cell the user never formatted — a reader that skipped it
|
|
134
|
+
* would report "no font" for most of a sheet, which is how the Sheet Block
|
|
135
|
+
* preview could not show the font the workbook is actually set in.
|
|
136
|
+
*
|
|
137
|
+
* `null` means there is nothing to paint, so the wire carries a compact matrix
|
|
138
|
+
* instead of an object per empty cell.
|
|
139
|
+
*/
|
|
140
|
+
export declare function effectiveCellStyle(root: WorkbookSnapshot, sheet: WorkbookSheet, cell: StoredCell | undefined): WorkbookCellStyle | null;
|
|
141
|
+
export declare function readWorkbookRange(snapshot: unknown, sheetRef: string, range: WorkbookRange, options?: {
|
|
142
|
+
styles?: boolean;
|
|
143
|
+
}): {
|
|
144
|
+
sheetId: string;
|
|
145
|
+
sheetName: string;
|
|
146
|
+
range: WorkbookRange;
|
|
147
|
+
values: Array<Array<WorkbookCellValue | null>>;
|
|
148
|
+
formulas: Array<Array<string | null>>;
|
|
149
|
+
cells: Array<Array<{
|
|
150
|
+
value: WorkbookCellValue | null;
|
|
151
|
+
formula: string | null;
|
|
152
|
+
type: string;
|
|
153
|
+
calculation?: 'cached' | 'unavailable';
|
|
154
|
+
error?: string;
|
|
155
|
+
}>>;
|
|
156
|
+
/**
|
|
157
|
+
* The effective style of every cell in `values`, when the caller asked for it.
|
|
158
|
+
*
|
|
159
|
+
* Opt-in, because the two readers of this range want different things: the SQL
|
|
160
|
+
* loader materializes values as a relation and would pay for a second matrix
|
|
161
|
+
* it never reads, while the Sheet Block preview exists to show the range the
|
|
162
|
+
* way the sheet draws it.
|
|
163
|
+
*/
|
|
164
|
+
styles?: Array<Array<WorkbookCellStyle | null>>;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Return original sheet row indexes that are duplicates within a rectangular
|
|
168
|
+
* range. This follows Excel's default behavior: compare the selected columns,
|
|
169
|
+
* keep the first occurrence, and leave the header untouched when requested.
|
|
170
|
+
*/
|
|
171
|
+
export declare function findDuplicateRows(values: ReadonlyArray<ReadonlyArray<unknown>>, range: WorkbookRange, columns?: readonly number[], hasHeader?: boolean, keep?: 'first' | 'last'): number[];
|
|
172
|
+
export declare function isSheetSchema(value: unknown): value is SheetSchema;
|
|
173
|
+
/** Force a snapshot's `name` field to the workbook's user-facing name.
|
|
174
|
+
* Both the read and the write path need it, which is why it is vocabulary
|
|
175
|
+
* rather than a store helper. */
|
|
176
|
+
export declare function normalizeSnapshotName(snapshot: unknown, name: string): unknown;
|