( options: SelectOptions<A> & MultiSelectOptions )
| 1209 | * @since 4.0.0 |
| 1210 | */ |
| 1211 | export const multiSelect = <const A>( |
| 1212 | options: SelectOptions<A> & MultiSelectOptions |
| 1213 | ): Prompt<Array<A>> => { |
| 1214 | const opts: SelectOptionsReq<A> & MultiSelectOptionsReq = { |
| 1215 | maxPerPage: 10, |
| 1216 | ...options |
| 1217 | } |
| 1218 | // Seed initial selection from choices marked as selected: true |
| 1219 | const initialSelected = new Set<number>() |
| 1220 | for (let i = 0; i < opts.choices.length; i++) { |
| 1221 | const choice = opts.choices[i] as SelectChoice<A> |
| 1222 | if (choice.selected === true && !choice.disabled) { |
| 1223 | initialSelected.add(i) |
| 1224 | } |
| 1225 | } |
| 1226 | const initialState: MultiSelectState = { index: 0, selectedIndices: initialSelected, error: Option.none() } |
| 1227 | return custom(initialState, { |
| 1228 | render: handleMultiSelectRender(opts), |
| 1229 | process: handleMultiSelectProcess(opts), |
| 1230 | clear: handleMultiSelectClear(opts) |
| 1231 | }) |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Creates a `Prompt` which immediately succeeds with the specified value. |
nothing calls this directly
no test coverage detected