(props: {
isLast: boolean
parent: Element
leaf: Text
text: Text
renderPlaceholder?: PlaceholderRender
})
| 10 | * Individual leaves in a text node with unique formatting. |
| 11 | */ |
| 12 | const Leaf = (props: { |
| 13 | isLast: boolean |
| 14 | parent: Element |
| 15 | leaf: Text |
| 16 | text: Text |
| 17 | renderPlaceholder?: PlaceholderRender |
| 18 | }) => { |
| 19 | const { isLast, text, leaf, parent, renderPlaceholder } = props |
| 20 | |
| 21 | let children = <String isLast={isLast} parent={parent} text={text} leaf={leaf} /> |
| 22 | |
| 23 | const editor = useEditableStatic() |
| 24 | if (renderPlaceholder) { |
| 25 | const placeholderComponent = editor.renderPlaceholder({ |
| 26 | attributes: { [DATA_EDITABLE_PLACEHOLDER]: true }, |
| 27 | node: text, |
| 28 | children: renderPlaceholder({ node: text }), |
| 29 | }) |
| 30 | if (placeholderComponent) |
| 31 | children = ( |
| 32 | <React.Fragment> |
| 33 | {placeholderComponent} |
| 34 | {children} |
| 35 | </React.Fragment> |
| 36 | ) |
| 37 | } |
| 38 | |
| 39 | // COMPAT: Having the `data-` attributes on these leaf elements ensures that |
| 40 | // in certain misbehaving browsers they aren't weirdly cloned/destroyed by |
| 41 | // contenteditable behaviors. (2019/05/08) |
| 42 | const attributes: TextAttributes = { |
| 43 | [DATA_EDITABLE_LEAF]: true, |
| 44 | } |
| 45 | const newAttributes = editor.renderLeafAttributes({ attributes, text }) |
| 46 | return editor.renderLeaf({ attributes: newAttributes, children, text }) |
| 47 | } |
| 48 | |
| 49 | const MemoizedLeaf = React.memo(Leaf, (prev, next) => { |
| 50 | return ( |
nothing calls this directly
no test coverage detected