Files
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

24 lines
712 B
TypeScript

import { Plugin } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import type { Node } from 'prosemirror-model';
const isEmptyParagraph = (node: Node) => {
return node.type.name === 'paragraph' && node.nodeSize === 2;
};
export const placeholderPlugin = (placeholder: string) => {
return new Plugin({
props: {
decorations(state) {
const { $from } = state.selection;
if (isEmptyParagraph($from.parent)) {
const decoration = Decoration.node($from.before(), $from.after(), {
'data-placeholder': placeholder,
});
return DecorationSet.create(state.doc, [decoration]);
}
},
},
});
};