@univerjs/sheets-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/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("@univerjs/core"),
|
|
1
|
+
"use strict";const n=require("@univerjs/core"),u=require("@univerjs/engine-formula"),i=require("@univerjs/sheets-formula"),l=require("@univerjs/engine-formula/facade");class d extends n.FUniver{_initialize(){this._debouncedFormulaCalculation=n.debounce(()=>{this._commandService.executeCommand(u.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(r){let c=this._injector.get(i.IRegisterFunctionService);c||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),c=this._injector.get(i.IRegisterFunctionService));const e=c.registerFunctions(r);return this._debouncedFormulaCalculation(),e}}n.FUniver.extend(d);class F extends l.FFormula{_initialize(){this._debouncedFormulaCalculation=n.debounce(()=>{this._commandService.executeCommand(u.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(r){const e=this._injector.get(n.LifecycleService).stage,t=this._injector.get(n.ILogService),s=this._injector.get(n.IConfigService);e>n.LifecycleStages.Starting&&t.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 o=s.getConfig(i.PLUGIN_CONFIG_KEY_BASE);o&&(o.initialFormulaComputing=r)}registerFunction(r,c,e){var a;let t=this._injector.get(i.IRegisterFunctionService);t||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),t=this._injector.get(i.IRegisterFunctionService));const s={name:r,func:c,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},o=t.registerFunction(s);return this._debouncedFormulaCalculation(),o}registerAsyncFunction(r,c,e){var a;let t=this._injector.get(i.IRegisterFunctionService);t||(this._injector.add([i.IRegisterFunctionService,{useClass:i.RegisterFunctionService}]),t=this._injector.get(i.IRegisterFunctionService));const s={name:r,func:c,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},o=t.registerAsyncFunction(s);return this._debouncedFormulaCalculation(),o}}l.FFormula.extend(F);
|
package/lib/es/facade.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { FUniver as s, debounce as u, LifecycleService as m, ILogService as h, IConfigService as F, LifecycleStages as S } from "@univerjs/core";
|
|
2
|
-
import { SetFormulaCalculationStartMutation as d
|
|
2
|
+
import { SetFormulaCalculationStartMutation as d } from "@univerjs/engine-formula";
|
|
3
3
|
import { IRegisterFunctionService as i, RegisterFunctionService as l, PLUGIN_CONFIG_KEY_BASE as _ } from "@univerjs/sheets-formula";
|
|
4
|
-
|
|
4
|
+
import { FFormula as f } from "@univerjs/engine-formula/facade";
|
|
5
|
+
class C extends s {
|
|
5
6
|
/**
|
|
6
7
|
* Initialize the FUniver instance.
|
|
7
|
-
*
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
10
|
_initialize() {
|
|
@@ -28,11 +28,10 @@ class v extends s {
|
|
|
28
28
|
return this._debouncedFormulaCalculation(), e;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
s.extend(
|
|
32
|
-
class
|
|
31
|
+
s.extend(C);
|
|
32
|
+
class v extends f {
|
|
33
33
|
/**
|
|
34
34
|
* Initialize the FUniver instance.
|
|
35
|
-
*
|
|
36
35
|
* @private
|
|
37
36
|
*/
|
|
38
37
|
_initialize() {
|
|
@@ -80,4 +79,4 @@ class C extends g {
|
|
|
80
79
|
return this._debouncedFormulaCalculation(), r;
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
|
-
|
|
82
|
+
f.extend(v);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IDisposable, ILocales } from '@univerjs/core';
|
|
2
|
-
import { IFunctionInfo
|
|
2
|
+
import { IFunctionInfo } from '@univerjs/engine-formula';
|
|
3
3
|
import { CalculationMode, IRegisterAsyncFunction, IRegisterFunction } from '@univerjs/sheets-formula';
|
|
4
|
+
import { FFormula } from '@univerjs/engine-formula/facade';
|
|
4
5
|
export interface IFFormulaSheetsMixin {
|
|
5
6
|
/**
|
|
6
7
|
* Update the calculation mode of the formula.
|
|
@@ -10,7 +11,6 @@ export interface IFFormulaSheetsMixin {
|
|
|
10
11
|
setInitialFormulaComputing(calculationMode: CalculationMode): void;
|
|
11
12
|
/**
|
|
12
13
|
* Register a custom synchronous formula function.
|
|
13
|
-
*
|
|
14
14
|
* @param name - The name of the function to register. This will be used in formulas (e.g., =MYFUNC())
|
|
15
15
|
* @param func - The implementation of the function
|
|
16
16
|
* @param description - A string describing the function's purpose and usage
|
|
@@ -37,16 +37,38 @@ export interface IFFormulaSheetsMixin {
|
|
|
37
37
|
* univerAPI.getActiveWorkbook().getActiveSheet().getRange('A2').setValue({ f: '=DISCOUNT(A1, 20)' });
|
|
38
38
|
* // A2 will display: 80
|
|
39
39
|
* ```
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Registered formulas support lambda functions
|
|
43
|
+
* univerAPI.getFormula().registerFunction('CUSTOMSUM', (...variants) => {
|
|
44
|
+
* let sum = 0;
|
|
45
|
+
*
|
|
46
|
+
* const last = variants[variants.length - 1];
|
|
47
|
+
* if (last.isLambda && last.isLambda()) {
|
|
48
|
+
* variants.pop();
|
|
49
|
+
*
|
|
50
|
+
* const variantsList = variants.map((variant) => Array.isArray(variant) ? variant[0][0]: variant);
|
|
51
|
+
*
|
|
52
|
+
* sum += last.executeCustom(...variantsList).getValue();
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* for (const variant of variants) {
|
|
56
|
+
* sum += Number(variant) || 0;
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* return sum;
|
|
60
|
+
* }, 'Adds its arguments');
|
|
61
|
+
* ```
|
|
40
62
|
*/
|
|
41
63
|
registerFunction(name: string, func: IRegisterFunction, description?: string): IDisposable;
|
|
42
64
|
/**
|
|
43
65
|
* Register a custom synchronous formula function with localization support.
|
|
44
|
-
*
|
|
45
66
|
* @param name - The name of the function to register. This will be used in formulas (e.g., =MYFUNC())
|
|
46
67
|
* @param func - The implementation of the function
|
|
47
68
|
* @param options - Object containing locales and description
|
|
69
|
+
* @param options.locales - Object containing locales
|
|
70
|
+
* @param options.description - Object containing description
|
|
48
71
|
* @returns A disposable object that will unregister the function when disposed
|
|
49
|
-
*
|
|
50
72
|
* @example
|
|
51
73
|
* ```js
|
|
52
74
|
* univerAPI.getFormula().registerFunction('HELLO',
|
|
@@ -85,11 +107,9 @@ export interface IFFormulaSheetsMixin {
|
|
|
85
107
|
}): IDisposable;
|
|
86
108
|
/**
|
|
87
109
|
* Register a custom asynchronous formula function.
|
|
88
|
-
*
|
|
89
110
|
* @param name - The name of the function to register. This will be used in formulas (e.g., =ASYNCFUNC())
|
|
90
111
|
* @param func - The async implementation of the function
|
|
91
112
|
* @returns A disposable object that will unregister the function when disposed
|
|
92
|
-
*
|
|
93
113
|
* @example
|
|
94
114
|
* ```js
|
|
95
115
|
* univerAPI.getFormula().registerAsyncFunction('RANDOM_DELAYED',
|
|
@@ -108,12 +128,12 @@ export interface IFFormulaSheetsMixin {
|
|
|
108
128
|
registerAsyncFunction(name: string, func: IRegisterAsyncFunction, description?: string): IDisposable;
|
|
109
129
|
/**
|
|
110
130
|
* Register a custom asynchronous formula function with description.
|
|
111
|
-
*
|
|
112
131
|
* @param name - The name of the function to register. This will be used in formulas (e.g., =ASYNCFUNC())
|
|
113
132
|
* @param func - The async implementation of the function
|
|
114
|
-
* @param
|
|
133
|
+
* @param options - Object containing locales and description
|
|
134
|
+
* @param options.locales - Object containing locales
|
|
135
|
+
* @param options.description - Object containing description
|
|
115
136
|
* @returns A disposable object that will unregister the function when disposed
|
|
116
|
-
*
|
|
117
137
|
* @example
|
|
118
138
|
* ```js
|
|
119
139
|
* // Mock a user score fetching function
|
|
@@ -156,12 +176,11 @@ export interface IFFormulaSheetsMixin {
|
|
|
156
176
|
}
|
|
157
177
|
export declare class FFormulaSheetsMixin extends FFormula implements IFFormulaSheetsMixin {
|
|
158
178
|
/**
|
|
159
|
-
*
|
|
179
|
+
* RegisterFunction may be executed multiple times, triggering multiple formula forced refreshes.
|
|
160
180
|
*/
|
|
161
181
|
private _debouncedFormulaCalculation;
|
|
162
182
|
/**
|
|
163
183
|
* Initialize the FUniver instance.
|
|
164
|
-
*
|
|
165
184
|
* @private
|
|
166
185
|
*/
|
|
167
186
|
_initialize(): void;
|
|
@@ -171,7 +190,7 @@ export declare class FFormulaSheetsMixin extends FFormula implements IFFormulaSh
|
|
|
171
190
|
registerAsyncFunction(name: string, func: IRegisterAsyncFunction): IDisposable;
|
|
172
191
|
registerAsyncFunction(name: string, func: IRegisterAsyncFunction, description: string): IDisposable;
|
|
173
192
|
}
|
|
174
|
-
declare module '@univerjs/engine-formula' {
|
|
193
|
+
declare module '@univerjs/engine-formula/facade' {
|
|
175
194
|
interface FFormula extends IFFormulaSheetsMixin {
|
|
176
195
|
}
|
|
177
196
|
}
|
|
@@ -11,12 +11,11 @@ export interface IFUniverSheetsFormulaMixin {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class FUniverSheetsFormulaMixin extends FUniver implements IFUniverSheetsFormulaMixin {
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* RegisterFunction may be executed multiple times, triggering multiple formula forced refreshes.
|
|
15
15
|
*/
|
|
16
16
|
private _debouncedFormulaCalculation;
|
|
17
17
|
/**
|
|
18
18
|
* Initialize the FUniver instance.
|
|
19
|
-
*
|
|
20
19
|
* @private
|
|
21
20
|
*/
|
|
22
21
|
_initialize(): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IDisposable, ILocales, Disposable, LocaleService } from '@univerjs/core';
|
|
2
|
-
import { FormulaFunctionValueType, IFunctionInfo, IFunctionService } from '@univerjs/engine-formula';
|
|
2
|
+
import { FormulaFunctionResultValueType, FormulaFunctionValueType, IFunctionInfo, IFunctionService } from '@univerjs/engine-formula';
|
|
3
3
|
import { IDescriptionService } from './description.service';
|
|
4
4
|
import { IRemoteRegisterFunctionService } from './remote/remote-register-function.service';
|
|
5
|
-
export type IRegisterFunction = (...arg: Array<FormulaFunctionValueType>) =>
|
|
6
|
-
export type IRegisterAsyncFunction = (...arg: Array<FormulaFunctionValueType>) => Promise<
|
|
5
|
+
export type IRegisterFunction = (...arg: Array<FormulaFunctionValueType>) => FormulaFunctionResultValueType;
|
|
6
|
+
export type IRegisterAsyncFunction = (...arg: Array<FormulaFunctionValueType>) => Promise<FormulaFunctionResultValueType>;
|
|
7
7
|
export type IRegisterFunctionList = [[IRegisterFunction, string, string?]];
|
|
8
8
|
export interface IFormulaCustomFunctionService {
|
|
9
9
|
/**
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,
|
|
1
|
+
(function(i,u){typeof exports=="object"&&typeof module<"u"?u(require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/engine-formula","@univerjs/sheets-formula","@univerjs/engine-formula/facade"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.UniverCore,i.UniverEngineFormula,i.UniverSheetsFormula,i.UniverEngineFormulaFacade))})(this,function(i,u,t,l){"use strict";class d extends i.FUniver{_initialize(){this._debouncedFormulaCalculation=i.debounce(()=>{this._commandService.executeCommand(u.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(r){let c=this._injector.get(t.IRegisterFunctionService);c||(this._injector.add([t.IRegisterFunctionService,{useClass:t.RegisterFunctionService}]),c=this._injector.get(t.IRegisterFunctionService));const e=c.registerFunctions(r);return this._debouncedFormulaCalculation(),e}}i.FUniver.extend(d);class f extends l.FFormula{_initialize(){this._debouncedFormulaCalculation=i.debounce(()=>{this._commandService.executeCommand(u.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}setInitialFormulaComputing(r){const e=this._injector.get(i.LifecycleService).stage,n=this._injector.get(i.ILogService),s=this._injector.get(i.IConfigService);e>i.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 o=s.getConfig(t.PLUGIN_CONFIG_KEY_BASE);o&&(o.initialFormulaComputing=r)}registerFunction(r,c,e){var a;let n=this._injector.get(t.IRegisterFunctionService);n||(this._injector.add([t.IRegisterFunctionService,{useClass:t.RegisterFunctionService}]),n=this._injector.get(t.IRegisterFunctionService));const s={name:r,func:c,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},o=n.registerFunction(s);return this._debouncedFormulaCalculation(),o}registerAsyncFunction(r,c,e){var a;let n=this._injector.get(t.IRegisterFunctionService);n||(this._injector.add([t.IRegisterFunctionService,{useClass:t.RegisterFunctionService}]),n=this._injector.get(t.IRegisterFunctionService));const s={name:r,func:c,description:typeof e=="string"?e:(a=e==null?void 0:e.description)!=null?a:"",locales:typeof e=="object"?e.locales:void 0},o=n.registerAsyncFunction(s);return this._debouncedFormulaCalculation(),o}}l.FFormula.extend(f)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-formula",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -57,18 +57,18 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/rpc": "0.5.
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
60
|
+
"@univerjs/core": "0.5.4",
|
|
61
|
+
"@univerjs/rpc": "0.5.4",
|
|
62
|
+
"@univerjs/engine-formula": "0.5.4",
|
|
63
|
+
"@univerjs/sheets": "0.5.4"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"rxjs": "^7.8.1",
|
|
67
67
|
"typescript": "^5.7.2",
|
|
68
|
-
"vite": "^6.0.
|
|
68
|
+
"vite": "^6.0.7",
|
|
69
69
|
"vitest": "^2.1.8",
|
|
70
|
-
"@univerjs/docs": "0.5.
|
|
71
|
-
"@univerjs-infra/shared": "0.5.
|
|
70
|
+
"@univerjs/docs": "0.5.4",
|
|
71
|
+
"@univerjs-infra/shared": "0.5.4"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"test": "vitest run",
|