({ inputParam, value, nodes, edges, nodeId, onChange, onBlur, disabled = false })
| 7 | import { getAvailableNodesForVariable } from '@/utils/genericHelper' |
| 8 | |
| 9 | export const Input = ({ inputParam, value, nodes, edges, nodeId, onChange, onBlur, disabled = false }) => { |
| 10 | const theme = useTheme() |
| 11 | const [myValue, setMyValue] = useState(value ?? '') |
| 12 | const [anchorEl, setAnchorEl] = useState(null) |
| 13 | const [availableNodesForVariable, setAvailableNodesForVariable] = useState([]) |
| 14 | const [isPasswordVisible, setIsPasswordVisible] = useState(false) |
| 15 | const ref = useRef(null) |
| 16 | const inputElementRef = useRef(null) |
| 17 | const selectionRangeRef = useRef({ start: null, end: null }) |
| 18 | |
| 19 | const openPopOver = Boolean(anchorEl) |
| 20 | const hasPasswordToggle = (inputParam?.type === 'password' || inputParam?.type === 'url') && !!inputParam?.enablePasswordToggle |
| 21 | |
| 22 | const handleClosePopOver = () => { |
| 23 | setAnchorEl(null) |
| 24 | } |
| 25 | |
| 26 | const setNewVal = (val) => { |
| 27 | const newVal = myValue + val.substring(2) |
| 28 | onChange(newVal) |
| 29 | setMyValue(newVal) |
| 30 | } |
| 31 | |
| 32 | const getInputType = (type) => { |
| 33 | switch (type) { |
| 34 | case 'string': |
| 35 | return 'text' |
| 36 | case 'password': |
| 37 | case 'url': |
| 38 | return 'password' |
| 39 | case 'number': |
| 40 | return 'number' |
| 41 | case 'email': |
| 42 | return 'email' |
| 43 | default: |
| 44 | return 'text' |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | const handleTogglePasswordVisibility = () => { |
| 49 | const inputElement = inputElementRef.current |
| 50 | if (inputElement) { |
| 51 | selectionRangeRef.current = { |
| 52 | start: inputElement.selectionStart, |
| 53 | end: inputElement.selectionEnd |
| 54 | } |
| 55 | } |
| 56 | setIsPasswordVisible((prev) => !prev) |
| 57 | } |
| 58 | |
| 59 | useEffect(() => { |
| 60 | if (!hasPasswordToggle) return |
| 61 | const { start, end } = selectionRangeRef.current |
| 62 | if (start === null || end === null || !inputElementRef.current) return |
| 63 | requestAnimationFrame(() => { |
| 64 | inputElementRef.current?.focus() |
| 65 | inputElementRef.current?.setSelectionRange(start, end) |
| 66 | }) |
nothing calls this directly
no test coverage detected