From c9a82f8f75843db8bc29d847d5df45f3660b7851 Mon Sep 17 00:00:00 2001 From: lumixraku Date: Tue, 13 Aug 2024 12:26:32 +0800 Subject: [PATCH] fix: set unitId in cmd params --- .../src/views/UniSlideSideBar.tsx | 6 +- .../commands/operations/activate.operation.ts | 8 +- .../operations/append-slide.operation.ts | 13 +--- .../operations/delete-element.operation.ts | 2 +- .../operations/insert-image.operation.ts | 4 +- .../operations/insert-shape.operation.ts | 6 +- .../operations/insert-text.operation.ts | 6 +- .../operations/set-thumb.operation.ts | 8 +- .../src/components/panels/ArrangePanel.tsx | 5 +- .../src/components/panels/FillPanel.tsx | 5 +- .../src/components/panels/TransformPanel.tsx | 15 ++-- .../src/components/sidebar/Sidebar.tsx | 13 +++- .../src/components/slide-bar/SlideBar.tsx | 7 +- .../slides-ui/src/controllers/canvas-view.ts | 75 +++++-------------- .../src/controllers/popup-menu.controller.ts | 4 +- 15 files changed, 76 insertions(+), 101 deletions(-) diff --git a/packages-experimental/uni-slides-ui/src/views/UniSlideSideBar.tsx b/packages-experimental/uni-slides-ui/src/views/UniSlideSideBar.tsx index 6728d28ea67..b4dcd4fc729 100644 --- a/packages-experimental/uni-slides-ui/src/views/UniSlideSideBar.tsx +++ b/packages-experimental/uni-slides-ui/src/views/UniSlideSideBar.tsx @@ -82,9 +82,11 @@ export function UniSlideSideBar() { }); if (divRefs.length > 0) { - commandService.syncExecuteCommand(SetSlidePageThumbOperation.id); + commandService.syncExecuteCommand(SetSlidePageThumbOperation.id, { + unitId: currentSlide?.getUnitId(), + }); } - }, [divRefs]); // 依赖于divRefs数组的变化 + }, [divRefs, commandService, renderManagerService, slideList, currentSlide]); // 依赖于divRefs数组的变化 useEffect(() => { const slideBar = slideBarRef.current; diff --git a/packages/slides-ui/src/commands/operations/activate.operation.ts b/packages/slides-ui/src/commands/operations/activate.operation.ts index 573178d9d06..31f3690d760 100644 --- a/packages/slides-ui/src/commands/operations/activate.operation.ts +++ b/packages/slides-ui/src/commands/operations/activate.operation.ts @@ -29,18 +29,18 @@ export const ActivateSlidePageOperation: IOperation(UniverInstanceType.UNIVER_SLIDE); - const id = model?.getActivePage()?.id; + const pageId = model?.getActivePage()?.id; - if (!id) return false; + if (!pageId) return false; - const page = canvasView.getRenderUnitByPageId(id); + const page = canvasView.getRenderUnitByPageId(pageId, params.unitId); if (!page) return false; const transformer = page.scene?.getTransformer(); if (transformer) { transformer.clearControls(); } - canvasView.activePage(params.id); + canvasView.activePage(params.id, params.unitId); return true; }, }; diff --git a/packages/slides-ui/src/commands/operations/append-slide.operation.ts b/packages/slides-ui/src/commands/operations/append-slide.operation.ts index b2ebf5da809..0d9bc2b3468 100644 --- a/packages/slides-ui/src/commands/operations/append-slide.operation.ts +++ b/packages/slides-ui/src/commands/operations/append-slide.operation.ts @@ -16,9 +16,8 @@ import type { IOperation, SlideDataModel } from '@univerjs/core'; import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core'; -import { IRenderManagerService } from '@univerjs/engine-render'; -import { SlideRenderController } from '../../controllers/slide.render-controller'; +import { CanvasView } from '../../controllers/canvas-view'; export interface IAppendSlideOperationParams { unitId: string; @@ -27,17 +26,13 @@ export interface IAppendSlideOperationParams { export const AppendSlideOperation: IOperation = { id: 'slide.operation.append-slide', type: CommandType.OPERATION, - handler: (accessor) => { + handler: (accessor, params: IAppendSlideOperationParams) => { const univerInstanceService = accessor.get(IUniverInstanceService); const slideData = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SLIDE); if (!slideData) return false; - // const canvasView = accessor.get(CanvasView); - const renderManagerService = accessor.get(IRenderManagerService); - const renderUnit = renderManagerService - .getRenderById(univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SLIDE)!.getUnitId())!; - const slideRC = renderUnit.with(SlideRenderController); - slideRC.appendPage(); + const canvasView = accessor.get(CanvasView); + canvasView.appendPage(params.unitId); return true; }, diff --git a/packages/slides-ui/src/commands/operations/delete-element.operation.ts b/packages/slides-ui/src/commands/operations/delete-element.operation.ts index 3e0abe32daa..8c094706163 100644 --- a/packages/slides-ui/src/commands/operations/delete-element.operation.ts +++ b/packages/slides-ui/src/commands/operations/delete-element.operation.ts @@ -41,7 +41,7 @@ export const DeleteSlideElementOperation: ICommand = { id: 'slide.operation.add-text', type: CommandType.OPERATION, - handler: async (accessor, params) => { + handler: async (accessor, params: ISlideAddTextParam) => { const elementId = Tools.generateRandomId(6); const defaultWidth = 220; const defaultheight = 40; @@ -78,10 +78,10 @@ export const SlideAddTextOperation: ICommand = { slideData.updatePage(activePage.id, activePage); const canvasview = accessor.get(CanvasView); - const sceneObject = canvasview.createObjectToPage(elementData, activePage.id); + const sceneObject = canvasview.createObjectToPage(elementData, activePage.id, params.unitId); // make object active: a control rect wrap the object. if (sceneObject) { - canvasview.setObjectActiveByPage(sceneObject, activePage.id); + canvasview.setObjectActiveByPage(sceneObject, activePage.id, params.unitId); } return true; diff --git a/packages/slides-ui/src/commands/operations/set-thumb.operation.ts b/packages/slides-ui/src/commands/operations/set-thumb.operation.ts index c3cfa938411..5d34343a51d 100644 --- a/packages/slides-ui/src/commands/operations/set-thumb.operation.ts +++ b/packages/slides-ui/src/commands/operations/set-thumb.operation.ts @@ -18,12 +18,16 @@ import type { IAccessor, IOperation } from '@univerjs/core'; import { CommandType } from '@univerjs/core'; import { CanvasView } from '../../controllers/canvas-view'; +export interface ISlideSetThumbParam { + unitId: string; +} + export const SetSlidePageThumbOperation: IOperation = { id: 'slide.operation.set-slide-page-thumb', type: CommandType.OPERATION, - handler: (accessor: IAccessor) => { + handler: (accessor: IAccessor, params: ISlideSetThumbParam) => { const canvasView = accessor.get(CanvasView); - canvasView.createThumbs(); + canvasView.createThumbs(params.unitId); return true; }, }; diff --git a/packages/slides-ui/src/components/panels/ArrangePanel.tsx b/packages/slides-ui/src/components/panels/ArrangePanel.tsx index 0f839b65f41..7e2fbf382ef 100644 --- a/packages/slides-ui/src/components/panels/ArrangePanel.tsx +++ b/packages/slides-ui/src/components/panels/ArrangePanel.tsx @@ -35,17 +35,18 @@ enum ArrangeTypeEnum { } interface IProps { + pageId: string; unitId: string; } export default function ArrangePanel(props: IProps) { - const { unitId } = props; + const { pageId, unitId } = props; const localeService = useDependency(LocaleService); const canvasView = useDependency(CanvasView); const commandService = useDependency(ICommandService); - const page = canvasView.getRenderUnitByPageId(unitId); + const page = canvasView.getRenderUnitByPageId(pageId, unitId); const scene = page?.scene; if (!scene) return null; diff --git a/packages/slides-ui/src/components/panels/FillPanel.tsx b/packages/slides-ui/src/components/panels/FillPanel.tsx index e0c5f44c17d..901ead80232 100644 --- a/packages/slides-ui/src/components/panels/FillPanel.tsx +++ b/packages/slides-ui/src/components/panels/FillPanel.tsx @@ -28,17 +28,18 @@ import { CanvasView } from '../../controllers/canvas-view'; import styles from './index.module.less'; interface IProps { + pageId: string; unitId: string; } export default function ArrangePanel(props: IProps) { - const { unitId } = props; + const { pageId, unitId } = props; const localeService = useDependency(LocaleService); const canvasView = useDependency(CanvasView); const commandService = useDependency(ICommandService); - const page = canvasView.getRenderUnitByPageId(unitId); + const page = canvasView.getRenderUnitByPageId(pageId, unitId); const scene = page?.scene; if (!scene) return null; diff --git a/packages/slides-ui/src/components/panels/TransformPanel.tsx b/packages/slides-ui/src/components/panels/TransformPanel.tsx index a7ca802f55f..8d2cead004a 100644 --- a/packages/slides-ui/src/components/panels/TransformPanel.tsx +++ b/packages/slides-ui/src/components/panels/TransformPanel.tsx @@ -26,17 +26,18 @@ import { CanvasView } from '../../controllers/canvas-view'; import styles from './index.module.less'; interface IProps { + pageId: string; unitId: string; } export default function TransformPanel(props: IProps) { - const { unitId } = props; + const { pageId, unitId } = props; const localeService = useDependency(LocaleService); const canvasView = useDependency(CanvasView); const commandService = useDependency(ICommandService); - const page = canvasView.getRenderUnitByPageId(unitId); + const page = canvasView.getRenderUnitByPageId(pageId, unitId); const scene = page?.scene; if (!scene) return null; @@ -200,7 +201,7 @@ export default function TransformPanel(props: IProps) { if (!val || !object) return; commandService.executeCommand(UpdateSlideElementOperation.id, { - unitId, + pageId, oKey: object.oKey, props: { width: val, @@ -215,7 +216,7 @@ export default function TransformPanel(props: IProps) { if (!val || !object) return; commandService.executeCommand(UpdateSlideElementOperation.id, { - unitId, + pageId, oKey: object.oKey, props: { height: val, @@ -230,7 +231,7 @@ export default function TransformPanel(props: IProps) { if (!val || !object) return; commandService.executeCommand(UpdateSlideElementOperation.id, { - unitId, + pageId, oKey: object.oKey, props: { left: val, @@ -245,7 +246,7 @@ export default function TransformPanel(props: IProps) { if (!val || !object) return; commandService.executeCommand(UpdateSlideElementOperation.id, { - unitId, + pageId, oKey: object.oKey, props: { right: val, @@ -260,7 +261,7 @@ export default function TransformPanel(props: IProps) { if (!val || !object) return; commandService.executeCommand(UpdateSlideElementOperation.id, { - unitId, + pageId, oKey: object.oKey, props: { angle: val, diff --git a/packages/slides-ui/src/components/sidebar/Sidebar.tsx b/packages/slides-ui/src/components/sidebar/Sidebar.tsx index 70e4510c946..9231c221849 100644 --- a/packages/slides-ui/src/components/sidebar/Sidebar.tsx +++ b/packages/slides-ui/src/components/sidebar/Sidebar.tsx @@ -36,7 +36,7 @@ export default function RectSidebar() { if (!pageId) return null; - const page = canvasView.getRenderUnitByPageId(pageId); + const page = canvasView.getRenderUnitByPageId(pageId, pageId); const transformer = page.scene?.getTransformer(); if (!transformer) return null; @@ -48,11 +48,16 @@ export default function RectSidebar() { return null; } + // see packages/sheets-ui/src/views/permission/permission-dialog/index.tsx@SheetPermissionDialog + // see packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx@getUnitId + // const unitId = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SLIDE)!.getUnitId(); + const unitId = univerInstanceService.getFocusedUnit()?.getUnitId() || ''; + return (
- - - {object.objectType === ObjectType.RECT && } + + + {object.objectType === ObjectType.RECT && }
); } diff --git a/packages/slides-ui/src/components/slide-bar/SlideBar.tsx b/packages/slides-ui/src/components/slide-bar/SlideBar.tsx index 6bfb4ceb471..c8f5e53834d 100644 --- a/packages/slides-ui/src/components/slide-bar/SlideBar.tsx +++ b/packages/slides-ui/src/components/slide-bar/SlideBar.tsx @@ -47,7 +47,6 @@ export function SlideSideBar() { // ); const pages = currentSlide?.getPages(); const pageOrder = currentSlide?.getPageOrder(); - if (!pages || !pageOrder) { return null; } @@ -83,9 +82,9 @@ export function SlideSideBar() { }); if (divRefs.length > 0) { - commandService.syncExecuteCommand(SetSlidePageThumbOperation.id); + commandService.syncExecuteCommand(SetSlidePageThumbOperation.id, { unitId: currentSlide?.getUnitId() }); } - }, [divRefs]); // 依赖于divRefs数组的变化 + }, [divRefs, slideList, renderManagerService, commandService, currentSlide]); // 依赖于divRefs数组的变化 const activatePage = useCallback((page: string) => { commandService.syncExecuteCommand(ActivateSlidePageOperation.id, { id: page, unitId: currentSlide?.getUnitId() }); @@ -93,7 +92,7 @@ export function SlideSideBar() { const handleAppendSlide = useCallback(() => { commandService.syncExecuteCommand(AppendSlideOperation.id, { unitId: currentSlide?.getUnitId() }); - }, [commandService]); + }, [commandService, currentSlide]); return (