import ClickAwayListener from '@mui/base/ClickAwayListener'; import FormHelperText from '@mui/material/FormHelperText'; import InputLabel from '@mui/material/InputLabel'; import * as React from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import { createEditor } from 'slate'; import { Editable } from 'slate-react'; import Slate from 'components/Slate'; import Element from 'components/Slate/Element'; import { customizeEditor, deserialize, insertVariable, serialize, } from 'components/Slate/utils'; import { StepExecutionsContext } from 'contexts/StepExecutions'; import Popper from './Popper'; import { processStepWithExecutions } from './data'; import { ChildrenWrapper, FakeInput, InputLabelWrapper } from './style'; const PowerInput = (props) => { const { control } = useFormContext(); const { defaultValue = '', onBlur, name, label, required, description, disabled, shouldUnregister, } = props; const priorStepsWithExecutions = React.useContext(StepExecutionsContext); const editorRef = React.useRef(null); const renderElement = React.useCallback( (props) => , [], ); const [editor] = React.useState(() => customizeEditor(createEditor())); const [showVariableSuggestions, setShowVariableSuggestions] = React.useState(false); const disappearSuggestionsOnShift = (event) => { if (event.code === 'Tab') { setShowVariableSuggestions(false); } }; const stepsWithVariables = React.useMemo(() => { return processStepWithExecutions(priorStepsWithExecutions); }, [priorStepsWithExecutions]); const handleBlur = React.useCallback( (value) => { onBlur?.(value); }, [onBlur], ); const handleVariableSuggestionClick = React.useCallback( (variable) => { insertVariable(editor, variable, stepsWithVariables); }, [stepsWithVariables], ); return ( ( { controllerOnChange(serialize(value)); }} > { setShowVariableSuggestions(false); }} > {/* ref-able single child for ClickAwayListener */} {`${label}${required ? ' *' : ''}`} { setShowVariableSuggestions(true); }} onBlur={() => { controllerOnBlur(); handleBlur(value); }} /> {/* ghost placer for the variables popover */}
{description} )} /> ); }; export default PowerInput;