add resize event
This commit is contained in:
@@ -45,6 +45,8 @@ export class Editor extends EventEmitter {
|
||||
|
||||
public isFocused = false
|
||||
|
||||
private resizeObserver!: ResizeObserver
|
||||
|
||||
public options: EditorOptions = {
|
||||
element: document.createElement('div'),
|
||||
content: '',
|
||||
@@ -63,6 +65,7 @@ export class Editor extends EventEmitter {
|
||||
onTransaction: () => null,
|
||||
onFocus: () => null,
|
||||
onBlur: () => null,
|
||||
onResize: () => null,
|
||||
onDestroy: () => null,
|
||||
}
|
||||
|
||||
@@ -86,7 +89,15 @@ export class Editor extends EventEmitter {
|
||||
window.setTimeout(() => {
|
||||
this.commands.focus(this.options.autofocus)
|
||||
this.emit('create', { editor: this })
|
||||
|
||||
if (window.ResizeObserver) {
|
||||
this.resizeObserver = new ResizeObserver(() => {
|
||||
this.emit('resize', { editor: this })
|
||||
})
|
||||
this.resizeObserver.observe(this.view.dom)
|
||||
}
|
||||
}, 0)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,6 +453,8 @@ export class Editor extends EventEmitter {
|
||||
* Destroy the editor.
|
||||
*/
|
||||
public destroy(): void {
|
||||
this.resizeObserver?.unobserve(this.view.dom)
|
||||
|
||||
this.emit('destroy')
|
||||
|
||||
if (this.view) {
|
||||
|
||||
@@ -36,6 +36,7 @@ export interface EditorOptions {
|
||||
onTransaction: (props: { editor: Editor, transaction: Transaction }) => void,
|
||||
onFocus: (props: { editor: Editor, event: FocusEvent }) => void,
|
||||
onBlur: (props: { editor: Editor, event: FocusEvent }) => void,
|
||||
onResize: (props: { editor: Editor }) => void,
|
||||
onDestroy: () => void,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user