@inquirer/input 4.0.2 → 4.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 +3 -0
- package/dist/commonjs/index.d.ts +4 -1
- package/dist/commonjs/index.js +12 -4
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +12 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -86,9 +86,12 @@ type Theme = {
|
|
|
86
86
|
error: (text: string) => string;
|
|
87
87
|
defaultAnswer: (text: string) => string;
|
|
88
88
|
};
|
|
89
|
+
validationFailureMode: 'keep' | 'clear';
|
|
89
90
|
};
|
|
90
91
|
```
|
|
91
92
|
|
|
93
|
+
`validationFailureMode` defines the behavior of the prompt when the value submitted is invalid. By default, we'll keep the value allowing the user to edit it. When the theme option is set to `clear`, we'll remove and reset to an empty string.
|
|
94
|
+
|
|
92
95
|
# License
|
|
93
96
|
|
|
94
97
|
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type Theme } from '@inquirer/core';
|
|
2
2
|
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
+
type InputTheme = {
|
|
4
|
+
validationFailureMode: 'keep' | 'clear';
|
|
5
|
+
};
|
|
3
6
|
type InputConfig = {
|
|
4
7
|
message: string;
|
|
5
8
|
default?: string;
|
|
@@ -8,7 +11,7 @@ type InputConfig = {
|
|
|
8
11
|
isFinal: boolean;
|
|
9
12
|
}) => string;
|
|
10
13
|
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
11
|
-
theme?: PartialDeep<Theme
|
|
14
|
+
theme?: PartialDeep<Theme<InputTheme>>;
|
|
12
15
|
};
|
|
13
16
|
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
14
17
|
export default _default;
|
package/dist/commonjs/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const core_1 = require("@inquirer/core");
|
|
4
|
+
const inputTheme = {
|
|
5
|
+
validationFailureMode: 'keep',
|
|
6
|
+
};
|
|
4
7
|
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
5
8
|
const { required, validate = () => true } = config;
|
|
6
|
-
const theme = (0, core_1.makeTheme)(config.theme);
|
|
9
|
+
const theme = (0, core_1.makeTheme)(inputTheme, config.theme);
|
|
7
10
|
const [status, setStatus] = (0, core_1.useState)('idle');
|
|
8
11
|
const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
|
|
9
12
|
const [errorMsg, setError] = (0, core_1.useState)();
|
|
@@ -24,9 +27,14 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
24
27
|
done(answer);
|
|
25
28
|
}
|
|
26
29
|
else {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
if (theme.validationFailureMode === 'clear') {
|
|
31
|
+
setValue('');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Reset the readline line value to the previous value. On line event, the value
|
|
35
|
+
// get cleared, forcing the user to re-enter the value instead of fixing it.
|
|
36
|
+
rl.write(value);
|
|
37
|
+
}
|
|
30
38
|
setError(isValid || 'You must provide a valid value');
|
|
31
39
|
setStatus('idle');
|
|
32
40
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type Theme } from '@inquirer/core';
|
|
2
2
|
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
+
type InputTheme = {
|
|
4
|
+
validationFailureMode: 'keep' | 'clear';
|
|
5
|
+
};
|
|
3
6
|
type InputConfig = {
|
|
4
7
|
message: string;
|
|
5
8
|
default?: string;
|
|
@@ -8,7 +11,7 @@ type InputConfig = {
|
|
|
8
11
|
isFinal: boolean;
|
|
9
12
|
}) => string;
|
|
10
13
|
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
11
|
-
theme?: PartialDeep<Theme
|
|
14
|
+
theme?: PartialDeep<Theme<InputTheme>>;
|
|
12
15
|
};
|
|
13
16
|
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
14
17
|
export default _default;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
|
|
2
|
+
const inputTheme = {
|
|
3
|
+
validationFailureMode: 'keep',
|
|
4
|
+
};
|
|
2
5
|
export default createPrompt((config, done) => {
|
|
3
6
|
const { required, validate = () => true } = config;
|
|
4
|
-
const theme = makeTheme(config.theme);
|
|
7
|
+
const theme = makeTheme(inputTheme, config.theme);
|
|
5
8
|
const [status, setStatus] = useState('idle');
|
|
6
9
|
const [defaultValue = '', setDefaultValue] = useState(config.default);
|
|
7
10
|
const [errorMsg, setError] = useState();
|
|
@@ -22,9 +25,14 @@ export default createPrompt((config, done) => {
|
|
|
22
25
|
done(answer);
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
if (theme.validationFailureMode === 'clear') {
|
|
29
|
+
setValue('');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Reset the readline line value to the previous value. On line event, the value
|
|
33
|
+
// get cleared, forcing the user to re-enter the value instead of fixing it.
|
|
34
|
+
rl.write(value);
|
|
35
|
+
}
|
|
28
36
|
setError(isValid || 'You must provide a valid value');
|
|
29
37
|
setStatus('idle');
|
|
30
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Inquirer input text prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"tsc": "tshy"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@inquirer/core": "^10.1.
|
|
77
|
+
"@inquirer/core": "^10.1.1",
|
|
78
78
|
"@inquirer/type": "^3.0.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@arethetypeswrong/cli": "^0.17.0",
|
|
82
|
-
"@inquirer/testing": "^2.1.
|
|
82
|
+
"@inquirer/testing": "^2.1.38",
|
|
83
83
|
"@repo/tsconfig": "workspace:*",
|
|
84
84
|
"tshy": "^3.0.2"
|
|
85
85
|
},
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"@types/node": ">=18"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "5713287885155c0081fca4190c17c18c598d9602"
|
|
105
105
|
}
|