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
fix(drawing): fix inner dom position (#3864)
VicKunc37f24c91ba8
diff --git a/packages/engine-render/src/shape/shape.ts b/packages/engine-render/src/shape/shape.tsindex b66eeff3dd..a5205250c3 100644--- a/packages/engine-render/src/shape/shape.ts+++ b/packages/engine-render/src/shape/shape.ts@@ -30,6 +30,7 @@ const BASE_OBJECT_ARRAY_Set = new Set(BASE_OBJECT_ARRAY);export interface IShapeProps extends IObjectFullState, ISize, IOffset, IScale {rotateEnabled?: boolean;resizeEnabled?: boolean;+ borderEnabled?: boolean;hoverCursor?: Nullable<string>;moveCursor?: string | null;fillRule?: string;@@ -402,7 +403,9 @@ export abstract class Shape<T extends IShapeProps> extends BaseObject {const hasRotateEnabled = props?.rotateEnabled !== undefined;const hasResizeEnabled = props?.resizeEnabled !== undefined;- if (hasRotateEnabled || hasResizeEnabled) {+ const hasBorderEnabled = props?.borderEnabled !== undefined;++ if (hasRotateEnabled || hasResizeEnabled || hasBorderEnabled) {const transformerConfig = this.transformerConfig || {};if (hasRotateEnabled) {transformerConfig.rotateEnabled = props?.rotateEnabled;@@ -410,6 +413,9 @@ export abstract class Shape<T extends IShapeProps> extends BaseObject {if (hasResizeEnabled) {transformerConfig.resizeEnabled = props?.resizeEnabled;}+ if (hasBorderEnabled) {+ transformerConfig.borderEnabled = props?.borderEnabled;+ }this.transformerConfig = { ...transformerConfig };}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 1a96c66616..c0fa706e2a 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@@ -21,7 +21,7 @@ import type { ISetFrozenMutationParams } from '@univerjs/sheets';import type { IFloatDomData, ISheetDrawingPosition, ISheetFloatDom } from '@univerjs/sheets-drawing';import type { IFloatDomLayout } from '@univerjs/ui';import type { IInsertDrawingCommandParams } from '../commands/commands/interfaces';-import { Disposable, DisposableCollection, fromEventSubject, generateRandomId, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';+import { Disposable, DisposableCollection, fromEventSubject, generateRandomId, ICommandService, Inject, IUniverInstanceService, LifecycleService, LifecycleStages, UniverInstanceType } from '@univerjs/core';import { DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';import { DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, ObjectType, Rect, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';@@ -29,7 +29,7 @@ import { getSheetCommandTarget, SetFrozenMutation } from '@univerjs/sheets';import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';import { ISheetSelectionRenderService, SetZoomRatioOperation, SheetSkeletonManagerService, VIEWPORT_KEY } from '@univerjs/sheets-ui';import { CanvasFloatDomService } from '@univerjs/ui';-import { BehaviorSubject, filter, map, Subject, switchMap } from 'rxjs';+import { BehaviorSubject, filter, map, Subject, switchMap, take } from 'rxjs';import { InsertSheetDrawingCommand } from '../commands/commands/insert-sheet-drawing.command';export interface ICanvasFloatDom {@@ -186,7 +186,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {private _transformChange$ = new Subject<{ id: string; value: ITransformState }>();transformChange$ = this._transformChange$.asObservable();- private _add$ = new Subject<{ unitId: string; subUnitId: string; id: string }>();+ private _add$ = new Subject<{ unitId: string; subUnitId: string; id: string; data?: Record<string, any> }>();public add$ = this._add$.asObservable();private _remove$ = new Subject<{ unitId: string; subUnitId: string; id: string }>();@@ -200,13 +200,20 @@ export class SheetCanvasFloatDomManagerService extends Disposable {@Inject(ICommandService) private _commandService: ICommandService,@IDrawingManagerService private _drawingManagerService: IDrawingManagerService,@Inject(CanvasFloatDomService) private readonly _canvasFloatDomService: CanvasFloatDomService,- @ISheetDrawingService private readonly _sheetDrawingService: ISheetDrawingService+ @ISheetDrawingService private readonly _sheetDrawingService: ISheetDrawingService,+ @Inject(LifecycleService) protected readonly _lifecycleService: LifecycleService) {super();this._drawingAddListener();- this._scrollUpdateListener();this._featureUpdateListener();this._deleteListener();+ this._bindScrollEvent();+ }++ private _bindScrollEvent() {+ this._lifecycleService.lifecycle$.pipe(filter((s) => s === LifecycleStages.Rendered), take(1)).subscribe(() => {+ this._scrollUpdateListener();+ });}private _ensureMap(unitId: string, subUnitId: string) {@@ -318,6 +325,12 @@ export class SheetCanvasFloatDomManagerService extends Disposable {if (isChart) {imageConfig.fill = 'white';imageConfig.rotateEnabled = false;+ if (data && (data as Record<string, string>).border) {+ imageConfig.stroke = (data as Record<string, string>).border;+ }+ imageConfig.paintFirst = 'stroke';+ imageConfig.strokeWidth = 1;+ imageConfig.borderEnabled = false;}const rect = new Rect(rectShapeKey, imageConfig);@@ -505,6 +518,19 @@ export class SheetCanvasFloatDomManagerService extends Disposable {);}+ updateFloatDomProps(unitId: string, subUnitId: string, id: string, props: Record<string, any>) {+ const info = this._domLayerInfoMap.get(id);+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);+ if (info && renderObject) {+ const { scene } = renderObject;+ const rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: id });+ const rectShape = scene.getObject(rectShapeKey);+ if (rectShape && rectShape instanceof Rect) {+ rectShape.setProps(props);+ }+ }+ }+addFloatDomToPosition(layer: ICanvasFloatDom, propId?: string, executeCommand = true) {const target = getSheetCommandTarget(this._univerInstanceService, {unitId: layer.unitId,diff --git a/packages/ui/src/views/components/dom/FloatDom.tsx b/packages/ui/src/views/components/dom/FloatDom.tsxindex fa9fb0c40c..55a1d4f421 100644--- a/packages/ui/src/views/components/dom/FloatDom.tsx+++ b/packages/ui/src/views/components/dom/FloatDom.tsx@@ -64,8 +64,8 @@ const FloatDomSingle = memo((props: { layer: IFloatDom; id: string }) => {if (innerDomRef.current) {const style = {- width: `${size.width}px`,- height: `${size.height}px`,+ width: `${size.width - 4}px`,+ height: `${size.height - 4}px`,left: `${size.absolute.left ? 0 : 'auto'}`,top: `${size.absolute.top ? 0 : 'auto'}`,right: `${size.absolute.left ? 'auto' : 0}`,