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