@univerjs/engine-formula 0.15.2 → 0.15.3-insiders.20260131-b9b8805

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/facade.js CHANGED
@@ -1,15 +1,15 @@
1
- import { FBase as C, FUniver as f } from "@univerjs/core/facade";
2
- import { Inject as c, ICommandService as _, Injector as h, IConfigService as v } from "@univerjs/core";
3
- import { LexerTreeBuilder as g, IFunctionService as E, IDefinedNamesService as T, ISuperTableService as x, SetTriggerFormulaCalculationStartMutation as F, SetFormulaCalculationStopMutation as y, SetFormulaCalculationStartMutation as R, SetFormulaCalculationNotificationMutation as d, GlobalComputingStatusService as b, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as w, SetFormulaCalculationResultMutation as D, SetFormulaStringBatchCalculationResultMutation as M, SetFormulaStringBatchCalculationMutation as I, SetFormulaDependencyCalculationResultMutation as N, SetFormulaDependencyCalculationMutation as P, SetCellFormulaDependencyCalculationResultMutation as B, SetCellFormulaDependencyCalculationMutation as L, SetQueryFormulaDependencyResultMutation as p, SetQueryFormulaDependencyMutation as S, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE as A, SetQueryFormulaDependencyAllResultMutation as O, SetQueryFormulaDependencyAllMutation as U } from "@univerjs/engine-formula";
4
- import { firstValueFrom as j, race as Q, filter as q, timer as G, map as z } from "rxjs";
5
- var V = Object.getOwnPropertyDescriptor, Y = (e, t, i, r) => {
6
- for (var n = r > 1 ? void 0 : r ? V(t, i) : t, a = e.length - 1, o; a >= 0; a--)
1
+ import { FBase as _, FUniver as S } from "@univerjs/core/facade";
2
+ import { Inject as c, ICommandService as f, Injector as C, IConfigService as h } from "@univerjs/core";
3
+ import { LexerTreeBuilder as v, SetTriggerFormulaCalculationStartMutation as g, SetFormulaCalculationStopMutation as E, SetFormulaCalculationStartMutation as x, SetFormulaCalculationNotificationMutation as m, GlobalComputingStatusService as F, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as T, SetFormulaStringBatchCalculationResultMutation as y, SetFormulaStringBatchCalculationMutation as R, SetFormulaDependencyCalculationResultMutation as b, SetFormulaDependencyCalculationMutation as w, SetCellFormulaDependencyCalculationResultMutation as D, SetCellFormulaDependencyCalculationMutation as M, SetQueryFormulaDependencyResultMutation as d, SetQueryFormulaDependencyMutation as p, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE as I, SetQueryFormulaDependencyAllResultMutation as N, SetQueryFormulaDependencyAllMutation as B, IFunctionService as P, IDefinedNamesService as L, ISuperTableService as O } from "@univerjs/engine-formula";
4
+ import { firstValueFrom as A, race as U, filter as j, timer as Q, map as G } from "rxjs";
5
+ var q = Object.getOwnPropertyDescriptor, z = (e, t, r, i) => {
6
+ for (var n = i > 1 ? void 0 : i ? q(t, r) : t, a = e.length - 1, o; a >= 0; a--)
7
7
  (o = e[a]) && (n = o(n) || n);
8
8
  return n;
9
- }, u = (e, t) => (i, r) => t(i, r, e);
10
- let m = class extends C {
11
- constructor(e, t, i, r, n, a, o) {
12
- super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = i, this._configService = r, this._functionService = n, this._definedNamesService = a, this._superTableService = o, this._initialize();
9
+ }, u = (e, t) => (r, i) => t(r, i, e);
10
+ let l = class extends _ {
11
+ constructor(e, t, r, i, n, a, o) {
12
+ super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = r, this._configService = i, this._functionService = n, this._definedNamesService = a, this._superTableService = o, this._initialize();
13
13
  }
14
14
  /**
15
15
  * @ignore
@@ -38,8 +38,8 @@ let m = class extends C {
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 m = class extends C {
66
66
  * ```
67
67
  */
68
68
  executeCalculation() {
69
- this._commandService.executeCommand(F.id, { commands: [], forceCalculation: !0 }, { onlyLocal: !0 });
69
+ this._commandService.executeCommand(g.id, { commands: [], forceCalculation: !0 }, { onlyLocal: !0 });
70
70
  }
71
71
  /**
72
72
  * Stop the calculation of the formula.
@@ -78,7 +78,7 @@ let m = class extends C {
78
78
  * ```
79
79
  */
80
80
  stopCalculation() {
81
- this._commandService.executeCommand(y.id, {});
81
+ this._commandService.executeCommand(E.id, {});
82
82
  }
83
83
  /**
84
84
  * Listening calculation starts.
@@ -95,9 +95,9 @@ let m = class extends C {
95
95
  */
96
96
  calculationStart(e) {
97
97
  return this._commandService.onCommandExecuted((t) => {
98
- if (t.id === R.id) {
99
- const i = t.params;
100
- e(i.forceCalculation);
98
+ if (t.id === x.id) {
99
+ const r = t.params;
100
+ e(r.forceCalculation);
101
101
  }
102
102
  });
103
103
  }
@@ -116,20 +116,20 @@ let m = class extends C {
116
116
  */
117
117
  calculationEnd(e) {
118
118
  return this._commandService.onCommandExecuted((t) => {
119
- if (t.id !== d.id)
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
  /**
126
126
  * @deprecated Use `onCalculationEnd` instead.
127
127
  */
128
128
  whenComputingCompleteAsync(e) {
129
- const t = this._injector.get(b);
130
- return t.computingStatus ? Promise.resolve(!0) : j(Q(
131
- t.computingStatus$.pipe(q((i) => i)),
132
- G(e != null ? e : 3e4).pipe(z(() => !1))
129
+ const t = this._injector.get(F);
130
+ return t.computingStatus ? Promise.resolve(!0) : A(U(
131
+ t.computingStatus$.pipe(j((r) => r)),
132
+ Q(e != null ? e : 3e4).pipe(G(() => !1))
133
133
  ));
134
134
  }
135
135
  /**
@@ -138,10 +138,10 @@ let m = class extends C {
138
138
  */
139
139
  onCalculationEnd() {
140
140
  return new Promise((e, t) => {
141
- const i = setTimeout(() => {
141
+ const r = setTimeout(() => {
142
142
  t(new Error("Calculation end timeout"));
143
- }, 3e4), r = this.calculationEnd(() => {
144
- clearTimeout(i), r.dispose(), e();
143
+ }, 3e4), i = this.calculationEnd(() => {
144
+ clearTimeout(r), i.dispose(), e();
145
145
  });
146
146
  });
147
147
  }
@@ -160,10 +160,10 @@ let m = class extends C {
160
160
  */
161
161
  calculationProcessing(e) {
162
162
  return this._commandService.onCommandExecuted((t) => {
163
- if (t.id !== d.id)
163
+ if (t.id !== m.id)
164
164
  return;
165
- const i = t.params;
166
- i.stageInfo !== void 0 && e(i.stageInfo);
165
+ const r = t.params;
166
+ r.stageInfo !== void 0 && e(r.stageInfo);
167
167
  });
168
168
  }
169
169
  /**
@@ -179,85 +179,7 @@ let m = class extends C {
179
179
  * ```
180
180
  */
181
181
  setMaxIteration(e) {
182
- this._configService.setConfig(w, e);
183
- }
184
- /**
185
- * Listens for the moment when formula-calculation results are applied.
186
- *
187
- * This event fires after the engine completes a calculation cycle and
188
- * dispatches a `SetFormulaCalculationResultMutation`.
189
- * The callback is invoked during an idle frame to avoid blocking UI updates.
190
- *
191
- * @param {Function} callback - A function called with the calculation result payload
192
- * once the result-application mutation is emitted.
193
- * @returns {IDisposable} A disposable used to unsubscribe from the event.
194
- *
195
- * @example
196
- * ```ts
197
- * const formulaEngine = univerAPI.getFormula();
198
- *
199
- * const dispose = formulaEngine.calculationResultApplied((result) => {
200
- * console.log('Calculation results applied:', result);
201
- * });
202
- *
203
- * // Later…
204
- * dispose.dispose();
205
- * ```
206
- */
207
- calculationResultApplied(e) {
208
- return this._commandService.onCommandExecuted((t) => {
209
- if (t.id !== D.id)
210
- return;
211
- const i = t.params;
212
- i !== void 0 && requestIdleCallback(() => {
213
- e(i);
214
- });
215
- });
216
- }
217
- /**
218
- * Waits for formula-calculation results to be applied.
219
- *
220
- * This method resolves under three conditions:
221
- * 1. A real calculation runs and the engine emits a "calculation started" signal,
222
- * followed by a "calculation result applied" signal.
223
- * 2. No calculation actually starts within 500 ms — the method assumes there is
224
- * nothing to wait for and resolves automatically.
225
- * 3. A global 30 s timeout triggers, in which case the promise rejects.
226
- *
227
- * The API internally listens to both “calculation in progress” events and
228
- * “calculation result applied” events, ensuring it behaves correctly whether
229
- * formulas are recalculated or skipped due to cache/state.
230
- *
231
- * @returns {Promise<void>} A promise that resolves when calculation results are applied
232
- * or when no calculation occurs within the start-detection window.
233
- *
234
- * @example
235
- * ```ts
236
- * const formulaEngine = univerAPI.getFormula();
237
- *
238
- * // Wait for formula updates to apply before reading values.
239
- * await formulaEngine.onCalculationResultApplied();
240
- *
241
- * const value = sheet.getRange("C24").getValue();
242
- * console.log("Updated value:", value);
243
- * ```
244
- */
245
- onCalculationResultApplied() {
246
- return new Promise((e, t) => {
247
- let i = !1, r = !1;
248
- const n = setTimeout(() => {
249
- l(), t(new Error("Calculation end timeout"));
250
- }, 3e4), a = setTimeout(() => {
251
- i || (l(), e());
252
- }, 500), o = this.calculationProcessing(() => {
253
- i || (i = !0, clearTimeout(a));
254
- }), s = this.calculationResultApplied(() => {
255
- r || (r = !0, l(), e());
256
- });
257
- function l() {
258
- clearTimeout(n), clearTimeout(a), o.dispose(), s.dispose();
259
- }
260
- });
182
+ this._configService.setConfig(T, e);
261
183
  }
262
184
  /**
263
185
  * Execute a batch of formulas asynchronously and receive computed results.
@@ -329,17 +251,17 @@ let m = class extends C {
329
251
  * ```
330
252
  */
331
253
  executeFormulas(e, t = 3e4) {
332
- return new Promise((i, r) => {
254
+ return new Promise((r, i) => {
333
255
  const n = this._commandService.onCommandExecuted((o) => {
334
- if (o.id !== M.id)
256
+ if (o.id !== y.id)
335
257
  return;
336
258
  const s = o.params;
337
- clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : r(new Error("Formula batch calculation returned no result"));
259
+ clearTimeout(a), n.dispose(), s.result != null ? r(s.result) : i(new Error("Formula batch calculation returned no result"));
338
260
  }), a = setTimeout(() => {
339
- n.dispose(), r(new Error("Formula batch calculation timeout"));
261
+ n.dispose(), i(new Error("Formula batch calculation timeout"));
340
262
  }, t);
341
263
  this._commandService.executeCommand(
342
- I.id,
264
+ R.id,
343
265
  { formulas: e },
344
266
  { onlyLocal: !0 }
345
267
  );
@@ -367,17 +289,17 @@ let m = class extends C {
367
289
  * ```
368
290
  */
369
291
  getAllDependencyTrees(e = 3e4) {
370
- return new Promise((t, i) => {
371
- const r = this._commandService.onCommandExecuted((a) => {
372
- if (a.id !== N.id)
292
+ return new Promise((t, r) => {
293
+ const i = this._commandService.onCommandExecuted((a) => {
294
+ if (a.id !== b.id)
373
295
  return;
374
296
  const o = a.params;
375
- clearTimeout(n), r.dispose(), o.result != null ? t(o.result) : t([]);
297
+ clearTimeout(n), i.dispose(), o.result != null ? t(o.result) : t([]);
376
298
  }), n = setTimeout(() => {
377
- r.dispose(), i(new Error("Formula dependency calculation timeout"));
299
+ i.dispose(), r(new Error("Formula dependency calculation timeout"));
378
300
  }, e);
379
301
  this._commandService.executeCommand(
380
- P.id,
302
+ w.id,
381
303
  void 0,
382
304
  { onlyLocal: !0 }
383
305
  );
@@ -418,17 +340,17 @@ let m = class extends C {
418
340
  * ```
419
341
  */
420
342
  getCellDependencyTree(e, t = 3e4) {
421
- return new Promise((i, r) => {
343
+ return new Promise((r, i) => {
422
344
  const n = this._commandService.onCommandExecuted((o) => {
423
- if (o.id !== B.id)
345
+ if (o.id !== D.id)
424
346
  return;
425
347
  const s = o.params;
426
- clearTimeout(a), n.dispose(), i(s.result);
348
+ clearTimeout(a), n.dispose(), r(s.result);
427
349
  }), a = setTimeout(() => {
428
- n.dispose(), r(new Error("Cell dependency calculation timeout"));
350
+ n.dispose(), i(new Error("Cell dependency calculation timeout"));
429
351
  }, t);
430
352
  this._commandService.executeCommand(
431
- L.id,
353
+ M.id,
432
354
  e,
433
355
  { onlyLocal: !0 }
434
356
  );
@@ -466,17 +388,17 @@ let m = class extends C {
466
388
  * ```
467
389
  */
468
390
  getRangeDependents(e, t = 3e4) {
469
- return new Promise((i, r) => {
391
+ return new Promise((r, i) => {
470
392
  const n = this._commandService.onCommandExecuted((o) => {
471
- if (o.id !== p.id)
393
+ if (o.id !== d.id)
472
394
  return;
473
395
  const s = o.params;
474
- clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i([]);
396
+ clearTimeout(a), n.dispose(), s.result != null ? r(s.result) : r([]);
475
397
  }), a = setTimeout(() => {
476
- n.dispose(), r(new Error("Range dependents calculation timeout"));
398
+ n.dispose(), i(new Error("Range dependents calculation timeout"));
477
399
  }, t);
478
400
  this._commandService.executeCommand(
479
- S.id,
401
+ p.id,
480
402
  { unitRanges: e },
481
403
  { onlyLocal: !0 }
482
404
  );
@@ -518,17 +440,17 @@ let m = class extends C {
518
440
  * ```
519
441
  */
520
442
  getInRangeFormulas(e, t = 3e4) {
521
- return new Promise((i, r) => {
443
+ return new Promise((r, i) => {
522
444
  const n = this._commandService.onCommandExecuted((o) => {
523
- if (o.id !== p.id)
445
+ if (o.id !== d.id)
524
446
  return;
525
447
  const s = o.params;
526
- clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i([]);
448
+ clearTimeout(a), n.dispose(), s.result != null ? r(s.result) : r([]);
527
449
  }), a = setTimeout(() => {
528
- n.dispose(), r(new Error("In-range formulas calculation timeout"));
450
+ n.dispose(), i(new Error("In-range formulas calculation timeout"));
529
451
  }, t);
530
452
  this._commandService.executeCommand(
531
- S.id,
453
+ p.id,
532
454
  { unitRanges: e, isInRange: !0 },
533
455
  { onlyLocal: !0 }
534
456
  );
@@ -583,7 +505,7 @@ let m = class extends C {
583
505
  * ```
584
506
  */
585
507
  setFormulaReturnDependencyTree(e) {
586
- this._configService.setConfig(A, e);
508
+ this._configService.setConfig(I, e);
587
509
  }
588
510
  /**
589
511
  * Parse a formula string and return its **formula expression tree**.
@@ -697,38 +619,38 @@ let m = class extends C {
697
619
  * ```
698
620
  */
699
621
  getRangeDependentsAndInRangeFormulas(e, t = 3e4) {
700
- return new Promise((i, r) => {
622
+ return new Promise((r, i) => {
701
623
  const n = this._commandService.onCommandExecuted((o) => {
702
- if (o.id !== O.id)
624
+ if (o.id !== N.id)
703
625
  return;
704
626
  const s = o.params;
705
- clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i({ dependents: [], inRanges: [] });
627
+ clearTimeout(a), n.dispose(), s.result != null ? r(s.result) : r({ dependents: [], inRanges: [] });
706
628
  }), a = setTimeout(() => {
707
- n.dispose(), r(new Error("Range dependents calculation timeout"));
629
+ n.dispose(), i(new Error("Range dependents calculation timeout"));
708
630
  }, t);
709
631
  this._commandService.executeCommand(
710
- U.id,
632
+ B.id,
711
633
  { unitRanges: e },
712
634
  { onlyLocal: !0 }
713
635
  );
714
636
  });
715
637
  }
716
638
  };
717
- m = Y([
718
- u(0, c(_)),
719
- u(1, c(h)),
720
- u(2, c(g)),
721
- u(3, v),
722
- u(4, E),
723
- u(5, T),
724
- u(6, x)
725
- ], m);
726
- class W extends f {
639
+ l = z([
640
+ u(0, c(f)),
641
+ u(1, c(C)),
642
+ u(2, c(v)),
643
+ u(3, h),
644
+ u(4, P),
645
+ u(5, L),
646
+ u(6, O)
647
+ ], l);
648
+ class V extends S {
727
649
  getFormula() {
728
- return this._injector.createInstance(m);
650
+ return this._injector.createInstance(l);
729
651
  }
730
652
  }
731
- f.extend(W);
653
+ S.extend(V);
732
654
  export {
733
- m as FFormula
655
+ l as FFormula
734
656
  };