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(sheet): set range values mutation handle cell.t (#436)
Dushusirddde3ef5c8bb
diff --git a/packages/base-formula-engine/src/basics/function.ts b/packages/base-formula-engine/src/basics/function.tsindex d2de9bd6a3..196e8bbd15 100644--- a/packages/base-formula-engine/src/basics/function.ts+++ b/packages/base-formula-engine/src/basics/function.ts@@ -65,6 +65,11 @@ export interface IFunctionInfo {*/functionName: string;+ /**+ * Alias function name+ */+ aliasFunctionName?: string;+/*** Function type*/diff --git a/packages/base-sheets/src/basics/const/command-listener-const.ts b/packages/base-sheets/src/basics/const/command-listener-const.tsindex 11c0d8510f..5849927e6e 100644--- a/packages/base-sheets/src/basics/const/command-listener-const.ts+++ b/packages/base-sheets/src/basics/const/command-listener-const.ts@@ -1,7 +1,6 @@import { InsertColMutation, InsertRowMutation } from '../../commands/mutations/insert-row-col.mutation';import { MoveRowsMutation } from '../../commands/mutations/move-rows-cols.mutation';import { RemoveColMutation, RemoveRowMutation } from '../../commands/mutations/remove-row-col.mutation';-import { SetBorderStylesMutation } from '../../commands/mutations/set-border-styles.mutation';import { SetColHiddenMutation, SetColVisibleMutation } from '../../commands/mutations/set-col-visible.mutation';import { SetRangeValuesMutation } from '../../commands/mutations/set-range-values.mutation';import { SetRowHiddenMutation, SetRowVisibleMutation } from '../../commands/mutations/set-row-visible.mutation';@@ -30,4 +29,4 @@ export const COMMAND_LISTENER_SKELETON_CHANGE = [SetRowVisibleMutation.id,];-export const COMMAND_LISTENER_VALUE_CHANGE = [SetBorderStylesMutation.id, SetRangeValuesMutation.id];+export const COMMAND_LISTENER_VALUE_CHANGE = [SetRangeValuesMutation.id];diff --git a/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.tsindex 22fd1955a7..83268c1172 100644--- a/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts+++ b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts@@ -149,6 +149,7 @@ describe('Test clear selection content commands', () => {expect(await commandService.executeCommand(ClearSelectionFormatCommand.id)).toBeTruthy();expect(getValue()).toStrictEqual({v: 'A1',+ t: 0,});// undo@@ -160,6 +161,7 @@ describe('Test clear selection content commands', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();expect(getValue()).toStrictEqual({v: 'A1',+ t: 0,});});it('clear formats with merged cells', async () => {@@ -226,6 +228,7 @@ describe('Test clear selection content commands', () => {// clear formatsexpect(getValue()).toStrictEqual({v: 'A1',+ t: 0,});// remove mergeexpect(getMerge()).toStrictEqual([]);@@ -242,6 +245,7 @@ describe('Test clear selection content commands', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();expect(getValue()).toStrictEqual({v: 'A1',+ t: 0,});expect(getMerge()).toStrictEqual([]);});diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-border.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-border.command.spec.tsindex 5da141a988..1e8f6ac8d4 100644--- a/packages/base-sheets/src/commands/commands/__tests__/set-border.command.spec.ts+++ b/packages/base-sheets/src/commands/commands/__tests__/set-border.command.spec.ts@@ -11,10 +11,10 @@ import {import { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import { SetRangeValuesMutation } from '../../..';import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '../../../services/selection-manager.service';import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation';import { RemoveWorksheetMergeMutation } from '../../mutations/remove-worksheet-merge.mutation';-import { SetBorderStylesMutation } from '../../mutations/set-border-styles.mutation';import { AddWorksheetMergeAllCommand, AddWorksheetMergeCommand } from '../add-worksheet-merge.command';import { RemoveWorksheetMergeCommand } from '../remove-worksheet-merge.command';import {@@ -46,7 +46,7 @@ describe('Test style commands', () => {RemoveWorksheetMergeCommand,AddWorksheetMergeMutation,RemoveWorksheetMergeMutation,- SetBorderStylesMutation,+ SetRangeValuesMutation,].forEach((c) => commandService.registerCommand(c));});diff --git a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-all.command.tsindex f0a81066cf..69f627620c 100644--- a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts+++ b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts@@ -56,7 +56,6 @@ export const ClearSelectionAllCommand: ICommand = {// clear style and contentconst clearMutationParams: ISetRangeValuesMutationParams = {- range: selections,worksheetId,workbookId,cellValue: generateNullCellValue(selections),diff --git a/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-content.command.tsindex b101d572da..19653b6138 100644--- a/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts+++ b/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts@@ -40,7 +40,6 @@ export const ClearSelectionContentCommand: ICommand = {}const clearMutationParams: ISetRangeValuesMutationParams = {- range: selections,worksheetId,workbookId,cellValue: generateNullCellValue(selections),diff --git a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-format.command.tsindex 107e541677..1dfe507828 100644--- a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts+++ b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts@@ -56,7 +56,6 @@ export const ClearSelectionFormatCommand: ICommand = {// clear styleconst clearMutationParams: ISetRangeValuesMutationParams = {- range: selections,worksheetId,workbookId,cellValue: generateNullCellValue(selections),diff --git a/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts b/packages/base-sheets/src/commands/commands/copy-format-to-range.command.tsdeleted file mode 100644index d69710b652..0000000000--- a/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts+++ /dev/null@@ -1,155 +0,0 @@-import {- CommandType,- ICellData,- ICellDataMatrix,- ICommand,- ICommandService,- IRange,- IStyleData,- IUndoRedoService,- IUniverInstanceService,- Nullable,- ObjectMatrix,-} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--import { SelectionManagerService } from '../../services/selection-manager.service';-import {- ISetRangeStyleMutationParams,- SetRangeStyleMutation,- SetRangeStyleUndoMutationFactory,-} from '../mutations/set-range-styles.mutation';--export interface ICopyFormatToRangeCommandParams {- destinationRange: IRange;-}--export const CopyFormatToRangeCommand: ICommand = {- type: CommandType.COMMAND,- id: 'sheet.command.copy-format-to-range',- handler: async (accessor: IAccessor, params: ICopyFormatToRangeCommandParams) => {- const selectionManagerService = accessor.get(SelectionManagerService);- const commandService = accessor.get(ICommandService);- const undoRedoService = accessor.get(IUndoRedoService);- const univerInstanceService = accessor.get(IUniverInstanceService);-- const selections = selectionManagerService.getSelectionRanges();- if (!selections?.length) return false;- const originRange = selections[0];-- const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const worksheetId = univerInstanceService- .getCurrentUniverSheetInstance()-- .getActiveSheet()- .getSheetId();- const workbook = univerInstanceService.getUniverSheetInstance(workbookId);- if (!workbook) return false;- const handleResult = handleCopyRange(accessor, workbookId, worksheetId, originRange, params.destinationRange);- if (!handleResult) return false;- const value = handleResult[0];- const range = handleResult[1];- const styles = workbook.getStyles();- const stylesMatrix = new ObjectMatrix<IStyleData>();- value.map((row, r) =>- row.map((cell, c) => {- cell = cell as ICellData;- stylesMatrix.setValue(r, c, styles.getStyleByCell(cell) || {});- return styles.getStyleByCell(cell) || {};- })- );-- const setRangeStyleMutationParams: ISetRangeStyleMutationParams = {- range: [range],- worksheetId,- workbookId,- value: stylesMatrix.getData(),- };-- const undoMutationParams: ISetRangeStyleMutationParams = SetRangeStyleUndoMutationFactory(- accessor,- setRangeStyleMutationParams- );- const result = commandService.syncExecuteCommand(SetRangeStyleMutation.id, setRangeStyleMutationParams);- if (result) {- undoRedoService.pushUndoRedo({- unitID: workbookId,- undoMutations: [{ id: SetRangeStyleMutation.id, params: undoMutationParams }],- redoMutations: [{ id: SetRangeStyleMutation.id, params: setRangeStyleMutationParams }],- });- return true;- }- return false;- },-};--function handleCopyRange(- accessor: IAccessor,- workbookId: string,- worksheetId: string,- originRange: IRange,- destinationRange: IRange-): Nullable<[ICellDataMatrix, IRange]> {- const worksheet = accessor- .get(IUniverInstanceService)- .getUniverSheetInstance(workbookId)- ?.getSheetBySheetId(worksheetId);- if (!worksheet) return;-- const sheetMatrix = worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- const { startRow, endRow, startColumn, endColumn } = originRange;- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || null);- }- }-- const cellData = worksheet.getCellMatrix();- // eslint-disable-next-line prefer-const- let { startRow: dStartRow, endRow: dEndRow, startColumn: dStartColumn, endColumn: dEndColumn } = destinationRange;-- const originRows = endRow - startRow + 1;- const originColumns = endColumn - startColumn + 1;- const destinationRows = dEndRow - dStartRow + 1;- const destinationColumns = dEndColumn - dStartColumn + 1;-- let value: ICellDataMatrix = [];- let range: IRange;-- // judge whether N2 is a multiple of N1- if (destinationRows % originRows === 0 && destinationColumns % originColumns === 0) {- /**- * A1,B1 => A1,B1,C1,D1- * A2,B2 A2,B2,C2,D2- * A3,B3,C3,D3- * A4,B4,C4,D4- */- for (let r = 0; r < destinationRows; r++) {- const row = [];- for (let c = 0; c < destinationColumns; c++) {- // Retrieve the corresponding cell data from the original range, {} as a fallback- const cell = cellData.getValue((r + startRow) % originRows, (c + startColumn) % originColumns) || {};- row.push(cell);- }- value.push(row);- }- range = destinationRange;- } else {- value = cellData.getFragments(startRow, endRow, startColumn, endColumn).getData() as ICellDataMatrix;-- // Extend the destination to the same size as the original range- dEndRow += originRows - destinationRows;- dEndColumn += originColumns - destinationColumns;-- range = {- startRow: dStartRow,- endRow: dEndRow,- startColumn: dStartColumn,- endColumn: dEndColumn,- };- }-- return [value, range];-}diff --git a/packages/base-sheets/src/commands/commands/copy-range-to.command.ts b/packages/base-sheets/src/commands/commands/copy-range-to.command.tsdeleted file mode 100644index ad8544befa..0000000000--- a/packages/base-sheets/src/commands/commands/copy-range-to.command.ts+++ /dev/null@@ -1,197 +0,0 @@-import {- CommandType,- ICellData,- ICellDataMatrix,- ICommand,- ICommandService,- IOptionData,- IRange,- IUndoRedoService,- IUniverInstanceService,- Nullable,- ObjectMatrix,-} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--import { SelectionManagerService } from '../../services/selection-manager.service';-import {- ISetRangeValuesMutationParams,- SetRangeValuesMutation,- SetRangeValuesUndoMutationFactory,-} from '../mutations/set-range-values.mutation';--export interface ICopyRangeToCommandParams {- destinationRange: IRange;- options?: IOptionData;-}--export const CopyRangeToCommand: ICommand = {- type: CommandType.COMMAND,- id: 'sheet.command.copy-range-to',- handler: async (accessor: IAccessor, params: ICopyRangeToCommandParams) => {- const selectionManagerService = accessor.get(SelectionManagerService);- const commandService = accessor.get(ICommandService);- const undoRedoService = accessor.get(IUndoRedoService);- const univerInstanceService = accessor.get(IUniverInstanceService);-- const selections = selectionManagerService.getSelectionRanges();- if (!selections?.length) return false;- const originRange = selections[0];- const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const worksheetId = univerInstanceService- .getCurrentUniverSheetInstance()-- .getActiveSheet()- .getSheetId();- const workbook = univerInstanceService.getUniverSheetInstance(workbookId);- if (!workbook) return false;- const handleResult = handleCopyRange(accessor, workbookId, worksheetId, originRange, params.destinationRange);- if (!handleResult) return false;- const value = handleResult[0];- const range = handleResult[1];- const options = params.options ?? {};- const cellValue = new ObjectMatrix<ICellData>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(r + range.startRow, c + range.startColumn, cell || {});- })- );-- const setRangeValuesMutationParams: ISetRangeValuesMutationParams = {- range: [range],- worksheetId,- workbookId,- cellValue: cellValue.getData(),- options,- };-- const undoMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(- accessor,- setRangeValuesMutationParams- );- const result = commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);- if (result) {- undoRedoService.pushUndoRedo({- unitID: workbookId,- undoMutations: [{ id: SetRangeValuesMutation.id, params: undoMutationParams }],- redoMutations: [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }],- });- return true;- }- return false;- },-};--/**- * en:- *- * The process of copying a range to another range is obtained by the following rules- *- * [The two-dimensional array composed of the content or format to be assigned] => [Target range]- *- * 1. 1 -> 1: 1 => 1- * 2. N -> 1: N => N- * 3. 1 -> N: N => N- * 4. N1 -> N2:- * 1) N1 <N2: If N2 is a multiple of N1 (X), N1 * X => N2; If not, N1 => N1 (refer to office excel, different from google sheet)- * 2) N1> N2: N1 => N1- *- * The above four cases can be combined and processed as- *- * Case 1, 1/2/4-2 merged into N1 => N1- * Case 2, 3/4-1 merge into N1 * X => N2 or Case 1- *- * In the end we only need to judge whether N2 is a multiple of N1- *- * zh:- *- * 处理复制一个范围到另一个范围,由以下规则得到- *- * [将要赋值的内容或者格式组成的二维数组] => [目标范围]- *- * 1. 1 -> 1 : 1 => 1- * 2. N -> 1 : N => N- * 3. 1 -> N : N => N- * 4. N1 -> N2 :- * 1) N1 < N2 : 如果N2是N1的倍数X, N1 * X => N2; 如果不是,N1 => N1(参考office excel,和google sheet不同)- * 2) N1 > N2 : N1 => N1- *- * 上面四种情况,可以合并处理为- * 情况一, 1/2/4-2合并为 N1 => N1- * 情况二, 3/4-1合并为 N1 * X => N2 或者情况一- *- * 最终我们只需要判断N2是否是N1的倍数- *- */--function handleCopyRange(- accessor: IAccessor,- workbookId: string,- worksheetId: string,- originRange: IRange,- destinationRange: IRange-): Nullable<[ICellDataMatrix, IRange]> {- const worksheet = accessor- .get(IUniverInstanceService)- .getUniverSheetInstance(workbookId)- ?.getSheetBySheetId(worksheetId);- if (!worksheet) return;-- const sheetMatrix = worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- const { startRow, endRow, startColumn, endColumn } = originRange;- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || null);- }- }-- const cellData = worksheet.getCellMatrix();- // eslint-disable-next-line prefer-const- let { startRow: dStartRow, endRow: dEndRow, startColumn: dStartColumn, endColumn: dEndColumn } = destinationRange;-- const originRows = endRow - startRow + 1;- const originColumns = endColumn - startColumn + 1;- const destinationRows = dEndRow - dStartRow + 1;- const destinationColumns = dEndColumn - dStartColumn + 1;-- let value: ICellDataMatrix = [];- let range: IRange;-- // judge whether N2 is a multiple of N1- if (destinationRows % originRows === 0 && destinationColumns % originColumns === 0) {- /**- * A1,B1 => A1,B1,C1,D1- * A2,B2 A2,B2,C2,D2- * A3,B3,C3,D3- * A4,B4,C4,D4- */- for (let r = 0; r < destinationRows; r++) {- const row = [];- for (let c = 0; c < destinationColumns; c++) {- // Retrieve the corresponding cell data from the original range, {} as a fallback- const cell = cellData.getValue((r + startRow) % originRows, (c + startColumn) % originColumns) || {};- row.push(cell);- }- value.push(row);- }- range = destinationRange;- } else {- value = cellData.getFragments(startRow, endRow, startColumn, endColumn).getData() as ICellDataMatrix;-- // Extend the destination to the same size as the original range- dEndRow += originRows - destinationRows;- dEndColumn += originColumns - destinationColumns;-- range = {- startRow: dStartRow,- endRow: dEndRow,- startColumn: dStartColumn,- endColumn: dEndColumn,- };- }-- return [value, range];-}diff --git a/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts b/packages/base-sheets/src/commands/commands/copy-values-to-range.command.tsdeleted file mode 100644index 617ed67448..0000000000--- a/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts+++ /dev/null@@ -1,157 +0,0 @@-import {- CommandType,- ICellData,- ICellDataMatrix,- ICellV,- ICommand,- ICommandService,- IRange,- IUndoRedoService,- IUniverInstanceService,- Nullable,- ObjectMatrix,-} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--import { SelectionManagerService } from '../../services/selection-manager.service';-import {- ISetRangeFormattedValueMutationParams,- SetRangeFormattedValueMutation,- SetRangeFormattedValueUndoMutationFactory,-} from '../mutations/set-range-formatted-value.mutation';--export interface ICopyValuesToRangeCommandParams {- destinationRange: IRange;-}--export const CopyValuesToRangeCommand: ICommand = {- type: CommandType.COMMAND,- id: 'sheet.command.copy-values-to-range',- handler: async (accessor: IAccessor, params: ICopyValuesToRangeCommandParams) => {- const selectionManagerService = accessor.get(SelectionManagerService);- const commandService = accessor.get(ICommandService);- const undoRedoService = accessor.get(IUndoRedoService);- const univerInstanceService = accessor.get(IUniverInstanceService);-- const selections = selectionManagerService.getSelectionRanges();- if (!selections?.length) return false;- const originRange = selections[0];- const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const worksheetId = univerInstanceService- .getCurrentUniverSheetInstance()-- .getActiveSheet()- .getSheetId();- const workbook = univerInstanceService.getUniverSheetInstance(workbookId);- if (!workbook) return false;- const handleResult = handleCopyRange(accessor, workbookId, worksheetId, originRange, params.destinationRange);- if (!handleResult) return false;- const value = handleResult[0];- const range = handleResult[1];- const cellValue = new ObjectMatrix<ICellV>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(r + range.startRow, c + range.startColumn, cell?.v || '');- })- );-- const setRangeFormattedValueMutationParams: ISetRangeFormattedValueMutationParams = {- range: [range],- worksheetId,- workbookId,- value: cellValue.getData(),- };-- const undoMutationParams: ISetRangeFormattedValueMutationParams = SetRangeFormattedValueUndoMutationFactory(- accessor,- setRangeFormattedValueMutationParams- );- const result = commandService.syncExecuteCommand(- SetRangeFormattedValueMutation.id,- setRangeFormattedValueMutationParams- );- if (result) {- undoRedoService.pushUndoRedo({- unitID: workbookId,- undoMutations: [{ id: SetRangeFormattedValueMutation.id, params: undoMutationParams }],- redoMutations: [- { id: SetRangeFormattedValueMutation.id, params: setRangeFormattedValueMutationParams },- ],- });- return true;- }- return false;- },-};--function handleCopyRange(- accessor: IAccessor,- workbookId: string,- worksheetId: string,- originRange: IRange,- destinationRange: IRange-): Nullable<[ICellDataMatrix, IRange]> {- const worksheet = accessor- .get(IUniverInstanceService)- .getUniverSheetInstance(workbookId)- ?.getSheetBySheetId(worksheetId);- if (!worksheet) return;-- const sheetMatrix = worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- const { startRow, endRow, startColumn, endColumn } = originRange;- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || null);- }- }-- const cellData = worksheet.getCellMatrix();- // eslint-disable-next-line prefer-const- let { startRow: dStartRow, endRow: dEndRow, startColumn: dStartColumn, endColumn: dEndColumn } = destinationRange;-- const originRows = endRow - startRow + 1;- const originColumns = endColumn - startColumn + 1;- const destinationRows = dEndRow - dStartRow + 1;- const destinationColumns = dEndColumn - dStartColumn + 1;-- let value: ICellDataMatrix = [];- let range: IRange;-- // judge whether N2 is a multiple of N1- if (destinationRows % originRows === 0 && destinationColumns % originColumns === 0) {- /**- * A1,B1 => A1,B1,C1,D1- * A2,B2 A2,B2,C2,D2- * A3,B3,C3,D3- * A4,B4,C4,D4- */- for (let r = 0; r < destinationRows; r++) {- const row = [];- for (let c = 0; c < destinationColumns; c++) {- // Retrieve the corresponding cell data from the original range, {} as a fallback- const cell = cellData.getValue((r + startRow) % originRows, (c + startColumn) % originColumns) || {};- row.push(cell);- }- value.push(row);- }- range = destinationRange;- } else {- value = cellData.getFragments(startRow, endRow, startColumn, endColumn).getData() as ICellDataMatrix;-- // Extend the destination to the same size as the original range- dEndRow += originRows - destinationRows;- dEndColumn += originColumns - destinationColumns;-- range = {- startRow: dStartRow,- endRow: dEndRow,- startColumn: dStartColumn,- endColumn: dEndColumn,- };- }-- return [value, range];-}diff --git a/packages/base-sheets/src/commands/commands/set-border-command.ts b/packages/base-sheets/src/commands/commands/set-border-command.tsindex d5405239ae..a9badbaea5 100644--- a/packages/base-sheets/src/commands/commands/set-border-command.ts+++ b/packages/base-sheets/src/commands/commands/set-border-command.ts@@ -4,6 +4,7 @@ import {CommandType,IBorderData,IBorderStyleData,+ ICellData,ICommand,ICommandService,IRange,@@ -19,10 +20,10 @@ import { IAccessor } from '@wendellhu/redi';import { BorderStyleManagerService } from '../../services/border-style-manager.service';import { SelectionManagerService } from '../../services/selection-manager.service';import {- ISetBorderStylesMutationParams,- SetBorderStylesMutation,- SetBorderStylesUndoMutationFactory,-} from '../mutations/set-border-styles.mutation';+ ISetRangeValuesMutationParams,+ SetRangeValuesMutation,+ SetRangeValuesUndoMutationFactory,+} from '../mutations/set-range-values.mutation';function forEach(range: IRange, action: (row: number, column: number) => void): void {const { startRow, startColumn, endRow, endColumn } = range;@@ -171,7 +172,7 @@ export const SetBorderCommand: ICommand = {endColumn: range.endColumn,};- const mr = new ObjectMatrix<IStyleData>();+ const mr = new ObjectMatrix<ICellData>();const border: IBorderStyleData = {s: style,@@ -206,18 +207,20 @@ export const SetBorderCommand: ICommand = {if (rectangle) {if (reserve) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;bdStyle = style?.bd ? Object.assign(style.bd, defaultStyle) : defaultStyle;}mr.setValue(rectangle.startRow, rectangle.startColumn, {- bd: bdStyle,+ s: {+ bd: bdStyle,+ },});} else {if (reserve) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;bdStyle = style?.bd ? Object.assign(style.bd, defaultStyle) : defaultStyle;}- mr.setValue(row, column, { bd: bdStyle });+ mr.setValue(row, column, { s: { bd: bdStyle } });}});}@@ -244,20 +247,24 @@ export const SetBorderCommand: ICommand = {const rectangle = hasMerge(row, column);if (rectangle) {if (rectangle.endColumn !== range.endColumn) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd- ? Object.assign(style.bd, { r: Tools.deepClone(border) })- : { r: Tools.deepClone(border) },+ s: {+ bd: style?.bd+ ? Object.assign(style.bd, { r: Tools.deepClone(border) })+ : { r: Tools.deepClone(border) },+ },});}} else {if (column !== range.endColumn) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd- ? Object.assign(style.bd, { r: Tools.deepClone(border) })- : { r: Tools.deepClone(border) },+ s: {+ bd: style?.bd+ ? Object.assign(style.bd, { r: Tools.deepClone(border) })+ : { r: Tools.deepClone(border) },+ },});}}@@ -269,20 +276,24 @@ export const SetBorderCommand: ICommand = {const rectangle = hasMerge(row, column);if (rectangle) {if (rectangle.endRow !== range.endRow) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd- ? Object.assign(style.bd, { b: Tools.deepClone(border) })- : { b: Tools.deepClone(border) },+ s: {+ bd: style?.bd+ ? Object.assign(style.bd, { b: Tools.deepClone(border) })+ : { b: Tools.deepClone(border) },+ },});}} else {if (row !== range.endRow) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd- ? Object.assign(style.bd, { b: Tools.deepClone(border) })- : { b: Tools.deepClone(border) },+ s: {+ bd: style?.bd+ ? Object.assign(style.bd, { b: Tools.deepClone(border) })+ : { b: Tools.deepClone(border) },+ },});}}@@ -304,83 +315,99 @@ export const SetBorderCommand: ICommand = {if (rectangle) {// Clear the right border of all columns except the last columnif (rectangle.endColumn !== range.endColumn) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { r: null }) : { r: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { r: null }) : { r: null },+ },});}// Clear the left border of all columns except the first columnif (rectangle.startColumn !== range.startColumn) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { l: null }) : { l: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { l: null }) : { l: null },+ },});}// Clear all the bottom border except the last lineif (rectangle.endRow !== range.endRow) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { b: null }) : { b: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { b: null }) : { b: null },+ },});}// Clear the top border of all lines except the first lineif (rectangle.startRow !== range.startRow) {- const style = mr.getValue(rectangle.startRow, rectangle.startColumn);+ const style = mr.getValue(rectangle.startRow, rectangle.startColumn)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { t: null }) : { t: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { t: null }) : { t: null },+ },});}} else {// Clear the right border of all columns except the last columnif (column !== range.endColumn) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { r: null }) : { r: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { r: null }) : { r: null },+ },});}// Clear the left border of all columns except the first columnif (column !== range.startColumn) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { l: null }) : { l: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { l: null }) : { l: null },+ },});}// Clear all the bottom border except the last lineif (row !== range.endRow) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { b: null }) : { b: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { b: null }) : { b: null },+ },});}// Clear the top border of all lines except the first lineif (row !== range.startRow) {- const style = mr.getValue(row, column);+ const style = mr.getValue(row, column)?.s as IStyleData;mr.setValue(row, column, {- bd: style?.bd ? Object.assign(style.bd, { t: null }) : { t: null },+ s: {+ bd: style?.bd ? Object.assign(style.bd, { t: null }) : { t: null },+ },});}}});}- const setBorderStylesMutationParams: ISetBorderStylesMutationParams = {+ const setRangeValuesMutationParams: ISetRangeValuesMutationParams = {workbookId,worksheetId,- value: mr.getData(),+ cellValue: mr.getData(),};- const undoSetBorderStylesMutationParams: ISetBorderStylesMutationParams = SetBorderStylesUndoMutationFactory(+ const undoSetRangeValuesMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor,- setBorderStylesMutationParams+ setRangeValuesMutationParams);// execute do mutations and add undo mutations to undo stack if completed- const result = commandService.syncExecuteCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);+ const result = commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);if (result) {undoRedoService.pushUndoRedo({unitID: workbookId,- undoMutations: [{ id: SetBorderStylesMutation.id, params: undoSetBorderStylesMutationParams }],- redoMutations: [{ id: SetBorderStylesMutation.id, params: setBorderStylesMutationParams }],+ undoMutations: [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }],+ redoMutations: [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }],});return true;diff --git a/packages/base-sheets/src/commands/commands/set-border-styles-command.ts b/packages/base-sheets/src/commands/commands/set-border-styles-command.tsdeleted file mode 100644index ebafbd41a5..0000000000--- a/packages/base-sheets/src/commands/commands/set-border-styles-command.ts+++ /dev/null@@ -1,496 +0,0 @@-import {- BorderStyleTypes,- BorderType,- CommandType,- IBorderStyleData,- ICommand,- ICommandService,- IRange,- IStyleData,- IUndoRedoService,- IUniverInstanceService,- Nullable,- ObjectMatrix,- Tools,-} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--import { BorderStyleManagerService } from '../../services/border-style-manager.service';-import { SelectionManagerService } from '../../services/selection-manager.service';-import {- ISetBorderStylesMutationParams,- SetBorderStylesMutation,- SetBorderStylesUndoMutationFactory,-} from '../mutations/set-border-styles.mutation';--export interface ISetBorderCommandParams {- workbookId?: string;- worksheetId?: string;- range?: IRange;- top?: Nullable<boolean>;- left?: Nullable<boolean>;- bottom?: Nullable<boolean>;- right?: Nullable<boolean>;- vertical?: Nullable<boolean>;- horizontal?: Nullable<boolean>;- color?: string;- style?: BorderStyleTypes;-}--function forEach(range: IRange, action: (row: number, column: number) => void): void {- const { startRow, startColumn, endRow, endColumn } = range;- for (let i = startRow; i <= endRow; i++) {- for (let j = startColumn; j <= endColumn; j++) {- action(i, j);- }- }-}--/**- * The command to clear content in current selected ranges.- */-export const SetBorderCommand: ICommand = {- id: 'sheet.command.set-border',- type: CommandType.COMMAND,- // eslint-disable-next-line max-lines-per-function- handler: async (accessor: IAccessor, params: ISetBorderCommandParams) => {- const commandService = accessor.get(ICommandService);- const undoRedoService = accessor.get(IUndoRedoService);- const univerInstanceService = accessor.get(IUniverInstanceService);- const selectionManagerService = accessor.get(SelectionManagerService);-- const range = params.range || selectionManagerService.getSelectionRanges()?.[0];- if (!range) {- return false;- }-- const {- top = null,- left = null,- bottom = null,- right = null,- vertical = null,- horizontal = null,- color = 'black',- style = BorderStyleTypes.DASH_DOT,- } = params;-- const workbookId = params.workbookId || univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const worksheetId =- params.worksheetId || univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();-- const workbook = univerInstanceService.getUniverSheetInstance(workbookId);- if (!workbook) return false;- const worksheet = workbook.getSheetBySheetId(worksheetId);- if (!worksheet) return false;- const sheetMatrix = worksheet.getCellMatrix();- const styles = workbook.getStyles();-- // Cells in the surrounding range may need to clear the border- const topRangeOut = {- startRow: range.startRow - 1,- startColumn: range.startColumn,- endRow: range.startRow - 1,- endColumn: range.endColumn,- };-- const leftRangeOut = {- startRow: range.startRow,- startColumn: range.startColumn - 1,- endRow: range.endRow,- endColumn: range.startColumn - 1,- };-- const bottomRangeOut = {- startRow: range.endRow + 1,- startColumn: range.startColumn,- endRow: range.endRow + 1,- endColumn: range.endColumn,- };-- const rightRangeOut = {- startRow: range.startRow,- startColumn: range.endColumn + 1,- endRow: range.endRow,- endColumn: range.endColumn + 1,- };-- // Cells in the upper, lower, left and right ranges- const topRange = {- startRow: range.startRow,- startColumn: range.startColumn,- endRow: range.startRow,- endColumn: range.endColumn,- };-- const leftRange = {- startRow: range.startRow,- startColumn: range.startColumn,- endRow: range.endRow,- endColumn: range.startColumn,- };-- const bottomRange = {- startRow: range.endRow,- startColumn: range.startColumn,- endRow: range.endRow,- endColumn: range.endColumn,- };-- const rightRange = {- startRow: range.startRow,- startColumn: range.endColumn,- endRow: range.endRow,- endColumn: range.endColumn,- };-- const mr = new ObjectMatrix<IStyleData>();-- const border: IBorderStyleData = {- s: style,- cl: {- rgb: color,- },- };-- if (top === true || top === false || top === null) {- // Probably to the border, there are no surrounding cells- // Clear the bottom border of the top range- forEach(topRangeOut, (row, column) => {- mr.setValue(row, column, { bd: { b: null } });- });-- // first row- forEach(topRange, (row, column) => {- // update- if (top === true) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { t: Tools.deepClone(border) },- }- );- mr.setValue(row, column, style);- }- // delete- else if (top === false) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { t: null },- }- );- mr.setValue(row, column, style);- }- });- }- if (bottom === true || bottom === false || bottom === null) {- // Probably to the border, there are no surrounding cells- // Clear the top border of the lower range- forEach(bottomRangeOut, (row, column) => {- mr.setValue(row, column, { bd: { t: null } });- });-- // the last row- forEach(bottomRange, (row, column) => {- // update- if (bottom === true) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { b: Tools.deepClone(border) },- }- );- mr.setValue(row, column, style);- }- // delete- else if (bottom === false) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { b: null },- }- );- mr.setValue(row, column, style);- }- });- }- if (left === true || left === false || left === null) {- // Probably to the border, there are no surrounding cells- // Clear the right border of the left range- forEach(leftRangeOut, (row, column) => {- mr.setValue(row, column, { bd: { r: null } });- });-- // first column- forEach(leftRange, (row, column) => {- // update- if (left === true) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { l: Tools.deepClone(border) },- }- );- mr.setValue(row, column, style);- }- // delete- else if (left === false) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { l: null },- }- );- mr.setValue(row, column, style);- }- });- }- if (right === true || right === false || right === null) {- // Probably to the border, there are no surrounding cells- // Clear the left border of the right range- forEach(rightRangeOut, (row, column) => {- mr.setValue(row, column, { bd: { l: null } });- });-- // last column- forEach(rightRange, (row, column) => {- // update- if (right === true) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { r: Tools.deepClone(border) },- }- );- mr.setValue(row, column, style);- }- // delete- else if (right === false) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { r: null },- }- );- mr.setValue(row, column, style);- }- });- }-- // inner vertical border- if (vertical === true || vertical === false) {- // current range- forEach(range, (row, column) => {- // Set the right border except the last column- if (column !== range.endColumn) {- // update- if (vertical === true) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { r: Tools.deepClone(border) },- }- );- mr.setValue(row, column, style);- }- // delete- else if (vertical === false) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { r: null },- }- );- mr.setValue(row, column, style);- }- }-- // Except for the first column, clear the left border- if (column !== range.startColumn) {- const style = Tools.deepMerge(- Tools.deepClone(styles.get(sheetMatrix.getValue(row, column)?.s)) || {},- {- bd: { l: null },- }- );- mr.setValue(row, column, style);- }- });- }- // inner horizontal border- if (horizontal === true || horizontal === false) {- // current range- forEach(range, (row, column) => {- // Except for the last row, set the bottom border- if (row !== range.endRow) {- // update- if (horizontal === true) {- const style = Tools.deepMerge(styles.get(sheetMatrix.getValue(row, column)?.s) || {}, {- bd: { b: Tools.deepClone(border) },- });- mr.setValue(row, column, style);- }- // delete- else if (horizontal === false) {- const style = Tools.deepMerge(styles.get(sheetMatrix.getValue(row, column)?.s) || {}, {- bd: { b: null },- });- mr.setValue(row, column, style);- }- }-- // Except for the first row, clear the top border- if (row !== range.startRow) {- const style = Tools.deepMerge(styles.get(sheetMatrix.getValue(row, column)?.s) || {}, {- bd: { t: null },- });- mr.setValue(row, column, style);- }- });- }-- const setBorderStylesMutationParams: ISetBorderStylesMutationParams = {- workbookId,- worksheetId,- value: mr.getData(),- };- const undoSetBorderStylesMutationParams: ISetBorderStylesMutationParams = SetBorderStylesUndoMutationFactory(- accessor,- setBorderStylesMutationParams- );-- // execute do mutations and add undo mutations to undo stack if completed- const result = commandService.syncExecuteCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);- if (result) {- undoRedoService.pushUndoRedo({- unitID: workbookId,- undoMutations: [{ id: SetBorderStylesMutation.id, params: undoSetBorderStylesMutationParams }],- redoMutations: [{ id: SetBorderStylesMutation.id, params: setBorderStylesMutationParams }],- });-- return true;- }-- return false;- },-};--interface ISetBorderType {- type: BorderType;-}--export const SetBorderTypeCommand: ICommand = {- id: 'sheet.command.set-border-types',- type: CommandType.COMMAND,- // eslint-disable-next-line max-lines-per-function- handler: async (accessor: IAccessor, params?: ISetBorderType) => {- const commandService = accessor.get(ICommandService);- const borderService = accessor.get(BorderStyleManagerService);- const type = params ? params.type : BorderType.ALL;- borderService.setType(type);-- let top = null;- let left = null;- let bottom = null;- let right = null;- let vertical = null;- let horizontal = null;-- switch (type) {- case BorderType.TOP:- top = true;- break;- case BorderType.BOTTOM:- bottom = true;- break;- case BorderType.LEFT:- left = true;- break;- case BorderType.RIGHT:- right = true;- break;- case BorderType.NONE:- top = false;- left = false;- bottom = false;- right = false;- vertical = false;- horizontal = false;- break;- case BorderType.ALL:- top = true;- left = true;- bottom = true;- right = true;- vertical = true;- horizontal = true;- break;- case BorderType.OUTSIDE:- top = true;- left = true;- bottom = true;- right = true;- break;- case BorderType.INSIDE:- vertical = true;- horizontal = true;- break;- case BorderType.HORIZONTAL:- horizontal = true;- break;- case BorderType.VERTICAL:- vertical = true;- break;-- default:- break;- }-- const { color, style } = borderService.getBorderInfo();- const setBorderParams: ISetBorderCommandParams = {- top,- left,- bottom,- right,- vertical,- horizontal,- color,- style,- };-- return commandService.executeCommand(SetBorderCommand.id, setBorderParams);- },-};--interface ISetBorderStyle {- style: BorderStyleTypes;-}--export const SetBorderStyleCommand: ICommand = {- id: 'sheet.command.set-border-styles',- type: CommandType.COMMAND,- // eslint-disable-next-line max-lines-per-function- handler: async (accessor: IAccessor, params?: ISetBorderStyle) => {- const borderService = accessor.get(BorderStyleManagerService);- const style = params ? params.style : BorderStyleTypes.THIN;- borderService.setStyle(style);- return true;- },-};--interface ISetBorderColor {- color: string;-}--export const SetBorderColorCommand: ICommand = {- id: 'sheet.command.set-border-color',- type: CommandType.COMMAND,- // eslint-disable-next-line max-lines-per-function- handler: async (accessor: IAccessor, params?: ISetBorderColor) => {- const borderService = accessor.get(BorderStyleManagerService);- const color = params ? params.color : '#000';- borderService.setColor(color);- return true;- },-};diff --git a/packages/base-sheets/src/commands/commands/set-range-values.command.ts b/packages/base-sheets/src/commands/commands/set-range-values.command.tsindex 27df12570e..0b5477d28b 100644--- a/packages/base-sheets/src/commands/commands/set-range-values.command.ts+++ b/packages/base-sheets/src/commands/commands/set-range-values.command.ts@@ -83,7 +83,6 @@ export const SetRangeValuesCommand: ICommand = {}const setRangeValuesMutationParams: ISetRangeValuesMutationParams = {- range: currentSelections,worksheetId,workbookId,cellValue: realCellValue ?? cellValue.getMatrix(),@@ -109,7 +108,7 @@ export const SetRangeValuesCommand: ICommand = {const { undos, redos } = sheetInterceptorService.onCommandExecute({id: SetRangeValuesCommand.id,- params: setRangeValuesMutationParams,+ params: { ...setRangeValuesMutationParams, range: currentSelections },});const result = sequenceExecute([...redos], commandService);diff --git a/packages/base-sheets/src/commands/commands/set-style.command.ts b/packages/base-sheets/src/commands/commands/set-style.command.tsindex da9d6ffd62..e50929837e 100644--- a/packages/base-sheets/src/commands/commands/set-style.command.ts+++ b/packages/base-sheets/src/commands/commands/set-style.command.ts@@ -105,7 +105,6 @@ export const SetStyleCommand: ICommand<ISetStyleParams<unknown>> = {}const setRangeValuesMutationParams: ISetRangeValuesMutationParams = {- range: ranges,worksheetId,workbookId,cellValue: cellValue.getMatrix(),diff --git a/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.ts b/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.tsdeleted file mode 100644index bc168b0451..0000000000--- a/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.ts+++ /dev/null@@ -1,245 +0,0 @@-import {- CommandType,- IBorderData,- IDocumentData,- IKeyValue,- IMutation,- IStyleData,- ITextStyle,- IUniverInstanceService,- Nullable,- ObjectMatrix,- ObjectMatrixPrimitiveType,- Tools,-} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--export interface ISetBorderStylesMutationParams {- workbookId: string;- worksheetId: string;- value: ObjectMatrixPrimitiveType<IStyleData>;-}--/**- * Generate undo mutation of a `SetRangeStyleMutation`- *- * @param {IAccessor} accessor - injector accessor- * @param {ISetRangeStyleMutationParams} params - do mutation params- * @returns {ISetRangeStyleMutationParams} undo mutation params- */-export const SetBorderStylesUndoMutationFactory = (- accessor: IAccessor,- params: ISetBorderStylesMutationParams-): ISetBorderStylesMutationParams => {- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getCurrentUniverSheetInstance();- const worksheet = univerInstanceService- .getCurrentUniverSheetInstance()-- .getSheetBySheetId(params.worksheetId);- const cellMatrix = worksheet?.getCellMatrix();- const styles = workbook.getStyles();- const data = new ObjectMatrix(params.value);-- const undoData = new ObjectMatrix<IStyleData>();- data.forValue((row: number, col: number, value: any) => {- const cell = cellMatrix?.getValue(row, col) || {};- const old = styles.getStyleByCell(cell);- undoData.setValue(row, col, transformStyle(old, value as Nullable<IStyleData>));- });-- return {- ...Tools.deepClone(params),- value: undoData.getData(),- };-};--export const SetBorderStylesMutation: IMutation<ISetBorderStylesMutationParams, boolean> = {- id: 'sheet.mutation.set-border-styles',- type: CommandType.MUTATION,- handler: (accessor, params) => {- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(params.workbookId);- if (!workbook) return false;- const worksheet = workbook.getSheetBySheetId(params.worksheetId);- if (!worksheet) return false;-- const cellMatrix = worksheet.getCellMatrix();- const styles = workbook.getStyles();-- const data = new ObjectMatrix(params.value);-- data.forValue((row: number, col: number, value: any) => {- const cell = cellMatrix.getValue(row, col) || {};- // use null to clear style- const old = styles.getStyleByCell(cell);-- if (old == null) {- // clear- delete cell.s;- }-- // set style- const merge = mergeStyle(old, value as Nullable<IStyleData>);-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete cell.s;- } else {- cell.s = styles.setValue(merge);- }-- // When the rich text sets the cell style, you need to modify the style of all rich text- // TODO redo/undo use setRangeData to undo rich text setting- if (cell.p) {- mergeRichTextStyle(cell.p, value as Nullable<IStyleData>);- }-- cellMatrix.setValue(row, col, cell);- });-- return true;- },-};--/**- * Convert old style data for storage- * @param style- */-export function transformStyle(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IStyleData>): Nullable<IStyleData> {- const backupStyle = transformNormalKey(oldStyle, newStyle);- return backupStyle;-}-/**- * Convert old style normal key for storage- *- * @param style- */-export function transformNormalKey(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>-): Nullable<IStyleData> {- // If there is no newly set style, directly store the historical style- if (!newStyle || !Object.keys(newStyle).length) {- return oldStyle;- }- const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};-- for (const k in newStyle) {- if (k === 'bd') {- backupStyle[k] = transformBorders(backupStyle[k] || {}, newStyle[k]);- }- // 1. To modify the existing style,we need original setting to undo- // 2. Newly set the style, we need null to undo- else if (!(k in backupStyle)) {- backupStyle[k] = null;- }- }- return backupStyle;-}-/**- * Convert old style border for storage- *-- * @param style- */-export function transformBorders(oldBorders: IBorderData, newBorders: Nullable<IBorderData>): IBorderData {- // If there is no newly set border, directly store the historical border- if (!newBorders || !Object.keys(newBorders).length) {- return oldBorders;- }-- for (const k in newBorders) {- // 1. To modify the existing border,we need original setting to undo- // 2. Newly set the border, we need null to undo- if (!(k in oldBorders)) {- (oldBorders as IKeyValue)[k] = null;- }- }-- return oldBorders;-}--/**- * merge new style to old style- *- * @param oldStyle- * @param newStyle- */-export function mergeStyle(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>,- isRichText: boolean = false-): Nullable<IStyleData> {- // clear style- if (newStyle === null) return newStyle;- // don't operate- if (newStyle === undefined) return oldStyle;-- const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};- if (!backupStyle) return;- for (const k in newStyle) {- if (isRichText && ['bd', 'tr', 'td', 'ht', 'vt', 'tb', 'pd'].includes(k)) {- continue;- }- // you can only choose one of the themeColor and rgbColor of the border setting- if (k in backupStyle && k === 'bd') {- backupStyle[k] = Object.assign(backupStyle[k], newStyle[k]);- } else {- backupStyle[k] = (newStyle as IKeyValue)[k];- }- }-- // Overline/Strikethrough/Underline color follows text color- // if ('cl' in backupStyle) {- // for (const k in newStyle) {- // if (['ul', 'ol', 'st'].includes(k)) {- // backupStyle[k].cl = backupStyle.cl;- // }- // }- // }-- if ('cl' in backupStyle) {- if ('ul' in backupStyle) {- backupStyle.ul.cl = backupStyle.cl;- }-- if ('ol' in backupStyle) {- backupStyle.ol.cl = backupStyle.cl;- }-- if ('st' in backupStyle) {- backupStyle.st.cl = backupStyle.cl;- }- }-- return backupStyle;-}--/**- * Find the text style of all paragraphs and modify it to the new style- * @param p- * @param newStyle- */-export function mergeRichTextStyle(p: IDocumentData, newStyle: Nullable<IStyleData>) {- p.body?.textRuns?.forEach((textRun) => {- if (!textRun.ts) {- textRun.ts = {};- }-- const oldStyle = textRun.ts || {};-- const merge = mergeStyle(oldStyle as Nullable<IStyleData>, newStyle, true);-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete textRun.ts;- } else {- textRun.ts = merge as ITextStyle;- }- });-}diff --git a/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.ts b/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.tsdeleted file mode 100644index a7d8d40bce..0000000000--- a/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.ts+++ /dev/null@@ -1,292 +0,0 @@-import {- CommandType,- IBorderData,- IDocumentData,- IKeyValue,- IMutation,- IRange,- IStyleData,- ITextStyle,- IUniverInstanceService,- Nullable,- ObjectMatrix,- ObjectMatrixPrimitiveType,- Tools,-} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--export interface ISetRangeStyleMutationParams {- workbookId: string;- worksheetId: string;- range: IRange[];- value?: ObjectMatrixPrimitiveType<IStyleData>;-}--/**- * Generate undo mutation of a `SetRangeStyleMutation`- *- * @param {IAccessor} accessor - injector accessor- * @param {ISetRangeStyleMutationParams} params - do mutation params- * @returns {ISetRangeStyleMutationParams} undo mutation params- *- */-export const SetRangeStyleUndoMutationFactory = (- accessor: IAccessor,- params: ISetRangeStyleMutationParams-): ISetRangeStyleMutationParams => {- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getCurrentUniverSheetInstance();- const worksheet = univerInstanceService- .getCurrentUniverSheetInstance()-- .getSheetBySheetId(params.worksheetId);- if (worksheet == null) {- throw new Error('error');- }- const cellMatrix = worksheet.getCellMatrix();- const styles = workbook.getStyles();-- const value = params.value ?? null;-- const undoData = new ObjectMatrix<IStyleData>();- for (let i = 0; i < params.range.length; i++) {- const { startRow, endRow, startColumn, endColumn } = params.range[i];- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- const cell = cellMatrix.getValue(r, c) || {};- const old = styles.getStyleByCell(cell);- const test = transformStyle(- old,- value ? (value[r - startRow][c - startColumn] as Nullable<IStyleData>) : null- );- undoData.setValue(r - startRow, c - startColumn, test);- }- }- }-- return {- ...Tools.deepClone(params),- value: undoData.getData(),- } as ISetRangeStyleMutationParams;-};--/**- * @deprecated use set range values mutation instead- */-export const SetRangeStyleMutation: IMutation<ISetRangeStyleMutationParams, boolean> = {- id: 'sheet.mutation.set-range-style',- type: CommandType.MUTATION,- handler: (accessor, params) => {- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(params.workbookId);- if (!workbook) return false;- const worksheet = workbook.getSheetBySheetId(params.worksheetId);- if (!worksheet) return false;-- const cellMatrix = worksheet.getCellMatrix();- const styles = workbook.getStyles();- const value = params.value ?? null;-- for (let i = 0; i < params.range.length; i++) {- const { startRow, endRow, startColumn, endColumn } = params.range[i];- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- const cell = cellMatrix.getValue(r, c) || {};- // use null to clear style- const old = styles.getStyleByCell(cell);-- if (old == null) {- // clear- delete cell.s;- }-- // set style- const merge = mergeStyle(- old,- value ? (value[r - startRow][c - startColumn] as Nullable<IStyleData>) : null- );-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete cell.s;- } else {- cell.s = styles.setValue(merge);- }-- // When the rich text sets the cell style, you need to modify the style of all rich text- // TODO redo/undo use setRangeData to undo rich text setting- if (cell.p) {- mergeRichTextStyle(- cell.p,- value ? (value[r - startRow][c - startColumn] as Nullable<IStyleData>) : null- );- }-- cellMatrix.setValue(r, c, cell);- }- }- }-- return true;- },-};--/**- * Convert old style data for storage- * @param style- */-export function transformStyle(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IStyleData>): Nullable<IStyleData> {- const backupStyle = transformNormalKey(oldStyle, newStyle);- return backupStyle;-}-/**- * Convert old style normal key for storage- *- * @param style- */-export function transformNormalKey(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>-): Nullable<IStyleData> {- // If there is no newly set style, directly store the historical style- if (!newStyle || !Object.keys(newStyle).length) {- return oldStyle;- }- const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};-- for (const k in newStyle) {- if (k === 'bd') {- backupStyle[k] = transformBorders(backupStyle[k] || {}, newStyle[k]);- }- // 1. To modify the existing style,we need original setting to undo- // 2. Newly set the style, we need null to undo- else if (!(k in backupStyle)) {- backupStyle[k] = null;- }- }- return backupStyle;-}-/**- * Convert old style border for storage- *-- * @param style- */-export function transformBorders(oldBorders: IBorderData, newBorders: Nullable<IBorderData>): IBorderData {- // If there is no newly set border, directly store the historical border- if (!newBorders || !Object.keys(newBorders).length) {- return oldBorders;- }-- for (const k in newBorders) {- // 1. To modify the existing border,we need original setting to undo- // 2. Newly set the border, we need null to undo- if (!(k in oldBorders)) {- (oldBorders as IKeyValue)[k] = null;- }- }-- return oldBorders;-}--/**- * merge new style to old style- *- * @param oldStyle- * @param newStyle- */-export function mergeStyle(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>,- isRichText: boolean = false-): Nullable<IStyleData> {- // clear style- if (newStyle === null) return newStyle;- // don't operate- if (newStyle === undefined) return oldStyle;-- const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};- if (!backupStyle) return;- for (const k in newStyle) {- if (isRichText && ['bd', 'tr', 'td', 'ht', 'vt', 'tb', 'pd'].includes(k)) {- continue;- }- // you can only choose one of the themeColor and rgbColor of the border setting- if (k in backupStyle && k === 'bd') {- backupStyle[k] = Object.assign(backupStyle[k], newStyle[k]);- } else {- backupStyle[k] = (newStyle as IKeyValue)[k];-- // overline/strikethrough/underline add color- if ('cl' in backupStyle) {- if (['ul', 'ol', 'st'].includes(k)) {- if (backupStyle[k]) {- backupStyle[k].cl = backupStyle.cl;- }- }- }- }- }- return backupStyle;-}--/**- * Find the text style of all paragraphs and modify it to the new style- * @param p- * @param newStyle- */-export function mergeRichTextStyle(p: IDocumentData, newStyle: Nullable<IStyleData>) {- // p.body?.blockElements.forEach((blockElement) => {- // if (blockElement.blockType === 0) {- // const paragraph = blockElement.paragraph;- // paragraph?.elements.forEach((element) => {- // if (!element.tr) {- // element.tr = {};- // }-- // const textRun = element.tr as ITextRun;-- // if (!textRun.ts) {- // textRun.ts = {};- // }-- // const oldStyle = textRun.ts;-- // const merge = mergeStyle(- // oldStyle as Nullable<IStyleData>,- // newStyle,- // true- // );-- // // then remove null- // merge && Tools.removeNull(merge);-- // if (Tools.isEmptyObject(merge)) {- // delete textRun.ts;- // } else {- // textRun.ts = merge as ITextStyle;- // }- // });- // }- // });- p.body?.textRuns?.forEach((textRun) => {- if (!textRun.ts) {- textRun.ts = {};- }-- const oldStyle = textRun.ts || {};-- const merge = mergeStyle(oldStyle as Nullable<IStyleData>, newStyle, true);-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete textRun.ts;- } else {- textRun.ts = merge as ITextStyle;- }- });-}diff --git a/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/base-sheets/src/commands/mutations/set-range-values.mutation.tsindex 37fff130c6..e3c970ede7 100644--- a/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts+++ b/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts@@ -1,10 +1,16 @@import {+ CellValueType,CommandType,+ IBorderData,ICellData,+ ICellV,ICopyToOptionsData,+ IDocumentData,+ IKeyValue,IMutation,IRange,IStyleData,+ ITextStyle,IUniverInstanceService,Nullable,ObjectMatrix,@@ -13,11 +19,8 @@ import {} from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { mergeRichTextStyle, mergeStyle, transformStyle } from './set-border-styles.mutation';-/** Params of `SetRangeValuesMutation` */export interface ISetRangeValuesMutationParams {- range: IRange[]; // FIXME: maybe don't need thisworksheetId: string;workbookId: string;@@ -32,6 +35,10 @@ export interface ISetRangeValuesMutationParams {options?: ICopyToOptionsData;}+export interface ISetRangeValuesRangeMutationParams extends ISetRangeValuesMutationParams {+ range: IRange[];+}+/*** Generate undo mutation of a `SetRangeValuesMutation`*@@ -150,6 +157,8 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, boif (newVal.t !== undefined) {oldVal.t = newVal.t;+ } else if (oldVal.v !== undefined) {+ oldVal.t = checkCellValueType(oldVal.v);}// handle style@@ -191,3 +200,158 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, boreturn true;},};++function checkCellValueType(v: Nullable<ICellV>): Nullable<CellValueType> {+ if (v === null) return null;++ if (typeof v === 'string') {+ return CellValueType.STRING;+ }+ if (typeof v === 'number') {+ return CellValueType.NUMBER;+ }+ if (typeof v === 'boolean') {+ return CellValueType.BOOLEAN;+ }+ return CellValueType.FORCE_STRING;+}++/**+ * Convert old style data for storage+ * @param style+ */+export function transformStyle(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IStyleData>): Nullable<IStyleData> {+ const backupStyle = transformNormalKey(oldStyle, newStyle);+ return backupStyle;+}+/**+ * Convert old style normal key for storage+ *+ * @param style+ */+export function transformNormalKey(+ oldStyle: Nullable<IStyleData>,+ newStyle: Nullable<IStyleData>+): Nullable<IStyleData> {+ // If there is no newly set style, directly store the historical style+ if (!newStyle || !Object.keys(newStyle).length) {+ return oldStyle;+ }+ const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};++ for (const k in newStyle) {+ if (k === 'bd') {+ backupStyle[k] = transformBorders(backupStyle[k] || {}, newStyle[k]);+ }+ // 1. To modify the existing style,we need original setting to undo+ // 2. Newly set the style, we need null to undo+ else if (!(k in backupStyle)) {+ backupStyle[k] = null;+ }+ }+ return backupStyle;+}+/**+ * Convert old style border for storage+ *++ * @param style+ */+export function transformBorders(oldBorders: IBorderData, newBorders: Nullable<IBorderData>): IBorderData {+ // If there is no newly set border, directly store the historical border+ if (!newBorders || !Object.keys(newBorders).length) {+ return oldBorders;+ }++ for (const k in newBorders) {+ // 1. To modify the existing border,we need original setting to undo+ // 2. Newly set the border, we need null to undo+ if (!(k in oldBorders)) {+ (oldBorders as IKeyValue)[k] = null;+ }+ }++ return oldBorders;+}++/**+ * merge new style to old style+ *+ * @param oldStyle+ * @param newStyle+ */+export function mergeStyle(+ oldStyle: Nullable<IStyleData>,+ newStyle: Nullable<IStyleData>,+ isRichText: boolean = false+): Nullable<IStyleData> {+ // clear style+ if (newStyle === null) return newStyle;+ // don't operate+ if (newStyle === undefined) return oldStyle;++ const backupStyle: { [key: string]: any } = Tools.deepClone(oldStyle) || {};+ if (!backupStyle) return;+ for (const k in newStyle) {+ if (isRichText && ['bd', 'tr', 'td', 'ht', 'vt', 'tb', 'pd'].includes(k)) {+ continue;+ }+ // you can only choose one of the themeColor and rgbColor of the border setting+ if (k in backupStyle && k === 'bd') {+ backupStyle[k] = Object.assign(backupStyle[k], newStyle[k]);+ } else {+ backupStyle[k] = (newStyle as IKeyValue)[k];+ }+ }++ // Overline/Strikethrough/Underline color follows text color+ // if ('cl' in backupStyle) {+ // for (const k in newStyle) {+ // if (['ul', 'ol', 'st'].includes(k)) {+ // backupStyle[k].cl = backupStyle.cl;+ // }+ // }+ // }++ if ('cl' in backupStyle) {+ if ('ul' in backupStyle) {+ backupStyle.ul.cl = backupStyle.cl;+ }++ if ('ol' in backupStyle) {+ backupStyle.ol.cl = backupStyle.cl;+ }++ if ('st' in backupStyle) {+ backupStyle.st.cl = backupStyle.cl;+ }+ }++ return backupStyle;+}++/**+ * Find the text style of all paragraphs and modify it to the new style+ * @param p+ * @param newStyle+ */+export function mergeRichTextStyle(p: IDocumentData, newStyle: Nullable<IStyleData>) {+ p.body?.textRuns?.forEach((textRun) => {+ if (!textRun.ts) {+ textRun.ts = {};+ }++ const oldStyle = textRun.ts || {};++ const merge = mergeStyle(oldStyle as Nullable<IStyleData>, newStyle, true);++ // then remove null+ merge && Tools.removeNull(merge);++ if (Tools.isEmptyObject(merge)) {+ delete textRun.ts;+ } else {+ textRun.ts = merge as ITextStyle;+ }+ });+}diff --git a/packages/base-sheets/src/controllers/basic-worksheet.controller.ts b/packages/base-sheets/src/controllers/basic-worksheet.controller.tsindex 9dd6fa6481..cff095791f 100644--- a/packages/base-sheets/src/controllers/basic-worksheet.controller.ts+++ b/packages/base-sheets/src/controllers/basic-worksheet.controller.ts@@ -83,11 +83,9 @@ import { MoveColsMutation, MoveRowsMutation } from '../commands/mutations/move-rimport { RemoveColMutation, RemoveRowMutation } from '../commands/mutations/remove-row-col.mutation';import { RemoveSheetMutation } from '../commands/mutations/remove-sheet.mutation';import { RemoveWorksheetMergeMutation } from '../commands/mutations/remove-worksheet-merge.mutation';-import { SetBorderStylesMutation } from '../commands/mutations/set-border-styles.mutation';import { SetColHiddenMutation, SetColVisibleMutation } from '../commands/mutations/set-col-visible.mutation';import { SetFrozenMutation } from '../commands/mutations/set-frozen.mutation';import { SetRangeFormattedValueMutation } from '../commands/mutations/set-range-formatted-value.mutation';-import { SetRangeStyleMutation } from '../commands/mutations/set-range-styles.mutation';import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';import { SetRowHiddenMutation, SetRowVisibleMutation } from '../commands/mutations/set-row-visible.mutation';import { SetTabColorMutation } from '../commands/mutations/set-tab-color.mutation';@@ -164,7 +162,6 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetBorderCommand,SetBorderPositionCommand,SetBorderStyleCommand,- SetBorderStylesMutation,SetColHiddenCommand,SetColHiddenMutation,SetColVisibleMutation,@@ -175,7 +172,6 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetHorizontalTextAlignCommand,SetRangeFormattedValueCommand,SetRangeFormattedValueMutation,- SetRangeStyleMutation,SetRangeValuesCommand,SetRangeValuesMutation,SetRowHeightCommand,diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.tsindex 39a5838d2b..056623c1f6 100644--- a/packages/base-sheets/src/index.ts+++ b/packages/base-sheets/src/index.ts@@ -147,7 +147,6 @@ export { RemoveColMutation, RemoveRowMutation } from './commands/mutations/removexport { RemoveSheetMutation, RemoveSheetUndoMutationFactory } from './commands/mutations/remove-sheet.mutation';export { RemoveWorksheetMergeMutation } from './commands/mutations/remove-worksheet-merge.mutation';export { RemoveMergeUndoMutationFactory } from './commands/mutations/remove-worksheet-merge.mutation';-export { SetBorderStylesMutation } from './commands/mutations/set-border-styles.mutation';export {type ISetColHiddenMutationParams,type ISetColVisibleMutationParams,@@ -159,11 +158,10 @@ export {SetFrozenMutation,SetFrozenMutationFactory,} from './commands/mutations/set-frozen.mutation';-export type { ISetRangeStyleMutationParams } from './commands/mutations/set-range-styles.mutation';-export { SetRangeStyleMutation } from './commands/mutations/set-range-styles.mutation';export type { ISetRangeValuesMutationParams } from './commands/mutations/set-range-values.mutation';export { SetRangeValuesMutation } from './commands/mutations/set-range-values.mutation';export { SetRangeValuesUndoMutationFactory } from './commands/mutations/set-range-values.mutation';+export { type ISetRangeValuesRangeMutationParams } from './commands/mutations/set-range-values.mutation';export { SetRowHiddenMutation, SetRowVisibleMutation } from './commands/mutations/set-row-visible.mutation';export { SetTabColorMutation } from './commands/mutations/set-tab-color.mutation';export { type ISetTabColorMutationParams } from './commands/mutations/set-tab-color.mutation';diff --git a/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts b/packages/sheets-plugin-formula/src/controllers/calculate.controller.tsindex 97ccc2dbe3..0ab0e40032 100644--- a/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts+++ b/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts@@ -55,7 +55,7 @@ export class CalculateController extends Disposable {const { params } = command;if (!params) return;- const { range, worksheetId: sheetId, workbookId: unitId, cellValue } = params;+ const { worksheetId: sheetId, workbookId: unitId, cellValue } = params;if (cellValue == null) return;const formulaData = Tools.deepClone(this._formulaDataModel.getFormulaData());@@ -142,7 +142,6 @@ export class CalculateController extends Disposable {sheetIds.forEach((sheetId) => {const cellData = sheetData[sheetId];const setRangeValuesMutation: ISetRangeValuesMutationParams = {- range: [],worksheetId: sheetId,workbookId: unitId,cellValue: cellData.getData(),diff --git a/packages/sheets-plugin-formula/src/controllers/util.ts b/packages/sheets-plugin-formula/src/controllers/util.tsindex f0a4a7568b..f11059d702 100644--- a/packages/sheets-plugin-formula/src/controllers/util.ts+++ b/packages/sheets-plugin-formula/src/controllers/util.ts@@ -1,7 +1,6 @@+import { IFunctionInfo } from '@univerjs/base-formula-engine';import { LocaleService } from '@univerjs/core';-import { IFunctionInfo } from '../services/function-list';-export function getFunctionName(item: IFunctionInfo, localeService: LocaleService) {let functionName = '';if (item.aliasFunctionName) {diff --git a/packages/sheets-plugin-formula/src/formula-plugin.ts b/packages/sheets-plugin-formula/src/formula-plugin.tsindex 2f2c3edc94..6deca1ae06 100644--- a/packages/sheets-plugin-formula/src/formula-plugin.ts+++ b/packages/sheets-plugin-formula/src/formula-plugin.ts@@ -9,6 +9,7 @@ import { enUS } from './locale';import { FormulaDataModel, IFormulaConfig } from './models/formula-data.model';import { FormulaPromptService, IFormulaPromptService } from './services/prompt.service';+// TODO@Dushusir: user config IFunctionInfo, we will register all function info in formula engineexport class FormulaPlugin extends Plugin {static override type = PluginType.Sheet;diff --git a/packages/sheets-plugin-formula/src/services/function-list.ts b/packages/sheets-plugin-formula/src/services/function-list.tsindex c043dd7a29..e8e6fc1163 100644--- a/packages/sheets-plugin-formula/src/services/function-list.ts+++ b/packages/sheets-plugin-formula/src/services/function-list.ts@@ -1,4 +1,4 @@-import { BooleanNumber } from '@univerjs/core';+import { IFunctionInfo } from '@univerjs/base-formula-engine';export enum FunctionType {Math,@@ -18,85 +18,6 @@ export enum FunctionType {Other,}-export interface IFunctionParam {- /**- * Function name, with internationalization- */- name: string;-- /**- * Detailed description of function, with internationalization- */- detail: string;-- /**- * Function example- */- example: string;-- /**- * Is it optional- *- * true: required- * false: optional- */- require: BooleanNumber;-- /**- * Whether it is repeatable, in the case of repeatability, the maximum parameter of m is generally set to 255, such as [1,255]- *- * true: repeatable- * false: not repeatable- */- repeat: BooleanNumber;-- /**- * Parameter types- *- * include ['range', 'rangeall', 'rangenumber', 'rangestring', 'rangedatetime', 'rangedate', 'string']- * Detected before each calculation- */- type: string;-}--export interface IFunctionInfo {- /**- * Function name- */- functionName: string;-- /**- * Alias Function name- */- aliasFunctionName?: string;-- /**- * Function type- */- functionType: FunctionType;-- /**- * Detailed description- */- description: string;-- /**- * Concise abstract- */- abstract: string;-- /**- * [Minimum number of parameters, maximum number of parameters]- * Detected before each calculation of the function- */- parameterRange: [min: number, max: number];-- /**- * Function params- */- functionParameter: IFunctionParam[];-}-// TODO@Dushusir: register custom function// TODO@Dushusir: register custom locale fileexport interface IFunctionDescription {diff --git a/packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsx b/packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsxindex 6140fcea95..1487cb1988 100644--- a/packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsx+++ b/packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsx@@ -1,3 +1,4 @@+import { IFunctionInfo, IFunctionParam } from '@univerjs/base-formula-engine';import { LocaleService } from '@univerjs/core';import { Dropdown } from '@univerjs/design';import { CloseSingle, DetailsSingle, MoreSingle } from '@univerjs/icons';@@ -5,7 +6,6 @@ import { ICellEditorManagerService } from '@univerjs/ui-plugin-sheets';import { useDependency } from '@wendellhu/redi/react-bindings';import React, { useEffect, useState } from 'react';-import { IFunctionInfo, IFunctionParam } from '../../../services/function-list';import { IFormulaPromptService, IHelpFunctionCommandParams } from '../../../services/prompt.service';import styles from './index.module.less';diff --git a/packages/ui-plugin-sheets/src/commands/commands/auto-fill.command.ts b/packages/ui-plugin-sheets/src/commands/commands/auto-fill.command.tsindex 42c5f93abe..73a7d95987 100644--- a/packages/ui-plugin-sheets/src/commands/commands/auto-fill.command.ts+++ b/packages/ui-plugin-sheets/src/commands/commands/auto-fill.command.ts@@ -66,7 +66,6 @@ export const AutoFillCommand: ICommand = {}const setRangeValuesMutationParams: ISetRangeValuesMutationParams = {- range: [selectionRange],worksheetId,workbookId,cellValue: cellValue.getMatrix(),@@ -170,7 +169,6 @@ export const AutoClearContentCommand: ICommand = {const { clearRange, selectionRange } = params;const clearMutationParams: ISetRangeValuesMutationParams = {- range: [clearRange],worksheetId,workbookId,cellValue: generateNullCellValue([clearRange]),diff --git a/packages/ui-plugin-sheets/src/controllers/auto-height.controller.ts b/packages/ui-plugin-sheets/src/controllers/auto-height.controller.tsindex d964e33255..2ea8ab3e8d 100644--- a/packages/ui-plugin-sheets/src/controllers/auto-height.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/auto-height.controller.ts@@ -1,7 +1,7 @@// TODO@wzhudev: re-export from base-sheetsimport {DeltaColumnWidthCommand,- ISetRangeValuesMutationParams,+ ISetRangeValuesRangeMutationParams,ISetStyleParams,ISetWorksheetColWidthMutationParams,ISetWorksheetRowAutoHeightMutationParams,@@ -77,7 +77,7 @@ export class AutoHeightController {this;// for intercept'SetRangeValuesCommand' command.sheetInterceptorService.interceptCommand({- getMutations: (command: { id: string; params: ISetRangeValuesMutationParams }) => {+ getMutations: (command: { id: string; params: ISetRangeValuesRangeMutationParams }) => {if (command.id !== SetRangeValuesCommand.id) {return {redos: [],diff --git a/packages/ui-plugin-sheets/src/controllers/clipboard/clipboard.controller.ts b/packages/ui-plugin-sheets/src/controllers/clipboard/clipboard.controller.tsindex 6c26e41348..5963ee2750 100644--- a/packages/ui-plugin-sheets/src/controllers/clipboard/clipboard.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/clipboard/clipboard.controller.ts@@ -417,7 +417,6 @@ export class SheetClipboardController extends Disposable {// clear styleif (clearStyleMatrix.getLength() > 0) {const clearMutation: ISetRangeValuesMutationParams = {- range: [range],worksheetId,workbookId,cellValue: clearStyleMatrix.getData(),@@ -443,7 +442,6 @@ export class SheetClipboardController extends Disposable {const setValuesMutation: ISetRangeValuesMutationParams = {workbookId,worksheetId,- range: [range],cellValue: valueMatrix.getData(),};diff --git a/packages/ui-plugin-sheets/src/controllers/menu/menu.ts b/packages/ui-plugin-sheets/src/controllers/menu/menu.tsindex 113b5ede19..e42c447dfb 100644--- a/packages/ui-plugin-sheets/src/controllers/menu/menu.ts+++ b/packages/ui-plugin-sheets/src/controllers/menu/menu.ts@@ -23,7 +23,6 @@ import {SetColVisibleMutation,SetColWidthCommand,SetHorizontalTextAlignCommand,- SetRangeStyleMutation,SetRangeValuesMutation,SetRowHeightCommand,SetRowHiddenCommand,@@ -148,11 +147,7 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id !== SetRangeStyleMutation.id &&- id !== SetRangeValuesMutation.id &&- id !== SetSelectionsOperation.id- ) {+ if (id !== SetRangeValuesMutation.id && id !== SetSelectionsOperation.id) {return;}@@ -201,11 +196,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id !== SetRangeStyleMutation.id &&- id !== SetRangeValuesMutation.id &&- id !== SetSelectionsOperation.id- ) {+ if (id !== SetRangeValuesMutation.id && id !== SetSelectionsOperation.id) {return;}@@ -252,11 +243,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id !== SetRangeStyleMutation.id &&- id !== SetRangeValuesMutation.id &&- id !== SetSelectionsOperation.id- ) {+ if (id !== SetRangeValuesMutation.id && id !== SetSelectionsOperation.id) {return;}@@ -303,11 +290,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItactivated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id !== SetRangeStyleMutation.id &&- id !== SetRangeValuesMutation.id &&- id !== SetSelectionsOperation.id- ) {+ if (id !== SetRangeValuesMutation.id && id !== SetSelectionsOperation.id) {return;}@@ -491,11 +474,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelconst disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id !== SetRangeStyleMutation.id &&- id !== SetRangeValuesMutation.id &&- id !== SetSelectionsOperation.id- ) {+ if (id !== SetRangeValuesMutation.id && id !== SetSelectionsOperation.id) {return;}@@ -549,11 +528,7 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelecconst DEFAULT_SIZE = 14;const disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id !== SetRangeStyleMutation.id &&- id !== SetRangeValuesMutation.id &&- id !== SetSelectionsOperation.id- ) {+ if (id !== SetRangeValuesMutation.id && id !== SetSelectionsOperation.id) {return;}@@ -1307,11 +1282,7 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonIteconst disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id === SetRangeStyleMutation.id ||- id === SetRangeValuesMutation.id ||- id === SetSelectionsOperation.id- ) {+ if (id === SetRangeValuesMutation.id || id === SetSelectionsOperation.id) {return update();}});@@ -1354,11 +1325,7 @@ export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItemconst disposable = commandService.onCommandExecuted((c) => {const id = c.id;- if (- id === SetRangeStyleMutation.id ||- id === SetRangeValuesMutation.id ||- id === SetSelectionsOperation.id- ) {+ if (id === SetRangeValuesMutation.id || id === SetSelectionsOperation.id) {return update();}});diff --git a/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts b/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.tsindex 0462bc6e4d..f55e3a71ee 100644--- a/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts+++ b/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts@@ -265,7 +265,6 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardconst setRangeValuesParams: ISetRangeValuesMutationParams = {workbookId: target.workbookId,worksheetId: target.worksheetId,- range: [target.selection.range],cellValue,};diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.tsindex 87dcb04372..64e0d8c995 100644--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts@@ -324,6 +324,8 @@ export class SlideTabItem {}}+// TODO@Dushusir: resize container trigger scroll box-shadow+// init container, no box-shadow, no scroll buttonexport class SlideScrollbar {protected _slideTabBar: SlideTabBar;