Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat: support chart drawing interact with shape (#7172)

siam526ee1a383df
diff --git a/packages/drawing-ui/src/commands/operations/__tests__/drawing-arrange-group.operation.spec.ts b/packages/drawing-ui/src/commands/operations/__tests__/drawing-arrange-group.operation.spec.ts
index 43802f4430..dc36cad92d 100644
--- a/packages/drawing-ui/src/commands/operations/__tests__/drawing-arrange-group.operation.spec.ts
+++ b/packages/drawing-ui/src/commands/operations/__tests__/drawing-arrange-group.operation.spec.ts
@@ -41,6 +41,7 @@ import {
import { CancelDrawingGroupOperation, SetDrawingGroupOperation } from '../drawing-group.operation';
import { AutoImageCropOperation, CloseImageCropOperation, CropType, OpenImageCropOperation } from '../image-crop.operation';
import { ImageResetSizeOperation } from '../image-reset-size.operation';
+import { resolveDrawingUIRotateEnabled } from '../../../utils/rotate-enabled';
const unitId = 'drawing-ui-unit';
const subUnitId = 'drawing-ui-subunit';
@@ -60,6 +61,31 @@ function createDrawing(drawingId: string, left: number): IDrawingParam {
};
}
+function createChartDrawing(drawingId: string, left: number): IDrawingParam {
+ return {
+ ...createDrawing(drawingId, left),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ };
+}
+
+function createGroupDrawing(drawingId: string, left: number, rotateEnabled?: boolean): IDrawingParam {
+ return {
+ ...createDrawing(drawingId, left),
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: {
+ left,
+ top: 10,
+ width: 20,
+ height: 30,
+ rotateEnabled,
+ },
+ };
+}
+
+function expectNoPersistedRotateEnabled(drawing: IDrawingParam): void {
+ expect(Object.prototype.hasOwnProperty.call(drawing.transform ?? {}, 'rotateEnabled')).toBe(false);
+}
+
describe('drawing arrange and group operations', () => {
let univer: Univer;
let commandService: ICommandService;
@@ -197,6 +223,12 @@ describe('drawing arrange and group operations', () => {
subUnitId,
drawingType: DrawingTypeEnum.DRAWING_GROUP,
});
+ expectNoPersistedRotateEnabled(groupUpdates[0][0].parent);
+ expect(resolveDrawingUIRotateEnabled(groupUpdates[0][0].parent, {
+ getChildren: (drawing) => drawing.drawingId === groupUpdates[0][0].parent.drawingId
+ ? groupUpdates[0][0].children
+ : drawingManagerService.getDrawingsByGroup(drawing),
+ })).toBe(true);
const childIds: string[] = [];
for (const child of groupUpdates[0][0].children) {
@@ -206,6 +238,61 @@ describe('drawing arrange and group operations', () => {
expect(childIds).toEqual(['image-1', 'image-2']);
});
+ it('groups chart drawings with regular drawings', async () => {
+ const groupUpdates: IDrawingGroupUpdateParam[][] = [];
+ drawingManagerService.featurePluginGroupUpdate$.subscribe((update) => groupUpdates.push(update));
+
+ const result = await commandService.executeCommand(SetDrawingGroupOperation.id, {
+ drawings: [createChartDrawing('chart-1', 0), createDrawing('image-1', 30)],
+ });
+
+ expect(result).toBe(true);
+ expect(groupUpdates).toHaveLength(1);
+ expectNoPersistedRotateEnabled(groupUpdates[0][0].parent);
+ expect(resolveDrawingUIRotateEnabled(groupUpdates[0][0].parent, {
+ getChildren: (drawing) => drawing.drawingId === groupUpdates[0][0].parent.drawingId
+ ? groupUpdates[0][0].children
+ : drawingManagerService.getDrawingsByGroup(drawing),
+ })).toBe(false);
+ expect(groupUpdates[0][0].children.map((child) => child.drawingId)).toEqual(['chart-1', 'image-1']);
+ expect(groupUpdates[0][0].children[0]).toMatchObject({
+ drawingId: 'chart-1',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: groupUpdates[0][0].parent.drawingId,
+ });
+ });
+
+ it('recomputes nested group rotate capability from current descendants', async () => {
+ drawingManagerService.registerDrawingData(unitId, {
+ [subUnitId]: {
+ data: {
+ staleGroup: {
+ ...createGroupDrawing('staleGroup', 0, false),
+ },
+ 'nested-child': {
+ ...createDrawing('nested-child', 10),
+ groupId: 'staleGroup',
+ },
+ },
+ order: ['staleGroup', 'nested-child'],
+ },
+ });
+ const groupUpdates: IDrawingGroupUpdateParam[][] = [];
+ drawingManagerService.featurePluginGroupUpdate$.subscribe((update) => groupUpdates.push(update));
+
+ const result = await commandService.executeCommand(SetDrawingGroupOperation.id, {
+ drawings: [createGroupDrawing('staleGroup', 0, false), createDrawing('image-1', 30)],
+ });
+
+ expect(result).toBe(true);
+ expectNoPersistedRotateEnabled(groupUpdates[0][0].parent);
+ expect(resolveDrawingUIRotateEnabled(groupUpdates[0][0].parent, {
+ getChildren: (drawing) => drawing.drawingId === groupUpdates[0][0].parent.drawingId
+ ? groupUpdates[0][0].children
+ : drawingManagerService.getDrawingsByGroup(drawing),
+ })).toBe(true);
+ });
+
it('does not create a drawing group from a single selected drawing', async () => {
const groupUpdates: IDrawingGroupUpdateParam[][] = [];
drawingManagerService.featurePluginGroupUpdate$.subscribe((update) => groupUpdates.push(update));
diff --git a/packages/drawing-ui/src/commands/operations/drawing-group.operation.ts b/packages/drawing-ui/src/commands/operations/drawing-group.operation.ts
index 821255c407..8e30fceca8 100644
--- a/packages/drawing-ui/src/commands/operations/drawing-group.operation.ts
+++ b/packages/drawing-ui/src/commands/operations/drawing-group.operation.ts
@@ -17,20 +17,22 @@
import type { IDrawingParam, IOperation } from '@univerjs/core';
import type { IDrawingGroupUpdateParam } from '@univerjs/drawing';
import { CommandType, DrawingTypeEnum, generateRandomId } from '@univerjs/core';
-import { IDrawingManagerService } from '@univerjs/drawing';
+import { DRAWING_GROUPABLE_TYPES, IDrawingManagerService, isGroupableDrawingType } from '@univerjs/drawing';
import { getGroupState, transformObjectOutOfGroup } from '@univerjs/engine-render';
/**
- * Now only support grouping images, shapes, and groups.
+ * Now only support grouping images, shapes, charts, and groups.
*/
-export const DRAWING_GROUP_TYPES = [DrawingTypeEnum.DRAWING_IMAGE, DrawingTypeEnum.DRAWING_SHAPE, DrawingTypeEnum.DRAWING_GROUP];
+export const DRAWING_GROUP_TYPES = DRAWING_GROUPABLE_TYPES;
export interface IDrawingGroupOperationParams {
drawings?: IDrawingParam[];
}
/**
- * Group the selected drawings into a new group. The selected drawings must be of type image, shape, or group, and there must be at least 2 drawings selected.
+ * Group the selected drawings into a new group. The selected drawings must be
+ * of type image, shape, chart, or group, and there must be at least 2 drawings
+ * selected.
*/
export const SetDrawingGroupOperation: IOperation<IDrawingGroupOperationParams> = {
id: 'drawing.operation.set-drawing-group',
@@ -40,7 +42,7 @@ export const SetDrawingGroupOperation: IOperation<IDrawingGroupOperationParams>
const drawings = params.drawings || drawingManagerService.getFocusDrawings();
if (drawings.length < 2) return false;
- if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return false;
+ if (!drawings.every((drawing) => isGroupableDrawingType(drawing.drawingType))) return false;
const { unitId, subUnitId } = drawings[0];
@@ -62,11 +64,12 @@ export const SetDrawingGroupOperation: IOperation<IDrawingGroupOperationParams>
const children = drawings.map((drawing) => {
const transform = drawing.transform || { left: 0, top: 0 };
- const { unitId, subUnitId, drawingId } = drawing;
+ const { unitId, subUnitId, drawingId, drawingType } = drawing;
return {
unitId,
subUnitId,
drawingId,
+ drawingType,
transform: {
...transform,
// left: transform.left! - groupTransform.left,
diff --git a/packages/drawing-ui/src/controllers/__tests__/drawing-update.controller.spec.ts b/packages/drawing-ui/src/controllers/__tests__/drawing-update.controller.spec.ts
index 82a5c96aaf..691a387c69 100644
--- a/packages/drawing-ui/src/controllers/__tests__/drawing-update.controller.spec.ts
+++ b/packages/drawing-ui/src/controllers/__tests__/drawing-update.controller.spec.ts
@@ -17,8 +17,8 @@
import type { ICommandInfo } from '@univerjs/core';
import type { IDrawingGroupUpdateParam } from '@univerjs/drawing';
import { DrawingTypeEnum, UniverInstanceType } from '@univerjs/core';
-import { SetDrawingSelectedOperation } from '@univerjs/drawing';
-import { DRAWING_OBJECT_LAYER_INDEX } from '@univerjs/engine-render';
+import { getDrawingShapeKeyByDrawingSearch, SetDrawingSelectedOperation } from '@univerjs/drawing';
+import { DRAWING_OBJECT_LAYER_INDEX, Rect } from '@univerjs/engine-render';
import { Subject } from 'rxjs';
import { describe, expect, it, vi } from 'vitest';
import { AlignType, SetDrawingAlignOperation } from '../../commands/operations/drawing-align.operation';
@@ -73,22 +73,25 @@ function createHarness() {
const disposeShape = { dispose: vi.fn() };
const showHideShape = { show: vi.fn(), hide: vi.fn() };
const transformShape = { layer: { zIndex: DRAWING_OBJECT_LAYER_INDEX }, transformByState: vi.fn(), setClipBounds: vi.fn(), show: vi.fn(), hide: vi.fn() };
+ const getSceneObject = vi.fn((key: string) => {
+ if (key === 'unit-1#-#sheet-1#-#drawing-visible') return showHideShape;
+ if (key === 'unit-1#-#sheet-1#-#drawing-transform') return transformShape;
+ if (key === 'unit-1#-#sheet-1#-#drawing-transform-refresh-hidden') return transformShape;
+ if (key === 'unit-1#-#sheet-1#-#drawing-remove') return disposeShape;
+ return null;
+ });
const scene = {
getTransformerByCreate: vi.fn(() => transformer),
getTransformer: vi.fn(() => sceneTransformer),
- getObject: vi.fn((key: string) => {
- if (key.includes('drawing-visible')) return showHideShape;
- if (key.includes('drawing-transform')) return transformShape;
- return null;
- }),
- getObjectIncludeInGroup: vi.fn(() => null),
+ getObject: getSceneObject,
+ getObjectIncludeInGroup: vi.fn(getSceneObject),
fuzzyMathObjects: vi.fn((key: string) => {
if (key.includes('drawing-z')) return [zIndexShape];
if (key.includes('drawing-remove')) return [disposeShape];
return [];
}),
- addObject: vi.fn(() => ({ attachTransformerTo: vi.fn() })),
+ addObject: vi.fn((_object: any, _layerIndex?: number) => ({ attachTransformerTo: vi.fn() })),
addObjects: vi.fn(),
removeObject: vi.fn(),
makeDirty: vi.fn(),
@@ -101,7 +104,9 @@ function createHarness() {
const drawingParams = new Map<string, { unitId: string; subUnitId: string; drawingId: string; drawingType: DrawingTypeEnum; behindText?: boolean; hidden?: boolean; transform: { left: number; top: number; width: number; height: number; angle: number; clipBounds?: { left: number; top: number; width: number; height: number } } }>([
['drawing-a', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'drawing-a', drawingType: DrawingTypeEnum.DRAWING_IMAGE, transform: { left: 0, top: 0, width: 10, height: 10, angle: 0 } }],
['drawing-b', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'drawing-b', drawingType: DrawingTypeEnum.DRAWING_IMAGE, transform: { left: 20, top: 0, width: 10, height: 10, angle: 0 } }],
+ ['chart-1', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'chart-1', drawingType: DrawingTypeEnum.DRAWING_CHART, transform: { left: 40, top: 0, width: 20, height: 10, angle: 0 } }],
['drawing-transform', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'drawing-transform', drawingType: DrawingTypeEnum.DRAWING_IMAGE, behindText: true, hidden: true, transform: { left: 1, top: 2, width: 3, height: 4, angle: 0, clipBounds: { left: 0, top: 0, width: 80, height: 120 } } }],
+ ['drawing-transform-in-group', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'drawing-transform-in-group', drawingType: DrawingTypeEnum.DRAWING_IMAGE, transform: { left: 8, top: 9, width: 10, height: 11, angle: 0 } }],
['drawing-transform-refresh-hidden', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'drawing-transform-refresh-hidden', drawingType: DrawingTypeEnum.DRAWING_IMAGE, transform: { left: 1, top: 2, width: 3, height: 4, angle: 0, clipBounds: { left: 0, top: 0, width: 80, height: 120 } } }],
['drawing-refresh-missing', { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'drawing-refresh-missing', drawingType: DrawingTypeEnum.DRAWING_IMAGE, transform: { left: 4, top: 5, width: 6, height: 7, angle: 0 } }],
]);
@@ -156,6 +161,7 @@ function createHarness() {
changeEnd$,
commandExecuted: () => commandExecuted,
drawingManagerService,
+ group$,
order$,
refreshTransform$,
remove$,
@@ -242,6 +248,29 @@ describe('DrawingUpdateController', () => {
harness.controller.dispose();
});
+ it('disposes grouped drawing children through grouped scene lookup on remove notifications', () => {
+ const harness = createHarness();
+ const groupedShape = { dispose: vi.fn() };
+ const drawingId = 'drawing-remove-in-group';
+ const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId: 'unit-1', subUnitId: 'sheet-1', drawingId });
+
+ harness.scene.getObjectIncludeInGroup.mockImplementation((key: string) => {
+ if (key === drawingShapeKey) {
+ return groupedShape;
+ }
+ return null;
+ });
+ harness.scene.fuzzyMathObjects.mockClear();
+
+ harness.remove$.next([{ unitId: 'unit-1', subUnitId: 'sheet-1', drawingId }]);
+
+ expect(groupedShape.dispose).toHaveBeenCalledTimes(1);
+ expect(harness.scene.getTransformer().clearSelectedObjects).toHaveBeenCalledTimes(1);
+ expect(harness.scene.fuzzyMathObjects).not.toHaveBeenCalled();
+
+ harness.controller.dispose();
+ });
+
it('requests drawing insertion when a refreshed transform belongs to a missing scene object', () => {
const harness = createHarness();
@@ -254,6 +283,97 @@ describe('DrawingUpdateController', () => {
harness.controller.dispose();
});
+ it('refreshes drawing transforms for objects inside groups without requesting insertion', () => {
+ const harness = createHarness();
+ const groupedShape = { transformByState: vi.fn(), setClipBounds: vi.fn(), show: vi.fn(), hide: vi.fn(), layer: { zIndex: DRAWING_OBJECT_LAYER_INDEX } };
+ const drawingId = 'drawing-transform-in-group';
+ const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId: 'unit-1', subUnitId: 'sheet-1', drawingId });
+
+ harness.scene.getObjectIncludeInGroup.mockImplementation((key: string) => {
+ if (key === drawingShapeKey) {
+ return groupedShape;
+ }
+ return null;
+ });
+
+ harness.refreshTransform$.next([{ unitId: 'unit-1', subUnitId: 'sheet-1', drawingId }]);
+
+ expect(groupedShape.transformByState).toHaveBeenCalledWith({
+ left: 8,
+ top: 9,
+ width: 10,
+ height: 11,
+ angle: 0,
+ flipX: false,
+ flipY: false,
+ skewX: 0,
+ skewY: 0,
+ });
+ expect(harness.drawingManagerService.addNotification).not.toHaveBeenCalled();
+
+ harness.controller.dispose();
+ });
+
+ it('groups existing chart render objects from the scene', () => {
+ const harness = createHarness();
+ const unitId = 'unit-1';
+ const subUnitId = 'sheet-1';
+ const imageKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: 'drawing-a' });
+ const chartKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: 'chart-1' });
+ const groupKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: 'group-1' });
+ const imageRect = new Rect(imageKey, { left: 0, top: 0, width: 10, height: 10 });
+ const chartRect = new Rect(chartKey, { left: 40, top: 0, width: 20, height: 10 });
+ const imageTransformSpy = vi.spyOn(imageRect, 'transformByState');
+ const chartTransformSpy = vi.spyOn(chartRect, 'transformByState');
+ let createdGroup: { oKey: string; getObjects: () => unknown[]; transformerConfig?: { rotateEnabled?: boolean }; angle?: number } | undefined;
+
+ harness.scene.getObjectIncludeInGroup.mockImplementation((key: string) => {
+ if (key === imageKey) {
+ return imageRect;
+ }
+ if (key === chartKey) {
+ return chartRect;
+ }
+ return null;
+ });
+ harness.scene.addObject.mockImplementation((object: { oKey: string; getObjects?: () => unknown[] }) => {
+ if (object.oKey === groupKey && object.getObjects) {
+ createdGroup = object as { oKey: string; getObjects: () => unknown[]; transformerConfig?: { rotateEnabled?: boolean }; angle?: number };
+ }
+ return { attachTransformerTo: vi.fn() };
+ });
+
+ harness.group$.next([{
+ parent: {
+ unitId,
+ subUnitId,
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 0, top: 0, width: 60, height: 10, angle: 30 },
+ groupBaseBound: { left: 0, top: 0, width: 60, height: 10 },
+ },
+ children: [
+ { unitId, subUnitId, drawingId: 'drawing-a', drawingType: DrawingTypeEnum.DRAWING_IMAGE, transform: { left: 0, top: 0, width: 10, height: 10, angle: 0 }, groupId: 'group-1' },
+ { unitId, subUnitId, drawingId: 'chart-1', drawingType: DrawingTypeEnum.DRAWING_CHART, transform: { left: 40, top: 0, width: 20, height: 10, angle: 0 }, groupId: 'group-1' },
+ ],
+ }]);
+
+ expect(createdGroup?.oKey).toBe(groupKey);
+ expect(createdGroup?.getObjects()).toEqual([imageRect, chartRect]);
+ expect(createdGroup?.transformerConfig?.rotateEnabled).toBe(false);
+ expect(createdGroup?.angle).toBe(30);
+ expect(imageRect.isInGroup).toBe(true);
+ expect(chartRect.isInGroup).toBe(true);
+ expect(imageRect.groupKey).toBe(groupKey);
+ expect(chartRect.groupKey).toBe(groupKey);
+ expect(imageTransformSpy).toHaveBeenCalledWith({ left: 0, top: 0, width: 10, height: 10, angle: 0 });
+ expect(chartTransformSpy).toHaveBeenCalledWith({ left: 40, top: 0, width: 20, height: 10, angle: 0 });
+ expect(harness.transformer.clearSelectedObjects).toHaveBeenCalledTimes(1);
+ expect(harness.transformer.setSelectedControl).toHaveBeenCalledWith(createdGroup);
+
+ harness.controller.dispose();
+ });
+
it('uses refresh metadata to hide stale drawings without re-adding missing hidden shapes', () => {
const harness = createHarness();
diff --git a/packages/drawing-ui/src/controllers/__tests__/utils.spec.ts b/packages/drawing-ui/src/controllers/__tests__/utils.spec.ts
index 4f9568f203..b40b9fbfb3 100644
--- a/packages/drawing-ui/src/controllers/__tests__/utils.spec.ts
+++ b/packages/drawing-ui/src/controllers/__tests__/utils.spec.ts
@@ -14,15 +14,16 @@
* limitations under the License.
*/
-import { UniverInstanceType } from '@univerjs/core';
+import { DrawingTypeEnum, UniverInstanceType } from '@univerjs/core';
import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
import { DrawingGroupObject, Group } from '@univerjs/engine-render';
import { describe, expect, it, vi } from 'vitest';
-import { getCurrentUnitInfo, insertGroupObject } from '../utils';
+import { disposeDrawingRenderObject, getCurrentUnitInfo, getDrawingRenderObject, insertGroupObject, syncGroupRotateEnabled } from '../utils';
const { MockGroup } = vi.hoisted(() => {
class HoistedMockGroup {
oKey: string;
+ transformerConfig?: { rotateEnabled?: boolean };
private _objects: Array<{ oKey: string }> = [];
setBaseBound = vi.fn();
transformByState = vi.fn();
@@ -49,9 +50,14 @@ const { MockGroup } = vi.hoisted(() => {
};
});
-vi.mock('@univerjs/drawing', () => ({
- getDrawingShapeKeyByDrawingSearch: vi.fn(({ drawingId }) => `group-${drawingId}`),
-}));
+vi.mock('@univerjs/drawing', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('@univerjs/drawing')>();
+
+ return {
+ ...actual,
+ getDrawingShapeKeyByDrawingSearch: vi.fn(({ drawingId }) => `group-${drawingId}`),
+ };
+});
vi.mock('@univerjs/engine-render', () => ({
DRAWING_OBJECT_LAYER_INDEX: 99,
@@ -80,9 +86,14 @@ describe('drawing controller utils', () => {
};
const drawingManagerService = {
getDrawingByParam: vi.fn(() => ({
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
transform: { left: 10, top: 20, width: 30, height: 40, angle: 15 },
groupBaseBound: { left: 1, top: 2, width: 3, height: 4 },
})),
+ getDrawingsByGroup: vi.fn(() => []),
};
insertGroupObject({ drawingId: 'group-1' } as never, object as never, scene as never, drawingManagerService as never);
@@ -97,20 +108,135 @@ describe('drawing controller utils', () => {
insertGroupObject({ drawingId: 'group-1' } as never, object as never, scene as never, drawingManagerService as never);
expect(group.getObjects()).toEqual([object]);
+
+ const nextObject = { oKey: 'child-2' };
+ insertGroupObject({ drawingId: 'group-1' } as never, nextObject as never, scene as never, drawingManagerService as never);
+ expect(group.getObjects()).toEqual([object, nextObject]);
+ });
+
+ it('inserts nested groups into their parent group', () => {
+ const object = { oKey: 'child-1' };
+ const scene = {
+ objects: new Map<string, InstanceType<typeof MockGroup> | { oKey: string }>(),
+ getObject(key: string) {
+ return this.objects.get(key) ?? null;
+ },
+ addObject(group: InstanceType<typeof MockGroup>) {
+ this.objects.set(group.oKey, group);
+ return {
+ attachTransformerTo: vi.fn(),
+ };
+ },
+ getObjectIncludeInGroup(key: string) {
+ return this.getObject(key);
+ },
+ };
+ const drawingManagerService = {
+ getDrawingByParam: vi.fn((param: { drawingId: string }) => ({
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: param.drawingId,
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ groupId: param.drawingId === 'child-group' ? 'parent-group' : undefined,
+ transform: { left: 0, top: 0, width: 10, height: 10 },
+ })),
+ getDrawingsByGroup: vi.fn(() => []),
+ };
+
+ insertGroupObject({ unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'child-group' }, object as never, scene as never, drawingManagerService as never);
+
+ const childGroup = scene.getObject('group-child-group') as InstanceType<typeof MockGroup> & { isInGroup?: boolean };
+ const parentGroup = scene.getObject('group-parent-group') as InstanceType<typeof MockGroup>;
+ expect(childGroup.isInGroup).toBe(true);
+ expect(parentGroup.getObjects()).toEqual([childGroup]);
+ });
+
+ it('disables restored group rotation when descendants include an old chart drawing', () => {
+ const object = { oKey: 'chart-1' };
+ const scene = {
+ objects: new Map<string, InstanceType<typeof MockGroup> | { oKey: string }>(),
+ getObject(key: string) {
+ return this.objects.get(key) ?? null;
+ },
+ addObject(group: InstanceType<typeof MockGroup>) {
+ this.objects.set(group.oKey, group);
+ return {
+ attachTransformerTo: vi.fn(),
+ };
+ },
+ getObjectIncludeInGroup(key: string) {
+ return this.getObject(key);
+ },
+ };
+ const drawingManagerService = {
+ getDrawingByParam: vi.fn(() => ({
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 10, top: 20, width: 30, height: 40, angle: 30 },
+ })),
+ getDrawingsByGroup: vi.fn(() => [{
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'chart-1',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ transform: { left: 10, top: 20, width: 30, height: 40 },
+ groupId: 'group-1',
+ }]),
+ };
+
+ insertGroupObject({ unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'group-1' }, object as never, scene as never, drawingManagerService as never);
+
+ const group = scene.getObject('group-group-1') as InstanceType<typeof MockGroup>;
+ expect(group.transformerConfig?.rotateEnabled).toBe(false);
+ expect(group.transformByState).toHaveBeenCalledWith({ left: 10, top: 20, width: 30, height: 40, angle: 30 });
+ });
+
+ it('uses explicit children when synchronizing group rotation state', () => {
+ const group = new MockGroup('group-group-1');
+ const scene = {
+ getObjectIncludeInGroup: vi.fn(() => null),
+ };
+ const drawingManagerService = {
+ getDrawingsByGroup: vi.fn(() => []),
+ };
+
+ syncGroupRotateEnabled(group as never, {
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ }, scene as never, drawingManagerService as never, [{
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'chart-1',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ }]);
+
+ expect(group.transformerConfig?.rotateEnabled).toBe(false);
+ expect(drawingManagerService.getDrawingsByGroup).not.toHaveBeenCalled();
});
it('skips invalid group targets and resolves current unit info for sheet, doc, and slide', () => {
const scene = {
getObject: vi.fn(() => ({ oKey: 'not-a-group' })),
- getObjectIncludeInGroup: vi.fn(() => null),
+ getObjectIncludeInGroup: vi.fn(() => ({ oKey: 'not-a-group' })),
addObject: vi.fn(() => ({ attachTransformerTo: vi.fn() })),
};
const drawingManagerService = {
getDrawingByParam: vi.fn(() => ({ transform: { left: 0, top: 0, width: 10, height: 10 } })),
+ getDrawingsByGroup: vi.fn(() => []),
};
insertGroupObject({ drawingId: 'group-2' } as never, { oKey: 'child-2' } as never, scene as never, drawingManagerService as never);
expect(scene.getObjectIncludeInGroup).toHaveBeenCalled();
+ expect(scene.addObject).not.toHaveBeenCalled();
+
+ insertGroupObject({ drawingId: 'missing-group' } as never, { oKey: 'child-3' } as never, scene as never, {
+ getDrawingByParam: vi.fn(() => null),
+ getDrawingsByGroup: vi.fn(() => []),
+ } as never);
const sheet = {
type: UniverInstanceType.UNIVER_SHEET,
@@ -157,4 +283,29 @@ describe('drawing controller utils', () => {
});
expect(Group).toBeDefined();
});
+
+ it('looks up and disposes grouped render objects through grouped scene lookup only', () => {
+ const renderObject = { oKey: 'group-child', dispose: vi.fn() };
+ const scene = {
+ getObject: vi.fn(() => ({ oKey: 'top-level-child' })),
+ getObjectIncludeInGroup: vi.fn(() => renderObject),
+ };
+ const drawingSearch = { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'child-1' };
+
+ expect(getDrawingRenderObject(scene as never, drawingSearch)).toBe(renderObject);
+ expect(disposeDrawingRenderObject(scene as never, drawingSearch)).toBe(true);
+ expect(renderObject.dispose).toHaveBeenCalledTimes(1);
+ expect(scene.getObject).not.toHaveBeenCalled();
+ });
+
+ it('does not fall back to top-level scene lookup when grouped lookup misses', () => {
+ const scene = {
+ getObject: vi.fn(() => ({ oKey: 'top-level-child', dispose: vi.fn() })),
+ getObjectIncludeInGroup: vi.fn(() => null),
+ };
+
+ expect(getDrawingRenderObject(scene as never, { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'child-1' })).toBeNull();
+ expect(disposeDrawingRenderObject(scene as never, { unitId: 'unit-1', subUnitId: 'sheet-1', drawingId: 'child-1' })).toBe(false);
+ expect(scene.getObject).not.toHaveBeenCalled();
+ });
});
diff --git a/packages/drawing-ui/src/controllers/drawing-update.controller.ts b/packages/drawing-ui/src/controllers/drawing-update.controller.ts
index a98f4d09e6..cd28d6cae8 100644
--- a/packages/drawing-ui/src/controllers/drawing-update.controller.ts
+++ b/packages/drawing-ui/src/controllers/drawing-update.controller.ts
@@ -48,7 +48,7 @@ import { AlignType, SetDrawingAlignOperation } from '../commands/operations/draw
import { CloseImageCropOperation } from '../commands/operations/image-crop.operation';
import { ensureDrawingRenderLayer } from '../services/drawing-render.service';
import { getUpdateParams } from '../utils/get-update-params';
-import { getCurrentUnitInfo, insertGroupObject } from './utils';
+import { disposeDrawingRenderObject, getCurrentUnitInfo, insertGroupObject, syncGroupRotateEnabled } from './utils';
interface IDrawingTransformCache {
unitId: string;
@@ -62,7 +62,18 @@ interface IDrawingTransformStateWithClipBounds extends ITransformState {
clipBounds?: Nullable<{ left: number; top: number; width: number; height: number }>;
}
-function syncDrawingHiddenState(shape: BaseObject, drawingParam: IDrawingParam): void {
+interface IDrawingRefreshMetadata {
+ hidden?: boolean;
+ behindText?: boolean;
+}
+
+type IDrawingParamWithRefreshMetadata = IDrawingParam & IDrawingRefreshMetadata;
+
+function hasRefreshMetadata(refreshParam: IDrawingSearch): refreshParam is IDrawingSearch & IDrawingRefreshMetadata {
+ return 'hidden' in refreshParam || 'behindText' in refreshParam;
+}
+
+function syncDrawingHiddenState(shape: BaseObject, drawingParam: IDrawingParamWithRefreshMetadata): void {
if (!('hidden' in drawingParam)) {
return;
}
@@ -70,15 +81,14 @@ function syncDrawingHiddenState(shape: BaseObject, drawingParam: IDrawingParam):
drawingParam.hidden === true ? shape.hide() : shape.show();
}
-function mergeRefreshMetadata(drawingParam: IDrawingParam, refreshParam: IDrawingSearch): IDrawingParam {
- const metadata = refreshParam as Partial<IDrawingParam>;
- if (!('hidden' in metadata) && !('behindText' in metadata)) {
+function mergeRefreshMetadata(drawingParam: IDrawingParam, refreshParam: IDrawingSearch): IDrawingParamWithRefreshMetadata {
+ if (!hasRefreshMetadata(refreshParam)) {
return drawingParam;
}
return {
...drawingParam,
- ...metadata,
+ ...refreshParam,
};
}
@@ -276,6 +286,7 @@ export class DrawingUpdateController extends Disposable {
scene.addObject(group, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
group.addObjects(...objects);
+ syncGroupRotateEnabled(group, parent, scene, this._drawingManagerService, children);
if (parent.groupBaseBound) {
group.setBaseBound(parent.groupBaseBound);
}
@@ -666,15 +677,7 @@ export class DrawingUpdateController extends Disposable {
}
const { scene } = renderObject;
- const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
-
- const drawingShapes = scene.fuzzyMathObjects(drawingShapeKey, true);
-
- if (drawingShapes.length > 0) {
- for (const drawingShape of drawingShapes) {
- drawingShape.dispose();
- }
-
+ if (disposeDrawingRenderObject(scene, { unitId, subUnitId, drawingId })) {
scene.getTransformer()?.clearSelectedObjects();
}
});
@@ -750,7 +753,7 @@ export class DrawingUpdateController extends Disposable {
}
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
- const drawingShape = scene.getObject(drawingShapeKey);
+ const drawingShape = scene.getObjectIncludeInGroup(drawingShapeKey);
const drawingParamWithRefreshMetadata = mergeRefreshMetadata(drawingParam, param);
if (drawingShape == null) {
diff --git a/packages/drawing-ui/src/controllers/utils.ts b/packages/drawing-ui/src/controllers/utils.ts
index 2b568b0760..c976fb67aa 100644
--- a/packages/drawing-ui/src/controllers/utils.ts
+++ b/packages/drawing-ui/src/controllers/utils.ts
@@ -14,12 +14,56 @@
* limitations under the License.
*/
-import type { IDrawingSearch, IUniverInstanceService, Nullable, Workbook } from '@univerjs/core';
+import type { IDrawingParam, IDrawingSearch, IUniverInstanceService, Nullable, Workbook } from '@univerjs/core';
import type { IDrawingManagerService } from '@univerjs/drawing';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import { UniverInstanceType } from '@univerjs/core';
import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
import { DRAWING_OBJECT_LAYER_INDEX, DrawingGroupObject, Group } from '@univerjs/engine-render';
+import { resolveDrawingUIRotateEnabled } from '../utils/rotate-enabled';
+
+export function getDrawingRenderObject(scene: Scene, drawingSearch: IDrawingSearch): BaseObject | null {
+ const key = getDrawingShapeKeyByDrawingSearch(drawingSearch);
+ return scene.getObjectIncludeInGroup(key) ?? null;
+}
+
+export function disposeDrawingRenderObject(scene: Scene, drawingSearch: IDrawingSearch): boolean {
+ const object = getDrawingRenderObject(scene, drawingSearch);
+
+ if (object == null) {
+ return false;
+ }
+
+ object.dispose();
+ return true;
+}
+
+function getRenderObjectForDrawing(scene: Scene, drawing: IDrawingParam): BaseObject | null {
+ return getDrawingRenderObject(scene, drawing);
+}
+
+export function syncGroupRotateEnabled(
+ group: Group,
+ groupParam: IDrawingParam,
+ scene: Scene,
+ drawingManagerService: IDrawingManagerService,
+ children?: readonly IDrawingParam[]
+): void {
+ const rotateEnabled = resolveDrawingUIRotateEnabled(groupParam, {
+ getChildren: (drawing) => {
+ if (children && drawing.drawingId === groupParam.drawingId && drawing.unitId === groupParam.unitId && drawing.subUnitId === groupParam.subUnitId) {
+ return children;
+ }
+
+ return drawingManagerService.getDrawingsByGroup(drawing);
+ },
+ getRenderObject: (drawing) => getRenderObjectForDrawing(scene, drawing),
+ });
+ group.transformerConfig = {
+ ...group.transformerConfig,
+ rotateEnabled,
+ };
+}
export function insertGroupObject(objectParam: IDrawingSearch, object: BaseObject, scene: Scene, drawingManagerService: IDrawingManagerService) {
const groupParam = drawingManagerService.getDrawingByParam(objectParam);
@@ -42,6 +86,7 @@ export function insertGroupObject(objectParam: IDrawingSearch, object: BaseObjec
}
}
groupObject.addObject(object);
+ syncGroupRotateEnabled(groupObject, groupParam, scene, drawingManagerService);
return;
}
@@ -50,6 +95,7 @@ export function insertGroupObject(objectParam: IDrawingSearch, object: BaseObjec
scene.addObject(group, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
group.addObject(object);
+ syncGroupRotateEnabled(group, groupParam, scene, drawingManagerService);
const { transform, groupBaseBound } = groupParam;
diff --git a/packages/drawing-ui/src/index.ts b/packages/drawing-ui/src/index.ts
index 322b59a674..2cf656321e 100644
--- a/packages/drawing-ui/src/index.ts
+++ b/packages/drawing-ui/src/index.ts
@@ -37,7 +37,7 @@ export {
} from './commands/operations/image-crop.operation';
export { ImageResetSizeOperation } from './commands/operations/image-reset-size.operation';
export type { IUniverDrawingUIConfig } from './config/config';
-export { getCurrentUnitInfo, insertGroupObject } from './controllers/utils';
+export { disposeDrawingRenderObject, getCurrentUnitInfo, getDrawingRenderObject, insertGroupObject } from './controllers/utils';
export { UniverDrawingUIPlugin } from './plugin';
export { DrawingImageClipService, IMAGE_CLIP_SHAPE_PICKER_COMPONENT } from './services/drawing-image-clip.service';
export type { ImageShapeClipDelegate } from './services/drawing-image-clip.service';
diff --git a/packages/drawing-ui/src/menu/group.menu.ts b/packages/drawing-ui/src/menu/group.menu.ts
index 66244c47ed..04f58072b3 100644
--- a/packages/drawing-ui/src/menu/group.menu.ts
+++ b/packages/drawing-ui/src/menu/group.menu.ts
@@ -18,12 +18,11 @@ import type { IAccessor, IDrawingParam } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import type { LocaleKey } from '../locale/types';
import { DrawingTypeEnum } from '@univerjs/core';
-import { IDrawingManagerService } from '@univerjs/drawing';
+import { IDrawingManagerService, isGroupableDrawingType } from '@univerjs/drawing';
import { MenuItemType } from '@univerjs/ui';
import { Observable } from 'rxjs';
import {
CancelDrawingGroupOperation,
- DRAWING_GROUP_TYPES,
SetDrawingGroupOperation,
} from '../commands/operations/drawing-group.operation';
@@ -45,7 +44,7 @@ function getMenuStateByDrawingFocusChangedObservable$(
return subscriber.next(true);
}
- if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) {
+ if (!drawings.every((drawing) => isGroupableDrawingType(drawing.drawingType))) {
return subscriber.next(true);
}
} else if (type === 'unGroup') {
@@ -57,7 +56,7 @@ function getMenuStateByDrawingFocusChangedObservable$(
}
} else {
// If there are drawings that cannot be grouped or ungrouped, hide the context menu
- if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) {
+ if (!drawings.every((drawing) => isGroupableDrawingType(drawing.drawingType))) {
return subscriber.next(true);
}
}
diff --git a/packages/drawing-ui/src/utils/__tests__/rotate-enabled.spec.ts b/packages/drawing-ui/src/utils/__tests__/rotate-enabled.spec.ts
new file mode 100644
index 0000000000..f442f790a6
--- /dev/null
+++ b/packages/drawing-ui/src/utils/__tests__/rotate-enabled.spec.ts
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IDrawingParam } from '@univerjs/core';
+import { DrawingTypeEnum } from '@univerjs/core';
+import { describe, expect, it } from 'vitest';
+import { isKnownDrawingUINonRotatableType, resolveDrawingUIRotateEnabled } from '../rotate-enabled';
+
+function createDrawing(drawingType: DrawingTypeEnum): IDrawingParam {
+ return {
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'drawing-1',
+ drawingType,
+ };
+}
+
+describe('drawing-ui rotate-enabled helpers', () => {
+ it('uses chart as the default non-rotatable UI drawing type', () => {
+ expect(isKnownDrawingUINonRotatableType(DrawingTypeEnum.DRAWING_CHART)).toBe(true);
+ expect(resolveDrawingUIRotateEnabled(createDrawing(DrawingTypeEnum.DRAWING_CHART))).toBe(false);
+ });
+
+ it('lets callers override known non-rotatable type handling', () => {
+ expect(resolveDrawingUIRotateEnabled(createDrawing(DrawingTypeEnum.DRAWING_CHART), {
+ isKnownNonRotatableType: () => false,
+ })).toBe(true);
+ });
+});
diff --git a/packages/drawing-ui/src/utils/rotate-enabled.ts b/packages/drawing-ui/src/utils/rotate-enabled.ts
new file mode 100644
index 0000000000..d77fc004cf
--- /dev/null
+++ b/packages/drawing-ui/src/utils/rotate-enabled.ts
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { DrawingType, IDrawingParam } from '@univerjs/core';
+import type { IDrawingRotateEnabledResolverOptions } from '@univerjs/drawing';
+import { DrawingTypeEnum } from '@univerjs/core';
+import { resolveDrawingRotateEnabled } from '@univerjs/drawing';
+
+export function isKnownDrawingUINonRotatableType(drawingType: DrawingType): boolean {
+ return drawingType === DrawingTypeEnum.DRAWING_CHART;
+}
+
+export function resolveDrawingUIRotateEnabled(
+ drawing: IDrawingParam,
+ options: IDrawingRotateEnabledResolverOptions = {}
+): boolean {
+ return resolveDrawingRotateEnabled(drawing, {
+ ...options,
+ isKnownNonRotatableType: options.isKnownNonRotatableType ?? isKnownDrawingUINonRotatableType,
+ });
+}
diff --git a/packages/drawing-ui/src/views/__tests__/DrawingTransformBehavior.spec.tsx b/packages/drawing-ui/src/views/__tests__/DrawingTransformBehavior.spec.tsx
index 3f8489a616..66350ac0e0 100644
--- a/packages/drawing-ui/src/views/__tests__/DrawingTransformBehavior.spec.tsx
+++ b/packages/drawing-ui/src/views/__tests__/DrawingTransformBehavior.spec.tsx
@@ -266,6 +266,46 @@ describe('DrawingTransform behavior', () => {
expect(renderManagerService.transformer.notificationCount).toBe(1);
});
+ it('disables rotation input for chart drawings', () => {
+ const drawing = {
+ ...createDrawing('chart-1'),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ };
+
+ const rendered = renderWithRediContext(univer.__getInjector(), drawing);
+ root = rendered.root;
+ container = rendered.container;
+
+ expect(inputInField(container, 'drawing-ui.image-panel.transform.rotate').disabled).toBe(true);
+ });
+
+ it('disables rotation input for groups containing chart drawings', () => {
+ const group = {
+ ...createDrawing('group-1'),
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ };
+ const chart = {
+ ...createDrawing('chart-child'),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: 'group-1',
+ };
+ drawingManagerService.registerDrawingData(unitId, {
+ [subUnitId]: {
+ data: {
+ [group.drawingId]: group,
+ [chart.drawingId]: chart,
+ },
+ order: [group.drawingId, chart.drawingId],
+ },
+ });
+
+ const rendered = renderWithRediContext(univer.__getInjector(), group);
+ root = rendered.root;
+ container = rendered.container;
+
+ expect(inputInField(container, 'drawing-ui.image-panel.transform.rotate').disabled).toBe(true);
+ });
+
it('clamps negative position inputs to the canvas origin', async () => {
const drawing = createDrawing('image-1');
const updates: IDrawingParam[][] = [];
diff --git a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
index 0b7685be8a..26f7f8eb3c 100644
--- a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
@@ -25,6 +25,8 @@ import { useDependency } from '@univerjs/ui';
import { useEffect, useState } from 'react';
import { MIN_DRAWING_HEIGHT_LIMIT, MIN_DRAWING_WIDTH_LIMIT, RANGE_DRAWING_ROTATION_LIMIT } from '../../utils/config';
import { getUpdateParams } from '../../utils/get-update-params';
+import { resolveDrawingUIRotateEnabled } from '../../utils/rotate-enabled';
+import { createDrawingTransformRotationChangeHandler, isDrawingTransformRotationDisabled } from './drawing-transform-rotation';
export interface IDrawingTransformProps {
transformShow: boolean;
@@ -80,6 +82,10 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
const [yPosition, setYPosition] = useState(originY);
const [rotation, setRotation] = useState(originRotation);
const [lockRatio, setLockRatio] = useState(transformer.keepRatio);
+ const rotateEnabled = resolveDrawingUIRotateEnabled(drawingParam, {
+ getChildren: (drawing) => drawingManagerService.getDrawingsByGroup(drawing),
+ });
+ const rotationDisabled = isDrawingTransformRotationDisabled(rotateEnabled);
const checkMoveBoundary = (left: number, top: number, width: number, height: number) => {
const { width: topSceneWidth, height: topSceneHeight } = topScene;
@@ -330,19 +336,13 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
transformer.refreshControls().changeNotification();
}, INPUT_DEBOUNCE_TIME);
- const handleRotationChange = (val: number | null) => {
- if (val == null) {
- return;
- }
-
- const updateParam: IDrawingParam = { unitId, subUnitId, drawingId, drawingType, transform: { angle: val } };
-
- setRotation(val);
-
- drawingManagerService.featurePluginUpdateNotification([updateParam]);
-
- transformer.refreshControls().changeNotification();
- };
+ const handleRotationChange = createDrawingTransformRotationChangeHandler({
+ rotateEnabled,
+ drawingParam: { unitId, subUnitId, drawingId, drawingType },
+ setRotation,
+ emitUpdate: (updateParams) => drawingManagerService.featurePluginUpdateNotification(updateParams),
+ notifyChange: () => transformer.refreshControls().changeNotification(),
+ });
const handleLockRatioChange = (val: string | number | boolean) => {
setLockRatio(val as boolean);
@@ -417,6 +417,7 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
value={rotation}
min={RANGE_DRAWING_ROTATION_LIMIT[0]}
max={RANGE_DRAWING_ROTATION_LIMIT[1]}
+ disabled={rotationDisabled}
onChange={handleRotationChange}
/>
</div>
diff --git a/packages/drawing-ui/src/views/panel/__tests__/drawing-transform-rotation.spec.ts b/packages/drawing-ui/src/views/panel/__tests__/drawing-transform-rotation.spec.ts
new file mode 100644
index 0000000000..8a4a80558d
--- /dev/null
+++ b/packages/drawing-ui/src/views/panel/__tests__/drawing-transform-rotation.spec.ts
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { DrawingTypeEnum } from '@univerjs/core';
+import { describe, expect, it, vi } from 'vitest';
+import { createDrawingTransformRotationChangeHandler, isDrawingTransformRotationDisabled } from '../drawing-transform-rotation';
+
+const drawingParam = {
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'drawing-1',
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
+};
+
+describe('drawing transform rotation controls', () => {
+ it('disables rotation and drops direct handler calls when rotation is not enabled', () => {
+ const setRotation = vi.fn();
+ const emitUpdate = vi.fn();
+ const notifyChange = vi.fn();
+ const handleRotationChange = createDrawingTransformRotationChangeHandler({
+ rotateEnabled: false,
+ drawingParam,
+ setRotation,
+ emitUpdate,
+ notifyChange,
+ });
+
+ expect(isDrawingTransformRotationDisabled(false)).toBe(true);
+
+ handleRotationChange(45);
+
+ expect(setRotation).not.toHaveBeenCalled();
+ expect(emitUpdate).not.toHaveBeenCalled();
+ expect(notifyChange).not.toHaveBeenCalled();
+ });
+
+ it('emits angle updates when rotation is enabled', () => {
+ const setRotation = vi.fn();
+ const emitUpdate = vi.fn();
+ const notifyChange = vi.fn();
+ const handleRotationChange = createDrawingTransformRotationChangeHandler({
+ rotateEnabled: true,
+ drawingParam,
+ setRotation,
+ emitUpdate,
+ notifyChange,
+ });
+
+ expect(isDrawingTransformRotationDisabled(true)).toBe(false);
+
+ handleRotationChange(45);
+
+ expect(setRotation).toHaveBeenCalledWith(45);
+ expect(emitUpdate).toHaveBeenCalledWith([{
+ ...drawingParam,
+ transform: {
+ angle: 45,
+ },
+ }]);
+ expect(notifyChange).toHaveBeenCalledTimes(1);
+ });
+
+ it('ignores null rotation updates even when rotation is enabled', () => {
+ const setRotation = vi.fn();
+ const emitUpdate = vi.fn();
+ const notifyChange = vi.fn();
+ const handleRotationChange = createDrawingTransformRotationChangeHandler({
+ rotateEnabled: true,
+ drawingParam,
+ setRotation,
+ emitUpdate,
+ notifyChange,
+ });
+
+ handleRotationChange(null);
+
+ expect(setRotation).not.toHaveBeenCalled();
+ expect(emitUpdate).not.toHaveBeenCalled();
+ expect(notifyChange).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/drawing-ui/src/views/panel/drawing-transform-rotation.ts b/packages/drawing-ui/src/views/panel/drawing-transform-rotation.ts
new file mode 100644
index 0000000000..ace27ae685
--- /dev/null
+++ b/packages/drawing-ui/src/views/panel/drawing-transform-rotation.ts
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IDrawingParam } from '@univerjs/core';
+
+interface IDrawingTransformRotationChangeHandlerOptions {
+ rotateEnabled: boolean;
+ drawingParam: Pick<IDrawingParam, 'unitId' | 'subUnitId' | 'drawingId' | 'drawingType'>;
+ setRotation: (rotation: number) => void;
+ emitUpdate: (updateParams: IDrawingParam[]) => void;
+ notifyChange: () => void;
+}
+
+export function isDrawingTransformRotationDisabled(rotateEnabled: boolean): boolean {
+ return !rotateEnabled;
+}
+
+export function createDrawingTransformRotationChangeHandler(options: IDrawingTransformRotationChangeHandlerOptions) {
+ return (val: number | null) => {
+ if (isDrawingTransformRotationDisabled(options.rotateEnabled)) {
+ return;
+ }
+
+ if (val == null) {
+ return;
+ }
+
+ const { unitId, subUnitId, drawingId, drawingType } = options.drawingParam;
+ const updateParam: IDrawingParam = { unitId, subUnitId, drawingId, drawingType, transform: { angle: val } };
+
+ options.setRotation(val);
+ options.emitUpdate([updateParam]);
+ options.notifyChange();
+ };
+}
diff --git a/packages/drawing/src/index.ts b/packages/drawing/src/index.ts
index e23a0c1848..53dbac8761 100644
--- a/packages/drawing/src/index.ts
+++ b/packages/drawing/src/index.ts
@@ -35,7 +35,11 @@ export type {
export { IDrawingManagerService } from './services/drawing-manager.service';
export { ImageIoService } from './services/image-io-impl.service';
export { URLImageService } from './services/url-image.service';
+export { createDrawingCopyPlan, DRAWING_COPY_CONTEXT_KEY, DRAWING_GROUPABLE_TYPES, getOrCreateDrawingCopyPlan, isGroupableDrawingType } from './utils/drawing-group';
+export type { ICreateDrawingCopyPlanOptions, IDrawingCopyPlan } from './utils/drawing-group';
export { getDrawingShapeKeyByDrawingSearch } from './utils/get-image-shape-key';
export { getImageSize } from './utils/get-image-size';
+export { resolveDrawingRotateEnabled } from './utils/rotate-enabled';
+export type { IDrawingRotateEnabledResolverOptions } from './utils/rotate-enabled';
export { IImageIoService, ImageSourceType, ImageUploadStatusType } from '@univerjs/core';
export type { IImageIoServiceParam } from '@univerjs/core';
diff --git a/packages/drawing/src/services/__tests__/drawing-manager-impl.service.spec.ts b/packages/drawing/src/services/__tests__/drawing-manager-impl.service.spec.ts
index 17c1f22b32..1db836fa95 100644
--- a/packages/drawing/src/services/__tests__/drawing-manager-impl.service.spec.ts
+++ b/packages/drawing/src/services/__tests__/drawing-manager-impl.service.spec.ts
@@ -16,7 +16,8 @@
import type { IDrawingParam, IDrawingSearch } from '@univerjs/core';
import { BooleanNumber, DrawingTypeEnum, Injector } from '@univerjs/core';
-import { beforeEach, describe, expect, it } from 'vitest';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { createDrawingCopyPlan, getOrCreateDrawingCopyPlan, isGroupableDrawingType } from '../../utils/drawing-group';
import { UnitDrawingService } from '../drawing-manager-impl.service';
const unitId = 'unit';
@@ -109,6 +110,177 @@ describe('UnitDrawingService', () => {
expect(service.getOldDrawingByParam(createSearch('b'))).toMatchObject(drawingB);
});
+ it('expands grouped remove operations to include all nested drawing records', () => {
+ service.applyJson1(unitId, subUnitId, service.getBatchAddOp([
+ createDrawing('group', { drawingType: DrawingTypeEnum.DRAWING_GROUP }),
+ createDrawing('image-child', { groupId: 'group' }),
+ createDrawing('chart-child', { drawingType: DrawingTypeEnum.DRAWING_CHART, groupId: 'group' }),
+ ]).redo);
+
+ const removeOp = service.getBatchRemoveOp([createSearch('group')]);
+
+ expect(removeOp.objects).toEqual([
+ createSearch('chart-child'),
+ createSearch('image-child'),
+ createSearch('group'),
+ ]);
+ });
+
+ it('keeps batch remove operations stable for empty drawing inputs', () => {
+ expect(service.getBatchRemoveOp([])).toMatchObject({
+ unitId: '',
+ subUnitId: '',
+ objects: [],
+ });
+ });
+
+ it('deduplicates expanded remove params for grouped, normal, and missing drawings', () => {
+ service.applyJson1(unitId, subUnitId, service.getBatchAddOp([
+ createDrawing('group', { drawingType: DrawingTypeEnum.DRAWING_GROUP }),
+ createDrawing('image'),
+ ]).redo);
+ vi.spyOn(service, 'getDrawingsByGroupNested').mockReturnValue(null);
+
+ const expanded = (service as unknown as {
+ _getExpandedBatchRemoveParams: (removeParams: IDrawingSearch[]) => IDrawingSearch[];
+ })._getExpandedBatchRemoveParams([
+ createSearch('group'),
+ createSearch('group'),
+ createSearch('image'),
+ createSearch('image'),
+ createSearch('missing'),
+ createSearch('missing'),
+ ]);
+
+ expect(expanded).toEqual([
+ createSearch('group'),
+ createSearch('image'),
+ createSearch('missing'),
+ ]);
+ });
+
+ it('creates one copy id map for group children and chart drawings', () => {
+ let nextId = 0;
+ const plan = createDrawingCopyPlan([
+ createDrawing('group', { drawingType: DrawingTypeEnum.DRAWING_GROUP }),
+ createDrawing('image-child', { groupId: 'group' }),
+ createDrawing('chart-child', { drawingType: DrawingTypeEnum.DRAWING_CHART, groupId: 'group' }),
+ ], {
+ unitId,
+ sourceSubUnitId: subUnitId,
+ targetSubUnitId: 'copied-sheet',
+ generateId: () => `copy-${nextId++}`,
+ });
+
+ expect(plan.idMap.size).toBe(3);
+ expect(plan.idMap.get('group')).toBe('copy-0');
+ expect(plan.idMap.get('image-child')).toBe('copy-1');
+ expect(plan.idMap.get('chart-child')).toBe('copy-2');
+ expect(plan.drawings).toEqual([
+ expect.objectContaining({ drawingId: 'copy-0', subUnitId: 'copied-sheet' }),
+ expect.objectContaining({ drawingId: 'copy-1', groupId: 'copy-0', subUnitId: 'copied-sheet' }),
+ expect.objectContaining({ drawingId: 'copy-2', groupId: 'copy-0', subUnitId: 'copied-sheet' }),
+ ]);
+ });
+
+ it('keeps copied drawing unchanged when the id map cannot resolve its current id', () => {
+ let readCount = 0;
+ const dynamicDrawing = {
+ ...createDrawing('registered-id'),
+ get drawingId() {
+ readCount += 1;
+ return readCount <= 2 ? 'registered-id' : 'unmapped-id';
+ },
+ } as IDrawingParam;
+
+ const plan = createDrawingCopyPlan([dynamicDrawing], {
+ unitId,
+ sourceSubUnitId: subUnitId,
+ targetSubUnitId: 'copied-sheet',
+ generateId: () => 'copy-0',
+ });
+
+ expect(plan.idMap.get('registered-id')).toBe('copy-0');
+ expect(plan.drawings[0]).toEqual(expect.objectContaining({
+ drawingId: 'unmapped-id',
+ subUnitId,
+ }));
+ });
+
+ it('creates uncached copy plans and reuses cached complete copy plans', () => {
+ let nextId = 0;
+ const options = {
+ unitId,
+ sourceSubUnitId: subUnitId,
+ targetSubUnitId: 'copied-sheet',
+ generateId: () => `copy-${nextId++}`,
+ };
+ const child = createDrawing('child', { groupId: 'missing-group' });
+ const uncachedPlan = getOrCreateDrawingCopyPlan(undefined, [child], options);
+
+ expect(isGroupableDrawingType(DrawingTypeEnum.DRAWING_TABLE)).toBe(false);
+ expect(uncachedPlan.drawings[0]).toEqual(expect.objectContaining({
+ drawingId: 'copy-0',
+ subUnitId: 'copied-sheet',
+ }));
+ expect(uncachedPlan.drawings[0].groupId).toBeUndefined();
+
+ const copyContext = new Map<string, unknown>();
+ const cachedPlan = getOrCreateDrawingCopyPlan(copyContext, [child], options);
+
+ expect(getOrCreateDrawingCopyPlan(copyContext, [child], options)).toBe(cachedPlan);
+ });
+
+ it('extends a cached copy plan with the default id generator when no generator is provided', () => {
+ const options = {
+ unitId,
+ sourceSubUnitId: subUnitId,
+ targetSubUnitId: 'copied-sheet',
+ };
+ const copyContext = new Map<string, unknown>();
+ const firstPlan = getOrCreateDrawingCopyPlan(copyContext, [createDrawing('child-1')], options);
+
+ const extendedPlan = getOrCreateDrawingCopyPlan(copyContext, [
+ createDrawing('child-1'),
+ createDrawing('child-2'),
+ ], options);
+
+ expect(extendedPlan).toBe(firstPlan);
+ expect(extendedPlan.idMap.has('child-2')).toBe(true);
+ expect(extendedPlan.drawings.map((drawing) => drawing.subUnitId)).toEqual(['copied-sheet', 'copied-sheet']);
+ });
+
+ it('extends a cached copy plan when a later caller provides more drawing graph nodes', () => {
+ let nextId = 0;
+ const copyContext = new Map<string, unknown>();
+ const options = {
+ unitId,
+ sourceSubUnitId: subUnitId,
+ targetSubUnitId: 'copied-sheet',
+ generateId: () => `copy-${nextId++}`,
+ };
+ const chart = createDrawing('chart-child', { drawingType: DrawingTypeEnum.DRAWING_CHART, groupId: 'group' });
+ const firstPlan = getOrCreateDrawingCopyPlan(copyContext, [chart], options);
+
+ expect(firstPlan.drawings[0].groupId).toBeUndefined();
+
+ const extendedPlan = getOrCreateDrawingCopyPlan(copyContext, [
+ createDrawing('group', { drawingType: DrawingTypeEnum.DRAWING_GROUP }),
+ createDrawing('image-child', { groupId: 'group' }),
+ chart,
+ ], options);
+
+ expect(extendedPlan).toBe(firstPlan);
+ expect(extendedPlan.idMap.get('chart-child')).toBe('copy-0');
+ expect(extendedPlan.idMap.get('group')).toBe('copy-1');
+ expect(extendedPlan.idMap.get('image-child')).toBe('copy-2');
+ expect(extendedPlan.drawings).toEqual([
+ expect.objectContaining({ drawingId: 'copy-1', subUnitId: 'copied-sheet' }),
+ expect.objectContaining({ drawingId: 'copy-2', groupId: 'copy-1', subUnitId: 'copied-sheet' }),
+ expect.objectContaining({ drawingId: 'copy-0', groupId: 'copy-1', subUnitId: 'copied-sheet' }),
+ ]);
+ });
+
it('should manage focus, refresh and visibility notifications', () => {
const focused: IDrawingParam[][] = [];
const refreshed: IDrawingParam[][] = [];
diff --git a/packages/drawing/src/services/drawing-manager-impl.service.ts b/packages/drawing/src/services/drawing-manager-impl.service.ts
index e547d08be9..6dc5257c20 100644
--- a/packages/drawing/src/services/drawing-manager-impl.service.ts
+++ b/packages/drawing/src/services/drawing-manager-impl.service.ts
@@ -255,11 +255,25 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawing
return this.getBatchRemoveOp(removeParams);
}
- getBatchRemoveOp(removeParams: IDrawingSearch[]): IDrawingJsonUndo1 {
- // Expand group drawings to include all nested group nodes and leaf children.
- // Non-group drawings are kept as-is.
+ private _getExpandedBatchRemoveParams(removeParams: IDrawingSearch[]): IDrawingSearch[] {
const seenIds = new Set<string>();
const allToRemove: IDrawingSearch[] = [];
+ const addDrawing = (drawing: IDrawingParam) => {
+ if (seenIds.has(drawing.drawingId)) {
+ return;
+ }
+
+ seenIds.add(drawing.drawingId);
+ allToRemove.push({ unitId: drawing.unitId, subUnitId: drawing.subUnitId, drawingId: drawing.drawingId });
+ };
+ const addSearch = (search: IDrawingSearch) => {
+ if (seenIds.has(search.drawingId)) {
+ return;
+ }
+
+ seenIds.add(search.drawingId);
+ allToRemove.push(search);
+ };
removeParams.forEach((removeParam) => {
const drawing = this.getDrawingByParam(removeParam);
if (drawing?.drawingType === DrawingTypeEnum.DRAWING_GROUP) {
@@ -267,22 +281,29 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawing
if (nested) {
const { flatChildren, groups } = nested;
[...(flatChildren ?? []), ...groups].forEach((d) => {
- if (!seenIds.has(d.drawingId)) {
- seenIds.add(d.drawingId);
- allToRemove.push({ unitId: d.unitId, subUnitId: d.subUnitId, drawingId: d.drawingId });
- }
+ addDrawing(d);
});
- } else if (!seenIds.has(removeParam.drawingId)) {
- seenIds.add(removeParam.drawingId);
- allToRemove.push(removeParam);
+ } else {
+ addDrawing(drawing);
}
- } else if (!seenIds.has(removeParam.drawingId)) {
- seenIds.add(removeParam.drawingId);
- allToRemove.push(removeParam);
+ } else if (drawing) {
+ addDrawing(drawing);
+ } else {
+ addSearch(removeParam);
}
});
- const { unitId, subUnitId } = allToRemove[0] ?? removeParams[0];
+ return allToRemove;
+ }
+
+ getBatchRemoveOp(removeParams: IDrawingSearch[]): IDrawingJsonUndo1 {
+ // Expand group drawings to include all nested group nodes and leaf children.
+ // Non-group drawings are kept as-is.
+ const allToRemove = this._getExpandedBatchRemoveParams(removeParams);
+ const { unitId, subUnitId } = allToRemove[0] ?? removeParams[0] ?? { unitId: '', subUnitId: '' };
+ if (allToRemove.length === 0) {
+ return { undo: null as unknown as JSONOp, redo: null as unknown as JSONOp, unitId, subUnitId, objects: [] };
+ }
// Sort ascending by order index so that, with the unshift trick below,
// composition applies removals from highest index to lowest (back-to-front).
diff --git a/packages/drawing/src/utils/__tests__/rotate-enabled.spec.ts b/packages/drawing/src/utils/__tests__/rotate-enabled.spec.ts
new file mode 100644
index 0000000000..83c7d32d5f
--- /dev/null
+++ b/packages/drawing/src/utils/__tests__/rotate-enabled.spec.ts
@@ -0,0 +1,107 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IDrawingParam } from '@univerjs/core';
+import { DrawingTypeEnum } from '@univerjs/core';
+import { describe, expect, it } from 'vitest';
+import { resolveDrawingRotateEnabled } from '../rotate-enabled';
+
+const unitId = 'unit-1';
+const subUnitId = 'sheet-1';
+
+function createDrawing(drawingId: string, drawingType = DrawingTypeEnum.DRAWING_IMAGE, rotateEnabled?: boolean): IDrawingParam {
+ return {
+ unitId,
+ subUnitId,
+ drawingId,
+ drawingType,
+ transform: {
+ left: 0,
+ top: 0,
+ width: 10,
+ height: 10,
+ rotateEnabled,
+ },
+ };
+}
+
+function createGroup(drawingId: string, rotateEnabled?: boolean): IDrawingParam {
+ return createDrawing(drawingId, DrawingTypeEnum.DRAWING_GROUP, rotateEnabled);
+}
+
+describe('resolveDrawingRotateEnabled', () => {
+ it('keeps a group rotatable when all descendants are rotatable', () => {
+ const group = createGroup('group');
+ const child = createDrawing('shape');
+
+ expect(resolveDrawingRotateEnabled(group, {
+ getChildren: (drawing) => drawing.drawingId === 'group' ? [child] : undefined,
+ })).toBe(true);
+ });
+
+ it('disables a group when a nested descendant cannot rotate', () => {
+ const root = createGroup('root');
+ const nested = createGroup('nested');
+ const child = createDrawing('shape', DrawingTypeEnum.DRAWING_SHAPE, false);
+
+ expect(resolveDrawingRotateEnabled(root, {
+ getChildren: (drawing) => {
+ if (drawing.drawingId === 'root') return [nested];
+ if (drawing.drawingId === 'nested') return [child];
+ return undefined;
+ },
+ })).toBe(false);
+ });
+
+ it('recomputes a stale group rotate flag from resolvable descendants', () => {
+ const group = createGroup('group', false);
+ const child = createDrawing('shape');
+
+ expect(resolveDrawingRotateEnabled(group, {
+ getChildren: (drawing) => drawing.drawingId === 'group' ? [child] : undefined,
+ })).toBe(true);
+ });
+
+ it('falls back to a group persisted rotate flag when children cannot be resolved', () => {
+ expect(resolveDrawingRotateEnabled(createGroup('group', false))).toBe(false);
+ });
+
+ it('uses known non-rotatable drawing types for old data without rotate flags', () => {
+ const group = createGroup('group');
+ const chart = createDrawing('chart', DrawingTypeEnum.DRAWING_CHART);
+
+ expect(resolveDrawingRotateEnabled(group, {
+ getChildren: (drawing) => drawing.drawingId === 'group' ? [chart] : undefined,
+ isKnownNonRotatableType: (drawingType) => drawingType === DrawingTypeEnum.DRAWING_CHART,
+ })).toBe(false);
+ });
+
+ it('keeps cyclic group graphs rotatable instead of recursing forever', () => {
+ const group = createGroup('group');
+
+ expect(resolveDrawingRotateEnabled(group, {
+ getChildren: () => [group],
+ })).toBe(true);
+ });
+
+ it('uses render object transformer config as a runtime rotation guard', () => {
+ const shape = createDrawing('shape');
+
+ expect(resolveDrawingRotateEnabled(shape, {
+ getRenderObject: () => ({ transformerConfig: { rotateEnabled: false } }),
+ })).toBe(false);
+ });
+});
diff --git a/packages/drawing/src/utils/drawing-group.ts b/packages/drawing/src/utils/drawing-group.ts
new file mode 100644
index 0000000000..7f3fb485a0
--- /dev/null
+++ b/packages/drawing/src/utils/drawing-group.ts
@@ -0,0 +1,136 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { DrawingType, IDrawingParam } from '@univerjs/core';
+import { DrawingTypeEnum, generateRandomId } from '@univerjs/core';
+
+export const DRAWING_GROUPABLE_TYPES = [
+ DrawingTypeEnum.DRAWING_IMAGE,
+ DrawingTypeEnum.DRAWING_SHAPE,
+ DrawingTypeEnum.DRAWING_CHART,
+ DrawingTypeEnum.DRAWING_GROUP,
+] as const;
+
+export function isGroupableDrawingType(type: DrawingType): boolean {
+ return (DRAWING_GROUPABLE_TYPES as readonly DrawingType[]).includes(type);
+}
+
+export const DRAWING_COPY_CONTEXT_KEY = 'univer.drawing.copy-plan';
+
+export interface ICreateDrawingCopyPlanOptions {
+ unitId: string;
+ sourceSubUnitId: string;
+ targetSubUnitId: string;
+ generateId?: () => string;
+}
+
+export interface IDrawingCopyPlan<T extends IDrawingParam = IDrawingParam> {
+ idMap: Map<string, string>;
+ drawings: T[];
+}
+
+function cloneDrawing<T extends IDrawingParam>(drawing: T): T {
+ return JSON.parse(JSON.stringify(drawing)) as T;
+}
+
+function copyDrawingWithIdMap<T extends IDrawingParam>(
+ drawing: T,
+ idMap: Map<string, string>,
+ options: ICreateDrawingCopyPlanOptions
+): T {
+ const copied = cloneDrawing(drawing);
+ const copiedDrawingId = idMap.get(drawing.drawingId);
+
+ if (copiedDrawingId == null) {
+ return copied;
+ }
+
+ copied.unitId = options.unitId;
+ copied.subUnitId = options.targetSubUnitId;
+ copied.drawingId = copiedDrawingId;
+
+ if (copied.groupId) {
+ const copiedGroupId = idMap.get(copied.groupId);
+ if (copiedGroupId) {
+ copied.groupId = copiedGroupId;
+ } else {
+ delete copied.groupId;
+ }
+ }
+
+ return copied;
+}
+
+export function createDrawingCopyPlan<T extends IDrawingParam>(
+ drawings: readonly T[],
+ options: ICreateDrawingCopyPlanOptions
+): IDrawingCopyPlan<T> {
+ const { generateId = () => generateRandomId(10) } = options;
+ const idMap = new Map<string, string>();
+
+ drawings.forEach((drawing) => {
+ if (!idMap.has(drawing.drawingId)) {
+ idMap.set(drawing.drawingId, generateId());
+ }
+ });
+
+ return {
+ idMap,
+ drawings: drawings.map((drawing) => copyDrawingWithIdMap(drawing, idMap, options)),
+ };
+}
+
+export function getOrCreateDrawingCopyPlan<T extends IDrawingParam>(
+ copyContext: Map<string, unknown> | undefined,
+ drawings: readonly T[],
+ options: ICreateDrawingCopyPlanOptions
+): IDrawingCopyPlan<T> {
+ if (copyContext == null) {
+ return createDrawingCopyPlan(drawings, options);
+ }
+
+ const cached = copyContext.get(DRAWING_COPY_CONTEXT_KEY) as IDrawingCopyPlan<T> | undefined;
+ if (cached) {
+ const { generateId = () => generateRandomId(10) } = options;
+ const hasMissingDrawing = drawings.some((drawing) => !cached.idMap.has(drawing.drawingId));
+ if (!hasMissingDrawing) {
+ return cached;
+ }
+
+ drawings.forEach((drawing) => {
+ if (!cached.idMap.has(drawing.drawingId)) {
+ cached.idMap.set(drawing.drawingId, generateId());
+ }
+ });
+
+ const incomingDrawingIds = new Set(drawings.map((drawing) => drawing.drawingId));
+ const originalIdByCopiedId = new Map(Array.from(cached.idMap.entries()).map(([drawingId, copiedDrawingId]) => [copiedDrawingId, drawingId]));
+ const retainedDrawings = cached.drawings.filter((drawing) => {
+ const originalDrawingId = originalIdByCopiedId.get(drawing.drawingId);
+ return originalDrawingId == null || !incomingDrawingIds.has(originalDrawingId);
+ });
+
+ cached.drawings = [
+ ...drawings.map((drawing) => copyDrawingWithIdMap(drawing, cached.idMap, options)),
+ ...retainedDrawings,
+ ];
+ return cached;
+ }
+
+ const plan = createDrawingCopyPlan(drawings, options);
+ copyContext.set(DRAWING_COPY_CONTEXT_KEY, plan);
+ return plan;
+}
diff --git a/packages/drawing/src/utils/rotate-enabled.ts b/packages/drawing/src/utils/rotate-enabled.ts
new file mode 100644
index 0000000000..d525942360
--- /dev/null
+++ b/packages/drawing/src/utils/rotate-enabled.ts
@@ -0,0 +1,70 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { DrawingType, IDrawingParam } from '@univerjs/core';
+import { DrawingTypeEnum } from '@univerjs/core';
+
+interface IRotateRenderObject {
+ transformerConfig?: {
+ rotateEnabled?: boolean;
+ };
+}
+
+export interface IDrawingRotateEnabledResolverOptions {
+ getChildren?: (drawing: IDrawingParam) => readonly IDrawingParam[] | null | undefined;
+ getRenderObject?: (drawing: IDrawingParam) => IRotateRenderObject | null | undefined;
+ isKnownNonRotatableType?: (drawingType: DrawingType) => boolean;
+}
+
+function getDrawingKey(drawing: IDrawingParam): string {
+ return `${drawing.unitId}\u0000${drawing.subUnitId}\u0000${drawing.drawingId}`;
+}
+
+export function resolveDrawingRotateEnabled(
+ drawing: IDrawingParam,
+ options: IDrawingRotateEnabledResolverOptions = {},
+ visiting = new Set<string>()
+): boolean {
+ const drawingKey = getDrawingKey(drawing);
+ if (visiting.has(drawingKey)) {
+ return true;
+ }
+
+ if (drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP) {
+ visiting.add(drawingKey);
+ const children = options.getChildren?.(drawing);
+ if (children != null) {
+ const enabled = children.every((child) => resolveDrawingRotateEnabled(child, options, visiting));
+ visiting.delete(drawingKey);
+ return enabled;
+ }
+ visiting.delete(drawingKey);
+ }
+
+ if (drawing.transform?.rotateEnabled === false) {
+ return false;
+ }
+
+ if (options.getRenderObject?.(drawing)?.transformerConfig?.rotateEnabled === false) {
+ return false;
+ }
+
+ if (options.isKnownNonRotatableType?.(drawing.drawingType)) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/packages/sheets-drawing-ui/src/controllers/__tests__/sheet-drawing-update.controller.spec.ts b/packages/sheets-drawing-ui/src/controllers/__tests__/sheet-drawing-update.controller.spec.ts
index 148f0018a1..431a4c50ef 100644
--- a/packages/sheets-drawing-ui/src/controllers/__tests__/sheet-drawing-update.controller.spec.ts
+++ b/packages/sheets-drawing-ui/src/controllers/__tests__/sheet-drawing-update.controller.spec.ts
@@ -72,6 +72,7 @@ function createController(options?: { openFiles?: unknown[] }) {
to: { row: 3, column: 4, rowOffset: 0, columnOffset: 0 },
},
})),
+ getDrawingsByGroup: vi.fn(() => []),
focusDrawing: vi.fn(),
};
const selectionManagerService = {
@@ -195,6 +196,7 @@ describe('SheetDrawingUpdateController', () => {
unitId: 'unit-1',
subUnitId: 'sheet-1',
drawingId: 'image-1',
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
transform: { left: 10, top: 20, width: 30, height: 40 },
};
@@ -237,4 +239,49 @@ describe('SheetDrawingUpdateController', () => {
controller.dispose();
});
+
+ it('does not persist derived group rotateEnabled before grouping', () => {
+ const {
+ controller,
+ commandService,
+ featurePluginGroupUpdate$,
+ } = createController();
+ const parent = {
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 0, top: 0, width: 80, height: 40 },
+ };
+ const children = [
+ {
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'image-1',
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
+ transform: { left: 10, top: 20, width: 30, height: 40 },
+ },
+ {
+ unitId: 'unit-1',
+ subUnitId: 'sheet-1',
+ drawingId: 'chart-1',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ transform: { left: 40, top: 20, width: 30, height: 40 },
+ },
+ ];
+
+ featurePluginGroupUpdate$.next([{ parent, children }]);
+
+ expect(commandService.executeCommand).toHaveBeenCalledWith(GroupSheetDrawingCommand.id, [
+ expect.objectContaining({
+ parent: expect.objectContaining({
+ drawingId: 'group-1',
+ }),
+ }),
+ ]);
+ const groupCommandParams = commandService.executeCommand.mock.calls.find(([commandId]) => commandId === GroupSheetDrawingCommand.id)?.[1] as any[];
+ expect(Object.prototype.hasOwnProperty.call(groupCommandParams[0].parent.transform ?? {}, 'rotateEnabled')).toBe(false);
+
+ controller.dispose();
+ });
});
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
index 5187c6f0dd..2cf813449f 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
@@ -684,7 +684,8 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
const grpParams = [];
for (const param of params) {
- const grpSheetTransform = this._getSheetTransformByParam(param.parent, true);
+ const parent = param.parent;
+ const grpSheetTransform = this._getSheetTransformByParam(parent, true);
const children = [];
for (const child of param.children) {
@@ -699,7 +700,7 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
}
const grpParam = {
- parent: { ...param.parent, sheetTransform: grpSheetTransform?.sheetTransform, axisAlignSheetTransform: grpSheetTransform?.axisAlignSheetTransform },
+ parent: { ...parent, sheetTransform: grpSheetTransform?.sheetTransform, axisAlignSheetTransform: grpSheetTransform?.axisAlignSheetTransform },
children,
};
diff --git a/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.ts b/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.ts
index 6178f338d9..aaee96d5e5 100644
--- a/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.ts
+++ b/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.ts
@@ -251,6 +251,7 @@ class TestRenderScene {
}
addObject(object: Rect) {
+ object.parent = this as never;
this._objects.set(object.oKey, object);
}
@@ -262,6 +263,10 @@ class TestRenderScene {
return this._objects.get(key);
}
+ getObjectIncludeInGroup(key: string) {
+ return this.getObject(key);
+ }
+
attachTransformerTo() { }
detachTransformerFrom() { }
diff --git a/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.ts b/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.ts
index 613458a005..a1b330bf35 100644
--- a/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.ts
+++ b/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.ts
@@ -17,7 +17,7 @@
import type { IWorkbookData } from '@univerjs/core';
import type { IRender, IRenderManagerService as IRenderManagerServiceType, Scene } from '@univerjs/engine-render';
import type { IFloatDom, IFloatDomLayout } from '@univerjs/ui';
-import type { ICanvasFloatDomInfo } from '../canvas-float-dom-manager.service';
+import type { ICanvasFloatDomInfo, ISheetFloatDomRenderObjectFactoryContext } from '../canvas-float-dom-manager.service';
import {
BooleanNumber,
Disposable,
@@ -29,11 +29,11 @@ import {
UniverInstanceType,
} from '@univerjs/core';
import { IRenderManagerService, Rect, SHEET_VIEWPORT_KEY, SpreadsheetSkeleton } from '@univerjs/engine-render';
-import { ISheetDrawingService, RemoveSheetDrawingCommand, SetSheetDrawingCommand } from '@univerjs/sheets-drawing';
+import { InsertSheetDrawingCommand, ISheetDrawingService, RemoveSheetDrawingCommand, SetSheetDrawingCommand } from '@univerjs/sheets-drawing';
import { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { CanvasFloatDomService } from '@univerjs/ui';
import { BehaviorSubject, Subject } from 'rxjs';
-import { afterEach, describe, expect, it } from 'vitest';
+import { afterEach, describe, expect, it, vi } from 'vitest';
import { createSheetsDrawingUiTestBed } from '../../__tests__/create-sheets-drawing-ui-test-bed';
import {
calcSheetFloatDomPosition,
@@ -186,8 +186,8 @@ class TestRenderScene {
readonly canvasEvents: string[] = [];
readonly onScrollAfter$ = new EventSubject();
private readonly _transformer = {
- clearControlByIds: () => undefined,
- clearSelectedObjects: () => undefined,
+ clearControlByIds: vi.fn(),
+ clearSelectedObjects: vi.fn(),
};
constructor(private readonly _viewport: {
@@ -222,15 +222,29 @@ class TestRenderScene {
return this._transformer;
}
- addObject(object: Rect) {
+ addObject(object: Rect): this {
+ object.parent = this as never;
this._objects.set(object.oKey, object);
+ return this;
}
- removeObject(object: Rect) {
- this._objects.delete(object.oKey);
+ removeObject(object: Rect | string) {
+ this._objects.delete(typeof object === 'string' ? object : object.oKey);
}
getObject(key: string) {
+ const object = this._objects.get(key);
+ return object && !object.isInGroup ? object : undefined;
+ }
+
+ getObjectIncludeInGroup(key: string) {
+ for (const item of this._objects.values()) {
+ const child = findChildObject(item, key);
+ if (child) {
+ return child;
+ }
+ }
+
return this._objects.get(key);
}
@@ -245,6 +259,23 @@ class TestRenderScene {
}
}
+function findChildObject(object: unknown, key: string): Rect | undefined {
+ const getObjects = (object as { getObjects?: () => Rect[] } | undefined)?.getObjects;
+ if (!getObjects) {
+ return;
+ }
+
+ for (const child of getObjects.call(object)) {
+ if (child.oKey === key) {
+ return child;
+ }
+ const nested = findChildObject(child, key);
+ if (nested) {
+ return nested;
+ }
+ }
+}
+
function createRender(skeleton: SpreadsheetSkeleton, scene: Scene): IRender {
const sheetSkeletonManager = new TestSheetSkeletonManager(skeleton);
const sheetSelectionRenderService = new TestSheetSelectionRenderService();
@@ -581,6 +612,438 @@ describe('SheetCanvasFloatDomManagerService', () => {
expect(findFloatDom(canvasFloatDomService, 'header-card')).toBeUndefined();
});
+ it('uses the registered render object factory for chart float dom rects without affecting normal float doms', () => {
+ const fixture = setup();
+ disposables.push(fixture);
+ const contexts: ISheetFloatDomRenderObjectFactoryContext[] = [];
+
+ class TestChartRect extends Rect {
+ readonly createdByChartFactory = true;
+ }
+
+ const disposable = fixture.manager.registerRenderObjectFactory(DrawingTypeEnum.DRAWING_CHART, (context) => {
+ contexts.push(context);
+ return new TestChartRect(context.key, context.config);
+ });
+
+ fixture.manager.addFloatDomToRange({
+ startRow: 1,
+ endRow: 2,
+ startColumn: 1,
+ endColumn: 2,
+ }, {
+ componentKey: 'RegularCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ allowTransform: true,
+ }, {
+ width: 80,
+ height: 24,
+ }, 'regular-card')!;
+
+ const chartDom = fixture.manager.addFloatDomToRange({
+ startRow: 3,
+ endRow: 4,
+ startColumn: 3,
+ endColumn: 4,
+ }, {
+ componentKey: 'ChartCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ data: { label: 'Revenue', backgroundColor: '#ffffff', border: '#111111' },
+ allowTransform: true,
+ type: DrawingTypeEnum.DRAWING_CHART,
+ }, {
+ width: 120,
+ height: 72,
+ }, 'chart-card')!;
+
+ const regularRect = fixture.manager.getFloatDomInfo('regular-card')?.rect;
+ const chartRect = fixture.manager.getFloatDomInfo('chart-card')?.rect;
+
+ expect(regularRect).toBeInstanceOf(Rect);
+ expect(regularRect).not.toBeInstanceOf(TestChartRect);
+ expect(chartRect).toBeInstanceOf(TestChartRect);
+ expect((chartRect as TestChartRect).createdByChartFactory).toBe(true);
+ expect(contexts).toEqual([
+ expect.objectContaining({
+ key: 'test#-#sheet1#-#chart-card',
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-card',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ data: { label: 'Revenue', backgroundColor: '#ffffff', border: '#111111' },
+ config: expect.objectContaining({
+ fill: '#ffffff',
+ stroke: '#111111',
+ radius: 8,
+ }),
+ }),
+ ]);
+
+ disposable.dispose();
+ chartDom.dispose();
+ fixture.manager.removeFloatDom('regular-card');
+ });
+
+ it('uses chart data background as the canvas rect fill', () => {
+ const fixture = setup();
+ disposables.push(fixture);
+
+ const chartDom = fixture.manager.addFloatDomToRange({
+ startRow: 3,
+ endRow: 4,
+ startColumn: 3,
+ endColumn: 4,
+ }, {
+ componentKey: 'ChartCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ data: { label: 'Revenue', background: '#f5ead7', border: '#111111' },
+ allowTransform: true,
+ type: DrawingTypeEnum.DRAWING_CHART,
+ }, {
+ width: 120,
+ height: 72,
+ }, 'chart-card')!;
+
+ const chartRect = fixture.manager.getFloatDomInfo('chart-card')?.rect;
+
+ expect(chartRect?.fill).toBe('#f5ead7');
+ expect(chartRect?.stroke).toBe('#111111');
+
+ chartDom.dispose();
+ });
+
+ it('falls back to the default rect after a chart render object factory is disposed', () => {
+ const fixture = setup();
+ disposables.push(fixture);
+
+ class TestChartRect extends Rect { }
+
+ const disposable = fixture.manager.registerRenderObjectFactory(DrawingTypeEnum.DRAWING_CHART, ({ key, config }) => new TestChartRect(key, config));
+ disposable.dispose();
+
+ const chartDom = fixture.manager.addFloatDomToRange({
+ startRow: 3,
+ endRow: 4,
+ startColumn: 3,
+ endColumn: 4,
+ }, {
+ componentKey: 'ChartCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ allowTransform: true,
+ type: DrawingTypeEnum.DRAWING_CHART,
+ }, {
+ width: 120,
+ height: 72,
+ }, 'chart-card')!;
+
+ expect(fixture.manager.getFloatDomInfo('chart-card')?.rect).toBeInstanceOf(Rect);
+ expect(fixture.manager.getFloatDomInfo('chart-card')?.rect).not.toBeInstanceOf(TestChartRect);
+
+ chartDom.dispose();
+ });
+
+ it('uses the latest registered render object factory and restores previous factories after dispose', () => {
+ const fixture = setup();
+ disposables.push(fixture);
+
+ class FirstChartRect extends Rect { }
+ class SecondChartRect extends Rect { }
+
+ const firstDisposable = fixture.manager.registerRenderObjectFactory(DrawingTypeEnum.DRAWING_CHART, ({ key, config }) => new FirstChartRect(key, config));
+ const secondDisposable = fixture.manager.registerRenderObjectFactory(DrawingTypeEnum.DRAWING_CHART, ({ key, config }) => new SecondChartRect(key, config));
+
+ const firstChartDom = fixture.manager.addFloatDomToRange({
+ startRow: 3,
+ endRow: 4,
+ startColumn: 3,
+ endColumn: 4,
+ }, {
+ componentKey: 'ChartCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ allowTransform: true,
+ type: DrawingTypeEnum.DRAWING_CHART,
+ }, {
+ width: 120,
+ height: 72,
+ }, 'chart-card-second')!;
+
+ expect(fixture.manager.getFloatDomInfo('chart-card-second')?.rect).toBeInstanceOf(SecondChartRect);
+ firstChartDom.dispose();
+
+ secondDisposable.dispose();
+ const secondChartDom = fixture.manager.addFloatDomToRange({
+ startRow: 3,
+ endRow: 4,
+ startColumn: 3,
+ endColumn: 4,
+ }, {
+ componentKey: 'ChartCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ allowTransform: true,
+ type: DrawingTypeEnum.DRAWING_CHART,
+ }, {
+ width: 120,
+ height: 72,
+ }, 'chart-card-first')!;
+
+ expect(fixture.manager.getFloatDomInfo('chart-card-first')?.rect).toBeInstanceOf(FirstChartRect);
+ secondChartDom.dispose();
+
+ firstDisposable.dispose();
+ const fallbackChartDom = fixture.manager.addFloatDomToRange({
+ startRow: 3,
+ endRow: 4,
+ startColumn: 3,
+ endColumn: 4,
+ }, {
+ componentKey: 'ChartCard',
+ initPosition: { startX: 0, startY: 0, endX: 0, endY: 0 },
+ allowTransform: true,
+ type: DrawingTypeEnum.DRAWING_CHART,
+ }, {
+ width: 120,
+ height: 72,
+ }, 'chart-card-fallback')!;
+
+ expect(fixture.manager.getFloatDomInfo('chart-card-fallback')?.rect).toBeInstanceOf(Rect);
+ expect(fixture.manager.getFloatDomInfo('chart-card-fallback')?.rect).not.toBeInstanceOf(FirstChartRect);
+ fallbackChartDom.dispose();
+ });
+
+ it('inserts grouped chart float dom render objects into the sheet group hierarchy', async () => {
+ const fixture = setup();
+ disposables.push(fixture);
+ const sheetDrawingService = fixture.get(ISheetDrawingService);
+
+ await fixture.commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ groupBaseBound: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ componentKey: 'ChartCard',
+ data: { label: 'Grouped chart' },
+ groupId: 'group-1',
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ ],
+ });
+
+ expect(sheetDrawingService.getDrawingByParam({
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ })?.groupId).toBe('group-1');
+
+ const chartRect = fixture.manager.getFloatDomInfo('chart-in-group')?.rect;
+ const groupObject = (fixture.scene as unknown as TestRenderScene).getObject('test#-#sheet1#-#group-1') as { getObjects?: () => Array<{ oKey: string }> } | undefined;
+
+ expect(chartRect?.oKey).toBe('test#-#sheet1#-#chart-in-group');
+ expect((fixture.scene as unknown as TestRenderScene).getObject('test#-#sheet1#-#chart-in-group')).toBeUndefined();
+ expect((fixture.scene as unknown as TestRenderScene).getObjectIncludeInGroup('test#-#sheet1#-#chart-in-group')).toBe(chartRect);
+ expect(groupObject?.getObjects?.().map((object) => object.oKey)).toContain('test#-#sheet1#-#chart-in-group');
+ });
+
+ it('removes grouped active chart float dom runtime state and render object', async () => {
+ const fixture = setup();
+ disposables.push(fixture);
+ const canvasFloatDomService = fixture.get(CanvasFloatDomService);
+ const scene = fixture.scene as unknown as TestRenderScene;
+
+ await fixture.commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ groupBaseBound: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ componentKey: 'ChartCard',
+ data: { label: 'Grouped chart' },
+ groupId: 'group-1',
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ ],
+ });
+
+ const chartKey = 'test#-#sheet1#-#chart-in-group';
+ const groupObject = scene.getObject('test#-#sheet1#-#group-1') as { getObjects?: () => Array<{ oKey: string }> } | undefined;
+
+ expect(fixture.manager.getFloatDomInfo('chart-in-group')).toBeDefined();
+ expect(findFloatDom(canvasFloatDomService, 'chart-in-group')).toBeDefined();
+ expect(scene.getObjectIncludeInGroup(chartKey)).toBeDefined();
+
+ fixture.manager.removeFloatDom('chart-in-group');
+
+ expect(fixture.manager.getFloatDomInfo('chart-in-group')).toBeUndefined();
+ expect(findFloatDom(canvasFloatDomService, 'chart-in-group')).toBeUndefined();
+ expect(scene.getObjectIncludeInGroup(chartKey)).toBeUndefined();
+ expect(scene.getObject(chartKey)).toBeUndefined();
+ expect(groupObject?.getObjects?.().map((object) => object.oKey)).not.toContain(chartKey);
+ expect(scene.getTransformer().clearControlByIds).toHaveBeenCalledWith([chartKey]);
+ expect(scene.getTransformer().clearSelectedObjects).toHaveBeenCalled();
+ });
+
+ it('updates a grouped chart fill through float dom props for old drawings without a background seed', async () => {
+ const fixture = setup();
+ disposables.push(fixture);
+
+ await fixture.commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ groupBaseBound: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ componentKey: 'ChartCard',
+ data: { label: 'Old grouped chart' },
+ groupId: 'group-1',
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ ],
+ });
+
+ const chartRect = fixture.manager.getFloatDomInfo('chart-in-group')?.rect as Rect | undefined;
+ const makeDirty = vi.spyOn(chartRect!, 'makeDirty');
+
+ fixture.manager.updateFloatDomProps('test', 'sheet1', 'chart-in-group', { fill: '#fff' });
+
+ expect(chartRect?.fill).toBe('#fff');
+ expect(makeDirty).toHaveBeenCalledWith(true);
+ expect((fixture.scene as unknown as TestRenderScene).getObject('test#-#sheet1#-#chart-in-group')).toBeUndefined();
+ });
+
+ it('prefers an existing grouped chart child over a top-level runtime duplicate when updating props', async () => {
+ const fixture = setup();
+ disposables.push(fixture);
+
+ await fixture.commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ groupBaseBound: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ componentKey: 'ChartCard',
+ data: { label: 'Grouped chart' },
+ groupId: 'group-1',
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ ],
+ });
+
+ const scene = fixture.scene as unknown as TestRenderScene;
+ const chartKey = 'test#-#sheet1#-#chart-in-group';
+ const groupedChartRect = fixture.manager.getFloatDomInfo('chart-in-group')?.rect as Rect;
+ const duplicate = new Rect(chartKey, {
+ left: 144,
+ top: 96,
+ width: 120,
+ height: 72,
+ fill: '#badbad',
+ });
+ scene.addObject(duplicate);
+
+ expect(scene.getObject(chartKey)).toBe(duplicate);
+
+ fixture.manager.updateFloatDomProps('test', 'sheet1', 'chart-in-group', { fill: '#fff' });
+
+ expect(groupedChartRect.fill).toBe('#fff');
+ expect(duplicate.fill).toBe('#badbad');
+ expect(scene.getObject(chartKey)).toBeUndefined();
+ expect(scene.getObjectIncludeInGroup(chartKey)).toBe(groupedChartRect);
+ });
+
+ it('does not create a top-level duplicate when a grouped chart float dom is added again', async () => {
+ const fixture = setup();
+ disposables.push(fixture);
+
+ await fixture.commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-1',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ groupBaseBound: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ componentKey: 'ChartCard',
+ data: { label: 'Grouped chart' },
+ groupId: 'group-1',
+ transform: { left: 120, top: 72, width: 120, height: 72 },
+ },
+ ],
+ });
+
+ await fixture.commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-in-group',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ componentKey: 'ChartCard',
+ data: { label: 'Grouped chart' },
+ groupId: 'group-1',
+ transform: { left: 144, top: 96, width: 120, height: 72 },
+ },
+ ],
+ });
+
+ const scene = fixture.scene as unknown as TestRenderScene;
+ const chartKey = 'test#-#sheet1#-#chart-in-group';
+ const groupObject = scene.getObject('test#-#sheet1#-#group-1') as { getObjects?: () => Array<{ oKey: string }> } | undefined;
+ const groupedChildren = groupObject?.getObjects?.().filter((object) => object.oKey === chartKey) ?? [];
+
+ expect(scene.getObject(chartKey)).toBeUndefined();
+ expect(scene.getObjectIncludeInGroup(chartKey)?.isInGroup).toBe(true);
+ expect(groupedChildren).toHaveLength(1);
+ });
+
it('adds a position anchored float dom through the sheet drawing pipeline', async () => {
const fixture = setup();
disposables.push(fixture);
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.ts
index 610a3b25e4..b081210651 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
@@ -22,6 +22,7 @@ import type { IFloatDomData, IInsertDrawingCommandParams, ISheetDrawingPosition,
import type { IFloatDom, IFloatDomLayout } from '@univerjs/ui';
import { Disposable, DisposableCollection, DrawingTypeEnum, fromEventSubject, generateRandomId, ICommandService, Inject, IUniverInstanceService, LifecycleService, LifecycleStages, Tools, UniverInstanceType } from '@univerjs/core';
import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
+import { disposeDrawingRenderObject, insertGroupObject } from '@univerjs/drawing-ui';
import { DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, ObjectType, Rect, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';
import { COMMAND_LISTENER_SKELETON_CHANGE, getSheetCommandTarget, SetFrozenMutation, SetSelectionsOperation, SetWorksheetRowAutoHeightMutation } from '@univerjs/sheets';
import { DrawingApplyType, InsertSheetDrawingCommand, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';
@@ -83,6 +84,36 @@ export interface ICanvasFloatDomInfo {
domId?: string; // Ensure unique id for dom element at runtime
}
+/**
+ * Context passed to a sheet float-dom render object factory.
+ *
+ * This shape is consumed by the sheet drawing render pipeline when it creates
+ * canvas-side render objects. Plugins normally use it through the callback
+ * passed to {@link SheetCanvasFloatDomManagerService.registerRenderObjectFactory}.
+ */
+export interface ISheetFloatDomRenderObjectFactoryContext {
+ key: string;
+ config: IRectProps;
+ unitId: string;
+ subUnitId: string;
+ drawingId: string;
+ drawingType: DrawingTypeEnum;
+ data?: Serializable;
+}
+
+/**
+ * Creates the canvas-side render object for a sheet float-dom drawing.
+ *
+ * The returned object must be a {@link Rect} or a {@link Rect} subclass because
+ * the sheet drawing manager owns transform, selection, order, and grouping
+ * through that render object.
+ *
+ * Prefer registering factories through
+ * {@link SheetCanvasFloatDomManagerService.registerRenderObjectFactory} instead
+ * of constructing render objects inside sheet drawing code.
+ */
+export type SheetFloatDomRenderObjectFactory = (context: ISheetFloatDomRenderObjectFactoryContext) => Rect;
+
export interface IDOMAnchor {
width: number;
height: number;
@@ -282,6 +313,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
private _remove$ = new Subject<{ unitId: string; subUnitId: string; id: string }>();
remove$ = this._remove$.asObservable();
+ private readonly _renderObjectFactories = new Map<DrawingTypeEnum, SheetFloatDomRenderObjectFactory[]>();
constructor(
@Inject(IRenderManagerService) private _renderManagerService: IRenderManagerService,
@@ -299,6 +331,42 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
this._bindScrollEvent();
}
+ /**
+ * Register a factory that creates the canvas-side render object for a sheet
+ * float-dom drawing type. The latest registered factory wins; disposing the
+ * returned handle unregisters it and restores the previous factory or the
+ * default {@link Rect} fallback.
+ */
+ registerRenderObjectFactory(drawingType: DrawingTypeEnum, factory: SheetFloatDomRenderObjectFactory): IDisposable {
+ const factories = this._renderObjectFactories.get(drawingType) ?? [];
+ factories.push(factory);
+ this._renderObjectFactories.set(drawingType, factories);
+
+ return {
+ dispose: () => {
+ const currentFactories = this._renderObjectFactories.get(drawingType);
+ if (!currentFactories) {
+ return;
+ }
+
+ const index = currentFactories.indexOf(factory);
+ if (index >= 0) {
+ currentFactories.splice(index, 1);
+ }
+
+ if (currentFactories.length === 0) {
+ this._renderObjectFactories.delete(drawingType);
+ }
+ },
+ };
+ }
+
+ private _createRenderObject(context: ISheetFloatDomRenderObjectFactoryContext): Rect {
+ const factories = this._renderObjectFactories.get(context.drawingType);
+ const factory = factories?.[factories.length - 1];
+ return factory?.(context) ?? new Rect(context.key, context.config);
+ }
+
private _bindScrollEvent() {
this._lifecycleService.lifecycle$.pipe(filter((s) => s === LifecycleStages.Rendered), take(1)).subscribe(() => {
this._scrollUpdateListener();
@@ -359,7 +427,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
return;
}
- const { transform, drawingType, data, hidden } = floatDomParam;
+ const { transform, drawingType, data, hidden, groupId } = floatDomParam;
if (drawingType !== DrawingTypeEnum.DRAWING_DOM && drawingType !== DrawingTypeEnum.DRAWING_CHART) {
return;
@@ -387,11 +455,14 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
const rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
+ const groupShapeKey = groupId ? getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: groupId }) : undefined;
- const rectShape = scene.getObject(rectShapeKey);
+ const rectShape = this._getObjectIncludingGroup(scene, rectShapeKey, groupShapeKey);
if (rectShape != null) {
+ this._removeTopLevelDuplicateIfGrouped(scene, rectShapeKey, rectShape);
rectShape.transformByState({ left, top, width, height, angle, flipX, flipY, skewX, skewY });
+ this._syncFloatDomRect(drawingId, rectShape);
return;
}
@@ -407,8 +478,10 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
imageConfig.rotateEnabled = false;
if (isChart) {
- const backgroundColor = data ? (data as Record<string, string>).backgroundColor : 'white';
- imageConfig.fill = backgroundColor;
+ const backgroundColor = this._getChartDataBackground(data);
+ if (backgroundColor !== undefined) {
+ imageConfig.fill = backgroundColor;
+ }
if (data && (data as Record<string, string>).border) {
imageConfig.stroke = (data as Record<string, string>).border;
@@ -419,7 +492,15 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
imageConfig.radius = 8;
}
- const rect = new Rect(rectShapeKey, imageConfig);
+ const rect = this._createRenderObject({
+ key: rectShapeKey,
+ config: imageConfig,
+ unitId,
+ subUnitId,
+ drawingId,
+ drawingType,
+ data,
+ });
if (isChart) {
rect.setObjectType(ObjectType.CHART);
@@ -431,6 +512,9 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
if (floatDomParam.allowTransform !== false) {
scene.attachTransformerTo(rect);
}
+ if (isChart && groupId) {
+ insertGroupObject({ drawingId: groupId, unitId, subUnitId }, rect, scene, this._drawingManagerService);
+ }
const disposableCollection = new DisposableCollection();
const initPosition = calcSheetFloatDomPosition(rect, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
const position$ = new BehaviorSubject<IFloatDomLayout>(initPosition);
@@ -495,7 +579,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
return;
}
const { transformer, scene } = renderObject;
- const rectShape = scene.getObject(rectShapeKey);
+ const rectShape = this._getObjectIncludingGroup(scene, rectShapeKey);
if (rectShape?.oKey) {
transformer.clearControlByIds([rectShape?.oKey]);
scene.getTransformer()?.clearSelectedObjects();
@@ -578,13 +662,82 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
if (info && renderObject) {
const { scene } = renderObject;
const rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: id });
- const rectShape = scene.getObject(rectShapeKey);
+ const drawing = this._drawingManagerService.getDrawingByParam({ unitId, subUnitId, drawingId: id });
+ const groupShapeKey = drawing?.groupId ? getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: drawing.groupId }) : undefined;
+ const rectShape = this._getObjectIncludingGroup(scene, rectShapeKey, groupShapeKey);
if (rectShape && rectShape instanceof Rect) {
+ this._removeTopLevelDuplicateIfGrouped(scene, rectShapeKey, rectShape);
rectShape.setProps(props);
+ this._syncFloatDomRect(id, rectShape);
}
}
}
+ private _getObjectIncludingGroup(scene: Scene, key: string, groupKey?: string): Nullable<BaseObject> {
+ return this._getChildObjectFromGroup(scene, key, groupKey) ?? scene.getObjectIncludeInGroup?.(key) ?? scene.getObject(key) ?? null;
+ }
+
+ private _getChildObjectFromGroup(scene: Scene, key: string, groupKey?: string): Nullable<BaseObject> {
+ if (!groupKey) {
+ return null;
+ }
+
+ const groupObject = scene.getObjectIncludeInGroup?.(groupKey) ?? scene.getObject(groupKey);
+ return this._findChildObject(groupObject, key);
+ }
+
+ private _findChildObject(object: Nullable<BaseObject>, key: string): Nullable<BaseObject> {
+ if (!object) {
+ return null;
+ }
+
+ const children = object.getObjects();
+ for (const child of children) {
+ if (child.oKey === key) {
+ return child;
+ }
+
+ const nested = this._findChildObject(child, key);
+ if (nested) {
+ return nested;
+ }
+ }
+
+ return null;
+ }
+
+ private _removeTopLevelDuplicateIfGrouped(scene: Scene, key: string, object: BaseObject): void {
+ if (!object.isInGroup) {
+ return;
+ }
+
+ const topLevelObject = scene.getObject(key);
+ if (topLevelObject && topLevelObject !== object) {
+ scene.removeObject(topLevelObject);
+ }
+ }
+
+ private _syncFloatDomRect(id: string, object: BaseObject): void {
+ if (!(object instanceof Rect)) {
+ return;
+ }
+
+ const info = this._domLayerInfoMap.get(id);
+ if (info) {
+ info.rect = object;
+ }
+ }
+
+ private _getChartDataBackground(data?: Serializable): string | undefined {
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
+ return undefined;
+ }
+
+ const record = data as Record<string, unknown>;
+ const background = record.backgroundColor ?? record.background;
+ return typeof background === 'string' ? background : undefined;
+ }
+
private _getPosition(position: IPosition, unitId: string): Nullable<ISheetDrawingPosition> {
const { startX, endX, startY, endY } = position;
const selectionRenderService = this._renderManagerService.getRenderById(unitId)?.with(ISheetSelectionRenderService);
@@ -736,7 +889,11 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
info.dispose.dispose();
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
if (renderObject) {
- renderObject.scene.removeObject(info.rect);
+ const { scene, transformer } = renderObject;
+ if (disposeDrawingRenderObject(scene, { unitId, subUnitId, drawingId: id })) {
+ transformer.clearControlByIds([info.rect.oKey]);
+ scene.getTransformer()?.clearSelectedObjects();
+ }
}
if (removeDrawing) {
@@ -828,7 +985,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
return;
}
- const { transform, drawingType, data } = floatDomParam;
+ const { transform, drawingType, data, groupId } = floatDomParam;
if (drawingType !== DrawingTypeEnum.DRAWING_DOM && drawingType !== DrawingTypeEnum.DRAWING_CHART) {
return;
@@ -852,11 +1009,14 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
const rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
+ const groupShapeKey = groupId ? getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: groupId }) : undefined;
- const rectShape = scene.getObject(rectShapeKey);
+ const rectShape = this._getObjectIncludingGroup(scene, rectShapeKey, groupShapeKey);
if (rectShape != null) {
+ this._removeTopLevelDuplicateIfGrouped(scene, rectShapeKey, rectShape);
rectShape.transformByState({ left, top, width, height, angle, flipX, flipY, skewX, skewY });
+ this._syncFloatDomRect(drawingId, rectShape);
return;
}
@@ -871,8 +1031,10 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
if (isChart) {
- const backgroundColor = data ? (data as Record<string, string>).backgroundColor : 'white';
- domConfig.fill = backgroundColor;
+ const backgroundColor = this._getChartDataBackground(data);
+ if (backgroundColor !== undefined) {
+ domConfig.fill = backgroundColor;
+ }
domConfig.rotateEnabled = false;
if (data && (data as Record<string, string>).border) {
domConfig.stroke = (data as Record<string, string>).border;
@@ -883,7 +1045,15 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
domConfig.radius = 8;
}
- const domRect = new Rect(rectShapeKey, domConfig);
+ const domRect = this._createRenderObject({
+ key: rectShapeKey,
+ config: domConfig,
+ unitId,
+ subUnitId,
+ drawingId,
+ drawingType,
+ data,
+ });
if (isChart) {
domRect.setObjectType(ObjectType.CHART);
@@ -893,6 +1063,9 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
if (floatDomParam.allowTransform !== false) {
scene.attachTransformerTo(domRect);
}
+ if (isChart && groupId) {
+ insertGroupObject({ drawingId: groupId, unitId, subUnitId }, domRect, scene, this._drawingManagerService);
+ }
const disposableCollection = new DisposableCollection();
const viewMain = scene.getMainViewport();
@@ -1106,10 +1279,12 @@ export class SheetCanvasFloatDomManagerService extends Disposable {
const rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId });
- const rectShape = scene.getObject(rectShapeKey);
+ const rectShape = this._getObjectIncludingGroup(scene, rectShapeKey);
if (rectShape != null) {
+ this._removeTopLevelDuplicateIfGrouped(scene, rectShapeKey, rectShape);
rectShape.transformByState({ left, top, width, height, angle, flipX, flipY, skewX, skewY });
+ this._syncFloatDomRect(drawingId, rectShape);
return;
}
diff --git a/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts b/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts
index b26d305591..f6f5561d67 100644
--- a/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts
+++ b/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts
@@ -14,14 +14,16 @@
* limitations under the License.
*/
-import type { ICommandService, Injector, Univer } from '@univerjs/core';
+import type { Injector, Univer } from '@univerjs/core';
import type { ISheetDrawing } from '../../../services/sheet-drawing.service';
-import { ArrangeTypeEnum, DrawingTypeEnum, ImageSourceType, IUniverInstanceService, UndoCommand } from '@univerjs/core';
-import { IDrawingManagerService } from '@univerjs/drawing';
-import { CopySheetCommand, RemoveSheetCommand, SetWorksheetActivateCommand } from '@univerjs/sheets';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { ArrangeTypeEnum, DrawingTypeEnum, ICommandService, ImageSourceType, IUndoRedoService, IUniverInstanceService, UndoCommand } from '@univerjs/core';
+import { DRAWING_COPY_CONTEXT_KEY, IDrawingManagerService } from '@univerjs/drawing';
+import { CopySheetCommand, RemoveSheetCommand, SetWorksheetActivateCommand, SheetInterceptorService } from '@univerjs/sheets';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { createSheetsDrawingTestBed } from '../../../__tests__/create-sheets-drawing-test-bed';
+import { resolveSheetDrawingRotateEnabled } from '../../../common/rotate-enabled';
import { ISheetDrawingService } from '../../../services/sheet-drawing.service';
+import { DrawingApplyType, SetDrawingApplyMutation } from '../../mutations/set-drawing-apply.mutation';
import { InsertSheetDrawingCommand } from '../insert-sheet-drawing.command';
import { RemoveSheetDrawingCommand } from '../remove-sheet-drawing.command';
import { SetDrawingArrangeCommand } from '../set-drawing-arrange.command';
@@ -76,6 +78,40 @@ function createSheetDrawing(drawingId: string, subUnitId = 'sheet1'): ISheetDraw
};
}
+function createSheetDrawingTransform(angle = 0) {
+ return {
+ left: 10,
+ top: 20,
+ width: 30,
+ height: 40,
+ angle,
+ };
+}
+
+function withoutAngle<T extends { angle?: number }>(value: T): Omit<T, 'angle'> {
+ const { angle: _angle, ...rest } = value;
+ return rest;
+}
+
+function createGroupSheetDrawing(drawingId: string, angle = 0): ISheetDrawing {
+ const drawing = createSheetDrawing(drawingId);
+
+ return {
+ ...drawing,
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: createSheetDrawingTransform(angle),
+ groupBaseBound: createSheetDrawingTransform(angle),
+ sheetTransform: {
+ ...drawing.sheetTransform,
+ angle,
+ },
+ axisAlignSheetTransform: {
+ ...drawing.axisAlignSheetTransform,
+ angle,
+ },
+ } as ISheetDrawing;
+}
+
describe('sheet drawing integration', () => {
let univer: Univer;
let get: Injector['get'];
@@ -140,6 +176,66 @@ describe('sheet drawing integration', () => {
expect(sheetDrawingService.getDrawingOrder('test', 'sheet1')).toEqual([]);
});
+ it('skips remove sheet drawing when no drawing objects are resolved', async () => {
+ expect(await commandService.executeCommand(RemoveSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [],
+ })).toBe(false);
+ });
+
+ it('removes and restores a grouped drawing graph including chart children', async () => {
+ await commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ createGroupSheetDrawing('group-delete'),
+ {
+ ...createSheetDrawing('image-child'),
+ groupId: 'group-delete',
+ transform: createSheetDrawingTransform(),
+ },
+ {
+ ...createSheetDrawing('chart-child'),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: 'group-delete',
+ transform: createSheetDrawingTransform(),
+ } as ISheetDrawing,
+ ],
+ });
+
+ expect(await commandService.executeCommand(RemoveSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [{
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-delete',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ }],
+ })).toBe(true);
+
+ const sheetDrawingService = get(ISheetDrawingService);
+ const drawingManagerService = get(IDrawingManagerService);
+ const drawingSearches = ['group-delete', 'image-child', 'chart-child'].map((drawingId) => ({ unitId: 'test', subUnitId: 'sheet1', drawingId }));
+
+ drawingSearches.forEach((drawingSearch) => {
+ expect(sheetDrawingService.getDrawingByParam(drawingSearch)).toBeUndefined();
+ expect(drawingManagerService.getDrawingByParam(drawingSearch)).toBeUndefined();
+ });
+ expect(sheetDrawingService.getDrawingOrder('test', 'sheet1')).toEqual([]);
+
+ expect(await commandService.executeCommand(UndoCommand.id)).toBe(true);
+
+ expect(sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-delete' })).toMatchObject({
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ });
+ expect(sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'image-child' })).toMatchObject({
+ groupId: 'group-delete',
+ });
+ expect(sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'chart-child' })).toMatchObject({
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: 'group-delete',
+ });
+ });
+
it('updates an existing drawing through the real command pipeline', async () => {
await commandService.executeCommand(InsertSheetDrawingCommand.id, {
unitId: 'test',
@@ -194,6 +290,189 @@ describe('sheet drawing integration', () => {
});
});
+ it('preserves angle updates for groups containing charts while applying move and resize fields', async () => {
+ const image = {
+ ...createSheetDrawing('image-child'),
+ groupId: 'group-with-chart',
+ transform: createSheetDrawingTransform(),
+ };
+ const chart = {
+ ...createSheetDrawing('chart-child'),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: 'group-with-chart',
+ transform: createSheetDrawingTransform(),
+ } as ISheetDrawing;
+
+ await commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ createGroupSheetDrawing('group-with-chart', 30),
+ image,
+ chart,
+ ],
+ });
+
+ const sheetDrawingService = get(ISheetDrawingService);
+ const restoredGroup = sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-with-chart' })!;
+ expect(Object.prototype.hasOwnProperty.call(restoredGroup.transform ?? {}, 'rotateEnabled')).toBe(false);
+ expect(restoredGroup.transform?.angle).toBe(30);
+ expect(resolveSheetDrawingRotateEnabled(restoredGroup, sheetDrawingService)).toBe(false);
+
+ expect(await commandService.executeCommand(SetSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [{
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-with-chart',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: {
+ left: 15,
+ top: 25,
+ width: 35,
+ height: 45,
+ angle: 60,
+ },
+ sheetTransform: {
+ ...createSheetDrawing('group-with-chart').sheetTransform,
+ angle: 60,
+ },
+ axisAlignSheetTransform: {
+ ...createSheetDrawing('group-with-chart').axisAlignSheetTransform,
+ angle: 60,
+ },
+ }],
+ })).toBe(true);
+
+ expect(sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-with-chart' })).toMatchObject({
+ transform: {
+ left: 15,
+ top: 25,
+ width: 35,
+ height: 45,
+ angle: 30,
+ },
+ sheetTransform: expect.objectContaining({ angle: 30 }),
+ axisAlignSheetTransform: expect.objectContaining({ angle: 30 }),
+ });
+
+ expect(await commandService.executeCommand(SetSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [{
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'group-with-chart',
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
+ transform: {
+ angle: 60,
+ },
+ }],
+ })).toBe(true);
+
+ expect(sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-with-chart' })).toMatchObject({
+ transform: {
+ left: 15,
+ top: 25,
+ width: 35,
+ height: 45,
+ angle: 30,
+ },
+ sheetTransform: expect.objectContaining({ angle: 30 }),
+ axisAlignSheetTransform: expect.objectContaining({ angle: 30 }),
+ });
+ });
+
+ it('drops incoming angles for non-rotatable drawings when current angle is absent', async () => {
+ const drawing = createSheetDrawing('chart-without-angle');
+ const chart = {
+ ...drawing,
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ transform: withoutAngle(createSheetDrawingTransform()),
+ sheetTransform: withoutAngle(drawing.sheetTransform),
+ axisAlignSheetTransform: withoutAngle(drawing.axisAlignSheetTransform),
+ } as ISheetDrawing;
+
+ await commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [chart],
+ });
+
+ expect(await commandService.executeCommand(SetSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [{
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-without-angle',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ transform: createSheetDrawingTransform(45),
+ sheetTransform: {
+ ...drawing.sheetTransform,
+ angle: 45,
+ },
+ axisAlignSheetTransform: {
+ ...drawing.axisAlignSheetTransform,
+ angle: 45,
+ },
+ }],
+ })).toBe(true);
+
+ const restoredChart = get(ISheetDrawingService).getDrawingByParam({
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'chart-without-angle',
+ })!;
+
+ expect(Object.prototype.hasOwnProperty.call(restoredChart.transform ?? {}, 'angle')).toBe(false);
+ expect(Object.prototype.hasOwnProperty.call(restoredChart.sheetTransform, 'angle')).toBe(false);
+ expect(Object.prototype.hasOwnProperty.call(restoredChart.axisAlignSheetTransform, 'angle')).toBe(false);
+ });
+
+ it('keeps angle updates unchanged when the current drawing is missing', () => {
+ const commandServiceMock = { syncExecuteCommand: vi.fn(() => true) };
+ const undoRedoServiceMock = { pushUndoRedo: vi.fn() };
+ const sheetDrawingServiceMock = {
+ getDrawingByParam: vi.fn(() => undefined),
+ getBatchUpdateOp: vi.fn((drawings: ISheetDrawing[]) => ({
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ undo: null,
+ redo: null,
+ objects: drawings.map(({ unitId, subUnitId, drawingId }) => ({ unitId, subUnitId, drawingId })),
+ })),
+ };
+ const sheetInterceptorServiceMock = {
+ onCommandExecute: vi.fn(() => ({ redos: [], undos: [] })),
+ };
+ const drawing = {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ drawingId: 'missing-chart',
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ transform: { angle: 45 },
+ };
+ const accessor = {
+ get: vi.fn((token) => {
+ if (token === ICommandService) return commandServiceMock;
+ if (token === IUndoRedoService) return undoRedoServiceMock;
+ if (token === ISheetDrawingService) return sheetDrawingServiceMock;
+ if (token === SheetInterceptorService) return sheetInterceptorServiceMock;
+ throw new Error('unexpected dependency');
+ }),
+ };
+
+ expect(SetSheetDrawingCommand.handler(accessor as never, {
+ unitId: 'test',
+ drawings: [drawing],
+ })).toBe(true);
+ expect(sheetDrawingServiceMock.getBatchUpdateOp).toHaveBeenCalledWith([drawing]);
+ expect(sheetInterceptorServiceMock.onCommandExecute).toHaveBeenCalledWith({
+ id: SetSheetDrawingCommand.id,
+ params: {
+ unitId: 'test',
+ drawings: [drawing],
+ },
+ });
+ });
+
it('arranges drawing order through the real command pipeline', async () => {
await commandService.executeCommand(InsertSheetDrawingCommand.id, {
unitId: 'test',
@@ -278,6 +557,169 @@ describe('sheet drawing integration', () => {
expect(get(IDrawingManagerService).getDrawingOrder('test', copiedSheetId)).toHaveLength(1);
});
+ it('copies grouped drawing records with the same group id map', async () => {
+ await commandService.executeCommand(SetWorksheetActivateCommand.id, {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ });
+ await commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ createGroupSheetDrawing('group-copy'),
+ {
+ ...createSheetDrawing('image-child'),
+ groupId: 'group-copy',
+ transform: createSheetDrawingTransform(),
+ },
+ {
+ ...createSheetDrawing('chart-child'),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: 'group-copy',
+ transform: createSheetDrawingTransform(),
+ } as ISheetDrawing,
+ ],
+ });
+
+ expect(commandService.syncExecuteCommand(CopySheetCommand.id, {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ })).toBe(true);
+
+ const workbook = get(IUniverInstanceService).getUniverSheetInstance('test')!;
+ const copiedSheetId = workbook.getSheets()
+ .map((sheet) => sheet.getSheetId())
+ .find((sheetId) => sheetId !== 'sheet1' && sheetId !== 'sheet2')!;
+ const copiedDrawings = Object.values(get(ISheetDrawingService).getDrawingData('test', copiedSheetId));
+ const copiedGroup = copiedDrawings.find((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP);
+ const copiedImage = copiedDrawings.find((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_IMAGE);
+ const copiedChart = copiedDrawings.find((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_CHART);
+
+ expect(copiedDrawings.map((drawing) => drawing.drawingType).sort()).toEqual([
+ DrawingTypeEnum.DRAWING_CHART,
+ DrawingTypeEnum.DRAWING_IMAGE,
+ DrawingTypeEnum.DRAWING_GROUP,
+ ].sort());
+ expect(copiedGroup?.drawingId).not.toBe('group-copy');
+ expect(copiedImage?.drawingId).not.toBe('image-child');
+ expect(copiedChart?.drawingId).not.toBe('chart-child');
+ expect(copiedImage?.groupId).toBe(copiedGroup?.drawingId);
+ expect(copiedChart?.groupId).toBe(copiedGroup?.drawingId);
+ });
+
+ it('includes grouped chart children in remove sheet drawing record mutations', async () => {
+ await commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [
+ createGroupSheetDrawing('group-remove'),
+ {
+ ...createSheetDrawing('image-child'),
+ groupId: 'group-remove',
+ transform: createSheetDrawingTransform(),
+ },
+ {
+ ...createSheetDrawing('chart-child'),
+ drawingType: DrawingTypeEnum.DRAWING_CHART,
+ groupId: 'group-remove',
+ transform: createSheetDrawingTransform(),
+ } as ISheetDrawing,
+ ],
+ });
+
+ const intercepted = get(SheetInterceptorService).onCommandExecute({
+ id: RemoveSheetCommand.id,
+ params: { unitId: 'test', subUnitId: 'sheet1' },
+ });
+ const removeMutation = intercepted.redos.find((mutation) => mutation.id === SetDrawingApplyMutation.id);
+ const removeObjects = (removeMutation?.params as { objects?: Array<{ drawingId: string }>; type?: DrawingApplyType } | undefined)?.objects ?? [];
+
+ expect((removeMutation?.params as { type?: DrawingApplyType } | undefined)?.type).toBe(DrawingApplyType.REMOVE);
+ expect(removeObjects.map((object) => object.drawingId)).toEqual(['chart-child', 'image-child', 'group-remove']);
+ });
+
+ it('copies drawing records that are missing from drawing order after ordered records', () => {
+ const sheetDrawingService = get(ISheetDrawingService);
+ sheetDrawingService.registerDrawingData('test', {
+ sheet1: {
+ data: {
+ ordered: createSheetDrawing('ordered'),
+ unordered: createSheetDrawing('unordered'),
+ },
+ order: ['ordered'],
+ },
+ });
+ const copyContext = new Map<string, unknown>();
+
+ const intercepted = get(SheetInterceptorService).onCommandExecute({
+ id: CopySheetCommand.id,
+ params: {
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ targetSubUnitId: 'copied-sheet',
+ copyContext,
+ },
+ });
+ const insertMutation = intercepted.redos.find((mutation) => mutation.id === SetDrawingApplyMutation.id);
+ const copiedObjects = (insertMutation?.params as { objects?: Array<{ drawingId: string; subUnitId: string }> } | undefined)?.objects ?? [];
+ const copyPlan = copyContext.get(DRAWING_COPY_CONTEXT_KEY) as { drawings: Array<ISheetDrawing & { source?: string }> };
+
+ expect(copyPlan.drawings.map((drawing) => drawing.source)).toEqual([
+ 'https://example.com/ordered.png',
+ 'https://example.com/unordered.png',
+ ]);
+ expect(copiedObjects.map((drawing) => drawing.drawingId)).toEqual(copyPlan.drawings.map((drawing) => drawing.drawingId));
+ expect(copiedObjects.map((drawing) => drawing.subUnitId)).toEqual(['copied-sheet', 'copied-sheet']);
+ });
+
+ it('does not create remove sheet mutations when batch remove resolves no objects', async () => {
+ await commandService.executeCommand(InsertSheetDrawingCommand.id, {
+ unitId: 'test',
+ drawings: [createSheetDrawing('empty-remove-guard')],
+ });
+
+ const sheetDrawingService = get(ISheetDrawingService);
+ const getBatchRemoveOpSpy = vi.spyOn(sheetDrawingService, 'getBatchRemoveOp').mockReturnValue({
+ unitId: 'test',
+ subUnitId: 'sheet1',
+ undo: null,
+ redo: null,
+ objects: [],
+ });
+
+ expect(get(SheetInterceptorService).onCommandExecute({
+ id: RemoveSheetCommand.id,
+ params: { unitId: 'test', subUnitId: 'sheet1' },
+ })).toMatchObject({ redos: [], undos: [] });
+
+ getBatchRemoveOpSpy.mockRestore();
+ });
+
+ it('does not create sheet lifecycle mutations when the source sheet has no drawings', () => {
+ const sheetInterceptorService = get(SheetInterceptorService);
+
+ expect(sheetInterceptorService.onCommandExecute({
+ id: RemoveSheetCommand.id,
+ params: { unitId: 'test', subUnitId: 'sheet2' },
+ })).toMatchObject({ redos: [], undos: [] });
+
+ expect(sheetInterceptorService.onCommandExecute({
+ id: CopySheetCommand.id,
+ params: {
+ unitId: 'test',
+ subUnitId: 'sheet2',
+ },
+ })).toMatchObject({ redos: [], undos: [] });
+
+ expect(sheetInterceptorService.onCommandExecute({
+ id: CopySheetCommand.id,
+ params: {
+ unitId: 'test',
+ subUnitId: 'sheet2',
+ targetSubUnitId: 'copied-empty-sheet',
+ copyContext: new Map<string, unknown>(),
+ },
+ })).toMatchObject({ redos: [], undos: [] });
+ });
+
it('removes and restores sheet drawings when a worksheet is deleted and undone', async () => {
await commandService.executeCommand(SetWorksheetActivateCommand.id, {
unitId: 'test',
diff --git a/packages/sheets-drawing/src/commands/commands/remove-sheet-drawing.command.ts b/packages/sheets-drawing/src/commands/commands/remove-sheet-drawing.command.ts
index 17f20ddaf4..9444620a79 100644
--- a/packages/sheets-drawing/src/commands/commands/remove-sheet-drawing.command.ts
+++ b/packages/sheets-drawing/src/commands/commands/remove-sheet-drawing.command.ts
@@ -54,6 +54,10 @@ export const RemoveSheetDrawingCommand: ICommand = {
const jsonOp = sheetDrawingService.getBatchRemoveOp(drawings) as IDrawingJsonUndo1;
const { unitId, subUnitId, undo, redo, objects } = jsonOp;
+ if (Array.isArray(objects) && objects.length === 0) {
+ return false;
+ }
+
const intercepted = sheetInterceptorService.onCommandExecute({ id: RemoveSheetDrawingCommand.id, params });
const redoMutations = [
...(intercepted.preRedos ?? []),
diff --git a/packages/sheets-drawing/src/commands/commands/set-sheet-drawing.command.ts b/packages/sheets-drawing/src/commands/commands/set-sheet-drawing.command.ts
index 01ed55c1c2..0be500b094 100644
--- a/packages/sheets-drawing/src/commands/commands/set-sheet-drawing.command.ts
+++ b/packages/sheets-drawing/src/commands/commands/set-sheet-drawing.command.ts
@@ -24,6 +24,7 @@ import {
sequenceExecute,
} from '@univerjs/core';
import { SheetInterceptorService } from '@univerjs/sheets';
+import { resolveSheetDrawingRotateEnabled } from '../../common/rotate-enabled';
import { ISheetDrawingService } from '../../services/sheet-drawing.service';
import { DrawingApplyType, SetDrawingApplyMutation } from '../mutations/set-drawing-apply.mutation';
import { ClearSheetDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation';
@@ -33,6 +34,66 @@ export interface ISetDrawingCommandParams {
drawings: Partial<ISheetDrawing>[];
}
+function hasIncomingAngle(drawing: Partial<ISheetDrawing>): boolean {
+ return drawing.transform?.angle !== undefined || drawing.sheetTransform?.angle !== undefined || drawing.axisAlignSheetTransform?.angle !== undefined;
+}
+
+type NullableAngleState = { angle?: number } | null | undefined | void;
+
+function preserveAngle<T extends { angle?: number }>(incoming: T, current: NullableAngleState): T {
+ const currentAngle = (current as { angle?: number } | null | undefined)?.angle;
+ const next = { ...((current ?? {}) as object), ...incoming } as T;
+ if (currentAngle === undefined) {
+ delete next.angle;
+ } else {
+ next.angle = currentAngle;
+ }
+
+ return next;
+}
+
+function normalizeNonRotatableAngleUpdate(drawing: Partial<ISheetDrawing>, sheetDrawingService: ISheetDrawingService): Partial<ISheetDrawing> {
+ if (!drawing.drawingId || !drawing.unitId || !drawing.subUnitId || !hasIncomingAngle(drawing)) {
+ return drawing;
+ }
+
+ const current = sheetDrawingService.getDrawingByParam({
+ unitId: drawing.unitId,
+ subUnitId: drawing.subUnitId,
+ drawingId: drawing.drawingId,
+ });
+ if (!current) {
+ return drawing;
+ }
+
+ const resolveTarget = {
+ ...current,
+ ...drawing,
+ drawingType: drawing.drawingType ?? current.drawingType,
+ transform: {
+ ...current.transform,
+ ...drawing.transform,
+ },
+ } as ISheetDrawing;
+
+ if (resolveSheetDrawingRotateEnabled(resolveTarget, sheetDrawingService)) {
+ return drawing;
+ }
+
+ const normalized = { ...drawing };
+ if (drawing.transform?.angle !== undefined) {
+ normalized.transform = preserveAngle(drawing.transform, current.transform);
+ }
+ if (drawing.sheetTransform?.angle !== undefined) {
+ normalized.sheetTransform = preserveAngle(drawing.sheetTransform, current.sheetTransform);
+ }
+ if (drawing.axisAlignSheetTransform?.angle !== undefined) {
+ normalized.axisAlignSheetTransform = preserveAngle(drawing.axisAlignSheetTransform, current.axisAlignSheetTransform);
+ }
+
+ return normalized;
+}
+
export const SetSheetDrawingCommand: ICommand<ISetDrawingCommandParams> = {
id: 'sheet.command.set-sheet-image',
type: CommandType.COMMAND,
@@ -45,10 +106,12 @@ export const SetSheetDrawingCommand: ICommand<ISetDrawingCommandParams> = {
const sheetInterceptorService = accessor.get(SheetInterceptorService);
const { drawings } = params;
- const jsonOp = sheetDrawingService.getBatchUpdateOp(drawings as ISheetDrawing[]) as IDrawingJsonUndo1;
+ const normalizedDrawings = drawings.map((drawing) => normalizeNonRotatableAngleUpdate(drawing, sheetDrawingService));
+ const normalizedParams = { ...params, drawings: normalizedDrawings };
+ const jsonOp = sheetDrawingService.getBatchUpdateOp(normalizedDrawings as ISheetDrawing[]) as IDrawingJsonUndo1;
const { unitId, subUnitId, undo, redo, objects } = jsonOp;
- const intercepted = sheetInterceptorService.onCommandExecute({ id: SetSheetDrawingCommand.id, params });
+ const intercepted = sheetInterceptorService.onCommandExecute({ id: SetSheetDrawingCommand.id, params: normalizedParams });
const redoMutations = [
...(intercepted.preRedos ?? []),
{
diff --git a/packages/sheets-drawing/src/common/__tests__/rotate-enabled.spec.ts b/packages/sheets-drawing/src/common/__tests__/rotate-enabled.spec.ts
new file mode 100644
index 0000000000..071db9d540
--- /dev/null
+++ b/packages/sheets-drawing/src/common/__tests__/rotate-enabled.spec.ts
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IDrawingParam } from '@univerjs/core';
+import type { ISheetDrawing } from '../../services/sheet-drawing.service';
+import { DrawingTypeEnum } from '@univerjs/core';
+import { describe, expect, it } from 'vitest';
+import { resolveSheetDrawingRotateEnabled } from '../rotate-enabled';
+
+const unitId = 'unit-1';
+const subUnitId = 'sheet-1';
+
+function createDrawing(drawingId: string, drawingType = DrawingTypeEnum.DRAWING_IMAGE, groupId?: string, rotateEnabled?: boolean): IDrawingParam {
+ const transform: IDrawingParam['transform'] = {
+ left: 0,
+ top: 0,
+ width: 10,
+ height: 10,
+ };
+ if (rotateEnabled !== undefined) {
+ transform.rotateEnabled = rotateEnabled;
+ }
+
+ return {
+ unitId,
+ subUnitId,
+ drawingId,
+ drawingType,
+ groupId,
+ transform,
+ };
+}
+
+function createGroup(drawingId: string, groupId?: string, rotateEnabled?: boolean): IDrawingParam {
+ return createDrawing(drawingId, DrawingTypeEnum.DRAWING_GROUP, groupId, rotateEnabled);
+}
+
+function createDrawingService(drawings: readonly IDrawingParam[] = []) {
+ return {
+ getDrawingsByGroup: (drawing: IDrawingParam) => drawings.filter((child) =>
+ child.groupId === drawing.drawingId &&
+ child.unitId === drawing.unitId &&
+ child.subUnitId === drawing.subUnitId
+ ) as ISheetDrawing[],
+ };
+}
+
+describe('sheet drawing rotate-enabled helpers', () => {
+ it('keeps regular drawings rotatable by default', () => {
+ expect(resolveSheetDrawingRotateEnabled(createDrawing('shape'), createDrawingService())).toBe(true);
+ });
+
+ it('treats chart drawings as non-rotatable without persisted rotate flags', () => {
+ const chart = createDrawing('chart', DrawingTypeEnum.DRAWING_CHART);
+
+ expect(Object.prototype.hasOwnProperty.call(chart.transform ?? {}, 'rotateEnabled')).toBe(false);
+ expect(resolveSheetDrawingRotateEnabled(chart, createDrawingService())).toBe(false);
+ });
+
+ it('treats old chart children as non-rotatable', () => {
+ const root = createGroup('root');
+ const chart = createDrawing('chart', DrawingTypeEnum.DRAWING_CHART, 'root');
+
+ expect(resolveSheetDrawingRotateEnabled(root, createDrawingService([chart]))).toBe(false);
+ });
+
+ it('recomputes stale nested group rotate flags from current children', () => {
+ const root = createGroup('root');
+ const nested = createGroup('nested', 'root', false);
+ const child = createDrawing('shape', DrawingTypeEnum.DRAWING_IMAGE, 'nested');
+
+ expect(resolveSheetDrawingRotateEnabled(root, createDrawingService([nested, child]))).toBe(true);
+ });
+});
diff --git a/packages/sheets-drawing/src/common/rotate-enabled.ts b/packages/sheets-drawing/src/common/rotate-enabled.ts
new file mode 100644
index 0000000000..e4826b5cd1
--- /dev/null
+++ b/packages/sheets-drawing/src/common/rotate-enabled.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { DrawingType, IDrawingParam } from '@univerjs/core';
+import type { IUnitDrawingService } from '@univerjs/drawing';
+import { DrawingTypeEnum } from '@univerjs/core';
+import { resolveDrawingRotateEnabled } from '@univerjs/drawing';
+import type { ISheetDrawing } from '../services/sheet-drawing.service';
+
+export function isKnownSheetNonRotatableDrawingType(drawingType: DrawingType): boolean {
+ return drawingType === DrawingTypeEnum.DRAWING_CHART;
+}
+
+export function resolveSheetDrawingRotateEnabled(
+ drawing: IDrawingParam,
+ drawingService: Pick<IUnitDrawingService<ISheetDrawing>, 'getDrawingsByGroup'>,
+ getChildren?: (drawing: IDrawingParam) => readonly IDrawingParam[] | null | undefined
+): boolean {
+ return resolveDrawingRotateEnabled(drawing, {
+ getChildren: (current) => getChildren?.(current) ?? drawingService.getDrawingsByGroup(current),
+ isKnownNonRotatableType: isKnownSheetNonRotatableDrawingType,
+ });
+}
diff --git a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
index 7e4522fa0b..f88cf6f0c6 100644
--- a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
+++ b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
@@ -16,10 +16,10 @@
import type { Workbook } from '@univerjs/core';
import type { IDrawingJsonUndo1, IDrawingSubunitMap } from '@univerjs/drawing';
-import type { ICopySheetCommandParams, IRemoveSheetCommandParams } from '@univerjs/sheets';
+import type { ICopySheetCommandInterceptorParams, IRemoveSheetCommandParams } from '@univerjs/sheets';
import type { ISheetDrawing } from '../services/sheet-drawing.service';
-import { Disposable, DrawingTypeEnum, generateRandomId, ICommandService, Inject, IResourceManagerService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { IDrawingManagerService } from '@univerjs/drawing';
+import { Disposable, ICommandService, Inject, IResourceManagerService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { getOrCreateDrawingCopyPlan, IDrawingManagerService } from '@univerjs/drawing';
import { CopySheetCommand, RemoveSheetCommand, SheetInterceptorService } from '@univerjs/sheets';
import { InsertSheetDrawingCommand } from '../commands/commands/insert-sheet-drawing.command';
import { RemoveSheetDrawingCommand } from '../commands/commands/remove-sheet-drawing.command';
@@ -31,6 +31,27 @@ import { ISheetDrawingService } from '../services/sheet-drawing.service';
export const SHEET_DRAWING_PLUGIN = 'SHEET_DRAWING_PLUGIN';
+function getDrawingsInOrder(drawingData: Record<string, ISheetDrawing>, drawingOrder: string[]): ISheetDrawing[] {
+ const visited = new Set<string>();
+ const drawings: ISheetDrawing[] = [];
+
+ drawingOrder.forEach((drawingId) => {
+ const drawing = drawingData[drawingId];
+ if (drawing) {
+ visited.add(drawingId);
+ drawings.push(drawing);
+ }
+ });
+
+ Object.values(drawingData).forEach((drawing) => {
+ if (!visited.has(drawing.drawingId)) {
+ drawings.push(drawing);
+ }
+ });
+
+ return drawings;
+}
+
export class SheetsDrawingLoadController extends Disposable {
constructor(
@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
@@ -115,13 +136,7 @@ export class SheetsDrawingLoadController extends Disposable {
}
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
- const drawings = Object.values(drawingData).filter((drawing) => {
- // filter out chart types and let the chart handle it itself, because chart id must match the drawing id.
- if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) {
- return false;
- }
- return true;
- });
+ const drawings = Object.values(drawingData);
if (drawings.length === 0) {
return { redos: [], undos: [] };
@@ -130,6 +145,10 @@ export class SheetsDrawingLoadController extends Disposable {
const jsonOp = this._sheetDrawingService.getBatchRemoveOp(drawings) as IDrawingJsonUndo1;
const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = jsonOp;
+ if (Array.isArray(objects) && objects.length === 0) {
+ return { redos: [], undos: [] };
+ }
+
return {
redos: [
{
@@ -157,27 +176,21 @@ export class SheetsDrawingLoadController extends Disposable {
],
};
} else if (commandInfo.id === CopySheetCommand.id) {
- const params = commandInfo.params as ICopySheetCommandParams & { targetSubUnitId: string };
- const { unitId, subUnitId, targetSubUnitId } = params;
+ const params = commandInfo.params as ICopySheetCommandInterceptorParams;
+ const { unitId, subUnitId, targetSubUnitId, copyContext } = params;
if (!unitId || !subUnitId || !targetSubUnitId) {
return { redos: [], undos: [] };
}
const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
- const drawings = Object.values(drawingData).filter((drawing) => {
- // filter out chart types and let the chart handle it itself, because chart id must match the drawing id.
- if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) {
- return false;
- }
- return true;
- }).map((drawing) => {
- return {
- ...drawing,
- subUnitId: targetSubUnitId,
- drawingId: generateRandomId(6),
- };
+ const sourceDrawings = getDrawingsInOrder(drawingData, this._sheetDrawingService.getDrawingOrder(unitId, subUnitId));
+ const copyPlan = getOrCreateDrawingCopyPlan(copyContext, sourceDrawings, {
+ unitId,
+ sourceSubUnitId: subUnitId,
+ targetSubUnitId,
});
+ const drawings = copyPlan.drawings;
if (drawings.length === 0) {
return { redos: [], undos: [] };
diff --git a/packages/sheets-drawing/src/facade/__tests__/f-worksheet.spec.ts b/packages/sheets-drawing/src/facade/__tests__/f-worksheet.spec.ts
index e9d0280217..392bb9b8df 100644
--- a/packages/sheets-drawing/src/facade/__tests__/f-worksheet.spec.ts
+++ b/packages/sheets-drawing/src/facade/__tests__/f-worksheet.spec.ts
@@ -29,6 +29,7 @@ import {
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { createSheetsDrawingTestBed } from '../../__tests__/create-sheets-drawing-test-bed';
import { InsertSheetDrawingCommand } from '../../commands/commands/insert-sheet-drawing.command';
+import { resolveSheetDrawingRotateEnabled } from '../../common/rotate-enabled';
import { ISheetDrawingService } from '../../services/sheet-drawing.service';
import { FWorksheetDrawingMixin } from '../f-worksheet';
@@ -58,31 +59,38 @@ describe('FWorksheetDrawingMixin group drawings', () => {
expect(commandService.syncExecuteCommand(InsertSheetDrawingCommand.id, { unitId: 'test', drawings })).toBe(true);
const groupId = fWorksheet.groupDrawings(['drawing-1', 'drawing-2'], 'group-1');
+ const groupDrawing = sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-1' });
expect(groupId).toBe('group-1');
- expect(sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-1' })?.drawingType)
- .toBe(DrawingTypeEnum.DRAWING_GROUP);
+ expect(groupDrawing?.drawingType).toBe(DrawingTypeEnum.DRAWING_GROUP);
+ expect(Object.prototype.hasOwnProperty.call(groupDrawing?.transform ?? {}, 'rotateEnabled')).toBe(false);
expect(fWorksheet.isDrawingGrouped('drawing-1')).toBe(true);
expect(fWorksheet.getDrawingParentGroup('drawing-1')?.drawingId).toBe('group-1');
expect(fWorksheet.getDrawingGroupChildren('group-1').map((drawing: ISheetDrawing) => drawing.drawingId))
.toEqual(['drawing-1', 'drawing-2']);
});
- it('does not group unsupported drawing types', () => {
+ it('groups chart drawings through the facade and disables group rotation', () => {
const drawings = [
createDrawing('drawing-1', 10),
createDrawing('chart-1', 80, DrawingTypeEnum.DRAWING_CHART),
];
const commandService = injector.get(ICommandService);
+ const sheetDrawingService = injector.get(ISheetDrawingService);
const fWorksheet = createFacade(injector);
expect(commandService.syncExecuteCommand(InsertSheetDrawingCommand.id, { unitId: 'test', drawings })).toBe(true);
const groupId = fWorksheet.groupDrawings(['drawing-1', 'chart-1'], 'group-1');
+ const groupDrawing = sheetDrawingService.getDrawingByParam({ unitId: 'test', subUnitId: 'sheet1', drawingId: 'group-1' });
- expect(groupId).toBeNull();
- expect(fWorksheet.isDrawingGrouped('drawing-1')).toBe(false);
- expect(fWorksheet.isDrawingGrouped('chart-1')).toBe(false);
+ expect(groupId).toBe('group-1');
+ expect(groupDrawing?.drawingType).toBe(DrawingTypeEnum.DRAWING_GROUP);
+ expect(fWorksheet.isDrawingGrouped('drawing-1')).toBe(true);
+ expect(fWorksheet.isDrawingGrouped('chart-1')).toBe(true);
+ expect(fWorksheet.getDrawingGroupChildren('group-1').map((drawing: ISheetDrawing) => drawing.drawingId).sort())
+ .toEqual(['chart-1', 'drawing-1']);
+ expect(resolveSheetDrawingRotateEnabled(groupDrawing!, sheetDrawingService)).toBe(false);
});
it('supports undo and redo for group and ungroup facade operations', async () => {
diff --git a/packages/sheets-drawing/src/facade/f-worksheet.ts b/packages/sheets-drawing/src/facade/f-worksheet.ts
index 695c07006d..501d7d4924 100644
--- a/packages/sheets-drawing/src/facade/f-worksheet.ts
+++ b/packages/sheets-drawing/src/facade/f-worksheet.ts
@@ -14,22 +14,17 @@
* limitations under the License.
*/
-import type { IFBlobSource } from '@univerjs/core/facade';
import type { IDrawingParam } from '@univerjs/core';
+import type { IFBlobSource } from '@univerjs/core/facade';
import type { IDrawingGroupUpdateParam, IDrawingJsonUndo1 } from '@univerjs/drawing';
import type { ISheetDrawing, ISheetImage } from '@univerjs/sheets-drawing';
import { DrawingTypeEnum, generateRandomId, ImageSourceType, IUndoRedoService } from '@univerjs/core';
+import { isGroupableDrawingType } from '@univerjs/drawing';
import { getGroupState, transformObjectOutOfGroup } from '@univerjs/engine-render';
import { DrawingApplyType, InsertSheetDrawingCommand, ISheetDrawingService, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetSheetDrawingCommand } from '@univerjs/sheets-drawing';
import { FWorksheet } from '@univerjs/sheets/facade';
import { FOverGridImage, FOverGridImageBuilder } from './f-over-grid-image';
-const GROUPABLE_DRAWING_TYPES = new Set([
- DrawingTypeEnum.DRAWING_IMAGE,
- DrawingTypeEnum.DRAWING_SHAPE,
- DrawingTypeEnum.DRAWING_GROUP,
-]);
-
/**
* @ignore
*/
@@ -511,7 +506,7 @@ export class FWorksheetDrawingMixin extends FWorksheet implements IFWorksheetDra
const drawings = uniqueDrawingIds.map((drawingId) => sheetDrawingService.getDrawingByParam({ unitId, subUnitId, drawingId }));
if (drawings.some((drawing) => !drawing)) return null;
- if (drawings.some((drawing) => !GROUPABLE_DRAWING_TYPES.has(drawing!.drawingType))) return null;
+ if (drawings.some((drawing) => !isGroupableDrawingType(drawing!.drawingType))) return null;
const validDrawings = drawings as ISheetDrawing[];
const groupTransform = getGroupState(0, 0, validDrawings.map((drawing) => drawing.transform || {}));
diff --git a/packages/sheets-drawing/src/index.ts b/packages/sheets-drawing/src/index.ts
index ad5d8441bd..67d7af6f96 100644
--- a/packages/sheets-drawing/src/index.ts
+++ b/packages/sheets-drawing/src/index.ts
@@ -33,6 +33,7 @@ export type { ISetDrawingCommandParams } from './commands/commands/set-sheet-dra
export { DrawingApplyType, SetDrawingApplyMutation } from './commands/mutations/set-drawing-apply.mutation';
export type { ISetDrawingApplyMutationParams } from './commands/mutations/set-drawing-apply.mutation';
export { ClearSheetDrawingTransformerOperation } from './commands/operations/clear-drawing-transformer.operation';
+export { isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled } from './common/rotate-enabled';
export type { IUniverSheetsDrawingConfig } from './config/config';
export { SHEET_DRAWING_PLUGIN } from './controllers/sheet-drawing.controller';
export { UniverSheetsDrawingPlugin } from './plugin';
diff --git a/packages/sheets/src/commands/commands/copy-worksheet.command.ts b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
index 0991eaac79..92835e6cc8 100644
--- a/packages/sheets/src/commands/commands/copy-worksheet.command.ts
+++ b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
@@ -140,6 +140,11 @@ export interface ICopySheetCommandParams {
subUnitId?: string;
}
+export interface ICopySheetCommandInterceptorParams extends ICopySheetCommandParams {
+ targetSubUnitId: string;
+ copyContext: Map<string, unknown>;
+}
+
const COPY_SHEET_COMMAND_ID = 'sheet.command.copy-sheet';
interface IBuildCopySheetResult {
@@ -218,9 +223,10 @@ function buildCopySheetMutations(
insertSheetMutationParams
);
+ const copyContext = new Map<string, unknown>();
const intercepted = sheetInterceptorService.onCommandExecute({
id: COPY_SHEET_COMMAND_ID,
- params: { unitId, subUnitId, targetSubUnitId: config.id },
+ params: { unitId, subUnitId, targetSubUnitId: config.id, copyContext } satisfies ICopySheetCommandInterceptorParams,
});
// Redos only include InsertSheetMutation (with first chunk), remaining mutations are scheduled
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index 6355b97509..01ea3c27e2 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -102,7 +102,7 @@ export type { IClearSelectionContentCommandParams } from './commands/commands/cl
export { ClearSelectionFormatCommand } from './commands/commands/clear-selection-format.command';
export type { IClearSelectionFormatCommandParams } from './commands/commands/clear-selection-format.command';
export { CopySheetCommand } from './commands/commands/copy-worksheet.command';
-export type { ICopySheetCommandParams } from './commands/commands/copy-worksheet.command';
+export type { ICopySheetCommandInterceptorParams, ICopySheetCommandParams } from './commands/commands/copy-worksheet.command';
export { DeleteRangeMoveLeftCommand } from './commands/commands/delete-range-move-left.command';
export type { IDeleteRangeMoveLeftCommandParams } from './commands/commands/delete-range-move-left.command';
export { DeleteRangeMoveUpCommand } from './commands/commands/delete-range-move-up.command';