@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.
Files changed (101) hide show
  1. package/README.md +1 -3
  2. package/dist/cjs/core/engine.cjs +515 -166
  3. package/dist/cjs/core/engine.cjs.map +3 -3
  4. package/dist/cjs/core/managers/dependency-manager.cjs.map +2 -2
  5. package/dist/cjs/core/managers/evaluation-manager.cjs.map +1 -1
  6. package/dist/cjs/core/mutation-invalidation.cjs +241 -0
  7. package/dist/cjs/core/mutation-invalidation.cjs.map +10 -0
  8. package/dist/cjs/lib.cjs +2 -13
  9. package/dist/cjs/lib.cjs.map +3 -3
  10. package/dist/cjs/package.json +1 -1
  11. package/dist/mjs/core/engine.mjs +529 -207
  12. package/dist/mjs/core/engine.mjs.map +3 -3
  13. package/dist/mjs/core/managers/dependency-manager.mjs.map +2 -2
  14. package/dist/mjs/core/managers/evaluation-manager.mjs.map +1 -1
  15. package/dist/mjs/core/mutation-invalidation.mjs +201 -0
  16. package/dist/mjs/core/mutation-invalidation.mjs.map +10 -0
  17. package/dist/mjs/lib.mjs +2 -13
  18. package/dist/mjs/lib.mjs.map +3 -3
  19. package/dist/mjs/package.json +1 -1
  20. package/dist/types/core/engine.d.ts +17 -135
  21. package/dist/types/core/managers/dependency-manager.d.ts +1 -1
  22. package/dist/types/core/managers/evaluation-manager.d.ts +1 -1
  23. package/dist/types/core/mutation-invalidation.d.ts +46 -0
  24. package/dist/types/lib.d.ts +0 -8
  25. package/package.json +1 -1
  26. package/dist/cjs/core/commands/command-executor.cjs +0 -149
  27. package/dist/cjs/core/commands/command-executor.cjs.map +0 -10
  28. package/dist/cjs/core/commands/content-commands.cjs +0 -857
  29. package/dist/cjs/core/commands/content-commands.cjs.map +0 -10
  30. package/dist/cjs/core/commands/metadata-commands.cjs +0 -160
  31. package/dist/cjs/core/commands/metadata-commands.cjs.map +0 -10
  32. package/dist/cjs/core/commands/named-expression-commands.cjs +0 -363
  33. package/dist/cjs/core/commands/named-expression-commands.cjs.map +0 -10
  34. package/dist/cjs/core/commands/structure-commands.cjs +0 -696
  35. package/dist/cjs/core/commands/structure-commands.cjs.map +0 -10
  36. package/dist/cjs/core/commands/style-commands.cjs +0 -229
  37. package/dist/cjs/core/commands/style-commands.cjs.map +0 -10
  38. package/dist/cjs/core/commands/table-commands.cjs +0 -495
  39. package/dist/cjs/core/commands/table-commands.cjs.map +0 -10
  40. package/dist/cjs/core/commands/types.cjs +0 -99
  41. package/dist/cjs/core/commands/types.cjs.map +0 -10
  42. package/dist/cjs/core/managers/schema-manager.cjs +0 -374
  43. package/dist/cjs/core/managers/schema-manager.cjs.map +0 -10
  44. package/dist/cjs/core/schema/cell-orm.cjs +0 -76
  45. package/dist/cjs/core/schema/cell-orm.cjs.map +0 -10
  46. package/dist/cjs/core/schema/grid-orm.cjs +0 -125
  47. package/dist/cjs/core/schema/grid-orm.cjs.map +0 -10
  48. package/dist/cjs/core/schema/schema-builder.cjs +0 -74
  49. package/dist/cjs/core/schema/schema-builder.cjs.map +0 -10
  50. package/dist/cjs/core/schema/schema-helpers.cjs +0 -200
  51. package/dist/cjs/core/schema/schema-helpers.cjs.map +0 -10
  52. package/dist/cjs/core/schema/schema.cjs +0 -91
  53. package/dist/cjs/core/schema/schema.cjs.map +0 -10
  54. package/dist/cjs/core/schema/table-orm.cjs +0 -189
  55. package/dist/cjs/core/schema/table-orm.cjs.map +0 -10
  56. package/dist/mjs/core/commands/command-executor.mjs +0 -109
  57. package/dist/mjs/core/commands/command-executor.mjs.map +0 -10
  58. package/dist/mjs/core/commands/content-commands.mjs +0 -821
  59. package/dist/mjs/core/commands/content-commands.mjs.map +0 -10
  60. package/dist/mjs/core/commands/metadata-commands.mjs +0 -120
  61. package/dist/mjs/core/commands/metadata-commands.mjs.map +0 -10
  62. package/dist/mjs/core/commands/named-expression-commands.mjs +0 -323
  63. package/dist/mjs/core/commands/named-expression-commands.mjs.map +0 -10
  64. package/dist/mjs/core/commands/structure-commands.mjs +0 -661
  65. package/dist/mjs/core/commands/structure-commands.mjs.map +0 -10
  66. package/dist/mjs/core/commands/style-commands.mjs +0 -189
  67. package/dist/mjs/core/commands/style-commands.mjs.map +0 -10
  68. package/dist/mjs/core/commands/table-commands.mjs +0 -459
  69. package/dist/mjs/core/commands/table-commands.mjs.map +0 -10
  70. package/dist/mjs/core/commands/types.mjs +0 -59
  71. package/dist/mjs/core/commands/types.mjs.map +0 -10
  72. package/dist/mjs/core/managers/schema-manager.mjs +0 -334
  73. package/dist/mjs/core/managers/schema-manager.mjs.map +0 -10
  74. package/dist/mjs/core/schema/cell-orm.mjs +0 -35
  75. package/dist/mjs/core/schema/cell-orm.mjs.map +0 -10
  76. package/dist/mjs/core/schema/grid-orm.mjs +0 -84
  77. package/dist/mjs/core/schema/grid-orm.mjs.map +0 -10
  78. package/dist/mjs/core/schema/schema-builder.mjs +0 -34
  79. package/dist/mjs/core/schema/schema-builder.mjs.map +0 -10
  80. package/dist/mjs/core/schema/schema-helpers.mjs +0 -160
  81. package/dist/mjs/core/schema/schema-helpers.mjs.map +0 -10
  82. package/dist/mjs/core/schema/schema.mjs +0 -51
  83. package/dist/mjs/core/schema/schema.mjs.map +0 -10
  84. package/dist/mjs/core/schema/table-orm.mjs +0 -156
  85. package/dist/mjs/core/schema/table-orm.mjs.map +0 -10
  86. package/dist/types/core/commands/command-executor.d.ts +0 -81
  87. package/dist/types/core/commands/content-commands.d.ts +0 -172
  88. package/dist/types/core/commands/metadata-commands.d.ts +0 -55
  89. package/dist/types/core/commands/named-expression-commands.d.ts +0 -130
  90. package/dist/types/core/commands/structure-commands.d.ts +0 -155
  91. package/dist/types/core/commands/style-commands.d.ts +0 -76
  92. package/dist/types/core/commands/table-commands.d.ts +0 -119
  93. package/dist/types/core/commands/types.d.ts +0 -143
  94. package/dist/types/core/managers/schema-manager.d.ts +0 -142
  95. package/dist/types/core/schema/cell-orm.d.ts +0 -33
  96. package/dist/types/core/schema/grid-orm.d.ts +0 -63
  97. package/dist/types/core/schema/schema-builder.d.ts +0 -16
  98. package/dist/types/core/schema/schema-helpers.d.ts +0 -49
  99. package/dist/types/core/schema/schema.d.ts +0 -167
  100. package/dist/types/core/schema/schema.type-test.d.ts +0 -1
  101. package/dist/types/core/schema/table-orm.d.ts +0 -46
