@inquirer/rawlist 2.2.4 → 3.0.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 +5 -3
- package/dist/cjs/index.js +30 -8
- package/dist/cjs/types/index.d.ts +4 -2
- package/dist/esm/index.mjs +30 -9
- package/dist/esm/types/index.d.mts +4 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -90,25 +90,27 @@ type Choice<Value> = {
|
|
|
90
90
|
|
|
91
91
|
Here's each property:
|
|
92
92
|
|
|
93
|
-
- `value`: The value is what will be returned by `await
|
|
93
|
+
- `value`: The value is what will be returned by `await rawlist()`.
|
|
94
94
|
- `name`: This is the string displayed in the choice list.
|
|
95
95
|
- `short`: Once the prompt is done (press enter), we'll use `short` if defined to render next to the question. By default we'll use `name`.
|
|
96
96
|
- `key`: The key of the choice. Displayed as `key) name`.
|
|
97
97
|
|
|
98
|
+
`choices` can also be an array of string, in which case the string will be used both as the `value` and the `name`.
|
|
99
|
+
|
|
98
100
|
## Theming
|
|
99
101
|
|
|
100
102
|
You can theme a prompt by passing a `theme` object option. The theme object only need to includes the keys you wish to modify, we'll fallback on the defaults for the rest.
|
|
101
103
|
|
|
102
104
|
```ts
|
|
103
105
|
type Theme = {
|
|
104
|
-
prefix: string;
|
|
106
|
+
prefix: string | { idle: string; done: string };
|
|
105
107
|
spinner: {
|
|
106
108
|
interval: number;
|
|
107
109
|
frames: string[];
|
|
108
110
|
};
|
|
109
111
|
style: {
|
|
110
112
|
answer: (text: string) => string;
|
|
111
|
-
message: (text: string) => string;
|
|
113
|
+
message: (text: string, status: 'idle' | 'done' | 'loading') => string;
|
|
112
114
|
error: (text: string) => string;
|
|
113
115
|
highlight: (text: string) => string;
|
|
114
116
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,13 +10,37 @@ const numberRegex = /\d+/;
|
|
|
10
10
|
function isSelectableChoice(choice) {
|
|
11
11
|
return choice != null && !core_1.Separator.isSeparator(choice);
|
|
12
12
|
}
|
|
13
|
+
function normalizeChoices(choices) {
|
|
14
|
+
let index = 0;
|
|
15
|
+
return choices.map((choice) => {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
if (core_1.Separator.isSeparator(choice))
|
|
18
|
+
return choice;
|
|
19
|
+
index += 1;
|
|
20
|
+
if (typeof choice === 'string') {
|
|
21
|
+
return {
|
|
22
|
+
value: choice,
|
|
23
|
+
name: choice,
|
|
24
|
+
short: choice,
|
|
25
|
+
key: String(index),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const name = (_a = choice.name) !== null && _a !== void 0 ? _a : String(choice.value);
|
|
29
|
+
return {
|
|
30
|
+
value: choice.value,
|
|
31
|
+
name,
|
|
32
|
+
short: (_b = choice.short) !== null && _b !== void 0 ? _b : name,
|
|
33
|
+
key: (_c = choice.key) !== null && _c !== void 0 ? _c : String(index),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
13
37
|
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
14
|
-
const
|
|
15
|
-
const [status, setStatus] = (0, core_1.useState)('
|
|
38
|
+
const choices = (0, core_1.useMemo)(() => normalizeChoices(config.choices), [config.choices]);
|
|
39
|
+
const [status, setStatus] = (0, core_1.useState)('idle');
|
|
16
40
|
const [value, setValue] = (0, core_1.useState)('');
|
|
17
41
|
const [errorMsg, setError] = (0, core_1.useState)();
|
|
18
42
|
const theme = (0, core_1.makeTheme)(config.theme);
|
|
19
|
-
const prefix = (0, core_1.usePrefix)({ theme });
|
|
43
|
+
const prefix = (0, core_1.usePrefix)({ status, theme });
|
|
20
44
|
(0, core_1.useKeypress)((key, rl) => {
|
|
21
45
|
var _a, _b;
|
|
22
46
|
if ((0, core_1.isEnterKey)(key)) {
|
|
@@ -45,19 +69,17 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
45
69
|
setError(undefined);
|
|
46
70
|
}
|
|
47
71
|
});
|
|
48
|
-
const message = theme.style.message(config.message);
|
|
72
|
+
const message = theme.style.message(config.message, status);
|
|
49
73
|
if (status === 'done') {
|
|
50
74
|
return `${prefix} ${message} ${theme.style.answer(value)}`;
|
|
51
75
|
}
|
|
52
|
-
let index = 0;
|
|
53
76
|
const choicesStr = choices
|
|
54
77
|
.map((choice) => {
|
|
55
78
|
if (core_1.Separator.isSeparator(choice)) {
|
|
56
79
|
return ` ${choice.separator}`;
|
|
57
80
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (choice.key === value.toLowerCase() || String(index) === value) {
|
|
81
|
+
const line = ` ${choice.key}) ${choice.name}`;
|
|
82
|
+
if (choice.key === value.toLowerCase()) {
|
|
61
83
|
return theme.style.highlight(line);
|
|
62
84
|
}
|
|
63
85
|
return line;
|
|
@@ -8,8 +8,10 @@ type Choice<Value> = {
|
|
|
8
8
|
};
|
|
9
9
|
declare const _default: <Value>(config: {
|
|
10
10
|
message: string;
|
|
11
|
-
choices: readonly (Separator | Choice<Value>)[];
|
|
11
|
+
choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
|
|
12
12
|
theme?: PartialDeep<Theme> | undefined;
|
|
13
|
-
}, context?: import("@inquirer/type").Context) =>
|
|
13
|
+
}, context?: import("@inquirer/type").Context) => Promise<Value> & {
|
|
14
|
+
cancel: () => void;
|
|
15
|
+
};
|
|
14
16
|
export default _default;
|
|
15
17
|
export { Separator } from '@inquirer/core';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
|
-
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, Separator, makeTheme, } from '@inquirer/core';
|
|
1
|
+
import { createPrompt, useMemo, useState, useKeypress, usePrefix, isEnterKey, Separator, makeTheme, } from '@inquirer/core';
|
|
2
2
|
import colors from 'yoctocolors-cjs';
|
|
3
3
|
const numberRegex = /\d+/;
|
|
4
4
|
function isSelectableChoice(choice) {
|
|
5
5
|
return choice != null && !Separator.isSeparator(choice);
|
|
6
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
|
+
}
|
|
7
30
|
export default createPrompt((config, done) => {
|
|
8
|
-
const
|
|
9
|
-
const [status, setStatus] = useState('
|
|
31
|
+
const choices = useMemo(() => normalizeChoices(config.choices), [config.choices]);
|
|
32
|
+
const [status, setStatus] = useState('idle');
|
|
10
33
|
const [value, setValue] = useState('');
|
|
11
34
|
const [errorMsg, setError] = useState();
|
|
12
35
|
const theme = makeTheme(config.theme);
|
|
13
|
-
const prefix = usePrefix({ theme });
|
|
36
|
+
const prefix = usePrefix({ status, theme });
|
|
14
37
|
useKeypress((key, rl) => {
|
|
15
38
|
if (isEnterKey(key)) {
|
|
16
39
|
let selectedChoice;
|
|
@@ -38,19 +61,17 @@ export default createPrompt((config, done) => {
|
|
|
38
61
|
setError(undefined);
|
|
39
62
|
}
|
|
40
63
|
});
|
|
41
|
-
const message = theme.style.message(config.message);
|
|
64
|
+
const message = theme.style.message(config.message, status);
|
|
42
65
|
if (status === 'done') {
|
|
43
66
|
return `${prefix} ${message} ${theme.style.answer(value)}`;
|
|
44
67
|
}
|
|
45
|
-
let index = 0;
|
|
46
68
|
const choicesStr = choices
|
|
47
69
|
.map((choice) => {
|
|
48
70
|
if (Separator.isSeparator(choice)) {
|
|
49
71
|
return ` ${choice.separator}`;
|
|
50
72
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (choice.key === value.toLowerCase() || String(index) === value) {
|
|
73
|
+
const line = ` ${choice.key}) ${choice.name}`;
|
|
74
|
+
if (choice.key === value.toLowerCase()) {
|
|
54
75
|
return theme.style.highlight(line);
|
|
55
76
|
}
|
|
56
77
|
return line;
|
|
@@ -8,8 +8,10 @@ type Choice<Value> = {
|
|
|
8
8
|
};
|
|
9
9
|
declare const _default: <Value>(config: {
|
|
10
10
|
message: string;
|
|
11
|
-
choices: readonly (Separator | Choice<Value>)[];
|
|
11
|
+
choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
|
|
12
12
|
theme?: PartialDeep<Theme> | undefined;
|
|
13
|
-
}, context?: import("@inquirer/type").Context) =>
|
|
13
|
+
}, context?: import("@inquirer/type").Context) => Promise<Value> & {
|
|
14
|
+
cancel: () => void;
|
|
15
|
+
};
|
|
14
16
|
export default _default;
|
|
15
17
|
export { Separator } from '@inquirer/core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/rawlist",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Inquirer rawlist prompt",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"typings": "./dist/cjs/types/index.d.ts",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/rawlist/README.md",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@inquirer/core": "^9.0
|
|
58
|
-
"@inquirer/type": "^1.5.
|
|
57
|
+
"@inquirer/core": "^9.2.0",
|
|
58
|
+
"@inquirer/type": "^1.5.4",
|
|
59
59
|
"yoctocolors-cjs": "^2.1.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@inquirer/testing": "^2.1.
|
|
62
|
+
"@inquirer/testing": "^2.1.33"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"sideEffects": false,
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "5fe03a4686d349d0d6cf281f86f12a4f7c992ad4"
|
|
90
90
|
}
|