UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

33 lines 1.25 kB
import { Plugin, PluginKey, DecorationSet, Decoration } from '../../../prosemirror'; import { isEmpty, isEmptyParagraph } from '../../utils'; export var pluginKey = new PluginKey('placeholderPlugin'); export function createPlaceholderDecoration(doc, placeholderText) { var placeholderNode = document.createElement('span'); placeholderNode.className = 'placeholder-decoration'; placeholderNode.setAttribute('data-text', placeholderText); return DecorationSet.create(doc, [Decoration.widget(1, placeholderNode)]); } export function createPlugin(placeholderText) { if (!placeholderText) { return; } return new Plugin({ key: pluginKey, props: { decorations: function (editorState) { if (isEmpty(editorState.doc) && isEmptyParagraph(editorState.doc.firstChild)) { return createPlaceholderDecoration(editorState.doc, placeholderText); } } } }); } var placeholderPlugin = { pmPlugins: function () { return [ { rank: 10000, plugin: function (schema, props) { return createPlugin(props.placeholder); } } ]; } }; export default placeholderPlugin; //# sourceMappingURL=index.js.map