@univerjs/engine-formula 0.11.0 → 0.12.0-nightly.202511220628

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 (50) hide show
  1. package/lib/cjs/index.js +1 -7
  2. package/lib/es/index.js +10711 -9615
  3. package/lib/index.js +10711 -9615
  4. package/lib/types/basics/common.d.ts +20 -3
  5. package/lib/types/basics/function.d.ts +5 -1
  6. package/lib/types/basics/inverted-index-cache.d.ts +4 -3
  7. package/lib/types/basics/regex.d.ts +10 -1
  8. package/lib/types/basics/statistical.d.ts +53 -0
  9. package/lib/types/commands/mutations/set-array-formula-data.mutation.d.ts +2 -1
  10. package/lib/types/commands/mutations/set-defined-name.mutation.d.ts +1 -0
  11. package/lib/types/commands/mutations/set-image-formula-data.mutation.d.ts +9 -0
  12. package/lib/types/engine/analysis/lexer-tree-builder.d.ts +8 -0
  13. package/lib/types/engine/ast-node/base-ast-node.d.ts +1 -0
  14. package/lib/types/engine/ast-node/function-node.d.ts +4 -0
  15. package/lib/types/engine/ast-node/lambda-node.d.ts +2 -1
  16. package/lib/types/engine/ast-node/operator-node.d.ts +9 -2
  17. package/lib/types/engine/ast-node/reference-node.d.ts +11 -2
  18. package/lib/types/engine/reference-object/base-reference-object.d.ts +13 -6
  19. package/lib/types/engine/reference-object/multi-area-reference-object.d.ts +92 -0
  20. package/lib/types/engine/reference-object/table-reference-object.d.ts +86 -4
  21. package/lib/types/engine/value-object/array-value-object.d.ts +5 -0
  22. package/lib/types/engine/value-object/base-value-object.d.ts +3 -1
  23. package/lib/types/engine/value-object/primitive-object.d.ts +25 -3
  24. package/lib/types/functions/information/cell/index.d.ts +1 -2
  25. package/lib/types/functions/lookup/image/index.d.ts +8 -0
  26. package/lib/types/functions/lookup/offset/index.d.ts +1 -1
  27. package/lib/types/functions/math/aggregate/index.d.ts +14 -0
  28. package/lib/types/functions/math/base/index.d.ts +1 -2
  29. package/lib/types/functions/math/function-map.d.ts +1 -2
  30. package/lib/types/functions/math/subtotal/index.d.ts +5 -16
  31. package/lib/types/functions/math/sumproduct/index.d.ts +21 -0
  32. package/lib/types/functions/new-excel-functions.d.ts +2 -0
  33. package/lib/types/functions/statistical/large/index.d.ts +0 -1
  34. package/lib/types/functions/statistical/median/index.d.ts +0 -1
  35. package/lib/types/functions/statistical/mode-sngl/index.d.ts +0 -1
  36. package/lib/types/functions/statistical/percentile-exc/index.d.ts +0 -1
  37. package/lib/types/functions/statistical/percentile-inc/index.d.ts +0 -1
  38. package/lib/types/functions/statistical/quartile-exc/index.d.ts +0 -1
  39. package/lib/types/functions/statistical/quartile-inc/index.d.ts +0 -1
  40. package/lib/types/functions/statistical/small/index.d.ts +0 -1
  41. package/lib/types/functions/text/function-map.d.ts +1 -2
  42. package/lib/types/index.d.ts +7 -3
  43. package/lib/types/models/formula-data.model.d.ts +6 -1
  44. package/lib/types/services/current-data.service.d.ts +3 -1
  45. package/lib/types/services/defined-names.service.d.ts +3 -0
  46. package/lib/types/services/runtime.service.d.ts +13 -1
  47. package/lib/types/services/super-table.service.d.ts +6 -0
  48. package/lib/umd/index.js +1 -7
  49. package/package.json +5 -5
  50. package/LICENSE +0 -176
@@ -1,4 +1,5 @@
1
- import { BooleanNumber, ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, Nullable, ObjectMatrix, Styles } from '@univerjs/core';
1
+ import { ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, Nullable, ObjectMatrix, Styles } from '@univerjs/core';
2
+ import { IImageFormulaInfo } from '../engine/value-object/primitive-object';
2
3
  export declare const ERROR_VALUE_OBJECT_CLASS_TYPE = "errorValueObject";
3
4
  export declare const ASYNC_OBJECT_CLASS_TYPE = "asyncObject";
4
5
  export declare const REFERENCE_OBJECT_CLASS_TYPE = "referenceObject";
@@ -92,11 +93,27 @@ export interface IArrayFormulaRangeType {
92
93
  [sheetId: string]: IObjectMatrixPrimitiveType<IRange>;
93
94
  }>;
94
95
  }
96
+ export interface IArrayFormulaEmbeddedMap {
97
+ [unitId: string]: Nullable<{
98
+ [sheetId: string]: IObjectMatrixPrimitiveType<boolean>;
99
+ }>;
100
+ }
95
101
  export interface IFeatureDirtyRangeType {
96
102
  [unitId: string]: Nullable<{
97
103
  [sheetId: string]: IRange[];
98
104
  }>;
99
105
  }
