mirror of
https://github.com/dream-num/univer.git
synced 2026-09-24 15:32:18 +08:00
feat(drawing): add interceptor for drawing update (#6490)
This commit is contained in:
@@ -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;
|
||||
|
||||
// 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 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 = 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;
|
||||
|
||||
Reference in New Issue
Block a user