@univerjs/engine-formula 0.12.4-insiders.20251213-692494c → 0.13.0-insiders.20251215-64041bb
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 +155 -35
- package/lib/es/index.js +2572 -2576
- package/lib/facade.js +155 -35
- package/lib/index.js +2572 -2576
- package/lib/types/basics/common.d.ts +7 -0
- package/lib/types/basics/match-token.d.ts +1 -1
- package/lib/types/controller/config.schema.d.ts +1 -0
- package/lib/types/engine/analysis/lexer-tree-builder.d.ts +2 -1
- package/lib/types/engine/ast-node/reference-node.d.ts +0 -1
- package/lib/types/engine/dependency/formula-dependency.d.ts +3 -2
- package/lib/types/engine/utils/reference.d.ts +9 -0
- package/lib/types/engine/utils/sequence.d.ts +2 -1
- package/lib/types/facade/f-formula.d.ts +118 -2
- package/lib/types/index.d.ts +3 -3
- package/lib/types/services/calculate-formula.service.d.ts +1 -0
- package/lib/types/services/current-data.service.d.ts +1 -0
- package/lib/types/services/defined-names.service.d.ts +1 -0
- package/lib/types/services/runtime.service.d.ts +7 -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 +4 -4
package/lib/facade.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { FBase as
|
|
2
|
-
import { Inject as
|
|
3
|
-
import { LexerTreeBuilder as x, SetFormulaCalculationStartMutation as d, SetFormulaCalculationStopMutation as
|
|
4
|
-
import { firstValueFrom as
|
|
5
|
-
var
|
|
6
|
-
for (var n = r > 1 ? void 0 : r ?
|
|
1
|
+
import { FBase as C, FUniver as _ } from "@univerjs/core/facade";
|
|
2
|
+
import { Inject as l, ICommandService as h, Injector as v, IConfigService as E } from "@univerjs/core";
|
|
3
|
+
import { LexerTreeBuilder as g, IFunctionService as T, IDefinedNamesService as x, ISuperTableService as F, SetFormulaCalculationStartMutation as d, SetFormulaCalculationStopMutation as y, SetFormulaCalculationNotificationMutation as p, GlobalComputingStatusService as R, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as b, SetFormulaCalculationResultMutation as w, SetFormulaStringBatchCalculationResultMutation as D, SetFormulaStringBatchCalculationMutation as I, SetFormulaDependencyCalculationResultMutation as N, SetFormulaDependencyCalculationMutation as M, SetCellFormulaDependencyCalculationResultMutation as P, SetCellFormulaDependencyCalculationMutation as B, SetQueryFormulaDependencyResultMutation as f, SetQueryFormulaDependencyMutation as S, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE as L } from "@univerjs/engine-formula";
|
|
4
|
+
import { firstValueFrom as O, race as A, filter as U, timer as j, map as q } from "rxjs";
|
|
5
|
+
var G = Object.getOwnPropertyDescriptor, z = (e, t, i, r) => {
|
|
6
|
+
for (var n = r > 1 ? void 0 : r ? G(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
|
|
11
|
-
constructor(e, t, i, r) {
|
|
12
|
-
super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = i, this._configService = r, this._initialize();
|
|
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();
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @ignore
|
|
@@ -78,7 +78,7 @@ let m = class extends h {
|
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
stopCalculation() {
|
|
81
|
-
this._commandService.executeCommand(
|
|
81
|
+
this._commandService.executeCommand(y.id, {});
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Listening calculation starts.
|
|
@@ -139,10 +139,10 @@ let m = class extends h {
|
|
|
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(R);
|
|
143
|
+
return t.computingStatus ? Promise.resolve(!0) : O(A(
|
|
144
|
+
t.computingStatus$.pipe(U((i) => i)),
|
|
145
|
+
j(e != null ? e : 3e4).pipe(q(() => !1))
|
|
146
146
|
));
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
@@ -192,7 +192,7 @@ let m = class extends h {
|
|
|
192
192
|
* ```
|
|
193
193
|
*/
|
|
194
194
|
setMaxIteration(e) {
|
|
195
|
-
this._configService.setConfig(
|
|
195
|
+
this._configService.setConfig(b, 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 h {
|
|
|
219
219
|
*/
|
|
220
220
|
calculationResultApplied(e) {
|
|
221
221
|
return this._commandService.onCommandExecuted((t) => {
|
|
222
|
-
if (t.id !==
|
|
222
|
+
if (t.id !== w.id)
|
|
223
223
|
return;
|
|
224
224
|
const i = t.params;
|
|
225
225
|
i !== void 0 && requestIdleCallback(() => {
|
|
@@ -259,15 +259,15 @@ let m = class extends h {
|
|
|
259
259
|
return new Promise((e, t) => {
|
|
260
260
|
let i = !1, r = !1;
|
|
261
261
|
const n = setTimeout(() => {
|
|
262
|
-
|
|
262
|
+
c(), t(new Error("Calculation end timeout"));
|
|
263
263
|
}, 3e4), a = setTimeout(() => {
|
|
264
|
-
i || (
|
|
264
|
+
i || (c(), 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, c(), e());
|
|
269
269
|
});
|
|
270
|
-
function
|
|
270
|
+
function c() {
|
|
271
271
|
clearTimeout(n), clearTimeout(a), o.dispose(), s.dispose();
|
|
272
272
|
}
|
|
273
273
|
});
|
|
@@ -344,7 +344,7 @@ let m = class extends h {
|
|
|
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 !== D.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 h {
|
|
|
352
352
|
n.dispose(), r(new Error("Formula batch calculation timeout"));
|
|
353
353
|
}, t);
|
|
354
354
|
this._commandService.executeCommand(
|
|
355
|
-
|
|
355
|
+
I.id,
|
|
356
356
|
{ formulas: e },
|
|
357
357
|
{ onlyLocal: !0 }
|
|
358
358
|
);
|
|
@@ -382,7 +382,7 @@ let m = class extends h {
|
|
|
382
382
|
getAllDependencyTrees(e = 3e4) {
|
|
383
383
|
return new Promise((t, i) => {
|
|
384
384
|
const r = this._commandService.onCommandExecuted((a) => {
|
|
385
|
-
if (a.id !==
|
|
385
|
+
if (a.id !== N.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 h {
|
|
|
390
390
|
r.dispose(), i(new Error("Formula dependency calculation timeout"));
|
|
391
391
|
}, e);
|
|
392
392
|
this._commandService.executeCommand(
|
|
393
|
-
|
|
393
|
+
M.id,
|
|
394
394
|
void 0,
|
|
395
395
|
{ onlyLocal: !0 }
|
|
396
396
|
);
|
|
@@ -433,7 +433,7 @@ let m = class extends h {
|
|
|
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 !== P.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 h {
|
|
|
441
441
|
n.dispose(), r(new Error("Cell dependency calculation timeout"));
|
|
442
442
|
}, t);
|
|
443
443
|
this._commandService.executeCommand(
|
|
444
|
-
|
|
444
|
+
B.id,
|
|
445
445
|
e,
|
|
446
446
|
{ onlyLocal: !0 }
|
|
447
447
|
);
|
|
@@ -489,7 +489,7 @@ let m = class extends h {
|
|
|
489
489
|
n.dispose(), r(new Error("Range dependents calculation timeout"));
|
|
490
490
|
}, t);
|
|
491
491
|
this._commandService.executeCommand(
|
|
492
|
-
|
|
492
|
+
S.id,
|
|
493
493
|
{ unitRanges: e },
|
|
494
494
|
{ onlyLocal: !0 }
|
|
495
495
|
);
|
|
@@ -541,25 +541,145 @@ let m = class extends h {
|
|
|
541
541
|
n.dispose(), r(new Error("In-range formulas calculation timeout"));
|
|
542
542
|
}, t);
|
|
543
543
|
this._commandService.executeCommand(
|
|
544
|
-
|
|
544
|
+
S.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(L, 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
|
+
}
|
|
550
667
|
};
|
|
551
|
-
m =
|
|
552
|
-
u(0,
|
|
553
|
-
u(1,
|
|
554
|
-
u(2,
|
|
555
|
-
u(3,
|
|
668
|
+
m = z([
|
|
669
|
+
u(0, l(h)),
|
|
670
|
+
u(1, l(v)),
|
|
671
|
+
u(2, l(g)),
|
|
672
|
+
u(3, E),
|
|
673
|
+
u(4, T),
|
|
674
|
+
u(5, x),
|
|
675
|
+
u(6, F)
|
|
556
676
|
], m);
|
|
557
|
-
class
|
|
677
|
+
class Q extends _ {
|
|
558
678
|
getFormula() {
|
|
559
679
|
return this._injector.createInstance(m);
|
|
560
680
|
}
|
|
561
681
|
}
|
|
562
|
-
|
|
682
|
+
_.extend(Q);
|
|
563
683
|
export {
|
|
564
684
|
m as FFormula
|
|
565
685
|
};
|