@univerjs/engine-formula 0.13.0-insiders.20251218-2062647 → 0.13.0-insiders.20251223-857805c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/facade.js +36 -218
  4. package/lib/es/index.js +3151 -3382
  5. package/lib/facade.js +36 -218
  6. package/lib/index.js +3151 -3382
  7. package/lib/types/basics/common.d.ts +0 -8
  8. package/lib/types/basics/match-token.d.ts +1 -1
  9. package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +1 -10
  10. package/lib/types/controller/calculate.controller.d.ts +0 -1
  11. package/lib/types/controller/config.schema.d.ts +0 -1
  12. package/lib/types/engine/analysis/lexer-tree-builder.d.ts +1 -2
  13. package/lib/types/engine/ast-node/reference-node.d.ts +1 -0
  14. package/lib/types/engine/dependency/dependency-tree.d.ts +1 -11
  15. package/lib/types/engine/dependency/formula-dependency.d.ts +3 -8
  16. package/lib/types/engine/utils/reference.d.ts +0 -9
  17. package/lib/types/engine/utils/sequence.d.ts +1 -2
  18. package/lib/types/facade/f-formula.d.ts +2 -164
  19. package/lib/types/index.d.ts +5 -9
  20. package/lib/types/services/active-dirty-manager.service.d.ts +0 -1
  21. package/lib/types/services/calculate-formula.service.d.ts +1 -4
  22. package/lib/types/services/current-data.service.d.ts +0 -1
  23. package/lib/types/services/defined-names.service.d.ts +0 -1
  24. package/lib/types/services/runtime.service.d.ts +0 -7
  25. package/lib/types/services/super-table.service.d.ts +0 -4
  26. package/lib/umd/facade.js +1 -1
  27. package/lib/umd/index.js +1 -1
  28. package/package.json +3 -3
  29. package/lib/types/commands/mutations/formula.mutation.d.ts +0 -9
  30. package/lib/types/services/formula-common.d.ts +0 -18
  31. package/lib/types/services/register-other-formula.service.d.ts +0 -40
