From 86871c310be1402f03831ca182698e7ba78a7912 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 4 Apr 2023 19:57:33 +0800 Subject: [PATCH] feat: add zone change listener --- src/editor/core/listener/Listener.ts | 5 ++++- src/editor/core/zone/Zone.ts | 8 ++++++++ src/editor/interface/Listener.ts | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/editor/core/listener/Listener.ts b/src/editor/core/listener/Listener.ts index 7479d47..c92242c 100644 --- a/src/editor/core/listener/Listener.ts +++ b/src/editor/core/listener/Listener.ts @@ -7,7 +7,8 @@ import { IPageSizeChange, IRangeStyleChange, ISaved, - IVisiblePageNoListChange + IVisiblePageNoListChange, + IZoneChange } from '../../interface/Listener' export class Listener { @@ -21,6 +22,7 @@ export class Listener { public contentChange: IContentChange | null public controlChange: IControlChange | null public pageModeChange: IPageModeChange | null + public zoneChange: IZoneChange | null constructor() { this.rangeStyleChange = null @@ -32,6 +34,7 @@ export class Listener { this.contentChange = null this.controlChange = null this.pageModeChange = null + this.zoneChange = null } } \ No newline at end of file diff --git a/src/editor/core/zone/Zone.ts b/src/editor/core/zone/Zone.ts index e19d401..3200cdd 100644 --- a/src/editor/core/zone/Zone.ts +++ b/src/editor/core/zone/Zone.ts @@ -1,6 +1,7 @@ import { EDITOR_PREFIX } from '../../dataset/constant/Editor' import { EditorZone } from '../../dataset/enum/Editor' import { IEditorOption } from '../../interface/Editor' +import { nextTick } from '../../utils' import { Draw } from '../draw/Draw' import { I18n } from '../i18n/I18n' @@ -53,6 +54,13 @@ export class Zone { }) // 指示器 this.drawZoneIndicator() + // 回调 + nextTick(() => { + const listener = this.draw.getListener() + if (listener.zoneChange) { + listener.zoneChange(payload) + } + }) } public drawZoneIndicator() { diff --git a/src/editor/interface/Listener.ts b/src/editor/interface/Listener.ts index f8f1af2..7ef0596 100644 --- a/src/editor/interface/Listener.ts +++ b/src/editor/interface/Listener.ts @@ -1,4 +1,4 @@ -import { ElementType, PageMode } from '..' +import { EditorZone, ElementType, PageMode } from '..' import { RowFlex } from '../dataset/enum/Row' import { IControl } from './Control' import { IEditorResult } from './Editor' @@ -37,4 +37,6 @@ export type IContentChange = () => void export type IControlChange = (payload: IControl | null) => void -export type IPageModeChange = (payload: PageMode) => void \ No newline at end of file +export type IPageModeChange = (payload: PageMode) => void + +export type IZoneChange = (payload: EditorZone) => void \ No newline at end of file