@univerjs/engine-formula 0.5.1 → 0.5.2

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.
@@ -169,6 +169,7 @@ export interface IFormulaDatasetConfig {
169
169
  allUnitData?: IUnitData;
170
170
  unitStylesData?: IUnitStylesData;
171
171
  unitSheetNameMap?: IUnitSheetNameMap;
172
+ maxIteration?: number;
172
173
  }
173
174
  export declare enum ConcatenateType {
174
175
  FRONT = 0,
@@ -2,6 +2,8 @@ import { Ctor } from '@univerjs/core';
2
2
  import { IFunctionNames } from '../basics/function';
3
3
  import { BaseFunction } from '../functions/base-function';
4
4
  export declare const ENGINE_FORMULA_PLUGIN_CONFIG_KEY = "engine-formula.config";
5
+ export declare const DEFAULT_CYCLE_REFERENCE_COUNT = 1;
6
+ export declare const ENGINE_FORMULA_CYCLE_REFERENCE_COUNT = "CYCLE_REFERENCE_COUNT";
5
7
  export declare const configSymbol: unique symbol;
6
8
  export interface IUniverEngineFormulaConfig {
7
9
  notExecuteFormula?: boolean;
@@ -40,7 +40,7 @@ export declare class LexerTreeBuilder extends Disposable {
40
40
  */
41
41
  checkIfAddBracket(formulaString: string): number;
42
42
  sequenceNodesBuilder(formulaString: string): (string | ISequenceNode)[] | undefined;
43
- convertRefersToAbsolute(formulaString: string, startAbsoluteRefType: AbsoluteRefType, endAbsoluteRefType: AbsoluteRefType): string;
43
+ convertRefersToAbsolute(formulaString: string, startAbsoluteRefType: AbsoluteRefType, endAbsoluteRefType: AbsoluteRefType, currentSheetName?: string): string;
44
44
  moveFormulaRefOffset(formulaString: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute?: boolean): string;
45
45
  /**
46
46
  * univer-pro/issues/1684
@@ -1,7 +1,7 @@
1
1
  import { IDirtyUnitSheetNameMap, IFeatureDirtyRangeType, IRuntimeUnitDataType, IUnitExcludedCell } from '../../basics/common';
2
2
  import { IFormulaDirtyData } from '../../services/current-data.service';
3
3
  import { IAllRuntimeData } from '../../services/runtime.service';
4
- import { AstRootNode } from '../ast-node';
4
+ import { AstRootNode, FunctionNode } from '../ast-node';
5
5
  import { IRange, IUnitRange, Nullable } from '@univerjs/core';
6
6
  export declare enum FDtreeStateType {
7
7
  DEFAULT = 0,
@@ -38,6 +38,7 @@ export declare class FormulaDependencyTreeVirtual extends FormulaDependencyTreeC
38
38
  refOffsetY: number;
39
39
  isCache: boolean;
40
40
  isDirty: boolean;
41
+ addressFunctionNodes: FunctionNode[];
41
42
  get isVirtual(): boolean;
42
43
  get row(): number;
43
44
  get column(): number;
@@ -88,6 +89,7 @@ export declare class FormulaDependencyTree extends FormulaDependencyTreeCalculat
88
89
  columnCount: number;
89
90
  isDirty: boolean;
90
91
  node: Nullable<AstRootNode>;
92
+ addressFunctionNodes: FunctionNode[];
91
93
  constructor(treeId: number);
92
94
  get isVirtual(): boolean;
93
95
  get nodeData(): {
@@ -1,6 +1,7 @@
1
- import { IRange, IUnitRange, Nullable, Disposable } from '@univerjs/core';
1
+ import { IRange, IUnitRange, Nullable, Disposable, RTree } from '@univerjs/core';
2
2
  import { IFeatureDirtyRangeType, IFormulaData, IFormulaDataItem, IOtherFormulaData, IUnitData } from '../../basics/common';
3
3
  import { IFeatureCalculationManagerParam, IFeatureCalculationManagerService } from '../../services/feature-calculation-manager.service';
4
+ import { FunctionNode } from '../ast-node';
4
5
  import { BaseAstNode } from '../ast-node/base-ast-node';
5
6
  import { IExecuteAstNodeData } from '../utils/ast-node-tool';
6
7
  import { IFormulaDependencyTree, FormulaDependencyTree, FormulaDependencyTreeVirtual } from './dependency-tree';
@@ -26,6 +27,7 @@ export declare class FormulaDependencyGenerator extends Disposable {
26
27
  protected readonly _lexer: Lexer;
27
28
  protected readonly _dependencyManagerService: IDependencyManagerService;
28
29
  private _updateRangeFlattenCache;
30
+ protected _dependencyRTreeCacheForAddressFunction: RTree;
29
31
  constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _otherFormulaManagerService: IOtherFormulaManagerService, _featureCalculationManagerService: IFeatureCalculationManagerService, _interpreter: Interpreter, _astTreeBuilder: AstTreeBuilder, _lexer: Lexer, _dependencyManagerService: IDependencyManagerService);
30
32
  dispose(): void;
31
33
  generate(): Promise<(FormulaDependencyTree | FormulaDependencyTreeVirtual)[]>;
@@ -71,6 +73,23 @@ export declare class FormulaDependencyGenerator extends Disposable {
71
73
  * @param node
72
74
  */
73
75
  protected _getRangeListByNode(nodeData: IExecuteAstNodeData): Promise<IUnitRange[]>;
76
+ protected _getAddressFunctionNodeList(node: Nullable<BaseAstNode>): FunctionNode[];
77
+ protected _getTreeNode(tree: IFormulaDependencyTree): import('../ast-node').AstRootNode;
78
+ protected _buildDirtyRangesByAddressFunction(treeDependencyCache: RTree, tree: IFormulaDependencyTree): Promise<void>;
79
+ private _executedAddressFunctionNodeIds;
80
+ protected _calculateListByFunctionRefNode(treeList: IFormulaDependencyTree[]): Promise<void>;
81
+ private _calculateAddressFunction;
82
+ private _calculateAddressFunctionRuntimeData;
83
+ private _buildTreeNodeById;
84
+ private _searchDependencyByAddressFunction;
85
+ protected _getTreeById(treeId: number): Nullable<IFormulaDependencyTree>;
86
+ private _addDependencyTreeByAddressFunction;
87
+ /**
88
+ * Calculate the range required for collection in advance,
89
+ * including references and location functions (such as OFFSET, INDIRECT, INDEX, etc.).
90
+ * @param node
91
+ */
92
+ protected _getRangeListByFunctionRefNode(referenceFunctionList: FunctionNode[], refOffsetX: number, refOffsetY: number): Promise<IUnitRange[]>;
74
93
  /**
75
94
  * Build a formula dependency tree based on the dependency relationships.
76
95
  * @param treeList
@@ -44,4 +44,3 @@ export declare enum ReferenceObjectType {
44
44
  }
45
45
  export declare function getReferenceObjectFromCache(trimToken: string, type: ReferenceObjectType): BaseReferenceObject;
46
46
  export declare function getRangeReferenceObjectFromCache(variant1: BaseReferenceObject, variant2: BaseReferenceObject): FunctionVariantType;
47
- export declare function clearReferenceObjectCache(): void;
@@ -1,4 +1,4 @@
1
- import { IDisposable, FBase, ICommandService, Injector } from '@univerjs/core';
1
+ import { IDisposable, FBase, ICommandService, IConfigService, Injector } from '@univerjs/core';
2
2
  import { FormulaExecutedStateType, IExecutionInProgressParams } from '@univerjs/engine-formula';
3
3
  /**
4
4
  * This interface class provides methods to modify the behavior of the operation formula.
@@ -6,7 +6,8 @@ import { FormulaExecutedStateType, IExecutionInProgressParams } from '@univerjs/
6
6
  export declare class FFormula extends FBase {
7
7
  private readonly _commandService;
8
8
  protected readonly _injector: Injector;
9
- constructor(_commandService: ICommandService, _injector: Injector);
9
+ protected readonly _configService: IConfigService;
10
+ constructor(_commandService: ICommandService, _injector: Injector, _configService: IConfigService);
10
11
  /**
11
12
  * Start the calculation of the formula.
12
13
  */
@@ -28,4 +29,16 @@ export declare class FFormula extends FBase {
28
29
  * Listening calculation processing.
29
30
  */
30
31
  calculationProcessing(callback: (stageInfo: IExecutionInProgressParams) => void): IDisposable;
32
+ /**
33
+ * When a formula contains a circular reference, set the maximum number of iterations for the formula calculation.
34
+ * @param maxIteration The maximum number of iterations. The default value is 1.
35
+ * @example
36
+ * ```ts
37
+ * // Set the maximum number of iterations for the formula calculation to 5.
38
+ * // The default value is 1.
39
+ * const formulaEngine = univerAPI.getFormula();
40
+ * formulaEngine.setMaxIteration(5);
41
+ * ```
42
+ */
43
+ setMaxIteration(maxIteration: number): void;
31
44
  }
@@ -4,6 +4,5 @@ export declare class Choose extends BaseFunction {
4
4
  minParams: number;
5
5
  maxParams: number;
6
6
  needsReferenceObject: boolean;
7
- isAddress(): boolean;
8
7
  calculate(indexNum: FunctionVariantType, ...variants: FunctionVariantType[]): FunctionVariantType;
9
8
  }
@@ -1,7 +1,7 @@
1
1
  import { Base } from './base';
2
2
  import { FUNCTION_NAMES_MATH } from './function-names';
3
+ import { Product } from './product';
3
4
  import { Randarray } from './randarray';
4
5
  import { Subtotal } from './subtotal';
5
- import { Sum } from './sum';
6
6
  import { Sumifs } from './sumifs';
7
- export declare const functionMath: ((FUNCTION_NAMES_MATH | typeof Base)[] | (FUNCTION_NAMES_MATH | typeof Randarray)[] | (FUNCTION_NAMES_MATH | typeof Subtotal)[] | (FUNCTION_NAMES_MATH | typeof Sum)[] | (FUNCTION_NAMES_MATH | typeof Sumifs)[])[];
7
+ export declare const functionMath: ((FUNCTION_NAMES_MATH | typeof Base)[] | (FUNCTION_NAMES_MATH | typeof Product)[] | (FUNCTION_NAMES_MATH | typeof Randarray)[] | (FUNCTION_NAMES_MATH | typeof Subtotal)[] | (FUNCTION_NAMES_MATH | typeof Sumifs)[])[];
@@ -4,5 +4,4 @@ export declare class Product extends BaseFunction {
4
4
  minParams: number;
5
5
  maxParams: number;
6
6
  calculate(...variants: BaseValueObject[]): BaseValueObject;
7
- private _multiplyArray;
8
7
  }
@@ -1,5 +1,5 @@
1
- import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
2
1
  import { BaseValueObject } from '../../../engine/value-object/base-value-object';
2
+ import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
3
3
  import { BaseFunction } from '../../base-function';
4
4
  export declare class Sumifs extends BaseFunction {
5
5
  minParams: number;
@@ -34,7 +34,6 @@ export { type ISetFormulaDataMutationParams, SetFormulaDataMutation } from './co
34
34
  export { type IRemoveOtherFormulaMutationParams, type ISetOtherFormulaMutationParams, RemoveOtherFormulaMutation, SetOtherFormulaMutation } from './commands/mutations/set-other-formula.mutation';
35
35
  export { RemoveSuperTableMutation, SetSuperTableMutation, SetSuperTableOptionMutation } from './commands/mutations/set-super-table.mutation';
36
36
  export { CalculateController } from './controller/calculate.controller';
37
- export { SetDefinedNameController } from './controller/set-defined-name.controller';
38
37
  export { Lexer } from './engine/analysis/lexer';
39
38
  export { LexerNode } from './engine/analysis/lexer-node';
40
39
  export { LexerTreeBuilder } from './engine/analysis/lexer-tree-builder';
@@ -124,6 +123,6 @@ export { FormulaDependencyTreeVirtual } from './engine/dependency/dependency-tre
124
123
  export { generateAstNode } from './engine/utils/generate-ast-node';
125
124
  export { type IFeatureCalculationManagerParam } from './services/feature-calculation-manager.service';
126
125
  export { DEFAULT_INTERVAL_COUNT } from './services/calculate-formula.service';
127
- export { ENGINE_FORMULA_PLUGIN_CONFIG_KEY, type IUniverEngineFormulaConfig } from './controller/config.schema';
126
+ export { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, type IUniverEngineFormulaConfig } from './controller/config.schema';
128
127
  export { generateRandomDependencyTreeId } from './engine/dependency/formula-dependency';
129
128
  export { DependencyManagerBaseService } from './services/dependency-manager.service';
@@ -8,7 +8,6 @@ import { ErrorNode } from '../engine/ast-node/base-ast-node';
8
8
  import { IFormulaDependencyGenerator } from '../engine/dependency/formula-dependency';
9
9
  import { Interpreter } from '../engine/interpreter/interpreter';
10
10
  import { IFormulaCurrentConfigService } from './current-data.service';
11
- export declare const DEFAULT_CYCLE_REFERENCE_COUNT = 1;
12
11
  export declare const DEFAULT_INTERVAL_COUNT = 500;
13
12
  export declare const CYCLE_REFERENCE_COUNT = "cycleReferenceCount";
14
13
  export declare const EVERY_N_FUNCTION_EXECUTION_PAUSE = 100;
@@ -8,6 +8,7 @@ export interface IFormulaDirtyData {
8
8
  dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
9
9
  dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
10
10
  clearDependencyTreeCache: IDirtyUnitSheetNameMap;
11
+ maxIteration?: number;
11
12
  }
12
13
  export interface IFormulaCurrentConfigService {
13
14
  load(config: IFormulaDatasetConfig): void;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.UniverEngineFormulaFacade={},i.UniverCore,i.UniverEngineFormula))})(this,function(i,a,u){"use strict";var m=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=(r,t,e,n)=>{for(var o=n>1?void 0:n?d(t,e):t,c=r.length-1,s;c>=0;c--)(s=r[c])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&m(t,e,o),o},l=(r,t)=>(e,n)=>t(e,n,r);i.FFormula=class extends a.FBase{constructor(t,e){super(),this._commandService=t,this._injector=e}executeCalculation(){this._commandService.executeCommand(u.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(u.SetFormulaCalculationStopMutation.id,{})}calculationStart(t){return this._commandService.onCommandExecuted(e=>{if(e.id===u.SetFormulaCalculationStartMutation.id){const n=e.params;t(n.forceCalculation)}})}calculationEnd(t){return this._commandService.onCommandExecuted(e=>{if(e.id!==u.SetFormulaCalculationNotificationMutation.id)return;const n=e.params;n.functionsExecutedState!==void 0&&t(n.functionsExecutedState)})}onCalculationEnd(){return new Promise((t,e)=>{const n=setTimeout(()=>{e(new Error("Calculation end timeout"))},3e4),o=this.calculationEnd(()=>{clearTimeout(n),o.dispose(),t()})})}calculationProcessing(t){return this._commandService.onCommandExecuted(e=>{if(e.id!==u.SetFormulaCalculationNotificationMutation.id)return;const n=e.params;n.stageInfo!==void 0&&t(n.stageInfo)})}},i.FFormula=f([l(0,a.Inject(a.ICommandService)),l(1,a.Inject(a.Injector))],i.FFormula);class v extends a.FUniver{getFormula(){return this._injector.createInstance(i.FFormula)}}a.FUniver.extend(v),Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula"],n):(a=typeof globalThis<"u"?globalThis:a||self,n(a.UniverEngineFormulaFacade={},a.UniverCore,a.UniverEngineFormula))})(this,function(a,n,r){"use strict";var m=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=(u,e,t,i)=>{for(var o=i>1?void 0:i?d(e,t):e,s=u.length-1,l;s>=0;s--)(l=u[s])&&(o=(i?l(e,t,o):l(o))||o);return i&&o&&m(e,t,o),o},c=(u,e)=>(t,i)=>e(t,i,u);a.FFormula=class extends n.FBase{constructor(e,t,i){super(),this._commandService=e,this._injector=t,this._configService=i}executeCalculation(){this._commandService.executeCommand(r.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(r.SetFormulaCalculationStopMutation.id,{})}calculationStart(e){return this._commandService.onCommandExecuted(t=>{if(t.id===r.SetFormulaCalculationStartMutation.id){const i=t.params;e(i.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.functionsExecutedState!==void 0&&e(i.functionsExecutedState)})}onCalculationEnd(){return new Promise((e,t)=>{const i=setTimeout(()=>{t(new Error("Calculation end timeout"))},3e4),o=this.calculationEnd(()=>{clearTimeout(i),o.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.stageInfo!==void 0&&e(i.stageInfo)})}setMaxIteration(e){this._configService.setConfig(r.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}},a.FFormula=f([c(0,n.Inject(n.ICommandService)),c(1,n.Inject(n.Injector)),c(2,n.IConfigService)],a.FFormula);class v extends n.FUniver{getFormula(){return this._injector.createInstance(a.FFormula)}}n.FUniver.extend(v),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});