@inquirer/select 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/select",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Inquirer select/list 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,28 +64,20 @@
61
64
  "tsc": "tsc"
62
65
  },
63
66
  "dependencies": {
64
- "@inquirer/ansi": "^2.0.0",
65
- "@inquirer/core": "^11.0.0",
66
- "@inquirer/figures": "^2.0.0",
67
- "@inquirer/type": "^4.0.0"
67
+ "@inquirer/ansi": "^2.0.2",
68
+ "@inquirer/core": "^11.0.2",
69
+ "@inquirer/figures": "^2.0.2",
70
+ "@inquirer/type": "^4.0.2"
68
71
  },
69
72
  "devDependencies": {
70
- "@inquirer/testing": "^3.0.0",
71
- "@repo/tsconfig": "0.0.0",
73
+ "@inquirer/testing": "^3.0.2",
72
74
  "typescript": "^5.9.3"
73
75
  },
74
76
  "engines": {
75
77
  "node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
76
78
  },
77
79
  "publishConfig": {
78
- "access": "public",
79
- "exports": {
80
- "./package.json": "./package.json",
81
- ".": {
82
- "types": "./dist/index.d.ts",
83
- "default": "./dist/index.js"
84
- }
85
- }
80
+ "access": "public"
86
81
  },
87
82
  "peerDependencies": {
88
83
  "@types/node": ">=18"
@@ -92,5 +87,7 @@
92
87
  "optional": true
93
88
  }
94
89
  },
95
- "gitHead": "676685d33374a30340c1b9f0831c7eae2b2357dd"
90
+ "main": "./dist/index.js",
91
+ "types": "./dist/index.d.ts",
92
+ "gitHead": "9c724296daad3d740b09173f9aae035dc62cb106"
96
93
  }
