mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 17:26:19 +00:00
feat: resolved trailing whitespace not showing up
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable react/no-danger */
|
/* eslint-disable react/no-danger */
|
||||||
import { forwardRef, HTMLAttributes, useState } from "react";
|
import { forwardRef, HTMLAttributes } from "react";
|
||||||
import sanitizeHtml, { DisallowedTagsModes } from "sanitize-html";
|
import sanitizeHtml, { DisallowedTagsModes } from "sanitize-html";
|
||||||
|
|
||||||
import { useToggle } from "@app/hooks";
|
import { useToggle } from "@app/hooks";
|
||||||
@@ -34,65 +34,49 @@ const syntaxHighlight = (content?: string | null, isVisible?: boolean) => {
|
|||||||
`<span class="ph-no-capture text-yellow">${<span class="ph-no-capture text-yello-200/80">${b}</span>}</span>`
|
`<span class="ph-no-capture text-yellow">${<span class="ph-no-capture text-yello-200/80">${b}</span>}</span>`
|
||||||
);
|
);
|
||||||
|
|
||||||
return newContent;
|
// 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 `${newContent}<br/>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = Omit<HTMLAttributes<HTMLTextAreaElement>, "onChange" | "onBlur"> & {
|
type Props = HTMLAttributes<HTMLTextAreaElement> & {
|
||||||
value?: string | null;
|
value?: string | null;
|
||||||
isVisible?: boolean;
|
isVisible?: boolean;
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
onChange?: (val: string) => void;
|
|
||||||
onBlur?: () => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const commonClassName =
|
const commonClassName = "font-mono text-sm caret-white border-none outline-none w-full break-all";
|
||||||
"font-mono text-sm caret-white border-none outline-none w-full break-all pb-4";
|
|
||||||
|
|
||||||
export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
|
export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
|
||||||
({ value, isVisible, onChange, onBlur, isDisabled, onFocus, ...props }, ref) => {
|
({ value, isVisible, onBlur, isDisabled, onFocus, ...props }, ref) => {
|
||||||
const [isSecretFocused, setIsSecretFocused] = useToggle();
|
const [isSecretFocused, setIsSecretFocused] = useToggle();
|
||||||
const [text, setText] = useState(() => value || "");
|
|
||||||
|
|
||||||
const update = (code: string) => {
|
|
||||||
setText(code);
|
|
||||||
if (onChange) {
|
|
||||||
onChange(code.trim());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onInput = (event: any) => {
|
|
||||||
const code = event.target.value || "";
|
|
||||||
update(code);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-auto" style={{ maxHeight: `${21 * 7}px` }}>
|
<div className="overflow-auto w-full" style={{ maxHeight: `${21 * 7}px` }}>
|
||||||
<div className="relative overflow-hidden">
|
<div className="relative overflow-hidden">
|
||||||
<pre aria-hidden className="m-0 ">
|
<pre aria-hidden className="m-0 ">
|
||||||
<code className={`inline-block w-full ${commonClassName}`}>
|
<code className={`inline-block w-full ${commonClassName}`}>
|
||||||
<span
|
<span
|
||||||
style={{ whiteSpace: "break-spaces" }}
|
style={{ whiteSpace: "break-spaces" }}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: syntaxHighlight(text, isVisible || isSecretFocused) ?? ""
|
__html: syntaxHighlight(value, isVisible || isSecretFocused) ?? ""
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
style={{ whiteSpace: "break-spaces" }}
|
style={{ whiteSpace: "break-spaces" }}
|
||||||
aria-label="secret value"
|
aria-label="secret value"
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={`absolute inset-0 block h-full resize-none overflow-hidden bg-transparent text-transparent no-scrollbar focus:border-0 ${commonClassName}`}
|
className={`absolute inset-0 block h-full resize-none overflow-hidden bg-transparent text-transparent no-scrollbar focus:border-0 ${commonClassName}`}
|
||||||
value={text}
|
|
||||||
onChange={onInput}
|
|
||||||
onFocus={() => setIsSecretFocused.on()}
|
onFocus={() => setIsSecretFocused.on()}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
onBlur={() => {
|
onBlur={(evt) => {
|
||||||
if (onBlur) onBlur();
|
onBlur?.(evt);
|
||||||
setIsSecretFocused.off();
|
setIsSecretFocused.off();
|
||||||
}}
|
}}
|
||||||
|
value={value || ""}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ export const SecretInputRow = memo(
|
|||||||
className="flex w-full flex-grow flex-row border-r border-none border-red"
|
className="flex w-full flex-grow flex-row border-r border-none border-red"
|
||||||
style={{ padding: "0.5rem 0 0.5rem 1rem" }}
|
style={{ padding: "0.5rem 0 0.5rem 1rem" }}
|
||||||
>
|
>
|
||||||
<div className="w-full">
|
<div className="w-full flex items-center">
|
||||||
{isOverridden ? (
|
{isOverridden ? (
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
|
|||||||
Reference in New Issue
Block a user