@univerjs/engine-formula 0.12.3 → 0.12.4-experimental.20251210-8d33c6e

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.
@@ -126,6 +126,20 @@ export interface IFormulaIdMap {
126
126
  r: number;
127
127
  c: number;
128
128
  }
129
+ export interface IFormulaStringMap {
130
+ [unitId: string]: Nullable<{
131
+ [sheetId: string]: IObjectMatrixPrimitiveType<string[]>;
132
+ }>;
133
+ }
134
+ export interface IFormulaExecuteResultItem {
135
+ value: Nullable<number | string | boolean | Array<Array<number | string | boolean | null>>>;
136
+ formula: string;
137
+ }
138
+ export interface IFormulaExecuteResultMap {
139
+ [unitId: string]: Nullable<{
140
+ [sheetId: string]: IObjectMatrixPrimitiveType<IFormulaExecuteResultItem[]>;
141
+ }>;
142
+ }
129
143
  export interface IFormulaIdMapData {
130
144
  [unitId: string]: Nullable<{
131
145
  [subUnitId: string]: Nullable<{
@@ -33,7 +33,6 @@ export declare function formatDateDefault(date: Date): string;
33
33
  */
34
34
  export declare function isValidDateStr(dateStr: string): boolean;
35
35
  export declare function parseFormattedDate(value: string): numfmt.ParseData | null;
36
- export declare function parseFormattedValue(value: string): numfmt.ParseData | null;
37
36
  export declare function parseFormattedTime(value: string): numfmt.ParseData | null;
38
37
  export declare function isDate(format: string): boolean;
39
38
  export declare function isValidWeekend(weekend: number | string): boolean;
@@ -1,15 +1,46 @@
1
- import { IExecutionOptions, IMutation, Nullable } from '@univerjs/core';
2
- import { IRuntimeOtherUnitDataType, IRuntimeUnitDataPrimitiveType } from '../../basics/common';
1
+ import { IExecutionOptions, IMutation, IUnitRange, Nullable } from '@univerjs/core';
2
+ import { IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeOtherUnitDataType, IRuntimeUnitDataPrimitiveType } from '../../basics/common';
3
+ import { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson } from '../../engine/dependency/dependency-tree';
3
4
  import { IFormulaDirtyData } from '../../services/current-data.service';
4
5
  import { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';
5
6
  export interface ISetFormulaCalculationStartMutation extends IFormulaDirtyData {
6
7
  options: Nullable<IExecutionOptions>;
7
8
  }
9
+ export interface ISetFormulaStringBatchCalculationMutation {
10
+ formulas: IFormulaStringMap;
11
+ }
12
+ export interface ISetFormulaStringBatchCalculationResultMutation {
13
+ result: IFormulaExecuteResultMap;
14
+ }
15
+ export interface ISetFormulaStringBatchCalculationResultMutation {
16
+ result: IFormulaExecuteResultMap;
17
+ }
18
+ export interface ISetFormulaDependencyCalculationMutation {
19
+ unitId: string;
20
+ sheetId: string;
21
+ row: number;
22
+ column: number;
23
+ }
24
+ export interface ISetFormulaDependencyCalculationResultMutation {
25
+ result: IFormulaDependencyTreeJson[];
26
+ }
27
+ export interface ISetCellFormulaDependencyCalculationResultMutation {
28
+ result: IFormulaDependencyTreeFullJson | undefined;
29
+ }
30
+ export interface ISetQueryFormulaDependencyMutation {
31
+ unitRanges: IUnitRange[];
32
+ isInRange?: boolean;
33
+ }
34
+ export interface ISetQueryFormulaDependencyResultMutation {
35
+ result: IFormulaDependencyTreeJson[];
36
+ }
8
37
  /**
9
38
  * TODO: @DR-Univer
10
39
  * Trigger the calculation of the formula and stop the formula
11
40
  */
12
41
  export declare const SetFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation>;
42
+ export declare const SetFormulaStringBatchCalculationMutation: IMutation<ISetFormulaStringBatchCalculationMutation>;
43
+ export declare const SetFormulaStringBatchCalculationResultMutation: IMutation<ISetFormulaStringBatchCalculationResultMutation>;
13
44
  export interface ISetFormulaCalculationStopMutation {
14
45
  }
15
46
  export declare const SetFormulaCalculationStopMutation: IMutation<ISetFormulaCalculationStopMutation>;
@@ -23,3 +54,9 @@ export interface ISetFormulaCalculationResultMutation {
23
54
  unitOtherData: IRuntimeOtherUnitDataType;
24
55
  }
25
56
  export declare const SetFormulaCalculationResultMutation: IMutation<ISetFormulaCalculationResultMutation>;
57
+ export declare const SetFormulaDependencyCalculationMutation: IMutation<{}>;
58
+ export declare const SetFormulaDependencyCalculationResultMutation: IMutation<ISetFormulaDependencyCalculationResultMutation>;
59
+ export declare const SetCellFormulaDependencyCalculationMutation: IMutation<ISetFormulaDependencyCalculationMutation>;
60
+ export declare const SetCellFormulaDependencyCalculationResultMutation: IMutation<ISetCellFormulaDependencyCalculationResultMutation>;
61
+ export declare const SetQueryFormulaDependencyMutation: IMutation<ISetQueryFormulaDependencyMutation>;
62
+ export declare const SetQueryFormulaDependencyResultMutation: IMutation<ISetQueryFormulaDependencyResultMutation>;
@@ -9,6 +9,10 @@ export declare class CalculateController extends Disposable {
9
9
  private _initialize;
10
10
  private _commandExecutedListener;
11
11
  private _calculate;
12
+ private _queryFormulaDependencyJson;
13
+ private _generateAllDependencyTreeJson;
14
+ private _generateCellDependencyTreeJson;
15
+ private _calculateFormulaString;
12
16
  private _initialExecuteFormulaListener;
13
17
  private _applyResult;
14
18
  }
@@ -115,4 +115,43 @@ export declare class FormulaDependencyTree extends FormulaDependencyTreeCalculat
115
115
  shouldBePushRangeList(): boolean;
116
116
  toRTreeItem(): IUnitRange[];
117
117
  }
118
+ interface IFormulaDependencyTreeJsonBase {
119
+ treeId: number;
120
+ formula: string;
121
+ row: number;
122
+ column: number;
123
+ unitId: string;
124
+ subUnitId: string;
125
+ refOffsetX: number;
126
+ refOffsetY: number;
127
+ rangeList: IUnitRange[];
128
+ refTreeId: number | undefined;
129
+ }
130
+ export interface IFormulaDependencyTreeJson extends IFormulaDependencyTreeJsonBase {
131
+ children: number[];
132
+ parents: number[];
133
+ }
134
+ export interface IFormulaDependencyTreeFullJson extends IFormulaDependencyTreeJsonBase {
135
+ children: IFormulaDependencyTreeJson[];
136
+ parents: IFormulaDependencyTreeJson[];
137
+ }
138
+ export declare class FormulaDependencyTreeModel {
139
+ children: Set<FormulaDependencyTreeModel>;
140
+ parents: Set<FormulaDependencyTreeModel>;
141
+ treeId: number;
142
+ formula: string;
143
+ refOffsetX: number;
144
+ refOffsetY: number;
145
+ row: number;
146
+ column: number;
147
+ unitId: string;
148
+ subUnitId: string;
149
+ rangeList: IUnitRange[];
150
+ refTreeId: number | undefined;
151
+ constructor(tree: IFormulaDependencyTree);
152
+ toJson(): IFormulaDependencyTreeJson;
153
+ toFullJson(): IFormulaDependencyTreeFullJson;
154
+ addParent(parent: FormulaDependencyTreeModel): void;
155
+ addChild(child: FormulaDependencyTreeModel): void;
156
+ }
118
157
  export {};
@@ -4,17 +4,22 @@ 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, FormulaDependencyTree, FormulaDependencyTreeVirtual } from './dependency-tree';
7
+ import { IFormulaDependencyTree, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, 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';
11
11
  import { IFormulaRuntimeService } from '../../services/runtime.service';
12
12
  import { Lexer } from '../analysis/lexer';
13
+ import { LexerTreeBuilder } from '../analysis/lexer-tree-builder';
13
14
  import { AstTreeBuilder } from '../analysis/parser';
14
15
  import { Interpreter } from '../interpreter/interpreter';
15
16
  export declare function generateRandomDependencyTreeId(dependencyManagerService: IDependencyManagerService): number;
16
17
  export interface IFormulaDependencyGenerator {
17
18
  generate(): Promise<IFormulaDependencyTree[]>;
19
+ getAllDependencyJson(): Promise<IFormulaDependencyTreeJson[]>;
20
+ getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
21
+ getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
22
+ getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
18
23
  }
19
24
  export declare const IFormulaDependencyGenerator: import('@wendellhu/redi').IdentifierDecorator<IFormulaDependencyGenerator>;
20
25
  export declare class FormulaDependencyGenerator extends Disposable {
@@ -26,9 +31,10 @@ export declare class FormulaDependencyGenerator extends Disposable {
26
31
  protected readonly _astTreeBuilder: AstTreeBuilder;
27
32
  protected readonly _lexer: Lexer;
28
33
  protected readonly _dependencyManagerService: IDependencyManagerService;
34
+ protected readonly _lexerTreeBuilder: LexerTreeBuilder;
29
35
  private _updateRangeFlattenCache;
30
36
  protected _dependencyRTreeCacheForAddressFunction: RTree;
31
- constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _otherFormulaManagerService: IOtherFormulaManagerService, _featureCalculationManagerService: IFeatureCalculationManagerService, _interpreter: Interpreter, _astTreeBuilder: AstTreeBuilder, _lexer: Lexer, _dependencyManagerService: IDependencyManagerService);
37
+ constructor(_currentConfigService: IFormulaCurrentConfigService, _runtimeService: IFormulaRuntimeService, _otherFormulaManagerService: IOtherFormulaManagerService, _featureCalculationManagerService: IFeatureCalculationManagerService, _interpreter: Interpreter, _astTreeBuilder: AstTreeBuilder, _lexer: Lexer, _dependencyManagerService: IDependencyManagerService, _lexerTreeBuilder: LexerTreeBuilder);
32
38
  dispose(): void;
33
39
  generate(): Promise<(FormulaDependencyTree | FormulaDependencyTreeVirtual)[]>;
34
40
  private _dependencyFeatureCalculation;
@@ -110,4 +116,17 @@ export declare class FormulaDependencyGenerator extends Disposable {
110
116
  * @param treeList
111
117
  */
112
118
  protected _calculateRunList(treeList: IFormulaDependencyTree[]): (FormulaDependencyTree | FormulaDependencyTreeVirtual)[];
119
+ protected _initializeGenerateTreeList(): Promise<IFormulaDependencyTree[]>;
120
+ protected _getAllTreeList(): Promise<IFormulaDependencyTree[]>;
121
+ protected _formulaDependencyTreeModel: Map<number, FormulaDependencyTreeModel>;
122
+ protected _getTreeModel(treeId: number): FormulaDependencyTreeModel;
123
+ protected _getDependencyTreeParenIds(tree: IFormulaDependencyTree): Set<number>;
124
+ protected _getDependencyTreeChildrenIds(tree: IFormulaDependencyTree): Set<number>;
125
+ protected _getFormulaDependencyTreeModel(tree: IFormulaDependencyTree): FormulaDependencyTreeModel;
126
+ protected _endFormulaDependencyTreeModel(): void;
127
+ protected _startFormulaDependencyTreeModel(): void;
128
+ getAllDependencyJson(): Promise<IFormulaDependencyTreeJson[]>;
129
+ getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
130
+ getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
131
+ getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
113
132
  }
@@ -1,5 +1,5 @@
1
- import { IDisposable, ICommandService, IConfigService, Injector } from '@univerjs/core';
2
- import { FormulaExecutedStateType, IExecutionInProgressParams, ISequenceNode, LexerTreeBuilder } from '@univerjs/engine-formula';
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';
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.
@@ -146,4 +146,245 @@ export declare class FFormula extends FBase {
146
146
  * ```
147
147
  */
148
148
  setMaxIteration(maxIteration: number): void;
149
+ /**
150
+ * Listens for the moment when formula-calculation results are applied.
151
+ *
152
+ * This event fires after the engine completes a calculation cycle and
153
+ * dispatches a `SetFormulaCalculationResultMutation`.
154
+ * The callback is invoked during an idle frame to avoid blocking UI updates.
155
+ *
156
+ * @param {Function} callback - A function called with the calculation result payload
157
+ * once the result-application mutation is emitted.
158
+ * @returns {IDisposable} A disposable used to unsubscribe from the event.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const formulaEngine = univerAPI.getFormula();
163
+ *
164
+ * const dispose = formulaEngine.calculationResultApplied((result) => {
165
+ * console.log('Calculation results applied:', result);
166
+ * });
167
+ *
168
+ * // Later…
169
+ * dispose.dispose();
170
+ * ```
171
+ */
172
+ calculationResultApplied(callback: (result: ISetFormulaCalculationResultMutation) => void): IDisposable;
173
+ /**
174
+ * Waits for formula-calculation results to be applied.
175
+ *
176
+ * This method resolves under three conditions:
177
+ * 1. A real calculation runs and the engine emits a "calculation started" signal,
178
+ * followed by a "calculation result applied" signal.
179
+ * 2. No calculation actually starts within 500 ms — the method assumes there is
180
+ * nothing to wait for and resolves automatically.
181
+ * 3. A global 30 s timeout triggers, in which case the promise rejects.
182
+ *
183
+ * The API internally listens to both “calculation in progress” events and
184
+ * “calculation result applied” events, ensuring it behaves correctly whether
185
+ * formulas are recalculated or skipped due to cache/state.
186
+ *
187
+ * @returns {Promise<void>} A promise that resolves when calculation results are applied
188
+ * or when no calculation occurs within the start-detection window.
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * const formulaEngine = univerAPI.getFormula();
193
+ *
194
+ * // Wait for formula updates to apply before reading values.
195
+ * await formulaEngine.onCalculationResultApplied();
196
+ *
197
+ * const value = sheet.getRange("C24").getValue();
198
+ * console.log("Updated value:", value);
199
+ * ```
200
+ */
201
+ onCalculationResultApplied(): Promise<void>;
202
+ /**
203
+ * Execute a batch of formulas asynchronously and receive computed results.
204
+ *
205
+ * Each formula cell is represented as a string array:
206
+ * [fullFormula, ...subFormulas]
207
+ *
208
+ * Where:
209
+ * - fullFormula (index 0) is the complete formula expression written in the cell.
210
+ * Example: "=SUM(A1:A10) + SQRT(D7)".
211
+ *
212
+ * - subFormulas (index 1+) are **optional decomposed expressions** extracted from
213
+ * the full formula. Each of them can be independently computed by the formula engine.
214
+ *
215
+ * These sub-expressions can include:
216
+ * - Single-cell references: "A2", "B2", "C5"
217
+ * - Range references: "A1:A10"
218
+ * - Function calls: "SQRT(D7)", "ABS(A2-B2)"
219
+ * - Any sub-formula that was parsed out of the original formula and can be
220
+ * evaluated on its own.
221
+ *
222
+ * The batch execution engine may use these sub-formulas for dependency resolution,
223
+ * incremental computation, or performance optimizations.
224
+ *
225
+ * @param {IFormulaStringMap} formulas
226
+ * Nested structure (unit → sheet → row → column) describing formulas and
227
+ * their decomposed sub-expressions.
228
+ *
229
+ * @param {(result: IFormulaExecuteResultMap) => void} callback
230
+ * Receives the computed value map mirroring the input structure.
231
+ *
232
+ * @returns {IDisposable}
233
+ * A disposer to stop listening for batch results.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * const formulaEngine = univerAPI.getFormula();
238
+ * const formulas = {
239
+ * Book1: {
240
+ * Sheet1: {
241
+ * 2: {
242
+ * 3: [
243
+ * // Full formula:
244
+ * "=SUM(A1:A10) + SQRT(D7)",
245
+ *
246
+ * // Decomposed sub-formulas (each one can be evaluated independently):
247
+ * "SUM(A1:A10)", // sub-formula 1
248
+ * "SQRT(D7)", // sub-formula 2
249
+ * "A1:A10", // range reference
250
+ * "D7", // single-cell reference
251
+ * ],
252
+ * },
253
+ * 4: {
254
+ * 5: [
255
+ * "=A2 + B2 + SQRT(C5)",
256
+ * "A2",
257
+ * "B2",
258
+ * "SQRT(C5)",
259
+ * ],
260
+ * }
261
+ * },
262
+ * },
263
+ * };
264
+ *
265
+ * const disposer = formulaEngine.executeFormulas(formulas, (result) => {
266
+ * console.log(result);
267
+ * });
268
+ *
269
+ * ```
270
+ */
271
+ executeFormulas(formulas: IFormulaStringMap, callback: (result: IFormulaExecuteResultMap) => void): void;
272
+ /**
273
+ * Retrieve all formula dependency trees that were produced during the latest
274
+ * dependency-analysis run. This triggers a local dependency-calculation command
275
+ * and returns the complete set of dependency trees once the calculation finishes.
276
+ *
277
+ * @param callback A function invoked with the resulting array of dependency trees.
278
+ *
279
+ * @returns {IDisposable} An object that disposes the internal event listener.
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * const formulaEngine = univerAPI.getFormula();
284
+ *
285
+ * // Fetch all dependency trees generated for the current workbook.
286
+ * const disposable = formulaEngine.getAllDependencyTrees((trees) => {
287
+ * console.log('All dependency trees:', trees);
288
+ * });
289
+ *
290
+ * ```
291
+ */
292
+ getAllDependencyTrees(callback: (result: IFormulaDependencyTreeJson[]) => void): void;
293
+ /**
294
+ * Retrieve the dependency tree of a specific cell. This triggers a local
295
+ * dependency-calculation command for the given unit, sheet, and cell location,
296
+ * and returns the computed dependency tree when the calculation is completed.
297
+ *
298
+ * @param param The target cell location:
299
+ * - `unitId` The workbook ID.
300
+ * - `sheetId` The sheet ID.
301
+ * - `row` The zero-based row index.
302
+ * - `column` The zero-based column index.
303
+ *
304
+ * @param callback A function invoked with the resulting dependency tree or
305
+ * `undefined` if no dependency tree exists for that cell.
306
+ *
307
+ * @returns {IDisposable} An object that disposes the internal event listener.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * const formulaEngine = univerAPI.getFormula();
312
+ *
313
+ * // Query the dependency tree for cell B2 in a specific sheet.
314
+ * const disposable = formulaEngine.getCellDependencyTree(
315
+ * { unitId: 'workbook1', sheetId: 'sheet1', row: 1, column: 1 },
316
+ * (tree) => {
317
+ * console.log('Cell dependency tree:', tree);
318
+ * }
319
+ * );
320
+ *
321
+ * ```
322
+ */
323
+ getCellDependencyTree(param: {
324
+ unitId: string;
325
+ sheetId: string;
326
+ row: number;
327
+ column: number;
328
+ }, callback: (result: IFormulaDependencyTreeFullJson | undefined) => void): void;
329
+ /**
330
+ * Retrieve the full dependency trees for all formulas that *depend on* the
331
+ * specified ranges. This triggers a local dependency-calculation command and
332
+ * invokes the callback once the calculation completes.
333
+ *
334
+ * @param unitRanges An array of workbook/sheet ranges to query. Each range
335
+ * includes:
336
+ * - `unitId` The workbook ID.
337
+ * - `sheetId` The sheet ID.
338
+ * - `range` The row/column boundaries.
339
+ *
340
+ * @param callback A function invoked with an array of `IFormulaDependencyTreeJson`
341
+ * results. Each entry represents a formula node and its parent/child
342
+ * relationships within the dependency graph.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * const formulaEngine = univerAPI.getFormula();
347
+ *
348
+ * // Query all formulas that depend on A1:B10 in Sheet1.
349
+ * formulaEngine.getRangeDependents(
350
+ * [{ unitId: 'workbook1', sheetId: 'sheet1', range: { startRow: 0, endRow: 9, startColumn: 0, endColumn: 1 } }],
351
+ * (result) => {
352
+ * console.log('Dependent formulas:', result);
353
+ * }
354
+ * );
355
+ * ```
356
+ */
357
+ getRangeDependents(unitRanges: IUnitRange[], callback: (result: IFormulaDependencyTreeJson[]) => void): void;
358
+ /**
359
+ * Retrieve the dependency trees of all formulas *inside* the specified ranges.
360
+ * Unlike `getRangeDependents`, this API only returns formulas whose definitions
361
+ * physically reside within the queried ranges.
362
+ *
363
+ * Internally this triggers the same dependency-calculation command but with
364
+ * `isInRange = true`, and the callback is invoked when the results are ready.
365
+ *
366
+ * @param unitRanges An array of workbook/sheet ranges defining the lookup
367
+ * boundaries:
368
+ * - `unitId` The workbook ID.
369
+ * - `sheetId` The sheet ID.
370
+ * - `range` The zero-based grid range.
371
+ *
372
+ * @param callback Receives an array of `IFormulaDependencyTreeJson` describing
373
+ * every formula found in the provided ranges along with their parent/child
374
+ * relationships.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * const formulaEngine = univerAPI.getFormula();
379
+ *
380
+ * // Query all formulas that lie within A1:D20 in Sheet1.
381
+ * formulaEngine.getInRangeFormulas(
382
+ * [{ unitId: 'workbook1', sheetId: 'sheet1', range: { startRow: 0, endRow: 19, startColumn: 0, endColumn: 3 } }],
383
+ * (result) => {
384
+ * console.log('Formulas inside range:', result);
385
+ * }
386
+ * );
387
+ * ```
388
+ */
389
+ getInRangeFormulas(unitRanges: IUnitRange[], callback: (result: IFormulaDependencyTreeJson[]) => void): void;
149
390
  }
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export type { IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IArrayFormulaUnitCellType, IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, IFeatureDirtyRangeType, IFormulaData, IFormulaDataItem, IFormulaDatasetConfig, IRuntimeImageFormulaDataType, IRuntimeUnitDataType, ISheetData, IUnitData, IUnitImageFormulaDataType, IUnitSheetNameMap, } from './basics/common';
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
19
  export { type IUnitRowData } from './basics/common';
@@ -33,7 +33,7 @@ export { type ISetArrayFormulaDataMutationParams, SetArrayFormulaDataMutation }
33
33
  export { type ISetDefinedNameMutationParam, type ISetDefinedNameMutationSearchParam, RemoveDefinedNameMutation, SetDefinedNameMutation } from './commands/mutations/set-defined-name.mutation';
34
34
  export { SetDefinedNameMutationFactory } from './commands/mutations/set-defined-name.mutation';
35
35
  export { RemoveFeatureCalculationMutation, SetFeatureCalculationMutation } from './commands/mutations/set-feature-calculation.mutation';
36
- export { type ISetFormulaCalculationNotificationMutation, type ISetFormulaCalculationResultMutation, type ISetFormulaCalculationStartMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, } from './commands/mutations/set-formula-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
37
  export { type ISetFormulaDataMutationParams, SetFormulaDataMutation } from './commands/mutations/set-formula-data.mutation';
38
38
  export { type ISetImageFormulaDataMutationParams, SetImageFormulaDataMutation } from './commands/mutations/set-image-formula-data.mutation';
39
39
  export { type IRemoveOtherFormulaMutationParams, type ISetOtherFormulaMutationParams, RemoveOtherFormulaMutation, SetOtherFormulaMutation } from './commands/mutations/set-other-formula.mutation';
@@ -56,7 +56,7 @@ export { ReferenceNodeFactory } from './engine/ast-node/reference-node';
56
56
  export { SuffixNodeFactory } from './engine/ast-node/suffix-node';
57
57
  export { UnionNodeFactory } from './engine/ast-node/union-node';
58
58
  export { ValueNodeFactory } from './engine/ast-node/value-node';
59
- export { FormulaDependencyTree, type IFormulaDependencyTree } from './engine/dependency/dependency-tree';
59
+ export { FormulaDependencyTree, FormulaDependencyTreeModel, type IFormulaDependencyTree, type IFormulaDependencyTreeFullJson, type IFormulaDependencyTreeJson } from './engine/dependency/dependency-tree';
60
60
  export { FormulaDependencyTreeType } from './engine/dependency/dependency-tree';
61
61
  export { FormulaDependencyTreeVirtual } from './engine/dependency/dependency-tree';
62
62
  export { FormulaDependencyGenerator, IFormulaDependencyGenerator } from './engine/dependency/formula-dependency';
@@ -1,10 +1,11 @@
1
+ import { IUnitRange, Disposable, IConfigService } from '@univerjs/core';
1
2
  import { Observable, Subject } from 'rxjs';
2
- import { IFeatureDirtyRangeType, IFormulaDatasetConfig, IRuntimeUnitDataType } from '../basics/common';
3
+ import { IFeatureDirtyRangeType, IFormulaDatasetConfig, IFormulaExecuteResultMap, IFormulaStringMap, IRuntimeUnitDataType, IUnitRowData } from '../basics/common';
4
+ import { IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson } from '../engine/dependency/dependency-tree';
5
+ import { FunctionVariantType } from '../engine/reference-object/base-reference-object';
3
6
  import { IAllRuntimeData, IExecutionInProgressParams, IFormulaRuntimeService } from './runtime.service';
4
- import { Disposable, IConfigService } from '@univerjs/core';
5
7
  import { Lexer } from '../engine/analysis/lexer';
6
8
  import { AstTreeBuilder } from '../engine/analysis/parser';
7
- import { ErrorNode } from '../engine/ast-node/base-ast-node';
8
9
  import { IFormulaDependencyGenerator } from '../engine/dependency/formula-dependency';
9
10
  import { Interpreter } from '../engine/interpreter/interpreter';
10
11
  import { IFormulaCurrentConfigService } from './current-data.service';
@@ -19,6 +20,11 @@ export interface ICalculateFormulaService {
19
20
  execute(formulaDatasetConfig: IFormulaDatasetConfig): Promise<void>;
20
21
  stopFormulaExecution(): void;
21
22
  calculate(formulaString: string, transformSuffix?: boolean): void;
23
+ executeFormulas(formulas: IFormulaStringMap, rowData?: IUnitRowData): Promise<IFormulaExecuteResultMap>;
24
+ getAllDependencyJson(rowData?: IUnitRowData): Promise<IFormulaDependencyTreeJson[]>;
25
+ getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number, rowData?: IUnitRowData): Promise<IFormulaDependencyTreeFullJson | undefined>;
26
+ getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
27
+ getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
22
28
  }
23
29
  export declare const ICalculateFormulaService: import('@wendellhu/redi').IdentifierDecorator<ICalculateFormulaService>;
24
30
  export declare class CalculateFormulaService extends Disposable implements ICalculateFormulaService {
@@ -53,5 +59,10 @@ export declare class CalculateFormulaService extends Disposable implements ICalc
53
59
  private _executeStep;
54
60
  private _getArrayFormulaDirtyRangeAndExcludedRange;
55
61
  protected _apply(isArrayFormulaState?: boolean): Promise<IAllRuntimeData | undefined>;
56
- calculate(formulaString: string, transformSuffix?: boolean): ErrorNode | undefined;
62
+ executeFormulas(formulas: IFormulaStringMap, rowData?: IUnitRowData): Promise<IFormulaExecuteResultMap>;
63
+ calculate(formulaString: string): Promise<FunctionVariantType | undefined>;
64
+ getAllDependencyJson(): Promise<IFormulaDependencyTreeJson[]>;
65
+ getCellDependencyJson(unitId: string, sheetId: string, row: number, column: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
66
+ getRangeDependents(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
67
+ getInRangeFormulas(unitRanges: IUnitRange[]): Promise<IFormulaDependencyTreeJson[]>;
57
68
  }
@@ -55,6 +55,7 @@ export interface IFormulaCurrentConfigService {
55
55
  };
56
56
  getFilteredOutRows(unitId: string, sheetId: string, startRow: number, endRow: number): number[];
57
57
  setSheetNameMap(sheetIdToNameMap: IUnitSheetIdToNameMap): void;
58
+ loadDataLite(rowData?: IUnitRowData): void;
58
59
  }
59
60
  export declare class FormulaCurrentConfigService extends Disposable implements IFormulaCurrentConfigService {
60
61
  private readonly _univerInstanceService;
@@ -113,6 +114,7 @@ export declare class FormulaCurrentConfigService extends Disposable implements I
113
114
  };
114
115
  getFilteredOutRows(unitId: string, sheetId: string, startRow: number, endRow: number): number[];
115
116
  load(config: IFormulaDatasetConfig): void;
117
+ loadDataLite(rowData?: IUnitRowData): void;
116
118
  getDirtyData(): IFormulaDirtyData;
117
119
  loadDirtyRangesAndExcludedCell(dirtyRanges: IUnitRange[], excludedCell?: IUnitExcludedCell): void;
118
120
  registerUnitData(unitData: IUnitData): void;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core/facade"),require("@univerjs/core"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core/facade","@univerjs/core","@univerjs/engine-formula","rxjs"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.UniverEngineFormulaFacade={},r.UniverCoreFacade,r.UniverCore,r.UniverEngineFormula,r.rxjs))})(this,(function(r,o,u,a,s){"use strict";var f=Object.getOwnPropertyDescriptor,v=(c,e,t,i)=>{for(var n=i>1?void 0:i?f(e,t):e,d=c.length-1,m;d>=0;d--)(m=c[d])&&(n=m(n)||n);return n},l=(c,e)=>(t,i)=>e(t,i,c);r.FFormula=class extends o.FBase{constructor(e,t,i,n){super(),this._commandService=e,this._injector=t,this._lexerTreeBuilder=i,this._configService=n,this._initialize()}_initialize(){}get lexerTreeBuilder(){return this._lexerTreeBuilder}moveFormulaRefOffset(e,t,i,n){return this._lexerTreeBuilder.moveFormulaRefOffset(e,t,i,n)}sequenceNodesBuilder(e){return this._lexerTreeBuilder.sequenceNodesBuilder(e)||[]}executeCalculation(){this._commandService.executeCommand(a.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(a.SetFormulaCalculationStopMutation.id,{})}calculationStart(e){return this._commandService.onCommandExecuted(t=>{if(t.id===a.SetFormulaCalculationStartMutation.id){const i=t.params;e(i.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==a.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.functionsExecutedState!==void 0&&e(i.functionsExecutedState)})}whenComputingCompleteAsync(e){const t=this._injector.get(a.GlobalComputingStatusService);return t.computingStatus?Promise.resolve(!0):s.firstValueFrom(s.race(t.computingStatus$.pipe(s.filter(i=>i)),s.timer(e!=null?e:3e4).pipe(s.map(()=>!1))))}onCalculationEnd(){return new Promise((e,t)=>{const i=setTimeout(()=>{t(new Error("Calculation end timeout"))},3e4),n=this.calculationEnd(()=>{clearTimeout(i),n.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(t=>{if(t.id!==a.SetFormulaCalculationNotificationMutation.id)return;const i=t.params;i.stageInfo!==void 0&&e(i.stageInfo)})}setMaxIteration(e){this._configService.setConfig(a.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}},r.FFormula=v([l(0,u.Inject(u.ICommandService)),l(1,u.Inject(u.Injector)),l(2,u.Inject(a.LexerTreeBuilder)),l(3,u.IConfigService)],r.FFormula);class C extends o.FUniver{getFormula(){return this._injector.createInstance(r.FFormula)}}o.FUniver.extend(C),Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core/facade"),require("@univerjs/core"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core/facade","@univerjs/core","@univerjs/engine-formula","rxjs"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.UniverEngineFormulaFacade={},o.UniverCoreFacade,o.UniverCore,o.UniverEngineFormula,o.rxjs))})(this,(function(o,s,u,r,l){"use strict";var f=Object.getOwnPropertyDescriptor,C=(c,e,i,t)=>{for(var n=t>1?void 0:t?f(e,i):e,a=c.length-1,d;a>=0;a--)(d=c[a])&&(n=d(n)||n);return n},m=(c,e)=>(i,t)=>e(i,t,c);o.FFormula=class extends s.FBase{constructor(e,i,t,n){super(),this._commandService=e,this._injector=i,this._lexerTreeBuilder=t,this._configService=n,this._initialize()}_initialize(){}get lexerTreeBuilder(){return this._lexerTreeBuilder}moveFormulaRefOffset(e,i,t,n){return this._lexerTreeBuilder.moveFormulaRefOffset(e,i,t,n)}sequenceNodesBuilder(e){return this._lexerTreeBuilder.sequenceNodesBuilder(e)||[]}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(i=>{if(i.id===r.SetFormulaCalculationStartMutation.id){const t=i.params;e(t.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(i=>{if(i.id!==r.SetFormulaCalculationNotificationMutation.id)return;const t=i.params;t.functionsExecutedState!==void 0&&e(t.functionsExecutedState)})}whenComputingCompleteAsync(e){const i=this._injector.get(r.GlobalComputingStatusService);return i.computingStatus?Promise.resolve(!0):l.firstValueFrom(l.race(i.computingStatus$.pipe(l.filter(t=>t)),l.timer(e!=null?e:3e4).pipe(l.map(()=>!1))))}onCalculationEnd(){return new Promise((e,i)=>{const t=setTimeout(()=>{i(new Error("Calculation end timeout"))},3e4),n=this.calculationEnd(()=>{clearTimeout(t),n.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(i=>{if(i.id!==r.SetFormulaCalculationNotificationMutation.id)return;const t=i.params;t.stageInfo!==void 0&&e(t.stageInfo)})}setMaxIteration(e){this._configService.setConfig(r.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}calculationResultApplied(e){return this._commandService.onCommandExecuted(i=>{if(i.id!==r.SetFormulaCalculationResultMutation.id)return;const t=i.params;t!==void 0&&requestIdleCallback(()=>{e(t)})})}onCalculationResultApplied(){return new Promise((e,i)=>{let t=!1,n=!1;const a=setTimeout(()=>{p(),i(new Error("Calculation end timeout"))},3e4),d=setTimeout(()=>{t||(p(),e())},500),v=this.calculationProcessing(()=>{t||(t=!0,clearTimeout(d))}),h=this.calculationResultApplied(()=>{n||(n=!0,p(),e())});function p(){clearTimeout(a),clearTimeout(d),v.dispose(),h.dispose()}})}executeFormulas(e,i){this._commandService.executeCommand(r.SetFormulaStringBatchCalculationMutation.id,{formulas:e},{onlyLocal:!0});const t=this._commandService.onCommandExecuted(n=>{if(n.id!==r.SetFormulaStringBatchCalculationResultMutation.id)return;const a=n.params;a.result!=null&&i(a.result),t.dispose()})}getAllDependencyTrees(e){this._commandService.executeCommand(r.SetFormulaDependencyCalculationMutation.id,void 0,{onlyLocal:!0});const i=this._commandService.onCommandExecuted(t=>{if(t.id!==r.SetFormulaDependencyCalculationResultMutation.id)return;const n=t.params;n.result!=null&&e(n.result),i.dispose()})}getCellDependencyTree(e,i){this._commandService.executeCommand(r.SetCellFormulaDependencyCalculationMutation.id,e,{onlyLocal:!0});const t=this._commandService.onCommandExecuted(n=>{if(n.id!==r.SetCellFormulaDependencyCalculationResultMutation.id)return;const a=n.params;a.result!==void 0&&i(a.result),t.dispose()})}getRangeDependents(e,i){this._commandService.executeCommand(r.SetQueryFormulaDependencyMutation.id,{unitRanges:e},{onlyLocal:!0});const t=this._commandService.onCommandExecuted(n=>{if(n.id!==r.SetQueryFormulaDependencyResultMutation.id)return;const a=n.params;a.result!=null&&i(a.result),t.dispose()})}getInRangeFormulas(e,i){this._commandService.executeCommand(r.SetQueryFormulaDependencyMutation.id,{unitRanges:e,isInRange:!0},{onlyLocal:!0});const t=this._commandService.onCommandExecuted(n=>{if(n.id!==r.SetQueryFormulaDependencyResultMutation.id)return;const a=n.params;a.result!=null&&i(a.result),t.dispose()})}},o.FFormula=C([m(0,u.Inject(u.ICommandService)),m(1,u.Inject(u.Injector)),m(2,u.Inject(r.LexerTreeBuilder)),m(3,u.IConfigService)],o.FFormula);class S extends s.FUniver{getFormula(){return this._injector.createInstance(o.FFormula)}}s.FUniver.extend(S),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));