@univerjs/sheets-formula 0.15.3 → 0.15.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/cjs/facade.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -0
- package/lib/es/facade.js +105 -74
- package/lib/es/locale/sk-SK.js +14 -0
- package/lib/facade.js +105 -74
- package/lib/locale/sk-SK.js +14 -0
- package/lib/types/facade/f-formula.d.ts +56 -1
- package/lib/types/locale/sk-SK.d.ts +3 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -0
- package/package.json +9 -9
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const C=require("@univerjs/core"),I=require("@univerjs/core/facade"),s=require("@univerjs/engine-formula"),c=require("@univerjs/sheets-formula"),b=require("@univerjs/engine-formula/facade"),y=require("@univerjs/sheets"),R=require("@univerjs/sheets/facade");class p extends I.FUniver{_initialize(){this._debouncedFormulaCalculation=C.debounce(()=>{this._commandService.executeCommand(s.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(t){let o=this._injector.get(c.IRegisterFunctionService);o||(this._injector.add([c.IRegisterFunctionService,{useClass:c.RegisterFunctionService}]),o=this._injector.get(c.IRegisterFunctionService));const e=o.registerFunctions(t);return this._debouncedFormulaCalculation(),e}}I.FUniver.extend(p);class M extends b.FFormula{_initialize(){this._debouncedFormulaCalculation=C.debounce(()=>{this._commandService.executeCommand(s.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(t){const e=this._injector.get(C.LifecycleService).stage,n=this._injector.get(C.ILogService),i=this._injector.get(C.IConfigService);e>C.LifecycleStages.Starting&&n.warn("[FFormula]","CalculationMode is called after the Starting lifecycle and will take effect the next time the Univer Sheet is constructed. If you want it to take effect when the Univer Sheet is initialized this time, consider calling it before the Ready lifecycle or using configuration.");const r=i.getConfig(c.PLUGIN_CONFIG_KEY_BASE);if(!r){i.setConfig(c.PLUGIN_CONFIG_KEY_BASE,{initialFormulaComputing:t});return}r.initialFormulaComputing=t}registerFunction(t,o,e){var a;let n=this._injector.get(c.IRegisterFunctionService);n||(this._injector.add([c.IRegisterFunctionService,{useClass:c.RegisterFunctionService}]),n=this._injector.get(c.IRegisterFunctionService));const i={name:t,func:o,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},r=n.registerFunction(i);return this._debouncedFormulaCalculation(),r}registerAsyncFunction(t,o,e){var a;let n=this._injector.get(c.IRegisterFunctionService);n||(this._injector.add([c.IRegisterFunctionService,{useClass:c.RegisterFunctionService}]),n=this._injector.get(c.IRegisterFunctionService));const i={name:t,func:o,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},r=n.registerAsyncFunction(i);return this._debouncedFormulaCalculation(),r}calculationResultApplied(t){let o=!1,e=!1,n=null;return this._commandService.onCommandExecuted((i,r)=>{i.id!==s.SetFormulaCalculationResultMutation.id&&i.id!==y.SetRangeValuesMutation.id||(i.id===s.SetFormulaCalculationResultMutation.id&&(o=!0,n=i.params),i.id===y.SetRangeValuesMutation.id&&(r!=null&&r.applyFormulaCalculationResult)&&(e=!0),!(!o||!e)&&requestIdleCallback(()=>{t(n)}))})}onCalculationResultApplied(){return new Promise((t,o)=>{let e=!1,n=!1;const i=setTimeout(()=>{l(),o(new Error("Calculation end timeout"))},6e4),r=setTimeout(()=>{e||(l(),t())},500),a=this.calculationProcessing(g=>{const{stage:m,totalArrayFormulasToCalculate:f,totalFormulasToCalculate:d}=g;if(m===s.FormulaExecuteStageType.START_CALCULATION&&f+d===0){l(),t();return}e||(e=!0,clearTimeout(r))}),_=this.calculationResultApplied(()=>{n||(n=!0,l(),t())});function l(){clearTimeout(i),clearTimeout(r),a.dispose(),_.dispose()}})}}b.FFormula.extend(M);class j{get CalculationMode(){return c.CalculationMode}}I.FEnum.extend(j);class E extends R.FWorkbook{getAllFormulaError(){const t=[],o=this._workbook,e=o.getUnitId(),n=o.getSheets(),i=this._injector.get(s.FormulaDataModel).getArrayFormulaCellData();return n.forEach(r=>{var m;const a=r.getName(),_=r.getSheetId(),l=r.getCellMatrix(),g=((m=i==null?void 0:i[e])==null?void 0:m[_])||{};l.forValue((f,d,h)=>{var S;if(!h)return;const F=(S=g==null?void 0:g[f])==null?void 0:S[d],u=s.extractFormulaError(h,!!F);u&&t.push({sheetName:a,row:f,column:d,formula:h.f||"",errorType:u})})}),t}}R.FWorkbook.extend(E);class T extends R.FRange{getFormulaError(){var d,h;const t=[],o=this._workbook.getUnitId(),e=this._worksheet.getSheetId(),n=this._worksheet.getName(),i=this._workbook.getSheetBySheetId(e);if(!i)return t;const r=this._injector.get(s.FormulaDataModel).getArrayFormulaCellData(),a=((d=r==null?void 0:r[o])==null?void 0:d[e])||{},_=i.getCellMatrix(),{startRow:l,endRow:g,startColumn:m,endColumn:f}=this._range;for(let F=l;F<=g;F++)for(let u=m;u<=f;u++){const S=_.getValue(F,u);if(!S)continue;const k=(h=a==null?void 0:a[F])==null?void 0:h[u],x=s.extractFormulaError(S,!!k);x&&t.push({sheetName:n,row:F,column:u,formula:S.f||"",errorType:x})}return t}}R.FRange.extend(T);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const a={formula:{progress:{analyzing:"Analyzovanie",calculating:"Výpočet","array-analysis":"Analýza poľa","array-calculation":"Výpočet poľa",done:"Hotovo"}}};module.exports=a;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { debounce as
|
|
2
|
-
import { FUniver as
|
|
3
|
-
import { SetTriggerFormulaCalculationStartMutation as
|
|
4
|
-
import { IRegisterFunctionService as
|
|
5
|
-
import { FFormula as
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { debounce as v, LifecycleService as E, ILogService as D, IConfigService as L, LifecycleStages as U } from "@univerjs/core";
|
|
2
|
+
import { FUniver as I, FEnum as N } from "@univerjs/core/facade";
|
|
3
|
+
import { SetTriggerFormulaCalculationStartMutation as k, SetFormulaCalculationResultMutation as y, FormulaExecuteStageType as z, FormulaDataModel as j, extractFormulaError as R } from "@univerjs/engine-formula";
|
|
4
|
+
import { IRegisterFunctionService as a, RegisterFunctionService as _, PLUGIN_CONFIG_KEY_BASE as x, CalculationMode as P } from "@univerjs/sheets-formula";
|
|
5
|
+
import { FFormula as T } from "@univerjs/engine-formula/facade";
|
|
6
|
+
import { SetRangeValuesMutation as b } from "@univerjs/sheets";
|
|
7
|
+
import { FWorkbook as w, FRange as M } from "@univerjs/sheets/facade";
|
|
8
|
+
class V extends I {
|
|
8
9
|
/**
|
|
9
10
|
* Initialize the FUniver instance.
|
|
10
11
|
* @ignore
|
|
11
12
|
*/
|
|
12
13
|
_initialize() {
|
|
13
|
-
this._debouncedFormulaCalculation =
|
|
14
|
+
this._debouncedFormulaCalculation = v(() => {
|
|
14
15
|
this._commandService.executeCommand(
|
|
15
|
-
|
|
16
|
+
k.id,
|
|
16
17
|
{
|
|
17
18
|
commands: [],
|
|
18
19
|
forceCalculation: !0
|
|
@@ -24,22 +25,22 @@ class z extends b {
|
|
|
24
25
|
}, 10);
|
|
25
26
|
}
|
|
26
27
|
registerFunction(t) {
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
const e =
|
|
28
|
+
let n = this._injector.get(a);
|
|
29
|
+
n || (this._injector.add([a, { useClass: _ }]), n = this._injector.get(a));
|
|
30
|
+
const e = n.registerFunctions(t);
|
|
30
31
|
return this._debouncedFormulaCalculation(), e;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
class
|
|
34
|
+
I.extend(V);
|
|
35
|
+
class W extends T {
|
|
35
36
|
/**
|
|
36
37
|
* Initialize the FUniver instance.
|
|
37
38
|
* @ignore
|
|
38
39
|
*/
|
|
39
40
|
_initialize() {
|
|
40
|
-
this._debouncedFormulaCalculation =
|
|
41
|
+
this._debouncedFormulaCalculation = v(() => {
|
|
41
42
|
this._commandService.executeCommand(
|
|
42
|
-
|
|
43
|
+
k.id,
|
|
43
44
|
{
|
|
44
45
|
commands: [],
|
|
45
46
|
forceCalculation: !0
|
|
@@ -51,89 +52,119 @@ class T extends w {
|
|
|
51
52
|
}, 10);
|
|
52
53
|
}
|
|
53
54
|
setInitialFormulaComputing(t) {
|
|
54
|
-
const e = this._injector.get(
|
|
55
|
-
e >
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
-
|
|
55
|
+
const e = this._injector.get(E).stage, o = this._injector.get(D), i = this._injector.get(L);
|
|
56
|
+
e > U.Starting && o.warn("[FFormula]", "CalculationMode is called after the Starting lifecycle and will take effect the next time the Univer Sheet is constructed. If you want it to take effect when the Univer Sheet is initialized this time, consider calling it before the Ready lifecycle or using configuration.");
|
|
57
|
+
const r = i.getConfig(x);
|
|
58
|
+
if (!r) {
|
|
59
|
+
i.setConfig(x, { initialFormulaComputing: t });
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
r.initialFormulaComputing = t;
|
|
62
63
|
}
|
|
63
|
-
registerFunction(t,
|
|
64
|
-
var
|
|
65
|
-
let o = this._injector.get(
|
|
66
|
-
o || (this._injector.add([
|
|
67
|
-
const
|
|
64
|
+
registerFunction(t, n, e) {
|
|
65
|
+
var l;
|
|
66
|
+
let o = this._injector.get(a);
|
|
67
|
+
o || (this._injector.add([a, { useClass: _ }]), o = this._injector.get(a));
|
|
68
|
+
const i = {
|
|
68
69
|
name: t,
|
|
69
|
-
func:
|
|
70
|
-
description: typeof e == "string" ? e : (
|
|
70
|
+
func: n,
|
|
71
|
+
description: typeof e == "string" ? e : (l = e == null ? void 0 : e.description) != null ? l : "",
|
|
71
72
|
locales: typeof e == "object" ? e.locales : void 0
|
|
72
|
-
},
|
|
73
|
-
return this._debouncedFormulaCalculation(),
|
|
73
|
+
}, r = o.registerFunction(i);
|
|
74
|
+
return this._debouncedFormulaCalculation(), r;
|
|
74
75
|
}
|
|
75
|
-
registerAsyncFunction(t,
|
|
76
|
-
var
|
|
77
|
-
let o = this._injector.get(
|
|
78
|
-
o || (this._injector.add([
|
|
79
|
-
const
|
|
76
|
+
registerAsyncFunction(t, n, e) {
|
|
77
|
+
var l;
|
|
78
|
+
let o = this._injector.get(a);
|
|
79
|
+
o || (this._injector.add([a, { useClass: _ }]), o = this._injector.get(a));
|
|
80
|
+
const i = {
|
|
80
81
|
name: t,
|
|
81
|
-
func:
|
|
82
|
-
description: typeof e == "string" ? e : (
|
|
82
|
+
func: n,
|
|
83
|
+
description: typeof e == "string" ? e : (l = e == null ? void 0 : e.description) != null ? l : "",
|
|
83
84
|
locales: typeof e == "object" ? e.locales : void 0
|
|
84
|
-
},
|
|
85
|
-
return this._debouncedFormulaCalculation(),
|
|
85
|
+
}, r = o.registerAsyncFunction(i);
|
|
86
|
+
return this._debouncedFormulaCalculation(), r;
|
|
87
|
+
}
|
|
88
|
+
calculationResultApplied(t) {
|
|
89
|
+
let n = !1, e = !1, o = null;
|
|
90
|
+
return this._commandService.onCommandExecuted((i, r) => {
|
|
91
|
+
i.id !== y.id && i.id !== b.id || (i.id === y.id && (n = !0, o = i.params), i.id === b.id && (r != null && r.applyFormulaCalculationResult) && (e = !0), !(!n || !e) && requestIdleCallback(() => {
|
|
92
|
+
t(o);
|
|
93
|
+
}));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
onCalculationResultApplied() {
|
|
97
|
+
return new Promise((t, n) => {
|
|
98
|
+
let e = !1, o = !1;
|
|
99
|
+
const i = setTimeout(() => {
|
|
100
|
+
c(), n(new Error("Calculation end timeout"));
|
|
101
|
+
}, 6e4), r = setTimeout(() => {
|
|
102
|
+
e || (c(), t());
|
|
103
|
+
}, 500), l = this.calculationProcessing((u) => {
|
|
104
|
+
const { stage: g, totalArrayFormulasToCalculate: f, totalFormulasToCalculate: d } = u;
|
|
105
|
+
if (g === z.START_CALCULATION && f + d === 0) {
|
|
106
|
+
c(), t();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
e || (e = !0, clearTimeout(r));
|
|
110
|
+
}), C = this.calculationResultApplied(() => {
|
|
111
|
+
o || (o = !0, c(), t());
|
|
112
|
+
});
|
|
113
|
+
function c() {
|
|
114
|
+
clearTimeout(i), clearTimeout(r), l.dispose(), C.dispose();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
86
117
|
}
|
|
87
118
|
}
|
|
88
|
-
|
|
119
|
+
T.extend(W);
|
|
89
120
|
class B {
|
|
90
121
|
get CalculationMode() {
|
|
91
|
-
return
|
|
122
|
+
return P;
|
|
92
123
|
}
|
|
93
124
|
}
|
|
94
|
-
|
|
95
|
-
class G extends
|
|
125
|
+
N.extend(B);
|
|
126
|
+
class G extends w {
|
|
96
127
|
getAllFormulaError() {
|
|
97
|
-
const t = [],
|
|
98
|
-
return o.forEach((
|
|
99
|
-
var
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
if (!
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
sheetName:
|
|
107
|
-
row:
|
|
128
|
+
const t = [], n = this._workbook, e = n.getUnitId(), o = n.getSheets(), i = this._injector.get(j).getArrayFormulaCellData();
|
|
129
|
+
return o.forEach((r) => {
|
|
130
|
+
var g;
|
|
131
|
+
const l = r.getName(), C = r.getSheetId(), c = r.getCellMatrix(), u = ((g = i == null ? void 0 : i[e]) == null ? void 0 : g[C]) || {};
|
|
132
|
+
c.forValue((f, d, h) => {
|
|
133
|
+
var F;
|
|
134
|
+
if (!h) return;
|
|
135
|
+
const m = (F = u == null ? void 0 : u[f]) == null ? void 0 : F[d], s = R(h, !!m);
|
|
136
|
+
s && t.push({
|
|
137
|
+
sheetName: l,
|
|
138
|
+
row: f,
|
|
108
139
|
column: d,
|
|
109
|
-
formula:
|
|
110
|
-
errorType:
|
|
140
|
+
formula: h.f || "",
|
|
141
|
+
errorType: s
|
|
111
142
|
});
|
|
112
143
|
});
|
|
113
144
|
}), t;
|
|
114
145
|
}
|
|
115
146
|
}
|
|
116
|
-
|
|
117
|
-
class
|
|
147
|
+
w.extend(G);
|
|
148
|
+
class O extends M {
|
|
118
149
|
getFormulaError() {
|
|
119
|
-
var d,
|
|
120
|
-
const t = [],
|
|
121
|
-
if (!
|
|
122
|
-
const
|
|
123
|
-
for (let
|
|
124
|
-
for (let
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
127
|
-
const
|
|
128
|
-
|
|
150
|
+
var d, h;
|
|
151
|
+
const t = [], n = this._workbook.getUnitId(), e = this._worksheet.getSheetId(), o = this._worksheet.getName(), i = this._workbook.getSheetBySheetId(e);
|
|
152
|
+
if (!i) return t;
|
|
153
|
+
const r = this._injector.get(j).getArrayFormulaCellData(), l = ((d = r == null ? void 0 : r[n]) == null ? void 0 : d[e]) || {}, C = i.getCellMatrix(), { startRow: c, endRow: u, startColumn: g, endColumn: f } = this._range;
|
|
154
|
+
for (let m = c; m <= u; m++)
|
|
155
|
+
for (let s = g; s <= f; s++) {
|
|
156
|
+
const F = C.getValue(m, s);
|
|
157
|
+
if (!F) continue;
|
|
158
|
+
const A = (h = l == null ? void 0 : l[m]) == null ? void 0 : h[s], p = R(F, !!A);
|
|
159
|
+
p && t.push({
|
|
129
160
|
sheetName: o,
|
|
130
|
-
row:
|
|
131
|
-
column:
|
|
132
|
-
formula:
|
|
133
|
-
errorType:
|
|
161
|
+
row: m,
|
|
162
|
+
column: s,
|
|
163
|
+
formula: F.f || "",
|
|
164
|
+
errorType: p
|
|
134
165
|
});
|
|
135
166
|
}
|
|
136
167
|
return t;
|
|
137
168
|
}
|
|
138
169
|
}
|
|
139
|
-
|
|
170
|
+
M.extend(O);
|
package/lib/facade.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { debounce as
|
|
2
|
-
import { FUniver as
|
|
3
|
-
import { SetTriggerFormulaCalculationStartMutation as
|
|
4
|
-
import { IRegisterFunctionService as
|
|
5
|
-
import { FFormula as
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { debounce as v, LifecycleService as E, ILogService as D, IConfigService as L, LifecycleStages as U } from "@univerjs/core";
|
|
2
|
+
import { FUniver as I, FEnum as N } from "@univerjs/core/facade";
|
|
3
|
+
import { SetTriggerFormulaCalculationStartMutation as k, SetFormulaCalculationResultMutation as y, FormulaExecuteStageType as z, FormulaDataModel as j, extractFormulaError as R } from "@univerjs/engine-formula";
|
|
4
|
+
import { IRegisterFunctionService as a, RegisterFunctionService as _, PLUGIN_CONFIG_KEY_BASE as x, CalculationMode as P } from "@univerjs/sheets-formula";
|
|
5
|
+
import { FFormula as T } from "@univerjs/engine-formula/facade";
|
|
6
|
+
import { SetRangeValuesMutation as b } from "@univerjs/sheets";
|
|
7
|
+
import { FWorkbook as w, FRange as M } from "@univerjs/sheets/facade";
|
|
8
|
+
class V extends I {
|
|
8
9
|
/**
|
|
9
10
|
* Initialize the FUniver instance.
|
|
10
11
|
* @ignore
|
|
11
12
|
*/
|
|
12
13
|
_initialize() {
|
|
13
|
-
this._debouncedFormulaCalculation =
|
|
14
|
+
this._debouncedFormulaCalculation = v(() => {
|
|
14
15
|
this._commandService.executeCommand(
|
|
15
|
-
|
|
16
|
+
k.id,
|
|
16
17
|
{
|
|
17
18
|
commands: [],
|
|
18
19
|
forceCalculation: !0
|
|
@@ -24,22 +25,22 @@ class z extends b {
|
|
|
24
25
|
}, 10);
|
|
25
26
|
}
|
|
26
27
|
registerFunction(t) {
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
const e =
|
|
28
|
+
let n = this._injector.get(a);
|
|
29
|
+
n || (this._injector.add([a, { useClass: _ }]), n = this._injector.get(a));
|
|
30
|
+
const e = n.registerFunctions(t);
|
|
30
31
|
return this._debouncedFormulaCalculation(), e;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
class
|
|
34
|
+
I.extend(V);
|
|
35
|
+
class W extends T {
|
|
35
36
|
/**
|
|
36
37
|
* Initialize the FUniver instance.
|
|
37
38
|
* @ignore
|
|
38
39
|
*/
|
|
39
40
|
_initialize() {
|
|
40
|
-
this._debouncedFormulaCalculation =
|
|
41
|
+
this._debouncedFormulaCalculation = v(() => {
|
|
41
42
|
this._commandService.executeCommand(
|
|
42
|
-
|
|
43
|
+
k.id,
|
|
43
44
|
{
|
|
44
45
|
commands: [],
|
|
45
46
|
forceCalculation: !0
|
|
@@ -51,89 +52,119 @@ class T extends w {
|
|
|
51
52
|
}, 10);
|
|
52
53
|
}
|
|
53
54
|
setInitialFormulaComputing(t) {
|
|
54
|
-
const e = this._injector.get(
|
|
55
|
-
e >
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
-
|
|
55
|
+
const e = this._injector.get(E).stage, o = this._injector.get(D), i = this._injector.get(L);
|
|
56
|
+
e > U.Starting && o.warn("[FFormula]", "CalculationMode is called after the Starting lifecycle and will take effect the next time the Univer Sheet is constructed. If you want it to take effect when the Univer Sheet is initialized this time, consider calling it before the Ready lifecycle or using configuration.");
|
|
57
|
+
const r = i.getConfig(x);
|
|
58
|
+
if (!r) {
|
|
59
|
+
i.setConfig(x, { initialFormulaComputing: t });
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
r.initialFormulaComputing = t;
|
|
62
63
|
}
|
|
63
|
-
registerFunction(t,
|
|
64
|
-
var
|
|
65
|
-
let o = this._injector.get(
|
|
66
|
-
o || (this._injector.add([
|
|
67
|
-
const
|
|
64
|
+
registerFunction(t, n, e) {
|
|
65
|
+
var l;
|
|
66
|
+
let o = this._injector.get(a);
|
|
67
|
+
o || (this._injector.add([a, { useClass: _ }]), o = this._injector.get(a));
|
|
68
|
+
const i = {
|
|
68
69
|
name: t,
|
|
69
|
-
func:
|
|
70
|
-
description: typeof e == "string" ? e : (
|
|
70
|
+
func: n,
|
|
71
|
+
description: typeof e == "string" ? e : (l = e == null ? void 0 : e.description) != null ? l : "",
|
|
71
72
|
locales: typeof e == "object" ? e.locales : void 0
|
|
72
|
-
},
|
|
73
|
-
return this._debouncedFormulaCalculation(),
|
|
73
|
+
}, r = o.registerFunction(i);
|
|
74
|
+
return this._debouncedFormulaCalculation(), r;
|
|
74
75
|
}
|
|
75
|
-
registerAsyncFunction(t,
|
|
76
|
-
var
|
|
77
|
-
let o = this._injector.get(
|
|
78
|
-
o || (this._injector.add([
|
|
79
|
-
const
|
|
76
|
+
registerAsyncFunction(t, n, e) {
|
|
77
|
+
var l;
|
|
78
|
+
let o = this._injector.get(a);
|
|
79
|
+
o || (this._injector.add([a, { useClass: _ }]), o = this._injector.get(a));
|
|
80
|
+
const i = {
|
|
80
81
|
name: t,
|
|
81
|
-
func:
|
|
82
|
-
description: typeof e == "string" ? e : (
|
|
82
|
+
func: n,
|
|
83
|
+
description: typeof e == "string" ? e : (l = e == null ? void 0 : e.description) != null ? l : "",
|
|
83
84
|
locales: typeof e == "object" ? e.locales : void 0
|
|
84
|
-
},
|
|
85
|
-
return this._debouncedFormulaCalculation(),
|
|
85
|
+
}, r = o.registerAsyncFunction(i);
|
|
86
|
+
return this._debouncedFormulaCalculation(), r;
|
|
87
|
+
}
|
|
88
|
+
calculationResultApplied(t) {
|
|
89
|
+
let n = !1, e = !1, o = null;
|
|
90
|
+
return this._commandService.onCommandExecuted((i, r) => {
|
|
91
|
+
i.id !== y.id && i.id !== b.id || (i.id === y.id && (n = !0, o = i.params), i.id === b.id && (r != null && r.applyFormulaCalculationResult) && (e = !0), !(!n || !e) && requestIdleCallback(() => {
|
|
92
|
+
t(o);
|
|
93
|
+
}));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
onCalculationResultApplied() {
|
|
97
|
+
return new Promise((t, n) => {
|
|
98
|
+
let e = !1, o = !1;
|
|
99
|
+
const i = setTimeout(() => {
|
|
100
|
+
c(), n(new Error("Calculation end timeout"));
|
|
101
|
+
}, 6e4), r = setTimeout(() => {
|
|
102
|
+
e || (c(), t());
|
|
103
|
+
}, 500), l = this.calculationProcessing((u) => {
|
|
104
|
+
const { stage: g, totalArrayFormulasToCalculate: f, totalFormulasToCalculate: d } = u;
|
|
105
|
+
if (g === z.START_CALCULATION && f + d === 0) {
|
|
106
|
+
c(), t();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
e || (e = !0, clearTimeout(r));
|
|
110
|
+
}), C = this.calculationResultApplied(() => {
|
|
111
|
+
o || (o = !0, c(), t());
|
|
112
|
+
});
|
|
113
|
+
function c() {
|
|
114
|
+
clearTimeout(i), clearTimeout(r), l.dispose(), C.dispose();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
86
117
|
}
|
|
87
118
|
}
|
|
88
|
-
|
|
119
|
+
T.extend(W);
|
|
89
120
|
class B {
|
|
90
121
|
get CalculationMode() {
|
|
91
|
-
return
|
|
122
|
+
return P;
|
|
92
123
|
}
|
|
93
124
|
}
|
|
94
|
-
|
|
95
|
-
class G extends
|
|
125
|
+
N.extend(B);
|
|
126
|
+
class G extends w {
|
|
96
127
|
getAllFormulaError() {
|
|
97
|
-
const t = [],
|
|
98
|
-
return o.forEach((
|
|
99
|
-
var
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
if (!
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
sheetName:
|
|
107
|
-
row:
|
|
128
|
+
const t = [], n = this._workbook, e = n.getUnitId(), o = n.getSheets(), i = this._injector.get(j).getArrayFormulaCellData();
|
|
129
|
+
return o.forEach((r) => {
|
|
130
|
+
var g;
|
|
131
|
+
const l = r.getName(), C = r.getSheetId(), c = r.getCellMatrix(), u = ((g = i == null ? void 0 : i[e]) == null ? void 0 : g[C]) || {};
|
|
132
|
+
c.forValue((f, d, h) => {
|
|
133
|
+
var F;
|
|
134
|
+
if (!h) return;
|
|
135
|
+
const m = (F = u == null ? void 0 : u[f]) == null ? void 0 : F[d], s = R(h, !!m);
|
|
136
|
+
s && t.push({
|
|
137
|
+
sheetName: l,
|
|
138
|
+
row: f,
|
|
108
139
|
column: d,
|
|
109
|
-
formula:
|
|
110
|
-
errorType:
|
|
140
|
+
formula: h.f || "",
|
|
141
|
+
errorType: s
|
|
111
142
|
});
|
|
112
143
|
});
|
|
113
144
|
}), t;
|
|
114
145
|
}
|
|
115
146
|
}
|
|
116
|
-
|
|
117
|
-
class
|
|
147
|
+
w.extend(G);
|
|
148
|
+
class O extends M {
|
|
118
149
|
getFormulaError() {
|
|
119
|
-
var d,
|
|
120
|
-
const t = [],
|
|
121
|
-
if (!
|
|
122
|
-
const
|
|
123
|
-
for (let
|
|
124
|
-
for (let
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
127
|
-
const
|
|
128
|
-
|
|
150
|
+
var d, h;
|
|
151
|
+
const t = [], n = this._workbook.getUnitId(), e = this._worksheet.getSheetId(), o = this._worksheet.getName(), i = this._workbook.getSheetBySheetId(e);
|
|
152
|
+
if (!i) return t;
|
|
153
|
+
const r = this._injector.get(j).getArrayFormulaCellData(), l = ((d = r == null ? void 0 : r[n]) == null ? void 0 : d[e]) || {}, C = i.getCellMatrix(), { startRow: c, endRow: u, startColumn: g, endColumn: f } = this._range;
|
|
154
|
+
for (let m = c; m <= u; m++)
|
|
155
|
+
for (let s = g; s <= f; s++) {
|
|
156
|
+
const F = C.getValue(m, s);
|
|
157
|
+
if (!F) continue;
|
|
158
|
+
const A = (h = l == null ? void 0 : l[m]) == null ? void 0 : h[s], p = R(F, !!A);
|
|
159
|
+
p && t.push({
|
|
129
160
|
sheetName: o,
|
|
130
|
-
row:
|
|
131
|
-
column:
|
|
132
|
-
formula:
|
|
133
|
-
errorType:
|
|
161
|
+
row: m,
|
|
162
|
+
column: s,
|
|
163
|
+
formula: F.f || "",
|
|
164
|
+
errorType: p
|
|
134
165
|
});
|
|
135
166
|
}
|
|
136
167
|
return t;
|
|
137
168
|
}
|
|
138
169
|
}
|
|
139
|
-
|
|
170
|
+
M.extend(O);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IDisposable, ILocales } from '@univerjs/core';
|
|
2
|
-
import { IFunctionInfo } from '@univerjs/engine-formula';
|
|
2
|
+
import { IFunctionInfo, ISetFormulaCalculationResultMutation } from '@univerjs/engine-formula';
|
|
3
3
|
import { CalculationMode, IRegisterAsyncFunction, IRegisterFunction } from '@univerjs/sheets-formula';
|
|
4
4
|
import { FFormula } from '@univerjs/engine-formula/facade';
|
|
5
5
|
/**
|
|
@@ -254,6 +254,59 @@ export interface IFFormulaSheetsMixin {
|
|
|
254
254
|
locales?: ILocales;
|
|
255
255
|
description?: string | IFunctionInfo;
|
|
256
256
|
}): IDisposable;
|
|
257
|
+
/**
|
|
258
|
+
* Listens for the moment when formula-calculation results are applied.
|
|
259
|
+
*
|
|
260
|
+
* This event fires after the engine completes a calculation cycle and
|
|
261
|
+
* dispatches a `SetFormulaCalculationResultMutation`.
|
|
262
|
+
* The callback is invoked during an idle frame to avoid blocking UI updates.
|
|
263
|
+
*
|
|
264
|
+
* @param {Function} callback - A function called with the calculation result payload
|
|
265
|
+
* once the result-application mutation is emitted.
|
|
266
|
+
* @returns {IDisposable} A disposable used to unsubscribe from the event.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* const formulaEngine = univerAPI.getFormula();
|
|
271
|
+
*
|
|
272
|
+
* const dispose = formulaEngine.calculationResultApplied((result) => {
|
|
273
|
+
* console.log('Calculation results applied:', result);
|
|
274
|
+
* });
|
|
275
|
+
*
|
|
276
|
+
* // Later…
|
|
277
|
+
* dispose.dispose();
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
calculationResultApplied(callback: (result: ISetFormulaCalculationResultMutation) => void): IDisposable;
|
|
281
|
+
/**
|
|
282
|
+
* Waits for formula-calculation results to be applied.
|
|
283
|
+
*
|
|
284
|
+
* This method resolves under three conditions:
|
|
285
|
+
* 1. A real calculation runs and the engine emits a "calculation started" signal,
|
|
286
|
+
* followed by a "calculation result applied" signal.
|
|
287
|
+
* 2. No calculation actually starts within 500 ms — the method assumes there is
|
|
288
|
+
* nothing to wait for and resolves automatically.
|
|
289
|
+
* 3. A global 30 s timeout triggers, in which case the promise rejects.
|
|
290
|
+
*
|
|
291
|
+
* The API internally listens to both “calculation in progress” events and
|
|
292
|
+
* “calculation result applied” events, ensuring it behaves correctly whether
|
|
293
|
+
* formulas are recalculated or skipped due to cache/state.
|
|
294
|
+
*
|
|
295
|
+
* @returns {Promise<void>} A promise that resolves when calculation results are applied
|
|
296
|
+
* or when no calculation occurs within the start-detection window.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* const formulaEngine = univerAPI.getFormula();
|
|
301
|
+
*
|
|
302
|
+
* // Wait for formula updates to apply before reading values.
|
|
303
|
+
* await formulaEngine.onCalculationResultApplied();
|
|
304
|
+
*
|
|
305
|
+
* const value = sheet.getRange("C24").getValue();
|
|
306
|
+
* console.log("Updated value:", value);
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
onCalculationResultApplied(): Promise<void>;
|
|
257
310
|
}
|
|
258
311
|
export declare class FFormulaSheetsMixin extends FFormula implements IFFormulaSheetsMixin {
|
|
259
312
|
/**
|
|
@@ -270,6 +323,8 @@ export declare class FFormulaSheetsMixin extends FFormula implements IFFormulaSh
|
|
|
270
323
|
registerFunction(name: string, func: IRegisterFunction, description: string): IDisposable;
|
|
271
324
|
registerAsyncFunction(name: string, func: IRegisterAsyncFunction): IDisposable;
|
|
272
325
|
registerAsyncFunction(name: string, func: IRegisterAsyncFunction, description: string): IDisposable;
|
|
326
|
+
calculationResultApplied(callback: (result: ISetFormulaCalculationResultMutation) => void): IDisposable;
|
|
327
|
+
onCalculationResultApplied(): Promise<void>;
|
|
273
328
|
}
|
|
274
329
|
declare module '@univerjs/engine-formula/facade' {
|
|
275
330
|
interface FFormula extends IFFormulaSheetsMixin {
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,f){typeof exports=="object"&&typeof module<"u"?f(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula/facade"),require("@univerjs/sheets"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/core/facade","@univerjs/engine-formula","@univerjs/sheets-formula","@univerjs/engine-formula/facade","@univerjs/sheets","@univerjs/sheets/facade"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c.UniverCore,c.UniverCoreFacade,c.UniverEngineFormula,c.UniverSheetsFormula,c.UniverEngineFormulaFacade,c.UniverSheets,c.UniverSheetsFacade))})(this,(function(c,f,u,s,I,y,j){"use strict";class p extends f.FUniver{_initialize(){this._debouncedFormulaCalculation=c.debounce(()=>{this._commandService.executeCommand(u.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(t){let o=this._injector.get(s.IRegisterFunctionService);o||(this._injector.add([s.IRegisterFunctionService,{useClass:s.RegisterFunctionService}]),o=this._injector.get(s.IRegisterFunctionService));const e=o.registerFunctions(t);return this._debouncedFormulaCalculation(),e}}f.FUniver.extend(p);class k extends I.FFormula{_initialize(){this._debouncedFormulaCalculation=c.debounce(()=>{this._commandService.executeCommand(u.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(t){const e=this._injector.get(c.LifecycleService).stage,n=this._injector.get(c.ILogService),i=this._injector.get(c.IConfigService);e>c.LifecycleStages.Starting&&n.warn("[FFormula]","CalculationMode is called after the Starting lifecycle and will take effect the next time the Univer Sheet is constructed. If you want it to take effect when the Univer Sheet is initialized this time, consider calling it before the Ready lifecycle or using configuration.");const r=i.getConfig(s.PLUGIN_CONFIG_KEY_BASE);if(!r){i.setConfig(s.PLUGIN_CONFIG_KEY_BASE,{initialFormulaComputing:t});return}r.initialFormulaComputing=t}registerFunction(t,o,e){var a;let n=this._injector.get(s.IRegisterFunctionService);n||(this._injector.add([s.IRegisterFunctionService,{useClass:s.RegisterFunctionService}]),n=this._injector.get(s.IRegisterFunctionService));const i={name:t,func:o,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},r=n.registerFunction(i);return this._debouncedFormulaCalculation(),r}registerAsyncFunction(t,o,e){var a;let n=this._injector.get(s.IRegisterFunctionService);n||(this._injector.add([s.IRegisterFunctionService,{useClass:s.RegisterFunctionService}]),n=this._injector.get(s.IRegisterFunctionService));const i={name:t,func:o,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},r=n.registerAsyncFunction(i);return this._debouncedFormulaCalculation(),r}calculationResultApplied(t){let o=!1,e=!1,n=null;return this._commandService.onCommandExecuted((i,r)=>{i.id!==u.SetFormulaCalculationResultMutation.id&&i.id!==y.SetRangeValuesMutation.id||(i.id===u.SetFormulaCalculationResultMutation.id&&(o=!0,n=i.params),i.id===y.SetRangeValuesMutation.id&&(r!=null&&r.applyFormulaCalculationResult)&&(e=!0),!(!o||!e)&&requestIdleCallback(()=>{t(n)}))})}onCalculationResultApplied(){return new Promise((t,o)=>{let e=!1,n=!1;const i=setTimeout(()=>{l(),o(new Error("Calculation end timeout"))},6e4),r=setTimeout(()=>{e||(l(),t())},500),a=this.calculationProcessing(g=>{const{stage:h,totalArrayFormulasToCalculate:S,totalFormulasToCalculate:m}=g;if(h===u.FormulaExecuteStageType.START_CALCULATION&&S+m===0){l(),t();return}e||(e=!0,clearTimeout(r))}),_=this.calculationResultApplied(()=>{n||(n=!0,l(),t())});function l(){clearTimeout(i),clearTimeout(r),a.dispose(),_.dispose()}})}}I.FFormula.extend(k);class b{get CalculationMode(){return s.CalculationMode}}f.FEnum.extend(b);class E extends j.FWorkbook{getAllFormulaError(){const t=[],o=this._workbook,e=o.getUnitId(),n=o.getSheets(),i=this._injector.get(u.FormulaDataModel).getArrayFormulaCellData();return n.forEach(r=>{var h;const a=r.getName(),_=r.getSheetId(),l=r.getCellMatrix(),g=((h=i==null?void 0:i[e])==null?void 0:h[_])||{};l.forValue((S,m,v)=>{var C;if(!v)return;const F=(C=g==null?void 0:g[S])==null?void 0:C[m],d=u.extractFormulaError(v,!!F);d&&t.push({sheetName:a,row:S,column:m,formula:v.f||"",errorType:d})})}),t}}j.FWorkbook.extend(E);class M extends j.FRange{getFormulaError(){var m,v;const t=[],o=this._workbook.getUnitId(),e=this._worksheet.getSheetId(),n=this._worksheet.getName(),i=this._workbook.getSheetBySheetId(e);if(!i)return t;const r=this._injector.get(u.FormulaDataModel).getArrayFormulaCellData(),a=((m=r==null?void 0:r[o])==null?void 0:m[e])||{},_=i.getCellMatrix(),{startRow:l,endRow:g,startColumn:h,endColumn:S}=this._range;for(let F=l;F<=g;F++)for(let d=h;d<=S;d++){const C=_.getValue(F,d);if(!C)continue;const T=(v=a==null?void 0:a[F])==null?void 0:v[d],x=u.extractFormulaError(C,!!T);x&&t.push({sheetName:n,row:F,column:d,formula:C.f||"",errorType:x})}return t}}j.FRange.extend(M)}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsFormulaSkSK=o())})(this,(function(){"use strict";return{formula:{progress:{analyzing:"Analyzovanie",calculating:"Výpočet","array-analysis":"Analýza poľa","array-calculation":"Výpočet poľa",done:"Hotovo"}}}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-formula",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -62,19 +62,19 @@
|
|
|
62
62
|
"rxjs": ">=7.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/sheets": "0.15.
|
|
67
|
-
"@univerjs/core": "0.15.
|
|
68
|
-
"@univerjs/
|
|
65
|
+
"@univerjs/engine-formula": "0.15.4",
|
|
66
|
+
"@univerjs/sheets": "0.15.4",
|
|
67
|
+
"@univerjs/core": "0.15.4",
|
|
68
|
+
"@univerjs/rpc": "0.15.4"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"rxjs": "^7.8.2",
|
|
72
72
|
"typescript": "^5.9.3",
|
|
73
73
|
"vite": "^7.3.1",
|
|
74
|
-
"vitest": "^4.0.
|
|
75
|
-
"@univerjs-infra/shared": "0.15.
|
|
76
|
-
"@univerjs/
|
|
77
|
-
"@univerjs/
|
|
74
|
+
"vitest": "^4.0.18",
|
|
75
|
+
"@univerjs-infra/shared": "0.15.4",
|
|
76
|
+
"@univerjs/docs": "0.15.4",
|
|
77
|
+
"@univerjs/engine-render": "0.15.4"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"test": "vitest run",
|