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