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