@univerjs/sheets-formula 0.4.2 → 0.5.0-alpha.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.
Files changed (41) hide show
  1. package/lib/cjs/facade.js +1 -0
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/cjs/locale/en-US.js +1 -0
  4. package/lib/cjs/locale/fa-IR.js +1 -0
  5. package/lib/cjs/locale/ru-RU.js +1 -0
  6. package/lib/cjs/locale/vi-VN.js +1 -0
  7. package/lib/cjs/locale/zh-CN.js +1 -0
  8. package/lib/cjs/locale/zh-TW.js +1 -0
  9. package/lib/es/facade.js +40 -0
  10. package/lib/es/index.js +3738 -3363
  11. package/lib/es/locale/en-US.js +14 -0
  12. package/lib/es/locale/fa-IR.js +14 -0
  13. package/lib/es/locale/ru-RU.js +14 -0
  14. package/lib/es/locale/vi-VN.js +14 -0
  15. package/lib/es/locale/zh-CN.js +14 -0
  16. package/lib/es/locale/zh-TW.js +14 -0
  17. package/lib/types/controllers/config.schema.d.ts +18 -0
  18. package/lib/types/controllers/trigger-calculation.controller.d.ts +18 -3
  19. package/lib/types/controllers/update-formula.controller.d.ts +4 -2
  20. package/lib/types/facade/f-formula.d.ts +14 -0
  21. package/lib/types/facade/f-univer.d.ts +16 -0
  22. package/lib/types/{controllers/utils/__tests__/utils.spec.d.ts → facade/index.d.ts} +2 -1
  23. package/lib/types/index.d.ts +1 -0
  24. package/lib/types/locale/en-US.d.ts +3 -0
  25. package/lib/types/locale/fa-IR.d.ts +3 -0
  26. package/lib/types/locale/ru-RU.d.ts +3 -0
  27. package/lib/types/locale/vi-VN.d.ts +3 -0
  28. package/lib/types/locale/zh-CN.d.ts +27 -0
  29. package/lib/types/locale/zh-TW.d.ts +3 -0
  30. package/lib/types/services/formula-common.d.ts +3 -3
  31. package/lib/types/services/register-other-formula.service.d.ts +24 -1
  32. package/lib/umd/facade.js +1 -0
  33. package/lib/umd/index.js +1 -1
  34. package/lib/umd/locale/en-US.js +1 -0
  35. package/lib/umd/locale/fa-IR.js +1 -0
  36. package/lib/umd/locale/ru-RU.js +1 -0
  37. package/lib/umd/locale/vi-VN.js +1 -0
  38. package/lib/umd/locale/zh-CN.js +1 -0
  39. package/lib/umd/locale/zh-TW.js +1 -0
  40. package/package.json +36 -18
  41. package/lib/types/controllers/utils/utils.d.ts +0 -15
@@ -0,0 +1,14 @@
1
+ const a = {
2
+ formula: {
3
+ progress: {
4
+ analyzing: "Analyzing",
5
+ calculating: "Calculating",
6
+ "array-analysis": "Array Analysis",
7
+ "array-calculation": "Array Calculation",
8
+ done: "Done"
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ a as default
14
+ };
@@ -0,0 +1,14 @@
1
+ const a = {
2
+ formula: {
3
+ progress: {
4
+ analyzing: "در حال تحلیل",
5
+ calculating: "در حال محاسبه",
6
+ "array-analysis": "تحلیل آرایه",
7
+ "array-calculation": "محاسبه آرایه",
8
+ done: "تمام"
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ a as default
14
+ };
@@ -0,0 +1,14 @@
1
+ const a = {
2
+ formula: {
3
+ progress: {
4
+ analyzing: "Анализ",
5
+ calculating: "Вычисление",
6
+ "array-analysis": "Анализ массива",
7
+ "array-calculation": "Вычисление массива",
8
+ done: "Готово"
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ a as default
14
+ };
@@ -0,0 +1,14 @@
1
+ const a = {
2
+ formula: {
3
+ progress: {
4
+ analyzing: "Đang phân tích",
5
+ calculating: "Đang tính toán",
6
+ "array-analysis": "Phân tích mảng",
7
+ "array-calculation": "Tính toán mảng",
8
+ done: "Hoàn tất"
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ a as default
14
+ };
@@ -0,0 +1,14 @@
1
+ const a = {
2
+ formula: {
3
+ progress: {
4
+ analyzing: "分析中",
5
+ calculating: "计算中",
6
+ "array-analysis": "数组分析",
7
+ "array-calculation": "数组计算",
8
+ done: "完成"
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ a as default
14
+ };
@@ -0,0 +1,14 @@
1
+ const a = {
2
+ formula: {
3
+ progress: {
4
+ analyzing: "分析中",
5
+ calculating: "計算中",
6
+ "array-analysis": "陣列分析",
7
+ "array-calculation": "陣列計算",
8
+ done: "完成"
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ a as default
14
+ };
@@ -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,5 @@
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
3
  /**
4
4
  * This interface is for the progress bar to display the calculation progress.
5
5
  */
@@ -8,10 +8,16 @@ export interface ICalculationProgress {
8
8
  done: number;
9
9
  /** The total number of formulas need to calculate. */
10
10
  count: number;
11
+ /** The label of the calculation progress. */
12
+ label?: string;
11
13
  }
12
14
  export declare class TriggerCalculationController extends Disposable {
13
15
  private readonly _commandService;
14
16
  private readonly _activeDirtyManagerService;
17
+ private readonly _logService;
18
+ private readonly _configService;
19
+ private readonly _formulaDataModel;
20
+ private readonly _localeService;
15
21
  private _waitingCommandQueue;
16
22
  private _executingDirtyData;
17
23
  private _setTimeoutKey;
@@ -20,6 +26,7 @@ export declare class TriggerCalculationController extends Disposable {
20
26
  private _doneCalculationTaskCount;
21
27
  private _executionInProgressParams;
22
28
  private _restartCalculation;
29
+ private _calculationMode;
23
30
  /**
24
31
  * The mark of forced calculation. If a new mutation triggers dirty area calculation during the forced calculation process, forced calculation is still required.
25
32
  */
@@ -28,16 +35,24 @@ export declare class TriggerCalculationController extends Disposable {
28
35
  readonly progress$: import('rxjs').Observable<ICalculationProgress>;
29
36
  private _emitProgress;
30
37
  private _startProgress;
38
+ private _calculateProgress;
31
39
  private _completeProgress;
32
40
  clearProgress(): void;
33
- constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService);
41
+ constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService, _logService: ILogService, _configService: IConfigService, _formulaDataModel: FormulaDataModel, _localeService: LocaleService);
34
42
  dispose(): void;
35
43
  private _commandExecutedListener;
36
44
  private _generateDirty;
37
45
  private _mergeDirty;
46
+ /**
47
+ * dirtyRanges may overlap with the ranges in allDirtyRanges and need to be deduplicated
48
+ * @param allDirtyRanges
49
+ * @param dirtyRanges
50
+ */
51
+ private _mergeDirtyRanges;
38
52
  private _mergeDirtyNameMap;
39
53
  private _mergeDirtyUnitFeatureOrOtherFormulaMap;
40
54
  private _initialExecuteFormulaProcessListener;
41
55
  private _resetExecutingDirtyData;
42
56
  private _initialExecuteFormula;
57
+ private _getDiryDataByCalculationMode;
43
58
  }
@@ -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 {};
@@ -13,4 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export {};
16
+ import './f-univer';
17
+ import './f-formula';
@@ -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,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -0,0 +1,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -0,0 +1,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -0,0 +1,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -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,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -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,17 +1,31 @@
1
- import { Nullable, Disposable, ICommandService } from '@univerjs/core';
1
+ import { IRange, Nullable, Disposable, ICommandService } from '@univerjs/core';
2
2
  import { IActiveDirtyManagerService } from '@univerjs/engine-formula';
3
3
  import { IOtherFormulaResult } from './formula-common';
4
4
  export declare class RegisterOtherFormulaService extends Disposable {
5
5
  private readonly _commandService;
6
6
  private _activeDirtyManagerService;
7
7
  private _formulaCacheMap;
8
+ /**
9
+ * @deprecated Use _formulaChangeWithRange$ instead
10
+ */
8
11
  private _formulaChange$;
12
+ /**
13
+ * @deprecated Use formulaChangeWithRange$ instead
14
+ */
9
15
  formulaChange$: import('rxjs').Observable<{
10
16
  unitId: string;
11
17
  subUnitId: string;
12
18
  formulaText: string;
13
19
  formulaId: string;
14
20
  }>;
21
+ private _formulaChangeWithRange$;
22
+ formulaChangeWithRange$: import('rxjs').Observable<{
23
+ unitId: string;
24
+ subUnitId: string;
25
+ formulaText: string;
26
+ formulaId: string;
27
+ ranges: IRange[];
28
+ }>;
15
29
  private _formulaResult$;
16
30
  formulaResult$: import('rxjs').Observable<Record<string, Record<string, IOtherFormulaResult[]>>>;
17
31
  constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService);
@@ -20,7 +34,16 @@ export declare class RegisterOtherFormulaService extends Disposable {
20
34
  private _createFormulaId;
21
35
  private _initFormulaRegister;
22
36
  private _initFormulaCalculationResultChange;
37
+ /**
38
+ * @deprecated Use registerFormulaWithRange instead
39
+ * @param unitId
40
+ * @param subUnitId
41
+ * @param formulaText
42
+ * @param extra
43
+ * @returns
44
+ */
23
45
  registerFormula(unitId: string, subUnitId: string, formulaText: string, extra?: Record<string, any>): string;
46
+ registerFormulaWithRange(unitId: string, subUnitId: string, formulaText: string, ranges?: IRange[], extra?: Record<string, any>): string;
24
47
  deleteFormula(unitId: string, subUnitId: string, formulaIdList: string[]): void;
25
48
  getFormulaValue(unitId: string, subUnitId: string, formulaId: string): Promise<Nullable<IOtherFormulaResult>>;
26
49
  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)});