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

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.
@@ -226,11 +226,13 @@ export declare class FFormula extends FBase {
226
226
  * Nested structure (unit → sheet → row → column) describing formulas and
227
227
  * their decomposed sub-expressions.
228
228
  *
229
- * @param {(result: IFormulaExecuteResultMap) => void} callback
230
- * Receives the computed value map mirroring the input structure.
229
+ * @param {number} [timeout]
230
+ * Optional timeout in milliseconds. If no result is received within this
231
+ * period, the promise will be rejected.
231
232
  *
232
- * @returns {IDisposable}
233
- * A disposer to stop listening for batch results.
233
+ * @returns {Promise<IFormulaExecuteResultMap>}
234
+ * A promise that resolves with the computed value map mirroring
235
+ * the input structure.
234
236
  *
235
237
  * @example
236
238
  * ```ts
@@ -262,34 +264,33 @@ export declare class FFormula extends FBase {
262
264
  * },
263
265
  * };
264
266
  *
265
- * const disposer = formulaEngine.executeFormulas(formulas, (result) => {
266
- * console.log(result);
267
- * });
268
- *
267
+ * const result = await formulaEngine.executeFormulas(formulas);
268
+ * console.log(result);
269
269
  * ```
270
270
  */
271
- executeFormulas(formulas: IFormulaStringMap, callback: (result: IFormulaExecuteResultMap) => void): void;
271
+ executeFormulas(formulas: IFormulaStringMap, timeout?: number): Promise<IFormulaExecuteResultMap>;
272
272
  /**
273
273
  * Retrieve all formula dependency trees that were produced during the latest
274
274
  * dependency-analysis run. This triggers a local dependency-calculation command
275
275
  * and returns the complete set of dependency trees once the calculation finishes.
276
276
  *
277
- * @param callback A function invoked with the resulting array of dependency trees.
277
+ * @param {number} [timeout]
278
+ * Optional timeout in milliseconds. If no result is received within this
279
+ * period, the promise will be rejected.
278
280
  *
279
- * @returns {IDisposable} An object that disposes the internal event listener.
281
+ * @returns {Promise<IFormulaDependencyTreeJson[]>}
282
+ * A promise that resolves with the array of dependency trees.
280
283
  *
281
284
  * @example
282
285
  * ```ts
283
286
  * const formulaEngine = univerAPI.getFormula();
284
287
  *
285
288
  * // Fetch all dependency trees generated for the current workbook.
286
- * const disposable = formulaEngine.getAllDependencyTrees((trees) => {
287
- * console.log('All dependency trees:', trees);
288
- * });
289
- *
289
+ * const trees = await formulaEngine.getAllDependencyTrees();
290
+ * console.log('All dependency trees:', trees);
290
291
  * ```
291
292
  */
292
- getAllDependencyTrees(callback: (result: IFormulaDependencyTreeJson[]) => void): void;
293
+ getAllDependencyTrees(timeout?: number): Promise<IFormulaDependencyTreeJson[]>;
293
294
  /**
294
295
  * Retrieve the dependency tree of a specific cell. This triggers a local
295
296
  * dependency-calculation command for the given unit, sheet, and cell location,
@@ -301,23 +302,27 @@ export declare class FFormula extends FBase {
301
302
  * - `row` The zero-based row index.
302
303
  * - `column` The zero-based column index.
303
304
  *
304
- * @param callback A function invoked with the resulting dependency tree or
305
- * `undefined` if no dependency tree exists for that cell.
305
+ * @param {number} [timeout]
306
+ * Optional timeout in milliseconds. If no result is received within this
307
+ * period, the promise will be rejected.
306
308
  *
307
- * @returns {IDisposable} An object that disposes the internal event listener.
309
+ * @returns {Promise<IFormulaDependencyTreeFullJson | undefined>}
310
+ * A promise that resolves with the dependency tree or `undefined`
311
+ * if no tree exists for that cell.
308
312
  *
309
313
  * @example
310
314
  * ```ts
311
315
  * const formulaEngine = univerAPI.getFormula();
312
316
  *
313
317
  * // 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
- * );
318
+ * const tree = await formulaEngine.getCellDependencyTree({
319
+ * unitId: 'workbook1',
320
+ * sheetId: 'sheet1',
321
+ * row: 1,
322
+ * column: 1,
323
+ * });
320
324
  *
325
+ * console.log('Cell dependency tree:', tree);
321
326
  * ```
322
327
  */
323
328
  getCellDependencyTree(param: {
@@ -325,11 +330,11 @@ export declare class FFormula extends FBase {
325
330
  sheetId: string;
326
331
  row: number;
327
332
  column: number;
328
- }, callback: (result: IFormulaDependencyTreeFullJson | undefined) => void): void;
333
+ }, timeout?: number): Promise<IFormulaDependencyTreeFullJson | undefined>;
329
334
  /**
330
335
  * Retrieve the full dependency trees for all formulas that *depend on* the
331
336
  * specified ranges. This triggers a local dependency-calculation command and
332
- * invokes the callback once the calculation completes.
337
+ * resolves once the calculation completes.
333
338
  *
334
339
  * @param unitRanges An array of workbook/sheet ranges to query. Each range
335
340
  * includes:
@@ -337,31 +342,34 @@ export declare class FFormula extends FBase {
337
342
  * - `sheetId` The sheet ID.
338
343
  * - `range` The row/column boundaries.
339
344
  *
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.
345
+ * @param {number} [timeout]
346
+ * Optional timeout in milliseconds. If no result is received within this
347
+ * period, the promise will be rejected.
348
+ *
349
+ * @returns {Promise<IFormulaDependencyTreeJson[]>}
350
+ * A promise that resolves with an array of `IFormulaDependencyTreeJson`
351
+ * representing formulas and their relationships within the dependency graph.
343
352
  *
344
353
  * @example
345
354
  * ```ts
346
355
  * const formulaEngine = univerAPI.getFormula();
347
356
  *
348
357
  * // 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
- * );
358
+ * const dependents = await formulaEngine.getRangeDependents([
359
+ * { unitId: 'workbook1', sheetId: 'sheet1', range: { startRow: 0, endRow: 9, startColumn: 0, endColumn: 1 } }
360
+ * ]);
361
+ *
362
+ * console.log('Dependent formulas:', dependents);
355
363
  * ```
356
364
  */
