Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(sheet): feature register in formula (#653)

Univerdcf41a44f431
diff --git a/examples/sheets/src/main.ts b/examples/sheets/src/main.ts
index 0e82ef0a66..f35d1279f9 100644
--- a/examples/sheets/src/main.ts
+++ b/examples/sheets/src/main.ts
@@ -1,16 +1,16 @@
+import { LocaleType, Univer } from '@univerjs/core';
+import { greenTheme } from '@univerjs/design';
import { DocsPlugin, RichTextEditingMutation } from '@univerjs/docs';
import { BaseFormulaEnginePlugin } from '@univerjs/engine-formula';
import { RenderEngine } from '@univerjs/engine-render';
-import { SheetsPlugin } from '@univerjs/sheets';
-import { UIPlugin } from '@univerjs/ui';
-import { LocaleType, Univer } from '@univerjs/core';
-import { greenTheme } from '@univerjs/design';
+import { FormulaPlugin } from '@univerjs/formula';
import type { IUniverRPCMainThreadPluginConfig } from '@univerjs/rpc';
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
-import { FormulaPlugin } from '@univerjs/formula';
+import { SheetsPlugin } from '@univerjs/sheets';
import { FormulaUIPlugin } from '@univerjs/sheets-formula';
import { NumfmtPlugin } from '@univerjs/sheets-numfmt';
import { SheetsUIPlugin } from '@univerjs/sheets-ui';
+import { UIPlugin } from '@univerjs/ui';
import type { IUniscriptPluginConfig } from '@univerjs/uniscript';
import { UniscriptPlugin } from '@univerjs/uniscript';
import { DEFAULT_WORKBOOK_DATA_DEMO } from 'data';
diff --git a/packages/engine-formula/src/analysis/un-parser.ts b/packages/engine-formula/src/analysis/un-parser.ts
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/engine-formula/src/basics/common.ts b/packages/engine-formula/src/basics/common.ts
index 3a4d3e7196..e60239e1bc 100644
--- a/packages/engine-formula/src/basics/common.ts
+++ b/packages/engine-formula/src/basics/common.ts
@@ -60,10 +60,18 @@ export interface IDirtyUnitSheetNameMap {
[unitId: string]: { [sheetId: string]: Nullable<string> };
}
+export interface IDirtyUnitFeatureMap {
+ [unitId: string]: { [sheetId: string]: { [featureId: string]: boolean } };
+}
+
export interface IArrayFormulaRangeType {
[unitId: string]: { [sheetId: string]: ObjectMatrixPrimitiveType<IRange> };
}
+export interface IFeatureDirtyRangeType {
+ [unitId: string]: { [sheetId: string]: IRange[] };
+}
+
export interface IArrayFormulaUnitCellType {
[unitId: string]: { [sheetId: string]: ObjectMatrixPrimitiveType<ICellData> };
}
@@ -114,6 +122,7 @@ export interface IFormulaDatasetConfig {
forceCalculate: boolean;
dirtyRanges: IUnitRange[];
dirtyNameMap: IDirtyUnitSheetNameMap;
+ dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
excludedCell?: IUnitExcludedCell;
}
diff --git a/packages/engine-formula/src/analysis/__tests__/create-command-test-bed.ts b/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts
similarity index 99%
rename from packages/engine-formula/src/analysis/__tests__/create-command-test-bed.ts
rename to packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts
index 69997c2aa8..e201437959 100644
--- a/packages/engine-formula/src/analysis/__tests__/create-command-test-bed.ts
+++ b/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts
@@ -3,6 +3,7 @@ import { ILogService, IUniverInstanceService, LocaleType, Plugin, PluginType, Un
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import { FormulaRuntimeService, IFormulaRuntimeService } from '../../../services/runtime.service';
import { AstRootNodeFactory } from '../../ast-node/ast-root-node';
import { FunctionNodeFactory } from '../../ast-node/function-node';
import { LambdaNodeFactory } from '../../ast-node/lambda-node';
@@ -13,7 +14,6 @@ import { ReferenceNodeFactory } from '../../ast-node/reference-node';
import { SuffixNodeFactory } from '../../ast-node/suffix-node';
import { UnionNodeFactory } from '../../ast-node/union-node';
import { ValueNodeFactory } from '../../ast-node/value-node';
-import { FormulaRuntimeService, IFormulaRuntimeService } from '../../services/runtime.service';
import { AstTreeBuilder } from '../parser';
const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
diff --git a/packages/engine-formula/src/analysis/__tests__/utils.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/utils.spec.ts
similarity index 100%
rename from packages/engine-formula/src/analysis/__tests__/utils.spec.ts
rename to packages/engine-formula/src/engine/analysis/__tests__/utils.spec.ts
diff --git a/packages/engine-formula/src/analysis/lexer-node.ts b/packages/engine-formula/src/engine/analysis/lexer-node.ts
similarity index 98%
rename from packages/engine-formula/src/analysis/lexer-node.ts
rename to packages/engine-formula/src/engine/analysis/lexer-node.ts
index 22fb6de9ba..0ab8b4ac91 100644
--- a/packages/engine-formula/src/analysis/lexer-node.ts
+++ b/packages/engine-formula/src/engine/analysis/lexer-node.ts
@@ -1,7 +1,7 @@
import type { Nullable, Observable } from '@univerjs/core';
+import { DEFAULT_TOKEN_TYPE_ROOT } from '../../basics/token-type';
import type { LambdaPrivacyVarType } from '../ast-node/base-ast-node';
-import { DEFAULT_TOKEN_TYPE_ROOT } from '../basics/token-type';
interface LexerNodeJson {
token: string;
diff --git a/packages/engine-formula/src/analysis/lexer.ts b/packages/engine-formula/src/engine/analysis/lexer.ts
similarity index 99%
rename from packages/engine-formula/src/analysis/lexer.ts
rename to packages/engine-formula/src/engine/analysis/lexer.ts
index f9167a63ec..042aef34d0 100644
--- a/packages/engine-formula/src/analysis/lexer.ts
+++ b/packages/engine-formula/src/engine/analysis/lexer.ts
@@ -1,12 +1,10 @@
import type { Nullable } from '@univerjs/core';
import { deserializeRangeWithSheet, Disposable, Rectangle, serializeRangeToRefString, Tools } from '@univerjs/core';
-import { FormulaAstLRU } from '../basics/cache-lru';
-import { ErrorType } from '../basics/error-type';
-import { isFormulaLexerToken } from '../basics/match-token';
-import { isReferenceString, REFERENCE_SINGLE_RANGE_REGEX } from '../basics/regex';
-import type { ISequenceArray, ISequenceNode } from '../basics/sequence';
-import { generateStringWithSequence, sequenceNodeType } from '../basics/sequence';
+import { FormulaAstLRU } from '../../basics/cache-lru';
+import { ErrorType } from '../../basics/error-type';
+import { isFormulaLexerToken } from '../../basics/match-token';
+import { isReferenceString, REFERENCE_SINGLE_RANGE_REGEX } from '../../basics/regex';
import {
matchToken,
OPERATOR_TOKEN_PRIORITY,
@@ -14,12 +12,14 @@ import {
operatorToken,
prefixToken,
SUFFIX_TOKEN_SET,
-} from '../basics/token';
+} from '../../basics/token';
import {
DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER,
DEFAULT_TOKEN_TYPE_PARAMETER,
DEFAULT_TOKEN_TYPE_ROOT,
-} from '../basics/token-type';
+} from '../../basics/token-type';
+import type { ISequenceArray, ISequenceNode } from '../utils/sequence';
+import { generateStringWithSequence, sequenceNodeType } from '../utils/sequence';
import { LexerNode } from './lexer-node';
enum bracketType {
diff --git a/packages/engine-formula/src/analysis/parser.ts b/packages/engine-formula/src/engine/analysis/parser.ts
similarity index 98%
rename from packages/engine-formula/src/analysis/parser.ts
rename to packages/engine-formula/src/engine/analysis/parser.ts
index c0eabf7f8a..b883f4f109 100644
--- a/packages/engine-formula/src/analysis/parser.ts
+++ b/packages/engine-formula/src/engine/analysis/parser.ts
@@ -2,6 +2,15 @@ import type { Nullable } from '@univerjs/core';
import { Disposable, sortRules } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
+import { ErrorType } from '../../basics/error-type';
+import {
+ DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME,
+ DEFAULT_TOKEN_LET_FUNCTION_NAME,
+ DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER,
+ DEFAULT_TOKEN_TYPE_PARAMETER,
+ DEFAULT_TOKEN_TYPE_ROOT,
+} from '../../basics/token-type';
+import { IFormulaRuntimeService } from '../../services/runtime.service';
import { AstRootNode, AstRootNodeFactory } from '../ast-node/ast-root-node';
import type { BaseAstNode } from '../ast-node/base-ast-node';
import { ErrorNode } from '../ast-node/base-ast-node';
@@ -17,16 +26,7 @@ import { ReferenceNodeFactory } from '../ast-node/reference-node';
import { SuffixNodeFactory } from '../ast-node/suffix-node';
import { UnionNodeFactory } from '../ast-node/union-node';
import { ValueNodeFactory } from '../ast-node/value-node';
-import { ErrorType } from '../basics/error-type';
-import { isChildRunTimeParameter, isFirstChildParameter } from '../basics/function-definition';
-import {
- DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME,
- DEFAULT_TOKEN_LET_FUNCTION_NAME,
- DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER,
- DEFAULT_TOKEN_TYPE_PARAMETER,
- DEFAULT_TOKEN_TYPE_ROOT,
-} from '../basics/token-type';
-import { IFormulaRuntimeService } from '../services/runtime.service';
+import { isChildRunTimeParameter, isFirstChildParameter } from '../utils/function-definition';
import { LexerNode } from './lexer-node';
export class AstTreeBuilder extends Disposable {
diff --git a/packages/engine-formula/src/ast-node/ast-root-node.ts b/packages/engine-formula/src/engine/ast-node/ast-root-node.ts
similarity index 96%
rename from packages/engine-formula/src/ast-node/ast-root-node.ts
rename to packages/engine-formula/src/engine/ast-node/ast-root-node.ts
index fc14509049..4e0ca2e409 100644
--- a/packages/engine-formula/src/ast-node/ast-root-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/ast-root-node.ts
@@ -1,5 +1,5 @@
+import { DEFAULT_TOKEN_TYPE_ROOT } from '../../basics/token-type';
import { LexerNode } from '../analysis/lexer-node';
-import { DEFAULT_TOKEN_TYPE_ROOT } from '../basics/token-type';
import { BaseAstNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
import { NODE_ORDER_MAP, NodeType } from './node-type';
diff --git a/packages/engine-formula/src/ast-node/base-ast-node-factory.ts b/packages/engine-formula/src/engine/ast-node/base-ast-node-factory.ts
similarity index 100%
rename from packages/engine-formula/src/ast-node/base-ast-node-factory.ts
rename to packages/engine-formula/src/engine/ast-node/base-ast-node-factory.ts
diff --git a/packages/engine-formula/src/ast-node/base-ast-node.ts b/packages/engine-formula/src/engine/ast-node/base-ast-node.ts
similarity index 96%
rename from packages/engine-formula/src/ast-node/base-ast-node.ts
rename to packages/engine-formula/src/engine/ast-node/base-ast-node.ts
index e40c2ab5f9..d3afb3c803 100644
--- a/packages/engine-formula/src/ast-node/base-ast-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/base-ast-node.ts
@@ -1,8 +1,8 @@
import type { Nullable } from '@univerjs/core';
import { Disposable } from '@univerjs/core';
-import { AstNodePromiseType } from '../basics/common';
-import type { ErrorType } from '../basics/error-type';
+import { AstNodePromiseType } from '../../basics/common';
+import type { ErrorType } from '../../basics/error-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { FunctionVariantType } from '../reference-object/base-reference-object';
import { NodeType } from './node-type';
diff --git a/packages/engine-formula/src/ast-node/function-node.ts b/packages/engine-formula/src/engine/ast-node/function-node.ts
similarity index 92%
rename from packages/engine-formula/src/ast-node/function-node.ts
rename to packages/engine-formula/src/engine/ast-node/function-node.ts
index 5f9af58b9f..22aaa72394 100644
--- a/packages/engine-formula/src/ast-node/function-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/function-node.ts
@@ -1,14 +1,14 @@
import type { Nullable } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
+import { AstNodePromiseType } from '../../basics/common';
+import { ErrorType } from '../../basics/error-type';
+import { FUNCTION_NAMES } from '../../basics/function';
+import { prefixToken } from '../../basics/token';
+import type { BaseFunction } from '../../functions/base-function';
+import { IFunctionService } from '../../services/function.service';
import type { LexerNode } from '../analysis/lexer-node';
-import { AstNodePromiseType } from '../basics/common';
-import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
-import { prefixToken } from '../basics/token';
-import type { BaseFunction } from '../functions/base-function';
import type { AsyncObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import { IFunctionService } from '../services/function.service';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
import { NODE_ORDER_MAP, NodeType } from './node-type';
diff --git a/packages/engine-formula/src/ast-node/index.ts b/packages/engine-formula/src/engine/ast-node/index.ts
similarity index 100%
rename from packages/engine-formula/src/ast-node/index.ts
rename to packages/engine-formula/src/engine/ast-node/index.ts
diff --git a/packages/engine-formula/src/ast-node/lambda-node.ts b/packages/engine-formula/src/engine/ast-node/lambda-node.ts
similarity index 95%
rename from packages/engine-formula/src/ast-node/lambda-node.ts
rename to packages/engine-formula/src/engine/ast-node/lambda-node.ts
index 26b6fe5358..d845f516ef 100644
--- a/packages/engine-formula/src/ast-node/lambda-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/lambda-node.ts
@@ -1,15 +1,15 @@
import type { Nullable } from '@univerjs/core';
import { Tools } from '@univerjs/core';
-import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
-import { isFirstChildParameter } from '../basics/function-definition';
+import { ErrorType } from '../../basics/error-type';
import {
DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER,
DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER,
DEFAULT_TOKEN_TYPE_LAMBDA_RUNTIME_PARAMETER,
-} from '../basics/token-type';
-import { IFormulaRuntimeService } from '../services/runtime.service';
+} from '../../basics/token-type';
+import { IFormulaRuntimeService } from '../../services/runtime.service';
+import { LexerNode } from '../analysis/lexer-node';
+import { isFirstChildParameter } from '../utils/function-definition';
import type { LambdaPrivacyVarType } from './base-ast-node';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
diff --git a/packages/engine-formula/src/ast-node/lambda-parameter-node.ts b/packages/engine-formula/src/engine/ast-node/lambda-parameter-node.ts
similarity index 97%
rename from packages/engine-formula/src/ast-node/lambda-parameter-node.ts
rename to packages/engine-formula/src/engine/ast-node/lambda-parameter-node.ts
index 5d2d451a3e..b158e85626 100644
--- a/packages/engine-formula/src/ast-node/lambda-parameter-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/lambda-parameter-node.ts
@@ -1,8 +1,8 @@
import type { Nullable } from '@univerjs/core';
+import { ErrorType } from '../../basics/error-type';
+import { DEFAULT_TOKEN_TYPE_LAMBDA_RUNTIME_PARAMETER } from '../../basics/token-type';
import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
-import { DEFAULT_TOKEN_TYPE_LAMBDA_RUNTIME_PARAMETER } from '../basics/token-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { LambdaPrivacyVarType } from './base-ast-node';
import { BaseAstNode, ErrorNode } from './base-ast-node';
diff --git a/packages/engine-formula/src/ast-node/node-type.ts b/packages/engine-formula/src/engine/ast-node/node-type.ts
similarity index 100%
rename from packages/engine-formula/src/ast-node/node-type.ts
rename to packages/engine-formula/src/engine/ast-node/node-type.ts
diff --git a/packages/engine-formula/src/ast-node/null-node.ts b/packages/engine-formula/src/engine/ast-node/null-node.ts
similarity index 100%
rename from packages/engine-formula/src/ast-node/null-node.ts
rename to packages/engine-formula/src/engine/ast-node/null-node.ts
diff --git a/packages/engine-formula/src/ast-node/operator-node.ts b/packages/engine-formula/src/engine/ast-node/operator-node.ts
similarity index 88%
rename from packages/engine-formula/src/ast-node/operator-node.ts
rename to packages/engine-formula/src/engine/ast-node/operator-node.ts
index a466fad22d..b35bcac875 100644
--- a/packages/engine-formula/src/ast-node/operator-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/operator-node.ts
@@ -1,12 +1,12 @@
+import { ErrorType } from '../../basics/error-type';
+import { FUNCTION_NAMES } from '../../basics/function';
+import type { compareToken } from '../../basics/token';
+import { OPERATOR_TOKEN_COMPARE_SET, OPERATOR_TOKEN_SET, operatorToken } from '../../basics/token';
+import type { BaseFunction } from '../../functions/base-function';
+import type { Compare } from '../../functions/meta/compare';
+import { IFunctionService } from '../../services/function.service';
import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
-import type { compareToken } from '../basics/token';
-import { OPERATOR_TOKEN_COMPARE_SET, OPERATOR_TOKEN_SET, operatorToken } from '../basics/token';
-import type { BaseFunction } from '../functions/base-function';
-import type { Compare } from '../functions/meta/compare';
import type { FunctionVariantType } from '../reference-object/base-reference-object';
-import { IFunctionService } from '../services/function.service';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
import { NODE_ORDER_MAP, NodeType } from './node-type';
diff --git a/packages/engine-formula/src/ast-node/prefix-node.ts b/packages/engine-formula/src/engine/ast-node/prefix-node.ts
similarity index 91%
rename from packages/engine-formula/src/ast-node/prefix-node.ts
rename to packages/engine-formula/src/engine/ast-node/prefix-node.ts
index 5e4e19a57c..56e824633e 100644
--- a/packages/engine-formula/src/ast-node/prefix-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/prefix-node.ts
@@ -2,15 +2,15 @@ import type { Nullable } from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import { ErrorType } from '../../basics/error-type';
+import { FUNCTION_NAMES } from '../../basics/function';
+import { prefixToken } from '../../basics/token';
+import type { BaseFunction } from '../../functions/base-function';
+import { IFunctionService } from '../../services/function.service';
+import { IFormulaRuntimeService } from '../../services/runtime.service';
import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
-import { prefixToken } from '../basics/token';
-import type { BaseFunction } from '../functions/base-function';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import { IFunctionService } from '../services/function.service';
-import { IFormulaRuntimeService } from '../services/runtime.service';
import { NumberValueObject } from '../value-object/primitive-object';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
diff --git a/packages/engine-formula/src/ast-node/reference-node.ts b/packages/engine-formula/src/engine/ast-node/reference-node.ts
similarity index 91%
rename from packages/engine-formula/src/ast-node/reference-node.ts
rename to packages/engine-formula/src/engine/ast-node/reference-node.ts
index f23f94cab3..92c430cd9b 100644
--- a/packages/engine-formula/src/ast-node/reference-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/reference-node.ts
@@ -1,24 +1,24 @@
import type { IAccessor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
-import { LexerTreeBuilder } from '../analysis/lexer';
-import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
+import { ErrorType } from '../../basics/error-type';
import {
$SUPER_TABLE_COLUMN_REGEX,
REFERENCE_REGEX_SINGLE_COLUMN,
REFERENCE_REGEX_SINGLE_ROW,
REFERENCE_SINGLE_RANGE_REGEX,
-} from '../basics/regex';
+} from '../../basics/regex';
+import { IFormulaCurrentConfigService } from '../../services/current-data.service';
+import { IDefinedNamesService } from '../../services/defined-names.service';
+import { IFormulaRuntimeService } from '../../services/runtime.service';
+import { ISuperTableService } from '../../services/super-table.service';
+import { LexerTreeBuilder } from '../analysis/lexer';
+import { LexerNode } from '../analysis/lexer-node';
import type { BaseReferenceObject } from '../reference-object/base-reference-object';
import { CellReferenceObject } from '../reference-object/cell-reference-object';
import { ColumnReferenceObject } from '../reference-object/column-reference-object';
import { RowReferenceObject } from '../reference-object/row-reference-object';
import { TableReferenceObject } from '../reference-object/table-reference-object';
-import { IFormulaCurrentConfigService } from '../services/current-data.service';
-import { IDefinedNamesService } from '../services/defined-names.service';
-import { IFormulaRuntimeService } from '../services/runtime.service';
-import { ISuperTableService } from '../services/super-table.service';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
import { NODE_ORDER_MAP, NodeType } from './node-type';
@@ -51,8 +51,11 @@ export class ReferenceNode extends BaseAstNode {
this._referenceObject.setArrayFormulaCellData(currentConfigService.getArrayFormulaCellData());
this._referenceObject.setRuntimeData(runtimeService.getUnitData());
+
this._referenceObject.setRuntimeArrayFormulaCellData(runtimeService.getRuntimeArrayFormulaCellData());
+ this._referenceObject.setRuntimeFeatureCellData(runtimeService.getRuntimeFeatureCellData());
+
const { x, y } = this.getRefOffset();
this._referenceObject.setRefOffset(x, y);
diff --git a/packages/engine-formula/src/ast-node/suffix-node.ts b/packages/engine-formula/src/engine/ast-node/suffix-node.ts
similarity index 91%
rename from packages/engine-formula/src/ast-node/suffix-node.ts
rename to packages/engine-formula/src/engine/ast-node/suffix-node.ts
index 4881edc2ad..6cb02f0d43 100644
--- a/packages/engine-formula/src/ast-node/suffix-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/suffix-node.ts
@@ -1,17 +1,17 @@
import type { IAccessor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import { ErrorType } from '../../basics/error-type';
+import { FUNCTION_NAMES } from '../../basics/function';
+import { suffixToken } from '../../basics/token';
+import type { BaseFunction } from '../../functions/base-function';
+import { IFormulaCurrentConfigService } from '../../services/current-data.service';
+import { IFunctionService } from '../../services/function.service';
import { LexerTreeBuilder } from '../analysis/lexer';
import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
-import { suffixToken } from '../basics/token';
-import type { BaseFunction } from '../functions/base-function';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
import type { CellReferenceObject } from '../reference-object/cell-reference-object';
-import { IFormulaCurrentConfigService } from '../services/current-data.service';
-import { IFunctionService } from '../services/function.service';
import { NumberValueObject } from '../value-object/primitive-object';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
diff --git a/packages/engine-formula/src/ast-node/union-node.ts b/packages/engine-formula/src/engine/ast-node/union-node.ts
similarity index 89%
rename from packages/engine-formula/src/ast-node/union-node.ts
rename to packages/engine-formula/src/engine/ast-node/union-node.ts
index 50dcef834e..6be53f70dd 100644
--- a/packages/engine-formula/src/ast-node/union-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/union-node.ts
@@ -1,11 +1,11 @@
+import { ErrorType } from '../../basics/error-type';
+import { FUNCTION_NAMES } from '../../basics/function';
+import { matchToken } from '../../basics/token';
+import type { BaseFunction } from '../../functions/base-function';
+import { IFunctionService } from '../../services/function.service';
import { LexerNode } from '../analysis/lexer-node';
-import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
-import { matchToken } from '../basics/token';
-import type { BaseFunction } from '../functions/base-function';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { FunctionVariantType } from '../reference-object/base-reference-object';
-import { IFunctionService } from '../services/function.service';
import { BaseAstNode, ErrorNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
import { NODE_ORDER_MAP, NodeType } from './node-type';
diff --git a/packages/engine-formula/src/ast-node/value-node.ts b/packages/engine-formula/src/engine/ast-node/value-node.ts
similarity index 97%
rename from packages/engine-formula/src/ast-node/value-node.ts
rename to packages/engine-formula/src/engine/ast-node/value-node.ts
index 1b0a6abafd..bc7fb09aba 100644
--- a/packages/engine-formula/src/ast-node/value-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/value-node.ts
@@ -1,5 +1,5 @@
+import { BooleanValue } from '../../basics/common';
import { LexerNode } from '../analysis/lexer-node';
-import { BooleanValue } from '../basics/common';
import { ValueObjectFactory } from '../value-object/array-value-object';
import { BaseAstNode } from './base-ast-node';
import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory';
diff --git a/packages/engine-formula/src/dependency/dependency-tree.ts b/packages/engine-formula/src/engine/dependency/dependency-tree.ts
similarity index 91%
rename from packages/engine-formula/src/dependency/dependency-tree.ts
rename to packages/engine-formula/src/engine/dependency/dependency-tree.ts
index 07fc958377..9bb00bcee3 100644
--- a/packages/engine-formula/src/dependency/dependency-tree.ts
+++ b/packages/engine-formula/src/engine/dependency/dependency-tree.ts
@@ -1,8 +1,13 @@
import type { IRange, IUnitRange, Nullable } from '@univerjs/core';
import { Disposable } from '@univerjs/core';
+import type {
+ IDirtyUnitSheetNameMap,
+ IFeatureDirtyRangeType,
+ IRuntimeUnitDataType,
+ IUnitExcludedCell,
+} from '../../basics/common';
import type { BaseAstNode } from '../ast-node/base-ast-node';
-import type { IDirtyUnitSheetNameMap, IUnitExcludedCell } from '../basics/common';
export enum FDtreeStateType {
DEFAULT,
@@ -10,6 +15,10 @@ export enum FDtreeStateType {
SKIP,
}
+/**
+ * A dependency tree, capable of calculating mutual dependencies,
+ * is used to determine the order of formula calculations.
+ */
export class FormulaDependencyTree extends Disposable {
node: Nullable<BaseAstNode>;
@@ -31,6 +40,15 @@ export class FormulaDependencyTree extends Disposable {
formulaId: Nullable<string>;
+ featureId: Nullable<string>;
+
+ getDirtyData: Nullable<
+ (tree: FormulaDependencyTree) => {
+ runtimeCellData: IRuntimeUnitDataType;
+ dirtyRanges: IFeatureDirtyRangeType;
+ }
+ >;
+
private _state = FDtreeStateType.DEFAULT;
override dispose(): void {
diff --git a/packages/engine-formula/src/dependency/formula-dependency.ts b/packages/engine-formula/src/engine/dependency/formula-dependency.ts
similarity index 89%
rename from packages/engine-formula/src/dependency/formula-dependency.ts
rename to packages/engine-formula/src/engine/dependency/formula-dependency.ts
index 03da2401b2..56bbe1390a 100644
--- a/packages/engine-formula/src/dependency/formula-dependency.ts
+++ b/packages/engine-formula/src/engine/dependency/formula-dependency.ts
@@ -2,6 +2,16 @@ import type { IRange, IUnitRange, Nullable } from '@univerjs/core';
import { Disposable, LifecycleStages, ObjectMatrix, OnLifecycle } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
+import { FormulaAstLRU } from '../../basics/cache-lru';
+import type { IDirtyUnitSheetNameMap, IFormulaData, IOtherFormulaData } from '../../basics/common';
+import { ErrorType } from '../../basics/error-type';
+import { prefixToken, suffixToken } from '../../basics/token';
+import { IFormulaCurrentConfigService } from '../../services/current-data.service';
+import {
+ IPassiveDirtyManagerService,
+ type PassiveDirtyManagerService,
+} from '../../services/passive-dirty-manager.service';
+import { IFormulaRuntimeService } from '../../services/runtime.service';
import { LexerTreeBuilder } from '../analysis/lexer';
import type { LexerNode } from '../analysis/lexer-node';
import { AstTreeBuilder } from '../analysis/parser';
@@ -9,15 +19,9 @@ import type { AstRootNode, FunctionNode, PrefixNode, SuffixNode } from '../ast-n
import type { BaseAstNode } from '../ast-node/base-ast-node';
import { ErrorNode } from '../ast-node/base-ast-node';
import { NodeType } from '../ast-node/node-type';
-import { FormulaAstLRU } from '../basics/cache-lru';
-import type { IDirtyUnitSheetNameMap, IFormulaData, IOtherFormulaData } from '../basics/common';
-import { ErrorType } from '../basics/error-type';
-import type { PreCalculateNodeType } from '../basics/node-type';
-import { prefixToken, suffixToken } from '../basics/token';
import { Interpreter } from '../interpreter/interpreter';
import type { BaseReferenceObject } from '../reference-object/base-reference-object';
-import { IFormulaCurrentConfigService } from '../services/current-data.service';
-import { IFormulaRuntimeService } from '../services/runtime.service';
+import type { PreCalculateNodeType } from '../utils/node-type';
import { FormulaDependencyTree } from './dependency-tree';
const FORMULA_CACHE_LRU_COUNT = 100000;
@@ -33,6 +37,8 @@ export class FormulaDependencyGenerator extends Disposable {
constructor(
@IFormulaCurrentConfigService private readonly _currentConfigService: IFormulaCurrentConfigService,
@IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService,
+ @IPassiveDirtyManagerService
+ private readonly _passiveDirtyManagerService: PassiveDirtyManagerService,
@Inject(Interpreter) private readonly _interpreter: Interpreter,
@Inject(AstTreeBuilder) private readonly _astTreeBuilder: AstTreeBuilder,
@Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder
@@ -123,6 +129,9 @@ export class FormulaDependencyGenerator extends Disposable {
const treeList: FormulaDependencyTree[] = [];
+ /**
+ * Register formulas in the sheet.
+ */
for (const unitId of formulaDataKeys) {
const sheetData = formulaData[unitId];
@@ -150,6 +159,9 @@ export class FormulaDependencyGenerator extends Disposable {
}
}
+ /**
+ * Register formulas in doc, slide, and other types of applications.
+ */
for (const unitId of otherFormulaDataKeys) {
const subComponentData = otherFormulaData[unitId];
@@ -181,13 +193,34 @@ export class FormulaDependencyGenerator extends Disposable {
}
}
+ /**
+ * Register the external application relying on 'ref' into the formula system,
+ * which can determine the execution timing of the external application
+ * registration Executor based on the dependency relationship.
+ */
+ this._passiveDirtyManagerService.getReferenceExecutorMap().forEach((params, featureId) => {
+ const { unitId, subComponentId, dependencyRanges, getDirtyData } = params;
+ const FDtree = new FormulaDependencyTree();
+
+ FDtree.unitId = unitId;
+ FDtree.subComponentId = subComponentId;
+
+ FDtree.getDirtyData = getDirtyData;
+
+ FDtree.featureId = featureId;
+
+ FDtree.rangeList = dependencyRanges;
+
+ treeList.push(FDtree);
+ });
+
for (let i = 0, len = treeList.length; i < len; i++) {
const tree = treeList[i];
this._runtimeService.setCurrent(tree.row, tree.column, tree.subComponentId, tree.unitId);
if (tree.node == null) {
- throw new Error('tree node is null');
+ continue;
}
const rangeList = await this._getRangeListByNode(tree.node);
@@ -436,6 +469,18 @@ export class FormulaDependencyGenerator extends Disposable {
const unitId = tree.unitId;
const subComponentId = tree.subComponentId;
+ /**
+ * Perform active dirty detection for the feature.
+ */
+ const featureId = tree.featureId;
+ if (featureId != null) {
+ const featureMap = this._currentConfigService.getDirtyUnitFeatureMap();
+ const state = featureMap?.[unitId]?.[subComponentId]?.[featureId];
+ if (state != null) {
+ return true;
+ }
+ }
+
const excludedCell = this._currentConfigService.getExcludedRange()?.[unitId]?.[subComponentId];
/**
diff --git a/packages/engine-formula/src/interpreter/interpreter.ts b/packages/engine-formula/src/engine/interpreter/interpreter.ts
similarity index 93%
rename from packages/engine-formula/src/interpreter/interpreter.ts
rename to packages/engine-formula/src/engine/interpreter/interpreter.ts
index e73f0c1d9a..88f540c742 100644
--- a/packages/engine-formula/src/interpreter/interpreter.ts
+++ b/packages/engine-formula/src/engine/interpreter/interpreter.ts
@@ -1,14 +1,14 @@
import { Disposable } from '@univerjs/core';
+import { AstNodePromiseType } from '../../basics/common';
+import { ErrorType } from '../../basics/error-type';
+import { IFormulaRuntimeService } from '../../services/runtime.service';
import type { FunctionNode } from '../ast-node';
import type { BaseAstNode } from '../ast-node/base-ast-node';
import { NodeType } from '../ast-node/node-type';
-import { AstNodePromiseType } from '../basics/common';
-import { ErrorType } from '../basics/error-type';
-import type { PreCalculateNodeType } from '../basics/node-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { FunctionVariantType } from '../reference-object/base-reference-object';
-import { IFormulaRuntimeService } from '../services/runtime.service';
+import type { PreCalculateNodeType } from '../utils/node-type';
export class Interpreter extends Disposable {
constructor(@IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService) {
diff --git a/packages/engine-formula/src/other-object/error-value-object.ts b/packages/engine-formula/src/engine/other-object/error-value-object.ts
similarity index 86%
rename from packages/engine-formula/src/other-object/error-value-object.ts
rename to packages/engine-formula/src/engine/other-object/error-value-object.ts
index df811d32b2..4a2b97968f 100644
--- a/packages/engine-formula/src/other-object/error-value-object.ts
+++ b/packages/engine-formula/src/engine/other-object/error-value-object.ts
@@ -1,5 +1,5 @@
-import type { ErrorType } from '../basics/error-type';
-import { ObjectClassType } from '../basics/object-class-type';
+import type { ErrorType } from '../../basics/error-type';
+import { ObjectClassType } from '../../basics/object-class-type';
export class ErrorValueObject extends ObjectClassType {
static errorMap: Map<ErrorType, ErrorValueObject> = new Map();
diff --git a/packages/engine-formula/src/reference-object/base-reference-object.ts b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
similarity index 87%
rename from packages/engine-formula/src/reference-object/base-reference-object.ts
rename to packages/engine-formula/src/engine/reference-object/base-reference-object.ts
index bf8727320a..5373244779 100644
--- a/packages/engine-formula/src/reference-object/base-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
@@ -1,9 +1,9 @@
import type { ICellData, IRange, Nullable } from '@univerjs/core';
import { CellValueType } from '@univerjs/core';
-import type { IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap } from '../basics/common';
-import { ERROR_TYPE_SET, ErrorType } from '../basics/error-type';
-import { ObjectClassType } from '../basics/object-class-type';
+import type { IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap } from '../../basics/common';
+import { ERROR_TYPE_SET, ErrorType } from '../../basics/error-type';
+import { ObjectClassType } from '../../basics/object-class-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import { ArrayValueObject } from '../value-object/array-value-object';
import type { BaseValueObject, CalculateValueType, IArrayValueObject } from '../value-object/base-value-object';
@@ -43,6 +43,8 @@ export class BaseReferenceObject extends ObjectClassType {
private _runtimeArrayFormulaCellData: IRuntimeUnitDataType = {};
+ private _runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType } = {};
+
private _refOffsetX = 0;
private _refOffsetY = 0;
@@ -106,7 +108,7 @@ export class BaseReferenceObject extends ObjectClassType {
iterator(callback: (valueObject: CalculateValueType, rowIndex: number, columnIndex: number) => Nullable<boolean>) {
const { startRow, endRow, startColumn, endColumn } = this.getRangePosition();
- if (this._checkIfComponentMiss()) {
+ if (this._checkIfWorksheetMiss()) {
return callback(new ErrorValueObject(ErrorType.VALUE), startRow, startColumn);
}
@@ -130,6 +132,17 @@ export class BaseReferenceObject extends ObjectClassType {
}
}
+ getFirstCell() {
+ const { startRow, startColumn } = this.getRangePosition();
+ const cell = this.getCellData(startRow + this._refOffsetY, startColumn + this._refOffsetX);
+
+ if (!cell) {
+ return new NumberValueObject(0, true);
+ }
+
+ return this.getCellValueObject(cell);
+ }
+
getRangeData() {
return this._rangeData;
}
@@ -232,6 +245,14 @@ export class BaseReferenceObject extends ObjectClassType {
this._runtimeArrayFormulaCellData = unitData;
}
+ getRuntimeFeatureCellData() {
+ return this._runtimeFeatureCellData;
+ }
+
+ setRuntimeFeatureCellData(unitData: { [featureId: string]: IRuntimeUnitDataType }) {
+ this._runtimeFeatureCellData = unitData;
+ }
+
getRowCount() {
return this.getCurrentActiveSheetData().rowCount;
}
@@ -325,11 +346,32 @@ export class BaseReferenceObject extends ObjectClassType {
return (
activeRuntimeData?.getValue(row, column) ||
activeRuntimeArrayFormulaCellData?.getValue(row, column) ||
+ this.getRuntimeFeatureCellValue(row, column) ||
activeArrayFormulaCellData?.getValue(row, column) ||
activeSheetData.cellData.getValue(row, column)
);
}
+ getRuntimeFeatureCellValue(row: number, column: number) {
+ const featureKeys = Object.keys(this._runtimeFeatureCellData);
+
+ for (const featureId of featureKeys) {
+ const data = this._runtimeFeatureCellData[featureId];
+ const runtimeFeatureCellData = data?.[this.getUnitId()]?.[this.getSheetId()];
+ if (runtimeFeatureCellData == null) {
+ continue;
+ }
+
+ const value = runtimeFeatureCellData.getValue(row, column);
+
+ if (value == null) {
+ continue;
+ }
+
+ return value;
+ }
+ }
+
getCellByPosition(row?: number, column?: number) {
if (!row) {
row = this._rangeData.startRow;
@@ -380,7 +422,7 @@ export class BaseReferenceObject extends ObjectClassType {
};
}
- private _checkIfComponentMiss() {
+ private _checkIfWorksheetMiss() {
if ((this._forcedSheetId == null || this._forcedSheetId.length === 0) && this._forcedSheetName.length > 0) {
return true;
}
diff --git a/packages/engine-formula/src/reference-object/cell-reference-object.ts b/packages/engine-formula/src/engine/reference-object/cell-reference-object.ts
similarity index 96%
rename from packages/engine-formula/src/reference-object/cell-reference-object.ts
rename to packages/engine-formula/src/engine/reference-object/cell-reference-object.ts
index 345550e152..746892fc30 100644
--- a/packages/engine-formula/src/reference-object/cell-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/cell-reference-object.ts
@@ -1,7 +1,7 @@
import type { IRange } from '@univerjs/core';
import { deserializeRangeWithSheet } from '@univerjs/core';
-import { ErrorType } from '../basics/error-type';
+import { ErrorType } from '../../basics/error-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import { BaseReferenceObject } from './base-reference-object';
import { RangeReferenceObject } from './range-reference-object';
@@ -84,6 +84,8 @@ export class CellReferenceObject extends BaseReferenceObject {
rangeReferenceObject.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData());
+ rangeReferenceObject.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());
+
const { x, y } = this.getRefOffset();
rangeReferenceObject.setRefOffset(x, y);
diff --git a/packages/engine-formula/src/reference-object/column-reference-object.ts b/packages/engine-formula/src/engine/reference-object/column-reference-object.ts
similarity index 97%
rename from packages/engine-formula/src/reference-object/column-reference-object.ts
rename to packages/engine-formula/src/engine/reference-object/column-reference-object.ts
index 8f6071a1b9..9b54a7ead2 100644
--- a/packages/engine-formula/src/reference-object/column-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/column-reference-object.ts
@@ -1,7 +1,7 @@
import type { IRange } from '@univerjs/core';
import { deserializeRangeWithSheet } from '@univerjs/core';
-import { ErrorType } from '../basics/error-type';
+import { ErrorType } from '../../basics/error-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import { BaseReferenceObject } from './base-reference-object';
diff --git a/packages/engine-formula/src/reference-object/range-reference-object.ts b/packages/engine-formula/src/engine/reference-object/range-reference-object.ts
similarity index 100%
rename from packages/engine-formula/src/reference-object/range-reference-object.ts
rename to packages/engine-formula/src/engine/reference-object/range-reference-object.ts
diff --git a/packages/engine-formula/src/reference-object/row-reference-object.ts b/packages/engine-formula/src/engine/reference-object/row-reference-object.ts
similarity index 96%
rename from packages/engine-formula/src/reference-object/row-reference-object.ts
rename to packages/engine-formula/src/engine/reference-object/row-reference-object.ts
index 8a511f7c9a..c6eb47c3f2 100644
--- a/packages/engine-formula/src/reference-object/row-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/row-reference-object.ts
@@ -1,7 +1,7 @@
import type { IRange } from '@univerjs/core';
import { deserializeRangeWithSheet } from '@univerjs/core';
-import { ErrorType } from '../basics/error-type';
+import { ErrorType } from '../../basics/error-type';
import { ErrorValueObject } from '../other-object/error-value-object';
import { BaseReferenceObject } from './base-reference-object';
diff --git a/packages/engine-formula/src/reference-object/table-reference-object.ts b/packages/engine-formula/src/engine/reference-object/table-reference-object.ts
similarity index 94%
rename from packages/engine-formula/src/reference-object/table-reference-object.ts
rename to packages/engine-formula/src/engine/reference-object/table-reference-object.ts
index 22a6fde8a2..ccd1866c3f 100644
--- a/packages/engine-formula/src/reference-object/table-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/table-reference-object.ts
@@ -1,7 +1,7 @@
-import type { ISuperTable } from '../basics/common';
-import { TableOptionType } from '../basics/common';
-import { $SUPER_TABLE_COLUMN_REGEX } from '../basics/regex';
-import { matchToken } from '../basics/token';
+import type { ISuperTable } from '../../basics/common';
+import { TableOptionType } from '../../basics/common';
+import { $SUPER_TABLE_COLUMN_REGEX } from '../../basics/regex';
+import { matchToken } from '../../basics/token';
import { BaseReferenceObject } from './base-reference-object';
// =Table2[[#Headers],[11111]:[Column3]]
diff --git a/packages/engine-formula/src/basics/function-definition.ts b/packages/engine-formula/src/engine/utils/function-definition.ts
similarity index 90%
rename from packages/engine-formula/src/basics/function-definition.ts
rename to packages/engine-formula/src/engine/utils/function-definition.ts
index 21e5ca7d5b..8ddddb7448 100644
--- a/packages/engine-formula/src/basics/function-definition.ts
+++ b/packages/engine-formula/src/engine/utils/function-definition.ts
@@ -1,5 +1,5 @@
+import { DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER } from '../../basics/token-type';
import { LexerNode } from '../analysis/lexer-node';
-import { DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER } from './token-type';
export function isFirstChildParameter(lexerNode: LexerNode | string) {
if (!(lexerNode instanceof LexerNode)) {
diff --git a/packages/engine-formula/src/basics/node-type.ts b/packages/engine-formula/src/engine/utils/node-type.ts
similarity index 100%
rename from packages/engine-formula/src/basics/node-type.ts
rename to packages/engine-formula/src/engine/utils/node-type.ts
diff --git a/packages/engine-formula/src/basics/sequence.ts b/packages/engine-formula/src/engine/utils/sequence.ts
similarity index 100%
rename from packages/engine-formula/src/basics/sequence.ts
rename to packages/engine-formula/src/engine/utils/sequence.ts
diff --git a/packages/engine-formula/src/value-object/array-value-object.ts b/packages/engine-formula/src/engine/value-object/array-value-object.ts
similarity index 96%
rename from packages/engine-formula/src/value-object/array-value-object.ts
rename to packages/engine-formula/src/engine/value-object/array-value-object.ts
index 09fd0a9fac..c269c60470 100644
--- a/packages/engine-formula/src/value-object/array-value-object.ts
+++ b/packages/engine-formula/src/engine/value-object/array-value-object.ts
@@ -1,9 +1,9 @@
import type { Nullable } from '@univerjs/core';
-import { BooleanValue } from '../basics/common';
-import { ErrorType } from '../basics/error-type';
-import { $ARRAY_VALUE_REGEX } from '../basics/regex';
-import type { compareToken } from '../basics/token';
+import { BooleanValue } from '../../basics/common';
+import { ErrorType } from '../../basics/error-type';
+import { $ARRAY_VALUE_REGEX } from '../../basics/regex';
+import type { compareToken } from '../../basics/token';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { CalculateValueType, IArrayValueObject } from './base-value-object';
import { BaseValueObject } from './base-value-object';
@@ -107,6 +107,12 @@ export class ArrayValueObject extends BaseValueObject {
}
}
+ getFirstCell() {
+ const { startRow, startColumn } = this.getRangePosition();
+ const valueList = this.getArrayValue();
+ return valueList[startRow][startColumn];
+ }
+
override plus(valueObject: BaseValueObject): CalculateValueType {
return this._batchOperator(valueObject, BatchOperatorType.PLUS);
}
diff --git a/packages/engine-formula/src/value-object/base-value-object.ts b/packages/engine-formula/src/engine/value-object/base-value-object.ts
similarity index 94%
rename from packages/engine-formula/src/value-object/base-value-object.ts
rename to packages/engine-formula/src/engine/value-object/base-value-object.ts
index 436fc20a4f..057cbe7c78 100644
--- a/packages/engine-formula/src/value-object/base-value-object.ts
+++ b/packages/engine-formula/src/engine/value-object/base-value-object.ts
@@ -1,7 +1,7 @@
-import { ConcatenateType } from '../basics/common';
-import { ErrorType } from '../basics/error-type';
-import { ObjectClassType } from '../basics/object-class-type';
-import type { compareToken } from '../basics/token';
+import { ConcatenateType } from '../../basics/common';
+import { ErrorType } from '../../basics/error-type';
+import { ObjectClassType } from '../../basics/object-class-type';
+import type { compareToken } from '../../basics/token';
import { ErrorValueObject } from '../other-object/error-value-object';
export type CalculateValueType = BaseValueObject | ErrorValueObject;
diff --git a/packages/engine-formula/src/value-object/primitive-object.ts b/packages/engine-formula/src/engine/value-object/primitive-object.ts
similarity index 98%
rename from packages/engine-formula/src/value-object/primitive-object.ts
rename to packages/engine-formula/src/engine/value-object/primitive-object.ts
index 26a0ec5c13..a0a7a36bb3 100644
--- a/packages/engine-formula/src/value-object/primitive-object.ts
+++ b/packages/engine-formula/src/engine/value-object/primitive-object.ts
@@ -1,7 +1,7 @@
-import { reverseCompareOperator } from '../basics/calculate';
-import { BooleanValue, ConcatenateType } from '../basics/common';
-import { ErrorType } from '../basics/error-type';
-import { compareToken } from '../basics/token';
+import { reverseCompareOperator } from '../../basics/calculate';
+import { BooleanValue, ConcatenateType } from '../../basics/common';
+import { ErrorType } from '../../basics/error-type';
+import { compareToken } from '../../basics/token';
import { ErrorValueObject } from '../other-object/error-value-object';
import type { CalculateValueType } from './base-value-object';
import { BaseValueObject } from './base-value-object';
diff --git a/packages/engine-formula/src/functions/average.ts b/packages/engine-formula/src/functions/average.ts
index cd3ded4d5a..bcba4f76ce 100644
--- a/packages/engine-formula/src/functions/average.ts
+++ b/packages/engine-formula/src/functions/average.ts
@@ -1,9 +1,9 @@
import { ErrorType } from '../basics/error-type';
import { FUNCTION_NAMES } from '../basics/function';
-import { ErrorValueObject } from '../other-object/error-value-object';
-import type { FunctionVariantType } from '../reference-object/base-reference-object';
+import { ErrorValueObject } from '../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../engine/value-object/base-value-object';
import { IFunctionService } from '../services/function.service';
-import type { BaseValueObject } from '../value-object/base-value-object';
import { BaseFunction } from './base-function';
export class Average extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/base-function.ts b/packages/engine-formula/src/functions/base-function.ts
index cdcff8d7d0..bad47f8dbd 100644
--- a/packages/engine-formula/src/functions/base-function.ts
+++ b/packages/engine-formula/src/functions/base-function.ts
@@ -2,9 +2,9 @@ import { Disposable } from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../other-object/error-value-object';
-import type { FunctionVariantType, NodeValueType } from '../reference-object/base-reference-object';
-import type { BaseValueObject } from '../value-object/base-value-object';
+import { ErrorValueObject } from '../engine/other-object/error-value-object';
+import type { FunctionVariantType, NodeValueType } from '../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../engine/value-object/base-value-object';
export class BaseFunction extends Disposable {
constructor(
diff --git a/packages/engine-formula/src/functions/concatenate.ts b/packages/engine-formula/src/functions/concatenate.ts
index 2c32554077..173dbed391 100644
--- a/packages/engine-formula/src/functions/concatenate.ts
+++ b/packages/engine-formula/src/functions/concatenate.ts
@@ -1,6 +1,6 @@
import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../other-object/error-value-object';
-import type { FunctionVariantType } from '../reference-object/base-reference-object';
+import { ErrorValueObject } from '../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
import { BaseFunction } from './base-function';
export class Concatenate extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/count.ts b/packages/engine-formula/src/functions/count.ts
index 16ffcebeca..2b2882d992 100644
--- a/packages/engine-formula/src/functions/count.ts
+++ b/packages/engine-formula/src/functions/count.ts
@@ -1,7 +1,7 @@
-import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import type { ArrayValueObject } from '../value-object/array-value-object';
-import type { BaseValueObject } from '../value-object/base-value-object';
-import { NumberValueObject } from '../value-object/primitive-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../engine/value-object/base-value-object';
+import { NumberValueObject } from '../engine/value-object/primitive-object';
import { BaseFunction } from './base-function';
export class Count extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/indirect.ts b/packages/engine-formula/src/functions/indirect.ts
index a6d2150a9c..955e67e95b 100644
--- a/packages/engine-formula/src/functions/indirect.ts
+++ b/packages/engine-formula/src/functions/indirect.ts
@@ -1,5 +1,5 @@
-import type { FunctionVariantType } from '../reference-object/base-reference-object';
-import { CellReferenceObject } from '../reference-object/cell-reference-object';
+import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import { CellReferenceObject } from '../engine/reference-object/cell-reference-object';
import { BaseFunction } from './base-function';
export class Indirect extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/max.ts b/packages/engine-formula/src/functions/max.ts
index 5caf0b135f..b0401379a6 100644
--- a/packages/engine-formula/src/functions/max.ts
+++ b/packages/engine-formula/src/functions/max.ts
@@ -1,9 +1,9 @@
import { compareToken } from '../basics/token';
-import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import type { ArrayValueObject } from '../value-object/array-value-object';
-import type { BaseValueObject } from '../value-object/base-value-object';
-import type { BooleanValueObject } from '../value-object/primitive-object';
-import { NumberValueObject } from '../value-object/primitive-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../engine/value-object/base-value-object';
+import type { BooleanValueObject } from '../engine/value-object/primitive-object';
+import { NumberValueObject } from '../engine/value-object/primitive-object';
import { BaseFunction } from './base-function';
export class Max extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/meta/compare.ts b/packages/engine-formula/src/functions/meta/compare.ts
index 8be58191b4..8872877055 100644
--- a/packages/engine-formula/src/functions/meta/compare.ts
+++ b/packages/engine-formula/src/functions/meta/compare.ts
@@ -1,8 +1,8 @@
import { ErrorType } from '../../basics/error-type';
import { compareToken } from '../../basics/token';
-import { ErrorValueObject } from '../../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../reference-object/base-reference-object';
-import type { BaseValueObject } from '../../value-object/base-value-object';
+import { ErrorValueObject } from '../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../engine/value-object/base-value-object';
import { BaseFunction } from '../base-function';
export class Compare extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/meta/divided.ts b/packages/engine-formula/src/functions/meta/divided.ts
index 3808b208fa..1f9677bb42 100644
--- a/packages/engine-formula/src/functions/meta/divided.ts
+++ b/packages/engine-formula/src/functions/meta/divided.ts
@@ -1,7 +1,7 @@
import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../reference-object/base-reference-object';
-import type { BaseValueObject } from '../../value-object/base-value-object';
+import { ErrorValueObject } from '../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../engine/value-object/base-value-object';
import { BaseFunction } from '../base-function';
export class Divided extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/meta/minus.ts b/packages/engine-formula/src/functions/meta/minus.ts
index 08cc192f44..796e467e8f 100644
--- a/packages/engine-formula/src/functions/meta/minus.ts
+++ b/packages/engine-formula/src/functions/meta/minus.ts
@@ -1,7 +1,7 @@
import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../other-object/error-value-object';
-import type { FunctionVariantType } from '../../reference-object/base-reference-object';
-import type { BaseValueObject } from '../../value-object/base-value-object';
+import { ErrorValueObject } from '../../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../engine/value-object/base-value-object';
import { BaseFunction } from '../base-function';
export class Minus extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/meta/multiply.ts b/packages/engine-formula/src/functions/meta/multiply.ts
index 8af6b30090..e83dda3fb0 100644
--- a/packages/engine-formula/src/functions/meta/multiply.ts
+++ b/packages/engine-formula/src/functions/meta/multiply.ts
@@ -1,7 +1,7 @@
import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../reference-object/base-reference-object';
-import type { BaseValueObject } from '../../value-object/base-value-object';
+import { ErrorValueObject } from '../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../engine/value-object/base-value-object';
import { BaseFunction } from '../base-function';
export class Multiply extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/meta/plus.ts b/packages/engine-formula/src/functions/meta/plus.ts
index 9f6cf7d22d..28548cc271 100644
--- a/packages/engine-formula/src/functions/meta/plus.ts
+++ b/packages/engine-formula/src/functions/meta/plus.ts
@@ -1,7 +1,7 @@
import { ErrorType } from '../../basics/error-type';
-import { ErrorValueObject } from '../../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../reference-object/base-reference-object';
-import type { BaseValueObject } from '../../value-object/base-value-object';
+import { ErrorValueObject } from '../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../engine/value-object/base-value-object';
import { BaseFunction } from '../base-function';
export class Plus extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/meta/union.ts b/packages/engine-formula/src/functions/meta/union.ts
index 95c66528ae..c33c6882ee 100644
--- a/packages/engine-formula/src/functions/meta/union.ts
+++ b/packages/engine-formula/src/functions/meta/union.ts
@@ -1,7 +1,7 @@
import { ErrorType } from '../../basics/error-type';
import { compareToken } from '../../basics/token';
-import { ErrorValueObject } from '../../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../../reference-object/base-reference-object';
+import { ErrorValueObject } from '../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object';
import { BaseFunction } from '../base-function';
export class Union extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/min.ts b/packages/engine-formula/src/functions/min.ts
index befb5ff4c0..20a5115736 100644
--- a/packages/engine-formula/src/functions/min.ts
+++ b/packages/engine-formula/src/functions/min.ts
@@ -1,9 +1,9 @@
import { compareToken } from '../basics/token';
-import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import type { ArrayValueObject } from '../value-object/array-value-object';
-import type { BaseValueObject } from '../value-object/base-value-object';
-import type { BooleanValueObject } from '../value-object/primitive-object';
-import { NumberValueObject } from '../value-object/primitive-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../engine/value-object/base-value-object';
+import type { BooleanValueObject } from '../engine/value-object/primitive-object';
+import { NumberValueObject } from '../engine/value-object/primitive-object';
import { BaseFunction } from './base-function';
export class Min extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/offset.ts b/packages/engine-formula/src/functions/offset.ts
index 3ec2ff381a..9c26a9ec57 100644
--- a/packages/engine-formula/src/functions/offset.ts
+++ b/packages/engine-formula/src/functions/offset.ts
@@ -1,5 +1,5 @@
-import type { FunctionVariantType } from '../reference-object/base-reference-object';
-import { CellReferenceObject } from '../reference-object/cell-reference-object';
+import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import { CellReferenceObject } from '../engine/reference-object/cell-reference-object';
import { BaseFunction } from './base-function';
export class Offset extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/power.ts b/packages/engine-formula/src/functions/power.ts
index 4e8f5521fa..59a483f459 100644
--- a/packages/engine-formula/src/functions/power.ts
+++ b/packages/engine-formula/src/functions/power.ts
@@ -1,6 +1,6 @@
import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../other-object/error-value-object';
-import type { FunctionVariantType } from '../reference-object/base-reference-object';
+import { ErrorValueObject } from '../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
import { BaseFunction } from './base-function';
export class Power extends BaseFunction {
diff --git a/packages/engine-formula/src/functions/sum.ts b/packages/engine-formula/src/functions/sum.ts
index 4af9fc0d52..c6b0d1e6bb 100644
--- a/packages/engine-formula/src/functions/sum.ts
+++ b/packages/engine-formula/src/functions/sum.ts
@@ -1,9 +1,9 @@
import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import type { ArrayValueObject } from '../value-object/array-value-object';
-import type { BaseValueObject } from '../value-object/base-value-object';
-import { NumberValueObject } from '../value-object/primitive-object';
+import { ErrorValueObject } from '../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../engine/value-object/base-value-object';
+import { NumberValueObject } from '../engine/value-object/primitive-object';
import { BaseFunction } from './base-function';
export class Sum extends BaseFunction {
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index 1101a16137..fdaa897a56 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -1,7 +1,7 @@
-export { LexerNode } from './analysis/lexer-node';
export type {
IArrayFormulaRangeType,
IArrayFormulaUnitCellType,
+ IDirtyUnitFeatureMap,
IDirtyUnitSheetNameMap,
IFormulaData,
IFormulaDataItem,
@@ -15,20 +15,23 @@ export { isInDirtyRange } from './basics/dirty';
export { ErrorType } from './basics/error-type';
export { FUNCTION_NAMES, FunctionType, type IFunctionInfo, type IFunctionParam } from './basics/function';
export { includeFormulaLexerToken, isFormulaLexerToken, normalizeSheetName } from './basics/match-token';
-export { generateStringWithSequence, type ISequenceNode, sequenceNodeType } from './basics/sequence';
export { matchToken } from './basics/token';
export { compareToken } from './basics/token';
+export { LexerNode } from './engine/analysis/lexer-node';
+export { ErrorValueObject } from './engine/other-object/error-value-object';
+export { BaseReferenceObject, type FunctionVariantType } from './engine/reference-object/base-reference-object';
+export { RangeReferenceObject } from './engine/reference-object/range-reference-object';
+export { generateStringWithSequence, type ISequenceNode, sequenceNodeType } from './engine/utils/sequence';
+export { ArrayValueObject } from './engine/value-object/array-value-object';
+export { BaseValueObject } from './engine/value-object/base-value-object';
+export { NumberValueObject } from './engine/value-object/primitive-object';
+export { BooleanValueObject } from './engine/value-object/primitive-object';
+export { StringValueObject } from './engine/value-object/primitive-object';
export { BaseFunction } from './functions/base-function';
-export { ErrorValueObject } from './other-object/error-value-object';
export { BaseFormulaEnginePlugin } from './plugin';
-export { BaseReferenceObject, type FunctionVariantType } from './reference-object/base-reference-object';
-export { RangeReferenceObject } from './reference-object/range-reference-object';
+export { IActiveDirtyManagerService } from './services/active-dirty-manager.service';
export { FormulaEngineService } from './services/formula-engine.service';
export { IFunctionService } from './services/function.service';
+export { IPassiveDirtyManagerService, PassiveDirtyManagerService } from './services/passive-dirty-manager.service';
export { FormulaExecuteStageType, type IExecutionInProgressParams } from './services/runtime.service';
export { FormulaExecutedStateType, type IAllRuntimeData } from './services/runtime.service';
-export { ArrayValueObject } from './value-object/array-value-object';
-export { BaseValueObject } from './value-object/base-value-object';
-export { NumberValueObject } from './value-object/primitive-object';
-export { BooleanValueObject } from './value-object/primitive-object';
-export { StringValueObject } from './value-object/primitive-object';
diff --git a/packages/engine-formula/src/plugin.ts b/packages/engine-formula/src/plugin.ts
index 47c4846fca..4e9ac30cf4 100644
--- a/packages/engine-formula/src/plugin.ts
+++ b/packages/engine-formula/src/plugin.ts
@@ -1,6 +1,7 @@
import { Plugin } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
+import { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service';
import { FormulaEngineService } from './services/formula-engine.service';
const PLUGIN_NAME = 'base-formula-engine';
@@ -15,5 +16,6 @@ export class BaseFormulaEnginePlugin extends Plugin {
override onStarting(injector: Injector): void {
injector.add([FormulaEngineService]);
+ injector.add([IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }]);
}
}
diff --git a/packages/engine-formula/src/services/active-dirty-manager.service.ts b/packages/engine-formula/src/services/active-dirty-manager.service.ts
new file mode 100644
index 0000000000..c7d3fa3f52
--- /dev/null
+++ b/packages/engine-formula/src/services/active-dirty-manager.service.ts
@@ -0,0 +1,64 @@
+import type { ICommandInfo, IUnitRange, Nullable } from '@univerjs/core';
+import { Disposable } from '@univerjs/core';
+import { createIdentifier } from '@wendellhu/redi';
+
+import type { IDirtyUnitFeatureMap, IDirtyUnitSheetNameMap } from '../basics/common';
+
+export interface IDirtyConversionManagerParams {
+ commandId: string;
+ getDirtyData: (command: ICommandInfo) => {
+ dirtyRanges?: IUnitRange[];
+ dirtyNameMap?: IDirtyUnitSheetNameMap;
+ dirtyUnitFeatureMap?: IDirtyUnitFeatureMap;
+ };
+}
+
+export interface IActiveDirtyManagerService {
+ dispose(): void;
+
+ remove(commandId: string): void;
+
+ get(commandId: string): Nullable<IDirtyConversionManagerParams>;
+
+ has(featureId: string): boolean;
+
+ register(featureId: string, dirtyConversion: IDirtyConversionManagerParams): void;
+
+ getDirtyConversionMap(): Map<string, IDirtyConversionManagerParams>;
+}
+
+/**
+ * Actively mark as dirty, calculate the dirty area based on the command,
+ * and plugins can register the ref range they affect into the formula engine.
+ */
+export class ActiveDirtyManagerService extends Disposable implements IActiveDirtyManagerService {
+ private _dirtyConversionMap: Map<string, IDirtyConversionManagerParams> = new Map();
+
+ override dispose(): void {
+ this._dirtyConversionMap.clear();
+ }
+
+ remove(commandId: string) {
+ this._dirtyConversionMap.delete(commandId);
+ }
+
+ get(commandId: string) {
+ return this._dirtyConversionMap.get(commandId);
+ }
+
+ has(commandId: string) {
+ return this._dirtyConversionMap.has(commandId);
+ }
+
+ register(commandId: string, dirtyConversion: IDirtyConversionManagerParams) {
+ this._dirtyConversionMap.set(commandId, dirtyConversion);
+ }
+
+ getDirtyConversionMap() {
+ return this._dirtyConversionMap;
+ }
+}
+
+export const IActiveDirtyManagerService = createIdentifier<ActiveDirtyManagerService>(
+ 'univer.formula.active-dirty-manager.service'
+);
diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts
index a2ba289a2c..9e33d3e0f3 100644
--- a/packages/engine-formula/src/services/current-data.service.ts
+++ b/packages/engine-formula/src/services/current-data.service.ts
@@ -4,6 +4,7 @@ import { createIdentifier } from '@wendellhu/redi';
import type {
IArrayFormulaUnitCellType,
+ IDirtyUnitFeatureMap,
IDirtyUnitSheetNameMap,
IFormulaData,
IFormulaDatasetConfig,
@@ -32,6 +33,8 @@ export interface IFormulaCurrentConfigService {
getDirtyNameMap(): IDirtyUnitSheetNameMap;
+ getDirtyUnitFeatureMap(): IDirtyUnitFeatureMap;
+
registerUnitData(unitData: IUnitData): void;
registerFormulaData(formulaData: IFormulaData): void;
@@ -60,6 +63,8 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
private _dirtyNameMap: IDirtyUnitSheetNameMap = {};
+ private _dirtyUnitFeatureMap: IDirtyUnitFeatureMap = {};
+
private _excludedCell: Nullable<IUnitExcludedCell>;
constructor(@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService) {
@@ -72,6 +77,8 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
this._arrayFormulaCellData = {};
this._sheetNameMap = {};
this._dirtyRanges = [];
+ this._dirtyNameMap = {};
+ this._dirtyUnitFeatureMap = {};
this._excludedCell = {};
}
@@ -111,6 +118,10 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
return this._dirtyNameMap;
}
+ getDirtyUnitFeatureMap() {
+ return this._dirtyUnitFeatureMap;
+ }
+
load(config: IFormulaDatasetConfig) {
const { allUnitData, unitSheetNameMap } = this._loadSheetData();
@@ -130,6 +141,8 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
this._dirtyNameMap = config.dirtyNameMap;
+ this._dirtyUnitFeatureMap = config.dirtyUnitFeatureMap;
+
this._excludedCell = config.excludedCell;
}
diff --git a/packages/engine-formula/src/services/formula-engine.service.ts b/packages/engine-formula/src/services/formula-engine.service.ts
index 34f5e99f2b..074004f7f1 100644
--- a/packages/engine-formula/src/services/formula-engine.service.ts
+++ b/packages/engine-formula/src/services/formula-engine.service.ts
@@ -11,25 +11,33 @@ import type { Ctor, Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { Subject } from 'rxjs';
-import { LexerTreeBuilder } from '../analysis/lexer';
-import type { LexerNode } from '../analysis/lexer-node';
-import { AstTreeBuilder } from '../analysis/parser';
-import { AstRootNodeFactory } from '../ast-node/ast-root-node';
-import { ErrorNode } from '../ast-node/base-ast-node';
-import { FunctionNodeFactory } from '../ast-node/function-node';
-import { LambdaNodeFactory } from '../ast-node/lambda-node';
-import { LambdaParameterNodeFactory } from '../ast-node/lambda-parameter-node';
-import { OperatorNodeFactory } from '../ast-node/operator-node';
-import { PrefixNodeFactory } from '../ast-node/prefix-node';
-import { ReferenceNodeFactory } from '../ast-node/reference-node';
-import { SuffixNodeFactory } from '../ast-node/suffix-node';
-import { UnionNodeFactory } from '../ast-node/union-node';
-import { ValueNodeFactory } from '../ast-node/value-node';
-import type { IArrayFormulaRangeType, IFormulaDatasetConfig, IUnitExcludedCell } from '../basics/common';
+import type {
+ IArrayFormulaRangeType,
+ IFeatureDirtyRangeType,
+ IFormulaDatasetConfig,
+ IRuntimeUnitDataType,
+ IUnitExcludedCell,
+} from '../basics/common';
import { ErrorType } from '../basics/error-type';
import type { IFunctionInfo } from '../basics/function';
import { FUNCTION_NAMES } from '../basics/function';
-import { FormulaDependencyGenerator } from '../dependency/formula-dependency';
+import { LexerTreeBuilder } from '../engine/analysis/lexer';
+import type { LexerNode } from '../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../engine/analysis/parser';
+import { AstRootNodeFactory } from '../engine/ast-node/ast-root-node';
+import { ErrorNode } from '../engine/ast-node/base-ast-node';
+import { FunctionNodeFactory } from '../engine/ast-node/function-node';
+import { LambdaNodeFactory } from '../engine/ast-node/lambda-node';
+import { LambdaParameterNodeFactory } from '../engine/ast-node/lambda-parameter-node';
+import { OperatorNodeFactory } from '../engine/ast-node/operator-node';
+import { PrefixNodeFactory } from '../engine/ast-node/prefix-node';
+import { ReferenceNodeFactory } from '../engine/ast-node/reference-node';
+import { SuffixNodeFactory } from '../engine/ast-node/suffix-node';
+import { UnionNodeFactory } from '../engine/ast-node/union-node';
+import { ValueNodeFactory } from '../engine/ast-node/value-node';
+import { FormulaDependencyGenerator } from '../engine/dependency/formula-dependency';
+import { Interpreter } from '../engine/interpreter/interpreter';
+import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
import {
Average,
Compare,
@@ -48,11 +56,10 @@ import {
Union,
} from '../functions';
import type { BaseFunction } from '../functions/base-function';
-import { Interpreter } from '../interpreter/interpreter';
-import type { FunctionVariantType } from '../reference-object/base-reference-object';
import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from './current-data.service';
import { DefinedNamesService, IDefinedNamesService } from './defined-names.service';
import { FunctionService, IFunctionService } from './function.service';
+import { IPassiveDirtyManagerService, PassiveDirtyManagerService } from './passive-dirty-manager.service';
import type { IAllRuntimeData, IExecutionInProgressParams } from './runtime.service';
import { FormulaExecuteStageType, FormulaRuntimeService, IFormulaRuntimeService } from './runtime.service';
import { ISuperTableService, SuperTableService } from './super-table.service';
@@ -124,6 +131,10 @@ export class FormulaEngineService extends Disposable {
return this._injector.get(LexerTreeBuilder);
}
+ get PassiveDirtyManagerService() {
+ return this._injector.get(IPassiveDirtyManagerService);
+ }
+
/**
* Use register to register a function, new CustomFunction(inject, name)
*/
@@ -199,6 +210,21 @@ export class FormulaEngineService extends Disposable {
this.runtimeService.stopExecution();
}
+ /**
+ * When the feature is loading,
+ * the pre-calculated content needs to be input to the formula engine in advance,
+ * so that the formula can read the correct values.
+ * @param featureId
+ * @param featureData
+ */
+ setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType) {
+ this.runtimeService.setRuntimeFeatureCellData(featureId, featureData);
+ }
+
+ setRuntimeFeatureRange(featureId: string, featureRange: IFeatureDirtyRangeType) {
+ this.runtimeService.setRuntimeFeatureRange(featureId, featureRange);
+ }
+
/**
*
* @param unitId
@@ -240,9 +266,12 @@ export class FormulaEngineService extends Disposable {
return;
}
- const { arrayFormulaRange } = executeState;
+ const { arrayFormulaRange, runtimeFeatureRange } = executeState;
- const { dirtyRanges, excludedCell } = this._getArrayFormulaDirtyRangeAndExcludedRange(arrayFormulaRange);
+ const { dirtyRanges, excludedCell } = this._getArrayFormulaDirtyRangeAndExcludedRange(
+ arrayFormulaRange,
+ runtimeFeatureRange
+ );
if (dirtyRanges == null || dirtyRanges.length === 0) {
return true;
@@ -255,7 +284,10 @@ export class FormulaEngineService extends Disposable {
return true;
}
- private _getArrayFormulaDirtyRangeAndExcludedRange(arrayFormulaRange: IArrayFormulaRangeType) {
+ private _getArrayFormulaDirtyRangeAndExcludedRange(
+ arrayFormulaRange: IArrayFormulaRangeType,
+ runtimeFeatureRange: { [featureId: string]: IFeatureDirtyRangeType }
+ ) {
const dirtyRanges: IUnitRange[] = [];
const excludedCell: IUnitExcludedCell = {};
Object.keys(arrayFormulaRange).forEach((unitId) => {
@@ -283,6 +315,24 @@ export class FormulaEngineService extends Disposable {
});
});
+ Object.keys(runtimeFeatureRange).forEach((featureId) => {
+ const arrayRange = runtimeFeatureRange[featureId];
+ Object.keys(arrayRange).forEach((unitId) => {
+ const sheetArrayFormulaRange = arrayRange[unitId];
+ Object.keys(sheetArrayFormulaRange).forEach((sheetId) => {
+ const ranges = sheetArrayFormulaRange[sheetId];
+
+ if (ranges == null) {
+ return true;
+ }
+
+ for (const range of ranges) {
+ dirtyRanges.push({ unitId, sheetId, range });
+ }
+ });
+ });
+ });
+
return { dirtyRanges, excludedCell };
}
@@ -328,26 +378,38 @@ export class FormulaEngineService extends Disposable {
const tree = treeList[i];
const astNode = tree.node;
+ const getDirtyData = tree.getDirtyData;
let value: FunctionVariantType;
- if (astNode == null) {
- throw new Error('astNode is null');
+ if (astNode == null && getDirtyData == null) {
+ throw new Error('AstNode or executor is null');
}
this.runtimeService.setCurrent(tree.row, tree.column, tree.subComponentId, tree.unitId);
- if (interpreter.checkAsyncNode(astNode)) {
- value = await interpreter.executeAsync(astNode);
- } else {
- value = interpreter.execute(astNode);
- }
-
- // this.runtimeService.setCurrent(tree.row, tree.column, tree.subComponentId, tree.unitId);
+ if (getDirtyData != null && tree.featureId != null) {
+ /**
+ * Execute the dependencies registered by the feature,
+ * and return the dirty area marked by the feature,
+ * so as to allow the formulas depending on the dirty area to continue the calculation.
+ */
+ const { runtimeCellData, dirtyRanges } = getDirtyData(tree);
+
+ this.runtimeService.setRuntimeFeatureCellData(tree.featureId, runtimeCellData);
+
+ this.runtimeService.setRuntimeFeatureRange(tree.featureId, dirtyRanges);
+ } else if (astNode != null) {
+ if (interpreter.checkAsyncNode(astNode)) {
+ value = await interpreter.executeAsync(astNode);
+ } else {
+ value = interpreter.execute(astNode);
+ }
- if (tree.formulaId != null) {
- this.runtimeService.setRuntimeOtherData(tree.formulaId, value);
- } else {
- this.runtimeService.setRuntimeData(value);
+ if (tree.formulaId != null) {
+ this.runtimeService.setRuntimeOtherData(tree.formulaId, value);
+ } else {
+ this.runtimeService.setRuntimeData(value);
+ }
}
if (isArrayFormulaState) {
@@ -420,6 +482,9 @@ export class FormulaEngineService extends Disposable {
[ISuperTableService, { useClass: SuperTableService }],
[IDefinedNamesService, { useClass: DefinedNamesService }],
[IFunctionService, { useClass: FunctionService }],
+ [IPassiveDirtyManagerService, { useClass: PassiveDirtyManagerService }],
+
+ // [IPassiveDirtyManagerService, { useClass: PassiveDirtyManagerService }],
// Calculation engine
[FormulaDependencyGenerator],
diff --git a/packages/engine-formula/src/services/passive-dirty-manager.service.ts b/packages/engine-formula/src/services/passive-dirty-manager.service.ts
new file mode 100644
index 0000000000..b006e72a4c
--- /dev/null
+++ b/packages/engine-formula/src/services/passive-dirty-manager.service.ts
@@ -0,0 +1,68 @@
+import type { IUnitRange, Nullable } from '@univerjs/core';
+import { Disposable } from '@univerjs/core';
+import { createIdentifier } from '@wendellhu/redi';
+
+import type { IFeatureDirtyRangeType, IRuntimeUnitDataType } from '../basics/common';
+import type { FormulaDependencyTree } from '../engine/dependency/dependency-tree';
+
+export interface IReferenceExecutorManagerParams {
+ unitId: string;
+ subComponentId: string;
+ dependencyRanges: IUnitRange[];
+ getDirtyData: (currentDependencyTree: FormulaDependencyTree) => {
+ runtimeCellData: IRuntimeUnitDataType;
+ dirtyRanges: IFeatureDirtyRangeType;
+ };
+}
+
+export interface IPassiveDirtyManagerService {
+ dispose(): void;
+
+ remove(featureId: string): void;
+
+ get(featureId: string): Nullable<IReferenceExecutorManagerParams>;
+
+ has(featureId: string): boolean;
+
+ register(featureId: string, referenceExecutor: IReferenceExecutorManagerParams): void;
+
+ getReferenceExecutorMap(): Map<string, IReferenceExecutorManagerParams>;
+}
+
+/**
+ * Passively marked as dirty, register the reference and execution actions of the feature plugin.
+ * After execution, a dirty area and calculated data will be returned,
+ * causing the formula to be marked dirty again,
+ * thereby completing the calculation of the entire dependency tree.
+ */
+export class PassiveDirtyManagerService extends Disposable implements IPassiveDirtyManagerService {
+ private _referenceExecutorMap: Map<string, IReferenceExecutorManagerParams> = new Map();
+
+ override dispose(): void {
+ this._referenceExecutorMap.clear();
+ }
+
+ remove(featureId: string) {
+ this._referenceExecutorMap.delete(featureId);
+ }
+
+ get(featureId: string) {
+ return this._referenceExecutorMap.get(featureId);
+ }
+
+ has(featureId: string) {
+ return this._referenceExecutorMap.has(featureId);
+ }
+
+ register(featureId: string, referenceExecutor: IReferenceExecutorManagerParams) {
+ this._referenceExecutorMap.set(featureId, referenceExecutor);
+ }
+
+ getReferenceExecutorMap() {
+ return this._referenceExecutorMap;
+ }
+}
+
+export const IPassiveDirtyManagerService = createIdentifier<PassiveDirtyManagerService>(
+ 'univer.formula.passive-dirty-manager.service'
+);
diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.ts
index 04324478b2..5879d650ec 100644
--- a/packages/engine-formula/src/services/runtime.service.ts
+++ b/packages/engine-formula/src/services/runtime.service.ts
@@ -2,14 +2,19 @@ import type { ICellData, IRange, Nullable } from '@univerjs/core';
import { CellValueType, Disposable, isNullCell, ObjectMatrix } from '@univerjs/core';
import { createIdentifier } from '@wendellhu/redi';
-import type { BaseAstNode } from '../ast-node/base-ast-node';
-import type { IArrayFormulaRangeType, IRuntimeOtherUnitDataType, IRuntimeUnitDataType } from '../basics/common';
+import type {
+ IArrayFormulaRangeType,
+ IFeatureDirtyRangeType,
+ IRuntimeOtherUnitDataType,
+ IRuntimeUnitDataType,
+} from '../basics/common';
import { isInDirtyRange } from '../basics/dirty';
import { ErrorType } from '../basics/error-type';
-import { ErrorValueObject } from '../other-object/error-value-object';
-import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';
-import type { ArrayValueObject } from '../value-object/array-value-object';
-import type { BaseValueObject, CalculateValueType } from '../value-object/base-value-object';
+import type { BaseAstNode } from '../engine/ast-node/base-ast-node';
+import { ErrorValueObject } from '../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../engine/value-object/array-value-object';
+import type { BaseValueObject, CalculateValueType } from '../engine/value-object/base-value-object';
import { IFormulaCurrentConfigService } from './current-data.service';
/**
@@ -46,6 +51,9 @@ export interface IAllRuntimeData {
functionsExecutedState: FormulaExecutedStateType;
arrayFormulaCellData: IRuntimeUnitDataType;
clearArrayFormulaCellData: IRuntimeUnitDataType;
+
+ runtimeFeatureRange: { [featureId: string]: IFeatureDirtyRangeType };
+ runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType };
}
export interface IExecutionInProgressParams {
@@ -130,6 +138,10 @@ export interface IFormulaRuntimeService {
isCycleDependency(): boolean;
getRuntimeArrayFormulaCellData(): IRuntimeUnitDataType;
+
+ getRuntimeFeatureRange(): { [featureId: string]: IFeatureDirtyRangeType };
+
+ getRuntimeFeatureCellData(): { [featureId: string]: IRuntimeUnitDataType };
}
export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeService {
@@ -152,6 +164,10 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
private _runtimeClearArrayFormulaCellData: IRuntimeUnitDataType = {};
+ private _runtimeFeatureRange: { [featureId: string]: IFeatureDirtyRangeType } = {};
+
+ private _runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType } = {};
+
private _functionsExecutedState: FormulaExecutedStateType = FormulaExecutedStateType.INITIAL;
// lambdaId: { key: BaseAstNode }
@@ -189,6 +205,8 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
override dispose(): void {
this.reset();
+ this._runtimeFeatureCellData = {};
+ this._runtimeFeatureRange = {};
}
enableCycleDependency() {
@@ -276,6 +294,10 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
this._unitArrayFormulaRange = {};
this._runtimeArrayFormulaCellData = {};
this._runtimeClearArrayFormulaCellData = {};
+
+ // this._runtimeFeatureCellData = {};
+ // this._runtimeFeatureRange = {};
+
this._functionDefinitionPrivacyVar.clear();
this.markedAsInitialFunctionsExecuted();
@@ -385,6 +407,17 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
const { startRow, startColumn, endRow, endColumn } = objectValueRefOrArray.getRangePosition();
+ /**
+ * If the referenced range or array only contains a single value, such as A5,
+ * then it is not treated as an array range and is directly assigned.
+ */
+ if (startRow === endRow && startColumn === endColumn) {
+ const valueObject = this._objectValueToCellValue(objectValueRefOrArray.getFirstCell());
+ sheetData.setValue(row, column, valueObject);
+ clearArrayUnitData.setValue(row, column, valueObject);
+ return;
+ }
+
const arrayRange = {
startRow: row,
startColumn: column,
@@ -446,6 +479,22 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
return this._runtimeClearArrayFormulaCellData;
}
+ getRuntimeFeatureRange() {
+ return this._runtimeFeatureRange;
+ }
+
+ setRuntimeFeatureRange(featureId: string, featureRange: IFeatureDirtyRangeType) {
+ this._runtimeFeatureRange[featureId] = featureRange;
+ }
+
+ getRuntimeFeatureCellData() {
+ return this._runtimeFeatureCellData;
+ }
+
+ setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType) {
+ this._runtimeFeatureCellData[featureId] = featureData;
+ }
+
getAllRuntimeData(): IAllRuntimeData {
return {
unitData: this.getUnitData(),
@@ -454,6 +503,9 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
functionsExecutedState: this._functionsExecutedState,
arrayFormulaCellData: this.getRuntimeArrayFormulaCellData(),
clearArrayFormulaCellData: this.getRuntimeClearArrayFormulaCellData(),
+
+ runtimeFeatureRange: this.getRuntimeFeatureRange(),
+ runtimeFeatureCellData: this.getRuntimeFeatureCellData(),
};
}
diff --git a/packages/engine-render/src/base-object.ts b/packages/engine-render/src/base-object.ts
index 2675644b31..bfb608365f 100644
--- a/packages/engine-render/src/base-object.ts
+++ b/packages/engine-render/src/base-object.ts
@@ -325,9 +325,9 @@ export abstract class BaseObject {
return;
}
- // window.clearTimeout(scene.debounceParentTimeout);
+ // clearTimeout(scene.debounceParentTimeout);
// // To prevent multiple refreshes caused by setting values for multiple object instances at once.
- // scene.debounceParentTimeout = window.setTimeout(() => {
+ // scene.debounceParentTimeout = setTimeout(() => {
// this._parent?.makeDirty(state);
// }, 0);
diff --git a/packages/engine-render/src/basics/performance-monitor.ts b/packages/engine-render/src/basics/performance-monitor.ts
index 720471dc97..6e0a30b0e7 100644
--- a/packages/engine-render/src/basics/performance-monitor.ts
+++ b/packages/engine-render/src/basics/performance-monitor.ts
@@ -91,8 +91,8 @@ export class PerformanceMonitor {
}
Now(): number {
- if (window.performance && window.performance.now) {
- return window.performance.now();
+ if (performance && performance.now) {
+ return performance.now();
}
return Date.now();
diff --git a/packages/engine-render/src/basics/tools.ts b/packages/engine-render/src/basics/tools.ts
index a8be3ed1f7..a437f9f79a 100644
--- a/packages/engine-render/src/basics/tools.ts
+++ b/packages/engine-render/src/basics/tools.ts
@@ -86,7 +86,7 @@ export const requestNewFrame = (func: Function, requester?: any): number => {
if (requester.oRequestAnimationFrame) {
return requester.oRequestAnimationFrame(func);
}
- return window.setTimeout(func, ONE_FRAME_NUMBER);
+ return setTimeout(func, ONE_FRAME_NUMBER);
};
export const cancelRequestFrame = (requestID: number, requester?: any) => {
@@ -112,7 +112,7 @@ export const cancelRequestFrame = (requestID: number, requester?: any) => {
if (requester.oRequestAnimationFrame) {
return requester.oCancelAnimationFrame(requestID);
}
- return window.clearTimeout(requestID);
+ return clearTimeout(requestID);
};
export const createCanvasElement = (): HTMLCanvasElement => {
diff --git a/packages/engine-render/src/scene.input-manager.ts b/packages/engine-render/src/scene.input-manager.ts
index a2caf9cd9f..5a56d3d16b 100644
--- a/packages/engine-render/src/scene.input-manager.ts
+++ b/packages/engine-render/src/scene.input-manager.ts
@@ -53,7 +53,7 @@ export class InputManager {
private _startingPosition = new Vector2(Infinity, Infinity);
- private _delayedTimeout: number = -1;
+ private _delayedTimeout: NodeJS.Timeout | number = -1;
private _doubleClickOccurred = 0;
@@ -337,7 +337,7 @@ export class InputManager {
this._doubleClickOccurred += 1;
- this._delayedTimeout = window.setTimeout(() => {
+ this._delayedTimeout = setTimeout(() => {
this._resetDoubleClickParam();
}, InputManager.DoubleOrTripleClickDelay);
@@ -380,6 +380,6 @@ export class InputManager {
this._doubleClickOccurred = 0;
this._startingPosition.x = Infinity;
this._startingPosition.y = Infinity;
- window.clearTimeout(this._delayedTimeout);
+ clearTimeout(this._delayedTimeout);
}
}
diff --git a/packages/engine-render/src/viewport.ts b/packages/engine-render/src/viewport.ts
index 368dd823a4..5eeaab6a9b 100644
--- a/packages/engine-render/src/viewport.ts
+++ b/packages/engine-render/src/viewport.ts
@@ -118,7 +118,7 @@ export class Viewport {
private _allowCache: boolean = false;
- private _scrollStopNum: number = 0;
+ private _scrollStopNum: NodeJS.Timeout | number = 0;
private _preScrollX: Nullable<number> = 0;
@@ -832,8 +832,8 @@ export class Viewport {
y?: number,
isTrigger = true
) {
- window.clearTimeout(this._scrollStopNum);
- this._scrollStopNum = window.setTimeout(() => {
+ clearTimeout(this._scrollStopNum);
+ this._scrollStopNum = setTimeout(() => {
this.onScrollStopObserver.notifyObservers({
viewport: this,
scrollX: this.scrollX,
diff --git a/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
index d4aa4d9407..a664785376 100644
--- a/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
+++ b/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
@@ -11,7 +11,7 @@ export interface ISetFormulaCalculationStartMutation {
* TODO: @DR-Univer
* Trigger the calculation of the formula and stop the formula
*/
-export const setFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation> = {
+export const SetFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation> = {
id: 'formula.mutation.set-formula-calculation-start',
type: CommandType.MUTATION,
handler: (accessor: IAccessor, params: ISetFormulaCalculationStartMutation) => true,
@@ -19,7 +19,7 @@ export const setFormulaCalculationStartMutation: IMutation<ISetFormulaCalculatio
export interface ISetFormulaCalculationStopMutation {}
-export const setFormulaCalculationStopMutation: IMutation<ISetFormulaCalculationStopMutation> = {
+export const SetFormulaCalculationStopMutation: IMutation<ISetFormulaCalculationStopMutation> = {
id: 'formula.mutation.set-formula-calculation-stop',
type: CommandType.MUTATION,
handler: (accessor: IAccessor, params: ISetFormulaCalculationStopMutation) => true,
@@ -30,7 +30,7 @@ export interface ISetFormulaCalculationNotificationMutation {
stageInfo?: IExecutionInProgressParams;
}
-export const setFormulaCalculationNotificationMutation: IMutation<ISetFormulaCalculationNotificationMutation> = {
+export const SetFormulaCalculationNotificationMutation: IMutation<ISetFormulaCalculationNotificationMutation> = {
id: 'formula.mutation.set-formula-calculation-notification',
type: CommandType.MUTATION,
handler: (accessor: IAccessor, params: ISetFormulaCalculationNotificationMutation) => true,
diff --git a/packages/formula/src/controllers/calculate.controller.ts b/packages/formula/src/controllers/calculate.controller.ts
index d165407cc5..b7522990ce 100644
--- a/packages/formula/src/controllers/calculate.controller.ts
+++ b/packages/formula/src/controllers/calculate.controller.ts
@@ -1,47 +1,23 @@
-import type { ICellData, ICommandInfo, IRange, IUnitRange, ObjectMatrixPrimitiveType } from '@univerjs/core';
-import {
- Dimension,
- Disposable,
- ICommandService,
- IUniverInstanceService,
- LifecycleStages,
- ObjectMatrix,
- OnLifecycle,
-} from '@univerjs/core';
-import type { IAllRuntimeData, IDirtyUnitSheetNameMap, IFormulaData } from '@univerjs/engine-formula';
-import { FormulaEngineService, FormulaExecutedStateType } from '@univerjs/engine-formula';
+import type { ICommandInfo, IUnitRange } from '@univerjs/core';
+import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type {
- IDeleteRangeMutationParams,
- IMoveColumnsMutationParams,
- IMoveRangeMutationParams,
- IMoveRowsMutationParams,
- IRemoveRowsMutationParams,
- IRemoveSheetMutationParams,
- ISetRangeValuesMutationParams,
-} from '@univerjs/sheets';
-import {
- DeleteRangeMutation,
- InsertRangeMutation,
- InsertSheetMutation,
- MoveColsMutation,
- MoveRangeMutation,
- MoveRowsMutation,
- RemoveColMutation,
- RemoveRowMutation,
- RemoveSheetMutation,
- SetRangeValuesMutation,
- SetStyleCommand,
-} from '@univerjs/sheets';
+ IAllRuntimeData,
+ IDirtyUnitFeatureMap,
+ IDirtyUnitSheetNameMap,
+ IFormulaData,
+} from '@univerjs/engine-formula';
+import { FormulaEngineService, FormulaExecutedStateType, IActiveDirtyManagerService } from '@univerjs/engine-formula';
+import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
+import { SetRangeValuesMutation } from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
-import type { Nullable } from 'vitest';
import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
import {
- setFormulaCalculationNotificationMutation,
- setFormulaCalculationStartMutation,
- setFormulaCalculationStopMutation,
+ SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationStartMutation,
+ SetFormulaCalculationStopMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
@@ -56,7 +32,8 @@ export class CalculateController extends Disposable {
@Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@Inject(IFormulaService) private readonly _formulaService: FormulaService,
- @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel
+ @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,
+ @IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService
) {
super();
@@ -73,20 +50,20 @@ export class CalculateController extends Disposable {
private _commandExecutedListener() {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (command.id === setFormulaCalculationStopMutation.id) {
+ if (command.id === SetFormulaCalculationStopMutation.id) {
this._formulaEngineService.stopFormulaExecution();
} else if (command.id === SetFormulaDataMutation.id) {
const formulaData = (command.params as ISetFormulaDataMutationParams).formulaData as IFormulaData;
this._formulaDataModel.setFormulaData(formulaData);
- } else if (command.id === setFormulaCalculationStartMutation.id) {
+ } else if (command.id === SetFormulaCalculationStartMutation.id) {
const params = command.params as ISetFormulaCalculationStartMutation;
if (params.forceCalculation === true) {
this._calculate(true);
} else {
- const { dirtyRanges, dirtyNameMap } = this._generateDirty(params.commands);
+ const { dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap } = this._generateDirty(params.commands);
- this._calculate(false, dirtyRanges, dirtyNameMap);
+ this._calculate(false, dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap);
}
} else if (command.id === SetArrayFormulaDataMutation.id) {
const params = command.params as ISetArrayFormulaDataMutationParams;
@@ -104,303 +81,87 @@ export class CalculateController extends Disposable {
}
private _generateDirty(commands: ICommandInfo[]) {
- const dirtyRanges: IUnitRange[] = [];
- const dirtyNameMap: IDirtyUnitSheetNameMap = {};
+ const allDirtyRanges: IUnitRange[] = [];
+ const allDirtyNameMap: IDirtyUnitSheetNameMap = {};
+ const allDirtyUnitFeatureMap: IDirtyUnitFeatureMap = {};
for (const command of commands) {
- if (command.id === SetRangeValuesMutation.id) {
- const params = command.params as ISetRangeValuesMutationParams;
- /**
- * Changes in the cell value caused by the formula or style
- * will not trigger the formula to be marked as dirty for calculation.
- */
- if (params.isFormulaUpdate === true || params.trigger === SetStyleCommand.id) {
- continue;
- }
- dirtyRanges.push(...this._getSetRangeValuesMutationDirtyRange(params));
- } else if (command.id === MoveRangeMutation.id) {
- const params = command.params as IMoveRangeMutationParams;
- dirtyRanges.push(...this._getMoveRangeMutationDirtyRange(params));
- } else if (command.id === MoveRowsMutation.id || command.id === MoveColsMutation.id) {
- const params = command.params as IMoveRowsMutationParams | IMoveColumnsMutationParams;
- dirtyRanges.push(...this._getMoveRowsMutationDirtyRange(params));
- } else if (command.id === DeleteRangeMutation.id || command.id === InsertRangeMutation.id) {
- const params = command.params as IDeleteRangeMutationParams;
- dirtyRanges.push(...this._getDeleteRangeMutationDirtyRange(params));
- } else if (command.id === RemoveRowMutation.id || command.id === RemoveColMutation.id) {
- const params = command.params as IRemoveRowsMutationParams;
- const isRow = command.id === RemoveRowMutation.id;
- dirtyRanges.push(...this._getRemoveRowOrColumnMutation(params, isRow));
- } else if (command.id === RemoveSheetMutation.id) {
- const params = command.params as IRemoveSheetMutationParams;
- this._getSheetMutationDirtyName(dirtyNameMap, params);
- } else if (command.id === InsertSheetMutation.id) {
- const params = command.params as IRemoveSheetMutationParams;
- this._getSheetMutationDirtyName(dirtyNameMap, params);
- }
- // else if (command.id === SetWorksheetNameMutation.id) {
- // const params = command.params as ISetWorksheetNameMutationParams;
- // this._getSheetMutationDirtyName(dirtyNameMap, params, params.name);
- // }
- }
-
- return {
- dirtyRanges,
- dirtyNameMap,
- };
- }
-
- private _getSetRangeValuesMutationDirtyRange(params: ISetRangeValuesMutationParams) {
- const { worksheetId: sheetId, workbookId: unitId, cellValue } = params;
-
- const dirtyRanges: IUnitRange[] = [];
-
- if (cellValue == null) {
- return dirtyRanges;
- }
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, cellValue));
-
- dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, cellValue));
-
- return dirtyRanges;
- }
-
- private _getMoveRangeMutationDirtyRange(params: IMoveRangeMutationParams) {
- const { worksheetId: sheetId, workbookId: unitId, from, to } = params;
-
- const dirtyRanges: IUnitRange[] = [];
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, from));
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, to));
-
- dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, to));
-
- return dirtyRanges;
- }
+ const conversion = this._activeDirtyManagerService.get(command.id);
- private _getMoveRowsMutationDirtyRange(params: IMoveRowsMutationParams) {
- const { worksheetId: sheetId, workbookId: unitId, sourceRange, targetRange } = params;
-
- const dirtyRanges: IUnitRange[] = [];
-
- const sourceMatrix = this._rangeToMatrix(sourceRange).getData();
-
- const targetMatrix = this._rangeToMatrix(targetRange).getData();
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, sourceMatrix));
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, targetMatrix));
-
- dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, targetMatrix));
-
- return dirtyRanges;
- }
-
- private _getDeleteRangeMutationDirtyRange(params: IDeleteRangeMutationParams) {
- const { worksheetId: sheetId, workbookId: unitId, ranges, shiftDimension } = params;
-
- const dirtyRanges: IUnitRange[] = [];
-
- const workbook = this._currentUniverService.getUniverSheetInstance(unitId);
-
- const worksheet = workbook?.getSheetBySheetId(sheetId);
-
- const lastEndRow = worksheet?.getLastRowWithContent() || 0;
-
- const lastEndColumn = worksheet?.getLastColumnWithContent() || 0;
-
- const matrix = new ObjectMatrix<ICellData | null>();
-
- for (const range of ranges) {
- let newMatrix: Nullable<ObjectMatrix<ICellData | null>> = null;
- const { startRow, startColumn, endRow, endColumn } = range;
- if (shiftDimension === Dimension.ROWS) {
- newMatrix = this._rangeToMatrix({
- startRow,
- startColumn,
- endRow: lastEndRow,
- endColumn,
- });
- } else if (shiftDimension === Dimension.COLUMNS) {
- newMatrix = this._rangeToMatrix({
- startRow,
- startColumn,
- endRow,
- endColumn: lastEndColumn,
- });
- }
-
- if (newMatrix != null) {
- matrix.merge(newMatrix);
+ if (conversion == null) {
+ continue;
}
- }
-
- const matrixData = matrix.getData();
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));
-
- dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrixData));
-
- return dirtyRanges;
- }
- private _getRemoveRowOrColumnMutation(params: IRemoveRowsMutationParams, isRow: boolean = true) {
- const { worksheetId: sheetId, workbookId: unitId, ranges } = params;
+ const params = conversion.getDirtyData(command);
- const dirtyRanges: IUnitRange[] = [];
+ const { dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap } = params;
- const workbook = this._currentUniverService.getUniverSheetInstance(unitId);
-
- const worksheet = workbook?.getSheetBySheetId(sheetId);
-
- const rowCount = worksheet?.getRowCount() || 0;
-
- const columnCount = worksheet?.getColumnCount() || 0;
-
- const matrix = new ObjectMatrix<ICellData | null>();
-
- for (const range of ranges) {
- let newMatrix: Nullable<ObjectMatrix<ICellData | null>> = null;
- const { startRow, endRow, startColumn, endColumn } = range;
-
- if (isRow === true) {
- newMatrix = this._rangeToMatrix({
- startRow,
- startColumn: 0,
- endRow,
- endColumn: columnCount - 1,
- });
- } else {
- newMatrix = this._rangeToMatrix({
- startRow: 0,
- startColumn,
- endRow: rowCount,
- endColumn,
- });
+ if (dirtyRanges != null) {
+ allDirtyRanges.push(...dirtyRanges);
}
- if (newMatrix != null) {
- matrix.merge(newMatrix);
+ if (dirtyNameMap != null) {
+ this._mergeDirtyNameMap(allDirtyNameMap, dirtyNameMap);
}
- }
-
- const matrixData = matrix.getData();
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));
-
- dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrixData));
- return dirtyRanges;
- }
-
- private _getSheetMutationDirtyName(
- dirtyNameMap: IDirtyUnitSheetNameMap,
- params: IRemoveSheetMutationParams,
- name?: Nullable<string>
- ) {
- const { worksheetId: sheetId, workbookId: unitId } = params;
-
- // const dirtyNameMap: IDirtyUnitSheetNameMap = {};
-
- if (dirtyNameMap[unitId] == null) {
- dirtyNameMap[unitId] = {};
- }
-
- dirtyNameMap[unitId][sheetId] = name;
-
- return dirtyNameMap;
- }
-
- private _rangeToMatrix(range: IRange) {
- const matrix = new ObjectMatrix<ICellData | null>();
-
- const { startRow, startColumn, endRow, endColumn } = range;
-
- for (let r = startRow; r <= endRow; r++) {
- for (let c = startColumn; c <= endColumn; c++) {
- matrix.setValue(r, c, {});
+ if (dirtyUnitFeatureMap != null) {
+ this._mergeDirtyUnitFeatureMap(allDirtyUnitFeatureMap, dirtyUnitFeatureMap);
}
}
- return matrix;
+ return {
+ dirtyRanges: allDirtyRanges,
+ dirtyNameMap: allDirtyNameMap,
+ dirtyUnitFeatureMap: allDirtyUnitFeatureMap,
+ };
}
- private _getDirtyRangesByCellValue(
- unitId: string,
- sheetId: string,
- cellValue?: ObjectMatrixPrimitiveType<ICellData | null>
- ) {
- const dirtyRanges: IUnitRange[] = [];
-
- if (cellValue == null) {
- return dirtyRanges;
- }
-
- const cellMatrix = new ObjectMatrix(cellValue);
-
- const discreteRanges = cellMatrix.getDiscreteRanges();
-
- discreteRanges.forEach((range) => {
- dirtyRanges.push({ unitId, sheetId, range });
+ private _mergeDirtyNameMap(allDirtyNameMap: IDirtyUnitSheetNameMap, dirtyNameMap: IDirtyUnitSheetNameMap) {
+ Object.keys(dirtyNameMap).forEach((unitId) => {
+ if (allDirtyNameMap[unitId] == null) {
+ allDirtyNameMap[unitId] = {};
+ }
+ Object.keys(dirtyNameMap[unitId]).forEach((sheetId) => {
+ allDirtyNameMap[unitId][sheetId] = dirtyNameMap[unitId][sheetId];
+ });
});
-
- return dirtyRanges;
}
- /**
- * The array formula is a range where only the top-left corner contains the formula value.
- * All other positions, apart from the top-left corner, need to be marked as dirty.
- */
- private _getDirtyRangesForArrayFormula(
- unitId: string,
- sheetId: string,
- cellValue: ObjectMatrixPrimitiveType<ICellData | null>
+ private _mergeDirtyUnitFeatureMap(
+ allDirtyUnitFeatureMap: IDirtyUnitFeatureMap,
+ dirtyUnitFeatureMap: IDirtyUnitFeatureMap
) {
- const dirtyRanges: IUnitRange[] = [];
-
- if (cellValue == null) {
- return dirtyRanges;
- }
-
- const cellMatrix = new ObjectMatrix(cellValue);
-
- const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
-
- /**
- * The array formula is a range where only the top-left corner contains the formula value.
- * All other positions, apart from the top-left corner, need to be marked as dirty.
- */
- if (arrayFormulaRange?.[unitId]?.[sheetId]) {
- const cellRangeData = new ObjectMatrix<IRange>(arrayFormulaRange?.[unitId]?.[sheetId]);
- cellMatrix.forValue((row, column) => {
- cellRangeData.forValue((arrayFormulaRow, arrayFormulaColumn, arrayFormulaRange) => {
- const { startRow, startColumn, endRow, endColumn } = arrayFormulaRange;
- if (row >= startRow && row <= endRow && column >= startColumn && column <= endColumn) {
- dirtyRanges.push({
- unitId,
- sheetId,
- range: {
- startRow,
- startColumn,
- endRow: startRow,
- endColumn: startColumn,
- },
- });
- }
+ Object.keys(dirtyUnitFeatureMap).forEach((unitId) => {
+ if (allDirtyUnitFeatureMap[unitId] == null) {
+ allDirtyUnitFeatureMap[unitId] = {};
+ }
+ Object.keys(dirtyUnitFeatureMap[unitId]).forEach((sheetId) => {
+ if (allDirtyUnitFeatureMap[unitId][sheetId] == null) {
+ allDirtyUnitFeatureMap[unitId][sheetId] = {};
+ }
+ Object.keys(dirtyUnitFeatureMap[unitId][sheetId]).forEach((featureId) => {
+ allDirtyUnitFeatureMap[unitId][sheetId][featureId] =
+ dirtyUnitFeatureMap[unitId][sheetId][featureId];
});
});
- }
-
- return dirtyRanges;
+ });
}
private async _calculate(
forceCalculate: boolean = false,
dirtyRanges: IUnitRange[] = [],
- dirtyNameMap: IDirtyUnitSheetNameMap = {}
+ dirtyNameMap: IDirtyUnitSheetNameMap = {},
+ dirtyUnitFeatureMap: IDirtyUnitFeatureMap = {}
) {
+ if (
+ dirtyRanges.length === 0 &&
+ Object.keys(dirtyNameMap).length === 0 &&
+ Object.keys(dirtyUnitFeatureMap).length === 0 &&
+ forceCalculate === false
+ ) {
+ return;
+ }
+
const formulaData = this._formulaDataModel.getFormulaData();
const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
@@ -413,6 +174,7 @@ export class CalculateController extends Disposable {
forceCalculate,
dirtyRanges,
dirtyNameMap,
+ dirtyUnitFeatureMap,
});
}
@@ -435,7 +197,7 @@ export class CalculateController extends Disposable {
break;
}
- this._commandService.executeCommand(setFormulaCalculationNotificationMutation.id, {
+ this._commandService.executeCommand(SetFormulaCalculationNotificationMutation.id, {
functionsExecutedState,
});
});
@@ -464,7 +226,7 @@ export class CalculateController extends Disposable {
);
}
- this._commandService.executeCommand(setFormulaCalculationNotificationMutation.id, {
+ this._commandService.executeCommand(SetFormulaCalculationNotificationMutation.id, {
stageInfo: data,
});
});
diff --git a/packages/formula/src/controllers/dirty-conversion.controller.ts b/packages/formula/src/controllers/dirty-conversion.controller.ts
new file mode 100644
index 0000000000..3c05b4a62a
--- /dev/null
+++ b/packages/formula/src/controllers/dirty-conversion.controller.ts
@@ -0,0 +1,440 @@
+import type { ICellData, ICommandInfo, IRange, IUnitRange, Nullable, ObjectMatrixPrimitiveType } from '@univerjs/core';
+import {
+ Dimension,
+ Disposable,
+ IUniverInstanceService,
+ LifecycleStages,
+ ObjectMatrix,
+ OnLifecycle,
+} from '@univerjs/core';
+import type { IDirtyUnitSheetNameMap } from '@univerjs/engine-formula';
+import { IActiveDirtyManagerService } from '@univerjs/engine-formula';
+import type {
+ IDeleteRangeMutationParams,
+ IInsertRangeMutationParams,
+ IInsertSheetMutationParams,
+ IMoveColumnsMutationParams,
+ IMoveRangeMutationParams,
+ IMoveRowsMutationParams,
+ IRemoveColMutationParams,
+ IRemoveRowsMutationParams,
+ IRemoveSheetMutationParams,
+ ISetRangeValuesMutationParams,
+} from '@univerjs/sheets';
+import {
+ DeleteRangeMutation,
+ InsertRangeMutation,
+ InsertSheetMutation,
+ MoveColsMutation,
+ MoveRangeMutation,
+ MoveRowsMutation,
+ RemoveColMutation,
+ RemoveRowMutation,
+ RemoveSheetMutation,
+ SetRangeValuesMutation,
+ SetStyleCommand,
+} from '@univerjs/sheets';
+import { Inject } from '@wendellhu/redi';
+
+import { FormulaDataModel } from '../models/formula-data.model';
+
+@OnLifecycle(LifecycleStages.Ready, DirtyConversionController)
+export class DirtyConversionController extends Disposable {
+ constructor(
+ @IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService,
+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
+ @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel
+ ) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ this._initialConversion();
+ }
+
+ private _initialConversion() {
+ // const updateCommandList = [
+ // SetRangeValuesMutation.id,
+ // MoveRangeMutation.id,
+ // MoveRowsMutation.id,
+ // MoveColsMutation.id,
+ // DeleteRangeMutation.id,
+ // InsertRangeMutation.id,
+ // RemoveRowMutation.id,
+ // RemoveColMutation.id,
+ // RemoveSheetMutation.id,
+ // InsertSheetMutation.id,
+ // // SetWorksheetNameMutation.id,
+ // ];
+
+ this._activeDirtyManagerService.register(SetRangeValuesMutation.id, {
+ commandId: SetRangeValuesMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as ISetRangeValuesMutationParams;
+ /**
+ * Changes in the cell value caused by the formula or style
+ * will not trigger the formula to be marked as dirty for calculation.
+ */
+ if (params.isFormulaUpdate === true || params.trigger === SetStyleCommand.id) {
+ return {};
+ }
+
+ return {
+ dirtyRanges: this._getSetRangeValuesMutationDirtyRange(params),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(MoveRangeMutation.id, {
+ commandId: MoveRangeMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IMoveRangeMutationParams;
+ return {
+ dirtyRanges: this._getMoveRangeMutationDirtyRange(params),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(MoveRowsMutation.id, {
+ commandId: MoveRowsMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IMoveRowsMutationParams;
+ return {
+ dirtyRanges: this._getMoveRowsMutationDirtyRange(params),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(MoveColsMutation.id, {
+ commandId: MoveColsMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IMoveColumnsMutationParams;
+ return {
+ dirtyRanges: this._getMoveRowsMutationDirtyRange(params),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(DeleteRangeMutation.id, {
+ commandId: DeleteRangeMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IDeleteRangeMutationParams;
+ return {
+ dirtyRanges: this._getDeleteRangeMutationDirtyRange(params),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(InsertRangeMutation.id, {
+ commandId: InsertRangeMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IInsertRangeMutationParams;
+ return {
+ dirtyRanges: this._getDeleteRangeMutationDirtyRange(params),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(RemoveRowMutation.id, {
+ commandId: RemoveRowMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IRemoveRowsMutationParams;
+ return {
+ dirtyRanges: this._getRemoveRowOrColumnMutation(params, true),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(RemoveColMutation.id, {
+ commandId: RemoveColMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IRemoveColMutationParams;
+ return {
+ dirtyRanges: this._getRemoveRowOrColumnMutation(params, false),
+ };
+ },
+ });
+
+ this._activeDirtyManagerService.register(RemoveSheetMutation.id, {
+ commandId: RemoveSheetMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IRemoveSheetMutationParams;
+ return { dirtyNameMap: this._getRemoveSheetMutation(params) };
+ },
+ });
+
+ this._activeDirtyManagerService.register(InsertSheetMutation.id, {
+ commandId: InsertSheetMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IInsertSheetMutationParams;
+ return { dirtyNameMap: this._getInsertSheetMutation(params) };
+ },
+ });
+
+ // this._activeDirtyManagerService.register(SetWorksheetNameMutation.id, {
+ // commandId: SetWorksheetNameMutation.id,
+ // getDirtyData: (command: ICommandInfo) => {
+ // const params = command.params as ISetWorksheetNameMutationParams;
+ // return { dirtyNameMap: this._getRemoveSheetMutation(params, params.name) };
+ // },
+ // });
+ }
+
+ private _getSetRangeValuesMutationDirtyRange(params: ISetRangeValuesMutationParams) {
+ const { worksheetId: sheetId, workbookId: unitId, cellValue } = params;
+
+ const dirtyRanges: IUnitRange[] = [];
+
+ if (cellValue == null) {
+ return dirtyRanges;
+ }
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, cellValue));
+
+ dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, cellValue));
+
+ return dirtyRanges;
+ }
+
+ private _getMoveRangeMutationDirtyRange(params: IMoveRangeMutationParams) {
+ const { worksheetId: sheetId, workbookId: unitId, from, to } = params;
+
+ const dirtyRanges: IUnitRange[] = [];
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, from));
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, to));
+
+ dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, to));
+
+ return dirtyRanges;
+ }
+
+ private _getMoveRowsMutationDirtyRange(params: IMoveRowsMutationParams) {
+ const { worksheetId: sheetId, workbookId: unitId, sourceRange, targetRange } = params;
+
+ const dirtyRanges: IUnitRange[] = [];
+
+ const sourceMatrix = this._rangeToMatrix(sourceRange).getData();
+
+ const targetMatrix = this._rangeToMatrix(targetRange).getData();
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, sourceMatrix));
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, targetMatrix));
+
+ dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, targetMatrix));
+
+ return dirtyRanges;
+ }
+
+ private _getDeleteRangeMutationDirtyRange(params: IDeleteRangeMutationParams) {
+ const { worksheetId: sheetId, workbookId: unitId, ranges, shiftDimension } = params;
+
+ const dirtyRanges: IUnitRange[] = [];
+
+ const workbook = this._currentUniverService.getUniverSheetInstance(unitId);
+
+ const worksheet = workbook?.getSheetBySheetId(sheetId);
+
+ const lastEndRow = worksheet?.getLastRowWithContent() || 0;
+
+ const lastEndColumn = worksheet?.getLastColumnWithContent() || 0;
+
+ const matrix = new ObjectMatrix<ICellData | null>();
+
+ for (const range of ranges) {
+ let newMatrix: Nullable<ObjectMatrix<ICellData | null>> = null;
+ const { startRow, startColumn, endRow, endColumn } = range;
+ if (shiftDimension === Dimension.ROWS) {
+ newMatrix = this._rangeToMatrix({
+ startRow,
+ startColumn,
+ endRow: lastEndRow,
+ endColumn,
+ });
+ } else if (shiftDimension === Dimension.COLUMNS) {
+ newMatrix = this._rangeToMatrix({
+ startRow,
+ startColumn,
+ endRow,
+ endColumn: lastEndColumn,
+ });
+ }
+
+ if (newMatrix != null) {
+ matrix.merge(newMatrix);
+ }
+ }
+
+ const matrixData = matrix.getData();
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));
+
+ dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrixData));
+
+ return dirtyRanges;
+ }
+
+ private _getRemoveRowOrColumnMutation(params: IRemoveRowsMutationParams, isRow: boolean = true) {
+ const { worksheetId: sheetId, workbookId: unitId, ranges } = params;
+
+ const dirtyRanges: IUnitRange[] = [];
+
+ const workbook = this._currentUniverService.getUniverSheetInstance(unitId);
+
+ const worksheet = workbook?.getSheetBySheetId(sheetId);
+
+ const rowCount = worksheet?.getRowCount() || 0;
+
+ const columnCount = worksheet?.getColumnCount() || 0;
+
+ const matrix = new ObjectMatrix<ICellData | null>();
+
+ for (const range of ranges) {
+ let newMatrix: Nullable<ObjectMatrix<ICellData | null>> = null;
+ const { startRow, endRow, startColumn, endColumn } = range;
+
+ if (isRow === true) {
+ newMatrix = this._rangeToMatrix({
+ startRow,
+ startColumn: 0,
+ endRow,
+ endColumn: columnCount - 1,
+ });
+ } else {
+ newMatrix = this._rangeToMatrix({
+ startRow: 0,
+ startColumn,
+ endRow: rowCount,
+ endColumn,
+ });
+ }
+
+ if (newMatrix != null) {
+ matrix.merge(newMatrix);
+ }
+ }
+
+ const matrixData = matrix.getData();
+
+ dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));
+
+ dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrixData));
+
+ return dirtyRanges;
+ }
+
+ private _getRemoveSheetMutation(params: IRemoveSheetMutationParams, name?: Nullable<string>) {
+ const dirtyNameMap: IDirtyUnitSheetNameMap = {};
+ const { worksheetId: sheetId, workbookId: unitId } = params;
+
+ // const dirtyNameMap: IDirtyUnitSheetNameMap = {};
+
+ if (dirtyNameMap[unitId] == null) {
+ dirtyNameMap[unitId] = {};
+ }
+
+ dirtyNameMap[unitId][sheetId] = name;
+
+ return dirtyNameMap;
+ }
+
+ private _getInsertSheetMutation(params: IInsertSheetMutationParams, name?: Nullable<string>) {
+ const dirtyNameMap: IDirtyUnitSheetNameMap = {};
+ const { sheet, workbookId: unitId } = params;
+
+ if (dirtyNameMap[unitId] == null) {
+ dirtyNameMap[unitId] = {};
+ }
+
+ dirtyNameMap[unitId][sheet.id] = name;
+
+ return dirtyNameMap;
+ }
+
+ private _rangeToMatrix(range: IRange) {
+ const matrix = new ObjectMatrix<ICellData | null>();
+
+ const { startRow, startColumn, endRow, endColumn } = range;
+
+ for (let r = startRow; r <= endRow; r++) {
+ for (let c = startColumn; c <= endColumn; c++) {
+ matrix.setValue(r, c, {});
+ }
+ }
+
+ return matrix;
+ }
+
+ private _getDirtyRangesByCellValue(
+ unitId: string,
+ sheetId: string,
+ cellValue?: ObjectMatrixPrimitiveType<ICellData | null>
+ ) {
+ const dirtyRanges: IUnitRange[] = [];
+
+ if (cellValue == null) {
+ return dirtyRanges;
+ }
+
+ const cellMatrix = new ObjectMatrix(cellValue);
+
+ const discreteRanges = cellMatrix.getDiscreteRanges();
+
+ discreteRanges.forEach((range) => {
+ dirtyRanges.push({ unitId, sheetId, range });
+ });
+
+ return dirtyRanges;
+ }
+
+ /**
+ * The array formula is a range where only the top-left corner contains the formula value.
+ * All other positions, apart from the top-left corner, need to be marked as dirty.
+ */
+ private _getDirtyRangesForArrayFormula(
+ unitId: string,
+ sheetId: string,
+ cellValue: ObjectMatrixPrimitiveType<ICellData | null>
+ ) {
+ const dirtyRanges: IUnitRange[] = [];
+
+ if (cellValue == null) {
+ return dirtyRanges;
+ }
+
+ const cellMatrix = new ObjectMatrix(cellValue);
+
+ const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
+
+ /**
+ * The array formula is a range where only the top-left corner contains the formula value.
+ * All other positions, apart from the top-left corner, need to be marked as dirty.
+ */
+ if (arrayFormulaRange?.[unitId]?.[sheetId]) {
+ const cellRangeData = new ObjectMatrix<IRange>(arrayFormulaRange?.[unitId]?.[sheetId]);
+ cellMatrix.forValue((row, column) => {
+ cellRangeData.forValue((arrayFormulaRow, arrayFormulaColumn, arrayFormulaRange) => {
+ const { startRow, startColumn, endRow, endColumn } = arrayFormulaRange;
+ if (row >= startRow && row <= endRow && column >= startColumn && column <= endColumn) {
+ dirtyRanges.push({
+ unitId,
+ sheetId,
+ range: {
+ startRow,
+ startColumn,
+ endRow: startRow,
+ endColumn: startColumn,
+ },
+ });
+ }
+ });
+ });
+ }
+
+ return dirtyRanges;
+ }
+}
diff --git a/packages/formula/src/controllers/formula.controller.ts b/packages/formula/src/controllers/formula.controller.ts
index 16b6bf73f0..e8e9e02aef 100644
--- a/packages/formula/src/controllers/formula.controller.ts
+++ b/packages/formula/src/controllers/formula.controller.ts
@@ -2,9 +2,9 @@ import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univ
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import {
- setFormulaCalculationNotificationMutation,
- setFormulaCalculationStartMutation,
- setFormulaCalculationStopMutation,
+ SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationStartMutation,
+ SetFormulaCalculationStopMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
@@ -24,9 +24,9 @@ export class FormulaController extends Disposable {
[
SetFormulaDataMutation,
SetArrayFormulaDataMutation,
- setFormulaCalculationStartMutation,
- setFormulaCalculationStopMutation,
- setFormulaCalculationNotificationMutation,
+ SetFormulaCalculationStartMutation,
+ SetFormulaCalculationStopMutation,
+ SetFormulaCalculationNotificationMutation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
}
diff --git a/packages/formula/src/controllers/reference-executor-register.controller.ts b/packages/formula/src/controllers/reference-executor-register.controller.ts
new file mode 100644
index 0000000000..331a1b18fd
--- /dev/null
+++ b/packages/formula/src/controllers/reference-executor-register.controller.ts
@@ -0,0 +1,86 @@
+import {
+ Disposable,
+ ICommandService,
+ IUniverInstanceService,
+ LifecycleStages,
+ ObjectMatrix,
+ OnLifecycle,
+} from '@univerjs/core';
+import { IActiveDirtyManagerService, IPassiveDirtyManagerService } from '@univerjs/engine-formula';
+import { Inject } from '@wendellhu/redi';
+
+import { FormulaDataModel } from '../models/formula-data.model';
+
+@OnLifecycle(LifecycleStages.Ready, ReferenceExecutorRegisterController)
+export class ReferenceExecutorRegisterController extends Disposable {
+ constructor(
+ @ICommandService private readonly _commandService: ICommandService,
+ @IPassiveDirtyManagerService
+ private readonly _passiveDirtyManagerService: IPassiveDirtyManagerService,
+ @IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService,
+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
+ @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel
+ ) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ const featureId = 'test';
+
+ const unitId = 'workbook-01';
+
+ const subComponentId = 'sheet-0011';
+
+ const runtimeCellData = {
+ [unitId]: {
+ [subComponentId]: new ObjectMatrix({
+ 4: {
+ 0: {
+ v: 10,
+ t: 2,
+ },
+ },
+ }),
+ },
+ };
+
+ const dirtyRanges = {
+ [unitId]: {
+ [subComponentId]: [
+ {
+ startRow: 4,
+ startColumn: 0,
+ endRow: 4,
+ endColumn: 0,
+ },
+ ],
+ },
+ };
+
+ this._passiveDirtyManagerService.register(featureId, {
+ unitId,
+ subComponentId,
+ dependencyRanges: [
+ {
+ unitId,
+ sheetId: subComponentId,
+ range: {
+ startRow: 0,
+ endRow: 3,
+ startColumn: 0,
+ endColumn: 3,
+ },
+ },
+ ],
+ getDirtyData: () => {
+ console.log('test reference executor register');
+ return {
+ runtimeCellData,
+ dirtyRanges,
+ };
+ },
+ });
+ }
+}
diff --git a/packages/formula/src/controllers/trigger-calculation.controller.ts b/packages/formula/src/controllers/trigger-calculation.controller.ts
index 72cc74953d..6e0cca16b3 100644
--- a/packages/formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/formula/src/controllers/trigger-calculation.controller.ts
@@ -1,26 +1,13 @@
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { FormulaEngineService, FormulaExecutedStateType } from '@univerjs/engine-formula';
+import { FormulaExecutedStateType, IActiveDirtyManagerService } from '@univerjs/engine-formula';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
-import {
- DeleteRangeMutation,
- InsertRangeMutation,
- InsertSheetMutation,
- MoveColsMutation,
- MoveRangeMutation,
- MoveRowsMutation,
- RemoveColMutation,
- RemoveRowMutation,
- RemoveSheetMutation,
- SetRangeValuesMutation,
- SetStyleCommand,
-} from '@univerjs/sheets';
-import { Inject } from '@wendellhu/redi';
+import { SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';
import type { ISetFormulaCalculationNotificationMutation } from '../commands/mutations/set-formula-calculation.mutation';
import {
- setFormulaCalculationNotificationMutation,
- setFormulaCalculationStartMutation,
+ SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationStartMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
const globalObject = typeof self !== 'undefined' ? self : window;
@@ -35,7 +22,7 @@ export class TriggerCalculationController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
- @Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService
+ @IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService
) {
super();
@@ -51,23 +38,23 @@ export class TriggerCalculationController extends Disposable {
}
private _commandExecutedListener() {
- const updateCommandList = [
- SetRangeValuesMutation.id,
- MoveRangeMutation.id,
- MoveRowsMutation.id,
- MoveColsMutation.id,
- DeleteRangeMutation.id,
- InsertRangeMutation.id,
- RemoveRowMutation.id,
- RemoveColMutation.id,
- RemoveSheetMutation.id,
- // SetWorksheetNameMutation.id,
- InsertSheetMutation.id,
- ];
+ // const updateCommandList = [
+ // SetRangeValuesMutation.id,
+ // MoveRangeMutation.id,
+ // MoveRowsMutation.id,
+ // MoveColsMutation.id,
+ // DeleteRangeMutation.id,
+ // InsertRangeMutation.id,
+ // RemoveRowMutation.id,
+ // RemoveColMutation.id,
+ // RemoveSheetMutation.id,
+ // // SetWorksheetNameMutation.id,
+ // InsertSheetMutation.id,
+ // ];
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (!updateCommandList.includes(command.id)) {
+ if (!this._activeDirtyManagerService.get(command.id)) {
return;
}
@@ -84,7 +71,7 @@ export class TriggerCalculationController extends Disposable {
globalObject.clearTimeout(this._setTimeoutKey);
this._setTimeoutKey = globalObject.setTimeout(() => {
- this._commandService.executeCommand(setFormulaCalculationStartMutation.id, {
+ this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, {
commands: this._waitingCommandQueue,
});
@@ -101,7 +88,7 @@ export class TriggerCalculationController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (command.id !== setFormulaCalculationNotificationMutation.id) {
+ if (command.id !== SetFormulaCalculationNotificationMutation.id) {
return;
}
@@ -150,7 +137,7 @@ export class TriggerCalculationController extends Disposable {
}
private _initialExecuteFormula() {
- this._commandService.executeCommand(setFormulaCalculationStartMutation.id, {
+ this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, {
commands: [],
forceCalculation: true,
});
diff --git a/packages/formula/src/formula-plugin.ts b/packages/formula/src/formula-plugin.ts
index e1056af789..1ab593c7df 100644
--- a/packages/formula/src/formula-plugin.ts
+++ b/packages/formula/src/formula-plugin.ts
@@ -5,7 +5,9 @@ import { Inject, Injector } from '@wendellhu/redi';
import { FORMULA_PLUGIN_NAME } from './common/plugin-name';
import { ArrayFormulaDisplayController } from './controllers/array-formula-display.controller';
import { CalculateController } from './controllers/calculate.controller';
+import { DirtyConversionController } from './controllers/dirty-conversion.controller';
import { FormulaController } from './controllers/formula.controller';
+import { ReferenceExecutorRegisterController } from './controllers/reference-executor-register.controller';
import { TriggerCalculationController } from './controllers/trigger-calculation.controller';
import { UpdateFormulaController } from './controllers/update-formula.controller';
import type { IFormulaConfig } from './models/formula-data.model';
@@ -34,12 +36,14 @@ export class FormulaPlugin extends Plugin {
[FormulaDataModel, { useValue: this._formulaDataModel }],
// controllers
[FormulaController],
+ [DirtyConversionController],
];
if (!this._config?.notExecuteFormula) {
// only worker
dependencies.push([IFormulaService, { useClass: FormulaService }]);
dependencies.push([CalculateController]);
+ dependencies.push([ReferenceExecutorRegisterController]);
} else {
// only main thread
dependencies.push([UpdateFormulaController]);
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/animate.ts b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/animate.ts
index 4e8528b1dd..036b8ed581 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/animate.ts
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/animate.ts
@@ -58,7 +58,7 @@ export class Animate {
protected _handle: number = 0;
- protected _delayHandle: number | null = null;
+ protected _delayHandle: NodeJS.Timeout | number | null = null;
constructor(config: Partial<AnimateConfig>) {
this._config = {
@@ -105,8 +105,8 @@ export class Animate {
this._start = Date.now();
this._fakeHandle();
} else {
- this._delayHandle && window.clearTimeout(this._delayHandle);
- this._delayHandle = window.setTimeout(() => {
+ this._delayHandle && clearTimeout(this._delayHandle);
+ this._delayHandle = setTimeout(() => {
this._status = AnimateStatus.Request;
this._start = Date.now();
this._fakeHandle();
@@ -116,7 +116,7 @@ export class Animate {
cancel(): void {
this._status = AnimateStatus.Cancel;
- this._delayHandle && window.clearTimeout(this._delayHandle);
+ this._delayHandle && clearTimeout(this._delayHandle);
cancelAnimationFrame(this._handle);
}
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts
index 53c26d60a4..45642623a0 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts
@@ -390,7 +390,7 @@ export class SlideTabBar {
protected _slideScrollbar: SlideScrollbar;
- protected _longPressTimer: number | null = null;
+ protected _longPressTimer: NodeJS.Timeout | number | null = null;
/**
* left border line
@@ -493,7 +493,7 @@ export class SlideTabBar {
lastTime = current;
// Set a timer to delay dragging for 300 milliseconds
- this._longPressTimer = window.setTimeout(() => {
+ this._longPressTimer = setTimeout(() => {
this._activeTabItem?.enableFixed();
this._startAutoScroll();
if (!activeSlideItemElement) return;