| 1 | import { type AnyPluginConfig } from "platejs"; |
| 2 | import { createTPlatePlugin, type RenderNodeWrapper } from "platejs/react"; |
| 3 | |
| 4 | import PlaceHolderCard from "../custom-elements/placeholder-card"; |
| 5 | |
| 6 | const elementsToIncludeTheTemplate = ["p", "h1", "h2", "h3", "h4", "h5", "h6"]; |
| 7 | const placeHolderWrapper: RenderNodeWrapper<AnyPluginConfig> = (props) => { |
| 8 | const { editor, element } = props; |
| 9 | const isEmpty = editor.api.isEmpty(); |
| 10 | const readonly = editor.api.isReadOnly(); |
| 11 | |
| 12 | if ( |
| 13 | readonly || |
| 14 | !isEmpty || |
| 15 | !elementsToIncludeTheTemplate.includes(element.type) |
| 16 | ) |
| 17 | return (props) => props.children; |
| 18 | |
| 19 | return (props) => <PlaceHolderCard {...props} />; |
| 20 | }; |
| 21 | |
| 22 | export const CustomPlaceholderPlugin = createTPlatePlugin({ |
| 23 | key: "customPlaceholder", |
| 24 | render: { |
| 25 | aboveNodes: placeHolderWrapper, |
| 26 | }, |
| 27 | }); |
| 28 |