Merge pull request #210 from Chrissi2812/reactive-plugin-options
Reactive extension options
This commit is contained in:
@@ -299,6 +299,7 @@ The most powerful feature of tiptap is that you can create your own extensions.
|
|||||||
| `commands({ schema, attrs })` | `Object` | `null` | Define a command. |
|
| `commands({ schema, attrs })` | `Object` | `null` | Define a command. |
|
||||||
| `inputRules({ schema })` | `Array` | `[]` | Define a list of input rules. |
|
| `inputRules({ schema })` | `Array` | `[]` | Define a list of input rules. |
|
||||||
| `pasteRules({ schema })` | `Array` | `[]` | Define a list of paste rules. |
|
| `pasteRules({ schema })` | `Array` | `[]` | Define a list of paste rules. |
|
||||||
|
| `get update()` | `Function` | `undefined` | Called when options of extension are changed via `editor.extensions.options` |
|
||||||
|
|
||||||
### Node|Mark Class
|
### Node|Mark Class
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="editor">
|
<div class="editor">
|
||||||
|
<input type="text" v-model="placeholder">
|
||||||
<editor-content class="editor__content" :editor="editor" />
|
<editor-content class="editor__content" :editor="editor" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -18,6 +19,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
placeholder: 'Write something …',
|
||||||
editor: new Editor({
|
editor: new Editor({
|
||||||
extensions: [
|
extensions: [
|
||||||
new BulletList(),
|
new BulletList(),
|
||||||
@@ -34,6 +36,11 @@ export default {
|
|||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.editor.destroy()
|
this.editor.destroy()
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
placeholder(newValue) {
|
||||||
|
this.editor.extensions.options.placeholder.emptyNodeText = newValue
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ export default class Placeholder extends Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get update() {
|
||||||
|
return view => {
|
||||||
|
view.updateState(view.state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get plugins() {
|
get plugins() {
|
||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ export default class Editor {
|
|||||||
view: this.view,
|
view: this.view,
|
||||||
state: this.state,
|
state: this.state,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// give extension manager access to our view
|
||||||
|
this.extensions.view = this.view
|
||||||
}
|
}
|
||||||
|
|
||||||
setOptions(options) {
|
setOptions(options) {
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ export default class Extension {
|
|||||||
return 'extension'
|
return 'extension'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get update() {
|
||||||
|
return () => {}
|
||||||
|
}
|
||||||
|
|
||||||
get defaultOptions() {
|
get defaultOptions() {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,27 @@ export default class ExtensionManager {
|
|||||||
}), {})
|
}), {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get options() {
|
||||||
|
const { view } = this
|
||||||
|
return this.extensions
|
||||||
|
.reduce((nodes, extension) => ({
|
||||||
|
...nodes,
|
||||||
|
[extension.name]: new Proxy(extension.options, {
|
||||||
|
set(obj, prop, value) {
|
||||||
|
const changed = (obj[prop] !== value)
|
||||||
|
|
||||||
|
Object.assign(obj, { [prop]: value })
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
extension.update(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}), {})
|
||||||
|
}
|
||||||
|
|
||||||
get marks() {
|
get marks() {
|
||||||
return this.extensions
|
return this.extensions
|
||||||
.filter(extension => extension.type === 'mark')
|
.filter(extension => extension.type === 'mark')
|
||||||
|
|||||||
Reference in New Issue
Block a user