rename init to create
This commit is contained in:
@@ -10,7 +10,7 @@ You can define your event listeners on a new editor instance right-away:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const editor = new Editor({
|
const editor = new Editor({
|
||||||
onInit() {
|
onCreate() {
|
||||||
// The editor is ready.
|
// The editor is ready.
|
||||||
},
|
},
|
||||||
onUpdate() {
|
onUpdate() {
|
||||||
@@ -28,6 +28,9 @@ const editor = new Editor({
|
|||||||
onBlur({ event }) {
|
onBlur({ event }) {
|
||||||
// The editor isn’t focused anymore.
|
// The editor isn’t focused anymore.
|
||||||
},
|
},
|
||||||
|
onDestroy() {
|
||||||
|
// The editor is destroyed.
|
||||||
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ Or you can register your event listeners on a running editor instance:
|
|||||||
|
|
||||||
### Bind event listeners
|
### Bind event listeners
|
||||||
```js
|
```js
|
||||||
editor.on('init', () => {
|
editor.on('create', () => {
|
||||||
// The editor is ready.
|
// The editor is ready.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +62,10 @@ editor.on('focus', ({ event }) => {
|
|||||||
editor.on('blur', ({ event }) => {
|
editor.on('blur', ({ event }) => {
|
||||||
// The editor isn’t focused anymore.
|
// The editor isn’t focused anymore.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor.on('destroy', () => {
|
||||||
|
// The editor is destroyed.
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Unbind event listeners
|
### Unbind event listeners
|
||||||
|
|||||||
@@ -50,12 +50,13 @@ export class Editor extends EventEmitter {
|
|||||||
parseOptions: {},
|
parseOptions: {},
|
||||||
enableInputRules: true,
|
enableInputRules: true,
|
||||||
enablePasteRules: true,
|
enablePasteRules: true,
|
||||||
onInit: () => null,
|
onCreate: () => null,
|
||||||
onUpdate: () => null,
|
onUpdate: () => null,
|
||||||
onSelection: () => null,
|
onSelection: () => null,
|
||||||
onTransaction: () => null,
|
onTransaction: () => null,
|
||||||
onFocus: () => null,
|
onFocus: () => null,
|
||||||
onBlur: () => null,
|
onBlur: () => null,
|
||||||
|
onDestroy: () => null,
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(options: Partial<EditorOptions> = {}) {
|
constructor(options: Partial<EditorOptions> = {}) {
|
||||||
@@ -73,16 +74,17 @@ export class Editor extends EventEmitter {
|
|||||||
this.createSchema()
|
this.createSchema()
|
||||||
this.createView()
|
this.createView()
|
||||||
this.injectCSS()
|
this.injectCSS()
|
||||||
this.on('init', this.options.onInit)
|
this.on('create', this.options.onCreate)
|
||||||
this.on('update', this.options.onUpdate)
|
this.on('update', this.options.onUpdate)
|
||||||
this.on('selection', this.options.onSelection)
|
this.on('selection', this.options.onSelection)
|
||||||
this.on('transaction', this.options.onTransaction)
|
this.on('transaction', this.options.onTransaction)
|
||||||
this.on('focus', this.options.onFocus)
|
this.on('focus', this.options.onFocus)
|
||||||
this.on('blur', this.options.onBlur)
|
this.on('blur', this.options.onBlur)
|
||||||
|
this.on('destroy', this.options.onDestroy)
|
||||||
|
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
this.commands.focus(this.options.autofocus)
|
this.commands.focus(this.options.autofocus)
|
||||||
this.emit('init')
|
this.emit('create')
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,13 @@ export interface EditorOptions {
|
|||||||
parseOptions: ParseOptions,
|
parseOptions: ParseOptions,
|
||||||
enableInputRules: boolean,
|
enableInputRules: boolean,
|
||||||
enablePasteRules: boolean,
|
enablePasteRules: boolean,
|
||||||
onInit: () => void,
|
onCreate: () => void,
|
||||||
onUpdate: () => void,
|
onUpdate: () => void,
|
||||||
onSelection: () => void,
|
onSelection: () => void,
|
||||||
onTransaction: (props: { transaction: Transaction }) => void,
|
onTransaction: (props: { transaction: Transaction }) => void,
|
||||||
onFocus: (props: { event: FocusEvent }) => void,
|
onFocus: (props: { event: FocusEvent }) => void,
|
||||||
onBlur: (props: { event: FocusEvent }) => void,
|
onBlur: (props: { event: FocusEvent }) => void,
|
||||||
|
onDestroy: () => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EditorContent = string | JSON | null
|
export type EditorContent = string | JSON | null
|
||||||
|
|||||||
Reference in New Issue
Block a user