feat: add override internal function api #260

This commit is contained in:
Hufe921
2023-08-30 22:11:05 +08:00
parent 640f26292f
commit abcaa9b51c
7 changed files with 72 additions and 2 deletions
+6
View File
@@ -57,6 +57,12 @@ export class CursorAgent {
if (isReadonly) return
const clipboardData = evt.clipboardData
if (!clipboardData) return
// 自定义粘贴事件
const { paste } = this.draw.getOverride()
if (paste) {
paste(evt)
return
}
const rangeManager = this.draw.getRange()
const { startIndex } = rangeManager.getRange()
const elementList = this.draw.getElementList()
+9 -1
View File
@@ -83,6 +83,7 @@ import { WORD_LIKE_REG } from '../../dataset/constant/Regular'
import { EventBus } from '../event/eventbus/EventBus'
import { EventBusMap } from '../../interface/EventBus'
import { Group } from './interactive/Group'
import { Override } from '../override/Override'
export class Draw {
private container: HTMLDivElement
@@ -98,6 +99,7 @@ export class Draw {
private elementList: IElement[]
private listener: Listener
private eventBus: EventBus<EventBusMap>
private override: Override
private i18n: I18n
private canvasEvent: CanvasEvent
@@ -152,7 +154,8 @@ export class Draw {
options: DeepRequired<IEditorOption>,
data: IEditorData,
listener: Listener,
eventBus: EventBus<EventBusMap>
eventBus: EventBus<EventBusMap>,
override: Override
) {
this.container = this._wrapContainer(rootContainer)
this.pageList = []
@@ -164,6 +167,7 @@ export class Draw {
this.elementList = data.main
this.listener = listener
this.eventBus = eventBus
this.override = override
this._formatContainer()
this.pageContainer = this._createPageContainer()
@@ -622,6 +626,10 @@ export class Draw {
return this.eventBus
}
public getOverride(): Override {
return this.override
}
public getCursor(): Cursor {
return this.cursor
}
+3
View File
@@ -0,0 +1,3 @@
export class Override {
public paste: ((evt: ClipboardEvent) => void) | undefined
}
+6 -1
View File
@@ -62,11 +62,13 @@ import { EventBusMap } from './interface/EventBus'
import { IGroup } from './interface/Group'
import { defaultGroupOption } from './dataset/constant/Group'
import { IRangeStyle } from './interface/Listener'
import { Override } from './core/override/Override'
export default class Editor {
public command: Command
public listener: Listener
public eventBus: EventBus<EventBusMap>
public override: Override
public register: Register
public destroy: () => void
public use: UsePlugin
@@ -193,6 +195,8 @@ export default class Editor {
this.listener = new Listener()
// 事件
this.eventBus = new EventBus<EventBusMap>()
// 重写
this.override = new Override()
// 启动
const draw = new Draw(
container,
@@ -203,7 +207,8 @@ export default class Editor {
footer: footerElementList
},
this.listener,
this.eventBus
this.eventBus,
this.override
)
// 命令
this.command = new Command(new CommandAdapt(draw))