@inquirer/expand 4.0.23 → 5.0.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.
|
@@ -18,8 +18,6 @@ declare const _default: <Value>(config: {
|
|
|
18
18
|
default?: (Key | "h") | undefined;
|
|
19
19
|
expanded?: boolean | undefined;
|
|
20
20
|
theme?: PartialDeep<Theme> | undefined;
|
|
21
|
-
}, context?: import("@inquirer/type").Context) => Promise<Value
|
|
22
|
-
cancel: () => void;
|
|
23
|
-
};
|
|
21
|
+
}, context?: import("@inquirer/type").Context) => Promise<Value>;
|
|
24
22
|
export default _default;
|
|
25
23
|
export { Separator } from '@inquirer/core';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPrompt, useMemo, useState, useKeypress, usePrefix, isEnterKey, makeTheme, Separator, } from '@inquirer/core';
|
|
2
|
-
import
|
|
2
|
+
import { styleText } from 'node:util';
|
|
3
3
|
function normalizeChoices(choices) {
|
|
4
4
|
return choices.map((choice) => {
|
|
5
5
|
if (Separator.isSeparator(choice)) {
|
|
@@ -46,7 +46,7 @@ export default createPrompt((config, done) => {
|
|
|
46
46
|
setError('Please input a value');
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
setError(`"${
|
|
49
|
+
setError(`"${styleText('red', value)}" isn't an available option`);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -94,7 +94,7 @@ export default createPrompt((config, done) => {
|
|
|
94
94
|
let helpTip = '';
|
|
95
95
|
const currentOption = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase());
|
|
96
96
|
if (currentOption) {
|
|
97
|
-
helpTip = `${
|
|
97
|
+
helpTip = `${styleText('cyan', '>>')} ${currentOption.name}`;
|
|
98
98
|
}
|
|
99
99
|
let error = '';
|
|
100
100
|
if (errorMsg) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/expand",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Inquirer checkbox prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -53,52 +53,30 @@
|
|
|
53
53
|
"exports": {
|
|
54
54
|
"./package.json": "./package.json",
|
|
55
55
|
".": {
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"default": "./dist/esm/index.js"
|
|
59
|
-
},
|
|
60
|
-
"require": {
|
|
61
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
62
|
-
"default": "./dist/commonjs/index.js"
|
|
63
|
-
}
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"default": "./dist/index.js"
|
|
64
58
|
}
|
|
65
59
|
},
|
|
66
|
-
"main": "./dist/commonjs/index.js",
|
|
67
|
-
"module": "./dist/esm/index.js",
|
|
68
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
69
60
|
"files": [
|
|
70
61
|
"dist"
|
|
71
62
|
],
|
|
72
63
|
"scripts": {
|
|
73
|
-
"
|
|
74
|
-
"tsc": "tshy"
|
|
64
|
+
"tsc": "tsc"
|
|
75
65
|
},
|
|
76
66
|
"dependencies": {
|
|
77
|
-
"@inquirer/core": "^
|
|
78
|
-
"@inquirer/type": "^
|
|
79
|
-
"yoctocolors-cjs": "^2.1.3"
|
|
67
|
+
"@inquirer/core": "^11.0.1",
|
|
68
|
+
"@inquirer/type": "^4.0.1"
|
|
80
69
|
},
|
|
81
70
|
"devDependencies": {
|
|
82
|
-
"@
|
|
83
|
-
"
|
|
84
|
-
"@repo/tsconfig": "0.0.0",
|
|
85
|
-
"tshy": "^3.0.3"
|
|
71
|
+
"@inquirer/testing": "^3.0.1",
|
|
72
|
+
"typescript": "^5.9.3"
|
|
86
73
|
},
|
|
87
74
|
"engines": {
|
|
88
|
-
"node": ">=
|
|
75
|
+
"node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
|
|
89
76
|
},
|
|
90
77
|
"publishConfig": {
|
|
91
78
|
"access": "public"
|
|
92
79
|
},
|
|
93
|
-
"tshy": {
|
|
94
|
-
"exclude": [
|
|
95
|
-
"src/**/*.test.ts"
|
|
96
|
-
],
|
|
97
|
-
"exports": {
|
|
98
|
-
"./package.json": "./package.json",
|
|
99
|
-
".": "./src/index.ts"
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
80
|
"peerDependencies": {
|
|
103
81
|
"@types/node": ">=18"
|
|
104
82
|
},
|
|
@@ -107,5 +85,5 @@
|
|
|
107
85
|
"optional": true
|
|
108
86
|
}
|
|
109
87
|
},
|
|
110
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "cce79ce3b9bbdfb4dbb798078cf3b94b9adc7d1b"
|
|
111
89
|
}
|
package/dist/commonjs/index.js
DELETED
|
@@ -1,115 +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
|
-
function normalizeChoices(choices) {
|
|
10
|
-
return choices.map((choice) => {
|
|
11
|
-
if (core_1.Separator.isSeparator(choice)) {
|
|
12
|
-
return choice;
|
|
13
|
-
}
|
|
14
|
-
const name = 'name' in choice ? choice.name : String(choice.value);
|
|
15
|
-
const value = 'value' in choice ? choice.value : name;
|
|
16
|
-
return {
|
|
17
|
-
value: value,
|
|
18
|
-
name,
|
|
19
|
-
key: choice.key.toLowerCase(),
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
const helpChoice = {
|
|
24
|
-
key: 'h',
|
|
25
|
-
name: 'Help, list all options',
|
|
26
|
-
value: undefined,
|
|
27
|
-
};
|
|
28
|
-
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
29
|
-
const { default: defaultKey = 'h' } = config;
|
|
30
|
-
const choices = (0, core_1.useMemo)(() => normalizeChoices(config.choices), [config.choices]);
|
|
31
|
-
const [status, setStatus] = (0, core_1.useState)('idle');
|
|
32
|
-
const [value, setValue] = (0, core_1.useState)('');
|
|
33
|
-
const [expanded, setExpanded] = (0, core_1.useState)(config.expanded ?? false);
|
|
34
|
-
const [errorMsg, setError] = (0, core_1.useState)();
|
|
35
|
-
const theme = (0, core_1.makeTheme)(config.theme);
|
|
36
|
-
const prefix = (0, core_1.usePrefix)({ theme, status });
|
|
37
|
-
(0, core_1.useKeypress)((event, rl) => {
|
|
38
|
-
if ((0, core_1.isEnterKey)(event)) {
|
|
39
|
-
const answer = (value || defaultKey).toLowerCase();
|
|
40
|
-
if (answer === 'h' && !expanded) {
|
|
41
|
-
setExpanded(true);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const selectedChoice = choices.find((choice) => !core_1.Separator.isSeparator(choice) && choice.key === answer);
|
|
45
|
-
if (selectedChoice) {
|
|
46
|
-
setStatus('done');
|
|
47
|
-
// Set the value as we might've selected the default one.
|
|
48
|
-
setValue(answer);
|
|
49
|
-
done(selectedChoice.value);
|
|
50
|
-
}
|
|
51
|
-
else if (value === '') {
|
|
52
|
-
setError('Please input a value');
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
setError(`"${yoctocolors_cjs_1.default.red(value)}" isn't an available option`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
setValue(rl.line);
|
|
61
|
-
setError(undefined);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const message = theme.style.message(config.message, status);
|
|
65
|
-
if (status === 'done') {
|
|
66
|
-
// If the prompt is done, it's safe to assume there is a selected value.
|
|
67
|
-
const selectedChoice = choices.find((choice) => !core_1.Separator.isSeparator(choice) && choice.key === value.toLowerCase());
|
|
68
|
-
return `${prefix} ${message} ${theme.style.answer(selectedChoice.name)}`;
|
|
69
|
-
}
|
|
70
|
-
const allChoices = expanded ? choices : [...choices, helpChoice];
|
|
71
|
-
// Collapsed display style
|
|
72
|
-
let longChoices = '';
|
|
73
|
-
let shortChoices = allChoices
|
|
74
|
-
.map((choice) => {
|
|
75
|
-
if (core_1.Separator.isSeparator(choice))
|
|
76
|
-
return '';
|
|
77
|
-
if (choice.key === defaultKey) {
|
|
78
|
-
return choice.key.toUpperCase();
|
|
79
|
-
}
|
|
80
|
-
return choice.key;
|
|
81
|
-
})
|
|
82
|
-
.join('');
|
|
83
|
-
shortChoices = ` ${theme.style.defaultAnswer(shortChoices)}`;
|
|
84
|
-
// Expanded display style
|
|
85
|
-
if (expanded) {
|
|
86
|
-
shortChoices = '';
|
|
87
|
-
longChoices = allChoices
|
|
88
|
-
.map((choice) => {
|
|
89
|
-
if (core_1.Separator.isSeparator(choice)) {
|
|
90
|
-
return ` ${choice.separator}`;
|
|
91
|
-
}
|
|
92
|
-
const line = ` ${choice.key}) ${choice.name}`;
|
|
93
|
-
if (choice.key === value.toLowerCase()) {
|
|
94
|
-
return theme.style.highlight(line);
|
|
95
|
-
}
|
|
96
|
-
return line;
|
|
97
|
-
})
|
|
98
|
-
.join('\n');
|
|
99
|
-
}
|
|
100
|
-
let helpTip = '';
|
|
101
|
-
const currentOption = choices.find((choice) => !core_1.Separator.isSeparator(choice) && choice.key === value.toLowerCase());
|
|
102
|
-
if (currentOption) {
|
|
103
|
-
helpTip = `${yoctocolors_cjs_1.default.cyan('>>')} ${currentOption.name}`;
|
|
104
|
-
}
|
|
105
|
-
let error = '';
|
|
106
|
-
if (errorMsg) {
|
|
107
|
-
error = theme.style.error(errorMsg);
|
|
108
|
-
}
|
|
109
|
-
return [
|
|
110
|
-
`${prefix} ${message}${shortChoices} ${value}`,
|
|
111
|
-
[longChoices, helpTip, error].filter(Boolean).join('\n'),
|
|
112
|
-
];
|
|
113
|
-
});
|
|
114
|
-
var core_2 = require("@inquirer/core");
|
|
115
|
-
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_2.Separator; } });
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Separator, type Theme } from '@inquirer/core';
|
|
2
|
-
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
-
type Key = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
4
|
-
type Choice<Value> = {
|
|
5
|
-
key: Key;
|
|
6
|
-
value: Value;
|
|
7
|
-
} | {
|
|
8
|
-
key: Key;
|
|
9
|
-
name: string;
|
|
10
|
-
value: Value;
|
|
11
|
-
};
|
|
12
|
-
declare const _default: <Value>(config: {
|
|
13
|
-
message: string;
|
|
14
|
-
choices: readonly {
|
|
15
|
-
key: Key;
|
|
16
|
-
name: string;
|
|
17
|
-
}[] | readonly (Separator | Choice<Value>)[];
|
|
18
|
-
default?: (Key | "h") | undefined;
|
|
19
|
-
expanded?: boolean | undefined;
|
|
20
|
-
theme?: PartialDeep<Theme> | undefined;
|
|
21
|
-
}, context?: import("@inquirer/type").Context) => Promise<Value> & {
|
|
22
|
-
cancel: () => void;
|
|
23
|
-
};
|
|
24
|
-
export default _default;
|
|
25
|
-
export { Separator } from '@inquirer/core';
|
package/dist/esm/package.json
DELETED