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.

chore(core): remove rangeData in setRangeData

Dushusirb46079dc0cd8
diff --git a/packages/core/src/Sheets/Action/ClearRangeAction.ts b/packages/core/src/Sheets/Action/ClearRangeAction.ts
index dbea311e47..55a07f27c7 100644
--- a/packages/core/src/Sheets/Action/ClearRangeAction.ts
+++ b/packages/core/src/Sheets/Action/ClearRangeAction.ts
@@ -71,7 +71,6 @@ export class ClearRangeAction extends SheetActionBase<
this._oldActionData = {
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
sheetId,
- rangeData,
cellValue: this.do(),
convertor: [new WorkSheetConvertor(CONVERTOR_OPERATION.INSERT)],
};
@@ -79,11 +78,11 @@ export class ClearRangeAction extends SheetActionBase<
undo(): void {
const worksheet = this.getWorkSheet();
- const { rangeData, cellValue } = this._oldActionData;
+ const { cellValue } = this._oldActionData;
const styles = this._workbook.getStyles();
if (worksheet) {
- SetRangeData(worksheet.getCellMatrix(), cellValue, rangeData, styles);
+ SetRangeData(worksheet.getCellMatrix(), cellValue, styles);
// no need update current data
this._observers.notifyObservers({
diff --git a/packages/core/src/Sheets/Action/SetRangeDataAction.ts b/packages/core/src/Sheets/Action/SetRangeDataAction.ts
index 4749436344..cb8df5c414 100644
--- a/packages/core/src/Sheets/Action/SetRangeDataAction.ts
+++ b/packages/core/src/Sheets/Action/SetRangeDataAction.ts
@@ -9,14 +9,13 @@ import {
ActionType,
CommandUnit,
} from '../../Command';
-import { ICopyToOptionsData, ICellData, IRangeData } from '../../Interfaces';
+import { ICopyToOptionsData, ICellData } from '../../Interfaces';
/**
* @internal
*/
export interface ISetRangeDataActionData extends ISheetActionData {
- cellValue: ObjectMatrixPrimitiveType<ICellData> | ICellData;
- rangeData: IRangeData;
+ cellValue: ObjectMatrixPrimitiveType<ICellData>;
options?: ICopyToOptionsData;
}
@@ -28,7 +27,7 @@ export interface ISetRangeDataActionData extends ISheetActionData {
export class SetRangeDataAction extends SheetActionBase<
ISetRangeDataActionData,
ISetRangeDataActionData,
- ObjectMatrixPrimitiveType<ICellData> | ICellData
+ ObjectMatrixPrimitiveType<ICellData>
> {
constructor(
actionData: ISetRangeDataActionData,
@@ -56,7 +55,6 @@ export class SetRangeDataAction extends SheetActionBase<
const result = SetRangeData(
worksheet.getCellMatrix(),
this._doActionData.cellValue,
- this._doActionData.rangeData,
styles,
this._doActionData.options
);
@@ -72,18 +70,17 @@ export class SetRangeDataAction extends SheetActionBase<
redo(): void {
// update pre data
- const { sheetId, rangeData, options } = this._doActionData;
+ const { sheetId, options } = this._doActionData;
this._oldActionData = {
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
sheetId,
cellValue: this.do(),
- rangeData,
options,
};
}
undo(): void {
- const { rangeData, sheetId, cellValue, options } = this._oldActionData;
+ const { sheetId, cellValue, options } = this._oldActionData;
const worksheet = this.getWorkSheet();
const styles = this._workbook.getStyles();
if (worksheet) {
@@ -94,10 +91,8 @@ export class SetRangeDataAction extends SheetActionBase<
cellValue: SetRangeData(
worksheet.getCellMatrix(),
cellValue,
- rangeData,
styles
),
- rangeData,
options,
};
diff --git a/packages/core/src/Sheets/Apply/SetRangeData.ts b/packages/core/src/Sheets/Apply/SetRangeData.ts
index 6f1deba0b2..64d6ac75c7 100644
--- a/packages/core/src/Sheets/Apply/SetRangeData.ts
+++ b/packages/core/src/Sheets/Apply/SetRangeData.ts
@@ -1,10 +1,5 @@
import { Styles } from '../Domain';
-import {
- ICellData,
- ICopyToOptionsData,
- IRangeData,
- IStyleData,
-} from '../../Interfaces';
+import { ICellData, ICopyToOptionsData, IStyleData } from '../../Interfaces';
import { Nullable, Tools } from '../../Shared';
import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';
import { mergeStyle, transformStyle } from './SetRangeStyle';
@@ -21,61 +16,46 @@ import { mergeStyle, transformStyle } from './SetRangeStyle';
*/
export function SetRangeData(
cellMatrix: ObjectMatrix<ICellData>,
- addMatrix: ObjectMatrixPrimitiveType<ICellData> | ICellData,
- rangeData: IRangeData,
+ addMatrix: ObjectMatrixPrimitiveType<ICellData>,
styles: Styles,
options?: ICopyToOptionsData
): ObjectMatrixPrimitiveType<ICellData> {
- let target;
- if (!isNaN(parseInt(Object.keys(addMatrix)[0]))) {
- target = new ObjectMatrix(addMatrix as ObjectMatrixPrimitiveType<ICellData>);
- }
- const result = new ObjectMatrix<ICellData>();
+ let target = new ObjectMatrix(addMatrix);
- const { startRow, endRow, startColumn, endColumn } = rangeData;
+ const result = new ObjectMatrix<ICellData>();
if (options) {
- for (let r = startRow; r <= endRow; r++) {
- for (let c = startColumn; c <= endColumn; c++) {
- const value: Nullable<ICellData> = target
- ? target.getValue(r, c)
- : addMatrix;
- const cell = cellMatrix.getValue(r, c);
- const newCell: ICellData = {};
-
- if (options.contentsOnly) {
- newCell.m = cell?.m;
- newCell.v = cell?.v;
- }
-
- if (options.formatOnly) {
- // newCell.f = cell?.f;
- newCell.v = cell?.v;
- newCell.m = cell?.m;
- }
-
- result.setValue(r, c, newCell || {});
-
- cellMatrix.setValue(r, c, value || {});
+ target.forValue((r, c, value) => {
+ const cell = cellMatrix.getValue(r, c);
+ const newCell: ICellData = {};
+
+ if (options.contentsOnly) {
+ newCell.m = cell?.m;
+ newCell.v = cell?.v;
}
- }
+
+ if (options.formatOnly) {
+ // newCell.f = cell?.f;
+ newCell.v = cell?.v;
+ newCell.m = cell?.m;
+ }
+
+ result.setValue(r, c, newCell || {});
+
+ cellMatrix.setValue(r, c, value || {});
+ });
+
return result.getData();
}
- for (let r = startRow; r <= endRow; r++) {
- for (let c = startColumn; c <= endColumn; c++) {
- const value: Nullable<ICellData> = target
- ? target.getValue(r, c)
- : addMatrix;
- const cell = cellMatrix.getValue(r, c) || {};
-
- // set null, clear cell
- if (!value) {
- cellMatrix.setValue(r, c, value);
- result.setValue(r, c, cell);
- continue;
- }
+ target.forValue((r, c, value) => {
+ const cell = cellMatrix.getValue(r, c) || {};
+ // set null, clear cell
+ if (!value) {
+ cellMatrix.setValue(r, c, value);
+ result.setValue(r, c, cell);
+ } else {
// update style
// use null to clear style
@@ -126,6 +106,6 @@ export function SetRangeData(
cellMatrix.setValue(r, c, cell);
}
- }
+ });
return result.getData();
}
diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.ts
index daae0cfb40..e993683d39 100644
--- a/packages/core/src/Sheets/Domain/Range.ts
+++ b/packages/core/src/Sheets/Domain/Range.ts
@@ -1787,7 +1787,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: matrix.getData(),
- rangeData: destination._rangeData,
};
const command = new Command(
{
@@ -2140,7 +2139,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: cellValue.getData(),
- rangeData: range,
};
const command = new Command(
{
@@ -2226,7 +2224,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: cellValue.getData(),
- rangeData: range,
options,
};
const command = new Command(
@@ -2249,7 +2246,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: cellValue.getData(),
- rangeData: range,
};
const command = new Command(
{
@@ -2462,12 +2458,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: targetMatrix.getData(),
- rangeData: {
- startRow: targetStartRow,
- endRow: targetStartRow + (endRow - startRow),
- startColumn: targetStartColumn,
- endColumn: targetStartColumn + (endColumn - startColumn),
- },
};
const command = new Command(
@@ -3276,12 +3266,15 @@ export class Range {
*/
setRangeData(value: ICellData): Range {
const { _rangeData, _context, _commandManager, _worksheet } = this;
-
+ const { startRow, startColumn } = _rangeData;
const setValue: ISetRangeDataActionData = {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
- cellValue: value,
- rangeData: _rangeData,
+ cellValue: {
+ [startRow]: {
+ [startColumn]: value,
+ },
+ },
};
const command = new Command(
{
@@ -3319,7 +3312,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: cellValue.getData(),
- rangeData: this._rangeData,
};
const command = new Command(
{
@@ -3333,7 +3325,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: values,
- rangeData: this._rangeData,
};
const command = new Command(
{
@@ -3698,7 +3689,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: newData,
- rangeData: _rangeData,
},
];
const command = new Command(
@@ -3898,7 +3888,6 @@ export class Range {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: cellValue.getData(),
- rangeData: _rangeData,
};
const command = new Command(
{
diff --git a/packages/core/src/Sheets/Domain/RangeList.ts b/packages/core/src/Sheets/Domain/RangeList.ts
index 4c64e0c84c..2d49087b91 100644
--- a/packages/core/src/Sheets/Domain/RangeList.ts
+++ b/packages/core/src/Sheets/Domain/RangeList.ts
@@ -127,7 +127,6 @@ export class RangeList {
sheetId: _worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
cellValue: cellValue.getData(),
- rangeData: range,
};
return setValue;
});
diff --git a/packages/core/test/Command/SetRangeDataAction.test.ts b/packages/core/test/Command/SetRangeDataAction.test.ts
index af744d949f..fc9f6c1a6a 100644
--- a/packages/core/test/Command/SetRangeDataAction.test.ts
+++ b/packages/core/test/Command/SetRangeDataAction.test.ts
@@ -45,7 +45,6 @@ test('Test SetRangeDataAction', () => {
actionName,
sheetId,
cellValue,
- rangeData,
};
const action = new SetRangeDataAction(configure, workbook, observers);
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
index 71e32f8862..3563dc31c6 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
@@ -104,19 +104,16 @@ export class FormulaActionExtension extends BaseActionExtension<ISetRangeDataAct
const action: ISetRangeDataActionData = {
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
sheetId,
- rangeData: {
- startColumn: c,
- endColumn: c,
- startRow: r,
- endRow: r,
+ cellValue: {
+ [r]: {
+ [c]: cellCalculate,
+ },
},
- cellValue: cellCalculate,
};
const setFormulaDataAction = {
actionName: PLUGIN_ACTION_NAMES.SET_FORMULA_RANGE_DATA_ACTION,
sheetId: this.actionData.sheetId,
- rangeData: this.actionData.rangeData,
formulaData,
};
const actionData = ActionOperation.make<ISetRangeDataActionData>(action).removeCollaboration().removeUndo().getAction();
diff --git a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
index 966009b64e..2a1bbb22f1 100644
--- a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
@@ -1,4 +1,4 @@
-import { ActionOperation, ACTION_NAMES, ISetRangeDataActionData, Command } from '@univer/core';
+import { ActionOperation, ACTION_NAMES, ISetRangeDataActionData, Command, ObjectMatrix, ICellData } from '@univer/core';
import { FormulaController } from './FormulaController';
export function firstLoader(formulaController: FormulaController) {
@@ -20,17 +20,11 @@ export function firstLoader(formulaController: FormulaController) {
for (let i = 0, len = sheetIds.length; i < len; i++) {
const sheetId = sheetIds[i];
- const cellData = sheetData[sheetId];
+ const cellData: ObjectMatrix<ICellData> = sheetData[sheetId];
cellData.forValue((row, column, mainCell) => {
const action = {
actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
sheetId,
- rangeData: {
- startColumn: column,
- endColumn: column,
- startRow: row,
- endRow: row,
- },
cellValue: {
[row]: {
[column]: mainCell,
diff --git a/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts b/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts
index c678e06496..49b927179a 100644
--- a/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts
+++ b/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts
@@ -42,7 +42,6 @@ export class NumfmtActionExtension extends BaseActionExtension<ISetRangeDataActi
const setNumfmtRangeDataAction = {
actionName: PLUGIN_ACTION_NAMES.SET_NUMFMT_RANGE_DATA_ACTION,
sheetId: this.actionData.sheetId,
- rangeData: this.actionData.rangeData,
cellValue: numfmtMatrix.toJSON(),
};
this.push(setNumfmtRangeDataAction);
diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts
index 320c0346d1..c4e4d86801 100644
--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts
+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts
@@ -57,7 +57,6 @@ export class NumfmtController {
const setRangeDataAction = {
sheetId: activeSheet.getSheetId(),
actionName: CORE_ACTION_NAME.SET_RANGE_DATA_ACTION,
- rangeData: range,
cellValue: matrix.getData(),
};
const newSetRangeDataAction = ActionOperation.make<ISetRangeDataActionData>(setRangeDataAction).removeExtension().getAction();