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(sheets-ui): support canvas float dom (#2343)
zhangw1f95047410ec
diff --git a/packages/core/src/services/drawing/drawing-manager.service.ts b/packages/core/src/services/drawing/drawing-manager.service.tsindex 0d1c947a96..2871ae3427 100644--- a/packages/core/src/services/drawing/drawing-manager.service.ts+++ b/packages/core/src/services/drawing/drawing-manager.service.ts@@ -39,6 +39,7 @@ export enum DrawingTypeEnum {DRAWING_VIDEO = 5,DRAWING_GROUP = 6,DRAWING_UNIT = 7,+ DRAWING_DOM = 8,}export type DrawingType = DrawingTypeEnum | number;diff --git a/packages/debugger/package.json b/packages/debugger/package.jsonindex 11e0de2757..b2fec10fa4 100644--- a/packages/debugger/package.json+++ b/packages/debugger/package.json@@ -58,6 +58,7 @@"@univerjs/design": "workspace:*","@univerjs/docs-ui": "workspace:*","@univerjs/sheets": "workspace:*",+ "@univerjs/sheets-drawing-ui": "workspace:*","@univerjs/ui": "workspace:*","@wendellhu/redi": "0.15.2","react": "^16.9.0 || ^17.0.0 || ^18.0.0",@@ -71,6 +72,7 @@"@univerjs/docs-ui": "workspace:*","@univerjs/shared": "workspace:*","@univerjs/sheets": "workspace:*",+ "@univerjs/sheets-drawing-ui": "workspace:*","@univerjs/ui": "workspace:*","@vitejs/plugin-vue": "^5.0.4","@wendellhu/redi": "0.15.2",diff --git a/packages/debugger/src/commands/commands/float-dom.command.ts b/packages/debugger/src/commands/commands/float-dom.command.tsnew file mode 100644index 0000000000..0e5ad6e791--- /dev/null+++ b/packages/debugger/src/commands/commands/float-dom.command.ts@@ -0,0 +1,38 @@+/**+ * 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 } from '@univerjs/core';+import { CommandType } from '@univerjs/core';+import { SheetCanvasFloatDomManagerService } from '@univerjs/sheets-drawing-ui';++export const CreateFloatDomCommand: ICommand = {+ id: 'debugger.command.create-float-dom',+ type: CommandType.COMMAND,+ handler: (accessor) => {+ const floatDomService = accessor.get(SheetCanvasFloatDomManagerService);+ floatDomService.addFloatDomToPosition({+ allowTransform: true,+ initPosition: {+ startX: 200,+ endX: 400,+ startY: 200,+ endY: 400,+ },+ componentKey: 'ImageDemo',+ });+ return true;+ },+};diff --git a/packages/debugger/src/components/Image.tsx b/packages/debugger/src/components/Image.tsxnew file mode 100644index 0000000000..8117408098--- /dev/null+++ b/packages/debugger/src/components/Image.tsx@@ -0,0 +1,23 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import React from 'react';++const image = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxITEBUSExMWFhIVFhIXEhYYFRUWGBYYFRUWFhUWGBUYHyghGB4lGxYVJDEhJSktLi4uGh8zODMsNyktLisBCgoKDg0OGxAQGysgHSYrLS03Ky4tKzctKy8tNysvLS83LS0tLS0rLS0rLS0tLS0vLTItLTc1LS0tLS0tNS0tLf/AABEIASsAqAMBIgACEQEDEQH/xAAcAAEAAgMBAQEAAAAAAAAAAAAABQYDBAc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0QctD/FCU+Cur7XdttjhVSqvBmqOR7vdT7Gu1yedULbSV/mYqmfQ4atvmVTaKg731xcrW4ducLcd+7f5k50Ljh542mq8koKSajJNqcl3YtrZK9nvs7W5k15HYnDC15DkeMxaUqGHqOD4VJWp0/VSnbUv5UzovR34bRi1PGTVSX/qhdQ/qk7OXpsvU3aeZS/eNmnjW+f1K75b2+pNa1haqajFJKySSSSskkuCS5HrWvErcMV5meGIM/St6k7rXiNa8SIjWM0apGk9SS1C5oxqGSMhpO22DFBsEJZQAAAAAAAeJxNLGYWrKLUZpX8USACNOLZh8GcTVnKTxsNLlJpdQ7rU2+OsUfgRH8eLk3/DCMV9ztIJ2acZr/Aqnb9XiZRkuDcVJfNNmrH4KYtNacXR2d0+pkmvPaR3ADZpTsH0PqRilKtdpK9o8fqb8OjNv+R+xYgT1SjohC08gS/G/Y2KeUQXFtkkCNynphrQwMFyMypR8EewQnTzoXgfbH0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//2Q==';++export const ImageDemo = () => {+ return <img src={image} style={{ width: '100%', height: '100%' }} />;+};diff --git a/packages/debugger/src/controllers/debugger.controller.ts b/packages/debugger/src/controllers/debugger.controller.tsindex b629a4f8f4..65d17b8294 100644--- a/packages/debugger/src/controllers/debugger.controller.ts+++ b/packages/debugger/src/controllers/debugger.controller.ts@@ -35,13 +35,17 @@ import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-import VueI18nIcon from '../components/VueI18nIcon.vue';import { CreateEmptySheetCommand, DisposeCurrentUnitCommand } from '../commands/commands/unit.command';+import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';+import { ImageDemo } from '../components/Image';import { ChangeUserCommand } from '../commands/operations/change-user.operation';import {ChangeUserMenuItemFactory,ConfirmMenuItemFactory,CreateEmptySheetMenuItemFactory,+ CreateFloatDOMMenuItemFactory,DialogMenuItemFactory,DisposeCurrentUnitMenuItemFactory,+ FloatDomMenuItemFactory,LocaleMenuItemFactory,MessageMenuItemFactory,NotificationMenuItemFactory,@@ -86,6 +90,7 @@ export class DebuggerController extends Disposable {SaveSnapshotOptions,DisposeCurrentUnitCommand,CreateEmptySheetCommand,+ CreateFloatDomCommand,ChangeUserCommand,].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));@@ -109,6 +114,8 @@ export class DebuggerController extends Disposable {UnitMenuItemFactory,DisposeCurrentUnitMenuItemFactory,CreateEmptySheetMenuItemFactory,+ FloatDomMenuItemFactory,+ CreateFloatDOMMenuItemFactory,ChangeUserMenuItemFactory,] as IMenuItemFactory[]).forEach((factory) => {this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));@@ -121,5 +128,6 @@ export class DebuggerController extends Disposable {this.disposeWithMe(componentManager.register('VueI18nIcon', VueI18nIcon, {framework: 'vue3',}));+ this.disposeWithMe(componentManager.register('ImageDemo', ImageDemo));}}diff --git a/packages/debugger/src/controllers/menu.ts b/packages/debugger/src/controllers/menu.tsindex a29f9be5d3..dff3e9a26d 100644--- a/packages/debugger/src/controllers/menu.ts+++ b/packages/debugger/src/controllers/menu.ts@@ -30,6 +30,7 @@ import { SetEditable } from '../commands/operations/set.editable.operation';import { SidebarOperation } from '../commands/operations/sidebar.operation';import { ThemeOperation } from '../commands/operations/theme.operation';import { CreateEmptySheetCommand, DisposeCurrentUnitCommand } from '../commands/commands/unit.command';+import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';import { ChangeUserCommand, UnitRole } from '../commands/operations/change-user.operation';export function LocaleMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {@@ -253,6 +254,28 @@ export function CreateEmptySheetMenuItemFactory(accessor: IAccessor): IMenuButto};}+const FLOAT_DOM_ITEM_MENU_ID = 'debugger.float-dom-menu-item';++export function FloatDomMenuItemFactory(): IMenuSelectorItem {+ return {+ id: FLOAT_DOM_ITEM_MENU_ID,+ title: 'FloatDom',+ tooltip: 'Float Dom Commands',+ type: MenuItemType.SUBITEMS,+ positions: [MenuPosition.TOOLBAR_OTHERS],+ };+}++export function CreateFloatDOMMenuItemFactory(): IMenuButtonItem {+ return {+ id: CreateFloatDomCommand.id,+ title: 'Create Float Dom',+ tooltip: 'Create Float Dom',+ icon: 'DS',+ type: MenuItemType.BUTTON,+ positions: [FLOAT_DOM_ITEM_MENU_ID],+ };+}export function ChangeUserMenuItemFactory(): IMenuSelectorItem {return {id: ChangeUserCommand.id,diff --git a/packages/sheets-drawing-ui/src/index.ts b/packages/sheets-drawing-ui/src/index.tsindex b5a0215d86..ee62c93fff 100644--- a/packages/sheets-drawing-ui/src/index.ts+++ b/packages/sheets-drawing-ui/src/index.ts@@ -15,3 +15,4 @@*/export { UniverSheetsDrawingUIPlugin } from './plugin';+export { SheetCanvasFloatDomManagerService, type ICanvasFloatDom } from './services/canvas-float-dom-manager.service';diff --git a/packages/sheets-drawing-ui/src/plugin.ts b/packages/sheets-drawing-ui/src/plugin.tsindex ccdc272135..4b3821cec9 100644--- a/packages/sheets-drawing-ui/src/plugin.ts+++ b/packages/sheets-drawing-ui/src/plugin.ts@@ -22,6 +22,7 @@ import { SheetDrawingUpdateController } from './controllers/sheet-drawing-updateimport type { IUniverSheetsDrawingConfig } from './controllers/sheet-drawing.controller';import { DefaultSheetsDrawingConfig, SheetDrawingUIController } from './controllers/sheet-drawing.controller';import { SheetDrawingTransformAffectedController } from './controllers/sheet-drawing-transform-affected.controller';+import { SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';const PLUGIN_NAME = 'SHEETS_IMAGE_UI_PLUGIN';@@ -50,7 +51,7 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {const dependencies: Dependency[] = [// services-+ [SheetCanvasFloatDomManagerService],// controllers[SheetDrawingUIController,diff --git a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.tsnew file mode 100644index 0000000000..5780c8c110--- /dev/null+++ b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts@@ -0,0 +1,493 @@+/**+ * 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 { IPosition, ITransformState, Nullable, Worksheet } from '@univerjs/core';+import { Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IDrawingManagerService, IUniverInstanceService, Tools } from '@univerjs/core';+import type { BaseObject, IBoundRectNoAngle, IRectProps, IRender, Scene, SpreadsheetSkeleton } from '@univerjs/engine-render';+import { DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Rect } from '@univerjs/engine-render';+import type { IFloatDomData, ISetFrozenMutationParams, ISheetDrawingPosition, ISheetFloatDom } from '@univerjs/sheets';+import { DrawingApplyType, getSheetCommandTarget, ISheetDrawingService, SetDrawingApplyMutation, SetFrozenMutation } from '@univerjs/sheets';+import type { IFloatDomLayout } from '@univerjs/ui';+import { CanvasFloatDomService } from '@univerjs/ui';+import type { IDisposable } from '@wendellhu/redi';+import { Inject } from '@wendellhu/redi';+import { BehaviorSubject, Subject } from 'rxjs';+import type { IDrawingJsonUndo1 } from '@univerjs/drawing';+import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';+import { ISelectionRenderService, SetScrollOperation, SetZoomRatioOperation, SheetSkeletonManagerService, VIEWPORT_KEY } from '@univerjs/sheets-ui';+import { InsertSheetDrawingCommand } from '../commands/commands/insert-sheet-drawing.command';+import type { IInsertDrawingCommandParams } from '../commands/commands/interfaces';++export interface ICanvasFloatDom {+ allowTransform: boolean;+ initPosition: IPosition;+ componentKey: string;+ unitId?: string;+ subUnitId?: string;+}++interface ICanvasFloatDomInfo {+ position$: BehaviorSubject<IFloatDomLayout>;+ dispose: IDisposable;+ rect: Rect;+ unitId: string;+ subUnitId: string;+}++export function transformBound2DOMBound(originBound: IBoundRectNoAngle, scene: Scene, skeleton: SpreadsheetSkeleton, worksheet: Worksheet) {+ const { scaleX, scaleY } = scene.getAncestorScale();+ const viewMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);+ const absolute = {+ left: true,+ top: true,+ };++ if (!viewMain) {+ return {+ ...originBound,+ absolute,+ };+ }+ const { left, right, top, bottom } = originBound;+ const freeze = worksheet.getFreeze();+ const { startColumn, startRow, xSplit, ySplit } = freeze;+ // freeze start+ const startSheetView = skeleton.getNoMergeCellPositionByIndexWithNoHeader(startRow - ySplit, startColumn - xSplit);+ // freeze end+ const endSheetView = skeleton.getNoMergeCellPositionByIndexWithNoHeader(startRow, startColumn);+ const { rowHeaderWidth, columnHeaderHeight } = skeleton;+ const freezeWidth = endSheetView.startX - startSheetView.startX;+ const freezeHeight = endSheetView.startY - startSheetView.startY;++ const { top: freezeTop, left: freezeLeft, viewportScrollX: actualScrollX, viewportScrollY: actualScrollY } = viewMain;+ let offsetLeft: number;+ let offsetRight: number;++ // viewMain or viewTop+ if (left < freezeLeft) {+ absolute.left = true;+ offsetLeft = ((freezeWidth + rowHeaderWidth) + (left - freezeLeft)) * scaleX;+ offsetRight = Math.max(+ Math.min(+ ((freezeWidth + rowHeaderWidth) + (right - freezeLeft)) * scaleX,+ (freezeWidth + rowHeaderWidth) * scaleX+ ),+ (right - actualScrollX) * scaleX);+ } else {+ absolute.left = false;+ offsetLeft = Math.max((left - actualScrollX) * scaleX, (freezeWidth + rowHeaderWidth) * scaleX);+ offsetRight = Math.max((right - actualScrollX) * scaleX, (freezeWidth + rowHeaderWidth) * scaleX);+ }++ let offsetTop: number;+ let offsetBottom: number;+ // viewMain or viewTop+ if (top < freezeTop) {+ absolute.top = true;+ offsetTop = ((freezeHeight + columnHeaderHeight) + (top - freezeTop)) * scaleY;+ offsetBottom = Math.max(+ Math.min(+ ((freezeHeight + columnHeaderHeight) + (right - freezeTop)) * scaleY,+ (freezeHeight + columnHeaderHeight) * scaleY+ ),+ (bottom - actualScrollY) * scaleY+ );+ } else {+ absolute.top = false;+ offsetTop = Math.max((top - actualScrollY) * scaleY, (freezeHeight + columnHeaderHeight) * scaleY);+ offsetBottom = Math.max((bottom - actualScrollY) * scaleY, (freezeHeight + columnHeaderHeight) * scaleY);+ }++ return {+ left: offsetLeft,+ right: offsetRight,+ top: offsetTop,+ bottom: offsetBottom,+ absolute,+ };+}++const calcPosition = (+ targetObject: BaseObject,+ currentRender: IRender,+ skeleton: SpreadsheetSkeleton,+ worksheet: Worksheet+): IFloatDomLayout => {+ const { scene } = currentRender;+ const { left, top, width, height, angle } = targetObject;++ const bound: IBoundRectNoAngle = {+ left,+ right: left + width,+ top,+ bottom: top + height,+ };++ const offsetBound = transformBound2DOMBound(bound, scene, skeleton, worksheet);+ return {+ startX: offsetBound.left,+ endX: offsetBound.right,+ startY: offsetBound.top,+ endY: offsetBound.bottom,+ rotate: angle,+ width,+ height,+ absolute: offsetBound.absolute,+ };+};++export class SheetCanvasFloatDomManagerService extends Disposable {+ private _domLayerMap: Map<string, Map<string, Map<string, ICanvasFloatDom>>> = new Map();+ private _domLayerInfoMap: Map<string, ICanvasFloatDomInfo> = new Map();++ private _transformChange$ = new Subject<{ id: string; value: ITransformState }>();+ transformChange$ = this._transformChange$.asObservable();++ private _remove$ = new Subject<{ unitId: string; subUnitId: string; id: string }>();+ remove$ = this._remove$.asObservable();++ constructor(+ @Inject(IRenderManagerService) private _renderManagerService: IRenderManagerService,+ @IUniverInstanceService private _univerInstanceService: IUniverInstanceService,+ @Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService,+ @Inject(ICommandService) private _commandService: ICommandService,+ @IDrawingManagerService private _drawingManagerService: IDrawingManagerService,+ @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,+ @Inject(CanvasFloatDomService) private readonly _canvasFloatDomService: CanvasFloatDomService,+ @ISheetDrawingService private readonly _sheetDrawingService: ISheetDrawingService+ ) {+ super();+ this._drawingAddListener();+ this._scrollUpdateListener();+ this._featureUpdateListener();+ this._deleteListener();+ }++ private _ensureMap(unitId: string, subUnitId: string) {+ let unitMap = this._domLayerMap.get(unitId);+ if (!unitMap) {+ unitMap = new Map();+ this._domLayerMap.set(unitId, unitMap);+ }++ let subUnitMap = unitMap.get(subUnitId);+ if (!subUnitMap) {+ subUnitMap = new Map();+ unitMap.set(subUnitId, subUnitMap);+ }++ return subUnitMap;+ }++ private _getSceneAndTransformerByDrawingSearch(unitId: Nullable<string>) {+ if (unitId == null) {+ return;+ }++ const renderObject = this._renderManagerService.getRenderById(unitId);++ const scene = renderObject?.scene;++ if (renderObject == null || scene == null) {+ return null;+ }++ const transformer = scene.getTransformerByCreate();+ const canvas = renderObject.engine.getCanvasElement();++ return { scene, transformer, renderObject, canvas };+ }++ // eslint-disable-next-line max-lines-per-function+ private _drawingAddListener() {+ this.disposeWithMe(+ // eslint-disable-next-line max-lines-per-function+ this._drawingManagerService.add$.subscribe((params) => {+ // eslint-disable-next-line max-lines-per-function+ (params).forEach((param) => {+ const { unitId, subUnitId, drawingId } = param;+ const target = getSheetCommandTarget(this._univerInstanceService, { unitId, subUnitId });+ const floatDomParam = this._drawingManagerService.getDrawingByParam(param) as IFloatDomData;+ const skeleton = this._sheetSkeletonManagerService.getUnitSkeleton(unitId, subUnitId);+ if (floatDomParam == null || target == null || skeleton == null) {+ return;+ }++ const { transform, drawingType } = floatDomParam;++ if (drawingType !== DrawingTypeEnum.DRAWING_DOM) {+ return;+ }++ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);++ if (renderObject == null) {+ return;+ }+ const { scene, canvas } = renderObject;++ if (transform == null) {+ return true;+ }++ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;++ const rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });++ const rectShape = scene.getObject(rectShapeKey);++ if (rectShape != null) {+ rectShape.transformByState({ left, top, width, height, angle, flipX, flipY, skewX, skewY });+ return;+ }++ const imageConfig: IRectProps = {+ left,+ top,+ width,+ height,+ zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1,+ };++ const rect = new Rect(rectShapeKey, imageConfig);++ scene.addObject(rect, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(rect);++ const disposableCollection = new DisposableCollection();+ const initPosition = calcPosition(rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);+ const position$ = new BehaviorSubject<IFloatDomLayout>(initPosition);++ const info: ICanvasFloatDomInfo = {+ dispose: disposableCollection,+ rect,+ position$,+ unitId,+ subUnitId,+ };+ this._canvasFloatDomService.addFloatDom({+ position$,+ id: drawingId,+ componentKey: floatDomParam.componentKey,+ onPointerDown: (evt) => {+ canvas.dispatchEvent(new PointerEvent(evt.type, evt));+ },+ onPointerMove: (evt: PointerEvent | MouseEvent) => {+ canvas.dispatchEvent(new PointerEvent(evt.type, evt));+ },+ onPointerUp: (evt: PointerEvent | MouseEvent) => {+ canvas.dispatchEvent(new PointerEvent(evt.type, evt));+ },+ onWheel: (evt: WheelEvent) => {+ canvas.dispatchEvent(new WheelEvent(evt.type, evt));+ },+ });++ const listener = rect.onTransformChangeObservable.add(() => {+ const newPosition = calcPosition(rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);+ position$.next(+ newPosition+ );+ });++ disposableCollection.add(() => {+ this._canvasFloatDomService.removeFloatDom(drawingId);+ });+ listener && disposableCollection.add(listener);+ this._domLayerInfoMap.set(drawingId, info);+ });+ })+ );+ }++ private _scrollUpdateListener() {+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {+ const updateSheet = (unitId: string, subUnitId: string) => {+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);+ const map = this._ensureMap(unitId, subUnitId);+ const ids = Array.from(map.keys());+ const target = getSheetCommandTarget(this._univerInstanceService, { unitId, subUnitId });+ const skeleton = this._sheetSkeletonManagerService.getUnitSkeleton(unitId, subUnitId);+ if (!renderObject || !target || !skeleton) {+ return;+ }+ ids.forEach((id) => {+ const info = this._domLayerInfoMap.get(id);+ if (info) {+ const position = calcPosition(info.rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);+ info.position$.next(position);+ }+ });+ };+ if (commandInfo.id === SetScrollOperation.id) {+ const params = (commandInfo.params) as any;+ const { unitId, sheetId } = params;+ updateSheet(unitId, sheetId);+ } else if (commandInfo.id === SetZoomRatioOperation.id) {+ const params = (commandInfo.params) as any;+ const { unitId } = params;+ const subUnitIds = Array.from(this._domLayerMap.get(unitId)?.keys() ?? []);+ subUnitIds.forEach((subUnitId) => {+ updateSheet(unitId, subUnitId);+ });+ } else if (commandInfo.id === SetFrozenMutation.id) {+ const { unitId, subUnitId } = commandInfo.params as ISetFrozenMutationParams;+ updateSheet(unitId, subUnitId);+ }+ }));+ }++ private _getPosition(position: IPosition): Nullable<ISheetDrawingPosition> {+ const { startX, endX, startY, endY } = position;++ const start = this._selectionRenderService.getSelectionCellByPosition(startX, startY);+ if (start == null) {+ return;+ }++ const from = {+ column: start.actualColumn,+ columnOffset: startX - start.startX,+ row: start.actualRow,+ rowOffset: startY - start.startY,+ };++ const end = this._selectionRenderService.getSelectionCellByPosition(endX, endY);++ if (end == null) {+ return;+ }++ const to = {+ column: end.actualColumn,+ columnOffset: endX - end.startX,+ row: end.actualRow,+ rowOffset: endY - end.startY,+ };++ return {+ from,+ to,+ };+ }++ private _featureUpdateListener() {+ this.disposeWithMe(+ this._drawingManagerService.update$.subscribe((params) => {+ (params).forEach((data) => {+ const sheetDrawing = this._drawingManagerService.getDrawingByParam(data);++ if (!sheetDrawing) {+ return;+ }++ if (sheetDrawing.drawingType !== DrawingTypeEnum.DRAWING_DOM) {+ return;+ }++ const newValue = {+ ...sheetDrawing.transform,+ };+ this._transformChange$.next({ id: data.drawingId, value: newValue });+ });+ })+ );+ }++ private _deleteListener() {+ this.disposeWithMe(+ this._drawingManagerService.remove$.subscribe((params) => {+ params.forEach((param) => {+ this._removeDom(param.drawingId);+ });+ })+ );+ }++ addFloatDomToPosition(layer: ICanvasFloatDom) {+ const target = getSheetCommandTarget(this._univerInstanceService, {+ unitId: layer.unitId,+ subUnitId: layer.subUnitId,+ });+ if (!target) {+ throw new Error('cannot find current target!');+ }++ const { unitId, subUnitId } = target;+ const { initPosition, componentKey } = layer;+ const id = Tools.generateRandomId();++ const sheetTransform = this._getPosition(initPosition);+ if (sheetTransform == null) {+ return;+ }++ const sheetDrawingParam: ISheetFloatDom = {+ unitId,+ subUnitId,+ drawingId: id,+ drawingType: DrawingTypeEnum.DRAWING_DOM,+ componentKey,+ sheetTransform,+ transform: {+ left: initPosition.startX,+ top: initPosition.startY,+ width: initPosition.endX - initPosition.startX,+ height: initPosition.endY - initPosition.startY,+ },+ };++ this._commandService.executeCommand(InsertSheetDrawingCommand.id, {+ unitId,+ drawings: [sheetDrawingParam],+ } as IInsertDrawingCommandParams);+ const map = this._ensureMap(unitId, subUnitId);+ map.set(id, layer);++ return {+ id,+ dispose: () => {+ this._removeDom(id, true);+ },+ };+ }++ private _removeDom(id: string, removeDrawing = false) {+ const info = this._domLayerInfoMap.get(id);+ if (!info) {+ return;+ }+ const { unitId, subUnitId } = info;+ const map = this._ensureMap(unitId, subUnitId);+ this._domLayerInfoMap.delete(id);+ map.delete(id);+ info.dispose.dispose();+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);+ if (renderObject) {+ renderObject.scene.removeObject(info.rect);+ }++ if (removeDrawing) {+ const param = this._drawingManagerService.getDrawingByParam({ unitId, subUnitId, drawingId: id });+ if (!param) {+ return;+ }+ const jsonOp = this._sheetDrawingService.getBatchRemoveOp([param]) as IDrawingJsonUndo1;++ const { redo, objects } = jsonOp;+ this._commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.REMOVE });+ }+ }+}diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.tsindex 7a4261b682..c83f6f595d 100644--- a/packages/sheets/src/index.ts+++ b/packages/sheets/src/index.ts@@ -304,6 +304,8 @@ export { SetDefinedNameCommand, type ISetDefinedNameCommandParams } from './commexport { ScrollToCellOperation } from './commands/operations/scroll-to-cell.operation';export type { FormatType } from './services/numfmt/type';export { getMoveRangeUndoRedoMutations } from './commands/commands/move-range.command';+export { type ISheetDrawing, type ISheetUpdateDrawing, type ISheetDrawingPosition, ISheetDrawingService, SheetDrawingAnchorType, type ISheetDrawingBase, type IFloatDomData, type ISheetFloatDom } from './services/sheet-drawing.service';+export { SetDrawingApplyMutation, type ISetDrawingApplyMutationParams, DrawingApplyType } from './commands/mutations/set-drawing-apply.mutation';// permissionexport { defaultWorksheetPermissionPoint, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel } from './services/permission';@@ -376,5 +378,3 @@ export {export { RangeProtectionPermissionEditPoint } from './services/permission/permission-point/range/edit';export { RangeProtectionPermissionViewPoint } from './services/permission/permission-point/range/view';-export { type ISheetDrawing, type ISheetUpdateDrawing, type ISheetDrawingPosition, ISheetDrawingService, SheetDrawingAnchorType, type ISheetDrawingBase } from './services/sheet-drawing.service';-export { SetDrawingApplyMutation, type ISetDrawingApplyMutationParams, DrawingApplyType } from './commands/mutations/set-drawing-apply.mutation';diff --git a/packages/sheets/src/services/sheet-drawing.service.ts b/packages/sheets/src/services/sheet-drawing.service.tsindex 835bdba83f..65bbcf2ccd 100644--- a/packages/sheets/src/services/sheet-drawing.service.ts+++ b/packages/sheets/src/services/sheet-drawing.service.ts@@ -52,7 +52,13 @@ export interface ISheetShape extends IDrawingParam, ISheetDrawingBase {}-export type ISheetDrawing = ISheetImage | ISheetShape;+export interface IFloatDomData extends IDrawingParam {+ componentKey: string;+}++export interface ISheetFloatDom extends IFloatDomData, ISheetDrawingBase {}++export type ISheetDrawing = ISheetImage | ISheetShape | ISheetFloatDom;type OptionalField<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;export type ISheetUpdateDrawing = OptionalField<ISheetImage | ISheetShape, 'sheetTransform'>;diff --git a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx b/packages/ui/src/controllers/ui/ui-desktop.controller.tsxindex e49dc93ba3..825214e905 100644--- a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx+++ b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx@@ -25,6 +25,9 @@ import { delay, filter, take } from 'rxjs';import { ILayoutService } from '../../services/layout/layout.service';import { App } from '../../views/App';+import { BuiltInUIPart, IUIPartsService } from '../../services/parts/parts.service';+import { CanvasPopup } from '../../views/components/popup/CanvasPopup';+import { FloatDom } from '../../views/components/dom/FloatDom';import type { IWorkbenchOptions } from './ui.controller';const STEADY_TIMEOUT = 3000;@@ -35,9 +38,11 @@ export class DesktopUIController extends Disposable {@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,@Inject(Injector) private readonly _injector: Injector,@Inject(LifecycleService) private readonly _lifecycleService: LifecycleService,+ @IUIPartsService private readonly _uiPartsService: IUIPartsService,@Optional(ILayoutService) private readonly _layoutService?: ILayoutService) {super();+ this._initBuiltinComponents();}bootstrapWorkbench(options: IWorkbenchOptions): void {@@ -70,6 +75,11 @@ export class DesktopUIController extends Disposable {}));}++ private _initBuiltinComponents() {+ this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(CanvasPopup, this._injector)));+ this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(FloatDom, this._injector)));+ }}function bootstrap(diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.tsindex 9d70e677a2..4cb326bec6 100644--- a/packages/ui/src/index.ts+++ b/packages/ui/src/index.ts@@ -102,5 +102,7 @@ export { ContextMenu } from './views/components/context-menu/ContextMenu';export { Sidebar } from './views/components/sidebar/Sidebar';export { ZenZone } from './views/components/zen-zone/ZenZone';export { CanvasPopup } from './views/components/popup/CanvasPopup';+export { CanvasFloatDomService, type IFloatDomLayout } from './services/dom/canvas-dom-layer.service';// #endregion+diff --git a/packages/ui/src/services/dom/canvas-dom-layer.service.ts b/packages/ui/src/services/dom/canvas-dom-layer.service.tsnew file mode 100644index 0000000000..721836f7d8--- /dev/null+++ b/packages/ui/src/services/dom/canvas-dom-layer.service.ts@@ -0,0 +1,69 @@+/**+ * 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 { IPosition } from '@univerjs/core';+import { BehaviorSubject, type Observable } from 'rxjs';++export interface IFloatDomLayout extends IPosition {+ rotate: number;+ width: number;+ height: number;+ absolute: {+ left: boolean;+ top: boolean;+ };+}++export interface IFloatDom {+ position$: Observable<IFloatDomLayout>;+ id: string;+ componentKey: string | React.ComponentType;+ onPointerMove: (evt: PointerEvent | MouseEvent) => void;+ onPointerDown: (evt: PointerEvent | MouseEvent) => void;+ onPointerUp: (evt: PointerEvent | MouseEvent) => void;+ onWheel: (evt: WheelEvent) => void;+}++export class CanvasFloatDomService {+ private _domLayerMap = new Map<string, IFloatDom>();+ private _domLayers$ = new BehaviorSubject<[string, IFloatDom][]>([]);++ domLayers$ = this._domLayers$.asObservable();++ get domLayers() {+ return Array.from(this._domLayerMap.entries());+ }++ private _notice() {+ this._domLayers$.next(Array.from(this._domLayerMap.entries()));+ }++ addFloatDom(item: IFloatDom) {+ this._domLayerMap.set(item.id, item);+ this._notice();+ }++ removeFloatDom(id: string): void {+ if (this._domLayerMap.delete(id)) {+ this._notice();+ }+ }++ removeAll(): void {+ this._domLayerMap.clear();+ this._notice();+ }+}diff --git a/packages/ui/src/ui-plugin.ts b/packages/ui/src/ui-plugin.tsindex ecb36d6f42..01a341c39c 100644--- a/packages/ui/src/ui-plugin.ts+++ b/packages/ui/src/ui-plugin.ts@@ -54,6 +54,7 @@ import { EditorService, IEditorService } from './services/editor/editor.service'import { IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';import { IProgressService, ProgressService } from './services/progress/progress.service';import { IUIPartsService, UIPartsService } from './services/parts/parts.service';+import { CanvasFloatDomService } from './services/dom/canvas-dom-layer.service';const PLUGIN_NAME = 'ui';@@ -118,7 +119,7 @@ export class UniverUIPlugin extends Plugin {[IRangeSelectorService, { useClass: RangeSelectorService }],[ICanvasPopupService, { useClass: CanvasPopupService }],[IProgressService, { useClass: ProgressService }],-+ [CanvasFloatDomService],// controllers[IUIController, { useClass: DesktopUIController }],[diff --git a/packages/ui/src/views/App.tsx b/packages/ui/src/views/App.tsxindex c125ff1e7f..de49e2d40b 100644--- a/packages/ui/src/views/App.tsx+++ b/packages/ui/src/views/App.tsx@@ -27,7 +27,6 @@ import { ComponentContainer } from './components/ComponentContainer';import { Toolbar } from './components/doc-bars/Toolbar';import { Sidebar } from './components/sidebar/Sidebar';import { ZenZone } from './components/zen-zone/ZenZone';-import { CanvasPopup } from './components/popup/CanvasPopup';import { builtInGlobalComponents } from './parts';import { ContextMenu } from './components/context-menu/ContextMenu';@@ -63,7 +62,7 @@ export function App(props: IUniverAppProps) {return () => {updateSubscription.unsubscribe();};- // eslint-disable-next-line react-hooks/exhaustive-deps+ // eslint-disable-next-line react-hooks/exhaustive-deps}, []);const { headerComponents, contentComponents, footerComponents, headerMenuComponents, leftSidebarComponents, globalComponents } = useMemo(() => ({@@ -73,14 +72,14 @@ export function App(props: IUniverAppProps) {headerMenuComponents: uiPartsService.getComponents(BuiltInUIPart.HEADER_MENU),leftSidebarComponents: uiPartsService.getComponents(BuiltInUIPart.LEFT_SIDEBAR),globalComponents: uiPartsService.getComponents(BuiltInUIPart.GLOBAL),- // eslint-disable-next-line react-hooks/exhaustive-deps+ // eslint-disable-next-line react-hooks/exhaustive-deps}), [updateTrigger]);useEffect(() => {if (!themeService.getCurrentTheme()) {themeService.setTheme(defaultTheme);}- // eslint-disable-next-line react-hooks/exhaustive-deps+ // eslint-disable-next-line react-hooks/exhaustive-deps}, []);useEffect(() => {@@ -150,7 +149,6 @@ export function App(props: IUniverAppProps) {data-range-selectoronContextMenu={(e) => e.preventDefault()}>- <CanvasPopup /><ComponentContainer components={contentComponents} /></section></section>diff --git a/packages/ui/src/views/components/dom/FloatDom.tsx b/packages/ui/src/views/components/dom/FloatDom.tsxnew file mode 100644index 0000000000..ab08c89643--- /dev/null+++ b/packages/ui/src/views/components/dom/FloatDom.tsx@@ -0,0 +1,90 @@+/**+ * 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 { useDependency } from '@wendellhu/redi/react-bindings';+import React, { memo } from 'react';+import type { IFloatDom } from '../../../services/dom/canvas-dom-layer.service';+import { CanvasFloatDomService } from '../../../services/dom/canvas-dom-layer.service';+import { useObservable } from '../../../components/hooks/observable';+import { ComponentManager } from '../../../common';+import styles from './index.module.less';++const FloatDomSingle = memo((props: { layer: IFloatDom; id: string }) => {+ const { layer, id } = props;+ const componentManager = useDependency(ComponentManager);+ const position = useObservable(layer.position$);+ const Component = typeof layer.componentKey === 'string' ? componentManager.get(layer.componentKey) : layer.componentKey;++ return position+ ? (+ <div+ className={styles.floatDomWrapper}+ style={{+ position: 'absolute',+ top: position.startY,+ left: position.startX,+ width: Math.max(position.endX - position.startX - 2, 0),+ height: Math.max(position.endY - position.startY - 2, 0),+ transform: `rotate(${position.rotate}deg)`,+ overflow: 'hidden',+ }}+ onPointerMove={(e) => {+ layer.onPointerMove(e.nativeEvent);+ }}+ onPointerDown={(e) => {+ layer.onPointerDown(e.nativeEvent);+ }}+ onPointerUp={(e) => {+ layer.onPointerUp(e.nativeEvent);+ }}+ onWheel={(e) => {+ layer.onWheel(e.nativeEvent);+ }}+ >+ <div+ id={id}+ className={styles.floatDom}+ style={{+ width: position.width,+ height: position.height,+ position: 'absolute',+ ...(position.absolute.left) ? { left: 0 } : { right: 0 },+ ...(position.absolute.top) ? { top: 0 } : { bottom: 0 },+ }}+ >+ {Component ? <Component /> : null}+ </div>+ </div>+ )+ : null;+});++export const FloatDom = () => {+ const domLayerService = useDependency(CanvasFloatDomService);+ const layers = useObservable(domLayerService.domLayers$);++ return (+ <>+ {layers?.map((layer) => (+ <FloatDomSingle+ id={layer[0]}+ layer={layer[1]}+ key={layer[0]}+ />+ ))}+ </>+ );+};diff --git a/packages/ui/src/views/components/dom/index.module.less b/packages/ui/src/views/components/dom/index.module.lessnew file mode 100644index 0000000000..cd0722a8fa--- /dev/null+++ b/packages/ui/src/views/components/dom/index.module.less@@ -0,0 +1,7 @@+.float-dom-wrapper {+ z-index: 10;+}++.float-dom {+ overflow: hidden;+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3b9e1563b8..2c6ef960d0 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -461,6 +461,9 @@ importers:'@univerjs/sheets':specifier: workspace:*version: link:../sheets+ '@univerjs/sheets-drawing-ui':+ specifier: workspace:*+ version: link:../sheets-drawing-ui'@univerjs/ui':specifier: workspace:*version: link:../ui