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(drawing): add interceptor for drawing update (#6490)

VicKun1d52ebb337fb
diff --git a/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts b/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts
index 38f3a76a2c..414c29b234 100644
--- a/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts
+++ b/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts
@@ -15,17 +15,19 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+
+import type { ISheetDrawing } from '@univerjs/sheets-drawing';
+import type { ISetDrawingCommandParams } from './interfaces';
import {
CommandType,
ICommandService,
IUndoRedoService,
+ sequenceExecute,
} from '@univerjs/core';
-
-import type { ISheetDrawing } from '@univerjs/sheets-drawing';
+import { SheetInterceptorService } from '@univerjs/sheets';
import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
import { ClearSheetDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation';
-import type { ISetDrawingCommandParams } from './interfaces';
/**
* The command to update defined name
@@ -37,6 +39,7 @@ export const SetSheetDrawingCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const sheetDrawingService = accessor.get(ISheetDrawingService);
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
if (!params) return false;
@@ -49,20 +52,30 @@ export const SetSheetDrawingCommand: ICommand = {
const { unitId, subUnitId, undo, redo, objects } = jsonOp;
+ const intercepted = sheetInterceptorService.onCommandExecute({ id: SetSheetDrawingCommand.id, params });
+ const redoMutations = [
+ ...(intercepted.preRedos ?? []),
+ { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE } },
+ ...intercepted.redos,
+ { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] },
+ ];
+ const undoMutations = [
+ ...(intercepted.preUndos ?? []),
+
+ { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: undo, objects, type: DrawingApplyType.UPDATE } },
+ ...intercepted.undos,
+ { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] },
+ ];
+
// execute do mutations and add undo mutations to undo stack if completed
- const result = commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE });
+ // const result = commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE });
+ const result = sequenceExecute(redoMutations, commandService);
if (result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
- undoMutations: [
- { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: undo, objects, type: DrawingApplyType.UPDATE } },
- { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] },
- ],
- redoMutations: [
- { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE } },
- { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] },
- ],
+ undoMutations,
+ redoMutations,
});
return true;