(props: {
element: SlateElement
selection: Range | null
renderPlaceholder?: PlaceholderRender
})
| 22 | * Element. |
| 23 | */ |
| 24 | const Element = (props: { |
| 25 | element: SlateElement |
| 26 | selection: Range | null |
| 27 | renderPlaceholder?: PlaceholderRender |
| 28 | }) => { |
| 29 | const { element, selection, renderPlaceholder } = props |
| 30 | const ref = React.useRef<HTMLElement>(null) |
| 31 | const editor = useEditableStatic() |
| 32 | const isInline = editor.isInline(element) |
| 33 | const key = Editable.findKey(editor, element) |
| 34 | |
| 35 | const currentRenderPlaceholder = usePlaceholder(element) |
| 36 | let children: React.ReactNode = useChildren({ |
| 37 | node: element, |
| 38 | selection, |
| 39 | renderPlaceholder: Editor.isEmpty(editor, element) |
| 40 | ? currentRenderPlaceholder ?? renderPlaceholder |
| 41 | : undefined, |
| 42 | }) |
| 43 | |
| 44 | // Attributes that the developer must mix into the element in their |
| 45 | // custom node renderer component. |
| 46 | const attributes: ElementAttributes = { |
| 47 | [DATA_EDITABLE_NODE]: 'element', |
| 48 | ref, |
| 49 | } |
| 50 | |
| 51 | if (isInline) { |
| 52 | attributes[DATA_EDITABLE_INLINE] = true |
| 53 | } |
| 54 | |
| 55 | // If it's a block node with inline children, add the proper `dir` attribute |
| 56 | // for text direction. |
| 57 | if (!isInline && Editor.hasInlines(editor, element)) { |
| 58 | const text = Node.string(element) |
| 59 | const dir = getDirection(text) |
| 60 | |
| 61 | if (dir === 'rtl') { |
| 62 | attributes.dir = dir |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // If it's a void node, wrap the children in extra void-specific elements. |
| 67 | if (Editor.isVoid(editor, element)) { |
| 68 | attributes[DATA_EDITABLE_VOID] = true |
| 69 | |
| 70 | const Tag = isInline ? 'span' : 'div' |
| 71 | const [[text]] = Node.texts(element) |
| 72 | |
| 73 | children = ( |
| 74 | <Tag |
| 75 | style={{ |
| 76 | height: '0', |
| 77 | color: 'transparent', |
| 78 | outline: 'none', |
| 79 | }} |
| 80 | > |
| 81 | <Text |
nothing calls this directly
no test coverage detected
searching dependent graphs…