(options: SelectOptionsReq<A> & MultiSelectOptionsReq)
| 2702 | }) |
| 2703 | |
| 2704 | const handleMultiSelectProcess = <A>(options: SelectOptionsReq<A> & MultiSelectOptionsReq) => { |
| 2705 | return (input: Terminal.UserInput, state: MultiSelectState) => { |
| 2706 | const totalChoices = options.choices.length + metaOptionsCount |
| 2707 | switch (input.key.name) { |
| 2708 | case "k": |
| 2709 | case "up": { |
| 2710 | return processMultiSelectCursorUp({ ...state, error: Option.none() }, totalChoices) |
| 2711 | } |
| 2712 | case "j": |
| 2713 | case "down": |
| 2714 | case "tab": { |
| 2715 | return processMultiSelectCursorDown({ ...state, error: Option.none() }, totalChoices) |
| 2716 | } |
| 2717 | case "space": { |
| 2718 | return processSpace(state, options) |
| 2719 | } |
| 2720 | case "enter": |
| 2721 | case "return": { |
| 2722 | const selectedIndices = Array.from(state.selectedIndices).filter((index) => !options.choices[index].disabled) |
| 2723 | const selectedCount = selectedIndices.length |
| 2724 | if (options.min !== undefined && selectedCount < options.min) { |
| 2725 | return Effect.succeed( |
| 2726 | Action.NextFrame({ state: { ...state, error: Option.some(`At least ${options.min} are required`) } }) |
| 2727 | ) |
| 2728 | } |
| 2729 | if (options.max !== undefined && selectedCount > options.max) { |
| 2730 | return Effect.succeed( |
| 2731 | Action.NextFrame({ state: { ...state, error: Option.some(`At most ${options.max} choices are allowed`) } }) |
| 2732 | ) |
| 2733 | } |
| 2734 | const selectedValues = selectedIndices.sort(EffectNumber.Order).map((index) => options.choices[index].value) |
| 2735 | return Effect.succeed(Action.Submit({ value: selectedValues })) |
| 2736 | } |
| 2737 | default: { |
| 2738 | return Effect.succeed(Action.Beep()) |
| 2739 | } |
| 2740 | } |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | const handleMultiSelectRender = <A>(options: SelectOptionsReq<A>) => { |
| 2745 | return (state: MultiSelectState, action: Action<MultiSelectState, Array<A>>) => { |
no test coverage detected