@@ -1,857 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- function __accessProp(key) {
6
- return this[key];
7
- }
8
- var __toCommonJS = (from) => {
9
- var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
- if (entry)
11
- return entry;
12
- entry = __defProp({}, "__esModule", { value: true });
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (var key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(entry, key))
16
- __defProp(entry, key, {
17
- get: __accessProp.bind(from, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
20
- }
21
- __moduleCache.set(from, entry);
22
- return entry;
23
- };
24
- var __moduleCache;
25
- var __returnValue = (v) => v;
26
- function __exportSetter(name, newValue) {
27
- this[name] = __returnValue.bind(null, newValue);
28
- }
29
- var __export = (target, all) => {
30
- for (var name in all)
31
- __defProp(target, name, {
32
- get: all[name],
33
- enumerable: true,
34
- configurable: true,
35
- set: __exportSetter.bind(all, name)
36
- });
37
- };
38
-
39
- // src/core/commands/content-commands.ts
40
- var exports_content_commands = {};
41
- __export(exports_content_commands, {
42
- SetSheetContentCommand: () => SetSheetContentCommand,
43
- SetCellContentCommand: () => SetCellContentCommand,
44
- PasteCellsCommand: () => PasteCellsCommand,
45
- MoveRangeCommand: () => MoveRangeCommand,
46
- MoveCellCommand: () => MoveCellCommand,
47
- FillAreasCommand: () => FillAreasCommand,
48
- ClearRangeCommand: () => ClearRangeCommand,
49
- AutoFillCommand: () => AutoFillCommand
50
- });
51
- module.exports = __toCommonJS(exports_content_commands);
52
- var import_types = require("./types.cjs");
53
- var import_utils = require("../utils.cjs");
54
- function buildTouchedCells(cells) {
55
- const deduped = new Map;
56
- for (const cell of cells) {
57
- deduped.set(`${cell.address.workbookName}:${cell.address.sheetName}:${import_utils.getCellReference(cell.address)}`, {
58
- address: cell.address,
59
- beforeKind: import_types.getSerializedCellValueKind(cell.before),
60
- afterKind: import_types.getSerializedCellValueKind(cell.after)
61
- });
62
- }
63
- return Array.from(deduped.values());
64
- }
65
- function getAddressKey(address) {
66
- return `${address.workbookName}:${address.sheetName}:${import_utils.getCellReference(address)}`;
67
- }
68
- function captureCellContents(workbookManager, addresses) {
69
- const contents = new Map;
70
- for (const address of addresses) {
71
- contents.set(getAddressKey(address), workbookManager.getCellContent(address));
72
- }
73
- return contents;
74
- }
75
-
76
- class SetCellContentCommand {
77
- workbookManager;
78
- address;
79
- newContent;
80
- requiresReevaluation = true;
81
- previousValue;
82
- hadPreviousValue = false;
83
- executeFootprint = import_types.emptyMutationInvalidation();
84
- undoFootprint = import_types.emptyMutationInvalidation();
85
- constructor(workbookManager, address, newContent) {
86
- this.workbookManager = workbookManager;
87
- this.address = address;
88
- this.newContent = newContent;
89
- }
90
- execute() {
91
- const sheet = this.workbookManager.getSheet({
92
- workbookName: this.address.workbookName,
93
- sheetName: this.address.sheetName
94
- });
95
- if (sheet) {
96
- const key = import_utils.getCellReference(this.address);
97
- this.hadPreviousValue = sheet.content.has(key);
98
- this.previousValue = sheet.content.get(key);
99
- }
100
- this.workbookManager.setCellContent(this.address, this.newContent);
101
- this.executeFootprint = {
102
- touchedCells: buildTouchedCells([
103
- {
104
- address: this.address,
105
- before: this.previousValue,
106
- after: this.newContent
107
- }
108
- ]),
109
- resourceKeys: []
110
- };
111
- this.undoFootprint = {
112
- touchedCells: buildTouchedCells([
113
- {
114
- address: this.address,
115
- before: this.newContent,
116
- after: this.hadPreviousValue ? this.previousValue : undefined
117
- }
118
- ]),
119
- resourceKeys: []
120
- };
121
- }
122
- undo() {
123
- if (this.hadPreviousValue) {
124
- this.workbookManager.setCellContent(this.address, this.previousValue);
125
- } else {
126
- this.workbookManager.setCellContent(this.address, undefined);
127
- }
128
- }
129
- getInvalidationFootprint(phase) {
130
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
131
- }
132
- toAction() {
133
- return {
134
- type: import_types.ActionTypes.SET_CELL_CONTENT,
135
- payload: {
136
- address: this.address,
137
- content: this.newContent
138
- }
139
- };
140
- }
141
- }
142
-
143
- class SetSheetContentCommand {
144
- workbookManager;
145
- opts;
146
- newContent;
147
- requiresReevaluation = true;
148
- previousContent;
149
- executeFootprint = import_types.emptyMutationInvalidation();
150
- undoFootprint = import_types.emptyMutationInvalidation();
151
- constructor(workbookManager, opts, newContent) {
152
- this.workbookManager = workbookManager;
153
- this.opts = opts;
154
- this.newContent = newContent;
155
- }
156
- execute() {
157
- const sheet = this.workbookManager.getSheet(this.opts);
158
- if (sheet) {
159
- this.previousContent = new Map(sheet.content);
160
- }
161
- this.workbookManager.setSheetContent(this.opts, this.newContent);
162
- const touchedKeys = new Set([
163
- ...Array.from(this.previousContent?.keys() ?? []),
164
- ...Array.from(this.newContent.keys())
165
- ]);
166
- const touchedCells = buildTouchedCells(Array.from(touchedKeys, (key) => ({
167
- address: {
168
- workbookName: this.opts.workbookName,
169
- sheetName: this.opts.sheetName,
170
- ...import_utils.parseCellReference(key)
171
- },
172
- before: this.previousContent?.get(key),
173
- after: this.newContent.get(key)
174
- })));
175
- this.executeFootprint = {
176
- touchedCells,
177
- resourceKeys: []
178
- };
179
- this.undoFootprint = {
180
- touchedCells: buildTouchedCells(Array.from(touchedKeys, (key) => ({
181
- address: {
182
- workbookName: this.opts.workbookName,
183
- sheetName: this.opts.sheetName,
184
- ...import_utils.parseCellReference(key)
185
- },
186
- before: this.newContent.get(key),
187
- after: this.previousContent?.get(key)
188
- }))),
189
- resourceKeys: []
190
- };
191
- }
192
- undo() {
193
- if (this.previousContent) {
194
- this.workbookManager.setSheetContent(this.opts, this.previousContent);
195
- }
196
- }
197
- getInvalidationFootprint(phase) {
198
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
199
- }
200
- toAction() {
201
- return {
202
- type: import_types.ActionTypes.SET_SHEET_CONTENT,
203
- payload: {
204
- opts: this.opts,
205
- content: Array.from(this.newContent.entries())
206
- }
207
- };
208
- }
209
- }
210
-
211
- class ClearRangeCommand {
212
- workbookManager;
213
- address;
214
- requiresReevaluation = true;
215
- clearedCells = new Map;
216
- executeFootprint = import_types.emptyMutationInvalidation();
217
- undoFootprint = import_types.emptyMutationInvalidation();
218
- constructor(workbookManager, address) {
219
- this.workbookManager = workbookManager;
220
- this.address = address;
221
- }
222
- execute() {
223
- this.clearedCells.clear();
224
- try {
225
- for (const cellAddress of this.workbookManager.iterateCellsInRange(this.address)) {
226
- const key = import_utils.getCellReference(cellAddress);
227
- const value = this.workbookManager.getCellContent(cellAddress);
228
- if (value !== undefined) {
229
- this.clearedCells.set(key, value);
230
- }
231
- }
232
- } catch {}
233
- this.workbookManager.clearSpreadsheetRange(this.address);
234
- this.executeFootprint = {
235
- touchedCells: buildTouchedCells(Array.from(this.clearedCells.entries(), ([key, before]) => ({
236
- address: {
237
- workbookName: this.address.workbookName,
238
- sheetName: this.address.sheetName,
239
- ...import_utils.parseCellReference(key)
240
- },
241
- before,
242
- after: undefined
243
- }))),
244
- resourceKeys: []
245
- };
246
- this.undoFootprint = {
247
- touchedCells: buildTouchedCells(Array.from(this.clearedCells.entries(), ([key, after]) => ({
248
- address: {
249
- workbookName: this.address.workbookName,
250
- sheetName: this.address.sheetName,
251
- ...import_utils.parseCellReference(key)
252
- },
253
- before: undefined,
254
- after
255
- }))),
256
- resourceKeys: []
257
- };
258
- }
259
- undo() {
260
- for (const [key, value] of this.clearedCells) {
261
- const { colIndex, rowIndex } = import_utils.parseCellReference(key);
262
- this.workbookManager.setCellContent({
263
- workbookName: this.address.workbookName,
264
- sheetName: this.address.sheetName,
265
- colIndex,
266
- rowIndex
267
- }, value);
268
- }
269
- }
270
- getInvalidationFootprint(phase) {
271
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
272
- }
273
- toAction() {
274
- return {
275
- type: import_types.ActionTypes.CLEAR_RANGE,
276
- payload: {
277
- address: this.address
278
- }
279
- };
280
- }
281
- }
282
-
283
- class PasteCellsCommand {
284
- workbookManager;
285
- copyManager;
286
- source;
287
- target;
288
- options;
289
- requiresReevaluation = true;
290
- targetSnapshots = [];
291
- sourceSnapshots = [];
292
- executeFootprint = import_types.emptyMutationInvalidation();
293
- undoFootprint = import_types.emptyMutationInvalidation();
294
- executedContents = new Map;
295
- constructor(workbookManager, copyManager, source, target, options) {
296
- this.workbookManager = workbookManager;
297
- this.copyManager = copyManager;
298
- this.source = source;
299
- this.target = target;
300
- this.options = options;
301
- }
302
- execute() {
303
- this.targetSnapshots = [];
304
- this.sourceSnapshots = [];
305
- this.executedContents.clear();
306
- if (this.source.length > 0) {
307
- const firstSource = this.source[0];
308
- const colOffset = this.target.colIndex - firstSource.colIndex;
309
- const rowOffset = this.target.rowIndex - firstSource.rowIndex;
310
- for (const sourceCell of this.source) {
311
- const targetCell = {
312
- workbookName: this.target.workbookName,
313
- sheetName: this.target.sheetName,
314
- colIndex: sourceCell.colIndex + colOffset,
315
- rowIndex: sourceCell.rowIndex + rowOffset
316
- };
317
- const sheet = this.workbookManager.getSheet({
318
- workbookName: targetCell.workbookName,
319
- sheetName: targetCell.sheetName
320
- });
321
- if (sheet) {
322
- const key = import_utils.getCellReference(targetCell);
323
- this.targetSnapshots.push({
324
- address: targetCell,
325
- content: sheet.content.get(key),
326
- metadata: sheet.metadata.get(key)
327
- });
328
- }
329
- }
330
- if (this.options.cut) {
331
- for (const sourceCell of this.source) {
332
- const sheet = this.workbookManager.getSheet({
333
- workbookName: sourceCell.workbookName,
334
- sheetName: sourceCell.sheetName
335
- });
336
- if (sheet) {
337
- const key = import_utils.getCellReference(sourceCell);
338
- this.sourceSnapshots.push({
339
- address: sourceCell,
340
- content: sheet.content.get(key),
341
- metadata: sheet.metadata.get(key)
342
- });
343
- }
344
- }
345
- }
346
- }
347
- this.copyManager.pasteCells(this.source, this.target, this.options);
348
- const touchedAddresses = [
349
- ...this.targetSnapshots.map((snapshot) => snapshot.address),
350
- ...this.sourceSnapshots.map((snapshot) => snapshot.address)
351
- ];
352
- this.executedContents = captureCellContents(this.workbookManager, touchedAddresses);
353
- this.executeFootprint = {
354
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => {
355
- const beforeSnapshot = this.targetSnapshots.find((snapshot) => snapshot.address.workbookName === address.workbookName && snapshot.address.sheetName === address.sheetName && snapshot.address.colIndex === address.colIndex && snapshot.address.rowIndex === address.rowIndex) ?? this.sourceSnapshots.find((snapshot) => snapshot.address.workbookName === address.workbookName && snapshot.address.sheetName === address.sheetName && snapshot.address.colIndex === address.colIndex && snapshot.address.rowIndex === address.rowIndex);
356
- return {
357
- address,
358
- before: beforeSnapshot?.content,
359
- after: this.executedContents.get(getAddressKey(address))
360
- };
361
- })),
362
- resourceKeys: []
363
- };
364
- }
365
- undo() {
366
- for (const snapshot of this.targetSnapshots) {
367
- this.workbookManager.setCellContent(snapshot.address, snapshot.content);
368
- if (snapshot.metadata !== undefined) {
369
- this.workbookManager.setCellMetadata(snapshot.address, snapshot.metadata);
370
- }
371
- }
372
- if (this.options.cut) {
373
- for (const snapshot of this.sourceSnapshots) {
374
- this.workbookManager.setCellContent(snapshot.address, snapshot.content);
375
- if (snapshot.metadata !== undefined) {
376
- this.workbookManager.setCellMetadata(snapshot.address, snapshot.metadata);
377
- }
378
- }
379
- }
380
- const touchedAddresses = [
381
- ...this.targetSnapshots.map((snapshot) => snapshot.address),
382
- ...this.sourceSnapshots.map((snapshot) => snapshot.address)
383
- ];
384
- this.undoFootprint = {
385
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => {
386
- return {
387
- address,
388
- before: this.executedContents.get(getAddressKey(address)),
389
- after: this.workbookManager.getCellContent(address)
390
- };
391
- })),
392
- resourceKeys: []
393
- };
394
- }
395
- getInvalidationFootprint(phase) {
396
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
397
- }
398
- toAction() {
399
- return {
400
- type: import_types.ActionTypes.PASTE_CELLS,
401
- payload: {
402
- source: this.source,
403
- target: this.target,
404
- options: this.options
405
- }
406
- };
407
- }
408
- }
409
-
410
- class FillAreasCommand {
411
- workbookManager;
412
- copyManager;
413
- seedRange;
414
- targetRanges;
415
- options;
416
- requiresReevaluation = true;
417
- targetSnapshots = new Map;
418
- executeFootprint = import_types.emptyMutationInvalidation();
419
- undoFootprint = import_types.emptyMutationInvalidation();
420
- executedContents = new Map;
421
- constructor(workbookManager, copyManager, seedRange, targetRanges, options) {
422
- this.workbookManager = workbookManager;
423
- this.copyManager = copyManager;
424
- this.seedRange = seedRange;
425
- this.targetRanges = targetRanges;
426
- this.options = options;
427
- }
428
- execute() {
429
- this.targetSnapshots.clear();
430
- this.executedContents.clear();
431
- for (const targetRange of this.targetRanges) {
432
- const sheet = this.workbookManager.getSheet({
433
- workbookName: targetRange.workbookName,
434
- sheetName: targetRange.sheetName
435
- });
436
- if (sheet) {
437
- const { start, end } = targetRange.range;
438
- const endCol = end.col.type === "number" ? end.col.value : start.col + 100;
439
- const endRow = end.row.type === "number" ? end.row.value : start.row + 100;
440
- for (let col = start.col;col <= endCol; col++) {
441
- for (let row = start.row;row <= endRow; row++) {
442
- const address = {
443
- workbookName: targetRange.workbookName,
444
- sheetName: targetRange.sheetName,
445
- colIndex: col,
446
- rowIndex: row
447
- };
448
- const key = import_utils.getCellReference(address);
449
- const fullKey = `${targetRange.workbookName}:${targetRange.sheetName}:${key}`;
450
- if (!this.targetSnapshots.has(fullKey)) {
451
- this.targetSnapshots.set(fullKey, {
452
- address,
453
- content: sheet.content.get(key),
454
- metadata: sheet.metadata.get(key)
455
- });
456
- }
457
- }
458
- }
459
- }
460
- }
461
- this.copyManager.fillAreas(this.seedRange, this.targetRanges, this.options);
462
- const touchedAddresses = Array.from(this.targetSnapshots.values()).map((snapshot) => snapshot.address);
463
- this.executedContents = captureCellContents(this.workbookManager, touchedAddresses);
464
- this.executeFootprint = {
465
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => ({
466
- address,
467
- before: this.targetSnapshots.get(getAddressKey(address))?.content,
468
- after: this.executedContents.get(getAddressKey(address))
469
- }))),
470
- resourceKeys: []
471
- };
472
- }
473
- undo() {
474
- for (const snapshot of this.targetSnapshots.values()) {
475
- this.workbookManager.setCellContent(snapshot.address, snapshot.content);
476
- if (snapshot.metadata !== undefined) {
477
- this.workbookManager.setCellMetadata(snapshot.address, snapshot.metadata);
478
- }
479
- }
480
- const touchedAddresses = Array.from(this.targetSnapshots.values()).map((snapshot) => snapshot.address);
481
- this.undoFootprint = {
482
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => ({
483
- address,
484
- before: this.executedContents.get(getAddressKey(address)),
485
- after: this.workbookManager.getCellContent(address)
486
- }))),
487
- resourceKeys: []
488
- };
489
- }
490
- getInvalidationFootprint(phase) {
491
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
492
- }
493
- toAction() {
494
- return {
495
- type: import_types.ActionTypes.FILL_AREAS,
496
- payload: {
497
- seedRange: this.seedRange,
498
- targetRanges: this.targetRanges,
499
- options: this.options
500
- }
501
- };
502
- }
503
- }
504
-
505
- class MoveCellCommand {
506
- workbookManager;
507
- copyManager;
508
- source;
509
- target;
510
- requiresReevaluation = true;
511
- sourceSnapshot;
512
- targetSnapshot;
513
- executeFootprint = import_types.emptyMutationInvalidation();
514
- undoFootprint = import_types.emptyMutationInvalidation();
515
- executedContents = new Map;
516
- constructor(workbookManager, copyManager, source, target) {
517
- this.workbookManager = workbookManager;
518
- this.copyManager = copyManager;
519
- this.source = source;
520
- this.target = target;
521
- }
522
- execute() {
523
- this.sourceSnapshot = undefined;
524
- this.targetSnapshot = undefined;
525
- this.executedContents.clear();
526
- const sourceSheet = this.workbookManager.getSheet({
527
- workbookName: this.source.workbookName,
528
- sheetName: this.source.sheetName
529
- });
530
- if (sourceSheet) {
531
- const key = import_utils.getCellReference(this.source);
532
- this.sourceSnapshot = {
533
- address: this.source,
534
- content: sourceSheet.content.get(key),
535
- metadata: sourceSheet.metadata.get(key)
536
- };
537
- }
538
- const targetSheet = this.workbookManager.getSheet({
539
- workbookName: this.target.workbookName,
540
- sheetName: this.target.sheetName
541
- });
542
- if (targetSheet) {
543
- const key = import_utils.getCellReference(this.target);
544
- this.targetSnapshot = {
545
- address: this.target,
546
- content: targetSheet.content.get(key),
547
- metadata: targetSheet.metadata.get(key)
548
- };
549
- }
550
- this.copyManager.pasteCells([this.source], this.target, {
551
- cut: true,
552
- type: "formula",
553
- include: "all"
554
- });
555
- const touchedAddresses = [this.source, this.target];
556
- this.executedContents = captureCellContents(this.workbookManager, touchedAddresses);
557
- this.executeFootprint = {
558
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => ({
559
- address,
560
- before: this.sourceSnapshot?.address === address ? this.sourceSnapshot.content : this.targetSnapshot?.content,
561
- after: this.executedContents.get(getAddressKey(address))
562
- }))),
563
- resourceKeys: []
564
- };
565
- }
566
- undo() {
567
- if (this.sourceSnapshot) {
568
- this.workbookManager.setCellContent(this.sourceSnapshot.address, this.sourceSnapshot.content);
569
- if (this.sourceSnapshot.metadata !== undefined) {
570
- this.workbookManager.setCellMetadata(this.sourceSnapshot.address, this.sourceSnapshot.metadata);
571
- }
572
- }
573
- if (this.targetSnapshot) {
574
- this.workbookManager.setCellContent(this.targetSnapshot.address, this.targetSnapshot.content);
575
- if (this.targetSnapshot.metadata !== undefined) {
576
- this.workbookManager.setCellMetadata(this.targetSnapshot.address, this.targetSnapshot.metadata);
577
- }
578
- }
579
- const touchedAddresses = [this.source, this.target];
580
- this.undoFootprint = {
581
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => ({
582
- address,
583
- before: this.executedContents.get(getAddressKey(address)),
584
- after: this.workbookManager.getCellContent(address)
585
- }))),
586
- resourceKeys: []
587
- };
588
- }
589
- getInvalidationFootprint(phase) {
590
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
591
- }
592
- toAction() {
593
- return {
594
- type: import_types.ActionTypes.MOVE_CELL,
595
- payload: {
596
- source: this.source,
597
- target: this.target
598
- }
599
- };
600
- }
601
- }
602
-
603
- class MoveRangeCommand {
604
- workbookManager;
605
- copyManager;
606
- sourceRange;
607
- target;
608
- requiresReevaluation = true;
609
- sourceSnapshots = [];
610
- targetSnapshots = [];
611
- executeFootprint = import_types.emptyMutationInvalidation();
612
- undoFootprint = import_types.emptyMutationInvalidation();
613
- executedContents = new Map;
614
- constructor(workbookManager, copyManager, sourceRange, target) {
615
- this.workbookManager = workbookManager;
616
- this.copyManager = copyManager;
617
- this.sourceRange = sourceRange;
618
- this.target = target;
619
- }
620
- execute() {
621
- this.sourceSnapshots = [];
622
- this.targetSnapshots = [];
623
- this.executedContents.clear();
624
- const sourceCells = this.copyManager.expandRangeToCells(this.sourceRange);
625
- for (const cell of sourceCells) {
626
- const sheet = this.workbookManager.getSheet({
627
- workbookName: cell.workbookName,
628
- sheetName: cell.sheetName
629
- });
630
- if (sheet) {
631
- const key = import_utils.getCellReference(cell);
632
- this.sourceSnapshots.push({
633
- address: cell,
634
- content: sheet.content.get(key),
635
- metadata: sheet.metadata.get(key)
636
- });
637
- }
638
- }
639
- if (sourceCells.length > 0) {
640
- const firstSource = sourceCells[0];
641
- const colOffset = this.target.colIndex - firstSource.colIndex;
642
- const rowOffset = this.target.rowIndex - firstSource.rowIndex;
643
- for (const sourceCell of sourceCells) {
644
- const targetCell = {
645
- workbookName: this.target.workbookName,
646
- sheetName: this.target.sheetName,
647
- colIndex: sourceCell.colIndex + colOffset,
648
- rowIndex: sourceCell.rowIndex + rowOffset
649
- };
650
- const sheet = this.workbookManager.getSheet({
651
- workbookName: targetCell.workbookName,
652
- sheetName: targetCell.sheetName
653
- });
654
- if (sheet) {
655
- const key = import_utils.getCellReference(targetCell);
656
- this.targetSnapshots.push({
657
- address: targetCell,
658
- content: sheet.content.get(key),
659
- metadata: sheet.metadata.get(key)
660
- });
661
- }
662
- }
663
- }
664
- this.copyManager.pasteCells(sourceCells, this.target, {
665
- cut: true,
666
- type: "formula",
667
- include: "all"
668
- });
669
- const touchedAddresses = [
670
- ...this.sourceSnapshots.map((snapshot) => snapshot.address),
671
- ...this.targetSnapshots.map((snapshot) => snapshot.address)
672
- ];
673
- this.executedContents = captureCellContents(this.workbookManager, touchedAddresses);
674
- this.executeFootprint = {
675
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => {
676
- const snapshot = this.sourceSnapshots.find((candidate) => getAddressKey(candidate.address) === getAddressKey(address)) ?? this.targetSnapshots.find((candidate) => getAddressKey(candidate.address) === getAddressKey(address));
677
- return {
678
- address,
679
- before: snapshot?.content,
680
- after: this.executedContents.get(getAddressKey(address))
681
- };
682
- })),
683
- resourceKeys: []
684
- };
685
- }
686
- undo() {
687
- for (const snapshot of this.sourceSnapshots) {
688
- this.workbookManager.setCellContent(snapshot.address, snapshot.content);
689
- if (snapshot.metadata !== undefined) {
690
- this.workbookManager.setCellMetadata(snapshot.address, snapshot.metadata);
691
- }
692
- }
693
- for (const snapshot of this.targetSnapshots) {
694
- this.workbookManager.setCellContent(snapshot.address, snapshot.content);
695
- if (snapshot.metadata !== undefined) {
696
- this.workbookManager.setCellMetadata(snapshot.address, snapshot.metadata);
697
- }
698
- }
699
- const touchedAddresses = [
700
- ...this.sourceSnapshots.map((snapshot) => snapshot.address),
701
- ...this.targetSnapshots.map((snapshot) => snapshot.address)
702
- ];
703
- this.undoFootprint = {
704
- touchedCells: buildTouchedCells(touchedAddresses.map((address) => ({
705
- address,
706
- before: this.executedContents.get(getAddressKey(address)),
707
- after: this.workbookManager.getCellContent(address)
708
- }))),
709
- resourceKeys: []
710
- };
711
- }
712
- getInvalidationFootprint(phase) {
713
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
714
- }
715
- toAction() {
716
- return {
717
- type: import_types.ActionTypes.MOVE_RANGE,
718
- payload: {
719
- sourceRange: this.sourceRange,
720
- target: this.target
721
- }
722
- };
723
- }
724
- }
725
-
726
- class AutoFillCommand {
727
- workbookManager;
728
- styleManager;
729
- autoFillManager;
730
- opts;
731
- seedRange;
732
- fillRanges;
733
- direction;
734
- requiresReevaluation = true;
735
- previousContent = new Map;
736
- previousMetadata = new Map;
737
- executeFootprint = import_types.emptyMutationInvalidation();
738
- undoFootprint = import_types.emptyMutationInvalidation();
739
- touchedAddresses = [];
740
- executedContents = new Map;
741
- constructor(workbookManager, styleManager, autoFillManager, opts, seedRange, fillRanges, direction) {
742
- this.workbookManager = workbookManager;
743
- this.styleManager = styleManager;
744
- this.autoFillManager = autoFillManager;
745
- this.opts = opts;
746
- this.seedRange = seedRange;
747
- this.fillRanges = fillRanges;
748
- this.direction = direction;
749
- }
750
- execute() {
751
- this.previousContent.clear();
752
- this.previousMetadata.clear();
753
- this.touchedAddresses = [];
754
- this.executedContents.clear();
755
- for (const fillRange of this.fillRanges) {
756
- if (fillRange.end.col.type === "infinity" || fillRange.end.row.type === "infinity") {
757
- continue;
758
- }
759
- const startCol = fillRange.start.col;
760
- const startRow = fillRange.start.row;
761
- const endCol = fillRange.end.col.value;
762
- const endRow = fillRange.end.row.value;
763
- for (let row = startRow;row <= endRow; row++) {
764
- for (let col = startCol;col <= endCol; col++) {
765
- const key = import_utils.getCellReference({ colIndex: col, rowIndex: row });
766
- const address = {
767
- workbookName: this.opts.workbookName,
768
- sheetName: this.opts.sheetName,
769
- colIndex: col,
770
- rowIndex: row
771
- };
772
- this.touchedAddresses.push(address);
773
- const content = this.workbookManager.getCellContent(address);
774
- if (content !== undefined) {
775
- this.previousContent.set(key, content);
776
- }
777
- const metadata = this.workbookManager.getCellMetadata(address);
778
- if (metadata !== undefined) {
779
- this.previousMetadata.set(key, metadata);
780
- }
781
- }
782
- }
783
- }
784
- this.autoFillManager.fill(this.opts, this.seedRange, this.fillRanges, this.direction);
785
- this.executedContents = captureCellContents(this.workbookManager, this.touchedAddresses);
786
- this.executeFootprint = {
787
- touchedCells: buildTouchedCells(this.touchedAddresses.map((address) => {
788
- const key = import_utils.getCellReference(address);
789
- return {
790
- address,
791
- before: this.previousContent.get(key),
792
- after: this.executedContents.get(getAddressKey(address))
793
- };
794
- })),
795
- resourceKeys: []
796
- };
797
- }
798
- undo() {
799
- const currentContent = this.workbookManager.getSheetSerialized(this.opts);
800
- const newContent = new Map(currentContent);
801
- for (const fillRange of this.fillRanges) {
802
- if (fillRange.end.col.type === "infinity" || fillRange.end.row.type === "infinity") {
803
- continue;
804
- }
805
- const startCol = fillRange.start.col;
806
- const startRow = fillRange.start.row;
807
- const endCol = fillRange.end.col.value;
808
- const endRow = fillRange.end.row.value;
809
- for (let row = startRow;row <= endRow; row++) {
810
- for (let col = startCol;col <= endCol; col++) {
811
- const key = import_utils.getCellReference({ colIndex: col, rowIndex: row });
812
- const address = {
813
- workbookName: this.opts.workbookName,
814
- sheetName: this.opts.sheetName,
815
- colIndex: col,
816
- rowIndex: row
817
- };
818
- if (this.previousContent.has(key)) {
819
- newContent.set(key, this.previousContent.get(key));
820
- } else {
821
- newContent.delete(key);
822
- }
823
- if (this.previousMetadata.has(key)) {
824
- this.workbookManager.setCellMetadata(address, this.previousMetadata.get(key));
825
- } else {
826
- this.workbookManager.setCellMetadata(address, undefined);
827
- }
828
- }
829
- }
830
- }
831
- this.workbookManager.setSheetContent(this.opts, newContent);
832
- this.undoFootprint = {
833
- touchedCells: buildTouchedCells(this.touchedAddresses.map((address) => ({
834
- address,
835
- before: this.executedContents.get(getAddressKey(address)),
836
- after: this.workbookManager.getCellContent(address)
837
- }))),
838
- resourceKeys: []
839
- };
840
- }
841
- getInvalidationFootprint(phase) {
842
- return phase === "execute" ? this.executeFootprint : this.undoFootprint;
843
- }
844
- toAction() {
845
- return {
846
- type: import_types.ActionTypes.AUTO_FILL,
847
- payload: {
848
- opts: this.opts,
849
- seedRange: this.seedRange,
850
- fillRanges: this.fillRanges,
851
- direction: this.direction
852
- }
853
- };
854
- }
855
- }
856
-
857
- //# debugId=7AAB2F977AF7BA6364756E2164756E21