package/lib/es/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 h, FUniver as S } from "@univerjs/core/facade";
2
+ import { Inject as c, ICommandService as _, Injector as v, IConfigService as g } from "@univerjs/core";
3
+ import { LexerTreeBuilder as x, SetFormulaCalculationStartMutation as d, SetFormulaCalculationStopMutation as E, SetFormulaCalculationNotificationMutation as p, GlobalComputingStatusService as F, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as T, SetFormulaCalculationResultMutation as y, SetFormulaStringBatchCalculationResultMutation as w, SetFormulaStringBatchCalculationMutation as R, SetFormulaDependencyCalculationResultMutation as M, SetFormulaDependencyCalculationMutation as b, SetCellFormulaDependencyCalculationResultMutation as D, SetCellFormulaDependencyCalculationMutation as I, SetQueryFormulaDependencyResultMutation as f, SetQueryFormulaDependencyMutation as C } from "@univerjs/engine-formula";
4
+ import { firstValueFrom as P, race as B, filter as L, timer as N, map as O } from "rxjs";
5
+ var A = Object.getOwnPropertyDescriptor, j = (e, t, i, r) => {
6
+ for (var n = r > 1 ? void 0 : r ? A(t, i) : t, a = e.length - 1, o; a >= 0; a--)
7
7
  (o = e[a]) && (n = o(n) || n);
8
8
  return n;
9
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();
10
+ let m = class extends h {
11
+ constructor(e, t, i, r) {
12
+ super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = i, this._configService = r, this._initialize();
13
13
  }
14
14
  /**
15
15
  * @ignore
@@ -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(d.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,7 +95,7 @@ let m = class extends C {
95
95
  */
96
96
  calculationStart(e) {
97
97
  return this._commandService.onCommandExecuted((t) => {
98
- if (t.id === R.id) {
98
+ if (t.id === d.id) {
99
99
  const i = t.params;
100
100
  e(i.forceCalculation);
101
101
  }
@@ -116,7 +116,7 @@ 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 !== p.id)
120
120
  return;
121
121
  const i = t.params;
122
122
  i.functionsExecutedState !== void 0 && e(i.functionsExecutedState);
@@ -139,10 +139,10 @@ let m = class extends C {
139
139
  * ```
140
140
  */
141
141
  whenComputingCompleteAsync(e) {
142
- const t = this._injector.get(b);
143
- return t.computingStatus ? Promise.resolve(!0) : j(Q(
144
- t.computingStatus$.pipe(q((i) => i)),
145
- G(e != null ? e : 3e4).pipe(z(() => !1))
142
+ const t = this._injector.get(F);
143
+ return t.computingStatus ? Promise.resolve(!0) : P(B(
144
+ t.computingStatus$.pipe(L((i) => i)),
145
+ N(e != null ? e : 3e4).pipe(O(() => !1))
146
146
  ));
147
147
  }
148
148
  /**
@@ -173,7 +173,7 @@ let m = class extends C {
173
173
  */
174
174
  calculationProcessing(e) {
175
175
  return this._commandService.onCommandExecuted((t) => {
176
- if (t.id !== d.id)
176
+ if (t.id !== p.id)
177
177
  return;
178
178
  const i = t.params;
179
179
  i.stageInfo !== void 0 && e(i.stageInfo);
@@ -192,7 +192,7 @@ let m = class extends C {
192
192
  * ```
193
193
  */
194
194
  setMaxIteration(e) {
195
- this._configService.setConfig(w, e);
195
+ this._configService.setConfig(T, e);
196
196
  }
197
197
  /**
198
198
  * Listens for the moment when formula-calculation results are applied.
@@ -219,7 +219,7 @@ let m = class extends C {
219
219
  */
220
220
  calculationResultApplied(e) {
221
221
  return this._commandService.onCommandExecuted((t) => {
222
- if (t.id !== D.id)
222
+ if (t.id !== y.id)
223
223
  return;
224
224
  const i = t.params;
225
225
  i !== void 0 && requestIdleCallback(() => {
@@ -344,7 +344,7 @@ let m = class extends C {
344
344
  executeFormulas(e, t = 3e4) {
345
345
  return new Promise((i, r) => {
346
346
  const n = this._commandService.onCommandExecuted((o) => {
347
- if (o.id !== M.id)
347
+ if (o.id !== w.id)
348
348
  return;
349
349
  const s = o.params;
350
350
  clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : r(new Error("Formula batch calculation returned no result"));
@@ -352,7 +352,7 @@ let m = class extends C {
352
352
  n.dispose(), r(new Error("Formula batch calculation timeout"));
353
353
  }, t);
354
354
  this._commandService.executeCommand(
355
- I.id,
355
+ R.id,
356
356
  { formulas: e },
357
357
  { onlyLocal: !0 }
358
358
  );
@@ -382,7 +382,7 @@ let m = class extends C {
382
382
  getAllDependencyTrees(e = 3e4) {
383
383
  return new Promise((t, i) => {
384
384
  const r = this._commandService.onCommandExecuted((a) => {
385
- if (a.id !== N.id)
385
+ if (a.id !== M.id)
386
386
  return;
387
387
  const o = a.params;
388
388
  clearTimeout(n), r.dispose(), o.result != null ? t(o.result) : t([]);
@@ -390,7 +390,7 @@ let m = class extends C {
390
390
  r.dispose(), i(new Error("Formula dependency calculation timeout"));
391
391
  }, e);
392
392
  this._commandService.executeCommand(
393
- P.id,
393
+ b.id,
394
394
  void 0,
395
395
  { onlyLocal: !0 }
396
396
  );
@@ -433,7 +433,7 @@ let m = class extends C {
433
433
  getCellDependencyTree(e, t = 3e4) {
434
434
  return new Promise((i, r) => {
435
435
  const n = this._commandService.onCommandExecuted((o) => {
436
- if (o.id !== B.id)
436
+ if (o.id !== D.id)
437
437
  return;
438
438
  const s = o.params;
439
439
  clearTimeout(a), n.dispose(), i(s.result);
@@ -441,7 +441,7 @@ let m = class extends C {
441
441
  n.dispose(), r(new Error("Cell dependency calculation timeout"));
442
442
  }, t);
443
443
  this._commandService.executeCommand(
444
- L.id,
444
+ I.id,
445
445
  e,
446
446
  { onlyLocal: !0 }
447
447
  );
@@ -481,7 +481,7 @@ let m = class extends C {
481
481
  getRangeDependents(e, t = 3e4) {
482
482
  return new Promise((i, r) => {
483
483
  const n = this._commandService.onCommandExecuted((o) => {
484
- if (o.id !== p.id)
484
+ if (o.id !== f.id)
485
485
  return;
486
486
  const s = o.params;
487
487
  clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i([]);
@@ -489,7 +489,7 @@ let m = class extends C {
489
489
  n.dispose(), r(new Error("Range dependents calculation timeout"));
490
490
  }, t);
491
491
  this._commandService.executeCommand(
492
- S.id,
492
+ C.id,
493
493
  { unitRanges: e },
494
494
  { onlyLocal: !0 }
495
495
  );
@@ -533,7 +533,7 @@ let m = class extends C {
533
533
  getInRangeFormulas(e, t = 3e4) {
534
534
  return new Promise((i, r) => {
535
535
  const n = this._commandService.onCommandExecuted((o) => {
536
- if (o.id !== p.id)
536
+ if (o.id !== f.id)
537
537
  return;
538
538
  const s = o.params;
539
539
  clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i([]);
@@ -541,207 +541,25 @@ let m = class extends C {
541
541
  n.dispose(), r(new Error("In-range formulas calculation timeout"));
542
542
  }, t);
543
543
  this._commandService.executeCommand(
544
- S.id,
544
+ C.id,
545
545
  { unitRanges: e, isInRange: !0 },
546
546
  { onlyLocal: !0 }
547
547
  );
548
548
  });
549
549
  }
550
- /**
551
- * Enable or disable emitting formula dependency trees after each formula calculation.
552
- *
553
- * When enabled, the formula engine will emit the dependency trees produced by
554
- * each completed formula calculation through the internal command system.
555
- * Consumers can obtain the result by listening for the corresponding
556
- * calculation-result command.
557
- *
558
- * When disabled, dependency trees will not be emitted.
559
- *
560
- * This option only controls whether dependency trees are exposed.
561
- * It does not affect formula calculation behavior.
562
- *
563
- * @param {boolean} value
564
- * Whether to emit formula dependency trees after calculation.
565
- * - `true`: Emit dependency trees after each calculation.
566
- * - `false`: Do not emit dependency trees (default behavior).
567
- *
568
- * @example
569
- * ```ts
570
- * const formulaEngine = univerAPI.getFormula();
571
- *
572
- * // Enable dependency tree emission
573
- * formulaEngine.setFormulaReturnDependencyTree(true);
574
- *
575
- * // Listen for dependency trees produced by formula calculation
576
- * const trees = await new Promise<IFormulaDependencyTreeJson[]>((resolve, reject) => {
577
- * const timer = setTimeout(() => {
578
- * disposable.dispose();
579
- * reject(new Error('Timeout waiting for formula dependency trees'));
580
- * }, 30_000);
581
- *
582
- * const disposable = commandService.onCommandExecuted((command) => {
583
- * if (command.id !== SetFormulaDependencyCalculationResultMutation.id) {
584
- * return;
585
- * }
586
- *
587
- * clearTimeout(timer);
588
- * disposable.dispose();
589
- *
590
- * const params = command.params as ISetFormulaDependencyCalculationResultMutation;
591
- * resolve(params.result ?? []);
592
- * });
593
- * });
594
- *
595
- * console.log('Dependency trees:', trees);
596
- * ```
597
- */
598
- setFormulaReturnDependencyTree(e) {
599
- this._configService.setConfig(A, e);
600
- }
601
- /**
602
- * Parse a formula string and return its **formula expression tree**.
603
- *
604
- * This API analyzes the syntactic structure of a formula and builds an
605
- * expression tree that reflects how the formula is composed (functions,
606
- * operators, ranges, and nested expressions), without performing calculation
607
- * or dependency evaluation.
608
- *
609
- * The returned tree is suitable for:
610
- * - Formula structure visualization
611
- * - Explaining complex formulas (e.g. LET / LAMBDA)
612
- * - Debugging or inspecting formula composition
613
- * - Building advanced formula tooling
614
- *
615
- * ---
616
- *
617
- * @example
618
- * ```ts
619
- * const formulaEngine = univerAPI.getFormula();
620
- *
621
- * const formula = '=LET(x,SUM(A1,B1,A1:B10),y,OFFSET(A1:B10,0,1),SUM(x,y)+x)+1';
622
- *
623
- * const exprTree = formulaEngine.getFormulaExpressTree(formula);
624
- *
625
- * console.log(exprTree);
626
- * ```
627
- *
628
- * Example output (simplified):
629
- *
630
- * ```json
631
- * {
632
- * "value": "let(x,sum(A1,B1,A1:B10),y,offset(A1:B10,0,1),sum(x,y)+x)+1",
633
- * "children": [
634
- * {
635
- * "value": "let(x,sum(A1,B1,A1:B10),y,offset(A1:B10,0,1),sum(x,y)+x)",
636
- * "children": [
637
- * {
638
- * "value": "sum(A1,B1,A1:B10)",
639
- * "children": [
640
- * {
641
- * "value": "A1:B10",
642
- * "children": []
643
- * }
644
- * ]
645
- * },
646
- * {
647
- * "value": "offset(A1:B10,0,1)",
648
- * "children": [
649
- * {
650
- * "value": "A1:B10",
651
- * "children": []
652
- * }
653
- * ]
654
- * }
655
- * ]
656
- * }
657
- * ]
658
- * }
659
- * ```
660
- *
661
- * @param formulaString The formula string to parse (with or without leading `=`)
662
- * @returns A formula expression tree describing the hierarchical structure of the formula
663
- */
664
- getFormulaExpressTree(e, t) {
665
- return this._lexerTreeBuilder.getFormulaExprTree(e, t, this._functionService.hasExecutor.bind(this._functionService), this._definedNamesService.getValueByName.bind(this._definedNamesService), this._superTableService.getTable.bind(this._superTableService));
666
- }
667
- /**
668
- * Retrieve **both**:
669
- * 1) the full dependency trees of all formulas that **depend on** the specified ranges, and
670
- * 2) the dependency trees of all formulas that **physically reside inside** the specified ranges.
671
- *
672
- * This is a convenience API that combines the behaviors of
673
- * `getRangeDependents` and `getInRangeFormulas` into a single call.
674
- *
675
- * Internally, it triggers a local dependency-calculation command once and
676
- * resolves when both result sets are available, avoiding duplicate
677
- * calculations and event listeners.
678
- *
679
- * @param unitRanges An array of workbook/sheet ranges to query. Each range
680
- * includes:
681
- * - `unitId` The workbook ID.
682
- * - `sheetId` The sheet ID.
683
- * - `range` The zero-based row/column boundaries.
684
- *
685
- * @param {number} [timeout]
686
- * Optional timeout in milliseconds. If the dependency calculation does
687
- * not complete within this period, the promise will be rejected.
688
- *
689
- * @returns {Promise<IFormulaDependentsAndInRangeResults>}
690
- * A promise that resolves with an object containing:
691
- * - `dependents`: Dependency trees of all formulas that depend on the
692
- * specified ranges (upstream consumers).
693
- * - `inRanges`: Dependency trees of all formulas whose definitions
694
- * are located inside the specified ranges.
695
- *
696
- * @example
697
- * ```ts
698
- * const formulaEngine = univerAPI.getFormula();
699
- *
700
- * const result = await formulaEngine.getRangeDependentsAndInRangeFormulas([
701
- * {
702
- * unitId: 'workbook1',
703
- * sheetId: 'sheet1',
704
- * range: { startRow: 0, endRow: 9, startColumn: 0, endColumn: 1 },
705
- * },
706
- * ]);
707
- *
708
- * console.log('Dependent formulas:', result.dependents);
709
- * console.log('Formulas inside range:', result.inRanges);
710
- * ```
711
- */
712
- getRangeDependentsAndInRangeFormulas(e, t = 3e4) {
713
- return new Promise((i, r) => {
714
- const n = this._commandService.onCommandExecuted((o) => {
715
- if (o.id !== O.id)
716
- return;
717
- const s = o.params;
718
- clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i({ dependents: [], inRanges: [] });
719
- }), a = setTimeout(() => {
720
- n.dispose(), r(new Error("Range dependents calculation timeout"));
721
- }, t);
722
- this._commandService.executeCommand(
723
- U.id,
724
- { unitRanges: e },
725
- { onlyLocal: !0 }
726
- );
727
- });
728
- }
729
550
  };
730
- m = Y([
551
+ m = j([
731
552
  u(0, c(_)),
732
- u(1, c(h)),
733
- u(2, c(g)),
734
- u(3, v),
735
- u(4, E),
736
- u(5, T),
737
- u(6, x)
553
+ u(1, c(v)),
554
+ u(2, c(x)),
555
+ u(3, g)
738
556
  ], m);
739
- class W extends f {
557
+ class U extends S {
740
558
  getFormula() {
741
559
  return this._injector.createInstance(m);
742
560
  }
743
561
  }
744
- f.extend(W);
562
+ S.extend(U);
745
563
  export {
746
564
  m as FFormula
747
565
  };