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): support partial slides function (#2890)

白熱3a90918b370f
diff --git a/packages/core/src/slides/slide-model.ts b/packages/core/src/slides/slide-model.ts
index 02ccc40069..986ccb2f4a 100644
--- a/packages/core/src/slides/slide-model.ts
+++ b/packages/core/src/slides/slide-model.ts
@@ -14,7 +14,9 @@
* limitations under the License.
*/
+import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../common/unit';
+import type { Nullable } from '../shared';
import { Tools } from '../shared';
import { DEFAULT_SLIDE } from '../types/const';
import type { ISlideData, ISlidePage } from '../types/interfaces';
@@ -22,6 +24,23 @@ import { PageType } from '../types/interfaces';
export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNIVER_SLIDE> {
override type: UniverInstanceType.UNIVER_SLIDE = UniverInstanceType.UNIVER_SLIDE;
+ private readonly _activePage$ = new BehaviorSubject<Nullable<ISlidePage>>(null);
+ private get _activePage(): Nullable<ISlidePage> {
+ const activePage = this._activePage$.getValue();
+
+ if (!activePage) {
+ const activePageId = this.getPageOrder()?.[0];
+ if (!activePageId) {
+ return null;
+ }
+
+ return this.getPages()?.[activePageId];
+ }
+
+ return activePage;
+ }
+
+ readonly activePage$ = this._activePage$.asObservable();
private _snapshot: ISlideData;
@@ -75,7 +94,7 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
return {
id: 'cover_1',
pageType: PageType.SLIDE,
- zIndex: 1,
+ zIndex: 10,
title: 'cover',
description: 'this is first page, cover',
pageBackgroundFill: {
@@ -84,4 +103,18 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
pageElements: {},
};
}
+
+ setActivePage(page: Nullable<ISlidePage>) {
+ this._activePage$.next(page);
+ }
+
+ getActivePage() {
+ return this._activePage;
+ }
+
+ updatePage(pageId: string, page: ISlidePage) {
+ if (!this._snapshot.body) return;
+
+ this._snapshot.body.pages[pageId] = page;
+ }
}
diff --git a/packages/engine-render/src/base-object.ts b/packages/engine-render/src/base-object.ts
index d5b5af8920..16575fcd6d 100644
--- a/packages/engine-render/src/base-object.ts
+++ b/packages/engine-render/src/base-object.ts
@@ -43,10 +43,21 @@ export const BASE_OBJECT_ARRAY = [
'strokeWidth',
];
+export enum ObjectType {
+ UNKNOWN,
+ RICH_TEXT,
+ SHAPE,
+ IMAGE,
+ RECT,
+ CIRCLE,
+}
+
export abstract class BaseObject extends Disposable {
groupKey?: string;
isInGroup: boolean = false;
+ objectType: ObjectType = ObjectType.UNKNOWN;
+
onTransformChange$ = new EventSubject<ITransformChangeState>();
onPointerDown$ = new EventSubject<IPointerEvent | IMouseEvent>();
diff --git a/packages/engine-render/src/layer.ts b/packages/engine-render/src/layer.ts
index 5721360618..185b3aeff4 100644
--- a/packages/engine-render/src/layer.ts
+++ b/packages/engine-render/src/layer.ts
@@ -102,7 +102,7 @@ export class Layer extends Disposable {
* insert o to _objects[]
* if o is a group, insert all its children and group itself to _objects[]
* @param o
- * @returns
+ * @returns this
*/
addObject(o: BaseObject) {
if (o.classType === RENDER_CLASS_TYPE.GROUP) {
diff --git a/packages/engine-render/src/render-manager/render-manager.service.ts b/packages/engine-render/src/render-manager/render-manager.service.ts
index dbd85741d2..2df8b780ba 100644
--- a/packages/engine-render/src/render-manager/render-manager.service.ts
+++ b/packages/engine-render/src/render-manager/render-manager.service.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType, UniverInstanceType } from '@univerjs/core';
-import { createIdentifier, Disposable, Inject, Injector, IUniverInstanceService, remove, toDisposable } from '@univerjs/core';
+import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType } from '@univerjs/core';
+import { createIdentifier, Disposable, Inject, Injector, IUniverInstanceService, remove, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { Observable } from 'rxjs';
import { BehaviorSubject, Subject } from 'rxjs';
@@ -148,9 +148,17 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
dependencies.push(ctor);
for (const [renderUnitId, render] of this._renderMap) {
- const renderType = this._univerInstanceService.getUnitType(renderUnitId);
- if (renderType === type) {
- (render as RenderUnit).addRenderDependencies([ctor]);
+ if (type === UniverInstanceType.UNIVER_SLIDE) {
+ // const renderType = this._univerInstanceService.getUnitType(renderUnitId);
+ // renderUnitId slide_test cover_1 rect_1....
+ if (this._univerInstanceService.getUnit(renderUnitId)) {
+ (render as RenderUnit).addRenderDependencies([ctor]);
+ }
+ } else {
+ const renderType = this._univerInstanceService.getUnitType(renderUnitId);
+ if (renderType === type) {
+ (render as RenderUnit).addRenderDependencies([ctor]);
+ }
}
}
@@ -217,7 +225,7 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
height,
});
- const unit = this._univerInstanceService.getUnit(unitId)!;
+ const unit = this._univerInstanceService.getUnit(unitId);
let renderUnit: IRender;
if (unit) {
diff --git a/packages/engine-render/src/scene.transformer.ts b/packages/engine-render/src/scene.transformer.ts
index d7b0040853..d14314cfbe 100644
--- a/packages/engine-render/src/scene.transformer.ts
+++ b/packages/engine-render/src/scene.transformer.ts
@@ -1609,6 +1609,10 @@ export class Transformer extends Disposable implements ITransformerConfig {
return currentScene.getEngine()?.activeScene as Nullable<Scene>;
}
+ activeAnObject(applyObject: BaseObject) {
+ this._updateActiveObjectList(applyObject, {} as IPointerEvent);
+ }
+
private _updateActiveObjectList(applyObject: BaseObject, evt: IPointerEvent | IMouseEvent) {
const { isCropper } = this._getConfig(applyObject);
diff --git a/packages/engine-render/src/shape/circle.ts b/packages/engine-render/src/shape/circle.ts
index 824af4213f..602f1dc1c0 100644
--- a/packages/engine-render/src/shape/circle.ts
+++ b/packages/engine-render/src/shape/circle.ts
@@ -18,6 +18,7 @@ import type { IKeyValue } from '@univerjs/core';
import { TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '../basics/interfaces';
import type { UniverRenderingContext } from '../context';
+import { ObjectType } from '../base-object';
import type { IShapeProps } from './shape';
import { Shape } from './shape';
@@ -30,6 +31,8 @@ export const CIRCLE_OBJECT_ARRAY = ['radius'];
export class Circle extends Shape<ICircleProps> {
private _radius: number;
+ override objectType = ObjectType.CIRCLE;
+
constructor(key?: string, props?: ICircleProps) {
super(key, props);
this._radius = props?.radius || 10;
diff --git a/packages/engine-render/src/shape/image.ts b/packages/engine-render/src/shape/image.ts
index 6f02df2a0c..7f6e9bb483 100644
--- a/packages/engine-render/src/shape/image.ts
+++ b/packages/engine-render/src/shape/image.ts
@@ -21,6 +21,7 @@ import type { IObjectFullState, ITransformChangeState, IViewportInfo } from '../
import { RENDER_CLASS_TYPE, Vector2 } from '../basics';
import { offsetRotationAxis } from '../basics/offset-rotation-axis';
import type { Scene } from '../scene';
+import { ObjectType } from '../base-object';
import type { IShapeProps } from './shape';
import { Shape } from './shape';
@@ -51,6 +52,8 @@ export class Image extends Shape<IImageProps> {
private _transformCalculateSrcRect: boolean = true;
+ override objectType = ObjectType.IMAGE;
+
constructor(id: string, config: IImageProps) {
super(id, config);
this._props = {
diff --git a/packages/engine-render/src/shape/rect.ts b/packages/engine-render/src/shape/rect.ts
index 64b99d3c4f..5ad8251019 100644
--- a/packages/engine-render/src/shape/rect.ts
+++ b/packages/engine-render/src/shape/rect.ts
@@ -18,6 +18,7 @@ import { type IKeyValue, Rectangle } from '@univerjs/core';
import type { UniverRenderingContext } from '../context';
import type { IViewportInfo } from '../basics/vector2';
+import { ObjectType } from '../base-object';
import type { IShapeProps } from './shape';
import { Shape } from './shape';
@@ -30,6 +31,8 @@ export const RECT_OBJECT_ARRAY = ['radius'];
export class Rect<T extends IRectProps = IRectProps> extends Shape<T> {
private _radius: number = 0;
+ override objectType = ObjectType.RECT;
+
constructor(key?: string, props?: T) {
super(key, props);
if (props?.radius) {
diff --git a/packages/engine-render/src/shape/rich-text.ts b/packages/engine-render/src/shape/rich-text.ts
index 9be21e6113..0791b9fd20 100644
--- a/packages/engine-render/src/shape/rich-text.ts
+++ b/packages/engine-render/src/shape/rich-text.ts
@@ -27,7 +27,7 @@ import type {
} from '@univerjs/core';
import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentDataModel } from '@univerjs/core';
-import { BaseObject } from '../base-object';
+import { BaseObject, ObjectType } from '../base-object';
import { TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '../basics/interfaces';
import type { IViewportInfo } from '../basics/vector2';
import { DocumentSkeleton } from '../components/docs/layout/doc-skeleton';
@@ -77,6 +77,8 @@ export class RichText extends BaseObject {
private _cl?: Nullable<IColorStyle>;
+ override objectType = ObjectType.RICH_TEXT;
+
constructor(
private _localeService: LocaleService,
key?: string,
diff --git a/packages/engine-render/src/shape/shape.ts b/packages/engine-render/src/shape/shape.ts
index 3b16d3e7cb..8cfbe7233b 100644
--- a/packages/engine-render/src/shape/shape.ts
+++ b/packages/engine-render/src/shape/shape.ts
@@ -16,7 +16,7 @@
import type { IKeyValue, IOffset, IScale, ISize, Nullable } from '@univerjs/core';
-import { BASE_OBJECT_ARRAY, BaseObject } from '../base-object';
+import { BASE_OBJECT_ARRAY, BaseObject, ObjectType } from '../base-object';
import { SHAPE_TYPE } from '../basics/const';
import type { IObjectFullState } from '../basics/interfaces';
import type { IViewportInfo, Vector2 } from '../basics/vector2';
@@ -133,6 +133,8 @@ export abstract class Shape<T extends IShapeProps> extends BaseObject {
private _type: SHAPE_TYPE = SHAPE_TYPE.RECT;
+ override objectType = ObjectType.SHAPE;
+
constructor(key?: string, props?: T) {
super(key);
diff --git a/packages/sheets-numfmt/src/locale/en-US.ts b/packages/sheets-numfmt/src/locale/en-US.ts
index 39b4bd8864..1936dab54d 100644
--- a/packages/sheets-numfmt/src/locale/en-US.ts
+++ b/packages/sheets-numfmt/src/locale/en-US.ts
@@ -51,7 +51,6 @@ const locale: typeof zhCN = {
subtractDecimal: 'Decreasing decimal places',
customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',
-
},
},
};
diff --git a/packages/sheets-numfmt/src/locale/ru-RU.ts b/packages/sheets-numfmt/src/locale/ru-RU.ts
index 0458fe7f01..0a35d55b0e 100644
--- a/packages/sheets-numfmt/src/locale/ru-RU.ts
+++ b/packages/sheets-numfmt/src/locale/ru-RU.ts
@@ -51,7 +51,6 @@ const locale: typeof zhCN = {
subtractDecimal: 'Уменьшить количество десятичных знаков',
customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',
-
},
},
};
diff --git a/packages/sheets-numfmt/src/locale/vi-VN.ts b/packages/sheets-numfmt/src/locale/vi-VN.ts
index 2b84a5f273..65b34a8847 100644
--- a/packages/sheets-numfmt/src/locale/vi-VN.ts
+++ b/packages/sheets-numfmt/src/locale/vi-VN.ts
@@ -51,7 +51,6 @@ const locale: typeof zhCN = {
subtractDecimal: 'Giảm chữ số thập phân',
customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',
-
},
},
};
diff --git a/packages/sheets-numfmt/src/locale/zh-CN.ts b/packages/sheets-numfmt/src/locale/zh-CN.ts
index 010b6ab31b..167a0fbade 100644
--- a/packages/sheets-numfmt/src/locale/zh-CN.ts
+++ b/packages/sheets-numfmt/src/locale/zh-CN.ts
@@ -49,7 +49,6 @@ const locale = {
subtractDecimal: '减少小数位',
customFormat: '自定义格式',
customFormatDes: '根据现有格式生成自定义数字格式。',
-
},
},
};
diff --git a/packages/sheets-numfmt/src/locale/zh-TW.ts b/packages/sheets-numfmt/src/locale/zh-TW.ts
index 5304410450..0b92b65e87 100644
--- a/packages/sheets-numfmt/src/locale/zh-TW.ts
+++ b/packages/sheets-numfmt/src/locale/zh-TW.ts
@@ -43,15 +43,14 @@ const locale: typeof zhCN = {
currencyDes: '貨幣格式用來表示一般貨幣數值。會計格式可以對一列數值進行小數點對齊',
accountingDes: '會計數字格式可對一列數值進行貨幣符號和小數點對齊',
dateType: '日期類型',
- dateDes: '日期格式將日期和時間系列數值品顯示為日期值。 ',
+ dateDes: '日期格式將日期和時間系列數值品顯示為日期值。',
negType: '負數型別',
- generalDes: '常規格式不包含任何特定的數字格式。 ',
- thousandthPercentileDes: '千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。 ',
+ generalDes: '常規格式不包含任何特定的數字格式。',
+ thousandthPercentileDes: '千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。',
addDecimal: '增加小數位',
subtractDecimal: '減少小數位',
- customFormat: '自定义格式',
- customFormatDes: '根据现有格式生成自定义数字格式。',
-
+ customFormat: 'Custom Format',
+ customFormatDes: 'Generate custom number formats based on existing formats.',
},
},
};
diff --git a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts
index 662edd5240..ffe54de85f 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts
@@ -59,7 +59,6 @@ export class SheetRenderController extends RxDisposable implements IRenderModule
private _addNewRender() {
const { scene, engine, unit: workbook } = this._context;
-
scene.addLayer(new Layer(scene, [], 0), new Layer(scene, [], 2));
this._addComponent(workbook);
diff --git a/packages/slides-ui/package.json b/packages/slides-ui/package.json
index 392116ab3c..6a86e27700 100644
--- a/packages/slides-ui/package.json
+++ b/packages/slides-ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@univerjs/slides-ui",
"version": "0.2.5",
- "private": false,
+ "private": true,
"description": "Univer normal ui-plugin-slides",
"author": "DreamNum <[email protected]>",
"license": "Apache-2.0",
@@ -67,16 +67,22 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
+ "@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/slides": "workspace:*",
"@univerjs/ui": "workspace:*",
"clsx": ">=2.0.0",
- "react": "^16.9.0 || ^17.0.0 || ^18.0.0"
+ "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
+ "rxjs": ">=7.0.0"
+ },
+ "dependencies": {
+ "@univerjs/icons": "^0.1.65"
},
"devDependencies": {
"@types/react": "^18.3.3",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
+ "@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/slides": "workspace:*",
diff --git a/packages/slides-ui/src/commands/operations/activate.operation.ts b/packages/slides-ui/src/commands/operations/activate.operation.ts
index 1310952936..10b538a0f8 100644
--- a/packages/slides-ui/src/commands/operations/activate.operation.ts
+++ b/packages/slides-ui/src/commands/operations/activate.operation.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import type { IAccessor, IOperation } from '@univerjs/core';
-import { CommandType } from '@univerjs/core';
+import type { IAccessor, IOperation, SlideDataModel } from '@univerjs/core';
+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { CanvasView } from '@univerjs/slides';
export interface IActiveSlidePageOperationParams {
@@ -26,6 +26,18 @@ export const ActivateSlidePageOperation: IOperation<IActiveSlidePageOperationPar
type: CommandType.OPERATION,
handler: (accessor: IAccessor, params: IActiveSlidePageOperationParams) => {
const canvasView = accessor.get(CanvasView);
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const model = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+ const id = model?.getActivePage()?.id;
+
+ if (!id) return false;
+
+ const page = canvasView.getRenderUnitByPageId(id);
+ const transformer = page.scene?.getTransformer();
+
+ if (!transformer) return false;
+ transformer.clearControls();
+
canvasView.activePage(params.id);
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
new file mode 100644
index 0000000000..c341fabf8a
--- /dev/null
+++ b/packages/slides-ui/src/commands/operations/delete-element.operation.ts
@@ -0,0 +1,47 @@
+/**
+ * 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 interface IDeleteElementOperationParams {
+ id: string;
+};
+
+export const DeleteSlideElementOperation: ICommand<IDeleteElementOperationParams> = {
+ id: 'slide.operation.delete-element',
+ type: CommandType.OPERATION,
+ handler: (accessor, params) => {
+ if (!params?.id) return false;
+
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+
+ if (!slideData) return false;
+
+ const activePage = slideData.getActivePage()!;
+
+ delete activePage.pageElements[params.id];
+
+ slideData.updatePage(activePage.id, activePage);
+
+ const canvasview = accessor.get(CanvasView);
+ canvasview.removeObjectById(params.id, activePage.id);
+
+ return true;
+ },
+};
diff --git a/packages/slides-ui/src/commands/operations/insert-image.operation.ts b/packages/slides-ui/src/commands/operations/insert-image.operation.ts
new file mode 100644
index 0000000000..32c593ee88
--- /dev/null
+++ b/packages/slides-ui/src/commands/operations/insert-image.operation.ts
@@ -0,0 +1,96 @@
+/**
+ * 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, Nullable, SlideDataModel } from '@univerjs/core';
+import { CommandType, IUniverInstanceService, PageElementType, UniverInstanceType } from '@univerjs/core';
+import { getImageSize, IImageIoService } from '@univerjs/drawing';
+import { CanvasView } from '@univerjs/slides';
+
+export interface IInsertImageOperationParams {
+ files: Nullable<File[]>;
+};
+
+export const InsertSlideFloatImageOperation: ICommand<IInsertImageOperationParams> = {
+ id: 'slide.operation.insert-float-image',
+ 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 data = {
+ id: imageId,
+ zIndex: 20,
+ left: 0,
+ top: 0,
+ width,
+ height,
+ title: '',
+ description: '',
+ type: PageElementType.IMAGE,
+ image: {
+ imageProperties: {
+ contentUrl: base64Cache,
+ imageSourceType,
+ source,
+ base64Cache,
+ image,
+ },
+ },
+ };
+
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+ if (!slideData) return false;
+
+ const activePage = slideData.getActivePage()!;
+
+ 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);
+ if (sceneObject) {
+ canvasview.setObjectActiveByPage(sceneObject, activePage.id);
+ }
+ // console.log(slideData);
+
+ // {
+ // "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"
+ // }
+ // }
+ // }
+ 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
new file mode 100644
index 0000000000..38cdc0a319
--- /dev/null
+++ b/packages/slides-ui/src/commands/operations/insert-shape.operation.ts
@@ -0,0 +1,98 @@
+/**
+ * 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 { BasicShapes, CommandType, generateRandomId, IUniverInstanceService, PageElementType, UniverInstanceType } from '@univerjs/core';
+import { CanvasView } from '@univerjs/slides';
+
+export interface IInsertShapeOperationParams {
+};
+
+export const InsertSlideShapeRectangleOperation: ICommand<IInsertShapeOperationParams> = {
+ 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,
+ zIndex: 20,
+ left: 378,
+ top: 0,
+ width: 204,
+ height: 144,
+ title: 'mask',
+ description: '',
+ type: PageElementType.SHAPE,
+ shape: {
+ shapeType: BasicShapes.Rect,
+ text: '',
+ shapeProperties: {
+ shapeBackgroundFill: {
+ rgb: 'rgb(0,79,86)',
+ },
+ },
+ },
+ };
+
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+
+ if (!slideData) return false;
+
+ const activePage = slideData.getActivePage()!;
+
+ activePage.pageElements[id] = data;
+
+ // console.log(activePage.id);
+
+ slideData.updatePage(activePage.id, activePage);
+
+ const canvasview = accessor.get(CanvasView);
+ const sceneObject = canvasview.createObjectToPage(data, activePage.id);
+ if (sceneObject) {
+ canvasview.setObjectActiveByPage(sceneObject, activePage.id);
+ }
+
+ // console.log(slideData);
+
+ // {
+ // "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"
+ // }
+ // }
+ // }
+ return true;
+ },
+};
diff --git a/packages/slides-ui/src/commands/operations/insert-text.operation.ts b/packages/slides-ui/src/commands/operations/insert-text.operation.ts
new file mode 100644
index 0000000000..abd85aa76b
--- /dev/null
+++ b/packages/slides-ui/src/commands/operations/insert-text.operation.ts
@@ -0,0 +1,70 @@
+/**
+ * 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, PageElementType, Tools, UniverInstanceType } from '@univerjs/core';
+import { CanvasView } from '@univerjs/slides';
+
+export interface ISlideAddTextParam {
+ text: string;
+};
+
+export const SlideAddTextOperation: ICommand<ISlideAddTextParam> = {
+ id: 'slide.operation.add-text',
+ type: CommandType.OPERATION,
+ handler: async (accessor, params) => {
+ const elementId = Tools.generateRandomId(6);
+ const defaultWidth = 220;
+ const defaultheight = 40;
+
+ const textContent = params?.text || 'A New Text';
+ const elmentData = {
+ id: elementId,
+ zIndex: 2,
+ left: 230,
+ top: 142,
+ width: defaultWidth,
+ height: defaultheight,
+ title: 'text',
+ description: '',
+ type: PageElementType.TEXT,
+ richText: {
+ text: textContent,
+ fs: 30,
+ cl: {
+ rgb: 'rgb(51, 51, 51)',
+ },
+ bl: 1,
+ },
+ };
+
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+ if (!slideData) return false;
+
+ const activePage = slideData.getActivePage()!;
+ activePage.pageElements[elementId] = elmentData;
+ slideData.updatePage(activePage.id, activePage);
+
+ const canvasview = accessor.get(CanvasView);
+ const sceneObject = canvasview.createObjectToPage(elmentData, activePage.id);
+ if (sceneObject) {
+ canvasview.setObjectActiveByPage(sceneObject, activePage.id);
+ }
+
+ return true;
+ },
+};
diff --git a/packages/slides-ui/src/components/image-popup-menu/ImagePopupMenu.tsx b/packages/slides-ui/src/components/image-popup-menu/ImagePopupMenu.tsx
new file mode 100644
index 0000000000..9036d4e5ab
--- /dev/null
+++ b/packages/slides-ui/src/components/image-popup-menu/ImagePopupMenu.tsx
@@ -0,0 +1,115 @@
+/**
+ * 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 { IDrawingSearch } from '@univerjs/core';
+import { ICommandService, LocaleService, useDependency } from '@univerjs/core';
+import { Dropdown } from '@univerjs/design';
+import { Autofill, MoreDownSingle } from '@univerjs/icons';
+import clsx from 'clsx';
+import React, { useState } from 'react';
+import styles from './index.module.less';
+
+export interface IImagePopupMenuItem {
+ label: string;
+ index: number;
+ commandId: string;
+ commandParams?: IDrawingSearch[];
+ disable: boolean;
+}
+
+export interface IImagePopupMenuExtraProps {
+ menuItems: IImagePopupMenuItem[];
+}
+
+export interface IImagePopupMenuProps {
+ popup: {
+ extraProps?: IImagePopupMenuExtraProps;
+ };
+}
+
+export const SlideImagePopupMenu: React.FC<IImagePopupMenuProps> = (props: IImagePopupMenuProps) => {
+ const menuItems = props.popup?.extraProps?.menuItems;
+
+ if (!menuItems) {
+ return null;
+ }
+
+ const commandService = useDependency(ICommandService);
+ const localeService = useDependency(LocaleService);
+
+ const [visible, setVisible] = useState(false);
+ const [isHovered, setHovered] = useState(false);
+
+ const handleMouseEnter = () => {
+ setHovered(true);
+ };
+
+ const handleMouseLeave = () => {
+ setHovered(false);
+ };
+
+ const onVisibleChange = (visible: boolean) => {
+ setVisible(visible);
+ };
+
+ const handleClick = (item: IImagePopupMenuItem) => {
+ commandService.executeCommand(item.commandId, item.commandParams);
+ setVisible(false);
+ };
+
+ const showMore = visible || isHovered;
+
+ const availableMenu = menuItems.filter((item) => !item.disable);
+
+ return (
+ <div
+ onMouseEnter={handleMouseEnter}
+ onMouseLeave={handleMouseLeave}
+ >
+ <Dropdown
+ placement="bottomLeft"
+ trigger={['click']}
+ overlay={(
+ <ul className={styles.imagePopupMenu}>
+ {availableMenu.map((item) => (
+ <li
+ key={item.index}
+ onClick={() => handleClick(item)}
+ className={styles.imagePopupMenuItem}
+ >
+ <span className={styles.imagePopupMenuItemTitle}>{localeService.t(item.label)}</span>
+ </li>
+ ))}
+ </ul>
+ )}
+ visible={visible}
+ onVisibleChange={onVisibleChange}
+ >
+ <div
+ className={clsx(styles.btnContainer, {
+ [styles.btnContainerExpand]: visible,
+ })}
+ >
+ <Autofill
+ style={{ color: '#35322B' }}
+ extend={{ colorChannel1: 'rgb(var(--green-700, #409f11))' }}
+ />
+ {showMore && <MoreDownSingle style={{ color: '#CCCCCC', fontSize: '8px', marginLeft: '8px' }} />}
+ </div>
+ </Dropdown>
+ </div>
+ );
+};
diff --git a/packages/slides/src/locale/zh-CN.ts b/packages/slides-ui/src/components/image-popup-menu/component-name.ts
similarity index 87%
rename from packages/slides/src/locale/zh-CN.ts
rename to packages/slides-ui/src/components/image-popup-menu/component-name.ts
index f0e425d5eb..7d92560610 100644
--- a/packages/slides/src/locale/zh-CN.ts
+++ b/packages/slides-ui/src/components/image-popup-menu/component-name.ts
@@ -14,7 +14,5 @@
* limitations under the License.
*/
-const locale = {
-};
+export const COMPONENT_SLIDE_IMAGE_POPUP_MENU = 'COMPONENT_SLIDE_IMAGE_POPUP_MENU';
-export default locale;
diff --git a/packages/slides-ui/src/components/image-popup-menu/index.module.less b/packages/slides-ui/src/components/image-popup-menu/index.module.less
new file mode 100644
index 0000000000..982003b0c2
--- /dev/null
+++ b/packages/slides-ui/src/components/image-popup-menu/index.module.less
@@ -0,0 +1,92 @@
+.image-popup-menu {
+ display: grid;
+ gap: var(--margin-xxs);
+ align-items: center;
+
+ box-sizing: border-box;
+
+ margin-top: 0;
+ margin-bottom: 0;
+ padding: var(--padding-sm);
+
+ font-size: var(--font-size-base);
+
+ background-color: rgb(var(--bg-color-secondary));
+ border: 1px solid rgb(var(--border-color));
+ border-radius: var(--border-radius-lg);
+ box-shadow: var(--box-shadow-lg);
+
+ li {
+ list-style: none;
+ }
+
+ &-item {
+ cursor: pointer;
+
+ position: relative;
+
+ display: flex;
+ align-items: center;
+
+ box-sizing: border-box;
+ height: 28px;
+
+ font-size: var(--font-size-base);
+ font-style: normal;
+ line-height: 20px; /* 153.846% */
+ text-align: left;
+
+ border-radius: 4px;
+ border-radius: var(--border-radius-base);
+
+ transition: background 0.2s;
+
+ &:hover {
+ background-color: rgb(var(--bg-color-hover));
+ }
+
+ &-icon {
+ position: absolute;
+ top: 50%;
+ left: var(--padding-xs);
+ transform: translateY(-50%);
+
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ }
+
+ &-title {
+ padding: var(--padding-xs) var(--padding-xs) var(--padding-xs) 0;
+ vertical-align: middle;
+ }
+
+ &-hide {
+ color: rgb(var(--text-color-secondary));
+ }
+
+ &:hover {
+ background: rgb(var(--grey-100));
+ }
+ }
+}
+
+.btn-container {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ padding: 3px;
+
+ background: white;
+ border: 1px solid rgb(var(--grey-200, #e5e5e5));
+ border-radius: 4px;
+
+ &:hover {
+ background: rgb(var(--grey-100, #f5f5f5));
+ }
+
+ &.btn-container-expand {
+ background: rgb(var(--grey-100, #f5f5f5));
+ }
+}
diff --git a/packages/slides-ui/src/components/upload-component/UploadFile.tsx b/packages/slides-ui/src/components/upload-component/UploadFile.tsx
new file mode 100644
index 0000000000..5f334ef652
--- /dev/null
+++ b/packages/slides-ui/src/components/upload-component/UploadFile.tsx
@@ -0,0 +1,73 @@
+/**
+ * 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 } from '@univerjs/core';
+import { ICommandService, useDependency } from '@univerjs/core';
+import React, { useRef } from 'react';
+import type { ICustomComponentProps } from '@univerjs/ui';
+import { DRAWING_IMAGE_ALLOW_IMAGE_LIST } from '@univerjs/drawing';
+import { InsertSlideFloatImageOperation } from '../../commands/operations/insert-image.operation';
+import styles from './index.module.less';
+import { UploadFileType } from './component-name';
+
+export interface IUploadFileProps extends ICustomComponentProps<Nullable<File>> {
+ type: UploadFileType;
+}
+
+export const UploadFileMenu = (props: IUploadFileProps) => {
+ const { type } = props;
+
+ const commandService = useDependency(ICommandService);
+
+ const fileInputRef = useRef<HTMLInputElement>(null);
+
+ const handleButtonClick = () => {
+ fileInputRef.current?.click();
+ };
+
+ const imageAccept = DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace('image/', '')}`).join(',');
+
+ const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const fileList = event.target.files;
+
+ if (fileList == null) {
+ return;
+ }
+
+ const files: File[] = Array.from(fileList);
+
+ if (type === UploadFileType.floatImage) {
+ commandService.executeCommand(InsertSlideFloatImageOperation.id, { files });
+ }
+
+ if (fileInputRef.current) {
+ fileInputRef.current.value = '';
+ }
+ };
+
+ return (
+ <div onClick={handleButtonClick} className={styles.uploadFileMenu}>
+ <input
+ type="file"
+ className={styles.uploadFileMenuInput}
+ ref={fileInputRef}
+ onChange={handleFileChange}
+ accept={imageAccept}
+ multiple
+ />
+ </div>
+ );
+};
diff --git a/packages/slides/src/locale/en-US.ts b/packages/slides-ui/src/components/upload-component/component-name.ts
similarity index 81%
rename from packages/slides/src/locale/en-US.ts
rename to packages/slides-ui/src/components/upload-component/component-name.ts
index 8f283396ae..5cd1cb4841 100644
--- a/packages/slides/src/locale/en-US.ts
+++ b/packages/slides-ui/src/components/upload-component/component-name.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import type zhCN from './zh-CN';
+export const COMPONENT_UPLOAD_FILE_MENU = 'COMPONENT_UPLOAD_FILE_MENU';
-const locale: typeof zhCN = {
-};
-
-export default locale;
+export enum UploadFileType {
+ cellImage,
+ floatImage,
+}
diff --git a/packages/slides-ui/src/components/upload-component/index.module.less b/packages/slides-ui/src/components/upload-component/index.module.less
new file mode 100644
index 0000000000..963abf12ee
--- /dev/null
+++ b/packages/slides-ui/src/components/upload-component/index.module.less
@@ -0,0 +1,12 @@
+.upload-file {
+ &-menu {
+ position: absolute;
+ height: 100%;
+ width: 100%;
+ text-align: center;
+
+ &-input {
+ display: none;
+ }
+ }
+}
diff --git a/packages/slides-ui/src/controllers/image.menu.ts b/packages/slides-ui/src/controllers/image.menu.ts
new file mode 100644
index 0000000000..404b67c90a
--- /dev/null
+++ b/packages/slides-ui/src/controllers/image.menu.ts
@@ -0,0 +1,54 @@
+/**
+ * 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 { IMenuItem } from '@univerjs/ui';
+import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
+import type { IAccessor } from '@univerjs/core';
+import { UniverInstanceType } from '@univerjs/core';
+import { COMPONENT_UPLOAD_FILE_MENU, UploadFileType } from '../components/upload-component/component-name';
+import { InsertSlideFloatImageOperation } from '../commands/operations/insert-image.operation';
+
+export const IMAGE_UPLOAD_ICON = 'addition-and-subtraction-single';
+const IMAGE_MENU_ID = 'slide.menu.image';
+
+export function SlideImageMenuFactory(accessor: IAccessor): IMenuItem {
+ return {
+ id: IMAGE_MENU_ID,
+ type: MenuItemType.SUBITEMS,
+ positions: [MenuPosition.TOOLBAR_START],
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
+ icon: IMAGE_UPLOAD_ICON,
+ tooltip: 'slide.image.insert.title',
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SLIDE),
+ // disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ };
+}
+
+export function UploadSlideFloatImageMenuFactory(_accessor: IAccessor): IMenuItem {
+ return {
+ id: InsertSlideFloatImageOperation.id,
+ title: 'slide.image.insert.float',
+ type: MenuItemType.SELECTOR,
+ label: {
+ name: COMPONENT_UPLOAD_FILE_MENU,
+ props: {
+ type: UploadFileType.floatImage,
+ },
+ },
+ positions: [IMAGE_MENU_ID],
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SLIDE),
+ };
+}
diff --git a/packages/slides-ui/src/controllers/popup-menu.controller.ts b/packages/slides-ui/src/controllers/popup-menu.controller.ts
new file mode 100644
index 0000000000..7fe0feec29
--- /dev/null
+++ b/packages/slides-ui/src/controllers/popup-menu.controller.ts
@@ -0,0 +1,225 @@
+/**
+ * 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 { 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 { 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';
+
+@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
+ ) {
+ super();
+
+ this._init();
+ }
+
+ private _init(): void {
+ // this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => this._create(workbook));
+ // this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => this._dispose(workbook));
+ this._univerInstanceService.getAllUnitsForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE).forEach((slide) => this._create(slide));
+ }
+
+ private _dispose(workbook: SlideDataModel) {
+ // const unitId = workbook.getUnitId();
+ // this._renderManagerService.removeRender(unitId);
+ }
+
+ private _create(slide: Nullable<SlideDataModel>) {
+ if (!slide) {
+ return;
+ }
+
+ const unitId = slide.getUnitId();
+
+ if (this._renderManagerService.has(unitId) && !this._initImagePopupMenu.has(unitId)) {
+ this._popupMenuListener(unitId);
+ this._initImagePopupMenu.add(unitId);
+ }
+ }
+
+ private _hasCropObject(scene: Scene) {
+ // const objects = scene.getAllObjects();
+
+ // for (const object of objects) {
+ // if (object instanceof ImageCropperObject) {
+ // return true;
+ // }
+ // }
+
+ // return false;
+ }
+
+ private _popupMenuListener(unitId: string) {
+ const model = this._univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
+ const pages = model?.getPages() ?? {};
+
+ Object.keys(pages).forEach((pageId) => {
+ const page = this._canvasView.getRenderUnitByPageId(pageId);
+ const transformer = page.scene?.getTransformer();
+
+ if (!transformer) return;
+
+ let singletonPopupDisposer: IDisposable;
+ this.disposeWithMe(
+ toDisposable(
+ transformer.createControl$.subscribe(() => {
+ // this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, true);
+
+ // if (this._hasCropObject(scene)) {
+ // return;
+ // }
+
+ const selectedObjects = transformer.getSelectedObjectMap();
+ if (selectedObjects.size > 1) {
+ singletonPopupDisposer?.dispose();
+ return;
+ }
+
+ const object = selectedObjects.values().next().value as Nullable<BaseObject>;
+ if (!object) {
+ return;
+ }
+
+ const oKey = object.oKey;
+ // const drawingParam = this._drawingManagerService.getDrawingOKey(oKey);
+ // if (!drawingParam) {
+ // return;
+ // }
+
+ // const { unitId, subUnitId, drawingId } = drawingParam;
+ singletonPopupDisposer?.dispose();
+ singletonPopupDisposer = this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {
+ componentKey: COMPONENT_SLIDE_IMAGE_POPUP_MENU,
+ direction: 'horizontal',
+ offset: [2, 0],
+ extraProps: {
+ menuItems: this._getMenuItemsByObjectType(object.objectType, oKey, unitId),
+ },
+ }));
+
+ // this._drawingManagerService.focusDrawing([{
+ // unitId,
+ // subUnitId,
+ // drawingId,
+ // }]);
+ })
+ )
+ );
+ this.disposeWithMe(
+ transformer.clearControl$.subscribe(() => {
+ singletonPopupDisposer?.dispose();
+ this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, false);
+ // this._drawingManagerService.focusDrawing(null);
+ })
+ );
+ this.disposeWithMe(
+ transformer.changing$.subscribe(() => {
+ singletonPopupDisposer?.dispose();
+ })
+ );
+ });
+ }
+
+ 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({
+ label: 'slide.popup.delete',
+ index: 5,
+ commandId: DeleteSlideElementOperation.id,
+ commandParams: {
+ 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/shape.menu.ts b/packages/slides-ui/src/controllers/shape.menu.ts
new file mode 100644
index 0000000000..9cb559bad4
--- /dev/null
+++ b/packages/slides-ui/src/controllers/shape.menu.ts
@@ -0,0 +1,47 @@
+/**
+ * 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 { IMenuButtonItem, IMenuItem } from '@univerjs/ui';
+import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
+import type { IAccessor } from '@univerjs/core';
+import { UniverInstanceType } from '@univerjs/core';
+import { InsertSlideShapeRectangleOperation } from '../commands/operations/insert-shape.operation';
+
+export const GRAPH_SINGLE_ICON = 'graph-single';
+const IMAGE_MENU_ID = 'slide.menu.shape';
+
+export function SlideShapeMenuFactory(accessor: IAccessor): IMenuItem {
+ return {
+ id: IMAGE_MENU_ID,
+ type: MenuItemType.SUBITEMS,
+ positions: [MenuPosition.TOOLBAR_START],
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
+ icon: GRAPH_SINGLE_ICON,
+ tooltip: 'slide.shape.insert.title',
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SLIDE),
+ // disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ };
+}
+
+export function UploadSlideFloatShapeMenuFactory(_accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: InsertSlideShapeRectangleOperation.id,
+ title: 'slide.shape.insert.rectangle',
+ type: MenuItemType.BUTTON,
+ positions: [IMAGE_MENU_ID],
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SLIDE),
+ };
+}
diff --git a/packages/slides-ui/src/controllers/slide-ui.controller.ts b/packages/slides-ui/src/controllers/slide-ui.controller.ts
index cdd66d7a9c..e3ef75e527 100644
--- a/packages/slides-ui/src/controllers/slide-ui.controller.ts
+++ b/packages/slides-ui/src/controllers/slide-ui.controller.ts
@@ -14,11 +14,33 @@
* limitations under the License.
*/
+import type { DependencyOverride } from '@univerjs/core';
import { connectInjector, Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { BuiltInUIPart, IUIPartsService } from '@univerjs/ui';
-import { SlideSideBar } from '../views/slide-bar/SlideBar';
+import { AddImageSingle, GraphSingle, TextSingle } from '@univerjs/icons';
+import type { MenuConfig } from '@univerjs/ui';
+import { BuiltInUIPart, ComponentManager, IMenuService, IUIPartsService } from '@univerjs/ui';
import { ActivateSlidePageOperation } from '../commands/operations/activate.operation';
+import { InsertSlideFloatImageOperation } from '../commands/operations/insert-image.operation';
+import { InsertSlideShapeRectangleOperation } from '../commands/operations/insert-shape.operation';
+import { SlideAddTextOperation } from '../commands/operations/insert-text.operation';
import { SetSlidePageThumbOperation } from '../commands/operations/set-thumb.operation';
+import { UploadFileMenu } from '../components/upload-component/UploadFile';
+import { COMPONENT_UPLOAD_FILE_MENU } from '../components/upload-component/component-name';
+import { SlideSideBar } from '../views/slide-bar/SlideBar';
+import { SlideImagePopupMenu } from '../components/image-popup-menu/ImagePopupMenu';
+import { COMPONENT_SLIDE_IMAGE_POPUP_MENU } from '../components/image-popup-menu/component-name';
+import { DeleteSlideElementOperation } from '../commands/operations/delete-element.operation';
+import { IMAGE_UPLOAD_ICON, SlideImageMenuFactory, UploadSlideFloatImageMenuFactory } from './image.menu';
+import { GRAPH_SINGLE_ICON, SlideShapeMenuFactory, UploadSlideFloatShapeMenuFactory } from './shape.menu';
+import { SlideAddTextMenuItemFactory, TEXT_ICON_ID } from './text.menu';
+
+export interface IUniverSlidesDrawingConfig {
+ menu?: MenuConfig;
+ overrides?: DependencyOverride;
+}
+
+export const DefaultSlidesDrawingConfig: IUniverSlidesDrawingConfig = {
+};
/**
* This controller registers UI parts of slide workbench to the base-ui workbench.
@@ -26,20 +48,53 @@ import { SetSlidePageThumbOperation } from '../commands/operations/set-thumb.ope
@OnLifecycle(LifecycleStages.Ready, SlideUIController)
export class SlideUIController extends Disposable {
constructor(
+ private readonly _config: Partial<IUniverSlidesDrawingConfig>,
@Inject(Injector) private readonly _injector: Injector,
+ @IMenuService private readonly _menuService: IMenuService,
+ @Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@IUIPartsService private readonly _uiPartsService: IUIPartsService,
@ICommandService private readonly _commandService: ICommandService
) {
super();
this._initCommands();
+ this._initCustomComponents();
this._initUIComponents();
+ this._initMenus();
+ }
+
+ private _initMenus(): void {
+ const { menu = {} } = this._config;
+
+ [
+ SlideAddTextMenuItemFactory,
+ SlideImageMenuFactory,
+ UploadSlideFloatImageMenuFactory,
+ SlideShapeMenuFactory,
+ UploadSlideFloatShapeMenuFactory,
+ ].forEach((menuFactory) => {
+ this._menuService.addMenuItem(menuFactory(this._injector), menu);
+ });
+ }
+
+ private _initCustomComponents(): void {
+ const componentManager = this._componentManager;
+ this.disposeWithMe(componentManager.register(IMAGE_UPLOAD_ICON, AddImageSingle));
+ this.disposeWithMe(componentManager.register(TEXT_ICON_ID, TextSingle));
+ 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));
}
private _initCommands(): void {
[
ActivateSlidePageOperation,
SetSlidePageThumbOperation,
+ InsertSlideFloatImageOperation,
+ SlideAddTextOperation,
+ InsertSlideShapeRectangleOperation,
+ DeleteSlideElementOperation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
diff --git a/packages/slides/src/model/info-bar-model.ts b/packages/slides-ui/src/controllers/slide.render-controller.ts
similarity index 65%
rename from packages/slides/src/model/info-bar-model.ts
rename to packages/slides-ui/src/controllers/slide.render-controller.ts
index 67bf0bb5f8..43829d0fba 100644
--- a/packages/slides/src/model/info-bar-model.ts
+++ b/packages/slides-ui/src/controllers/slide.render-controller.ts
@@ -14,16 +14,15 @@
* limitations under the License.
*/
-export class InfoBarModel {
- constructor(private _name: string) {
- // empty
- }
+import { RxDisposable } from '@univerjs/core';
+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
- get name(): string {
- return this._name;
+export class SlideRenderController extends RxDisposable implements IRenderModule {
+ constructor(private readonly _context: IRenderContext<any>) {
+ super();
}
- setName(name: string) {
- this._name = name;
+ override dispose() {
+ //...
}
}
diff --git a/packages/slides-ui/src/controllers/text.menu.ts b/packages/slides-ui/src/controllers/text.menu.ts
new file mode 100644
index 0000000000..6318f0acf3
--- /dev/null
+++ b/packages/slides-ui/src/controllers/text.menu.ts
@@ -0,0 +1,35 @@
+/**
+ * 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 { IAccessor } from '@univerjs/core';
+import { UniverInstanceType } from '@univerjs/core';
+import type { IMenuButtonItem } from '@univerjs/ui';
+import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
+import { SlideAddTextOperation } from '../commands/operations/insert-text.operation';
+
+export const TEXT_ICON_ID = 'text-single';
+
+export function SlideAddTextMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: SlideAddTextOperation.id,
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
+ type: MenuItemType.BUTTON,
+ icon: TEXT_ICON_ID,
+ tooltip: 'slide.text.insert.title',
+ positions: [MenuPosition.TOOLBAR_START],
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SLIDE),
+ };
+}
diff --git a/packages/slides-ui/src/index.ts b/packages/slides-ui/src/index.ts
index 2481d12c64..557c0d3119 100644
--- a/packages/slides-ui/src/index.ts
+++ b/packages/slides-ui/src/index.ts
@@ -16,6 +16,8 @@
export { UniverSlidesUIPlugin } from './slides-ui-plugin';
+export { SlideCanvasPopMangerService } from './services/slide-popup-manager.service';
+
// #region - all commands
export { ActivateSlidePageOperation } from './commands/operations/activate.operation';
diff --git a/packages/slides-ui/src/locale/en-US.ts b/packages/slides-ui/src/locale/en-US.ts
index b73a3c63ae..a62c32adad 100644
--- a/packages/slides-ui/src/locale/en-US.ts
+++ b/packages/slides-ui/src/locale/en-US.ts
@@ -17,9 +17,31 @@
import type zhCN from './zh-CN';
const locale: typeof zhCN = {
- toolbar: {
- undo: 'Undo',
- redo: 'Redo',
+ slide: {
+ text: {
+ insert: {
+ title: 'Insert Text',
+ },
+ },
+
+ shape: {
+ insert: {
+ title: 'Insert Shape',
+ rectangle: 'Insert Rectangle',
+ },
+ },
+
+ image: {
+ insert: {
+ title: 'Insert Image',
+ float: 'Insert Float Image',
+ },
+ },
+
+ popup: {
+ edit: 'Edit',
+ delete: 'Delete',
+ },
},
};
diff --git a/packages/slides-ui/src/locale/ru-RU.ts b/packages/slides-ui/src/locale/ru-RU.ts
index 7ee2dd1ea0..1a9815b8c9 100644
--- a/packages/slides-ui/src/locale/ru-RU.ts
+++ b/packages/slides-ui/src/locale/ru-RU.ts
@@ -15,12 +15,8 @@
*/
import type zhCN from './zh-CN';
+import enUS from './en-US.ts';
-const locale: typeof zhCN = {
- toolbar: {
- undo: 'Отменить',
- redo: 'Повторить',
- },
-};
+const locale: typeof zhCN = enUS;
export default locale;
diff --git a/packages/slides-ui/src/locale/vi-VN.ts b/packages/slides-ui/src/locale/vi-VN.ts
index ed56ff1246..1a9815b8c9 100644
--- a/packages/slides-ui/src/locale/vi-VN.ts
+++ b/packages/slides-ui/src/locale/vi-VN.ts
@@ -15,12 +15,8 @@
*/
import type zhCN from './zh-CN';
+import enUS from './en-US.ts';
-const locale: typeof zhCN = {
- toolbar: {
- undo: 'Hoàn tác',
- redo: 'làm lại',
- },
-};
+const locale: typeof zhCN = enUS;
export default locale;
diff --git a/packages/slides-ui/src/locale/zh-CN.ts b/packages/slides-ui/src/locale/zh-CN.ts
index 5a9c22fc32..6db784db89 100644
--- a/packages/slides-ui/src/locale/zh-CN.ts
+++ b/packages/slides-ui/src/locale/zh-CN.ts
@@ -15,9 +15,31 @@
*/
const locale = {
- toolbar: {
- undo: '撤销',
- redo: '重做',
+ slide: {
+ text: {
+ insert: {
+ title: '插入文本',
+ },
+ },
+
+ shape: {
+ insert: {
+ title: '插入图形',
+ rectangle: '插入矩形',
+ },
+ },
+
+ image: {
+ insert: {
+ title: '插入图片',
+ float: '插入浮动图片',
+ },
+ },
+
+ popup: {
+ edit: '编辑',
+ delete: '删除',
+ },
},
};
diff --git a/packages/slides-ui/src/locale/zh-TW.ts b/packages/slides-ui/src/locale/zh-TW.ts
index 79567a0dc8..1a9815b8c9 100644
--- a/packages/slides-ui/src/locale/zh-TW.ts
+++ b/packages/slides-ui/src/locale/zh-TW.ts
@@ -15,12 +15,8 @@
*/
import type zhCN from './zh-CN';
+import enUS from './en-US.ts';
-const locale: typeof zhCN = {
- toolbar: {
- undo: '撤銷',
- redo: '重做',
- },
-};
+const locale: typeof zhCN = enUS;
export default locale;
diff --git a/packages/slides-ui/src/services/slide-popup-manager.service.ts b/packages/slides-ui/src/services/slide-popup-manager.service.ts
new file mode 100644
index 0000000000..a77093465d
--- /dev/null
+++ b/packages/slides-ui/src/services/slide-popup-manager.service.ts
@@ -0,0 +1,131 @@
+/**
+ * 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 { 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 { IPopup } from '@univerjs/ui';
+import { ICanvasPopupService } from '@univerjs/ui';
+import { BehaviorSubject } from 'rxjs';
+
+export interface ISlideCanvasPopup extends Pick<IPopup,
+ 'direction' | 'excludeOutside' | 'closeOnSelfTarget' | 'componentKey' | 'offset' | 'onClickOutside'
+> {
+ mask?: boolean;
+ extraProps?: Record<string, any>;
+}
+
+export class SlideCanvasPopMangerService extends Disposable {
+ constructor(
+ @Inject(ICanvasPopupService) private readonly _globalPopupManagerService: ICanvasPopupService,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @ICommandService private readonly _commandService: ICommandService
+ ) {
+ super();
+ }
+
+ private _createObjectPositionObserver(
+ targetObject: BaseObject,
+ currentRender: IRender
+ ) {
+ const calc = () => {
+ const { scene, engine } = currentRender;
+ const { left, top, width, height } = targetObject;
+
+ const bound: IBoundRectNoAngle = {
+ left,
+ right: left + width,
+ top,
+ bottom: top + height,
+ };
+ const canvasElement = engine.getCanvasElement();
+ const canvasClientRect = canvasElement.getBoundingClientRect();
+ const widthOfCanvas = pxToNum(canvasElement.style.width); // declared width
+
+ const { scaleX, scaleY } = scene.getAncestorScale();
+
+ // 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,
+ };
+ return position;
+ };
+
+ const position = calc();
+ const position$ = new BehaviorSubject(position);
+ const disposable = new DisposableCollection();
+
+ // disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
+ // if (commandInfo.id === SetDocZoomRatioOperation.id) {
+ // position$.next(calc());
+ // }
+ // }));
+
+ // const viewMain = currentRender.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
+ // if (viewMain) {
+ // disposable.add(viewMain.onScrollAfter$.subscribeEvent(() => {
+ // position$.next(calc());
+ // }));
+ // }
+
+ return {
+ position,
+ position$,
+ disposable,
+ };
+ }
+
+ attachPopupToObject(targetObject: BaseObject, popup: ISlideCanvasPopup): IDisposable {
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SLIDE)!;
+ const unitId = workbook.getUnitId();
+ // const subUnitId =
+
+ const currentRender = this._renderManagerService.getRenderById(unitId);
+ if (!currentRender) {
+ return {
+ dispose: () => {
+ // empty
+ },
+ };
+ }
+
+ const { position, position$, disposable } = this._createObjectPositionObserver(targetObject, currentRender);
+
+ const id = this._globalPopupManagerService.addPopup({
+ ...popup,
+ unitId,
+ subUnitId: 'default',
+ anchorRect: position,
+ anchorRect$: position$,
+ });
+
+ return {
+ dispose: () => {
+ this._globalPopupManagerService.removePopup(id);
+ position$.complete();
+ disposable.dispose();
+ },
+ };
+ }
+}
diff --git a/packages/slides-ui/src/slides-ui-plugin.ts b/packages/slides-ui/src/slides-ui-plugin.ts
index fc4e1d9759..0c826551b3 100644
--- a/packages/slides-ui/src/slides-ui-plugin.ts
+++ b/packages/slides-ui/src/slides-ui-plugin.ts
@@ -17,7 +17,13 @@
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 { SlideUIController } from './controllers/slide-ui.controller';
+import type { IUniverSlidesDrawingConfig } from './controllers/slide-ui.controller';
+import { SlideRenderController } from './controllers/slide.render-controller';
+import { SlidePopupMenuController } from './controllers/popup-menu.controller';
+import { SlideCanvasPopMangerService } from './services/slide-popup-manager.service';
export const SLIDE_UI_PLUGIN_NAME = 'SLIDE_UI';
@@ -26,15 +32,34 @@ export class UniverSlidesUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_SLIDE;
constructor(
- _config: unknown,
+ private readonly _config: Partial<IUniverSlidesDrawingConfig> = {},
@Inject(Injector) override readonly _injector: Injector,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
) {
super();
}
override onStarting(injector: Injector): void {
- ([[SlideUIController]] as Dependency[]).forEach((d) => injector.add(d));
+ ([
+ [
+ SlideUIController,
+ {
+ useFactory: () => this._injector.createInstance(SlideUIController, this._config),
+ },
+ ],
+ [IImageIoService, { useClass: ImageIoService }],
+ [SlideCanvasPopMangerService],
+ ] as Dependency[]).forEach((d) => injector.add(d));
+ }
+
+ override onReady(): void {
+ ([
+ [SlideRenderController],
+ [SlidePopupMenuController],
+ ] as Dependency[]).forEach((m) => {
+ this.disposeWithMe(this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SLIDE, m));
+ });
}
override onRendered(): void {
diff --git a/packages/slides-ui/src/views/slide-bar/SlideBar.tsx b/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
index be02142095..2625f97556 100644
--- a/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
+++ b/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
@@ -22,7 +22,6 @@ 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 { CanvasView } from '@univerjs/slides';
import { ActivateSlidePageOperation } from '../../commands/operations/activate.operation';
import { SetSlidePageThumbOperation } from '../../commands/operations/set-thumb.operation';
import styles from './index.module.less';
@@ -35,7 +34,6 @@ export function SlideSideBar() {
const univerInstanceService = useDependency(IUniverInstanceService);
const commandService = useDependency(ICommandService);
const renderManagerService = useDependency(IRenderManagerService);
- const canvasView = useDependency(CanvasView);
const slideBarRef = useRef<HTMLDivElement>(null);
const currentSlide = useObservable(
@@ -61,8 +59,8 @@ export function SlideSideBar() {
}, [slideList.length]);
useEffect(() => {
- canvasView.activePageId$.subscribe((id) => {
- setActivatePageId(id);
+ currentSlide?.activePage$.subscribe((page) => {
+ setActivatePageId(page?.id ?? null);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
diff --git a/packages/slides/package.json b/packages/slides/package.json
index 44e2076e82..b8025ccf5d 100644
--- a/packages/slides/package.json
+++ b/packages/slides/package.json
@@ -1,7 +1,7 @@
{
"name": "@univerjs/slides",
"version": "0.2.5",
- "private": false,
+ "private": true,
"description": "",
"author": "DreamNum <[email protected]>",
"license": "Apache-2.0",
@@ -22,8 +22,7 @@
],
"exports": {
".": "./src/index.ts",
- "./*": "./src/*",
- "./locale/*": "./src/locale/*.ts"
+ "./*": "./src/*"
},
"main": "./lib/cjs/index.js",
"module": "./lib/es/index.js",
@@ -43,8 +42,7 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
- "./lib/*": "./lib/*",
- "./locale/*": "./lib/locale/*.json"
+ "./lib/*": "./lib/*"
}
},
"directories": {
@@ -86,7 +84,6 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
- "./lib/*": "./lib/*",
- "./locale/*": "./lib/locale/*.json"
+ "./lib/*": "./lib/*"
}
}
diff --git a/packages/slides/src/locale/ru-RU.ts b/packages/slides/src/locale/ru-RU.ts
deleted file mode 100644
index 8f283396ae..0000000000
--- a/packages/slides/src/locale/ru-RU.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * 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 zhCN from './zh-CN';
-
-const locale: typeof zhCN = {
-};
-
-export default locale;
diff --git a/packages/slides/src/locale/vi-VN.ts b/packages/slides/src/locale/vi-VN.ts
deleted file mode 100644
index 8f283396ae..0000000000
--- a/packages/slides/src/locale/vi-VN.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * 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 zhCN from './zh-CN';
-
-const locale: typeof zhCN = {
-};
-
-export default locale;
diff --git a/packages/slides/src/locale/zh-TW.ts b/packages/slides/src/locale/zh-TW.ts
deleted file mode 100644
index 8f283396ae..0000000000
--- a/packages/slides/src/locale/zh-TW.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * 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 zhCN from './zh-CN';
-
-const locale: typeof zhCN = {
-};
-
-export default locale;
diff --git a/packages/slides/src/model/toolbar-model.ts b/packages/slides/src/model/toolbar-model.ts
deleted file mode 100644
index 1890910b1d..0000000000
--- a/packages/slides/src/model/toolbar-model.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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.
- */
-
-// export interface IShowToolbarConfig {
-// undoRedo?: boolean; // Undo redo
-// paintFormat?: boolean; // Format brush
-// currencyFormat?: boolean; // currency format
-// percentageFormat?: boolean; // Percentage format
-// numberDecrease?: boolean; // 'Decrease the number of decimal places'
-// numberIncrease?: boolean; // 'Increase the number of decimal places
-// moreFormats?: boolean; // 'More Formats'
-// font?: boolean; // 'font'
-// fontSize?: boolean; // 'Font size'
-// bold?: boolean; // 'Bold (Ctrl+B)'
-// italic?: boolean; // 'Italic (Ctrl+I)'
-// strikethrough?: boolean; // 'Strikethrough (Alt+Shift+5)'
-// underline?: boolean; // 'Underline (Alt+Shift+6)'
-// textColor?: boolean; // 'Text color'
-// fillColor?: boolean; // 'Cell color'
-// border?: boolean; // 'border'
-// mergeCell?: boolean; // 'Merge cells'
-// horizontalAlignMode?: boolean; // 'Horizontal alignment'
-// verticalAlignMode?: boolean; // 'Vertical alignment'
-// textWrapMode?: boolean; // 'Wrap mode'
-// textRotateMode?: boolean; // 'Text Rotation Mode'
-
-// image?: boolean; // 'Insert picture'
-// link?: boolean; // 'Insert link'
-// chart?: boolean; // 'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click)
-// comment?: boolean; // 'comment'
-// pivotTable?: boolean; // 'PivotTable'
-// function?: boolean; // 'formula'
-// frozenMode?: boolean; // 'freeze mode'
-// sortAndFilter?: boolean; // 'Sort and filter'
-// conditionalFormatting?: boolean; // 'Conditional Formatting'
-// dataValidation?: boolean; // 'Data Validation'
-// splitColumn?: boolean; // 'Split column'
-// screenshot?: boolean; // 'screenshot'
-// findAndReplace?: boolean; // 'Find and Replace'
-// protection?: boolean; // 'Worksheet protection'
-// print?: boolean; // 'Print'
-// }
-
-// enum ToolbarType {
-// SELECT,
-// BUTTON,
-// }
-
-// // 继承基础下拉属性,添加国际化
-// export interface BaseToolbarSelectChildrenProps extends BaseSelectChildrenProps {
-// locale?: string;
-// suffixLocale?: string;
-// children?: BaseToolbarSelectChildrenProps[];
-// }
-
-// interface BaseToolbarSelectProps extends IBaseSelectProps {
-// locale?: string;
-// suffixLocale?: string;
-// children?: BaseToolbarSelectChildrenProps[];
-// }
-
-// export interface IToolbarItemProps extends BaseToolbarSelectProps, BaseTextButtonProps {
-// show?: boolean; //是否显示按钮
-// toolbarType?: ToolbarType;
-// locale?: string; //label国际化
-// tooltipLocale?: string; //tooltip国际化
-// tooltip?: string; //tooltip文字
-// border?: boolean;
-// }
-
-// export class ToolbarModel {
-// private _config: IShowToolbarConfig[];
-
-// private _toolList: IToolbarItemProps[];
-
-// get config(): IShowToolbarConfig[] {
-// return this._config;
-// }
-
-// get toolList(): IToolbarItemProps[] {
-// return this._toolList;
-// }
-
-// set config(value: IShowToolbarConfig[]) {
-// this._config = value;
-// }
-
-// set toolList(value: IToolbarItemProps[]) {
-// this._toolList = value;
-// }
-// }
diff --git a/packages/slides/src/slides-plugin.ts b/packages/slides/src/slides-plugin.ts
index f05fc605e0..d0178c5190 100644
--- a/packages/slides/src/slides-plugin.ts
+++ b/packages/slides/src/slides-plugin.ts
@@ -16,7 +16,7 @@
import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Engine } from '@univerjs/engine-render';
-import { IRenderingEngine } from '@univerjs/engine-render';
+import { IRenderingEngine, IRenderManagerService } from '@univerjs/engine-render';
import type { Dependency } from '@univerjs/core';
import { CanvasView } from './views/render';
@@ -35,11 +35,12 @@ export class UniverSlidesPlugin extends Plugin {
private _canvasEngine: Engine | null = null;
- private _canvasView: CanvasView | null = null;
+ // private _canvasView: CanvasView | null = null;
constructor(
config: Partial<IUniverSlidesConfig> = {},
- @Inject(Injector) override readonly _injector: Injector
+ @Inject(Injector) override readonly _injector: Injector,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService
) {
super();
@@ -51,6 +52,10 @@ export class UniverSlidesPlugin extends Plugin {
this.initCanvasEngine();
}
+ override onReady(): void {
+
+ }
+
getConfig() {
return this._config;
}
@@ -67,10 +72,6 @@ export class UniverSlidesPlugin extends Plugin {
return this._canvasEngine;
}
- getCanvasView() {
- return this._canvasView;
- }
-
private _initializeDependencies(slideInjector: Injector) {
const dependencies: Dependency[] = [[CanvasView]];
diff --git a/packages/slides/src/views/render/adaptor.ts b/packages/slides/src/views/render/adaptor.ts
index 7e04460ca8..22186e2881 100644
--- a/packages/slides/src/views/render/adaptor.ts
+++ b/packages/slides/src/views/render/adaptor.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import type { Injector, IPageElement, PageElementType } from '@univerjs/core';
+import type { Injector, IPageElement, Nullable, PageElementType } from '@univerjs/core';
import { Registry } from '@univerjs/core';
-import type { Scene } from '@univerjs/engine-render';
+import type { BaseObject, Scene } from '@univerjs/engine-render';
export abstract class ObjectAdaptor {
zIndex = 0;
@@ -30,7 +30,7 @@ export abstract class ObjectAdaptor {
return this;
}
- abstract convert(pageElement: IPageElement, mainScene: Scene): void;
+ abstract convert(pageElement: IPageElement, mainScene: Scene): Nullable<BaseObject>;
create(injector: Injector): void {
// FIXME: should not be empty
diff --git a/packages/slides/src/views/render/adaptors/rich-text-adaptor.ts b/packages/slides/src/views/render/adaptors/rich-text-adaptor.ts
index 2eb8d0434b..7b2ddf0967 100644
--- a/packages/slides/src/views/render/adaptors/rich-text-adaptor.ts
+++ b/packages/slides/src/views/render/adaptors/rich-text-adaptor.ts
@@ -37,7 +37,7 @@ export class RichTextAdaptor extends ObjectAdaptor {
return this;
}
- override convert(pageElement: IPageElement, mainScene: Scene) {
+ override convert(pageElement: IPageElement, _mainScene: Scene) {
const {
id,
zIndex,
diff --git a/packages/slides/src/views/render/canvas-view.ts b/packages/slides/src/views/render/canvas-view.ts
index 59beaa5729..f98f4e875c 100644
--- a/packages/slides/src/views/render/canvas-view.ts
+++ b/packages/slides/src/views/render/canvas-view.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import type { EventState, IColorStyle, ISlidePage, Nullable, SlideDataModel } from '@univerjs/core';
+import type { EventState, IColorStyle, IPageElement, ISlidePage, Nullable, SlideDataModel } from '@univerjs/core';
import { debounce, getColorStyle, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, UniverInstanceType } from '@univerjs/core';
-import type { IWheelEvent } from '@univerjs/engine-render';
+import type { BaseObject, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
import {
IRenderManagerService,
Rect,
@@ -26,7 +26,7 @@ import {
Viewport,
} from '@univerjs/engine-render';
-import { Subject, takeUntil } from 'rxjs';
+import { takeUntil } from 'rxjs';
import { ObjectProvider } from './object-provider';
export enum SLIDE_KEY {
@@ -34,16 +34,17 @@ export enum SLIDE_KEY {
SCENE = '__mainScene__',
VIEW = '__mainView__',
}
+
+export type PageID = string;
+
+// export const ICanvasView = createIdentifier<IUniverInstanceService>('univer.slide.canvas-view');
@OnLifecycle(LifecycleStages.Ready, CanvasView)
-export class CanvasView extends RxDisposable {
+export class CanvasView extends RxDisposable implements IRenderModule {
private _objectProvider: ObjectProvider | null = null;
- private _activePageId: string = '';
- readonly activePageId$ = new Subject<string>();
-
constructor(
- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(Injector) private readonly _injector: Injector,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService
) {
super();
@@ -92,9 +93,7 @@ export class CanvasView extends RxDisposable {
const slide = render.mainComponent as Slide;
- this._activePageId = pageId;
-
- this.activePageId$.next(pageId);
+ model.setActivePage(page);
if (slide?.hasPage(id)) {
slide.changePage(id);
@@ -169,12 +168,6 @@ export class CanvasView extends RxDisposable {
}, 300);
});
- // const scene = new Scene(SLIDE_KEY.SCENE, engine, {
- // width: 2400,
- // height: 1800,
- // });
- scene.resize(2400, 1800);
-
const viewMain = new Viewport(SLIDE_KEY.VIEW, scene, {
left: 0,
top: 0,
@@ -361,8 +354,6 @@ export class CanvasView extends RxDisposable {
// }
// }, 0);
- this._activePageId = pageOrder[0];
-
slide.activeFirstPage();
}
@@ -392,25 +383,29 @@ export class CanvasView extends RxDisposable {
this._renderManagerService.createRender(pageId);
}
+ private _sceneMap = new Map<string, Scene>();
+ /**
+ *
+ * @param pageId
+ * @param page
+ * @returns
+ */
private _createScene(pageId: string, page: ISlidePage) {
const render = this._currentRender();
-
if (!render || !this._objectProvider) {
return;
}
const { scene: mainScene, mainComponent } = render;
-
const slide = mainComponent as Slide;
-
const { width, height } = slide;
-
- const scene = new Scene(pageId, slide, {
+ const pageScene = new Scene(pageId, slide, {
width,
height,
});
+ this._sceneMap.set(pageId, pageScene);
- const viewMain = new Viewport(`PageViewer_${pageId}`, scene, {
+ const viewMain = new Viewport(`PageViewer_${pageId}`, pageScene, {
left: 0,
top: 0,
bottom: 0,
@@ -418,7 +413,6 @@ export class CanvasView extends RxDisposable {
isRelativeX: true,
isRelativeY: true,
});
-
viewMain.closeClip();
const { pageElements, pageBackgroundFill } = page;
@@ -427,30 +421,74 @@ export class CanvasView extends RxDisposable {
const objects = this._objectProvider.convertToRenderObjects(pageElements, mainScene);
if (!objects || !slide) return;
- this._addBackgroundRect(scene, pageBackgroundFill);
+ this._addBackgroundRect(pageScene, pageBackgroundFill);
// So finally SceneViewers are added to the scene as objects. How can we do optimizations on this?
- scene.addObjects(objects);
+ pageScene.addObjects(objects);
objects.forEach((object) => {
- scene.attachTransformerTo(object);
+ pageScene.attachTransformerTo(object);
});
- const transformer = scene.getTransformer();
+ const transformer = pageScene.getTransformer();
transformer?.changeEnd$.subscribe(() => {
- this._thumbSceneRender(this._activePageId, slide);
+ this._thumbSceneRender(pageId, slide);
});
transformer?.clearControl$.subscribe(() => {
- this._thumbSceneRender(this._activePageId, slide);
+ this._thumbSceneRender(pageId, slide);
});
- slide.addPage(scene);
+ slide.addPage(pageScene);
- return scene;
+ return pageScene;
}
private _initializeDependencies(slideInjector: Injector) {
this._objectProvider = slideInjector.createInstance(ObjectProvider);
}
+
+ getRenderUnitByPageId(pageId: PageID) {
+ const scene = this._sceneMap.get(pageId);
+ // no render context
+ // const { engine, unit } = this._renderContext;
+ return {
+ scene,
+ // engine,
+ // unit,
+ };
+ }
+
+ createObjectToPage(element: IPageElement, pageID: PageID): Nullable<BaseObject> {
+ const render = this._currentRender();
+
+ if (!render || !this._objectProvider) {
+ return;
+ }
+ const { scene } = this.getRenderUnitByPageId(pageID);
+ if (!scene) return;
+
+ const object = this._objectProvider.convertToRenderObject(element, scene);
+ if (object) {
+ scene.addObject(object);
+ scene.attachTransformerTo(object);
+ scene.getLayer().makeDirty();
+ return object;
+ }
+ }
+
+ setObjectActiveByPage(obj: BaseObject, pageID: PageID) {
+ const { scene } = this.getRenderUnitByPageId(pageID);
+ if (!scene) return;
+ const transformer = scene.getTransformer();
+ transformer?.activeAnObject(obj);
+ }
+
+ removeObjectById(id: string, pageID: PageID) {
+ const { scene } = this.getRenderUnitByPageId(pageID);
+ if (!scene) return;
+ scene.removeObject(id);
+ const transformer = scene.getTransformer();
+ transformer?.clearControls();
+ }
}
diff --git a/packages/slides/src/views/render/object-provider.ts b/packages/slides/src/views/render/object-provider.ts
index 3abb14699e..c1adafb6d5 100644
--- a/packages/slides/src/views/render/object-provider.ts
+++ b/packages/slides/src/views/render/object-provider.ts
@@ -43,6 +43,10 @@ export class ObjectProvider {
return objects;
}
+ convertToRenderObject(pageElement: IPageElement, mainScene: Scene) {
+ return this._executor(pageElement, mainScene);
+ }
+
private _executor(pageElement: IPageElement, mainScene: Scene) {
const { id: pageElementId, type } = pageElement;
diff --git a/packages/ui/src/views/components/doc-bars/hook.ts b/packages/ui/src/views/components/doc-bars/hook.ts
index 40e0f4f3a7..9b03ddd87b 100644
--- a/packages/ui/src/views/components/doc-bars/hook.ts
+++ b/packages/ui/src/views/components/doc-bars/hook.ts
@@ -82,6 +82,7 @@ export function useToolbarGroups(categories: MenuPositionWithCustom[]): IToolbar
return () => s.unsubscribe();
}, [menuService, category, categories]);
+ // groupsByKey see menu/menu.ts @MenuGroup
const groupsByKey = useMemo(() => {
return groups.find((g) => g.name === category)?.menuItems.reduce(
(acc, item) => {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 693a2ca6bb..006179eec0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2404,6 +2404,10 @@ importers:
packages/slides-ui:
+ dependencies:
+ '@univerjs/icons':
+ specifier: ^0.1.65
devDependencies:
'@types/react':
specifier: ^18.3.3
@@ -2414,6 +2418,9 @@ importers:
'@univerjs/design':
specifier: workspace:*
version: link:../design
+ '@univerjs/drawing':
+ specifier: workspace:*
+ version: link:../drawing
'@univerjs/engine-render':
specifier: workspace:*
version: link:../engine-render