@univerjs/engine-formula 0.13.0-insiders.20251216-1519cb7 → 0.13.0-insiders.20251220-0a5ea4d
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/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +99 -37
- package/lib/es/index.js +3313 -3090
- package/lib/facade.js +99 -37
- package/lib/index.js +3313 -3090
- package/lib/types/basics/common.d.ts +1 -0
- package/lib/types/commands/mutations/formula.mutation.d.ts +9 -0
- package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +10 -1
- package/lib/types/controller/calculate.controller.d.ts +1 -0
- package/lib/types/engine/dependency/dependency-tree.d.ts +4 -0
- package/lib/types/engine/dependency/formula-dependency.d.ts +5 -1
- package/lib/types/facade/f-formula.d.ts +47 -1
- package/lib/types/index.d.ts +6 -2
- package/lib/types/services/active-dirty-manager.service.d.ts +1 -0
- package/lib/types/services/calculate-formula.service.d.ts +3 -1
- package/lib/types/services/formula-common.d.ts +18 -0
- package/lib/types/services/register-other-formula.service.d.ts +40 -0
- package/lib/types/services/super-table.service.d.ts +2 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +3 -3
package/lib/es/facade.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FBase as C, FUniver as
|
|
2
|
-
import { Inject as
|
|
3
|
-
import { LexerTreeBuilder as g, IFunctionService as
|
|
4
|
-
import { firstValueFrom as
|
|
5
|
-
var
|
|
6
|
-
for (var n = r > 1 ? void 0 : r ?
|
|
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--)
|
|
7
7
|
(o = e[a]) && (n = o(n) || n);
|
|
8
8
|
return n;
|
|
9
9
|
}, u = (e, t) => (i, r) => t(i, r, e);
|
|
@@ -66,7 +66,7 @@ let m = class extends C {
|
|
|
66
66
|
* ```
|
|
67
67
|
*/
|
|
68
68
|
executeCalculation() {
|
|
69
|
-
this._commandService.executeCommand(
|
|
69
|
+
this._commandService.executeCommand(F.id, { commands: [], forceCalculation: !0 }, { onlyLocal: !0 });
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Stop the calculation of the formula.
|
|
@@ -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 ===
|
|
98
|
+
if (t.id === R.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 !==
|
|
119
|
+
if (t.id !== d.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(
|
|
143
|
-
return t.computingStatus ? Promise.resolve(!0) :
|
|
144
|
-
t.computingStatus$.pipe(
|
|
145
|
-
|
|
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))
|
|
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 !==
|
|
176
|
+
if (t.id !== d.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(
|
|
195
|
+
this._configService.setConfig(w, 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 !==
|
|
222
|
+
if (t.id !== D.id)
|
|
223
223
|
return;
|
|
224
224
|
const i = t.params;
|
|
225
225
|
i !== void 0 && requestIdleCallback(() => {
|
|
@@ -259,15 +259,15 @@ let m = class extends C {
|
|
|
259
259
|
return new Promise((e, t) => {
|
|
260
260
|
let i = !1, r = !1;
|
|
261
261
|
const n = setTimeout(() => {
|
|
262
|
-
|
|
262
|
+
l(), t(new Error("Calculation end timeout"));
|
|
263
263
|
}, 3e4), a = setTimeout(() => {
|
|
264
|
-
i || (
|
|
264
|
+
i || (l(), e());
|
|
265
265
|
}, 500), o = this.calculationProcessing(() => {
|
|
266
266
|
i || (i = !0, clearTimeout(a));
|
|
267
267
|
}), s = this.calculationResultApplied(() => {
|
|
268
|
-
r || (r = !0,
|
|
268
|
+
r || (r = !0, l(), e());
|
|
269
269
|
});
|
|
270
|
-
function
|
|
270
|
+
function l() {
|
|
271
271
|
clearTimeout(n), clearTimeout(a), o.dispose(), s.dispose();
|
|
272
272
|
}
|
|
273
273
|
});
|
|
@@ -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 !==
|
|
347
|
+
if (o.id !== M.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"));
|
|
@@ -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
|
-
|
|
393
|
+
P.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 !==
|
|
436
|
+
if (o.id !== B.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
|
-
|
|
444
|
+
L.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 !==
|
|
484
|
+
if (o.id !== p.id)
|
|
485
485
|
return;
|
|
486
486
|
const s = o.params;
|
|
487
487
|
clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i([]);
|
|
@@ -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 !==
|
|
536
|
+
if (o.id !== p.id)
|
|
537
537
|
return;
|
|
538
538
|
const s = o.params;
|
|
539
539
|
clearTimeout(a), n.dispose(), s.result != null ? i(s.result) : i([]);
|
|
@@ -596,7 +596,7 @@ let m = class extends C {
|
|
|
596
596
|
* ```
|
|
597
597
|
*/
|
|
598
598
|
setFormulaReturnDependencyTree(e) {
|
|
599
|
-
this._configService.setConfig(
|
|
599
|
+
this._configService.setConfig(A, e);
|
|
600
600
|
}
|
|
601
601
|
/**
|
|
602
602
|
* Parse a formula string and return its **formula expression tree**.
|
|
@@ -664,22 +664,84 @@ let m = class extends C {
|
|
|
664
664
|
getFormulaExpressTree(e, t) {
|
|
665
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
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
|
+
}
|
|
667
729
|
};
|
|
668
|
-
m =
|
|
669
|
-
u(0,
|
|
670
|
-
u(1,
|
|
671
|
-
u(2,
|
|
672
|
-
u(3,
|
|
673
|
-
u(4,
|
|
674
|
-
u(5,
|
|
675
|
-
u(6,
|
|
730
|
+
m = Y([
|
|
731
|
+
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)
|
|
676
738
|
], m);
|
|
677
|
-
class
|
|
739
|
+
class W extends f {
|
|
678
740
|
getFormula() {
|
|
679
741
|
return this._injector.createInstance(m);
|
|
680
742
|
}
|
|
681
743
|
}
|
|
682
|
-
|
|
744
|
+
f.extend(W);
|
|
683
745
|
export {
|
|
684
746
|
m as FFormula
|
|
685
747
|
};
|