Skip to content

Commit

Permalink
fix: set unitId in cmd params
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Aug 13, 2024
1 parent f95af7e commit d471a9b
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ export const ActivateSlidePageOperation: IOperation<IActiveSlidePageOperationPar
const canvasView = accessor.get(CanvasView);
const univerInstanceService = accessor.get(IUniverInstanceService);
const model = univerInstanceService.getCurrentUnitForType<SlideDataModel>(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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,17 +26,13 @@ export interface IAppendSlideOperationParams {
export const AppendSlideOperation: IOperation<IAppendSlideOperationParams> = {
id: 'slide.operation.append-slide',
type: CommandType.OPERATION,
handler: (accessor) => {
handler: (accessor, params: IAppendSlideOperationParams) => {
const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(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;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const DeleteSlideElementOperation: ICommand<IDeleteElementOperationParams
slideData.updatePage(activePage.id, activePage);

const canvasview = accessor.get(CanvasView);
canvasview.removeObjectById(params.id, activePage.id);
canvasview.removeObjectById(params.id, activePage.id, params.unitId);

return true;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export const InsertSlideFloatImageOperation: ICommand<IInsertImageOperationParam
slideData.updatePage(activePage.id, activePage);

const canvasview = accessor.get(CanvasView);
const sceneObject = canvasview.createObjectToPage(data, activePage.id);
const sceneObject = canvasview.createObjectToPage(data, activePage.id, params.unitId);
if (sceneObject) {
canvasview.setObjectActiveByPage(sceneObject, activePage.id);
canvasview.setObjectActiveByPage(sceneObject, activePage.id, params.unitId);
}
// console.log(slideData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationP
};

activePage.pageElements[id] = data;

slideData.updatePage(activePage.id, activePage);

const unitId = params?.unitId || '';
const canvasview = accessor.get(CanvasView);
const sceneObject = canvasview.createObjectToPage(data, activePage.id);
const sceneObject = canvasview.createObjectToPage(data, activePage.id, unitId);
if (sceneObject) {
canvasview.setObjectActiveByPage(sceneObject, activePage.id);
canvasview.setObjectActiveByPage(sceneObject, activePage.id, unitId);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const SlideAddTextCommand: ICommand = {
export const SlideAddTextOperation: ICommand<ISlideAddTextParam> = {
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;
Expand Down Expand Up @@ -78,10 +78,10 @@ export const SlideAddTextOperation: ICommand<ISlideAddTextParam> = {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
5 changes: 3 additions & 2 deletions packages/slides-ui/src/components/panels/ArrangePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions packages/slides-ui/src/components/panels/FillPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 8 additions & 7 deletions packages/slides-ui/src/components/panels/TransformPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions packages/slides-ui/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
<section className={styles.imageCommonPanel}>
<ArrangePanel unitId={pageId} />
<TransformPanel unitId={pageId} />
{object.objectType === ObjectType.RECT && <FillPanel unitId={pageId} />}
<ArrangePanel pageId={pageId} unitId={unitId} />
<TransformPanel pageId={pageId} unitId={unitId} />
{object.objectType === ObjectType.RECT && <FillPanel pageId={pageId} unitId={unitId} />}
</section>
);
}
7 changes: 3 additions & 4 deletions packages/slides-ui/src/components/slide-bar/SlideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function SlideSideBar() {
// );
const pages = currentSlide?.getPages();
const pageOrder = currentSlide?.getPageOrder();

if (!pages || !pageOrder) {
return null;
}
Expand Down Expand Up @@ -83,17 +82,17 @@ 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() });
}, [commandService, currentSlide]);

const handleAppendSlide = useCallback(() => {
commandService.syncExecuteCommand(AppendSlideOperation.id, { unitId: currentSlide?.getUnitId() });
}, [commandService]);
}, [commandService, currentSlide]);

return (
<aside className={styles.slideBar} ref={slideBarRef}>
Expand Down
Loading

0 comments on commit d471a9b

Please sign in to comment.