/* eslint-disable react/no-danger */ import { forwardRef, TextareaHTMLAttributes } from "react"; import { twMerge } from "tailwind-merge"; import { useToggle } from "@app/hooks"; const REGEX = /(\${([a-zA-Z0-9-_.]+)})/g; const replaceContentWithDot = (str: string) => { let finalStr = ""; for (let i = 0; i < str.length; i += 1) { const char = str.at(i); finalStr += char === "\n" ? "\n" : "*"; } return finalStr; }; 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 replaceContentWithDot(content); 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; isImport?: boolean; isReadOnly?: boolean; isDisabled?: boolean; containerClassName?: string; }; const commonClassName = "font-mono text-sm caret-white border-none outline-none w-full break-all"; export const SecretInput = forwardRef( ( { value, isVisible, isImport, containerClassName, onBlur, isDisabled, isReadOnly, onFocus, ...props }, ref ) => { const [isSecretFocused, setIsSecretFocused] = useToggle(); return (
            
              
                {syntaxHighlight(value, isVisible || isSecretFocused, isImport)}