mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
make options for extensions reactive
changing options will call the update method off the extension.
This commit is contained in:
parent
3de6b13004
commit
45945e2c09
@ -67,6 +67,10 @@ export default class Editor {
|
||||
view: this.view,
|
||||
state: this.state,
|
||||
})
|
||||
|
||||
// give extension manager access to our view and state
|
||||
this.extensions.state = this.state
|
||||
this.extensions.view = this.view
|
||||
}
|
||||
|
||||
setOptions(options) {
|
||||
|
@ -15,6 +15,10 @@ export default class Extension {
|
||||
return 'extension'
|
||||
}
|
||||
|
||||
get update() {
|
||||
return () => {}
|
||||
}
|
||||
|
||||
get defaultOptions() {
|
||||
return {}
|
||||
}
|
||||
|
@ -15,6 +15,28 @@ export default class ExtensionManager {
|
||||
}), {})
|
||||
}
|
||||
|
||||
get options() {
|
||||
const { state, view } = this
|
||||
return this.extensions
|
||||
// { name, options, update = () => {} }
|
||||
.reduce((nodes, extension) => ({
|
||||
...nodes,
|
||||
[extension.name]: new Proxy(extension.options, {
|
||||
set(obj, prop, value) {
|
||||
const changed = (obj[prop] !== value)
|
||||
|
||||
obj[prop] = value
|
||||
|
||||
if (changed) {
|
||||
extension.update({ state, view })
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
}),
|
||||
}), {})
|
||||
}
|
||||
|
||||
get marks() {
|
||||
return this.extensions
|
||||
.filter(extension => extension.type === 'mark')
|
||||
|
Loading…
Reference in New Issue
Block a user