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-drawing-ui): support disable transform on float dom (#3342)
zhangw9fe9468990f3
diff --git a/packages/sheets-data-validation/src/services/dropdown-manager.service.ts b/packages/sheets-data-validation/src/services/dropdown-manager.service.tsindex c268cc8695..1d3d656840 100644--- a/packages/sheets-data-validation/src/services/dropdown-manager.service.ts+++ b/packages/sheets-data-validation/src/services/dropdown-manager.service.ts@@ -112,7 +112,7 @@ export class DataValidationDropdownManagerService extends Disposable {showDropdown(param: IDropdownParam, closeOnOutSide = true) {const { location } = param;- const { row, col } = location;+ const { row, col, unitId, subUnitId } = location;if (this._currentPopup) {this._currentPopup.dispose();@@ -137,8 +137,9 @@ export class DataValidationDropdownManagerService extends Disposable {},offset: [0, 3],excludeOutside: [currentRender?.engine.getCanvasElement()].filter(Boolean) as HTMLElement[],- }-+ },+ unitId,+ subUnitId);if (!popupDisposable) {diff --git a/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts b/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.tsindex c89af70813..87e58e214a 100644--- a/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts+++ b/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts@@ -21,7 +21,7 @@ import { IRenderManagerService } from '@univerjs/engine-render';import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';import { SheetCanvasPopManagerService } from '@univerjs/sheets-ui';import { takeUntil } from 'rxjs';-import { IDrawingManagerService } from '@univerjs/drawing';+import { DrawingTypeEnum, IDrawingManagerService } from '@univerjs/drawing';import { BuiltInUIPart, IUIPartsService } from '@univerjs/ui';import { RemoveSheetDrawingCommand } from '../commands/commands/remove-sheet-drawing.command';@@ -119,7 +119,10 @@ export class DrawingPopupMenuController extends RxDisposable {return;}- const { unitId, subUnitId, drawingId } = drawingParam;+ const { unitId, subUnitId, drawingId, drawingType } = drawingParam;+ if (drawingType === DrawingTypeEnum.DRAWING_DOM) {+ return;+ }singletonPopupDisposer?.dispose();singletonPopupDisposer = this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {componentKey: COMPONENT_IMAGE_POPUP_MENU,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.tsindex 09482fb8f4..bb537dfc1c 100644--- 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.ts@@ -35,7 +35,7 @@ export interface ICanvasFloatDom {/*** whether allow transform float-dom*/- allowTransform: boolean;+ allowTransform?: boolean;/*** initial position of float-dom*/@@ -303,7 +303,10 @@ export class SheetCanvasFloatDomManagerService extends Disposable {const rect = new Rect(rectShapeKey, imageConfig);- scene.addObject(rect, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(rect);+ scene.addObject(rect, DRAWING_OBJECT_LAYER_INDEX);+ if (floatDomParam.allowTransform !== false) {+ scene.attachTransformerTo(rect);+ }const map = this._ensureMap(unitId, subUnitId);const disposableCollection = new DisposableCollection();const initPosition = calcPosition(rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);@@ -474,7 +477,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {}const { unitId, subUnitId } = target;- const { initPosition, componentKey, data } = layer;+ const { initPosition, componentKey, data, allowTransform = true } = layer;const id = propId ?? generateRandomId();const sheetTransform = this._getPosition(initPosition, unitId);@@ -498,6 +501,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {height: initPosition.endY - initPosition.startY,},data,+ allowTransform,};this._commandService.executeCommand(InsertSheetDrawingCommand.id, {diff --git a/packages/sheets-drawing/src/services/sheet-drawing.service.ts b/packages/sheets-drawing/src/services/sheet-drawing.service.tsindex 558231aa4e..55ebf8d756 100644--- a/packages/sheets-drawing/src/services/sheet-drawing.service.ts+++ b/packages/sheets-drawing/src/services/sheet-drawing.service.ts@@ -55,6 +55,7 @@ export interface ISheetShape extends IDrawingParam, ISheetDrawingBase {export interface IFloatDomData extends IDrawingParam {componentKey: string;data?: Serializable;+ allowTransform?: boolean;}// TODO@wzhudev: this shouldn't be here. It should be in the sheets packagediff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.tsindex e96f65e6e5..a32c4e0ff8 100644--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts@@ -63,14 +63,20 @@ export class SheetCanvasPopManagerService extends Disposable {top,bottom: top + height,};-const offsetBound = transformBound2OffsetBound(bound, scene, skeleton, worksheet);+ const canvasElement = currentRender.engine.getCanvasElement();+ const canvasClientRect = canvasElement.getBoundingClientRect();++ // We should take the scale into account when canvas is scaled by CSS.+ const widthOfCanvas = pxToNum(canvasElement.style.width); // declared width+ // const { top, left, width } = canvasClientRect; // real width affected by scale+ const scaleAdjust = canvasClientRect.width / widthOfCanvas;const position = {- left: offsetBound.left,- right: offsetBound.right,- top: offsetBound.top,- bottom: offsetBound.bottom,+ left: (offsetBound.left * scaleAdjust) + canvasClientRect.left,+ right: (offsetBound.right * scaleAdjust) + canvasClientRect.left,+ top: (offsetBound.top * scaleAdjust) + canvasClientRect.top,+ bottom: (offsetBound.bottom * scaleAdjust) + canvasClientRect.top,};return position;};