From bc296ff7f64949a6d141c373fee3ac51ddc5c2a5 Mon Sep 17 00:00:00 2001 From: gggpound Date: Sat, 21 Dec 2024 15:31:44 +0800 Subject: [PATCH] feat(facade): add formula facade --- .../engine-formula/src/facade/f-formula.ts | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/engine-formula/src/facade/f-formula.ts b/packages/engine-formula/src/facade/f-formula.ts index c1bcc57d5c2..044423451f4 100644 --- a/packages/engine-formula/src/facade/f-formula.ts +++ b/packages/engine-formula/src/facade/f-formula.ts @@ -15,9 +15,9 @@ */ import type { ICommandInfo, IDisposable } from '@univerjs/core'; -import type { FormulaExecutedStateType, IExecutionInProgressParams, ISetFormulaCalculationNotificationMutation, ISetFormulaCalculationStartMutation } from '@univerjs/engine-formula'; +import type { FormulaExecutedStateType, IExecutionInProgressParams, ISequenceNode, ISetFormulaCalculationNotificationMutation, ISetFormulaCalculationStartMutation } from '@univerjs/engine-formula'; import { FBase, ICommandService, IConfigService, Inject, Injector } from '@univerjs/core'; -import { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula'; +import { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, LexerTreeBuilder, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula'; /** * This interface class provides methods to modify the behavior of the operation formula. @@ -26,11 +26,36 @@ export class FFormula extends FBase { constructor( @Inject(ICommandService) private readonly _commandService: ICommandService, @Inject(Injector) protected readonly _injector: Injector, + @Inject(LexerTreeBuilder) private _lexerTreeBuilder: LexerTreeBuilder, @IConfigService protected readonly _configService: IConfigService ) { super(); } + /** + * Offsets the formula + * @param {string} formulaString + * @param {number} refOffsetX + * @param {number} refOffsetY + * @param {boolean} [ignoreAbsolute] default is false + * @example + * const result = moveFormulaRefOffset('sum(a1,b2)',1,1) + * // result is 'sum(b2,c3)' + */ + moveFormulaRefOffset(formulaString: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute?: boolean): string { + return this._lexerTreeBuilder.moveFormulaRefOffset(formulaString, refOffsetX, refOffsetY, ignoreAbsolute); + } + + /** + * Resolves the formula string to a 'node' node + * @param {string} formulaString + * @return {*} {((string | ISequenceNode)[])} + * @memberof FFormula + */ + sequenceNodesBuilder(formulaString: string): (string | ISequenceNode)[] { + return this._lexerTreeBuilder.sequenceNodesBuilder(formulaString) || []; + } + /** * Start the calculation of the formula. */ @@ -38,9 +63,9 @@ export class FFormula extends FBase { this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { commands: [], forceCalculation: true }, { onlyLocal: true }); } - /** - * Stop the calculation of the formula. - */ + /** + * Stop the calculation of the formula. + */ stopCalculation(): void { this._commandService.executeCommand(SetFormulaCalculationStopMutation.id, {}); }