@inquirer/rawlist 5.0.0 → 5.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/rawlist",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Inquirer rawlist prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -52,7 +52,10 @@
52
52
  "type": "module",
53
53
  "exports": {
54
54
  "./package.json": "./package.json",
55
- ".": "./src/index.ts"
55
+ ".": {
56
+ "types": "./dist/index.d.ts",
57
+ "default": "./dist/index.js"
58
+ }
56
59
  },
57
60
  "files": [
58
61
  "dist"
@@ -61,26 +64,18 @@
61
64
  "tsc": "tsc"
62
65
  },
63
66
  "dependencies": {
64
- "@inquirer/core": "^11.0.0",
65
- "@inquirer/type": "^4.0.0"
67
+ "@inquirer/core": "^11.0.2",
68
+ "@inquirer/type": "^4.0.2"
66
69
  },
67
70
  "devDependencies": {
68
- "@inquirer/testing": "^3.0.0",
69
- "@repo/tsconfig": "0.0.0",
71
+ "@inquirer/testing": "^3.0.2",
70
72
  "typescript": "^5.9.3"
71
73
  },
72
74
  "engines": {
73
75
  "node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
74
76
  },
75
77
  "publishConfig": {
76
- "access": "public",
77
- "exports": {
78
- "./package.json": "./package.json",
79
- ".": {
80
- "types": "./dist/index.d.ts",
81
- "default": "./dist/index.js"
82
- }
83
- }
78
+ "access": "public"
84
79
  },
85
80
  "peerDependencies": {
86
81
  "@types/node": ">=18"
@@ -90,5 +85,7 @@
90
85
  "optional": true
91
86
  }
92
87
  },
93
- "gitHead": "676685d33374a30340c1b9f0831c7eae2b2357dd"
88
+ "main": "./dist/index.js",
89
+ "types": "./dist/index.d.ts",
90
+ "gitHead": "9c724296daad3d740b09173f9aae035dc62cb106"
94
91
  }