357
- getRangeDependents(unitRanges: IUnitRange[], callback: (result: IFormulaDependencyTreeJson[]) => void): void;
365
+ getRangeDependents(unitRanges: IUnitRange[], timeout?: number): Promise<IFormulaDependencyTreeJson[]>;
358
366
  /**
359
367
  * Retrieve the dependency trees of all formulas *inside* the specified ranges.
360
368
  * Unlike `getRangeDependents`, this API only returns formulas whose definitions
361
369
  * physically reside within the queried ranges.
362
370
  *
363
371
  * Internally this triggers the same dependency-calculation command but with
364
- * `isInRange = true`, and the callback is invoked when the results are ready.
372
+ * `isInRange = true`, and the promise resolves when the results are ready.
365
373
  *
366
374
  * @param unitRanges An array of workbook/sheet ranges defining the lookup
367
375
  * boundaries:
@@ -369,22 +377,26 @@ export declare class FFormula extends FBase {
369
377
  * - `sheetId` The sheet ID.
370
378
  * - `range` The zero-based grid range.
371
379
  *
372
- * @param callback Receives an array of `IFormulaDependencyTreeJson` describing
373
- * every formula found in the provided ranges along with their parent/child
374
- * relationships.
380
+ * @param {number} [timeout]
381
+ * Optional timeout in milliseconds. If no result is received within this
382
+ * period, the promise will be rejected.
383
+ *
384
+ * @returns {Promise<IFormulaDependencyTreeJson[]>}
385
+ * A promise that resolves with an array of `IFormulaDependencyTreeJson`
386
+ * describing every formula found in the provided ranges along with
387
+ * their parent/child relationships.
375
388
  *
376
389
  * @example
377
390
  * ```ts
378
391
  * const formulaEngine = univerAPI.getFormula();
379
392
  *
380
393
  * // 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
- * );
394
+ * const formulasInRange = await formulaEngine.getInRangeFormulas([
395
+ * { unitId: 'workbook1', sheetId: 'sheet1', range: { startRow: 0, endRow: 19, startColumn: 0, endColumn: 3 } }
396
+ * ]);
397
+ *
398
+ * console.log('Formulas inside range:', formulasInRange);
387
399
  * ```
388
400
  */
