@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.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +160 -108
- package/lib/es/index.js +20 -36
- package/lib/facade.js +160 -108
- package/lib/index.js +20 -36
- package/lib/types/engine/dependency/formula-dependency.d.ts +1 -0
- package/lib/types/facade/f-formula.d.ts +60 -48
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +3 -3
|
@@ -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 {
|
|
230
|
-
*
|
|
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 {
|
|
233
|
-
* A
|
|
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
|
|
266
|
-
*
|
|
267
|
-
* });
|
|
268
|
-
*
|
|
267
|
+
* const result = await formulaEngine.executeFormulas(formulas);
|
|
268
|
+
* console.log(result);
|
|
269
269
|
* ```
|
|
270
270
|
*/
|
|
271
|
-
executeFormulas(formulas: IFormulaStringMap,
|
|
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
|
|
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 {
|
|
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
|
|
287
|
-
*
|
|
288
|
-
* });
|
|
289
|
-
*
|
|
289
|
+
* const trees = await formulaEngine.getAllDependencyTrees();
|
|
290
|
+
* console.log('All dependency trees:', trees);
|
|
290
291
|
* ```
|
|
291
292
|
*/
|
|
292
|
-
getAllDependencyTrees(
|
|
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
|
|
305
|
-
*
|
|
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 {
|
|
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
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
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
|
-
},
|
|
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
|
-
*
|
|
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
|
|
341
|
-
*
|
|
342
|
-
*
|
|
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
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
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[],
|
|
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
|
|
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
|
|
373
|
-
*
|
|
374
|
-
*
|
|
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
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
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[],
|
|
401
|
+
getInRangeFormulas(unitRanges: IUnitRange[], timeout?: number): Promise<IFormulaDependencyTreeJson[]>;
|
|
390
402
|
}
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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"})}));
|