@univerjs/engine-formula 0.12.4-experimental.20251208-c4b8a44 → 0.12.4

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/lib/es/facade.js CHANGED
@@ -1,15 +1,15 @@
1
- import { FBase as p, FUniver as d } from "@univerjs/core/facade";
2
- import { Inject as c, ICommandService as C, Injector as f, IConfigService as S } from "@univerjs/core";
3
- import { LexerTreeBuilder as _, SetFormulaCalculationStartMutation as u, SetFormulaCalculationStopMutation as v, SetFormulaCalculationNotificationMutation as m, GlobalComputingStatusService as h, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as x, SetFormulaStringBatchCalculationMutation as g, SetFormulaStringBatchCalculationResultMutation as F, SetFormulaDependencyCalculationMutation as E, SetFormulaDependencyCalculationResultMutation as y, SetCellFormulaDependencyCalculationMutation as M, SetCellFormulaDependencyCalculationResultMutation as B } from "@univerjs/engine-formula";
4
- import { firstValueFrom as T, race as I, filter as D, timer as R, map as L } from "rxjs";
5
- var N = Object.getOwnPropertyDescriptor, O = (e, t, i, r) => {
6
- for (var n = r > 1 ? void 0 : r ? N(t, i) : t, a = e.length - 1, l; a >= 0; a--)
7
- (l = e[a]) && (n = l(n) || n);
8
- return n;
9
- }, o = (e, t) => (i, r) => t(i, r, e);
10
- let s = class extends p {
11
- constructor(e, t, i, r) {
12
- super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = i, this._configService = r, this._initialize();
1
+ import { FBase as f, FUniver as d } from "@univerjs/core/facade";
2
+ import { Inject as c, ICommandService as p, Injector as _, IConfigService as C } from "@univerjs/core";
3
+ import { LexerTreeBuilder as v, SetFormulaCalculationStartMutation as l, SetFormulaCalculationStopMutation as S, SetFormulaCalculationNotificationMutation as m, GlobalComputingStatusService as x, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as h } from "@univerjs/engine-formula";
4
+ import { firstValueFrom as g, race as E, filter as F, timer as B, map as I } from "rxjs";
5
+ var T = Object.getOwnPropertyDescriptor, N = (e, t, r, i) => {
6
+ for (var o = i > 1 ? void 0 : i ? T(t, r) : t, a = e.length - 1, u; a >= 0; a--)
7
+ (u = e[a]) && (o = u(o) || o);
8
+ return o;
9
+ }, n = (e, t) => (r, i) => t(r, i, e);
10
+ let s = class extends f {
11
+ constructor(e, t, r, i) {
12
+ super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = r, this._configService = i, this._initialize();
13
13
  }
14
14
  /**
15
15
  * @ignore
@@ -38,8 +38,8 @@ let s = class extends p {
38
38
  * console.log(result);
39
39
  * ```
40
40
  */
41
- moveFormulaRefOffset(e, t, i, r) {
42
- return this._lexerTreeBuilder.moveFormulaRefOffset(e, t, i, r);
41
+ moveFormulaRefOffset(e, t, r, i) {
42
+ return this._lexerTreeBuilder.moveFormulaRefOffset(e, t, r, i);
43
43
  }
44
44
  /**
45
45
  * Resolves the formula string to a 'node' node
@@ -66,7 +66,7 @@ let s = class extends p {
66
66
  * ```
67
67
  */
68
68
  executeCalculation() {
69
- this._commandService.executeCommand(u.id, { commands: [], forceCalculation: !0 }, { onlyLocal: !0 });
69
+ this._commandService.executeCommand(l.id, { commands: [], forceCalculation: !0 }, { onlyLocal: !0 });
70
70
  }
71
71
  /**
72
72
  * Stop the calculation of the formula.
@@ -78,7 +78,7 @@ let s = class extends p {
78
78
  * ```
79
79
  */
80
80
  stopCalculation() {
81
- this._commandService.executeCommand(v.id, {});
81
+ this._commandService.executeCommand(S.id, {});
82
82
  }
83
83
  /**
84
84
  * Listening calculation starts.
@@ -95,9 +95,9 @@ let s = class extends p {
95
95
  */
96
96
  calculationStart(e) {
97
97
  return this._commandService.onCommandExecuted((t) => {
98
- if (t.id === u.id) {
99
- const i = t.params;
100
- e(i.forceCalculation);
98
+ if (t.id === l.id) {
99
+ const r = t.params;
100
+ e(r.forceCalculation);
101
101
  }
102
102
  });
103
103
  }
@@ -118,8 +118,8 @@ let s = class extends p {
118
118
  return this._commandService.onCommandExecuted((t) => {
119
119
  if (t.id !== m.id)
120
120
  return;
121
- const i = t.params;
122
- i.functionsExecutedState !== void 0 && e(i.functionsExecutedState);
121
+ const r = t.params;
122
+ r.functionsExecutedState !== void 0 && e(r.functionsExecutedState);
123
123
  });
124
124
  }
125
125
  /**
@@ -139,10 +139,10 @@ let s = class extends p {
139
139
  * ```
140
140
  */
141
141
  whenComputingCompleteAsync(e) {
142
- const t = this._injector.get(h);
143
- return t.computingStatus ? Promise.resolve(!0) : T(I(
144
- t.computingStatus$.pipe(D((i) => i)),
145
- R(e != null ? e : 3e4).pipe(L(() => !1))
142
+ const t = this._injector.get(x);
143
+ return t.computingStatus ? Promise.resolve(!0) : g(E(
144
+ t.computingStatus$.pipe(F((r) => r)),
145
+ B(e != null ? e : 3e4).pipe(I(() => !1))
146
146
  ));
147
147
  }
148
148
  /**
@@ -151,10 +151,10 @@ let s = class extends p {
151
151
  */
152
152
  onCalculationEnd() {
153
153
  return new Promise((e, t) => {
154
- const i = setTimeout(() => {
154
+ const r = setTimeout(() => {
155
155
  t(new Error("Calculation end timeout"));
156
- }, 3e4), r = this.calculationEnd(() => {
157
- clearTimeout(i), r.dispose(), e();
156
+ }, 3e4), i = this.calculationEnd(() => {
157
+ clearTimeout(r), i.dispose(), e();
158
158
  });
159
159
  });
160
160
  }
@@ -175,8 +175,8 @@ let s = class extends p {
175
175
  return this._commandService.onCommandExecuted((t) => {
176
176
  if (t.id !== m.id)
177
177
  return;
178
- const i = t.params;
179
- i.stageInfo !== void 0 && e(i.stageInfo);
178
+ const r = t.params;
179
+ r.stageInfo !== void 0 && e(r.stageInfo);
180
180
  });
181
181
  }
182
182
  /**
@@ -192,167 +192,21 @@ let s = class extends p {
192
192
  * ```
193
193
  */
194
194
  setMaxIteration(e) {
195
- this._configService.setConfig(x, e);
196
- }
197
- /**
198
- * Execute a batch of formulas asynchronously and receive computed results.
199
- *
200
- * Each formula cell is represented as a string array:
201
- * [fullFormula, ...subFormulas]
202
- *
203
- * Where:
204
- * - fullFormula (index 0) is the complete formula expression written in the cell.
205
- * Example: "=SUM(A1:A10) + SQRT(D7)".
206
- *
207
- * - subFormulas (index 1+) are **optional decomposed expressions** extracted from
208
- * the full formula. Each of them can be independently computed by the formula engine.
209
- *
210
- * These sub-expressions can include:
211
- * - Single-cell references: "A2", "B2", "C5"
212
- * - Range references: "A1:A10"
213
- * - Function calls: "SQRT(D7)", "ABS(A2-B2)"
214
- * - Any sub-formula that was parsed out of the original formula and can be
215
- * evaluated on its own.
216
- *
217
- * The batch execution engine may use these sub-formulas for dependency resolution,
218
- * incremental computation, or performance optimizations.
219
- *
220
- * @param {IFormulaStringMap} formulas
221
- * Nested structure (unit → sheet → row → column) describing formulas and
222
- * their decomposed sub-expressions.
223
- *
224
- * @param {(result: IFormulaExecuteResultMap) => void} callback
225
- * Receives the computed value map mirroring the input structure.
226
- *
227
- * @returns {IDisposable}
228
- * A disposer to stop listening for batch results.
229
- *
230
- * @example
231
- * ```ts
232
- * const formulaEngine = univerAPI.getFormula();
233
- * const formulas = {
234
- * Book1: {
235
- * Sheet1: {
236
- * 2: {
237
- * 3: [
238
- * // Full formula:
239
- * "=SUM(A1:A10) + SQRT(D7)",
240
- *
241
- * // Decomposed sub-formulas (each one can be evaluated independently):
242
- * "SUM(A1:A10)", // sub-formula 1
243
- * "SQRT(D7)", // sub-formula 2
244
- * "A1:A10", // range reference
245
- * "D7", // single-cell reference
246
- * ],
247
- * },
248
- * 4: {
249
- * 5: [
250
- * "=A2 + B2 + SQRT(C5)",
251
- * "A2",
252
- * "B2",
253
- * "SQRT(C5)",
254
- * ],
255
- * }
256
- * },
257
- * },
258
- * };
259
- *
260
- * const disposer = formulaEngine.executeFormulas(formulas, (result) => {
261
- * console.log(result);
262
- * });
263
- *
264
- * ```
265
- */
266
- executeFormulas(e, t) {
267
- this._commandService.executeCommand(g.id, { formulas: e }, { onlyLocal: !0 });
268
- const i = this._commandService.onCommandExecuted((r) => {
269
- if (r.id !== F.id)
270
- return;
271
- const n = r.params;
272
- n.result != null && t(n.result), i.dispose();
273
- });
274
- }
275
- /**
276
- * Retrieve all formula dependency trees that were produced during the latest
277
- * dependency-analysis run. This triggers a local dependency-calculation command
278
- * and returns the complete set of dependency trees once the calculation finishes.
279
- *
280
- * @param callback A function invoked with the resulting array of dependency trees.
281
- *
282
- * @returns {IDisposable} An object that disposes the internal event listener.
283
- *
284
- * @example
285
- * ```ts
286
- * const formulaEngine = univerAPI.getFormula();
287
- *
288
- * // Fetch all dependency trees generated for the current workbook.
289
- * const disposable = formulaEngine.getAllDependencyTrees((trees) => {
290
- * console.log('All dependency trees:', trees);
291
- * });
292
- *
293
- * ```
294
- */
295
- getAllDependencyTrees(e) {
296
- this._commandService.executeCommand(E.id, void 0, { onlyLocal: !0 });
297
- const t = this._commandService.onCommandExecuted((i) => {
298
- if (i.id !== y.id)
299
- return;
300
- const r = i.params;
301
- r.result != null && e(r.result), t.dispose();
302
- });
303
- }
304
- /**
305
- * Retrieve the dependency tree of a specific cell. This triggers a local
306
- * dependency-calculation command for the given unit, sheet, and cell location,
307
- * and returns the computed dependency tree when the calculation is completed.
308
- *
309
- * @param param The target cell location:
310
- * - `unitId` The workbook ID.
311
- * - `sheetId` The sheet ID.
312
- * - `row` The zero-based row index.
313
- * - `column` The zero-based column index.
314
- *
315
- * @param callback A function invoked with the resulting dependency tree or
316
- * `undefined` if no dependency tree exists for that cell.
317
- *
318
- * @returns {IDisposable} An object that disposes the internal event listener.
319
- *
320
- * @example
321
- * ```ts
322
- * const formulaEngine = univerAPI.getFormula();
323
- *
324
- * // Query the dependency tree for cell B2 in a specific sheet.
325
- * const disposable = formulaEngine.getCellDependencyTree(
326
- * { unitId: 'workbook1', sheetId: 'sheet1', row: 1, column: 1 },
327
- * (tree) => {
328
- * console.log('Cell dependency tree:', tree);
329
- * }
330
- * );
331
- *
332
- * ```
333
- */
334
- getCellDependencyTree(e, t) {
335
- this._commandService.executeCommand(M.id, e, { onlyLocal: !0 });
336
- const i = this._commandService.onCommandExecuted((r) => {
337
- if (r.id !== B.id)
338
- return;
339
- const n = r.params;
340
- n.result !== void 0 && t(n.result), i.dispose();
341
- });
195
+ this._configService.setConfig(h, e);
342
196
  }
343
197
  };
344
- s = O([
345
- o(0, c(C)),
346
- o(1, c(f)),
347
- o(2, c(_)),
348
- o(3, S)
198
+ s = N([
199
+ n(0, c(p)),
200
+ n(1, c(_)),
201
+ n(2, c(v)),
202
+ n(3, C)
349
203
  ], s);
350
- class b extends d {
204
+ class O extends d {
351
205
  getFormula() {
352
206
  return this._injector.createInstance(s);
353
207
  }
354
208
  }
355
- d.extend(b);
209
+ d.extend(O);
356
210
  export {
357
211
  s as FFormula
358
212
  };