@univerjs/engine-formula 0.13.0 → 0.14.0-insiders.20251227-b250a8d

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.
Files changed (33) hide show
  1. package/lib/cjs/facade.js +1 -1
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/facade.js +218 -36
  4. package/lib/es/index.js +3447 -3180
  5. package/lib/facade.js +218 -36
  6. package/lib/index.js +3447 -3180
  7. package/lib/types/basics/common.d.ts +8 -0
  8. package/lib/types/basics/match-token.d.ts +1 -1
  9. package/lib/types/commands/mutations/formula.mutation.d.ts +9 -0
  10. package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +10 -1
  11. package/lib/types/controller/calculate.controller.d.ts +2 -0
  12. package/lib/types/controller/config.schema.d.ts +1 -0
  13. package/lib/types/engine/analysis/lexer-tree-builder.d.ts +2 -1
  14. package/lib/types/engine/ast-node/reference-node.d.ts +0 -1
  15. package/lib/types/engine/dependency/dependency-tree.d.ts +11 -1
  16. package/lib/types/engine/dependency/formula-dependency.d.ts +9 -4
  17. package/lib/types/engine/utils/reference.d.ts +9 -0
  18. package/lib/types/engine/utils/sequence.d.ts +2 -1
  19. package/lib/types/facade/f-formula.d.ts +164 -2
  20. package/lib/types/index.d.ts +9 -5
  21. package/lib/types/services/active-dirty-manager.service.d.ts +1 -0
  22. package/lib/types/services/calculate-formula.service.d.ts +4 -1
  23. package/lib/types/services/current-data.service.d.ts +1 -0
  24. package/lib/types/services/defined-names.service.d.ts +1 -0
  25. package/lib/types/services/dependency-manager.service.d.ts +3 -0
  26. package/lib/types/services/formula-common.d.ts +18 -0
  27. package/lib/types/services/register-other-formula.service.d.ts +40 -0
  28. package/lib/types/services/runtime.service.d.ts +7 -0
  29. package/lib/types/services/super-table.service.d.ts +4 -0
  30. package/lib/umd/facade.js +1 -1
  31. package/lib/umd/index.js +1 -1
  32. package/package.json +6 -6
  33. package/LICENSE +0 -176
@@ -0,0 +1,40 @@
1
+ import { IRange, Nullable, Disposable, ICommandService, LifecycleService } from '@univerjs/core';
2
+ import { IOtherFormulaResult } from './formula-common';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ import { IActiveDirtyManagerService } from './active-dirty-manager.service';
5
+ export declare enum OtherFormulaBizType {
6
+ DEFAULT = "default",
7
+ DATA_VALIDATION = "dv",
8
+ DATA_VALIDATION_CUSTOM = "dv-custom",
9
+ CONDITIONAL_FORMATTING = "cf",
10
+ DOC = "doc",
11
+ SLIDE = "slide"
12
+ }
13
+ export declare class RegisterOtherFormulaService extends Disposable {
14
+ private readonly _commandService;
15
+ private _activeDirtyManagerService;
16
+ private readonly _lifecycleService;
17
+ private _formulaCacheMap;
18
+ private _formulaChangeWithRange$;
19
+ formulaChangeWithRange$: import('rxjs').Observable<{
20
+ unitId: string;
21
+ subUnitId: string;
22
+ formulaText: string;
23
+ formulaId: string;
24
+ ranges: IRange[];
25
+ }>;
26
+ private _formulaResult$;
27
+ formulaResult$: import('rxjs').Observable<Record<string, Record<string, IOtherFormulaResult[]>>>;
28
+ calculateStarted$: BehaviorSubject<boolean>;
29
+ constructor(_commandService: ICommandService, _activeDirtyManagerService: IActiveDirtyManagerService, _lifecycleService: LifecycleService);
30
+ dispose(): void;
31
+ private _ensureCacheMap;
32
+ private _createFormulaId;
33
+ private _initFormulaRegister;
34
+ private _initFormulaCalculationResultChange;
35
+ registerFormulaWithRange(unitId: string, subUnitId: string, formulaText: string, ranges?: IRange[], extra?: Record<string, any>, bizType?: OtherFormulaBizType, bizId?: string): string;
36
+ deleteFormula(unitId: string, subUnitId: string, formulaIdList: string[]): void;
37
+ getFormulaValue(unitId: string, subUnitId: string, formulaId: string): Promise<Nullable<IOtherFormulaResult>>;
38
+ getFormulaValueSync(unitId: string, subUnitId: string, formulaId: string): Nullable<IOtherFormulaResult>;
39
+ markFormulaDirty(unitId: string, subUnitId: string, formulaId: string): void;
40
+ }
@@ -1,6 +1,7 @@
1
1
  import { Nullable, Disposable } from '@univerjs/core';
