@univerjs/engine-formula 0.5.3 → 0.5.4
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.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/es/facade.js +70 -37
- package/lib/es/index.js +2950 -3015
- package/lib/types/engine/utils/generate-ast-node.d.ts +2 -0
- package/lib/types/engine/utils/reference.d.ts +4 -0
- package/lib/types/engine/value-object/lambda-value-object.d.ts +6 -0
- package/lib/types/engine/value-object/primitive-object.d.ts +2 -1
- package/lib/types/facade/f-formula.d.ts +29 -2
- package/lib/types/functions/base-function.d.ts +2 -2
- package/lib/types/index.d.ts +2 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +5 -5
|
@@ -4,5 +4,7 @@ import { Lexer } from '../analysis/lexer';
|
|
|
4
4
|
import { AstTreeBuilder } from '../analysis/parser';
|
|
5
5
|
import { AstRootNode } from '../ast-node/ast-root-node';
|
|
6
6
|
import { IFormulaDependencyTree } from '../dependency/dependency-tree';
|
|
7
|
+
import { FormulaAstLRU } from '../../basics/cache-lru';
|
|
8
|
+
export declare const FORMULA_AST_CACHE: FormulaAstLRU<AstRootNode>;
|
|
7
9
|
export declare function generateAstNode(unitId: string, formulaString: string, lexer: Lexer, astTreeBuilder: AstTreeBuilder, currentConfigService: IFormulaCurrentConfigService): AstRootNode;
|
|
8
10
|
export declare function includeDefinedName(tree: IFormulaDependencyTree, node: Nullable<AstRootNode>, currentConfigService: IFormulaCurrentConfigService): boolean;
|
|
@@ -69,3 +69,7 @@ export declare function isReferenceStrings(refString: string): boolean;
|
|
|
69
69
|
* @returns Result
|
|
70
70
|
*/
|
|
71
71
|
export declare function needsQuoting(name: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Add quotes to the sheet name
|
|
74
|
+
*/
|
|
75
|
+
export declare function addQuotesBothSides(name: string): string;
|
|
@@ -2,6 +2,7 @@ import { Nullable } from '@univerjs/core';
|
|
|
2
2
|
import { BaseAstNode } from '../ast-node/base-ast-node';
|
|
3
3
|
import { Interpreter } from '../interpreter/interpreter';
|
|
4
4
|
import { FunctionVariantType, AsyncObject } from '../reference-object/base-reference-object';
|
|
5
|
+
import { PrimitiveValueType } from './primitive-object';
|
|
5
6
|
import { BaseValueObject } from './base-value-object';
|
|
6
7
|
export declare class LambdaValueObjectObject extends BaseValueObject {
|
|
7
8
|
private _lambdaNode;
|
|
@@ -13,6 +14,11 @@ export declare class LambdaValueObjectObject extends BaseValueObject {
|
|
|
13
14
|
dispose(): void;
|
|
14
15
|
isLambda(): boolean;
|
|
15
16
|
execute(...variants: FunctionVariantType[]): BaseValueObject | AsyncObject;
|
|
17
|
+
/**
|
|
18
|
+
* Execute custom lambda function, handle basic types
|
|
19
|
+
* @param variants
|
|
20
|
+
*/
|
|
21
|
+
executeCustom(...variants: PrimitiveValueType[]): BaseValueObject | AsyncObject;
|
|
16
22
|
private _setLambdaNodeValue;
|
|
17
23
|
private _setLambdaPrivacyValueMap;
|
|
18
24
|
getLambdaPrivacyVarKeys(): string[];
|
|
@@ -2,7 +2,8 @@ import { FormulaAstLRU } from '../../basics/cache-lru';
|
|
|
2
2
|
import { compareToken } from '../../basics/token';
|
|
3
3
|
import { BaseValueObject, ErrorValueObject } from './base-value-object';
|
|
4
4
|
export type PrimitiveValueType = string | boolean | number | null;
|
|
5
|
-
export type FormulaFunctionValueType = PrimitiveValueType | PrimitiveValueType[][];
|
|
5
|
+
export type FormulaFunctionValueType = PrimitiveValueType | PrimitiveValueType[][] | BaseValueObject;
|
|
6
|
+
export type FormulaFunctionResultValueType = PrimitiveValueType | PrimitiveValueType[][];
|
|
6
7
|
export declare class NullValueObject extends BaseValueObject {
|
|
7
8
|
private static _instance;
|
|
8
9
|
static create(): NullValueObject;
|
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
import { IDisposable, FBase, ICommandService, IConfigService, Injector } from '@univerjs/core';
|
|
2
|
-
import { FormulaExecutedStateType, IExecutionInProgressParams } from '@univerjs/engine-formula';
|
|
2
|
+
import { FormulaExecutedStateType, IExecutionInProgressParams, ISequenceNode, LexerTreeBuilder } from '@univerjs/engine-formula';
|
|
3
3
|
/**
|
|
4
4
|
* This interface class provides methods to modify the behavior of the operation formula.
|
|
5
5
|
*/
|
|
6
6
|
export declare class FFormula extends FBase {
|
|
7
7
|
protected readonly _commandService: ICommandService;
|
|
8
8
|
protected readonly _injector: Injector;
|
|
9
|
+
private _lexerTreeBuilder;
|
|
9
10
|
protected readonly _configService: IConfigService;
|
|
10
|
-
constructor(_commandService: ICommandService, _injector: Injector, _configService: IConfigService);
|
|
11
|
+
constructor(_commandService: ICommandService, _injector: Injector, _lexerTreeBuilder: LexerTreeBuilder, _configService: IConfigService);
|
|
11
12
|
_initialize(): void;
|
|
13
|
+
/**
|
|
14
|
+
* The tree builder for formula string.
|
|
15
|
+
* @type {LexerTreeBuilder}
|
|
16
|
+
*/
|
|
17
|
+
get lexerTreeBuilder(): LexerTreeBuilder;
|
|
18
|
+
/**
|
|
19
|
+
* Offsets the formula
|
|
20
|
+
* @param {string} formulaString
|
|
21
|
+
* @param {number} refOffsetX
|
|
22
|
+
* @param {number} refOffsetY
|
|
23
|
+
* @param {boolean} [ignoreAbsolute] default is false
|
|
24
|
+
* @example
|
|
25
|
+
* const result = moveFormulaRefOffset('sum(a1,b2)',1,1)
|
|
26
|
+
* // result is 'sum(b2,c3)'
|
|
27
|
+
*/
|
|
28
|
+
moveFormulaRefOffset(formulaString: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute?: boolean): string;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the formula string to a 'node' node
|
|
31
|
+
* @param {string} formulaString
|
|
32
|
+
* @returns {*} {((string | ISequenceNode)[])}
|
|
33
|
+
* @memberof FFormula
|
|
34
|
+
*/
|
|
35
|
+
sequenceNodesBuilder(formulaString: string): (string | ISequenceNode)[];
|
|
12
36
|
/**
|
|
13
37
|
* Start the calculation of the formula.
|
|
14
38
|
*/
|
|
@@ -19,15 +43,18 @@ export declare class FFormula extends FBase {
|
|
|
19
43
|
stopCalculation(): void;
|
|
20
44
|
/**
|
|
21
45
|
* Listening calculation starts.
|
|
46
|
+
* @param callback
|
|
22
47
|
*/
|
|
23
48
|
calculationStart(callback: (forceCalculation: boolean) => void): IDisposable;
|
|
24
49
|
/**
|
|
25
50
|
* Listening calculation ends.
|
|
51
|
+
* @param callback
|
|
26
52
|
*/
|
|
27
53
|
calculationEnd(callback: (functionsExecutedState: FormulaExecutedStateType) => void): IDisposable;
|
|
28
54
|
onCalculationEnd(): Promise<void>;
|
|
29
55
|
/**
|
|
30
56
|
* Listening calculation processing.
|
|
57
|
+
* @param callback
|
|
31
58
|
*/
|
|
32
59
|
calculationProcessing(callback: (stageInfo: IExecutionInProgressParams) => void): IDisposable;
|
|
33
60
|
/**
|
|
@@ -3,7 +3,7 @@ import { IFunctionNames } from '../basics/function';
|
|
|
3
3
|
import { BaseReferenceObject, FunctionVariantType, NodeValueType } from '../engine/reference-object/base-reference-object';
|
|
4
4
|
import { ArrayBinarySearchType, ArrayOrderSearchType } from '../engine/utils/compare';
|
|
5
5
|
import { ArrayValueObject } from '../engine/value-object/array-value-object';
|
|
6
|
-
import { FormulaFunctionValueType } from '../engine/value-object/primitive-object';
|
|
6
|
+
import { FormulaFunctionResultValueType, FormulaFunctionValueType } from '../engine/value-object/primitive-object';
|
|
7
7
|
import { FormulaDataModel } from '../models/formula-data.model';
|
|
8
8
|
import { IDefinedNameMapItem } from '../services/defined-names.service';
|
|
9
9
|
import { BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
|
|
@@ -87,7 +87,7 @@ export declare class BaseFunction {
|
|
|
87
87
|
isAddress(): boolean;
|
|
88
88
|
isCustom(): boolean;
|
|
89
89
|
setRefInfo(unitId: string, subUnitId: string, row: number, column: number): void;
|
|
90
|
-
calculateCustom(...arg: Array<FormulaFunctionValueType>):
|
|
90
|
+
calculateCustom(...arg: Array<FormulaFunctionValueType>): FormulaFunctionResultValueType | Promise<FormulaFunctionResultValueType>;
|
|
91
91
|
calculate(...arg: BaseValueObject[]): NodeValueType;
|
|
92
92
|
checkArrayType(variant: FunctionVariantType): boolean;
|
|
93
93
|
/**
|
package/lib/types/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export { handleRefStringInfo } from './engine/utils/reference';
|
|
|
61
61
|
export { generateStringWithSequence, type ISequenceNode, sequenceNodeType } from './engine/utils/sequence';
|
|
62
62
|
export { ArrayValueObject, ValueObjectFactory } from './engine/value-object/array-value-object';
|
|
63
63
|
export { BaseValueObject, ErrorValueObject } from './engine/value-object/base-value-object';
|
|
64
|
-
export type { FormulaFunctionValueType, PrimitiveValueType } from './engine/value-object/primitive-object';
|
|
64
|
+
export type { FormulaFunctionResultValueType, FormulaFunctionValueType, PrimitiveValueType } from './engine/value-object/primitive-object';
|
|
65
65
|
export { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from './engine/value-object/primitive-object';
|
|
66
66
|
export { functionArray } from './functions/array/function-map';
|
|
67
67
|
export { FUNCTION_NAMES_ARRAY } from './functions/array/function-names';
|
|
@@ -115,7 +115,6 @@ export { FormulaExecutedStateType, FormulaExecuteStageType, FormulaRuntimeServic
|
|
|
115
115
|
export { ISuperTableService } from './services/super-table.service';
|
|
116
116
|
export { SuperTableService } from './services/super-table.service';
|
|
117
117
|
export { deserializeRangeWithSheetWithCache } from './engine/utils/reference-cache';
|
|
118
|
-
export { FFormula } from './facade/f-formula';
|
|
119
118
|
export { FormulaDependencyTree, type IFormulaDependencyTree } from './engine/dependency/dependency-tree';
|
|
120
119
|
export { type IOtherFormulaData } from './basics/common';
|
|
121
120
|
export { FormulaDependencyTreeType } from './engine/dependency/dependency-tree';
|
|
@@ -126,3 +125,4 @@ export { DEFAULT_INTERVAL_COUNT } from './services/calculate-formula.service';
|
|
|
126
125
|
export { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, type IUniverEngineFormulaConfig } from './controller/config.schema';
|
|
127
126
|
export { generateRandomDependencyTreeId } from './engine/dependency/formula-dependency';
|
|
128
127
|
export { DependencyManagerBaseService } from './services/dependency-manager.service';
|
|
128
|
+
export { LambdaValueObjectObject } from './engine/value-object/lambda-value-object';
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,o){"use strict";var d=Object.defineProperty,m=Object.getOwnPropertyDescriptor,f=(u,e,t,i)=>{for(var r=i>1?void 0:i?m(e,t):e,s=u.length-1,l;s>=0;s--)(l=u[s])&&(r=(i?l(e,t,r):l(r))||r);return i&&r&&d(e,t,r),r},c=(u,e)=>(t,i)=>e(t,i,u);a.FFormula=class extends n.FBase{constructor(e,t,i,r){super(),this._commandService=e,this._injector=t,this._lexerTreeBuilder=i,this._configService=r,this._initialize()}_initialize(){}get lexerTreeBuilder(){return this._lexerTreeBuilder}moveFormulaRefOffset(e,t,i,r){return this._lexerTreeBuilder.moveFormulaRefOffset(e,t,i,r)}sequenceNodesBuilder(e){return this._lexerTreeBuilder.sequenceNodesBuilder(e)||[]}executeCalculation(){this._commandService.executeCommand(o.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(o.SetFormulaCalculationStopMutation.id,{})}calculationStart(e){return this._commandService.onCommandExecuted(t=>{if(t.id===o.SetFormulaCalculationStartMutation.id){const i=t.params;e(i.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==o.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),r=this.calculationEnd(()=>{clearTimeout(i),r.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==o.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.stageInfo!==void 0&&e(i.stageInfo)})}setMaxIteration(e){this._configService.setConfig(o.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}},a.FFormula=f([c(0,n.Inject(n.ICommandService)),c(1,n.Inject(n.Injector)),c(2,n.Inject(o.LexerTreeBuilder)),c(3,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"})});
|