add placeholder extension
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"dependencies": {
|
||||
"lowlight": "^1.10.0",
|
||||
"prosemirror-history": "^1.0.2",
|
||||
"prosemirror-view": "^1.5.1",
|
||||
"tiptap": "^0.10.0",
|
||||
"tiptap-commands": "^0.3.0"
|
||||
}
|
||||
|
||||
39
packages/tiptap-extensions/src/extensions/Placeholder.js
Normal file
39
packages/tiptap-extensions/src/extensions/Placeholder.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Extension, Plugin } from 'tiptap'
|
||||
import { Decoration, DecorationSet } from 'prosemirror-view'
|
||||
|
||||
export default class PlaceholderExtension extends Extension {
|
||||
|
||||
get name() {
|
||||
return 'placeholder'
|
||||
}
|
||||
|
||||
get defaultOptions() {
|
||||
return {
|
||||
emptyNodeClass: 'is-empty',
|
||||
}
|
||||
}
|
||||
|
||||
get plugins() {
|
||||
return [
|
||||
new Plugin({
|
||||
props: {
|
||||
decorations: state => {
|
||||
const decorations = []
|
||||
|
||||
state.doc.descendants((node, pos) => {
|
||||
if (node.type.isBlock && node.childCount === 0) {
|
||||
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
||||
class: this.options.emptyNodeClass,
|
||||
})
|
||||
decorations.push(decoration)
|
||||
}
|
||||
})
|
||||
|
||||
return DecorationSet.create(state.doc, decorations)
|
||||
},
|
||||
},
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,3 +17,4 @@ export { default as LinkMark } from './marks/Link'
|
||||
export { default as StrikeMark } from './marks/Strike'
|
||||
|
||||
export { default as HistoryExtension } from './extensions/History'
|
||||
export { default as PlaceholderExtension } from './extensions/Placeholder'
|
||||
|
||||
Reference in New Issue
Block a user