2
2
  import { IArrayFormulaEmbeddedMap, IArrayFormulaRangeType, IFeatureDirtyRangeType, IRuntimeImageFormulaDataType, IRuntimeOtherUnitDataType, IRuntimeUnitDataType } from '../basics/common';
3
3
  import { BaseAstNode } from '../engine/ast-node/base-ast-node';
4
+ import { IFormulaDependencyTreeJson } from '../engine/dependency/dependency-tree';
4
5
  import { FunctionVariantType } from '../engine/reference-object/base-reference-object';
5
6
  import { IFormulaCurrentConfigService } from './current-data.service';
6
7
  import { IHyperlinkEngineFormulaService } from './hyperlink-engine-formula.service';
@@ -40,6 +41,7 @@ export interface IAllRuntimeData {
40
41
  runtimeFeatureCellData: {
41
42
  [featureId: string]: IRuntimeUnitDataType;
42
43
  };
44
+ dependencyTreeModelData: IFormulaDependencyTreeJson[];
43
45
  }
44
46
  export interface IExecutionInProgressParams {
45
47
  totalFormulasToCalculate: number;
@@ -100,6 +102,8 @@ export interface IFormulaRuntimeService {
100
102
  setUnitArrayFormulaEmbeddedMap(): void;
101
103
  clearArrayObjectCache(): void;
102
104
  getRuntimeImageFormulaData(): IRuntimeImageFormulaDataType[];
105
+ setDependencyTreeModelData(data: IFormulaDependencyTreeJson[]): void;
106
+ getDependencyTreeModelData(): IFormulaDependencyTreeJson[];
103
107
  }
104
108
  export declare class FormulaRuntimeService extends Disposable implements IFormulaRuntimeService {
105
109
  private readonly _currentConfigService;
@@ -129,6 +133,7 @@ export declare class FormulaRuntimeService extends Disposable implements IFormul
129
133
  private _completedArrayFormulasCount;
130
134
  private _formulaCycleIndex;
131
135
  private _isCycleDependency;
136
+ private _dependencyTreeModelData;
132
137
  constructor(_currentConfigService: IFormulaCurrentConfigService, _hyperlinkEngineFormulaService: IHyperlinkEngineFormulaService);
133
138
  get currentRow(): number;
134
139
  get currentColumn(): number;
@@ -182,6 +187,8 @@ export declare class FormulaRuntimeService extends Disposable implements IFormul
182
187
  [featureId: string]: IRuntimeUnitDataType;
183
188
  };
184
189
  setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType): void;
190
+ setDependencyTreeModelData(data: IFormulaDependencyTreeJson[]): void;
191
+ getDependencyTreeModelData(): IFormulaDependencyTreeJson[];
185
192
  getRuntimeImageFormulaData(): IRuntimeImageFormulaDataType[];
186
193
  getAllRuntimeData(): IAllRuntimeData;
187
194
  getRuntimeState(): IExecutionInProgressParams;
@@ -12,6 +12,8 @@ export interface ISuperTableService {
12
12
  registerTableOptionMap(tableOption: string, tableOptionType: TableOptionType): void;
13
13
  remove(unitId: string, tableName: string): void;
14
14
  update$: Observable<unknown>;
15
+ getTable(unitId: string, tableName: string): Nullable<ISuperTable>;
16
+ hasTable(unitId: string, tableName: string): boolean;
15
17
  }
16
18
  export declare class SuperTableService extends Disposable implements ISuperTableService {
17
19
  private _tableMap;
@@ -25,6 +27,8 @@ export declare class SuperTableService extends Disposable implements ISuperTable
25
27
  getTableOptionMap(): Map<string, TableOptionType>;
26
28
  registerTable(unitId: string, tableName: string, reference: ISuperTable): void;
27
29
  registerTableOptionMap(tableOption: string, tableOptionType: TableOptionType): void;
30
+ getTable(unitId: string, tableName: string): Nullable<ISuperTable>;
31
+ hasTable(unitId: string, tableName: string): boolean;
28
32
  private _update;
29
33
  }
