chore: move doOperations into AppModelManager

This commit is contained in:
MrWindlike 2022-07-20 11:32:25 +08:00
parent 549e7276a3
commit b408fa620b
4 changed files with 11 additions and 17 deletions

View File

@ -10,11 +10,11 @@ export interface EditorServices {
};
appModelManager: {
appModel: any;
doOperations: (operations: Operations) => void;
};
stateManager: {
store: Record<string, any>;
maskedEval: Function;
};
widgetManager: WidgetManager;
doOperations: (operations: Operations) => void;
}

View File

@ -18,10 +18,6 @@ import { EditorStore } from './services/EditorStore';
import { StorageHandler } from './types';
import { AppStorage } from './services/AppStorage';
import { Application, Module } from '@sunmao-ui/core';
import {
BatchBranchOperation,
type BatchBranchOperationContext,
} from './operations/branch/batch';
import './styles.css';
type SunmaoUIEditorProps = {
@ -65,15 +61,6 @@ export function initSunmaoUIEditor(props: SunmaoUIEditorProps = {}) {
if (props.runtimeProps?.hooks?.didDomUpdate) props.runtimeProps.hooks.didDomUpdate();
};
const doOperations = (operations: BatchBranchOperationContext['operations']) => {
const context = {
operations,
};
const operation = new BatchBranchOperation(registry, context);
eventBus.send('operation', operation);
};
const ui = initSunmaoUI({
...props.runtimeProps,
hooks: { didMount, didUpdate, didDomUpdate },
@ -113,7 +100,6 @@ export function initSunmaoUIEditor(props: SunmaoUIEditorProps = {}) {
widgetManager,
eventBus,
editorStore,
doOperations,
};
const Editor: React.FC = () => {

View File

@ -3,6 +3,7 @@ import { RegistryInterface } from '@sunmao-ui/runtime';
import { EventBusType } from '../services/eventBus';
import { AppModel } from '../AppModel/AppModel';
import { IUndoRedoManager, IOperation, OperationList } from './type';
import { BatchBranchOperation, type BatchBranchOperationContext } from './branch/batch';
export class AppModelManager implements IUndoRedoManager {
appModel: AppModel;
@ -78,4 +79,13 @@ export class AppModelManager implements IUndoRedoManager {
console.warn('cannot undo as cursor has no operation', this.operationStack);
}
}
doOperations(operations: BatchBranchOperationContext['operations']) {
const context = {
operations,
};
const operation = new BatchBranchOperation(this.registry, context);
this.do(operation);
}
}

View File

@ -8,7 +8,6 @@ import { WidgetManager } from '@sunmao-ui/editor-sdk';
import { EditorStore } from './services/EditorStore';
import { EventBusType } from './services/eventBus';
import { AppModelManager } from './operations/AppModelManager';
import { type BatchBranchOperationContext } from './operations/branch/batch';
type ReturnOfInit = ReturnType<typeof initSunmaoUI>;
@ -21,7 +20,6 @@ export type EditorServices = {
widgetManager: WidgetManager;
eventBus: EventBusType;
editorStore: EditorStore;
doOperations: (operations: BatchBranchOperationContext['operations']) => void;
};
export type StorageHandler = {