add-empty-editor-class-to-root-div
This commit is contained in:
@@ -32,6 +32,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
|
let cachedEmptyTopNode: ProsemirrorNode;
|
||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
props: {
|
props: {
|
||||||
@@ -44,14 +45,18 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
|
||||||
|
let isEditorEmpty = cachedEmptyTopNode.content.findDiffStart(state.doc.content) === null
|
||||||
|
|
||||||
doc.descendants((node, pos) => {
|
doc.descendants((node, pos) => {
|
||||||
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
||||||
const isEmpty = !node.isLeaf && !node.childCount
|
const isEmpty = !node.isLeaf && !node.childCount
|
||||||
|
|
||||||
|
|
||||||
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
||||||
const classes = [this.options.emptyNodeClass]
|
const classes = [this.options.emptyNodeClass]
|
||||||
|
|
||||||
if (this.editor.isEmpty) {
|
if (isEditorEmpty) {
|
||||||
classes.push(this.options.emptyEditorClass)
|
classes.push(this.options.emptyEditorClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +81,14 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|||||||
return DecorationSet.create(doc, decorations)
|
return DecorationSet.create(doc, decorations)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
attributes(state) {
|
||||||
|
cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
|
||||||
|
let isEditorEmpty = cachedEmptyTopNode.content.findDiffStart(state.doc.content) === null
|
||||||
|
if (isEditorEmpty) {
|
||||||
|
return {class: this.options.emptyEditorClass}
|
||||||
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user