@inquirer/editor
Advanced tools
Comparing version 4.1.0 to 4.2.0
import { IFileOptions } from 'external-editor'; | ||
import { type Theme } from '@inquirer/core'; | ||
import type { PartialDeep } from '@inquirer/type'; | ||
type EditorTheme = { | ||
validationFailureMode: 'keep' | 'clear'; | ||
}; | ||
type EditorConfig = { | ||
@@ -11,5 +14,5 @@ message: string; | ||
file?: IFileOptions; | ||
theme?: PartialDeep<Theme>; | ||
theme?: PartialDeep<Theme<EditorTheme>>; | ||
}; | ||
declare const _default: import("@inquirer/type").Prompt<string, EditorConfig>; | ||
export default _default; |
@@ -6,7 +6,10 @@ "use strict"; | ||
const core_1 = require("@inquirer/core"); | ||
const editorTheme = { | ||
validationFailureMode: 'keep', | ||
}; | ||
exports.default = (0, core_1.createPrompt)((config, done) => { | ||
const { waitForUseInput = true, file: { postfix = config.postfix ?? '.txt', ...fileProps } = {}, validate = () => true, } = config; | ||
const theme = (0, core_1.makeTheme)(config.theme); | ||
const theme = (0, core_1.makeTheme)(editorTheme, config.theme); | ||
const [status, setStatus] = (0, core_1.useState)('idle'); | ||
const [value, setValue] = (0, core_1.useState)(config.default || ''); | ||
const [value = '', setValue] = (0, core_1.useState)(config.default); | ||
const [errorMsg, setError] = (0, core_1.useState)(); | ||
@@ -31,3 +34,8 @@ const prefix = (0, core_1.usePrefix)({ status, theme }); | ||
else { | ||
setValue(answer); | ||
if (theme.validationFailureMode === 'clear') { | ||
setValue(config.default); | ||
} | ||
else { | ||
setValue(answer); | ||
} | ||
setError(isValid || 'You must provide a valid value'); | ||
@@ -34,0 +42,0 @@ setStatus('idle'); |
import { IFileOptions } from 'external-editor'; | ||
import { type Theme } from '@inquirer/core'; | ||
import type { PartialDeep } from '@inquirer/type'; | ||
type EditorTheme = { | ||
validationFailureMode: 'keep' | 'clear'; | ||
}; | ||
type EditorConfig = { | ||
@@ -11,5 +14,5 @@ message: string; | ||
file?: IFileOptions; | ||
theme?: PartialDeep<Theme>; | ||
theme?: PartialDeep<Theme<EditorTheme>>; | ||
}; | ||
declare const _default: import("@inquirer/type").Prompt<string, EditorConfig>; | ||
export default _default; |
import { AsyncResource } from 'node:async_hooks'; | ||
import { editAsync } from 'external-editor'; | ||
import { createPrompt, useEffect, useState, useKeypress, usePrefix, isEnterKey, makeTheme, } from '@inquirer/core'; | ||
const editorTheme = { | ||
validationFailureMode: 'keep', | ||
}; | ||
export default createPrompt((config, done) => { | ||
const { waitForUseInput = true, file: { postfix = config.postfix ?? '.txt', ...fileProps } = {}, validate = () => true, } = config; | ||
const theme = makeTheme(config.theme); | ||
const theme = makeTheme(editorTheme, config.theme); | ||
const [status, setStatus] = useState('idle'); | ||
const [value, setValue] = useState(config.default || ''); | ||
const [value = '', setValue] = useState(config.default); | ||
const [errorMsg, setError] = useState(); | ||
@@ -28,3 +31,8 @@ const prefix = usePrefix({ status, theme }); | ||
else { | ||
setValue(answer); | ||
if (theme.validationFailureMode === 'clear') { | ||
setValue(config.default); | ||
} | ||
else { | ||
setValue(answer); | ||
} | ||
setError(isValid || 'You must provide a valid value'); | ||
@@ -31,0 +39,0 @@ setStatus('idle'); |
{ | ||
"name": "@inquirer/editor", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Inquirer multiline editor prompt", | ||
@@ -77,3 +77,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@inquirer/core": "^10.1.0", | ||
"@inquirer/core": "^10.1.1", | ||
"@inquirer/type": "^3.0.1", | ||
@@ -84,3 +84,3 @@ "external-editor": "^3.1.0" | ||
"@arethetypeswrong/cli": "^0.17.0", | ||
"@inquirer/testing": "^2.1.37", | ||
"@inquirer/testing": "^2.1.38", | ||
"@repo/tsconfig": "workspace:*", | ||
@@ -107,3 +107,3 @@ "tshy": "^3.0.2" | ||
}, | ||
"gitHead": "84e49bdb552e1cb4f035d644190913f367a66e74" | ||
"gitHead": "5713287885155c0081fca4190c17c18c598d9602" | ||
} |
@@ -90,5 +90,8 @@ # `@inquirer/editor` | ||
}; | ||
validationFailureMode: 'keep' | 'clear'; | ||
}; | ||
``` | ||
`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 the default value or empty string. | ||
# License | ||
@@ -95,0 +98,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15042
186
100
Updated@inquirer/core@^10.1.1