Skip to content

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.

feat(slides): add basic support for editing shapes and images (#2933)

白熱a5f23b9751a8
diff --git a/examples/src/slides/main.ts b/examples/src/slides/main.ts
index b8b3a83a67..a1fb3a88fb 100644
--- a/examples/src/slides/main.ts
+++ b/examples/src/slides/main.ts
@@ -25,6 +25,7 @@ import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
+import { UniverDrawingPlugin } from '@univerjs/drawing';
import { DEFAULT_SLIDE_DATA } from '../data';
import { enUS, ruRU, zhCN } from '../locales';
@@ -47,6 +48,7 @@ univer.registerPlugin(UniverDocsUIPlugin);
univer.registerPlugin(UniverDocsHyperLinkPlugin);
// base-render
univer.registerPlugin(UniverFormulaEnginePlugin);
+univer.registerPlugin(UniverDrawingPlugin);
univer.registerPlugin(UniverSlidesPlugin);
univer.registerPlugin(UniverSlidesUIPlugin);
diff --git a/packages/core/src/slides/slide-model.ts b/packages/core/src/slides/slide-model.ts
index 986ccb2f4a..5be5347e83 100644
--- a/packages/core/src/slides/slide-model.ts
+++ b/packages/core/src/slides/slide-model.ts
@@ -17,7 +17,7 @@
import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../common/unit';
import type { Nullable } from '../shared';
-import { Tools } from '../shared';
+import { generateRandomId } from '../shared';
import { DEFAULT_SLIDE } from '../types/const';
import type { ISlideData, ISlidePage } from '../types/interfaces';
import { PageType } from '../types/interfaces';
@@ -50,7 +50,7 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
super();
this._snapshot = { ...DEFAULT_SLIDE, ...snapshot };
- this._unitId = this._snapshot.id ?? Tools.generateRandomId(6);
+ this._unitId = this._snapshot.id ?? generateRandomId(6);
}
getContainer() {
@@ -90,18 +90,22 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
return this._snapshot.pageSize;
}
- addPage(): ISlidePage {
- return {
- id: 'cover_1',
+ getBlankPage() {
+ const id = generateRandomId(6);
+
+ const page = {
+ id,
pageType: PageType.SLIDE,
zIndex: 10,
- title: 'cover',
- description: 'this is first page, cover',
+ title: id,
+ description: '',
pageBackgroundFill: {
rgb: 'rgb(255,255,255)',
},
pageElements: {},
};
+
+ return page;
}
setActivePage(page: Nullable<ISlidePage>) {
@@ -117,4 +121,14 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
this._snapshot.body.pages[pageId] = page;
}
+
+ appendPage(page: ISlidePage) {
+ if (!this._snapshot.body) return;
+
+ this._snapshot.body.pages[page.id] = page;
+
+ const activePage = this._activePage;
+ const index = this._snapshot.body.pageOrder.indexOf(activePage?.id ?? '');
+ this._snapshot.body.pageOrder.splice(index + 1, 0, page.id);
+ }
}
diff --git a/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts b/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
index 3b3effda0c..c742b5f3b8 100644
--- a/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
+++ b/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
@@ -56,4 +56,3 @@ export const SidebarSheetDrawingOperation: ICommand = {
return true;
},
};
-
diff --git a/packages/slides-ui/package.json b/packages/slides-ui/package.json
index 00bf57bdb0..7708211b7d 100644
--- a/packages/slides-ui/package.json
+++ b/packages/slides-ui/package.json
@@ -68,7 +68,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/docs-drawing-ui": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
diff --git a/packages/slides-ui/src/commands/operations/activate.operation.ts b/packages/slides-ui/src/commands/operations/activate.operation.ts
index 10b538a0f8..cd26e704da 100644
--- a/packages/slides-ui/src/commands/operations/activate.operation.ts
+++ b/packages/slides-ui/src/commands/operations/activate.operation.ts
@@ -34,9 +34,9 @@ export const ActivateSlidePageOperation: IOperation<IActiveSlidePageOperationPar
const page = canvasView.getRenderUnitByPageId(id);
const transformer = page.scene?.getTransformer();
-
- if (!transformer) return false;
- transformer.clearControls();
+ if (transformer) {
+ transformer.clearControls();
+ }
canvasView.activePage(params.id);
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
new file mode 100644
index 0000000000..a05ab9948b
--- /dev/null
+++ b/packages/slides-ui/src/commands/operations/append-slide.operation.ts
@@ -0,0 +1,34 @@
+/**
+ * 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, SlideDataModel } from '@univerjs/core';
+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { CanvasView } from '@univerjs/slides';
+
+export const AppendSlideOperation: ICommand = {
+ id: 'slide.operation.append-slide',
+ type: CommandType.OPERATION,
+ handler: (accessor) => {
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const canvasView = accessor.get(CanvasView);
+ const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+
+ if (!slideData) return false;
+ canvasView.appendPage();
+
+ return true;
+ },
+};
diff --git a/packages/slides-ui/src/commands/operations/insert-shape.operation.ts b/packages/slides-ui/src/commands/operations/insert-shape.operation.ts
index 38cdc0a319..ff272cab3a 100644
--- a/packages/slides-ui/src/commands/operations/insert-shape.operation.ts
+++ b/packages/slides-ui/src/commands/operations/insert-shape.operation.ts
@@ -14,9 +14,12 @@
* limitations under the License.
*/
-import type { ICommand, SlideDataModel } from '@univerjs/core';
-import { BasicShapes, CommandType, generateRandomId, IUniverInstanceService, PageElementType, UniverInstanceType } from '@univerjs/core';
+import type { IAccessor, ICommand, SlideDataModel } from '@univerjs/core';
+import { BasicShapes, CommandType, generateRandomId, IUniverInstanceService, LocaleService, PageElementType, UniverInstanceType } from '@univerjs/core';
+import { ObjectType } from '@univerjs/engine-render';
import { CanvasView } from '@univerjs/slides';
+import { ISidebarService } from '@univerjs/ui';
+import { COMPONENT_SLIDE_SIDEBAR } from '../../components/sidebar/Sidebar';
export interface IInsertShapeOperationParams {
};
@@ -25,15 +28,6 @@ export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationP
id: 'slide.operation.insert-float-shape',
type: CommandType.OPERATION,
handler: async (accessor, params) => {
- // const imageIoService = accessor.get(IImageIoService);
- // if (!params?.files?.length) return false;
-
- // const imageParam = await imageIoService.saveImage(params.files[0]);
- // if (!imageParam) return false;
-
- // const { imageId, imageSourceType, source, base64Cache } = imageParam;
- // const { width, height, image } = await getImageSize(base64Cache || '');
-
const id = generateRandomId(6);
const data = {
id,
@@ -65,8 +59,6 @@ export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationP
activePage.pageElements[id] = data;
- // console.log(activePage.id);
-
slideData.updatePage(activePage.id, activePage);
const canvasview = accessor.get(CanvasView);
@@ -75,24 +67,49 @@ export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationP
canvasview.setObjectActiveByPage(sceneObject, activePage.id);
}
- // console.log(slideData);
+ return true;
+ },
+};
+
+export interface IToggleSlideEditSidebarOperation {
+ visible: string;
+ objectType: ObjectType;
+}
+
+export const ToggleSlideEditSidebarOperation: ICommand = {
+ id: 'sidebar.operation.slide-shape',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor, params: IToggleSlideEditSidebarOperation) => {
+ const { visible, objectType } = params;
- // {
- // "id": "background1",
- // "zIndex": 0,
- // "left": 0,
- // "top": 0,
- // "width": 960,
- // "height": 540,
- // "title": "background",
- // "description": "",
- // "type": 1,
- // "image": {
- // "imageProperties": {
- // "contentUrl": "https://minio.cnbabylon.com/univer/slide/Picture1.jpg"
- // }
- // }
- // }
+ const sidebarService = accessor.get(ISidebarService);
+ const localeService = accessor.get(LocaleService);
+
+ let title = '';
+ let children = '';
+ if (objectType === ObjectType.RECT) {
+ title = 'slide.sidebar.shape';
+ children = COMPONENT_SLIDE_SIDEBAR;
+ } else if (objectType === ObjectType.IMAGE) {
+ title = 'slide.sidebar.image';
+ children = COMPONENT_SLIDE_SIDEBAR;
+ } else if (objectType === ObjectType.RICH_TEXT) {
+ title = 'slide.sidebar.text';
+ children = COMPONENT_SLIDE_SIDEBAR;
+ }
+
+ if (visible) {
+ sidebarService.open({
+ header: { title: localeService.t(title) },
+ children: { label: children },
+ onClose: () => {
+ // drawingManagerService.focusDrawing(null);
+ },
+ width: 360,
+ });
+ } else {
+ sidebarService.close();
+ }
return true;
},
};
diff --git a/packages/slides-ui/src/components/panels/ArrangePanel.tsx b/packages/slides-ui/src/components/panels/ArrangePanel.tsx
new file mode 100644
index 0000000000..c2d4b0f193
--- /dev/null
+++ b/packages/slides-ui/src/components/panels/ArrangePanel.tsx
@@ -0,0 +1,127 @@
+/**
+ * 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 React from 'react';
+
+import type { Nullable } from '@univerjs/core';
+import { LocaleService, useDependency } from '@univerjs/core';
+import clsx from 'clsx';
+import { Button } from '@univerjs/design';
+import { BottomSingle, MoveDownSingle, MoveUpSingle, TopmostSingle } from '@univerjs/icons';
+import { CanvasView } from '@univerjs/slides';
+import type { Image, Rect, RichText } from '@univerjs/engine-render';
+import styles from './index.module.less';
+
+enum ArrangeTypeEnum {
+ forward,
+ backward,
+ front,
+ back,
+}
+
+interface IProps {
+ unitId: string;
+}
+
+export default function ArrangePanel(props: IProps) {
+ const { unitId } = props;
+
+ const localeService = useDependency(LocaleService);
+ const canvasView = useDependency(CanvasView);
+
+ const page = canvasView.getRenderUnitByPageId(unitId);
+ const scene = page?.scene;
+ if (!scene) return null;
+
+ const transformer = scene.getTransformer();
+ if (!transformer) return null;
+
+ const selectedObjects = transformer.getSelectedObjectMap();
+ const object = selectedObjects.values().next().value as Nullable<Rect | RichText | Image>;
+ if (!object) return null;
+
+ const onArrangeBtnClick = (arrangeType: ArrangeTypeEnum) => {
+ const allObjects = scene.getAllObjects();
+
+ const [minZIndex, maxZIndex] = allObjects.reduce(([min, max], obj) => {
+ const zIndex = obj.zIndex;
+ const minZIndex = zIndex < min ? zIndex : min;
+ const maxZIndex = zIndex > max ? zIndex : max;
+
+ return [minZIndex, maxZIndex];
+ }, [0, 0]);
+
+ if (arrangeType === ArrangeTypeEnum.back) {
+ object.setProps({ zIndex: minZIndex - 1 });
+ } else if (arrangeType === ArrangeTypeEnum.front) {
+ object.setProps({ zIndex: maxZIndex + 1 });
+ } else if (arrangeType === ArrangeTypeEnum.forward) {
+ object.setProps({ zIndex: object.zIndex + 1 });
+ } else if (arrangeType === ArrangeTypeEnum.backward) {
+ object.setProps({ zIndex: object.zIndex - 1 });
+ }
+ };
+
+ return (
+ <div className={styles.imageCommonPanelGrid}>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelTitle)}>
+ <div>{localeService.t('image-panel.arrange.title')}</div>
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2)}>
+ <Button size="small" onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.forward); }}>
+ <span className={styles.imageCommonPanelInline}>
+ <MoveUpSingle />
+ {localeService.t('image-panel.arrange.forward')}
+ </span>
+
+ </Button>
+ </div>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2)}>
+ <Button size="small" onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.backward); }}>
+ <span className={styles.imageCommonPanelInline}>
+ <MoveDownSingle />
+ {localeService.t('image-panel.arrange.backward')}
+ </span>
+
+ </Button>
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2)}>
+ <Button size="small" onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.front); }}>
+ <span className={styles.imageCommonPanelInline}>
+ <TopmostSingle />
+ {localeService.t('image-panel.arrange.front')}
+ </span>
+
+ </Button>
+ </div>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2)}>
+ <Button size="small" onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.back); }}>
+ <span className={styles.imageCommonPanelInline}>
+ <BottomSingle />
+ {localeService.t('image-panel.arrange.back')}
+ </span>
+
+ </Button>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/slides-ui/src/components/panels/FillPanel.tsx b/packages/slides-ui/src/components/panels/FillPanel.tsx
new file mode 100644
index 0000000000..3629da10f8
--- /dev/null
+++ b/packages/slides-ui/src/components/panels/FillPanel.tsx
@@ -0,0 +1,93 @@
+/**
+ * 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 React from 'react';
+
+import type { Nullable } from '@univerjs/core';
+import { LocaleService, useDependency } from '@univerjs/core';
+import clsx from 'clsx';
+import { ColorPicker, Dropdown } from '@univerjs/design';
+import { MoreDownSingle, PaintBucket } from '@univerjs/icons';
+import { CanvasView } from '@univerjs/slides';
+import type { Rect } from '@univerjs/engine-render';
+import styles from './index.module.less';
+
+interface IProps {
+ unitId: string;
+}
+
+export default function ArrangePanel(props: IProps) {
+ const { unitId } = props;
+
+ const localeService = useDependency(LocaleService);
+ const canvasView = useDependency(CanvasView);
+
+ const page = canvasView.getRenderUnitByPageId(unitId);
+ const scene = page?.scene;
+ if (!scene) return null;
+
+ const transformer = scene.getTransformer();
+ if (!transformer) return null;
+
+ const selectedObjects = transformer.getSelectedObjectMap();
+ const object = selectedObjects.values().next().value as Nullable<Rect>;
+ if (!object) return null;
+
+ const [color, setColor] = React.useState<string>(object.fill?.toString() ?? '');
+
+ function handleChangeColor(color: string) {
+ object?.setProps({ fill: color });
+ setColor(color);
+ }
+
+ return (
+ <div
+ className={clsx(styles.imageCommonPanelGrid, styles.imageCommonPanelBorder)}
+ >
+ <div className={styles.imageCommonPanelGrid}>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelTitle)}>
+ <div>{localeService.t('slide.panel.fill.title')}</div>
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2)}>
+ <Dropdown
+ align={{
+ offset: [0, 18],
+ }}
+ overlay={(
+ <section className={styles.slidePanelColorPicker}>
+ <ColorPicker
+ color="#fff"
+ onChange={handleChangeColor}
+ />
+ </section>
+ )}
+ >
+ <a className={styles.uiPluginSheetsBorderPanelButton}>
+ <PaintBucket extend={{ colorChannel1: color ?? 'rgb(var(--primary-color))' }} />
+ <span className={styles.uiPluginSheetsBorderPanelMoreIcon}>
+ <MoreDownSingle />
+ </span>
+ </a>
+ </Dropdown>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/slides-ui/src/components/panels/TransformPanel.tsx b/packages/slides-ui/src/components/panels/TransformPanel.tsx
new file mode 100644
index 0000000000..a60feb5924
--- /dev/null
+++ b/packages/slides-ui/src/components/panels/TransformPanel.tsx
@@ -0,0 +1,365 @@
+/**
+ * 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 React, { useEffect, useState } from 'react';
+
+import type { Nullable } from '@univerjs/core';
+import { LocaleService, useDependency } from '@univerjs/core';
+import clsx from 'clsx';
+import { InputNumber } from '@univerjs/design';
+import type { BaseObject, IChangeObserverConfig, Image, Rect, RichText } from '@univerjs/engine-render';
+import { CanvasView } from '@univerjs/slides';
+import styles from './index.module.less';
+
+interface IProps {
+ unitId: string;
+}
+
+export default function TransformPanel(props: IProps) {
+ const { unitId } = props;
+
+ const localeService = useDependency(LocaleService);
+ const canvasView = useDependency(CanvasView);
+
+ const page = canvasView.getRenderUnitByPageId(unitId);
+ const scene = page?.scene;
+ if (!scene) return null;
+
+ const transformer = scene.getTransformer();
+ if (!transformer) return null;
+
+ const selectedObjects = transformer.getSelectedObjectMap();
+ const object = selectedObjects.values().next().value as Nullable<Rect | Image | RichText>;
+ if (!object) return null;
+
+ const {
+ width: originWidth = 0,
+ height: originHeight = 0,
+ left: originX = 0,
+ top: originY = 0,
+ angle: originRotation = 0,
+ } = object;
+
+ const [width, setWidth] = useState<number>(originWidth);
+ const [height, setHeight] = useState(originHeight);
+ const [xPosition, setXPosition] = useState(originX);
+ const [yPosition, setYPosition] = useState(originY);
+ const [rotation, setRotation] = useState(originRotation);
+ // const [lockRatio, setLockRatio] = useState(transformer.keepRatio);
+
+ // const handleLockRatioChange = (val: string | number | boolean) => {
+ // setLockRatio(val as boolean);
+ // transformer.keepRatio = val as boolean;
+ // };
+
+ const changeObs = (state: IChangeObserverConfig) => {
+ const { objects } = state;
+
+ const object = objects.values().next().value as BaseObject;
+
+ const {
+ width: originWidth = 0,
+ height: originHeight = 0,
+ left: originX = 0,
+ top: originY = 0,
+ angle: originRotation = 0,
+ } = object;
+
+ setWidth(originWidth);
+ setHeight(originHeight);
+ setXPosition(originX);
+ setYPosition(originY);
+ setRotation(originRotation);
+
+ // const params = getUpdateParams(objects, drawingManagerService);
+
+ // if (params.length !== 1) {
+ // return;
+ // }
+
+ // const drawingParam = params[0];
+
+ // if (drawingParam == null) {
+ // return;
+ // }
+
+ // const { transform } = drawingParam;
+
+ // if (transform == null) {
+ // return;
+ // }
+
+ // const {
+ // width: originWidth,
+ // height: originHeight,
+ // left: originX,
+ // top: originY,
+ // angle: originRotation,
+ // } = transform;
+
+ // if (originWidth != null) {
+ // setWidth(originWidth);
+ // }
+
+ // if (originHeight != null) {
+ // setHeight(originHeight);
+ // }
+
+ // if (originX != null) {
+ // setXPosition(originX);
+ // }
+
+ // if (originY != null) {
+ // setYPosition(originY);
+ // }
+
+ // if (originRotation != null) {
+ // setRotation(originRotation);
+ // }
+ };
+
+ useEffect(() => {
+ const changeStartSub = transformer.changeStart$.subscribe((state) => {
+ changeObs(state);
+ });
+
+ const changingSub = transformer.changing$.subscribe((state) => {
+ changeObs(state);
+ });
+
+ // const focusSub = drawingManagerService.focus$.subscribe((drawings) => {
+ // if (drawings.length !== 1) {
+ // return;
+ // }
+
+ // const drawingParam = drawingManagerService.getDrawingByParam(drawings[0]);
+
+ // if (drawingParam == null) {
+ // return;
+ // }
+
+ // const transform = drawingParam.transform;
+
+ // if (transform == null) {
+ // return;
+ // }
+
+ // const {
+ // width: originWidth,
+ // height: originHeight,
+ // left: originX,
+ // top: originY,
+ // angle: originRotation,
+ // } = transform;
+
+ // if (originWidth != null) {
+ // setWidth(originWidth);
+ // }
+
+ // if (originHeight != null) {
+ // setHeight(originHeight);
+ // }
+
+ // if (originX != null) {
+ // setXPosition(originX);
+ // }
+
+ // if (originY != null) {
+ // setYPosition(originY);
+ // }
+
+ // if (originRotation != null) {
+ // setRotation(originRotation);
+ // }
+ // });
+
+ return () => {
+ changingSub.unsubscribe();
+ changeStartSub.unsubscribe();
+ // focusSub.unsubscribe();
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ function handleWidthChange(val: number | null) {
+ if (!val || !object) return;
+
+ object?.resize(val, object.height);
+ setWidth(val);
+ transformer?.refreshControls();
+ }
+
+ function handleHeightChange(val: number | null) {
+ if (!val || !object) return;
+
+ object?.resize(object.width, val);
+ setHeight(val);
+ transformer?.refreshControls();
+ }
+
+ function handleXChange(val: number | null) {
+ if (!val || !object) return;
+
+ object?.translate(val, object.top);
+ setXPosition(val);
+ transformer?.refreshControls();
+ }
+
+ function handleYChange(val: number | null) {
+ if (!val || !object) return;
+
+ object?.translate(object.left, val);
+ setYPosition(val);
+ transformer?.refreshControls();
+ }
+
+ function handleChangeRotation(val: number | null) {
+ if (!val) return;
+
+ object?.transformByState({
+ angle: val,
+ });
+ setRotation(val);
+ transformer?.refreshControls();
+ }
+
+ return (
+ <div
+ className={clsx(styles.imageCommonPanelGrid, styles.imageCommonPanelBorder)}
+ >
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelTitle)}>
+ <div>{localeService.t('image-panel.transform.title')}</div>
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan3)}>
+ <label>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ {localeService.t('image-panel.transform.width')}
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ <InputNumber
+ className={styles.imageCommonPanelInput}
+ min={1}
+ value={width}
+ onChange={(val) => { handleWidthChange(val); }}
+ />
+ </div>
+ </div>
+ </label>
+ </div>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan3)}>
+ <label>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ {localeService.t('image-panel.transform.height')}
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ <InputNumber
+ className={styles.imageCommonPanelInput}
+ min={1}
+ value={height}
+ onChange={(val) => { handleHeightChange(val); }}
+ />
+ </div>
+ </div>
+ </label>
+ </div>
+ {/* <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan3)}>
+ <label>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ {localeService.t('image-panel.transform.lock')}
+ </div>
+ </div>
+ <div className={clsx(styles.imageCommonPanelRow, styles.imageCommonPanelRowVertical)}>
+ <div className={styles.imageCommonPanelColumn}>
+ <Checkbox checked={lockRatio} onChange={handleLockRatioChange}></Checkbox>
+ </div>
+ </div>
+ </label>
+ </div> */}
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan3)}>
+ <label>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ {localeService.t('image-panel.transform.x')}
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ <InputNumber
+ className={styles.imageCommonPanelInput}
+ precision={1}
+ min={0}
+ value={xPosition}
+ onChange={(val) => { handleXChange(val); }}
+ />
+ </div>
+ </div>
+ </label>
+ </div>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan3)}>
+ <label>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ {localeService.t('image-panel.transform.y')}
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ <InputNumber
+ className={styles.imageCommonPanelInput}
+ precision={1}
+ min={0}
+ value={yPosition}
+ onChange={(val) => { handleYChange(val); }}
+ />
+ </div>
+ </div>
+ </label>
+ </div>
+ <div className={clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan3)}>
+ <label>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ {localeService.t('image-panel.transform.rotate')}
+ </div>
+ </div>
+ <div className={styles.imageCommonPanelRow}>
+ <div className={styles.imageCommonPanelColumn}>
+ <InputNumber
+ className={styles.imageCommonPanelInput}
+ precision={1}
+ value={rotation}
+ onChange={handleChangeRotation}
+ />
+ </div>
+ </div>
+ </label>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/slides-ui/src/components/panels/index.module.less b/packages/slides-ui/src/components/panels/index.module.less
new file mode 100644
index 0000000000..cd983a8454
--- /dev/null
+++ b/packages/slides-ui/src/components/panels/index.module.less
@@ -0,0 +1,85 @@
+.slide-arrange-panel {
+}
+
+.image-common-panel {
+ text-align: center;
+ padding: var(--padding-sm);
+ font-size: var(--font-size-sm);
+ &-grid {
+ position: relative;
+ width: 100%;
+ }
+
+ &-border {
+ border-top: 1px solid rgb(var(--border-color));
+ margin-top: 20px;
+ }
+
+ &-title {
+ color: rgb(var(--text-color-secondary));
+ text-align: left;
+ }
+
+ &-subtitle {
+ color: rgb(var(--text-color-primary));
+ text-align: left;
+ }
+
+ &-row {
+ position: relative;
+ display: flex;
+ justify-content: flex-start;
+ align-items: flex-start;
+ height: 100%;
+ margin-top: 10px;
+
+ &-vertical {
+ justify-content: center;
+ align-items: center;
+ height: 36px;
+ }
+ }
+
+ &-column {
+ width: 100%;
+
+ &-center {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+ }
+
+ &-inline {
+ display: flex;
+ align-items: center;
+ gap: var(--margin-xxs);
+ }
+
+ &-span2 {
+ width: 50%;
+ }
+
+ &-span3 {
+ width: 33.33333333%;
+ }
+
+ &-input {
+ width: 90%;
+ }
+}
+
+.slide-panel {
+ &-color-picker {
+ box-sizing: border-box;
+ margin: 0;
+ padding: var(--padding-base);
+ font-size: var(--font-size-xs);
+ list-style: none;
+ background-color: rgb(var(--bg-color-secondary));
+ border: 1px solid rgb(var(--border-color));
+ border-radius: var(--border-radius-lg);
+ outline: none;
+ box-shadow: var(--box-shadow-base);
+ }
+}
diff --git a/packages/slides-ui/src/components/sidebar/Sidebar.tsx b/packages/slides-ui/src/components/sidebar/Sidebar.tsx
new file mode 100644
index 0000000000..b3bb6279f3
--- /dev/null
+++ b/packages/slides-ui/src/components/sidebar/Sidebar.tsx
@@ -0,0 +1,57 @@
+/**
+ * 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 { Nullable, SlideDataModel } from '@univerjs/core';
+import { IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';
+import { type BaseObject, ObjectType } from '@univerjs/engine-render';
+import { CanvasView } from '@univerjs/slides';
+import React from 'react';
+import ArrangePanel from '../panels/ArrangePanel';
+import TransformPanel from '../panels/TransformPanel';
+import FillPanel from '../panels/FillPanel';
+import styles from './index.module.less';
+
+export const COMPONENT_SLIDE_SIDEBAR = 'COMPONENT_SLIDE_SIDEBAR';
+
+export default function RectSidebar() {
+ const univerInstanceService = useDependency(IUniverInstanceService);
+ const canvasView = useDependency(CanvasView);
+
+ const currentSlide = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+ const pageId = currentSlide?.getActivePage()?.id;
+
+ if (!pageId) return null;
+
+ const page = canvasView.getRenderUnitByPageId(pageId);
+ const transformer = page.scene?.getTransformer();
+
+ if (!transformer) return null;
+
+ const selectedObjects = transformer.getSelectedObjectMap();
+
+ const object = selectedObjects.values().next().value as Nullable<BaseObject>;
+ if (!object) {
+ return null;
+ }
+
+ return (
+ <section className={styles.imageCommonPanel}>
+ <ArrangePanel unitId={pageId} />
+ <TransformPanel unitId={pageId} />
+ {object.objectType === ObjectType.RECT && <FillPanel unitId={pageId} />}
+ </section>
+ );
+}
diff --git a/packages/slides-ui/src/components/sidebar/index.module.less b/packages/slides-ui/src/components/sidebar/index.module.less
new file mode 100644
index 0000000000..6a9392c566
--- /dev/null
+++ b/packages/slides-ui/src/components/sidebar/index.module.less
@@ -0,0 +1,67 @@
+.image-common-panel {
+ text-align: center;
+ padding: var(--padding-sm);
+ font-size: var(--font-size-sm);
+ &-grid {
+ position: relative;
+ width: 100%;
+ }
+
+ &-border {
+ border-top: 1px solid rgb(var(--border-color));
+ margin-top: 20px;
+ }
+
+ &-title {
+ color: rgb(var(--text-color-secondary));
+ text-align: left;
+ }
+
+ &-subtitle {
+ color: rgb(var(--text-color-primary));
+ text-align: left;
+ }
+
+ &-row {
+ position: relative;
+ display: flex;
+ justify-content: flex-start;
+ align-items: flex-start;
+ height: 100%;
+ margin-top: 10px;
+
+ &-vertical {
+ justify-content: center;
+ align-items: center;
+ height: 36px;
+ }
+ }
+
+ &-column {
+ width: 100%;
+
+ &-center {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+ }
+
+ &-inline {
+ display: flex;
+ align-items: center;
+ gap: var(--margin-xxs);
+ }
+
+ &-span2 {
+ width: 50%;
+ }
+
+ &-span3 {
+ width: 33.33333333%;
+ }
+
+ &-input {
+ width: 90%;
+ }
+}
diff --git a/packages/slides-ui/src/views/slide-bar/SlideBar.tsx b/packages/slides-ui/src/components/slide-bar/SlideBar.tsx
similarity index 73%
rename from packages/slides-ui/src/views/slide-bar/SlideBar.tsx
rename to packages/slides-ui/src/components/slide-bar/SlideBar.tsx
index 2625f97556..0fe4cdb222 100644
--- a/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
+++ b/packages/slides-ui/src/components/slide-bar/SlideBar.tsx
@@ -16,14 +16,14 @@
import type { SlideDataModel } from '@univerjs/core';
import clsx from 'clsx';
-import { ICommandService, IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
import { Scrollbar } from '@univerjs/design';
import type { RefObject } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
-import { useObservable } from '@univerjs/ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { ActivateSlidePageOperation } from '../../commands/operations/activate.operation';
import { SetSlidePageThumbOperation } from '../../commands/operations/set-thumb.operation';
+import { AppendSlideOperation } from '../../commands/operations/append-slide.operation';
import styles from './index.module.less';
/**
@@ -34,14 +34,17 @@ export function SlideSideBar() {
const univerInstanceService = useDependency(IUniverInstanceService);
const commandService = useDependency(ICommandService);
const renderManagerService = useDependency(IRenderManagerService);
+ const localeService = useDependency(LocaleService);
const slideBarRef = useRef<HTMLDivElement>(null);
- const currentSlide = useObservable(
- () => univerInstanceService.getCurrentTypeOfUnit$<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE),
- undefined,
- undefined,
- []
- );
+ const currentSlide = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+
+ // const currentSlide = useObservable(
+ // () => univerInstanceService.getCurrentTypeOfUnit$<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE),
+ // undefined,
+ // undefined,
+ // []
+ // );
const pages = currentSlide?.getPages();
const pageOrder = currentSlide?.getPageOrder();
@@ -52,16 +55,22 @@ export function SlideSideBar() {
const slideList = pageOrder.map((id) => pages[id]);
const [divRefs, setDivRefs] = useState<RefObject<HTMLDivElement>[]>([]);
- const [activatePageId, setActivatePageId] = useState<string | null>(pageOrder[0]);
+ const [activatePageId, setActivatePageId] = useState<string | null>(currentSlide?.getActivePage()?.id ?? null);
useEffect(() => {
setDivRefs(slideList.map((_) => React.createRef()));
}, [slideList.length]);
useEffect(() => {
- currentSlide?.activePage$.subscribe((page) => {
- setActivatePageId(page?.id ?? null);
+ const subscriber = currentSlide?.activePage$.subscribe((page) => {
+ const id = page?.id ?? null;
+
+ id && setActivatePageId(id);
});
+
+ return () => {
+ subscriber?.unsubscribe();
+ };
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -82,10 +91,18 @@ export function SlideSideBar() {
commandService.syncExecuteCommand(ActivateSlidePageOperation.id, { id: page });
}, [commandService]);
+ const handleAppendSlide = useCallback(() => {
+ commandService.syncExecuteCommand(AppendSlideOperation.id);
+ }, [commandService]);
+
return (
- <div className={styles.slideBar} ref={slideBarRef}>
+ <aside className={styles.slideBar} ref={slideBarRef}>
<Scrollbar>
<div className={styles.slideBarContent}>
+ <header className={styles.slideBarContentHeader}>
+ <a onClick={handleAppendSlide}>{localeService.t('slide.append')}</a>
+ </header>
+
{slideList.map((item, index) => (
<div
key={item.id}
@@ -103,6 +120,6 @@ export function SlideSideBar() {
<Button onClick={addSlide}>+</Button>
</div> */}
</Scrollbar>
- </div>
+ </aside>
);
}
diff --git a/packages/slides-ui/src/views/slide-bar/index.module.less b/packages/slides-ui/src/components/slide-bar/index.module.less
similarity index 62%
rename from packages/slides-ui/src/views/slide-bar/index.module.less
rename to packages/slides-ui/src/components/slide-bar/index.module.less
index 4587922dac..2ee76b58db 100644
--- a/packages/slides-ui/src/views/slide-bar/index.module.less
+++ b/packages/slides-ui/src/components/slide-bar/index.module.less
@@ -14,9 +14,32 @@
.slide-bar-content {
padding: 0 15px;
+ &-header {
+ padding-top: var(--padding-lg);
+ display: flex;
+ justify-content: center;
+
+ a {
+ width: 212px;
+ padding: var(--padding-xs) 0;
+ font-size: var(--font-size-sm);
+ background: rgb(var(--bg-color-secondary));
+ text-align: center;
+ border: 1px solid rgb(var(--border-color));
+ border-radius: var(--border-radius-base);
+ display: block;
+ transition: all 0.25s;
+ cursor: pointer;
+
+ &:hover {
+ background: rgb(var(--bg-color-hover));
+ }
+ }
+ }
+
.slide-bar-item {
display: flex;
- margin: 15px 0;
+ margin: var(--margin-base) 0;
span {
width: 15px;
diff --git a/packages/slides-ui/src/controllers/popup-menu.controller.ts b/packages/slides-ui/src/controllers/popup-menu.controller.ts
index 7fe0feec29..b53dd704ed 100644
--- a/packages/slides-ui/src/controllers/popup-menu.controller.ts
+++ b/packages/slides-ui/src/controllers/popup-menu.controller.ts
@@ -15,28 +15,28 @@
*/
import type { IDisposable, Nullable, SlideDataModel } from '@univerjs/core';
-import { FOCUSING_COMMON_DRAWINGS, IContextService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
-import type { BaseObject, Scene } from '@univerjs/engine-render';
-import { IRenderManagerService, ObjectType } from '@univerjs/engine-render';
-import { IUIPartsService } from '@univerjs/ui';
+import { FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
+import type { BaseObject, ObjectType, Scene } from '@univerjs/engine-render';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { ISidebarService } from '@univerjs/ui';
import { CanvasView } from '@univerjs/slides';
import { SlideCanvasPopMangerService } from '../services/slide-popup-manager.service';
import { COMPONENT_SLIDE_IMAGE_POPUP_MENU } from '../components/image-popup-menu/component-name';
import { DeleteSlideElementOperation } from '../commands/operations/delete-element.operation';
+import { ToggleSlideEditSidebarOperation } from '../commands/operations/insert-shape.operation';
@OnLifecycle(LifecycleStages.Steady, SlidePopupMenuController)
export class SlidePopupMenuController extends RxDisposable {
private _initImagePopupMenu = new Set<string>();
constructor(
- @Inject(Injector) private _injector: Injector,
- // @IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
@Inject(SlideCanvasPopMangerService) private readonly _canvasPopManagerService: SlideCanvasPopMangerService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IContextService private readonly _contextService: IContextService,
- @Inject(IUIPartsService) private readonly _uiPartsService: IUIPartsService,
- @Inject(CanvasView) private readonly _canvasView: CanvasView
+ @Inject(CanvasView) private readonly _canvasView: CanvasView,
+ @ISidebarService private readonly _sidebarService: ISidebarService,
+ @ICommandService private readonly _commandService: ICommandService
) {
super();
@@ -127,6 +127,13 @@ export class SlidePopupMenuController extends RxDisposable {
},
}));
+ if (this._sidebarService.visible) {
+ this._commandService.executeCommand(ToggleSlideEditSidebarOperation.id, {
+ visible: true,
+ objectType: object.objectType,
+ });
+ }
+
// this._drawingManagerService.focusDrawing([{
// unitId,
// subUnitId,
@@ -151,35 +158,16 @@ export class SlidePopupMenuController extends RxDisposable {
}
private _getMenuItemsByObjectType(objectType: ObjectType, oKey: string, unitId: string) {
- const menuItems = [];
-
- if (objectType === ObjectType.RICH_TEXT) {
- menuItems.push({
- label: 'slide.popup.edit',
- index: 0,
- commandId: 'xxxx',
- commandParams: {},
- disable: false,
- });
- } else if (objectType === ObjectType.IMAGE) {
- menuItems.push({
- label: 'slide.popup.edit',
- index: 0,
- commandId: 'xxxx',
- commandParams: {},
- disable: false,
- });
- } else if (objectType === ObjectType.RECT) {
- menuItems.push({
- label: 'slide.popup.edit',
- index: 0,
- commandId: 'xxxx',
- commandParams: {},
- disable: false,
- });
- }
-
- menuItems.push({
+ const menuItems = [{
+ label: 'slide.popup.edit',
+ index: 0,
+ commandId: ToggleSlideEditSidebarOperation.id,
+ commandParams: {
+ visible: true,
+ objectType,
+ },
+ disable: false,
+ }, {
label: 'slide.popup.delete',
index: 5,
commandId: DeleteSlideElementOperation.id,
@@ -187,38 +175,7 @@ export class SlidePopupMenuController extends RxDisposable {
id: oKey,
},
disable: false,
- });
-
- // return [
- // {
- // label: 'image-popup.edit',
- // index: 0,
- // commandId: 'EditSheetDrawingOperation.id',
- // commandParams: { unitId },
- // disable: false,
- // },
- // {
- // label: 'image-popup.delete',
- // index: 1,
- // commandId: 'RemoveSheetDrawingCommand.id',
- // commandParams: { unitId, drawings: [{ unitId }] },
- // disable: false,
- // },
- // {
- // label: 'image-popup.crop',
- // index: 2,
- // commandId: 'OpenImageCropOperation.id',
- // commandParams: { unitId },
- // disable: false,
- // },
- // {
- // label: 'image-popup.reset',
- // index: 3,
- // commandId: 'ImageResetSizeOperation.id',
- // commandParams: [{ unitId }],
- // disable: false,
- // },
- // ];
+ }];
return menuItems;
}
diff --git a/packages/slides-ui/src/controllers/slide-ui.controller.ts b/packages/slides-ui/src/controllers/slide-ui.controller.ts
index 68ef76ec2e..4f379440ac 100644
--- a/packages/slides-ui/src/controllers/slide-ui.controller.ts
+++ b/packages/slides-ui/src/controllers/slide-ui.controller.ts
@@ -22,7 +22,7 @@ import { BuiltInUIPart, ComponentManager, IMenuService, IShortcutService, IUIPar
import { ActivateSlidePageOperation } from '../commands/operations/activate.operation';
import { DeleteSlideElementOperation } from '../commands/operations/delete-element.operation';
import { InsertSlideFloatImageOperation } from '../commands/operations/insert-image.operation';
-import { InsertSlideShapeRectangleOperation } from '../commands/operations/insert-shape.operation';
+import { InsertSlideShapeRectangleOperation, ToggleSlideEditSidebarOperation } from '../commands/operations/insert-shape.operation';
import { SlideAddTextOperation } from '../commands/operations/insert-text.operation';
import { SetSlidePageThumbOperation } from '../commands/operations/set-thumb.operation';
import { SetTextEditArrowOperation } from '../commands/operations/text-edit.operation';
@@ -31,7 +31,9 @@ import { COMPONENT_SLIDE_IMAGE_POPUP_MENU } from '../components/image-popup-menu
import { UploadFileMenu } from '../components/upload-component/UploadFile';
import { COMPONENT_UPLOAD_FILE_MENU } from '../components/upload-component/component-name';
import { EditorContainer } from '../views/editor-container';
-import { SlideSideBar } from '../views/slide-bar/SlideBar';
+import { SlideSideBar } from '../components/slide-bar/SlideBar';
+import Sidebar, { COMPONENT_SLIDE_SIDEBAR } from '../components/sidebar/Sidebar';
+import { AppendSlideOperation } from '../commands/operations/append-slide.operation';
import { IMAGE_UPLOAD_ICON, SlideImageMenuFactory, UploadSlideFloatImageMenuFactory } from './image.menu';
import { GRAPH_SINGLE_ICON, SlideShapeMenuFactory, UploadSlideFloatShapeMenuFactory } from './shape.menu';
import { EditorDeleteLeftShortcut, generateArrowSelectionShortCutItem } from './shortcuts/editor.shortcuts';
@@ -90,16 +92,18 @@ export class SlideUIController extends Disposable {
this.disposeWithMe(componentManager.register(GRAPH_SINGLE_ICON, GraphSingle));
this.disposeWithMe(componentManager.register(COMPONENT_UPLOAD_FILE_MENU, UploadFileMenu));
this.disposeWithMe(componentManager.register(COMPONENT_SLIDE_IMAGE_POPUP_MENU, SlideImagePopupMenu));
- // this.disposeWithMe(componentManager.register(COMPONENT_SHEET_DRAWING_PANEL, SheetDrawingPanel));
+ this.disposeWithMe(componentManager.register(COMPONENT_SLIDE_SIDEBAR, Sidebar));
}
private _initCommands(): void {
[
+ AppendSlideOperation,
ActivateSlidePageOperation,
SetSlidePageThumbOperation,
InsertSlideFloatImageOperation,
SlideAddTextOperation,
InsertSlideShapeRectangleOperation,
+ ToggleSlideEditSidebarOperation,
DeleteSlideElementOperation,
//cmds for editor
diff --git a/packages/slides-ui/src/locale/en-US.ts b/packages/slides-ui/src/locale/en-US.ts
index a62c32adad..e0080fdc92 100644
--- a/packages/slides-ui/src/locale/en-US.ts
+++ b/packages/slides-ui/src/locale/en-US.ts
@@ -18,6 +18,8 @@ import type zhCN from './zh-CN';
const locale: typeof zhCN = {
slide: {
+ append: 'Append Slide',
+
text: {
insert: {
title: 'Insert Text',
@@ -42,6 +44,18 @@ const locale: typeof zhCN = {
edit: 'Edit',
delete: 'Delete',
},
+
+ sidebar: {
+ text: 'Edit Text',
+ shape: 'Edit Shape',
+ image: 'Edit Image',
+ },
+
+ panel: {
+ fill: {
+ title: 'Fill Color',
+ },
+ },
},
};
diff --git a/packages/slides-ui/src/locale/zh-CN.ts b/packages/slides-ui/src/locale/zh-CN.ts
index 6db784db89..61c248ba76 100644
--- a/packages/slides-ui/src/locale/zh-CN.ts
+++ b/packages/slides-ui/src/locale/zh-CN.ts
@@ -16,6 +16,8 @@
const locale = {
slide: {
+ append: '新增幻灯片',
+
text: {
insert: {
title: '插入文本',
@@ -40,6 +42,18 @@ const locale = {
edit: '编辑',
delete: '删除',
},
+
+ sidebar: {
+ text: '编辑文本',
+ shape: '编辑图形',
+ image: '编辑图片',
+ },
+
+ panel: {
+ fill: {
+ title: '填充',
+ },
+ },
},
};
diff --git a/packages/slides-ui/src/services/slide-popup-manager.service.ts b/packages/slides-ui/src/services/slide-popup-manager.service.ts
index a77093465d..868e4186f7 100644
--- a/packages/slides-ui/src/services/slide-popup-manager.service.ts
+++ b/packages/slides-ui/src/services/slide-popup-manager.service.ts
@@ -17,7 +17,8 @@
import type { IDisposable } from '@univerjs/core';
import { Disposable, DisposableCollection, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService, pxToNum } from '@univerjs/engine-render';
-import type { BaseObject, IBoundRectNoAngle, IRender } from '@univerjs/engine-render';
+import type { BaseObject, IBoundRectNoAngle, IRender, Scene } from '@univerjs/engine-render';
+import { SLIDE_KEY } from '@univerjs/slides';
import type { IPopup } from '@univerjs/ui';
import { ICanvasPopupService } from '@univerjs/ui';
import { BehaviorSubject } from 'rxjs';
@@ -29,6 +30,40 @@ export interface ISlideCanvasPopup extends Pick<IPopup,
extraProps?: Record<string, any>;
}
+export function transformBound2OffsetBound(originBound: IBoundRectNoAngle, scene: Scene): IBoundRectNoAngle {
+ const topLeft = transformPosition2Offset(originBound.left, originBound.top, scene);
+ const bottomRight = transformPosition2Offset(originBound.right, originBound.bottom, scene);
+
+ return {
+ left: topLeft.x,
+ top: topLeft.y,
+ right: bottomRight.x,
+ bottom: bottomRight.y,
+ };
+}
+
+export function transformPosition2Offset(x: number, y: number, scene: Scene) {
+ const { scaleX, scaleY } = scene.getAncestorScale();
+ const viewMain = scene.getViewport(SLIDE_KEY.VIEW);
+ if (!viewMain) {
+ return {
+ x,
+ y,
+ };
+ }
+
+ const { viewportScrollX: actualScrollX, viewportScrollY: actualScrollY } = viewMain;
+
+ const offsetX = (x - actualScrollX) * scaleX;
+
+ const offsetY = (y - actualScrollY) * scaleY;
+
+ return {
+ x: offsetX,
+ y: offsetY,
+ };
+}
+
export class SlideCanvasPopMangerService extends Disposable {
constructor(
@Inject(ICanvasPopupService) private readonly _globalPopupManagerService: ICanvasPopupService,
@@ -47,6 +82,9 @@ export class SlideCanvasPopMangerService extends Disposable {
const { scene, engine } = currentRender;
const { left, top, width, height } = targetObject;
+ const horizontalOffset = (scene.width - (currentRender.mainComponent?.width ?? 0)) / 2;
+ const verticalOffset = (scene.height - (currentRender.mainComponent?.height ?? 0)) / 2;
+
const bound: IBoundRectNoAngle = {
left,
right: left + width,
@@ -59,15 +97,15 @@ export class SlideCanvasPopMangerService extends Disposable {
const { scaleX, scaleY } = scene.getAncestorScale();
- // const offsetBound = transformBound2OffsetBound(bound, scene);
+ const offsetBound = transformBound2OffsetBound(bound, scene);
const { top: topOffset, left: leftOffset, width: domWidth } = canvasClientRect;
const scaleAdjust = domWidth / widthOfCanvas;
const position = {
- left: (bound.left * scaleAdjust * scaleX) + leftOffset,
- right: (bound.right * scaleAdjust * scaleX) + leftOffset,
- top: (bound.top * scaleAdjust * scaleY) + topOffset,
- bottom: (bound.bottom * scaleAdjust * scaleY) + topOffset,
+ left: (offsetBound.left * scaleAdjust * scaleX) + leftOffset + horizontalOffset,
+ right: (offsetBound.right * scaleAdjust * scaleX) + leftOffset + horizontalOffset,
+ top: (offsetBound.top * scaleAdjust * scaleY) + topOffset + verticalOffset,
+ bottom: (offsetBound.bottom * scaleAdjust * scaleY) + topOffset + verticalOffset,
};
return position;
};
diff --git a/packages/slides-ui/src/slides-ui-plugin.ts b/packages/slides-ui/src/slides-ui-plugin.ts
index fca0ec286a..bd9a60ccb1 100644
--- a/packages/slides-ui/src/slides-ui-plugin.ts
+++ b/packages/slides-ui/src/slides-ui-plugin.ts
@@ -17,7 +17,6 @@
import type { Dependency, SlideDataModel } from '@univerjs/core';
import { Inject, Injector, IUniverInstanceService, Plugin, UniverInstanceType } from '@univerjs/core';
-import { IImageIoService, ImageIoService } from '@univerjs/drawing';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { IUniverSlidesDrawingConfig } from './controllers/slide-ui.controller';
import { SlideUIController } from './controllers/slide-ui.controller';
@@ -49,7 +48,6 @@ export class UniverSlidesUIPlugin extends Plugin {
[ISlideEditorBridgeService, { useClass: SlideEditorBridgeService }],
// used by SlideUIController --> EditorContainer
[ISlideEditorManagerService, { useClass: SlideEditorManagerService }],
- [IImageIoService, { useClass: ImageIoService }],
[SlideCanvasPopMangerService],
] as Dependency[]).forEach((d) => this._injector.add(d));
}
diff --git a/packages/slides/src/views/render/adaptors/docs-adaptor.ts b/packages/slides/src/views/render/adaptors/docs-adaptor.ts
index 5b10bdd6a2..239cde2a86 100644
--- a/packages/slides/src/views/render/adaptors/docs-adaptor.ts
+++ b/packages/slides/src/views/render/adaptors/docs-adaptor.ts
@@ -24,7 +24,7 @@ import {
Image,
Liquid,
PageLayoutType,
- Rect,
+ // Rect,
Scene,
SceneViewer,
ScrollBar,
@@ -165,14 +165,14 @@ export class DocsAdaptor extends ObjectAdaptor {
const { width, height, marginBottom, marginLeft, marginRight, marginTop } = page;
ctx.save();
ctx.translate(pageLeft - 0.5, pageTop - 0.5);
- Rect.drawWith(ctx, {
- width: pageSize?.width || width,
- height: pageSize?.height || height,
- strokeWidth: 1,
- stroke: 'rgba(198,198,198, 1)',
- fill: 'rgba(255,255,255, 1)',
- zIndex: 3,
- });
+ // Rect.drawWith(ctx, {
+ // width: pageSize?.width || width,
+ // height: pageSize?.height || height,
+ // strokeWidth: 1,
+ // stroke: 'rgba(198,198,198, 1)',
+ // fill: 'rgba(255,255,255, 1)',
+ // zIndex: 3,
+ // });
ctx.restore();
});
diff --git a/packages/slides/src/views/render/canvas-view.ts b/packages/slides/src/views/render/canvas-view.ts
index 1967ba50a5..2aff41d6e9 100644
--- a/packages/slides/src/views/render/canvas-view.ts
+++ b/packages/slides/src/views/render/canvas-view.ts
@@ -258,7 +258,7 @@ export class CanvasView extends RxDisposable implements IRenderModule {
zIndex: 10,
});
- slideComponent.enableNav();
+ // slideComponent.enableNav();
slideComponent.enableSelectedClipElement();
@@ -280,8 +280,8 @@ export class CanvasView extends RxDisposable implements IRenderModule {
width: pageWidth,
height: pageHeight,
strokeWidth: 1,
- stroke: 'rgba(198,198,198, 1)',
- fill: getColorStyle(fill) || 'rgba(255,255,255, 1)',
+ stroke: 'rgba(198,198,198,1)',
+ fill: getColorStyle(fill) || 'rgba(255,255,255,1)',
zIndex: 0,
evented: false,
});
@@ -480,6 +480,7 @@ export class CanvasView extends RxDisposable implements IRenderModule {
setObjectActiveByPage(obj: BaseObject, pageID: PageID) {
const { scene } = this.getRenderUnitByPageId(pageID);
+ // console.log(obj);
if (!scene) return;
const transformer = scene.getTransformer();
transformer?.activeAnObject(obj);
@@ -492,4 +493,26 @@ export class CanvasView extends RxDisposable implements IRenderModule {
const transformer = scene.getTransformer();
transformer?.clearControls();
}
+
+ appendPage() {
+ const model = this._univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE)!;
+ const page = model.getBlankPage();
+
+ const render = this._currentRender();
+
+ if (page == null || render == null || render.mainComponent == null) {
+ return;
+ }
+
+ const { id } = page;
+
+ const slide = render.mainComponent as Slide;
+
+ const scene = this._createScene(id, page);
+
+ scene && slide?.addPage(scene);
+
+ model.appendPage(page);
+ model.setActivePage(page);
+ }
}
diff --git a/packages/ui/src/services/sidebar/desktop-sidebar.service.ts b/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
index 258d0a574e..43ce264950 100644
--- a/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
+++ b/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
@@ -27,6 +27,10 @@ export class DesktopSidebarService implements ISidebarService {
readonly scrollEvent$ = new Subject<Event>();
+ get visible(): boolean {
+ return this._sidebarOptions.visible || false;
+ }
+
open(params: ISidebarMethodOptions): IDisposable {
this._sidebarOptions = {
...params,
diff --git a/packages/ui/src/services/sidebar/sidebar.service.ts b/packages/ui/src/services/sidebar/sidebar.service.ts
index 976d7741bd..c28c6075e2 100644
--- a/packages/ui/src/services/sidebar/sidebar.service.ts
+++ b/packages/ui/src/services/sidebar/sidebar.service.ts
@@ -28,4 +28,6 @@ export interface ISidebarService {
open(params: ISidebarMethodOptions): IDisposable;
close(id?: string): void;
+
+ get visible(): boolean;
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 855b8521e9..a8072f5c4e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2413,9 +2413,6 @@ importers:
packages/slides-ui:
dependencies:
- '@univerjs/docs-drawing-ui':
- specifier: workspace:*
- version: link:../docs-drawing-ui
'@univerjs/docs-ui':
specifier: workspace:*
version: link:../docs-ui