@univerjs/sheets-formula 0.20.1 → 0.21.0-insiders.20260424-262d69f

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 (47) hide show
  1. package/lib/cjs/facade.js +252 -1
  2. package/lib/cjs/index.js +16484 -1
  3. package/lib/cjs/locale/ca-ES.js +12 -1
  4. package/lib/cjs/locale/en-US.js +27 -1
  5. package/lib/cjs/locale/es-ES.js +12 -1
  6. package/lib/cjs/locale/fa-IR.js +12 -1
  7. package/lib/cjs/locale/fr-FR.js +12 -1
  8. package/lib/cjs/locale/ja-JP.js +12 -1
  9. package/lib/cjs/locale/ko-KR.js +12 -1
  10. package/lib/cjs/locale/ru-RU.js +12 -1
  11. package/lib/cjs/locale/sk-SK.js +12 -1
  12. package/lib/cjs/locale/vi-VN.js +12 -1
  13. package/lib/cjs/locale/zh-CN.js +12 -1
  14. package/lib/cjs/locale/zh-TW.js +12 -1
  15. package/lib/es/facade.js +253 -1
  16. package/lib/es/index.js +16410 -1
  17. package/lib/es/locale/ca-ES.js +11 -1
  18. package/lib/es/locale/en-US.js +26 -1
  19. package/lib/es/locale/es-ES.js +11 -1
  20. package/lib/es/locale/fa-IR.js +11 -1
  21. package/lib/es/locale/fr-FR.js +11 -1
  22. package/lib/es/locale/ja-JP.js +11 -1
  23. package/lib/es/locale/ko-KR.js +11 -1
  24. package/lib/es/locale/ru-RU.js +11 -1
  25. package/lib/es/locale/sk-SK.js +11 -1
  26. package/lib/es/locale/vi-VN.js +11 -1
  27. package/lib/es/locale/zh-CN.js +11 -1
  28. package/lib/es/locale/zh-TW.js +11 -1
  29. package/lib/facade.js +253 -1
  30. package/lib/index.js +16410 -1
  31. package/lib/locale/ca-ES.js +11 -1
  32. package/lib/locale/en-US.js +26 -1
  33. package/lib/locale/es-ES.js +11 -1
  34. package/lib/locale/fa-IR.js +11 -1
  35. package/lib/locale/fr-FR.js +11 -1
  36. package/lib/locale/ja-JP.js +11 -1
  37. package/lib/locale/ko-KR.js +11 -1
  38. package/lib/locale/ru-RU.js +11 -1
  39. package/lib/locale/sk-SK.js +11 -1
  40. package/lib/locale/vi-VN.js +11 -1
  41. package/lib/locale/zh-CN.js +11 -1
  42. package/lib/locale/zh-TW.js +11 -1
  43. package/lib/types/controllers/defined-name.controller.d.ts +2 -2
  44. package/lib/types/services/description.service.d.ts +7 -18
  45. package/lib/umd/index.js +1 -1
  46. package/package.json +9 -9
  47. package/LICENSE +0 -176
