@ricsam/formula-engine 0.0.17 → 0.0.18
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/dist/cjs/core/api/api-builder.cjs +67 -0
- package/dist/cjs/core/api/api-builder.cjs.map +10 -0
- package/dist/cjs/core/api/api-helpers.cjs +191 -0
- package/dist/cjs/core/api/api-helpers.cjs.map +10 -0
- package/dist/cjs/core/api/api.cjs +65 -0
- package/dist/cjs/core/api/api.cjs.map +10 -0
- package/dist/cjs/core/api/cell-orm.cjs +80 -0
- package/dist/cjs/core/api/cell-orm.cjs.map +10 -0
- package/dist/cjs/core/api/table-orm.cjs +171 -0
- package/dist/cjs/core/api/table-orm.cjs.map +10 -0
- package/dist/cjs/core/autofill-utils.cjs +3 -5
- package/dist/cjs/core/autofill-utils.cjs.map +3 -3
- package/dist/cjs/core/commands/command-executor.cjs +140 -0
- package/dist/cjs/core/commands/command-executor.cjs.map +10 -0
- package/dist/cjs/core/commands/content-commands.cjs +574 -0
- package/dist/cjs/core/commands/content-commands.cjs.map +10 -0
- package/dist/cjs/core/commands/index.cjs +95 -0
- package/dist/cjs/core/commands/index.cjs.map +10 -0
- package/dist/cjs/core/commands/metadata-commands.cjs +150 -0
- package/dist/cjs/core/commands/metadata-commands.cjs.map +10 -0
- package/dist/cjs/core/commands/named-expression-commands.cjs +238 -0
- package/dist/cjs/core/commands/named-expression-commands.cjs.map +10 -0
- package/dist/cjs/core/commands/structure-commands.cjs +495 -0
- package/dist/cjs/core/commands/structure-commands.cjs.map +10 -0
- package/dist/cjs/core/commands/style-commands.cjs +219 -0
- package/dist/cjs/core/commands/style-commands.cjs.map +10 -0
- package/dist/cjs/core/commands/table-commands.cjs +226 -0
- package/dist/cjs/core/commands/table-commands.cjs.map +10 -0
- package/dist/cjs/core/commands/types.cjs +72 -0
- package/dist/cjs/core/commands/types.cjs.map +10 -0
- package/dist/cjs/core/engine.cjs +159 -296
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/api-schema-manager.cjs +304 -0
- package/dist/cjs/core/managers/api-schema-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/copy-manager.cjs +1 -2
- package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
- package/dist/cjs/core/types.cjs.map +2 -2
- package/dist/cjs/lib.cjs +13 -2
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/api/api-builder.mjs +37 -0
- package/dist/mjs/core/api/api-builder.mjs.map +10 -0
- package/dist/mjs/core/api/api-helpers.mjs +161 -0
- package/dist/mjs/core/api/api-helpers.mjs.map +10 -0
- package/dist/mjs/core/api/api.mjs +35 -0
- package/dist/mjs/core/api/api.mjs.map +10 -0
- package/dist/mjs/core/api/cell-orm.mjs +49 -0
- package/dist/mjs/core/api/cell-orm.mjs.map +10 -0
- package/dist/mjs/core/api/table-orm.mjs +148 -0
- package/dist/mjs/core/api/table-orm.mjs.map +10 -0
- package/dist/mjs/core/autofill-utils.mjs +3 -5
- package/dist/mjs/core/autofill-utils.mjs.map +3 -3
- package/dist/mjs/core/commands/command-executor.mjs +109 -0
- package/dist/mjs/core/commands/command-executor.mjs.map +10 -0
- package/dist/mjs/core/commands/content-commands.mjs +544 -0
- package/dist/mjs/core/commands/content-commands.mjs.map +10 -0
- package/dist/mjs/core/commands/index.mjs +87 -0
- package/dist/mjs/core/commands/index.mjs.map +10 -0
- package/dist/mjs/core/commands/metadata-commands.mjs +120 -0
- package/dist/mjs/core/commands/metadata-commands.mjs.map +10 -0
- package/dist/mjs/core/commands/named-expression-commands.mjs +208 -0
- package/dist/mjs/core/commands/named-expression-commands.mjs.map +10 -0
- package/dist/mjs/core/commands/structure-commands.mjs +465 -0
- package/dist/mjs/core/commands/structure-commands.mjs.map +10 -0
- package/dist/mjs/core/commands/style-commands.mjs +189 -0
- package/dist/mjs/core/commands/style-commands.mjs.map +10 -0
- package/dist/mjs/core/commands/table-commands.mjs +196 -0
- package/dist/mjs/core/commands/table-commands.mjs.map +10 -0
- package/dist/mjs/core/commands/types.mjs +42 -0
- package/dist/mjs/core/commands/types.mjs.map +10 -0
- package/dist/mjs/core/engine.mjs +194 -296
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/api-schema-manager.mjs +274 -0
- package/dist/mjs/core/managers/api-schema-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/copy-manager.mjs +1 -2
- package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
- package/dist/mjs/core/types.mjs.map +2 -2
- package/dist/mjs/lib.mjs +13 -2
- package/dist/mjs/lib.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/api/api-builder.d.ts +16 -0
- package/dist/types/core/api/api-helpers.d.ts +37 -0
- package/dist/types/core/api/api.d.ts +83 -0
- package/dist/types/core/api/api.type-test.d.ts +1 -0
- package/dist/types/core/api/cell-orm.d.ts +29 -0
- package/dist/types/core/api/table-orm.d.ts +46 -0
- package/dist/types/core/autofill-utils.d.ts +2 -9
- package/dist/types/core/commands/command-executor.d.ts +83 -0
- package/dist/types/core/commands/content-commands.d.ts +142 -0
- package/dist/types/core/commands/index.d.ts +16 -0
- package/dist/types/core/commands/metadata-commands.d.ts +55 -0
- package/dist/types/core/commands/named-expression-commands.d.ts +115 -0
- package/dist/types/core/commands/structure-commands.d.ts +132 -0
- package/dist/types/core/commands/style-commands.d.ts +76 -0
- package/dist/types/core/commands/table-commands.d.ts +104 -0
- package/dist/types/core/commands/types.d.ts +114 -0
- package/dist/types/core/engine.d.ts +130 -26
- package/dist/types/core/managers/api-schema-manager.d.ts +121 -0
- package/dist/types/core/types.d.ts +1 -1
- package/dist/types/lib.d.ts +8 -0
- package/package.json +1 -1
package/dist/mjs/core/engine.mjs
CHANGED
|
@@ -16,6 +16,44 @@ import { DependencyManager } from "./managers/dependency-manager.mjs";
|
|
|
16
16
|
import { StyleManager } from "./managers/style-manager.mjs";
|
|
17
17
|
import { CopyManager } from "./managers/copy-manager.mjs";
|
|
18
18
|
import { ReferenceManager } from "./managers/reference-manager.mjs";
|
|
19
|
+
import { ApiSchemaManager } from "./managers/api-schema-manager.mjs";
|
|
20
|
+
import { buildApiFromDeclaration } from "./api/api-builder.mjs";
|
|
21
|
+
import {
|
|
22
|
+
CommandExecutor,
|
|
23
|
+
SetCellContentCommand,
|
|
24
|
+
SetSheetContentCommand,
|
|
25
|
+
ClearRangeCommand,
|
|
26
|
+
PasteCellsCommand,
|
|
27
|
+
FillAreasCommand,
|
|
28
|
+
MoveCellCommand,
|
|
29
|
+
MoveRangeCommand,
|
|
30
|
+
AutoFillCommand,
|
|
31
|
+
AddWorkbookCommand,
|
|
32
|
+
RemoveWorkbookCommand,
|
|
33
|
+
RenameWorkbookCommand,
|
|
34
|
+
CloneWorkbookCommand,
|
|
35
|
+
AddSheetCommand,
|
|
36
|
+
RemoveSheetCommand,
|
|
37
|
+
RenameSheetCommand,
|
|
38
|
+
AddTableCommand,
|
|
39
|
+
RemoveTableCommand,
|
|
40
|
+
RenameTableCommand,
|
|
41
|
+
UpdateTableCommand,
|
|
42
|
+
ResetTablesCommand,
|
|
43
|
+
AddNamedExpressionCommand,
|
|
44
|
+
RemoveNamedExpressionCommand,
|
|
45
|
+
UpdateNamedExpressionCommand,
|
|
46
|
+
RenameNamedExpressionCommand,
|
|
47
|
+
SetNamedExpressionsCommand,
|
|
48
|
+
SetCellMetadataCommand,
|
|
49
|
+
SetSheetMetadataCommand,
|
|
50
|
+
SetWorkbookMetadataCommand,
|
|
51
|
+
AddConditionalStyleCommand,
|
|
52
|
+
RemoveConditionalStyleCommand,
|
|
53
|
+
AddCellStyleCommand,
|
|
54
|
+
RemoveCellStyleCommand,
|
|
55
|
+
ClearCellStylesCommand
|
|
56
|
+
} from "./commands.mjs";
|
|
19
57
|
|
|
20
58
|
class FormulaEngine {
|
|
21
59
|
workbookManager;
|
|
@@ -28,6 +66,10 @@ class FormulaEngine {
|
|
|
28
66
|
styleManager;
|
|
29
67
|
copyManager;
|
|
30
68
|
referenceManager;
|
|
69
|
+
apiSchemaManager;
|
|
70
|
+
commandExecutor;
|
|
71
|
+
api;
|
|
72
|
+
apiDeclaration;
|
|
31
73
|
_workbookManager;
|
|
32
74
|
_namedExpressionManager;
|
|
33
75
|
_tableManager;
|
|
@@ -36,7 +78,8 @@ class FormulaEngine {
|
|
|
36
78
|
_autoFillManager;
|
|
37
79
|
_dependencyManager;
|
|
38
80
|
_styleManager;
|
|
39
|
-
constructor() {
|
|
81
|
+
constructor(api) {
|
|
82
|
+
this.apiDeclaration = api?.declaration;
|
|
40
83
|
this.eventManager = new EventManager;
|
|
41
84
|
this.workbookManager = new WorkbookManager;
|
|
42
85
|
this.namedExpressionManager = new NamedExpressionManager;
|
|
@@ -47,8 +90,15 @@ class FormulaEngine {
|
|
|
47
90
|
this.evaluationManager = new EvaluationManager(this.workbookManager, this.tableManager, formulaEvaluator, this.dependencyManager);
|
|
48
91
|
this.styleManager = new StyleManager(this.evaluationManager);
|
|
49
92
|
this.copyManager = new CopyManager(this.workbookManager, this.evaluationManager, this.styleManager);
|
|
50
|
-
this.autoFillManager = new AutoFill(this.workbookManager, this.styleManager
|
|
93
|
+
this.autoFillManager = new AutoFill(this.workbookManager, this.styleManager);
|
|
51
94
|
this.referenceManager = new ReferenceManager;
|
|
95
|
+
this.apiSchemaManager = new ApiSchemaManager(this.tableManager);
|
|
96
|
+
this.commandExecutor = new CommandExecutor(this.apiDeclaration, this.evaluationManager, this.eventManager, () => this.apiSchemaManager.validateAllSchemaConstraints((cell) => this.getCellValue(cell), (cell) => this.getCellMetadata(cell), (table) => this.getTableDataCells(table)));
|
|
97
|
+
if (this.apiDeclaration) {
|
|
98
|
+
this.api = buildApiFromDeclaration(this, this.apiDeclaration, this.apiSchemaManager);
|
|
99
|
+
} else {
|
|
100
|
+
this.api = undefined;
|
|
101
|
+
}
|
|
52
102
|
this._workbookManager = this.workbookManager;
|
|
53
103
|
this._namedExpressionManager = this.namedExpressionManager;
|
|
54
104
|
this._tableManager = this.tableManager;
|
|
@@ -58,8 +108,8 @@ class FormulaEngine {
|
|
|
58
108
|
this._dependencyManager = this.dependencyManager;
|
|
59
109
|
this._styleManager = this.styleManager;
|
|
60
110
|
}
|
|
61
|
-
static buildEmpty() {
|
|
62
|
-
return new FormulaEngine;
|
|
111
|
+
static buildEmpty(api) {
|
|
112
|
+
return new FormulaEngine(api);
|
|
63
113
|
}
|
|
64
114
|
getCellEvaluationResult(cellAddress) {
|
|
65
115
|
return this.evaluationManager.getCellEvaluationResult(cellAddress);
|
|
@@ -72,25 +122,23 @@ class FormulaEngine {
|
|
|
72
122
|
return this.evaluationManager.evaluationResultToSerializedValue(result, cellAddress, debug);
|
|
73
123
|
}
|
|
74
124
|
setCellMetadata(address, metadata) {
|
|
75
|
-
this.
|
|
76
|
-
this.eventManager.emitUpdate();
|
|
125
|
+
this.commandExecutor.execute(new SetCellMetadataCommand(this.workbookManager, address, metadata));
|
|
77
126
|
}
|
|
78
127
|
getCellMetadata(address) {
|
|
79
|
-
|
|
128
|
+
const metadata = this.workbookManager.getCellMetadata(address);
|
|
129
|
+
return metadata;
|
|
80
130
|
}
|
|
81
131
|
getSheetMetadataSerialized(opts) {
|
|
82
132
|
return this.workbookManager.getSheetMetadataSerialized(opts);
|
|
83
133
|
}
|
|
84
134
|
setSheetMetadata(opts, metadata) {
|
|
85
|
-
this.
|
|
86
|
-
this.eventManager.emitUpdate();
|
|
135
|
+
this.commandExecutor.execute(new SetSheetMetadataCommand(this.workbookManager, opts, metadata));
|
|
87
136
|
}
|
|
88
137
|
getSheetMetadata(opts) {
|
|
89
138
|
return this.workbookManager.getSheetMetadata(opts);
|
|
90
139
|
}
|
|
91
140
|
setWorkbookMetadata(workbookName, metadata) {
|
|
92
|
-
this.
|
|
93
|
-
this.eventManager.emitUpdate();
|
|
141
|
+
this.commandExecutor.execute(new SetWorkbookMetadataCommand(this.workbookManager, workbookName, metadata));
|
|
94
142
|
}
|
|
95
143
|
getWorkbookMetadata(workbookName) {
|
|
96
144
|
return this.workbookManager.getWorkbookMetadata(workbookName);
|
|
@@ -116,111 +164,54 @@ class FormulaEngine {
|
|
|
116
164
|
getCellPrecedents(address) {
|
|
117
165
|
throw new Error("Not implemented");
|
|
118
166
|
}
|
|
119
|
-
addNamedExpression({
|
|
120
|
-
|
|
121
|
-
expressionName,
|
|
122
|
-
sheetName,
|
|
123
|
-
workbookName
|
|
124
|
-
}) {
|
|
125
|
-
this.namedExpressionManager.addNamedExpression({
|
|
126
|
-
expression,
|
|
127
|
-
expressionName,
|
|
128
|
-
sheetName,
|
|
129
|
-
workbookName
|
|
130
|
-
});
|
|
131
|
-
this.reevaluate();
|
|
132
|
-
this.eventManager.emitUpdate();
|
|
167
|
+
addNamedExpression(opts) {
|
|
168
|
+
this.commandExecutor.execute(new AddNamedExpressionCommand(this.getNamedExpressionCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
133
169
|
}
|
|
134
|
-
removeNamedExpression({
|
|
135
|
-
|
|
136
|
-
sheetName,
|
|
137
|
-
workbookName
|
|
138
|
-
}) {
|
|
139
|
-
const found = this.namedExpressionManager.removeNamedExpression({
|
|
140
|
-
expressionName,
|
|
141
|
-
sheetName,
|
|
142
|
-
workbookName
|
|
143
|
-
});
|
|
144
|
-
if (found) {
|
|
145
|
-
this.reevaluate();
|
|
146
|
-
this.eventManager.emitUpdate();
|
|
147
|
-
}
|
|
148
|
-
return found;
|
|
170
|
+
removeNamedExpression(opts) {
|
|
171
|
+
this.commandExecutor.execute(new RemoveNamedExpressionCommand(this.getNamedExpressionCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
149
172
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}) {
|
|
156
|
-
this.namedExpressionManager.updateNamedExpression({
|
|
157
|
-
expression,
|
|
158
|
-
expressionName,
|
|
159
|
-
sheetName,
|
|
160
|
-
workbookName
|
|
173
|
+
hasNamedExpression(opts) {
|
|
174
|
+
const scope = opts.sheetName && opts.workbookName ? { type: "sheet", workbookName: opts.workbookName, sheetName: opts.sheetName } : opts.workbookName ? { type: "workbook", workbookName: opts.workbookName } : { type: "global" };
|
|
175
|
+
return !!this.namedExpressionManager.getNamedExpression({
|
|
176
|
+
name: opts.expressionName,
|
|
177
|
+
scope
|
|
161
178
|
});
|
|
162
|
-
this.reevaluate();
|
|
163
|
-
this.eventManager.emitUpdate();
|
|
164
179
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}) {
|
|
171
|
-
const result = this.namedExpressionManager.renameNamedExpression({
|
|
172
|
-
expressionName,
|
|
173
|
-
sheetName,
|
|
174
|
-
workbookName,
|
|
175
|
-
newName
|
|
176
|
-
});
|
|
177
|
-
this.workbookManager.updateAllFormulas((formula) => renameNamedExpressionInFormula(formula, expressionName, newName));
|
|
178
|
-
this.namedExpressionManager.updateAllNamedExpressions((formula) => renameNamedExpressionInFormula(formula, expressionName, newName));
|
|
179
|
-
this.reevaluate();
|
|
180
|
-
this.eventManager.emitUpdate();
|
|
181
|
-
return result;
|
|
180
|
+
updateNamedExpression(opts) {
|
|
181
|
+
this.commandExecutor.execute(new UpdateNamedExpressionCommand(this.getNamedExpressionCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
182
|
+
}
|
|
183
|
+
renameNamedExpression(opts) {
|
|
184
|
+
this.commandExecutor.execute(new RenameNamedExpressionCommand(this.getNamedExpressionCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
182
185
|
}
|
|
183
186
|
setNamedExpressions(opts) {
|
|
184
|
-
this.
|
|
185
|
-
this.reevaluate();
|
|
186
|
-
this.eventManager.emitUpdate();
|
|
187
|
+
this.commandExecutor.execute(new SetNamedExpressionsCommand(this.getNamedExpressionCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
187
188
|
}
|
|
188
189
|
addTable(props) {
|
|
189
|
-
|
|
190
|
-
...props,
|
|
191
|
-
getCellValue: (cellAddress) => this.getCellValue(cellAddress)
|
|
192
|
-
});
|
|
193
|
-
this.reevaluate();
|
|
194
|
-
this.eventManager.emitUpdate();
|
|
195
|
-
return table;
|
|
190
|
+
this.commandExecutor.execute(new AddTableCommand(this.getTableCommandDeps(), props), { validate: !!this.apiDeclaration });
|
|
196
191
|
}
|
|
197
192
|
renameTable(workbookName, names) {
|
|
198
|
-
this.
|
|
199
|
-
this.workbookManager.updateAllFormulas((formula) => renameTableInFormula(formula, names.oldName, names.newName));
|
|
200
|
-
this.namedExpressionManager.updateAllNamedExpressions((formula) => renameTableInFormula(formula, names.oldName, names.newName));
|
|
201
|
-
this.reevaluate();
|
|
202
|
-
this.eventManager.emitUpdate();
|
|
193
|
+
this.commandExecutor.execute(new RenameTableCommand(this.getTableCommandDeps(), workbookName, names.oldName, names.newName), { validate: !!this.apiDeclaration });
|
|
203
194
|
}
|
|
204
195
|
updateTable(opts) {
|
|
205
|
-
this.
|
|
206
|
-
...opts,
|
|
207
|
-
getCellValue: (cellAddress) => this.getCellValue(cellAddress)
|
|
208
|
-
});
|
|
209
|
-
this.reevaluate();
|
|
210
|
-
this.eventManager.emitUpdate();
|
|
196
|
+
this.commandExecutor.execute(new UpdateTableCommand(this.getTableCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
211
197
|
}
|
|
212
198
|
removeTable(opts) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
199
|
+
this.commandExecutor.execute(new RemoveTableCommand(this.getTableCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
200
|
+
}
|
|
201
|
+
hasTable(opts) {
|
|
202
|
+
return !!this.tableManager.getTable({
|
|
203
|
+
workbookName: opts.workbookName,
|
|
204
|
+
name: opts.tableName
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
getTable(opts) {
|
|
208
|
+
return this.tableManager.getTable({
|
|
209
|
+
workbookName: opts.workbookName,
|
|
210
|
+
name: opts.tableName
|
|
211
|
+
});
|
|
219
212
|
}
|
|
220
213
|
resetTables(tables) {
|
|
221
|
-
this.
|
|
222
|
-
this.reevaluate();
|
|
223
|
-
this.eventManager.emitUpdate();
|
|
214
|
+
this.commandExecutor.execute(new ResetTablesCommand(this.getTableCommandDeps(), tables), { validate: !!this.apiDeclaration });
|
|
224
215
|
}
|
|
225
216
|
getTables(workbookName) {
|
|
226
217
|
return this.tableManager.getTables(workbookName);
|
|
@@ -228,16 +219,32 @@ class FormulaEngine {
|
|
|
228
219
|
isCellInTable(cellAddress) {
|
|
229
220
|
return this.tableManager.isCellInTable(cellAddress);
|
|
230
221
|
}
|
|
222
|
+
getTableDataCells(table) {
|
|
223
|
+
const { start, endRow, headers } = table;
|
|
224
|
+
const dataStartRow = start.rowIndex + 1;
|
|
225
|
+
const endColIndex = start.colIndex + headers.size - 1;
|
|
226
|
+
const rangeAddress = {
|
|
227
|
+
workbookName: table.workbookName,
|
|
228
|
+
sheetName: table.sheetName,
|
|
229
|
+
range: {
|
|
230
|
+
start: { col: start.colIndex, row: dataStartRow },
|
|
231
|
+
end: {
|
|
232
|
+
col: { type: "number", value: endColIndex },
|
|
233
|
+
row: endRow
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
return this.workbookManager.getCellsInRange(rangeAddress);
|
|
238
|
+
}
|
|
231
239
|
addConditionalStyle(style) {
|
|
232
|
-
this.
|
|
233
|
-
this.eventManager.emitUpdate();
|
|
240
|
+
this.commandExecutor.execute(new AddConditionalStyleCommand(this.styleManager, style));
|
|
234
241
|
}
|
|
235
242
|
removeConditionalStyle(workbookName, index) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return
|
|
243
|
+
this.commandExecutor.execute(new RemoveConditionalStyleCommand(this.styleManager, workbookName, index));
|
|
244
|
+
}
|
|
245
|
+
getConditionalStyleCount(workbookName) {
|
|
246
|
+
const allStyles = this.styleManager.getAllConditionalStyles();
|
|
247
|
+
return allStyles.filter((s) => s.areas.some((a) => a.workbookName === workbookName)).length;
|
|
241
248
|
}
|
|
242
249
|
getConditionalStylesIntersectingWithRange(range) {
|
|
243
250
|
return this.styleManager.getConditionalStylesIntersectingWithRange(range);
|
|
@@ -252,15 +259,14 @@ class FormulaEngine {
|
|
|
252
259
|
return this.styleManager.getAllConditionalStyles();
|
|
253
260
|
}
|
|
254
261
|
addCellStyle(style) {
|
|
255
|
-
this.
|
|
256
|
-
this.eventManager.emitUpdate();
|
|
262
|
+
this.commandExecutor.execute(new AddCellStyleCommand(this.styleManager, style));
|
|
257
263
|
}
|
|
258
264
|
removeCellStyle(workbookName, index) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return
|
|
265
|
+
this.commandExecutor.execute(new RemoveCellStyleCommand(this.styleManager, workbookName, index));
|
|
266
|
+
}
|
|
267
|
+
getCellStyleCount(workbookName) {
|
|
268
|
+
const allStyles = this.styleManager.getAllCellStyles();
|
|
269
|
+
return allStyles.filter((s) => s.areas.some((a) => a.workbookName === workbookName)).length;
|
|
264
270
|
}
|
|
265
271
|
getStylesIntersectingWithRange(range) {
|
|
266
272
|
return this.styleManager.getStylesIntersectingWithRange(range);
|
|
@@ -269,18 +275,13 @@ class FormulaEngine {
|
|
|
269
275
|
return this.styleManager.getStyleForRange(range);
|
|
270
276
|
}
|
|
271
277
|
clearCellStyles(range) {
|
|
272
|
-
this.
|
|
273
|
-
this.eventManager.emitUpdate();
|
|
278
|
+
this.commandExecutor.execute(new ClearCellStylesCommand(this.styleManager, range));
|
|
274
279
|
}
|
|
275
280
|
pasteCells(source, target, options) {
|
|
276
|
-
this.
|
|
277
|
-
this.reevaluate();
|
|
278
|
-
this.eventManager.emitUpdate();
|
|
281
|
+
this.commandExecutor.execute(new PasteCellsCommand(this.workbookManager, this.copyManager, source, target, options), { validate: !!this.apiDeclaration });
|
|
279
282
|
}
|
|
280
283
|
fillAreas(seedRange, targetRanges, options) {
|
|
281
|
-
this.
|
|
282
|
-
this.reevaluate();
|
|
283
|
-
this.eventManager.emitUpdate();
|
|
284
|
+
this.commandExecutor.execute(new FillAreasCommand(this.workbookManager, this.copyManager, seedRange, targetRanges, options), { validate: !!this.apiDeclaration });
|
|
284
285
|
}
|
|
285
286
|
smartPaste(sourceCells, pasteSelection, options) {
|
|
286
287
|
if (sourceCells.length === 0) {
|
|
@@ -361,55 +362,22 @@ class FormulaEngine {
|
|
|
361
362
|
return { minCol, minRow, maxCol, maxRow };
|
|
362
363
|
}
|
|
363
364
|
moveCell(source, target) {
|
|
364
|
-
this.
|
|
365
|
-
cut: true,
|
|
366
|
-
type: "formula",
|
|
367
|
-
include: "all"
|
|
368
|
-
});
|
|
369
|
-
this.reevaluate();
|
|
370
|
-
this.eventManager.emitUpdate();
|
|
365
|
+
this.commandExecutor.execute(new MoveCellCommand(this.workbookManager, this.copyManager, source, target), { validate: !!this.apiDeclaration });
|
|
371
366
|
}
|
|
372
367
|
moveRange(sourceRange, target) {
|
|
373
|
-
|
|
374
|
-
this.pasteCells(cells, target, {
|
|
375
|
-
cut: true,
|
|
376
|
-
type: "formula",
|
|
377
|
-
include: "all"
|
|
378
|
-
});
|
|
379
|
-
this.reevaluate();
|
|
380
|
-
this.eventManager.emitUpdate();
|
|
368
|
+
this.commandExecutor.execute(new MoveRangeCommand(this.workbookManager, this.copyManager, sourceRange, target), { validate: !!this.apiDeclaration });
|
|
381
369
|
}
|
|
382
370
|
addSheet(opts) {
|
|
383
|
-
|
|
384
|
-
const wbLevel = this.namedExpressionManager.addSheet(opts);
|
|
385
|
-
this.reevaluate();
|
|
386
|
-
this.eventManager.emitUpdate();
|
|
387
|
-
return newSheet;
|
|
371
|
+
this.commandExecutor.execute(new AddSheetCommand(this.getStructureCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
388
372
|
}
|
|
389
373
|
removeSheet(opts) {
|
|
390
|
-
|
|
391
|
-
this.namedExpressionManager.removeSheet(opts);
|
|
392
|
-
this.tableManager.removeSheet(opts);
|
|
393
|
-
this.styleManager.removeSheetStyles(opts.workbookName, opts.sheetName);
|
|
394
|
-
this.referenceManager.invalidateSheet(opts.workbookName, opts.sheetName);
|
|
395
|
-
this.reevaluate();
|
|
396
|
-
this.eventManager.emitUpdate();
|
|
397
|
-
return sheet;
|
|
374
|
+
this.commandExecutor.execute(new RemoveSheetCommand(this.getStructureCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
398
375
|
}
|
|
399
376
|
renameSheet(opts) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.
|
|
404
|
-
this.workbookManager.updateAllFormulas((formula) => renameSheetInFormula({
|
|
405
|
-
formula,
|
|
406
|
-
oldSheetName: opts.sheetName,
|
|
407
|
-
newSheetName: opts.newSheetName
|
|
408
|
-
}));
|
|
409
|
-
this.referenceManager.updateSheetName(opts.workbookName, opts.sheetName, opts.newSheetName);
|
|
410
|
-
this.reevaluate();
|
|
411
|
-
this.eventManager.emitUpdate();
|
|
412
|
-
return sheet;
|
|
377
|
+
this.commandExecutor.execute(new RenameSheetCommand(this.getStructureCommandDeps(), opts), { validate: !!this.apiDeclaration });
|
|
378
|
+
}
|
|
379
|
+
hasSheet(opts) {
|
|
380
|
+
return !!this.workbookManager.getSheet(opts);
|
|
413
381
|
}
|
|
414
382
|
getSheets(workbookName) {
|
|
415
383
|
return this.workbookManager.getSheets(workbookName);
|
|
@@ -424,154 +392,34 @@ class FormulaEngine {
|
|
|
424
392
|
return this.workbookManager.getSheetSerialized(opts);
|
|
425
393
|
}
|
|
426
394
|
addWorkbook(workbookName) {
|
|
427
|
-
this.
|
|
428
|
-
this.namedExpressionManager.addWorkbook(workbookName);
|
|
429
|
-
this.tableManager.addWorkbook(workbookName);
|
|
430
|
-
this.reevaluate();
|
|
431
|
-
this.eventManager.emitUpdate();
|
|
395
|
+
this.commandExecutor.execute(new AddWorkbookCommand(this.getStructureCommandDeps(), workbookName), { validate: !!this.apiDeclaration });
|
|
432
396
|
}
|
|
433
397
|
removeWorkbook(workbookName) {
|
|
434
|
-
this.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
this.
|
|
438
|
-
this.referenceManager.invalidateWorkbook(workbookName);
|
|
439
|
-
this.reevaluate();
|
|
440
|
-
this.eventManager.emitUpdate();
|
|
398
|
+
this.commandExecutor.execute(new RemoveWorkbookCommand(this.getStructureCommandDeps(), workbookName), { validate: !!this.apiDeclaration });
|
|
399
|
+
}
|
|
400
|
+
hasWorkbook(workbookName) {
|
|
401
|
+
return this.workbookManager.getWorkbooks().has(workbookName);
|
|
441
402
|
}
|
|
442
403
|
cloneWorkbook(fromWorkbookName, toWorkbookName) {
|
|
443
|
-
|
|
444
|
-
if (!sourceWorkbook) {
|
|
445
|
-
throw new Error(`Source workbook "${fromWorkbookName}" not found`);
|
|
446
|
-
}
|
|
447
|
-
if (this.workbookManager.getWorkbooks().has(toWorkbookName)) {
|
|
448
|
-
throw new Error(`Target workbook "${toWorkbookName}" already exists`);
|
|
449
|
-
}
|
|
450
|
-
this.addWorkbook(toWorkbookName);
|
|
451
|
-
for (const [sheetName, sheet] of sourceWorkbook.sheets) {
|
|
452
|
-
this.addSheet({
|
|
453
|
-
workbookName: toWorkbookName,
|
|
454
|
-
sheetName
|
|
455
|
-
});
|
|
456
|
-
this.setSheetContent({
|
|
457
|
-
workbookName: toWorkbookName,
|
|
458
|
-
sheetName
|
|
459
|
-
}, new Map(sheet.content));
|
|
460
|
-
const targetSheet = this.workbookManager.getSheet({
|
|
461
|
-
workbookName: toWorkbookName,
|
|
462
|
-
sheetName
|
|
463
|
-
});
|
|
464
|
-
if (targetSheet) {
|
|
465
|
-
targetSheet.metadata = new Map(sheet.metadata);
|
|
466
|
-
if (sheet.sheetMetadata !== undefined) {
|
|
467
|
-
targetSheet.sheetMetadata = structuredClone(sheet.sheetMetadata);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
const targetWorkbook = this.workbookManager.getWorkbooks().get(toWorkbookName);
|
|
472
|
-
if (targetWorkbook && sourceWorkbook.workbookMetadata !== undefined) {
|
|
473
|
-
targetWorkbook.workbookMetadata = structuredClone(sourceWorkbook.workbookMetadata);
|
|
474
|
-
}
|
|
475
|
-
const sourceWorkbookExpressions = this.namedExpressionManager.getNamedExpressions().workbookExpressions.get(fromWorkbookName);
|
|
476
|
-
if (sourceWorkbookExpressions) {
|
|
477
|
-
for (const [name, expression] of sourceWorkbookExpressions) {
|
|
478
|
-
this.addNamedExpression({
|
|
479
|
-
expressionName: name,
|
|
480
|
-
expression: expression.expression,
|
|
481
|
-
workbookName: toWorkbookName
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
const sourceSheetExpressions = this.namedExpressionManager.getNamedExpressions().sheetExpressions.get(fromWorkbookName);
|
|
486
|
-
if (sourceSheetExpressions) {
|
|
487
|
-
for (const [sheetName, sheetExpressions] of sourceSheetExpressions) {
|
|
488
|
-
for (const [name, expression] of sheetExpressions) {
|
|
489
|
-
this.addNamedExpression({
|
|
490
|
-
expressionName: name,
|
|
491
|
-
expression: expression.expression,
|
|
492
|
-
workbookName: toWorkbookName,
|
|
493
|
-
sheetName
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
const sourceTables = this.tableManager.tables.get(fromWorkbookName);
|
|
499
|
-
if (sourceTables) {
|
|
500
|
-
for (const [tableName, table] of sourceTables) {
|
|
501
|
-
this.tableManager.copyTable({
|
|
502
|
-
workbookName: fromWorkbookName,
|
|
503
|
-
tableName
|
|
504
|
-
}, {
|
|
505
|
-
workbookName: toWorkbookName,
|
|
506
|
-
tableName
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
const allConditionalStyles = this.styleManager.getAllConditionalStyles();
|
|
511
|
-
for (const style of allConditionalStyles) {
|
|
512
|
-
if (style.areas.some((area) => area.workbookName === fromWorkbookName)) {
|
|
513
|
-
const newStyle = {
|
|
514
|
-
...style,
|
|
515
|
-
areas: style.areas.map((area) => area.workbookName === fromWorkbookName ? { ...area, workbookName: toWorkbookName } : area)
|
|
516
|
-
};
|
|
517
|
-
this.styleManager.addConditionalStyle(newStyle);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
const allCellStyles = this.styleManager.getAllCellStyles();
|
|
521
|
-
for (const style of allCellStyles) {
|
|
522
|
-
if (style.areas.some((area) => area.workbookName === fromWorkbookName)) {
|
|
523
|
-
const newStyle = {
|
|
524
|
-
...style,
|
|
525
|
-
areas: style.areas.map((area) => area.workbookName === fromWorkbookName ? { ...area, workbookName: toWorkbookName } : area)
|
|
526
|
-
};
|
|
527
|
-
this.styleManager.addCellStyle(newStyle);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
this.workbookManager.updateFormulasForWorkbook(toWorkbookName, (formula) => renameWorkbookInFormula({
|
|
531
|
-
formula,
|
|
532
|
-
oldWorkbookName: fromWorkbookName,
|
|
533
|
-
newWorkbookName: toWorkbookName
|
|
534
|
-
}));
|
|
535
|
-
this.reevaluate();
|
|
536
|
-
this.eventManager.emitUpdate();
|
|
404
|
+
this.commandExecutor.execute(new CloneWorkbookCommand(this.getStructureCommandDeps(), fromWorkbookName, toWorkbookName), { validate: !!this.apiDeclaration });
|
|
537
405
|
}
|
|
538
406
|
renameWorkbook(opts) {
|
|
539
|
-
this.
|
|
540
|
-
this.namedExpressionManager.renameWorkbook(opts);
|
|
541
|
-
this.tableManager.updateTablesForWorkbookRename(opts);
|
|
542
|
-
this.styleManager.updateWorkbookName(opts.workbookName, opts.newWorkbookName);
|
|
543
|
-
this.workbookManager.updateAllFormulas((formula) => renameWorkbookInFormula({
|
|
544
|
-
formula,
|
|
545
|
-
oldWorkbookName: opts.workbookName,
|
|
546
|
-
newWorkbookName: opts.newWorkbookName
|
|
547
|
-
}));
|
|
548
|
-
this.referenceManager.updateWorkbookName(opts.workbookName, opts.newWorkbookName);
|
|
549
|
-
this.reevaluate();
|
|
550
|
-
this.eventManager.emitUpdate();
|
|
407
|
+
this.commandExecutor.execute(new RenameWorkbookCommand(this.getStructureCommandDeps(), opts.workbookName, opts.newWorkbookName), { validate: !!this.apiDeclaration });
|
|
551
408
|
}
|
|
552
409
|
getWorkbooks() {
|
|
553
410
|
return this.workbookManager.getWorkbooks();
|
|
554
411
|
}
|
|
555
412
|
setSheetContent(opts, content) {
|
|
556
|
-
this.
|
|
557
|
-
this.reevaluate();
|
|
558
|
-
this.eventManager.emitUpdate();
|
|
413
|
+
this.commandExecutor.execute(new SetSheetContentCommand(this.workbookManager, opts, content), { validate: !!this.apiDeclaration });
|
|
559
414
|
}
|
|
560
415
|
setCellContent(address, content) {
|
|
561
|
-
this.
|
|
562
|
-
this.reevaluate();
|
|
563
|
-
this.eventManager.emitUpdate();
|
|
564
|
-
}
|
|
565
|
-
reevaluate() {
|
|
566
|
-
this.evaluationManager.clearEvaluationCache();
|
|
416
|
+
this.commandExecutor.execute(new SetCellContentCommand(this.workbookManager, address, content), { validate: !!this.apiDeclaration });
|
|
567
417
|
}
|
|
568
418
|
autoFill(opts, seedRange, fillRanges, direction) {
|
|
569
|
-
this.
|
|
419
|
+
this.commandExecutor.execute(new AutoFillCommand(this.workbookManager, this.styleManager, this.autoFillManager, opts, seedRange, fillRanges, direction), { validate: !!this.apiDeclaration });
|
|
570
420
|
}
|
|
571
421
|
clearSpreadsheetRange(address) {
|
|
572
|
-
this.
|
|
573
|
-
this.reevaluate();
|
|
574
|
-
this.eventManager.emitUpdate();
|
|
422
|
+
this.commandExecutor.execute(new ClearRangeCommand(this.workbookManager, address), { validate: !!this.apiDeclaration });
|
|
575
423
|
}
|
|
576
424
|
getState() {
|
|
577
425
|
return {
|
|
@@ -622,12 +470,62 @@ class FormulaEngine {
|
|
|
622
470
|
if (deserialized.references) {
|
|
623
471
|
this.referenceManager.resetReferences(deserialized.references);
|
|
624
472
|
}
|
|
625
|
-
this.
|
|
473
|
+
this.evaluationManager.clearEvaluationCache();
|
|
626
474
|
this.eventManager.emitUpdate();
|
|
627
475
|
}
|
|
476
|
+
undo() {
|
|
477
|
+
return this.commandExecutor.undo();
|
|
478
|
+
}
|
|
479
|
+
redo() {
|
|
480
|
+
return this.commandExecutor.redo();
|
|
481
|
+
}
|
|
482
|
+
canUndo() {
|
|
483
|
+
return this.commandExecutor.canUndo();
|
|
484
|
+
}
|
|
485
|
+
canRedo() {
|
|
486
|
+
return this.commandExecutor.canRedo();
|
|
487
|
+
}
|
|
488
|
+
getActionLog() {
|
|
489
|
+
return this.commandExecutor.getActionLog();
|
|
490
|
+
}
|
|
491
|
+
clearActionLog() {
|
|
492
|
+
this.commandExecutor.clearActionLog();
|
|
493
|
+
}
|
|
494
|
+
clearHistory() {
|
|
495
|
+
this.commandExecutor.clearHistory();
|
|
496
|
+
}
|
|
497
|
+
getStructureCommandDeps() {
|
|
498
|
+
return {
|
|
499
|
+
workbookManager: this.workbookManager,
|
|
500
|
+
namedExpressionManager: this.namedExpressionManager,
|
|
501
|
+
tableManager: this.tableManager,
|
|
502
|
+
styleManager: this.styleManager,
|
|
503
|
+
referenceManager: this.referenceManager,
|
|
504
|
+
apiSchemaManager: this.apiSchemaManager,
|
|
505
|
+
renameSheetInFormula,
|
|
506
|
+
renameWorkbookInFormula
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
getTableCommandDeps() {
|
|
510
|
+
return {
|
|
511
|
+
tableManager: this.tableManager,
|
|
512
|
+
namedExpressionManager: this.namedExpressionManager,
|
|
513
|
+
workbookManager: this.workbookManager,
|
|
514
|
+
apiSchemaManager: this.apiSchemaManager,
|
|
515
|
+
getCellValue: (cell) => this.getCellValue(cell),
|
|
516
|
+
renameTableInFormula
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
getNamedExpressionCommandDeps() {
|
|
520
|
+
return {
|
|
521
|
+
namedExpressionManager: this.namedExpressionManager,
|
|
522
|
+
workbookManager: this.workbookManager,
|
|
523
|
+
renameNamedExpressionInFormula
|
|
524
|
+
};
|
|
525
|
+
}
|
|
628
526
|
}
|
|
629
527
|
export {
|
|
630
528
|
FormulaEngine
|
|
631
529
|
};
|
|
632
530
|
|
|
633
|
-
//# debugId=
|
|
531
|
+
//# debugId=ACD6AB3C2CAB92F864756E2164756E21
|