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(drawing): add drawing group/arrange/align context menu (#6678)
wpxp123456275d2f9fd2c7
diff --git a/packages/drawing-ui/src/commands/operations/drawing-align.operation.ts b/packages/drawing-ui/src/commands/operations/drawing-align.operation.tsindex e253838a3a..626c365209 100644--- a/packages/drawing-ui/src/commands/operations/drawing-align.operation.ts+++ b/packages/drawing-ui/src/commands/operations/drawing-align.operation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IOperation } from '@univerjs/core';-import { CommandType } from '@univerjs/core';+import type { IDrawingParam, IOperation } from '@univerjs/core';+import { CommandType, ICommandService } from '@univerjs/core';export enum AlignType {default = '0',@@ -31,8 +31,12 @@ export enum AlignType {export interface ISetDrawingAlignOperationParams {alignType: AlignType;+ drawings?: IDrawingParam[];}+/**+ * Set drawing align operation, including left, center, right, top, middle, bottom, horizon and vertical align.+ */export const SetDrawingAlignOperation: IOperation<ISetDrawingAlignOperationParams> = {id: 'sheet.operation.set-image-align',type: CommandType.OPERATION,@@ -40,3 +44,67 @@ export const SetDrawingAlignOperation: IOperation<ISetDrawingAlignOperationParamreturn true;},};++export const SetDrawingAlignLeftOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-left',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.left });+ },+};++export const SetDrawingAlignCenterOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-center',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.center });+ },+};++export const SetDrawingAlignRightOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-right',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.right });+ },+};++export const SetDrawingAlignTopOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-top',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.top });+ },+};++export const SetDrawingAlignMiddleOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-middle',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.middle });+ },+};++export const SetDrawingAlignBottomOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-bottom',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.bottom });+ },+};++export const SetDrawingAlignHorizonOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-horizon',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.horizon });+ },+};++export const SetDrawingAlignVerticalOperation: IOperation = {+ id: 'sheet.operation.set-drawing-align-vertical',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.vertical });+ },+};diff --git a/packages/drawing-ui/src/commands/operations/drawing-arrange.operation.ts b/packages/drawing-ui/src/commands/operations/drawing-arrange.operation.tsnew file mode 100644index 0000000000..28dcb81f69--- /dev/null+++ b/packages/drawing-ui/src/commands/operations/drawing-arrange.operation.ts@@ -0,0 +1,77 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { IDrawingParam, IOperation } from '@univerjs/core';+import { ArrangeTypeEnum, CommandType, ICommandService } from '@univerjs/core';+import { IDrawingManagerService } from '@univerjs/drawing';++export interface IDrawingArrangeOperationParams {+ arrangeType: ArrangeTypeEnum;+ drawings?: IDrawingParam[];+}++/**+ * Set the layer of the drawing, including forward, backward, front, and back+ */+export const SetDrawingArrangeOperation: IOperation<IDrawingArrangeOperationParams> = {+ id: 'drawing.operation.set-drawing-arrange',+ type: CommandType.OPERATION,+ handler: (accessor, params) => {+ const drawingManagerService = accessor.get(IDrawingManagerService);++ const { arrangeType } = params;+ const drawings = params.drawings || drawingManagerService.getFocusDrawings();++ const { unitId, subUnitId } = drawings[0];+ const drawingIds = drawings.map((drawing) => drawing.drawingId);++ drawingManagerService.featurePluginOrderUpdateNotification({ unitId, subUnitId, drawingIds, arrangeType });++ return true;+ },+};++export const SetDrawingArrangeFrontOperation: IOperation = {+ id: 'drawing.operation.set-drawing-arrange-front',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.front });+ },+};++export const SetDrawingArrangeForwardOperation: IOperation = {+ id: 'drawing.operation.set-drawing-arrange-forward',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.forward });+ },+};++export const SetDrawingArrangeBackOperation: IOperation = {+ id: 'drawing.operation.set-drawing-arrange-back',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.back });+ },+};++export const SetDrawingArrangeBackwardOperation: IOperation = {+ id: 'drawing.operation.set-drawing-arrange-backward',+ type: CommandType.OPERATION,+ handler: (accessor) => {+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.backward });+ },+};diff --git a/packages/drawing-ui/src/commands/operations/drawing-group.operation.ts b/packages/drawing-ui/src/commands/operations/drawing-group.operation.tsnew file mode 100644index 0000000000..821255c407--- /dev/null+++ b/packages/drawing-ui/src/commands/operations/drawing-group.operation.ts@@ -0,0 +1,141 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { IDrawingParam, IOperation } from '@univerjs/core';+import type { IDrawingGroupUpdateParam } from '@univerjs/drawing';+import { CommandType, DrawingTypeEnum, generateRandomId } from '@univerjs/core';+import { IDrawingManagerService } from '@univerjs/drawing';+import { getGroupState, transformObjectOutOfGroup } from '@univerjs/engine-render';++/**+ * Now only support grouping images, shapes, and groups.+ */+export const DRAWING_GROUP_TYPES = [DrawingTypeEnum.DRAWING_IMAGE, DrawingTypeEnum.DRAWING_SHAPE, DrawingTypeEnum.DRAWING_GROUP];++export interface IDrawingGroupOperationParams {+ drawings?: IDrawingParam[];+}++/**+ * Group the selected drawings into a new group. The selected drawings must be of type image, shape, or group, and there must be at least 2 drawings selected.+ */+export const SetDrawingGroupOperation: IOperation<IDrawingGroupOperationParams> = {+ id: 'drawing.operation.set-drawing-group',+ type: CommandType.OPERATION,+ handler: (accessor, params) => {+ const drawingManagerService = accessor.get(IDrawingManagerService);+ const drawings = params.drawings || drawingManagerService.getFocusDrawings();++ if (drawings.length < 2) return false;+ if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return false;++ const { unitId, subUnitId } = drawings[0];++ const groupId = generateRandomId(10);+ const groupTransform = getGroupState(0, 0, drawings.map((o) => o.transform || {}));+ const groupParam = {+ unitId,+ subUnitId,+ drawingId: groupId,+ drawingType: DrawingTypeEnum.DRAWING_GROUP,+ transform: groupTransform,+ groupBaseBound: {+ left: groupTransform.left,+ top: groupTransform.top,+ width: groupTransform.width,+ height: groupTransform.height,+ },+ } as IDrawingParam;++ const children = drawings.map((drawing) => {+ const transform = drawing.transform || { left: 0, top: 0 };+ const { unitId, subUnitId, drawingId } = drawing;+ return {+ unitId,+ subUnitId,+ drawingId,+ transform: {+ ...transform,+ // left: transform.left! - groupTransform.left,+ // top: transform.top! - groupTransform.top,+ },+ groupId,+ };+ }) as IDrawingParam[];++ drawingManagerService.featurePluginGroupUpdateNotification([{+ parent: groupParam,+ children,+ }]);++ return true;+ },+};++export interface ICancelDrawingGroupOperationParams {+ drawings?: IDrawingParam[];+}++/**+ * Ungroup the selected groups. The selected drawings must be at least 1 group selected.+ */+export const CancelDrawingGroupOperation: IOperation<ICancelDrawingGroupOperationParams> = {+ id: 'drawing.operation.cancel-drawing-group',+ type: CommandType.OPERATION,+ handler: (accessor, params) => {+ const drawingManagerService = accessor.get(IDrawingManagerService);+ const drawings = params.drawings || drawingManagerService.getFocusDrawings();++ const groupParams = drawings+ .map((drawing) => {+ if (drawing.drawingType !== DrawingTypeEnum.DRAWING_GROUP) return null;++ const { unitId, subUnitId, drawingId, transform: groupTransform = { width: 0, height: 0 }, groupBaseBound } = drawing;+ if (groupTransform === null) return null;++ const objects = drawingManagerService.getDrawingsByGroup({ unitId, subUnitId, drawingId });+ if (objects.length === 0) return null;++ const children = objects.map((object) => {+ const { transform } = object;+ const { unitId, subUnitId, drawingId } = object;+ const newTransform = transformObjectOutOfGroup(transform || {}, groupTransform, groupTransform.width || 0, groupTransform.height || 0, groupBaseBound);+ return {+ unitId,+ subUnitId,+ drawingId,+ transform: {+ ...transform,+ ...newTransform,+ },+ groupId: undefined,+ };+ });++ return {+ parent: drawing,+ children,+ } as IDrawingGroupUpdateParam;+ })+ .filter((o) => o !== null);++ if (groupParams.length === 0) return false;++ drawingManagerService.featurePluginUngroupUpdateNotification(groupParams);++ return true;+ },+};diff --git a/packages/drawing-ui/src/controllers/__tests__/drawing-ui.controller.spec.ts b/packages/drawing-ui/src/controllers/__tests__/drawing-ui.controller.spec.tsindex aaf2daa936..aa067baf84 100644--- a/packages/drawing-ui/src/controllers/__tests__/drawing-ui.controller.spec.ts+++ b/packages/drawing-ui/src/controllers/__tests__/drawing-ui.controller.spec.ts@@ -15,7 +15,7 @@*/import type { ICommandService } from '@univerjs/core';-import type { ComponentManager } from '@univerjs/ui';+import type { ComponentManager, IMenuManagerService } from '@univerjs/ui';import { describe, expect, it, vi } from 'vitest';import { COMPONENT_IMAGE_POPUP_MENU } from '../../views/image-popup-menu/component-name';import { DrawingUIController } from '../drawing-ui.controller';@@ -24,14 +24,16 @@ describe('DrawingUIController', () => {it('registers popup components and drawing operations', () => {const register = vi.fn(() => ({ dispose: vi.fn() }));const registerCommand = vi.fn(() => ({ dispose: vi.fn() }));+ const mergeMenu = vi.fn();const controller = new DrawingUIController({ register } as unknown as ComponentManager,- { registerCommand } as unknown as ICommandService+ { registerCommand } as unknown as ICommandService,+ { mergeMenu } as unknown as IMenuManagerService);expect(controller).toBeTruthy();- expect(registerCommand).toHaveBeenCalledTimes(5);+ expect(registerCommand).toHaveBeenCalledTimes(20);expect(register).toHaveBeenCalledWith(COMPONENT_IMAGE_POPUP_MENU, expect.any(Function));});});diff --git a/packages/drawing-ui/src/controllers/drawing-ui.controller.ts b/packages/drawing-ui/src/controllers/drawing-ui.controller.tsindex f61e6ef0ad..781708ed33 100644--- a/packages/drawing-ui/src/controllers/drawing-ui.controller.ts+++ b/packages/drawing-ui/src/controllers/drawing-ui.controller.ts@@ -15,26 +15,52 @@*/import { Disposable, ICommandService, Inject } from '@univerjs/core';-import { ComponentManager } from '@univerjs/ui';-import { SetDrawingAlignOperation } from '../commands/operations/drawing-align.operation';+import { BottomIcon, GroupIcon, MoveDownIcon, MoveUpIcon, TopmostIcon, UngroupIcon } from '@univerjs/icons';+import { ComponentManager, IMenuManagerService } from '@univerjs/ui';+import {+ SetDrawingAlignBottomOperation,+ SetDrawingAlignCenterOperation,+ SetDrawingAlignHorizonOperation,+ SetDrawingAlignLeftOperation,+ SetDrawingAlignMiddleOperation,+ SetDrawingAlignOperation,+ SetDrawingAlignRightOperation,+ SetDrawingAlignTopOperation,+ SetDrawingAlignVerticalOperation,+} from '../commands/operations/drawing-align.operation';+import {+ SetDrawingArrangeBackOperation,+ SetDrawingArrangeBackwardOperation,+ SetDrawingArrangeForwardOperation,+ SetDrawingArrangeFrontOperation,+ SetDrawingArrangeOperation,+} from '../commands/operations/drawing-arrange.operation';+import { CancelDrawingGroupOperation, SetDrawingGroupOperation } from '../commands/operations/drawing-group.operation';import { AutoImageCropOperation, CloseImageCropOperation, OpenImageCropOperation } from '../commands/operations/image-crop.operation';import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';+import { menuSchema } from '../menu/schema';import { COMPONENT_IMAGE_POPUP_MENU } from '../views/image-popup-menu/component-name';import { ImagePopupMenu } from '../views/image-popup-menu/ImagePopupMenu';export class DrawingUIController extends Disposable {constructor(@Inject(ComponentManager) private readonly _componentManager: ComponentManager,- @ICommandService private readonly _commandService: ICommandService+ @ICommandService private readonly _commandService: ICommandService,+ @IMenuManagerService private readonly _menuManagerService: IMenuManagerService) {super();this._init();}- private _initCustomComponents(): void {- const componentManager = this._componentManager;- this.disposeWithMe(componentManager.register(COMPONENT_IMAGE_POPUP_MENU, ImagePopupMenu));+ private _init(): void {+ this._initMenus();+ this._initCommands();+ this._initComponents();+ }++ private _initMenus(): void {+ this._menuManagerService.mergeMenu(menuSchema);}private _initCommands() {@@ -43,12 +69,36 @@ export class DrawingUIController extends Disposable {CloseImageCropOperation,ImageResetSizeOperation,SetDrawingAlignOperation,+ SetDrawingAlignLeftOperation,+ SetDrawingAlignCenterOperation,+ SetDrawingAlignRightOperation,+ SetDrawingAlignTopOperation,+ SetDrawingAlignMiddleOperation,+ SetDrawingAlignBottomOperation,+ SetDrawingAlignHorizonOperation,+ SetDrawingAlignVerticalOperation,AutoImageCropOperation,+ SetDrawingGroupOperation,+ CancelDrawingGroupOperation,+ SetDrawingArrangeOperation,+ SetDrawingArrangeFrontOperation,+ SetDrawingArrangeForwardOperation,+ SetDrawingArrangeBackOperation,+ SetDrawingArrangeBackwardOperation,].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}- private _init(): void {- this._initCommands();- this._initCustomComponents();+ private _initComponents(): void {+ ([+ [COMPONENT_IMAGE_POPUP_MENU, ImagePopupMenu],+ ['BottomIcon', BottomIcon],+ ['GroupIcon', GroupIcon],+ ['MoveDownIcon', MoveDownIcon],+ ['MoveUpIcon', MoveUpIcon],+ ['TopmostIcon', TopmostIcon],+ ['UngroupIcon', UngroupIcon],+ ] as const).forEach(([key, component]) => {+ this.disposeWithMe(this._componentManager.register(key, component));+ });}}diff --git a/packages/drawing-ui/src/controllers/drawing-update.controller.ts b/packages/drawing-ui/src/controllers/drawing-update.controller.tsindex 440b60d444..555ac1d318 100644--- a/packages/drawing-ui/src/controllers/drawing-update.controller.ts+++ b/packages/drawing-ui/src/controllers/drawing-update.controller.ts@@ -373,7 +373,7 @@ export class DrawingUpdateController extends Disposable {private _drawingAlign(params: ISetDrawingAlignOperationParams) {const { alignType } = params;- const drawings = this._drawingManagerService.getFocusDrawings();+ const drawings = params.drawings || this._drawingManagerService.getFocusDrawings();if (alignType === AlignType.default) {return;diff --git a/packages/drawing-ui/src/index.ts b/packages/drawing-ui/src/index.tsindex 7b01ad20b4..6d0d0eba05 100644--- a/packages/drawing-ui/src/index.ts+++ b/packages/drawing-ui/src/index.ts@@ -17,6 +17,17 @@import './global.css';export { SetDrawingAlignOperation } from './commands/operations/drawing-align.operation';+export {+ type IDrawingArrangeOperationParams,+ SetDrawingArrangeOperation,+} from './commands/operations/drawing-arrange.operation';+export {+ CancelDrawingGroupOperation,+ DRAWING_GROUP_TYPES,+ type ICancelDrawingGroupOperationParams,+ type IDrawingGroupOperationParams,+ SetDrawingGroupOperation,+} from './commands/operations/drawing-group.operation';export { AutoImageCropOperation, CloseImageCropOperation, OpenImageCropOperation } from './commands/operations/image-crop.operation';export { ImageResetSizeOperation } from './commands/operations/image-reset-size.operation';export type { IUniverDrawingUIConfig } from './config/config';diff --git a/packages/drawing-ui/src/menu/align.menu.ts b/packages/drawing-ui/src/menu/align.menu.tsnew file mode 100644index 0000000000..989b28133d--- /dev/null+++ b/packages/drawing-ui/src/menu/align.menu.ts@@ -0,0 +1,144 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { IAccessor, IDrawingParam } from '@univerjs/core';+import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';+import { IDrawingManagerService } from '@univerjs/drawing';+import { MenuItemType } from '@univerjs/ui';+import { Observable } from 'rxjs';+import {+ SetDrawingAlignBottomOperation,+ SetDrawingAlignCenterOperation,+ SetDrawingAlignHorizonOperation,+ SetDrawingAlignLeftOperation,+ SetDrawingAlignMiddleOperation,+ SetDrawingAlignRightOperation,+ SetDrawingAlignTopOperation,+ SetDrawingAlignVerticalOperation,+} from '../commands/operations/drawing-align.operation';++const getMenuStateByDrawingFocusChangedObservable$ = (accessor: IAccessor): Observable<boolean> => {+ const drawingManagerService = accessor.get(IDrawingManagerService);++ return new Observable((subscriber) => {+ const update = (drawings: IDrawingParam[]) => {+ if (!drawings || drawings.length === 0) {+ return subscriber.next(true);+ }++ if (drawings.length < 2) {+ return subscriber.next(true);+ }++ subscriber.next(false);+ };++ const subscription = drawingManagerService.focus$.subscribe((drawings) => {+ if (!drawings || drawings.length === 0) {+ return subscriber.next(true);+ }++ update(drawings);+ });++ update(drawingManagerService.getFocusDrawings());++ return () => subscription.unsubscribe();+ });+};++export const DRAWING_ALIGN_CONTEXT_MENU_ID = 'contextMenu.drawing-align';+export function DrawingAlignContextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {+ return {+ id: DRAWING_ALIGN_CONTEXT_MENU_ID,+ type: MenuItemType.SUBITEMS,+ icon: 'HorizontallyIcon',+ title: 'image-panel.align.title',+ hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor),+ };+}++export function SetDrawingAlignLeftMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignLeftOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'LeftJustifyingIcon',+ title: 'image-panel.align.left',+ };+}++export function SetDrawingAlignCenterMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignCenterOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'HorizontallyIcon',+ title: 'image-panel.align.center',+ };+}++export function SetDrawingAlignRightMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignRightOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'RightJustifyingIcon',+ title: 'image-panel.align.right',+ };+}++export function SetDrawingAlignTopMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignTopOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'AlignTopIcon',+ title: 'image-panel.align.top',+ };+}++export function SetDrawingAlignMiddleMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignMiddleOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'VerticalCenterIcon',+ title: 'image-panel.align.middle',+ };+}++export function SetDrawingAlignBottomMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignBottomOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'AlignBottomIcon',+ title: 'image-panel.align.bottom',+ };+}++export function SetDrawingAlignHorizonMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignHorizonOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'HorizontallyIcon',+ title: 'image-panel.align.horizon',+ };+}++export function SetDrawingAlignVerticalMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingAlignVerticalOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'VerticalCenterIcon',+ title: 'image-panel.align.vertical',+ };+}diff --git a/packages/drawing-ui/src/menu/arrange.menu.ts b/packages/drawing-ui/src/menu/arrange.menu.tsnew file mode 100644index 0000000000..064b5bec11--- /dev/null+++ b/packages/drawing-ui/src/menu/arrange.menu.ts@@ -0,0 +1,70 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';+import { MenuItemType } from '@univerjs/ui';+import {+ SetDrawingArrangeBackOperation,+ SetDrawingArrangeBackwardOperation,+ SetDrawingArrangeForwardOperation,+ SetDrawingArrangeFrontOperation,+} from '../commands/operations/drawing-arrange.operation';++export const DRAWING_ARRANGE_CONTEXT_MENU_ID = 'contextMenu.drawing-arrange';+export function DrawingArrangeContextMenuItemFactory(): IMenuSelectorItem<string> {+ return {+ id: DRAWING_ARRANGE_CONTEXT_MENU_ID,+ type: MenuItemType.SUBITEMS,+ icon: 'TopmostIcon',+ title: 'image-panel.arrange.title',+ };+}++export function SetDrawingArrangeFrontMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingArrangeFrontOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'TopmostIcon',+ title: 'image-panel.arrange.front',+ };+}++export function SetDrawingArrangeForwardMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingArrangeForwardOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'MoveUpIcon',+ title: 'image-panel.arrange.forward',+ };+}++export function SetDrawingArrangeBackMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingArrangeBackOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'BottomIcon',+ title: 'image-panel.arrange.back',+ };+}++export function SetDrawingArrangeBackwardMenuItemFactory(): IMenuButtonItem {+ return {+ id: SetDrawingArrangeBackwardOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'MoveDownIcon',+ title: 'image-panel.arrange.backward',+ };+}diff --git a/packages/drawing-ui/src/menu/group.menu.ts b/packages/drawing-ui/src/menu/group.menu.tsnew file mode 100644index 0000000000..dc11e8e2bf--- /dev/null+++ b/packages/drawing-ui/src/menu/group.menu.ts@@ -0,0 +1,103 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { IAccessor, IDrawingParam } from '@univerjs/core';+import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';+import { DrawingTypeEnum } from '@univerjs/core';+import { IDrawingManagerService } from '@univerjs/drawing';+import { MenuItemType } from '@univerjs/ui';+import { Observable } from 'rxjs';+import { CancelDrawingGroupOperation, DRAWING_GROUP_TYPES, SetDrawingGroupOperation } from '../commands/operations/drawing-group.operation';++const getMenuStateByDrawingFocusChangedObservable$ = (accessor: IAccessor, type?: 'group' | 'unGroup'): Observable<boolean> => {+ const drawingManagerService = accessor.get(IDrawingManagerService);++ return new Observable((subscriber) => {+ const update = (drawings: IDrawingParam[]) => {+ if (!drawings || drawings.length === 0) {+ return subscriber.next(true);+ }++ if (type === 'group') {+ // If there are less than 2 drawings that can be grouped, disable the group button+ if (drawings.length < 2) {+ return subscriber.next(true);+ }++ if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) {+ return subscriber.next(true);+ }+ } else if (type === 'unGroup') {+ // If there are no groups, disable the unGroup button+ const groups = drawings.filter((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP);++ if (groups.length === 0) {+ return subscriber.next(true);+ }+ } else {+ // If there are drawings that cannot be grouped or ungrouped, hide the context menu+ if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) {+ return subscriber.next(true);+ }+ }++ subscriber.next(false);+ };++ const subscription = drawingManagerService.focus$.subscribe((drawings) => {+ if (!drawings || drawings.length === 0) {+ return subscriber.next(true);+ }++ update(drawings);+ });++ update(drawingManagerService.getFocusDrawings());++ return () => subscription.unsubscribe();+ });+};++export const DRAWING_GROUP_CONTEXT_MENU_ID = 'contextMenu.drawing-group';+export function DrawingGroupContextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {+ return {+ id: DRAWING_GROUP_CONTEXT_MENU_ID,+ type: MenuItemType.SUBITEMS,+ icon: 'GroupIcon',+ title: 'image-panel.group.title',+ hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor),+ };+}++export function SetDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButtonItem {+ return {+ id: SetDrawingGroupOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'GroupIcon',+ title: 'image-panel.group.group',+ disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, 'group'),+ };+}++export function CancelDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButtonItem {+ return {+ id: CancelDrawingGroupOperation.id,+ type: MenuItemType.BUTTON,+ icon: 'UngroupIcon',+ title: 'image-panel.group.unGroup',+ disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, 'unGroup'),+ };+}diff --git a/packages/drawing-ui/src/menu/schema.ts b/packages/drawing-ui/src/menu/schema.tsnew file mode 100644index 0000000000..2b1037d304--- /dev/null+++ b/packages/drawing-ui/src/menu/schema.ts@@ -0,0 +1,136 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { MenuSchemaType } from '@univerjs/ui';+import { ContextMenuGroup, ContextMenuPosition } from '@univerjs/ui';+import {+ SetDrawingAlignBottomOperation,+ SetDrawingAlignCenterOperation,+ SetDrawingAlignHorizonOperation,+ SetDrawingAlignLeftOperation,+ SetDrawingAlignMiddleOperation,+ SetDrawingAlignRightOperation,+ SetDrawingAlignTopOperation,+ SetDrawingAlignVerticalOperation,+} from '../commands/operations/drawing-align.operation';+import {+ SetDrawingArrangeBackOperation,+ SetDrawingArrangeBackwardOperation,+ SetDrawingArrangeForwardOperation,+ SetDrawingArrangeFrontOperation,+} from '../commands/operations/drawing-arrange.operation';+import { CancelDrawingGroupOperation, SetDrawingGroupOperation } from '../commands/operations/drawing-group.operation';+import {+ DRAWING_ALIGN_CONTEXT_MENU_ID,+ DrawingAlignContextMenuItemFactory,+ SetDrawingAlignBottomMenuItemFactory,+ SetDrawingAlignCenterMenuItemFactory,+ SetDrawingAlignHorizonMenuItemFactory,+ SetDrawingAlignLeftMenuItemFactory,+ SetDrawingAlignMiddleMenuItemFactory,+ SetDrawingAlignRightMenuItemFactory,+ SetDrawingAlignTopMenuItemFactory,+ SetDrawingAlignVerticalMenuItemFactory,+} from './align.menu';+import {+ DRAWING_ARRANGE_CONTEXT_MENU_ID,+ DrawingArrangeContextMenuItemFactory,+ SetDrawingArrangeBackMenuItemFactory,+ SetDrawingArrangeBackwardMenuItemFactory,+ SetDrawingArrangeForwardMenuItemFactory,+ SetDrawingArrangeFrontMenuItemFactory,+} from './arrange.menu';+import {+ CancelDrawingGroupMenuItemFactory,+ DRAWING_GROUP_CONTEXT_MENU_ID,+ DrawingGroupContextMenuItemFactory,+ SetDrawingGroupMenuItemFactory,+} from './group.menu';++export const menuSchema: MenuSchemaType = {+ [ContextMenuPosition.DRAWING]: {+ [ContextMenuGroup.OTHERS]: {+ [DRAWING_GROUP_CONTEXT_MENU_ID]: {+ order: 1,+ menuItemFactory: DrawingGroupContextMenuItemFactory,+ [SetDrawingGroupOperation.id]: {+ order: 0,+ menuItemFactory: SetDrawingGroupMenuItemFactory,+ },+ [CancelDrawingGroupOperation.id]: {+ order: 1,+ menuItemFactory: CancelDrawingGroupMenuItemFactory,+ },+ },+ [DRAWING_ARRANGE_CONTEXT_MENU_ID]: {+ order: 2,+ menuItemFactory: DrawingArrangeContextMenuItemFactory,+ [SetDrawingArrangeFrontOperation.id]: {+ order: 0,+ menuItemFactory: SetDrawingArrangeFrontMenuItemFactory,+ },+ [SetDrawingArrangeForwardOperation.id]: {+ order: 1,+ menuItemFactory: SetDrawingArrangeForwardMenuItemFactory,+ },+ [SetDrawingArrangeBackOperation.id]: {+ order: 2,+ menuItemFactory: SetDrawingArrangeBackMenuItemFactory,+ },+ [SetDrawingArrangeBackwardOperation.id]: {+ order: 3,+ menuItemFactory: SetDrawingArrangeBackwardMenuItemFactory,+ },+ },+ [DRAWING_ALIGN_CONTEXT_MENU_ID]: {+ order: 3,+ menuItemFactory: DrawingAlignContextMenuItemFactory,+ [SetDrawingAlignLeftOperation.id]: {+ order: 0,+ menuItemFactory: SetDrawingAlignLeftMenuItemFactory,+ },+ [SetDrawingAlignCenterOperation.id]: {+ order: 1,+ menuItemFactory: SetDrawingAlignCenterMenuItemFactory,+ },+ [SetDrawingAlignRightOperation.id]: {+ order: 2,+ menuItemFactory: SetDrawingAlignRightMenuItemFactory,+ },+ [SetDrawingAlignTopOperation.id]: {+ order: 3,+ menuItemFactory: SetDrawingAlignTopMenuItemFactory,+ },+ [SetDrawingAlignMiddleOperation.id]: {+ order: 4,+ menuItemFactory: SetDrawingAlignMiddleMenuItemFactory,+ },+ [SetDrawingAlignBottomOperation.id]: {+ order: 5,+ menuItemFactory: SetDrawingAlignBottomMenuItemFactory,+ },+ [SetDrawingAlignHorizonOperation.id]: {+ order: 6,+ menuItemFactory: SetDrawingAlignHorizonMenuItemFactory,+ },+ [SetDrawingAlignVerticalOperation.id]: {+ order: 7,+ menuItemFactory: SetDrawingAlignVerticalMenuItemFactory,+ },+ },+ },+ },+};diff --git a/packages/drawing-ui/src/views/panel/DrawingAlign.tsx b/packages/drawing-ui/src/views/panel/DrawingAlign.tsxindex bcf8b9915b..8abb50cc3d 100644--- a/packages/drawing-ui/src/views/panel/DrawingAlign.tsx+++ b/packages/drawing-ui/src/views/panel/DrawingAlign.tsx@@ -30,7 +30,7 @@ export const DrawingAlign = (props: IDrawingAlignProps) => {const commandService = useDependency(ICommandService);const localeService = useDependency(LocaleService);- const { alignShow } = props;+ const { drawings, alignShow } = props;const [alignValue, setAlignValue] = useState<string>(AlignType.default as string);const alignOptions = [@@ -88,6 +88,7 @@ export const DrawingAlign = (props: IDrawingAlignProps) => {setAlignValue((value as string));commandService.executeCommand(SetDrawingAlignOperation.id, {alignType: value as AlignType,+ drawings,});}diff --git a/packages/drawing-ui/src/views/panel/DrawingArrange.tsx b/packages/drawing-ui/src/views/panel/DrawingArrange.tsxindex f97969a2fe..2b8055ac7f 100644--- a/packages/drawing-ui/src/views/panel/DrawingArrange.tsx+++ b/packages/drawing-ui/src/views/panel/DrawingArrange.tsx@@ -15,12 +15,12 @@*/import type { IDrawingParam } from '@univerjs/core';-import { ArrangeTypeEnum, LocaleService } from '@univerjs/core';+import { ArrangeTypeEnum, ICommandService, LocaleService } from '@univerjs/core';import { Button, clsx } from '@univerjs/design';import { IDrawingManagerService } from '@univerjs/drawing';-import { BottomIcon, MoveDownIcon, MoveUpIcon, TopmostIcon } from '@univerjs/icons';-import { useDependency } from '@univerjs/ui';+import { ComponentManager, useDependency } from '@univerjs/ui';import { useEffect, useState } from 'react';+import { SetDrawingArrangeOperation } from '../../commands/operations/drawing-arrange.operation';export interface IDrawingArrangeProps {arrangeShow: boolean;@@ -32,6 +32,13 @@ export const DrawingArrange = (props: IDrawingArrangeProps) => {const localeService = useDependency(LocaleService);const drawingManagerService = useDependency(IDrawingManagerService);+ const commandService = useDependency(ICommandService);+ const componentManager = useDependency(ComponentManager);++ const MoveUpIcon = componentManager.get('MoveUpIcon');+ const MoveDownIcon = componentManager.get('MoveDownIcon');+ const TopmostIcon = componentManager.get('TopmostIcon');+ const BottomIcon = componentManager.get('BottomIcon');const [drawings, setDrawings] = useState<IDrawingParam[]>(focusDrawings);@@ -46,11 +53,7 @@ export const DrawingArrange = (props: IDrawingArrangeProps) => {}, []);const onArrangeBtnClick = (arrangeType: ArrangeTypeEnum) => {- const unitId = drawings[0].unitId;- const subUnitId = drawings[0].subUnitId;- const drawingIds = drawings.map((drawing) => drawing.drawingId);-- drawingManagerService.featurePluginOrderUpdateNotification({ unitId, subUnitId, drawingIds, arrangeType });+ commandService.syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType, drawings });};return (diff --git a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx b/packages/drawing-ui/src/views/panel/DrawingGroup.tsxindex b2bfcde349..2af32b3a80 100644--- a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx+++ b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx@@ -15,14 +15,13 @@*/import type { IDrawingParam } from '@univerjs/core';-import type { IDrawingGroupUpdateParam } from '@univerjs/drawing';-import { DrawingTypeEnum, generateRandomId, LocaleService } from '@univerjs/core';+import { DrawingTypeEnum, ICommandService, LocaleService } from '@univerjs/core';import { Button, clsx } from '@univerjs/design';import { IDrawingManagerService } from '@univerjs/drawing';-import { getGroupState, IRenderManagerService, transformObjectOutOfGroup } from '@univerjs/engine-render';-import { GroupIcon, UngroupIcon } from '@univerjs/icons';-import { useDependency } from '@univerjs/ui';+import { IRenderManagerService } from '@univerjs/engine-render';+import { ComponentManager, useDependency } from '@univerjs/ui';import { useEffect, useState } from 'react';+import { CancelDrawingGroupOperation, SetDrawingGroupOperation } from '../../commands/operations/drawing-group.operation';import { getUpdateParams } from '../../utils/get-update-params';export interface IDrawingGroupProps {@@ -34,114 +33,25 @@ export const DrawingGroup = (props: IDrawingGroupProps) => {const localeService = useDependency(LocaleService);const renderManagerService = useDependency(IRenderManagerService);const drawingManagerService = useDependency(IDrawingManagerService);+ const commandService = useDependency(ICommandService);+ const componentManager = useDependency(ComponentManager);const { hasGroup, drawings } = props;+ const GroupIcon = componentManager.get('GroupIcon');+ const UngroupIcon = componentManager.get('UngroupIcon');const [groupShow, setGroupShow] = useState(false);-const [groupBtnShow, setGroupBtnShow] = useState(true);const [ungroupBtnShow, setUngroupBtnShow] = useState(true);const onGroupBtnClick = () => {- const focusDrawings = drawingManagerService.getFocusDrawings();- if (focusDrawings.length <= 1) {- return;- }- const { unitId, subUnitId } = focusDrawings[0];- const groupId = generateRandomId(10);- const groupTransform = getGroupState(0, 0, focusDrawings.map((o) => o.transform || {}));- const groupParam = {- unitId,- subUnitId,- drawingId: groupId,- drawingType: DrawingTypeEnum.DRAWING_GROUP,- transform: groupTransform,- groupBaseBound: {- left: groupTransform.left,- top: groupTransform.top,- width: groupTransform.width,- height: groupTransform.height,- },- } as IDrawingParam;-- const children = focusDrawings.map((drawing) => {- const transform = drawing.transform || { left: 0, top: 0 };- const { unitId, subUnitId, drawingId } = drawing;- return {- unitId,- subUnitId,- drawingId,- transform: {- ...transform,- // left: transform.left! - groupTransform.left,- // top: transform.top! - groupTransform.top,- },- groupId,- };- }) as IDrawingParam[];-- drawingManagerService.featurePluginGroupUpdateNotification([{- parent: groupParam,- children,- }]);- };-- const ungroup = (param: IDrawingParam) => {- if (param.drawingType !== DrawingTypeEnum.DRAWING_GROUP) {- return;- }-- const { unitId, subUnitId, drawingId, transform: groupTransform = { width: 0, height: 0 }, groupBaseBound } = param;-- if (groupTransform == null) {- return;- }-- const objects = drawingManagerService.getDrawingsByGroup({ unitId, subUnitId, drawingId });-- if (objects.length === 0) {- return;- }-- const children = objects.map((object) => {- const { transform } = object;- const { unitId, subUnitId, drawingId } = object;- const newTransform = transformObjectOutOfGroup(transform || {}, groupTransform, groupTransform.width || 0, groupTransform.height || 0, groupBaseBound);- return {- unitId,- subUnitId,- drawingId,- transform: {- ...transform,- ...newTransform,- },- groupId: undefined,- };- });-- return {- parent: param,- children,- } as IDrawingGroupUpdateParam;+ commandService.syncExecuteCommand(SetDrawingGroupOperation.id, { drawings });};const onUngroupBtnClick = () => {- const focusDrawings = drawingManagerService.getFocusDrawings();- const params = focusDrawings.map((drawing) =>- ungroup(drawing)- ).filter((o) => o != null) as IDrawingGroupUpdateParam[];-- if (params.length === 0) {- return;- }-- drawingManagerService.featurePluginUngroupUpdateNotification(params);+ commandService.syncExecuteCommand(CancelDrawingGroupOperation.id, { drawings });};- useEffect(() => {- setGroupShow(hasGroup);- }, [hasGroup]);-useEffect(() => {const drawingParam = drawings[0];diff --git a/packages/engine-render/src/scene.transformer.ts b/packages/engine-render/src/scene.transformer.tsindex 15a59e5b25..9818094e98 100644--- a/packages/engine-render/src/scene.transformer.ts+++ b/packages/engine-render/src/scene.transformer.ts@@ -170,7 +170,7 @@ export class Transformer extends Disposable implements ITransformerConfig {private readonly _changing$ = new Subject<IChangeObserverConfig>();readonly changing$ = this._changing$.asObservable();- private readonly _changeEnd$ = new Subject<IChangeObserverConfig>();+ private readonly _changeEnd$ = new Subject<IChangeObserverConfig & { event: IPointerEvent | IMouseEvent }>();readonly changeEnd$ = this._changeEnd$.asObservable();private readonly _clearControl$ = new Subject<boolean>();@@ -466,6 +466,7 @@ export class Transformer extends Disposable implements ITransformerConfig {type: MoveObserverType.MOVE_END,offsetX,offsetY,+ event,});} else {this._changeEnd$.next({@@ -473,6 +474,7 @@ export class Transformer extends Disposable implements ITransformerConfig {type: MoveObserverType.MOVE_END,offsetX,offsetY,+ event,});}});@@ -1038,6 +1040,7 @@ export class Transformer extends Disposable implements ITransformerConfig {type: MoveObserverType.MOVE_END,offsetX,offsetY,+ event,});} else {this._recoverySizeBoundary([applyObject], ancestorLeft, ancestorTop, topSceneWidth, topSceneHeight);@@ -1046,6 +1049,7 @@ export class Transformer extends Disposable implements ITransformerConfig {type: MoveObserverType.MOVE_END,offsetX,offsetY,+ event,});}this.refreshControls();@@ -1139,6 +1143,7 @@ export class Transformer extends Disposable implements ITransformerConfig {type: MoveObserverType.MOVE_END,offsetX,offsetY,+ event,});});diff --git a/packages/sheets-drawing-ui/src/controllers/drawing-context-menu.controller.ts b/packages/sheets-drawing-ui/src/controllers/drawing-context-menu.controller.tsnew file mode 100644index 0000000000..00ac13e46c--- /dev/null+++ b/packages/sheets-drawing-ui/src/controllers/drawing-context-menu.controller.ts@@ -0,0 +1,71 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { Nullable, Workbook } from '@univerjs/core';+import { IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';+import { IDrawingManagerService } from '@univerjs/drawing';+import { IRenderManagerService } from '@univerjs/engine-render';+import { ContextMenuPosition, IContextMenuService } from '@univerjs/ui';++export class DrawingContextMenuController extends RxDisposable {+ constructor(+ @IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,+ @IContextMenuService private readonly _contextMenuService: IContextMenuService,+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService+ ) {+ super();++ this._init();+ }++ private _init(): void {+ this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => this._contextMenuListener(workbook));+ }++ private _contextMenuListener(workbook: Nullable<Workbook>) {+ if (!workbook) {+ return;+ }++ const scene = this._renderManagerService.getRenderById(workbook.getUnitId())?.scene;+ if (!scene) {+ return;+ }++ const transformer = scene.getTransformerByCreate();+ if (!transformer) {+ return;+ }++ this.disposeWithMe(transformer.changeEnd$.subscribe((params) => {+ const { event } = params;+ if (event.button !== 2) return;++ const selectedObjects = transformer.getSelectedObjectMap();+ if (selectedObjects.size === 0) return;++ for (const object of selectedObjects.values()) {+ const oKey = object.oKey;+ const drawingParam = this._drawingManagerService.getDrawingOKey(oKey);++ if (!drawingParam) return;+ }++ this._contextMenuService.triggerContextMenu(event, ContextMenuPosition.DRAWING);+ }));+ }+}diff --git a/packages/sheets-drawing-ui/src/plugin.ts b/packages/sheets-drawing-ui/src/plugin.tsindex cd266e98dd..ad806e3548 100644--- a/packages/sheets-drawing-ui/src/plugin.ts+++ b/packages/sheets-drawing-ui/src/plugin.ts@@ -34,6 +34,7 @@ import { IRenderManagerService } from '@univerjs/engine-render';import { UniverSheetsDrawingPlugin } from '@univerjs/sheets-drawing';import pkg from '../package.json';import { defaultPluginConfig, SHEETS_DRAWING_UI_PLUGIN_CONFIG_KEY } from './config/config';+import { DrawingContextMenuController } from './controllers/drawing-context-menu.controller';import { SheetCellImageHoverRenderController } from './controllers/render-controllers/sheet-celll-image-hover.render-controller';import { SheetsDrawingRenderController } from './controllers/render-controllers/sheet-drawing.render-controller';import { SheetCellImageAutofillController } from './controllers/sheet-cell-image-autofill.controller';@@ -88,6 +89,7 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {[SheetCellImageAutofillController],[SheetCellImageCopyPasteController],[IBatchSaveImagesService, { useClass: BatchSaveImagesService }],+ [DrawingContextMenuController],]);touchDependencies(this._injector, [@@ -116,6 +118,7 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {override onSteady(): void {this._injector.get(DrawingPopupMenuController);+ this._injector.get(DrawingContextMenuController);}private _registerRenderModules(): void {diff --git a/packages/ui/src/services/menu/menu-manager.service.ts b/packages/ui/src/services/menu/menu-manager.service.tsindex 0578692b40..dc3c5f0047 100644--- a/packages/ui/src/services/menu/menu-manager.service.ts+++ b/packages/ui/src/services/menu/menu-manager.service.ts@@ -230,6 +230,12 @@ export class MenuManagerService extends Disposable implements IMenuManagerServicorder: 3,},},+ [ContextMenuPosition.DRAWING]: {+ order: 5,+ [ContextMenuGroup.OTHERS]: {+ order: 3,+ },+ },},};diff --git a/packages/ui/src/services/menu/types.ts b/packages/ui/src/services/menu/types.tsindex 0e2f2cf3b7..1e30aed349 100644--- a/packages/ui/src/services/menu/types.ts+++ b/packages/ui/src/services/menu/types.ts@@ -73,6 +73,10 @@ export enum ContextMenuPosition {* paragraph context menu in doc*/PARAGRAPH = 'contextMenu.paragraph',+ /**+ * drawing context menu, now only used in drawing group operation+ */+ DRAWING = 'contextMenu.drawing',}export enum ContextMenuGroup {