MCPcopy Index your code
hub / github.com/ChatGPTBox-dev/chatGPTBox / InputBox

Function InputBox

src/components/InputBox/index.jsx:7–114  ·  view source on GitHub ↗
({ onSubmit, enabled, postMessage, reverseResizeDir })

Source from the content-addressed store, hash-verified

5import { getUserConfig } from '../../config/index.mjs'
6
7export function InputBox({ onSubmit, enabled, postMessage, reverseResizeDir }) {
8 const { t } = useTranslation()
9 const [value, setValue] = useState('')
10 const reverseDivRef = useRef(null)
11 const inputRef = useRef(null)
12 const resizedRef = useRef(false)
13 const [internalReverseResizeDir, setInternalReverseResizeDir] = useState(reverseResizeDir)
14
15 useEffect(() => {
16 setInternalReverseResizeDir(
17 !isSafari() && !isFirefox() && !isMobile() ? internalReverseResizeDir : false,
18 )
19 }, [])
20
21 const virtualInputRef = internalReverseResizeDir ? reverseDivRef : inputRef
22
23 useEffect(() => {
24 inputRef.current.focus()
25
26 const onResizeY = () => {
27 if (virtualInputRef.current.h !== virtualInputRef.current.offsetHeight) {
28 virtualInputRef.current.h = virtualInputRef.current.offsetHeight
29 if (!resizedRef.current) {
30 resizedRef.current = true
31 virtualInputRef.current.style.maxHeight = ''
32 }
33 }
34 }
35 virtualInputRef.current.h = virtualInputRef.current.offsetHeight
36 virtualInputRef.current.addEventListener('mousemove', onResizeY)
37 }, [])
38
39 useEffect(() => {
40 if (!resizedRef.current) {
41 if (!internalReverseResizeDir) {
42 updateRefHeight(inputRef)
43 virtualInputRef.current.h = virtualInputRef.current.offsetHeight
44 virtualInputRef.current.style.maxHeight = '160px'
45 }
46 }
47 })
48
49 useEffect(() => {
50 if (enabled)
51 getUserConfig().then((config) => {
52 if (config.focusAfterAnswer) inputRef.current.focus()
53 })
54 }, [enabled])
55
56 const handleKeyDownOrClick = (e) => {
57 e.stopPropagation()
58 if (e.type === 'click' || (e.keyCode === 13 && e.shiftKey === false)) {
59 e.preventDefault()
60 if (enabled) {
61 if (!value) return
62 onSubmit(value)
63 setValue('')
64 } else {

Callers

nothing calls this directly

Calls 6

isSafariFunction · 0.90
isFirefoxFunction · 0.90
isMobileFunction · 0.90
updateRefHeightFunction · 0.90
getUserConfigFunction · 0.90
tFunction · 0.85

Tested by

no test coverage detected