@univerjs/sheets-formula 0.4.2 → 0.5.0-beta.0
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 -0
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -0
- package/lib/cjs/locale/fa-IR.js +1 -0
- package/lib/cjs/locale/ru-RU.js +1 -0
- package/lib/cjs/locale/vi-VN.js +1 -0
- package/lib/cjs/locale/zh-CN.js +1 -0
- package/lib/cjs/locale/zh-TW.js +1 -0
- package/lib/es/facade.js +40 -0
- package/lib/es/index.js +3891 -3397
- package/lib/es/locale/en-US.js +14 -0
- package/lib/es/locale/fa-IR.js +14 -0
- package/lib/es/locale/ru-RU.js +14 -0
- package/lib/es/locale/vi-VN.js +14 -0
- package/lib/es/locale/zh-CN.js +14 -0
- package/lib/es/locale/zh-TW.js +14 -0
- package/lib/types/controllers/config.schema.d.ts +18 -0
- package/lib/types/controllers/trigger-calculation.controller.d.ts +20 -3
- package/lib/types/controllers/update-formula.controller.d.ts +4 -2
- package/lib/types/facade/f-formula.d.ts +14 -0
- package/lib/types/facade/f-univer.d.ts +16 -0
- package/lib/types/facade/index.d.ts +17 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/locale/en-US.d.ts +3 -0
- package/lib/types/locale/fa-IR.d.ts +3 -0
- package/lib/types/locale/ru-RU.d.ts +3 -0
- package/lib/types/locale/vi-VN.d.ts +3 -0
- package/lib/types/locale/zh-CN.d.ts +27 -0
- package/lib/types/locale/zh-TW.d.ts +3 -0
- package/lib/types/services/__test__/util.d.ts +7 -0
- package/lib/types/services/formula-common.d.ts +3 -3
- package/lib/types/services/formula-ref-range.service.d.ts +7 -4
- package/lib/types/services/register-other-formula.service.d.ts +9 -5
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/lib/umd/locale/en-US.js +1 -0
- package/lib/umd/locale/fa-IR.js +1 -0
- package/lib/umd/locale/ru-RU.js +1 -0
- package/lib/umd/locale/vi-VN.js +1 -0
- package/lib/umd/locale/zh-CN.js +1 -0
- package/lib/umd/locale/zh-TW.js +1 -0
- package/package.json +37 -18
- package/lib/types/common/selection.d.ts +0 -4
- package/lib/types/controllers/utils/utils.d.ts +0 -15
- /package/lib/types/{controllers/utils/__tests__/utils.spec.d.ts → services/__test__/formula-ref.spec.d.ts} +0 -0
|
@@ -5,10 +5,28 @@ import { BaseFunction, IFunctionInfo, IFunctionNames } from '@univerjs/engine-fo
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const PLUGIN_CONFIG_KEY_BASE = "sheets-formula.base.config";
|
|
7
7
|
export declare const configSymbolBase: unique symbol;
|
|
8
|
+
export declare enum CalculationMode {
|
|
9
|
+
/**
|
|
10
|
+
* Force calculation of all formulas
|
|
11
|
+
*/
|
|
12
|
+
FORCED = 0,
|
|
13
|
+
/**
|
|
14
|
+
* Partial calculation, only cells with formulas but no v values are calculated
|
|
15
|
+
*/
|
|
16
|
+
WHEN_EMPTY = 1,
|
|
17
|
+
/**
|
|
18
|
+
* All formulas are not calculated
|
|
19
|
+
*/
|
|
20
|
+
NO_CALCULATION = 2
|
|
21
|
+
}
|
|
8
22
|
export interface IUniverSheetsFormulaBaseConfig {
|
|
9
23
|
notExecuteFormula?: boolean;
|
|
10
24
|
description?: IFunctionInfo[];
|
|
11
25
|
function?: Array<[Ctor<BaseFunction>, IFunctionNames]>;
|
|
26
|
+
/**
|
|
27
|
+
* Define the calculation mode during initialization, default is `WHEN_EMPTY`
|
|
28
|
+
*/
|
|
29
|
+
initialFormulaComputing?: CalculationMode;
|
|
12
30
|
}
|
|
13
31
|
export declare const defaultPluginBaseConfig: IUniverSheetsFormulaBaseConfig;
|
|
14
32
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Disposable, ICommandService } from '@univerjs/core';
|
|
2
|
-
import { IActiveDirtyManagerService } from '@univerjs/engine-formula';
|
|
1
|
+
import { Disposable, ICommandService, IConfigService, ILogService, LocaleService } from '@univerjs/core';
|
|
2
|
+
import { FormulaDataModel, IActiveDirtyManagerService } from '@univerjs/engine-formula';
|
|
3
|
+
import { RegisterOtherFormulaService } from '../services/register-other-formula.service';
|
|
3
4
|
/**
|
|
4
5
|
* This interface is for the progress bar to display the calculation progress.
|
|
5
6
|
*/
|
|
@@ -8,10 +9,17 @@ export interface ICalculationProgress {
|
|
|
8
9
|
done: number;
|
|
9
10
|
/** The total number of formulas need to calculate. */
|
|
10
11
|
count: number;
|
|
12
|
+
/** The label of the calculation progress. */
|
|
13
|
+
label?: string;
|
|
11
14
|
}
|
|
12
15
|
export declare class TriggerCalculationController extends Disposable {
|
|
13
16
|
private readonly _commandService;
|
|
14
17
|
private readonly _activeDirtyManagerService;
|
|
18
|
+
private readonly _logService;
|
|
19
|
+
private readonly _configService;
|
|
20
|
+
private readonly _formulaDataModel;
|
|
21
|
+
private readonly _localeService;
|
|
22
|
+
private readonly _registerOtherFormulaService;
|
|
15
23
|
private _waitingCommandQueue;
|
|
16
24
|
private _executingDirtyData;
|
|
17
25
|
private _setTimeoutKey;
|
|
@@ -20,6 +28,7 @@ export declare class TriggerCalculationController extends Disposable {
|
|
|
20
28
|
private _doneCalculationTaskCount;
|
|
21
29
|
private _executionInProgressParams;
|
|
22
30
|
private _restartCalculation;
|
|
31
|
+
private _calculationMode;
|
|
23
32
|
/**
|
|
24
33
|
* The mark of forced calculation. If a new mutation triggers dirty area calculation during the forced calculation process, forced calculation is still required.
|
|
25
34
|
*/
|
|
@@ -28,16 +37,24 @@ export declare class TriggerCalculationController extends Disposable {
|
|
|
28
37
|
readonly progress$: import('rxjs').Observable<ICalculationProgress>;
|
|
29
38
|
private _emitProgress;
|
|
30
39
|
private _startProgress;
|
|
40
|
+
private _calculateProgress;
|
|
31
41
|
private _completeProgress;
|
|
32
42
|
clearProgress(): void;
|
|
33
|
-
constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService);
|
|
43
|
+
constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService, _logService: ILogService, _configService: IConfigService, _formulaDataModel: FormulaDataModel, _localeService: LocaleService, _registerOtherFormulaService: RegisterOtherFormulaService);
|
|
34
44
|
dispose(): void;
|
|
35
45
|
private _commandExecutedListener;
|
|
36
46
|
private _generateDirty;
|
|
37
47
|
private _mergeDirty;
|
|
48
|
+
/**
|
|
49
|
+
* dirtyRanges may overlap with the ranges in allDirtyRanges and need to be deduplicated
|
|
50
|
+
* @param allDirtyRanges
|
|
51
|
+
* @param dirtyRanges
|
|
52
|
+
*/
|
|
53
|
+
private _mergeDirtyRanges;
|
|
38
54
|
private _mergeDirtyNameMap;
|
|
39
55
|
private _mergeDirtyUnitFeatureOrOtherFormulaMap;
|
|
40
56
|
private _initialExecuteFormulaProcessListener;
|
|
41
57
|
private _resetExecutingDirtyData;
|
|
42
58
|
private _initialExecuteFormula;
|
|
59
|
+
private _getDiryDataByCalculationMode;
|
|
43
60
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Disposable, ICommandService, Injector, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { Disposable, ICommandService, IConfigService, Injector, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { FormulaDataModel, IDefinedNamesService, LexerTreeBuilder } from '@univerjs/engine-formula';
|
|
3
3
|
import { SheetInterceptorService } from '@univerjs/sheets';
|
|
4
4
|
/**
|
|
@@ -19,13 +19,15 @@ export declare class UpdateFormulaController extends Disposable {
|
|
|
19
19
|
private readonly _formulaDataModel;
|
|
20
20
|
private _sheetInterceptorService;
|
|
21
21
|
private readonly _definedNamesService;
|
|
22
|
+
private readonly _configService;
|
|
22
23
|
readonly _injector: Injector;
|
|
23
|
-
constructor(_univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _lexerTreeBuilder: LexerTreeBuilder, _formulaDataModel: FormulaDataModel, _sheetInterceptorService: SheetInterceptorService, _definedNamesService: IDefinedNamesService, _injector: Injector);
|
|
24
|
+
constructor(_univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _lexerTreeBuilder: LexerTreeBuilder, _formulaDataModel: FormulaDataModel, _sheetInterceptorService: SheetInterceptorService, _definedNamesService: IDefinedNamesService, _configService: IConfigService, _injector: Injector);
|
|
24
25
|
private _commandExecutedListener;
|
|
25
26
|
private _handleSetRangeValuesMutation;
|
|
26
27
|
private _handleWorkbookDisposed;
|
|
27
28
|
private _handleInsertSheetMutation;
|
|
28
29
|
private _handleWorkbookAdded;
|
|
30
|
+
private _getDiryDataByCalculationMode;
|
|
29
31
|
private _getUpdateFormula;
|
|
30
32
|
private _getFormulaReferenceMoveInfo;
|
|
31
33
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CalculationMode } from '@univerjs/sheets-formula';
|
|
2
|
+
interface IFFormulaSheetsMixin {
|
|
3
|
+
/**
|
|
4
|
+
* Update the calculation mode of the formula.
|
|
5
|
+
* @param calculationMode
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
setInitialFormulaComputing(calculationMode: CalculationMode): void;
|
|
9
|
+
}
|
|
10
|
+
declare module '@univerjs/engine-formula' {
|
|
11
|
+
interface FFormula extends IFFormulaSheetsMixin {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IDisposable } from '@univerjs/core';
|
|
2
|
+
import { IRegisterFunctionParams } from '@univerjs/sheets-formula';
|
|
3
|
+
interface IFUniverSheetsFormulaMixin {
|
|
4
|
+
/**
|
|
5
|
+
* Register a function to the spreadsheet.
|
|
6
|
+
*
|
|
7
|
+
* @param {IRegisterFunctionParams} config The configuration of the function.
|
|
8
|
+
* @returns {IDisposable} The disposable instance.
|
|
9
|
+
*/
|
|
10
|
+
registerFunction(config: IRegisterFunctionParams): IDisposable;
|
|
11
|
+
}
|
|
12
|
+
declare module '@univerjs/core' {
|
|
13
|
+
interface FUniver extends IFUniverSheetsFormulaMixin {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import './f-univer';
|
|
17
|
+
import './f-formula';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export { type IInsertFunction, type IInsertFunctionCommandParams, InsertFunction
|
|
|
17
17
|
export { OtherFormulaMarkDirty } from './commands/mutations/formula.mutation';
|
|
18
18
|
export { UpdateDefinedNameController } from './controllers/update-defined-name.controller';
|
|
19
19
|
export { TriggerCalculationController } from './controllers/trigger-calculation.controller';
|
|
20
|
+
export { CalculationMode, type IUniverSheetsFormulaBaseConfig, PLUGIN_CONFIG_KEY_BASE } from './controllers/config.schema';
|
|
20
21
|
export { UpdateFormulaController } from './controllers/update-formula.controller';
|
|
21
22
|
export { DescriptionService, IDescriptionService, type ISearchItem } from './services/description.service';
|
|
22
23
|
export type { IFormulaInfo, IOtherFormulaResult } from './services/formula-common';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
declare const locale: {
|
|
17
|
+
formula: {
|
|
18
|
+
progress: {
|
|
19
|
+
analyzing: string;
|
|
20
|
+
calculating: string;
|
|
21
|
+
'array-analysis': string;
|
|
22
|
+
'array-calculation': string;
|
|
23
|
+
done: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default locale;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Dependency, IWorkbookData, Workbook, Injector, Univer } from '@univerjs/core';
|
|
2
|
+
export interface ITestBed {
|
|
3
|
+
univer: Univer;
|
|
4
|
+
get: Injector['get'];
|
|
5
|
+
sheet: Workbook;
|
|
6
|
+
}
|
|
7
|
+
export declare function createCommandTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICellData, Nullable } from '@univerjs/core';
|
|
1
|
+
import { ICellData, IObjectMatrixPrimitiveType, Nullable } from '@univerjs/core';
|
|
2
2
|
export declare enum FormulaResultStatus {
|
|
3
3
|
NOT_REGISTER = 1,
|
|
4
4
|
SUCCESS = 2,
|
|
@@ -6,10 +6,10 @@ export declare enum FormulaResultStatus {
|
|
|
6
6
|
ERROR = 4
|
|
7
7
|
}
|
|
8
8
|
export interface IOtherFormulaResult {
|
|
9
|
-
result?: Nullable<ICellData>[][]
|
|
9
|
+
result?: IObjectMatrixPrimitiveType<Nullable<ICellData>[][]>;
|
|
10
10
|
status: FormulaResultStatus;
|
|
11
11
|
formulaId: string;
|
|
12
|
-
callbacks: Set<(value: Nullable<ICellData>[][]) => void>;
|
|
12
|
+
callbacks: Set<(value: IObjectMatrixPrimitiveType<Nullable<ICellData>[][]>) => void>;
|
|
13
13
|
extra?: Record<string, any>;
|
|
14
14
|
}
|
|
15
15
|
export interface IFormulaInfo {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDisposable, IMutationInfo, IRange, Disposable, IUniverInstanceService } from '@univerjs/core';
|
|
1
|
+
import { IDisposable, IMutationInfo, IRange, Disposable, Injector, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { EffectRefRangeParams, RefRangeService } from '@univerjs/sheets';
|
|
3
3
|
import { LexerTreeBuilder } from '@univerjs/engine-formula';
|
|
4
4
|
export type FormulaChangeMap = Record<string, Record<string, Record<string, string>>>;
|
|
@@ -6,8 +6,8 @@ export type FormulaChangeCallback = (formulaString: string) => {
|
|
|
6
6
|
redos: IMutationInfo[];
|
|
7
7
|
undos: IMutationInfo[];
|
|
8
8
|
};
|
|
9
|
-
export type RangeFormulaChangeCallback = (
|
|
10
|
-
|
|
9
|
+
export type RangeFormulaChangeCallback = (infos: {
|
|
10
|
+
formulas: string[];
|
|
11
11
|
ranges: IRange[];
|
|
12
12
|
}[]) => {
|
|
13
13
|
redos: IMutationInfo[];
|
|
@@ -17,7 +17,10 @@ export declare class FormulaRefRangeService extends Disposable {
|
|
|
17
17
|
private readonly _refRangeService;
|
|
18
18
|
private readonly _lexerTreeBuilder;
|
|
19
19
|
private readonly _univerInstanceService;
|
|
20
|
-
|
|
20
|
+
private readonly _injector;
|
|
21
|
+
constructor(_refRangeService: RefRangeService, _lexerTreeBuilder: LexerTreeBuilder, _univerInstanceService: IUniverInstanceService, _injector: Injector);
|
|
21
22
|
transformFormulaByEffectCommand(unitId: string, subUnitId: string, formula: string, params: EffectRefRangeParams): string;
|
|
22
23
|
registerFormula(unitId: string, subUnitId: string, formula: string, callback: FormulaChangeCallback): IDisposable;
|
|
24
|
+
private _getFormulaDependcy;
|
|
25
|
+
registerRangeFormula(unitId: string, subUnitId: string, oldRanges: IRange[], formulas: string[], callback: RangeFormulaChangeCallback): IDisposable;
|
|
23
26
|
}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import { Nullable, Disposable, ICommandService } from '@univerjs/core';
|
|
1
|
+
import { IRange, Nullable, Disposable, ICommandService, LifecycleService } from '@univerjs/core';
|
|
2
2
|
import { IActiveDirtyManagerService } from '@univerjs/engine-formula';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
3
4
|
import { IOtherFormulaResult } from './formula-common';
|
|
4
5
|
export declare class RegisterOtherFormulaService extends Disposable {
|
|
5
6
|
private readonly _commandService;
|
|
6
7
|
private _activeDirtyManagerService;
|
|
8
|
+
private readonly _lifecycleService;
|
|
7
9
|
private _formulaCacheMap;
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
+
private _formulaChangeWithRange$;
|
|
11
|
+
formulaChangeWithRange$: import('rxjs').Observable<{
|
|
10
12
|
unitId: string;
|
|
11
13
|
subUnitId: string;
|
|
12
14
|
formulaText: string;
|
|
13
15
|
formulaId: string;
|
|
16
|
+
ranges: IRange[];
|
|
14
17
|
}>;
|
|
15
18
|
private _formulaResult$;
|
|
16
19
|
formulaResult$: import('rxjs').Observable<Record<string, Record<string, IOtherFormulaResult[]>>>;
|
|
17
|
-
|
|
20
|
+
calculateStarted$: BehaviorSubject<boolean>;
|
|
21
|
+
constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService, _lifecycleService: LifecycleService);
|
|
18
22
|
dispose(): void;
|
|
19
23
|
private _ensureCacheMap;
|
|
20
24
|
private _createFormulaId;
|
|
21
25
|
private _initFormulaRegister;
|
|
22
26
|
private _initFormulaCalculationResultChange;
|
|
23
|
-
|
|
27
|
+
registerFormulaWithRange(unitId: string, subUnitId: string, formulaText: string, ranges?: IRange[], extra?: Record<string, any>): string;
|
|
24
28
|
deleteFormula(unitId: string, subUnitId: string, formulaIdList: string[]): void;
|
|
25
29
|
getFormulaValue(unitId: string, subUnitId: string, formulaId: string): Promise<Nullable<IOtherFormulaResult>>;
|
|
26
30
|
getFormulaValueSync(unitId: string, subUnitId: string, formulaId: string): Nullable<IOtherFormulaResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?i(require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/engine-formula","@univerjs/sheets-formula"],i):(e=typeof globalThis<"u"?globalThis:e||self,i(e.UniverCore,e.UniverEngineFormula,e.UniverSheetsFormula))})(this,function(e,i,t){"use strict";class s extends e.FUniver{_initialize(){this._debouncedFormulaCalculation=e.debounce(()=>{this._commandService.executeCommand(i.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})},10)}registerFunction(r){let n=this._injector.get(t.IRegisterFunctionService);n||(this._injector.add([t.IRegisterFunctionService,{useClass:t.RegisterFunctionService}]),n=this._injector.get(t.IRegisterFunctionService));const c=n.registerFunctions(r);return this._debouncedFormulaCalculation(),c}}e.FUniver.extend(s);class u extends i.FFormula{setInitialFormulaComputing(r){const c=this._injector.get(e.LifecycleService).stage,a=this._injector.get(e.ILogService),f=this._injector.get(e.IConfigService);c>e.LifecycleStages.Starting&&a.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=f.getConfig(t.PLUGIN_CONFIG_KEY_BASE);o&&(o.initialFormulaComputing=r)}}i.FFormula.extend(u)});
|