@univerjs/engine-formula 0.13.0 → 0.14.0-insiders.20251227-b250a8d

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 (33) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/facade.js +218 -36
  4. package/lib/es/index.js +3447 -3180
  5. package/lib/facade.js +218 -36
  6. package/lib/index.js +3447 -3180
  7. package/lib/types/basics/common.d.ts +8 -0
  8. package/lib/types/basics/match-token.d.ts +1 -1
  9. package/lib/types/commands/mutations/formula.mutation.d.ts +9 -0
  10. package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +10 -1
  11. package/lib/types/controller/calculate.controller.d.ts +2 -0
  12. package/lib/types/controller/config.schema.d.ts +1 -0
  13. package/lib/types/engine/analysis/lexer-tree-builder.d.ts +2 -1
  14. package/lib/types/engine/ast-node/reference-node.d.ts +0 -1
  15. package/lib/types/engine/dependency/dependency-tree.d.ts +11 -1
  16. package/lib/types/engine/dependency/formula-dependency.d.ts +9 -4
  17. package/lib/types/engine/utils/reference.d.ts +9 -0
  18. package/lib/types/engine/utils/sequence.d.ts +2 -1
  19. package/lib/types/facade/f-formula.d.ts +164 -2
  20. package/lib/types/index.d.ts +9 -5
  21. package/lib/types/services/active-dirty-manager.service.d.ts +1 -0
  22. package/lib/types/services/calculate-formula.service.d.ts +4 -1
  23. package/lib/types/services/current-data.service.d.ts +1 -0
  24. package/lib/types/services/defined-names.service.d.ts +1 -0
  25. package/lib/types/services/dependency-manager.service.d.ts +3 -0
  26. package/lib/types/services/formula-common.d.ts +18 -0
  27. package/lib/types/services/register-other-formula.service.d.ts +40 -0
  28. package/lib/types/services/runtime.service.d.ts +7 -0
  29. package/lib/types/services/super-table.service.d.ts +4 -0
  30. package/lib/umd/facade.js +1 -1
  31. package/lib/umd/index.js +1 -1
  32. package/package.json +6 -6
  33. package/LICENSE +0 -176
@@ -1,4 +1,5 @@
1
1
  import { ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, Nullable, ObjectMatrix, Styles } from '@univerjs/core';
2
+ import { sequenceNodeType } from '../engine/utils/sequence';
2
3
  import { IImageFormulaInfo } from '../engine/value-object/primitive-object';
3
4
  export declare const ERROR_VALUE_OBJECT_CLASS_TYPE = "errorValueObject";
4
5
  export declare const ASYNC_OBJECT_CLASS_TYPE = "asyncObject";
@@ -206,9 +207,16 @@ export interface IFormulaDatasetConfig {
206
207
  unitStylesData?: IUnitStylesData;
207
208
  unitSheetNameMap?: IUnitSheetNameMap;
208
209
  maxIteration?: number;
210
+ isCalculateTreeModel?: boolean;
209
211
  rowData?: IUnitRowData;
210
212
  }
211
213
  export declare enum ConcatenateType {
212
214
  FRONT = 0,
213
215
  BACK = 1
214
216
  }
217
+ export interface IExprTreeNode {
218
+ value: string;
219
+ children: IExprTreeNode[];
220
+ startIndex: number;
221
+ type?: sequenceNodeType;
222
+ }
@@ -1,5 +1,5 @@
1
1
  import { compareToken, matchToken, operatorToken, prefixToken, suffixToken } from './token';
2
- export declare const FORMULA_LEXER_TOKENS: (operatorToken | suffixToken | compareToken | matchToken | prefixToken)[];
2
+ export declare const FORMULA_LEXER_TOKENS: (operatorToken | suffixToken | compareToken | prefixToken | matchToken)[];
3
3
  export declare function isFormulaLexerToken(str: string): boolean;
4
4
  export declare function includeFormulaLexerToken(str: string): boolean;
5
5
  export declare function normalizeSheetName(sheetName: string): string;
@@ -0,0 +1,9 @@
1
+ import { IMutation } from '@univerjs/core';
2
+ export interface IOtherFormulaMarkDirtyParams {
3
+ [unitId: string]: {
4
+ [sunUnitId: string]: {
5
+ [formulaId: string]: boolean;
6
+ };
7
+ };
8
+ }
9
+ export declare const OtherFormulaMarkDirty: IMutation<IOtherFormulaMarkDirtyParams>;
@@ -1,6 +1,6 @@
1
1
  import { IExecutionOptions, IMutation, IUnitRange, Nullable } from '@univerjs/core';
2
2
  import { IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeOtherUnitDataType, IRuntimeUnitDataPrimitiveType } from '../../basics/common';
3
- import { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson } from '../../engine/dependency/dependency-tree';
3
+ import { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults } from '../../engine/dependency/dependency-tree';
4
4
  import { IFormulaDirtyData } from '../../services/current-data.service';
