fix placeholder
This commit is contained in:
@@ -8,7 +8,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Editor } from 'tiptap'
|
import { Editor } from 'tiptap'
|
||||||
import { PlaceholderExtension } from 'tiptap-extensions'
|
import {
|
||||||
|
BulletListNode,
|
||||||
|
ListItemNode,
|
||||||
|
PlaceholderExtension,
|
||||||
|
} from 'tiptap-extensions'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -17,6 +21,8 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
extensions: [
|
extensions: [
|
||||||
|
new BulletListNode(),
|
||||||
|
new ListItemNode(),
|
||||||
new PlaceholderExtension({
|
new PlaceholderExtension({
|
||||||
emptyNodeClass: 'is-empty',
|
emptyNodeClass: 'is-empty',
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -17,19 +17,22 @@ export default class PlaceholderExtension extends Extension {
|
|||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
props: {
|
props: {
|
||||||
decorations: state => {
|
decorations: ({ doc }) => {
|
||||||
const decorations = []
|
const decorations = []
|
||||||
|
const completelyEmpty = doc.textContent === '' && doc.childCount <= 1 && doc.content.size <= 2
|
||||||
|
|
||||||
|
doc.descendants((node, pos) => {
|
||||||
|
if (!completelyEmpty) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
state.doc.descendants((node, pos) => {
|
|
||||||
if (node.type.isBlock && node.childCount === 0) {
|
|
||||||
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
||||||
class: this.options.emptyNodeClass,
|
class: this.options.emptyNodeClass,
|
||||||
})
|
})
|
||||||
decorations.push(decoration)
|
decorations.push(decoration)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return DecorationSet.create(state.doc, decorations)
|
return DecorationSet.create(doc, decorations)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user