do not show placeholder if non editable
This commit is contained in:
@@ -25,6 +25,7 @@ export default {
|
|||||||
new Placeholder({
|
new Placeholder({
|
||||||
emptyClass: 'is-empty',
|
emptyClass: 'is-empty',
|
||||||
emptyNodeText: 'Write something …',
|
emptyNodeText: 'Write something …',
|
||||||
|
showOnlyWhenEditable: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export default class Placeholder extends Extension {
|
|||||||
return {
|
return {
|
||||||
emptyNodeClass: 'is-empty',
|
emptyNodeClass: 'is-empty',
|
||||||
emptyNodeText: 'Write something...',
|
emptyNodeText: 'Write something...',
|
||||||
|
showOnlyWhenEditable: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +19,15 @@ export default class Placeholder extends Extension {
|
|||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
props: {
|
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 decorations = []
|
||||||
const completelyEmpty = doc.textContent === '' && doc.childCount <= 1 && doc.content.size <= 2
|
const completelyEmpty = doc.textContent === '' && doc.childCount <= 1 && doc.content.size <= 2
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EditorState, Plugin } from 'prosemirror-state'
|
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
|
||||||
import { EditorView } from 'prosemirror-view'
|
import { EditorView } from 'prosemirror-view'
|
||||||
import { Schema, DOMParser, DOMSerializer } from 'prosemirror-model'
|
import { Schema, DOMParser, DOMSerializer } from 'prosemirror-model'
|
||||||
import { dropCursor } from 'prosemirror-dropcursor'
|
import { dropCursor } from 'prosemirror-dropcursor'
|
||||||
@@ -162,8 +162,13 @@ export default class Editor {
|
|||||||
dropCursor(this.options.dropCursor),
|
dropCursor(this.options.dropCursor),
|
||||||
gapCursor(),
|
gapCursor(),
|
||||||
new Plugin({
|
new Plugin({
|
||||||
|
key: new PluginKey('editable'),
|
||||||
props: {
|
props: {
|
||||||
editable: () => this.options.editable,
|
editable: () => this.options.editable,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Plugin({
|
||||||
|
props: {
|
||||||
attributes: {
|
attributes: {
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user