@inquirer/select 5.0.6 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -9,6 +9,9 @@ type SelectTheme = {
9
9
  description: (text: string) => string;
10
10
  keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
11
11
  };
12
+ i18n: {
13
+ disabledError: string;
14
+ };
12
15
  indexMode: 'hidden' | 'number';
13
16
  keybindings: ReadonlyArray<Keybinding>;
14
17
  };
package/dist/index.js CHANGED
@@ -5,18 +5,22 @@ import figures from '@inquirer/figures';
5
5
  const selectTheme = {
6
6
  icon: { cursor: figures.pointer },
7
7
  style: {
8
- disabled: (text) => styleText('dim', `- ${text}`),
8
+ disabled: (text) => styleText('dim', text),
9
9
  description: (text) => styleText('cyan', text),
10
10
  keysHelpTip: (keys) => keys
11
11
  .map(([key, action]) => `${styleText('bold', key)} ${styleText('dim', action)}`)
12
12
  .join(styleText('dim', ' • ')),
13
13
  },
14
+ i18n: { disabledError: 'This option is disabled and cannot be selected.' },
14
15
  indexMode: 'hidden',
15
16
  keybindings: [],
16
17
  };
17
18
  function isSelectable(item) {
18
19
  return !Separator.isSeparator(item) && !item.disabled;
19
20
  }
21
+ function isNavigable(item) {
22
+ return !Separator.isSeparator(item);
23
+ }
20
24
  function normalizeChoices(choices) {
21
25
  return choices.map((choice) => {
22
26
  if (Separator.isSeparator(choice))
@@ -56,8 +60,8 @@ export default createPrompt((config, done) => {
56
60
  const searchEnabled = !keybindings.includes('vim');
57
61
  const items = useMemo(() => normalizeChoices(config.choices), [config.choices]);
58
62
  const bounds = useMemo(() => {
59
- const first = items.findIndex(isSelectable);
60
- const last = items.findLastIndex(isSelectable);
63
+ const first = items.findIndex(isNavigable);
64
+ const last = items.findLastIndex(isNavigable);
61
65
  if (first === -1) {
62
66
  throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
63
67
  }
@@ -71,11 +75,20 @@ export default createPrompt((config, done) => {
71
75
  const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
72
76
  // Safe to assume the cursor position always point to a Choice.
73
77
  const selectedChoice = items[active];
78
+ const [errorMsg, setError] = useState();
74
79
  useKeypress((key, rl) => {
75
80
  clearTimeout(searchTimeoutRef.current);
81
+ if (errorMsg) {
82
+ setError(undefined);
83
+ }
76
84
  if (isEnterKey(key)) {
77
- setStatus('done');
78
- done(selectedChoice.value);
85
+ if (selectedChoice.disabled) {
86
+ setError(theme.i18n.disabledError);
87
+ }
88
+ else {
89
+ setStatus('done');
90
+ done(selectedChoice.value);
91
+ }
79
92
  }
80
93
  else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
81
94
  rl.clearLine(0);
@@ -86,7 +99,7 @@ export default createPrompt((config, done) => {
86
99
  let next = active;
87
100
  do {
88
101
  next = (next + offset + items.length) % items.length;
89
- } while (!isSelectable(items[next]));
102
+ } while (!isNavigable(items[next]));
90
103
  setActive(next);
91
104
  }
92
105
  }
@@ -143,13 +156,14 @@ export default createPrompt((config, done) => {
143
156
  separatorCount++;
144
157
  return ` ${item.separator}`;
145
158
  }
159
+ const cursor = isActive ? theme.icon.cursor : ' ';
146
160
  const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
147
161
  if (item.disabled) {
148
162
  const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
149
- return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
163
+ const disabledCursor = isActive ? theme.icon.cursor : '-';
164
+ return theme.style.disabled(`${disabledCursor} ${indexLabel}${item.name} ${disabledLabel}`);
150
165
  }
151
166
  const color = isActive ? theme.style.highlight : (x) => x;
152
- const cursor = isActive ? theme.icon.cursor : ` `;
153
167
  return color(`${cursor} ${indexLabel}${item.name}`);
154
168
  },
155
169
  pageSize,
@@ -166,6 +180,7 @@ export default createPrompt((config, done) => {
166
180
  page,
167
181
  ' ',
168
182
  description ? theme.style.description(description) : '',
183
+ errorMsg ? theme.style.error(errorMsg) : '',
169
184
  helpLine,
170
185
  ]
171
186
  .filter(Boolean)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/select",
3
- "version": "5.0.6",
3
+ "version": "5.1.0",
4
4
  "description": "Inquirer select/list prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -68,12 +68,12 @@
68
68
  },
69
69
  "dependencies": {
70
70
  "@inquirer/ansi": "^2.0.3",
71
- "@inquirer/core": "^11.1.3",
71
+ "@inquirer/core": "^11.1.5",
72
72
  "@inquirer/figures": "^2.0.3",
73
73
  "@inquirer/type": "^4.0.3"
74
74
  },
75
75
  "devDependencies": {
76
- "@inquirer/testing": "^3.1.1",
76
+ "@inquirer/testing": "^3.3.0",
77
77
  "typescript": "^5.9.3"
78
78
  },
79
79
  "peerDependencies": {
@@ -89,5 +89,5 @@
89
89
  },
90
90
  "main": "./dist/index.js",
91
91
  "types": "./dist/index.d.ts",
92
- "gitHead": "48b5d7e8b14d5c9fc4a19a8f1ead20a7593b29e1"
92
+ "gitHead": "526eca2e64853510821ffd457561840ec0cbfb93"
93
93
  }