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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(plugin): floating object and image plugin (#380)
Univer6eddb413cb29
diff --git a/examples/univer-doc-ts/package.json b/examples/univer-doc-ts/package.jsonindex 602b34760d..44893f5e70 100644--- a/examples/univer-doc-ts/package.json+++ b/examples/univer-doc-ts/package.json@@ -28,6 +28,7 @@"@univerjs/core": "workspace:*","@univerjs/design": "workspace:*","@univerjs/ui-plugin-docs": "workspace:*",+ "@univerjs/common-plugin-image": "workspace:*","react": "^18.2.0","react-dom": "^18.2.0"},diff --git a/examples/univer-doc-ts/src/main.tsx b/examples/univer-doc-ts/src/main.tsxindex f9d5e667e6..4d7505be12 100644--- a/examples/univer-doc-ts/src/main.tsx+++ b/examples/univer-doc-ts/src/main.tsx@@ -2,6 +2,7 @@ import { DocPlugin } from '@univerjs/base-docs';import { RenderEngine } from '@univerjs/base-render';import { UIPlugin } from '@univerjs/base-ui';import { DEFAULT_DOCUMENT_DATA_EN } from '@univerjs/common-plugin-data';+import { ImagePlugin } from '@univerjs/common-plugin-image';import { LocaleType, Univer } from '@univerjs/core';import { defaultTheme } from '@univerjs/design';import { DocUIPlugin } from '@univerjs/ui-plugin-docs';@@ -34,6 +35,8 @@ univer.registerPlugin(DocUIPlugin, {},});+univer.registerPlugin(ImagePlugin);+univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_EN);// use for console testdiff --git a/examples/univer-sheet-ts/package.json b/examples/univer-sheet-ts/package.jsonindex 3cedf1edb3..bdd342029f 100644--- a/examples/univer-sheet-ts/package.json+++ b/examples/univer-sheet-ts/package.json@@ -28,6 +28,7 @@"@univerjs/sheets-plugin-numfmt": "workspace:*","@univerjs/ui-plugin-docs": "workspace:*","@univerjs/ui-plugin-sheets": "workspace:*",+ "@univerjs/common-plugin-image": "workspace:*","react": "^18.2.0","react-dom": "^18.2.0"},diff --git a/packages/base-docs/src/Basics/DemoData.ts b/packages/base-docs/src/Basics/DemoData.tsindex 8c31b2208e..3215142fa7 100644--- a/packages/base-docs/src/Basics/DemoData.ts+++ b/packages/base-docs/src/Basics/DemoData.ts@@ -17,9 +17,9 @@ export const DOCS_DEMO_DATA: IDocumentData = {drawings: {shapeTest1: {objectId: 'shapeTest1',- objectProperties: {- title: 'test shape',- description: 'test shape',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {size: {width: 100,height: 400,@@ -33,9 +33,9 @@ export const DOCS_DEMO_DATA: IDocumentData = {posOffset: 160,},angle: 0,- imageProperties: {- contentUrl: 'https://cnbabylon.com/assets/img/agents.png',- },+ // imageProperties: {+ // contentUrl: 'https://cnbabylon.com/assets/img/agents.png',+ // },},layoutType: PositionedObjectLayoutType.WRAP_SQUARE,behindDoc: BooleanNumber.FALSE,diff --git a/packages/base-docs/src/Controller/floating-object.controller.ts b/packages/base-docs/src/Controller/floating-object.controller.tsnew file mode 100644index 0000000000..c9d3399118--- /dev/null+++ b/packages/base-docs/src/Controller/floating-object.controller.ts@@ -0,0 +1,229 @@+import {+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,+ Documents,+ DocumentSkeleton,+ IRender,+ IRenderManagerService,+ Liquid,+} from '@univerjs/base-render';+import {+ DEFAULT_DOCUMENT_SUB_COMPONENT_ID,+ Disposable,+ ICommandInfo,+ ICommandService,+ IFloatingObjectManagerParam,+ IFloatingObjectManagerService,+ IUniverInstanceService,+ LifecycleStages,+ OnLifecycle,+} from '@univerjs/core';+import { Inject } from '@wendellhu/redi';++import { IRichTextEditingMutationParams, RichTextEditingMutation } from '../commands/mutations/core-editing.mutation';+import { DocSkeletonManagerService } from '../services/doc-skeleton-manager.service';++@OnLifecycle(LifecycleStages.Steady, FloatingObjectController)+export class FloatingObjectController extends Disposable {+ private _liquid = new Liquid();++ private _pageMarginCache = new Map<string, { marginLeft: number; marginTop: number }>();++ constructor(+ @Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,+ @ICommandService private readonly _commandService: ICommandService,+ @IFloatingObjectManagerService private readonly _floatingObjectManagerService: IFloatingObjectManagerService+ ) {+ super();++ this._initialize();++ this._commandExecutedListener();+ }++ private _initialize() {+ this._initialRenderRefresh();++ this._updateOnPluginChange();+ }++ private _updateOnPluginChange() {+ this._floatingObjectManagerService.pluginUpdate$.subscribe((params) => {+ const docsSkeletonObject = this._docSkeletonManagerService.getCurrent();++ if (docsSkeletonObject == null) {+ return;+ }++ const { unitId, skeleton } = docsSkeletonObject;++ const currentRender = this._renderManagerService.getRenderById(unitId);++ if (currentRender == null) {+ return;+ }++ const { mainComponent, components, scene } = currentRender;++ const docsComponent = mainComponent as Documents;++ const { left: docsLeft, top: docsTop } = docsComponent;++ params.forEach((param) => {+ const { unitId, subComponentId, floatingObjectId, floatingObject } = param;++ const { left = 0, top = 0, width = 0, height = 0, angle, flipX, flipY, skewX, skewY } = floatingObject;++ const cache = this._pageMarginCache.get(floatingObjectId);++ const marginLeft = cache?.marginLeft || 0;+ const marginTop = cache?.marginTop || 0;++ skeleton?.getModel().updateDrawing(floatingObjectId, {+ left: left - docsLeft - marginLeft,+ top: top - docsTop - marginTop,+ height,+ width,+ });+ });++ skeleton?.calculate();+ mainComponent?.makeDirty();+ });+ }++ private _initialRenderRefresh() {+ this._docSkeletonManagerService.currentSkeleton$.subscribe((param) => {+ if (param == null) {+ return;+ }++ const { skeleton: documentSkeleton, unitId } = param;++ const currentRender = this._renderManagerService.getRenderById(unitId);++ if (currentRender == null) {+ return;+ }++ const { mainComponent, components, scene } = currentRender;++ const docsComponent = mainComponent as Documents;++ docsComponent.changeSkeleton(documentSkeleton);++ this._refreshFloatingObject(unitId, documentSkeleton, currentRender);+ });+ }++ private _commandExecutedListener() {+ const updateCommandList = [RichTextEditingMutation.id];++ const excludeUnitList = [DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];++ this.disposeWithMe(+ this._commandService.onCommandExecuted((command: ICommandInfo) => {+ if (updateCommandList.includes(command.id)) {+ const params = command.params as IRichTextEditingMutationParams;+ const { unitId: commandUnitId } = params;++ const docsSkeletonObject = this._docSkeletonManagerService.getCurrent();++ if (docsSkeletonObject == null) {+ return;+ }++ const { unitId, skeleton } = docsSkeletonObject;++ if (commandUnitId !== unitId) {+ return;+ }++ const currentRender = this._renderManagerService.getRenderById(unitId);++ if (currentRender == null) {+ return;+ }++ if (excludeUnitList.includes(unitId)) {+ currentRender.mainComponent?.makeDirty();+ return;+ }++ this._refreshFloatingObject(unitId, skeleton, currentRender);++ // this.calculatePagePosition(currentRender);+ }+ })+ );+ }++ private _refreshFloatingObject(unitId: string, skeleton: DocumentSkeleton, currentRender: IRender) {+ const skeletonData = skeleton?.getSkeletonData();++ const documents = currentRender.mainComponent as Documents;++ if (!skeletonData) {+ return;+ }++ const { left: docsLeft, top: docsTop } = documents;++ const { pages } = skeletonData;++ const Objects: IFloatingObjectManagerParam[] = [];++ this._liquid.reset();++ this._pageMarginCache.clear();++ // const objectList: BaseObject[] = [];+ // const pageMarginCache = new Map<string, { marginLeft: number; marginTop: number }>();++ // const cumPageLeft = 0;+ // const cumPageTop = 0;+ /**+ * TODO: @DR-Univer We should not refresh all floating elements, but instead make a diff.+ */+ for (let i = 0, len = pages.length; i < len; i++) {+ const page = pages[i];+ const { skeDrawings, marginLeft, marginTop } = page;++ // cumPageLeft + = pageWidth + documents.pageMarginLeft;++ this._liquid.translatePagePadding(page);++ skeDrawings.forEach((drawing) => {+ const { aLeft, aTop, height, width, objectId } = drawing;++ Objects.push({+ unitId,+ subComponentId: DEFAULT_DOCUMENT_SUB_COMPONENT_ID,+ floatingObjectId: objectId,+ floatingObject: {+ left: aLeft + docsLeft + this._liquid.x,+ top: aTop + docsTop + this._liquid.y,+ width,+ height,+ },+ });++ this._pageMarginCache.set(objectId, {+ marginLeft: this._liquid.x,+ marginTop: this._liquid.y,+ });+ });++ this._liquid.translatePage(+ page,+ documents.pageLayoutType,+ documents.pageMarginLeft,+ documents.pageMarginTop+ );+ }++ this._floatingObjectManagerService.BatchAddOrUpdate(Objects);+ }+}diff --git a/packages/base-docs/src/DocPlugin.ts b/packages/base-docs/src/DocPlugin.tsindex 93dda802fb..62796b6f3c 100644--- a/packages/base-docs/src/DocPlugin.ts+++ b/packages/base-docs/src/DocPlugin.ts@@ -29,6 +29,7 @@ import { SetDocZoomRatioOperation } from './commands/operations/set-doc-zoom-ratimport { SetTextSelectionsOperation } from './commands/operations/text-selection.operation';import { DeleteLeftInputController } from './Controller/delete-left-input.controller';import { DocRenderController } from './Controller/doc-render.controller';+import { FloatingObjectController } from './Controller/floating-object.controller';import { IMEInputController } from './Controller/ime-input.controller';import { InlineFormatController } from './Controller/inline-format.controller';import { LineBreakInputController } from './Controller/line-break-input.controller';@@ -39,7 +40,6 @@ import { TextSelectionController } from './Controller/text-selection.controller'import { ZoomController } from './Controller/zoom.cotroller';import { enUS } from './locale';import { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';-import { DocsViewManagerService } from './services/docs-view-manager/docs-view-manager.service';import { TextSelectionManagerService } from './services/text-selection-manager.service';import { BreakLineShortcut, DeleteLeftShortcut } from './shortcuts/core-editing.shortcut';import {@@ -169,8 +169,6 @@ export class DocPlugin extends Plugin {},],[TextSelectionManagerService],- [DocsViewManagerService],-// controllers[DocRenderController],[PageRenderController],@@ -182,6 +180,7 @@ export class DocPlugin extends Plugin {[LineBreakInputController],[MoveCursorController],[ZoomController],+ [FloatingObjectController],] as Dependency[]).forEach((d) => docInjector.add(d));}diff --git a/packages/base-docs/src/View/Render/BaseView.ts b/packages/base-docs/src/View/Render/BaseView.tsdeleted file mode 100644index f0b8cd70e6..0000000000--- a/packages/base-docs/src/View/Render/BaseView.ts+++ /dev/null@@ -1,31 +0,0 @@-import { Scene } from '@univerjs/base-render';-import { Registry } from '@univerjs/core';--export class BaseView {- zIndex = 0;-- viewKey = '';-- private _scene!: Scene; // this is ensure to be initialized by concrete classes-- getScene() {- return this._scene;- }-- updateToSheet() {}-- initialize(scene: Scene) {- this._scene = scene;- this._initialize();- return this;- }-- protected _initialize() {}-}--export enum CANVAS_VIEW_KEY {- MAIN_SCENE = 'docMainScene',- DOCS_VIEW = 'docsView',-}--export const CanvasViewRegistry = Registry.create();diff --git a/packages/base-docs/src/View/Render/Views/DocsView.ts b/packages/base-docs/src/View/Render/Views/DocsView.tsdeleted file mode 100644index a1ec0b19f2..0000000000--- a/packages/base-docs/src/View/Render/Views/DocsView.ts+++ /dev/null@@ -1,172 +0,0 @@-import { Documents, DocumentSkeleton, Scene } from '@univerjs/base-render';-import { DocumentModel, IUniverInstanceService, LocaleService } from '@univerjs/core';-import { Inject, Injector } from '@wendellhu/redi';--import { DocsViewManagerService } from '../../../services/docs-view-manager/docs-view-manager.service';-import { BaseView, CANVAS_VIEW_KEY, CanvasViewRegistry } from '../BaseView';--export enum DOCS_VIEW_KEY {- MAIN = '__DocsRender__',-}--export class DocsView extends BaseView {- override zIndex = 1;-- override viewKey = CANVAS_VIEW_KEY.DOCS_VIEW;-- private _documentSkeleton!: DocumentSkeleton;-- private _documents!: Documents;-- private readonly _useExternalModel: boolean;-- private _model: DocumentModel | null = null;-- constructor(- externalModel: DocumentModel | undefined,- @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,- @Inject(DocsViewManagerService) private _docsViewManagerService: DocsViewManagerService,- @Inject(LocaleService) private readonly _localeService: LocaleService- ) {- super();-- if (externalModel) {- this._useExternalModel = true;- this._model = externalModel;- } else {- this._useExternalModel = false;- }-- const docsModel = this._useExternalModel- ? externalModel- : this._currentUniverService.getCurrentUniverDocInstance();- if (docsModel) {- this._docsViewManagerService.registerCanvasViewForUniverInstance(docsModel!.getUnitId(), this);- }- }-- getDocumentSkeleton() {- return this._documentSkeleton;- }-- getDocs() {- return this._documents;- }-- scrollToCenter() {- // const { docsLeft, docsTop } = this._documents.calculatePagePosition();- const pages = this._documentSkeleton.getSkeletonData()?.pages;-- // if (!pages) {- // return;- // }-- // for (let i = 0; i < pages.length; i++) {- // const page = pages[i];- // for (const k of page.skeDrawings.keys()) {- // const obj = this.getScene().getObject(k);- // if (obj) {- // const drawing = page.skeDrawings.get(k) as IDocumentSkeletonDrawing;- // if (obj instanceof Picture) {- // const props = obj.getPictureProps();- // obj.translate(- // drawing.aLeft + docsLeft + (props.liX ?? 0),- // drawing.aTop + docsTop + (props.liY ?? 0)- // );- // } else {- // obj.translate(drawing.aLeft + docsLeft, drawing.aTop + docsTop);- // }- // }- // }- // }- }-- protected override _initialize() {- const scene = this.getScene();- const docsModel = this._useExternalModel- ? this._model!- : this._currentUniverService.getCurrentUniverDocInstance();-- if (!docsModel) {- return;- }-- const documentSkeleton = this._buildSkeleton(docsModel);- const documents = new Documents(DOCS_VIEW_KEY.MAIN, documentSkeleton, {- pageMarginLeft: docsModel.documentStyle.marginLeft || 0,- pageMarginTop: docsModel.documentStyle.marginTop || 0,- });- documents.zIndex = 1000;- this._documentSkeleton = documentSkeleton;- this._documents = documents;-- documentSkeleton.calculate();-- scene.addObjects([documents], 0);-- // const engine = scene.getEngine();- // if (engine) {- // const { width: engineWidth, height: engineHeight } = engine;-- // const { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = documents;-- // let docsLeft = 0;- // let docsTop = 0;-- // let sceneWidth = 0;-- // let sceneHeight = 0;-- // if (engineWidth > docsWidth) {- // docsLeft = engineWidth / 2 - docsWidth / 2;- // sceneWidth = engineWidth - 30;- // } else {- // docsLeft = pageMarginLeft;- // sceneWidth = docsWidth + pageMarginLeft * 2;- // }-- // if (engineHeight > docsHeight) {- // docsTop = engineHeight / 2 - docsHeight / 2;- // sceneHeight = engineHeight - 30;- // } else {- // docsTop = pageMarginTop;- // sceneHeight = docsHeight + pageMarginTop * 2;- // }-- // scene.resize(sceneWidth, sceneHeight + 200);-- // documents.translate(docsLeft, docsTop);- // }- // documents.calculatePagePosition();-- const pages = documentSkeleton.getSkeletonData()?.pages;- if (!pages) {- throw new Error();- }-- // const { pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documents.calculatePagePosition();-- // for (let i = 0; i < pages.length; i++) {- // for (const k of pages[i].skeDrawings.keys()) {- // const obj = this.getScene().getObject(k);- // obj?.translate(obj.left + docsLeft - pageMarginLeft, obj.top + docsTop - pageMarginTop);- // }- // }- }-- private _buildSkeleton(model: DocumentModel) {- return DocumentSkeleton.create(model, this._localeService);- }-}--export class DocsViewFactory {- readonly zIndex = 0;-- create(scene: Scene, injector: Injector): DocsView {- const docsView = injector.createInstance(DocsView) as DocsView;- docsView.initialize(scene);- return docsView;- }-}--CanvasViewRegistry.add(new DocsViewFactory());diff --git a/packages/base-docs/src/View/Render/Views/DrawingsView.ts b/packages/base-docs/src/View/Render/Views/DrawingsView.tsdeleted file mode 100644index 6e699ad756..0000000000--- a/packages/base-docs/src/View/Render/Views/DrawingsView.ts+++ /dev/null@@ -1,118 +0,0 @@-import { BaseObject, Documents, Liquid, Picture, Scene } from '@univerjs/base-render';-import { Injector } from '@wendellhu/redi';--import { BaseView, CanvasViewRegistry } from '../BaseView';-import { DOCS_VIEW_KEY } from './DocsView';--const DRAWINGS_VIEW_BACKGROUND = 'drawings_view_background';--export class DrawingsView extends BaseView {- override viewKey = DRAWINGS_VIEW_BACKGROUND;-- private _liquid = new Liquid();-- // eslint-disable-next-line max-lines-per-function- protected override _initialize() {- const scene = this.getScene();-- const documents = scene.getObject(DOCS_VIEW_KEY.MAIN) as Documents;-- const docsSkeleton = documents.getSkeleton();-- const skeletonData = docsSkeleton?.getSkeletonData();-- if (!skeletonData) {- return;- }-- const { left: docsLeft, top: docsTop } = documents;-- const { pages } = skeletonData;- const objectList: BaseObject[] = [];- const pageMarginCache = new Map<string, { marginLeft: number; marginTop: number }>();-- const cumPageLeft = 0;- const cumPageTop = 0;-- for (let i = 0, len = pages.length; i < len; i++) {- const page = pages[i];- const { skeDrawings, marginLeft, marginTop } = page;-- // cumPageLeft + = pageWidth + documents.pageMarginLeft;-- this._liquid.translatePagePadding(page);-- skeDrawings.forEach((drawing) => {- const { aLeft, aTop, height, width, drawingOrigin } = drawing;-- const { objectProperties } = drawingOrigin;-- const rect = new Picture(drawing.objectId, {- url: objectProperties.imageProperties?.contentUrl || '',- left: aLeft + docsLeft + this._liquid.x,- top: aTop + docsTop + this._liquid.y,- width,- height,- liY: this._liquid.y,- liX: this._liquid.x,- zIndex: 11,- isTransformer: true,- });-- pageMarginCache.set(drawing.objectId, {- marginLeft: this._liquid.x,- marginTop: this._liquid.y,- });-- objectList.push(rect);- });-- this._liquid.translatePage(- page,- documents.pageLayoutType,- documents.pageMarginLeft,- documents.pageMarginTop- );- }- scene.openTransformer();- scene.addObjects(objectList);- scene.getTransformer()?.onChangingObservable.add((state) => {- const { objects } = state;-- const { docsLeft, docsTop } = documents;-- objects.forEach((object) => {- const { oKey, left, top, height, width } = object;- const cache = pageMarginCache.get(oKey);- const marginLeft = cache?.marginLeft || 0;- const marginTop = cache?.marginTop || 0;-- // console.log('onChangingObservable', top, docsTop, marginTop, top - docsTop - marginTop);-- docsSkeleton?.getModel().updateDrawing(oKey, {- left: left - docsLeft - marginLeft,- top: top - docsTop - marginTop,- height,- width,- });- });-- docsSkeleton?.calculate();- });- scene.closeTransformer();-- // scene.addObjects([pageBackground], 0);- }-}--class DrawingsViewFactory {- readonly zIndex = 2;-- create(scene: Scene, injector: Injector) {- const drawingsView = injector.createInstance(DrawingsView) as DrawingsView;- drawingsView.initialize(scene);- return drawingsView;- }-}--CanvasViewRegistry.add(new DrawingsViewFactory());diff --git a/packages/base-docs/src/View/Render/Views/PageView.ts b/packages/base-docs/src/View/Render/Views/PageView.tsdeleted file mode 100644index 2eab3389b2..0000000000--- a/packages/base-docs/src/View/Render/Views/PageView.ts+++ /dev/null@@ -1,51 +0,0 @@-import { Documents, IPageRenderConfig, Rect, Scene } from '@univerjs/base-render';-import { Injector } from '@wendellhu/redi';--import { BaseView, CanvasViewRegistry } from '../BaseView';-import { DOCS_VIEW_KEY } from './DocsView';--const PAGE_VIEW_BACKGROUND = 'page_view_background';--export class PageView extends BaseView {- override zIndex = 2;-- override viewKey = PAGE_VIEW_BACKGROUND;-- protected override _initialize() {- const scene = this.getScene();-- const documents = scene.getObject(DOCS_VIEW_KEY.MAIN) as Documents;-- const pageSize = documents.getSkeleton()?.getPageSize();-- documents.onPageRenderObservable.add((config: IPageRenderConfig) => {- const { page, pageLeft, pageTop, ctx } = config;- 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,- });- ctx.restore();- });-- // scene.addObjects([pageBackground], 0);- }-}--class PageViewFactory {- readonly zIndex = 1;-- create(scene: Scene, injector: Injector) {- const pageView = injector.createInstance(PageView) as PageView;- pageView.initialize(scene);- return pageView;- }-}--CanvasViewRegistry.add(new PageViewFactory());diff --git a/packages/base-docs/src/View/Render/Views/TestView.ts b/packages/base-docs/src/View/Render/Views/TestView.tsdeleted file mode 100644index 007f15eded..0000000000--- a/packages/base-docs/src/View/Render/Views/TestView.ts+++ /dev/null@@ -1,52 +0,0 @@-import { COLORS, getColor, RegularPolygon } from '@univerjs/base-render';--import { BaseView, CanvasViewRegistry } from '../BaseView';--const PAGE_VIEW_BACKGROUND = 'page_view_background';--export class PageView extends BaseView {- override zIndex = 3;-- override viewKey = PAGE_VIEW_BACKGROUND;-- protected override _initialize() {- const scene = this.getScene();-- const polygon = new RegularPolygon('TEXT_POLYGON_KEY_PREFIX_TEST', {- pointsGroup: [- [- { x: 100, y: 10 },- { x: 40, y: 180 },- { x: 190, y: 60 },- { x: 10, y: 60 },- { x: 160, y: 180 },- ],- ],- fill: getColor(COLORS.black, 0.2),- isTransformer: true,- });-- // const object = scene.fuzzyMathObjects('__TestSelection__')[0];- // const ctx = scene.getEngine()?.getCanvas().getGlobalContext();- // object.onTransformChangeObservable.add((state) => {- // if (!ctx) {- // return;- // }- // Rect.drawWith(ctx, {- // left: object.left,- // top: object.top,- // width: object.width,- // height: object.height,- // strokeWidth: 1,- // stroke: 'rgba(198,198,198, 1)',- // fill: 'rgba(255,255,255, 1)',- // zIndex: 3,- // });- // });- scene.openTransformer();- scene.addObjects([polygon]);- scene.closeTransformer();- }-}--CanvasViewRegistry.add(new PageView());diff --git a/packages/base-docs/src/View/Render/Views/index.ts b/packages/base-docs/src/View/Render/Views/index.tsdeleted file mode 100644index 979d837c68..0000000000--- a/packages/base-docs/src/View/Render/Views/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export * from './DocsView';-export * from './DrawingsView';-export * from './PageView';diff --git a/packages/base-docs/src/View/Render/index.ts b/packages/base-docs/src/View/Render/index.tsdeleted file mode 100644index 6457cd61e2..0000000000--- a/packages/base-docs/src/View/Render/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from './BaseView';diff --git a/packages/base-docs/src/commands/commands/doc-object.command.ts b/packages/base-docs/src/commands/commands/doc-object.command.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/base-docs/src/commands/commands/insert-floating-object.command.ts b/packages/base-docs/src/commands/commands/insert-floating-object.command.tsnew file mode 100644index 0000000000..3721602fdc--- /dev/null+++ b/packages/base-docs/src/commands/commands/insert-floating-object.command.ts@@ -0,0 +1,57 @@+import { CommandType, ICommand, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { IInsertDrawingMutation, InsertDrawingMutation } from '../mutations/insert-floating-object.mutation';+import { RemoveDrawingMutation } from '../mutations/remove-floating-object.mutation';++export const InsertDrawingCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'doc.command.insert-drawing',++ handler: async (accessor: IAccessor, params?: IInsertDrawingMutation) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ if (params == null) {+ return false;+ }++ const documentId = params.documentId;++ const documentModel = univerInstanceService.getUniverDocInstance(documentId);+ if (!documentModel) return false;++ const snapshot = documentModel.snapshot;+ if (snapshot == null || snapshot.drawings == null) return false;++ const { objectId, drawing } = params;++ const redoMutationParams: IInsertDrawingMutation = {+ documentId,+ objectId,+ drawing,+ };++ const undoMutationParams = {+ documentId,+ objectId,+ };+ const result = commandService.syncExecuteCommand(InsertDrawingMutation.id, redoMutationParams);++ if (result) {+ undoRedoService.pushUndoRedo({+ URI: documentId,+ undo() {+ return commandService.syncExecuteCommand(RemoveDrawingMutation.id, undoMutationParams);+ },+ redo() {+ return commandService.syncExecuteCommand(InsertDrawingMutation.id, redoMutationParams);+ },+ });+ return true;+ }++ return false;+ },+};diff --git a/packages/base-docs/src/commands/commands/remove-floating-object.command.ts b/packages/base-docs/src/commands/commands/remove-floating-object.command.tsnew file mode 100644index 0000000000..5726b8f252--- /dev/null+++ b/packages/base-docs/src/commands/commands/remove-floating-object.command.ts@@ -0,0 +1,58 @@+import { CommandType, ICommand, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { IInsertDrawingMutation, InsertDrawingMutation } from '../mutations/insert-floating-object.mutation';+import { RemoveDrawingMutation } from '../mutations/remove-floating-object.mutation';+import { ISeachDrawingMutation } from '../mutations/set-floating-object.mutation';++export const RemoveDrawingCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'doc.command.remove-drawing',++ handler: async (accessor: IAccessor, params?: ISeachDrawingMutation) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ if (params == null) {+ return false;+ }++ const documentId = params.documentId;++ const documentModel = univerInstanceService.getUniverDocInstance(documentId);+ if (!documentModel) return false;++ const snapshot = documentModel.snapshot;+ if (snapshot == null || snapshot.drawings == null) return false;++ const { objectId } = params;++ const redoMutationParams: ISeachDrawingMutation = {+ documentId,+ objectId,+ };++ const undoMutationParams: IInsertDrawingMutation = {+ documentId,+ objectId,+ drawing: snapshot.drawings[objectId],+ };+ const result = commandService.syncExecuteCommand(RemoveDrawingMutation.id, redoMutationParams);++ if (result) {+ undoRedoService.pushUndoRedo({+ URI: documentId,+ undo() {+ return commandService.syncExecuteCommand(InsertDrawingMutation.id, undoMutationParams);+ },+ redo() {+ return commandService.syncExecuteCommand(RemoveDrawingMutation.id, redoMutationParams);+ },+ });+ return true;+ }++ return false;+ },+};diff --git a/packages/base-docs/src/commands/commands/set-floating-object-transform.command.ts b/packages/base-docs/src/commands/commands/set-floating-object-transform.command.tsnew file mode 100644index 0000000000..15fb6430b5--- /dev/null+++ b/packages/base-docs/src/commands/commands/set-floating-object-transform.command.ts@@ -0,0 +1,129 @@+import {+ CommandType,+ ICommand,+ ICommandService,+ ISize,+ IUndoRedoService,+ IUniverInstanceService,+ ObjectPositionH,+ ObjectPositionV,+} from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import {+ IDrawingTransformMutation,+ SetDrawingTransformMutation,+ SetDrawingTransformMutationFactory,+} from '../mutations/set-floating-object.mutation';++export interface ISetDrawingSizeCommandParams {+ documentId: string;+ objectId: string;+ size: ISize;+}++export const SetDrawingSizeCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'doc.command.set-drawing-size',++ handler: async (accessor: IAccessor, params?: ISetDrawingSizeCommandParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ if (params == null) {+ return false;+ }++ const documentId = params.documentId;++ const documentModel = univerInstanceService.getUniverDocInstance(documentId);+ if (!documentModel) return false;++ const snapshot = documentModel.snapshot;+ if (snapshot == null) return false;++ const { objectId, size } = params;++ const redoMutationParams: IDrawingTransformMutation = {+ documentId,+ objectId,+ size,+ };++ const undoMutationParams = SetDrawingTransformMutationFactory(accessor, redoMutationParams);+ const result = commandService.syncExecuteCommand(SetDrawingTransformMutation.id, redoMutationParams);++ if (result) {+ undoRedoService.pushUndoRedo({+ URI: documentId,+ undo() {+ return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, undoMutationParams);+ },+ redo() {+ return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, redoMutationParams);+ },+ });+ return true;+ }++ return false;+ },+};++export interface ISetDrawingPositionCommandParams {+ documentId: string;+ objectId: string;+ positionH: ObjectPositionH;+ positionV: ObjectPositionV;+}++export const SetDrawingPositionCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'doc.command.set-drawing-size',++ handler: async (accessor: IAccessor, params?: ISetDrawingPositionCommandParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const univerInstanceService = accessor.get(IUniverInstanceService);++ if (params == null) {+ return false;+ }++ const documentId = params.documentId;++ const documentModel = univerInstanceService.getUniverDocInstance(documentId);+ if (!documentModel) return false;++ const snapshot = documentModel.snapshot;+ if (snapshot == null) return false;++ const { objectId, positionH, positionV } = params;++ const redoMutationParams: IDrawingTransformMutation = {+ documentId,+ objectId,+ positionH,+ positionV,+ };++ const undoMutationParams = SetDrawingTransformMutationFactory(accessor, redoMutationParams);+ const result = commandService.syncExecuteCommand(SetDrawingTransformMutation.id, redoMutationParams);++ if (result) {+ undoRedoService.pushUndoRedo({+ URI: documentId,+ undo() {+ return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, undoMutationParams);+ },+ redo() {+ return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, redoMutationParams);+ },+ });+ return true;+ }++ return false;+ },+};diff --git a/packages/base-docs/src/commands/mutations/doc-object.mutation.ts b/packages/base-docs/src/commands/mutations/doc-object.mutation.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/base-docs/src/commands/mutations/insert-floating-object.mutation.ts b/packages/base-docs/src/commands/mutations/insert-floating-object.mutation.tsnew file mode 100644index 0000000000..f00ea62046--- /dev/null+++ b/packages/base-docs/src/commands/mutations/insert-floating-object.mutation.ts@@ -0,0 +1,32 @@+import { CommandType, IDrawing, IMutation, IUniverInstanceService } from '@univerjs/core';++import { ISeachDrawingMutation } from './set-floating-object.mutation';++export interface IInsertDrawingMutation extends ISeachDrawingMutation {+ drawing: IDrawing;+}++export const InsertDrawingMutation: IMutation<IInsertDrawingMutation> = {+ id: 'doc.mutation.insert-drawing',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const univerdoc = accessor.get(IUniverInstanceService).getUniverDocInstance(params.documentId);++ if (univerdoc == null) {+ return false;+ }++ let drawings = univerdoc.snapshot.drawings;++ if (drawings == null) {+ drawings = {};+ univerdoc.snapshot.drawings = drawings;+ }++ const { objectId, drawing } = params;++ drawings[objectId] = drawing;++ return true;+ },+};diff --git a/packages/base-docs/src/commands/mutations/remove-floating-object.mutation.ts b/packages/base-docs/src/commands/mutations/remove-floating-object.mutation.tsnew file mode 100644index 0000000000..ddbafc34f6--- /dev/null+++ b/packages/base-docs/src/commands/mutations/remove-floating-object.mutation.ts@@ -0,0 +1,26 @@+import { CommandType, IMutation, IUniverInstanceService } from '@univerjs/core';++import { ISeachDrawingMutation } from './set-floating-object.mutation';++export const RemoveDrawingMutation: IMutation<ISeachDrawingMutation> = {+ id: 'doc.mutation.remove-drawing',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const univerdoc = accessor.get(IUniverInstanceService).getUniverDocInstance(params.documentId);++ if (univerdoc == null) {+ return false;+ }++ let drawings = univerdoc.snapshot.drawings;++ if (drawings == null) {+ drawings = {};+ univerdoc.snapshot.drawings = drawings;+ }++ delete drawings[params.objectId];++ return true;+ },+};diff --git a/packages/base-docs/src/commands/mutations/set-floating-object.mutation.ts b/packages/base-docs/src/commands/mutations/set-floating-object.mutation.tsnew file mode 100644index 0000000000..28fe0de044--- /dev/null+++ b/packages/base-docs/src/commands/mutations/set-floating-object.mutation.ts@@ -0,0 +1,197 @@+import {+ BooleanNumber,+ CommandType,+ IMutation,+ ISize,+ IUniverInstanceService,+ ObjectPositionH,+ ObjectPositionV,+ PositionedObjectLayoutType,+ WrapTextType,+} from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++export interface ISeachDrawingMutation {+ documentId: string;+ objectId: string;+}++export interface IDrawingTransformMutation extends ISeachDrawingMutation {+ size?: ISize;+ positionH?: ObjectPositionH;+ positionV?: ObjectPositionV;+ angle?: number;+}++export const SetDrawingTransformMutationFactory = (+ accessor: IAccessor,+ params: IDrawingTransformMutation+): IDrawingTransformMutation => {+ const { documentId, objectId } = params;+ const documentModel = accessor.get(IUniverInstanceService).getUniverDocInstance(documentId);+ if (documentModel == null) {+ throw new Error('documentModel is null error!');+ }++ const drawings = documentModel.snapshot.drawings;++ if (drawings == null) {+ return {+ documentId,+ objectId,+ };+ }++ const drawing = drawings[objectId];++ if (drawing == null) {+ return {+ documentId,+ objectId,+ };+ }++ return {+ size: drawing.objectTransform.size,+ positionH: drawing.objectTransform.positionH,+ positionV: drawing.objectTransform.positionV,+ angle: drawing.objectTransform.angle,+ documentId,+ objectId,+ };+};++export const SetDrawingTransformMutation: IMutation<IDrawingTransformMutation> = {+ id: 'doc.mutation.set-drawing-transform',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const univerdoc = accessor.get(IUniverInstanceService).getUniverDocInstance(params.documentId);++ if (univerdoc == null) {+ return false;+ }++ let drawings = univerdoc.snapshot.drawings;++ if (drawings == null) {+ drawings = {};+ univerdoc.snapshot.drawings = drawings;+ }++ const { objectId, size, positionH, positionV, angle } = params;++ const drawing = drawings[objectId];++ if (drawing == null) {+ return false;+ }++ if (size != null) drawing.objectTransform.size = size;++ if (positionH != null) drawing.objectTransform.positionH = positionH;++ if (positionV != null) drawing.objectTransform.positionV = positionV;++ if (angle != null) drawing.objectTransform.angle = angle;++ return true;+ },+};++export interface IDrawingLayoutMutation extends ISeachDrawingMutation {+ layoutType?: PositionedObjectLayoutType;++ behindDoc?: BooleanNumber; // wrapNone+ start?: number[]; // wrapPolygon+ lineTo?: number[][]; // wrapPolygon+ wrapText?: WrapTextType; // wrapSquare | wrapThrough | wrapTight+ distL?: number; // wrapSquare | wrapThrough | wrapTight+ distR?: number; // wrapSquare | wrapThrough | wrapTight+ distT?: number; // wrapSquare | wrapTopAndBottom+ distB?: number; // wrapSquare | wrapTopAndBottom+}++export const SetDrawingLayoutMutation: IMutation<IDrawingLayoutMutation> = {+ id: 'doc.mutation.set-drawing-layout',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const univerdoc = accessor.get(IUniverInstanceService).getUniverDocInstance(params.documentId);++ if (univerdoc == null) {+ return false;+ }++ let drawings = univerdoc.snapshot.drawings;++ if (drawings == null) {+ drawings = {};+ univerdoc.snapshot.drawings = drawings;+ }++ const { objectId, layoutType, behindDoc, start, lineTo, wrapText, distL, distR, distT, distB } = params;++ const drawing = drawings[objectId];++ if (drawing == null) {+ return false;+ }++ layoutType && (drawing.layoutType = layoutType);++ behindDoc && (drawing.behindDoc = behindDoc);++ start && (drawing.start = start);++ lineTo && (drawing.lineTo = lineTo);++ wrapText && (drawing.wrapText = wrapText);++ distL && (drawing.distL = distL);++ distR && (drawing.distR = distR);++ distT && (drawing.distT = distT);++ distB && (drawing.distB = distB);++ return true;+ },+};++export interface IDrawingInfoMutation extends ISeachDrawingMutation {+ title?: string;+ description?: string;+}++export const SetDrawingInfoMutation: IMutation<IDrawingInfoMutation> = {+ id: 'doc.mutation.set-drawing-info',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const univerdoc = accessor.get(IUniverInstanceService).getUniverDocInstance(params.documentId);++ if (univerdoc == null) {+ return false;+ }++ let drawings = univerdoc.snapshot.drawings;++ if (drawings == null) {+ drawings = {};+ univerdoc.snapshot.drawings = drawings;+ }++ const { objectId, title, description } = params;++ const drawing = drawings[objectId];++ if (drawing == null) {+ return false;+ }++ title && (drawing.title = title);++ description && (drawing.description = description);++ return true;+ },+};diff --git a/packages/base-docs/src/index.ts b/packages/base-docs/src/index.tsindex 248bf8b325..f4b0db4148 100644--- a/packages/base-docs/src/index.ts+++ b/packages/base-docs/src/index.ts@@ -21,6 +21,4 @@ export {export { MoveCursorOperation } from './commands/operations/cursor.operation';export * from './DocPlugin';export { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';-export { DocsViewManagerService } from './services/docs-view-manager/docs-view-manager.service';export { TextSelectionManagerService } from './services/text-selection-manager.service';-export { DocsView, DocsViewFactory } from './View/Render/Views/DocsView';diff --git a/packages/base-docs/src/services/docs-view-manager/docs-view-manager.service.ts b/packages/base-docs/src/services/docs-view-manager/docs-view-manager.service.tsdeleted file mode 100644index 8b74185938..0000000000--- a/packages/base-docs/src/services/docs-view-manager/docs-view-manager.service.ts+++ /dev/null@@ -1,59 +0,0 @@-import { Disposable, IUniverInstanceService, toDisposable } from '@univerjs/core';-import { IDisposable } from '@wendellhu/redi';-import { BehaviorSubject, Observable } from 'rxjs';--import { DocsView } from '../../View/Render/Views/DocsView';--/**- * This services manages instances of doc CanvasView and determines which one- * the user is currently interacting with.- */-export class DocsViewManagerService extends Disposable {- readonly current$: Observable<DocsView | null>;-- private readonly _current$ = new BehaviorSubject<DocsView | null>(null);-- private readonly _viewsMap = new Map<string, DocsView>();-- constructor(@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService) {- super();-- this.disposeWithMe(- toDisposable(- this._currentUniverService.focused$.subscribe((id) => {- if (!id) {- this._current$.next(null);- return;- }-- // FIXME: if the focused id is a sheet ID, we should focus on the cell editor instead- const view = this._viewsMap.get(id);- if (view) {- this._current$.next(view ?? null);- }- })- )- );-- this.current$ = this._current$.asObservable();- }-- override dispose(): void {- super.dispose();-- this._viewsMap.clear();- this._current$.complete();- }-- registerCanvasViewForUniverInstance(unitId: string, docsView: DocsView): IDisposable {- this._viewsMap.set(unitId, docsView);-- return toDisposable(() => {- this._viewsMap.delete(unitId);- });- }-- getDocsView(unitId: string): DocsView | undefined {- return this._viewsMap.get(unitId);- }-}diff --git a/packages/base-render/src/Basics/Interfaces.ts b/packages/base-render/src/Basics/Interfaces.tsindex 3ec54a3fee..2c17af9752 100644--- a/packages/base-render/src/Basics/Interfaces.ts+++ b/packages/base-render/src/Basics/Interfaces.ts@@ -131,7 +131,7 @@ export interface IFontCreateConfig {// export interface IPageConfig {// pageNumberStart: number;-// pageSize: ISizeData;+// pageSize: ISize;// headerIds: IHeaderIds;// footerIds: IFooterIds;// footers?: IFooters;diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.tsindex 2af70c6588..b7492a700d 100644--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.ts+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.ts@@ -604,9 +604,9 @@ function __updateDrawingPosition(return;}- const { objectProperties } = drawingOrigin;+ const { objectTransform } = drawingOrigin;- const { positionH, positionV, size, angle } = objectProperties;+ const { positionH, positionV, size, angle } = objectTransform;const { width = 0, height = 0 } = size;drawing.aLeft = getPositionHorizon(positionH, column, page, width, isPageBreak) || 0;diff --git a/packages/base-render/src/Scene.Transformer.ts b/packages/base-render/src/Scene.Transformer.tsindex fcb3d6498c..680c6e74b5 100644--- a/packages/base-render/src/Scene.Transformer.ts+++ b/packages/base-render/src/Scene.Transformer.ts@@ -435,6 +435,11 @@ export class Transformer implements ITransformerConfig {scene.enableEvent();scene.resetCursor();scrollTimer.dispose();++ this.onChangeEndObservable.notifyObservers({+ objects: this._selectedObjectMap,+ type: MoveObserverType.MOVE_END,+ });});state.stopPropagation();diff --git a/packages/base-sheets/src/Controller/freeze.controller.ts b/packages/base-sheets/src/Controller/freeze.controller.tsindex cfc5efe119..b4093427e8 100644--- a/packages/base-sheets/src/Controller/freeze.controller.ts+++ b/packages/base-sheets/src/Controller/freeze.controller.ts@@ -22,12 +22,12 @@ import {} from '@univerjs/core';import { Inject } from '@wendellhu/redi';-import { SetWorksheetActivateMutation } from '..';import { getCoordByOffset, getSheetObject } from '../Basics/component-tools';import { SHEET_COMPONENT_HEADER_LAYER_INDEX, VIEWPORT_KEY } from '../Basics/Const/DEFAULT_SPREADSHEET_VIEW';import { SetFrozenCommand } from '../commands/commands/set-frozen.command';import { ScrollCommand } from '../commands/commands/set-scroll.command';import { ISetFrozenMutationParams, SetFrozenMutation } from '../commands/mutations/set-frozen.mutation';+import { SetWorksheetActivateMutation } from '../commands/mutations/set-worksheet-activate.mutation';import { SetZoomRatioOperation } from '../commands/operations/set-zoom-ratio.operation';import { ScrollManagerService } from '../services/scroll-manager.service';import { SelectionManagerService } from '../services/selection/selection-manager.service';diff --git a/packages/base-slides/src/Basics/DemoData.ts b/packages/base-slides/src/Basics/DemoData.tsindex 8a193315da..fbdb8182a6 100644--- a/packages/base-slides/src/Basics/DemoData.ts+++ b/packages/base-slides/src/Basics/DemoData.ts@@ -17,9 +17,9 @@ export const docsDemoData: IDocumentData = {drawings: {shapeTest1: {objectId: 'shapeTest1',- objectProperties: {- title: 'test shape',- description: 'test shape',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {size: {width: 100,height: 400,@@ -33,9 +33,9 @@ export const docsDemoData: IDocumentData = {posOffset: 160,},angle: 0,- imageProperties: {- contentUrl: 'https://cnbabylon.com/assets/img/agents.png',- },+ // imageProperties: {+ // contentUrl: 'https://cnbabylon.com/assets/img/agents.png',+ // },},layoutType: PositionedObjectLayoutType.WRAP_SQUARE,behindDoc: BooleanNumber.FALSE,diff --git a/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.ts b/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.tsindex 45ad20992d..db0b2ffe38 100644--- a/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.ts+++ b/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.ts@@ -179,10 +179,10 @@ export class DocsAdaptor extends ObjectAdaptor {skeDrawings.forEach((drawing: IDocumentSkeletonDrawing) => {const { aLeft, aTop, height, width, drawingOrigin } = drawing;- const { objectProperties } = drawingOrigin;+ const { objectTransform } = drawingOrigin;const rect = new Picture(drawing.objectId, {- url: objectProperties.imageProperties?.contentUrl || '',+ // url: objectTransform.imageProperties?.contentUrl || '',left: aLeft + docsLeft + this._liquid.x,top: aTop + docsTop + this._liquid.y,width,diff --git a/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA.ts b/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA.tsindex bbbecb1a7b..8de91497c5 100644--- a/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA.ts+++ b/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA.ts@@ -17,9 +17,9 @@ export const DEFAULT_DOCUMENT_DATA: IDocumentData = {drawings: {shapeTest1: {objectId: 'shapeTest1',- objectProperties: {- title: 'test shape',- description: 'test shape',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {size: {width: 100,height: 400,@@ -33,9 +33,9 @@ export const DEFAULT_DOCUMENT_DATA: IDocumentData = {posOffset: 160,},angle: 0,- imageProperties: {- contentUrl: 'https://cnbabylon.com/assets/img/agents.png',- },+ // imageProperties: {+ // contentUrl: 'https://cnbabylon.com/assets/img/agents.png',+ // },},layoutType: PositionedObjectLayoutType.WRAP_SQUARE,behindDoc: BooleanNumber.FALSE,diff --git a/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.ts b/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.tsindex 1f0f70c621..2734972f52 100644--- a/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.ts+++ b/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.ts@@ -16,9 +16,9 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {drawings: {shapeTest1: {objectId: 'shapeTest1',- objectProperties: {- title: 'test shape',- description: 'test shape',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {size: {width: 1484 * 0.15,height: 864 * 0.15,@@ -32,9 +32,6 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {posOffset: 510,},angle: 0,- imageProperties: {- contentUrl: 'https://minio.cnbabylon.com/univer/slide/gartner-tech-2022.png',- },},layoutType: PositionedObjectLayoutType.WRAP_SQUARE,behindDoc: BooleanNumber.FALSE,@@ -42,9 +39,9 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {},shapeTest2: {objectId: 'shapeTest2',- objectProperties: {- title: 'test shape',- description: 'test shape',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {size: {width: 2548 * 0.1,height: 2343 * 0.1,@@ -58,9 +55,6 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {posOffset: 200,},angle: 0,- imageProperties: {- contentUrl: 'https://minio.cnbabylon.com/univer/slide/hype-cycle-for-emerging-tech-2022.png',- },},layoutType: PositionedObjectLayoutType.WRAP_SQUARE,behindDoc: BooleanNumber.FALSE,diff --git a/packages/common-plugin-data/src/Sheets/DEFAULT_WORKBOOK_DATA.ts b/packages/common-plugin-data/src/Sheets/DEFAULT_WORKBOOK_DATA.tsindex ff744e4d4c..095df8f9d2 100644--- a/packages/common-plugin-data/src/Sheets/DEFAULT_WORKBOOK_DATA.ts+++ b/packages/common-plugin-data/src/Sheets/DEFAULT_WORKBOOK_DATA.ts@@ -25,9 +25,9 @@ const richTextTestFloat: IDocumentData = {drawings: {shapeTest1: {objectId: 'shapeTest1',- objectProperties: {- title: 'test shape',- description: 'test shape',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {size: {width: 100,height: 400,@@ -41,9 +41,9 @@ const richTextTestFloat: IDocumentData = {posOffset: 160,},angle: 0,- imageProperties: {- contentUrl: 'https://cnbabylon.com/assets/img/agents.png',- },+ // imageProperties: {+ // contentUrl: 'https://cnbabylon.com/assets/img/agents.png',+ // },},layoutType: PositionedObjectLayoutType.WRAP_SQUARE,behindDoc: BooleanNumber.FALSE,diff --git a/packages/common-plugin-image/README.md b/packages/common-plugin-image/README.mdnew file mode 100644index 0000000000..9e7a4ea9ee--- /dev/null+++ b/packages/common-plugin-image/README.md@@ -0,0 +1,14 @@+# @univerjs/common-plugin-image++## Introduction++Univer common-plugin-image++## Usage+### Installation+```shell+npm i @univerjs/common-plugin-image+```++### API+Check [Univer](https://github.com/dream-num/univer/)diff --git a/packages/common-plugin-image/package.json b/packages/common-plugin-image/package.jsonnew file mode 100644index 0000000000..3cff3b3c73--- /dev/null+++ b/packages/common-plugin-image/package.json@@ -0,0 +1,25 @@+{+ "name": "@univerjs/common-plugin-image",+ "version": "0.0.1",+ "description": "Univer's public plugins can be shared among multiple businesses.",+ "author": "DreamNum <[email protected]>",+ "license": "MIT",+ "main": "./src/index.ts",+ "module": "./src/index.ts",+ "dependencies": {+ "@univerjs/base-render": "workspace:*",+ "@univerjs/base-sheets": "workspace:*",+ "@univerjs/base-ui": "workspace:*",+ "@univerjs/core": "workspace:*",+ "@wendellhu/redi": "^0.12.10",+ "rxjs": "^7.8.1"+ },+ "devDependencies": {+ "@types/node": "^20.8.9",+ "@vitest/coverage-v8": "^0.34.6",+ "esbuild": "^0.19.5",+ "less": "^4.2.0",+ "ts-node": "^10.9.1",+ "vitest": "^0.34.6"+ }+}diff --git a/packages/common-plugin-image/src/ImagePlugin.ts b/packages/common-plugin-image/src/ImagePlugin.tsnew file mode 100644index 0000000000..198d448d54--- /dev/null+++ b/packages/common-plugin-image/src/ImagePlugin.ts@@ -0,0 +1,65 @@+import { DEFAULT_DOCUMENT_SUB_COMPONENT_ID, LocaleService, Plugin, PLUGIN_NAMES, PluginType } from '@univerjs/core';+import { Dependency, Inject, Injector } from '@wendellhu/redi';++import { ImageLoadController } from './controllers/image.load.controller';+import { ImageModel } from './models/image-model';+import { IImageManagerService, ImageManagerService } from './services/image-manager.service';+import { IImageRenderService, ImageRenderService } from './services/image-render.service';++export class ImagePlugin extends Plugin {+ static override type = PluginType.Univer;++ constructor(+ config: undefined,+ @Inject(Injector) protected readonly _injector: Injector,+ @Inject(LocaleService) private readonly _localeService: LocaleService+ ) {+ super(PLUGIN_NAMES.BASE_COMPONENT);+ }++ override onStarting(_injector: Injector): void {+ this._initDependencies(_injector);+ }++ override onReady(): void {+ /**+ * TODO: @DR-Univer Before the loading process is completed, mock some data for testing.+ */+ const imageManagerService = this._injector.get(IImageManagerService);+ const model = new ImageModel({+ imageId: 'shapeTest1',+ contentUrl: 'https://minio.cnbabylon.com/univer/slide/gartner-tech-2022.png',+ });+ imageManagerService.add({+ unitId: 'd',+ subComponentId: DEFAULT_DOCUMENT_SUB_COMPONENT_ID,+ imageId: 'shapeTest1',+ imageModel: model,+ });++ // imageProperties: {+ // contentUrl: 'https://minio.cnbabylon.com/univer/slide/gartner-tech-2022.png',+ // },++ // imageProperties: {+ // contentUrl: 'https://minio.cnbabylon.com/univer/slide/hype-cycle-for-emerging-tech-2022.png',+ // },+ }++ private _initDependencies(injector: Injector): void {+ const dependencies: Dependency[] = [+ // legacy managers - deprecated+ // [ComponentManager],+ // [ZIndexManager],+ // services+ [IImageManagerService, { useClass: ImageManagerService }],+ [IImageRenderService, { useClass: ImageRenderService }],+ // controllers+ [ImageLoadController],+ // [SharedController],+ // [IUIController, { useClass: DesktopUIController }],+ ];++ dependencies.forEach((dependency) => injector.add(dependency));+ }+}diff --git a/packages/common-plugin-image/src/controllers/image.load.controller.ts b/packages/common-plugin-image/src/controllers/image.load.controller.tsnew file mode 100644index 0000000000..0f5efbdeb3--- /dev/null+++ b/packages/common-plugin-image/src/controllers/image.load.controller.ts@@ -0,0 +1,183 @@+import { IRenderManagerService, Picture, Scene } from '@univerjs/base-render';+import {+ Disposable,+ ICommandInfo,+ ICommandService,+ IFloatingObjectManagerParam,+ IFloatingObjectManagerService,+ IUniverInstanceService,+ LifecycleStages,+ OnLifecycle,+ toDisposable,+} from '@univerjs/core';++import { IImageManagerService } from '../services/image-manager.service';+import { IImageRenderService } from '../services/image-render.service';++@OnLifecycle(LifecycleStages.Rendered, ImageLoadController)+export class ImageLoadController extends Disposable {+ constructor(+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,+ @ICommandService private readonly _commandService: ICommandService,+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,+ @IImageManagerService private readonly _imageManagerService: IImageManagerService,+ @IImageRenderService private readonly _imageRenderService: IImageRenderService,+ @IFloatingObjectManagerService private readonly _floatingObjectManagerService: IFloatingObjectManagerService+ ) {+ super();++ this._initialize();+ }++ override dispose(): void {+ super.dispose();+ }++ private _initialize() {+ this._floatingObjectListener();++ this._commandExecutedListener();+ }++ private _commandExecutedListener() {+ const updateCommandList: string[] = [];++ this.disposeWithMe(+ this._commandService.onCommandExecuted((command: ICommandInfo) => {+ if (updateCommandList.includes(command.id)) {+ return true;+ }+ })+ );+ }++ private _floatingObjectListener() {+ this.disposeWithMe(+ toDisposable(+ this._floatingObjectManagerService.andOrUpdate$.subscribe((params) => {+ const sceneList: Scene[] = [];+ params.forEach((param) => {+ const { unitId, subComponentId, floatingObjectId, floatingObject } = param;++ const renderObject = this._renderManagerService.getRenderById(unitId);++ const scene = renderObject?.scene;++ if (scene == null) {+ return true;+ }++ const searchParam = {+ unitId,+ subComponentId,+ imageId: floatingObjectId,+ };++ const imageModel = this._imageManagerService.getImageByParam(searchParam)?.imageModel;++ if (imageModel == null) {+ return true;+ }++ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = floatingObject;++ const imageShapeKey = `${unitId}_${subComponentId}_${floatingObjectId}`;++ const imageShape = scene.getObject(imageShapeKey);++ if (imageShape != null) {+ imageShape.transformByState({+ left,+ top,+ width,+ height,+ angle,+ flipX,+ flipY,+ skewX,+ skewY,+ });+ return;+ }++ this._imageRenderService.add(imageShapeKey, searchParam);++ const image = new Picture(imageShapeKey, {+ url: imageModel.getUrl(),+ left,+ top,+ width,+ height,+ zIndex: 11,+ isTransformer: true,+ });++ if (!scene.getTransformer()) {+ scene.openTransformer();+ }++ scene.addObject(image);++ if (!sceneList.includes(scene)) {+ sceneList.push(scene);+ }+ });++ sceneList.forEach((scene) => {+ this._addListenerOnImage(scene);+ scene.closeTransformer();+ });+ })+ )+ );+ }++ private _addListenerOnImage(scene: Scene) {+ scene.getTransformer()?.onChangingObservable.add((state) => {+ const { objects } = state;++ // const { docsLeft, docsTop } = documents;+ const params: IFloatingObjectManagerParam[] = [];+ objects.forEach((object) => {+ const { oKey, left, top, height, width } = object;++ const searchParam = this._imageRenderService.get(oKey);++ if (searchParam == null) {+ return true;+ }++ const { unitId, subComponentId, imageId } = searchParam;++ params.push({+ unitId,+ subComponentId,+ floatingObjectId: imageId,+ floatingObject: {+ left,+ top,+ height,+ width,+ },+ });++ // const cache = pageMarginCache.get(oKey);+ // const marginLeft = cache?.marginLeft || 0;+ // const marginTop = cache?.marginTop || 0;++ // console.log('onChangingObservable', top, docsTop, marginTop, top - docsTop - marginTop);++ // docsSkeleton?.getModel().updateDrawing(oKey, {+ // left: left - docsLeft - marginLeft,+ // top: top - docsTop - marginTop,+ // height,+ // width,+ // });+ });++ this._floatingObjectManagerService.pluginUpdateRefresh(params);++ // docsSkeleton?.calculate();+ });+ }+}diff --git a/packages/common-plugin-image/src/index.ts b/packages/common-plugin-image/src/index.tsnew file mode 100644index 0000000000..9965f6d59a--- /dev/null+++ b/packages/common-plugin-image/src/index.ts@@ -0,0 +1,2 @@+export { ImagePlugin } from './ImagePlugin';+export { ImageManagerService } from './services/image-manager.service';diff --git a/packages/common-plugin-image/src/models/image-model.ts b/packages/common-plugin-image/src/models/image-model.tsnew file mode 100644index 0000000000..398351ccd0--- /dev/null+++ b/packages/common-plugin-image/src/models/image-model.ts@@ -0,0 +1,36 @@+import { Nullable } from '@univerjs/core';++export interface IImageData {+ imageId: string;+ contentUrl: string;+}++export class ImageModel {+ private _imageShapeKey: Nullable<string>;++ constructor(private _imageData: IImageData) {}++ getImageData() {+ return this._imageData;+ }++ getUrl() {+ return this._imageData.contentUrl;+ }++ getId() {+ return this._imageData.imageId;+ }++ setKey(key: string) {+ this._imageShapeKey = key;+ }++ getKey() {+ return this._imageShapeKey;+ }++ hasRender() {+ return this._imageShapeKey != null;+ }+}diff --git a/packages/common-plugin-image/src/services/image-manager.service.ts b/packages/common-plugin-image/src/services/image-manager.service.tsnew file mode 100644index 0000000000..d80f10df07--- /dev/null+++ b/packages/common-plugin-image/src/services/image-manager.service.ts@@ -0,0 +1,149 @@+import { Nullable } from '@univerjs/core';+import { createIdentifier, IDisposable } from '@wendellhu/redi';+import { Observable, Subject } from 'rxjs';++import { ImageModel } from '../models/image-model';++export interface IImageManagerSearchParam {+ unitId: string;+ subComponentId: string; //sheetId, pageId and so on, it has a default name in doc business+ imageId: string;+}++export interface IImageManagerParam extends IImageManagerSearchParam {+ imageModel: ImageModel;+}++export type ImageManagerInfo = Map<string, Map<string, Map<string, IImageManagerParam>>>;++export interface IImageManagerService {+ readonly remove$: Observable<IImageManagerParam[]>;++ readonly andOrUpdate$: Observable<IImageManagerSearchParam[]>;++ dispose(): void;++ add(insertParam: IImageManagerParam): void;++ batchAdd(insertParams: IImageManagerParam[]): void;++ remove(searchParam: IImageManagerSearchParam): void;++ batchRemove(removeParams: IImageManagerSearchParam[]): void;++ setCurrent(searchParam: Nullable<IImageManagerSearchParam>): void;++ getCurrent(): Nullable<IImageManagerParam>;++ getImageByParam(param: Nullable<IImageManagerSearchParam>): Nullable<IImageManagerParam>;+}++/**+ *+ */+export class ImageManagerService implements IDisposable, IImageManagerService {+ private _current: Nullable<IImageManagerSearchParam> = null;++ private _imageManagerInfo: ImageManagerInfo = new Map();++ private readonly _remove$ = new Subject<IImageManagerParam[]>();+ readonly remove$ = this._remove$.asObservable();++ private readonly _add$ = new Subject<IImageManagerSearchParam[]>();+ readonly andOrUpdate$ = this._add$.asObservable();++ dispose(): void {+ this._remove$.complete();+ this._add$.complete();+ this._imageManagerInfo.clear();+ }++ add(insertParam: IImageManagerParam) {+ this._add$.next(this._addByParam(insertParam));+ }++ batchAdd(insertParams: IImageManagerParam[]) {+ const objects: IImageManagerSearchParam[] = [];+ insertParams.forEach((insertParam) => {+ objects.push(...this._addByParam(insertParam));+ });++ this._add$.next(objects);+ }++ remove(searchParam: IImageManagerSearchParam) {+ this._remove$.next(this._removeByParam(searchParam));+ }++ batchRemove(removeParams: IImageManagerSearchParam[]) {+ const objects: IImageManagerParam[] = [];+ removeParams.forEach((removeParam) => {+ objects.push(...this._removeByParam(removeParam));+ });++ this._remove$.next(objects);+ }++ setCurrent(searchParam: Nullable<IImageManagerSearchParam>) {+ this._current = searchParam;+ }++ getCurrent(): Nullable<IImageManagerParam> {+ return this._getCurrentBySearch(this._current);+ }++ getImageByParam(param: Nullable<IImageManagerSearchParam>): Nullable<IImageManagerParam> {+ return this._getCurrentBySearch(param);+ }++ private _getCurrentBySearch(searchParam: Nullable<IImageManagerSearchParam>): Nullable<IImageManagerParam> {+ if (searchParam == null) {+ return;+ }+ const { unitId, subComponentId, imageId } = searchParam;+ return this._imageManagerInfo.get(unitId)?.get(subComponentId)?.get(imageId);+ }++ private _addByParam(insertParam: IImageManagerParam): IImageManagerSearchParam[] {+ const { unitId, subComponentId, imageId, imageModel } = insertParam;++ if (!this._imageManagerInfo.has(unitId)) {+ this._imageManagerInfo.set(unitId, new Map());+ }++ const subComponentData = this._imageManagerInfo.get(unitId)!;++ if (!subComponentData.has(subComponentId)) {+ subComponentData.set(subComponentId, new Map());+ }++ subComponentData.get(subComponentId)!.set(imageId, insertParam);++ return [{ unitId, subComponentId, imageId }];+ }++ private _removeByParam(searchParam: IImageManagerSearchParam): IImageManagerParam[] {+ if (searchParam == null) {+ return [];+ }+ const { unitId, subComponentId, imageId } = searchParam;++ const subComponentObjects = this._imageManagerInfo.get(unitId)?.get(subComponentId);++ if (subComponentObjects == null) {+ return [];+ }++ const object = subComponentObjects.get(imageId);++ if (object == null) {+ return [];+ }++ subComponentObjects.delete(imageId);++ return [{ ...searchParam, imageModel: object.imageModel }];+ }+}++export const IImageManagerService = createIdentifier<IImageManagerService>('univer.plugin.image-manager.service');diff --git a/packages/common-plugin-image/src/services/image-render.service.ts b/packages/common-plugin-image/src/services/image-render.service.tsnew file mode 100644index 0000000000..9b904f1d44--- /dev/null+++ b/packages/common-plugin-image/src/services/image-render.service.ts@@ -0,0 +1,43 @@+import { Nullable } from '@univerjs/core';+import { createIdentifier, IDisposable } from '@wendellhu/redi';++export interface IImageRenderParam {+ unitId: string;+ subComponentId: string; //sheetId, pageId and so on, it has a default name in doc business+ imageId: string;+}++export interface IImageRenderService {+ dispose(): void;++ add(key: string, param: IImageRenderParam): void;++ remove(key: string): void;++ get(key: string): Nullable<IImageRenderParam>;+}++/**+ *+ */+export class ImageRenderService implements IDisposable, IImageRenderService {+ private _imageRenderInfo: Map<string, IImageRenderParam> = new Map();++ dispose(): void {+ this._imageRenderInfo.clear();+ }++ add(key: string, param: IImageRenderParam) {+ this._imageRenderInfo.set(key, param);+ }++ remove(key: string) {+ this._imageRenderInfo.delete(key);+ }++ get(key: string): Nullable<IImageRenderParam> {+ return this._imageRenderInfo.get(key);+ }+}++export const IImageRenderService = createIdentifier<IImageRenderService>('univer.plugin.image-render.service');diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.tsindex 536ff78584..d0892ade22 100644--- a/packages/core/src/Basics/Univer.ts+++ b/packages/core/src/Basics/Univer.ts@@ -7,6 +7,10 @@ import { CommandService, ICommandService } from '../services/command/command.serimport { ConfigService, IConfigService } from '../services/config/config.service';import { ContextService, IContextService } from '../services/context/context.service';import { ErrorService } from '../services/error/error.service';+import {+ FloatingObjectManagerService,+ IFloatingObjectManagerService,+} from '../services/floating-object/floating-object-manager.service';import { IUniverInstanceService, UniverInstanceService } from '../services/instance/instance.service';import { LifecycleStages } from '../services/lifecycle/lifecycle';import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';@@ -186,6 +190,7 @@ export class Univer {[IPermissionService, { useClass: DesktopPermissionService }],[IConfigService, { useClass: ConfigService }],[IContextService, { useClass: ContextService }],+ [IFloatingObjectManagerService, { useClass: FloatingObjectManagerService, lazy: true }],]);}diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.tsindex 6c955d74e3..24a6271954 100644--- a/packages/core/src/Docs/Domain/DocumentModel.ts+++ b/packages/core/src/Docs/Domain/DocumentModel.ts@@ -170,13 +170,13 @@ export class DocumentModelSimple {return;}- const { objectProperties } = drawing;+ const objectTransform = drawing.objectTransform;- objectProperties.size.width = width;- objectProperties.size.height = height;+ objectTransform.size.width = config.width;+ objectTransform.size.height = config.height;- objectProperties.positionH.posOffset = left;- objectProperties.positionV.posOffset = top;+ objectTransform.positionH.posOffset = config.left;+ objectTransform.positionV.posOffset = config.top;}setZoomRatio(zoomRatio: number = 1) {diff --git a/packages/core/src/Types/Interfaces/IDocumentData.ts b/packages/core/src/Types/Interfaces/IDocumentData.tsindex c3c5fe9cbe..24fdf54e1b 100644--- a/packages/core/src/Types/Interfaces/IDocumentData.ts+++ b/packages/core/src/Types/Interfaces/IDocumentData.ts@@ -1,7 +1,6 @@+import { ISize } from '../../services/floating-object/floating-object-interfaces';import { BooleanNumber, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../Enum';import { IExtraModelConfig } from './IExtraModelConfig';-import { IImageProperties } from './IImageProperties';-import { IShapeProperties } from './IShapeProperties';import { IColorStyle, IStyleBase } from './IStyleData';// 注意:所有的尺寸单位,若无特殊说明,都是指pt,1 pt = 1 / 72 in@@ -68,14 +67,6 @@ export interface IDocStyles {[styleId: string]: IDocStyle;}-/**- * A width and height.- */-export interface ISizeData {- width?: number;- height?: number;-}-/*** Properties of document body* 三种更新类型,范围叠加、范围互斥、占位符@@ -301,7 +292,7 @@ export interface IHeaderAndFooterBase {*/export interface IDocStyleBase extends IMargin {pageNumberStart?: number; // pageNumberStart- pageSize?: ISizeData; // pageSize+ pageSize?: ISize; // pageSizepageOrient?: PageOrientType;@@ -449,7 +440,7 @@ export interface IParagraph {// }// export interface ICustomElement {-// size: ISizeData;+// size: ISize;// }// /**@@ -490,7 +481,11 @@ export interface IBullet {export interface IDrawing {objectId: string;- objectProperties: IObjectProperties;+ title: string;+ description: string;+ // embeddedObjectBorder?: IDocsBorder;++ objectTransform: IObjectTransform;layoutType: PositionedObjectLayoutType;@@ -530,18 +525,15 @@ export enum PositionedObjectLayoutType {/*** Properties of a draw object*/-export interface IObjectProperties {- title: string;- description: string;- embeddedObjectBorder?: IDocsBorder;- size: ISizeData;+export interface IObjectTransform {+ size: ISize;positionH: ObjectPositionH;positionV: ObjectPositionV;angle: number;// Union field properties can be only one of the following:- shapeProperties?: IShapeProperties;- chartProperties?: IChartProperties;- imageProperties?: IImageProperties;+ // shapeProperties?: IShapeProperties;+ // chartProperties?: IChartProperties;+ // imageProperties?: IImageProperties;}/**diff --git a/packages/core/src/Types/Interfaces/ISlideData.ts b/packages/core/src/Types/Interfaces/ISlideData.tsindex 6ae15dcff4..e4b9e68be1 100644--- a/packages/core/src/Types/Interfaces/ISlideData.ts+++ b/packages/core/src/Types/Interfaces/ISlideData.ts@@ -1,41 +1,19 @@+import { ISize, ITransformState } from '../../services/floating-object/floating-object-interfaces';import { IKeyType, Nullable } from '../../Shared/Types';import { LocaleType, ThemeColorType } from '../Enum';import { ShapeType } from '../Enum/ShapeType';-import { ICustomBlock, IDocumentData, ILists, ISizeData } from './IDocumentData';+import { ICustomBlock, IDocumentData, ILists } from './IDocumentData';import { IImageProperties } from './IImageProperties';import { IPlaceholder } from './IPlaceholder';import { IShapeProperties } from './IShapeProperties';import { IColorStyle, IStyleBase, IStyleData } from './IStyleData';import { IWorksheetConfig } from './IWorksheetData';-export interface ISize {- width?: number;- height?: number;-}--export interface IScale {- scaleX?: number;- scaleY?: number;-}--export interface IOffset {- left?: number;- top?: number;-}--export interface ITransformState extends IOffset, ISize, IScale {- angle?: number;- skewX?: number;- skewY?: number;- flipX?: boolean;- flipY?: boolean;-}-export interface ISlideData extends IReferenceSource {id: string; // unit idlocale?: LocaleType;title: string;- pageSize: ISizeData;+ pageSize: ISize;body?: ISlidePageBody;}diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 88cbbb8eb8..681c3645f1 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -58,6 +58,14 @@ export { Worksheet } from './sheets/worksheet';// #endregion+export type { IOffset, IScale, ISize, ITransformState } from './services/floating-object/floating-object-interfaces';+export {+ DEFAULT_DOCUMENT_SUB_COMPONENT_ID,+ FloatingObjectManagerService,+ type IFloatingObjectManagerParam,+ type IFloatingObjectManagerSearchItemParam,+ IFloatingObjectManagerService,+} from './services/floating-object/floating-object-manager.service';export * from './Slides/Domain';export * from './Types/Const';export * from './Types/Enum';diff --git a/packages/core/src/services/floating-object/floating-object-interfaces.ts b/packages/core/src/services/floating-object/floating-object-interfaces.tsnew file mode 100644index 0000000000..87d13a6c3c--- /dev/null+++ b/packages/core/src/services/floating-object/floating-object-interfaces.ts@@ -0,0 +1,22 @@+export interface ISize {+ width?: number;+ height?: number;+}++export interface IScale {+ scaleX?: number;+ scaleY?: number;+}++export interface IOffset {+ left?: number;+ top?: number;+}++export interface ITransformState extends IOffset, ISize, IScale {+ angle?: number;+ skewX?: number;+ skewY?: number;+ flipX?: boolean;+ flipY?: boolean;+}diff --git a/packages/core/src/services/floating-object/floating-object-manager.service.ts b/packages/core/src/services/floating-object/floating-object-manager.service.tsnew file mode 100644index 0000000000..6796496f41--- /dev/null+++ b/packages/core/src/services/floating-object/floating-object-manager.service.ts@@ -0,0 +1,205 @@+import { createIdentifier, IDisposable } from '@wendellhu/redi';+import { Observable, Subject } from 'rxjs';++import { Nullable } from '../../common/type-utils';+import { ITransformState } from './floating-object-interfaces';++export const DEFAULT_DOCUMENT_SUB_COMPONENT_ID = '__default_document_sub_component_id20231101__';++export interface IFloatingObjectManagerSearchParam {+ unitId: string;+ subComponentId: string; //sheetId, pageId and so on, it has a default name in doc business+}++export interface IFloatingObjectManagerSearchItemParam extends IFloatingObjectManagerSearchParam {+ floatingObjectId: string;+}++export interface IFloatingObjectManagerParam extends IFloatingObjectManagerSearchItemParam {+ floatingObject: ITransformState;+}++export type FloatingObjects = Map<string, ITransformState>;++//{ [unitId: string]: { [sheetId: string]: ISelectionWithCoord[] } }+export type IFloatingObjectManagerInfo = Map<string, Map<string, FloatingObjects>>;++export interface IFloatingObjectManagerService {+ readonly remove$: Observable<IFloatingObjectManagerParam[]>;++ readonly andOrUpdate$: Observable<IFloatingObjectManagerParam[]>;++ readonly pluginUpdate$: Observable<IFloatingObjectManagerParam[]>;++ getFloatObject(searchItem: IFloatingObjectManagerSearchItemParam): Nullable<ITransformState>;++ getFloatObjects(search: IFloatingObjectManagerSearchParam): Nullable<FloatingObjects>;++ dispose(): void;++ clear(search: IFloatingObjectManagerSearchParam): void;++ addOrUpdate(insertParam: IFloatingObjectManagerParam): void;++ remove(searchItem: IFloatingObjectManagerSearchItemParam): void;++ BatchAddOrUpdate(insertParam: IFloatingObjectManagerParam[]): void;++ remove(searchItem: IFloatingObjectManagerSearchItemParam): void;++ pluginUpdateRefresh(searchObjects: IFloatingObjectManagerParam[]): void;+}++/**+ * This service is primarily used for the management of 'univer' floating objects,+ * decoupling common configurations such as position, volume,+ * and rotation of the floating objects from the core business.+ * This allows plugins to be reused across multiple core businesses.+ *+ * Floating elements in spreadsheets need to stay synchronized with the grid layout,+ * and inserting rows and columns will change their position;+ * Floating elements in documents need to stay synchronized with the text layout and can affect the text layout;+ * Floating elements in slides are more flexible but support settings such as animations.+ *+ * Please open the architecture diagram with TLDraw.+ * https://github.com/dream-num/univer/blob/db227563b4df65572dd4fceebecdbd9f27fa7a39/docs/selection%20architecture%20design.tldr+ */+export class FloatingObjectManagerService implements IDisposable, IFloatingObjectManagerService {+ private readonly _managerInfo: IFloatingObjectManagerInfo = new Map();++ /**+ * The deletion action is triggered and broadcasted within the core business plugin.+ * Upon receiving the deletion broadcast, the plugin executes the plugin command logic.+ */+ private readonly _remove$ = new Subject<IFloatingObjectManagerParam[]>();+ readonly remove$ = this._remove$.asObservable();++ /**+ * Addition and updates are also triggered and broadcasted within the core business plugin.+ * Upon receiving the update broadcast, the plugin updates the location of its business components.+ */+ private readonly _andOrUpdate$ = new Subject<IFloatingObjectManagerParam[]>();+ readonly andOrUpdate$ = this._andOrUpdate$.asObservable();++ /**+ * The position, width, and height of the plugin's business components can be changed by the user through interface operations.+ * Here, it is necessary to notify the core business plugin to update the relevant location model.+ * The logic converges in the core business plugin.+ */+ private readonly _pluginUpdate$ = new Subject<IFloatingObjectManagerParam[]>();+ readonly pluginUpdate$ = this._pluginUpdate$.asObservable();++ getFloatObject(searchItem: IFloatingObjectManagerSearchItemParam): Nullable<ITransformState> {+ return this._getFloatingObject(searchItem);+ }++ getFloatObjects(search: IFloatingObjectManagerSearchParam): Nullable<FloatingObjects> {+ return this._getFloatingObjects(search);+ }++ dispose(): void {+ this._remove$.complete();+ this._andOrUpdate$.complete();+ this._pluginUpdate$.complete();+ this._managerInfo.clear();+ }++ clear(search: IFloatingObjectManagerSearchParam): void {+ const searchObjects = this._clearByParam(search);+ this._remove$.next(searchObjects);+ }++ addOrUpdate(insertParam: IFloatingObjectManagerParam): void {+ const searchObjects = this._addByParam(insertParam);+ this._andOrUpdate$.next(searchObjects);+ }++ BatchAddOrUpdate(insertParams: IFloatingObjectManagerParam[]): void {+ const searchObjects: IFloatingObjectManagerParam[] = [];+ insertParams.forEach((insertParam) => {+ searchObjects.push(...this._addByParam(insertParam));+ });+ this._andOrUpdate$.next(searchObjects);+ }++ remove(searchItem: IFloatingObjectManagerSearchItemParam): void {+ const searchObjects = this._removeByParam(searchItem);+ this._remove$.next(searchObjects);+ }++ pluginUpdateRefresh(updateObjects: IFloatingObjectManagerParam[]) {+ this._pluginUpdate$.next(updateObjects);+ }++ private _getFloatingObjects(param: Nullable<IFloatingObjectManagerSearchParam>) {+ if (param == null) {+ return;+ }+ const { unitId, subComponentId } = param;+ return this._managerInfo.get(unitId)?.get(subComponentId);+ }++ private _getFloatingObject(param: Nullable<IFloatingObjectManagerSearchItemParam>) {+ if (param == null) {+ return;+ }+ const { unitId, subComponentId, floatingObjectId } = param;+ return this._managerInfo.get(unitId)?.get(subComponentId)?.get(floatingObjectId);+ }++ private _addByParam(insertParam: IFloatingObjectManagerParam): IFloatingObjectManagerParam[] {+ const { unitId, subComponentId, floatingObject, floatingObjectId } = insertParam;++ if (!this._managerInfo.has(unitId)) {+ this._managerInfo.set(unitId, new Map());+ }++ const subComponentData = this._managerInfo.get(unitId)!;++ if (!subComponentData.has(subComponentId)) {+ subComponentData.set(subComponentId, new Map());+ }++ subComponentData.get(subComponentId)!.set(floatingObjectId, floatingObject);++ return [{ unitId, subComponentId, floatingObjectId, floatingObject }];+ }++ private _clearByParam(param: IFloatingObjectManagerSearchParam): IFloatingObjectManagerParam[] {+ const floatingObjects = this._getFloatingObjects(param);++ const { unitId, subComponentId } = param;++ const refreshObjects: IFloatingObjectManagerParam[] = [];++ floatingObjects?.forEach((value, key) => {+ refreshObjects.push({+ unitId,+ subComponentId,+ floatingObjectId: key,+ floatingObject: value,+ });+ });++ floatingObjects?.clear();++ return refreshObjects;+ }++ private _removeByParam(param: IFloatingObjectManagerSearchItemParam): IFloatingObjectManagerParam[] {+ const floatingObjects = this._getFloatingObjects(param);+ const item = floatingObjects?.get(param.floatingObjectId);++ if (item == null) {+ return [];+ }++ floatingObjects?.delete(param.floatingObjectId);++ return [{ ...param, floatingObject: item }];+ }+}++export const IFloatingObjectManagerService = createIdentifier<IFloatingObjectManagerService>(+ 'univer.floating-object.service'+);diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 065b3e1267..81262cb627 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -95,6 +95,9 @@ importers:'@univerjs/common-plugin-data':specifier: workspace:*version: link:../../packages/common-plugin-data+ '@univerjs/common-plugin-image':+ specifier: workspace:*+ version: link:../../packages/common-plugin-image'@univerjs/core':specifier: workspace:*version: link:../../packages/core@@ -165,6 +168,9 @@ importers:'@univerjs/common-plugin-data':specifier: workspace:*version: link:../../packages/common-plugin-data+ '@univerjs/common-plugin-image':+ specifier: workspace:*+ version: link:../../packages/common-plugin-image'@univerjs/core':specifier: workspace:*version: link:../../packages/core@@ -626,6 +632,46 @@ importers:specifier: ^0.34.6version: 0.34.6([email protected])([email protected])+ packages/common-plugin-image:+ dependencies:+ '@univerjs/base-render':+ specifier: workspace:*+ version: link:../base-render+ '@univerjs/base-sheets':+ specifier: workspace:*+ version: link:../base-sheets+ '@univerjs/base-ui':+ specifier: workspace:*+ version: link:../base-ui+ '@univerjs/core':+ specifier: workspace:*+ version: link:../core+ '@wendellhu/redi':+ specifier: ^0.12.10+ version: 0.12.10+ rxjs:+ specifier: ^7.8.1+ version: 7.8.1+ devDependencies:+ '@types/node':+ specifier: ^20.8.9+ version: 20.8.9+ '@vitest/coverage-v8':+ specifier: ^0.34.6+ version: 0.34.6([email protected])+ esbuild:+ specifier: ^0.19.5+ version: 0.19.5+ less:+ specifier: ^4.2.0+ version: 4.2.0+ ts-node:+ specifier: ^10.9.1+ version: 10.9.1(@types/[email protected])([email protected])+ vitest:+ specifier: ^0.34.6+ version: 0.34.6([email protected])([email protected])+packages/core:dependencies:'@wendellhu/redi':