@univerjs/engine-formula 0.5.3 → 0.5.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,16 +1,45 @@
1
- import { Inject as u, ICommandService as _, Injector as f, FBase as C, IConfigService as v, FUniver as d } from "@univerjs/core";
2
- import { SetFormulaCalculationStartMutation as l, SetFormulaCalculationStopMutation as p, SetFormulaCalculationNotificationMutation as m, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as S } from "@univerjs/engine-formula";
3
- var E = Object.defineProperty, x = Object.getOwnPropertyDescriptor, h = (t, e, i, a) => {
4
- for (var n = a > 1 ? void 0 : a ? x(e, i) : e, o = t.length - 1, r; o >= 0; o--)
5
- (r = t[o]) && (n = (a ? r(e, i, n) : r(n)) || n);
6
- return a && n && E(e, i, n), n;
7
- }, c = (t, e) => (i, a) => e(i, a, t);
1
+ import { Inject as u, ICommandService as f, Injector as _, FBase as C, IConfigService as v, FUniver as m } from "@univerjs/core";
2
+ import { LexerTreeBuilder as x, SetFormulaCalculationStartMutation as l, SetFormulaCalculationStopMutation as p, SetFormulaCalculationNotificationMutation as d, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT as S } from "@univerjs/engine-formula";
3
+ var h = Object.defineProperty, E = Object.getOwnPropertyDescriptor, F = (e, t, r, i) => {
4
+ for (var n = i > 1 ? void 0 : i ? E(t, r) : t, a = e.length - 1, c; a >= 0; a--)
5
+ (c = e[a]) && (n = (i ? c(t, r, n) : c(n)) || n);
6
+ return i && n && h(t, r, n), n;
7
+ }, o = (e, t) => (r, i) => t(r, i, e);
8
8
  let s = class extends C {
9
- constructor(t, e, i) {
10
- super(), this._commandService = t, this._injector = e, this._configService = i, this._initialize();
9
+ constructor(e, t, r, i) {
10
+ super(), this._commandService = e, this._injector = t, this._lexerTreeBuilder = r, this._configService = i, this._initialize();
11
11
  }
12
12
  _initialize() {
13
13
  }
14
+ /**
15
+ * The tree builder for formula string.
16
+ * @type {LexerTreeBuilder}
17
+ */
18
+ get lexerTreeBuilder() {
19
+ return this._lexerTreeBuilder;
20
+ }
21
+ /**
22
+ * Offsets the formula
23
+ * @param {string} formulaString
24
+ * @param {number} refOffsetX
25
+ * @param {number} refOffsetY
26
+ * @param {boolean} [ignoreAbsolute] default is false
27
+ * @example
28
+ * const result = moveFormulaRefOffset('sum(a1,b2)',1,1)
29
+ * // result is 'sum(b2,c3)'
30
+ */
31
+ moveFormulaRefOffset(e, t, r, i) {
32
+ return this._lexerTreeBuilder.moveFormulaRefOffset(e, t, r, i);
33
+ }
34
+ /**
35
+ * Resolves the formula string to a 'node' node
36
+ * @param {string} formulaString
37
+ * @returns {*} {((string | ISequenceNode)[])}
38
+ * @memberof FFormula
39
+ */
40
+ sequenceNodesBuilder(e) {
41
+ return this._lexerTreeBuilder.sequenceNodesBuilder(e) || [];
42
+ }
14
43
  /**
15
44
  * Start the calculation of the formula.
16
45
  */
@@ -25,44 +54,47 @@ let s = class extends C {
25
54
  }
26
55
  /**
27
56
  * Listening calculation starts.
57
+ * @param callback
28
58
  */
29
- calculationStart(t) {
30
- return this._commandService.onCommandExecuted((e) => {
31
- if (e.id === l.id) {
32
- const i = e.params;
33
- t(i.forceCalculation);
59
+ calculationStart(e) {
60
+ return this._commandService.onCommandExecuted((t) => {
61
+ if (t.id === l.id) {
62
+ const r = t.params;
63
+ e(r.forceCalculation);
34
64
  }
35
65
  });
36
66
  }
37
67
  /**
38
68
  * Listening calculation ends.
69
+ * @param callback
39
70
  */
40
- calculationEnd(t) {
41
- return this._commandService.onCommandExecuted((e) => {
42
- if (e.id !== m.id)
71
+ calculationEnd(e) {
72
+ return this._commandService.onCommandExecuted((t) => {
73
+ if (t.id !== d.id)
43
74
  return;
44
- const i = e.params;
45
- i.functionsExecutedState !== void 0 && t(i.functionsExecutedState);
75
+ const r = t.params;
76
+ r.functionsExecutedState !== void 0 && e(r.functionsExecutedState);
46
77
  });
47
78
  }
48
79
  onCalculationEnd() {
49
- return new Promise((t, e) => {
50
- const i = setTimeout(() => {
51
- e(new Error("Calculation end timeout"));
52
- }, 3e4), a = this.calculationEnd(() => {
53
- clearTimeout(i), a.dispose(), t();
80
+ return new Promise((e, t) => {
81
+ const r = setTimeout(() => {
82
+ t(new Error("Calculation end timeout"));
83
+ }, 3e4), i = this.calculationEnd(() => {
84
+ clearTimeout(r), i.dispose(), e();
54
85
  });
55
86
  });
56
87
  }
57
88
  /**
58
89
  * Listening calculation processing.
90
+ * @param callback
59
91
  */
60
- calculationProcessing(t) {
61
- return this._commandService.onCommandExecuted((e) => {
62
- if (e.id !== m.id)
92
+ calculationProcessing(e) {
93
+ return this._commandService.onCommandExecuted((t) => {
94
+ if (t.id !== d.id)
63
95
  return;
64
- const i = e.params;
65
- i.stageInfo !== void 0 && t(i.stageInfo);
96
+ const r = t.params;
97
+ r.stageInfo !== void 0 && e(r.stageInfo);
66
98
  });
67
99
  }
68
100
  /**
@@ -76,21 +108,22 @@ let s = class extends C {
76
108
  * formulaEngine.setMaxIteration(5);
77
109
  * ```
78
110
  */
79
- setMaxIteration(t) {
80
- this._configService.setConfig(S, t);
111
+ setMaxIteration(e) {
112
+ this._configService.setConfig(S, e);
81
113
  }
82
114
  };
83
- s = h([
84
- c(0, u(_)),
85
- c(1, u(f)),
86
- c(2, v)
115
+ s = F([
116
+ o(0, u(f)),
117
+ o(1, u(_)),
118
+ o(2, u(x)),
119
+ o(3, v)
87
120
  ], s);
88
- class F extends d {
121
+ class g extends m {
89
122
  getFormula() {
90
123
  return this._injector.createInstance(s);
91
124
  }
92
125
  }
93
- d.extend(F);
126
+ m.extend(g);
94
127
  export {
95
128
  s as FFormula
96
129
  };