mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-25 10:18:31 +02:00
Fix pair editor adding new entry when clicking below
This commit is contained in:
@@ -23,6 +23,7 @@ import { Icon } from './Icon';
|
|||||||
import { IconButton } from './IconButton';
|
import { IconButton } from './IconButton';
|
||||||
import type { InputProps } from './Input';
|
import type { InputProps } from './Input';
|
||||||
import { Input } from './Input';
|
import { Input } from './Input';
|
||||||
|
import { PlainInput } from './PlainInput';
|
||||||
import { RadioDropdown } from './RadioDropdown';
|
import { RadioDropdown } from './RadioDropdown';
|
||||||
|
|
||||||
export interface PairEditorRef {
|
export interface PairEditorRef {
|
||||||
@@ -172,7 +173,14 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
|
|||||||
setForceFocusNamePairId(null); // Remove focus override when something focused
|
setForceFocusNamePairId(null); // Remove focus override when something focused
|
||||||
setForceFocusValuePairId(null); // Remove focus override when something focused
|
setForceFocusValuePairId(null); // Remove focus override when something focused
|
||||||
const isLast = pair.id === pairs[pairs.length - 1]?.id;
|
const isLast = pair.id === pairs[pairs.length - 1]?.id;
|
||||||
return isLast ? [...pairs, newPairContainer()] : pairs;
|
if (isLast) {
|
||||||
|
const newPair = newPairContainer();
|
||||||
|
const prevPair = pairs[pairs.length - 1];
|
||||||
|
setForceFocusNamePairId(prevPair?.id ?? null);
|
||||||
|
return [...pairs, newPair];
|
||||||
|
} else {
|
||||||
|
return pairs;
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
@@ -192,7 +200,7 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
|
|||||||
'pb-2 mb-auto h-full',
|
'pb-2 mb-auto h-full',
|
||||||
!noScroll && 'overflow-y-auto max-h-full',
|
!noScroll && 'overflow-y-auto max-h-full',
|
||||||
// Move over the width of the drag handle
|
// Move over the width of the drag handle
|
||||||
'-ml-3',
|
'-ml-3 -mr-2 pr-2',
|
||||||
// Pad to make room for the drag divider
|
// Pad to make room for the drag divider
|
||||||
'pt-0.5',
|
'pt-0.5',
|
||||||
)}
|
)}
|
||||||
@@ -224,6 +232,7 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
|
|||||||
onDelete={handleDelete}
|
onDelete={handleDelete}
|
||||||
onEnd={handleEnd}
|
onEnd={handleEnd}
|
||||||
onMove={handleMove}
|
onMove={handleMove}
|
||||||
|
index={i}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
@@ -248,6 +257,7 @@ type PairEditorRowProps = {
|
|||||||
onFocus?: (pair: PairContainer) => void;
|
onFocus?: (pair: PairContainer) => void;
|
||||||
onSubmit?: (pair: PairContainer) => void;
|
onSubmit?: (pair: PairContainer) => void;
|
||||||
isLast?: boolean;
|
isLast?: boolean;
|
||||||
|
index: number;
|
||||||
} & Pick<
|
} & Pick<
|
||||||
PairEditorProps,
|
PairEditorProps,
|
||||||
| 'nameAutocomplete'
|
| 'nameAutocomplete'
|
||||||
@@ -270,6 +280,7 @@ function PairEditorRow({
|
|||||||
forceFocusValuePairId,
|
forceFocusValuePairId,
|
||||||
forceUpdateKey,
|
forceUpdateKey,
|
||||||
isLast,
|
isLast,
|
||||||
|
index,
|
||||||
nameAutocomplete,
|
nameAutocomplete,
|
||||||
nameAutocompleteVariables,
|
nameAutocompleteVariables,
|
||||||
namePlaceholder,
|
namePlaceholder,
|
||||||
@@ -406,25 +417,39 @@ function PairEditorRow({
|
|||||||
'gap-0.5 grid-cols-1 grid-rows-2',
|
'gap-0.5 grid-cols-1 grid-rows-2',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Input
|
{isLast ? (
|
||||||
ref={nameInputRef}
|
// Use PlainInput for last ones because there's a unique bug where clicking below
|
||||||
hideLabel
|
// the Codemirror input focuses it.
|
||||||
useTemplating
|
<PlainInput
|
||||||
readOnly={pairContainer.pair.readOnlyName}
|
hideLabel
|
||||||
size="sm"
|
size="sm"
|
||||||
require={!isLast && !!pairContainer.pair.enabled && !!pairContainer.pair.value}
|
containerClassName={classNames(isLast && 'border-dashed')}
|
||||||
validate={nameValidate}
|
label="Name"
|
||||||
forceUpdateKey={forceUpdateKey}
|
name={`name[${index}]`}
|
||||||
containerClassName={classNames(isLast && 'border-dashed')}
|
onFocus={handleFocus}
|
||||||
defaultValue={pairContainer.pair.name}
|
placeholder={namePlaceholder ?? 'name'}
|
||||||
label="Name"
|
/>
|
||||||
name="name"
|
) : (
|
||||||
onChange={handleChangeName}
|
<Input
|
||||||
onFocus={handleFocus}
|
ref={nameInputRef}
|
||||||
placeholder={namePlaceholder ?? 'name'}
|
hideLabel
|
||||||
autocomplete={nameAutocomplete}
|
useTemplating
|
||||||
autocompleteVariables={nameAutocompleteVariables}
|
readOnly={pairContainer.pair.readOnlyName}
|
||||||
/>
|
size="sm"
|
||||||
|
require={!isLast && !!pairContainer.pair.enabled && !!pairContainer.pair.value}
|
||||||
|
validate={nameValidate}
|
||||||
|
forceUpdateKey={forceUpdateKey}
|
||||||
|
containerClassName={classNames(isLast && 'border-dashed')}
|
||||||
|
defaultValue={pairContainer.pair.name}
|
||||||
|
label="Name"
|
||||||
|
name={`name[${index}]`}
|
||||||
|
onChange={handleChangeName}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
placeholder={namePlaceholder ?? 'name'}
|
||||||
|
autocomplete={nameAutocomplete}
|
||||||
|
autocompleteVariables={nameAutocompleteVariables}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<div className="w-full grid grid-cols-[minmax(0,1fr)_auto] gap-1 items-center">
|
<div className="w-full grid grid-cols-[minmax(0,1fr)_auto] gap-1 items-center">
|
||||||
{pairContainer.pair.isFile ? (
|
{pairContainer.pair.isFile ? (
|
||||||
<SelectFile
|
<SelectFile
|
||||||
@@ -433,6 +458,18 @@ function PairEditorRow({
|
|||||||
filePath={pairContainer.pair.value}
|
filePath={pairContainer.pair.value}
|
||||||
onChange={handleChangeValueFile}
|
onChange={handleChangeValueFile}
|
||||||
/>
|
/>
|
||||||
|
) : isLast ? (
|
||||||
|
// Use PlainInput for last ones because there's a unique bug where clicking below
|
||||||
|
// the Codemirror input focuses it.
|
||||||
|
<PlainInput
|
||||||
|
hideLabel
|
||||||
|
size="sm"
|
||||||
|
containerClassName={classNames(isLast && 'border-dashed')}
|
||||||
|
label="Value"
|
||||||
|
name={`value[${index}]`}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
placeholder={valuePlaceholder ?? 'value'}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Input
|
<Input
|
||||||
ref={valueInputRef}
|
ref={valueInputRef}
|
||||||
@@ -444,7 +481,7 @@ function PairEditorRow({
|
|||||||
forceUpdateKey={forceUpdateKey}
|
forceUpdateKey={forceUpdateKey}
|
||||||
defaultValue={pairContainer.pair.value}
|
defaultValue={pairContainer.pair.value}
|
||||||
label="Value"
|
label="Value"
|
||||||
name="value"
|
name={`value[${index}]`}
|
||||||
onChange={handleChangeValueText}
|
onChange={handleChangeValueText}
|
||||||
onFocus={handleFocus}
|
onFocus={handleFocus}
|
||||||
type={isLast ? 'text' : valueType}
|
type={isLast ? 'text' : valueType}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export const PlainInput = forwardRef<HTMLInputElement, PlainInputProps>(function
|
|||||||
const inputClassName = classNames(
|
const inputClassName = classNames(
|
||||||
className,
|
className,
|
||||||
'!bg-transparent min-w-0 h-auto w-full focus:outline-none placeholder:text-placeholder',
|
'!bg-transparent min-w-0 h-auto w-full focus:outline-none placeholder:text-placeholder',
|
||||||
'px-1.5 text-xs font-mono cursor-text',
|
'px-2 text-xs font-mono cursor-text',
|
||||||
);
|
);
|
||||||
|
|
||||||
const isValid = useMemo(() => {
|
const isValid = useMemo(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user