@ricsam/formula-engine 0.2.7 → 0.2.9
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/README.md +1 -3
- package/dist/cjs/core/engine.cjs +518 -149
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/dependency-manager.cjs.map +2 -2
- package/dist/cjs/core/managers/evaluation-manager.cjs.map +1 -1
- package/dist/cjs/core/mutation-invalidation.cjs +241 -0
- package/dist/cjs/core/mutation-invalidation.cjs.map +10 -0
- package/dist/cjs/lib.cjs +2 -13
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/engine.mjs +532 -190
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/dependency-manager.mjs.map +2 -2
- package/dist/mjs/core/managers/evaluation-manager.mjs.map +1 -1
- package/dist/mjs/core/mutation-invalidation.mjs +201 -0
- package/dist/mjs/core/mutation-invalidation.mjs.map +10 -0
- package/dist/mjs/lib.mjs +2 -13
- package/dist/mjs/lib.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/engine.d.ts +17 -116
- package/dist/types/core/managers/dependency-manager.d.ts +1 -1
- package/dist/types/core/managers/evaluation-manager.d.ts +1 -1
- package/dist/types/core/mutation-invalidation.d.ts +46 -0
- package/dist/types/lib.d.ts +0 -8
- package/package.json +1 -1
- package/dist/cjs/core/commands/command-executor.cjs +0 -149
- package/dist/cjs/core/commands/command-executor.cjs.map +0 -10
- package/dist/cjs/core/commands/content-commands.cjs +0 -857
- package/dist/cjs/core/commands/content-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/metadata-commands.cjs +0 -160
- package/dist/cjs/core/commands/metadata-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/named-expression-commands.cjs +0 -363
- package/dist/cjs/core/commands/named-expression-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/structure-commands.cjs +0 -696
- package/dist/cjs/core/commands/structure-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/style-commands.cjs +0 -229
- package/dist/cjs/core/commands/style-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/table-commands.cjs +0 -495
- package/dist/cjs/core/commands/table-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/types.cjs +0 -99
- package/dist/cjs/core/commands/types.cjs.map +0 -10
- package/dist/cjs/core/managers/schema-manager.cjs +0 -374
- package/dist/cjs/core/managers/schema-manager.cjs.map +0 -10
- package/dist/cjs/core/schema/cell-orm.cjs +0 -76
- package/dist/cjs/core/schema/cell-orm.cjs.map +0 -10
- package/dist/cjs/core/schema/grid-orm.cjs +0 -125
- package/dist/cjs/core/schema/grid-orm.cjs.map +0 -10
- package/dist/cjs/core/schema/schema-builder.cjs +0 -74
- package/dist/cjs/core/schema/schema-builder.cjs.map +0 -10
- package/dist/cjs/core/schema/schema-helpers.cjs +0 -200
- package/dist/cjs/core/schema/schema-helpers.cjs.map +0 -10
- package/dist/cjs/core/schema/schema.cjs +0 -91
- package/dist/cjs/core/schema/schema.cjs.map +0 -10
- package/dist/cjs/core/schema/table-orm.cjs +0 -189
- package/dist/cjs/core/schema/table-orm.cjs.map +0 -10
- package/dist/mjs/core/commands/command-executor.mjs +0 -109
- package/dist/mjs/core/commands/command-executor.mjs.map +0 -10
- package/dist/mjs/core/commands/content-commands.mjs +0 -821
- package/dist/mjs/core/commands/content-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/metadata-commands.mjs +0 -120
- package/dist/mjs/core/commands/metadata-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/named-expression-commands.mjs +0 -323
- package/dist/mjs/core/commands/named-expression-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/structure-commands.mjs +0 -661
- package/dist/mjs/core/commands/structure-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/style-commands.mjs +0 -189
- package/dist/mjs/core/commands/style-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/table-commands.mjs +0 -459
- package/dist/mjs/core/commands/table-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/types.mjs +0 -59
- package/dist/mjs/core/commands/types.mjs.map +0 -10
- package/dist/mjs/core/managers/schema-manager.mjs +0 -334
- package/dist/mjs/core/managers/schema-manager.mjs.map +0 -10
- package/dist/mjs/core/schema/cell-orm.mjs +0 -35
- package/dist/mjs/core/schema/cell-orm.mjs.map +0 -10
- package/dist/mjs/core/schema/grid-orm.mjs +0 -84
- package/dist/mjs/core/schema/grid-orm.mjs.map +0 -10
- package/dist/mjs/core/schema/schema-builder.mjs +0 -34
- package/dist/mjs/core/schema/schema-builder.mjs.map +0 -10
- package/dist/mjs/core/schema/schema-helpers.mjs +0 -160
- package/dist/mjs/core/schema/schema-helpers.mjs.map +0 -10
- package/dist/mjs/core/schema/schema.mjs +0 -51
- package/dist/mjs/core/schema/schema.mjs.map +0 -10
- package/dist/mjs/core/schema/table-orm.mjs +0 -156
- package/dist/mjs/core/schema/table-orm.mjs.map +0 -10
- package/dist/types/core/commands/command-executor.d.ts +0 -81
- package/dist/types/core/commands/content-commands.d.ts +0 -172
- package/dist/types/core/commands/metadata-commands.d.ts +0 -55
- package/dist/types/core/commands/named-expression-commands.d.ts +0 -130
- package/dist/types/core/commands/structure-commands.d.ts +0 -155
- package/dist/types/core/commands/style-commands.d.ts +0 -76
- package/dist/types/core/commands/table-commands.d.ts +0 -119
- package/dist/types/core/commands/types.d.ts +0 -143
- package/dist/types/core/managers/schema-manager.d.ts +0 -142
- package/dist/types/core/schema/cell-orm.d.ts +0 -33
- package/dist/types/core/schema/grid-orm.d.ts +0 -63
- package/dist/types/core/schema/schema-builder.d.ts +0 -16
- package/dist/types/core/schema/schema-helpers.d.ts +0 -49
- package/dist/types/core/schema/schema.d.ts +0 -167
- package/dist/types/core/schema/schema.type-test.d.ts +0 -1
- package/dist/types/core/schema/table-orm.d.ts +0 -46
|
@@ -1,696 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
function __accessProp(key) {
|
|
6
|
-
return this[key];
|
|
7
|
-
}
|
|
8
|
-
var __toCommonJS = (from) => {
|
|
9
|
-
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
-
if (entry)
|
|
11
|
-
return entry;
|
|
12
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (var key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(entry, key))
|
|
16
|
-
__defProp(entry, key, {
|
|
17
|
-
get: __accessProp.bind(from, key),
|
|
18
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
__moduleCache.set(from, entry);
|
|
22
|
-
return entry;
|
|
23
|
-
};
|
|
24
|
-
var __moduleCache;
|
|
25
|
-
var __returnValue = (v) => v;
|
|
26
|
-
function __exportSetter(name, newValue) {
|
|
27
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
-
}
|
|
29
|
-
var __export = (target, all) => {
|
|
30
|
-
for (var name in all)
|
|
31
|
-
__defProp(target, name, {
|
|
32
|
-
get: all[name],
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
set: __exportSetter.bind(all, name)
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/core/commands/structure-commands.ts
|
|
40
|
-
var exports_structure_commands = {};
|
|
41
|
-
__export(exports_structure_commands, {
|
|
42
|
-
RenameWorkbookCommand: () => RenameWorkbookCommand,
|
|
43
|
-
RenameSheetCommand: () => RenameSheetCommand,
|
|
44
|
-
RemoveWorkbookCommand: () => RemoveWorkbookCommand,
|
|
45
|
-
RemoveSheetCommand: () => RemoveSheetCommand,
|
|
46
|
-
CloneWorkbookCommand: () => CloneWorkbookCommand,
|
|
47
|
-
AddWorkbookCommand: () => AddWorkbookCommand,
|
|
48
|
-
AddSheetCommand: () => AddSheetCommand
|
|
49
|
-
});
|
|
50
|
-
module.exports = __toCommonJS(exports_structure_commands);
|
|
51
|
-
var import_types = require("./types.cjs");
|
|
52
|
-
var import_resource_keys = require("../resource-keys.cjs");
|
|
53
|
-
|
|
54
|
-
class AddWorkbookCommand {
|
|
55
|
-
deps;
|
|
56
|
-
workbookName;
|
|
57
|
-
requiresReevaluation = true;
|
|
58
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
59
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
60
|
-
constructor(deps, workbookName) {
|
|
61
|
-
this.deps = deps;
|
|
62
|
-
this.workbookName = workbookName;
|
|
63
|
-
}
|
|
64
|
-
execute() {
|
|
65
|
-
this.deps.workbookManager.addWorkbook(this.workbookName);
|
|
66
|
-
this.deps.namedExpressionManager.addWorkbook(this.workbookName);
|
|
67
|
-
this.deps.tableManager.addWorkbook(this.workbookName);
|
|
68
|
-
this.executeFootprint = {
|
|
69
|
-
touchedCells: [],
|
|
70
|
-
resourceKeys: [import_resource_keys.getWorkbookResourceKey(this.workbookName)]
|
|
71
|
-
};
|
|
72
|
-
this.undoFootprint = {
|
|
73
|
-
touchedCells: [],
|
|
74
|
-
resourceKeys: [import_resource_keys.getWorkbookResourceKey(this.workbookName)],
|
|
75
|
-
removedScopes: [{ type: "workbook", workbookName: this.workbookName }]
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
undo() {
|
|
79
|
-
this.deps.workbookManager.removeWorkbook(this.workbookName);
|
|
80
|
-
this.deps.namedExpressionManager.removeWorkbook(this.workbookName);
|
|
81
|
-
this.deps.tableManager.removeWorkbook(this.workbookName);
|
|
82
|
-
}
|
|
83
|
-
getInvalidationFootprint(phase) {
|
|
84
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
85
|
-
}
|
|
86
|
-
toAction() {
|
|
87
|
-
return {
|
|
88
|
-
type: import_types.ActionTypes.ADD_WORKBOOK,
|
|
89
|
-
payload: { workbookName: this.workbookName }
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function captureWorkbookSnapshot(deps, workbookName) {
|
|
94
|
-
const workbook = deps.workbookManager.getWorkbooks().get(workbookName);
|
|
95
|
-
if (!workbook)
|
|
96
|
-
return;
|
|
97
|
-
const clonedSheets = new Map;
|
|
98
|
-
for (const [name, sheet] of workbook.sheets) {
|
|
99
|
-
clonedSheets.set(name, {
|
|
100
|
-
name: sheet.name,
|
|
101
|
-
index: sheet.index,
|
|
102
|
-
content: new Map(sheet.content),
|
|
103
|
-
metadata: new Map(sheet.metadata),
|
|
104
|
-
sheetMetadata: sheet.sheetMetadata
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const namedExpressions = deps.namedExpressionManager.getNamedExpressions();
|
|
108
|
-
const snapshot = {
|
|
109
|
-
workbook: {
|
|
110
|
-
name: workbook.name,
|
|
111
|
-
sheets: clonedSheets,
|
|
112
|
-
workbookMetadata: workbook.workbookMetadata
|
|
113
|
-
},
|
|
114
|
-
namedExpressions: {
|
|
115
|
-
workbookLevel: new Map(namedExpressions.workbookExpressions.get(workbookName) || []),
|
|
116
|
-
sheetLevel: new Map
|
|
117
|
-
},
|
|
118
|
-
tables: new Map(deps.tableManager.getTables(workbookName)),
|
|
119
|
-
conditionalStyles: deps.styleManager.getAllConditionalStyles().filter((s) => s.areas.some((a) => a.workbookName === workbookName)),
|
|
120
|
-
cellStyles: deps.styleManager.getAllCellStyles().filter((s) => s.areas.some((a) => a.workbookName === workbookName))
|
|
121
|
-
};
|
|
122
|
-
const sheetExpressions = namedExpressions.sheetExpressions.get(workbookName);
|
|
123
|
-
if (sheetExpressions) {
|
|
124
|
-
for (const [sheetName, expressions] of sheetExpressions) {
|
|
125
|
-
snapshot.namedExpressions.sheetLevel.set(sheetName, new Map(expressions));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return snapshot;
|
|
129
|
-
}
|
|
130
|
-
function removeWorkbook(deps, workbookName) {
|
|
131
|
-
deps.workbookManager.removeWorkbook(workbookName);
|
|
132
|
-
deps.namedExpressionManager.removeWorkbook(workbookName);
|
|
133
|
-
deps.tableManager.removeWorkbook(workbookName);
|
|
134
|
-
deps.styleManager.removeWorkbookStyles(workbookName);
|
|
135
|
-
deps.referenceManager.invalidateWorkbook(workbookName);
|
|
136
|
-
}
|
|
137
|
-
function renameWorkbookAcrossManagers(deps, oldName, newName) {
|
|
138
|
-
deps.workbookManager.renameWorkbook({
|
|
139
|
-
workbookName: oldName,
|
|
140
|
-
newWorkbookName: newName
|
|
141
|
-
});
|
|
142
|
-
deps.namedExpressionManager.renameWorkbook({
|
|
143
|
-
workbookName: oldName,
|
|
144
|
-
newWorkbookName: newName
|
|
145
|
-
});
|
|
146
|
-
deps.tableManager.updateTablesForWorkbookRename({
|
|
147
|
-
workbookName: oldName,
|
|
148
|
-
newWorkbookName: newName
|
|
149
|
-
});
|
|
150
|
-
deps.styleManager.updateWorkbookName(oldName, newName);
|
|
151
|
-
const changedCells = deps.workbookManager.updateAllFormulas((formula) => deps.renameWorkbookInFormula({
|
|
152
|
-
formula,
|
|
153
|
-
oldWorkbookName: oldName,
|
|
154
|
-
newWorkbookName: newName
|
|
155
|
-
}));
|
|
156
|
-
deps.referenceManager.updateWorkbookName(oldName, newName);
|
|
157
|
-
deps.apiSchemaManager.updateForWorkbookRename(oldName, newName);
|
|
158
|
-
return changedCells;
|
|
159
|
-
}
|
|
160
|
-
function renameSheetAcrossManagers(deps, opts) {
|
|
161
|
-
deps.workbookManager.renameSheet(opts);
|
|
162
|
-
deps.namedExpressionManager.renameSheet(opts);
|
|
163
|
-
deps.tableManager.updateTablesForSheetRename(opts);
|
|
164
|
-
deps.styleManager.updateSheetName(opts.workbookName, opts.sheetName, opts.newSheetName);
|
|
165
|
-
const changedCells = deps.workbookManager.updateAllFormulas((formula) => deps.renameSheetInFormula({
|
|
166
|
-
formula,
|
|
167
|
-
oldSheetName: opts.sheetName,
|
|
168
|
-
newSheetName: opts.newSheetName
|
|
169
|
-
}));
|
|
170
|
-
deps.referenceManager.updateSheetName(opts.workbookName, opts.sheetName, opts.newSheetName);
|
|
171
|
-
deps.apiSchemaManager.updateForSheetRename(opts.workbookName, opts.sheetName, opts.newSheetName);
|
|
172
|
-
return changedCells;
|
|
173
|
-
}
|
|
174
|
-
function getWorkbookSnapshotResourceKeys(workbookName, snapshot) {
|
|
175
|
-
const resourceKeys = new Set([import_resource_keys.getWorkbookResourceKey(workbookName)]);
|
|
176
|
-
if (!snapshot) {
|
|
177
|
-
return Array.from(resourceKeys);
|
|
178
|
-
}
|
|
179
|
-
for (const tableName of snapshot.tables.keys()) {
|
|
180
|
-
resourceKeys.add(import_resource_keys.getTableResourceKey({ workbookName, tableName }));
|
|
181
|
-
}
|
|
182
|
-
for (const name of snapshot.namedExpressions.workbookLevel.keys()) {
|
|
183
|
-
resourceKeys.add(import_resource_keys.getNamedExpressionResourceKey({ expressionName: name, workbookName }));
|
|
184
|
-
}
|
|
185
|
-
for (const [sheetName, expressions] of snapshot.namedExpressions.sheetLevel) {
|
|
186
|
-
resourceKeys.add(import_resource_keys.getSheetResourceKey({ workbookName, sheetName }));
|
|
187
|
-
for (const name of expressions.keys()) {
|
|
188
|
-
resourceKeys.add(import_resource_keys.getNamedExpressionResourceKey({
|
|
189
|
-
expressionName: name,
|
|
190
|
-
workbookName,
|
|
191
|
-
sheetName
|
|
192
|
-
}));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return Array.from(resourceKeys);
|
|
196
|
-
}
|
|
197
|
-
function getSheetSnapshotResourceKeys(workbookName, sheetName, snapshot) {
|
|
198
|
-
const resourceKeys = new Set([
|
|
199
|
-
import_resource_keys.getWorkbookResourceKey(workbookName),
|
|
200
|
-
import_resource_keys.getSheetResourceKey({ workbookName, sheetName })
|
|
201
|
-
]);
|
|
202
|
-
if (!snapshot) {
|
|
203
|
-
return Array.from(resourceKeys);
|
|
204
|
-
}
|
|
205
|
-
for (const tableName of snapshot.tables.keys()) {
|
|
206
|
-
resourceKeys.add(import_resource_keys.getTableResourceKey({ workbookName, tableName }));
|
|
207
|
-
}
|
|
208
|
-
for (const name of snapshot.namedExpressions.keys()) {
|
|
209
|
-
resourceKeys.add(import_resource_keys.getNamedExpressionResourceKey({
|
|
210
|
-
expressionName: name,
|
|
211
|
-
workbookName,
|
|
212
|
-
sheetName
|
|
213
|
-
}));
|
|
214
|
-
}
|
|
215
|
-
return Array.from(resourceKeys);
|
|
216
|
-
}
|
|
217
|
-
function restoreTables(tableManager, tables, workbookName) {
|
|
218
|
-
for (const [tableName, table] of tables) {
|
|
219
|
-
tableManager.addTable({
|
|
220
|
-
workbookName,
|
|
221
|
-
tableName,
|
|
222
|
-
sheetName: table.sheetName,
|
|
223
|
-
start: `${String.fromCharCode(65 + table.start.colIndex)}${table.start.rowIndex + 1}`,
|
|
224
|
-
numRows: table.endRow,
|
|
225
|
-
numCols: table.headers.size,
|
|
226
|
-
getCellValue: () => {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
function restoreStyles(styleManager, conditionalStyles, cellStyles) {
|
|
233
|
-
for (const style of conditionalStyles) {
|
|
234
|
-
styleManager.addConditionalStyle(style);
|
|
235
|
-
}
|
|
236
|
-
for (const style of cellStyles) {
|
|
237
|
-
styleManager.addCellStyle(style);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
class RemoveWorkbookCommand {
|
|
242
|
-
deps;
|
|
243
|
-
workbookName;
|
|
244
|
-
requiresReevaluation = true;
|
|
245
|
-
snapshot;
|
|
246
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
247
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
248
|
-
constructor(deps, workbookName) {
|
|
249
|
-
this.deps = deps;
|
|
250
|
-
this.workbookName = workbookName;
|
|
251
|
-
}
|
|
252
|
-
execute() {
|
|
253
|
-
this.snapshot = captureWorkbookSnapshot(this.deps, this.workbookName);
|
|
254
|
-
removeWorkbook(this.deps, this.workbookName);
|
|
255
|
-
const resourceKeys = getWorkbookSnapshotResourceKeys(this.workbookName, this.snapshot);
|
|
256
|
-
this.executeFootprint = {
|
|
257
|
-
touchedCells: [],
|
|
258
|
-
resourceKeys,
|
|
259
|
-
removedScopes: [{ type: "workbook", workbookName: this.workbookName }]
|
|
260
|
-
};
|
|
261
|
-
this.undoFootprint = {
|
|
262
|
-
touchedCells: [],
|
|
263
|
-
resourceKeys
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
undo() {
|
|
267
|
-
if (!this.snapshot)
|
|
268
|
-
return;
|
|
269
|
-
this.deps.workbookManager.addWorkbook(this.workbookName);
|
|
270
|
-
this.deps.namedExpressionManager.addWorkbook(this.workbookName);
|
|
271
|
-
this.deps.tableManager.addWorkbook(this.workbookName);
|
|
272
|
-
for (const [sheetName, sheet] of this.snapshot.workbook.sheets) {
|
|
273
|
-
this.deps.workbookManager.addSheet({
|
|
274
|
-
workbookName: this.workbookName,
|
|
275
|
-
sheetName
|
|
276
|
-
});
|
|
277
|
-
this.deps.namedExpressionManager.addSheet({
|
|
278
|
-
workbookName: this.workbookName,
|
|
279
|
-
sheetName
|
|
280
|
-
});
|
|
281
|
-
this.deps.workbookManager.setSheetContent({ workbookName: this.workbookName, sheetName }, sheet.content);
|
|
282
|
-
}
|
|
283
|
-
for (const [name, expr] of this.snapshot.namedExpressions.workbookLevel) {
|
|
284
|
-
this.deps.namedExpressionManager.addNamedExpression({
|
|
285
|
-
expressionName: name,
|
|
286
|
-
expression: expr.expression,
|
|
287
|
-
workbookName: this.workbookName
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
for (const [sheetName, expressions] of this.snapshot.namedExpressions.sheetLevel) {
|
|
291
|
-
for (const [name, expr] of expressions) {
|
|
292
|
-
this.deps.namedExpressionManager.addNamedExpression({
|
|
293
|
-
expressionName: name,
|
|
294
|
-
expression: expr.expression,
|
|
295
|
-
workbookName: this.workbookName,
|
|
296
|
-
sheetName
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
restoreTables(this.deps.tableManager, this.snapshot.tables, this.workbookName);
|
|
301
|
-
restoreStyles(this.deps.styleManager, this.snapshot.conditionalStyles, this.snapshot.cellStyles);
|
|
302
|
-
}
|
|
303
|
-
getInvalidationFootprint(phase) {
|
|
304
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
305
|
-
}
|
|
306
|
-
toAction() {
|
|
307
|
-
return {
|
|
308
|
-
type: import_types.ActionTypes.REMOVE_WORKBOOK,
|
|
309
|
-
payload: { workbookName: this.workbookName }
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
class RenameWorkbookCommand {
|
|
315
|
-
deps;
|
|
316
|
-
workbookName;
|
|
317
|
-
newWorkbookName;
|
|
318
|
-
requiresReevaluation = true;
|
|
319
|
-
snapshot;
|
|
320
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
321
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
322
|
-
constructor(deps, workbookName, newWorkbookName) {
|
|
323
|
-
this.deps = deps;
|
|
324
|
-
this.workbookName = workbookName;
|
|
325
|
-
this.newWorkbookName = newWorkbookName;
|
|
326
|
-
}
|
|
327
|
-
execute() {
|
|
328
|
-
this.snapshot = captureWorkbookSnapshot(this.deps, this.workbookName);
|
|
329
|
-
const changedCells = renameWorkbookAcrossManagers(this.deps, this.workbookName, this.newWorkbookName);
|
|
330
|
-
this.executeFootprint = {
|
|
331
|
-
touchedCells: changedCells.map((address) => ({
|
|
332
|
-
address,
|
|
333
|
-
beforeKind: "formula",
|
|
334
|
-
afterKind: "formula"
|
|
335
|
-
})),
|
|
336
|
-
resourceKeys: Array.from(new Set([
|
|
337
|
-
...getWorkbookSnapshotResourceKeys(this.workbookName, this.snapshot),
|
|
338
|
-
...getWorkbookSnapshotResourceKeys(this.newWorkbookName, this.snapshot)
|
|
339
|
-
]))
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
undo() {
|
|
343
|
-
const changedCells = renameWorkbookAcrossManagers(this.deps, this.newWorkbookName, this.workbookName);
|
|
344
|
-
this.undoFootprint = {
|
|
345
|
-
touchedCells: changedCells.map((address) => ({
|
|
346
|
-
address,
|
|
347
|
-
beforeKind: "formula",
|
|
348
|
-
afterKind: "formula"
|
|
349
|
-
})),
|
|
350
|
-
resourceKeys: Array.from(new Set([
|
|
351
|
-
...getWorkbookSnapshotResourceKeys(this.workbookName, this.snapshot),
|
|
352
|
-
...getWorkbookSnapshotResourceKeys(this.newWorkbookName, this.snapshot)
|
|
353
|
-
]))
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
getInvalidationFootprint(phase) {
|
|
357
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
358
|
-
}
|
|
359
|
-
toAction() {
|
|
360
|
-
return {
|
|
361
|
-
type: import_types.ActionTypes.RENAME_WORKBOOK,
|
|
362
|
-
payload: {
|
|
363
|
-
workbookName: this.workbookName,
|
|
364
|
-
newWorkbookName: this.newWorkbookName
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
class CloneWorkbookCommand {
|
|
371
|
-
deps;
|
|
372
|
-
fromWorkbookName;
|
|
373
|
-
toWorkbookName;
|
|
374
|
-
requiresReevaluation = true;
|
|
375
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
376
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
377
|
-
constructor(deps, fromWorkbookName, toWorkbookName) {
|
|
378
|
-
this.deps = deps;
|
|
379
|
-
this.fromWorkbookName = fromWorkbookName;
|
|
380
|
-
this.toWorkbookName = toWorkbookName;
|
|
381
|
-
}
|
|
382
|
-
execute() {
|
|
383
|
-
const {
|
|
384
|
-
workbookManager,
|
|
385
|
-
namedExpressionManager,
|
|
386
|
-
tableManager,
|
|
387
|
-
styleManager,
|
|
388
|
-
renameWorkbookInFormula
|
|
389
|
-
} = this.deps;
|
|
390
|
-
const sourceWorkbook = workbookManager.getWorkbooks().get(this.fromWorkbookName);
|
|
391
|
-
if (!sourceWorkbook) {
|
|
392
|
-
throw new Error(`Source workbook "${this.fromWorkbookName}" not found`);
|
|
393
|
-
}
|
|
394
|
-
if (workbookManager.getWorkbooks().has(this.toWorkbookName)) {
|
|
395
|
-
throw new Error(`Target workbook "${this.toWorkbookName}" already exists`);
|
|
396
|
-
}
|
|
397
|
-
workbookManager.addWorkbook(this.toWorkbookName);
|
|
398
|
-
namedExpressionManager.addWorkbook(this.toWorkbookName);
|
|
399
|
-
tableManager.addWorkbook(this.toWorkbookName);
|
|
400
|
-
for (const [sheetName, sheet] of sourceWorkbook.sheets) {
|
|
401
|
-
workbookManager.addSheet({
|
|
402
|
-
workbookName: this.toWorkbookName,
|
|
403
|
-
sheetName
|
|
404
|
-
});
|
|
405
|
-
namedExpressionManager.addSheet({
|
|
406
|
-
workbookName: this.toWorkbookName,
|
|
407
|
-
sheetName
|
|
408
|
-
});
|
|
409
|
-
workbookManager.setSheetContent({ workbookName: this.toWorkbookName, sheetName }, new Map(sheet.content));
|
|
410
|
-
const targetSheet = workbookManager.getSheet({
|
|
411
|
-
workbookName: this.toWorkbookName,
|
|
412
|
-
sheetName
|
|
413
|
-
});
|
|
414
|
-
if (targetSheet) {
|
|
415
|
-
targetSheet.metadata = new Map(sheet.metadata);
|
|
416
|
-
if (sheet.sheetMetadata !== undefined) {
|
|
417
|
-
targetSheet.sheetMetadata = structuredClone(sheet.sheetMetadata);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const targetWorkbook = workbookManager.getWorkbooks().get(this.toWorkbookName);
|
|
422
|
-
if (targetWorkbook && sourceWorkbook.workbookMetadata !== undefined) {
|
|
423
|
-
targetWorkbook.workbookMetadata = structuredClone(sourceWorkbook.workbookMetadata);
|
|
424
|
-
}
|
|
425
|
-
const allExpressions = namedExpressionManager.getNamedExpressions();
|
|
426
|
-
const sourceWorkbookExpressions = allExpressions.workbookExpressions.get(this.fromWorkbookName);
|
|
427
|
-
if (sourceWorkbookExpressions) {
|
|
428
|
-
for (const [expressionName, expression] of sourceWorkbookExpressions) {
|
|
429
|
-
namedExpressionManager.addNamedExpression({
|
|
430
|
-
expressionName,
|
|
431
|
-
expression: expression.expression,
|
|
432
|
-
workbookName: this.toWorkbookName
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
const sourceSheetExpressions = allExpressions.sheetExpressions.get(this.fromWorkbookName);
|
|
437
|
-
if (sourceSheetExpressions) {
|
|
438
|
-
for (const [sheetName, sheetExpressions] of sourceSheetExpressions) {
|
|
439
|
-
for (const [expressionName, expression] of sheetExpressions) {
|
|
440
|
-
namedExpressionManager.addNamedExpression({
|
|
441
|
-
expressionName,
|
|
442
|
-
expression: expression.expression,
|
|
443
|
-
workbookName: this.toWorkbookName,
|
|
444
|
-
sheetName
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
const sourceTables = tableManager.tables.get(this.fromWorkbookName);
|
|
450
|
-
if (sourceTables) {
|
|
451
|
-
for (const [tableName] of sourceTables) {
|
|
452
|
-
tableManager.copyTable({ workbookName: this.fromWorkbookName, tableName }, { workbookName: this.toWorkbookName, tableName });
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
const allConditionalStyles = styleManager.getAllConditionalStyles();
|
|
456
|
-
for (const style of allConditionalStyles) {
|
|
457
|
-
if (style.areas.some((area) => area.workbookName === this.fromWorkbookName)) {
|
|
458
|
-
const newStyle = {
|
|
459
|
-
...style,
|
|
460
|
-
areas: style.areas.map((area) => area.workbookName === this.fromWorkbookName ? { ...area, workbookName: this.toWorkbookName } : area)
|
|
461
|
-
};
|
|
462
|
-
styleManager.addConditionalStyle(newStyle);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
const allCellStyles = styleManager.getAllCellStyles();
|
|
466
|
-
for (const style of allCellStyles) {
|
|
467
|
-
if (style.areas.some((area) => area.workbookName === this.fromWorkbookName)) {
|
|
468
|
-
const newStyle = {
|
|
469
|
-
...style,
|
|
470
|
-
areas: style.areas.map((area) => area.workbookName === this.fromWorkbookName ? { ...area, workbookName: this.toWorkbookName } : area)
|
|
471
|
-
};
|
|
472
|
-
styleManager.addCellStyle(newStyle);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
workbookManager.updateFormulasForWorkbook(this.toWorkbookName, (formula) => renameWorkbookInFormula({
|
|
476
|
-
formula,
|
|
477
|
-
oldWorkbookName: this.fromWorkbookName,
|
|
478
|
-
newWorkbookName: this.toWorkbookName
|
|
479
|
-
}));
|
|
480
|
-
this.executeFootprint = {
|
|
481
|
-
touchedCells: [],
|
|
482
|
-
resourceKeys: [import_resource_keys.getWorkbookResourceKey(this.toWorkbookName)]
|
|
483
|
-
};
|
|
484
|
-
this.undoFootprint = {
|
|
485
|
-
touchedCells: [],
|
|
486
|
-
resourceKeys: [import_resource_keys.getWorkbookResourceKey(this.toWorkbookName)],
|
|
487
|
-
removedScopes: [{ type: "workbook", workbookName: this.toWorkbookName }]
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
undo() {
|
|
491
|
-
removeWorkbook(this.deps, this.toWorkbookName);
|
|
492
|
-
}
|
|
493
|
-
getInvalidationFootprint(phase) {
|
|
494
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
495
|
-
}
|
|
496
|
-
toAction() {
|
|
497
|
-
return {
|
|
498
|
-
type: import_types.ActionTypes.CLONE_WORKBOOK,
|
|
499
|
-
payload: {
|
|
500
|
-
fromWorkbookName: this.fromWorkbookName,
|
|
501
|
-
toWorkbookName: this.toWorkbookName
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
class AddSheetCommand {
|
|
508
|
-
deps;
|
|
509
|
-
opts;
|
|
510
|
-
requiresReevaluation = true;
|
|
511
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
512
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
513
|
-
constructor(deps, opts) {
|
|
514
|
-
this.deps = deps;
|
|
515
|
-
this.opts = opts;
|
|
516
|
-
}
|
|
517
|
-
execute() {
|
|
518
|
-
this.deps.workbookManager.addSheet(this.opts);
|
|
519
|
-
this.deps.namedExpressionManager.addSheet(this.opts);
|
|
520
|
-
const resourceKey = import_resource_keys.getSheetResourceKey(this.opts);
|
|
521
|
-
this.executeFootprint = {
|
|
522
|
-
touchedCells: [],
|
|
523
|
-
resourceKeys: [resourceKey]
|
|
524
|
-
};
|
|
525
|
-
this.undoFootprint = {
|
|
526
|
-
touchedCells: [],
|
|
527
|
-
resourceKeys: [resourceKey],
|
|
528
|
-
removedScopes: [{ type: "sheet", ...this.opts }]
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
undo() {
|
|
532
|
-
this.deps.workbookManager.removeSheet(this.opts);
|
|
533
|
-
this.deps.namedExpressionManager.removeSheet(this.opts);
|
|
534
|
-
}
|
|
535
|
-
getInvalidationFootprint(phase) {
|
|
536
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
537
|
-
}
|
|
538
|
-
toAction() {
|
|
539
|
-
return {
|
|
540
|
-
type: import_types.ActionTypes.ADD_SHEET,
|
|
541
|
-
payload: this.opts
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
class RemoveSheetCommand {
|
|
547
|
-
deps;
|
|
548
|
-
opts;
|
|
549
|
-
requiresReevaluation = true;
|
|
550
|
-
snapshot;
|
|
551
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
552
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
553
|
-
constructor(deps, opts) {
|
|
554
|
-
this.deps = deps;
|
|
555
|
-
this.opts = opts;
|
|
556
|
-
}
|
|
557
|
-
execute() {
|
|
558
|
-
const sheet = this.deps.workbookManager.getSheet(this.opts);
|
|
559
|
-
if (sheet) {
|
|
560
|
-
const namedExpressions = this.deps.namedExpressionManager.getNamedExpressions();
|
|
561
|
-
const sheetExpressions = namedExpressions.sheetExpressions.get(this.opts.workbookName)?.get(this.opts.sheetName) || new Map;
|
|
562
|
-
const allTables = this.deps.tableManager.getTables(this.opts.workbookName);
|
|
563
|
-
const sheetTables = new Map;
|
|
564
|
-
for (const [name, table] of allTables) {
|
|
565
|
-
if (table.sheetName === this.opts.sheetName) {
|
|
566
|
-
sheetTables.set(name, table);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
this.snapshot = {
|
|
570
|
-
sheet: {
|
|
571
|
-
name: sheet.name,
|
|
572
|
-
index: sheet.index,
|
|
573
|
-
content: new Map(sheet.content),
|
|
574
|
-
metadata: new Map(sheet.metadata),
|
|
575
|
-
sheetMetadata: sheet.sheetMetadata
|
|
576
|
-
},
|
|
577
|
-
namedExpressions: new Map(sheetExpressions),
|
|
578
|
-
tables: sheetTables,
|
|
579
|
-
conditionalStyles: this.deps.styleManager.getAllConditionalStyles().filter((s) => s.areas.some((a) => a.workbookName === this.opts.workbookName && a.sheetName === this.opts.sheetName)),
|
|
580
|
-
cellStyles: this.deps.styleManager.getAllCellStyles().filter((s) => s.areas.some((a) => a.workbookName === this.opts.workbookName && a.sheetName === this.opts.sheetName))
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
this.deps.workbookManager.removeSheet(this.opts);
|
|
584
|
-
this.deps.namedExpressionManager.removeSheet(this.opts);
|
|
585
|
-
this.deps.tableManager.removeSheet(this.opts);
|
|
586
|
-
this.deps.styleManager.removeSheetStyles(this.opts.workbookName, this.opts.sheetName);
|
|
587
|
-
this.deps.referenceManager.invalidateSheet(this.opts.workbookName, this.opts.sheetName);
|
|
588
|
-
const resourceKeys = getSheetSnapshotResourceKeys(this.opts.workbookName, this.opts.sheetName, this.snapshot);
|
|
589
|
-
this.executeFootprint = {
|
|
590
|
-
touchedCells: [],
|
|
591
|
-
resourceKeys,
|
|
592
|
-
removedScopes: [{ type: "sheet", ...this.opts }]
|
|
593
|
-
};
|
|
594
|
-
this.undoFootprint = {
|
|
595
|
-
touchedCells: [],
|
|
596
|
-
resourceKeys
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
undo() {
|
|
600
|
-
if (!this.snapshot)
|
|
601
|
-
return;
|
|
602
|
-
this.deps.workbookManager.addSheet(this.opts);
|
|
603
|
-
this.deps.namedExpressionManager.addSheet(this.opts);
|
|
604
|
-
this.deps.workbookManager.setSheetContent(this.opts, this.snapshot.sheet.content);
|
|
605
|
-
for (const [name, expr] of this.snapshot.namedExpressions) {
|
|
606
|
-
this.deps.namedExpressionManager.addNamedExpression({
|
|
607
|
-
expressionName: name,
|
|
608
|
-
expression: expr.expression,
|
|
609
|
-
workbookName: this.opts.workbookName,
|
|
610
|
-
sheetName: this.opts.sheetName
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
restoreTables(this.deps.tableManager, this.snapshot.tables, this.opts.workbookName);
|
|
614
|
-
restoreStyles(this.deps.styleManager, this.snapshot.conditionalStyles, this.snapshot.cellStyles);
|
|
615
|
-
}
|
|
616
|
-
getInvalidationFootprint(phase) {
|
|
617
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
618
|
-
}
|
|
619
|
-
toAction() {
|
|
620
|
-
return {
|
|
621
|
-
type: import_types.ActionTypes.REMOVE_SHEET,
|
|
622
|
-
payload: this.opts
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
class RenameSheetCommand {
|
|
628
|
-
deps;
|
|
629
|
-
opts;
|
|
630
|
-
requiresReevaluation = true;
|
|
631
|
-
snapshot;
|
|
632
|
-
executeFootprint = import_types.emptyMutationInvalidation();
|
|
633
|
-
undoFootprint = import_types.emptyMutationInvalidation();
|
|
634
|
-
constructor(deps, opts) {
|
|
635
|
-
this.deps = deps;
|
|
636
|
-
this.opts = opts;
|
|
637
|
-
}
|
|
638
|
-
execute() {
|
|
639
|
-
const namedExpressions = this.deps.namedExpressionManager.getNamedExpressions().sheetExpressions.get(this.opts.workbookName)?.get(this.opts.sheetName) || new Map;
|
|
640
|
-
const tables = new Map;
|
|
641
|
-
for (const [name, table] of this.deps.tableManager.getTables(this.opts.workbookName)) {
|
|
642
|
-
if (table.sheetName === this.opts.sheetName) {
|
|
643
|
-
tables.set(name, table);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
const sheet = this.deps.workbookManager.getSheet(this.opts);
|
|
647
|
-
this.snapshot = {
|
|
648
|
-
sheet,
|
|
649
|
-
namedExpressions: new Map(namedExpressions),
|
|
650
|
-
tables,
|
|
651
|
-
conditionalStyles: [],
|
|
652
|
-
cellStyles: []
|
|
653
|
-
};
|
|
654
|
-
const changedCells = renameSheetAcrossManagers(this.deps, this.opts);
|
|
655
|
-
this.executeFootprint = {
|
|
656
|
-
touchedCells: changedCells.map((address) => ({
|
|
657
|
-
address,
|
|
658
|
-
beforeKind: "formula",
|
|
659
|
-
afterKind: "formula"
|
|
660
|
-
})),
|
|
661
|
-
resourceKeys: Array.from(new Set([
|
|
662
|
-
...getSheetSnapshotResourceKeys(this.opts.workbookName, this.opts.sheetName, this.snapshot),
|
|
663
|
-
...getSheetSnapshotResourceKeys(this.opts.workbookName, this.opts.newSheetName, this.snapshot)
|
|
664
|
-
]))
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
undo() {
|
|
668
|
-
const changedCells = renameSheetAcrossManagers(this.deps, {
|
|
669
|
-
workbookName: this.opts.workbookName,
|
|
670
|
-
sheetName: this.opts.newSheetName,
|
|
671
|
-
newSheetName: this.opts.sheetName
|
|
672
|
-
});
|
|
673
|
-
this.undoFootprint = {
|
|
674
|
-
touchedCells: changedCells.map((address) => ({
|
|
675
|
-
address,
|
|
676
|
-
beforeKind: "formula",
|
|
677
|
-
afterKind: "formula"
|
|
678
|
-
})),
|
|
679
|
-
resourceKeys: Array.from(new Set([
|
|
680
|
-
...getSheetSnapshotResourceKeys(this.opts.workbookName, this.opts.sheetName, this.snapshot),
|
|
681
|
-
...getSheetSnapshotResourceKeys(this.opts.workbookName, this.opts.newSheetName, this.snapshot)
|
|
682
|
-
]))
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
getInvalidationFootprint(phase) {
|
|
686
|
-
return phase === "execute" ? this.executeFootprint : this.undoFootprint;
|
|
687
|
-
}
|
|
688
|
-
toAction() {
|
|
689
|
-
return {
|
|
690
|
-
type: import_types.ActionTypes.RENAME_SHEET,
|
|
691
|
-
payload: this.opts
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
//# debugId=9D7106D25079DB6D64756E2164756E21
|