@@ -1,18 +0,0 @@
1
- import { Separator, type Theme } from '@inquirer/core';
2
- import type { PartialDeep } from '@inquirer/type';
3
- type Choice<Value> = {
4
- value: Value;
5
- name?: string;
6
- short?: string;
7
- key?: string;
8
- };
9
- declare const _default: <Value>(config: {
10
- message: string;
11
- choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
12
- loop?: boolean | undefined;
13
- theme?: PartialDeep<Theme> | undefined;
14
- }, context?: import("@inquirer/type").Context) => Promise<Value> & {
15
- cancel: () => void;
16
- };
17
- export default _default;
18
- export { Separator } from '@inquirer/core';
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Separator = void 0;
7
- const core_1 = require("@inquirer/core");
8
- const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
9
- const numberRegex = /\d+/;
10
- function isSelectableChoice(choice) {
11
- return choice != null && !core_1.Separator.isSeparator(choice);
12
- }
13
- function normalizeChoices(choices) {
14
- let index = 0;
15
- return choices.map((choice) => {
16
- if (core_1.Separator.isSeparator(choice))
17
- return choice;
18
- index += 1;
19
- if (typeof choice === 'string') {
20
- return {
21
- value: choice,
22
- name: choice,
23
- short: choice,
24
- key: String(index),
25
- };
26
- }
27
- const name = choice.name ?? String(choice.value);
28
- return {
29
- value: choice.value,
30
- name,
31
- short: choice.short ?? name,
32
- key: choice.key ?? String(index),
33
- };
34
- });
35
- }
36
- function getSelectedChoice(input, choices) {
37
- let selectedChoice;
38
- const selectableChoices = choices.filter(isSelectableChoice);
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)) {
43
- const answer = Number.parseInt(input, 10) - 1;
44
- selectedChoice = selectableChoices[answer];
45
- }
46
- return selectedChoice
47
- ? [selectedChoice, choices.indexOf(selectedChoice)]
48
- : [undefined, undefined];
49
- }
50
- exports.default = (0, core_1.createPrompt)((config, done) => {
51
- const { loop = true } = config;
52
- const choices = (0, core_1.useMemo)(() => normalizeChoices(config.choices), [config.choices]);
53
- const [status, setStatus] = (0, core_1.useState)('idle');
54
- const [value, setValue] = (0, core_1.useState)('');
55
- const [errorMsg, setError] = (0, core_1.useState)();
56
- const theme = (0, core_1.makeTheme)(config.theme);
57
- const prefix = (0, core_1.usePrefix)({ status, theme });
58
- const bounds = (0, core_1.useMemo)(() => {
59
- const first = choices.findIndex(isSelectableChoice);
60
- const last = choices.findLastIndex(isSelectableChoice);
61
- if (first === -1) {
62
- throw new core_1.ValidationError('[select prompt] No selectable choices. All choices are disabled.');
63
- }
64
- return { first, last };
65
- }, [choices]);
66
- (0, core_1.useKeypress)((key, rl) => {
67
- if ((0, core_1.isEnterKey)(key)) {
68
- const [selectedChoice] = getSelectedChoice(value, choices);
69
- if (isSelectableChoice(selectedChoice)) {
70
- setValue(selectedChoice.short);
71
- setStatus('done');
72
- done(selectedChoice.value);
73
- }
74
- else if (value === '') {
75
- setError('Please input a value');
76
- }
77
- else {
78
- setError(`"${yoctocolors_cjs_1.default.red(value)}" isn't an available option`);
79
- }
80
- }
81
- else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) {
82
- rl.clearLine(0);
83
- const [selectedChoice, active] = getSelectedChoice(value, choices);
84
- if (!selectedChoice) {
85
- const firstChoice = (0, core_1.isDownKey)(key)
86
- ? choices.find(isSelectableChoice)
87
- : choices.findLast(isSelectableChoice);
88
- setValue(firstChoice.key);
89
- }
90
- else if (loop ||
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
- let next = active;
95
- do {
96
- next = (next + offset + choices.length) % choices.length;
97
- } while (!isSelectableChoice(choices[next]));
98
- setValue(choices[next].key);
99
- }
100
- }
101
- else {
102
- setValue(rl.line);
103
- setError(undefined);
104
- }
105
- });
106
- const message = theme.style.message(config.message, status);
107
- if (status === 'done') {
108
- return `${prefix} ${message} ${theme.style.answer(value)}`;
109
- }
110
- const choicesStr = choices
111
- .map((choice) => {
112
- if (core_1.Separator.isSeparator(choice)) {
113
- return ` ${choice.separator}`;
114
- }
115
- const line = ` ${choice.key}) ${choice.name}`;
116
- if (choice.key === value.toLowerCase()) {
117
- return theme.style.highlight(line);
118
- }
119
- return line;
120
- })
121
- .join('\n');
122
- let error = '';
123
- if (errorMsg) {
124
- error = theme.style.error(errorMsg);
125
- }
126
- return [
127
- `${prefix} ${message} ${value}`,
128
- [choicesStr, error].filter(Boolean).join('\n'),
129
- ];
130
- });
131
- var core_2 = require("@inquirer/core");
132
- Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_2.Separator; } });
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,18 +0,0 @@
1
- import { Separator, type Theme } from '@inquirer/core';
2
- import type { PartialDeep } from '@inquirer/type';
3
- type Choice<Value> = {
4
- value: Value;
5
- name?: string;
6
- short?: string;
7
- key?: string;
8
- };
9
- declare const _default: <Value>(config: {
10
- message: string;
11
- choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
12
- loop?: boolean | undefined;
13
- theme?: PartialDeep<Theme> | undefined;
14
- }, context?: import("@inquirer/type").Context) => Promise<Value> & {
15
- cancel: () => void;
16
- };
17
- export default _default;
18
- export { Separator } from '@inquirer/core';
package/dist/esm/index.js DELETED
@@ -1,125 +0,0 @@
1
- import { createPrompt, useMemo, useState, useKeypress, usePrefix, isDownKey, isEnterKey, isUpKey, Separator, makeTheme, ValidationError, } from '@inquirer/core';
2
- import colors from 'yoctocolors-cjs';
3
- const numberRegex = /\d+/;
4
- function isSelectableChoice(choice) {
5
- return choice != null && !Separator.isSeparator(choice);
6
- }
7
- function normalizeChoices(choices) {
8
- let index = 0;
9
- return choices.map((choice) => {
10
- if (Separator.isSeparator(choice))
11
- return choice;
12
- index += 1;
13
- if (typeof choice === 'string') {
14
- return {
15
- value: choice,
16
- name: choice,
17
- short: choice,
18
- key: String(index),
19
- };
20
- }
21
- const name = choice.name ?? String(choice.value);
22
- return {
23
- value: choice.value,
24
- name,
25
- short: choice.short ?? name,
26
- key: choice.key ?? String(index),
27
- };
28
- });
29
- }
30
- function getSelectedChoice(input, choices) {
31
- let selectedChoice;
32
- const selectableChoices = choices.filter(isSelectableChoice);
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)) {
37
- const answer = Number.parseInt(input, 10) - 1;
38
- selectedChoice = selectableChoices[answer];
39
- }
40
- return selectedChoice
41
- ? [selectedChoice, choices.indexOf(selectedChoice)]
42
- : [undefined, undefined];
43
- }
44
- export default createPrompt((config, done) => {
45
- const { loop = true } = config;
46
- const choices = useMemo(() => normalizeChoices(config.choices), [config.choices]);
47
- const [status, setStatus] = useState('idle');
48
- const [value, setValue] = useState('');
49
- const [errorMsg, setError] = useState();
50
- const theme = makeTheme(config.theme);
51
- const prefix = usePrefix({ status, theme });
52
- const bounds = useMemo(() => {
53
- const first = choices.findIndex(isSelectableChoice);
54
- const last = choices.findLastIndex(isSelectableChoice);
55
- if (first === -1) {
56
- throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
57
- }
58
- return { first, last };
59
- }, [choices]);
60
- useKeypress((key, rl) => {
61
- if (isEnterKey(key)) {
62
- const [selectedChoice] = getSelectedChoice(value, choices);
63
- if (isSelectableChoice(selectedChoice)) {
64
- setValue(selectedChoice.short);
65
- setStatus('done');
66
- done(selectedChoice.value);
67
- }
68
- else if (value === '') {
69
- setError('Please input a value');
70
- }
71
- else {
72
- setError(`"${colors.red(value)}" isn't an available option`);
73
- }
74
- }
75
- else if (isUpKey(key) || isDownKey(key)) {
76
- rl.clearLine(0);
77
- const [selectedChoice, active] = getSelectedChoice(value, choices);
78
- if (!selectedChoice) {
79
- const firstChoice = isDownKey(key)
80
- ? choices.find(isSelectableChoice)
81
- : choices.findLast(isSelectableChoice);
82
- setValue(firstChoice.key);
83
- }
84
- else if (loop ||
85
- (isUpKey(key) && active !== bounds.first) ||
86
- (isDownKey(key) && active !== bounds.last)) {
87
- const offset = isUpKey(key) ? -1 : 1;
88
- let next = active;
89
- do {
90
- next = (next + offset + choices.length) % choices.length;
91
- } while (!isSelectableChoice(choices[next]));
92
- setValue(choices[next].key);
93
- }
94
- }
95
- else {
96
- setValue(rl.line);
97
- setError(undefined);
98
- }
99
- });
100
- const message = theme.style.message(config.message, status);
101
- if (status === 'done') {
102
- return `${prefix} ${message} ${theme.style.answer(value)}`;
103
- }
104
- const choicesStr = choices
105
- .map((choice) => {
106
- if (Separator.isSeparator(choice)) {
107
- return ` ${choice.separator}`;
108
- }
109
- const line = ` ${choice.key}) ${choice.name}`;
110
- if (choice.key === value.toLowerCase()) {
111
- return theme.style.highlight(line);
112
- }
113
- return line;
114
- })
115
- .join('\n');
116
- let error = '';
117
- if (errorMsg) {
118
- error = theme.style.error(errorMsg);
119
- }
120
- return [
121
- `${prefix} ${message} ${value}`,
122
- [choicesStr, error].filter(Boolean).join('\n'),
123
- ];
124
- });
125
- export { Separator } from '@inquirer/core';
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }