feat:add control change callback
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { ControlComponent, ControlType } from '../../../dataset/enum/Control'
|
||||
import { ElementType } from '../../../dataset/enum/Element'
|
||||
import { IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control'
|
||||
import { IControl, IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control'
|
||||
import { IElement, IElementPosition } from '../../../interface/Element'
|
||||
import { deepClone } from '../../../utils'
|
||||
import { pickElementAttr, zipElementList } from '../../../utils/element'
|
||||
import { Listener } from '../../listener/Listener'
|
||||
import { RangeManager } from '../../range/RangeManager'
|
||||
import { Draw } from '../Draw'
|
||||
import { SelectControl } from './select/SelectControl'
|
||||
@@ -15,12 +18,14 @@ export class Control {
|
||||
|
||||
private draw: Draw
|
||||
private range: RangeManager
|
||||
private listener: Listener
|
||||
private options: IControlOption
|
||||
private activeControl: IControlInstance | null
|
||||
|
||||
constructor(draw: Draw) {
|
||||
this.draw = draw
|
||||
this.range = draw.getRange()
|
||||
this.listener = draw.getListener()
|
||||
this.options = draw.getOptions().control
|
||||
this.activeControl = null
|
||||
}
|
||||
@@ -97,6 +102,19 @@ export class Control {
|
||||
this.activeControl = selectControl
|
||||
selectControl.awake()
|
||||
}
|
||||
// 激活控件回调
|
||||
setTimeout(() => {
|
||||
if (this.listener.controlChange) {
|
||||
let payload: IControl
|
||||
const value = this.activeControl?.getValue()
|
||||
if (value && value.length) {
|
||||
payload = zipElementList(value)[0].control!
|
||||
} else {
|
||||
payload = pickElementAttr(deepClone(element)).control!
|
||||
}
|
||||
this.listener.controlChange(payload)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public destroyControl() {
|
||||
@@ -105,6 +123,12 @@ export class Control {
|
||||
this.activeControl.destroy()
|
||||
}
|
||||
this.activeControl = null
|
||||
// 销毁控件回调
|
||||
setTimeout(() => {
|
||||
if (this.listener.controlChange) {
|
||||
this.listener.controlChange(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
IContentChange,
|
||||
IControlChange,
|
||||
IIntersectionPageNoChange,
|
||||
IPageScaleChange,
|
||||
IPageSizeChange,
|
||||
@@ -17,6 +18,7 @@ export class Listener {
|
||||
public pageScaleChange: IPageScaleChange | null
|
||||
public saved: ISaved | null
|
||||
public contentChange: IContentChange | null
|
||||
public controlChange: IControlChange | null
|
||||
|
||||
constructor() {
|
||||
this.rangeStyleChange = null
|
||||
@@ -26,6 +28,7 @@ export class Listener {
|
||||
this.pageScaleChange = null
|
||||
this.saved = null
|
||||
this.contentChange = null
|
||||
this.controlChange = null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ElementType } from '..'
|
||||
import { RowFlex } from '../dataset/enum/Row'
|
||||
import { IControl } from './Control'
|
||||
import { IEditorResult } from './Editor'
|
||||
|
||||
export interface IRangeStyle {
|
||||
@@ -32,3 +33,5 @@ export type IPageScaleChange = (payload: number) => void
|
||||
export type ISaved = (payload: IEditorResult) => void
|
||||
|
||||
export type IContentChange = () => void
|
||||
|
||||
export type IControlChange = (payload: IControl | null) => void
|
||||
Reference in New Issue
Block a user