30
34
  export declare const ISuperTableService: import('@wendellhu/redi').IdentifierDecorator<ISuperTableService>;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
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"})}));
1
+ (function(c,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):(c=typeof globalThis<"u"?globalThis:c||self,l(c.UniverEngineFormulaFacade={},c.UniverCoreFacade,c.UniverCore,c.UniverEngineFormula,c.rxjs))})(this,(function(c,l,m,n,f){"use strict";var v=Object.getOwnPropertyDescriptor,C=(p,e,i,t)=>{for(var r=t>1?void 0:t?v(e,i):e,o=p.length-1,s;o>=0;o--)(s=p[o])&&(r=s(r)||r);return r},d=(p,e)=>(i,t)=>e(i,t,p);c.FFormula=class extends l.FBase{constructor(e,i,t,r,o,s,a){super(),this._commandService=e,this._injector=i,this._lexerTreeBuilder=t,this._configService=r,this._functionService=o,this._definedNamesService=s,this._superTableService=a,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.SetTriggerFormulaCalculationStartMutation.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):f.firstValueFrom(f.race(i.computingStatus$.pipe(f.filter(t=>t)),f.timer(e!=null?e:3e4).pipe(f.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(()=>{S(),i(new Error("Calculation end timeout"))},3e4),s=setTimeout(()=>{t||(S(),e())},500),a=this.calculationProcessing(()=>{t||(t=!0,clearTimeout(s))}),u=this.calculationResultApplied(()=>{r||(r=!0,S(),e())});function S(){clearTimeout(o),clearTimeout(s),a.dispose(),u.dispose()}})}executeFormulas(e,i=3e4){return new Promise((t,r)=>{const o=this._commandService.onCommandExecuted(a=>{if(a.id!==n.SetFormulaStringBatchCalculationResultMutation.id)return;const u=a.params;clearTimeout(s),o.dispose(),u.result!=null?t(u.result):r(new Error("Formula batch calculation returned no result"))}),s=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(s=>{if(s.id!==n.SetFormulaDependencyCalculationResultMutation.id)return;const a=s.params;clearTimeout(o),r.dispose(),a.result!=null?i(a.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(a=>{if(a.id!==n.SetCellFormulaDependencyCalculationResultMutation.id)return;const u=a.params;clearTimeout(s),o.dispose(),t(u.result)}),s=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(a=>{if(a.id!==n.SetQueryFormulaDependencyResultMutation.id)return;const u=a.params;clearTimeout(s),o.dispose(),u.result!=null?t(u.result):t([])}),s=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(a=>{if(a.id!==n.SetQueryFormulaDependencyResultMutation.id)return;const u=a.params;clearTimeout(s),o.dispose(),u.result!=null?t(u.result):t([])}),s=setTimeout(()=>{o.dispose(),r(new Error("In-range formulas calculation timeout"))},i);this._commandService.executeCommand(n.SetQueryFormulaDependencyMutation.id,{unitRanges:e,isInRange:!0},{onlyLocal:!0})})}setFormulaReturnDependencyTree(e){this._configService.setConfig(n.ENGINE_FORMULA_RETURN_DEPENDENCY_TREE,e)}getFormulaExpressTree(e,i){return this._lexerTreeBuilder.getFormulaExprTree(e,i,this._functionService.hasExecutor.bind(this._functionService),this._definedNamesService.getValueByName.bind(this._definedNamesService),this._superTableService.getTable.bind(this._superTableService))}getRangeDependentsAndInRangeFormulas(e,i=3e4){return new Promise((t,r)=>{const o=this._commandService.onCommandExecuted(a=>{if(a.id!==n.SetQueryFormulaDependencyAllResultMutation.id)return;const u=a.params;clearTimeout(s),o.dispose(),u.result!=null?t(u.result):t({dependents:[],inRanges:[]})}),s=setTimeout(()=>{o.dispose(),r(new Error("Range dependents calculation timeout"))},i);this._commandService.executeCommand(n.SetQueryFormulaDependencyAllMutation.id,{unitRanges:e},{onlyLocal:!0})})}},c.FFormula=C([d(0,m.Inject(m.ICommandService)),d(1,m.Inject(m.Injector)),d(2,m.Inject(n.LexerTreeBuilder)),d(3,m.IConfigService),d(4,n.IFunctionService),d(5,n.IDefinedNamesService),d(6,n.ISuperTableService)],c.FFormula);class h extends l.FUniver{getFormula(){return this._injector.createInstance(c.FFormula)}}l.FUniver.extend(h),Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));