package/lib/cjs/facade.js CHANGED
@@ -1 +1,252 @@
1
- let e=require(`@univerjs/core`),t=require(`@univerjs/core/facade`),n=require(`@univerjs/engine-formula`),r=require(`@univerjs/sheets-formula`),i=require(`@univerjs/engine-formula/facade`),a=require(`@univerjs/sheets`),o=require(`@univerjs/sheets/facade`);var s=class extends t.FUniver{_initialize(){this._debouncedFormulaCalculation=(0,e.debounce)(()=>{this._commandService.executeCommand(n.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(e){let t=this._injector.get(r.IRegisterFunctionService);t||(this._injector.add([r.IRegisterFunctionService,{useClass:r.RegisterFunctionService}]),t=this._injector.get(r.IRegisterFunctionService));let n=t.registerFunctions(e);return this._debouncedFormulaCalculation(),n}};t.FUniver.extend(s);var c=class extends i.FFormula{_initialize(){this._debouncedFormulaCalculation=(0,e.debounce)(()=>{this._commandService.executeCommand(n.SetTriggerFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(t){let n=this._injector.get(e.LifecycleService).stage,i=this._injector.get(e.ILogService),a=this._injector.get(e.IConfigService);n>e.LifecycleStages.Starting&&i.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.`);let o=a.getConfig(r.PLUGIN_CONFIG_KEY_BASE);if(!o){a.setConfig(r.PLUGIN_CONFIG_KEY_BASE,{initialFormulaComputing:t});return}o.initialFormulaComputing=t}registerFunction(e,t,n){var i;let a=this._injector.get(r.IRegisterFunctionService);a||(this._injector.add([r.IRegisterFunctionService,{useClass:r.RegisterFunctionService}]),a=this._injector.get(r.IRegisterFunctionService));let o={name:e,func:t,description:typeof n==`string`?n:(i=n==null?void 0:n.description)==null?``:i,locales:typeof n==`object`?n.locales:void 0},s=a.registerFunction(o);return this._debouncedFormulaCalculation(),s}registerAsyncFunction(e,t,n){var i;let a=this._injector.get(r.IRegisterFunctionService);a||(this._injector.add([r.IRegisterFunctionService,{useClass:r.RegisterFunctionService}]),a=this._injector.get(r.IRegisterFunctionService));let o={name:e,func:t,description:typeof n==`string`?n:(i=n==null?void 0:n.description)==null?``:i,locales:typeof n==`object`?n.locales:void 0},s=a.registerAsyncFunction(o);return this._debouncedFormulaCalculation(),s}calculationResultApplied(e){let t=!1,r=!1,i=null;return this._commandService.onCommandExecuted((o,s)=>{o.id!==n.SetFormulaCalculationResultMutation.id&&o.id!==a.SetRangeValuesMutation.id||(o.id===n.SetFormulaCalculationResultMutation.id&&(t=!0,i=o.params),o.id===a.SetRangeValuesMutation.id&&s!=null&&s.applyFormulaCalculationResult&&(r=!0),!(!t||!r)&&requestIdleCallback(()=>{e(i)}))})}onCalculationResultApplied(){return new Promise((e,t)=>{let r=!1,i=!1,a=setTimeout(()=>{l(),t(Error(`Calculation end timeout`))},6e4),o=setTimeout(()=>{r||(l(),e())},500),s=this.calculationProcessing(t=>{let{stage:i,totalArrayFormulasToCalculate:a,totalFormulasToCalculate:s}=t;if(i===n.FormulaExecuteStageType.START_CALCULATION&&a+s===0){l(),e();return}r||(r=!0,clearTimeout(o))}),c=this.calculationResultApplied(()=>{i||(i=!0,l(),e())});function l(){clearTimeout(a),clearTimeout(o),s.dispose(),c.dispose()}})}};i.FFormula.extend(c);var l=class extends t.FEnum{get CalculationMode(){return r.CalculationMode}};t.FEnum.extend(l);var u=class extends o.FWorkbook{getAllFormulaError(){let e=[],t=this._workbook,r=t.getUnitId(),i=t.getSheets(),a=this._injector.get(n.FormulaDataModel).getArrayFormulaCellData();return i.forEach(t=>{var i;let o=t.getName(),s=t.getSheetId(),c=t.getCellMatrix(),l=(a==null||(i=a[r])==null?void 0:i[s])||{};c.forValue((t,r,i)=>{var a;if(!i)return;let s=(0,n.extractFormulaError)(i,!!(!(l==null||(a=l[t])==null)&&a[r]));s&&e.push({sheetName:o,row:t,column:r,formula:i.f||``,errorType:s})})}),e}};o.FWorkbook.extend(u);var d=class extends o.FRange{getFormulaError(){var e;let t=[],r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=this._worksheet.getName(),o=this._workbook.getSheetBySheetId(i);if(!o)return t;let s=this._injector.get(n.FormulaDataModel).getArrayFormulaCellData(),c=(s==null||(e=s[r])==null?void 0:e[i])||{},l=o.getCellMatrix(),{startRow:u,endRow:d,startColumn:f,endColumn:p}=this._range;for(let e=u;e<=d;e++)for(let r=f;r<=p;r++){var m;let i=l.getValue(e,r);if(!i)continue;let o=(0,n.extractFormulaError)(i,!!(!(c==null||(m=c[e])==null)&&m[r]));o&&t.push({sheetName:a,row:e,column:r,formula:i.f||``,errorType:o})}return t}};o.FRange.extend(d);
1
+ let _univerjs_core = require("@univerjs/core");
2
+ let _univerjs_core_facade = require("@univerjs/core/facade");
3
+ let _univerjs_engine_formula = require("@univerjs/engine-formula");
4
+ let _univerjs_sheets_formula = require("@univerjs/sheets-formula");
5
+ let _univerjs_engine_formula_facade = require("@univerjs/engine-formula/facade");
6
+ let _univerjs_sheets = require("@univerjs/sheets");
7
+ let _univerjs_sheets_facade = require("@univerjs/sheets/facade");
8
+
9
+ //#region src/facade/f-univer.ts
10
+ /**
11
+ * @ignore
12
+ */
13
+ var FUniverSheetsFormulaMixin = class extends _univerjs_core_facade.FUniver {
14
+ /**
15
+ * Initialize the FUniver instance.
16
+ * @ignore
17
+ */
18
+ _initialize() {
19
+ this._debouncedFormulaCalculation = (0, _univerjs_core.debounce)(() => {
20
+ this._commandService.executeCommand(_univerjs_engine_formula.SetTriggerFormulaCalculationStartMutation.id, {
21
+ commands: [],
22
+ forceCalculation: true
23
+ }, { onlyLocal: true });
24
+ }, 10);
25
+ }
26
+ registerFunction(config) {
27
+ let registerFunctionService = this._injector.get(_univerjs_sheets_formula.IRegisterFunctionService);
28
+ if (!registerFunctionService) {
29
+ this._injector.add([_univerjs_sheets_formula.IRegisterFunctionService, { useClass: _univerjs_sheets_formula.RegisterFunctionService }]);
30
+ registerFunctionService = this._injector.get(_univerjs_sheets_formula.IRegisterFunctionService);
31
+ }
32
+ const functionsDisposable = registerFunctionService.registerFunctions(config);
33
+ this._debouncedFormulaCalculation();
34
+ return functionsDisposable;
35
+ }
36
+ };
37
+ _univerjs_core_facade.FUniver.extend(FUniverSheetsFormulaMixin);
38
+
39
+ //#endregion
40
+ //#region src/facade/f-formula.ts
41
+ var FFormulaSheetsMixin = class extends _univerjs_engine_formula_facade.FFormula {
42
+ /**
43
+ * Initialize the FUniver instance.
44
+ * @ignore
45
+ */
46
+ _initialize() {
47
+ this._debouncedFormulaCalculation = (0, _univerjs_core.debounce)(() => {
48
+ this._commandService.executeCommand(_univerjs_engine_formula.SetTriggerFormulaCalculationStartMutation.id, {
49
+ commands: [],
50
+ forceCalculation: true
51
+ }, { onlyLocal: true });
52
+ }, 10);
53
+ }
54
+ setInitialFormulaComputing(calculationMode) {
55
+ const lifecycleStage = this._injector.get(_univerjs_core.LifecycleService).stage;
56
+ const logService = this._injector.get(_univerjs_core.ILogService);
57
+ const configService = this._injector.get(_univerjs_core.IConfigService);
58
+ if (lifecycleStage > _univerjs_core.LifecycleStages.Starting) logService.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.");
59
+ const config = configService.getConfig(_univerjs_sheets_formula.PLUGIN_CONFIG_KEY_BASE);
60
+ if (!config) {
61
+ configService.setConfig(_univerjs_sheets_formula.PLUGIN_CONFIG_KEY_BASE, { initialFormulaComputing: calculationMode });
62
+ return;
63
+ }
64
+ config.initialFormulaComputing = calculationMode;
65
+ }
66
+ registerFunction(name, func, options) {
67
+ var _options$description;
68
+ let registerFunctionService = this._injector.get(_univerjs_sheets_formula.IRegisterFunctionService);
69
+ if (!registerFunctionService) {
70
+ this._injector.add([_univerjs_sheets_formula.IRegisterFunctionService, { useClass: _univerjs_sheets_formula.RegisterFunctionService }]);
71
+ registerFunctionService = this._injector.get(_univerjs_sheets_formula.IRegisterFunctionService);
72
+ }
73
+ const params = {
74
+ name,
75
+ func,
76
+ description: typeof options === "string" ? options : (_options$description = options === null || options === void 0 ? void 0 : options.description) !== null && _options$description !== void 0 ? _options$description : "",
77
+ locales: typeof options === "object" ? options.locales : void 0
78
+ };
79
+ const functionsDisposable = registerFunctionService.registerFunction(params);
80
+ this._debouncedFormulaCalculation();
81
+ return functionsDisposable;
82
+ }
83
+ registerAsyncFunction(name, func, options) {
84
+ var _options$description2;
85
+ let registerFunctionService = this._injector.get(_univerjs_sheets_formula.IRegisterFunctionService);
86
+ if (!registerFunctionService) {
87
+ this._injector.add([_univerjs_sheets_formula.IRegisterFunctionService, { useClass: _univerjs_sheets_formula.RegisterFunctionService }]);
88
+ registerFunctionService = this._injector.get(_univerjs_sheets_formula.IRegisterFunctionService);
89
+ }
90
+ const params = {
91
+ name,
92
+ func,
93
+ description: typeof options === "string" ? options : (_options$description2 = options === null || options === void 0 ? void 0 : options.description) !== null && _options$description2 !== void 0 ? _options$description2 : "",
94
+ locales: typeof options === "object" ? options.locales : void 0
95
+ };
96
+ const functionsDisposable = registerFunctionService.registerAsyncFunction(params);
97
+ this._debouncedFormulaCalculation();
98
+ return functionsDisposable;
99
+ }
100
+ calculationResultApplied(callback) {
101
+ let setFormulaCalculationResult = false;
102
+ let applyFormulaCalculationResult = false;
103
+ let result = null;
104
+ return this._commandService.onCommandExecuted((command, options) => {
105
+ if (command.id !== _univerjs_engine_formula.SetFormulaCalculationResultMutation.id && command.id !== _univerjs_sheets.SetRangeValuesMutation.id) return;
106
+ if (command.id === _univerjs_engine_formula.SetFormulaCalculationResultMutation.id) {
107
+ setFormulaCalculationResult = true;
108
+ result = command.params;
109
+ }
110
+ if (command.id === _univerjs_sheets.SetRangeValuesMutation.id && (options === null || options === void 0 ? void 0 : options.applyFormulaCalculationResult)) applyFormulaCalculationResult = true;
111
+ if (!setFormulaCalculationResult || !applyFormulaCalculationResult) return;
112
+ requestIdleCallback(() => {
113
+ callback(result);
114
+ });
115
+ });
116
+ }
117
+ onCalculationResultApplied() {
118
+ return new Promise((resolve, reject) => {
119
+ let started = false;
120
+ let finished = false;
121
+ const mainTimer = setTimeout(() => {
122
+ cleanup();
123
+ reject(/* @__PURE__ */ new Error("Calculation end timeout"));
124
+ }, 6e4);
125
+ const startWatchdog = setTimeout(() => {
126
+ if (!started) {
127
+ cleanup();
128
+ resolve();
129
+ }
130
+ }, 500);
131
+ const processingDisposable = this.calculationProcessing((stageInfo) => {
132
+ const { stage, totalArrayFormulasToCalculate, totalFormulasToCalculate } = stageInfo;
133
+ if (stage === _univerjs_engine_formula.FormulaExecuteStageType.START_CALCULATION && totalArrayFormulasToCalculate + totalFormulasToCalculate === 0) {
134
+ cleanup();
135
+ resolve();
136
+ return;
137
+ }
138
+ if (started) return;
139
+ started = true;
140
+ clearTimeout(startWatchdog);
141
+ });
142
+ const endDisposable = this.calculationResultApplied(() => {
143
+ if (finished) return;
144
+ finished = true;
145
+ cleanup();
146
+ resolve();
147
+ });
148
+ function cleanup() {
149
+ clearTimeout(mainTimer);
150
+ clearTimeout(startWatchdog);
151
+ processingDisposable.dispose();
152
+ endDisposable.dispose();
153
+ }
154
+ });
155
+ }
156
+ };
157
+ _univerjs_engine_formula_facade.FFormula.extend(FFormulaSheetsMixin);
158
+
159
+ //#endregion
160
+ //#region src/facade/f-enum.ts
161
+ /**
162
+ * Copyright 2023-present DreamNum Co., Ltd.
163
+ *
164
+ * Licensed under the Apache License, Version 2.0 (the "License");
165
+ * you may not use this file except in compliance with the License.
166
+ * You may obtain a copy of the License at
167
+ *
168
+ * http://www.apache.org/licenses/LICENSE-2.0
169
+ *
170
+ * Unless required by applicable law or agreed to in writing, software
171
+ * distributed under the License is distributed on an "AS IS" BASIS,
172
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
173
+ * See the License for the specific language governing permissions and
174
+ * limitations under the License.
175
+ */
176
+ var FSheetsFormulaEnumMixin = class extends _univerjs_core_facade.FEnum {
177
+ get CalculationMode() {
178
+ return _univerjs_sheets_formula.CalculationMode;
179
+ }
180
+ };
181
+ _univerjs_core_facade.FEnum.extend(FSheetsFormulaEnumMixin);
182
+
183
+ //#endregion
184
+ //#region src/facade/f-workbook.ts
185
+ var FWorkbookEngineFormulaMixin = class extends _univerjs_sheets_facade.FWorkbook {
186
+ getAllFormulaError() {
187
+ const errors = [];
188
+ const workbook = this._workbook;
189
+ const unitId = workbook.getUnitId();
190
+ const worksheets = workbook.getSheets();
191
+ const arrayFormula = this._injector.get(_univerjs_engine_formula.FormulaDataModel).getArrayFormulaCellData();
192
+ worksheets.forEach((worksheet) => {
193
+ var _arrayFormula$unitId;
194
+ const sheetName = worksheet.getName();
195
+ const sheetId = worksheet.getSheetId();
196
+ const cellMatrix = worksheet.getCellMatrix();
197
+ const arrayFormulaSheet = (arrayFormula === null || arrayFormula === void 0 || (_arrayFormula$unitId = arrayFormula[unitId]) === null || _arrayFormula$unitId === void 0 ? void 0 : _arrayFormula$unitId[sheetId]) || {};
198
+ cellMatrix.forValue((row, column, cell) => {
199
+ var _arrayFormulaSheet$ro;
200
+ if (!cell) return;
201
+ const errorType = (0, _univerjs_engine_formula.extractFormulaError)(cell, !!(arrayFormulaSheet === null || arrayFormulaSheet === void 0 || (_arrayFormulaSheet$ro = arrayFormulaSheet[row]) === null || _arrayFormulaSheet$ro === void 0 ? void 0 : _arrayFormulaSheet$ro[column]));
202
+ if (errorType) errors.push({
203
+ sheetName,
204
+ row,
205
+ column,
206
+ formula: cell.f || "",
207
+ errorType
208
+ });
209
+ });
210
+ });
211
+ return errors;
212
+ }
213
+ };
214
+ _univerjs_sheets_facade.FWorkbook.extend(FWorkbookEngineFormulaMixin);
215
+
216
+ //#endregion
217
+ //#region src/facade/f-range.ts
218
+ /**
219
+ * @ignore
220
+ */
221
+ var FRangeEngineFormulaMixin = class extends _univerjs_sheets_facade.FRange {
222
+ getFormulaError() {
223
+ var _arrayFormula$unitId;
224
+ const errors = [];
225
+ const unitId = this._workbook.getUnitId();
226
+ const sheetId = this._worksheet.getSheetId();
227
+ const sheetName = this._worksheet.getName();
228
+ const worksheet = this._workbook.getSheetBySheetId(sheetId);
229
+ if (!worksheet) return errors;
230
+ const arrayFormula = this._injector.get(_univerjs_engine_formula.FormulaDataModel).getArrayFormulaCellData();
231
+ const arrayFormulaSheet = (arrayFormula === null || arrayFormula === void 0 || (_arrayFormula$unitId = arrayFormula[unitId]) === null || _arrayFormula$unitId === void 0 ? void 0 : _arrayFormula$unitId[sheetId]) || {};
232
+ const cellMatrix = worksheet.getCellMatrix();
233
+ const { startRow, endRow, startColumn, endColumn } = this._range;
234
+ for (let row = startRow; row <= endRow; row++) for (let column = startColumn; column <= endColumn; column++) {
235
+ var _arrayFormulaSheet$ro;
236
+ const cell = cellMatrix.getValue(row, column);
237
+ if (!cell) continue;
238
+ const errorType = (0, _univerjs_engine_formula.extractFormulaError)(cell, !!(arrayFormulaSheet === null || arrayFormulaSheet === void 0 || (_arrayFormulaSheet$ro = arrayFormulaSheet[row]) === null || _arrayFormulaSheet$ro === void 0 ? void 0 : _arrayFormulaSheet$ro[column]));
239
+ if (errorType) errors.push({
240
+ sheetName,
241
+ row,
242
+ column,
243
+ formula: cell.f || "",
244
+ errorType
245
+ });
246
+ }
247
+ return errors;
248
+ }
249
+ };
250
+ _univerjs_sheets_facade.FRange.extend(FRangeEngineFormulaMixin);
251
+
252
+ //#endregion