@inquirer/rawlist 4.1.5 → 4.1.7

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.
@@ -36,13 +36,13 @@ function normalizeChoices(choices) {
36
36
  function getSelectedChoice(input, choices) {
37
37
  let selectedChoice;
38
38
  const selectableChoices = choices.filter(isSelectableChoice);
39
- if (numberRegex.test(input)) {
39
+ // First, try to match by custom key (exact match)
40
+ selectedChoice = selectableChoices.find((choice) => choice.key === input);
41
+ // If no custom key match and input is numeric, try 1-based index
42
+ if (!selectedChoice && numberRegex.test(input)) {
40
43
  const answer = Number.parseInt(input, 10) - 1;
41
44
  selectedChoice = selectableChoices[answer];
42
45
  }
43
- else {
44
- selectedChoice = selectableChoices.find((choice) => choice.key === input);
45
- }
46
46
  return selectedChoice
47
47
  ? [selectedChoice, choices.indexOf(selectedChoice)]
48
48
  : [undefined, undefined];
@@ -78,19 +78,19 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
78
78
  setError(`"${yoctocolors_cjs_1.default.red(value)}" isn't an available option`);
79
79
  }
80
80
  }
81
- else if (key.name === 'up' || key.name === 'down') {
81
+ else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) {
82
82
  rl.clearLine(0);
83
83
  const [selectedChoice, active] = getSelectedChoice(value, choices);
84
84
  if (!selectedChoice) {
85
- const firstChoice = key.name === 'down'
85
+ const firstChoice = (0, core_1.isDownKey)(key)
86
86
  ? choices.find(isSelectableChoice)
87
87
  : choices.findLast(isSelectableChoice);
88
88
  setValue(firstChoice.key);
89
89
  }
90
90
  else if (loop ||
91
- (key.name === 'up' && active !== bounds.first) ||
92
- (key.name === 'down' && active !== bounds.last)) {
93
- const offset = key.name === 'up' ? -1 : 1;
91
+ ((0, core_1.isUpKey)(key) && active !== bounds.first) ||
92
+ ((0, core_1.isDownKey)(key) && active !== bounds.last)) {
93
+ const offset = (0, core_1.isUpKey)(key) ? -1 : 1;
94
94
  let next = active;
95
95
  do {
96
96
  next = (next + offset + choices.length) % choices.length;
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createPrompt, useMemo, useState, useKeypress, usePrefix, isEnterKey, Separator, makeTheme, ValidationError, } from '@inquirer/core';
1
+ import { createPrompt, useMemo, useState, useKeypress, usePrefix, isDownKey, isEnterKey, isUpKey, Separator, makeTheme, ValidationError, } from '@inquirer/core';
2
2
  import colors from 'yoctocolors-cjs';
3
3
  const numberRegex = /\d+/;
4
4
  function isSelectableChoice(choice) {
@@ -30,13 +30,13 @@ function normalizeChoices(choices) {
30
30
  function getSelectedChoice(input, choices) {
31
31
  let selectedChoice;
32
32
  const selectableChoices = choices.filter(isSelectableChoice);
33
- if (numberRegex.test(input)) {
33
+ // First, try to match by custom key (exact match)
34
+ selectedChoice = selectableChoices.find((choice) => choice.key === input);
35
+ // If no custom key match and input is numeric, try 1-based index
36
+ if (!selectedChoice && numberRegex.test(input)) {
34
37
  const answer = Number.parseInt(input, 10) - 1;
35
38
  selectedChoice = selectableChoices[answer];
36
39
  }
37
- else {
38
- selectedChoice = selectableChoices.find((choice) => choice.key === input);
39
- }
40
40
  return selectedChoice
41
41
  ? [selectedChoice, choices.indexOf(selectedChoice)]
42
42
  : [undefined, undefined];
@@ -72,19 +72,19 @@ export default createPrompt((config, done) => {
72
72
  setError(`"${colors.red(value)}" isn't an available option`);
73
73
  }
74
74
  }
75
- else if (key.name === 'up' || key.name === 'down') {
75
+ else if (isUpKey(key) || isDownKey(key)) {
76
76
  rl.clearLine(0);
77
77
  const [selectedChoice, active] = getSelectedChoice(value, choices);
78
78
  if (!selectedChoice) {
79
- const firstChoice = key.name === 'down'
79
+ const firstChoice = isDownKey(key)
80
80
  ? choices.find(isSelectableChoice)
81
81
  : choices.findLast(isSelectableChoice);
82
82
  setValue(firstChoice.key);
83
83
  }
84
84
  else if (loop ||
85
- (key.name === 'up' && active !== bounds.first) ||
86
- (key.name === 'down' && active !== bounds.last)) {
87
- const offset = key.name === 'up' ? -1 : 1;
85
+ (isUpKey(key) && active !== bounds.first) ||
86
+ (isDownKey(key) && active !== bounds.last)) {
87
+ const offset = isUpKey(key) ? -1 : 1;
88
88
  let next = active;
89
89
  do {
90
90
  next = (next + offset + choices.length) % choices.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/rawlist",
3
- "version": "4.1.5",
3
+ "version": "4.1.7",
4
4
  "description": "Inquirer rawlist prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -74,7 +74,7 @@
74
74
  "tsc": "tshy"
75
75
  },
76
76
  "dependencies": {
77
- "@inquirer/core": "^10.1.15",
77
+ "@inquirer/core": "^10.2.1",
78
78
  "@inquirer/type": "^3.0.8",
79
79
  "yoctocolors-cjs": "^2.1.2"
80
80
  },
@@ -106,5 +106,5 @@
106
106
  "optional": true
107
107
  }
108
108
  },
109
- "gitHead": "c1a755fe8b50377b685ea5951e0794985ce8d356"
109
+ "gitHead": "62045dc4a4cd6f31ba0f77b20874be2409570957"
110
110
  }