1515 */
1616
1717import type { IUnitRange } from '@univerjs/core' ;
18- import type { FormulaCurrentConfigService } from '@univerjs/engine-formula' ;
19- import { createIdentifier , isFormulaId , isFormulaString } from '@univerjs/core' ;
20- import { IFormulaCurrentConfigService , IFormulaDependencyGenerator } from '@univerjs/engine-formula' ;
18+ import { createIdentifier , Inject , isFormulaId , isFormulaString } from '@univerjs/core' ;
19+ import { FormulaDataModel , ICalculateFormulaService , IFormulaCurrentConfigService } from '@univerjs/engine-formula' ;
2120
2221export interface IFormulaCellAndFeatureItem {
2322 unitId : string ;
@@ -41,43 +40,46 @@ export const IRemoteFormulaDependencyGenerator = createIdentifier<IRemoteFormula
4140 */
4241export class RemoteFormulaDependencyGeneratorService implements IRemoteFormulaDependencyGenerator {
4342 constructor (
44- @IFormulaDependencyGenerator private readonly _dependencyGenerator : IFormulaDependencyGenerator ,
43+ @ICalculateFormulaService private readonly _calculateFormulaService : ICalculateFormulaService ,
44+ @Inject ( FormulaDataModel ) private readonly _formulaDataModel : FormulaDataModel ,
4545 @IFormulaCurrentConfigService private readonly _currentConfigService : IFormulaCurrentConfigService
4646 ) { }
4747
4848 async generate ( range ?: IUnitRange ) : Promise < Array < IFormulaCellAndFeatureItem > > {
49- const configService = this . _currentConfigService as FormulaCurrentConfigService ;
50- const originalForceCalculate = configService . isForceCalculate ( ) ;
51- configService . setForceCalculate ( true ) ;
52- const trees = await this . _dependencyGenerator . generate ( ) ;
53- configService . setForceCalculate ( originalForceCalculate ) ;
49+ const formulaData = this . _formulaDataModel . getFormulaData ( ) ;
50+ const arrayFormulaCellData = this . _formulaDataModel . getArrayFormulaCellData ( ) ;
51+ const arrayFormulaRange = this . _formulaDataModel . getArrayFormulaRange ( ) ;
52+
53+ const formulaDatasetConfig = {
54+ formulaData,
55+ arrayFormulaCellData,
56+ arrayFormulaRange,
57+ forceCalculate : false ,
58+ dirtyRanges : range ? [ range ] : [ ] ,
59+ dirtyNameMap : { } ,
60+ dirtyDefinedNameMap : { } ,
61+ dirtyUnitFeatureMap : { } ,
62+ dirtyUnitOtherFormulaMap : { } ,
63+ clearDependencyTreeCache : { } ,
64+ maxIteration : 1 ,
65+ rowData : undefined ,
66+ } ;
67+
68+ const trees = await this . _calculateFormulaService . generateDependencyTrees ( formulaDatasetConfig ) ;
69+
5470 const result : Array < IFormulaCellAndFeatureItem > = [ ] ;
5571 for ( let i = 0 ; i < trees . length ; i ++ ) {
5672 const tree = trees [ i ] ;
5773 if ( ( isFormulaString ( tree . formula ) || isFormulaId ( tree . formulaId ) ) || tree . featureId != null ) {
58- let include = true ;
59- if ( range ) {
60- if ( tree . unitId !== range . unitId || tree . subUnitId !== range . sheetId ) {
61- include = false ;
62- } else if ( tree . row != null && tree . column != null ) {
63- const r = range . range ;
64- if ( tree . row < r . startRow || tree . row > r . endRow || tree . column < r . startColumn || tree . column > r . endColumn ) {
65- include = false ;
66- }
67- }
68- // For features without row/column, include if unitId and subUnitId match
69- }
70- if ( include ) {
71- result . push ( {
72- unitId : tree . unitId ,
73- subUnitId : tree . subUnitId ,
74- row : tree . row ,
75- column : tree . column ,
76- featureId : tree . featureId || undefined ,
77- formula : tree . formula || undefined ,
78- formulaId : tree . formulaId || undefined ,
79- } ) ;
80- }
74+ result . push ( {
75+ unitId : tree . unitId ,
76+ subUnitId : tree . subUnitId ,
77+ row : tree . row ,
78+ column : tree . column ,
79+ featureId : tree . featureId || undefined ,
80+ formula : tree . formula || undefined ,
81+ formulaId : tree . formulaId || undefined ,
82+ } ) ;
8183 }
8284 }
8385 return result ;
0 commit comments