@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
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,26 +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
|
|
107
|
+
static buildEmpty() {
|
|
108
|
+
return new FormulaEngine;
|
|
109
|
+
}
|
|
110
|
+
emitMutation(footprint) {
|
|
111
|
+
this.evaluationManager.invalidateFromMutation(footprint);
|
|
112
|
+
this.eventManager.emitUpdate();
|
|
131
113
|
}
|
|
132
|
-
|
|
133
|
-
this.
|
|
134
|
-
const orm = new import_table_orm.TableOrm(this, address.workbookName, address.tableName, headers, namespace);
|
|
135
|
-
this.schema[namespace] = orm;
|
|
136
|
-
return orm;
|
|
114
|
+
emitUpdate() {
|
|
115
|
+
this.eventManager.emitUpdate();
|
|
137
116
|
}
|
|
138
|
-
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
this.schema[namespace] = orm;
|
|
142
|
-
return orm;
|
|
117
|
+
getExistingSheetContent(opts) {
|
|
118
|
+
const sheet = this.workbookManager.getSheet(opts);
|
|
119
|
+
return sheet ? new Map(sheet.content) : undefined;
|
|
143
120
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
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 }));
|
|
125
|
+
}
|
|
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
|
+
}
|
|
142
|
+
}
|
|
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);
|
|
149
164
|
}
|
|
150
165
|
getCellEvaluationResult(cellAddress) {
|
|
151
166
|
return this.evaluationManager.getCellEvaluationResult(cellAddress);
|
|
@@ -158,7 +173,8 @@ class FormulaEngine {
|
|
|
158
173
|
return this.evaluationManager.evaluationResultToSerializedValue(result, cellAddress, debug);
|
|
159
174
|
}
|
|
160
175
|
setCellMetadata(address, metadata) {
|
|
161
|
-
this.
|
|
176
|
+
this.workbookManager.setCellMetadata(address, metadata);
|
|
177
|
+
this.emitUpdate();
|
|
162
178
|
}
|
|
163
179
|
getCellMetadata(address) {
|
|
164
180
|
const metadata = this.workbookManager.getCellMetadata(address);
|
|
@@ -168,13 +184,15 @@ class FormulaEngine {
|
|
|
168
184
|
return this.workbookManager.getSheetMetadataSerialized(opts);
|
|
169
185
|
}
|
|
170
186
|
setSheetMetadata(opts, metadata) {
|
|
171
|
-
this.
|
|
187
|
+
this.workbookManager.setSheetMetadata(opts, metadata);
|
|
188
|
+
this.emitUpdate();
|
|
172
189
|
}
|
|
173
190
|
getSheetMetadata(opts) {
|
|
174
191
|
return this.workbookManager.getSheetMetadata(opts);
|
|
175
192
|
}
|
|
176
193
|
setWorkbookMetadata(workbookName, metadata) {
|
|
177
|
-
this.
|
|
194
|
+
this.workbookManager.setWorkbookMetadata(workbookName, metadata);
|
|
195
|
+
this.emitUpdate();
|
|
178
196
|
}
|
|
179
197
|
getWorkbookMetadata(workbookName) {
|
|
180
198
|
return this.workbookManager.getWorkbookMetadata(workbookName);
|
|
@@ -201,10 +219,20 @@ class FormulaEngine {
|
|
|
201
219
|
throw new Error("Not implemented");
|
|
202
220
|
}
|
|
203
221
|
addNamedExpression(opts) {
|
|
204
|
-
this.
|
|
222
|
+
this.namedExpressionManager.addNamedExpression(opts);
|
|
223
|
+
this.emitMutation({
|
|
224
|
+
touchedCells: [],
|
|
225
|
+
resourceKeys: [import_resource_keys.getNamedExpressionResourceKey(opts)]
|
|
226
|
+
});
|
|
205
227
|
}
|
|
206
228
|
removeNamedExpression(opts) {
|
|
207
|
-
|
|
229
|
+
const removed = this.namedExpressionManager.removeNamedExpression(opts);
|
|
230
|
+
if (removed) {
|
|
231
|
+
this.emitMutation({
|
|
232
|
+
touchedCells: [],
|
|
233
|
+
resourceKeys: [import_resource_keys.getNamedExpressionResourceKey(opts)]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
208
236
|
}
|
|
209
237
|
hasNamedExpression(opts) {
|
|
210
238
|
const scope = opts.sheetName && opts.workbookName ? {
|
|
@@ -218,25 +246,154 @@ class FormulaEngine {
|
|
|
218
246
|
});
|
|
219
247
|
}
|
|
220
248
|
updateNamedExpression(opts) {
|
|
221
|
-
this.
|
|
249
|
+
this.namedExpressionManager.updateNamedExpression(opts);
|
|
250
|
+
this.emitMutation({
|
|
251
|
+
touchedCells: [],
|
|
252
|
+
resourceKeys: [import_resource_keys.getNamedExpressionResourceKey(opts)]
|
|
253
|
+
});
|
|
222
254
|
}
|
|
223
255
|
renameNamedExpression(opts) {
|
|
224
|
-
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
|
+
});
|
|
225
275
|
}
|
|
226
276
|
setNamedExpressions(opts) {
|
|
227
|
-
|
|
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
|
+
});
|
|
228
299
|
}
|
|
229
300
|
addTable(props) {
|
|
230
|
-
|
|
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
|
+
});
|
|
231
315
|
}
|
|
232
316
|
renameTable(workbookName, names) {
|
|
233
|
-
|
|
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
|
+
});
|
|
234
344
|
}
|
|
235
345
|
updateTable(opts) {
|
|
236
|
-
|
|
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
|
+
});
|
|
237
369
|
}
|
|
238
370
|
removeTable(opts) {
|
|
239
|
-
|
|
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
|
+
})));
|
|
240
397
|
}
|
|
241
398
|
hasTable(opts) {
|
|
242
399
|
return !!this.tableManager.getTable({
|
|
@@ -251,7 +408,21 @@ class FormulaEngine {
|
|
|
251
408
|
});
|
|
252
409
|
}
|
|
253
410
|
resetTables(tables) {
|
|
254
|
-
|
|
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
|
+
});
|
|
255
426
|
}
|
|
256
427
|
getTables(workbookName) {
|
|
257
428
|
return this.tableManager.getTables(workbookName);
|
|
@@ -259,28 +430,15 @@ class FormulaEngine {
|
|
|
259
430
|
isCellInTable(cellAddress) {
|
|
260
431
|
return this.tableManager.isCellInTable(cellAddress);
|
|
261
432
|
}
|
|
262
|
-
getTableDataCells(table) {
|
|
263
|
-
const { start, endRow, headers } = table;
|
|
264
|
-
const dataStartRow = start.rowIndex + 1;
|
|
265
|
-
const endColIndex = start.colIndex + headers.size - 1;
|
|
266
|
-
const rangeAddress = {
|
|
267
|
-
workbookName: table.workbookName,
|
|
268
|
-
sheetName: table.sheetName,
|
|
269
|
-
range: {
|
|
270
|
-
start: { col: start.colIndex, row: dataStartRow },
|
|
271
|
-
end: {
|
|
272
|
-
col: { type: "number", value: endColIndex },
|
|
273
|
-
row: endRow
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
return this.workbookManager.getCellsInRange(rangeAddress);
|
|
278
|
-
}
|
|
279
433
|
addConditionalStyle(style) {
|
|
280
|
-
this.
|
|
434
|
+
this.styleManager.addConditionalStyle(style);
|
|
435
|
+
this.emitUpdate();
|
|
281
436
|
}
|
|
282
437
|
removeConditionalStyle(workbookName, index) {
|
|
283
|
-
this.
|
|
438
|
+
const removed = this.styleManager.removeConditionalStyle(workbookName, index);
|
|
439
|
+
if (removed) {
|
|
440
|
+
this.emitUpdate();
|
|
441
|
+
}
|
|
284
442
|
}
|
|
285
443
|
getConditionalStyleCount(workbookName) {
|
|
286
444
|
const allStyles = this.styleManager.getAllConditionalStyles();
|
|
@@ -299,10 +457,14 @@ class FormulaEngine {
|
|
|
299
457
|
return this.styleManager.getAllConditionalStyles();
|
|
300
458
|
}
|
|
301
459
|
addCellStyle(style) {
|
|
302
|
-
this.
|
|
460
|
+
this.styleManager.addCellStyle(style);
|
|
461
|
+
this.emitUpdate();
|
|
303
462
|
}
|
|
304
463
|
removeCellStyle(workbookName, index) {
|
|
305
|
-
this.
|
|
464
|
+
const removed = this.styleManager.removeCellStyle(workbookName, index);
|
|
465
|
+
if (removed) {
|
|
466
|
+
this.emitUpdate();
|
|
467
|
+
}
|
|
306
468
|
}
|
|
307
469
|
getCellStyleCount(workbookName) {
|
|
308
470
|
const allStyles = this.styleManager.getAllCellStyles();
|
|
@@ -315,13 +477,69 @@ class FormulaEngine {
|
|
|
315
477
|
return this.styleManager.getStyleForRange(range);
|
|
316
478
|
}
|
|
317
479
|
clearCellStyles(range) {
|
|
318
|
-
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);
|
|
319
509
|
}
|
|
320
510
|
pasteCells(source, target, options) {
|
|
321
|
-
|
|
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
|
+
});
|
|
322
526
|
}
|
|
323
527
|
fillAreas(seedRange, targetRanges, options) {
|
|
324
|
-
|
|
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
|
+
});
|
|
325
543
|
}
|
|
326
544
|
smartPaste(sourceCells, pasteSelection, options) {
|
|
327
545
|
if (sourceCells.length === 0) {
|
|
@@ -402,17 +620,27 @@ class FormulaEngine {
|
|
|
402
620
|
return { minCol, minRow, maxCol, maxRow };
|
|
403
621
|
}
|
|
404
622
|
moveCell(source, target) {
|
|
405
|
-
this.
|
|
623
|
+
this.pasteCells([source], target, {
|
|
624
|
+
cut: true,
|
|
625
|
+
type: "formula",
|
|
626
|
+
include: "all"
|
|
627
|
+
});
|
|
406
628
|
}
|
|
407
629
|
moveRange(sourceRange, target) {
|
|
408
|
-
|
|
630
|
+
const cells = this.copyManager.expandRangeToCells(sourceRange);
|
|
631
|
+
this.pasteCells(cells, target, {
|
|
632
|
+
cut: true,
|
|
633
|
+
type: "formula",
|
|
634
|
+
include: "all"
|
|
635
|
+
});
|
|
409
636
|
}
|
|
410
637
|
addSheet(opts) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
+
});
|
|
416
644
|
return sheet;
|
|
417
645
|
}
|
|
418
646
|
createSheet(opts) {
|
|
@@ -423,10 +651,40 @@ class FormulaEngine {
|
|
|
423
651
|
});
|
|
424
652
|
}
|
|
425
653
|
removeSheet(opts) {
|
|
426
|
-
|
|
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
|
+
});
|
|
427
665
|
}
|
|
428
666
|
renameSheet(opts) {
|
|
429
|
-
|
|
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
|
+
});
|
|
430
688
|
}
|
|
431
689
|
hasSheet(opts) {
|
|
432
690
|
return !!this.workbookManager.getSheet(opts);
|
|
@@ -453,34 +711,197 @@ class FormulaEngine {
|
|
|
453
711
|
return this.workbookManager.getSheetSerialized(opts);
|
|
454
712
|
}
|
|
455
713
|
addWorkbook(workbookName) {
|
|
456
|
-
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
|
+
});
|
|
457
721
|
}
|
|
458
722
|
removeWorkbook(workbookName) {
|
|
459
|
-
|
|
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
|
+
});
|
|
460
734
|
}
|
|
461
735
|
hasWorkbook(workbookName) {
|
|
462
736
|
return this.workbookManager.getWorkbooks().has(workbookName);
|
|
463
737
|
}
|
|
464
738
|
cloneWorkbook(fromWorkbookName, toWorkbookName) {
|
|
465
|
-
|
|
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
|
+
});
|
|
466
829
|
}
|
|
467
830
|
renameWorkbook(opts) {
|
|
468
|
-
|
|
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
|
+
});
|
|
469
849
|
}
|
|
470
850
|
getWorkbooks() {
|
|
471
851
|
return this.workbookManager.getWorkbooks();
|
|
472
852
|
}
|
|
473
853
|
setSheetContent(opts, content) {
|
|
474
|
-
|
|
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
|
+
});
|
|
475
860
|
}
|
|
476
861
|
setCellContent(address, content) {
|
|
477
|
-
|
|
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
|
+
});
|
|
478
874
|
}
|
|
479
875
|
autoFill(opts, seedRange, fillRanges, direction) {
|
|
480
|
-
|
|
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
|
+
});
|
|
481
892
|
}
|
|
482
893
|
clearSpreadsheetRange(address) {
|
|
483
|
-
|
|
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
|
+
});
|
|
484
905
|
}
|
|
485
906
|
getState() {
|
|
486
907
|
return {
|
|
@@ -536,60 +957,8 @@ class FormulaEngine {
|
|
|
536
957
|
dependency: deserialized.managers.dependency,
|
|
537
958
|
cache: deserialized.managers.cache
|
|
538
959
|
}, this.evaluationManager);
|
|
539
|
-
this.commandExecutor.clearHistory();
|
|
540
|
-
this.commandExecutor.clearActionLog();
|
|
541
960
|
this.eventManager.emitUpdate();
|
|
542
961
|
}
|
|
543
|
-
undo() {
|
|
544
|
-
return this.commandExecutor.undo();
|
|
545
|
-
}
|
|
546
|
-
redo() {
|
|
547
|
-
return this.commandExecutor.redo();
|
|
548
|
-
}
|
|
549
|
-
canUndo() {
|
|
550
|
-
return this.commandExecutor.canUndo();
|
|
551
|
-
}
|
|
552
|
-
canRedo() {
|
|
553
|
-
return this.commandExecutor.canRedo();
|
|
554
|
-
}
|
|
555
|
-
getActionLog() {
|
|
556
|
-
return this.commandExecutor.getActionLog();
|
|
557
|
-
}
|
|
558
|
-
clearActionLog() {
|
|
559
|
-
this.commandExecutor.clearActionLog();
|
|
560
|
-
}
|
|
561
|
-
clearHistory() {
|
|
562
|
-
this.commandExecutor.clearHistory();
|
|
563
|
-
}
|
|
564
|
-
getStructureCommandDeps() {
|
|
565
|
-
return {
|
|
566
|
-
workbookManager: this.workbookManager,
|
|
567
|
-
namedExpressionManager: this.namedExpressionManager,
|
|
568
|
-
tableManager: this.tableManager,
|
|
569
|
-
styleManager: this.styleManager,
|
|
570
|
-
referenceManager: this.referenceManager,
|
|
571
|
-
apiSchemaManager: this.schemaManager,
|
|
572
|
-
renameSheetInFormula: import_sheet_renamer.renameSheetInFormula,
|
|
573
|
-
renameWorkbookInFormula: import_workbook_renamer.renameWorkbookInFormula
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
getTableCommandDeps() {
|
|
577
|
-
return {
|
|
578
|
-
tableManager: this.tableManager,
|
|
579
|
-
namedExpressionManager: this.namedExpressionManager,
|
|
580
|
-
workbookManager: this.workbookManager,
|
|
581
|
-
apiSchemaManager: this.schemaManager,
|
|
582
|
-
getCellValue: (cell) => this.getCellValue(cell),
|
|
583
|
-
renameTableInFormula: import_table_renamer.renameTableInFormula
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
getNamedExpressionCommandDeps() {
|
|
587
|
-
return {
|
|
588
|
-
namedExpressionManager: this.namedExpressionManager,
|
|
589
|
-
workbookManager: this.workbookManager,
|
|
590
|
-
renameNamedExpressionInFormula: import_named_expression_renamer.renameNamedExpressionInFormula
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
962
|
}
|
|
594
963
|
|
|
595
|
-
//# debugId=
|
|
964
|
+
//# debugId=1447559B44E2B85C64756E2164756E21
|