389
- getInRangeFormulas(unitRanges: IUnitRange[], callback: (result: IFormulaDependencyTreeJson[]) => void): void;
401
+ getInRangeFormulas(unitRanges: IUnitRange[], timeout?: number): Promise<IFormulaDependencyTreeJson[]>;
390
402
  }
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
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"})}));
1
+ (function(s,l){typeof exports=="object"&&typeof module<"u"?l(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"],l):(s=typeof globalThis<"u"?globalThis:s||self,l(s.UniverEngineFormulaFacade={},s.UniverCoreFacade,s.UniverCore,s.UniverEngineFormula,s.rxjs))})(this,(function(s,l,d,n,p){"use strict";var S=Object.getOwnPropertyDescriptor,v=(m,e,i,t)=>{for(var r=t>1?void 0:t?S(e,i):e,o=m.length-1,a;o>=0;o--)(a=m[o])&&(r=a(r)||r);return r},f=(m,e)=>(i,t)=>e(i,t,m);s.FFormula=class extends l.FBase{constructor(e,i,t,r){super(),this._commandService=e,this._injector=i,this._lexerTreeBuilder=t,this._configService=r,this._initialize()}_initialize(){}get lexerTreeBuilder(){return this._lexerTreeBuilder}moveFormulaRefOffset(e,i,t,r){return this._lexerTreeBuilder.moveFormulaRefOffset(e,i,t,r)}sequenceNodesBuilder(e){return this._lexerTreeBuilder.sequenceNodesBuilder(e)||[]}executeCalculation(){this._commandService.executeCommand(n.SetFormulaCalculationStartMutation.id,{commands:[],forceCalculation:!0},{onlyLocal:!0})}stopCalculation(){this._commandService.executeCommand(n.SetFormulaCalculationStopMutation.id,{})}calculationStart(e){return this._commandService.onCommandExecuted(i=>{if(i.id===n.SetFormulaCalculationStartMutation.id){const t=i.params;e(t.forceCalculation)}})}calculationEnd(e){return this._commandService.onCommandExecuted(i=>{if(i.id!==n.SetFormulaCalculationNotificationMutation.id)return;const t=i.params;t.functionsExecutedState!==void 0&&e(t.functionsExecutedState)})}whenComputingCompleteAsync(e){const i=this._injector.get(n.GlobalComputingStatusService);return i.computingStatus?Promise.resolve(!0):p.firstValueFrom(p.race(i.computingStatus$.pipe(p.filter(t=>t)),p.timer(e!=null?e:3e4).pipe(p.map(()=>!1))))}onCalculationEnd(){return new Promise((e,i)=>{const t=setTimeout(()=>{i(new Error("Calculation end timeout"))},3e4),r=this.calculationEnd(()=>{clearTimeout(t),r.dispose(),e()})})}calculationProcessing(e){return this._commandService.onCommandExecuted(i=>{if(i.id!==n.SetFormulaCalculationNotificationMutation.id)return;const t=i.params;t.stageInfo!==void 0&&e(t.stageInfo)})}setMaxIteration(e){this._configService.setConfig(n.ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,e)}calculationResultApplied(e){return this._commandService.onCommandExecuted(i=>{if(i.id!==n.SetFormulaCalculationResultMutation.id)return;const t=i.params;t!==void 0&&requestIdleCallback(()=>{e(t)})})}onCalculationResultApplied(){return new Promise((e,i)=>{let t=!1,r=!1;const o=setTimeout(()=>{C(),i(new Error("Calculation end timeout"))},3e4),a=setTimeout(()=>{t||(C(),e())},500),u=this.calculationProcessing(()=>{t||(t=!0,clearTimeout(a))}),c=this.calculationResultApplied(()=>{r||(r=!0,C(),e())});function C(){clearTimeout(o),clearTimeout(a),u.dispose(),c.dispose()}})}executeFormulas(e,i=3e4){return new Promise((t,r)=>{const o=this._commandService.onCommandExecuted(u=>{if(u.id!==n.SetFormulaStringBatchCalculationResultMutation.id)return;const c=u.params;clearTimeout(a),o.dispose(),c.result!=null?t(c.result):r(new Error("Formula batch calculation returned no result"))}),a=setTimeout(()=>{o.dispose(),r(new Error("Formula batch calculation timeout"))},i);this._commandService.executeCommand(n.SetFormulaStringBatchCalculationMutation.id,{formulas:e},{onlyLocal:!0})})}getAllDependencyTrees(e=3e4){return new Promise((i,t)=>{const r=this._commandService.onCommandExecuted(a=>{if(a.id!==n.SetFormulaDependencyCalculationResultMutation.id)return;const u=a.params;clearTimeout(o),r.dispose(),u.result!=null?i(u.result):i([])}),o=setTimeout(()=>{r.dispose(),t(new Error("Formula dependency calculation timeout"))},e);this._commandService.executeCommand(n.SetFormulaDependencyCalculationMutation.id,void 0,{onlyLocal:!0})})}getCellDependencyTree(e,i=3e4){return new Promise((t,r)=>{const o=this._commandService.onCommandExecuted(u=>{if(u.id!==n.SetCellFormulaDependencyCalculationResultMutation.id)return;const c=u.params;clearTimeout(a),o.dispose(),t(c.result)}),a=setTimeout(()=>{o.dispose(),r(new Error("Cell dependency calculation timeout"))},i);this._commandService.executeCommand(n.SetCellFormulaDependencyCalculationMutation.id,e,{onlyLocal:!0})})}getRangeDependents(e,i=3e4){return new Promise((t,r)=>{const o=this._commandService.onCommandExecuted(u=>{if(u.id!==n.SetQueryFormulaDependencyResultMutation.id)return;const c=u.params;clearTimeout(a),o.dispose(),c.result!=null?t(c.result):t([])}),a=setTimeout(()=>{o.dispose(),r(new Error("Range dependents calculation timeout"))},i);this._commandService.executeCommand(n.SetQueryFormulaDependencyMutation.id,{unitRanges:e},{onlyLocal:!0})})}getInRangeFormulas(e,i=3e4){return new Promise((t,r)=>{const o=this._commandService.onCommandExecuted(u=>{if(u.id!==n.SetQueryFormulaDependencyResultMutation.id)return;const c=u.params;clearTimeout(a),o.dispose(),c.result!=null?t(c.result):t([])}),a=setTimeout(()=>{o.dispose(),r(new Error("In-range formulas calculation timeout"))},i);this._commandService.executeCommand(n.SetQueryFormulaDependencyMutation.id,{unitRanges:e,isInRange:!0},{onlyLocal:!0})})}},s.FFormula=v([f(0,d.Inject(d.ICommandService)),f(1,d.Inject(d.Injector)),f(2,d.Inject(n.LexerTreeBuilder)),f(3,d.IConfigService)],s.FFormula);class h extends l.FUniver{getFormula(){return this._injector.createInstance(s.FFormula)}}l.FUniver.extend(h),Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));