({ autoFocus })
| 25 | } |
| 26 | |
| 27 | const InputComponent: React.FC<InputProps> = ({ autoFocus }) => { |
| 28 | const editor = useEditableStatic() |
| 29 | const inputRef = React.useRef<HTMLTextAreaElement>(null) |
| 30 | const [focused, setFocused] = useFocused() |
| 31 | const [readOnly] = useReadOnly() |
| 32 | |
| 33 | const [rect, setRect] = React.useState<ShadowRect | null>(null) |
| 34 | |
| 35 | useIsomorphicLayoutEffect(() => { |
| 36 | if (inputRef.current) EDITOR_TO_INPUT.set(editor, inputRef.current) |
| 37 | return () => { |
| 38 | EDITOR_TO_INPUT.delete(editor) |
| 39 | } |
| 40 | }, [editor]) |
| 41 | |
| 42 | useEffect(() => { |
| 43 | if (autoFocus) { |
| 44 | editor.focus() |
| 45 | Editable.scrollIntoView(editor) |
| 46 | } |
| 47 | }, [editor, autoFocus]) |
| 48 | |
| 49 | const handleKeydown = (event: React.KeyboardEvent) => { |
| 50 | const { nativeEvent } = event |
| 51 | if (Editable.isComposing(editor) && nativeEvent.isComposing === false) { |
| 52 | IS_COMPOSING.set(editor, false) |
| 53 | } |
| 54 | |
| 55 | if (event.defaultPrevented || Editable.isComposing(editor)) { |
| 56 | return |
| 57 | } |
| 58 | editor.onKeydown(nativeEvent) |
| 59 | } |
| 60 | |
| 61 | const handleKeyup = (event: React.KeyboardEvent) => { |
| 62 | const { nativeEvent } = event |
| 63 | editor.onKeyup(nativeEvent) |
| 64 | } |
| 65 | |
| 66 | const handleBlur = () => { |
| 67 | if (!IS_MOUSEDOWN.get(editor) && !IS_TOUCHING.get(editor)) setFocused(false) |
| 68 | } |
| 69 | |
| 70 | const handleFocus = () => { |
| 71 | setFocused(true) |
| 72 | } |
| 73 | |
| 74 | const handleBeforeInput = (event: React.FormEvent<HTMLTextAreaElement>) => { |
| 75 | const textarea = event.target |
| 76 | if (!(textarea instanceof HTMLTextAreaElement)) return |
| 77 | const { value } = textarea |
| 78 | editor.onBeforeInput(value) |
| 79 | } |
| 80 | |
| 81 | const handleInput = (event: React.FormEvent<HTMLTextAreaElement>) => { |
| 82 | const textarea = event.target |
| 83 | if (!(textarea instanceof HTMLTextAreaElement)) return |
| 84 | const value = textarea.value |
nothing calls this directly
no test coverage detected