@inquirer/rawlist 5.0.1 → 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/README.md +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -4
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@ const answer = await rawlist({
|
|
|
72
72
|
| message | `string` | yes | The question to ask |
|
|
73
73
|
| choices | `Choice[]` | yes | List of the available choices. |
|
|
74
74
|
| loop | `boolean` | no | Defaults to `true`. When set to `false`, the cursor will be constrained to the top and bottom of the choice list without looping. |
|
|
75
|
+
| default | `Value` | no | The value of the choice to preselect. If the value is not found, no choice is preselected. |
|
|
75
76
|
| theme | [See Theming](#Theming) | no | Customize look of the prompt. |
|
|
76
77
|
|
|
77
78
|
`Separator` objects can be used in the `choices` array to render non-selectable lines in the choice list. By default it'll render a line, but you can provide the text as argument (`new Separator('-- Dependencies --')`). This option is often used to add labels to groups within long list of options.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ type Choice<Value> = {
|
|
|
8
8
|
};
|
|
9
9
|
declare const _default: <Value>(config: {
|
|
10
10
|
message: string;
|
|
11
|
-
choices: readonly (
|
|
11
|
+
choices: readonly (Separator | Value | Choice<Value>)[];
|
|
12
12
|
loop?: boolean | undefined;
|
|
13
13
|
theme?: PartialDeep<Theme> | undefined;
|
|
14
|
+
default?: NoInfer<Value> | undefined;
|
|
14
15
|
}, context?: import("@inquirer/type").Context) => Promise<Value>;
|
|
15
16
|
export default _default;
|
|
16
17
|
export { Separator } from '@inquirer/core';
|
package/dist/index.js
CHANGED
|
@@ -10,11 +10,12 @@ function normalizeChoices(choices) {
|
|
|
10
10
|
if (Separator.isSeparator(choice))
|
|
11
11
|
return choice;
|
|
12
12
|
index += 1;
|
|
13
|
-
if (typeof choice === '
|
|
13
|
+
if (typeof choice !== 'object' || choice === null || !('value' in choice)) {
|
|
14
|
+
const name = String(choice);
|
|
14
15
|
return {
|
|
15
16
|
value: choice,
|
|
16
|
-
name
|
|
17
|
-
short:
|
|
17
|
+
name,
|
|
18
|
+
short: name,
|
|
18
19
|
key: String(index),
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -45,7 +46,12 @@ export default createPrompt((config, done) => {
|
|
|
45
46
|
const { loop = true } = config;
|
|
46
47
|
const choices = useMemo(() => normalizeChoices(config.choices), [config.choices]);
|
|
47
48
|
const [status, setStatus] = useState('idle');
|
|
48
|
-
const [value, setValue] = useState(
|
|
49
|
+
const [value, setValue] = useState(() => {
|
|
50
|
+
const defaultChoice = config.default == null
|
|
51
|
+
? undefined
|
|
52
|
+
: choices.find((choice) => isSelectableChoice(choice) && choice.value === config.default);
|
|
53
|
+
return defaultChoice?.key ?? '';
|
|
54
|
+
});
|
|
49
55
|
const [errorMsg, setError] = useState();
|
|
50
56
|
const theme = makeTheme(config.theme);
|
|
51
57
|
const prefix = usePrefix({ status, theme });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/rawlist",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Inquirer rawlist prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -64,11 +64,12 @@
|
|
|
64
64
|
"tsc": "tsc"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@inquirer/core": "^11.0
|
|
68
|
-
"@inquirer/type": "^4.0.
|
|
67
|
+
"@inquirer/core": "^11.1.0",
|
|
68
|
+
"@inquirer/type": "^4.0.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@inquirer/testing": "^3.0.
|
|
71
|
+
"@inquirer/testing": "^3.0.3",
|
|
72
|
+
"@repo/tsconfig": "0.0.0",
|
|
72
73
|
"typescript": "^5.9.3"
|
|
73
74
|
},
|
|
74
75
|
"engines": {
|
|
@@ -85,5 +86,7 @@
|
|
|
85
86
|
"optional": true
|
|
86
87
|
}
|
|
87
88
|
},
|
|
88
|
-
"
|
|
89
|
+
"main": "./dist/index.js",
|
|
90
|
+
"types": "./dist/index.d.ts",
|
|
91
|
+
"gitHead": "7eedd8e1de71764d0d30e762c97992ceb9f68ed3"
|
|
89
92
|
}
|