allow setOptions updating options
This commit is contained in:
@@ -12,11 +12,31 @@ import { Doc, Paragraph, Text } from './Nodes'
|
|||||||
export default class Editor {
|
export default class Editor {
|
||||||
|
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
|
this.defaultOptions = {
|
||||||
|
editable: true,
|
||||||
|
extensions: [],
|
||||||
|
content: '',
|
||||||
|
emptyDocument: {
|
||||||
|
type: 'doc',
|
||||||
|
content: [{
|
||||||
|
type: 'paragraph',
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
useBuiltInExtensions: true,
|
||||||
|
onInit: () => {},
|
||||||
|
onUpdate: () => {},
|
||||||
|
onFocus: () => {},
|
||||||
|
onBlur: () => {},
|
||||||
|
}
|
||||||
|
|
||||||
this.init(options)
|
this.init(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(options = {}) {
|
init(options = {}) {
|
||||||
this.setOptions(options)
|
this.setOptions({
|
||||||
|
...this.defaultOptions,
|
||||||
|
...options,
|
||||||
|
})
|
||||||
this.element = document.createElement('div')
|
this.element = document.createElement('div')
|
||||||
this.extensions = this.createExtensions()
|
this.extensions = this.createExtensions()
|
||||||
this.nodes = this.createNodes()
|
this.nodes = this.createNodes()
|
||||||
@@ -37,26 +57,13 @@ export default class Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setOptions(options) {
|
setOptions(options) {
|
||||||
const defaultOptions = {
|
this.options = {
|
||||||
editable: true,
|
...this.options,
|
||||||
extensions: [],
|
...options,
|
||||||
content: '',
|
|
||||||
emptyDocument: {
|
|
||||||
type: 'doc',
|
|
||||||
content: [{
|
|
||||||
type: 'paragraph',
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
useBuiltInExtensions: true,
|
|
||||||
onInit: () => {},
|
|
||||||
onUpdate: () => {},
|
|
||||||
onFocus: () => {},
|
|
||||||
onBlur: () => {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options = {
|
if (this.view && this.state) {
|
||||||
...defaultOptions,
|
this.view.updateState(this.state)
|
||||||
...options,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user