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
feat(merge-cell): support waring when insert or delete range (#1147)
Gpound.liu2c45ae8b12c7
diff --git a/packages/sheets-ui/src/commands/commands/delete-range-move-down-confirm.command.ts b/packages/sheets-ui/src/commands/commands/delete-range-move-down-confirm.command.tsnew file mode 100644index 0000000000..90af20fff0--- /dev/null+++ b/packages/sheets-ui/src/commands/commands/delete-range-move-down-confirm.command.ts@@ -0,0 +1,67 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICommand, IRange } from '@univerjs/core';+import { CommandType, ICommandService, IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';+import { DeleteRangeMoveUpCommand, SelectionManagerService } from '@univerjs/sheets';+import { IConfirmService } from '@univerjs/ui';++export const DeleteRangeMoveUpConfirmCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.delete-range-move-up-confirm',+ handler: async (accessor) => {+ const confirmService = accessor.get(IConfirmService);+ const commandService = accessor.get(ICommandService);+ const localeService = accessor.get(LocaleService);+ const selectionManagerService = accessor.get(SelectionManagerService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ const selection = selectionManagerService.getSelections();+ if (!selection) {+ return false;+ }+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const worksheet = workbook.getActiveSheet();+ let range = selection[0].range;++ if (!range) {+ return false;+ }+ range = { ...range, endRow: worksheet.getColumnCount() - 1 };++ const getColLength = (range: IRange) => range.endColumn - range.startColumn;+ const mergeData = worksheet.getMergeData().find((mergeRange) => {+ const interSectedRange = Rectangle.getIntersects(mergeRange, range);+ return interSectedRange ? getColLength(mergeRange) > getColLength(interSectedRange) : false;+ });++ if (!mergeData) {+ return commandService.executeCommand(DeleteRangeMoveUpCommand.id);+ }++ const result = await confirmService.confirm({+ id: DeleteRangeMoveUpConfirmCommand.id,+ title: { title: localeService.t('merge.confirm.waring') },+ children: { title: localeService.t('merge.confirm.dismantleMergeCellWaring') },+ cancelText: localeService.t('button.cancel'),+ confirmText: localeService.t('button.confirm'),+ });+ if (result) {+ return commandService.executeCommand(DeleteRangeMoveUpCommand.id);+ }+ return true;+ },+};diff --git a/packages/sheets-ui/src/commands/commands/delete-range-move-left-confirm.command .ts b/packages/sheets-ui/src/commands/commands/delete-range-move-left-confirm.command .tsnew file mode 100644index 0000000000..2396e30c29--- /dev/null+++ b/packages/sheets-ui/src/commands/commands/delete-range-move-left-confirm.command .ts@@ -0,0 +1,67 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICommand, IRange } from '@univerjs/core';+import { CommandType, ICommandService, IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';+import { DeleteRangeMoveLeftCommand, SelectionManagerService } from '@univerjs/sheets';+import { IConfirmService } from '@univerjs/ui';++export const DeleteRangeMoveLeftConfirmCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.delete-range-move-left-confirm',+ handler: async (accessor) => {+ const confirmService = accessor.get(IConfirmService);+ const commandService = accessor.get(ICommandService);+ const localeService = accessor.get(LocaleService);+ const selectionManagerService = accessor.get(SelectionManagerService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ const selection = selectionManagerService.getSelections();+ if (!selection) {+ return false;+ }+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const worksheet = workbook.getActiveSheet();+ let range = selection[0].range;++ if (!range) {+ return false;+ }+ range = { ...range, endColumn: worksheet.getColumnCount() - 1 };++ const getRowLength = (range: IRange) => range.endRow - range.startRow;+ const mergeData = worksheet.getMergeData().find((mergeRange) => {+ const interSectedRange = Rectangle.getIntersects(mergeRange, range);+ return interSectedRange ? getRowLength(mergeRange) > getRowLength(interSectedRange) : false;+ });++ if (!mergeData) {+ return commandService.executeCommand(DeleteRangeMoveLeftCommand.id);+ }++ const result = await confirmService.confirm({+ id: DeleteRangeMoveLeftConfirmCommand.id,+ title: { title: localeService.t('merge.confirm.waring') },+ children: { title: localeService.t('merge.confirm.dismantleMergeCellWaring') },+ cancelText: localeService.t('button.cancel'),+ confirmText: localeService.t('button.confirm'),+ });+ if (result) {+ return commandService.executeCommand(DeleteRangeMoveLeftCommand.id);+ }+ return true;+ },+};diff --git a/packages/sheets-ui/src/commands/commands/insert-range-move-right-confirm.command.ts b/packages/sheets-ui/src/commands/commands/insert-range-move-right-confirm.command.tsnew file mode 100644index 0000000000..411f50cdd4--- /dev/null+++ b/packages/sheets-ui/src/commands/commands/insert-range-move-right-confirm.command.ts@@ -0,0 +1,68 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICommand, IRange } from '@univerjs/core';+import { CommandType, ICommandService, IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';+import { InsertRangeMoveRightCommand, SelectionManagerService } from '@univerjs/sheets';+import { IConfirmService } from '@univerjs/ui';++export const InsertRangeMoveRightConfirmCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.insert-range-move-right-confirm',+ handler: async (accessor) => {+ const confirmService = accessor.get(IConfirmService);+ const commandService = accessor.get(ICommandService);+ const localeService = accessor.get(LocaleService);+ const selectionManagerService = accessor.get(SelectionManagerService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ const selection = selectionManagerService.getSelections();+ if (!selection) {+ return false;+ }+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const worksheet = workbook.getActiveSheet();+ let range = selection[0].range;++ if (!range) {+ return false;+ }+ range = { ...range, endColumn: worksheet.getColumnCount() - 1 };++ const getRowLength = (range: IRange) => range.endRow - range.startRow;++ const mergeData = worksheet.getMergeData().find((mergeRange) => {+ const interSectedRange = Rectangle.getIntersects(mergeRange, range);+ return interSectedRange ? getRowLength(mergeRange) > getRowLength(interSectedRange) : false;+ });++ if (!mergeData) {+ return commandService.executeCommand(InsertRangeMoveRightCommand.id);+ }++ const result = await confirmService.confirm({+ id: InsertRangeMoveRightConfirmCommand.id,+ title: { title: localeService.t('merge.confirm.waring') },+ children: { title: localeService.t('merge.confirm.dismantleMergeCellWaring') },+ cancelText: localeService.t('button.cancel'),+ confirmText: localeService.t('button.confirm'),+ });+ if (result) {+ return commandService.executeCommand(InsertRangeMoveRightCommand.id);+ }+ return true;+ },+};diff --git a/packages/sheets-ui/src/commands/commands/insert-range-move-up-confirm.command.ts b/packages/sheets-ui/src/commands/commands/insert-range-move-up-confirm.command.tsnew file mode 100644index 0000000000..dd1a3ac749--- /dev/null+++ b/packages/sheets-ui/src/commands/commands/insert-range-move-up-confirm.command.ts@@ -0,0 +1,67 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICommand, IRange } from '@univerjs/core';+import { CommandType, ICommandService, IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';+import { InsertRangeMoveDownCommand, SelectionManagerService } from '@univerjs/sheets';+import { IConfirmService } from '@univerjs/ui';++export const InsertRangeMoveDownConfirmCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.insert-range-move-down-confirm',+ handler: async (accessor) => {+ const confirmService = accessor.get(IConfirmService);+ const commandService = accessor.get(ICommandService);+ const localeService = accessor.get(LocaleService);+ const selectionManagerService = accessor.get(SelectionManagerService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ const selection = selectionManagerService.getSelections();+ if (!selection) {+ return false;+ }+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const worksheet = workbook.getActiveSheet();+ let range = selection[0].range;++ if (!range) {+ return false;+ }+ range = { ...range, endRow: worksheet.getColumnCount() - 1 };++ const getColLength = (range: IRange) => range.endColumn - range.startColumn;+ const mergeData = worksheet.getMergeData().find((mergeRange) => {+ const interSectedRange = Rectangle.getIntersects(mergeRange, range);+ return interSectedRange ? getColLength(mergeRange) > getColLength(interSectedRange) : false;+ });++ if (!mergeData) {+ return commandService.executeCommand(InsertRangeMoveDownCommand.id);+ }++ const result = await confirmService.confirm({+ id: InsertRangeMoveDownConfirmCommand.id,+ title: { title: localeService.t('merge.confirm.waring') },+ children: { title: localeService.t('merge.confirm.dismantleMergeCellWaring') },+ cancelText: localeService.t('button.cancel'),+ confirmText: localeService.t('button.confirm'),+ });+ if (result) {+ return commandService.executeCommand(InsertRangeMoveDownCommand.id);+ }+ return true;+ },+};diff --git a/packages/sheets-ui/src/controllers/menu/delete.menu.ts b/packages/sheets-ui/src/controllers/menu/delete.menu.tsindex 549b415eb6..53ce6c622f 100644--- a/packages/sheets-ui/src/controllers/menu/delete.menu.ts+++ b/packages/sheets-ui/src/controllers/menu/delete.menu.ts@@ -14,15 +14,12 @@* limitations under the License.*/-import {- DeleteRangeMoveLeftCommand,- DeleteRangeMoveUpCommand,- RemoveColCommand,- RemoveRowCommand,-} from '@univerjs/sheets';+import { RemoveColCommand, RemoveRowCommand } from '@univerjs/sheets';import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';import { MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';+import { DeleteRangeMoveUpConfirmCommand } from '../../commands/commands/delete-range-move-down-confirm.command';+import { DeleteRangeMoveLeftConfirmCommand } from '../../commands/commands/delete-range-move-left-confirm.command ';import { SheetMenuPosition } from './menu';const DELETE_RANGE_MENU_ID = 'sheet.menu.delete';@@ -61,7 +58,7 @@ export function RemoveRowMenuItemFactory(): IMenuButtonItem {export function DeleteRangeMoveLeftMenuItemFactory(): IMenuButtonItem {return {- id: DeleteRangeMoveLeftCommand.id,+ id: DeleteRangeMoveLeftConfirmCommand.id,group: MenuGroup.CONTEXT_MENU_LAYOUT,type: MenuItemType.BUTTON,title: 'rightClick.moveLeft',@@ -72,7 +69,7 @@ export function DeleteRangeMoveLeftMenuItemFactory(): IMenuButtonItem {export function DeleteRangeMoveUpMenuItemFactory(): IMenuButtonItem {return {- id: DeleteRangeMoveUpCommand.id,+ id: DeleteRangeMoveUpConfirmCommand.id,group: MenuGroup.CONTEXT_MENU_LAYOUT,type: MenuItemType.BUTTON,title: 'rightClick.moveUp',diff --git a/packages/sheets-ui/src/controllers/menu/insert.menu.ts b/packages/sheets-ui/src/controllers/menu/insert.menu.tsindex 59381f029e..d816130c64 100644--- a/packages/sheets-ui/src/controllers/menu/insert.menu.ts+++ b/packages/sheets-ui/src/controllers/menu/insert.menu.ts@@ -17,8 +17,6 @@import {InsertColAfterCommand,InsertColBeforeCommand,- InsertRangeMoveDownCommand,- InsertRangeMoveRightCommand,InsertRowAfterCommand,InsertRowBeforeCommand,SelectionManagerService,@@ -28,6 +26,8 @@ import { MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';import type { IAccessor } from '@wendellhu/redi';import { Observable } from 'rxjs';+import { InsertRangeMoveRightConfirmCommand } from '../../commands/commands/insert-range-move-right-confirm.command';+import { InsertRangeMoveDownConfirmCommand } from '../../commands/commands/insert-range-move-up-confirm.command';import { SheetMenuPosition } from './menu';const COL_INSERT_MENU_ID = 'sheet.menu.col-insert';@@ -131,7 +131,7 @@ export function InsertColAfterMenuItemFactory(accessor: IAccessor): IMenuButtonIexport function InsertRangeMoveRightMenuItemFactory(): IMenuButtonItem {return {- id: InsertRangeMoveRightCommand.id,+ id: InsertRangeMoveRightConfirmCommand.id,type: MenuItemType.BUTTON,title: 'rightClick.moveRight',icon: 'InsertCellShiftRight',@@ -141,7 +141,7 @@ export function InsertRangeMoveRightMenuItemFactory(): IMenuButtonItem {export function InsertRangeMoveDownMenuItemFactory(): IMenuButtonItem {return {- id: InsertRangeMoveDownCommand.id,+ id: InsertRangeMoveDownConfirmCommand.id,type: MenuItemType.BUTTON,title: 'rightClick.moveDown',icon: 'InsertCellDown',diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.tsindex c82f6ef9e2..c27ed56069 100644--- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts+++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts@@ -34,6 +34,8 @@ import {AddWorksheetMergeHorizontalCommand,AddWorksheetMergeVerticalCommand,} from '../commands/commands/add-worksheet-merge.command';+import { DeleteRangeMoveUpConfirmCommand } from '../commands/commands/delete-range-move-down-confirm.command';+import { DeleteRangeMoveLeftConfirmCommand } from '../commands/commands/delete-range-move-left-confirm.command ';import {SetRangeBoldCommand,SetRangeFontFamilyCommand,@@ -45,6 +47,8 @@ import {SetRangeTextColorCommand,SetRangeUnderlineCommand,} from '../commands/commands/inline-format.command';+import { InsertRangeMoveRightConfirmCommand } from '../commands/commands/insert-range-move-right-confirm.command';+import { InsertRangeMoveDownConfirmCommand } from '../commands/commands/insert-range-move-up-confirm.command';import { RefillCommand } from '../commands/commands/refill.command';import { RemoveSheetConfirmCommand } from '../commands/commands/remove-sheet-confirm.command';import {@@ -281,6 +285,10 @@ export class SheetUIController extends Disposable {SetZoomRatioOperation,ShowMenuListCommand,RefillCommand,+ InsertRangeMoveDownConfirmCommand,+ DeleteRangeMoveUpConfirmCommand,+ InsertRangeMoveRightConfirmCommand,+ DeleteRangeMoveLeftConfirmCommand,].forEach((c) => {this.disposeWithMe(this._commandService.registerCommand(c));});diff --git a/packages/sheets-ui/src/locale/en-US.ts b/packages/sheets-ui/src/locale/en-US.tsindex b17f2895b5..698c443a76 100644--- a/packages/sheets-ui/src/locale/en-US.ts+++ b/packages/sheets-ui/src/locale/en-US.ts@@ -401,6 +401,8 @@ export default {title: 'Continue merging would only keep the upper-left cell value, discard other values. Are you sure to continue?',cancel: 'Cancel merging',confirm: 'Continue merging',+ waring: 'Waring',+ dismantleMergeCellWaring: 'This will cause some merged cells to be split. Do you want to continue?',},},textWrap: {diff --git a/packages/sheets-ui/src/locale/zh-CN.ts b/packages/sheets-ui/src/locale/zh-CN.tsindex ba3518aa2a..33251f7740 100644--- a/packages/sheets-ui/src/locale/zh-CN.ts+++ b/packages/sheets-ui/src/locale/zh-CN.ts@@ -265,6 +265,8 @@ export default {title: '合并单元格仅保存左上角单元格的值,是否继续?',cancel: '取消合并',confirm: '继续合并',+ waring: '警告',+ dismantleMergeCellWaring: '此操作会导致一些合并单元格被拆散,是否继续?',},},textWrap: {