106
+ export interface IRuntimeImageFormulaDataType extends IImageFormulaInfo {
107
+ unitId: string;
108
+ sheetId: string;
109
+ row: number;
110
+ column: number;
111
+ }
112
+ export interface IUnitImageFormulaDataType {
113
+ [unitId: string]: Nullable<{
114
+ [sheetId: string]: ObjectMatrix<Nullable<IImageFormulaInfo>>;
115
+ }>;
116
+ }
100
117
  export interface IArrayFormulaUnitCellType extends IRuntimeUnitDataPrimitiveType {
101
118
  }
102
119
  export interface IFormulaData {
@@ -139,7 +156,6 @@ export interface IOtherFormulaDataItem {
139
156
  }
140
157
  export interface ISuperTable {
141
158
  sheetId: string;
142
- hasCustomTitle: BooleanNumber;
143
159
  titleMap: Map<string, number>;
144
160
  range: IRange;
145
161
  }
@@ -147,7 +163,8 @@ export declare enum TableOptionType {
147
163
  ALL = "#All",
148
164
  DATA = "#Data",
149
165
  HEADERS = "#Headers",
150
- TOTALS = "#Totals"
166
+ TOTALS = "#Totals",
167
+ THIS_ROW = "#This Row"
151
168
  }
152
169
  export interface IUnitExcludedCell {
153
170
  [unitId: string]: Nullable<{
@@ -86,7 +86,11 @@ export declare enum FunctionType {
86
86
  /**
87
87
  * Defined name
88
88
  */
89
- DefinedName = 16
89
+ DefinedName = 16,
90
+ /**
91
+ * Super Table name
92
+ */
93
+ Table = 17
90
94
  }
91
95
  export interface IFunctionParam {
92
96
  /**
@@ -1,4 +1,5 @@
1
1
  import { NumericTuple } from '@flatten-js/interval-tree';
2
+ export declare const DEFAULT_EMPTY_CELL_KEY: unique symbol;
2
3
  export declare class InvertedIndexCache {
3
4
  /**
4
5
  * {
@@ -14,9 +15,9 @@ export declare class InvertedIndexCache {
14
15
  */
15
16
  private _cache;
16
17
  private _continueBuildingCache;
17
- set(unitId: string, sheetId: string, column: number, value: string | number | boolean | null, row: number, isForceUpdate?: boolean): void;
18
- getCellValuePositions(unitId: string, sheetId: string, column: number): Map<string | number | boolean | null, Set<number>> | undefined;
19
- getCellPositions(unitId: string, sheetId: string, column: number, value: string | number | boolean, rowsInCache: NumericTuple[]): number[] | undefined;
18
+ set(unitId: string, sheetId: string, column: number, value: string | number | boolean | null | symbol, row: number, isForceUpdate?: boolean): void;
19
+ getCellValuePositions(unitId: string, sheetId: string, column: number): Map<string | number | boolean | symbol | null, Set<number>> | undefined;
20
+ getCellPositions(unitId: string, sheetId: string, column: number, value: string | number | boolean | null | symbol, rowsInCache: NumericTuple[]): number[] | undefined;
20
21
  setContinueBuildingCache(unitId: string, sheetId: string, column: number, startRow: number, endRow: number): void;
21
22
  shouldContinueBuildingCache(unitId: string, sheetId: string, column: number, row: number): boolean;
22
23
  canUseCache(unitId: string, sheetId: string, column: number, rangeStartRow: number, rangeEndRow: number): {
@@ -35,7 +35,12 @@ export declare const REFERENCE_REGEX_SINGLE_COLUMN_PRECOMPILING: RegExp;
35
35
  export declare const REFERENCE_TABLE_ALL_COLUMN_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+$";
36
36
  export declare const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[((?<!#).)*\\]|\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#).)*\\]\\])+$";
37
37
  export declare const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[((?<!#).)*\\]\\s*?:\\s*?\\[((?<!#).)*\\]\\])?$|^((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#).)*\\]\\s*?:\\s*?\\[((?<!#).)*\\]\\])?$";
38
- export declare const SUPER_TABLE_COLUMN_REGEX = "[.*?]";
38
+ export declare const REFERENCE_TABLE_TITLE_ONLY_ANY_HASH_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+\\[\\s*#([^\\]]+)\\s*\\]$";
39
+ export declare const REFERENCE_TABLE_ALL_COLUMN_REGEX_PRECOMPILING: RegExp;
40
+ export declare const REFERENCE_TABLE_SINGLE_COLUMN_REGEX_PRECOMPILING: RegExp;
41
+ export declare const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX_PRECOMPILING: RegExp;
42
+ export declare const REFERENCE_TABLE_TITLE_ONLY_ANY_HASH_REGEX_PRECOMPILING: RegExp;
43
+ export declare const SUPER_TABLE_COLUMN_REGEX = "\\[[^\\]]*?]";
39
44
  export declare const SUPER_TABLE_COLUMN_REGEX_PRECOMPILING: RegExp;
40
45
  export declare const ARRAY_VALUE_REGEX = "{.*?}";
41
46
  export declare const ARRAY_VALUE_REGEX_PRECOMPILING: RegExp;
@@ -46,5 +51,9 @@ export declare function regexTestColumn(token: string): boolean;
46
51
  export declare function regexTestSingleRow(token: string): boolean;
47
52
  export declare function regexTestSingleColumn(token: string): boolean;
48
53
  export declare function regexTestSuperTableColumn(token: string): boolean;
54
+ export declare function regexTestReferenceTableAllColumn(token: string): boolean;
55
+ export declare function regexTestReferenceTableSingleColumn(token: string): boolean;
56
+ export declare function regexTestReferenceTableMultipleColumn(token: string): boolean;
57
+ export declare function regexTestReferenceTableTitleOnlyAnyHash(token: string): boolean;
49
58
  export declare function regexTestArrayValue(token: string): boolean;
50
59
  export declare function isReferenceString(refString: string): boolean;
@@ -1,4 +1,7 @@
1
+ import { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
2
+ import { MultiAreaReferenceObject } from '../engine/reference-object/multi-area-reference-object';
1
3
  import { BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
4
+ import { FormulaDataModel } from '../models/formula-data.model';
2
5
  export declare function betaCDF(x: number, alpha: number, beta: number): number;
3
6
  export declare function betaPDF(x: number, alpha: number, beta: number): number;
4
7
  export declare function betaINV(probability: number, alpha: number, beta: number): number;
@@ -67,3 +70,53 @@ export declare function getKnownsArrayCoefficients(knownYsValues: number[][], kn
67
70
  newX: number[][];
68
71
  XTXInverse: number[][];
69
72
  };
73
+ /**
74
+ * Parse aggregate data references into multi-area refs and normal refs, currently only used in functions like SUBTOTAL and AGGREGATE.
75
+ * If there is any invalid reference, return isError as true.
76
+ */
77
+ export declare function parseAggregateDataRefs(refs: FunctionVariantType[]): {
78
+ isError: boolean;
79
+ multiAreaRefs: MultiAreaReferenceObject[];
80
+ normalRefs: BaseReferenceObject[];
81
+ };
82
+ export declare enum AggregateFunctionType {
83
+ AVERAGE = "AVERAGE",
84
+ COUNT = "COUNT",
85
+ COUNTA = "COUNTA",
86
+ MAX = "MAX",
87
+ MIN = "MIN",
88
+ PRODUCT = "PRODUCT",
89
+ STDEV = "STDEV",
90
+ STDEV_S = "STDEV.S",
91
+ STDEVP = "STDEVP",
92
+ STDEV_P = "STDEV.P",
93
+ SUM = "SUM",
94
+ VAR = "VAR",
95
+ VAR_S = "VAR.S",
96
+ VARP = "VARP",
97
+ VAR_P = "VAR.P",
98
+ MEDIAN = "MEDIAN",
99
+ MODE_SNGL = "MODE.SNGL"
100
+ }
101
+ export type modeSnglValueCountMapType = Record<number, {
102
+ count: number;
103
+ order: number;
104
+ }>;
105
+ export declare function getModeSnglResult(valueCountMap: modeSnglValueCountMapType, valueMaxCount: number): BaseValueObject;
106
+ export interface IAggregateIgnoreOptions {
107
+ ignoreRowHidden: boolean;
108
+ ignoreErrorValues: boolean;
109
+ ignoreNested: boolean;
110
+ }
111
+ export declare function getAggregateResult(options: {
112
+ type: AggregateFunctionType;
113
+ formulaDataModel: FormulaDataModel;
114
+ } & IAggregateIgnoreOptions, refs: BaseReferenceObject[]): BaseValueObject;
115
+ export declare function getArrayValuesByAggregateIgnoreOptions(array: FunctionVariantType, options?: IAggregateIgnoreOptions, formulaDataModel?: FormulaDataModel): number[] | ErrorValueObject;
116
+ export declare function getMedianResult(array: number[]): BaseValueObject;
117
+ export declare function getLargeResult(array: number[], k: number): BaseValueObject;
118
+ export declare function getSmallResult(array: number[], k: number): BaseValueObject;
119
+ export declare function getPercentileIncResult(array: number[], k: number): BaseValueObject;
120
+ export declare function getPercentileExcResult(array: number[], k: number): BaseValueObject;
121
+ export declare function getQuartileIncResult(array: number[], quart: number): BaseValueObject;
122
+ export declare function getQuartileExcResult(array: number[], quart: number): BaseValueObject;
@@ -1,8 +1,9 @@
1
1
  import { IMutation } from '@univerjs/core';
2
- import { IArrayFormulaRangeType, IArrayFormulaUnitCellType } from '../../basics/common';
2
+ import { IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IArrayFormulaUnitCellType } from '../../basics/common';
3
3
  export interface ISetArrayFormulaDataMutationParams {
4
4
  arrayFormulaRange: IArrayFormulaRangeType;
5
5
  arrayFormulaCellData: IArrayFormulaUnitCellType;
6
+ arrayFormulaEmbedded: IArrayFormulaEmbeddedMap;
6
7
  }
7
8
  /**
8
9
  * There is no need to process data here, it is used as the main thread to send data to the worker. The main thread has already updated the data in advance, and there is no need to update it again here.
@@ -9,6 +9,7 @@ export interface ISetDefinedNameMutationParam extends ISetDefinedNameMutationSea
9
9
  comment?: string;
10
10
  localSheetId?: string;
11
11
  hidden?: boolean;
12
+ formulaOrRefStringWithPrefix?: string;
12
13
  }
13
14
  /**
14
15
  * Generate undo mutation of a `SetDefinedNameMutation`
@@ -0,0 +1,9 @@
1
+ import { IMutation } from '@univerjs/core';
2
+ import { IRuntimeImageFormulaDataType } from '../../basics/common';
3
+ export interface ISetImageFormulaDataMutationParams {
4
+ imageFormulaData: IRuntimeImageFormulaDataType[];
5
+ }
6
+ /**
7
+ * There is no need to process data here, it is used as the main thread to send data to the worker. The main thread has already updated the data in advance, and there is no need to update it again here.
8
+ */
9
+ export declare const SetImageFormulaDataMutation: IMutation<ISetImageFormulaDataMutationParams>;
@@ -1,5 +1,6 @@
1
1
  import { Nullable, AbsoluteRefType, Disposable } from '@univerjs/core';
2
2
  import { IDirtyUnitSheetDefinedNameMap } from '../../basics/common';
3
+ import { IFunctionNames } from '../../basics/function';
3
4
  import { IDefinedNamesServiceParam } from '../../services/defined-names.service';
4
5
  import { ISequenceArray, ISequenceNode } from '../utils/sequence';
5
6
  import { FormulaAstLRU } from '../../basics/cache-lru';
@@ -11,6 +12,7 @@ interface IInjectDefinedNameParam {
11
12
  unitId: Nullable<string>;
12
13
  getValueByName(unitId: string, name: string): Nullable<IDefinedNamesServiceParam>;
13
14
  getDirtyDefinedNameMap(): IDirtyUnitSheetDefinedNameMap;
15
+ getSheetName: (unitId: string, sheetId: string) => string;
14
16
  }
15
17
  export declare class LexerTreeBuilder extends Disposable {
16
18
  private _currentLexerNode;
@@ -54,6 +56,10 @@ export declare class LexerTreeBuilder extends Disposable {
54
56
  * =sum({}{})
55
57
  */
56
58
  private _formulaSpellCheck;
59
+ /**
60
+ * ={0,1,2,3,4,5,6} + {0;1;2;3;4;5;6}*7
61
+ */
62
+ private _passArrayOperator;
57
63
  getSequenceNode(sequenceArray: ISequenceArray[]): (string | ISequenceNode)[];
58
64
  private _processPushSequenceNode;
59
65
  private _getCurrentParamIndex;
@@ -71,6 +77,7 @@ export declare class LexerTreeBuilder extends Disposable {
71
77
  nodeMakerTest(formulaString: string): ErrorType.VALUE | (string | LexerNode)[] | undefined;
72
78
  treeBuilder(formulaString: string, transformSuffix?: boolean, injectDefinedNameParam?: IInjectDefinedNameParam): ErrorType.VALUE | LexerNode | (string | LexerNode)[] | undefined;
73
79
  private _handleDefinedName;
80
+ private _getHasSheetNameDefinedName;
74
81
  private _handleNestedDefinedName;
75
82
  private _simpleCheckDefinedName;
76
83
  private _checkDefinedNameDirty;
@@ -137,5 +144,6 @@ export declare class LexerTreeBuilder extends Disposable {
137
144
  private _nodeMaker;
138
145
  private _isScientificNotation;
139
146
  private _addSequenceArray;
147
+ getNewFormulaWithPrefix(formulaString: string, hasFunction: (functionToken: IFunctionNames) => boolean): string | null;
140
148
  }
141
149
  export {};
@@ -23,6 +23,7 @@ export declare class BaseAstNode {
23
23
  constructor(_token: string);
24
24
  dispose(): void;
25
25
  get nodeType(): NodeType;
26
+ resetCalculationState(): void;
26
27
  isAsync(): boolean;
27
28
  isAddress(): boolean;
28
29
  isForcedCalculateFunction(): boolean;
@@ -21,6 +21,10 @@ export declare class FunctionNode extends BaseAstNode {
21
21
  executeAsync(): Promise<AstNodePromiseType>;
22
22
  execute(): void;
23
23
  isFunctionExecutorArgumentsIgnoreNumberPattern(): boolean;
24
+ /**
25
+ * If it contains an array formula, set the current cell to the cache and send itself as a ref outward
26
+ */
27
+ private _setEmbeddedArrayFormulaToResult;
24
28
  /**
25
29
  * Compatibility handling for special functions.
26
30
  */
@@ -8,8 +8,9 @@ export declare class LambdaNode extends BaseAstNode {
8
8
  private _lambdaId;
9
9
  private _interpreter;
10
10
  private _lambdaPrivacyVarKeys;
11
+ private _runtimeService;
11
12
  private _isNotEmpty;
12
- constructor(token: string, _lambdaId: string, _interpreter: Interpreter, _lambdaPrivacyVarKeys: string[]);
13
+ constructor(token: string, _lambdaId: string, _interpreter: Interpreter, _lambdaPrivacyVarKeys: string[], _runtimeService: IFormulaRuntimeService);
13
14
  get nodeType(): NodeType;
14
15
  setNotEmpty(state?: boolean): void;
15
16
  isEmptyParamFunction(): boolean;
@@ -1,18 +1,25 @@
1
1
  import { BaseFunction } from '../../functions/base-function';
2
2
  import { IFunctionService } from '../../services/function.service';
3
+ import { IFormulaRuntimeService } from '../../services/runtime.service';
3
4
  import { LexerNode } from '../analysis/lexer-node';
4
5
  import { BaseAstNode } from './base-ast-node';
5
6
  import { BaseAstNodeFactory } from './base-ast-node-factory';
6
7
  import { NodeType } from './node-type';
7
8
  export declare class OperatorNode extends BaseAstNode {
8
9
  private _functionExecutor;
9
- constructor(operatorString: string, _functionExecutor: BaseFunction);
10
+ private _runtimeService;
11
+ constructor(operatorString: string, _functionExecutor: BaseFunction, _runtimeService: IFormulaRuntimeService);
10
12
  get nodeType(): NodeType;
11
13
  execute(): void;
14
+ /**
15
+ * If it contains an array formula, set the current cell to the cache and send itself as a ref outward
16
+ */
17
+ private _setEmbeddedArrayFormulaToResult;
12
18
  }
13
19
  export declare class OperatorNodeFactory extends BaseAstNodeFactory {
14
20
  private readonly _functionService;
15
- constructor(_functionService: IFunctionService);
21
+ private readonly _runtimeService;
22
+ constructor(_functionService: IFunctionService, _runtimeService: IFormulaRuntimeService);
16
23
  get zIndex(): number;
17
24
  create(param: string): BaseAstNode;
18
25
  checkAndCreateNodeType(param: LexerNode | string): BaseAstNode | undefined;
@@ -1,7 +1,9 @@
1
1
  import { IFormulaCurrentConfigService } from '../../services/current-data.service';
2
2
  import { IFunctionService } from '../../services/function.service';
3
3
  import { IFormulaRuntimeService } from '../../services/runtime.service';
4
+ import { ISuperTableService } from '../../services/super-table.service';
4
5
  import { LexerNode } from '../analysis/lexer-node';
6
+ import { TableReferenceObject } from '../reference-object/table-reference-object';
5
7
  import { ReferenceObjectType } from '../utils/value-object';
6
8
  import { BaseAstNode } from './base-ast-node';
7
9
  import { BaseAstNodeFactory } from './base-ast-node-factory';
@@ -11,9 +13,10 @@ export declare class ReferenceNode extends BaseAstNode {
11
13
  private _runtimeService;
12
14
  private _referenceObjectType;
13
15
  private _isPrepareMerge;
16
+ private _tableReferenceObject?;
14
17
  private _refOffsetX;
15
18
  private _refOffsetY;
16
- constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, operatorString: string, _referenceObjectType: ReferenceObjectType, _isPrepareMerge?: boolean);
19
+ constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, operatorString: string, _referenceObjectType: ReferenceObjectType, _isPrepareMerge?: boolean, _tableReferenceObject?: TableReferenceObject | undefined);
17
20
  get nodeType(): NodeType;
18
21
  execute(): void;
19
22
  setRefOffset(x?: number, y?: number): void;
@@ -26,8 +29,14 @@ export declare class ReferenceNodeFactory extends BaseAstNodeFactory {
26
29
  private readonly _currentConfigService;
27
30
  private readonly _formulaRuntimeService;
28
31
  private readonly _functionService;
29
- constructor(_currentConfigService: IFormulaCurrentConfigService, _formulaRuntimeService: IFormulaRuntimeService, _functionService: IFunctionService);
32
+ private readonly _superTableService;
33
+ constructor(_currentConfigService: IFormulaCurrentConfigService, _formulaRuntimeService: IFormulaRuntimeService, _functionService: IFunctionService, _superTableService: ISuperTableService);
30
34
  get zIndex(): number;
31
35
  checkAndCreateNodeType(param: LexerNode | string): ReferenceNode | undefined;
36
+ private _getTableMap;
37
+ private _getNode;
38
+ private _getTableReferenceNode;
39
+ private _splitTableStructuredRef;
40
+ private _checkTokenIsTableReference;
32
41
  private _checkParentIsUnionOperator;
33
42
  }
@@ -4,7 +4,6 @@ import { BaseValueObject } from '../value-object/base-value-object';
4
4
  import { FormulaAstLRU } from '../../basics/cache-lru';
5
5
  import { ObjectClassType } from '../../basics/object-class-type';
6
6
  import { ArrayValueObject } from '../value-object/array-value-object';
7
- import { StringValueObject } from '../value-object/primitive-object';
8
7
  export type NodeValueType = BaseValueObject | BaseReferenceObject | AsyncObject | AsyncArrayObject;
9
8
  export type FunctionVariantType = BaseValueObject | BaseReferenceObject;
10
9
  export declare const FORMULA_REF_TO_ARRAY_CACHE: FormulaAstLRU<ArrayValueObject>;
@@ -25,6 +24,8 @@ export declare class BaseReferenceObject extends ObjectClassType {
25
24
  private _runtimeFeatureCellData;
26
25
  private _refOffsetX;
27
26
  private _refOffsetY;
27
+ private _currentRow?;
28
+ private _currentColumn?;
28
29
  constructor(_token: string);
29
30
  dispose(): void;
30
31
  getToken(): string;
@@ -48,7 +49,7 @@ export declare class BaseReferenceObject extends ObjectClassType {
48
49
  };
49
50
  isReferenceObject(): boolean;
50
51
  iterator(callback: (valueObject: Nullable<BaseValueObject>, rowIndex: number, columnIndex: number) => Nullable<boolean>): Nullable<boolean>;
51
- getFirstCell(): BaseValueObject | StringValueObject;
52
+ getFirstCell(): BaseValueObject;
52
53
  getRangeData(): IRange;
53
54
  setRangeData(range: IRange): void;
54
55
  getUnitId(): string;
@@ -93,12 +94,15 @@ export declare class BaseReferenceObject extends ObjectClassType {
93
94
  isRow(): boolean;
94
95
  isRange(): boolean;
95
96
  isTable(): boolean;
97
+ isCurrentRowForRange(): boolean;
98
+ isCurrentColumnForRange(): boolean;
99
+ isMultiArea(): boolean;
96
100
  unionBy(referenceObject: BaseReferenceObject): NodeValueType;
97
101
  unionRange(rangeData1: IRange, rangeData2: IRange): IRange;
98
- getCellValueObject(cell: ICellData): BaseValueObject | StringValueObject;
102
+ getCellValueObject(cell: ICellData): BaseValueObject;
99
103
  private _getPatternByCell;
100
- getCellByRow(row: number): BaseValueObject | StringValueObject;
101
- getCellByColumn(column: number): BaseValueObject | StringValueObject;
104
+ getCellByRow(row: number): BaseValueObject;
105
+ getCellByColumn(column: number): BaseValueObject;
102
106
  getCurrentActiveSheetData(): import('../../basics/common').ISheetItem;
103
107
  getCurrentStylesData(): import('@univerjs/core').Styles;
104
108
  getCurrentRuntimeSheetData(): import('@univerjs/core').ObjectMatrix<Nullable<ICellData>> | undefined;
@@ -106,7 +110,10 @@ export declare class BaseReferenceObject extends ObjectClassType {
106
110
  getCurrentRuntimeActiveArrayFormulaCellData(): import('@univerjs/core').ObjectMatrix<Nullable<ICellData>> | undefined;
107
111
  getCellData(row: number, column: number): Nullable<ICellData>;
108
112
  getRuntimeFeatureCellValue(row: number, column: number): ICellData | undefined;
109
- getCellByPosition(rowRaw?: number, columnRaw?: number): BaseValueObject | StringValueObject;
113
+ getCellByPosition(rowRaw?: number, columnRaw?: number): BaseValueObject;
114
+ setCurrentRowAndColumn(row: number, column: number): void;
115
+ getCurrentRow(): number | undefined;
116
+ getCurrentColumn(): number | undefined;
110
117
  /**
111
118
  * Get the pattern of the cell
112
119
  * @param unitId
@@ -0,0 +1,92 @@
1
+ import { Nullable } from '@univerjs/core';
2
+ import { ArrayValueObject } from '../value-object/array-value-object';
3
+ import { BaseValueObject, ErrorValueObject } from '../value-object/base-value-object';
4
+ import { BaseReferenceObject } from './base-reference-object';
5
+ export type MultiAreaValue = BaseReferenceObject | ErrorValueObject;
6
+ export declare class MultiAreaReferenceObject extends BaseReferenceObject {
7
+ /**
8
+ * 2D structure:
9
+ * - First dimension: stored by rows
10
+ * - Second dimension: each AreaValue within that row
11
+ */
12
+ private _areas;
13
+ constructor(token: string, areas?: MultiAreaValue[][]);
14
+ dispose(): void;
15
+ getAreas(): MultiAreaValue[][];
16
+ setAreas(areas: MultiAreaValue[][]): void;
17
+ /**
18
+ * Append an area:
19
+ * - If a single AreaValue is passed, it will be wrapped as one row.
20
+ * - If an AreaValue[] is passed, it will be inserted as an entire row.
21
+ */
22
+ addArea(area: MultiAreaValue | MultiAreaValue[]): void;
23
+ /** Flatten the 2D areas to reuse 1D logic */
24
+ private _flatAreas;
25
+ isMultiArea(): boolean;
26
+ isRange(): boolean;
27
+ isCell(): boolean;
28
+ isRow(): boolean;
29
+ isColumn(): boolean;
30
+ getRowCount(): number;
31
+ getColumnCount(): number;
32
+ isExceedRange(): boolean;
33
+ setRefOffset(x?: number, y?: number): void;
34
+ private _getReferenceArea;
35
+ /**
36
+ * Multi-area reference may span multiple sheets, but Excel requires
37
+ * them to be in the same sheet for most functions. We follow Excel semantics
38
+ * by returning the first area’s identifiers.
39
+ */
40
+ getUnitId(): string;
41
+ getSheetId(): string;
42
+ getActiveSheetRowCount(): number;
43
+ getActiveSheetColumnCount(): number;
44
+ /**
45
+ * Iterate through all areas in order, flattening the multi-area into
46
+ * a sequence of cells.
47
+ *
48
+ * Note: The order here is "row-major":
49
+ * iterate by the row order of _areas, then within each row by the area order.
50
+ */
51
+ iterator(callback: (v: Nullable<BaseValueObject>, row: number, col: number) => Nullable<boolean>): void;
52
+ /**
53
+ * Excel defines the "first cell" of a multi-area reference
54
+ * as the first cell of the first area.
55
+ */
56
+ getFirstCell(): BaseValueObject;
57
+ /**
58
+ * For multi-area, we only take the *first cell* of each area and
59
+ * arrange them into a 2D ArrayValueObject:
60
+ *
61
+ * - outer `_areas` dimension => rows
62
+ * - inner `_areas[row]` dimension => columns
63
+ */
64
+ toArrayValueObject(): ArrayValueObject;
65
+ getRangePosition(): {
66
+ startRow: number;
67
+ endRow: number;
68
+ startColumn: number;
69
+ endColumn: number;
70
+ rangeType?: import('@univerjs/core').RANGE_TYPE;
71
+ startAbsoluteRefType?: import('@univerjs/core').AbsoluteRefType;
72
+ endAbsoluteRefType?: import('@univerjs/core').AbsoluteRefType;
73
+ unitId?: string;
74
+ sheetId?: string;
75
+ };
76
+ toUnitRange(): {
77
+ range: {
78
+ startRow: number;
79
+ endRow: number;
80
+ startColumn: number;
81
+ endColumn: number;
82
+ rangeType?: import('@univerjs/core').RANGE_TYPE;
83
+ startAbsoluteRefType?: import('@univerjs/core').AbsoluteRefType;
84
+ endAbsoluteRefType?: import('@univerjs/core').AbsoluteRefType;
85
+ unitId?: string;
86
+ sheetId?: string;
87
+ };
88
+ sheetId: string;
89
+ unitId: string;
90
+ };
91
+ getRangeData(): import('@univerjs/core').IRange;
92
+ }
@@ -1,10 +1,92 @@
1
- import { ISuperTable, TableOptionType } from '../../basics/common';
1
+ import { ISuperTable, IUnitSheetNameMap, TableOptionType } from '../../basics/common';
2
2
  import { BaseReferenceObject } from './base-reference-object';
3
+ /**
4
+ * Table reference object compatible with Excel Structured References
5
+ *
6
+ * Supported (examples):
7
+ * - =Table[Column] // Single column (default DATA)
8
+ * - =Table[[ColumnA]:[ColumnB]] // Column range (default DATA)
9
+ * - =Table[#All] / [#Data] / [#Headers] / [#Totals] / [#This Row]
10
+ * - =Table[[#All],[Column]] // Section + column/column range
11
+ * - =Table[[#Data],[ColA]:[ColB]]
12
+ * - =Table[[#This Row],[Column]]
13
+ *
14
+ * Not supported (invalid):
15
+ * - Multiple sections in parallel (e.g., [[#Headers],[#Data]])
16
+ * - Non-existent sections (e.g., #Title)
17
+ * - Column indices instead of column names (e.g., [[1]:[3]])
18
+ */
3
19
  export declare class TableReferenceObject extends BaseReferenceObject {
4
20
  private _tableData;
21
+ /**
22
+ * Structured reference body (with or without outer []):
23
+ * - "#Data" / "#All"
24
+ * - "[Col]" / "[[ColA]:[ColB]]"
25
+ * - "[[#Data],[Col]]" / "[[#All],[ColA]:[ColB]]"
26
+ */
5
27
  private _columnDataString;
6
- constructor(token: string, _tableData: ISuperTable, _columnDataString: string, tableOptionMap: Map<string, TableOptionType>);
28
+ /** Section text to enum mapping ('#All', '#Data', '#Headers', '#Totals', '#This Row') */
29
+ private _tableOptionMap;
30
+ private _isCurrentRowForRange;
31
+ constructor(token: string, _tableData: ISuperTable,
32
+ /**
33
+ * Structured reference body (with or without outer []):
34
+ * - "#Data" / "#All"
35
+ * - "[Col]" / "[[ColA]:[ColB]]"
36
+ * - "[[#Data],[Col]]" / "[[#All],[ColA]:[ColB]]"
37
+ */
38
+ _columnDataString: string | undefined,
39
+ /** Section text to enum mapping ('#All', '#Data', '#Headers', '#Totals', '#This Row') */
40
+ _tableOptionMap: Map<string, TableOptionType>);
41
+ getRangeData(): import('@univerjs/core').IRange;
42
+ getRefOffset(): {
43
+ x: number;
44
+ y: number;
45
+ };
7
46
  isTable(): boolean;
8
- private _stringToColumnData;
9
- private _columnHandler;
47
+ isCurrentRowForRange(): boolean;
48
+ setForcedSheetId(sheetNameMap: IUnitSheetNameMap): void;
49
+ /**
50
+ * Parse structured reference body, returning column range and Section type.
51
+ * Determination rules:
52
+ * - Whether it's a Section depends on "whether it starts with # after stripping", not whether it still has brackets.
53
+ * - No comma: Either Section, or column/column range
54
+ * - Has comma: Left is Section, right is column/column range
55
+ */
56
+ private _parseStructuredRef;
57
+ /** Strip one layer of outer brackets from "[...]" (return as-is if none) */
58
+ private _stripOuterBracketOnce;
59
+ /**
60
+ * Find first comma at depth=0 (used to split Section and column parts)
61
+ * Compatible with nesting like "[[#Data],[ColA]:[ColB]]".
62
+ */
63
+ private _findCommaAtTopLevel;
64
+ /**
65
+ * Parse Section, compatible with both "[#Data]" and "#Data" inputs
66
+ * Returns TableOptionType if matched; returns DATA if not (could throw error instead)
67
+ */
68
+ private _parseSectionMaybeBracketed;
69
+ /**
70
+ * Section mapping: Only accepts keywords starting with #.
71
+ * Returns undefined if not a valid Section (caller treats as column or fallback).
72
+ */
73
+ private _mapSection;
74
+ /**
75
+ * Parse column selection:
76
+ * - "[Col]" / "Col" => Single column
77
+ * - "[[ColA]:[ColB]]" / "[ColA]:[ColB]" / "ColA:ColB" => Column range
78
+ *
79
+ * Rules:
80
+ * - First find colon at top level, strip one layer of brackets from left and right sides (if present)
81
+ * - Returns -1 if column name not found (caller should handle as parse error)
82
+ */
83
+ private _parseColumnOrRange;
84
+ /** Strip one layer of outer brackets; return as-is if none (compatible with "[Col]" and "Col") */
85
+ private _stripOuterBracketIfAny;
86
+ /** Find range colon at depth=0 */
87
+ private _findColonAtTopLevel;
88
+ /** Column title → column index; returns -1 if not found (caller should handle as parse error) */
89
+ private _titleToIndex;
90
+ /** Resolve #This Row's row number; takes first data row (tableStartRow+1) when no context available */
91
+ private _resolveThisRow;
10
92
  }
@@ -172,6 +172,11 @@ export declare class ArrayValueObject extends BaseValueObject {
172
172
  atan2(valueObject: BaseValueObject): BaseValueObject;
173
173
  atan2Inverse(valueObject: BaseValueObject): BaseValueObject;
174
174
  mean(ddof?: number): BaseValueObject;
175
+ /**
176
+ * TODO: @DR-Univer
177
+ * This calculation method contains an error, please note.
178
+ * Please refer `getMedianResult` function in /engine-formula/src/basics/statistical.ts
179
+ */
175
180
  median(): BaseValueObject;
176
181
  /**
177
182
  * ┌──────────────┬────────────────────────────────┬───────────────────┐
@@ -40,9 +40,11 @@ export declare class BaseValueObject extends ObjectClassType {
40
40
  isNumber(): boolean;
41
41
  isBoolean(): boolean;
42
42
  isLambda(): boolean;
43
+ isDateFormat(): boolean;
43
44
  isError(): boolean;
44
45
  isNull(): boolean;
45
46
  isHyperlink(): boolean;
47
+ isImage(): boolean;
46
48
  sum(): BaseValueObject;
47
49
  max(): BaseValueObject;
48
50
  min(): BaseValueObject;
@@ -82,7 +84,7 @@ export declare class BaseValueObject extends ObjectClassType {
82
84
  multiplyBy(value: string | number | boolean): BaseValueObject;
83
85
  dividedBy(value: string | number | boolean): BaseValueObject;
84
86
  modInverse(valueObject: BaseValueObject): BaseValueObject;
85
- compareBy(value: string | number | boolean, operator: compareToken): BaseValueObject;
87
+ compareBy(value: string | number | boolean, operator: compareToken, isDateCompare?: boolean): BaseValueObject;
86
88
  concatenate(value: string | number | boolean, concatenateType?: ConcatenateType): string;
87
89
  pow(valueObject: BaseValueObject): BaseValueObject;
88
90
  powInverse(valueObject: BaseValueObject): BaseValueObject;