@univerjs/engine-formula 1.0.0-alpha.3 → 1.0.0-alpha.5

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.
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, Nullable, ObjectMatrix, Styles } from '@univerjs/core';
16
+ import type { ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, Nullable, ObjectMatrix, Styles, UniverInstanceType } from '@univerjs/core';
17
17
  import type { sequenceNodeType } from '../engine/utils/sequence';
18
18
  import type { IImageFormulaInfo } from '../engine/value-object/primitive-object';
19
19
  export declare const ERROR_VALUE_OBJECT_CLASS_TYPE = "errorValueObject";
@@ -75,6 +75,15 @@ export interface IUnitSheetNameMap {
75
75
  [sheetName: string]: string;
76
76
  }>;
77
77
  }
78
+ export type FormulaUnitType = UniverInstanceType.UNIVER_SHEET | UniverInstanceType.UNIVER_BASE;
79
+ export interface IFormulaUnitNameMapItem {
80
+ name: string;
81
+ unitType: FormulaUnitType;
82
+ }
83
+ /** Runtime Unit metadata keyed by stable unitId. */
84
+ export interface IFormulaUnitNameMap {
85
+ [unitId: string]: IFormulaUnitNameMapItem;
86
+ }
78
87
  export interface IUnitSheetIdToNameMap {
79
88
  [unitId: string]: Nullable<{
80
89
  [sheetId: string]: string;
@@ -193,6 +202,11 @@ export interface ISuperTable {
193
202
  sheetId: string;
194
203
  titleMap: Map<string, number>;
195
204
  range: IRange;
205
+ /**
206
+ * Whether the projected range contains a physical header row.
207
+ * Sheet tables default to true; Base virtual tables store records from row 0.
208
+ */
209
+ showHeader?: boolean;
196
210
  }
197
211
  export declare enum TableOptionType {
198
212
  ALL = "#All",
@@ -227,6 +241,7 @@ export interface IFormulaDatasetConfig {
227
241
  allUnitData?: IUnitData;
228
242
  unitStylesData?: IUnitStylesData;
229
243
  unitSheetNameMap?: IUnitSheetNameMap;
244
+ unitNameMap?: IFormulaUnitNameMap;
230
245
  maxIteration?: number;
231
246
  isCalculateTreeModel?: boolean;
232
247
  rowData?: IUnitRowData;
@@ -42,8 +42,8 @@ export declare function formatDateDefault(date: Date): string;
42
42
  * TODO @Dushusir: Internationalization and more format support, can be reused when editing and saving cells, like "2020年1月1日"
43
43
  */
44
44
  export declare function isValidDateStr(dateStr: string): boolean;
45
- export declare function parseFormattedDate(value: string): numfmt.ParseData | null;
46
- export declare function parseFormattedTime(value: string): numfmt.ParseData | null;
45
+ export declare function parseFormattedDate(value: string): numfmt.ParseData<number> | null;
46
+ export declare function parseFormattedTime(value: string): numfmt.ParseData<number> | null;
47
47
  export declare function isDate(format: string): boolean;
48
48
  export declare function isValidWeekend(weekend: number | string): boolean;
49
49
  export declare function getWeekendArray(weekend: number | string): number[];
@@ -32,10 +32,10 @@ export declare const REFERENCE_REGEX_SINGLE_ROW = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\
32
32
  export declare const REFERENCE_REGEX_SINGLE_ROW_PRECOMPILING: RegExp;
33
33
  export declare const REFERENCE_REGEX_SINGLE_COLUMN = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\s*?\\$?[A-Za-z]+$";
34
34
  export declare const REFERENCE_REGEX_SINGLE_COLUMN_PRECOMPILING: RegExp;
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
- 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])*\\]|\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#)[\\s\\S])*\\]\\])+$";
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])*\\]\\s*?:\\s*?\\[((?<!#)[\\s\\S])*\\]\\])?$|^((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#)[\\s\\S])*\\]\\s*?:\\s*?\\[((?<!#)[\\s\\S])*\\]\\])?$";
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*\\]$";
35
+ export declare const REFERENCE_TABLE_ALL_COLUMN_REGEX = "^(?:(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+$";
36
+ export declare const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = "^(?:(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[((?<!#)[\\s\\S])*\\]|\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#)[\\s\\S])*\\]\\])+$";
37
+ export declare const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX = "^(?:(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[((?<!#)[\\s\\S])*\\]\\s*?:\\s*?\\[((?<!#)[\\s\\S])*\\]\\])?$|^(?:(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#)[\\s\\S])*\\]\\s*?:\\s*?\\[((?<!#)[\\s\\S])*\\]\\])?$";
38
+ export declare const REFERENCE_TABLE_TITLE_ONLY_ANY_HASH_REGEX = "^(?:(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+\\[\\s*#([^\\]]+)\\s*\\]$";
39
39
  export declare const REFERENCE_TABLE_ALL_COLUMN_REGEX_PRECOMPILING: RegExp;
40
40
  export declare const REFERENCE_TABLE_SINGLE_COLUMN_REGEX_PRECOMPILING: RegExp;
41
41
  export declare const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX_PRECOMPILING: RegExp;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable, LifecycleService } from '@univerjs/core';
17
+ import { FormulaCalculationTriggerService } from '../services/formula-calculation-trigger.service';
18
+ export declare class FormulaCalculationTriggerController extends Disposable {
19
+ constructor(formulaCalculationTriggerService: FormulaCalculationTriggerService, lifecycleService: LifecycleService);
20
+ }
@@ -15,9 +15,9 @@
15
15
  */
16
16
  import type { Nullable } from '@univerjs/core';
17
17
  import type { LambdaPrivacyVarType } from '../ast-node/base-ast-node';
18
- interface LexerNodeJson {
18
+ interface ILexerNodeJson {
19
19
  token: string;
20
- children: Array<LexerNodeJson | string>;
20
+ children: Array<ILexerNodeJson | string>;
21
21
  }
22
22
  export declare class LexerNode {
23
23
  private _parent;
@@ -56,7 +56,7 @@ export declare class LexerNode {
56
56
  token: string;
57
57
  st: number;
58
58
  ed: number;
59
- children: (string | LexerNodeJson)[];
59
+ children: (string | ILexerNodeJson)[];
60
60
  };
61
61
  private _getIndexInParent;
62
62
  }
@@ -22,6 +22,7 @@ import { IFormulaCurrentConfigService } from '../../services/current-data.servic
22
22
  import { IDefinedNamesService } from '../../services/defined-names.service';
23
23
  import { IFunctionService } from '../../services/function.service';
24
24
  import { IFormulaRuntimeService } from '../../services/runtime.service';
25
+ import { IFormulaUnitReferenceResolver } from '../../services/unit-reference-resolver.service';
25
26
  import { BaseAstNode } from './base-ast-node';
26
27
  import { BaseAstNodeFactory } from './base-ast-node-factory';
27
28
  import { NodeType } from './node-type';
@@ -31,7 +32,8 @@ export declare class FunctionNode extends BaseAstNode {
31
32
  private _runtimeService;
32
33
  private _definedNamesService;
33
34
  private _formulaDataModel;
34
- constructor(token: string, _functionExecutor: BaseFunction, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _definedNamesService: IDefinedNamesService, _formulaDataModel: FormulaDataModel);
35
+ private _unitReferenceResolver;
36
+ constructor(token: string, _functionExecutor: BaseFunction, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _definedNamesService: IDefinedNamesService, _formulaDataModel: FormulaDataModel, _unitReferenceResolver: IFormulaUnitReferenceResolver);
35
37
  get nodeType(): NodeType;
36
38
  executeAsync(): Promise<AstNodePromiseType>;
37
39
  execute(): void;
@@ -84,7 +86,8 @@ export declare class FunctionNodeFactory extends BaseAstNodeFactory {
84
86
  private readonly _definedNamesService;
85
87
  private readonly _injector;
86
88
  private readonly _formulaDataModel;
87
- constructor(_functionService: IFunctionService, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _definedNamesService: IDefinedNamesService, _injector: Injector, _formulaDataModel: FormulaDataModel);
89
+ private readonly _unitReferenceResolver;
90
+ constructor(_functionService: IFunctionService, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _definedNamesService: IDefinedNamesService, _injector: Injector, _formulaDataModel: FormulaDataModel, _unitReferenceResolver: IFormulaUnitReferenceResolver);
88
91
  get zIndex(): number;
89
92
  create(token: string): BaseAstNode;
90
93
  checkAndCreateNodeType(param: LexerNode | string): BaseAstNode | undefined;
@@ -17,23 +17,31 @@ import { IFormulaCurrentConfigService } from '../../services/current-data.servic
17
17
  import { IFunctionService } from '../../services/function.service';
18
18
  import { IFormulaRuntimeService } from '../../services/runtime.service';
19
19
  import { ISuperTableService } from '../../services/super-table.service';
20
+ import { IFormulaUnitReferenceResolver } from '../../services/unit-reference-resolver.service';
20
21
  import { LexerNode } from '../analysis/lexer-node';
21
- import { TableReferenceObject } from '../reference-object/table-reference-object';
22
22
  import { ReferenceObjectType } from '../utils/value-object';
23
23
  import { BaseAstNode } from './base-ast-node';
24
24
  import { BaseAstNodeFactory } from './base-ast-node-factory';
25
25
  import { NodeType } from './node-type';
26
+ interface ITableReferenceDescriptor {
27
+ unitQualifier: string;
28
+ tableName: string;
29
+ columnStruct: string | undefined;
30
+ }
26
31
  export declare class ReferenceNode extends BaseAstNode {
27
32
  private _currentConfigService;
28
33
  private _runtimeService;
29
34
  private _referenceObjectType;
35
+ private _unitReferenceResolver;
36
+ private _superTableService;
30
37
  private _isPrepareMerge;
31
- private _tableReferenceObject?;
38
+ private _tableReference?;
32
39
  private _refOffsetX;
33
40
  private _refOffsetY;
34
- constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, operatorString: string, _referenceObjectType: ReferenceObjectType, _isPrepareMerge?: boolean, _tableReferenceObject?: TableReferenceObject | undefined);
41
+ constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, operatorString: string, _referenceObjectType: ReferenceObjectType, _unitReferenceResolver: IFormulaUnitReferenceResolver, _superTableService: ISuperTableService, _isPrepareMerge?: boolean, _tableReference?: ITableReferenceDescriptor | undefined);
35
42
  get nodeType(): NodeType;
36
43
  execute(): void;
44
+ private _configureReferenceObject;
37
45
  setRefOffset(x?: number, y?: number): void;
38
46
  getRefOffset(): {
39
47
  x: number;
@@ -45,7 +53,8 @@ export declare class ReferenceNodeFactory extends BaseAstNodeFactory {
45
53
  private readonly _formulaRuntimeService;
46
54
  private readonly _functionService;
47
55
  private readonly _superTableService;
48
- constructor(_currentConfigService: IFormulaCurrentConfigService, _formulaRuntimeService: IFormulaRuntimeService, _functionService: IFunctionService, _superTableService: ISuperTableService);
56
+ private readonly _unitReferenceResolver;
57
+ constructor(_currentConfigService: IFormulaCurrentConfigService, _formulaRuntimeService: IFormulaRuntimeService, _functionService: IFunctionService, _superTableService: ISuperTableService, _unitReferenceResolver: IFormulaUnitReferenceResolver);
49
58
  get zIndex(): number;
50
59
  checkAndCreateNodeType(param: LexerNode | string): ReferenceNode | undefined;
51
60
  private _getTableMap;
@@ -54,3 +63,4 @@ export declare class ReferenceNodeFactory extends BaseAstNodeFactory {
54
63
  private _checkTokenIsTableReference;
55
64
  private _checkParentIsUnionOperator;
56
65
  }
66
+ export {};
@@ -34,6 +34,7 @@ export declare class BaseReferenceObject extends ObjectClassType {
34
34
  private _filteredOutRows;
35
35
  private _defaultUnitId;
36
36
  private _forcedUnitId;
37
+ private _unitQualifier;
37
38
  private _runtimeData;
38
39
  private _arrayFormulaCellData;
39
40
  private _arrayFormulaRange;
@@ -63,6 +64,8 @@ export declare class BaseReferenceObject extends ObjectClassType {
63
64
  getUnitId(): string;
64
65
  getSheetId(): string;
65
66
  setForcedUnitIdDirect(unitId: string): void;
67
+ setUnitQualifier(unitQualifier: string): void;
68
+ getUnitQualifier(): string;
66
69
  getForcedUnitId(): string;
67
70
  setForcedSheetId(sheetNameMap: IUnitSheetNameMap): void;
68
71
  setForcedSheetIdDirect(sheetId: string): void;
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import type { ICellData, Nullable } from '@univerjs/core';
16
17
  import type { ISuperTable, IUnitSheetNameMap } from '../../basics/common';
17
18
  import { TableOptionType } from '../../basics/common';
18
19
  import { BaseReferenceObject } from './base-reference-object';
@@ -55,6 +56,7 @@ export declare class TableReferenceObject extends BaseReferenceObject {
55
56
  /** Section text to enum mapping ('#All', '#Data', '#Headers', '#Totals', '#This Row') */
56
57
  _tableOptionMap: Map<string, TableOptionType>);
57
58
  getRangeData(): import("@univerjs/core").IRange;
59
+ getCellData(row: number, column: number): Nullable<ICellData>;
58
60
  getRefOffset(): {
59
61
  x: number;
60
62
  y: number;
@@ -56,6 +56,8 @@ export declare function singleReferenceToGrid(refBody: string): {
56
56
  export declare function handleRefStringInfo(refString: string): {
57
57
  refBody: string;
58
58
  sheetName: string;
59
+ unitQualifier: string;
60
+ /** @deprecated Use unitQualifier. Kept for reference-grid compatibility. */
59
61
  unitId: string;
60
62
  };
61
63
  export declare function deserializeRangeWithSheet(refString: string): IUnitRangeName;
@@ -102,11 +104,7 @@ export declare function quoteSheetName(name: string): string;
102
104
  */
103
105
  export declare function unquoteSheetName(name: string): string;
104
106
  export declare function splitTableStructuredRef(ref: string): {
105
- tableName: string;
106
- struct: string;
107
- columnStruct?: undefined;
108
- } | {
107
+ unitQualifier: string;
109
108
  tableName: string;
110
109
  columnStruct: string;
111
- struct?: undefined;
112
110
  };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /** Refactors only parsed reference qualifiers and INDIRECT literal references, never arbitrary text. */
17
+ export declare function refactorFormulaUnitQualifier(formula: string, oldName: string, newName: string): string;
18
+ /**
19
+ * Copyright 2023-present DreamNum Co., Ltd.
20
+ *
21
+ * Licensed under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License.
23
+ * You may obtain a copy of the License at
24
+ *
25
+ * http://www.apache.org/licenses/LICENSE-2.0
26
+ *
27
+ * Unless required by applicable law or agreed to in writing, software
28
+ * distributed under the License is distributed on an "AS IS" BASIS,
29
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
+ * See the License for the specific language governing permissions and
31
+ * limitations under the License.
32
+ */
@@ -23,6 +23,7 @@ import type { BaseValueObject } from '../engine/value-object/base-value-object';
23
23
  import type { FormulaFunctionResultValueType, FormulaFunctionValueType } from '../engine/value-object/primitive-object';
24
24
  import type { FormulaDataModel } from '../models/formula-data.model';
25
25
  import type { IDefinedNameMapItem } from '../services/defined-names.service';
26
+ import type { IFormulaUnitReferenceResolver } from '../services/unit-reference-resolver.service';
26
27
  import { ArrayOrderSearchType } from '../engine/utils/compare';
27
28
  import { ErrorValueObject } from '../engine/value-object/base-value-object';
28
29
  export declare class BaseFunction {
@@ -38,6 +39,7 @@ export declare class BaseFunction {
38
39
  private _sheetOrder;
39
40
  private _sheetNameMap;
40
41
  protected _formulaDataModel: Nullable<FormulaDataModel>;
42
+ protected _unitReferenceResolver: Nullable<IFormulaUnitReferenceResolver>;
41
43
  protected _rowCount: number;
42
44
  protected _columnCount: number;
43
45
  /**
@@ -60,6 +62,8 @@ export declare class BaseFunction {
60
62
  * Whether the function needs function methods in FormulaDataModel
61
63
  */
62
64
  needsFormulaDataModel: boolean;
65
+ /** Whether the function resolves external Unit qualifiers. */
66
+ needsUnitReferenceResolver: boolean;
63
67
  /**
64
68
  * Whether the function needs the number of rows and columns in the sheet
65
69
  */
@@ -117,6 +121,7 @@ export declare class BaseFunction {
117
121
  };
118
122
  }): void;
119
123
  setFormulaDataModel(_formulaDataModel: FormulaDataModel): void;
124
+ setUnitReferenceResolver(unitReferenceResolver: IFormulaUnitReferenceResolver): void;
120
125
  setSheetRowColumnCount(rowCount: number, columnCount: number): void;
121
126
  isAsync(): boolean;
122
127
  isAddress(): boolean;
@@ -19,6 +19,7 @@ import { BaseFunction } from '../../base-function';
19
19
  export declare class Indirect extends BaseFunction {
20
20
  minParams: number;
21
21
  maxParams: number;
22
+ needsUnitReferenceResolver: boolean;
22
23
  isAddress(): boolean;
23
24
  calculate(refText: BaseValueObject, a1?: BaseValueObject): BaseValueObject | BaseReferenceObject;
24
25
  private _handleSingleObject;
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export type { IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IArrayFormulaUnitCellType, IDirtyUnitDefinedNameMap, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetNameMap, IDirtyUnitSuperTableMap, IFeatureDirtyRangeType, IFormulaData, IFormulaDataItem, IFormulaDatasetConfig, IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeImageFormulaDataType, IRuntimeUnitDataType, ISheetData, IUnitData, IUnitImageFormulaDataType, IUnitSheetNameMap, } from './basics/common';
16
+ export type { FormulaUnitType, IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IArrayFormulaUnitCellType, IDirtyUnitDefinedNameMap, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetNameMap, IDirtyUnitSuperTableMap, IFeatureDirtyRangeType, IFormulaData, IFormulaDataItem, IFormulaDatasetConfig, IFormulaExecuteResultMap, IFormulaStringMap, IFormulaUnitNameMap, IFormulaUnitNameMapItem, IRuntimeImageFormulaDataType, IRuntimeUnitDataType, ISheetData, IUnitData, IUnitImageFormulaDataType, IUnitSheetNameMap, } from './basics/common';
17
17
  export { BooleanValue } from './basics/common';
18
18
  export { type IOtherFormulaData } from './basics/common';
19
19
  export type { IExprTreeNode, ISuperTable, IUnitRowData } from './basics/common';
@@ -91,6 +91,7 @@ export { handleRefStringInfo } from './engine/utils/reference';
91
91
  export { deserializeRangeWithSheetWithCache } from './engine/utils/reference-cache';
92
92
  export { generateStringWithSequence, sequenceNodeType } from './engine/utils/sequence';
93
93
  export type { ISequenceNode } from './engine/utils/sequence';
94
+ export { refactorFormulaUnitQualifier } from './engine/utils/unit-qualifier';
94
95
  export { ArrayValueObject, ValueObjectFactory } from './engine/value-object/array-value-object';
95
96
  export { BaseValueObject, ErrorValueObject } from './engine/value-object/base-value-object';
96
97
  export { LambdaValueObjectObject } from './engine/value-object/lambda-value-object';
@@ -162,3 +163,5 @@ export type { IAllRuntimeData, IExecutionInProgressParams } from './services/run
162
163
  export { ISheetRowFilteredService, SheetRowFilteredService } from './services/sheet-row-filtered.service';
163
164
  export { ISuperTableService } from './services/super-table.service';
164
165
  export { SuperTableService } from './services/super-table.service';
166
+ export { FormulaUnitReferenceResolver, IFormulaUnitReferenceResolver, normalizeFormulaUnitName, } from './services/unit-reference-resolver.service';
167
+ export type { FormulaUnitReferenceKind, IFormulaUnitReferenceResolution, IFormulaUnitReferenceResolveInput, } from './services/unit-reference-resolver.service';
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { ICellData, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable } from '@univerjs/core';
17
- import type { IArrayFormulaRangeType, IArrayFormulaUnitCellType, IFormulaData, IFormulaDataItem, IRuntimeUnitDataType, IUnitData, IUnitImageFormulaDataType, IUnitRowData, IUnitSheetNameMap, IUnitStylesData } from '../basics/common';
17
+ import type { IArrayFormulaRangeType, IArrayFormulaUnitCellType, IFormulaData, IFormulaDataItem, IFormulaUnitNameMap, IRuntimeUnitDataType, IUnitData, IUnitImageFormulaDataType, IUnitRowData, IUnitSheetNameMap, IUnitStylesData } from '../basics/common';
18
18
  import { Disposable, IUniverInstanceService, ObjectMatrix } from '@univerjs/core';
19
19
  import { LexerTreeBuilder } from '../engine/analysis/lexer-tree-builder';
20
20
  export interface IRangeChange {
@@ -46,6 +46,7 @@ export declare class FormulaDataModel extends Disposable {
46
46
  allUnitData: IUnitData;
47
47
  unitStylesData: IUnitStylesData;
48
48
  unitSheetNameMap: IUnitSheetNameMap;
49
+ unitNameMap: IFormulaUnitNameMap;
49
50
  };
50
51
  /**
51
52
  * Get the hidden rows that are filtered or manually hidden.
@@ -54,6 +55,7 @@ export declare class FormulaDataModel extends Disposable {
54
55
  */
55
56
  getHiddenRowsFiltered(): IUnitRowData;
56
57
  updateFormulaData(unitId: string, sheetId: string, cellValue: IObjectMatrixPrimitiveType<Nullable<ICellData>>): IObjectMatrixPrimitiveType<IFormulaDataItem | null>;
58
+ private _rebindSharedFormulaData;
57
59
  updateArrayFormulaRange(unitId: string, sheetId: string, cellValue: IObjectMatrixPrimitiveType<Nullable<ICellData>>): boolean;
58
60
  updateArrayFormulaCellData(unitId: string, sheetId: string, cellValue: IObjectMatrixPrimitiveType<Nullable<ICellData>>): boolean;
59
61
  updateImageFormulaData(unitId: string, sheetId: string, cellValue: IObjectMatrixPrimitiveType<Nullable<ICellData>>): void;
@@ -63,7 +65,6 @@ export declare class FormulaDataModel extends Disposable {
63
65
  * @returns
64
66
  */
65
67
  getFormulaDirtyRanges(): IUnitRange[];
66
- private _getSheetFormulaIdMap;
67
68
  private _initSheetArrayFormulaData;
68
69
  }
69
70
  export declare function initSheetFormulaData(formulaData: IFormulaData, unitId: string, sheetId: string, cellMatrix: ObjectMatrix<Nullable<ICellData>>): IFormulaData;
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IUnitRange, LocaleType, Nullable } from '@univerjs/core';
17
- import type { IArrayFormulaRangeType, IDirtyUnitDefinedNameMap, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetNameMap, IDirtyUnitSuperTableMap, IFormulaData, IFormulaDatasetConfig, IRuntimeUnitDataType, IUnitData, IUnitExcludedCell, IUnitRowData, IUnitSheetIdToNameMap, IUnitSheetNameMap, IUnitStylesData } from '../basics/common';
17
+ import type { IArrayFormulaRangeType, IDirtyUnitDefinedNameMap, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetNameMap, IDirtyUnitSuperTableMap, IFormulaData, IFormulaDatasetConfig, IFormulaUnitNameMap, IRuntimeUnitDataType, IUnitData, IUnitExcludedCell, IUnitRowData, IUnitSheetIdToNameMap, IUnitSheetNameMap, IUnitStylesData } from '../basics/common';
18
18
  import { Disposable, IUniverInstanceService, LocaleService } from '@univerjs/core';
19
19
  import { FormulaDataModel } from '../models/formula-data.model';
20
20
  import { ISheetRowFilteredService } from './sheet-row-filtered.service';
@@ -40,6 +40,7 @@ export interface IFormulaCurrentConfigService {
40
40
  getUnitStylesData(): IUnitStylesData;
41
41
  getFormulaData(): IFormulaData;
42
42
  getSheetNameMap(): IUnitSheetNameMap;
43
+ getUnitNameMap(): IFormulaUnitNameMap;
43
44
  isForceCalculate(): boolean;
44
45
  getDirtyRanges(): IUnitRange[];
45
46
  getDirtyNameMap(): IDirtyUnitSheetNameMap;
@@ -49,6 +50,7 @@ export interface IFormulaCurrentConfigService {
49
50
  registerUnitData(unitData: IUnitData): void;
50
51
  registerFormulaData(formulaData: IFormulaData): void;
51
52
  registerSheetNameMap(sheetNameMap: IUnitSheetNameMap): void;
53
+ registerUnitNameMap(unitNameMap: IFormulaUnitNameMap): void;
52
54
  getExcludedRange(): Nullable<IUnitExcludedCell>;
53
55
  loadDirtyRangesAndExcludedCell(dirtyRanges: IUnitRange[], excludedCell?: IUnitExcludedCell): void;
54
56
  getArrayFormulaCellData(): IRuntimeUnitDataType;
@@ -87,6 +89,7 @@ export declare class FormulaCurrentConfigService extends Disposable implements I
87
89
  private _arrayFormulaRange;
88
90
  private _formulaData;
89
91
  private _sheetNameMap;
92
+ private _unitNameMap;
90
93
  private _forceCalculate;
91
94
  private _clearDependencyTreeCache;
92
95
  private _dirtyRanges;
@@ -112,6 +115,7 @@ export declare class FormulaCurrentConfigService extends Disposable implements I
112
115
  getArrayFormulaCellData(): IRuntimeUnitDataType;
113
116
  getArrayFormulaRange(): IArrayFormulaRangeType;
114
117
  getSheetNameMap(): IUnitSheetNameMap;
118
+ getUnitNameMap(): IFormulaUnitNameMap;
115
119
  isForceCalculate(): boolean;
116
120
  getDirtyRanges(): IUnitRange[];
117
121
  getDirtyNameMap(): IDirtyUnitSheetNameMap;
@@ -141,6 +145,7 @@ export declare class FormulaCurrentConfigService extends Disposable implements I
141
145
  registerUnitData(unitData: IUnitData): void;
142
146
  registerFormulaData(formulaData: IFormulaData): void;
143
147
  registerSheetNameMap(sheetNameMap: IUnitSheetNameMap): void;
148
+ registerUnitNameMap(unitNameMap: IFormulaUnitNameMap): void;
144
149
  private _mergeNameMap;
145
150
  private _loadSheetData;
146
151
  /**
@@ -24,13 +24,18 @@ export declare class FormulaCalculationTriggerService extends Disposable {
24
24
  private readonly _commandService;
25
25
  private readonly _activeDirtyManagerService;
26
26
  private _waitingCommandQueue;
27
- private _executingDirtyData;
27
+ private _pendingDirtyData;
28
+ private _runningDirtyData;
28
29
  private _timer;
30
+ private _started;
29
31
  private _executionInProgress;
30
- private _restartCalculation;
32
+ private _hasPendingCalculation;
33
+ private _stopRequested;
31
34
  constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService);
35
+ start(): void;
32
36
  dispose(): void;
33
37
  private _initialize;
38
+ private _scheduleFlush;
34
39
  private _flush;
35
40
  private _startCalculation;
36
41
  private _handleCalculationNotification;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { FormulaUnitType } from '../basics/common';
17
+ import { ErrorType } from '../basics/error-type';
18
+ import { IFormulaCurrentConfigService } from './current-data.service';
19
+ export type FormulaUnitReferenceKind = 'a1' | 'table';
20
+ export interface IFormulaUnitReferenceResolveInput {
21
+ hostUnitId: string;
22
+ qualifier: string;
23
+ referenceKind: FormulaUnitReferenceKind;
24
+ }
25
+ export interface IFormulaUnitReferenceResolution {
26
+ unitId: string;
27
+ unitType?: FormulaUnitType;
28
+ }
29
+ export interface IFormulaUnitReferenceResolver {
30
+ resolve(input: IFormulaUnitReferenceResolveInput): IFormulaUnitReferenceResolution | ErrorType;
31
+ }
32
+ export declare const IFormulaUnitReferenceResolver: import("@wendellhu/redi").IdentifierDecorator<IFormulaUnitReferenceResolver>;
33
+ export declare function normalizeFormulaUnitName(name: string): string;
34
+ export declare class FormulaUnitReferenceResolver implements IFormulaUnitReferenceResolver {
35
+ protected readonly _currentConfigService: IFormulaCurrentConfigService;
36
+ constructor(_currentConfigService: IFormulaCurrentConfigService);
37
+ resolve({ hostUnitId, qualifier, referenceKind, }: IFormulaUnitReferenceResolveInput): IFormulaUnitReferenceResolution | ErrorType;
38
+ private _validateReferenceKind;
39
+ }