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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(formula): redo delete sheet (#1035)
Univera7924bfd844e
diff --git a/packages/engine-formula/src/basics/common.ts b/packages/engine-formula/src/basics/common.tsindex 1d1ce0b9f9..370c00f0bd 100644--- a/packages/engine-formula/src/basics/common.ts+++ b/packages/engine-formula/src/basics/common.ts@@ -61,43 +61,43 @@ export interface IUnitData {}export interface IRuntimeUnitDataType {- [unitId: string]: { [sheetId: string]: ObjectMatrix<Nullable<ICellData>> };+ [unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix<Nullable<ICellData>> }>;}export interface IRuntimeOtherUnitDataType {- [unitId: string]: { [sheetId: string]: { [formulaId: string]: ICellData } };+ [unitId: string]: Nullable<{ [sheetId: string]: Nullable<{ [formulaId: string]: ICellData }> }>;}export interface IUnitSheetNameMap {- [unitId: string]: { [sheetName: string]: string };+ [unitId: string]: Nullable<{ [sheetName: string]: string }>;}export interface IDirtyUnitSheetNameMap {- [unitId: string]: { [sheetId: string]: Nullable<string> };+ [unitId: string]: Nullable<{ [sheetId: string]: Nullable<string> }>;}export interface IDirtyUnitFeatureMap {- [unitId: string]: { [sheetId: string]: { [featureId: string]: boolean } };+ [unitId: string]: Nullable<{ [sheetId: string]: { [featureId: string]: boolean } }>;}export interface IArrayFormulaRangeType {- [unitId: string]: { [sheetId: string]: IObjectMatrixPrimitiveType<IRange> };+ [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<IRange> }>;}export interface IFeatureDirtyRangeType {- [unitId: string]: { [sheetId: string]: IRange[] };+ [unitId: string]: Nullable<{ [sheetId: string]: IRange[] }>;}export interface IArrayFormulaUnitCellType {- [unitId: string]: { [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<ICellData>> };+ [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<ICellData>> }>;}export interface IFormulaData {- [unitId: string]: { [sheetId: string]: IObjectMatrixPrimitiveType<IFormulaDataItem> };+ [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<IFormulaDataItem> }>;}export interface IOtherFormulaData {- [unitId: string]: { [subUnitId: string]: { [formulaId: string]: IFormulaDataItem } };+ [unitId: string]: Nullable<{ [subUnitId: string]: Nullable<{ [formulaId: string]: IFormulaDataItem }> }>;}/**@@ -129,7 +129,7 @@ export enum TableOptionType {}export interface IUnitExcludedCell {- [unitId: string]: { [sheetId: string]: ObjectMatrix<boolean> };+ [unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix<boolean> }>;}export interface IFormulaDatasetConfig {diff --git a/packages/engine-formula/src/basics/runtime.ts b/packages/engine-formula/src/basics/runtime.tsindex 5f35ae4d43..e1ec434196 100644--- a/packages/engine-formula/src/basics/runtime.ts+++ b/packages/engine-formula/src/basics/runtime.ts@@ -23,6 +23,10 @@ export function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType) {Object.keys(unitData).forEach((unitId) => {const sheetData = unitData[unitId];+ if (sheetData == null) {+ return true;+ }+if (arrayFormulaCellData[unitId] == null) {arrayFormulaCellData[unitId] = {};}@@ -30,7 +34,7 @@ export function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType) {Object.keys(sheetData).forEach((sheetId) => {const cellData = sheetData[sheetId];- arrayFormulaCellData[unitId][sheetId] = new ObjectMatrix(cellData);+ arrayFormulaCellData[unitId]![sheetId] = new ObjectMatrix(cellData);});});diff --git a/packages/engine-formula/src/engine/dependency/formula-dependency.ts b/packages/engine-formula/src/engine/dependency/formula-dependency.tsindex 61eef32c3c..aae185846d 100644--- a/packages/engine-formula/src/engine/dependency/formula-dependency.ts+++ b/packages/engine-formula/src/engine/dependency/formula-dependency.ts@@ -150,6 +150,10 @@ export class FormulaDependencyGenerator extends Disposable {for (const unitId of formulaDataKeys) {const sheetData = formulaData[unitId];+ if (sheetData == null) {+ continue;+ }+const sheetDataKeys = Object.keys(sheetData);for (const sheetId of sheetDataKeys) {@@ -183,11 +187,19 @@ export class FormulaDependencyGenerator extends Disposable {for (const unitId of otherFormulaDataKeys) {const subComponentData = otherFormulaData[unitId];+ if (subComponentData == null) {+ continue;+ }+const subComponentKeys = Object.keys(subComponentData);for (const subUnitId of subComponentKeys) {const subFormulaData = subComponentData[subUnitId];+ if (subFormulaData == null) {+ continue;+ }+const subFormulaDataKeys = Object.keys(subFormulaData);for (const subFormulaDataId of subFormulaDataKeys) {@@ -518,12 +530,12 @@ export class FormulaDependencyGenerator extends Disposable {}/**- * When the name of a worksheet is changed, or a worksheet is inserted or deleted,- * the formulas within it may not need to be calculated.+ * When a worksheet is inserted or deleted,+ * the formulas within it need to be calculated.*/- // if (this._dirtyUnitSheetNameMap[unitId][subUnitId] != null) {- // return true;- // }+ if (this._dirtyUnitSheetNameMap[unitId]?.[subUnitId] != null) {+ return true;+ }if (!this._updateRangeFlattenCache.has(unitId)) {return false;diff --git a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts b/packages/engine-formula/src/engine/reference-object/base-reference-object.tsindex ac42c890eb..7646eac72a 100644--- a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts+++ b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts@@ -38,7 +38,7 @@ const FORMULA_CACHE_LRU_COUNT = 100000;export const FORMULA_REF_TO_ARRAY_CACHE = new FormulaAstLRU<ArrayValueObject>(FORMULA_CACHE_LRU_COUNT);export class BaseReferenceObject extends ObjectClassType {- private _forcedSheetId: string = '';+ private _forcedSheetId: Nullable<string> = '';private _forcedSheetName: string = '';diff --git a/packages/engine-formula/src/engine/reference-object/range-reference-object.ts b/packages/engine-formula/src/engine/reference-object/range-reference-object.tsindex 35eeb1300b..d792342b48 100644--- a/packages/engine-formula/src/engine/reference-object/range-reference-object.ts+++ b/packages/engine-formula/src/engine/reference-object/range-reference-object.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import type { IRange } from '@univerjs/core';+import type { IRange, Nullable } from '@univerjs/core';import { BaseReferenceObject } from './base-reference-object';export class RangeReferenceObject extends BaseReferenceObject {- constructor(range: IRange, forcedSheetId?: string, forcedUnitId?: string) {+ constructor(range: IRange, forcedSheetId?: Nullable<string>, forcedUnitId?: string) {super('');this.setRangeData(range);if (forcedSheetId) {diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.tsindex 68ed94da34..fdec60eb91 100644--- a/packages/engine-formula/src/models/formula-data.model.ts+++ b/packages/engine-formula/src/models/formula-data.model.ts@@ -52,9 +52,14 @@ export class FormulaDataModel extends Disposable {clearPreviousArrayFormulaCellData(clearArrayFormulaCellData: IRuntimeUnitDataType) {Object.keys(clearArrayFormulaCellData).forEach((unitId) => {- const sheetData = clearArrayFormulaCellData[unitId];- Object.keys(sheetData).forEach((sheetId) => {- const cellMatrixData = sheetData[sheetId];+ const clearSheetData = clearArrayFormulaCellData[unitId];++ if (clearSheetData == null) {+ return true;+ }++ Object.keys(clearSheetData).forEach((sheetId) => {+ const clearCellMatrixData = clearSheetData[sheetId];const rangeMatrix = this._arrayFormulaRange?.[unitId]?.[sheetId];if (rangeMatrix == null) {return true;@@ -62,13 +67,13 @@ export class FormulaDataModel extends Disposable {let arrayFormulaCellMatrixData = new ObjectMatrix<Nullable<ICellData>>(); // Original array formula cell data.- if (this._arrayFormulaCellData[unitId][sheetId] != null) {+ if (this._arrayFormulaCellData[unitId]?.[sheetId] != null) {arrayFormulaCellMatrixData = new ObjectMatrix<Nullable<ICellData>>(- this._arrayFormulaCellData[unitId][sheetId]+ this._arrayFormulaCellData[unitId]?.[sheetId]);}- cellMatrixData.forValue((row, column) => {+ clearCellMatrixData.forValue((row, column) => {const range = rangeMatrix?.[row]?.[column];if (range == null) {return true;@@ -81,7 +86,9 @@ export class FormulaDataModel extends Disposable {}});- this._arrayFormulaCellData[unitId][sheetId] = arrayFormulaCellMatrixData.getData();+ if (this._arrayFormulaCellData[unitId]) {+ this._arrayFormulaCellData[unitId]![sheetId] = arrayFormulaCellMatrixData.getData();+ }});});}@@ -89,6 +96,11 @@ export class FormulaDataModel extends Disposable {mergeArrayFormulaCellData(unitData: IRuntimeUnitDataType) {Object.keys(unitData).forEach((unitId) => {const sheetData = unitData[unitId];++ if (sheetData == null) {+ return true;+ }+if (this._arrayFormulaRange[unitId] == null) {this._arrayFormulaRange[unitId] = {};}@@ -104,13 +116,13 @@ export class FormulaDataModel extends Disposable {let arrayFormulaCellMatrixData = new ObjectMatrix<Nullable<ICellData>>(); // Original array formula cell data.- if (this._arrayFormulaRange[unitId][sheetId] != null) {- arrayFormulaRangeMatrix = new ObjectMatrix<IRange>(this._arrayFormulaRange[unitId][sheetId]);+ if (this._arrayFormulaRange[unitId]?.[sheetId] != null) {+ arrayFormulaRangeMatrix = new ObjectMatrix<IRange>(this._arrayFormulaRange[unitId]?.[sheetId]);}- if (this._arrayFormulaCellData[unitId][sheetId] != null) {+ if (this._arrayFormulaCellData[unitId]?.[sheetId] != null) {arrayFormulaCellMatrixData = new ObjectMatrix<Nullable<ICellData>>(- this._arrayFormulaCellData[unitId][sheetId]+ this._arrayFormulaCellData[unitId]?.[sheetId]);}@@ -134,7 +146,9 @@ export class FormulaDataModel extends Disposable {arrayFormulaCellMatrixData.setValue(row, column, cellData);});- this._arrayFormulaCellData[unitId][sheetId] = arrayFormulaCellMatrixData.getData();+ if (this._arrayFormulaCellData[unitId]) {+ this._arrayFormulaCellData[unitId]![sheetId] = arrayFormulaCellMatrixData.getData();+ }});});}@@ -167,6 +181,10 @@ export class FormulaDataModel extends Disposable {Object.keys(formulaData).forEach((unitId) => {const sheetData = formulaData[unitId];+ if (sheetData == null) {+ return true;+ }+if (!this._arrayFormulaRange[unitId]) {this._arrayFormulaRange[unitId] = {};}@@ -176,15 +194,17 @@ export class FormulaDataModel extends Disposable {let rangeMatrix = new ObjectMatrix<IRange>();- if (this._arrayFormulaRange[unitId][sheetId]) {- rangeMatrix = new ObjectMatrix(this._arrayFormulaRange[unitId][sheetId]);+ if (this._arrayFormulaRange[unitId]?.[sheetId]) {+ rangeMatrix = new ObjectMatrix(this._arrayFormulaRange[unitId]?.[sheetId]);}arrayFormula.forValue((r, c, v) => {rangeMatrix.setValue(r, c, v);});- this._arrayFormulaRange[unitId][sheetId] = rangeMatrix.getData();+ if (this._arrayFormulaRange[unitId]) {+ this._arrayFormulaRange[unitId]![sheetId] = rangeMatrix.getData();+ }});});}@@ -198,7 +218,9 @@ export class FormulaDataModel extends Disposable {if (rangeMatrixData.getValue(row, column)) {rangeMatrixData.realDeleteValue(row, column);- this._arrayFormulaRange[unitId][sheetId] = rangeMatrixData.getData();+ if (this._arrayFormulaRange[unitId]) {+ this._arrayFormulaRange[unitId]![sheetId] = rangeMatrixData.getData();+ }}}@@ -269,7 +291,7 @@ export class FormulaDataModel extends Disposable {if (formulaData[unitId] == null) {formulaData[unitId] = {};}- const workbookFormulaData = formulaData[unitId];+ const workbookFormulaData = formulaData[unitId]!;if (workbookFormulaData[sheetId] == null) {workbookFormulaData[sheetId] = {};@@ -360,7 +382,7 @@ export class FormulaDataModel extends Disposable {}const workbookFormulaData = formulaData[unitId];- if (workbookFormulaData[sheetId] == null) {+ if (workbookFormulaData?.[sheetId] == null) {return null;}@@ -393,7 +415,7 @@ export class FormulaDataModel extends Disposable {}const workbookFormulaData = formulaData[unitId];- if (workbookFormulaData[sheetId] == null) {+ if (workbookFormulaData?.[sheetId] == null) {return formulaIdMap;}@@ -463,5 +485,7 @@ export function initSheetFormulaData(}});- formulaData[unitId][sheetId] = sheetFormulaDataMatrix.getData();+ if (formulaData[unitId]) {+ formulaData[unitId]![sheetId] = sheetFormulaDataMatrix.getData();+ }}diff --git a/packages/engine-formula/src/services/calculate-formula.service.ts b/packages/engine-formula/src/services/calculate-formula.service.tsindex 3ce37921b7..4977c57eff 100644--- a/packages/engine-formula/src/services/calculate-formula.service.ts+++ b/packages/engine-formula/src/services/calculate-formula.service.ts@@ -164,6 +164,11 @@ export class CalculateFormulaService extends Disposable {const excludedCell: IUnitExcludedCell = {};Object.keys(arrayFormulaRange).forEach((unitId) => {const sheetArrayFormulaRange = arrayFormulaRange[unitId];++ if (sheetArrayFormulaRange == null) {+ return true;+ }+Object.keys(sheetArrayFormulaRange).forEach((sheetId) => {const cellValue = new ObjectMatrix(sheetArrayFormulaRange[sheetId]);@@ -183,7 +188,7 @@ export class CalculateFormulaService extends Disposable {excludedCell[unitId] = {};}- excludedCell[unitId][sheetId] = newCellData;+ excludedCell[unitId]![sheetId] = newCellData;});});@@ -191,6 +196,11 @@ export class CalculateFormulaService extends Disposable {const arrayRange = runtimeFeatureRange[featureId];Object.keys(arrayRange).forEach((unitId) => {const sheetArrayFormulaRange = arrayRange[unitId];++ if (sheetArrayFormulaRange == null) {+ return true;+ }+Object.keys(sheetArrayFormulaRange).forEach((sheetId) => {const ranges = sheetArrayFormulaRange[sheetId];diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.tsindex 028c342728..619df9db4a 100644--- a/packages/engine-formula/src/services/current-data.service.ts+++ b/packages/engine-formula/src/services/current-data.service.ts@@ -164,6 +164,11 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCthis._dirtyRanges = dirtyRanges;this._excludedCell = excludedCell;++ /**+ * Mark dirty for expansion of array formulas, need to clear the worksheet's dirty flag.+ */+ this._dirtyNameMap = {};}registerUnitData(unitData: IUnitData) {diff --git a/packages/engine-formula/src/services/other-formula-manager.service.ts b/packages/engine-formula/src/services/other-formula-manager.service.tsindex 30f9de000b..e6e66b193f 100644--- a/packages/engine-formula/src/services/other-formula-manager.service.ts+++ b/packages/engine-formula/src/services/other-formula-manager.service.ts@@ -78,11 +78,11 @@ export class OtherFormulaManagerService extends Disposable implements IOtherFormthis._otherFormulaData[unitId] = {};}- if (this._otherFormulaData[unitId][subUnitId]) {- this._otherFormulaData[unitId][subUnitId] = {};+ if (this._otherFormulaData[unitId]![subUnitId]) {+ this._otherFormulaData[unitId]![subUnitId] = {};}- this._otherFormulaData[unitId][subUnitId][formulaId] = item;+ this._otherFormulaData[unitId]![subUnitId]![formulaId] = item;}getOtherFormulaData() {diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.tsindex e86b932ef7..0146d09219 100644--- a/packages/engine-formula/src/services/runtime.service.ts+++ b/packages/engine-formula/src/services/runtime.service.ts@@ -353,7 +353,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._runtimeOtherData[unitId] = {};}- const unitData = this._runtimeOtherData[unitId];+ const unitData = this._runtimeOtherData[unitId]!;if (unitData[subUnitId] === undefined) {unitData[subUnitId] = {};@@ -361,7 +361,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeconst subComponentData = unitData[subUnitId];- subComponentData[formulaId] = this._objectValueToCellValue(functionVariant as BaseValueObject)!;+ subComponentData![formulaId] = this._objectValueToCellValue(functionVariant as BaseValueObject)!;}setRuntimeData(functionVariant: FunctionVariantType) {@@ -374,7 +374,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._runtimeData[unitId] = {};}- const unitData = this._runtimeData[unitId];+ const unitData = this._runtimeData[unitId]!;if (unitData[sheetId] == null) {unitData[sheetId] = new ObjectMatrix<Nullable<ICellData>>();@@ -384,11 +384,11 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._unitArrayFormulaRange[unitId] = {};}- const arrayFormulaRange = this._unitArrayFormulaRange[unitId];+ const arrayFormulaRange = this._unitArrayFormulaRange[unitId]!;let arrayData = new ObjectMatrix<IRange>();- if (!arrayFormulaRange[sheetId]) {+ if (arrayFormulaRange[sheetId]) {arrayData = new ObjectMatrix(arrayFormulaRange[sheetId]);}@@ -396,7 +396,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._runtimeArrayFormulaCellData[unitId] = {};}- const arrayFormulaCellData = this._runtimeArrayFormulaCellData[unitId];+ const arrayFormulaCellData = this._runtimeArrayFormulaCellData[unitId]!;if (arrayFormulaCellData[sheetId] == null) {arrayFormulaCellData[sheetId] = new ObjectMatrix<Nullable<ICellData>>();@@ -406,7 +406,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._runtimeClearArrayFormulaCellData[unitId] = {};}- const clearArrayFormulaCellData = this._runtimeClearArrayFormulaCellData[unitId];+ const clearArrayFormulaCellData = this._runtimeClearArrayFormulaCellData[unitId]!;if (clearArrayFormulaCellData[sheetId] == null) {clearArrayFormulaCellData[sheetId] = new ObjectMatrix<Nullable<ICellData>>();@@ -444,6 +444,10 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeendColumn: endColumn - startColumn + column,};+ arrayData.setValue(row, column, arrayRange);++ arrayFormulaRange[sheetId] = arrayData.getData();+if (this._checkIfArrayFormulaRangeHasData(unitId, sheetId, row, column, arrayRange)) {const errorObject = this._objectValueToCellValue(new ErrorValueObject(ErrorType.SPILL));sheetData.setValue(row, column, errorObject);@@ -466,10 +470,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime}arrayUnitData.setValue(rowIndex - startRow + row, columnIndex - startColumn + column, value);});-- arrayData.setValue(row, column, arrayRange);-- arrayFormulaRange[sheetId] = arrayData.getData();}} else {const valueObject = this._objectValueToCellValue(functionVariant as BaseValueObject);@@ -588,6 +588,9 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeconst unitData = this._currentConfigService.getUnitData();+ const unitArrayFormulaRange =+ this._unitArrayFormulaRange[formulaUnitId]?.[formulaSheetId]?.[formulaRow]?.[formulaColumn];+for (let r = startRow; r <= endRow; r++) {for (let c = startColumn; c <= endColumn; c++) {if (r === formulaRow && formulaColumn === c) {@@ -596,11 +599,16 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeconst cell = this._runtimeData?.[formulaUnitId]?.[formulaSheetId]?.getValue(r, c);+ const arrayDataCell = this._runtimeArrayFormulaCellData?.[formulaUnitId]?.[formulaSheetId]?.getValue(+ r,+ c+ );const currentCell = unitData?.[formulaUnitId]?.[formulaSheetId]?.cellData?.getValue(r, c);if (- (!isNullCell(cell) || !isNullCell(currentCell)) &&- this._isInDirtyRange(formulaUnitId, formulaSheetId, r, c)+ !isNullCell(cell) ||+ (!isNullCell(arrayDataCell) && !this._isInArrayFormulaRange(unitArrayFormulaRange, r, c)) ||+ !isNullCell(currentCell)) {return true;}@@ -610,8 +618,26 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimereturn false;}+ private _isInArrayFormulaRange(range: Nullable<IRange>, r: number, c: number) {+ if (range == null) {+ return false;+ }++ const { startRow, startColumn, endRow, endColumn } = range;++ if (r >= startRow && r <= endRow && c >= startColumn && c <= endColumn) {+ return true;+ }++ return false;+ }+private _isInDirtyRange(unitId: string, sheetId: string, row: number, column: number) {const dirtyRanges = this._currentConfigService.getDirtyRanges();+ // Handle the deletion and add of sheet.+ if (dirtyRanges.length === 0) {+ return true;+ }return isInDirtyRange(dirtyRanges, unitId, sheetId, row, column);}}diff --git a/packages/sheets-formula/src/controllers/active-dirty.controller.ts b/packages/sheets-formula/src/controllers/active-dirty.controller.tsindex c643a780a3..190bd8c5ea 100644--- a/packages/sheets-formula/src/controllers/active-dirty.controller.ts+++ b/packages/sheets-formula/src/controllers/active-dirty.controller.ts@@ -189,6 +189,9 @@ export class ActiveDirtyController extends Disposable {},});+ /**+ * Changing the name of a sheet triggers an adjustment of the formula references, but does not trigger formula calculation; therefore, this logic has been removed.+ */// this._activeDirtyManagerService.register(SetWorksheetNameMutation.id, {// commandId: SetWorksheetNameMutation.id,// getDirtyData: (command: ICommandInfo) => {@@ -349,12 +352,12 @@ export class ActiveDirtyController extends Disposable {dirtyNameMap[unitId] = {};}- dirtyNameMap[unitId][sheetId] = name;+ dirtyNameMap[unitId]![sheetId] = name;return dirtyNameMap;}- private _getInsertSheetMutation(params: IInsertSheetMutationParams, name?: Nullable<string>) {+ private _getInsertSheetMutation(params: IInsertSheetMutationParams, name: string = '') {const dirtyNameMap: IDirtyUnitSheetNameMap = {};const { sheet, unitId } = params;@@ -362,7 +365,7 @@ export class ActiveDirtyController extends Disposable {dirtyNameMap[unitId] = {};}- dirtyNameMap[unitId][sheet.id] = name;+ dirtyNameMap[unitId]![sheet.id] = name;return dirtyNameMap;}diff --git a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts b/packages/sheets-formula/src/controllers/formula-editor-show.controller.tsindex 3eeb04467a..0f3e2afd30 100644--- a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts@@ -251,7 +251,7 @@ export class FormulaEditorShowController extends Disposable {const { rowHeaderWidth, columnHeaderHeight } = skeleton;const control = new SelectionShape(scene, 100, false, this._themeService);control.update(rangeWithCoord, rowHeaderWidth, columnHeaderHeight, style, primaryWithCoord);-+ control.setEvent(false);this._previousShape = control;}diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.tsindex 60559f091f..79287ecae5 100644--- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts@@ -157,8 +157,9 @@ export class TriggerCalculationController extends Disposable {if (allDirtyNameMap[unitId] == null) {allDirtyNameMap[unitId] = {};}- Object.keys(dirtyNameMap[unitId]).forEach((sheetId) => {- allDirtyNameMap[unitId][sheetId] = dirtyNameMap[unitId][sheetId];++ Object.keys(dirtyNameMap[unitId]!).forEach((sheetId) => {+ allDirtyNameMap[unitId]![sheetId] = dirtyNameMap[unitId]?.[sheetId];});});}@@ -171,13 +172,13 @@ export class TriggerCalculationController extends Disposable {if (allDirtyUnitFeatureMap[unitId] == null) {allDirtyUnitFeatureMap[unitId] = {};}- Object.keys(dirtyUnitFeatureMap[unitId]).forEach((sheetId) => {- if (allDirtyUnitFeatureMap[unitId][sheetId] == null) {- allDirtyUnitFeatureMap[unitId][sheetId] = {};+ 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];+ Object.keys(dirtyUnitFeatureMap[unitId]![sheetId]).forEach((featureId) => {+ allDirtyUnitFeatureMap[unitId]![sheetId][featureId] =+ dirtyUnitFeatureMap[unitId]![sheetId]![featureId] || false;});});});diff --git a/packages/sheets-formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.tsindex 8e827e6235..7a9e8f1678 100644--- a/packages/sheets-formula/src/controllers/update-formula.controller.ts+++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts@@ -564,10 +564,17 @@ export class UpdateFormulaController extends Disposable {for (const unitId of formulaDataKeys) {const sheetData = formulaData[unitId];++ if (sheetData == null) {+ continue;+ }+const sheetDataKeys = Object.keys(sheetData);for (const subUnitId of sheetDataKeys) {- const oldFormulaMatrix = new ObjectMatrix<IFormulaDataItem>(oldFormulaData[unitId][subUnitId]);+ const value = oldFormulaData[unitId]?.[subUnitId];++ const oldFormulaMatrix = new ObjectMatrix<IFormulaDataItem>(value);const formulaMatrix = new ObjectMatrix<IFormulaDataItem>(sheetData[subUnitId]);const cellMatrix = new ObjectMatrix<ICellData>();@@ -632,6 +639,10 @@ export class UpdateFormulaController extends Disposable {for (const unitId of formulaDataKeys) {const sheetData = formulaData[unitId];+ if (sheetData == null) {+ continue;+ }+const sheetDataKeys = Object.keys(sheetData);if (newFormulaData[unitId] == null) {@@ -672,6 +683,10 @@ export class UpdateFormulaController extends Disposable {const sequenceSheetId = unitSheetNameMap?.[mapUnitId]?.[sheetName];+ if (sequenceSheetId == null) {+ continue;+ }+const sequenceUnitRangeWidthOffset = {range,sheetId: sequenceSheetId,@@ -739,7 +754,9 @@ export class UpdateFormulaController extends Disposable {});});- newFormulaData[unitId][sheetId] = newFormulaDataItem.getData();+ if (newFormulaData[unitId]) {+ newFormulaData[unitId]![sheetId] = newFormulaDataItem.getData();+ }}}diff --git a/packages/sheets-formula/src/controllers/utils.ts b/packages/sheets-formula/src/controllers/utils.tsindex fcc46182d9..c9766377f2 100644--- a/packages/sheets-formula/src/controllers/utils.ts+++ b/packages/sheets-formula/src/controllers/utils.ts@@ -47,7 +47,7 @@ import {} from '@univerjs/sheets';interface IFormulaDataGenerics<T> {- [unitId: string]: { [sheetId: string]: IObjectMatrixPrimitiveType<T> };+ [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<T> }>;}export function offsetFormula<T>(@@ -61,7 +61,7 @@ export function offsetFormula<T>(if (checkFormulaDataNull(formulaData, unitId, sheetId)) return formulaData;- const formulaMatrix = new ObjectMatrix(formulaData[unitId][sheetId]);+ const formulaMatrix = new ObjectMatrix(formulaData[unitId]?.[sheetId]);switch (id) {case MoveRangeCommand.id:@@ -288,12 +288,17 @@ function handleDeleteRangeMoveLeft<T>(export function offsetArrayFormula(arrayFormulaRange: IArrayFormulaRangeType, unitId: string, sheetId: string) {if (checkFormulaDataNull(arrayFormulaRange, unitId, sheetId)) return arrayFormulaRange;-- const arrayFormulaRangeMatrix = new ObjectMatrix(arrayFormulaRange[unitId][sheetId]);+ if (arrayFormulaRange[unitId]?.[sheetId] == null) {+ return arrayFormulaRange;+ }+ const arrayFormulaRangeMatrix = new ObjectMatrix(arrayFormulaRange[unitId]![sheetId]);arrayFormulaRangeMatrix.forValue((row, column, range) => {+ if (range == null) {+ return true;+ }const { startRow, startColumn, endRow, endColumn } = range;if (row === startRow && column === startColumn) {- return;+ return true;}const rows = endRow - startRow;@@ -313,7 +318,7 @@ export function offsetArrayFormula(arrayFormulaRange: IArrayFormulaRangeType, un}function checkFormulaDataNull<T>(formulaData: IFormulaDataGenerics<T>, unitId: string, sheetId: string) {- if (formulaData == null || formulaData[unitId] == null || formulaData[unitId][sheetId] == null) {+ if (formulaData == null || formulaData[unitId] == null || formulaData[unitId]?.[sheetId] == null) {return true;}@@ -321,7 +326,7 @@ function checkFormulaDataNull<T>(formulaData: IFormulaDataGenerics<T>, unitId: s}export function removeFormulaData<T>(formulaData: IFormulaDataGenerics<T>, unitId: string, sheetId: string) {- if (formulaData && formulaData[unitId] && formulaData[unitId][sheetId]) {- delete formulaData[unitId][sheetId];+ if (formulaData && formulaData[unitId] && formulaData[unitId]?.[sheetId]) {+ delete formulaData[unitId]![sheetId];}}diff --git a/packages/sheets-ui/src/services/selection/selection-shape.ts b/packages/sheets-ui/src/services/selection/selection-shape.tsindex 9236570aad..8a19e67d18 100644--- a/packages/sheets-ui/src/services/selection/selection-shape.ts+++ b/packages/sheets-ui/src/services/selection/selection-shape.ts@@ -229,6 +229,13 @@ export class SelectionShape {return this._isHelperSelection;}+ setEvent(state: boolean) {+ this.leftControl.evented = state;+ this.rightControl.evented = state;+ this.topControl.evented = state;+ this.bottomControl.evented = state;+ }+enableHeaderHighlight() {this._isHelperSelection = true;}diff --git a/packages/sheets/src/controllers/calculate-result-apply.controller.ts b/packages/sheets/src/controllers/calculate-result-apply.controller.tsindex 27c6752998..0d5475aad4 100644--- a/packages/sheets/src/controllers/calculate-result-apply.controller.ts+++ b/packages/sheets/src/controllers/calculate-result-apply.controller.ts@@ -52,6 +52,10 @@ export class CalculateResultApplyController extends Disposable {unitIds.forEach((unitId) => {const sheetData = unitData[unitId];+ if (sheetData == null) {+ return true;+ }+const sheetIds = Object.keys(sheetData);sheetIds.forEach((sheetId) => {