5
5
  import { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';
6
6
  export interface ISetFormulaCalculationStartMutation extends IFormulaDirtyData {
@@ -34,11 +34,18 @@ export interface ISetQueryFormulaDependencyMutation {
34
34
  export interface ISetQueryFormulaDependencyResultMutation {
35
35
  result: IFormulaDependencyTreeJson[];
36
36
  }
37
+ export interface ISetQueryFormulaDependencyAllMutation {
38
+ unitRanges: IUnitRange[];
39
+ }
40
+ export interface ISetQueryFormulaDependencyAllResultMutation {
41
+ result: IFormulaDependentsAndInRangeResults;
42
+ }
37
43
  /**
38
44
  * TODO: @DR-Univer
39
45
  * Trigger the calculation of the formula and stop the formula
40
46
  */
41
47
  export declare const SetFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation>;
48
+ export declare const SetTriggerFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation>;
42
49
  export declare const SetFormulaStringBatchCalculationMutation: IMutation<ISetFormulaStringBatchCalculationMutation>;
43
50
  export declare const SetFormulaStringBatchCalculationResultMutation: IMutation<ISetFormulaStringBatchCalculationResultMutation>;
44
51
  export interface ISetFormulaCalculationStopMutation {
@@ -60,3 +67,5 @@ export declare const SetCellFormulaDependencyCalculationMutation: IMutation<ISet
60
67
  export declare const SetCellFormulaDependencyCalculationResultMutation: IMutation<ISetCellFormulaDependencyCalculationResultMutation>;
61
68
  export declare const SetQueryFormulaDependencyMutation: IMutation<ISetQueryFormulaDependencyMutation>;
62
69
  export declare const SetQueryFormulaDependencyResultMutation: IMutation<ISetQueryFormulaDependencyResultMutation>;
70
+ export declare const SetQueryFormulaDependencyAllMutation: IMutation<ISetQueryFormulaDependencyAllMutation>;
71
+ export declare const SetQueryFormulaDependencyAllResultMutation: IMutation<ISetQueryFormulaDependencyAllResultMutation>;
@@ -10,9 +10,11 @@ export declare class CalculateController extends Disposable {
10
10
  private _commandExecutedListener;
11
11
  private _calculate;
12
12
  private _queryFormulaDependencyJson;
13
+ private _queryFormulaDependencyAllJson;
13
14
  private _generateAllDependencyTreeJson;
14
15
  private _generateCellDependencyTreeJson;
15
16
  private _calculateFormulaString;
16
17
  private _initialExecuteFormulaListener;
18
+ private _applyTreeResult;
17
19
  private _applyResult;
18
20
  }
@@ -4,6 +4,7 @@ import { BaseFunction } from '../functions/base-function';
4
4
  export declare const ENGINE_FORMULA_PLUGIN_CONFIG_KEY = "engine-formula.config";
5
5
  export declare const DEFAULT_CYCLE_REFERENCE_COUNT = 1;
6
6
  export declare const ENGINE_FORMULA_CYCLE_REFERENCE_COUNT = "CYCLE_REFERENCE_COUNT";
7
+ export declare const ENGINE_FORMULA_RETURN_DEPENDENCY_TREE = "RETURN_DEPENDENCY_TREE";
7
8
  export declare const configSymbol: unique symbol;
8
9
  export interface IUniverEngineFormulaConfig {
9
10
  notExecuteFormula?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { Nullable, AbsoluteRefType, Disposable } from '@univerjs/core';
2
- import { IDirtyUnitSheetDefinedNameMap } from '../../basics/common';
2
+ import { IDirtyUnitSheetDefinedNameMap, IExprTreeNode, ISuperTable } from '../../basics/common';
3
3
  import { IFunctionNames } from '../../basics/function';
4
4
  import { IDefinedNamesServiceParam } from '../../services/defined-names.service';
5
5
  import { ISequenceArray, ISequenceNode } from '../utils/sequence';
@@ -145,5 +145,6 @@ export declare class LexerTreeBuilder extends Disposable {
145
145
  private _isScientificNotation;
146
146
  private _addSequenceArray;
147
147
  getNewFormulaWithPrefix(formulaString: string, hasFunction: (functionToken: IFunctionNames) => boolean): string | null;
148
+ getFormulaExprTree(formulaString: string, unitId: string, hasFunction: (functionToken: IFunctionNames) => boolean, getDefinedNameName: (unitId: string, name: string) => Nullable<IDefinedNamesServiceParam>, getTable: (unitId: string, tableName: string) => Nullable<ISuperTable>): IExprTreeNode | null;
148
149
  }
149
150
  export {};
@@ -36,7 +36,6 @@ export declare class ReferenceNodeFactory extends BaseAstNodeFactory {
36
36
  private _getTableMap;
37
37
  private _getNode;
38
38
  private _getTableReferenceNode;
39
- private _splitTableStructuredRef;
40
39
  private _checkTokenIsTableReference;
41
40
  private _checkParentIsUnionOperator;
42
41
  }
@@ -15,6 +15,7 @@ export declare enum FormulaDependencyTreeType {
15
15
  }
16
16
  declare class FormulaDependencyTreeCalculator {
17
17
  private _state;
18
+ type: FormulaDependencyTreeType;
18
19
  resetState(): void;
19
20
  setAdded(): void;
20
21
  isAdded(): boolean;
@@ -77,7 +78,6 @@ export declare class FormulaDependencyTree extends FormulaDependencyTreeCalculat
77
78
  featureDirtyRanges: IUnitRange[];
78
79
  refOffsetX: number;
79
80
  refOffsetY: number;
80
- type: FormulaDependencyTreeType;
81
81
  formulaId: Nullable<string>;
82
82
  subUnitId: string;
83
83
  unitId: string;
@@ -126,6 +126,9 @@ interface IFormulaDependencyTreeJsonBase {
126
126
  refOffsetY: number;
127
127
  rangeList: IUnitRange[];
128
128
  refTreeId: number | undefined;
129
+ formulaId: Nullable<string>;
130
+ featureId: Nullable<string>;
131
+ type: Nullable<FormulaDependencyTreeType>;
129
132
  }
130
133
  export interface IFormulaDependencyTreeJson extends IFormulaDependencyTreeJsonBase {
131
134
  children: number[];
@@ -135,6 +138,10 @@ export interface IFormulaDependencyTreeFullJson extends IFormulaDependencyTreeJs
135
138
  children: IFormulaDependencyTreeJson[];
136
139
  parents: IFormulaDependencyTreeJson[];
137
140
  }
141
+ export interface IFormulaDependentsAndInRangeResults {
142
+ dependents: IFormulaDependencyTreeJson[];
143
+ inRanges: IFormulaDependencyTreeJson[];
144
+ }
138
145
  export declare class FormulaDependencyTreeModel {
139
146
  children: Set<FormulaDependencyTreeModel>;
140
147
  parents: Set<FormulaDependencyTreeModel>;
@@ -148,6 +155,9 @@ export declare class FormulaDependencyTreeModel {
148
155
  subUnitId: string;
149
156
  rangeList: IUnitRange[];
150
157
  refTreeId: number | undefined;
158
+ formulaId: Nullable<string>;
159
+ featureId: Nullable<string>;
160
+ type: Nullable<FormulaDependencyTreeType>;
151
161
  constructor(tree: IFormulaDependencyTree);
152
162
  toJson(): IFormulaDependencyTreeJson;
153
163
  toFullJson(): IFormulaDependencyTreeFullJson;
@@ -4,7 +4,7 @@ import { IFeatureCalculationManagerParam, IFeatureCalculationManagerService } fr
4
4
  import { FunctionNode } from '../ast-node';
5
5
  import { BaseAstNode } from '../ast-node/base-ast-node';
6
6
  import { IExecuteAstNodeData } from '../utils/ast-node-tool';
7
- import { IFormulaDependencyTree, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, FormulaDependencyTree, FormulaDependencyTreeModel, FormulaDependencyTreeVirtual } from './dependency-tree';
7
+ import { IFormulaDependencyTree, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults, FormulaDependencyTree, FormulaDependencyTreeModel, FormulaDependencyTreeVirtual } from './dependency-tree';
8
8
  import { IFormulaCurrentConfigService } from '../../services/current-data.service';
9
9
  import { IDependencyManagerService } from '../../services/dependency-manager.service';
10
10
  import { IOtherFormulaManagerService } from '../../services/other-formula-manager.service';
@@ -15,11 +15,12 @@ import { AstTreeBuilder } from '../analysis/parser';
15
15
  import { Interpreter } from '../interpreter/interpreter';
16
16
  export declare function generateRandomDependencyTreeId(dependencyManagerService: IDependencyManagerService): number;
17
17
  export interface IFormulaDependencyGenerator {
18
- generate(): Promise<IFormulaDependencyTree[]>;
18
+ generate(isCalculateTreeModel?: boolean): Promise<IFormulaDependencyTree[]>;
19
19
  getAllDependencyJson(): Promise<IFormulaDependencyTreeJson[]>;
20
20
  getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
21
21
  getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
22
22
  getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
23
+ getRangeDependentsAndInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependentsAndInRangeResults>;
23
24
  }
24
25
  export declare const IFormulaDependencyGenerator: import('@wendellhu/redi').IdentifierDecorator<IFormulaDependencyGenerator>;
25
26
  export declare class FormulaDependencyGenerator extends Disposable {
@@ -36,7 +37,7 @@ export declare class FormulaDependencyGenerator extends Disposable {
36
37
  protected _dependencyRTreeCacheForAddressFunction: RTree;
37
38
  constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _otherFormulaManagerService: IOtherFormulaManagerService, _featureCalculationManagerService: IFeatureCalculationManagerService, _interpreter: Interpreter, _astTreeBuilder: AstTreeBuilder, _lexer: Lexer, _dependencyManagerService: IDependencyManagerService, _lexerTreeBuilder: LexerTreeBuilder);
38
39
  dispose(): void;
39
- generate(): Promise<(FormulaDependencyTree | FormulaDependencyTreeVirtual)[]>;
40
+ generate(isCalculateTreeModel?: boolean): Promise<(FormulaDependencyTree | FormulaDependencyTreeVirtual)[]>;
40
41
  private _dependencyFeatureCalculation;
41
42
  private _clearFeatureCalculationNode;
42
43
  /**
@@ -119,15 +120,19 @@ export declare class FormulaDependencyGenerator extends Disposable {
119
120
  protected _initializeGenerateTreeList(): Promise<IFormulaDependencyTree[]>;
120
121
  protected _getAllTreeList(): Promise<IFormulaDependencyTree[]>;
121
122
  protected _formulaDependencyTreeModel: Map<number, FormulaDependencyTreeModel>;
122
- protected _getTreeModel(treeId: number): FormulaDependencyTreeModel;
123
+ protected _getTreeModel(treeId: number): FormulaDependencyTreeModel | undefined;
123
124
  protected _getDependencyTreeParenIds(tree: IFormulaDependencyTree): Set<number>;
124
125
  protected _getDependencyTreeChildrenIds(tree: IFormulaDependencyTree): Set<number>;
125
126
  protected _getFormulaDependencyTreeModel(tree: IFormulaDependencyTree): FormulaDependencyTreeModel;
126
127
  protected _endFormulaDependencyTreeModel(): void;
127
128
  protected _startFormulaDependencyTreeModel(): void;
129
+ protected _getAllDependencyJson(treeList: IFormulaDependencyTree[]): IFormulaDependencyTreeJson[];
128
130
  getAllDependencyJson(): Promise<IFormulaDependencyTreeJson[]>;
129
131
  protected _setRealFormulaString(treeModel: FormulaDependencyTreeModel): void;
130
132
  getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
133
+ protected _getRangeDependents(unitRanges: IUnitRange[]): IFormulaDependencyTreeJson[];
131
134
  getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
135
+ protected _getInRangeFormulas(unitRanges: IUnitRange[], treeList: IFormulaDependencyTree[]): IFormulaDependencyTreeJson[];
132
136
  getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
137
+ getRangeDependentsAndInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependentsAndInRangeResults>;
133
138
  }
@@ -85,3 +85,12 @@ export declare function quoteSheetName(name: string): string;
85
85
  * @returns Unquoted name
86
86
  */
87
87
  export declare function unquoteSheetName(name: string): string;
88
+ export declare function splitTableStructuredRef(ref: string): {
89
+ tableName: string;
90
+ struct: string;
91
+ columnStruct?: undefined;
92
+ } | {
93
+ tableName: string;
94
+ columnStruct: string;
95
+ struct?: undefined;
96
+ };
@@ -6,7 +6,8 @@ export declare enum sequenceNodeType {
6
6
  FUNCTION = 3,
7
7
  REFERENCE = 4,
8
8
  ARRAY = 5,
9
- DEFINED_NAME = 6
9
+ DEFINED_NAME = 6,
10
+ TABLE = 7
10
11
  }
11
12
  export interface ISequenceNode {
12
13
  nodeType: sequenceNodeType;
@@ -1,5 +1,5 @@
1
1
  import { IDisposable, IUnitRange, ICommandService, IConfigService, Injector } from '@univerjs/core';
2
- import { FormulaExecutedStateType, IExecutionInProgressParams, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaExecuteResultMap, IFormulaStringMap, ISequenceNode, ISetFormulaCalculationResultMutation, LexerTreeBuilder } from '@univerjs/engine-formula';
2
+ import { FormulaExecutedStateType, IExecutionInProgressParams, IExprTreeNode, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults, IFormulaExecuteResultMap, IFormulaStringMap, ISequenceNode, ISetFormulaCalculationResultMutation, IDefinedNamesService, IFunctionService, ISuperTableService, LexerTreeBuilder } from '@univerjs/engine-formula';
3
3
  import { FBase } from '@univerjs/core/facade';
4
4
  /**
5
5
  * This interface class provides methods to modify the behavior of the operation formula.
@@ -10,7 +10,10 @@ export declare class FFormula extends FBase {
10
10
  protected readonly _injector: Injector;
11
11
  private _lexerTreeBuilder;
12
12
  protected readonly _configService: IConfigService;
13
- constructor(_commandService: ICommandService, _injector: Injector, _lexerTreeBuilder: LexerTreeBuilder, _configService: IConfigService);
13
+ private readonly _functionService;
14
+ private readonly _definedNamesService;
15
+ private readonly _superTableService;
16
+ constructor(_commandService: ICommandService, _injector: Injector, _lexerTreeBuilder: LexerTreeBuilder, _configService: IConfigService, _functionService: IFunctionService, _definedNamesService: IDefinedNamesService, _superTableService: ISuperTableService);
14
17
  /**
15
18
  * @ignore
16
19
  */
@@ -399,4 +402,163 @@ export declare class FFormula extends FBase {
399
402
  * ```
400
403
  */
401
404
  getInRangeFormulas(unitRanges: IUnitRange[], timeout?: number): Promise<IFormulaDependencyTreeJson[]>;
405
+ /**
406
+ * Enable or disable emitting formula dependency trees after each formula calculation.
407
+ *
408
+ * When enabled, the formula engine will emit the dependency trees produced by
409
+ * each completed formula calculation through the internal command system.
410
+ * Consumers can obtain the result by listening for the corresponding
411
+ * calculation-result command.
412
+ *
413
+ * When disabled, dependency trees will not be emitted.
414
+ *
415
+ * This option only controls whether dependency trees are exposed.
416
+ * It does not affect formula calculation behavior.
417
+ *
418
+ * @param {boolean} value
419
+ * Whether to emit formula dependency trees after calculation.
420
+ * - `true`: Emit dependency trees after each calculation.
421
+ * - `false`: Do not emit dependency trees (default behavior).
422
+ *
423
+ * @example
424
+ * ```ts
425
+ * const formulaEngine = univerAPI.getFormula();
426
+ *
427
+ * // Enable dependency tree emission
428
+ * formulaEngine.setFormulaReturnDependencyTree(true);
429
+ *
430
+ * // Listen for dependency trees produced by formula calculation
431
+ * const trees = await new Promise<IFormulaDependencyTreeJson[]>((resolve, reject) => {
432
+ * const timer = setTimeout(() => {
433
+ * disposable.dispose();
434
+ * reject(new Error('Timeout waiting for formula dependency trees'));
435
+ * }, 30_000);
436
+ *
437
+ * const disposable = commandService.onCommandExecuted((command) => {
438
+ * if (command.id !== SetFormulaDependencyCalculationResultMutation.id) {
439
+ * return;
440
+ * }
441
+ *
442
+ * clearTimeout(timer);
443
+ * disposable.dispose();
444
+ *
445
+ * const params = command.params as ISetFormulaDependencyCalculationResultMutation;
446
+ * resolve(params.result ?? []);
447
+ * });
448
+ * });
449
+ *
450
+ * console.log('Dependency trees:', trees);
451
+ * ```
452
+ */
453
+ setFormulaReturnDependencyTree(value: boolean): void;
454
+ /**
455
+ * Parse a formula string and return its **formula expression tree**.
456
+ *
457
+ * This API analyzes the syntactic structure of a formula and builds an
458
+ * expression tree that reflects how the formula is composed (functions,
459
+ * operators, ranges, and nested expressions), without performing calculation
460
+ * or dependency evaluation.
461
+ *
462
+ * The returned tree is suitable for:
463
+ * - Formula structure visualization
464
+ * - Explaining complex formulas (e.g. LET / LAMBDA)
465
+ * - Debugging or inspecting formula composition
466
+ * - Building advanced formula tooling
467
+ *
468
+ * ---
469
+ *
470
+ * @example
471
+ * ```ts
472
+ * const formulaEngine = univerAPI.getFormula();
473
+ *
474
+ * const formula = '=LET(x,SUM(A1,B1,A1:B10),y,OFFSET(A1:B10,0,1),SUM(x,y)+x)+1';
475
+ *
476
+ * const exprTree = formulaEngine.getFormulaExpressTree(formula);
477
+ *
478
+ * console.log(exprTree);
479
+ * ```
480
+ *
481
+ * Example output (simplified):
482
+ *
483
+ * ```json
484
+ * {
485
+ * "value": "let(x,sum(A1,B1,A1:B10),y,offset(A1:B10,0,1),sum(x,y)+x)+1",
486
+ * "children": [
487
+ * {
488
+ * "value": "let(x,sum(A1,B1,A1:B10),y,offset(A1:B10,0,1),sum(x,y)+x)",
489
+ * "children": [
490
+ * {
491
+ * "value": "sum(A1,B1,A1:B10)",
492
+ * "children": [
493
+ * {
494
+ * "value": "A1:B10",
495
+ * "children": []
496
+ * }
497
+ * ]
498
+ * },
499
+ * {
500
+ * "value": "offset(A1:B10,0,1)",
501
+ * "children": [
502
+ * {
503
+ * "value": "A1:B10",
504
+ * "children": []
505
+ * }
506
+ * ]
507
+ * }
508
+ * ]
509
+ * }
510
+ * ]
511
+ * }
512
+ * ```
513
+ *
514
+ * @param formulaString The formula string to parse (with or without leading `=`)
515
+ * @returns A formula expression tree describing the hierarchical structure of the formula
516
+ */
517
+ getFormulaExpressTree(formulaString: string, unitId: string): IExprTreeNode | null;
518
+ /**
519
+ * Retrieve **both**:
520
+ * 1) the full dependency trees of all formulas that **depend on** the specified ranges, and
521
+ * 2) the dependency trees of all formulas that **physically reside inside** the specified ranges.
522
+ *
523
+ * This is a convenience API that combines the behaviors of
524
+ * `getRangeDependents` and `getInRangeFormulas` into a single call.
525
+ *
526
+ * Internally, it triggers a local dependency-calculation command once and
527
+ * resolves when both result sets are available, avoiding duplicate
528
+ * calculations and event listeners.
529
+ *
530
+ * @param unitRanges An array of workbook/sheet ranges to query. Each range
531
+ * includes:
532
+ * - `unitId` The workbook ID.
533
+ * - `sheetId` The sheet ID.
534
+ * - `range` The zero-based row/column boundaries.
535
+ *
536
+ * @param {number} [timeout]
537
+ * Optional timeout in milliseconds. If the dependency calculation does
538
+ * not complete within this period, the promise will be rejected.
539
+ *
540
+ * @returns {Promise<IFormulaDependentsAndInRangeResults>}
541
+ * A promise that resolves with an object containing:
542
+ * - `dependents`: Dependency trees of all formulas that depend on the
543
+ * specified ranges (upstream consumers).
544
+ * - `inRanges`: Dependency trees of all formulas whose definitions
545
+ * are located inside the specified ranges.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * const formulaEngine = univerAPI.getFormula();
550
+ *
551
+ * const result = await formulaEngine.getRangeDependentsAndInRangeFormulas([
552
+ * {
553
+ * unitId: 'workbook1',
554
+ * sheetId: 'sheet1',
555
+ * range: { startRow: 0, endRow: 9, startColumn: 0, endColumn: 1 },
556
+ * },
557
+ * ]);
558
+ *
559
+ * console.log('Dependent formulas:', result.dependents);
560
+ * console.log('Formulas inside range:', result.inRanges);
561
+ * ```
562
+ */
563
+ getRangeDependentsAndInRangeFormulas(unitRanges: IUnitRange[], timeout?: number): Promise<IFormulaDependentsAndInRangeResults>;
402
564
  }
@@ -16,7 +16,7 @@
16
16
  export type { IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IArrayFormulaUnitCellType, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, IFeatureDirtyRangeType, IFormulaData, IFormulaDataItem, IFormulaDatasetConfig, IFormulaExecuteResultMap, IFormulaStringMap, 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
- export { type IUnitRowData } from './basics/common';
19
+ export type { IExprTreeNode, ISuperTable, IUnitRowData } from './basics/common';
20
20
  export { isInDirtyRange } from './basics/dirty';
21
21
  export { ERROR_TYPE_SET, ErrorType } from './basics/error-type';
22
22
  export { type ISheetFormulaError } from './basics/error-type';
@@ -28,19 +28,20 @@ export { isReferenceString } from './basics/regex';
28
28
  export { convertUnitDataToRuntime } from './basics/runtime';
29
29
  export { compareToken, matchToken, OPERATOR_TOKEN_SET, operatorToken, prefixToken, SUFFIX_TOKEN_SET } from './basics/token';
30
30
  export { DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME, DEFAULT_TOKEN_LET_FUNCTION_NAME, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, DEFAULT_TOKEN_TYPE_PARAMETER, DEFAULT_TOKEN_TYPE_ROOT } from './basics/token-type';
31
+ export { OtherFormulaMarkDirty } from './commands/mutations/formula.mutation';
31
32
  export { RegisterFunctionMutation } from './commands/mutations/register-function.mutation';
32
33
  export { type ISetArrayFormulaDataMutationParams, SetArrayFormulaDataMutation } from './commands/mutations/set-array-formula-data.mutation';
33
34
  export { type ISetDefinedNameMutationParam, type ISetDefinedNameMutationSearchParam, RemoveDefinedNameMutation, SetDefinedNameMutation } from './commands/mutations/set-defined-name.mutation';
34
35
  export { SetDefinedNameMutationFactory } from './commands/mutations/set-defined-name.mutation';
35
36
  export { RemoveFeatureCalculationMutation, SetFeatureCalculationMutation } from './commands/mutations/set-feature-calculation.mutation';
36
- export { type ISetCellFormulaDependencyCalculationResultMutation, type ISetFormulaCalculationNotificationMutation, type ISetFormulaCalculationResultMutation, type ISetFormulaCalculationStartMutation, type ISetFormulaDependencyCalculationMutation, type ISetFormulaDependencyCalculationResultMutation, type ISetFormulaStringBatchCalculationResultMutation, type ISetQueryFormulaDependencyResultMutation, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, } from './commands/mutations/set-formula-calculation.mutation';
37
+ export { type ISetCellFormulaDependencyCalculationResultMutation, type ISetFormulaCalculationNotificationMutation, type ISetFormulaCalculationResultMutation, type ISetFormulaCalculationStartMutation, type ISetFormulaDependencyCalculationMutation, type ISetFormulaDependencyCalculationResultMutation, type ISetFormulaStringBatchCalculationResultMutation, type ISetQueryFormulaDependencyAllResultMutation, type ISetQueryFormulaDependencyResultMutation, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetQueryFormulaDependencyAllMutation, SetQueryFormulaDependencyAllResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, SetTriggerFormulaCalculationStartMutation, } from './commands/mutations/set-formula-calculation.mutation';
37
38
  export { type ISetFormulaDataMutationParams, SetFormulaDataMutation } from './commands/mutations/set-formula-data.mutation';
38
39
  export { type ISetImageFormulaDataMutationParams, SetImageFormulaDataMutation } from './commands/mutations/set-image-formula-data.mutation';
39
40
  export { type IRemoveOtherFormulaMutationParams, type ISetOtherFormulaMutationParams, RemoveOtherFormulaMutation, SetOtherFormulaMutation } from './commands/mutations/set-other-formula.mutation';
40
41
  export { RemoveSuperTableMutation, SetSuperTableMutation, SetSuperTableOptionMutation } from './commands/mutations/set-super-table.mutation';
41
42
  export type { ISetSuperTableMutationParam, ISetSuperTableMutationSearchParam } from './commands/mutations/set-super-table.mutation';
42
43
  export { CalculateController } from './controller/calculate.controller';
43
- export { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, type IUniverEngineFormulaConfig } from './controller/config.schema';
44
+ export { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, type IUniverEngineFormulaConfig } from './controller/config.schema';
44
45
  export { Lexer } from './engine/analysis/lexer';
45
46
  export { LexerNode } from './engine/analysis/lexer-node';
46
47
  export { LexerTreeBuilder } from './engine/analysis/lexer-tree-builder';
@@ -56,7 +57,7 @@ export { ReferenceNodeFactory } from './engine/ast-node/reference-node';
56
57
  export { SuffixNodeFactory } from './engine/ast-node/suffix-node';
57
58
  export { UnionNodeFactory } from './engine/ast-node/union-node';
58
59
  export { ValueNodeFactory } from './engine/ast-node/value-node';
59
- export { FormulaDependencyTree, FormulaDependencyTreeModel, type IFormulaDependencyTree, type IFormulaDependencyTreeFullJson, type IFormulaDependencyTreeJson } from './engine/dependency/dependency-tree';
60
+ export { FormulaDependencyTree, FormulaDependencyTreeModel, type IFormulaDependencyTree, type IFormulaDependencyTreeFullJson, type IFormulaDependencyTreeJson, type IFormulaDependentsAndInRangeResults } from './engine/dependency/dependency-tree';
60
61
  export { FormulaDependencyTreeType } from './engine/dependency/dependency-tree';
61
62
  export { FormulaDependencyTreeVirtual } from './engine/dependency/dependency-tree';
62
63
  export { FormulaDependencyGenerator, IFormulaDependencyGenerator } from './engine/dependency/formula-dependency';
@@ -71,7 +72,7 @@ export { generateAstNode } from './engine/utils/generate-ast-node';
71
72
  export { strip, stripErrorMargin } from './engine/utils/math-kit';
72
73
  export { handleNumfmtInCell } from './engine/utils/numfmt-kit';
73
74
  export { deserializeRangeForR1C1 } from './engine/utils/r1c1-reference';
74
- export { deserializeRangeWithSheet, getAbsoluteRefTypeWithSingleString, getAbsoluteRefTypeWitString, getRangeWithRefsString, type IAbsoluteRefTypeForRange, isReferenceStrings, isReferenceStringWithEffectiveColumn, needsQuoting, quoteSheetName, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, singleReferenceToGrid, unquoteSheetName, } from './engine/utils/reference';
75
+ export { deserializeRangeWithSheet, getAbsoluteRefTypeWithSingleString, getAbsoluteRefTypeWitString, getRangeWithRefsString, type IAbsoluteRefTypeForRange, isReferenceStrings, isReferenceStringWithEffectiveColumn, needsQuoting, quoteSheetName, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, singleReferenceToGrid, splitTableStructuredRef, unquoteSheetName, } from './engine/utils/reference';
75
76
  export { handleRefStringInfo } from './engine/utils/reference';
76
77
  export { deserializeRangeWithSheetWithCache } from './engine/utils/reference-cache';
77
78
  export { generateStringWithSequence, type ISequenceNode, sequenceNodeType } from './engine/utils/sequence';
@@ -129,11 +130,14 @@ export { DependencyManagerService } from './services/dependency-manager.service'
129
130
  export { DependencyManagerBaseService } from './services/dependency-manager.service';
130
131
  export { FeatureCalculationManagerService, IFeatureCalculationManagerService } from './services/feature-calculation-manager.service';
131
132
  export type { IFeatureCalculationManagerParam } from './services/feature-calculation-manager.service';
133
+ export type { IFormulaInfo, IOtherFormulaResult } from './services/formula-common';
134
+ export { FormulaResultStatus } from './services/formula-common';
132
135
  export { FunctionService } from './services/function.service';
133
136
  export { IFunctionService } from './services/function.service';
134
137
  export { GlobalComputingStatusService } from './services/global-computing-status.service';
135
138
  export { HyperlinkEngineFormulaService, IHyperlinkEngineFormulaService } from './services/hyperlink-engine-formula.service';
136
139
  export { IOtherFormulaManagerService, OtherFormulaManagerService } from './services/other-formula-manager.service';
140
+ export { OtherFormulaBizType, RegisterOtherFormulaService } from './services/register-other-formula.service';
137
141
  export { FormulaExecutedStateType, FormulaExecuteStageType, FormulaRuntimeService, type IAllRuntimeData, type IExecutionInProgressParams, IFormulaRuntimeService } from './services/runtime.service';
138
142
  export { ISheetRowFilteredService, SheetRowFilteredService } from './services/sheet-row-filtered.service';
139
143
  export { ISuperTableService } from './services/super-table.service';
@@ -3,6 +3,7 @@ import { IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefined
3
3
  export interface IDirtyConversionManagerParams {
4
4
  commandId: string;
5
5
  getDirtyData: (command: ICommandInfo) => {
6
+ forceCalculation?: boolean;
6
7
  dirtyRanges?: IUnitRange[];
7
8
  dirtyNameMap?: IDirtyUnitSheetNameMap;
8
9
  dirtyDefinedNameMap?: IDirtyUnitSheetDefinedNameMap;
@@ -1,7 +1,7 @@
1
1
  import { IUnitRange, Disposable, IConfigService } from '@univerjs/core';
2
2
  import { Observable, Subject } from 'rxjs';
3
3
  import { IFeatureDirtyRangeType, IFormulaDatasetConfig, IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeUnitDataType, IUnitRowData } from '../basics/common';
4
- import { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson } from '../engine/dependency/dependency-tree';
4
+ import { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults } from '../engine/dependency/dependency-tree';
5
5
  import { FunctionVariantType } from '../engine/reference-object/base-reference-object';
6
6
  import { IAllRuntimeData, IExecutionInProgressParams, IFormulaRuntimeService } from './runtime.service';
7
7
  import { Lexer } from '../engine/analysis/lexer';
@@ -25,6 +25,7 @@ export interface ICalculateFormulaService {
25
25
  getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number, rowData?: IUnitRowData): Promise<IFormulaDependencyTreeFullJson | undefined>;
26
26
  getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
27
27
  getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
28
+ getDependentsAndInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependentsAndInRangeResults>;
28
29
  }
29
30
  export declare const ICalculateFormulaService: import('@wendellhu/redi').IdentifierDecorator<ICalculateFormulaService>;
30
31
  export declare class CalculateFormulaService extends Disposable implements ICalculateFormulaService {
@@ -40,6 +41,7 @@ export declare class CalculateFormulaService extends Disposable implements ICalc
40
41
  protected readonly _executionCompleteListener$: Subject<IAllRuntimeData>;
41
42
  readonly executionCompleteListener$: Observable<IAllRuntimeData>;
42
43
  private _executeLock;
44
+ protected _isCalculateTreeModel: boolean;
43
45
  constructor(_configService: IConfigService, _lexer: Lexer, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _formulaDependencyGenerator: IFormulaDependencyGenerator, _interpreter: Interpreter, _astTreeBuilder: AstTreeBuilder);
44
46
  dispose(): void;
45
47
  /**
@@ -65,4 +67,5 @@ export declare class CalculateFormulaService extends Disposable implements ICalc
65
67
  getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
66
68
  getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
67
69
  getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
70
+ getDependentsAndInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependentsAndInRangeResults>;
68
71
  }
@@ -11,6 +11,7 @@ export interface IFormulaDirtyData {
11
11
  dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
12
12
  clearDependencyTreeCache: IDirtyUnitSheetNameMap;
13
13
  maxIteration?: number;
14
+ isCalculateTreeModel?: boolean;
14
15
  rowData?: IUnitRowData;
15
16
  }
16
17
  export interface IFormulaCurrentConfigService {
@@ -64,6 +64,7 @@ export declare class DefinedNamesService extends Disposable implements IDefinedN
64
64
  getValueById(unitId: string, id: string): IDefinedNamesServiceParam;
65
65
  hasDefinedName(unitId: string): boolean;
66
66
  getAllDefinedNames(): IDefinedNameMap;
67
+ getDefinedNameByRefString(unitId: string, formulaOrRefString: string): IDefinedNamesServiceParam | undefined;
67
68
  private _update;
68
69
  private _updateCache;
69
70
  }
@@ -26,6 +26,7 @@ export interface IDependencyManagerService {
26
26
  getTreeById(treeId: number): Nullable<IFormulaDependencyTree>;
27
27
  getAllTree(): IFormulaDependencyTree[];
28
28
  buildDependencyTree(shouldBeBuildTrees: IFormulaDependencyTree[], dependencyTrees?: IFormulaDependencyTree[]): IFormulaDependencyTree[];
29
+ updateDependencyTreeDirtyState(treeId: number, isDirty: boolean): void;
29
30
  }
30
31
  export declare class DependencyManagerBaseService extends Disposable implements IDependencyManagerService {
31
32
  buildDependencyTree(shouldBeBuildTrees: IFormulaDependencyTree[], dependencyTrees?: IFormulaDependencyTree[]): IFormulaDependencyTree[];
@@ -62,6 +63,7 @@ export declare class DependencyManagerBaseService extends Disposable implements
62
63
  protected _addAllTreeMap(tree: IFormulaDependencyTree): void;
63
64
  protected _addDefinedName(unitId: string, definedName: string, treeId: number): void;
64
65
  addFormulaDependencyByDefinedName(tree: IFormulaDependencyTree, node: Nullable<AstRootNode>): void;
66
+ updateDependencyTreeDirtyState(treeId: number, isDirty: boolean): void;
65
67
  }
66
68
  /**
67
69
  * Passively marked as dirty, register the reference and execution actions of the feature plugin.
@@ -111,5 +113,6 @@ export declare class DependencyManagerService extends DependencyManagerBaseServi
111
113
  removeFormulaDependencyByDefinedName(unitId: string, definedName: string): void;
112
114
  protected _removeAllTreeMap(treeId: Nullable<number>): void;
113
115
  protected _addAllTreeMap(tree: IFormulaDependencyTree): void;
116
+ updateDependencyTreeDirtyState(treeId: number, isDirty: boolean): void;
114
117
  }
115
118
  export declare const IDependencyManagerService: import('@wendellhu/redi').IdentifierDecorator<DependencyManagerService>;
@@ -0,0 +1,18 @@
1
+ import { ICellData, IObjectMatrixPrimitiveType, Nullable } from '@univerjs/core';
2
+ export declare enum FormulaResultStatus {
3
+ NOT_REGISTER = 1,
4
+ SUCCESS = 2,
5
+ WAIT = 3,
6
+ ERROR = 4
7
+ }
8
+ export interface IOtherFormulaResult {
9
+ result?: IObjectMatrixPrimitiveType<Nullable<ICellData>[][]>;
10
+ status: FormulaResultStatus;
11
+ formulaId: string;
12
+ callbacks: Set<(value: IObjectMatrixPrimitiveType<Nullable<ICellData>[][]>) => void>;
13
+ extra?: Record<string, any>;
14
+ }
15
+ export interface IFormulaInfo {
16
+ id: string;
17
+ text: string;
18
+ }