feat(editor): history增加page-change事件

This commit is contained in:
roymondchen 2022-11-25 16:34:42 +08:00
parent 64d71bef42
commit 830c8d8747
3 changed files with 20 additions and 16 deletions

View File

@ -25,9 +25,9 @@ import StageCore from '@tmagic/stage';
import { getNodePath, isNumber, isPage, isPop } from '@tmagic/utils';
import codeBlockService from '../services/codeBlock';
import historyService, { StepValue } from '../services/history';
import historyService from '../services/history';
import storageService, { Protocol } from '../services/storage';
import type { AddMNode, EditorNodeInfo, PastePosition, StoreState } from '../type';
import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState } from '../type';
import { LayerOffset, Layout } from '../type';
import {
change2Fixed,

View File

@ -18,25 +18,13 @@
import { reactive } from 'vue';
import type { Id, MPage } from '@tmagic/schema';
import type { MPage } from '@tmagic/schema';
import { HistoryState, StepValue } from '../type';
import { UndoRedo } from '../utils/undo-redo';
import BaseService from './BaseService';
export interface StepValue {
data: MPage;
modifiedNodeIds: Map<Id, Id>;
nodeId: Id;
}
export interface HistoryState {
pageId?: Id;
pageSteps: Record<Id, UndoRedo<StepValue>>;
canRedo: boolean;
canUndo: boolean;
}
class History extends BaseService {
public state = reactive<HistoryState>({
pageSteps: {},
@ -76,6 +64,8 @@ class History extends BaseService {
}
this.setCanUndoRedo();
this.emit('page-change', this.state.pageSteps[this.state.pageId]);
}
public empty(): void {

View File

@ -36,6 +36,7 @@ import type { HistoryService } from './services/history';
import type { PropsService } from './services/props';
import type { StorageService } from './services/storage';
import type { UiService } from './services/ui';
import type { UndoRedo } from './utils/undo-redo';
export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
@ -395,3 +396,16 @@ export interface CodeParamStatement {
/** 参数类型 */
type?: string;
}
export interface StepValue {
data: MPage;
modifiedNodeIds: Map<Id, Id>;
nodeId: Id;
}
export interface HistoryState {
pageId?: Id;
pageSteps: Record<Id, UndoRedo<StepValue>>;
canRedo: boolean;
canUndo: boolean;
}