do not show placeholder if non editable

This commit is contained in:
Philipp Kühn
2019-02-06 11:28:40 +01:00
parent 44525063bc
commit 9b90d6437e
3 changed files with 17 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ export default class Placeholder extends Extension {
return {
emptyNodeClass: 'is-empty',
emptyNodeText: 'Write something...',
showOnlyWhenEditable: true,
}
}
@@ -18,7 +19,15 @@ export default class Placeholder extends Extension {
return [
new Plugin({
props: {
decorations: ({ doc }) => {
decorations: ({ doc, plugins }) => {
const editablePlugin = plugins.find(plugin => plugin.key.startsWith('editable$'))
const editable = editablePlugin.props.editable()
const active = editable || !this.options.showOnlyWhenEditable
if (!active) {
return false
}
const decorations = []
const completelyEmpty = doc.textContent === '' && doc.childCount <= 1 && doc.content.size <= 2