(props: EditableProps)
| 77 | * ContentEditable. |
| 78 | */ |
| 79 | export const ContentEditable = (props: EditableProps) => { |
| 80 | const { |
| 81 | autoFocus = true, |
| 82 | placeholder, |
| 83 | readOnly: readOnlyProp = false, |
| 84 | lang, |
| 85 | style = {}, |
| 86 | as: Component = 'div', |
| 87 | selectionDrawingStyle: selectionDrawingStyleProp, |
| 88 | ...attributes |
| 89 | } = props |
| 90 | const editor = useEditableStatic() |
| 91 | |
| 92 | const ref = React.useRef<HTMLDivElement>(null) |
| 93 | const [readOnly, setReadOnly] = useReadOnly() |
| 94 | // 标记是否是刚拖拽完毕 |
| 95 | const isDragEnded = React.useRef(false) |
| 96 | const dragTo = useDragTo() |
| 97 | const dragging = useDragging() |
| 98 | const { getDrag, setDrag } = useDragMethods() |
| 99 | |
| 100 | const [rendered, setRendered] = React.useState(false) |
| 101 | |
| 102 | // Touch hold timer |
| 103 | const touchHoldTimer = React.useRef<number | null>(null) |
| 104 | |
| 105 | React.useEffect(() => { |
| 106 | if (placeholder && !readOnly) { |
| 107 | const unsubscribe = Placeholder.subscribe( |
| 108 | editor, |
| 109 | ([node]) => { |
| 110 | if (Editable.isEditor(node) && !node.children.some(n => Editor.isList(editor, n))) |
| 111 | return () => placeholder |
| 112 | }, |
| 113 | true, |
| 114 | ) |
| 115 | |
| 116 | return () => { |
| 117 | unsubscribe() |
| 118 | } |
| 119 | } |
| 120 | }, [editor, placeholder, readOnly]) |
| 121 | |
| 122 | useIsomorphicLayoutEffect(() => { |
| 123 | setReadOnly(readOnlyProp) |
| 124 | }, [readOnlyProp]) |
| 125 | |
| 126 | useIsomorphicLayoutEffect(() => { |
| 127 | Locale.setLang(editor, props.lang || 'en-US') |
| 128 | }, [editor, lang]) |
| 129 | |
| 130 | useIsomorphicLayoutEffect(() => { |
| 131 | if (selectionDrawingStyleProp) SelectionDrawing.setStyle(editor, selectionDrawingStyleProp) |
| 132 | }, [editor, selectionDrawingStyleProp]) |
| 133 | |
| 134 | const [focused, setFocused] = useFocused() |
| 135 | |
| 136 | const startPointRef = React.useRef<Point | null>(null) |
nothing calls this directly
no test coverage detected