@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.
- package/lib/cjs/facade.js +252 -1
- package/lib/cjs/index.js +16484 -1
- package/lib/cjs/locale/ca-ES.js +12 -1
- package/lib/cjs/locale/en-US.js +27 -1
- package/lib/cjs/locale/es-ES.js +12 -1
- package/lib/cjs/locale/fa-IR.js +12 -1
- package/lib/cjs/locale/fr-FR.js +12 -1
- package/lib/cjs/locale/ja-JP.js +12 -1
- package/lib/cjs/locale/ko-KR.js +12 -1
- package/lib/cjs/locale/ru-RU.js +12 -1
- package/lib/cjs/locale/sk-SK.js +12 -1
- package/lib/cjs/locale/vi-VN.js +12 -1
- package/lib/cjs/locale/zh-CN.js +12 -1
- package/lib/cjs/locale/zh-TW.js +12 -1
- package/lib/es/facade.js +253 -1
- package/lib/es/index.js +16410 -1
- package/lib/es/locale/ca-ES.js +11 -1
- package/lib/es/locale/en-US.js +26 -1
- package/lib/es/locale/es-ES.js +11 -1
- package/lib/es/locale/fa-IR.js +11 -1
- package/lib/es/locale/fr-FR.js +11 -1
- package/lib/es/locale/ja-JP.js +11 -1
- package/lib/es/locale/ko-KR.js +11 -1
- package/lib/es/locale/ru-RU.js +11 -1
- package/lib/es/locale/sk-SK.js +11 -1
- package/lib/es/locale/vi-VN.js +11 -1
- package/lib/es/locale/zh-CN.js +11 -1
- package/lib/es/locale/zh-TW.js +11 -1
- package/lib/facade.js +253 -1
- package/lib/index.js +16410 -1
- package/lib/locale/ca-ES.js +11 -1
- package/lib/locale/en-US.js +26 -1
- package/lib/locale/es-ES.js +11 -1
- package/lib/locale/fa-IR.js +11 -1
- package/lib/locale/fr-FR.js +11 -1
- package/lib/locale/ja-JP.js +11 -1
- package/lib/locale/ko-KR.js +11 -1
- package/lib/locale/ru-RU.js +11 -1
- package/lib/locale/sk-SK.js +11 -1
- package/lib/locale/vi-VN.js +11 -1
- package/lib/locale/zh-CN.js +11 -1
- package/lib/locale/zh-TW.js +11 -1
- package/lib/types/controllers/defined-name.controller.d.ts +2 -2
- package/lib/types/services/description.service.d.ts +7 -18
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/LICENSE +0 -176
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1,252 @@
|
|
|
1
|
-
let
|
|
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
|