mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-19 06:43:02 +08:00
add state getter
This commit is contained in:
parent
e4dd55d08b
commit
d4a9c0ee09
@ -71,7 +71,6 @@ export default class Editor extends Emitter {
|
||||
this.keymaps = this.createKeymaps()
|
||||
this.inputRules = this.createInputRules()
|
||||
this.pasteRules = this.createPasteRules()
|
||||
this.state = this.createState()
|
||||
this.view = this.createView()
|
||||
this.commands = this.createCommands()
|
||||
this.setActiveNodesAndMarks()
|
||||
@ -118,6 +117,10 @@ export default class Editor extends Emitter {
|
||||
]
|
||||
}
|
||||
|
||||
get state() {
|
||||
return this.view ? this.view.state : null
|
||||
}
|
||||
|
||||
createExtensions() {
|
||||
return new ExtensionManager([
|
||||
...this.builtInExtensions,
|
||||
@ -233,7 +236,7 @@ export default class Editor extends Emitter {
|
||||
|
||||
createView() {
|
||||
const view = new EditorView(this.element, {
|
||||
state: this.state,
|
||||
state: this.createState(),
|
||||
handlePaste: (...args) => { this.emit('paste', ...args) },
|
||||
handleDrop: (...args) => { this.emit('drop', ...args) },
|
||||
dispatchTransaction: this.dispatchTransaction.bind(this),
|
||||
@ -300,8 +303,8 @@ export default class Editor extends Emitter {
|
||||
}
|
||||
|
||||
dispatchTransaction(transaction) {
|
||||
this.state = this.state.apply(transaction)
|
||||
this.view.updateState(this.state)
|
||||
const newState = this.state.apply(transaction)
|
||||
this.view.updateState(newState)
|
||||
this.setActiveNodesAndMarks()
|
||||
|
||||
if (!transaction.docChanged) {
|
||||
@ -365,13 +368,13 @@ export default class Editor extends Emitter {
|
||||
}
|
||||
|
||||
setContent(content = {}, emitUpdate = false, parseOptions) {
|
||||
this.state = EditorState.create({
|
||||
const newState = EditorState.create({
|
||||
schema: this.state.schema,
|
||||
doc: this.createDocument(content, parseOptions),
|
||||
plugins: this.state.plugins,
|
||||
})
|
||||
|
||||
this.view.updateState(this.state)
|
||||
this.view.updateState(newState)
|
||||
|
||||
if (emitUpdate) {
|
||||
this.emitUpdate()
|
||||
@ -426,10 +429,10 @@ export default class Editor extends Emitter {
|
||||
return
|
||||
}
|
||||
|
||||
this.state = this.state.reconfigure({
|
||||
const newState = this.state.reconfigure({
|
||||
plugins: this.state.plugins.concat([plugin]),
|
||||
})
|
||||
this.view.updateState(this.state)
|
||||
this.view.updateState(newState)
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
Loading…
Reference in New Issue
Block a user