Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add unit param for slide cmd #3038

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion packages/engine-render/src/render-manager/render-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface IRenderContext<T extends UnitModel = UnitModel> extends Omit<IR
}

/**
* This class is responsible
* RenderUnit impl IRender
*/
export class RenderUnit extends Disposable implements IRender {
readonly isRenderUnit: boolean = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { IAccessor, IOperation, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
import { CanvasView } from '../../controllers/canvas-view';

export interface IActiveSlidePageOperationParams {
Expand All @@ -26,21 +26,24 @@ export const ActivateSlidePageOperation: IOperation<IActiveSlidePageOperationPar
id: 'slide.operation.activate-slide',
type: CommandType.OPERATION,
handler: (accessor: IAccessor, params: IActiveSlidePageOperationParams) => {
const unitId = params.unitId;
const canvasView = accessor.get(CanvasView);
const univerInstanceService = accessor.get(IUniverInstanceService);
const model = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
const id = model?.getActivePage()?.id;
// const model = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

if (!id) return false;
const model = univerInstanceService.getUnit<SlideDataModel>(unitId);
const pageId = model?.getActivePage()?.id;

const page = canvasView.getRenderUnitByPageId(id);
if (!pageId) return false;

const page = canvasView.getRenderUnitByPageId(pageId, unitId);
if (!page) return false;
const transformer = page.scene?.getTransformer();
if (transformer) {
transformer.clearControls();
}

canvasView.activePage(params.id);
canvasView.activePage(params.id, unitId);
return true;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/

import type { IOperation, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { CommandType, IUniverInstanceService } from '@univerjs/core';

import { SlideRenderController } from '../../controllers/slide.render-controller';
import { CanvasView } from '../../controllers/canvas-view';

export interface IAppendSlideOperationParams {
unitId: string;
Expand All @@ -27,17 +26,17 @@ export interface IAppendSlideOperationParams {
export const AppendSlideOperation: IOperation<IAppendSlideOperationParams> = {
id: 'slide.operation.append-slide',
type: CommandType.OPERATION,
handler: (accessor) => {
handler: (accessor, params: IAppendSlideOperationParams) => {
const unitId = params.unitId;
const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
// const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

const slideData = univerInstanceService.getUnit<SlideDataModel>(unitId);

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(unitId);

return true;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { ICommand, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
import { CanvasView } from '../../controllers/canvas-view';

export interface IDeleteElementOperationParams {
Expand All @@ -29,8 +29,11 @@ export const DeleteSlideElementOperation: ICommand<IDeleteElementOperationParams
handler: (accessor, params) => {
if (!params?.id) return false;

const unitId = params.unitId;
const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
// const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

const slideData = univerInstanceService.getUnit<SlideDataModel>(unitId);

if (!slideData) return false;

Expand All @@ -41,7 +44,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, unitId);

return true;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { ICommand, Nullable, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, PageElementType, UniverInstanceType } from '@univerjs/core';
import { CommandType, IUniverInstanceService, PageElementType } from '@univerjs/core';
import { getImageSize, IImageIoService } from '@univerjs/drawing';
import { CanvasView } from '../../controllers/canvas-view';

Expand All @@ -38,7 +38,10 @@ export const InsertSlideFloatImageOperation: ICommand<IInsertImageOperationParam
const { width, height, image } = await getImageSize(base64Cache || '');

const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
// const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

const unitId = params.unitId;
const slideData = univerInstanceService.getUnit<SlideDataModel>(unitId);
if (!slideData) return false;

const activePage = slideData.getActivePage()!;
Expand All @@ -64,16 +67,13 @@ export const InsertSlideFloatImageOperation: ICommand<IInsertImageOperationParam
},
},
};

activePage.pageElements[imageId] = data;
// console.log(activePage.id);

slideData.updatePage(activePage.id, activePage);

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);
}
// console.log(slideData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { IAccessor, ICommand, SlideDataModel } from '@univerjs/core';
import { BasicShapes, CommandType, generateRandomId, ICommandService, IUniverInstanceService, LocaleService, PageElementType, UniverInstanceType } from '@univerjs/core';
import { BasicShapes, CommandType, generateRandomId, ICommandService, IUniverInstanceService, LocaleService, PageElementType } from '@univerjs/core';
import { ObjectType } from '@univerjs/engine-render';

import { ISidebarService } from '@univerjs/ui';
Expand All @@ -40,18 +40,20 @@ export const InsertSlideShapeRectangleCommand: ICommand = {
export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationParams> = {
id: 'slide.operation.insert-float-shape',
type: CommandType.OPERATION,
handler: async (accessor, params) => {
handler: async (accessor, params: IInsertShapeOperationParams) => {
const id = generateRandomId(6);

const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
// const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

const unitId = params.unitId;
const slideData = univerInstanceService.getUnit<SlideDataModel>(unitId);

if (!slideData) return false;

const activePage = slideData.getActivePage()!;
const elements = Object.values(activePage.pageElements);
const maxIndex = (elements?.length) ? Math.max(...elements.map((element) => element.zIndex)) : 20;

const data = {
id,
zIndex: maxIndex + 1,
Expand All @@ -72,15 +74,13 @@ export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationP
},
},
};

activePage.pageElements[id] = data;

slideData.updatePage(activePage.id, activePage);

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 @@ -15,7 +15,7 @@
*/

import type { ICommand, IPageElement, SlideDataModel } from '@univerjs/core';
import { CommandType, ICommandService, IUniverInstanceService, PageElementType, Tools, UniverInstanceType } from '@univerjs/core';
import { CommandType, generateRandomId, ICommandService, IUniverInstanceService, PageElementType } from '@univerjs/core';
import { CanvasView } from '../../controllers/canvas-view';

export interface ISlideAddTextParam {
Expand All @@ -38,16 +38,20 @@ export const SlideAddTextCommand: ICommand = {
export const SlideAddTextOperation: ICommand<ISlideAddTextParam> = {
id: 'slide.operation.add-text',
type: CommandType.OPERATION,
handler: async (accessor, params) => {
const elementId = Tools.generateRandomId(6);
handler: async (accessor, params: ISlideAddTextParam) => {
const unitId = params.unitId;

const elementId = generateRandomId(6);
const defaultWidth = 220;
const defaultheight = 40;
const left = 230;
const top = 142;
const textContent = params?.text || 'A New Text';

const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
// const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

const slideData = univerInstanceService.getUnit<SlideDataModel>(unitId);
if (!slideData) return false;

const activePage = slideData.getActivePage()!;
Expand Down Expand Up @@ -78,10 +82,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, unitId);
// make object active: a control rect wrap the object.
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 @@ -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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { ICommand, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';
import { CommandType, IUniverInstanceService, Tools } from '@univerjs/core';

export interface IUpdateElementOperationParams {
unitId: string;
Expand All @@ -26,19 +26,19 @@ export interface IUpdateElementOperationParams {
export const UpdateSlideElementOperation: ICommand<IUpdateElementOperationParams> = {
id: 'slide.operation.update-element',
type: CommandType.OPERATION,
handler: (accessor, params) => {
handler: (accessor, params: IUpdateElementOperationParams) => {
const { oKey, props } = params!;

const univerInstanceService = accessor.get(IUniverInstanceService);
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
// const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);

const unitId = params?.unitId;
const slideData = univerInstanceService.getUnit<SlideDataModel>(unitId);
if (!slideData) return false;

const activePage = slideData.getActivePage()!;

activePage.pageElements[oKey] = Tools.deepMerge(activePage.pageElements[oKey], props);

slideData.updatePage(activePage.id, activePage);

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
Loading
Loading