/* eslint-disable react/no-danger */ import { forwardRef, TextareaHTMLAttributes } from "react"; import { twMerge } from "tailwind-merge"; import { useToggle } from "@app/hooks"; import { HIDDEN_SECRET_VALUE } from "@app/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretItem"; const REGEX = /(\${([a-zA-Z0-9-_.]+)})/g; const syntaxHighlight = (content?: string | null, isVisible?: boolean, isImport?: boolean) => { if (isImport && !content) return "IMPORTED"; if (content === "") return "EMPTY"; if (!content) return "EMPTY"; if (!isVisible) return HIDDEN_SECRET_VALUE; let skipNext = false; const formattedContent = content.split(REGEX).flatMap((el, i) => { const isInterpolationSyntax = el.startsWith("${") && el.endsWith("}"); if (isInterpolationSyntax) { skipNext = true; return ( ${{el.slice(2, -1)} } ); } if (skipNext) { skipNext = false; return []; } return el; }); // akhilmhdh: Dont remove this br. I am still clueless how this works but weirdly enough // when break is added a line break works properly return formattedContent.concat(
); }; type Props = TextareaHTMLAttributes & { value?: string | null; isVisible?: boolean; valueAlwaysHidden?: boolean; isImport?: boolean; isReadOnly?: boolean; isDisabled?: boolean; containerClassName?: string; canEditButNotView?: boolean; }; const commonClassName = "font-mono text-sm caret-white border-none outline-none w-full break-all"; export const SecretInput = forwardRef( ( { value, isVisible, isImport, valueAlwaysHidden, containerClassName, onBlur, isDisabled, isReadOnly, onFocus, canEditButNotView, ...props }, ref ) => { const [isSecretFocused, setIsSecretFocused] = useToggle(); return (
            
              
                {syntaxHighlight(
                  value,
                  isVisible || (isSecretFocused && !valueAlwaysHidden),
                  isImport
                )}