@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,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-canvas diagnostics and command mapping (docs/issue/0022 P4).
|
|
3
|
+
*
|
|
4
|
+
* Two jobs that both start from a Univer command: turning it into the small DSH
|
|
5
|
+
* change contract the Host persists, and leaving a probe behind so a live
|
|
6
|
+
* workbook can be inspected from the console (`__dshLastCellMutation`). They sit
|
|
7
|
+
* together because both are "what did Univer just do", and neither decides what
|
|
8
|
+
* to persist — `contract/operations.ts` decides that.
|
|
9
|
+
*/
|
|
10
|
+
import { normalizeCellFormula } from "../contract/snapshots.js";
|
|
11
|
+
/**
|
|
12
|
+
* Diagnostic seam for the incremental-save mapping (PRD v3.1 follow-up).
|
|
13
|
+
*
|
|
14
|
+
* Cell edits that cannot be expressed as a plain value fall back to a whole
|
|
15
|
+
* snapshot save, which is correct but ~230 KB per edit. This records why the
|
|
16
|
+
* last such mutation was not mapped, so the reason can be read from the
|
|
17
|
+
* browser console instead of guessed:
|
|
18
|
+
*
|
|
19
|
+
* __dshLastCellMutation // { commandId, mapped, reason?, keys? }
|
|
20
|
+
*/
|
|
21
|
+
let lastCellMutationNote;
|
|
22
|
+
/** Why the current mutation could not become an incremental cell change. */
|
|
23
|
+
export function noteCellMutation(_commandId, mapped, detail = {}) {
|
|
24
|
+
lastCellMutationNote = mapped ? undefined : detail;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Publish the outcome of one persisted mutation. This runs for *every*
|
|
28
|
+
* mutation the workbook persists, so a command id we do not map is still
|
|
29
|
+
* visible instead of leaving the probe undefined:
|
|
30
|
+
*
|
|
31
|
+
* __dshLastCellMutation // { commandId, mapped, reason?, keys? }
|
|
32
|
+
*/
|
|
33
|
+
export function publishMutationAttempt(commandId, mapped) {
|
|
34
|
+
if (typeof window === 'undefined')
|
|
35
|
+
return;
|
|
36
|
+
window.__dshLastCellMutation = {
|
|
37
|
+
at: new Date().toISOString(),
|
|
38
|
+
commandId,
|
|
39
|
+
mapped,
|
|
40
|
+
...(mapped ? {} : (lastCellMutationNote ?? { reason: 'command-not-mapped' })),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function cellKeysOf(cellValue) {
|
|
44
|
+
if (typeof cellValue !== 'object' || cellValue === null)
|
|
45
|
+
return [];
|
|
46
|
+
const firstRow = Object.values(cellValue)[0];
|
|
47
|
+
if (typeof firstRow !== 'object' || firstRow === null)
|
|
48
|
+
return [];
|
|
49
|
+
const firstCell = Object.values(firstRow)[0];
|
|
50
|
+
return typeof firstCell === 'object' && firstCell !== null ? Object.keys(firstCell) : [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convert Univer's sparse set-range-values mutation into the small DSH edit
|
|
54
|
+
* contract. Formatting, pasted rich objects, and structural commands return
|
|
55
|
+
* undefined so the browser deliberately falls back to a full snapshot save.
|
|
56
|
+
*/
|
|
57
|
+
export function toLocalCellChange(commandInfo) {
|
|
58
|
+
if (commandInfo.id !== 'sheet.mutation.set-range-values')
|
|
59
|
+
return undefined;
|
|
60
|
+
if (typeof commandInfo.params !== 'object' || commandInfo.params === null) {
|
|
61
|
+
noteCellMutation(commandInfo.id, false, { reason: 'params-missing' });
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const params = commandInfo.params;
|
|
65
|
+
if (typeof params.subUnitId !== 'string' || typeof params.cellValue !== 'object' || params.cellValue === null) {
|
|
66
|
+
noteCellMutation(commandInfo.id, false, { reason: 'cellValue-missing', keys: cellKeysOf(params.cellValue) });
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const cells = [];
|
|
70
|
+
const rows = params.cellValue;
|
|
71
|
+
for (const [rowKey, rowValue] of Object.entries(rows)) {
|
|
72
|
+
const row = Number(rowKey);
|
|
73
|
+
if (!Number.isInteger(row) || typeof rowValue !== 'object' || rowValue === null)
|
|
74
|
+
return undefined;
|
|
75
|
+
for (const [columnKey, cellValue] of Object.entries(rowValue)) {
|
|
76
|
+
const column = Number(columnKey);
|
|
77
|
+
if (!Number.isInteger(column)) {
|
|
78
|
+
noteCellMutation(commandInfo.id, false, { reason: 'bad-column-key', keys: cellKeysOf(params.cellValue) });
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
if (cellValue === null) {
|
|
82
|
+
cells.push({ row, column, value: null });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (typeof cellValue !== 'object' || Array.isArray(cellValue)) {
|
|
86
|
+
noteCellMutation(commandInfo.id, false, { reason: 'cell-not-object', keys: cellKeysOf(params.cellValue) });
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const cell = cellValue;
|
|
90
|
+
const unsupportedKeys = Object.keys(cell).filter(key => !['v', 'f', 't'].includes(key));
|
|
91
|
+
if (unsupportedKeys.length > 0) {
|
|
92
|
+
noteCellMutation(commandInfo.id, false, { reason: 'unsupported-cell-keys', keys: Object.keys(cell) });
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const value = cell.v;
|
|
96
|
+
if (value !== undefined && value !== null && typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean')
|
|
97
|
+
return undefined;
|
|
98
|
+
const formula = normalizeCellFormula(cell.f);
|
|
99
|
+
cells.push({ row, column, value: value === undefined ? null : value, ...(formula === undefined ? {} : { formula }) });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (cells.length === 0) {
|
|
103
|
+
noteCellMutation(commandInfo.id, false, { reason: 'no-cells', keys: cellKeysOf(params.cellValue) });
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
noteCellMutation(commandInfo.id, true);
|
|
107
|
+
return { type: 'update_cells', payload: { sheetId: params.subUnitId, cells } };
|
|
108
|
+
}
|
|
109
|
+
/** Convert selection/focus commands into a compact ephemeral presence event.
|
|
110
|
+
* Unknown commands are intentionally ignored so UI internals never become
|
|
111
|
+
* durable edits or high-volume network traffic. */
|
|
112
|
+
export function toPresence(commandInfo) {
|
|
113
|
+
const commandId = commandInfo.id.toLowerCase();
|
|
114
|
+
let kind;
|
|
115
|
+
if (commandId.includes('selection') || commandId.includes('set-selections'))
|
|
116
|
+
kind = 'selection';
|
|
117
|
+
else if (commandId.includes('activate') || commandId.includes('active') || commandId.includes('focus') || commandId.includes('current-sheet'))
|
|
118
|
+
kind = 'active-sheet';
|
|
119
|
+
else
|
|
120
|
+
return undefined;
|
|
121
|
+
const params = typeof commandInfo.params === 'object' && commandInfo.params !== null
|
|
122
|
+
? commandInfo.params
|
|
123
|
+
: {};
|
|
124
|
+
const payload = { commandId };
|
|
125
|
+
for (const key of ['subUnitId', 'unitId', 'sheetId']) {
|
|
126
|
+
if (typeof params[key] === 'string')
|
|
127
|
+
payload[key] = params[key];
|
|
128
|
+
}
|
|
129
|
+
const range = params.range;
|
|
130
|
+
if (typeof range === 'object' && range !== null && !Array.isArray(range)) {
|
|
131
|
+
const candidate = range;
|
|
132
|
+
const safeRange = {};
|
|
133
|
+
for (const key of ['startRow', 'startColumn', 'endRow', 'endColumn']) {
|
|
134
|
+
if (typeof candidate[key] === 'number' && Number.isFinite(candidate[key]))
|
|
135
|
+
safeRange[key] = candidate[key];
|
|
136
|
+
}
|
|
137
|
+
if (Object.keys(safeRange).length > 0)
|
|
138
|
+
payload.range = safeRange;
|
|
139
|
+
}
|
|
140
|
+
return { kind, payload };
|
|
141
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heavy Univer engine for dsh-data-table: the sheets-core preset
|
|
3
|
+
* mount plus the free feature presets (filter/sort/find-replace/conditional
|
|
4
|
+
* formatting/data validation/drawing/hyper-link/note/thread-comment/table)
|
|
5
|
+
* and the Univer-native CSV/Excel export plugin. Bundled as a self-contained IIFE chunk
|
|
6
|
+
* (`lib/univer-client.js`) served on demand by the node half — the ~16MB
|
|
7
|
+
* Univer graph never enters the boot bundle.
|
|
8
|
+
* @module dsh-data-table/univer-engine
|
|
9
|
+
*/
|
|
10
|
+
import type { WorkbookMount, WorkbookMountOptions } from './chunk.ts';
|
|
11
|
+
export type { WorkbookDecoration, WorkbookDecorationCell, WorkbookDecorationTone, WorkbookMount, WorkbookMountOptions } from './chunk.ts';
|
|
12
|
+
import '@univerjs/presets/lib/styles/preset-sheets-core.css';
|
|
13
|
+
import '@univerjs/presets/lib/styles/preset-sheets-filter.css';
|
|
14
|
+
import '@univerjs/presets/lib/styles/preset-sheets-sort.css';
|
|
15
|
+
import '@univerjs/presets/lib/styles/preset-sheets-find-replace.css';
|
|
16
|
+
import '@univerjs/presets/lib/styles/preset-sheets-conditional-formatting.css';
|
|
17
|
+
import '@univerjs/presets/lib/styles/preset-sheets-data-validation.css';
|
|
18
|
+
import '@univerjs/presets/lib/styles/preset-sheets-drawing.css';
|
|
19
|
+
import '@univerjs/presets/lib/styles/preset-sheets-hyper-link.css';
|
|
20
|
+
import '@univerjs/presets/lib/styles/preset-sheets-note.css';
|
|
21
|
+
import '@univerjs/presets/lib/styles/preset-sheets-thread-comment.css';
|
|
22
|
+
import '@univerjs/presets/lib/styles/preset-sheets-table.css';
|
|
23
|
+
import '@univerjs/sheets-crosshair-highlight/lib/index.css';
|
|
24
|
+
import './overrides.css';
|
|
25
|
+
import type { WorkbookLocalChange, WorkbookPresencePayload, WorkbookSelectionRange } from '../types.ts';
|
|
26
|
+
/**
|
|
27
|
+
* Mount one resident Univer engine into a container; the container must be in
|
|
28
|
+
* the DOM and the chunk must already be loaded. The workbook data is an
|
|
29
|
+
* Univer snapshot (IWorkbookData-shaped) that the residency renders; `save()`
|
|
30
|
+
* returns the current snapshot for the client half to persist. The client
|
|
31
|
+
* batches ten durable user steps (or flushes on Ctrl/Cmd+S) into one Version.
|
|
32
|
+
*/
|
|
33
|
+
export declare function mountWorkbook(container: HTMLElement, workbookData: object, onDirty?: (change?: WorkbookLocalChange) => void, onPresence?: (presence: WorkbookPresencePayload) => void, options?: WorkbookMountOptions, onSelection?: (ranges: readonly WorkbookSelectionRange[]) => void): WorkbookMount;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heavy Univer engine for dsh-data-table: the sheets-core preset
|
|
3
|
+
* mount plus the free feature presets (filter/sort/find-replace/conditional
|
|
4
|
+
* formatting/data validation/drawing/hyper-link/note/thread-comment/table)
|
|
5
|
+
* and the Univer-native CSV/Excel export plugin. Bundled as a self-contained IIFE chunk
|
|
6
|
+
* (`lib/univer-client.js`) served on demand by the node half — the ~16MB
|
|
7
|
+
* Univer graph never enters the boot bundle.
|
|
8
|
+
* @module dsh-data-table/univer-engine
|
|
9
|
+
*/
|
|
10
|
+
import { createUniver, defaultTheme, LocaleType, merge, UniverInstanceType, } from '@univerjs/presets';
|
|
11
|
+
// The es-path values carry runtime code; the honest types live in the types tree.
|
|
12
|
+
import { UniverSheetsCorePreset } from '@univerjs/presets/lib/es/preset-sheets-core/index.js';
|
|
13
|
+
import { UniverSheetsFilterPreset } from '@univerjs/presets/lib/es/preset-sheets-filter/index.js';
|
|
14
|
+
import { UniverSheetsSortPreset } from '@univerjs/presets/lib/es/preset-sheets-sort/index.js';
|
|
15
|
+
import { UniverSheetsFindReplacePreset } from '@univerjs/presets/lib/es/preset-sheets-find-replace/index.js';
|
|
16
|
+
import { UniverSheetsConditionalFormattingPreset } from '@univerjs/presets/lib/es/preset-sheets-conditional-formatting/index.js';
|
|
17
|
+
import { UniverSheetsDataValidationPreset } from '@univerjs/presets/lib/es/preset-sheets-data-validation/index.js';
|
|
18
|
+
import { UniverSheetsDrawingPreset } from '@univerjs/presets/lib/es/preset-sheets-drawing/index.js';
|
|
19
|
+
import { UniverSheetsHyperLinkPreset } from '@univerjs/presets/lib/es/preset-sheets-hyper-link/index.js';
|
|
20
|
+
import { UniverSheetsNotePreset } from '@univerjs/presets/lib/es/preset-sheets-note/index.js';
|
|
21
|
+
import { UniverSheetsThreadCommentPreset } from '@univerjs/presets/lib/es/preset-sheets-thread-comment/index.js';
|
|
22
|
+
import { UniverSheetsTablePreset } from '@univerjs/presets/lib/es/preset-sheets-table/index.js';
|
|
23
|
+
import { UniverSheetsCrosshairHighlightPlugin } from '@univerjs/sheets-crosshair-highlight';
|
|
24
|
+
import coreZhCN from '@univerjs/presets/lib/es/preset-sheets-core/locales/zh-CN.js';
|
|
25
|
+
import coreEnUS from '@univerjs/presets/lib/es/preset-sheets-core/locales/en-US.js';
|
|
26
|
+
import filterZhCN from '@univerjs/presets/lib/es/preset-sheets-filter/locales/zh-CN.js';
|
|
27
|
+
import filterEnUS from '@univerjs/presets/lib/es/preset-sheets-filter/locales/en-US.js';
|
|
28
|
+
import sortZhCN from '@univerjs/presets/lib/es/preset-sheets-sort/locales/zh-CN.js';
|
|
29
|
+
import sortEnUS from '@univerjs/presets/lib/es/preset-sheets-sort/locales/en-US.js';
|
|
30
|
+
import findReplaceZhCN from '@univerjs/presets/lib/es/preset-sheets-find-replace/locales/zh-CN.js';
|
|
31
|
+
import findReplaceEnUS from '@univerjs/presets/lib/es/preset-sheets-find-replace/locales/en-US.js';
|
|
32
|
+
import condFmtZhCN from '@univerjs/presets/lib/es/preset-sheets-conditional-formatting/locales/zh-CN.js';
|
|
33
|
+
import condFmtEnUS from '@univerjs/presets/lib/es/preset-sheets-conditional-formatting/locales/en-US.js';
|
|
34
|
+
import dataValZhCN from '@univerjs/presets/lib/es/preset-sheets-data-validation/locales/zh-CN.js';
|
|
35
|
+
import dataValEnUS from '@univerjs/presets/lib/es/preset-sheets-data-validation/locales/en-US.js';
|
|
36
|
+
import drawingZhCN from '@univerjs/presets/lib/es/preset-sheets-drawing/locales/zh-CN.js';
|
|
37
|
+
import drawingEnUS from '@univerjs/presets/lib/es/preset-sheets-drawing/locales/en-US.js';
|
|
38
|
+
import hyperLinkZhCN from '@univerjs/presets/lib/es/preset-sheets-hyper-link/locales/zh-CN.js';
|
|
39
|
+
import hyperLinkEnUS from '@univerjs/presets/lib/es/preset-sheets-hyper-link/locales/en-US.js';
|
|
40
|
+
import noteZhCN from '@univerjs/presets/lib/es/preset-sheets-note/locales/zh-CN.js';
|
|
41
|
+
import noteEnUS from '@univerjs/presets/lib/es/preset-sheets-note/locales/en-US.js';
|
|
42
|
+
import threadZhCN from '@univerjs/presets/lib/es/preset-sheets-thread-comment/locales/zh-CN.js';
|
|
43
|
+
import threadEnUS from '@univerjs/presets/lib/es/preset-sheets-thread-comment/locales/en-US.js';
|
|
44
|
+
import tableZhCN from '@univerjs/presets/lib/es/preset-sheets-table/locales/zh-CN.js';
|
|
45
|
+
import tableEnUS from '@univerjs/presets/lib/es/preset-sheets-table/locales/en-US.js';
|
|
46
|
+
import crosshairZhCN from '@univerjs/sheets-crosshair-highlight/locale/zh-CN';
|
|
47
|
+
import crosshairEnUS from '@univerjs/sheets-crosshair-highlight/locale/en-US';
|
|
48
|
+
// Univer ships its styles as separate artifacts; without them the workbench
|
|
49
|
+
// renders unstyled (toolbar stacked vertically). The client build turns these
|
|
50
|
+
// imports into inlined style injections.
|
|
51
|
+
import '@univerjs/presets/lib/styles/preset-sheets-core.css';
|
|
52
|
+
import '@univerjs/presets/lib/styles/preset-sheets-filter.css';
|
|
53
|
+
import '@univerjs/presets/lib/styles/preset-sheets-sort.css';
|
|
54
|
+
import '@univerjs/presets/lib/styles/preset-sheets-find-replace.css';
|
|
55
|
+
import '@univerjs/presets/lib/styles/preset-sheets-conditional-formatting.css';
|
|
56
|
+
import '@univerjs/presets/lib/styles/preset-sheets-data-validation.css';
|
|
57
|
+
import '@univerjs/presets/lib/styles/preset-sheets-drawing.css';
|
|
58
|
+
import '@univerjs/presets/lib/styles/preset-sheets-hyper-link.css';
|
|
59
|
+
import '@univerjs/presets/lib/styles/preset-sheets-note.css';
|
|
60
|
+
import '@univerjs/presets/lib/styles/preset-sheets-thread-comment.css';
|
|
61
|
+
import '@univerjs/presets/lib/styles/preset-sheets-table.css';
|
|
62
|
+
import '@univerjs/sheets-crosshair-highlight/lib/index.css';
|
|
63
|
+
import './overrides.css';
|
|
64
|
+
import { DataSheetExportPlugin } from "./plugins/export.js";
|
|
65
|
+
import { DataSheetCollaborationPlugin } from "./plugins/collaboration.js";
|
|
66
|
+
import { DataSheetHistoryPlugin } from "./plugins/history.js";
|
|
67
|
+
import { getInstalledFontConfigs, withDefaultSheetFont } from "./fonts.js";
|
|
68
|
+
import { shouldPersistUniverMutation } from "../contract/operations.js";
|
|
69
|
+
import { publishMutationAttempt, toLocalCellChange, toPresence } from "./diagnostics.js";
|
|
70
|
+
import { createDecorationApplier } from "./decoration.js";
|
|
71
|
+
import { createOperationApplier } from "./apply-operation.js";
|
|
72
|
+
/** Default sheet extent (Univer's own default), so data lands on a full-size grid. */
|
|
73
|
+
/**
|
|
74
|
+
* Load marker + default probe value.
|
|
75
|
+
*
|
|
76
|
+
* The engine chunk is a classic script the browser may still serve from cache,
|
|
77
|
+
* so "is my bundle current?" was impossible to answer from the console. These
|
|
78
|
+
* two globals are set as soon as the chunk evaluates:
|
|
79
|
+
*
|
|
80
|
+
* __dshDataSheetEngine // { version, loadedAt } — undefined means a stale chunk
|
|
81
|
+
* __dshLastCellMutation // { reason: 'no-persisted-mutation-yet' } until you edit
|
|
82
|
+
*/
|
|
83
|
+
if (typeof window !== 'undefined') {
|
|
84
|
+
const win = window;
|
|
85
|
+
win.__dshDataSheetEngine = { version: 'v3.2', loadedAt: new Date().toISOString() };
|
|
86
|
+
// One line, so "which engine build is this page running?" is answered by the
|
|
87
|
+
// console itself instead of a hand-typed global.
|
|
88
|
+
console.info('[data-sheet] Univer engine chunk v3.2 loaded · probe: __dshLastCellMutation');
|
|
89
|
+
win.__dshLastCellMutation = { reason: 'no-persisted-mutation-yet' };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Mount one resident Univer engine into a container; the container must be in
|
|
93
|
+
* the DOM and the chunk must already be loaded. The workbook data is an
|
|
94
|
+
* Univer snapshot (IWorkbookData-shaped) that the residency renders; `save()`
|
|
95
|
+
* returns the current snapshot for the client half to persist. The client
|
|
96
|
+
* batches ten durable user steps (or flushes on Ctrl/Cmd+S) into one Version.
|
|
97
|
+
*/
|
|
98
|
+
export function mountWorkbook(container, workbookData, onDirty, onPresence, options = {}, onSelection) {
|
|
99
|
+
const readOnly = options.readOnly === true;
|
|
100
|
+
const decoration = options.decoration;
|
|
101
|
+
const installedFontConfigs = getInstalledFontConfigs();
|
|
102
|
+
let openHistory;
|
|
103
|
+
let refreshSelection = () => { };
|
|
104
|
+
const onUniverMutation = (commandInfo, options) => {
|
|
105
|
+
if (applier.isApplyingRemote() || options?.onlyLocal || options?.fromChangeset || options?.fromCollab)
|
|
106
|
+
return;
|
|
107
|
+
if (!shouldPersistUniverMutation(commandInfo.id)) {
|
|
108
|
+
const presence = toPresence(commandInfo);
|
|
109
|
+
// A preview is not somebody editing: it publishes no editing presence,
|
|
110
|
+
// so peers do not see a phantom collaborator.
|
|
111
|
+
if (presence !== undefined && !readOnly)
|
|
112
|
+
onPresence?.(presence);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Belt and braces with `setEditable(false)` below: even a command that
|
|
116
|
+
// slipped past the permission interceptor is never reported as a change,
|
|
117
|
+
// so a preview can never fork a Version.
|
|
118
|
+
if (readOnly)
|
|
119
|
+
return;
|
|
120
|
+
onPresence?.({ kind: 'editing', payload: { commandId: commandInfo.id } });
|
|
121
|
+
const change = toLocalCellChange(commandInfo);
|
|
122
|
+
publishMutationAttempt(commandInfo.id, change !== undefined);
|
|
123
|
+
onDirty?.(change);
|
|
124
|
+
refreshSelection();
|
|
125
|
+
};
|
|
126
|
+
const { univer, univerAPI } = createUniver({
|
|
127
|
+
// packs and theme; keep both in sync with the official 0.25 usage.
|
|
128
|
+
locale: LocaleType.ZH_CN,
|
|
129
|
+
locales: {
|
|
130
|
+
zhCN: merge({}, coreZhCN, filterZhCN, sortZhCN, findReplaceZhCN, condFmtZhCN, dataValZhCN, drawingZhCN, hyperLinkZhCN, noteZhCN, threadZhCN, tableZhCN, crosshairZhCN),
|
|
131
|
+
enUS: merge({}, coreEnUS, filterEnUS, sortEnUS, findReplaceEnUS, condFmtEnUS, dataValEnUS, drawingEnUS, hyperLinkEnUS, noteEnUS, threadEnUS, tableEnUS, crosshairEnUS),
|
|
132
|
+
},
|
|
133
|
+
theme: defaultTheme,
|
|
134
|
+
plugins: [
|
|
135
|
+
DataSheetExportPlugin,
|
|
136
|
+
[DataSheetHistoryPlugin, { onOpenHistory: () => openHistory?.() }],
|
|
137
|
+
[DataSheetCollaborationPlugin, { onMutation: onUniverMutation }],
|
|
138
|
+
UniverSheetsCrosshairHighlightPlugin,
|
|
139
|
+
],
|
|
140
|
+
presets: [
|
|
141
|
+
UniverSheetsCorePreset({
|
|
142
|
+
container,
|
|
143
|
+
header: true,
|
|
144
|
+
// A preview shows history: the editing chrome would only invite edits
|
|
145
|
+
// that cannot be saved (PRD v3.3 §7.2). Read-only mode keeps the grid,
|
|
146
|
+
// the headers and the sheet tabs, and drops the rest.
|
|
147
|
+
toolbar: !readOnly,
|
|
148
|
+
formulaBar: !readOnly,
|
|
149
|
+
// (`disableEdit` is deliberately *not* passed here: this preset
|
|
150
|
+
// destructures a fixed key set and would drop it silently. It is not
|
|
151
|
+
// needed either — with the workbook permission off, the cell editor
|
|
152
|
+
// refuses to open, measured.)
|
|
153
|
+
statusBarStatistic: true,
|
|
154
|
+
// The footer carries the sheet tabs. A past Version still has several
|
|
155
|
+
// sheets, so switching between them is navigation and must stay
|
|
156
|
+
// available in a read-only view (GUI feedback 2026-09-19).
|
|
157
|
+
footer: true,
|
|
158
|
+
contextMenu: !readOnly,
|
|
159
|
+
// Register custom families during UI initialization so they are
|
|
160
|
+
// present in the font dropdown (addFonts alone is too late for the
|
|
161
|
+
// initial font-family component in this Univer version).
|
|
162
|
+
customFontFamily: {
|
|
163
|
+
list: installedFontConfigs,
|
|
164
|
+
override: true,
|
|
165
|
+
},
|
|
166
|
+
}),
|
|
167
|
+
// Free feature presets (mirrors the best_excel plugin set). Datasheet
|
|
168
|
+
// collaboration is provided by its own dependency-free adapter above;
|
|
169
|
+
// the commercial Univer collaboration preset is intentionally unused.
|
|
170
|
+
UniverSheetsFilterPreset(),
|
|
171
|
+
UniverSheetsSortPreset(),
|
|
172
|
+
UniverSheetsFindReplacePreset(),
|
|
173
|
+
UniverSheetsConditionalFormattingPreset(),
|
|
174
|
+
UniverSheetsDataValidationPreset(),
|
|
175
|
+
UniverSheetsDrawingPreset(),
|
|
176
|
+
UniverSheetsHyperLinkPreset(),
|
|
177
|
+
UniverSheetsNotePreset(),
|
|
178
|
+
UniverSheetsThreadCommentPreset(),
|
|
179
|
+
UniverSheetsTablePreset(),
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
// Univer does not download these fonts; the browser uses them when the
|
|
183
|
+
// corresponding family is installed on the user's machine.
|
|
184
|
+
univer.createUnit(UniverInstanceType.UNIVER_SHEET, withDefaultSheetFont(workbookData));
|
|
185
|
+
// Debug seam: mounted engines by container, for live workbook inspection.
|
|
186
|
+
{
|
|
187
|
+
const win = window;
|
|
188
|
+
win.__bestExcelDebugMounts = win.__bestExcelDebugMounts ?? [];
|
|
189
|
+
win.__bestExcelDebugMounts.push({ container, api: univerAPI });
|
|
190
|
+
}
|
|
191
|
+
// The sheets facade augments FUniver with the workbook API; the core type
|
|
192
|
+
// lacks it, so the engine views the facade structurally (see `facade.ts`).
|
|
193
|
+
const sheetsApi = univerAPI;
|
|
194
|
+
const getSheet = (sheetRef) => {
|
|
195
|
+
const workbook = sheetsApi.getActiveWorkbook();
|
|
196
|
+
if (workbook === null)
|
|
197
|
+
return null;
|
|
198
|
+
if (sheetRef !== undefined)
|
|
199
|
+
return workbook.getSheetBySheetId(sheetRef) ?? workbook.getSheetByName(sheetRef);
|
|
200
|
+
return workbook.getSheetBySheetId('sheet1') ?? null;
|
|
201
|
+
};
|
|
202
|
+
let selectionSubscription;
|
|
203
|
+
let currentSelectionRanges = [];
|
|
204
|
+
const projectSelections = (ranges) => {
|
|
205
|
+
const workbook = sheetsApi.getActiveWorkbook();
|
|
206
|
+
if (workbook === null)
|
|
207
|
+
return [];
|
|
208
|
+
const activeSheetId = workbook.getActiveSheet?.()?.getSheetId?.();
|
|
209
|
+
const projected = [];
|
|
210
|
+
for (const range of ranges.slice(0, 40)) {
|
|
211
|
+
const sheetId = range.sheetId ?? activeSheetId;
|
|
212
|
+
if (sheetId === undefined)
|
|
213
|
+
continue;
|
|
214
|
+
const sheet = workbook.getSheetBySheetId(sheetId);
|
|
215
|
+
if (sheet === null)
|
|
216
|
+
continue;
|
|
217
|
+
const startRow = Math.max(0, Math.floor(range.startRow));
|
|
218
|
+
const startColumn = Math.max(0, Math.floor(range.startColumn));
|
|
219
|
+
const endRow = Math.max(startRow, Math.floor(range.endRow));
|
|
220
|
+
const endColumn = Math.max(startColumn, Math.floor(range.endColumn));
|
|
221
|
+
const values = sheet.getRange(startRow, startColumn, Math.min(endRow - startRow + 1, 10), Math.min(endColumn - startColumn + 1, 20)).getValues?.() ?? [];
|
|
222
|
+
projected.push({
|
|
223
|
+
sheetId,
|
|
224
|
+
sheetName: sheet.getSheetName?.() ?? sheetId,
|
|
225
|
+
startRow,
|
|
226
|
+
startColumn,
|
|
227
|
+
endRow,
|
|
228
|
+
endColumn,
|
|
229
|
+
values,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return projected;
|
|
233
|
+
};
|
|
234
|
+
const publishSelections = (ranges) => {
|
|
235
|
+
currentSelectionRanges = [...ranges];
|
|
236
|
+
onSelection?.(projectSelections(currentSelectionRanges));
|
|
237
|
+
};
|
|
238
|
+
refreshSelection = () => {
|
|
239
|
+
if (currentSelectionRanges.length > 0)
|
|
240
|
+
onSelection?.(projectSelections(currentSelectionRanges));
|
|
241
|
+
};
|
|
242
|
+
const bindSelectionWatcher = () => {
|
|
243
|
+
selectionSubscription?.dispose();
|
|
244
|
+
selectionSubscription = undefined;
|
|
245
|
+
currentSelectionRanges = [];
|
|
246
|
+
onSelection?.([]);
|
|
247
|
+
const workbook = sheetsApi.getActiveWorkbook();
|
|
248
|
+
if (workbook?.onSelectionChange === undefined)
|
|
249
|
+
return;
|
|
250
|
+
selectionSubscription = workbook.onSelectionChange(ranges => {
|
|
251
|
+
if (sheetsApi.getActiveWorkbook()?.getId() !== workbook.getId())
|
|
252
|
+
return;
|
|
253
|
+
publishSelections(ranges);
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
bindSelectionWatcher();
|
|
257
|
+
/**
|
|
258
|
+
* Show a different workbook **without rebuilding Univer** (PRD v3.5 §7.2).
|
|
259
|
+
*
|
|
260
|
+
* Switching the inspected Version used to change the canvas key, which
|
|
261
|
+
* unmounted the residency and called `createUniver` again — re-registering
|
|
262
|
+
* every plugin and rebuilding the whole DI graph for a change that is only
|
|
263
|
+
* "different cells". Swapping the *unit* on the same engine keeps the grid,
|
|
264
|
+
* the sheet tabs and the scroll position, and removes the re-init cost.
|
|
265
|
+
*
|
|
266
|
+
* A fresh unit also means the previous Version's diff tint disappears with
|
|
267
|
+
* it, so there is nothing to un-paint.
|
|
268
|
+
*/
|
|
269
|
+
const decoration_ = createDecorationApplier({ sheetsApi, getSheet, readOnly });
|
|
270
|
+
// Paint on the **mount** path too, not only in `swapWorkbook`. Entering inspect
|
|
271
|
+
// remounts the canvas (`preview === null` means there is no residency to swap),
|
|
272
|
+
// so the mount is the *first* preview a reader ever sees. Applying the plan
|
|
273
|
+
// only when swapping dropped both the diff tint and the read-only lock on that
|
|
274
|
+
// first look — the cells were counted in the bar but nothing was painted, and
|
|
275
|
+
// the unit stayed editable. Restores the pre-split behaviour, where the mount
|
|
276
|
+
// called the same thing (`if (readOnly || decoration !== undefined) apply…`).
|
|
277
|
+
if (readOnly || decoration !== undefined)
|
|
278
|
+
decoration_.apply(decoration);
|
|
279
|
+
const applier = createOperationApplier({ sheetsApi, getSheet });
|
|
280
|
+
const swapWorkbook = (next, options = {}) => {
|
|
281
|
+
const previousId = sheetsApi.getActiveWorkbook()?.getId();
|
|
282
|
+
try {
|
|
283
|
+
univer.createUnit(UniverInstanceType.UNIVER_SHEET, withDefaultSheetFont(next));
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
bindSelectionWatcher();
|
|
289
|
+
decoration_.apply(options.decoration);
|
|
290
|
+
if (previousId !== undefined) {
|
|
291
|
+
try {
|
|
292
|
+
sheetsApi.disposeUnit?.(previousId);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// A unit that refuses to dispose is a leak, not a broken canvas.
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
swapWorkbook,
|
|
302
|
+
save: () => {
|
|
303
|
+
const wb = sheetsApi.getActiveWorkbook();
|
|
304
|
+
if (wb === null)
|
|
305
|
+
return workbookData;
|
|
306
|
+
const snapshot = wb.getSnapshot();
|
|
307
|
+
if (typeof snapshot === 'object' && snapshot !== null && typeof snapshot.sheets === 'object') {
|
|
308
|
+
const sheets = snapshot.sheets;
|
|
309
|
+
for (const [sheetId, meta] of applier.liveSheetMetadata.entries()) {
|
|
310
|
+
const sheet = sheets[sheetId];
|
|
311
|
+
if (sheet !== undefined)
|
|
312
|
+
sheet.dataSheetMeta = meta;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return snapshot;
|
|
316
|
+
},
|
|
317
|
+
applyOperation: applier.apply,
|
|
318
|
+
focusRange: (target) => {
|
|
319
|
+
const workbook = sheetsApi.getActiveWorkbook();
|
|
320
|
+
const sheet = workbook?.getSheetBySheetId(target.sheetId);
|
|
321
|
+
if (workbook === null || workbook === undefined || sheet === null || sheet === undefined || workbook.setActiveRange === undefined)
|
|
322
|
+
return false;
|
|
323
|
+
workbook.setActiveSheet?.(sheet);
|
|
324
|
+
const range = sheet.getRange(target.startRow, target.startColumn, target.endRow - target.startRow + 1, target.endColumn - target.startColumn + 1);
|
|
325
|
+
workbook.setActiveRange(range);
|
|
326
|
+
return true;
|
|
327
|
+
},
|
|
328
|
+
dispose: () => {
|
|
329
|
+
selectionSubscription?.dispose();
|
|
330
|
+
selectionSubscription = undefined;
|
|
331
|
+
univer.dispose();
|
|
332
|
+
const win = window;
|
|
333
|
+
if (win.__bestExcelDebugMounts !== undefined) {
|
|
334
|
+
win.__bestExcelDebugMounts = win.__bestExcelDebugMounts.filter(entry => entry.container !== container);
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chunk entry for dsh-data-table. Built as a self-contained IIFE
|
|
3
|
+
* (`lib/univer-client.js`, Univer fully inlined) and loaded as a classic
|
|
4
|
+
* script on first sheet render; it hands the engine surface to the client
|
|
5
|
+
* half through a global so the ~16MB graph never enters the boot bundle.
|
|
6
|
+
* @module dsh-data-table/univer/entry
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chunk entry for dsh-data-table. Built as a self-contained IIFE
|
|
3
|
+
* (`lib/univer-client.js`, Univer fully inlined) and loaded as a classic
|
|
4
|
+
* script on first sheet render; it hands the engine surface to the client
|
|
5
|
+
* half through a global so the ~16MB graph never enters the boot bundle.
|
|
6
|
+
* @module dsh-data-table/univer/entry
|
|
7
|
+
*/
|
|
8
|
+
import { mountWorkbook } from "./engine.js";
|
|
9
|
+
// The interface and the `window` global live in ./chunk.ts so the loader
|
|
10
|
+
// in the client bundle cannot drift from the chunk it loads.
|
|
11
|
+
window.__bestExcelUniver = { mountWorkbook };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Univer facade surface this adapter actually uses (docs/issue/0022 P4).
|
|
3
|
+
*
|
|
4
|
+
* The sheets facade augments `FUniver` with `getActiveWorkbook`/`getSnapshot`,
|
|
5
|
+
* which the core type does not declare, so the engine views it structurally. It
|
|
6
|
+
* is declared once here because three modules need the same view of it —
|
|
7
|
+
* decoration, the operation applier and the engine — and three copies would
|
|
8
|
+
* drift the moment one of them used a facade method the others did not declare.
|
|
9
|
+
*/
|
|
10
|
+
import type { WorkbookRange } from '../types.ts';
|
|
11
|
+
export interface UniverRange {
|
|
12
|
+
getValue?(): unknown;
|
|
13
|
+
getValues?(): unknown[][];
|
|
14
|
+
setValue(value: unknown): unknown;
|
|
15
|
+
clearContent(): unknown;
|
|
16
|
+
setValues(value: unknown): unknown;
|
|
17
|
+
getRange?(): WorkbookRange;
|
|
18
|
+
/** Tint one cell; the diff overlay's only painting primitive. */
|
|
19
|
+
setBackgroundColor?(color: string): unknown | Promise<unknown>;
|
|
20
|
+
setFontColor?(color: string): unknown;
|
|
21
|
+
setFontFamily?(family: string): unknown;
|
|
22
|
+
setFontSize?(size: number): unknown;
|
|
23
|
+
setFontWeight?(weight: 'bold' | 'normal' | null): unknown;
|
|
24
|
+
setFontStyle?(style: 'italic' | 'normal' | null): unknown;
|
|
25
|
+
setFontLine?(line: 'underline' | 'line-through' | 'none' | null): unknown;
|
|
26
|
+
setHorizontalAlignment?(alignment: 'left' | 'center' | 'normal'): unknown;
|
|
27
|
+
setVerticalAlignment?(alignment: 'top' | 'middle' | 'bottom'): unknown;
|
|
28
|
+
setTextRotation?(rotation: number): unknown;
|
|
29
|
+
sort?(column: number | {
|
|
30
|
+
column: number;
|
|
31
|
+
ascending: boolean;
|
|
32
|
+
}): unknown;
|
|
33
|
+
merge?(options?: {
|
|
34
|
+
defaultMerge?: boolean;
|
|
35
|
+
isForceMerge?: boolean;
|
|
36
|
+
}): unknown;
|
|
37
|
+
breakApart?(): unknown;
|
|
38
|
+
/** 0 = shift cells left, 1 = shift cells up (Univer facade enum). */
|
|
39
|
+
deleteCells?: (direction: 0 | 1) => unknown;
|
|
40
|
+
setHyperLink?(url: string, label?: string): Promise<boolean>;
|
|
41
|
+
cancelHyperLink?(): boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface UniverSheet {
|
|
44
|
+
getSheetId?: () => string;
|
|
45
|
+
getSheetName?: () => string;
|
|
46
|
+
getRange(row: number, column: number, numRows?: number, numColumns?: number): UniverRange;
|
|
47
|
+
deleteRows?: (rowPosition: number, howMany?: number) => unknown;
|
|
48
|
+
insertRows?: (rowIndex: number, numRows?: number) => unknown;
|
|
49
|
+
deleteColumns?: (columnPosition: number, howMany?: number) => unknown;
|
|
50
|
+
insertColumns?: (columnIndex: number, numColumns?: number) => unknown;
|
|
51
|
+
setName?: (name: string) => unknown;
|
|
52
|
+
setColumnWidth?: (columnPosition: number, width: number) => unknown;
|
|
53
|
+
setRowHeight?: (rowPosition: number, height: number) => unknown;
|
|
54
|
+
setFreeze?: (freeze: {
|
|
55
|
+
startRow: number;
|
|
56
|
+
startColumn: number;
|
|
57
|
+
xSplit: number;
|
|
58
|
+
ySplit: number;
|
|
59
|
+
}) => unknown;
|
|
60
|
+
cancelFreeze?: () => unknown;
|
|
61
|
+
getLastRow?: () => number;
|
|
62
|
+
getMaxColumns?: () => number;
|
|
63
|
+
getMaxRows?: () => number;
|
|
64
|
+
setColumnCount?: (count: number) => unknown;
|
|
65
|
+
setRowCount?: (count: number) => unknown;
|
|
66
|
+
}
|
|
67
|
+
export interface UniverWorkbook {
|
|
68
|
+
getId(): string;
|
|
69
|
+
getSnapshot(): unknown;
|
|
70
|
+
getSheetBySheetId(sheetId: string): UniverSheet | null;
|
|
71
|
+
getSheetByName(name: string): UniverSheet | null;
|
|
72
|
+
getActiveSheet?(): UniverSheet | null;
|
|
73
|
+
onSelectionChange?(listener: (ranges: readonly (WorkbookRange & {
|
|
74
|
+
sheetId?: string;
|
|
75
|
+
})[]) => void): {
|
|
76
|
+
dispose(): void;
|
|
77
|
+
};
|
|
78
|
+
create(name: string, rows: number, columns: number, options?: {
|
|
79
|
+
sheet?: {
|
|
80
|
+
id?: string;
|
|
81
|
+
};
|
|
82
|
+
}): unknown;
|
|
83
|
+
deleteSheet?(sheet: string | UniverSheet): unknown;
|
|
84
|
+
/** Workbook-level edit permission (docs/issue/0002 PRD v3.2 §7.2). */
|
|
85
|
+
setEditable?(value: boolean): unknown;
|
|
86
|
+
/**
|
|
87
|
+
* The permission facade behind that call, for *reading back* what was set.
|
|
88
|
+
* `canEdit()` is the only way to tell whether the lock actually landed — see
|
|
89
|
+
* `lockWorkbook` in `decoration.ts` for why that question is not rhetorical.
|
|
90
|
+
*/
|
|
91
|
+
getWorkbookPermission?(): {
|
|
92
|
+
canEdit?(): boolean;
|
|
93
|
+
} | null;
|
|
94
|
+
/** Select a range; the facade scrolls the active range into view. */
|
|
95
|
+
setActiveRange?(range: unknown): unknown;
|
|
96
|
+
/** Activate a sheet before selecting a range on it. */
|
|
97
|
+
setActiveSheet?(sheet: unknown): unknown;
|
|
98
|
+
}
|
|
99
|
+
/** The facade's workbook-scoped API, as this adapter uses it. */
|
|
100
|
+
export interface SheetsApi {
|
|
101
|
+
/** Dispose a unit without tearing the engine down (used by `swapWorkbook`). */
|
|
102
|
+
disposeUnit?(unitId: string): boolean;
|
|
103
|
+
getActiveWorkbook(): UniverWorkbook | null;
|
|
104
|
+
executeCommand(id: string, params: unknown, options?: unknown): Promise<unknown>;
|
|
105
|
+
}
|
|
106
|
+
/** Resolve a sheet by id, by name, or the default first sheet. */
|
|
107
|
+
export type SheetResolver = (sheetRef: string | undefined) => UniverSheet | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|