@@ -1,40 +0,0 @@
1
- import { Separator, type Theme, type Keybinding } from '@inquirer/core';
2
- import type { PartialDeep } from '@inquirer/type';
3
- type SelectTheme = {
4
- icon: {
5
- cursor: string;
6
- };
7
- style: {
8
- disabled: (text: string) => string;
9
- description: (text: string) => string;
10
- keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
11
- };
12
- /** @deprecated Use theme.style.keysHelpTip instead */
13
- helpMode: 'always' | 'never' | 'auto';
14
- indexMode: 'hidden' | 'number';
15
- keybindings: ReadonlyArray<Keybinding>;
16
- };
17
- type Choice<Value> = {
18
- value: Value;
19
- name?: string;
20
- description?: string;
21
- short?: string;
22
- disabled?: boolean | string;
23
- type?: never;
24
- };
25
- declare const _default: <Value>(config: {
26
- message: string;
27
- choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
28
- pageSize?: number | undefined;
29
- loop?: boolean | undefined;
30
- default?: unknown;
31
- instructions?: {
32
- navigation: string;
33
- pager: string;
34
- } | undefined;
35
- theme?: PartialDeep<Theme<SelectTheme>> | undefined;
36
- }, context?: import("@inquirer/type").Context) => Promise<Value> & {
37
- cancel: () => void;
38
- };
39
- export default _default;
40
- export { Separator } from '@inquirer/core';
@@ -1,194 +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 ansi_1 = require("@inquirer/ansi");
9
- const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
10
- const figures_1 = __importDefault(require("@inquirer/figures"));
11
- const selectTheme = {
12
- icon: { cursor: figures_1.default.pointer },
13
- style: {
14
- disabled: (text) => yoctocolors_cjs_1.default.dim(`- ${text}`),
15
- description: (text) => yoctocolors_cjs_1.default.cyan(text),
16
- keysHelpTip: (keys) => keys
17
- .map(([key, action]) => `${yoctocolors_cjs_1.default.bold(key)} ${yoctocolors_cjs_1.default.dim(action)}`)
18
- .join(yoctocolors_cjs_1.default.dim(' • ')),
19
- },
20
- helpMode: 'always',
21
- indexMode: 'hidden',
22
- keybindings: [],
23
- };
24
- function isSelectable(item) {
25
- return !core_1.Separator.isSeparator(item) && !item.disabled;
26
- }
27
- function normalizeChoices(choices) {
28
- return choices.map((choice) => {
29
- if (core_1.Separator.isSeparator(choice))
30
- return choice;
31
- if (typeof choice === 'string') {
32
- return {
33
- value: choice,
34
- name: choice,
35
- short: choice,
36
- disabled: false,
37
- };
38
- }
39
- const name = choice.name ?? String(choice.value);
40
- const normalizedChoice = {
41
- value: choice.value,
42
- name,
43
- short: choice.short ?? name,
44
- disabled: choice.disabled ?? false,
45
- };
46
- if (choice.description) {
47
- normalizedChoice.description = choice.description;
48
- }
49
- return normalizedChoice;
50
- });
51
- }
52
- exports.default = (0, core_1.createPrompt)((config, done) => {
53
- const { loop = true, pageSize = 7 } = config;
54
- const theme = (0, core_1.makeTheme)(selectTheme, config.theme);
55
- const { keybindings } = theme;
56
- const [status, setStatus] = (0, core_1.useState)('idle');
57
- const prefix = (0, core_1.usePrefix)({ status, theme });
58
- const searchTimeoutRef = (0, core_1.useRef)();
59
- // Vim keybindings (j/k) conflict with typing those letters in search,
60
- // so search must be disabled when vim bindings are enabled
61
- const searchEnabled = !keybindings.includes('vim');
62
- const items = (0, core_1.useMemo)(() => normalizeChoices(config.choices), [config.choices]);
63
- const bounds = (0, core_1.useMemo)(() => {
64
- const first = items.findIndex(isSelectable);
65
- const last = items.findLastIndex(isSelectable);
66
- if (first === -1) {
67
- throw new core_1.ValidationError('[select prompt] No selectable choices. All choices are disabled.');
68
- }
69
- return { first, last };
70
- }, [items]);
71
- const defaultItemIndex = (0, core_1.useMemo)(() => {
72
- if (!('default' in config))
73
- return -1;
74
- return items.findIndex((item) => isSelectable(item) && item.value === config.default);
75
- }, [config.default, items]);
76
- const [active, setActive] = (0, core_1.useState)(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
77
- // Safe to assume the cursor position always point to a Choice.
78
- const selectedChoice = items[active];
79
- (0, core_1.useKeypress)((key, rl) => {
80
- clearTimeout(searchTimeoutRef.current);
81
- if ((0, core_1.isEnterKey)(key)) {
82
- setStatus('done');
83
- done(selectedChoice.value);
84
- }
85
- else if ((0, core_1.isUpKey)(key, keybindings) || (0, core_1.isDownKey)(key, keybindings)) {
86
- rl.clearLine(0);
87
- if (loop ||
88
- ((0, core_1.isUpKey)(key, keybindings) && active !== bounds.first) ||
89
- ((0, core_1.isDownKey)(key, keybindings) && active !== bounds.last)) {
90
- const offset = (0, core_1.isUpKey)(key, keybindings) ? -1 : 1;
91
- let next = active;
92
- do {
93
- next = (next + offset + items.length) % items.length;
94
- } while (!isSelectable(items[next]));
95
- setActive(next);
96
- }
97
- }
98
- else if ((0, core_1.isNumberKey)(key) && !Number.isNaN(Number(rl.line))) {
99
- const selectedIndex = Number(rl.line) - 1;
100
- // Find the nth item (ignoring separators)
101
- let selectableIndex = -1;
102
- const position = items.findIndex((item) => {
103
- if (core_1.Separator.isSeparator(item))
104
- return false;
105
- selectableIndex++;
106
- return selectableIndex === selectedIndex;
107
- });
108
- const item = items[position];
109
- if (item != null && isSelectable(item)) {
110
- setActive(position);
111
- }
112
- searchTimeoutRef.current = setTimeout(() => {
113
- rl.clearLine(0);
114
- }, 700);
115
- }
116
- else if ((0, core_1.isBackspaceKey)(key)) {
117
- rl.clearLine(0);
118
- }
119
- else if (searchEnabled) {
120
- const searchTerm = rl.line.toLowerCase();
121
- const matchIndex = items.findIndex((item) => {
122
- if (core_1.Separator.isSeparator(item) || !isSelectable(item))
123
- return false;
124
- return item.name.toLowerCase().startsWith(searchTerm);
125
- });
126
- if (matchIndex !== -1) {
127
- setActive(matchIndex);
128
- }
129
- searchTimeoutRef.current = setTimeout(() => {
130
- rl.clearLine(0);
131
- }, 700);
132
- }
133
- });
134
- (0, core_1.useEffect)(() => () => {
135
- clearTimeout(searchTimeoutRef.current);
136
- }, []);
137
- const message = theme.style.message(config.message, status);
138
- let helpLine;
139
- // eslint-disable-next-line @typescript-eslint/no-deprecated
140
- if (theme.helpMode !== 'never') {
141
- // eslint-disable-next-line @typescript-eslint/no-deprecated
142
- if (config.instructions) {
143
- // eslint-disable-next-line @typescript-eslint/no-deprecated
144
- const { pager, navigation } = config.instructions;
145
- helpLine = theme.style.help(items.length > pageSize ? pager : navigation);
146
- }
147
- else {
148
- helpLine = theme.style.keysHelpTip([
149
- ['↑↓', 'navigate'],
150
- ['⏎', 'select'],
151
- ]);
152
- }
153
- }
154
- let separatorCount = 0;
155
- const page = (0, core_1.usePagination)({
156
- items,
157
- active,
158
- renderItem({ item, isActive, index }) {
159
- if (core_1.Separator.isSeparator(item)) {
160
- separatorCount++;
161
- return ` ${item.separator}`;
162
- }
163
- const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
164
- if (item.disabled) {
165
- const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
166
- return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
167
- }
168
- const color = isActive ? theme.style.highlight : (x) => x;
169
- const cursor = isActive ? theme.icon.cursor : ` `;
170
- return color(`${cursor} ${indexLabel}${item.name}`);
171
- },
172
- pageSize,
173
- loop,
174
- });
175
- if (status === 'done') {
176
- return [prefix, message, theme.style.answer(selectedChoice.short)]
177
- .filter(Boolean)
178
- .join(' ');
179
- }
180
- const { description } = selectedChoice;
181
- const lines = [
182
- [prefix, message].filter(Boolean).join(' '),
183
- page,
184
- ' ',
185
- description ? theme.style.description(description) : '',
186
- helpLine,
187
- ]
188
- .filter(Boolean)
189
- .join('\n')
190
- .trimEnd();
191
- return `${lines}${ansi_1.cursorHide}`;
192
- });
193
- var core_2 = require("@inquirer/core");
194
- Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_2.Separator; } });
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,40 +0,0 @@
1
- import { Separator, type Theme, type Keybinding } from '@inquirer/core';
2
- import type { PartialDeep } from '@inquirer/type';
3
- type SelectTheme = {
4
- icon: {
5
- cursor: string;
6
- };
7
- style: {
8
- disabled: (text: string) => string;
9
- description: (text: string) => string;
10
- keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
11
- };
12
- /** @deprecated Use theme.style.keysHelpTip instead */
13
- helpMode: 'always' | 'never' | 'auto';
14
- indexMode: 'hidden' | 'number';
15
- keybindings: ReadonlyArray<Keybinding>;
16
- };
17
- type Choice<Value> = {
18
- value: Value;
19
- name?: string;
20
- description?: string;
21
- short?: string;
22
- disabled?: boolean | string;
23
- type?: never;
24
- };
25
- declare const _default: <Value>(config: {
26
- message: string;
27
- choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
28
- pageSize?: number | undefined;
29
- loop?: boolean | undefined;
30
- default?: unknown;
31
- instructions?: {
32
- navigation: string;
33
- pager: string;
34
- } | undefined;
35
- theme?: PartialDeep<Theme<SelectTheme>> | undefined;
36
- }, context?: import("@inquirer/type").Context) => Promise<Value> & {
37
- cancel: () => void;
38
- };
39
- export default _default;
40
- export { Separator } from '@inquirer/core';
package/dist/esm/index.js DELETED
@@ -1,187 +0,0 @@
1
- import { createPrompt, useState, useKeypress, usePrefix, usePagination, useRef, useMemo, useEffect, isBackspaceKey, isEnterKey, isUpKey, isDownKey, isNumberKey, Separator, ValidationError, makeTheme, } from '@inquirer/core';
2
- import { cursorHide } from '@inquirer/ansi';
3
- import colors from 'yoctocolors-cjs';
4
- import figures from '@inquirer/figures';
5
- const selectTheme = {
6
- icon: { cursor: figures.pointer },
7
- style: {
8
- disabled: (text) => colors.dim(`- ${text}`),
9
- description: (text) => colors.cyan(text),
10
- keysHelpTip: (keys) => keys
11
- .map(([key, action]) => `${colors.bold(key)} ${colors.dim(action)}`)
12
- .join(colors.dim(' • ')),
13
- },
14
- helpMode: 'always',
15
- indexMode: 'hidden',
16
- keybindings: [],
17
- };
18
- function isSelectable(item) {
19
- return !Separator.isSeparator(item) && !item.disabled;
20
- }
21
- function normalizeChoices(choices) {
22
- return choices.map((choice) => {
23
- if (Separator.isSeparator(choice))
24
- return choice;
25
- if (typeof choice === 'string') {
26
- return {
27
- value: choice,
28
- name: choice,
29
- short: choice,
30
- disabled: false,
31
- };
32
- }
33
- const name = choice.name ?? String(choice.value);
34
- const normalizedChoice = {
35
- value: choice.value,
36
- name,
37
- short: choice.short ?? name,
38
- disabled: choice.disabled ?? false,
39
- };
40
- if (choice.description) {
41
- normalizedChoice.description = choice.description;
42
- }
43
- return normalizedChoice;
44
- });
45
- }
46
- export default createPrompt((config, done) => {
47
- const { loop = true, pageSize = 7 } = config;
48
- const theme = makeTheme(selectTheme, config.theme);
49
- const { keybindings } = theme;
50
- const [status, setStatus] = useState('idle');
51
- const prefix = usePrefix({ status, theme });
52
- const searchTimeoutRef = useRef();
53
- // Vim keybindings (j/k) conflict with typing those letters in search,
54
- // so search must be disabled when vim bindings are enabled
55
- const searchEnabled = !keybindings.includes('vim');
56
- const items = useMemo(() => normalizeChoices(config.choices), [config.choices]);
57
- const bounds = useMemo(() => {
58
- const first = items.findIndex(isSelectable);
59
- const last = items.findLastIndex(isSelectable);
60
- if (first === -1) {
61
- throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
62
- }
63
- return { first, last };
64
- }, [items]);
65
- const defaultItemIndex = useMemo(() => {
66
- if (!('default' in config))
67
- return -1;
68
- return items.findIndex((item) => isSelectable(item) && item.value === config.default);
69
- }, [config.default, items]);
70
- const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
71
- // Safe to assume the cursor position always point to a Choice.
72
- const selectedChoice = items[active];
73
- useKeypress((key, rl) => {
74
- clearTimeout(searchTimeoutRef.current);
75
- if (isEnterKey(key)) {
76
- setStatus('done');
77
- done(selectedChoice.value);
78
- }
79
- else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
80
- rl.clearLine(0);
81
- if (loop ||
82
- (isUpKey(key, keybindings) && active !== bounds.first) ||
83
- (isDownKey(key, keybindings) && active !== bounds.last)) {
84
- const offset = isUpKey(key, keybindings) ? -1 : 1;
85
- let next = active;
86
- do {
87
- next = (next + offset + items.length) % items.length;
88
- } while (!isSelectable(items[next]));
89
- setActive(next);
90
- }
91
- }
92
- else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
93
- const selectedIndex = Number(rl.line) - 1;
94
- // Find the nth item (ignoring separators)
95
- let selectableIndex = -1;
96
- const position = items.findIndex((item) => {
97
- if (Separator.isSeparator(item))
98
- return false;
99
- selectableIndex++;
100
- return selectableIndex === selectedIndex;
101
- });
102
- const item = items[position];
103
- if (item != null && isSelectable(item)) {
104
- setActive(position);
105
- }
106
- searchTimeoutRef.current = setTimeout(() => {
107
- rl.clearLine(0);
108
- }, 700);
109
- }
110
- else if (isBackspaceKey(key)) {
111
- rl.clearLine(0);
112
- }
113
- else if (searchEnabled) {
114
- const searchTerm = rl.line.toLowerCase();
115
- const matchIndex = items.findIndex((item) => {
116
- if (Separator.isSeparator(item) || !isSelectable(item))
117
- return false;
118
- return item.name.toLowerCase().startsWith(searchTerm);
119
- });
120
- if (matchIndex !== -1) {
121
- setActive(matchIndex);
122
- }
123
- searchTimeoutRef.current = setTimeout(() => {
124
- rl.clearLine(0);
125
- }, 700);
126
- }
127
- });
128
- useEffect(() => () => {
129
- clearTimeout(searchTimeoutRef.current);
130
- }, []);
131
- const message = theme.style.message(config.message, status);
132
- let helpLine;
133
- // eslint-disable-next-line @typescript-eslint/no-deprecated
134
- if (theme.helpMode !== 'never') {
135
- // eslint-disable-next-line @typescript-eslint/no-deprecated
136
- if (config.instructions) {
137
- // eslint-disable-next-line @typescript-eslint/no-deprecated
138
- const { pager, navigation } = config.instructions;
139
- helpLine = theme.style.help(items.length > pageSize ? pager : navigation);
140
- }
141
- else {
142
- helpLine = theme.style.keysHelpTip([
143
- ['↑↓', 'navigate'],
144
- ['⏎', 'select'],
145
- ]);
146
- }
147
- }
148
- let separatorCount = 0;
149
- const page = usePagination({
150
- items,
151
- active,
152
- renderItem({ item, isActive, index }) {
153
- if (Separator.isSeparator(item)) {
154
- separatorCount++;
155
- return ` ${item.separator}`;
156
- }
157
- const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
158
- if (item.disabled) {
159
- const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
160
- return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
161
- }
162
- const color = isActive ? theme.style.highlight : (x) => x;
163
- const cursor = isActive ? theme.icon.cursor : ` `;
164
- return color(`${cursor} ${indexLabel}${item.name}`);
165
- },
166
- pageSize,
167
- loop,
168
- });
169
- if (status === 'done') {
170
- return [prefix, message, theme.style.answer(selectedChoice.short)]
171
- .filter(Boolean)
172
- .join(' ');
173
- }
174
- const { description } = selectedChoice;
175
- const lines = [
176
- [prefix, message].filter(Boolean).join(' '),
177
- page,
178
- ' ',
179
- description ? theme.style.description(description) : '',
180
- helpLine,
181
- ]
182
- .filter(Boolean)
183
- .join('\n')
184
- .trimEnd();
185
- return `${lines}${cursorHide}`;
186
- });
187
- export { Separator } from '@inquirer/core';
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }