Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(formula): auto fill bug, change functions folder (#695)

Dushusir6f4913924e9d
diff --git a/packages/engine-formula/src/basics/function.ts b/packages/engine-formula/src/basics/function.ts
index 34032a4519..ba583ba15a 100644
--- a/packages/engine-formula/src/basics/function.ts
+++ b/packages/engine-formula/src/basics/function.ts
@@ -1,5 +1,22 @@
import type { BooleanNumber } from '@univerjs/core';
+import type { FUNCTION_NAMES_ARRAY } from '../functions/array/function-names';
+import type { FUNCTION_NAMES_COMPATIBILITY } from '../functions/compatibility/function-names';
+import type { FUNCTION_NAMES_CUBE } from '../functions/cube/function-names';
+import type { FUNCTION_NAMES_DATABASE } from '../functions/database/function-names';
+import type { FUNCTION_NAMES_DATE } from '../functions/date/function-names';
+import type { FUNCTION_NAMES_ENGINEERING } from '../functions/engineering/function-names';
+import type { FUNCTION_NAMES_FINANCIAL } from '../functions/financial/function-names';
+import type { FUNCTION_NAMES_INFORMATION } from '../functions/information/function-names';
+import type { FUNCTION_NAMES_LOGICAL } from '../functions/logical/function-names';
+import type { FUNCTION_NAMES_LOOKUP } from '../functions/lookup/function-names';
+import type { FUNCTION_NAMES_MATH } from '../functions/math/function-names';
+import type { FUNCTION_NAMES_META } from '../functions/meta/function-names';
+import type { FUNCTION_NAMES_STATISTICAL } from '../functions/statistical/function-names';
+import type { FUNCTION_NAMES_TEXT } from '../functions/text/function-names';
+import type { FUNCTION_NAMES_UNIVER } from '../functions/univer/function-names';
+import type { FUNCTION_NAMES_WEB } from '../functions/web/function-names';
+
/**
* Function type, refer to https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb
*/
@@ -145,20 +162,21 @@ export interface IFunctionInfo {
functionParameter: IFunctionParam[];
}
-export enum FUNCTION_NAMES {
- AVERAGE = 'AVERAGE',
- CONCATENATE = 'CONCATENATE',
- COUNT = 'COUNT',
- INDIRECT = 'INDIRECT',
- MAX = 'MAX',
- MIN = 'MIN',
- OFFSET = 'OFFSET',
- POWER = 'POWER',
- SUM = 'SUM',
- COMPARE = 'COMPARE',
- DIVIDED = 'DIVIDED',
- MINUS = 'MINUS',
- MULTIPLY = 'MULTIPLY',
- PLUS = 'PLUS',
- UNION = 'UNION',
-}
+export type IFunctionNames =
+ | string
+ | FUNCTION_NAMES_ARRAY
+ | FUNCTION_NAMES_COMPATIBILITY
+ | FUNCTION_NAMES_CUBE
+ | FUNCTION_NAMES_DATABASE
+ | FUNCTION_NAMES_DATE
+ | FUNCTION_NAMES_ENGINEERING
+ | FUNCTION_NAMES_FINANCIAL
+ | FUNCTION_NAMES_INFORMATION
+ | FUNCTION_NAMES_LOGICAL
+ | FUNCTION_NAMES_LOOKUP
+ | FUNCTION_NAMES_MATH
+ | FUNCTION_NAMES_META
+ | FUNCTION_NAMES_STATISTICAL
+ | FUNCTION_NAMES_TEXT
+ | FUNCTION_NAMES_UNIVER
+ | FUNCTION_NAMES_WEB;
diff --git a/packages/engine-formula/src/controller/formula.controller.ts b/packages/engine-formula/src/controller/formula.controller.ts
index e89a782470..c62be8f4aa 100644
--- a/packages/engine-formula/src/controller/formula.controller.ts
+++ b/packages/engine-formula/src/controller/formula.controller.ts
@@ -2,7 +2,6 @@ import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univ
import type { Ctor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
-import { FUNCTION_NAMES } from '../basics/function';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import {
SetFormulaCalculationNotificationMutation,
@@ -11,39 +10,23 @@ import {
SetFormulaCalculationStopMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
-import {
- Average,
- Compare,
- Concatenate,
- Count,
- Divided,
- Indirect,
- Max,
- Min,
- Minus,
- Multiply,
- Offset,
- Plus,
- Power,
- Sum,
- Union,
-} from '../functions';
-import { functionArray } from '../functions/array/function-names';
+import { functionArray } from '../functions/array/function-map';
import type { BaseFunction } from '../functions/base-function';
-import { functionCompatibility } from '../functions/compatibility/function-names';
-import { functionCube } from '../functions/cube/function-names';
-import { functionDatabase } from '../functions/database/function-names';
-import { functionDate } from '../functions/date/function-names';
-import { functionEngineering } from '../functions/engineering/function-names';
-import { functionFinancial } from '../functions/financial/function-names';
-import { functionInformation } from '../functions/information/function-names';
-import { functionLogical } from '../functions/logical/function-names';
-import { functionLookup } from '../functions/lookup/function-names';
-import { functionMath } from '../functions/math/function-names';
-import { functionStatistical } from '../functions/statistical/function-names';
-import { functionText } from '../functions/text/function-names';
-import { functionUniver } from '../functions/univer/function-names';
-import { functionWeb } from '../functions/web/function-names';
+import { functionCompatibility } from '../functions/compatibility/function-map';
+import { functionCube } from '../functions/cube/function-map';
+import { functionDatabase } from '../functions/database/function-map';
+import { functionDate } from '../functions/date/function-map';
+import { functionEngineering } from '../functions/engineering/function-map';
+import { functionFinancial } from '../functions/financial/function-map';
+import { functionInformation } from '../functions/information/function-map';
+import { functionLogical } from '../functions/logical/function-map';
+import { functionLookup } from '../functions/lookup/function-map';
+import { functionMath } from '../functions/math/function-map';
+import { functionMeta } from '../functions/meta/function-map';
+import { functionStatistical } from '../functions/statistical/function-map';
+import { functionText } from '../functions/text/function-map';
+import { functionUniver } from '../functions/univer/function-map';
+import { functionWeb } from '../functions/web/function-map';
import { IFunctionService } from '../services/function.service';
@OnLifecycle(LifecycleStages.Ready, FormulaController)
@@ -60,10 +43,7 @@ export class FormulaController extends Disposable {
private _initialize(): void {
this._registerCommands();
-
this._registerFunctions();
-
- this._initializeFunctions();
}
private _registerCommands(): void {
@@ -90,6 +70,7 @@ export class FormulaController extends Disposable {
...functionLogical,
...functionLookup,
...functionMath,
+ ...functionMeta,
...functionStatistical,
...functionText,
...functionUniver,
@@ -103,35 +84,4 @@ export class FormulaController extends Disposable {
this._functionService.registerExecutors(...functions);
}
-
- private _initializeFunctions() {
- // new Sum(this._injector, FUNCTION_NAMES.SUM)
- const functions: BaseFunction[] = [
- // base function
- [Compare, FUNCTION_NAMES.COMPARE],
- [Divided, FUNCTION_NAMES.DIVIDED],
- [Minus, FUNCTION_NAMES.MINUS],
- [Multiply, FUNCTION_NAMES.MULTIPLY],
- [Plus, FUNCTION_NAMES.PLUS],
- [Union, FUNCTION_NAMES.UNION],
-
- // static
- [Average, FUNCTION_NAMES.AVERAGE],
- [Concatenate, FUNCTION_NAMES.CONCATENATE],
- [Count, FUNCTION_NAMES.COUNT],
- [Indirect, FUNCTION_NAMES.INDIRECT],
- [Max, FUNCTION_NAMES.MAX],
- [Min, FUNCTION_NAMES.MIN],
- [Offset, FUNCTION_NAMES.OFFSET],
- [Power, FUNCTION_NAMES.POWER],
- [Sum, FUNCTION_NAMES.SUM],
- ].map((registerObject) => {
- const Func = registerObject[0] as Ctor<BaseFunction>;
- const name = registerObject[1] as string;
-
- return new Func(this._injector, name);
- });
-
- this._functionService.registerExecutors(...functions);
- }
}
diff --git a/packages/engine-formula/src/engine/ast-node/function-node.ts b/packages/engine-formula/src/engine/ast-node/function-node.ts
index 22aaa72394..e947992ba8 100644
--- a/packages/engine-formula/src/engine/ast-node/function-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/function-node.ts
@@ -3,9 +3,9 @@ import { Inject, Injector } from '@wendellhu/redi';
import { AstNodePromiseType } from '../../basics/common';
import { ErrorType } from '../../basics/error-type';
-import { FUNCTION_NAMES } from '../../basics/function';
import { prefixToken } from '../../basics/token';
import type { BaseFunction } from '../../functions/base-function';
+import { FUNCTION_NAMES_META } from '../../functions/meta/function-names';
import { IFunctionService } from '../../services/function.service';
import type { LexerNode } from '../analysis/lexer-node';
import type { AsyncObject, FunctionVariantType } from '../reference-object/base-reference-object';
@@ -105,7 +105,7 @@ export class FunctionNodeFactory extends BaseAstNodeFactory {
const prefix = tokenTrim.slice(0, 2);
let sliceLength = 0;
if (new RegExp(prefixToken.MINUS, 'g').test(prefix)) {
- const functionExecutor = this._functionService.getExecutor(FUNCTION_NAMES.MINUS);
+ const functionExecutor = this._functionService.getExecutor(FUNCTION_NAMES_META.MINUS);
minusPrefixNode = new PrefixNode(this._injector, prefixToken.MINUS, functionExecutor);
sliceLength++;
}
diff --git a/packages/engine-formula/src/engine/ast-node/operator-node.ts b/packages/engine-formula/src/engine/ast-node/operator-node.ts
index b35bcac875..0698298db7 100644
--- a/packages/engine-formula/src/engine/ast-node/operator-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/operator-node.ts
@@ -1,9 +1,11 @@
import { ErrorType } from '../../basics/error-type';
-import { FUNCTION_NAMES } from '../../basics/function';
import type { compareToken } from '../../basics/token';
import { OPERATOR_TOKEN_COMPARE_SET, OPERATOR_TOKEN_SET, operatorToken } from '../../basics/token';
import type { BaseFunction } from '../../functions/base-function';
-import type { Compare } from '../../functions/meta/compare';
+import { FUNCTION_NAMES_COMPATIBILITY } from '../../functions/compatibility/function-names';
+import { FUNCTION_NAMES_MATH } from '../../functions/math/function-names';
+import type { Compare } from '../../functions/meta/compare/compare';
+import { FUNCTION_NAMES_META } from '../../functions/meta/function-names';
import { IFunctionService } from '../../services/function.service';
import { LexerNode } from '../analysis/lexer-node';
import type { FunctionVariantType } from '../reference-object/base-reference-object';
@@ -25,7 +27,7 @@ export class OperatorNode extends BaseAstNode {
override execute() {
const children = this.getChildren();
- if (this._functionExecutor.name === FUNCTION_NAMES.COMPARE) {
+ if (this._functionExecutor.name === FUNCTION_NAMES_META.COMPARE) {
(this._functionExecutor as Compare).setCompareType(this.getToken() as compareToken);
}
const object1 = children[0].getValue();
@@ -50,19 +52,19 @@ export class OperatorNodeFactory extends BaseAstNodeFactory {
let functionName = '';
const tokenTrim = param;
if (tokenTrim === operatorToken.PLUS) {
- functionName = FUNCTION_NAMES.PLUS;
+ functionName = FUNCTION_NAMES_META.PLUS;
} else if (tokenTrim === operatorToken.MINUS) {
- functionName = FUNCTION_NAMES.MINUS;
+ functionName = FUNCTION_NAMES_META.MINUS;
} else if (tokenTrim === operatorToken.MULTIPLY) {
- functionName = FUNCTION_NAMES.MULTIPLY;
+ functionName = FUNCTION_NAMES_META.MULTIPLY;
} else if (tokenTrim === operatorToken.DIVIDED) {
- functionName = FUNCTION_NAMES.DIVIDED;
+ functionName = FUNCTION_NAMES_META.DIVIDED;
} else if (tokenTrim === operatorToken.CONCATENATE) {
- functionName = FUNCTION_NAMES.CONCATENATE;
+ functionName = FUNCTION_NAMES_COMPATIBILITY.CONCATENATE;
} else if (tokenTrim === operatorToken.POWER) {
- functionName = FUNCTION_NAMES.POWER;
+ functionName = FUNCTION_NAMES_MATH.POWER;
} else if (OPERATOR_TOKEN_COMPARE_SET.has(tokenTrim)) {
- functionName = FUNCTION_NAMES.COMPARE;
+ functionName = FUNCTION_NAMES_META.COMPARE;
}
const functionExecutor = this._functionService.getExecutor(functionName);
diff --git a/packages/engine-formula/src/engine/ast-node/prefix-node.ts b/packages/engine-formula/src/engine/ast-node/prefix-node.ts
index 56e824633e..40c3d9c072 100644
--- a/packages/engine-formula/src/engine/ast-node/prefix-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/prefix-node.ts
@@ -3,9 +3,9 @@ import type { IAccessor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { ErrorType } from '../../basics/error-type';
-import { FUNCTION_NAMES } from '../../basics/function';
import { prefixToken } from '../../basics/token';
import type { BaseFunction } from '../../functions/base-function';
+import { FUNCTION_NAMES_META } from '../../functions/meta/function-names';
import { IFunctionService } from '../../services/function.service';
import { IFormulaRuntimeService } from '../../services/runtime.service';
import { LexerNode } from '../analysis/lexer-node';
@@ -106,7 +106,7 @@ export class PrefixNodeFactory extends BaseAstNodeFactory {
let functionName = '';
if (tokenTrim === prefixToken.MINUS) {
- functionName = FUNCTION_NAMES.MINUS;
+ functionName = FUNCTION_NAMES_META.MINUS;
} else if (tokenTrim === prefixToken.AT) {
return new PrefixNode(this._injector, tokenTrim);
} else {
diff --git a/packages/engine-formula/src/engine/ast-node/suffix-node.ts b/packages/engine-formula/src/engine/ast-node/suffix-node.ts
index 6cb02f0d43..a422c64ecd 100644
--- a/packages/engine-formula/src/engine/ast-node/suffix-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/suffix-node.ts
@@ -2,9 +2,9 @@ import type { IAccessor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { ErrorType } from '../../basics/error-type';
-import { FUNCTION_NAMES } from '../../basics/function';
import { suffixToken } from '../../basics/token';
import type { BaseFunction } from '../../functions/base-function';
+import { FUNCTION_NAMES_META } from '../../functions/meta/function-names';
import { IFormulaCurrentConfigService } from '../../services/current-data.service';
import { IFunctionService } from '../../services/function.service';
import { LexerTreeBuilder } from '../analysis/lexer';
@@ -109,7 +109,7 @@ export class SuffixNodeFactory extends BaseAstNodeFactory {
let functionName = '';
if (tokenTrim === suffixToken.PERCENTAGE) {
- functionName = FUNCTION_NAMES.DIVIDED;
+ functionName = FUNCTION_NAMES_META.DIVIDED;
} else if (tokenTrim === suffixToken.POUND) {
return new SuffixNode(this._injector, tokenTrim);
} else {
diff --git a/packages/engine-formula/src/engine/ast-node/union-node.ts b/packages/engine-formula/src/engine/ast-node/union-node.ts
index 6be53f70dd..92daf299d9 100644
--- a/packages/engine-formula/src/engine/ast-node/union-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/union-node.ts
@@ -1,7 +1,7 @@
import { ErrorType } from '../../basics/error-type';
-import { FUNCTION_NAMES } from '../../basics/function';
import { matchToken } from '../../basics/token';
import type { BaseFunction } from '../../functions/base-function';
+import { FUNCTION_NAMES_META } from '../../functions/meta/function-names';
import { IFunctionService } from '../../services/function.service';
import { LexerNode } from '../analysis/lexer-node';
import { ErrorValueObject } from '../other-object/error-value-object';
@@ -53,7 +53,7 @@ export class UnionNodeFactory extends BaseAstNodeFactory {
}
override create(param: string): BaseAstNode {
- const functionExecutor = this._functionService.getExecutor(FUNCTION_NAMES.UNION);
+ const functionExecutor = this._functionService.getExecutor(FUNCTION_NAMES_META.UNION);
if (!functionExecutor) {
console.error(`No function ${param}`);
return ErrorNode.create(ErrorType.NAME);
diff --git a/packages/engine-formula/src/functions/array/function-map.ts b/packages/engine-formula/src/functions/array/function-map.ts
new file mode 100644
index 0000000000..18292fcd68
--- /dev/null
+++ b/packages/engine-formula/src/functions/array/function-map.ts
@@ -0,0 +1 @@
+export const functionArray = [];
diff --git a/packages/engine-formula/src/functions/array/function-names.ts b/packages/engine-formula/src/functions/array/function-names.ts
index 7904c2c47b..afa1209bf6 100644
--- a/packages/engine-formula/src/functions/array/function-names.ts
+++ b/packages/engine-formula/src/functions/array/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_ARRAY {}
-
-export const functionArray = [];
diff --git a/packages/engine-formula/src/functions/base-function.ts b/packages/engine-formula/src/functions/base-function.ts
index bad47f8dbd..28d078e5c3 100644
--- a/packages/engine-formula/src/functions/base-function.ts
+++ b/packages/engine-formula/src/functions/base-function.ts
@@ -1,6 +1,7 @@
import { Disposable } from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
+import type { IFunctionNames } from '..';
import { ErrorType } from '../basics/error-type';
import { ErrorValueObject } from '../engine/other-object/error-value-object';
import type { FunctionVariantType, NodeValueType } from '../engine/reference-object/base-reference-object';
@@ -9,7 +10,7 @@ import type { BaseValueObject } from '../engine/value-object/base-value-object';
export class BaseFunction extends Disposable {
constructor(
readonly accessor: IAccessor,
- private _name: string
+ private _name: IFunctionNames
) {
super();
}
diff --git a/packages/engine-formula/src/functions/compatibility/concatenate/concatenate.ts b/packages/engine-formula/src/functions/compatibility/concatenate/concatenate.ts
new file mode 100644
index 0000000000..9136763724
--- /dev/null
+++ b/packages/engine-formula/src/functions/compatibility/concatenate/concatenate.ts
@@ -0,0 +1,10 @@
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { BaseFunction } from '../../base-function';
+
+export class Concatenate extends BaseFunction {
+ override calculate(numberVar: FunctionVariantType, powerVar: FunctionVariantType) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+}
diff --git a/packages/engine-formula/src/functions/compatibility/function-map.ts b/packages/engine-formula/src/functions/compatibility/function-map.ts
new file mode 100644
index 0000000000..f78eaf7526
--- /dev/null
+++ b/packages/engine-formula/src/functions/compatibility/function-map.ts
@@ -0,0 +1,4 @@
+import { Concatenate } from './concatenate/concatenate';
+import { FUNCTION_NAMES_COMPATIBILITY } from './function-names';
+
+export const functionCompatibility = [[Concatenate, FUNCTION_NAMES_COMPATIBILITY.CONCATENATE]];
diff --git a/packages/engine-formula/src/functions/compatibility/function-names.ts b/packages/engine-formula/src/functions/compatibility/function-names.ts
index 996fa95f81..b1f6b706fe 100644
--- a/packages/engine-formula/src/functions/compatibility/function-names.ts
+++ b/packages/engine-formula/src/functions/compatibility/function-names.ts
@@ -1,3 +1,3 @@
-export enum FUNCTION_NAMES_COMPATIBILITY {}
-
-export const functionCompatibility = [];
+export enum FUNCTION_NAMES_COMPATIBILITY {
+ CONCATENATE = 'CONCATENATE',
+}
diff --git a/packages/engine-formula/src/functions/concatenate.ts b/packages/engine-formula/src/functions/concatenate.ts
deleted file mode 100644
index 173dbed391..0000000000
--- a/packages/engine-formula/src/functions/concatenate.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../engine/other-object/error-value-object';
-import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import { BaseFunction } from './base-function';
-
-export class Concatenate extends BaseFunction {
- override calculate(numberVar: FunctionVariantType, powerVar: FunctionVariantType) {
- return ErrorValueObject.create(ErrorType.VALUE);
- }
-}
diff --git a/packages/engine-formula/src/functions/cube/function-map.ts b/packages/engine-formula/src/functions/cube/function-map.ts
new file mode 100644
index 0000000000..4a61651e8b
--- /dev/null
+++ b/packages/engine-formula/src/functions/cube/function-map.ts
@@ -0,0 +1 @@
+export const functionCube = [];
diff --git a/packages/engine-formula/src/functions/cube/function-names.ts b/packages/engine-formula/src/functions/cube/function-names.ts
index d8a4e715f6..16880e4c55 100644
--- a/packages/engine-formula/src/functions/cube/function-names.ts
+++ b/packages/engine-formula/src/functions/cube/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_CUBE {}
-
-export const functionCube = [];
diff --git a/packages/engine-formula/src/functions/database/function-map.ts b/packages/engine-formula/src/functions/database/function-map.ts
new file mode 100644
index 0000000000..41c237d577
--- /dev/null
+++ b/packages/engine-formula/src/functions/database/function-map.ts
@@ -0,0 +1 @@
+export const functionDatabase = [];
diff --git a/packages/engine-formula/src/functions/database/function-names.ts b/packages/engine-formula/src/functions/database/function-names.ts
index 34a0d8bd2f..122076d0bd 100644
--- a/packages/engine-formula/src/functions/database/function-names.ts
+++ b/packages/engine-formula/src/functions/database/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_DATABASE {}
-
-export const functionDatabase = [];
diff --git a/packages/engine-formula/src/functions/date/function-map.ts b/packages/engine-formula/src/functions/date/function-map.ts
new file mode 100644
index 0000000000..7063ec7d03
--- /dev/null
+++ b/packages/engine-formula/src/functions/date/function-map.ts
@@ -0,0 +1 @@
+export const functionDate = [];
diff --git a/packages/engine-formula/src/functions/date/function-names.ts b/packages/engine-formula/src/functions/date/function-names.ts
index 51abcd18ac..efb077aae4 100644
--- a/packages/engine-formula/src/functions/date/function-names.ts
+++ b/packages/engine-formula/src/functions/date/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_DATE {}
-
-export const functionDate = [];
diff --git a/packages/engine-formula/src/functions/engineering/function-map.ts b/packages/engine-formula/src/functions/engineering/function-map.ts
new file mode 100644
index 0000000000..73a1621fe0
--- /dev/null
+++ b/packages/engine-formula/src/functions/engineering/function-map.ts
@@ -0,0 +1 @@
+export const functionEngineering = [];
diff --git a/packages/engine-formula/src/functions/engineering/function-names.ts b/packages/engine-formula/src/functions/engineering/function-names.ts
index 3991fbda13..d915b15dea 100644
--- a/packages/engine-formula/src/functions/engineering/function-names.ts
+++ b/packages/engine-formula/src/functions/engineering/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_ENGINEERING {}
-
-export const functionEngineering = [];
diff --git a/packages/engine-formula/src/functions/financial/function-map.ts b/packages/engine-formula/src/functions/financial/function-map.ts
new file mode 100644
index 0000000000..086cb65307
--- /dev/null
+++ b/packages/engine-formula/src/functions/financial/function-map.ts
@@ -0,0 +1 @@
+export const functionFinancial = [];
diff --git a/packages/engine-formula/src/functions/financial/function-names.ts b/packages/engine-formula/src/functions/financial/function-names.ts
index 96cbbf9139..2174f2730d 100644
--- a/packages/engine-formula/src/functions/financial/function-names.ts
+++ b/packages/engine-formula/src/functions/financial/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_FINANCIAL {}
-
-export const functionFinancial = [];
diff --git a/packages/engine-formula/src/functions/index.ts b/packages/engine-formula/src/functions/index.ts
deleted file mode 100644
index 316893286b..0000000000
--- a/packages/engine-formula/src/functions/index.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-export * from './average';
-export * from './concatenate';
-export * from './count';
-export * from './indirect';
-export * from './max';
-export * from './meta/compare';
-export * from './meta/divided';
-export * from './meta/minus';
-export * from './meta/multiply';
-export * from './meta/plus';
-export * from './meta/union';
-export * from './min';
-export * from './offset';
-export * from './power';
-export * from './sum';
diff --git a/packages/engine-formula/src/functions/indirect.ts b/packages/engine-formula/src/functions/indirect.ts
deleted file mode 100644
index 955e67e95b..0000000000
--- a/packages/engine-formula/src/functions/indirect.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import { CellReferenceObject } from '../engine/reference-object/cell-reference-object';
-import { BaseFunction } from './base-function';
-
-export class Indirect extends BaseFunction {
- override calculate(refText: FunctionVariantType, a1?: FunctionVariantType) {
- return new CellReferenceObject('A5');
- }
-}
diff --git a/packages/engine-formula/src/functions/information/function-map.ts b/packages/engine-formula/src/functions/information/function-map.ts
new file mode 100644
index 0000000000..a0da1cf0d2
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/function-map.ts
@@ -0,0 +1 @@
+export const functionInformation = [];
diff --git a/packages/engine-formula/src/functions/information/function-names.ts b/packages/engine-formula/src/functions/information/function-names.ts
index 61622a2843..bc9b8b7f33 100644
--- a/packages/engine-formula/src/functions/information/function-names.ts
+++ b/packages/engine-formula/src/functions/information/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_INFORMATION {}
-
-export const functionInformation = [];
diff --git a/packages/engine-formula/src/functions/logical/function-map.ts b/packages/engine-formula/src/functions/logical/function-map.ts
new file mode 100644
index 0000000000..b927792855
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/function-map.ts
@@ -0,0 +1 @@
+export const functionLogical = [];
diff --git a/packages/engine-formula/src/functions/logical/function-names.ts b/packages/engine-formula/src/functions/logical/function-names.ts
index c01bd9fa44..09b6b5d1a4 100644
--- a/packages/engine-formula/src/functions/logical/function-names.ts
+++ b/packages/engine-formula/src/functions/logical/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_LOGICAL {}
-
-export const functionLogical = [];
diff --git a/packages/engine-formula/src/functions/lookup/function-map.ts b/packages/engine-formula/src/functions/lookup/function-map.ts
new file mode 100644
index 0000000000..9c22255c73
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/function-map.ts
@@ -0,0 +1,8 @@
+import { FUNCTION_NAMES_LOOKUP } from './function-names';
+import { Indirect } from './indirect/indirect';
+import { Offset } from './offset/offset';
+
+export const functionLookup = [
+ [Indirect, FUNCTION_NAMES_LOOKUP.INDIRECT],
+ [Offset, FUNCTION_NAMES_LOOKUP.OFFSET],
+];
diff --git a/packages/engine-formula/src/functions/lookup/function-names.ts b/packages/engine-formula/src/functions/lookup/function-names.ts
index 91feb06101..6350cabf6e 100644
--- a/packages/engine-formula/src/functions/lookup/function-names.ts
+++ b/packages/engine-formula/src/functions/lookup/function-names.ts
@@ -1,3 +1,4 @@
-export enum FUNCTION_NAMES_LOOKUP {}
-
-export const functionLookup = [];
+export enum FUNCTION_NAMES_LOOKUP {
+ INDIRECT = 'INDIRECT',
+ OFFSET = 'OFFSET',
+}
diff --git a/packages/engine-formula/src/functions/lookup/indirect/indirect.ts b/packages/engine-formula/src/functions/lookup/indirect/indirect.ts
new file mode 100644
index 0000000000..c22817f286
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/indirect/indirect.ts
@@ -0,0 +1,9 @@
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { CellReferenceObject } from '../../../engine/reference-object/cell-reference-object';
+import { BaseFunction } from '../../base-function';
+
+export class Indirect extends BaseFunction {
+ override calculate(refText: FunctionVariantType, a1?: FunctionVariantType) {
+ return new CellReferenceObject('A5');
+ }
+}
diff --git a/packages/engine-formula/src/functions/offset.ts b/packages/engine-formula/src/functions/lookup/offset/offset.ts
similarity index 56%
rename from packages/engine-formula/src/functions/offset.ts
rename to packages/engine-formula/src/functions/lookup/offset/offset.ts
index 9c26a9ec57..83dcfe9cd6 100644
--- a/packages/engine-formula/src/functions/offset.ts
+++ b/packages/engine-formula/src/functions/lookup/offset/offset.ts
@@ -1,6 +1,6 @@
-import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import { CellReferenceObject } from '../engine/reference-object/cell-reference-object';
-import { BaseFunction } from './base-function';
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { CellReferenceObject } from '../../../engine/reference-object/cell-reference-object';
+import { BaseFunction } from '../../base-function';
export class Offset extends BaseFunction {
override calculate(
diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.ts
new file mode 100644
index 0000000000..95cfd03c06
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/function-map.ts
@@ -0,0 +1,12 @@
+import { FUNCTION_NAMES_MATH } from './function-names';
+import { Power } from './power/power';
+import { Sum } from './sum/sum';
+import { Sumif } from './sumif/sumif';
+import { Sumifs } from './sumifs/sumifs';
+
+export const functionMath = [
+ [Sum, FUNCTION_NAMES_MATH.SUM],
+ [Sumif, FUNCTION_NAMES_MATH.SUMIF],
+ [Sumifs, FUNCTION_NAMES_MATH.SUMIFS],
+ [Power, FUNCTION_NAMES_MATH.POWER],
+];
diff --git a/packages/engine-formula/src/functions/math/function-names.ts b/packages/engine-formula/src/functions/math/function-names.ts
index be0c7f309a..f714f295e5 100644
--- a/packages/engine-formula/src/functions/math/function-names.ts
+++ b/packages/engine-formula/src/functions/math/function-names.ts
@@ -1,12 +1,6 @@
-import { Sumif } from './sumif/sumif';
-import { Sumifs } from './sumifs/sumifs';
-
export enum FUNCTION_NAMES_MATH {
+ SUM = 'SUM',
SUMIF = 'SUMIF',
SUMIFS = 'SUMIFS',
+ POWER = 'POWER',
}
-
-export const functionMath = [
- [Sumif, FUNCTION_NAMES_MATH.SUMIF],
- [Sumifs, FUNCTION_NAMES_MATH.SUMIFS],
-];
diff --git a/packages/engine-formula/src/functions/math/power/power.ts b/packages/engine-formula/src/functions/math/power/power.ts
new file mode 100644
index 0000000000..6994c09c82
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/power/power.ts
@@ -0,0 +1,10 @@
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { BaseFunction } from '../../base-function';
+
+export class Power extends BaseFunction {
+ override calculate(numberVar: FunctionVariantType, powerVar: FunctionVariantType) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+}
diff --git a/packages/engine-formula/src/functions/sum.ts b/packages/engine-formula/src/functions/math/sum/sum.ts
similarity index 72%
rename from packages/engine-formula/src/functions/sum.ts
rename to packages/engine-formula/src/functions/math/sum/sum.ts
index c6b0d1e6bb..533d6a98e4 100644
--- a/packages/engine-formula/src/functions/sum.ts
+++ b/packages/engine-formula/src/functions/math/sum/sum.ts
@@ -1,10 +1,10 @@
-import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../engine/other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import type { ArrayValueObject } from '../engine/value-object/array-value-object';
-import type { BaseValueObject } from '../engine/value-object/base-value-object';
-import { NumberValueObject } from '../engine/value-object/primitive-object';
-import { BaseFunction } from './base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
export class Sum extends BaseFunction {
override calculate(...variants: FunctionVariantType[]) {
diff --git a/packages/engine-formula/src/functions/meta/compare.ts b/packages/engine-formula/src/functions/meta/compare/compare.ts
similarity index 78%
rename from packages/engine-formula/src/functions/meta/compare.ts
rename to packages/engine-formula/src/functions/meta/compare/compare.ts
index 8872877055..7a2189c433 100644
--- a/packages/engine-formula/src/functions/meta/compare.ts
+++ b/packages/engine-formula/src/functions/meta/compare/compare.ts
@@ -1,9 +1,9 @@
-import { ErrorType } from '../../basics/error-type';
-import { compareToken } from '../../basics/token';
-import { ErrorValueObject } from '../../engine/other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
-import type { BaseValueObject } from '../../engine/value-object/base-value-object';
-import { BaseFunction } from '../base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { compareToken } from '../../../basics/token';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
export class Compare extends BaseFunction {
private _compareType: compareToken = compareToken.EQUALS;
diff --git a/packages/engine-formula/src/functions/meta/divided.ts b/packages/engine-formula/src/functions/meta/divided/divided.ts
similarity index 78%
rename from packages/engine-formula/src/functions/meta/divided.ts
rename to packages/engine-formula/src/functions/meta/divided/divided.ts
index 1f9677bb42..398b1a72da 100644
--- a/packages/engine-formula/src/functions/meta/divided.ts
+++ b/packages/engine-formula/src/functions/meta/divided/divided.ts
@@ -1,8 +1,8 @@
-import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../engine/other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
-import type { BaseValueObject } from '../../engine/value-object/base-value-object';
-import { BaseFunction } from '../base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
export class Divided extends BaseFunction {
override calculate(variant1: FunctionVariantType, variant2: FunctionVariantType) {
diff --git a/packages/engine-formula/src/functions/meta/function-map.ts b/packages/engine-formula/src/functions/meta/function-map.ts
new file mode 100644
index 0000000000..24b7874f30
--- /dev/null
+++ b/packages/engine-formula/src/functions/meta/function-map.ts
@@ -0,0 +1,16 @@
+import { Compare } from './compare/compare';
+import { Divided } from './divided/divided';
+import { FUNCTION_NAMES_META } from './function-names';
+import { Minus } from './minus/minus';
+import { Multiply } from './multiply/multiply';
+import { Plus } from './plus/plus';
+import { Union } from './union/union';
+
+export const functionMeta = [
+ [Compare, FUNCTION_NAMES_META.COMPARE],
+ [Divided, FUNCTION_NAMES_META.DIVIDED],
+ [Minus, FUNCTION_NAMES_META.MINUS],
+ [Multiply, FUNCTION_NAMES_META.MULTIPLY],
+ [Plus, FUNCTION_NAMES_META.PLUS],
+ [Union, FUNCTION_NAMES_META.UNION],
+];
diff --git a/packages/engine-formula/src/functions/meta/function-names.ts b/packages/engine-formula/src/functions/meta/function-names.ts
new file mode 100644
index 0000000000..219d5ada7e
--- /dev/null
+++ b/packages/engine-formula/src/functions/meta/function-names.ts
@@ -0,0 +1,8 @@
+export enum FUNCTION_NAMES_META {
+ COMPARE = 'COMPARE',
+ DIVIDED = 'DIVIDED',
+ MINUS = 'MINUS',
+ MULTIPLY = 'MULTIPLY',
+ PLUS = 'PLUS',
+ UNION = 'UNION',
+}
diff --git a/packages/engine-formula/src/functions/meta/minus.ts b/packages/engine-formula/src/functions/meta/minus.ts
deleted file mode 100644
index 796e467e8f..0000000000
--- a/packages/engine-formula/src/functions/meta/minus.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../engine/other-object/error-value-object';
-import type { FunctionVariantType } from '../../engine/reference-object/base-reference-object';
-import type { BaseValueObject } from '../../engine/value-object/base-value-object';
-import { BaseFunction } from '../base-function';
-
-export class Minus extends BaseFunction {
- override calculate(variant1: FunctionVariantType, variant2: FunctionVariantType) {
- if (variant1.isErrorObject() || variant2.isErrorObject()) {
- return ErrorValueObject.create(ErrorType.VALUE);
- }
-
- return (variant1 as BaseValueObject).minus(variant2 as BaseValueObject);
- }
-}
diff --git a/packages/engine-formula/src/functions/meta/minus/minus.ts b/packages/engine-formula/src/functions/meta/minus/minus.ts
new file mode 100644
index 0000000000..23a7f3a85b
--- /dev/null
+++ b/packages/engine-formula/src/functions/meta/minus/minus.ts
@@ -0,0 +1,15 @@
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Minus extends BaseFunction {
+ override calculate(variant1: FunctionVariantType, variant2: FunctionVariantType) {
+ if (variant1.isErrorObject() || variant2.isErrorObject()) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ return (variant1 as BaseValueObject).minus(variant2 as BaseValueObject);
+ }
+}
diff --git a/packages/engine-formula/src/functions/meta/multiply.ts b/packages/engine-formula/src/functions/meta/multiply/multiply.ts
similarity index 76%
rename from packages/engine-formula/src/functions/meta/multiply.ts
rename to packages/engine-formula/src/functions/meta/multiply/multiply.ts
index e83dda3fb0..62cf391cd6 100644
--- a/packages/engine-formula/src/functions/meta/multiply.ts
+++ b/packages/engine-formula/src/functions/meta/multiply/multiply.ts
@@ -1,8 +1,8 @@
-import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../engine/other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
-import type { BaseValueObject } from '../../engine/value-object/base-value-object';
-import { BaseFunction } from '../base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
export class Multiply extends BaseFunction {
override calculate(variant1: FunctionVariantType, variant2: FunctionVariantType) {
diff --git a/packages/engine-formula/src/functions/meta/plus.ts b/packages/engine-formula/src/functions/meta/plus/plus.ts
similarity index 76%
rename from packages/engine-formula/src/functions/meta/plus.ts
rename to packages/engine-formula/src/functions/meta/plus/plus.ts
index 28548cc271..cf4096b60e 100644
--- a/packages/engine-formula/src/functions/meta/plus.ts
+++ b/packages/engine-formula/src/functions/meta/plus/plus.ts
@@ -1,8 +1,8 @@
-import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../engine/other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
-import type { BaseValueObject } from '../../engine/value-object/base-value-object';
-import { BaseFunction } from '../base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
export class Plus extends BaseFunction {
override calculate(variant1: FunctionVariantType, variant2: FunctionVariantType) {
diff --git a/packages/engine-formula/src/functions/meta/union.ts b/packages/engine-formula/src/functions/meta/union/union.ts
similarity index 78%
rename from packages/engine-formula/src/functions/meta/union.ts
rename to packages/engine-formula/src/functions/meta/union/union.ts
index c33c6882ee..a33e323657 100644
--- a/packages/engine-formula/src/functions/meta/union.ts
+++ b/packages/engine-formula/src/functions/meta/union/union.ts
@@ -1,8 +1,8 @@
-import { ErrorType } from '../../basics/error-type';
-import { compareToken } from '../../basics/token';
-import { ErrorValueObject } from '../../engine/other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
-import { BaseFunction } from '../base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { compareToken } from '../../../basics/token';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { BaseFunction } from '../../base-function';
export class Union extends BaseFunction {
private _compareType: compareToken = compareToken.EQUALS;
diff --git a/packages/engine-formula/src/functions/power.ts b/packages/engine-formula/src/functions/power.ts
deleted file mode 100644
index 59a483f459..0000000000
--- a/packages/engine-formula/src/functions/power.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../engine/other-object/error-value-object';
-import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import { BaseFunction } from './base-function';
-
-export class Power extends BaseFunction {
- override calculate(numberVar: FunctionVariantType, powerVar: FunctionVariantType) {
- return ErrorValueObject.create(ErrorType.VALUE);
- }
-}
diff --git a/packages/engine-formula/src/functions/average.ts b/packages/engine-formula/src/functions/statistical/average/average.ts
similarity index 53%
rename from packages/engine-formula/src/functions/average.ts
rename to packages/engine-formula/src/functions/statistical/average/average.ts
index bcba4f76ce..c8ddf89fb4 100644
--- a/packages/engine-formula/src/functions/average.ts
+++ b/packages/engine-formula/src/functions/statistical/average/average.ts
@@ -1,17 +1,18 @@
-import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
-import { ErrorValueObject } from '../engine/other-object/error-value-object';
-import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import type { BaseValueObject } from '../engine/value-object/base-value-object';
-import { IFunctionService } from '../services/function.service';
-import { BaseFunction } from './base-function';
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { IFunctionService } from '../../../services/function.service';
+import { BaseFunction } from '../../base-function';
+import { FUNCTION_NAMES_MATH } from '../../math/function-names';
+import { FUNCTION_NAMES_STATISTICAL } from '../function-names';
export class Average extends BaseFunction {
override calculate(...variants: FunctionVariantType[]) {
const functionService = this.accessor.get(IFunctionService);
- const accumulatorSum = functionService.getExecutor(FUNCTION_NAMES.SUM)?.calculate(...variants);
- const accumulatorCount = functionService.getExecutor(FUNCTION_NAMES.COUNT)?.calculate(...variants);
+ const accumulatorSum = functionService.getExecutor(FUNCTION_NAMES_MATH.SUM)?.calculate(...variants);
+ const accumulatorCount = functionService.getExecutor(FUNCTION_NAMES_STATISTICAL.COUNT)?.calculate(...variants);
//TODO@DR-Univer: accumulatorCount should be calculated by numeric type count instead of all counts
if (
diff --git a/packages/engine-formula/src/functions/count.ts b/packages/engine-formula/src/functions/statistical/count/count.ts
similarity index 73%
rename from packages/engine-formula/src/functions/count.ts
rename to packages/engine-formula/src/functions/statistical/count/count.ts
index 2b2882d992..a92b85da86 100644
--- a/packages/engine-formula/src/functions/count.ts
+++ b/packages/engine-formula/src/functions/statistical/count/count.ts
@@ -1,8 +1,8 @@
-import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import type { ArrayValueObject } from '../engine/value-object/array-value-object';
-import type { BaseValueObject } from '../engine/value-object/base-value-object';
-import { NumberValueObject } from '../engine/value-object/primitive-object';
-import { BaseFunction } from './base-function';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
export class Count extends BaseFunction {
override calculate(...variants: FunctionVariantType[]) {
diff --git a/packages/engine-formula/src/functions/statistical/function-map.ts b/packages/engine-formula/src/functions/statistical/function-map.ts
new file mode 100644
index 0000000000..93e866ca5d
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/function-map.ts
@@ -0,0 +1,12 @@
+import { Average } from './average/average';
+import { Count } from './count/count';
+import { FUNCTION_NAMES_STATISTICAL } from './function-names';
+import { Max } from './max/max';
+import { Min } from './min/min';
+
+export const functionStatistical = [
+ [Average, FUNCTION_NAMES_STATISTICAL.AVERAGE],
+ [Count, FUNCTION_NAMES_STATISTICAL.COUNT],
+ [Max, FUNCTION_NAMES_STATISTICAL.MAX],
+ [Min, FUNCTION_NAMES_STATISTICAL.MIN],
+];
diff --git a/packages/engine-formula/src/functions/statistical/function-names.ts b/packages/engine-formula/src/functions/statistical/function-names.ts
index 23c314b8a3..33cbeea090 100644
--- a/packages/engine-formula/src/functions/statistical/function-names.ts
+++ b/packages/engine-formula/src/functions/statistical/function-names.ts
@@ -1,3 +1,6 @@
-export enum FUNCTION_NAMES_STATISTICAL {}
-
-export const functionStatistical = [];
+export enum FUNCTION_NAMES_STATISTICAL {
+ AVERAGE = 'AVERAGE',
+ COUNT = 'COUNT',
+ MAX = 'MAX',
+ MIN = 'MIN',
+}
diff --git a/packages/engine-formula/src/functions/max.ts b/packages/engine-formula/src/functions/statistical/max/max.ts
similarity index 74%
rename from packages/engine-formula/src/functions/max.ts
rename to packages/engine-formula/src/functions/statistical/max/max.ts
index b0401379a6..f5d589afed 100644
--- a/packages/engine-formula/src/functions/max.ts
+++ b/packages/engine-formula/src/functions/statistical/max/max.ts
@@ -1,10 +1,10 @@
-import { compareToken } from '../basics/token';
-import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import type { ArrayValueObject } from '../engine/value-object/array-value-object';
-import type { BaseValueObject } from '../engine/value-object/base-value-object';
-import type { BooleanValueObject } from '../engine/value-object/primitive-object';
-import { NumberValueObject } from '../engine/value-object/primitive-object';
-import { BaseFunction } from './base-function';
+import { compareToken } from '../../../basics/token';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import type { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
export class Max extends BaseFunction {
override calculate(...variants: FunctionVariantType[]) {
diff --git a/packages/engine-formula/src/functions/min.ts b/packages/engine-formula/src/functions/statistical/min/min.ts
similarity index 74%
rename from packages/engine-formula/src/functions/min.ts
rename to packages/engine-formula/src/functions/statistical/min/min.ts
index 20a5115736..03b4b12c79 100644
--- a/packages/engine-formula/src/functions/min.ts
+++ b/packages/engine-formula/src/functions/statistical/min/min.ts
@@ -1,10 +1,10 @@
-import { compareToken } from '../basics/token';
-import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
-import type { ArrayValueObject } from '../engine/value-object/array-value-object';
-import type { BaseValueObject } from '../engine/value-object/base-value-object';
-import type { BooleanValueObject } from '../engine/value-object/primitive-object';
-import { NumberValueObject } from '../engine/value-object/primitive-object';
-import { BaseFunction } from './base-function';
+import { compareToken } from '../../../basics/token';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import type { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
export class Min extends BaseFunction {
override calculate(...variants: FunctionVariantType[]) {
diff --git a/packages/engine-formula/src/functions/text/function-map.ts b/packages/engine-formula/src/functions/text/function-map.ts
new file mode 100644
index 0000000000..69518d1dfc
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/function-map.ts
@@ -0,0 +1 @@
+export const functionText = [];
diff --git a/packages/engine-formula/src/functions/text/function-names.ts b/packages/engine-formula/src/functions/text/function-names.ts
index ff675c0fca..336ed24ebf 100644
--- a/packages/engine-formula/src/functions/text/function-names.ts
+++ b/packages/engine-formula/src/functions/text/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_TEXT {}
-
-export const functionText = [];
diff --git a/packages/engine-formula/src/functions/univer/function-map.ts b/packages/engine-formula/src/functions/univer/function-map.ts
new file mode 100644
index 0000000000..9240f214d2
--- /dev/null
+++ b/packages/engine-formula/src/functions/univer/function-map.ts
@@ -0,0 +1 @@
+export const functionUniver = [];
diff --git a/packages/engine-formula/src/functions/univer/function-names.ts b/packages/engine-formula/src/functions/univer/function-names.ts
index af6756f3ad..0ee1ec1cb8 100644
--- a/packages/engine-formula/src/functions/univer/function-names.ts
+++ b/packages/engine-formula/src/functions/univer/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_UNIVER {}
-
-export const functionUniver = [];
diff --git a/packages/engine-formula/src/functions/web/function-map.ts b/packages/engine-formula/src/functions/web/function-map.ts
new file mode 100644
index 0000000000..a72d344951
--- /dev/null
+++ b/packages/engine-formula/src/functions/web/function-map.ts
@@ -0,0 +1 @@
+export const functionWeb = [];
diff --git a/packages/engine-formula/src/functions/web/function-names.ts b/packages/engine-formula/src/functions/web/function-names.ts
index 3932ff51b4..418d80c1c5 100644
--- a/packages/engine-formula/src/functions/web/function-names.ts
+++ b/packages/engine-formula/src/functions/web/function-names.ts
@@ -1,3 +1 @@
export enum FUNCTION_NAMES_WEB {}
-
-export const functionWeb = [];
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index e8e65d1953..5accedb448 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -13,7 +13,8 @@ export type {
} from './basics/common';
export { isInDirtyRange } from './basics/dirty';
export { ErrorType } from './basics/error-type';
-export { FUNCTION_NAMES, FunctionType, type IFunctionInfo, type IFunctionParam } from './basics/function';
+export { FunctionType, type IFunctionInfo, type IFunctionParam } from './basics/function';
+export { type IFunctionNames } from './basics/function';
export { includeFormulaLexerToken, isFormulaLexerToken, normalizeSheetName } from './basics/match-token';
export { matchToken } from './basics/token';
export { compareToken } from './basics/token';
@@ -46,8 +47,22 @@ export { BaseValueObject } from './engine/value-object/base-value-object';
export { NumberValueObject } from './engine/value-object/primitive-object';
export { BooleanValueObject } from './engine/value-object/primitive-object';
export { StringValueObject } from './engine/value-object/primitive-object';
+export { FUNCTION_NAMES_ARRAY } from './functions/array/function-names';
export { BaseFunction } from './functions/base-function';
+export { FUNCTION_NAMES_COMPATIBILITY } from './functions/compatibility/function-names';
+export { FUNCTION_NAMES_CUBE } from './functions/cube/function-names';
+export { FUNCTION_NAMES_DATABASE } from './functions/database/function-names';
+export { FUNCTION_NAMES_DATE } from './functions/date/function-names';
+export { FUNCTION_NAMES_ENGINEERING } from './functions/engineering/function-names';
+export { FUNCTION_NAMES_FINANCIAL } from './functions/financial/function-names';
+export { FUNCTION_NAMES_INFORMATION } from './functions/information/function-names';
+export { FUNCTION_NAMES_LOGICAL } from './functions/logical/function-names';
+export { FUNCTION_NAMES_LOOKUP } from './functions/lookup/function-names';
export { FUNCTION_NAMES_MATH } from './functions/math/function-names';
+export { FUNCTION_NAMES_STATISTICAL } from './functions/statistical/function-names';
+export { FUNCTION_NAMES_TEXT } from './functions/text/function-names';
+export { FUNCTION_NAMES_UNIVER } from './functions/univer/function-names';
+export { FUNCTION_NAMES_WEB } from './functions/web/function-names';
export { FormulaDataModel } from './models/formula-data.model';
export { initSheetFormulaData } from './models/formula-data.model';
export { BaseFormulaEnginePlugin } from './plugin';
diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.ts
index 3cb0390cda..4aa456fd46 100644
--- a/packages/engine-formula/src/models/formula-data.model.ts
+++ b/packages/engine-formula/src/models/formula-data.model.ts
@@ -14,6 +14,12 @@ import type {
} from '../basics/common';
import { LexerTreeBuilder } from '../engine/analysis/lexer';
+export interface IFormulaIdMap {
+ f: string;
+ r: number;
+ c: number;
+}
+
export class FormulaDataModel extends Disposable {
private _formulaData: IFormulaData = {};
@@ -240,8 +246,8 @@ export class FormulaDataModel extends Disposable {
updateFormulaData(unitId: string, sheetId: string, cellValue: ObjectMatrixPrimitiveType<ICellData | null>) {
const cellMatrix = new ObjectMatrix(cellValue);
- const formulaIdMap = new Map<string, { f: string; r: number; c: number }>(); // Connect the formula and ID
- const deleteFormulaIdMap = new Map<string, string | { f: string; r: number; c: number }>();
+ const formulaIdMap = this.getFormulaIdMap(unitId, sheetId); // Connect the formula and ID
+ const deleteFormulaIdMap = new Map<string, string | IFormulaIdMap>();
const formulaData = this._formulaData;
if (formulaData[unitId] == null) {
@@ -361,6 +367,33 @@ export class FormulaDataModel extends Disposable {
getFormulaDataItem(row: number, column: number, sheetId: string, unitId: string) {
return this._formulaData?.[unitId]?.[sheetId]?.[row]?.[column];
}
+
+ getFormulaIdMap(unitId: string, sheetId: string): Map<string, IFormulaIdMap> {
+ const formulaIdMap = new Map<string, IFormulaIdMap>(); // Connect the formula and ID
+
+ const formulaData = this._formulaData;
+ if (formulaData[unitId] == null) {
+ return formulaIdMap;
+ }
+ const workbookFormulaData = formulaData[unitId];
+
+ if (workbookFormulaData[sheetId] == null) {
+ return formulaIdMap;
+ }
+
+ const sheetFormulaDataMatrix = new ObjectMatrix(workbookFormulaData[sheetId]);
+
+ sheetFormulaDataMatrix.forValue((r, c, cell) => {
+ const formulaString = cell?.f || '';
+ const formulaId = cell?.si || '';
+
+ if (isFormulaString(formulaString) && isFormulaId(formulaId)) {
+ formulaIdMap.set(formulaId, { f: formulaString, r, c });
+ }
+ });
+
+ return formulaIdMap;
+ }
}
export function initSheetFormulaData(
diff --git a/packages/engine-formula/src/services/function.service.ts b/packages/engine-formula/src/services/function.service.ts
index 528cb0db79..c9076c0173 100644
--- a/packages/engine-formula/src/services/function.service.ts
+++ b/packages/engine-formula/src/services/function.service.ts
@@ -2,7 +2,7 @@ import type { Nullable } from '@univerjs/core';
import { Disposable } from '@univerjs/core';
import { createIdentifier } from '@wendellhu/redi';
-import type { FUNCTION_NAMES, IFunctionInfo } from '../basics/function';
+import type { IFunctionInfo, IFunctionNames } from '../basics/function';
import type { BaseFunction } from '../functions/base-function';
export interface IFunctionService {
@@ -11,35 +11,35 @@ export interface IFunctionService {
*/
registerExecutors(...functions: BaseFunction[]): void;
- getExecutors(): Map<string, BaseFunction>;
+ getExecutors(): Map<IFunctionNames, BaseFunction>;
/**
* Obtain the operator of the function to reuse the calculation logic.
* The argument type accepted by the function is: FunctionVariantType.
* For instance, the sum formula capability is needed for the statistics bar.
* You can obtain the calculation result by using
- * const sum = formulaService.getExecutor(FUNCTION_NAMES.SUM);
+ * const sum = formulaService.getExecutor(FUNCTION_NAMES_MATH.SUM);
* sum.calculate(new RangeReferenceObject(range, sheetId, unitId), ref2, re3).
* @param functionName Function name, which can be obtained through the FUNCTION_NAMES enumeration.
* @returns
*/
- getExecutor(functionToken: string): Nullable<BaseFunction>;
+ getExecutor(functionToken: IFunctionNames): Nullable<BaseFunction>;
- hasExecutor(functionToken: string): boolean;
+ hasExecutor(functionToken: IFunctionNames): boolean;
registerDescriptions(...functions: IFunctionInfo[]): void;
- getDescriptions(): Map<string, IFunctionInfo>;
+ getDescriptions(): Map<IFunctionNames, IFunctionInfo>;
- getDescription(functionToken: string): Nullable<IFunctionInfo>;
+ getDescription(functionToken: IFunctionNames): Nullable<IFunctionInfo>;
- hasDescription(functionToken: string): boolean;
+ hasDescription(functionToken: IFunctionNames): boolean;
}
export class FunctionService extends Disposable implements IFunctionService {
- private _functionExecutors: Map<string, BaseFunction> = new Map();
+ private _functionExecutors: Map<IFunctionNames, BaseFunction> = new Map();
- private _functionDescriptions: Map<string, IFunctionInfo> = new Map();
+ private _functionDescriptions: Map<IFunctionNames, IFunctionInfo> = new Map();
override dispose(): void {
this._functionExecutors.clear();
@@ -57,11 +57,11 @@ export class FunctionService extends Disposable implements IFunctionService {
return this._functionExecutors;
}
- getExecutor(functionToken: string | FUNCTION_NAMES) {
+ getExecutor(functionToken: IFunctionNames) {
return this._functionExecutors.get(functionToken);
}
- hasExecutor(functionToken: string | FUNCTION_NAMES) {
+ hasExecutor(functionToken: IFunctionNames) {
return this._functionExecutors.has(functionToken);
}
@@ -76,11 +76,11 @@ export class FunctionService extends Disposable implements IFunctionService {
return this._functionDescriptions;
}
- getDescription(functionToken: string) {
+ getDescription(functionToken: IFunctionNames) {
return this._functionDescriptions.get(functionToken);
}
- hasDescription(functionToken: string) {
+ hasDescription(functionToken: IFunctionNames) {
return this._functionDescriptions.has(functionToken);
}
}
diff --git a/packages/sheets-formula/src/controllers/__tests__/formula-auto-fill.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/formula-auto-fill.controller.spec.ts
index 5fda25cc8e..cb921d1c94 100644
--- a/packages/sheets-formula/src/controllers/__tests__/formula-auto-fill.controller.spec.ts
+++ b/packages/sheets-formula/src/controllers/__tests__/formula-auto-fill.controller.spec.ts
@@ -7,7 +7,6 @@ import {
ThemeService,
UndoCommand,
} from '@univerjs/core';
-import { LexerTreeBuilder } from '@univerjs/engine-formula';
import {
AddWorksheetMergeMutation,
NORMAL_SELECTION_PLUGIN_NAME,
@@ -54,7 +53,6 @@ describe('Test auto fill with formula', () => {
[SheetInterceptorService],
[ISelectionRenderService, { useClass: SelectionRenderService }],
[AutoFillController],
- [LexerTreeBuilder],
[IAutoFillService, { useClass: AutoFillService }],
[IShortcutService, { useClass: DesktopShortcutService }],
[IPlatformService, { useClass: DesktopPlatformService }],
@@ -190,7 +188,6 @@ describe('Test auto fill with formula', () => {
// "si": "d4_488"
// },
// {
- // "f": "=SUM(B2)",
// "si": "d4_488"
// },
// {
@@ -218,7 +215,7 @@ describe('Test auto fill with formula', () => {
let D3 = values && values[2][2];
expect(C1?.f).toStrictEqual('=SUM(B1)');
- expect(C2?.f).toStrictEqual('=SUM(B2)');
+ expect(C2?.f).toBeUndefined();
expect(C1?.si).toEqual(D1?.si);
expect(B2?.si).toEqual(C2?.si);
@@ -256,7 +253,7 @@ describe('Test auto fill with formula', () => {
D3 = values && values[2][2];
expect(C1?.f).toStrictEqual('=SUM(B1)');
- expect(C2?.f).toStrictEqual('=SUM(B2)');
+ expect(C2?.f).toBeUndefined();
expect(C1?.si).toEqual(D1?.si);
expect(B2?.si).toEqual(C2?.si);
diff --git a/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts
index 221f4d0e4e..154027b1ee 100644
--- a/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts
+++ b/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts
@@ -25,7 +25,6 @@ describe('Test paste with formula', () => {
beforeEach(() => {
const testBed = createCommandTestBed(undefined, [
[ISelectionRenderService, { useClass: SelectionRenderService }],
- [LexerTreeBuilder],
]);
univer = testBed.univer;
get = testBed.get;
diff --git a/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts b/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts
index 085ce4b990..44df30d030 100644
--- a/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts
+++ b/packages/sheets-formula/src/controllers/formula-auto-fill.controller.ts
@@ -71,12 +71,23 @@ export class FormulaAutoFillController extends Disposable {
const checkFormula = isFormulaString(originalFormula);
const checkFormulaId = isFormulaId(originalFormulaId);
- if (checkFormula) {
+ if (checkFormulaId) {
+ d.si = originalFormulaId;
+ d.f = null;
+ d.v = null;
+ d.p = null;
+
+ if (direction === Direction.DOWN || direction === Direction.RIGHT) {
+ applyData.push(d);
+ } else {
+ applyData.unshift(d);
+ }
+ } else if (checkFormula) {
// The first position setting formula and formulaId
let formulaId = formulaIdMap.get(index);
if (!formulaId) {
- formulaId = checkFormulaId ? originalFormulaId : Tools.generateRandomId(6);
+ formulaId = Tools.generateRandomId(6);
formulaIdMap.set(index, formulaId);
const { offsetX, offsetY } = directionToOffset(step, direction);
@@ -98,17 +109,6 @@ export class FormulaAutoFillController extends Disposable {
d.p = null;
}
- if (direction === Direction.DOWN || direction === Direction.RIGHT) {
- applyData.push(d);
- } else {
- applyData.unshift(d);
- }
- } else if (checkFormulaId) {
- d.si = originalFormulaId;
- d.f = null;
- d.v = null;
- d.p = null;
-
if (direction === Direction.DOWN || direction === Direction.RIGHT) {
applyData.push(d);
} else {
diff --git a/packages/sheets-formula/src/services/description.service.ts b/packages/sheets-formula/src/services/description.service.ts
index 5a49b5fb98..1e59cc56bc 100644
--- a/packages/sheets-formula/src/services/description.service.ts
+++ b/packages/sheets-formula/src/services/description.service.ts
@@ -1,5 +1,5 @@
import { LocaleService } from '@univerjs/core';
-import type { IFunctionInfo } from '@univerjs/engine-formula';
+import type { IFunctionInfo, IFunctionNames } from '@univerjs/engine-formula';
import { IFunctionService } from '@univerjs/engine-formula';
import type { IDisposable } from '@wendellhu/redi';
import { createIdentifier, Inject } from '@wendellhu/redi';
@@ -16,7 +16,7 @@ export interface IDescriptionService {
/**
* get all descriptions
*/
- getDescriptions(): Map<string, IFunctionInfo>;
+ getDescriptions(): Map<IFunctionNames, IFunctionInfo>;
hasFunction(searchText: string): boolean;
diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.ts
index c3f03f1453..9c4d28a97a 100644
--- a/packages/sheets-formula/src/services/function-list/math.ts
+++ b/packages/sheets-formula/src/services/function-list/math.ts
@@ -1,9 +1,9 @@
import type { IFunctionInfo } from '@univerjs/engine-formula';
-import { FUNCTION_NAMES, FUNCTION_NAMES_MATH, FunctionType } from '@univerjs/engine-formula';
+import { FUNCTION_NAMES_MATH, FunctionType } from '@univerjs/engine-formula';
export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
- functionName: FUNCTION_NAMES.SUM,
+ functionName: FUNCTION_NAMES_MATH.SUM,
aliasFunctionName: 'formula.functionList.SUM.aliasFunctionName',
functionType: FunctionType.Math,
description: 'formula.functionList.SUM.description',
diff --git a/packages/sheets-formula/src/services/function-list/statistical.ts b/packages/sheets-formula/src/services/function-list/statistical.ts
index 0298a77246..840ec65fc2 100644
--- a/packages/sheets-formula/src/services/function-list/statistical.ts
+++ b/packages/sheets-formula/src/services/function-list/statistical.ts
@@ -1,9 +1,9 @@
import type { IFunctionInfo } from '@univerjs/engine-formula';
-import { FUNCTION_NAMES, FunctionType } from '@univerjs/engine-formula';
+import { FUNCTION_NAMES_STATISTICAL, FunctionType } from '@univerjs/engine-formula';
export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
{
- functionName: FUNCTION_NAMES.AVERAGE,
+ functionName: FUNCTION_NAMES_STATISTICAL.AVERAGE,
aliasFunctionName: 'formula.functionList.AVERAGE.aliasFunctionName',
functionType: FunctionType.Statistical,
description: 'formula.functionList.AVERAGE.description',
@@ -26,7 +26,7 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
],
},
{
- functionName: FUNCTION_NAMES.MAX,
+ functionName: FUNCTION_NAMES_STATISTICAL.MAX,
aliasFunctionName: 'formula.functionList.MAX.aliasFunctionName',
functionType: FunctionType.Statistical,
description: 'formula.functionList.MAX.description',
@@ -49,7 +49,7 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
],
},
{
- functionName: FUNCTION_NAMES.COUNT,
+ functionName: FUNCTION_NAMES_STATISTICAL.COUNT,
aliasFunctionName: 'formula.functionList.COUNT.aliasFunctionName',
functionType: FunctionType.Statistical,
description: 'formula.functionList.COUNT.description',
@@ -72,7 +72,7 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
],
},
{
- functionName: FUNCTION_NAMES.MIN,
+ functionName: FUNCTION_NAMES_STATISTICAL.MIN,
aliasFunctionName: 'formula.functionList.MIN.aliasFunctionName',
functionType: FunctionType.Statistical,
description: 'formula.functionList.MIN.description',
diff --git a/packages/sheets-ui/src/services/status-bar.service.ts b/packages/sheets-ui/src/services/status-bar.service.ts
index 0de338fed4..a69ac105fe 100644
--- a/packages/sheets-ui/src/services/status-bar.service.ts
+++ b/packages/sheets-ui/src/services/status-bar.service.ts
@@ -1,5 +1,6 @@
import type { Nullable } from '@univerjs/core';
-import { FUNCTION_NAMES } from '@univerjs/engine-formula';
+import type { IFunctionNames } from '@univerjs/engine-formula';
+import { FUNCTION_NAMES_MATH, FUNCTION_NAMES_STATISTICAL } from '@univerjs/engine-formula';
import type { IDisposable } from '@wendellhu/redi';
import { createIdentifier } from '@wendellhu/redi';
import type { Observable } from 'rxjs';
@@ -10,21 +11,21 @@ export interface IStatusBarService {
dispose(): void;
setState(param: IStatusBarServiceStatus | null): void;
getState(): Readonly<Nullable<IStatusBarServiceStatus>>;
- getFunctions(): Readonly<FUNCTION_NAMES[]>;
+ getFunctions(): Readonly<IFunctionNames[]>;
}
export type IStatusBarServiceStatus = Array<{
- func: FUNCTION_NAMES;
+ func: IFunctionNames;
value: number;
}>;
export class StatusBarService implements IStatusBarService, IDisposable {
private readonly _functions = [
- FUNCTION_NAMES.SUM,
- FUNCTION_NAMES.MAX,
- FUNCTION_NAMES.MIN,
- FUNCTION_NAMES.AVERAGE,
- FUNCTION_NAMES.COUNT,
+ FUNCTION_NAMES_MATH.SUM,
+ FUNCTION_NAMES_STATISTICAL.MAX,
+ FUNCTION_NAMES_STATISTICAL.MIN,
+ FUNCTION_NAMES_STATISTICAL.AVERAGE,
+ FUNCTION_NAMES_STATISTICAL.COUNT,
];
private readonly _state$ = new BehaviorSubject<Nullable<IStatusBarServiceStatus>>(null);
readonly state$ = this._state$.asObservable();
@@ -41,7 +42,7 @@ export class StatusBarService implements IStatusBarService, IDisposable {
return this._state$.getValue();
}
- getFunctions(): Readonly<FUNCTION_NAMES[]> {
+ getFunctions(): Readonly<IFunctionNames[]> {
return this._functions;
}
}
diff --git a/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx b/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx
index 62deab467e..d8ef74d702 100644
--- a/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx
+++ b/packages/sheets-ui/src/views/status-bar/CopyableStatisticItem.tsx
@@ -1,6 +1,11 @@
import { LocaleService } from '@univerjs/core';
import { MessageType, Tooltip } from '@univerjs/design';
-import { FUNCTION_NAMES } from '@univerjs/engine-formula';
+import type { IFunctionNames } from '@univerjs/engine-formula';
+import {
+ FUNCTION_NAMES_COMPATIBILITY,
+ FUNCTION_NAMES_MATH,
+ FUNCTION_NAMES_STATISTICAL,
+} from '@univerjs/engine-formula';
import { IClipboardInterfaceService, IMessageService } from '@univerjs/ui';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React from 'react';
@@ -8,18 +13,18 @@ import React from 'react';
import styles from './index.module.less';
export interface IStatisticItem {
- name: FUNCTION_NAMES;
+ name: IFunctionNames;
value: number;
show: boolean;
}
export const functionDisplayNames: FunctionNameMap = {
- [FUNCTION_NAMES.SUM]: 'statusbar.sum',
- [FUNCTION_NAMES.AVERAGE]: 'statusbar.average',
- [FUNCTION_NAMES.MIN]: 'statusbar.min',
- [FUNCTION_NAMES.MAX]: 'statusbar.max',
- [FUNCTION_NAMES.COUNT]: 'statusbar.count',
- [FUNCTION_NAMES.CONCATENATE]: 'concatenate',
+ [FUNCTION_NAMES_MATH.SUM]: 'statusbar.sum',
+ [FUNCTION_NAMES_STATISTICAL.AVERAGE]: 'statusbar.average',
+ [FUNCTION_NAMES_STATISTICAL.MIN]: 'statusbar.min',
+ [FUNCTION_NAMES_STATISTICAL.MAX]: 'statusbar.max',
+ [FUNCTION_NAMES_STATISTICAL.COUNT]: 'statusbar.count',
+ [FUNCTION_NAMES_COMPATIBILITY.CONCATENATE]: 'concatenate',
};
interface FunctionNameMap {
[key: string]: string;
@@ -41,7 +46,9 @@ export const CopyableStatisticItem: React.FC<IStatisticItem> = (item: IStatistic
return (
<Tooltip title={localeService.t('statusbar.clickToCopy')} placement="top">
<div key={item.name} className={styles.statisticItem} onClick={copyToClipboard}>
- <span>{`${localeService.t(functionDisplayNames?.[item.name] || item.name)}: ${formateValue}`}</span>
+ <span>{`${localeService.t(
+ functionDisplayNames?.[item.name as string] || (item.name as string)
+ )}: ${formateValue}`}</span>
</div>
</Tooltip>
);
diff --git a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx
index 7ca9c27b81..1653154a91 100644
--- a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx
+++ b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx
@@ -126,7 +126,7 @@ export const StatusBar = () => {
onChange={() => onChange && onChange(item)}
/>
<span>{`${localeService.t(
- functionDisplayNames?.[item.name] || item.name
+ functionDisplayNames?.[item.name as string] || (item.name as string)
)}: ${formatNumber(item.value)}`}</span>
</a>
))}