@univerjs/engine-formula 1.0.4 → 1.1.0
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/{en-US-DrAfIiBE.js → en-US-BYMYuEpp.js} +15 -15
- package/lib/cjs/facade.js +3 -18
- package/lib/cjs/index.js +450 -161
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/zh-HK.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/cjs/{zh-TW-CvMudVQy.js → zh-TW-B5pYt-NJ.js} +15 -15
- package/lib/es/facade.js +3 -18
- package/lib/es/index.js +424 -135
- package/lib/facade.js +3 -18
- package/lib/index.js +424 -135
- package/lib/types/basics/common.d.ts +8 -2
- package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +2 -1
- package/lib/types/config/config.d.ts +0 -2
- package/lib/types/engine/dependency/dependency-groups.d.ts +21 -0
- package/lib/types/engine/dependency/dependency-tree.d.ts +1 -0
- package/lib/types/engine/dependency/formula-dependency.d.ts +1 -1
- package/lib/types/facade/f-formula.d.ts +0 -13
- package/lib/types/functions/lookup/xlookup/index.d.ts +2 -4
- package/lib/types/index.d.ts +4 -2
- package/lib/types/models/formula-data.model.d.ts +5 -0
- package/lib/types/services/active-dirty-manager.service.d.ts +1 -0
- package/lib/types/services/calculate-formula.service.d.ts +34 -2
- package/lib/types/services/current-data.service.d.ts +4 -2
- package/lib/types/services/formula-calculation-trigger.service.d.ts +5 -0
- package/lib/types/services/formula-changeset-calculation.service.d.ts +34 -0
- package/lib/types/services/runtime.service.d.ts +36 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +4 -4
- package/package.json +5 -5
|
@@ -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, UniverInstanceType } from '@univerjs/core';
|
|
16
|
+
import type { ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, IWorkbookCalculationSettings, 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";
|
|
@@ -243,6 +243,12 @@ export interface IUnitRowData {
|
|
|
243
243
|
}>;
|
|
244
244
|
}
|
|
245
245
|
export interface IFormulaDatasetConfig {
|
|
246
|
+
/** Recalculate iteration-sensitive groups and their dependents in these workbooks. */
|
|
247
|
+
dirtyIterationUnits?: string[];
|
|
248
|
+
/** Snapshot replay limits calculation to affected cycles and their required precedents. */
|
|
249
|
+
calculateCircularOnly?: boolean;
|
|
250
|
+
/** Finalize replay by calculating ordinary formulas without advancing complete circular caches. */
|
|
251
|
+
preserveCircularUnits?: string[];
|
|
246
252
|
formulaData: IFormulaData;
|
|
247
253
|
arrayFormulaCellData: IArrayFormulaUnitCellType;
|
|
248
254
|
arrayFormulaRange: IArrayFormulaRangeType;
|
|
@@ -260,7 +266,7 @@ export interface IFormulaDatasetConfig {
|
|
|
260
266
|
unitSheetNameMap?: IUnitSheetNameMap;
|
|
261
267
|
unitNameMap?: IFormulaUnitNameMap;
|
|
262
268
|
externalReferences?: IFormulaExternalReferences;
|
|
263
|
-
|
|
269
|
+
calculationSettings?: Record<string, IWorkbookCalculationSettings>;
|
|
264
270
|
isCalculateTreeModel?: boolean;
|
|
265
271
|
rowData?: IUnitRowData;
|
|
266
272
|
}
|
|
@@ -17,7 +17,7 @@ import type { IExecutionOptions, IMutation, IUnitRange, Nullable } from '@univer
|
|
|
17
17
|
import type { IFormulaData, IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeOtherUnitDataType, IRuntimeUnitDataPrimitiveType } from '../../basics/common';
|
|
18
18
|
import type { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults } from '../../engine/dependency/dependency-tree';
|
|
19
19
|
import type { IFormulaDirtyData } from '../../services/current-data.service';
|
|
20
|
-
import type { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';
|
|
20
|
+
import type { FormulaExecutedStateType, ICircularReference, IExecutionInProgressParams } from '../../services/runtime.service';
|
|
21
21
|
export interface ISetFormulaCalculationStartMutation extends IFormulaDirtyData {
|
|
22
22
|
options: Nullable<IExecutionOptions>;
|
|
23
23
|
}
|
|
@@ -67,6 +67,7 @@ export interface ISetFormulaCalculationStopMutation {
|
|
|
67
67
|
}
|
|
68
68
|
export declare const SetFormulaCalculationStopMutation: IMutation<ISetFormulaCalculationStopMutation>;
|
|
69
69
|
export interface ISetFormulaCalculationNotificationMutation {
|
|
70
|
+
circularReferences?: ICircularReference[];
|
|
70
71
|
functionsExecutedState?: FormulaExecutedStateType;
|
|
71
72
|
stageInfo?: IExecutionInProgressParams;
|
|
72
73
|
}
|
|
@@ -17,8 +17,6 @@ import type { Ctor } from '@univerjs/core';
|
|
|
17
17
|
import type { IFunctionNames } from '../basics/function';
|
|
18
18
|
import type { BaseFunction } from '../functions/base-function';
|
|
19
19
|
export declare const ENGINE_FORMULA_PLUGIN_CONFIG_KEY = "engine-formula.config";
|
|
20
|
-
export declare const DEFAULT_CYCLE_REFERENCE_COUNT = 1;
|
|
21
|
-
export declare const ENGINE_FORMULA_CYCLE_REFERENCE_COUNT = "CYCLE_REFERENCE_COUNT";
|
|
22
20
|
export declare const ENGINE_FORMULA_RETURN_DEPENDENCY_TREE = "RETURN_DEPENDENCY_TREE";
|
|
23
21
|
export declare const configSymbol: unique symbol;
|
|
24
22
|
export interface IUniverEngineFormulaConfig {
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* Returns strongly connected components in dependency order: precedents before their dependents.
|
|
18
|
+
* Mutually dependent nodes stay together so only their group needs iterative calculation.
|
|
19
|
+
* Uses iterative Kosaraju traversal to avoid overflowing the call stack on large dependency graphs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getDependencyGroups<T>(nodes: T[], getId: (node: T) => number, getDependents: (node: T) => Iterable<number>): T[][];
|
|
@@ -60,7 +60,6 @@ export declare class FormulaDependencyGenerator extends Disposable implements IF
|
|
|
60
60
|
private _initUnitDispose;
|
|
61
61
|
private _disposeByUnitId;
|
|
62
62
|
generate(isCalculateTreeModel?: boolean): Promise<(FormulaDependencyTree | FormulaDependencyTreeVirtual)[]>;
|
|
63
|
-
private _isCyclicUtilMap;
|
|
64
63
|
protected _checkIsCycleDependency(treeList: IFormulaDependencyTree[]): boolean;
|
|
65
64
|
protected _getFeatureFormulaTree(featureId: string, treeId: Nullable<number>, params: IFeatureCalculationManagerParam): FormulaDependencyTree;
|
|
66
65
|
protected _registerOtherFormulas(otherFormulaData: IOtherFormulaData, otherFormulaDataKeys: string[], treeList: IFormulaDependencyTree[]): void;
|
|
@@ -104,6 +103,7 @@ export declare class FormulaDependencyGenerator extends Disposable implements IF
|
|
|
104
103
|
protected _updateRangeFlatten(): void;
|
|
105
104
|
private _addFlattenCache;
|
|
106
105
|
private _isPreCalculateNode;
|
|
106
|
+
private _isStaticReference;
|
|
107
107
|
private _nodeTraversalRef;
|
|
108
108
|
private _nodeTraversalReferenceFunction;
|
|
109
109
|
private _executeNode;
|
|
@@ -148,19 +148,6 @@ export declare class FFormula extends FBase {
|
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
calculationProcessing(callback: (stageInfo: IExecutionInProgressParams) => void): IDisposable;
|
|
151
|
-
/**
|
|
152
|
-
* When a formula contains a circular reference, set the maximum number of iterations for the formula calculation.
|
|
153
|
-
* @param {number} maxIteration The maximum number of iterations. The default value is 1.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* // Set the maximum number of iterations for the formula calculation to 5.
|
|
158
|
-
* // The default value is 1.
|
|
159
|
-
* const formulaEngine = univerAPI.getFormula();
|
|
160
|
-
* formulaEngine.setMaxIteration(5);
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
setMaxIteration(maxIteration: number): void;
|
|
164
151
|
/**
|
|
165
152
|
* Execute a batch of formulas asynchronously and receive computed results.
|
|
166
153
|
*
|
|
@@ -21,10 +21,8 @@ export declare class Xlookup extends BaseFunction {
|
|
|
21
21
|
calculate(lookupValue: BaseValueObject, lookupArray: BaseValueObject, returnArray: BaseValueObject, ifNotFound?: BaseValueObject, matchMode?: BaseValueObject, searchMode?: BaseValueObject): BaseValueObject;
|
|
22
22
|
private _getResult;
|
|
23
23
|
private _legacyImplicitLookupValue;
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private _exactSearch;
|
|
27
|
-
private _exactSearchExpand;
|
|
24
|
+
private _getLookupResult;
|
|
25
|
+
private _findPosition;
|
|
28
26
|
private _findExactPosition;
|
|
29
27
|
private _isExactMatch;
|
|
30
28
|
private _blankResultAsZero;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from './commands/
|
|
|
48
48
|
export type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams, } from './commands/mutations/set-other-formula.mutation';
|
|
49
49
|
export { RemoveSuperTableMutation, SetSuperTableMutation, SetSuperTableOptionMutation, } from './commands/mutations/set-super-table.mutation';
|
|
50
50
|
export type { IRemoveSuperTableMutationParam, ISetSuperTableMutationParam, ISetSuperTableMutationSearchParam, } from './commands/mutations/set-super-table.mutation';
|
|
51
|
-
export {
|
|
51
|
+
export { ENGINE_FORMULA_PLUGIN_CONFIG_KEY, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, } from './config/config';
|
|
52
52
|
export type { IUniverEngineFormulaConfig } from './config/config';
|
|
53
53
|
export { CalculateController } from './controllers/calculate.controller';
|
|
54
54
|
export { FormulaCalculationSessionController } from './controllers/formula-calculation-session.controller';
|
|
@@ -152,7 +152,8 @@ export { IFormulaExternalReferenceDataLoader, NoopFormulaExternalReferenceDataLo
|
|
|
152
152
|
export type { IFormulaExternalReferenceLoadInput } from './services/external-reference-data-loader.service';
|
|
153
153
|
export { FeatureCalculationManagerService, IFeatureCalculationManagerService, } from './services/feature-calculation-manager.service';
|
|
154
154
|
export type { IFeatureCalculationManagerParam } from './services/feature-calculation-manager.service';
|
|
155
|
-
export { FormulaCalculationTriggerService } from './services/formula-calculation-trigger.service';
|
|
155
|
+
export { FormulaCalculationTriggerService, mergeDirtyData } from './services/formula-calculation-trigger.service';
|
|
156
|
+
export { IFormulaChangesetCalculationService } from './services/formula-changeset-calculation.service';
|
|
156
157
|
export type { IFormulaInfo, IOtherFormulaResult } from './services/formula-common';
|
|
157
158
|
export { FormulaResultStatus } from './services/formula-common';
|
|
158
159
|
export { DescriptionService, IDescriptionService } from './services/formula/description.service';
|
|
@@ -186,6 +187,7 @@ export { IOtherFormulaManagerService, OtherFormulaManagerService } from './servi
|
|
|
186
187
|
export { OtherFormulaBizType, RegisterOtherFormulaService } from './services/register-other-formula.service';
|
|
187
188
|
export { FormulaExecutedStateType, FormulaExecuteStageType, FormulaRuntimeService, IFormulaRuntimeService, } from './services/runtime.service';
|
|
188
189
|
export type { IAllRuntimeData, IExecutionInProgressParams } from './services/runtime.service';
|
|
190
|
+
export type { ICircularReference } from './services/runtime.service';
|
|
189
191
|
export { ISheetRowFilteredService, SheetRowFilteredService } from './services/sheet-row-filtered.service';
|
|
190
192
|
export { ISuperTableService } from './services/super-table.service';
|
|
191
193
|
export { SuperTableService } from './services/super-table.service';
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { ICellData, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable } from '@univerjs/core';
|
|
17
17
|
import type { IArrayFormulaRangeType, IArrayFormulaUnitCellType, IFormulaData, IFormulaDataItem, IFormulaUnitNameMap, IRuntimeUnitDataType, IUnitData, IUnitImageFormulaDataType, IUnitRowData, IUnitSheetNameMap, IUnitStylesData } from '../basics/common';
|
|
18
|
+
import type { ICircularReference } from '../services/runtime.service';
|
|
18
19
|
import { Disposable, IUniverInstanceService, ObjectMatrix } from '@univerjs/core';
|
|
19
20
|
import { LexerTreeBuilder } from '../engine/analysis/lexer-tree-builder';
|
|
20
21
|
export interface IRangeChange {
|
|
@@ -24,12 +25,16 @@ export interface IRangeChange {
|
|
|
24
25
|
export declare class FormulaDataModel extends Disposable {
|
|
25
26
|
private readonly _univerInstanceService;
|
|
26
27
|
private readonly _lexerTreeBuilder;
|
|
28
|
+
private _circularReferences;
|
|
27
29
|
private _formulaIdMapData;
|
|
28
30
|
private _arrayFormulaRange;
|
|
29
31
|
private _arrayFormulaCellData;
|
|
30
32
|
private _unitImageFormulaData;
|
|
31
33
|
constructor(_univerInstanceService: IUniverInstanceService, _lexerTreeBuilder: LexerTreeBuilder);
|
|
32
34
|
dispose(): void;
|
|
35
|
+
setCircularReferences(cells: ICircularReference[]): void;
|
|
36
|
+
getCircularReferences(unitId: string): ICircularReference[];
|
|
37
|
+
isCircularReference(unitId: string, sheetId: string, row: number, column: number): boolean;
|
|
33
38
|
clearPreviousArrayFormulaCellData(clearArrayFormulaCellData: IRuntimeUnitDataType): void;
|
|
34
39
|
mergeArrayFormulaCellData(unitData: IRuntimeUnitDataType): void;
|
|
35
40
|
getFormulaData(): IFormulaData;
|
|
@@ -20,6 +20,7 @@ export interface IDirtyConversionManagerParams {
|
|
|
20
20
|
commandId: string;
|
|
21
21
|
shouldTrigger?: (command: ICommandInfo, options?: IExecutionOptions) => boolean;
|
|
22
22
|
getDirtyData: (command: ICommandInfo) => {
|
|
23
|
+
dirtyIterationUnits?: string[];
|
|
23
24
|
forceCalculation?: boolean;
|
|
24
25
|
dirtyRanges?: IUnitRange[];
|
|
25
26
|
dirtyNameMap?: IDirtyUnitSheetNameMap;
|
|
@@ -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 { IUnitRange } from '@univerjs/core';
|
|
16
|
+
import type { ICellData, IUnitRange, IWorkbookCalculationSettings } from '@univerjs/core';
|
|
17
17
|
import type { Observable } from 'rxjs';
|
|
18
18
|
import type { IArrayFormulaRangeType, IFeatureDirtyRangeType, IFormulaDatasetConfig, IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeUnitDataType, IUnitExcludedCell, IUnitRowData } from '../basics/common';
|
|
19
19
|
import type { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults } from '../engine/dependency/dependency-tree';
|
|
@@ -28,7 +28,6 @@ import { Interpreter } from '../engine/interpreter/interpreter';
|
|
|
28
28
|
import { IFormulaCurrentConfigService } from './current-data.service';
|
|
29
29
|
import { IFormulaRuntimeService } from './runtime.service';
|
|
30
30
|
export declare const DEFAULT_INTERVAL_COUNT = 500;
|
|
31
|
-
export declare const CYCLE_REFERENCE_COUNT = "cycleReferenceCount";
|
|
32
31
|
export declare const EVERY_N_FUNCTION_EXECUTION_PAUSE = 100;
|
|
33
32
|
export interface ICalculateFormulaService {
|
|
34
33
|
readonly executionInProgressListener$: Observable<IExecutionInProgressParams>;
|
|
@@ -60,6 +59,39 @@ export declare class CalculateFormulaService extends Disposable implements ICalc
|
|
|
60
59
|
readonly executionCompleteListener$: Observable<IAllRuntimeData>;
|
|
61
60
|
protected _executeLock: AsyncLock;
|
|
62
61
|
protected _isCalculateTreeModel: boolean;
|
|
62
|
+
protected _workbookCalculationSettings: Record<string, IWorkbookCalculationSettings>;
|
|
63
|
+
protected _preserveCircularUnits: Set<string>;
|
|
64
|
+
private readonly _normalizedCalculationSettings;
|
|
65
|
+
protected _loadCalculationSettings(settings?: Record<string, IWorkbookCalculationSettings>): void;
|
|
66
|
+
protected _getCalculationSettings(unitId: string): IWorkbookCalculationSettings;
|
|
67
|
+
protected _getIterationCell(tree: {
|
|
68
|
+
unitId: string;
|
|
69
|
+
subUnitId: string;
|
|
70
|
+
row: number;
|
|
71
|
+
column: number;
|
|
72
|
+
}): Pick<ICellData, 'v' | 't'>;
|
|
73
|
+
protected _iterateCalculationGroup<T extends {
|
|
74
|
+
unitId: string;
|
|
75
|
+
subUnitId: string;
|
|
76
|
+
row: number;
|
|
77
|
+
column: number;
|
|
78
|
+
formula?: string;
|
|
79
|
+
}>(group: T[], groupId: string): AsyncGenerator<{
|
|
80
|
+
tree: T;
|
|
81
|
+
preserve: boolean;
|
|
82
|
+
iteration: number;
|
|
83
|
+
}, void, unknown>;
|
|
84
|
+
protected _getCalculationSteps<T extends {
|
|
85
|
+
cycleGroup?: string;
|
|
86
|
+
unitId: string;
|
|
87
|
+
subUnitId: string;
|
|
88
|
+
row: number;
|
|
89
|
+
column: number;
|
|
90
|
+
}>(trees: T[]): AsyncGenerator<{
|
|
91
|
+
tree: T;
|
|
92
|
+
preserve: boolean;
|
|
93
|
+
iteration: number;
|
|
94
|
+
}, void, unknown>;
|
|
63
95
|
constructor(_configService: IConfigService, _lexer: Lexer, _currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _formulaDependencyGenerator: IFormulaDependencyGenerator, _interpreter: Interpreter, _astTreeBuilder: AstTreeBuilder);
|
|
64
96
|
dispose(): void;
|
|
65
97
|
/**
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IUnitRange, LocaleType, Nullable } from '@univerjs/core';
|
|
16
|
+
import type { IUnitRange, IWorkbookCalculationSettings, LocaleType, Nullable } from '@univerjs/core';
|
|
17
17
|
import type { IArrayFormulaRangeType, IDirtyUnitDefinedNameMap, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetNameMap, IDirtyUnitSuperTableMap, IFormulaData, IFormulaDatasetConfig, IFormulaExternalReferences, IFormulaUnitNameMap, IRuntimeUnitDataType, IUnitData, IUnitExcludedCell, IUnitRowData, IUnitSheetIdToNameMap, IUnitSheetNameMap, IUnitStylesData } from '../basics/common';
|
|
18
18
|
import { DateSystem, Disposable, IUniverInstanceService, LocaleService } from '@univerjs/core';
|
|
19
19
|
import { FormulaDataModel } from '../models/formula-data.model';
|
|
20
20
|
import { ISheetRowFilteredService } from './sheet-row-filtered.service';
|
|
21
21
|
export interface IFormulaDirtyData {
|
|
22
|
+
dirtyIterationUnits?: string[];
|
|
22
23
|
forceCalculation: boolean;
|
|
23
24
|
dirtyRanges: IUnitRange[];
|
|
24
25
|
dirtyNameMap: IDirtyUnitSheetNameMap;
|
|
@@ -27,7 +28,7 @@ export interface IFormulaDirtyData {
|
|
|
27
28
|
dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
|
|
28
29
|
dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
|
|
29
30
|
clearDependencyTreeCache: IDirtyUnitSheetNameMap;
|
|
30
|
-
|
|
31
|
+
calculationSettings?: Record<string, IWorkbookCalculationSettings>;
|
|
31
32
|
isCalculateTreeModel?: boolean;
|
|
32
33
|
rowData?: IUnitRowData;
|
|
33
34
|
externalReferences?: IFormulaExternalReferences;
|
|
@@ -87,6 +88,7 @@ export declare class FormulaCurrentConfigService extends Disposable implements I
|
|
|
87
88
|
private readonly _localeService;
|
|
88
89
|
private readonly _formulaDataModel;
|
|
89
90
|
private readonly _sheetRowFilteredService;
|
|
91
|
+
private _dirtyIterationUnits;
|
|
90
92
|
private _unitData;
|
|
91
93
|
private _unitStylesData;
|
|
92
94
|
private _arrayFormulaCellData;
|
|
@@ -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 { IFormulaDirtyData } from './current-data.service';
|
|
16
17
|
import { Disposable, ICommandService } from '@univerjs/core';
|
|
17
18
|
import { IActiveDirtyManagerService } from './active-dirty-manager.service';
|
|
18
19
|
/**
|
|
@@ -31,8 +32,11 @@ export declare class FormulaCalculationTriggerService extends Disposable {
|
|
|
31
32
|
private _executionInProgress;
|
|
32
33
|
private _hasPendingCalculation;
|
|
33
34
|
private _stopRequested;
|
|
35
|
+
private _suppressed;
|
|
34
36
|
constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService);
|
|
35
37
|
start(): void;
|
|
38
|
+
/** Snapshot reconstruction calculates these synchronous mutations in its isolated runtime. */
|
|
39
|
+
runWithoutTriggering<T>(operation: () => T): T;
|
|
36
40
|
dispose(): void;
|
|
37
41
|
private _initialize;
|
|
38
42
|
private _registerGenericDirtyConversions;
|
|
@@ -42,3 +46,4 @@ export declare class FormulaCalculationTriggerService extends Disposable {
|
|
|
42
46
|
private _handleCalculationNotification;
|
|
43
47
|
private _generateDirty;
|
|
44
48
|
}
|
|
49
|
+
export declare function mergeDirtyData(left: Partial<IFormulaDirtyData>, right: Partial<IFormulaDirtyData>): IFormulaDirtyData;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { IMutationInfo, IWorkbookData } from '@univerjs/core';
|
|
17
|
+
/**
|
|
18
|
+
* Temporary revision-ordered circular replay for snapshot loading, export, and snapshot generation.
|
|
19
|
+
* Hosts opt in through begin() and release the replay state with end() after publishing results.
|
|
20
|
+
* Live collaboration and ordinary local calculation do not call this service.
|
|
21
|
+
*/
|
|
22
|
+
export interface IFormulaChangesetCalculationService {
|
|
23
|
+
/** Units with an active snapshot replay. */
|
|
24
|
+
readonly managedUnitIds: string[];
|
|
25
|
+
/** Capture the base revision; snapshot can precede the already loaded workbook's current revision. */
|
|
26
|
+
begin(unitId: string, mutations?: IMutationInfo[], snapshot?: IWorkbookData): void;
|
|
27
|
+
/** Queue one canonical revision; calculate after all mutations, ignoring intermediate cell states. */
|
|
28
|
+
applyChangeset(unitId: string, revision: number, mutations: IMutationInfo[]): void;
|
|
29
|
+
/** Drain replay and publish when revisions match; true also calculates ordinary formulas for snapshotting. */
|
|
30
|
+
flush(unitId: string, calculateOrdinary?: boolean): Promise<void>;
|
|
31
|
+
/** Release temporary replay state so later local edits use the normal calculation path. */
|
|
32
|
+
end(unitId: string): void;
|
|
33
|
+
}
|
|
34
|
+
export declare const IFormulaChangesetCalculationService: import("@wendellhu/redi").IdentifierDecorator<IFormulaChangesetCalculationService>;
|
|
@@ -18,7 +18,7 @@ import type { IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IFeatureDirtyRan
|
|
|
18
18
|
import type { BaseAstNode } from '../engine/ast-node/base-ast-node';
|
|
19
19
|
import type { IFormulaDependencyTreeJson } from '../engine/dependency/dependency-tree';
|
|
20
20
|
import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
|
|
21
|
-
import { Disposable } from '@univerjs/core';
|
|
21
|
+
import { Disposable, IUniverInstanceService } from '@univerjs/core';
|
|
22
22
|
import { IFormulaCurrentConfigService } from './current-data.service';
|
|
23
23
|
import { IHyperlinkEngineFormulaService } from './hyperlink-engine-formula.service';
|
|
24
24
|
/**
|
|
@@ -42,7 +42,17 @@ export declare enum FormulaExecutedStateType {
|
|
|
42
42
|
NOT_EXECUTED = 2,
|
|
43
43
|
SUCCESS = 3
|
|
44
44
|
}
|
|
45
|
+
export interface ICircularReference {
|
|
46
|
+
unitId: string;
|
|
47
|
+
sheetId: string;
|
|
48
|
+
row: number;
|
|
49
|
+
column: number;
|
|
50
|
+
groupId: string;
|
|
51
|
+
iterations: number;
|
|
52
|
+
converged?: boolean;
|
|
53
|
+
}
|
|
45
54
|
export interface IAllRuntimeData {
|
|
55
|
+
circularReferences?: ICircularReference[];
|
|
46
56
|
unitData: IRuntimeUnitDataType;
|
|
47
57
|
sourceFormulaData?: IFormulaData;
|
|
48
58
|
arrayFormulaRange: IArrayFormulaRangeType;
|
|
@@ -65,6 +75,7 @@ export interface IExecutionInProgressParams {
|
|
|
65
75
|
completedFormulasCount: number;
|
|
66
76
|
totalArrayFormulasToCalculate: number;
|
|
67
77
|
completedArrayFormulasCount: number;
|
|
78
|
+
circularReferences?: ICircularReference[];
|
|
68
79
|
formulaCycleIndex: number;
|
|
69
80
|
stage: FormulaExecuteStageType;
|
|
70
81
|
}
|
|
@@ -77,6 +88,16 @@ export interface IFormulaRuntimeService {
|
|
|
77
88
|
currentUnitId: string;
|
|
78
89
|
dispose(): void;
|
|
79
90
|
reset(): void;
|
|
91
|
+
beginCircularReferences(): void;
|
|
92
|
+
clearCircularReferenceCells(cells: {
|
|
93
|
+
unitId: string;
|
|
94
|
+
subUnitId: string;
|
|
95
|
+
row: number;
|
|
96
|
+
column: number;
|
|
97
|
+
}[]): void;
|
|
98
|
+
recordCircularReferences(cells: ICircularReference[]): void;
|
|
99
|
+
completeCircularReferences(): void;
|
|
100
|
+
preserveCurrentCellData(): void;
|
|
80
101
|
setCurrent(row: number, column: number, rowCount: number, columnCount: number, sheetId: string, unitId: string): void;
|
|
81
102
|
setFunctionRefInfoOverride(rowCount: number, columnCount: number): () => void;
|
|
82
103
|
hasFunctionRefInfoOverride(): boolean;
|
|
@@ -130,7 +151,10 @@ export interface IFormulaRuntimeService {
|
|
|
130
151
|
export declare class FormulaRuntimeService extends Disposable implements IFormulaRuntimeService {
|
|
131
152
|
private readonly _currentConfigService;
|
|
132
153
|
private readonly _hyperlinkEngineFormulaService;
|
|
154
|
+
private readonly _univerInstanceService;
|
|
133
155
|
private _formulaExecuteStage;
|
|
156
|
+
private _circularReferences;
|
|
157
|
+
private _pendingCircularReferences;
|
|
134
158
|
private _stopState;
|
|
135
159
|
private _externalReferenceUnavailable;
|
|
136
160
|
private _currentRow;
|
|
@@ -160,7 +184,7 @@ export declare class FormulaRuntimeService extends Disposable implements IFormul
|
|
|
160
184
|
private _formulaCycleIndex;
|
|
161
185
|
private _isCycleDependency;
|
|
162
186
|
private _dependencyTreeModelData;
|
|
163
|
-
constructor(_currentConfigService: IFormulaCurrentConfigService, _hyperlinkEngineFormulaService: IHyperlinkEngineFormulaService);
|
|
187
|
+
constructor(_currentConfigService: IFormulaCurrentConfigService, _hyperlinkEngineFormulaService: IHyperlinkEngineFormulaService, _univerInstanceService: IUniverInstanceService);
|
|
164
188
|
get currentRow(): number;
|
|
165
189
|
get currentColumn(): number;
|
|
166
190
|
get currentRowCount(): number;
|
|
@@ -191,6 +215,16 @@ export declare class FormulaRuntimeService extends Disposable implements IFormul
|
|
|
191
215
|
getFormulaExecuteStage(): FormulaExecuteStageType;
|
|
192
216
|
reset(): void;
|
|
193
217
|
clearReferenceAndNumberformatCache(): void;
|
|
218
|
+
beginCircularReferences(): void;
|
|
219
|
+
clearCircularReferenceCells(cells: {
|
|
220
|
+
unitId: string;
|
|
221
|
+
subUnitId: string;
|
|
222
|
+
row: number;
|
|
223
|
+
column: number;
|
|
224
|
+
}[]): void;
|
|
225
|
+
recordCircularReferences(cells: ICircularReference[]): void;
|
|
226
|
+
completeCircularReferences(): void;
|
|
227
|
+
preserveCurrentCellData(): void;
|
|
194
228
|
setCurrent(row: number, column: number, rowCount: number, columnCount: number, sheetId: string, unitId: string): void;
|
|
195
229
|
setFunctionRefInfoOverride(rowCount: number, columnCount: number): () => void;
|
|
196
230
|
hasFunctionRefInfoOverride(): boolean;
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core/facade"),require("@univerjs/core"),require("@univerjs/engine-formula")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core/facade`,`@univerjs/core`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverEngineFormulaFacade={},e.UniverCoreFacade,e.UniverCore,e.UniverEngineFormula))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e,t){return function(n,r){t(n,r,e)}}function a(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let o=class extends t.FBase{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._injector=t,this._lexerTreeBuilder=n,this._configService=r,this._functionService=i,this._definedNamesService=a,this._superTableService=o,this._initialize()}_initialize(){}get lexerTreeBuilder(){return this._lexerTreeBuilder}moveFormulaRefOffset(e,t,n,r){return this._lexerTreeBuilder.moveFormulaRefOffset(e,t,n,r)}sequenceNodesBuilder(e){return this._lexerTreeBuilder.sequenceNodesBuilder(e)||[]}executeCalculation(){this._commandService.executeCommand(r.SetTriggerFormulaCalculationStartMutation.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){let n=t.params;e(n.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;let n=t.params;n.functionsExecutedState!==void 0&&e(n.functionsExecutedState)})}calculationResultApplied(e){let t=this._injector.get(r.FormulaCalculationSessionService).resultApplied$.subscribe(t=>{
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core/facade"),require("@univerjs/core"),require("@univerjs/engine-formula")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core/facade`,`@univerjs/core`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverEngineFormulaFacade={},e.UniverCoreFacade,e.UniverCore,e.UniverEngineFormula))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e,t){return function(n,r){t(n,r,e)}}function a(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let o=class extends t.FBase{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._injector=t,this._lexerTreeBuilder=n,this._configService=r,this._functionService=i,this._definedNamesService=a,this._superTableService=o,this._initialize()}_initialize(){}get lexerTreeBuilder(){return this._lexerTreeBuilder}moveFormulaRefOffset(e,t,n,r){return this._lexerTreeBuilder.moveFormulaRefOffset(e,t,n,r)}sequenceNodesBuilder(e){return this._lexerTreeBuilder.sequenceNodesBuilder(e)||[]}executeCalculation(){this._commandService.executeCommand(r.SetTriggerFormulaCalculationStartMutation.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){let n=t.params;e(n.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;let n=t.params;n.functionsExecutedState!==void 0&&e(n.functionsExecutedState)})}calculationResultApplied(e){let t=this._injector.get(r.FormulaCalculationSessionService).resultApplied$.subscribe(t=>{typeof requestIdleCallback==`function`?requestIdleCallback(()=>e(t)):queueMicrotask(()=>e(t))});return{dispose:()=>t.unsubscribe()}}onCalculationResultApplied(e){return this._injector.get(r.FormulaCalculationSessionService).waitForLatestApplied(e)}calculationProcessing(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaCalculationNotificationMutation.id)return;let n=t.params;n.stageInfo!==void 0&&e(n.stageInfo)})}executeFormulas(e,t=3e4){return new Promise((n,i)=>{let a=this._commandService.onCommandExecuted(e=>{if(e.id!==r.SetFormulaStringBatchCalculationResultMutation.id)return;let t=e.params;clearTimeout(o),a.dispose(),t.result==null?i(/* @__PURE__ */ Error(`Formula batch calculation returned no result`)):n(t.result)}),o=setTimeout(()=>{a.dispose(),i(/* @__PURE__ */ Error(`Formula batch calculation timeout`))},t);this._commandService.executeCommand(r.SetFormulaStringBatchCalculationMutation.id,{formulas:e},{onlyLocal:!0})})}getAllDependencyTrees(e=3e4){return new Promise((t,n)=>{let i=this._commandService.onCommandExecuted(e=>{if(e.id!==r.SetFormulaDependencyCalculationResultMutation.id)return;let n=e.params;clearTimeout(a),i.dispose(),n.result==null?t([]):t(n.result)}),a=setTimeout(()=>{i.dispose(),n(/* @__PURE__ */ Error(`Formula dependency calculation timeout`))},e);this._commandService.executeCommand(r.SetFormulaDependencyCalculationMutation.id,void 0,{onlyLocal:!0})})}getCellDependencyTree(e,t=3e4){return new Promise((n,i)=>{let a=this._commandService.onCommandExecuted(e=>{if(e.id!==r.SetCellFormulaDependencyCalculationResultMutation.id)return;let t=e.params;clearTimeout(o),a.dispose(),n(t.result)}),o=setTimeout(()=>{a.dispose(),i(/* @__PURE__ */ Error(`Cell dependency calculation timeout`))},t);this._commandService.executeCommand(r.SetCellFormulaDependencyCalculationMutation.id,e,{onlyLocal:!0})})}getRangeDependents(e,t=3e4){return new Promise((n,i)=>{let a=this._commandService.onCommandExecuted(e=>{if(e.id!==r.SetQueryFormulaDependencyResultMutation.id)return;let t=e.params;clearTimeout(o),a.dispose(),t.result==null?n([]):n(t.result)}),o=setTimeout(()=>{a.dispose(),i(/* @__PURE__ */ Error(`Range dependents calculation timeout`))},t);this._commandService.executeCommand(r.SetQueryFormulaDependencyMutation.id,{unitRanges:e},{onlyLocal:!0})})}getInRangeFormulas(e,t=3e4){return new Promise((n,i)=>{let a=this._commandService.onCommandExecuted(e=>{if(e.id!==r.SetQueryFormulaDependencyResultMutation.id)return;let t=e.params;clearTimeout(o),a.dispose(),t.result==null?n([]):n(t.result)}),o=setTimeout(()=>{a.dispose(),i(/* @__PURE__ */ Error(`In-range formulas calculation timeout`))},t);this._commandService.executeCommand(r.SetQueryFormulaDependencyMutation.id,{unitRanges:e,isInRange:!0},{onlyLocal:!0})})}setFormulaReturnDependencyTree(e){this._configService.setConfig(r.ENGINE_FORMULA_RETURN_DEPENDENCY_TREE,e)}getFormulaExpressTree(e,t){return this._lexerTreeBuilder.getFormulaExprTree(e,t,this._functionService.hasExecutor.bind(this._functionService),this._definedNamesService.getValueByName.bind(this._definedNamesService),this._superTableService.getTable.bind(this._superTableService))}getRangeDependentsAndInRangeFormulas(e,t=3e4){return new Promise((n,i)=>{let a=this._commandService.onCommandExecuted(e=>{if(e.id!==r.SetQueryFormulaDependencyAllResultMutation.id)return;let t=e.params;clearTimeout(o),a.dispose(),t.result==null?n({dependents:[],inRanges:[]}):n(t.result)}),o=setTimeout(()=>{a.dispose(),i(/* @__PURE__ */ Error(`Range dependents calculation timeout`))},t);this._commandService.executeCommand(r.SetQueryFormulaDependencyAllMutation.id,{unitRanges:e},{onlyLocal:!0})})}};o=a([i(0,(0,n.Inject)(n.ICommandService)),i(1,(0,n.Inject)(n.Injector)),i(2,(0,n.Inject)(r.LexerTreeBuilder)),i(3,n.IConfigService),i(4,r.IFunctionService),i(5,r.IDefinedNamesService),i(6,r.ISuperTableService)],o);var s=class extends t.FUniver{getFormula(){return this._injector.createInstance(o)}};t.FUniver.extend(s),Object.defineProperty(e,"FFormula",{enumerable:!0,get:function(){return o}})});
|