@ricsam/formula-engine 0.2.8 → 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 +515 -166
- 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 +529 -207
- 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 -135
- 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
package/dist/cjs/core/engine.cjs
CHANGED
|
@@ -59,19 +59,9 @@ var import_dependency_manager = require("./managers/dependency-manager.cjs");
|
|
|
59
59
|
var import_style_manager = require("./managers/style-manager.cjs");
|
|
60
60
|
var import_copy_manager = require("./managers/copy-manager.cjs");
|
|
61
61
|
var import_reference_manager = require("./managers/reference-manager.cjs");
|
|
62
|
-
var import_schema_manager = require("./managers/schema-manager.cjs");
|
|
63
|
-
var import_schema_builder = require("./schema/schema-builder.cjs");
|
|
64
|
-
var import_table_orm = require("./schema/table-orm.cjs");
|
|
65
|
-
var import_cell_orm = require("./schema/cell-orm.cjs");
|
|
66
|
-
var import_grid_orm = require("./schema/grid-orm.cjs");
|
|
67
62
|
var import_engine_snapshot = require("./engine-snapshot.cjs");
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
var import_structure_commands = require("./commands/structure-commands.cjs");
|
|
71
|
-
var import_table_commands = require("./commands/table-commands.cjs");
|
|
72
|
-
var import_named_expression_commands = require("./commands/named-expression-commands.cjs");
|
|
73
|
-
var import_metadata_commands = require("./commands/metadata-commands.cjs");
|
|
74
|
-
var import_style_commands = require("./commands/style-commands.cjs");
|
|
63
|
+
var import_mutation_invalidation = require("./mutation-invalidation.cjs");
|
|
64
|
+
var import_resource_keys = require("./resource-keys.cjs");
|
|
75
65
|
|
|
76
66
|
class FormulaEngine {
|
|
77
67
|
workbookManager;
|
|
@@ -84,10 +74,6 @@ class FormulaEngine {
|
|
|
84
74
|
styleManager;
|
|
85
75
|
copyManager;
|
|
86
76
|
referenceManager;
|
|
87
|
-
schemaManager;
|
|
88
|
-
commandExecutor;
|
|
89
|
-
schema;
|
|
90
|
-
schemaDeclaration;
|
|
91
77
|
_workbookManager;
|
|
92
78
|
_namedExpressionManager;
|
|
93
79
|
_tableManager;
|
|
@@ -96,8 +82,7 @@ class FormulaEngine {
|
|
|
96
82
|
_autoFillManager;
|
|
97
83
|
_dependencyManager;
|
|
98
84
|
_styleManager;
|
|
99
|
-
constructor(
|
|
100
|
-
this.schemaDeclaration = schema?.declaration;
|
|
85
|
+
constructor() {
|
|
101
86
|
this.eventManager = new import_event_manager.EventManager;
|
|
102
87
|
this.workbookManager = new import_workbook_manager.WorkbookManager;
|
|
103
88
|
this.namedExpressionManager = new import_named_expression_manager.NamedExpressionManager;
|
|
@@ -110,13 +95,6 @@ class FormulaEngine {
|
|
|
110
95
|
this.copyManager = new import_copy_manager.CopyManager(this.workbookManager, this.evaluationManager, this.styleManager);
|
|
111
96
|
this.autoFillManager = new import_autofill_utils.AutoFill(this.workbookManager, this.styleManager);
|
|
112
97
|
this.referenceManager = new import_reference_manager.ReferenceManager;
|
|
113
|
-
this.schemaManager = new import_schema_manager.SchemaManager(this.tableManager);
|
|
114
|
-
this.commandExecutor = new import_command_executor.CommandExecutor(this.evaluationManager, this.eventManager, () => this.schemaManager.validateAllSchemaConstraints((cell) => this.getCellValue(cell), (cell) => this.getCellMetadata(cell), (table) => this.getTableDataCells(table)));
|
|
115
|
-
if (this.schemaDeclaration) {
|
|
116
|
-
this.schema = import_schema_builder.buildSchemaFromDeclaration(this, this.schemaDeclaration, this.schemaManager);
|
|
117
|
-
} else {
|
|
118
|
-
this.schema = {};
|
|
119
|
-
}
|
|
120
98
|
this._workbookManager = this.workbookManager;
|
|
121
99
|
this._namedExpressionManager = this.namedExpressionManager;
|
|
122
100
|
this._tableManager = this.tableManager;
|
|
@@ -126,46 +104,63 @@ class FormulaEngine {
|
|
|
126
104
|
this._dependencyManager = this.dependencyManager;
|
|
127
105
|
this._styleManager = this.styleManager;
|
|
128
106
|
}
|
|
129
|
-
static buildEmpty(
|
|
130
|
-
return new FormulaEngine
|
|
131
|
-
}
|
|
132
|
-
addTableSchema(namespace, address, headers) {
|
|
133
|
-
this.schemaManager.registerTableSchema(namespace, address.workbookName, address.tableName, headers);
|
|
134
|
-
const orm = new import_table_orm.TableOrm(this, address.workbookName, address.tableName, headers, namespace);
|
|
135
|
-
this.schema[namespace] = orm;
|
|
136
|
-
return orm;
|
|
137
|
-
}
|
|
138
|
-
addCellSchema(namespace, cellAddress, parse, write = (value) => ({ value })) {
|
|
139
|
-
this.schemaManager.registerCellSchema(namespace, cellAddress, parse);
|
|
140
|
-
const orm = new import_cell_orm.CellOrm(this, cellAddress, parse, write, namespace);
|
|
141
|
-
this.schema[namespace] = orm;
|
|
142
|
-
return orm;
|
|
107
|
+
static buildEmpty() {
|
|
108
|
+
return new FormulaEngine;
|
|
143
109
|
}
|
|
144
|
-
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
this.schema[namespace] = orm;
|
|
148
|
-
return orm;
|
|
149
|
-
}
|
|
150
|
-
removeTableSchema(namespace) {
|
|
151
|
-
return this.removeSchemaOfType(namespace, "table");
|
|
110
|
+
emitMutation(footprint) {
|
|
111
|
+
this.evaluationManager.invalidateFromMutation(footprint);
|
|
112
|
+
this.eventManager.emitUpdate();
|
|
152
113
|
}
|
|
153
|
-
|
|
154
|
-
|
|
114
|
+
emitUpdate() {
|
|
115
|
+
this.eventManager.emitUpdate();
|
|
155
116
|
}
|
|
156
|
-
|
|
157
|
-
|
|
117
|
+
getExistingSheetContent(opts) {
|
|
118
|
+
const sheet = this.workbookManager.getSheet(opts);
|
|
119
|
+
return sheet ? new Map(sheet.content) : undefined;
|
|
158
120
|
}
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
121
|
+
getWorkbookResourceKeys(workbookName) {
|
|
122
|
+
const resourceKeys = new Set([import_resource_keys.getWorkbookResourceKey(workbookName)]);
|
|
123
|
+
for (const sheetName of this.workbookManager.getWorkbooks().get(workbookName)?.sheets.keys() ?? []) {
|
|
124
|
+
resourceKeys.add(import_resource_keys.getSheetResourceKey({ workbookName, sheetName }));
|
|
163
125
|
}
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
126
|
+
for (const tableName of this.tableManager.getTables(workbookName).keys()) {
|
|
127
|
+
resourceKeys.add(import_resource_keys.getTableResourceKey({ workbookName, tableName }));
|
|
128
|
+
}
|
|
129
|
+
const namedExpressions = this.namedExpressionManager.getNamedExpressions();
|
|
130
|
+
for (const name of namedExpressions.workbookExpressions.get(workbookName)?.keys() ?? []) {
|
|
131
|
+
resourceKeys.add(import_resource_keys.getNamedExpressionResourceKey({ expressionName: name, workbookName }));
|
|
132
|
+
}
|
|
133
|
+
for (const [sheetName, expressions] of namedExpressions.sheetExpressions.get(workbookName) ?? []) {
|
|
134
|
+
resourceKeys.add(import_resource_keys.getSheetResourceKey({ workbookName, sheetName }));
|
|
135
|
+
for (const name of expressions.keys()) {
|
|
136
|
+
resourceKeys.add(import_resource_keys.getNamedExpressionResourceKey({
|
|
137
|
+
expressionName: name,
|
|
138
|
+
workbookName,
|
|
139
|
+
sheetName
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
167
142
|
}
|
|
168
|
-
return
|
|
143
|
+
return Array.from(resourceKeys);
|
|
144
|
+
}
|
|
145
|
+
getSheetResourceKeys(opts) {
|
|
146
|
+
const resourceKeys = new Set([
|
|
147
|
+
import_resource_keys.getWorkbookResourceKey(opts.workbookName),
|
|
148
|
+
import_resource_keys.getSheetResourceKey(opts)
|
|
149
|
+
]);
|
|
150
|
+
for (const [tableName, table] of this.tableManager.getTables(opts.workbookName)) {
|
|
151
|
+
if (table.sheetName === opts.sheetName) {
|
|
152
|
+
resourceKeys.add(import_resource_keys.getTableResourceKey({ workbookName: opts.workbookName, tableName }));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const sheetExpressions = this.namedExpressionManager.getNamedExpressions().sheetExpressions.get(opts.workbookName)?.get(opts.sheetName);
|
|
156
|
+
for (const name of sheetExpressions?.keys() ?? []) {
|
|
157
|
+
resourceKeys.add(import_resource_keys.getNamedExpressionResourceKey({
|
|
158
|
+
expressionName: name,
|
|
159
|
+
workbookName: opts.workbookName,
|
|
160
|
+
sheetName: opts.sheetName
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
return Array.from(resourceKeys);
|
|
169
164
|
}
|
|
170
165
|
getCellEvaluationResult(cellAddress) {
|
|
171
166
|
return this.evaluationManager.getCellEvaluationResult(cellAddress);
|
|
@@ -178,7 +173,8 @@ class FormulaEngine {
|
|
|
178
173
|
return this.evaluationManager.evaluationResultToSerializedValue(result, cellAddress, debug);
|
|
179
174
|
}
|
|
180
175
|
setCellMetadata(address, metadata) {
|
|
181
|
-
this.
|
|
176
|
+
this.workbookManager.setCellMetadata(address, metadata);
|
|
177
|
+
this.emitUpdate();
|
|
182
178
|
}
|
|
183
179
|
getCellMetadata(address) {
|
|
184
180
|
const metadata = this.workbookManager.getCellMetadata(address);
|
|
@@ -188,13 +184,15 @@ class FormulaEngine {
|
|
|
188
184
|
return this.workbookManager.getSheetMetadataSerialized(opts);
|
|
189
185
|
}
|
|
190
186
|
setSheetMetadata(opts, metadata) {
|
|
191
|
-
this.
|
|
187
|
+
this.workbookManager.setSheetMetadata(opts, metadata);
|
|
188
|
+
this.emitUpdate();
|
|
192
189
|
}
|
|
193
190
|
getSheetMetadata(opts) {
|
|
194
191
|
return this.workbookManager.getSheetMetadata(opts);
|
|
195
192
|
}
|
|
196
193
|
setWorkbookMetadata(workbookName, metadata) {
|
|
197
|
-
this.
|
|
194
|
+
this.workbookManager.setWorkbookMetadata(workbookName, metadata);
|
|
195
|
+
this.emitUpdate();
|
|
198
196
|
}
|
|
199
197
|
getWorkbookMetadata(workbookName) {
|
|
200
198
|
return this.workbookManager.getWorkbookMetadata(workbookName);
|
|
@@ -221,10 +219,20 @@ class FormulaEngine {
|
|
|
221
219
|
throw new Error("Not implemented");
|
|
222
220
|
}
|
|
223
221
|
addNamedExpression(opts) {
|
|
224
|
-
this.
|
|
222
|
+
this.namedExpressionManager.addNamedExpression(opts);
|
|
223
|
+
this.emitMutation({
|
|
224
|
+
touchedCells: [],
|
|
225
|
+
resourceKeys: [import_resource_keys.getNamedExpressionResourceKey(opts)]
|
|
226
|
+
});
|
|
225
227
|
}
|
|
226
228
|
removeNamedExpression(opts) {
|
|
227
|
-
|
|
229
|
+
const removed = this.namedExpressionManager.removeNamedExpression(opts);
|
|
230
|
+
if (removed) {
|
|
231
|
+
this.emitMutation({
|
|
232
|
+
touchedCells: [],
|
|
233
|
+
resourceKeys: [import_resource_keys.getNamedExpressionResourceKey(opts)]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
228
236
|
}
|
|
229
237
|
hasNamedExpression(opts) {
|
|
230
238
|
const scope = opts.sheetName && opts.workbookName ? {
|
|
@@ -238,25 +246,154 @@ class FormulaEngine {
|
|
|
238
246
|
});
|
|
239
247
|
}
|
|
240
248
|
updateNamedExpression(opts) {
|
|
241
|
-
this.
|
|
249
|
+
this.namedExpressionManager.updateNamedExpression(opts);
|
|
250
|
+
this.emitMutation({
|
|
251
|
+
touchedCells: [],
|
|
252
|
+
resourceKeys: [import_resource_keys.getNamedExpressionResourceKey(opts)]
|
|
253
|
+
});
|
|
242
254
|
}
|
|
243
255
|
renameNamedExpression(opts) {
|
|
244
|
-
this.
|
|
256
|
+
this.namedExpressionManager.renameNamedExpression(opts);
|
|
257
|
+
const changedCells = this.workbookManager.updateAllFormulas((formula) => import_named_expression_renamer.renameNamedExpressionInFormula(formula, opts.expressionName, opts.newName));
|
|
258
|
+
const changedNamedExpressions = this.namedExpressionManager.updateAllNamedExpressions((formula) => import_named_expression_renamer.renameNamedExpressionInFormula(formula, opts.expressionName, opts.newName));
|
|
259
|
+
this.emitMutation({
|
|
260
|
+
touchedCells: import_mutation_invalidation.buildFormulaTouchedCells(changedCells),
|
|
261
|
+
resourceKeys: [
|
|
262
|
+
import_resource_keys.getNamedExpressionResourceKey({
|
|
263
|
+
expressionName: opts.expressionName,
|
|
264
|
+
workbookName: opts.workbookName,
|
|
265
|
+
sheetName: opts.sheetName
|
|
266
|
+
}),
|
|
267
|
+
import_resource_keys.getNamedExpressionResourceKey({
|
|
268
|
+
expressionName: opts.newName,
|
|
269
|
+
workbookName: opts.workbookName,
|
|
270
|
+
sheetName: opts.sheetName
|
|
271
|
+
}),
|
|
272
|
+
...changedNamedExpressions
|
|
273
|
+
]
|
|
274
|
+
});
|
|
245
275
|
}
|
|
246
276
|
setNamedExpressions(opts) {
|
|
247
|
-
|
|
277
|
+
const allExpressions = this.namedExpressionManager.getNamedExpressions();
|
|
278
|
+
let previousExpressions;
|
|
279
|
+
if (opts.type === "global") {
|
|
280
|
+
previousExpressions = new Map(allExpressions.globalExpressions);
|
|
281
|
+
} else if (opts.type === "workbook") {
|
|
282
|
+
previousExpressions = new Map(allExpressions.workbookExpressions.get(opts.workbookName) || []);
|
|
283
|
+
} else {
|
|
284
|
+
const sheetExpressions = allExpressions.sheetExpressions.get(opts.workbookName)?.get(opts.sheetName);
|
|
285
|
+
previousExpressions = new Map(sheetExpressions || []);
|
|
286
|
+
}
|
|
287
|
+
this.namedExpressionManager.setNamedExpressions(opts);
|
|
288
|
+
const scope = opts.type === "global" ? {} : opts.type === "workbook" ? { workbookName: opts.workbookName } : {
|
|
289
|
+
workbookName: opts.workbookName,
|
|
290
|
+
sheetName: opts.sheetName
|
|
291
|
+
};
|
|
292
|
+
this.emitMutation({
|
|
293
|
+
touchedCells: [],
|
|
294
|
+
resourceKeys: [
|
|
295
|
+
...import_mutation_invalidation.getNamedExpressionScopeResourceKeys(previousExpressions.keys(), scope),
|
|
296
|
+
...import_mutation_invalidation.getNamedExpressionScopeResourceKeys(opts.expressions.keys(), scope)
|
|
297
|
+
]
|
|
298
|
+
});
|
|
248
299
|
}
|
|
249
300
|
addTable(props) {
|
|
250
|
-
|
|
301
|
+
const table = this.tableManager.addTable({
|
|
302
|
+
...props,
|
|
303
|
+
getCellValue: (cellAddress) => this.getCellValue(cellAddress)
|
|
304
|
+
});
|
|
305
|
+
this.emitMutation({
|
|
306
|
+
touchedCells: import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, [table]),
|
|
307
|
+
tableContextChangedCells: import_mutation_invalidation.buildTableContextChangedCells(this.workbookManager, [table]),
|
|
308
|
+
resourceKeys: [
|
|
309
|
+
import_resource_keys.getTableResourceKey({
|
|
310
|
+
workbookName: props.workbookName,
|
|
311
|
+
tableName: props.tableName
|
|
312
|
+
})
|
|
313
|
+
]
|
|
314
|
+
});
|
|
251
315
|
}
|
|
252
316
|
renameTable(workbookName, names) {
|
|
253
|
-
|
|
317
|
+
const oldTable = this.tableManager.getTable({
|
|
318
|
+
workbookName,
|
|
319
|
+
name: names.oldName
|
|
320
|
+
});
|
|
321
|
+
const oldTableSnapshot = oldTable ? { ...oldTable, headers: new Map(oldTable.headers) } : undefined;
|
|
322
|
+
this.tableManager.renameTable(workbookName, names);
|
|
323
|
+
const changedCells = this.workbookManager.updateAllFormulas((formula) => import_table_renamer.renameTableInFormula(formula, names.oldName, names.newName));
|
|
324
|
+
const changedNamedExpressions = this.namedExpressionManager.updateAllNamedExpressions((formula) => import_table_renamer.renameTableInFormula(formula, names.oldName, names.newName));
|
|
325
|
+
const newTable = this.tableManager.getTable({
|
|
326
|
+
workbookName,
|
|
327
|
+
name: names.newName
|
|
328
|
+
});
|
|
329
|
+
this.emitMutation({
|
|
330
|
+
touchedCells: import_mutation_invalidation.mergeTouchedCells(import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, [oldTableSnapshot]), import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, [newTable]), import_mutation_invalidation.buildFormulaTouchedCells(changedCells)),
|
|
331
|
+
tableContextChangedCells: import_mutation_invalidation.buildTableContextChangedCells(this.workbookManager, [oldTableSnapshot, newTable]),
|
|
332
|
+
resourceKeys: [
|
|
333
|
+
import_resource_keys.getTableResourceKey({
|
|
334
|
+
workbookName,
|
|
335
|
+
tableName: names.oldName
|
|
336
|
+
}),
|
|
337
|
+
import_resource_keys.getTableResourceKey({
|
|
338
|
+
workbookName,
|
|
339
|
+
tableName: names.newName
|
|
340
|
+
}),
|
|
341
|
+
...changedNamedExpressions
|
|
342
|
+
]
|
|
343
|
+
});
|
|
254
344
|
}
|
|
255
345
|
updateTable(opts) {
|
|
256
|
-
|
|
346
|
+
const oldTable = this.tableManager.getTable({
|
|
347
|
+
workbookName: opts.workbookName,
|
|
348
|
+
name: opts.tableName
|
|
349
|
+
});
|
|
350
|
+
const oldTableSnapshot = oldTable ? { ...oldTable, headers: new Map(oldTable.headers) } : undefined;
|
|
351
|
+
this.tableManager.updateTable({
|
|
352
|
+
...opts,
|
|
353
|
+
getCellValue: (cellAddress) => this.getCellValue(cellAddress)
|
|
354
|
+
});
|
|
355
|
+
const newTable = this.tableManager.getTable({
|
|
356
|
+
workbookName: opts.workbookName,
|
|
357
|
+
name: opts.tableName
|
|
358
|
+
});
|
|
359
|
+
this.emitMutation({
|
|
360
|
+
touchedCells: import_mutation_invalidation.mergeTouchedCells(import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, [oldTableSnapshot]), import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, [newTable])),
|
|
361
|
+
tableContextChangedCells: import_mutation_invalidation.buildTableContextChangedCells(this.workbookManager, [oldTableSnapshot, newTable]),
|
|
362
|
+
resourceKeys: [
|
|
363
|
+
import_resource_keys.getTableResourceKey({
|
|
364
|
+
workbookName: opts.workbookName,
|
|
365
|
+
tableName: opts.tableName
|
|
366
|
+
})
|
|
367
|
+
]
|
|
368
|
+
});
|
|
257
369
|
}
|
|
258
370
|
removeTable(opts) {
|
|
259
|
-
|
|
371
|
+
const oldTable = this.tableManager.getTable({
|
|
372
|
+
workbookName: opts.workbookName,
|
|
373
|
+
name: opts.tableName
|
|
374
|
+
});
|
|
375
|
+
const oldTableSnapshot = oldTable ? { ...oldTable, headers: new Map(oldTable.headers) } : undefined;
|
|
376
|
+
const found = this.tableManager.removeTable(opts);
|
|
377
|
+
if (found) {
|
|
378
|
+
this.emitMutation({
|
|
379
|
+
touchedCells: import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, [
|
|
380
|
+
oldTableSnapshot
|
|
381
|
+
]),
|
|
382
|
+
tableContextChangedCells: import_mutation_invalidation.buildTableContextChangedCells(this.workbookManager, [oldTableSnapshot]),
|
|
383
|
+
resourceKeys: [
|
|
384
|
+
import_resource_keys.getTableResourceKey({
|
|
385
|
+
workbookName: opts.workbookName,
|
|
386
|
+
tableName: opts.tableName
|
|
387
|
+
})
|
|
388
|
+
]
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
getAllTables() {
|
|
393
|
+
return Array.from(this.tableManager.tables.values()).flatMap((tables) => Array.from(tables.values()).map((table) => ({
|
|
394
|
+
...table,
|
|
395
|
+
headers: new Map(table.headers)
|
|
396
|
+
})));
|
|
260
397
|
}
|
|
261
398
|
hasTable(opts) {
|
|
262
399
|
return !!this.tableManager.getTable({
|
|
@@ -271,7 +408,21 @@ class FormulaEngine {
|
|
|
271
408
|
});
|
|
272
409
|
}
|
|
273
410
|
resetTables(tables) {
|
|
274
|
-
|
|
411
|
+
const oldTables = this.getAllTables();
|
|
412
|
+
const newTables = Array.from(tables.values()).flatMap((workbookTables) => Array.from(workbookTables.values()));
|
|
413
|
+
const resourceKeys = new Set;
|
|
414
|
+
for (const table of [...oldTables, ...newTables]) {
|
|
415
|
+
resourceKeys.add(import_resource_keys.getTableResourceKey({
|
|
416
|
+
workbookName: table.workbookName,
|
|
417
|
+
tableName: table.name
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
this.tableManager.resetTables(tables);
|
|
421
|
+
this.emitMutation({
|
|
422
|
+
touchedCells: import_mutation_invalidation.mergeTouchedCells(import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, oldTables), import_mutation_invalidation.buildTableTouchedCells(this.workbookManager, newTables)),
|
|
423
|
+
tableContextChangedCells: import_mutation_invalidation.buildTableContextChangedCells(this.workbookManager, [...oldTables, ...newTables]),
|
|
424
|
+
resourceKeys: Array.from(resourceKeys)
|
|
425
|
+
});
|
|
275
426
|
}
|
|
276
427
|
getTables(workbookName) {
|
|
277
428
|
return this.tableManager.getTables(workbookName);
|
|
@@ -279,28 +430,15 @@ class FormulaEngine {
|
|
|
279
430
|
isCellInTable(cellAddress) {
|
|
280
431
|
return this.tableManager.isCellInTable(cellAddress);
|
|
281
432
|
}
|
|
282
|
-
getTableDataCells(table) {
|
|
283
|
-
const { start, endRow, headers } = table;
|
|
284
|
-
const dataStartRow = start.rowIndex + 1;
|
|
285
|
-
const endColIndex = start.colIndex + headers.size - 1;
|
|
286
|
-
const rangeAddress = {
|
|
287
|
-
workbookName: table.workbookName,
|
|
288
|
-
sheetName: table.sheetName,
|
|
289
|
-
range: {
|
|
290
|
-
start: { col: start.colIndex, row: dataStartRow },
|
|
291
|
-
end: {
|
|
292
|
-
col: { type: "number", value: endColIndex },
|
|
293
|
-
row: endRow
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
return this.workbookManager.getCellsInRange(rangeAddress);
|
|
298
|
-
}
|
|
299
433
|
addConditionalStyle(style) {
|
|
300
|
-
this.
|
|
434
|
+
this.styleManager.addConditionalStyle(style);
|
|
435
|
+
this.emitUpdate();
|
|
301
436
|
}
|
|
302
437
|
removeConditionalStyle(workbookName, index) {
|
|
303
|
-
this.
|
|
438
|
+
const removed = this.styleManager.removeConditionalStyle(workbookName, index);
|
|
439
|
+
if (removed) {
|
|
440
|
+
this.emitUpdate();
|
|
441
|
+
}
|
|
304
442
|
}
|
|
305
443
|
getConditionalStyleCount(workbookName) {
|
|
306
444
|
const allStyles = this.styleManager.getAllConditionalStyles();
|
|
@@ -319,10 +457,14 @@ class FormulaEngine {
|
|
|
319
457
|
return this.styleManager.getAllConditionalStyles();
|
|
320
458
|
}
|
|
321
459
|
addCellStyle(style) {
|
|
322
|
-
this.
|
|
460
|
+
this.styleManager.addCellStyle(style);
|
|
461
|
+
this.emitUpdate();
|
|
323
462
|
}
|
|
324
463
|
removeCellStyle(workbookName, index) {
|
|
325
|
-
this.
|
|
464
|
+
const removed = this.styleManager.removeCellStyle(workbookName, index);
|
|
465
|
+
if (removed) {
|
|
466
|
+
this.emitUpdate();
|
|
467
|
+
}
|
|
326
468
|
}
|
|
327
469
|
getCellStyleCount(workbookName) {
|
|
328
470
|
const allStyles = this.styleManager.getAllCellStyles();
|
|
@@ -335,13 +477,69 @@ class FormulaEngine {
|
|
|
335
477
|
return this.styleManager.getStyleForRange(range);
|
|
336
478
|
}
|
|
337
479
|
clearCellStyles(range) {
|
|
338
|
-
this.
|
|
480
|
+
this.styleManager.clearCellStyles(range);
|
|
481
|
+
this.emitUpdate();
|
|
482
|
+
}
|
|
483
|
+
getTopLeftCell(cells) {
|
|
484
|
+
let topLeft = cells[0];
|
|
485
|
+
for (const cell of cells) {
|
|
486
|
+
if (cell.rowIndex < topLeft.rowIndex || cell.rowIndex === topLeft.rowIndex && cell.colIndex < topLeft.colIndex) {
|
|
487
|
+
topLeft = cell;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return topLeft;
|
|
491
|
+
}
|
|
492
|
+
dedupeAddresses(addresses) {
|
|
493
|
+
return Array.from(new Map(addresses.map((address) => [import_mutation_invalidation.getMutationAddressKey(address), address])).values());
|
|
494
|
+
}
|
|
495
|
+
getPasteTouchedAddresses(source, target, options) {
|
|
496
|
+
if (source.length === 0) {
|
|
497
|
+
return [];
|
|
498
|
+
}
|
|
499
|
+
const topLeft = this.getTopLeftCell(source);
|
|
500
|
+
const colOffset = target.colIndex - topLeft.colIndex;
|
|
501
|
+
const rowOffset = target.rowIndex - topLeft.rowIndex;
|
|
502
|
+
const targetCells = source.map((sourceCell) => ({
|
|
503
|
+
workbookName: target.workbookName,
|
|
504
|
+
sheetName: target.sheetName,
|
|
505
|
+
colIndex: sourceCell.colIndex + colOffset,
|
|
506
|
+
rowIndex: sourceCell.rowIndex + rowOffset
|
|
507
|
+
}));
|
|
508
|
+
return this.dedupeAddresses(options.cut ? [...source, ...targetCells] : targetCells);
|
|
339
509
|
}
|
|
340
510
|
pasteCells(source, target, options) {
|
|
341
|
-
|
|
511
|
+
if (source.length === 0) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const touchedAddresses = this.getPasteTouchedAddresses(source, target, options);
|
|
515
|
+
const before = import_mutation_invalidation.captureCellContents(this.workbookManager, touchedAddresses);
|
|
516
|
+
this.copyManager.pasteCells(source, target, options);
|
|
517
|
+
const after = import_mutation_invalidation.captureCellContents(this.workbookManager, touchedAddresses);
|
|
518
|
+
this.emitMutation({
|
|
519
|
+
touchedCells: import_mutation_invalidation.buildTouchedCells(touchedAddresses.map((address) => ({
|
|
520
|
+
address,
|
|
521
|
+
before: before.get(import_mutation_invalidation.getMutationAddressKey(address)),
|
|
522
|
+
after: after.get(import_mutation_invalidation.getMutationAddressKey(address))
|
|
523
|
+
}))),
|
|
524
|
+
resourceKeys: []
|
|
525
|
+
});
|
|
342
526
|
}
|
|
343
527
|
fillAreas(seedRange, targetRanges, options) {
|
|
344
|
-
|
|
528
|
+
const touchedAddresses = this.dedupeAddresses([
|
|
529
|
+
...targetRanges.flatMap((targetRange) => import_mutation_invalidation.getFiniteRangeAddresses(targetRange)),
|
|
530
|
+
...options.cut ? import_mutation_invalidation.getFiniteRangeAddresses(seedRange) : []
|
|
531
|
+
]);
|
|
532
|
+
const before = import_mutation_invalidation.captureCellContents(this.workbookManager, touchedAddresses);
|
|
533
|
+
this.copyManager.fillAreas(seedRange, targetRanges, options);
|
|
534
|
+
const after = import_mutation_invalidation.captureCellContents(this.workbookManager, touchedAddresses);
|
|
535
|
+
this.emitMutation({
|
|
536
|
+
touchedCells: import_mutation_invalidation.buildTouchedCells(touchedAddresses.map((address) => ({
|
|
537
|
+
address,
|
|
538
|
+
before: before.get(import_mutation_invalidation.getMutationAddressKey(address)),
|
|
539
|
+
after: after.get(import_mutation_invalidation.getMutationAddressKey(address))
|
|
540
|
+
}))),
|
|
541
|
+
resourceKeys: []
|
|
542
|
+
});
|
|
345
543
|
}
|
|
346
544
|
smartPaste(sourceCells, pasteSelection, options) {
|
|
347
545
|
if (sourceCells.length === 0) {
|
|
@@ -422,17 +620,27 @@ class FormulaEngine {
|
|
|
422
620
|
return { minCol, minRow, maxCol, maxRow };
|
|
423
621
|
}
|
|
424
622
|
moveCell(source, target) {
|
|
425
|
-
this.
|
|
623
|
+
this.pasteCells([source], target, {
|
|
624
|
+
cut: true,
|
|
625
|
+
type: "formula",
|
|
626
|
+
include: "all"
|
|
627
|
+
});
|
|
426
628
|
}
|
|
427
629
|
moveRange(sourceRange, target) {
|
|
428
|
-
|
|
630
|
+
const cells = this.copyManager.expandRangeToCells(sourceRange);
|
|
631
|
+
this.pasteCells(cells, target, {
|
|
632
|
+
cut: true,
|
|
633
|
+
type: "formula",
|
|
634
|
+
include: "all"
|
|
635
|
+
});
|
|
429
636
|
}
|
|
430
637
|
addSheet(opts) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
638
|
+
const sheet = this.workbookManager.addSheet(opts);
|
|
639
|
+
this.namedExpressionManager.addSheet(opts);
|
|
640
|
+
this.emitMutation({
|
|
641
|
+
touchedCells: [],
|
|
642
|
+
resourceKeys: [import_resource_keys.getSheetResourceKey(opts)]
|
|
643
|
+
});
|
|
436
644
|
return sheet;
|
|
437
645
|
}
|
|
438
646
|
createSheet(opts) {
|
|
@@ -443,10 +651,40 @@ class FormulaEngine {
|
|
|
443
651
|
});
|
|
444
652
|
}
|
|
445
653
|
removeSheet(opts) {
|
|
446
|
-
|
|
654
|
+
const resourceKeys = this.getSheetResourceKeys(opts);
|
|
655
|
+
this.workbookManager.removeSheet(opts);
|
|
656
|
+
this.namedExpressionManager.removeSheet(opts);
|
|
657
|
+
this.tableManager.removeSheet(opts);
|
|
658
|
+
this.styleManager.removeSheetStyles(opts.workbookName, opts.sheetName);
|
|
659
|
+
this.referenceManager.invalidateSheet(opts.workbookName, opts.sheetName);
|
|
660
|
+
this.emitMutation({
|
|
661
|
+
touchedCells: [],
|
|
662
|
+
resourceKeys,
|
|
663
|
+
removedScopes: [{ type: "sheet", ...opts }]
|
|
664
|
+
});
|
|
447
665
|
}
|
|
448
666
|
renameSheet(opts) {
|
|
449
|
-
|
|
667
|
+
const oldResourceKeys = this.getSheetResourceKeys(opts);
|
|
668
|
+
this.workbookManager.renameSheet(opts);
|
|
669
|
+
this.namedExpressionManager.renameSheet(opts);
|
|
670
|
+
this.tableManager.updateTablesForSheetRename(opts);
|
|
671
|
+
this.styleManager.updateSheetName(opts.workbookName, opts.sheetName, opts.newSheetName);
|
|
672
|
+
const changedCells = this.workbookManager.updateAllFormulas((formula) => import_sheet_renamer.renameSheetInFormula({
|
|
673
|
+
formula,
|
|
674
|
+
oldSheetName: opts.sheetName,
|
|
675
|
+
newSheetName: opts.newSheetName
|
|
676
|
+
}));
|
|
677
|
+
this.referenceManager.updateSheetName(opts.workbookName, opts.sheetName, opts.newSheetName);
|
|
678
|
+
this.emitMutation({
|
|
679
|
+
touchedCells: import_mutation_invalidation.buildFormulaTouchedCells(changedCells),
|
|
680
|
+
resourceKeys: Array.from(new Set([
|
|
681
|
+
...oldResourceKeys,
|
|
682
|
+
...this.getSheetResourceKeys({
|
|
683
|
+
workbookName: opts.workbookName,
|
|
684
|
+
sheetName: opts.newSheetName
|
|
685
|
+
})
|
|
686
|
+
]))
|
|
687
|
+
});
|
|
450
688
|
}
|
|
451
689
|
hasSheet(opts) {
|
|
452
690
|
return !!this.workbookManager.getSheet(opts);
|
|
@@ -473,34 +711,197 @@ class FormulaEngine {
|
|
|
473
711
|
return this.workbookManager.getSheetSerialized(opts);
|
|
474
712
|
}
|
|
475
713
|
addWorkbook(workbookName) {
|
|
476
|
-
this.
|
|
714
|
+
this.workbookManager.addWorkbook(workbookName);
|
|
715
|
+
this.namedExpressionManager.addWorkbook(workbookName);
|
|
716
|
+
this.tableManager.addWorkbook(workbookName);
|
|
717
|
+
this.emitMutation({
|
|
718
|
+
touchedCells: [],
|
|
719
|
+
resourceKeys: [import_resource_keys.getWorkbookResourceKey(workbookName)]
|
|
720
|
+
});
|
|
477
721
|
}
|
|
478
722
|
removeWorkbook(workbookName) {
|
|
479
|
-
|
|
723
|
+
const resourceKeys = this.getWorkbookResourceKeys(workbookName);
|
|
724
|
+
this.workbookManager.removeWorkbook(workbookName);
|
|
725
|
+
this.namedExpressionManager.removeWorkbook(workbookName);
|
|
726
|
+
this.tableManager.removeWorkbook(workbookName);
|
|
727
|
+
this.styleManager.removeWorkbookStyles(workbookName);
|
|
728
|
+
this.referenceManager.invalidateWorkbook(workbookName);
|
|
729
|
+
this.emitMutation({
|
|
730
|
+
touchedCells: [],
|
|
731
|
+
resourceKeys,
|
|
732
|
+
removedScopes: [{ type: "workbook", workbookName }]
|
|
733
|
+
});
|
|
480
734
|
}
|
|
481
735
|
hasWorkbook(workbookName) {
|
|
482
736
|
return this.workbookManager.getWorkbooks().has(workbookName);
|
|
483
737
|
}
|
|
484
738
|
cloneWorkbook(fromWorkbookName, toWorkbookName) {
|
|
485
|
-
|
|
739
|
+
const sourceWorkbook = this.workbookManager.getWorkbooks().get(fromWorkbookName);
|
|
740
|
+
if (!sourceWorkbook) {
|
|
741
|
+
throw new Error(`Source workbook "${fromWorkbookName}" not found`);
|
|
742
|
+
}
|
|
743
|
+
if (this.workbookManager.getWorkbooks().has(toWorkbookName)) {
|
|
744
|
+
throw new Error(`Target workbook "${toWorkbookName}" already exists`);
|
|
745
|
+
}
|
|
746
|
+
this.workbookManager.addWorkbook(toWorkbookName);
|
|
747
|
+
this.namedExpressionManager.addWorkbook(toWorkbookName);
|
|
748
|
+
this.tableManager.addWorkbook(toWorkbookName);
|
|
749
|
+
for (const [sheetName, sheet] of sourceWorkbook.sheets) {
|
|
750
|
+
this.workbookManager.addSheet({
|
|
751
|
+
workbookName: toWorkbookName,
|
|
752
|
+
sheetName
|
|
753
|
+
});
|
|
754
|
+
this.namedExpressionManager.addSheet({
|
|
755
|
+
workbookName: toWorkbookName,
|
|
756
|
+
sheetName
|
|
757
|
+
});
|
|
758
|
+
this.workbookManager.setSheetContent({ workbookName: toWorkbookName, sheetName }, new Map(sheet.content));
|
|
759
|
+
const targetSheet = this.workbookManager.getSheet({
|
|
760
|
+
workbookName: toWorkbookName,
|
|
761
|
+
sheetName
|
|
762
|
+
});
|
|
763
|
+
if (targetSheet) {
|
|
764
|
+
targetSheet.metadata = new Map(sheet.metadata);
|
|
765
|
+
if (sheet.sheetMetadata !== undefined) {
|
|
766
|
+
targetSheet.sheetMetadata = structuredClone(sheet.sheetMetadata);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
const targetWorkbook = this.workbookManager.getWorkbooks().get(toWorkbookName);
|
|
771
|
+
if (targetWorkbook && sourceWorkbook.workbookMetadata !== undefined) {
|
|
772
|
+
targetWorkbook.workbookMetadata = structuredClone(sourceWorkbook.workbookMetadata);
|
|
773
|
+
}
|
|
774
|
+
const namedExpressions = this.namedExpressionManager.getNamedExpressions();
|
|
775
|
+
const sourceWorkbookExpressions = namedExpressions.workbookExpressions.get(fromWorkbookName);
|
|
776
|
+
if (sourceWorkbookExpressions) {
|
|
777
|
+
for (const [expressionName, expression] of sourceWorkbookExpressions) {
|
|
778
|
+
this.namedExpressionManager.addNamedExpression({
|
|
779
|
+
expressionName,
|
|
780
|
+
expression: expression.expression,
|
|
781
|
+
workbookName: toWorkbookName
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
const sourceSheetExpressions = namedExpressions.sheetExpressions.get(fromWorkbookName);
|
|
786
|
+
if (sourceSheetExpressions) {
|
|
787
|
+
for (const [sheetName, expressions] of sourceSheetExpressions) {
|
|
788
|
+
for (const [expressionName, expression] of expressions) {
|
|
789
|
+
this.namedExpressionManager.addNamedExpression({
|
|
790
|
+
expressionName,
|
|
791
|
+
expression: expression.expression,
|
|
792
|
+
workbookName: toWorkbookName,
|
|
793
|
+
sheetName
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
const sourceTables = this.tableManager.tables.get(fromWorkbookName);
|
|
799
|
+
if (sourceTables) {
|
|
800
|
+
for (const [tableName] of sourceTables) {
|
|
801
|
+
this.tableManager.copyTable({ workbookName: fromWorkbookName, tableName }, { workbookName: toWorkbookName, tableName });
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
for (const style of this.styleManager.getAllConditionalStyles()) {
|
|
805
|
+
if (style.areas.some((area) => area.workbookName === fromWorkbookName)) {
|
|
806
|
+
this.styleManager.addConditionalStyle({
|
|
807
|
+
...style,
|
|
808
|
+
areas: style.areas.map((area) => area.workbookName === fromWorkbookName ? { ...area, workbookName: toWorkbookName } : area)
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
for (const style of this.styleManager.getAllCellStyles()) {
|
|
813
|
+
if (style.areas.some((area) => area.workbookName === fromWorkbookName)) {
|
|
814
|
+
this.styleManager.addCellStyle({
|
|
815
|
+
...style,
|
|
816
|
+
areas: style.areas.map((area) => area.workbookName === fromWorkbookName ? { ...area, workbookName: toWorkbookName } : area)
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
this.workbookManager.updateFormulasForWorkbook(toWorkbookName, (formula) => import_workbook_renamer.renameWorkbookInFormula({
|
|
821
|
+
formula,
|
|
822
|
+
oldWorkbookName: fromWorkbookName,
|
|
823
|
+
newWorkbookName: toWorkbookName
|
|
824
|
+
}));
|
|
825
|
+
this.emitMutation({
|
|
826
|
+
touchedCells: [],
|
|
827
|
+
resourceKeys: [import_resource_keys.getWorkbookResourceKey(toWorkbookName)]
|
|
828
|
+
});
|
|
486
829
|
}
|
|
487
830
|
renameWorkbook(opts) {
|
|
488
|
-
|
|
831
|
+
const oldResourceKeys = this.getWorkbookResourceKeys(opts.workbookName);
|
|
832
|
+
this.workbookManager.renameWorkbook(opts);
|
|
833
|
+
this.namedExpressionManager.renameWorkbook(opts);
|
|
834
|
+
this.tableManager.updateTablesForWorkbookRename(opts);
|
|
835
|
+
this.styleManager.updateWorkbookName(opts.workbookName, opts.newWorkbookName);
|
|
836
|
+
const changedCells = this.workbookManager.updateAllFormulas((formula) => import_workbook_renamer.renameWorkbookInFormula({
|
|
837
|
+
formula,
|
|
838
|
+
oldWorkbookName: opts.workbookName,
|
|
839
|
+
newWorkbookName: opts.newWorkbookName
|
|
840
|
+
}));
|
|
841
|
+
this.referenceManager.updateWorkbookName(opts.workbookName, opts.newWorkbookName);
|
|
842
|
+
this.emitMutation({
|
|
843
|
+
touchedCells: import_mutation_invalidation.buildFormulaTouchedCells(changedCells),
|
|
844
|
+
resourceKeys: Array.from(new Set([
|
|
845
|
+
...oldResourceKeys,
|
|
846
|
+
...this.getWorkbookResourceKeys(opts.newWorkbookName)
|
|
847
|
+
]))
|
|
848
|
+
});
|
|
489
849
|
}
|
|
490
850
|
getWorkbooks() {
|
|
491
851
|
return this.workbookManager.getWorkbooks();
|
|
492
852
|
}
|
|
493
853
|
setSheetContent(opts, content) {
|
|
494
|
-
|
|
854
|
+
const previousContent = this.getExistingSheetContent(opts);
|
|
855
|
+
this.workbookManager.setSheetContent(opts, content);
|
|
856
|
+
this.emitMutation({
|
|
857
|
+
touchedCells: import_mutation_invalidation.buildSheetContentTouchedCells(opts, previousContent, content),
|
|
858
|
+
resourceKeys: []
|
|
859
|
+
});
|
|
495
860
|
}
|
|
496
861
|
setCellContent(address, content) {
|
|
497
|
-
|
|
862
|
+
const previousValue = this.workbookManager.getCellContent(address);
|
|
863
|
+
this.workbookManager.setCellContent(address, content);
|
|
864
|
+
this.emitMutation({
|
|
865
|
+
touchedCells: import_mutation_invalidation.buildTouchedCells([
|
|
866
|
+
{
|
|
867
|
+
address,
|
|
868
|
+
before: previousValue,
|
|
869
|
+
after: content
|
|
870
|
+
}
|
|
871
|
+
]),
|
|
872
|
+
resourceKeys: []
|
|
873
|
+
});
|
|
498
874
|
}
|
|
499
875
|
autoFill(opts, seedRange, fillRanges, direction) {
|
|
500
|
-
|
|
876
|
+
const touchedAddresses = this.dedupeAddresses(fillRanges.flatMap((range) => import_mutation_invalidation.getFiniteRangeAddresses({
|
|
877
|
+
workbookName: opts.workbookName,
|
|
878
|
+
sheetName: opts.sheetName,
|
|
879
|
+
range
|
|
880
|
+
})));
|
|
881
|
+
const before = import_mutation_invalidation.captureCellContents(this.workbookManager, touchedAddresses);
|
|
882
|
+
this.autoFillManager.fill(opts, seedRange, fillRanges, direction);
|
|
883
|
+
const after = import_mutation_invalidation.captureCellContents(this.workbookManager, touchedAddresses);
|
|
884
|
+
this.emitMutation({
|
|
885
|
+
touchedCells: import_mutation_invalidation.buildTouchedCells(touchedAddresses.map((address) => ({
|
|
886
|
+
address,
|
|
887
|
+
before: before.get(import_mutation_invalidation.getMutationAddressKey(address)),
|
|
888
|
+
after: after.get(import_mutation_invalidation.getMutationAddressKey(address))
|
|
889
|
+
}))),
|
|
890
|
+
resourceKeys: []
|
|
891
|
+
});
|
|
501
892
|
}
|
|
502
893
|
clearSpreadsheetRange(address) {
|
|
503
|
-
|
|
894
|
+
const clearedCells = Array.from(this.workbookManager.iterateCellsInRange(address));
|
|
895
|
+
const before = import_mutation_invalidation.captureCellContents(this.workbookManager, clearedCells);
|
|
896
|
+
this.workbookManager.clearSpreadsheetRange(address);
|
|
897
|
+
this.emitMutation({
|
|
898
|
+
touchedCells: import_mutation_invalidation.buildTouchedCells(clearedCells.map((cellAddress) => ({
|
|
899
|
+
address: cellAddress,
|
|
900
|
+
before: before.get(import_mutation_invalidation.getMutationAddressKey(cellAddress)),
|
|
901
|
+
after: undefined
|
|
902
|
+
}))),
|
|
903
|
+
resourceKeys: []
|
|
904
|
+
});
|
|
504
905
|
}
|
|
505
906
|
getState() {
|
|
506
907
|
return {
|
|
@@ -556,60 +957,8 @@ class FormulaEngine {
|
|
|
556
957
|
dependency: deserialized.managers.dependency,
|
|
557
958
|
cache: deserialized.managers.cache
|
|
558
959
|
}, this.evaluationManager);
|
|
559
|
-
this.commandExecutor.clearHistory();
|
|
560
|
-
this.commandExecutor.clearActionLog();
|
|
561
960
|
this.eventManager.emitUpdate();
|
|
562
961
|
}
|
|
563
|
-
undo() {
|
|
564
|
-
return this.commandExecutor.undo();
|
|
565
|
-
}
|
|
566
|
-
redo() {
|
|
567
|
-
return this.commandExecutor.redo();
|
|
568
|
-
}
|
|
569
|
-
canUndo() {
|
|
570
|
-
return this.commandExecutor.canUndo();
|
|
571
|
-
}
|
|
572
|
-
canRedo() {
|
|
573
|
-
return this.commandExecutor.canRedo();
|
|
574
|
-
}
|
|
575
|
-
getActionLog() {
|
|
576
|
-
return this.commandExecutor.getActionLog();
|
|
577
|
-
}
|
|
578
|
-
clearActionLog() {
|
|
579
|
-
this.commandExecutor.clearActionLog();
|
|
580
|
-
}
|
|
581
|
-
clearHistory() {
|
|
582
|
-
this.commandExecutor.clearHistory();
|
|
583
|
-
}
|
|
584
|
-
getStructureCommandDeps() {
|
|
585
|
-
return {
|
|
586
|
-
workbookManager: this.workbookManager,
|
|
587
|
-
namedExpressionManager: this.namedExpressionManager,
|
|
588
|
-
tableManager: this.tableManager,
|
|
589
|
-
styleManager: this.styleManager,
|
|
590
|
-
referenceManager: this.referenceManager,
|
|
591
|
-
apiSchemaManager: this.schemaManager,
|
|
592
|
-
renameSheetInFormula: import_sheet_renamer.renameSheetInFormula,
|
|
593
|
-
renameWorkbookInFormula: import_workbook_renamer.renameWorkbookInFormula
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
getTableCommandDeps() {
|
|
597
|
-
return {
|
|
598
|
-
tableManager: this.tableManager,
|
|
599
|
-
namedExpressionManager: this.namedExpressionManager,
|
|
600
|
-
workbookManager: this.workbookManager,
|
|
601
|
-
apiSchemaManager: this.schemaManager,
|
|
602
|
-
getCellValue: (cell) => this.getCellValue(cell),
|
|
603
|
-
renameTableInFormula: import_table_renamer.renameTableInFormula
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
getNamedExpressionCommandDeps() {
|
|
607
|
-
return {
|
|
608
|
-
namedExpressionManager: this.namedExpressionManager,
|
|
609
|
-
workbookManager: this.workbookManager,
|
|
610
|
-
renameNamedExpressionInFormula: import_named_expression_renamer.renameNamedExpressionInFormula
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
962
|
}
|
|
614
963
|
|
|
615
|
-
//# debugId=
|
|
964
|
+
//# debugId=1447559B44E2B85C64756E2164756E21
|