mirror of
http://10.0.2.1:3031/sauer/claude-code.git
synced 2026-06-30 15:26:58 +10:00
213 lines
29 KiB
TypeScript
213 lines
29 KiB
TypeScript
|
|
import { c as _c } from "react/compiler-runtime";
|
||
|
|
import figures from 'figures';
|
||
|
|
import React from 'react';
|
||
|
|
import { Box, Text } from '../../ink.js';
|
||
|
|
import type { PastedContent } from '../../utils/config.js';
|
||
|
|
import type { ImageDimensions } from '../../utils/imageResizer.js';
|
||
|
|
import type { OptionWithDescription } from './select.js';
|
||
|
|
import { SelectInputOption } from './select-input-option.js';
|
||
|
|
import { SelectOption } from './select-option.js';
|
||
|
|
import { useMultiSelectState } from './use-multi-select-state.js';
|
||
|
|
export type SelectMultiProps<T> = {
|
||
|
|
readonly isDisabled?: boolean;
|
||
|
|
readonly visibleOptionCount?: number;
|
||
|
|
readonly options: OptionWithDescription<T>[];
|
||
|
|
readonly defaultValue?: T[];
|
||
|
|
readonly onCancel: () => void;
|
||
|
|
readonly onChange?: (values: T[]) => void;
|
||
|
|
readonly onFocus?: (value: T) => void;
|
||
|
|
readonly focusValue?: T;
|
||
|
|
/**
|
||
|
|
* Text for the submit button. When provided, a submit button is shown and
|
||
|
|
* Enter toggles selection (submit only fires when the button is focused).
|
||
|
|
* When omitted, Enter submits directly and Space toggles selection.
|
||
|
|
*/
|
||
|
|
readonly submitButtonText?: string;
|
||
|
|
/**
|
||
|
|
* Callback when user submits. Receives the currently selected values.
|
||
|
|
*/
|
||
|
|
readonly onSubmit?: (values: T[]) => void;
|
||
|
|
/**
|
||
|
|
* When true, hides the numeric indexes next to each option.
|
||
|
|
*/
|
||
|
|
readonly hideIndexes?: boolean;
|
||
|
|
/**
|
||
|
|
* Callback when user presses down from the last item (submit button).
|
||
|
|
* If provided, navigation will not wrap to the first item.
|
||
|
|
*/
|
||
|
|
readonly onDownFromLastItem?: () => void;
|
||
|
|
/**
|
||
|
|
* Callback when user presses up from the first item.
|
||
|
|
* If provided, navigation will not wrap to the last item.
|
||
|
|
*/
|
||
|
|
readonly onUpFromFirstItem?: () => void;
|
||
|
|
/**
|
||
|
|
* Focus the last option initially instead of the first.
|
||
|
|
*/
|
||
|
|
readonly initialFocusLast?: boolean;
|
||
|
|
/**
|
||
|
|
* Callback to open external editor for editing input option values.
|
||
|
|
* When provided, ctrl+g will trigger this callback in input options
|
||
|
|
* with the current value and a setter function to update the internal state.
|
||
|
|
*/
|
||
|
|
readonly onOpenEditor?: (currentValue: string, setValue: (value: string) => void) => void;
|
||
|
|
readonly onImagePaste?: (base64Image: string, mediaType?: string, filename?: string, dimensions?: ImageDimensions, sourcePath?: string) => void;
|
||
|
|
readonly pastedContents?: Record<number, PastedContent>;
|
||
|
|
readonly onRemoveImage?: (id: number) => void;
|
||
|
|
};
|
||
|
|
export function SelectMulti(t0) {
|
||
|
|
const $ = _c(44);
|
||
|
|
const {
|
||
|
|
isDisabled: t1,
|
||
|
|
visibleOptionCount: t2,
|
||
|
|
options,
|
||
|
|
defaultValue: t3,
|
||
|
|
onCancel,
|
||
|
|
onChange,
|
||
|
|
onFocus,
|
||
|
|
focusValue,
|
||
|
|
submitButtonText,
|
||
|
|
onSubmit,
|
||
|
|
onDownFromLastItem,
|
||
|
|
onUpFromFirstItem,
|
||
|
|
initialFocusLast,
|
||
|
|
onOpenEditor,
|
||
|
|
hideIndexes: t4,
|
||
|
|
onImagePaste,
|
||
|
|
pastedContents,
|
||
|
|
onRemoveImage
|
||
|
|
} = t0;
|
||
|
|
const isDisabled = t1 === undefined ? false : t1;
|
||
|
|
const visibleOptionCount = t2 === undefined ? 5 : t2;
|
||
|
|
let t5;
|
||
|
|
if ($[0] !== t3) {
|
||
|
|
t5 = t3 === undefined ? [] : t3;
|
||
|
|
$[0] = t3;
|
||
|
|
$[1] = t5;
|
||
|
|
} else {
|
||
|
|
t5 = $[1];
|
||
|
|
}
|
||
|
|
const defaultValue = t5;
|
||
|
|
const hideIndexes = t4 === undefined ? false : t4;
|
||
|
|
let t6;
|
||
|
|
if ($[2] !== defaultValue || $[3] !== focusValue || $[4] !== hideIndexes || $[5] !== initialFocusLast || $[6] !== isDisabled || $[7] !== onCancel || $[8] !== onChange || $[9] !== onDownFromLastItem || $[10] !== onFocus || $[11] !== onSubmit || $[12] !== onUpFromFirstItem || $[13] !== options || $[14] !== submitButtonText || $[15] !== visibleOptionCount) {
|
||
|
|
t6 = {
|
||
|
|
isDisabled,
|
||
|
|
visibleOptionCount,
|
||
|
|
options,
|
||
|
|
defaultValue,
|
||
|
|
onChange,
|
||
|
|
onCancel,
|
||
|
|
onFocus,
|
||
|
|
focusValue,
|
||
|
|
submitButtonText,
|
||
|
|
onSubmit,
|
||
|
|
onDownFromLastItem,
|
||
|
|
onUpFromFirstItem,
|
||
|
|
initialFocusLast,
|
||
|
|
hideIndexes
|
||
|
|
};
|
||
|
|
$[2] = defaultValue;
|
||
|
|
$[3] = focusValue;
|
||
|
|
$[4] = hideIndexes;
|
||
|
|
$[5] = initialFocusLast;
|
||
|
|
$[6] = isDisabled;
|
||
|
|
$[7] = onCancel;
|
||
|
|
$[8] = onChange;
|
||
|
|
$[9] = onDownFromLastItem;
|
||
|
|
$[10] = onFocus;
|
||
|
|
$[11] = onSubmit;
|
||
|
|
$[12] = onUpFromFirstItem;
|
||
|
|
$[13] = options;
|
||
|
|
$[14] = submitButtonText;
|
||
|
|
$[15] = visibleOptionCount;
|
||
|
|
$[16] = t6;
|
||
|
|
} else {
|
||
|
|
t6 = $[16];
|
||
|
|
}
|
||
|
|
const state = useMultiSelectState(t6);
|
||
|
|
let T0;
|
||
|
|
let T1;
|
||
|
|
let t7;
|
||
|
|
let t8;
|
||
|
|
let t9;
|
||
|
|
if ($[17] !== hideIndexes || $[18] !== isDisabled || $[19] !== onCancel || $[20] !== onImagePaste || $[21] !== onOpenEditor || $[22] !== onRemoveImage || $[23] !== options.length || $[24] !== pastedContents || $[25] !== state) {
|
||
|
|
const maxIndexWidth = options.length.toString().length;
|
||
|
|
T1 = Box;
|
||
|
|
t9 = "column";
|
||
|
|
T0 = Box;
|
||
|
|
t7 = "column";
|
||
|
|
t8 = state.visibleOptions.map((option, index) => {
|
||
|
|
const isOptionFocused = !isDisabled && state.focusedValue === option.value && !state.isSubmitFocused;
|
||
|
|
const isSelected = state.selectedValues.includes(option.value);
|
||
|
|
const isFirstVisibleOption = option.index === state.visibleFromIndex;
|
||
|
|
const isLastVisibleOption = option.index === state.visibleToIndex - 1;
|
||
|
|
const areMoreOptionsBelow = state.visibleToIndex < options.length;
|
||
|
|
const areMoreOptionsAbove = state.visibleFromIndex > 0;
|
||
|
|
const i = state.visibleFromIndex + index + 1;
|
||
|
|
if (option.type === "input") {
|
||
|
|
const inputValue = state.inputValues.get(option.value) || "";
|
||
|
|
return <Box key={String(option.value)} gap={1}><SelectInputOption option={option} isFocused={isOptionFocused} isSelected={false} shouldShowDownArrow={areMoreOptionsBelow && isLastVisibleOption} shouldShowUpArrow={areMoreOptionsAbove && isFirstVisibleOption} maxIndexWidth={maxIndexWidth} index={i} inputValue={inputValue} onInputChange={value => {
|
||
|
|
state.updateInputValue(option.value, value);
|
||
|
|
}} onSubmit={_temp} onExit={() => {
|
||
|
|
onCancel();
|
||
|
|
}} layout="compact" onOpenEditor={onOpenEditor} onImagePaste={onImagePaste} pastedContents={pastedContents} onRemoveImage={onRemoveImage}><Text color={isSelected ? "success" : undefined}>[{isSelected ? figures.tick : " "}]{" "}</Text></SelectInputOption></Box>;
|
||
|
|
}
|
||
|
|
return <Box key={String(option.value)} gap={1}><SelectOption isFocused={isOptionFocused} isSelected={false} shouldShowDownArrow={areMoreOptionsBelow && isLastVisibleOption} shouldShowUpArrow={areMoreOptionsAbove && isFirstVisibleOption} description={option.description}>{!hideIndexes && <Text dimColor={true}>{`${i}.`.padEnd(maxIndexWidth)}</Text>}<Text color={isSelected ? "success" : undefined}>[{isSelected ? figures.tick : " "}]</Text><Text color={isOptionFocused ? "suggestion" : undefined}>{option.label}</Text></SelectOption></Box>;
|
||
|
|
});
|
||
|
|
$[17] = hideIndexes;
|
||
|
|
$[18] = isDisabled;
|
||
|
|
$[19] = onCancel;
|
||
|
|
$[20] = onImagePaste;
|
||
|
|
$[21] = onOpenEditor;
|
||
|
|
$[22] = onRemoveImage;
|
||
|
|
$[23] = options.length;
|
||
|
|
$[24] = pastedContents;
|
||
|
|
$[25] = state;
|
||
|
|
$[26] = T0;
|
||
|
|
$[27] = T1;
|
||
|
|
$[28] = t7;
|
||
|
|
$[29] = t8;
|
||
|
|
$[30] = t9;
|
||
|
|
} else {
|
||
|
|
T0 = $[26];
|
||
|
|
T1 = $[27];
|
||
|
|
t7 = $[28];
|
||
|
|
t8 = $[29];
|
||
|
|
t9 = $[30];
|
||
|
|
}
|
||
|
|
let t10;
|
||
|
|
if ($[31] !== T0 || $[32] !== t7 || $[33] !== t8) {
|
||
|
|
t10 = <T0 flexDirection={t7}>{t8}</T0>;
|
||
|
|
$[31] = T0;
|
||
|
|
$[32] = t7;
|
||
|
|
$[33] = t8;
|
||
|
|
$[34] = t10;
|
||
|
|
} else {
|
||
|
|
t10 = $[34];
|
||
|
|
}
|
||
|
|
let t11;
|
||
|
|
if ($[35] !== onSubmit || $[36] !== state.isSubmitFocused || $[37] !== submitButtonText) {
|
||
|
|
t11 = submitButtonText && onSubmit && <Box marginTop={0} gap={1}>{state.isSubmitFocused ? <Text color="suggestion">{figures.pointer}</Text> : <Text> </Text>}<Box marginLeft={3}><Text color={state.isSubmitFocused ? "suggestion" : undefined} bold={true}>{submitButtonText}</Text></Box></Box>;
|
||
|
|
$[35] = onSubmit;
|
||
|
|
$[36] = state.isSubmitFocused;
|
||
|
|
$[37] = submitButtonText;
|
||
|
|
$[38] = t11;
|
||
|
|
} else {
|
||
|
|
t11 = $[38];
|
||
|
|
}
|
||
|
|
let t12;
|
||
|
|
if ($[39] !== T1 || $[40] !== t10 || $[41] !== t11 || $[42] !== t9) {
|
||
|
|
t12 = <T1 flexDirection={t9}>{t10}{t11}</T1>;
|
||
|
|
$[39] = T1;
|
||
|
|
$[40] = t10;
|
||
|
|
$[41] = t11;
|
||
|
|
$[42] = t9;
|
||
|
|
$[43] = t12;
|
||
|
|
} else {
|
||
|
|
t12 = $[43];
|
||
|
|
}
|
||
|
|
return t12;
|
||
|
|
}
|
||
|
|
function _temp() {}
|
||
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJmaWd1cmVzIiwiUmVhY3QiLCJCb3giLCJUZXh0IiwiUGFzdGVkQ29udGVudCIsIkltYWdlRGltZW5zaW9ucyIsIk9wdGlvbldpdGhEZXNjcmlwdGlvbiIsIlNlbGVjdElucHV0T3B0aW9uIiwiU2VsZWN0T3B0aW9uIiwidXNlTXVsdGlTZWxlY3RTdGF0ZSIsIlNlbGVjdE11bHRpUHJvcHMiLCJpc0Rpc2FibGVkIiwidmlzaWJsZU9wdGlvbkNvdW50Iiwib3B0aW9ucyIsIlQiLCJkZWZhdWx0VmFsdWUiLCJvbkNhbmNlbCIsIm9uQ2hhbmdlIiwidmFsdWVzIiwib25Gb2N1cyIsInZhbHVlIiwiZm9jdXNWYWx1ZSIsInN1Ym1pdEJ1dHRvblRleHQiLCJvblN1Ym1pdCIsImhpZGVJbmRleGVzIiwib25Eb3duRnJvbUxhc3RJdGVtIiwib25VcEZyb21GaXJzdEl0ZW0iLCJpbml0aWFsRm9jdXNMYXN0Iiwib25PcGVuRWRpdG9yIiwiY3VycmVudFZhbHVlIiwic2V0VmFsdWUiLCJvbkltYWdlUGFzdGUiLCJiYXNlNjRJbWFnZSIsIm1lZGlhVHlwZSIsImZpbGVuYW1lIiwiZGltZW5zaW9ucyIsInNvdXJjZVBhdGgiLCJwYXN0ZWRDb250ZW50cyIsIlJlY29yZCIsIm9uUmVtb3ZlSW1hZ2UiLCJpZCIsIlNlbGVjdE11bHRpIiwidDAiLCIkIiwiX2MiLCJ0MSIsInQyIiwidDMiLCJ0NCIsInVuZGVmaW5lZCIsInQ1IiwidDYiLCJzdGF0ZSIsIlQwIi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