[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

Apply suggestions from code review

Co-authored-by: Oskar Löfgren <516549+ulken@users.noreply.github.com>

authored by

Nate Moore
Oskar Löfgren
and committed by
Nate Moore
(Feb 24, 2023, 6:45 PM -0600) 11552e21 1e647c13

+8 -8
+6 -6
packages/core/src/prompts/group-multiselect.ts
··· 27 27 if (this.isGroupSelected(group)) { 28 28 this.value = this.value.filter((v: string) => groupedItems.findIndex(i => i.value === v) === -1); 29 29 } else { 30 - this.value = [...this.value, ...groupedItems.map(v => v.value)]; 30 + this.value = [...this.value, ...groupedItems.map(i => i.value)]; 31 31 } 32 32 this.value = Array.from(new Set(this.value)); 33 33 } else { 34 34 const selected = this.value.includes(item.value); 35 35 this.value = selected 36 - ? this.value.filter((value: T['value']) => value !== item.value) 36 + ? this.value.filter((v: T['value']) => v !== item.value) 37 37 : [...this.value, item.value]; 38 38 } 39 39 } ··· 41 41 constructor(opts: GroupMultiSelectOptions<T>) { 42 42 super(opts, false); 43 43 44 - this.options = Object.keys(opts.options).reduce((acc, key) => { 45 - acc.push({ value: key, group: true, label: key }, ...opts.options[key].map(opt => ({ ...opt, group: key }))); 46 - return acc; 47 - }, [] as { value: any, [key: string]: any }[]); 44 + this.options = Object.entries(options).flatMap(([key, option]) => [ 45 + { value: key, group: true, label: key }, 46 + ...option.map((opt) => ({ ...opt, group: key })), 47 + ]) 48 48 this.value = [...(opts.initialValues ?? [])]; 49 49 this.cursor = Math.max( 50 50 this.options.findIndex(({ value }) => value === opts.cursorAt),
+2 -2
packages/prompts/src/index.ts
··· 407 407 const isItem = typeof option.group === 'string'; 408 408 const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true }); 409 409 const isLast = isItem && next.group === true; 410 - const prefix = typeof option.group === 'string' ? `${isLast ? S_BAR_END : S_BAR} ` : ''; 410 + const prefix = isItem ? `${isLast ? S_BAR_END : S_BAR} ` : ''; 411 411 412 412 if (state === 'active') { 413 413 return `${color.dim(prefix)}${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${ ··· 495 495 .map((option, i, options) => { 496 496 const selected = this.value.includes(option.value) || (option.group === true && this.isGroupSelected(option.value)); 497 497 const active = i === this.cursor; 498 - const groupActive = !active && typeof option.group === 'string' && this.options[this.cursor].value === option.group; 498 + const groupActive = !active && typeof option.group === 'string' && this.options[this.cursor].value === option.group; 499 499 if (groupActive) { 500 500 return opt(option, selected ? 'group-active-selected' : 'group-active', options); 501 501 }