@inquirer/input 4.1.11 → 4.2.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 +2 -1
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.js +9 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +10 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -73,7 +73,8 @@ const answer = await input({ message: 'Enter your name' });
|
|
|
73
73
|
| Property | Type | Required | Description |
|
|
74
74
|
| ----------- | ----------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
75
75
|
| message | `string` | yes | The question to ask |
|
|
76
|
-
| default | `string` | no | Default value if no answer is provided
|
|
76
|
+
| default | `string` | no | Default value if no answer is provided; see the prefill option below for governing it's behaviour. |
|
|
77
|
+
| prefill | `'tab' \| 'editable'` | no | Defaults to `'tab'`. If set to `'tab'`, pressing `backspace` will clear the default and pressing `tab` will inline the value for edits; If set to `'editable'`, the default value will already be inlined to edit. |
|
|
77
78
|
| required | `boolean` | no | Defaults to `false`. If set to true, `undefined` (empty) will not be accepted for this. |
|
|
78
79
|
| transformer | `(string, { isFinal: boolean }) => string` | no | Transform/Format the raw value entered by the user. Once the prompt is completed, `isFinal` will be `true`. This function is purely visual, modify the answer in your code if needed. |
|
|
79
80
|
| validate | `string => boolean \| string \| Promise<boolean \| string>` | no | On submit, validate the filtered answered content. When returning a string, it'll be used as the error message displayed to the user. Note: returning a rejected promise, we'll assume a code error happened and crash. |
|
package/dist/commonjs/index.d.ts
CHANGED
package/dist/commonjs/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const inputTheme = {
|
|
|
5
5
|
validationFailureMode: 'keep',
|
|
6
6
|
};
|
|
7
7
|
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
8
|
-
const { required, validate = () => true } = config;
|
|
8
|
+
const { required, validate = () => true, prefill = 'tab' } = config;
|
|
9
9
|
const theme = (0, core_1.makeTheme)(inputTheme, config.theme);
|
|
10
10
|
const [status, setStatus] = (0, core_1.useState)('idle');
|
|
11
11
|
const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
|
|
@@ -53,6 +53,14 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
53
53
|
setError(undefined);
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
|
+
// If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer
|
|
57
|
+
// They can edit the value immediately instead of needing to press 'tab'
|
|
58
|
+
(0, core_1.useEffect)((rl) => {
|
|
59
|
+
if (prefill === 'editable' && defaultValue) {
|
|
60
|
+
rl.write(defaultValue);
|
|
61
|
+
setValue(defaultValue);
|
|
62
|
+
}
|
|
63
|
+
}, []);
|
|
56
64
|
const message = theme.style.message(config.message, status);
|
|
57
65
|
let formattedValue = value;
|
|
58
66
|
if (typeof config.transformer === 'function') {
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
|
|
1
|
+
import { createPrompt, useState, useKeypress, useEffect, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
|
|
2
2
|
const inputTheme = {
|
|
3
3
|
validationFailureMode: 'keep',
|
|
4
4
|
};
|
|
5
5
|
export default createPrompt((config, done) => {
|
|
6
|
-
const { required, validate = () => true } = config;
|
|
6
|
+
const { required, validate = () => true, prefill = 'tab' } = config;
|
|
7
7
|
const theme = makeTheme(inputTheme, config.theme);
|
|
8
8
|
const [status, setStatus] = useState('idle');
|
|
9
9
|
const [defaultValue = '', setDefaultValue] = useState(config.default);
|
|
@@ -51,6 +51,14 @@ export default createPrompt((config, done) => {
|
|
|
51
51
|
setError(undefined);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
// If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer
|
|
55
|
+
// They can edit the value immediately instead of needing to press 'tab'
|
|
56
|
+
useEffect((rl) => {
|
|
57
|
+
if (prefill === 'editable' && defaultValue) {
|
|
58
|
+
rl.write(defaultValue);
|
|
59
|
+
setValue(defaultValue);
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
54
62
|
const message = theme.style.message(config.message, status);
|
|
55
63
|
let formattedValue = value;
|
|
56
64
|
if (typeof config.transformer === 'function') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.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.14",
|
|
78
78
|
"@inquirer/type": "^3.0.7"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@arethetypeswrong/cli": "^0.18.1",
|
|
82
|
-
"@inquirer/testing": "^2.1.
|
|
82
|
+
"@inquirer/testing": "^2.1.48",
|
|
83
83
|
"tshy": "^3.0.2"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
@@ -105,5 +105,5 @@
|
|
|
105
105
|
"optional": true
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "43b7bb94390c1e2b6473af1b790ff2fd1c8007c8"
|
|
109
109
|
}
|