@inquirer/expand 5.0.0 → 5.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/expand",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Inquirer checkbox prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -52,7 +52,10 @@
52
52
  "type": "module",
53
53
  "exports": {
54
54
  "./package.json": "./package.json",
55
- ".": "./src/index.ts"
55
+ ".": {
56
+ "types": "./dist/index.d.ts",
57
+ "default": "./dist/index.js"
58
+ }
56
59
  },
57
60
  "files": [
58
61
  "dist"
@@ -61,26 +64,18 @@
61
64
  "tsc": "tsc"
62
65
  },
63
66
  "dependencies": {
64
- "@inquirer/core": "^11.0.0",
65
- "@inquirer/type": "^4.0.0"
67
+ "@inquirer/core": "^11.0.2",
68
+ "@inquirer/type": "^4.0.2"
66
69
  },
67
70
  "devDependencies": {
68
- "@inquirer/testing": "^3.0.0",
69
- "@repo/tsconfig": "0.0.0",
71
+ "@inquirer/testing": "^3.0.2",
70
72
  "typescript": "^5.9.3"
71
73
  },
72
74
  "engines": {
73
75
  "node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
74
76
  },
75
77
  "publishConfig": {
76
- "access": "public",
77
- "exports": {
78
- "./package.json": "./package.json",
79
- ".": {
80
- "types": "./dist/index.d.ts",
81
- "default": "./dist/index.js"
82
- }
83
- }
78
+ "access": "public"
84
79
  },
85
80
  "peerDependencies": {
86
81
  "@types/node": ">=18"
@@ -90,5 +85,7 @@
90
85
  "optional": true
91
86
  }
92
87
  },
93
- "gitHead": "676685d33374a30340c1b9f0831c7eae2b2357dd"
88
+ "main": "./dist/index.js",
89
+ "types": "./dist/index.d.ts",
90
+ "gitHead": "9c724296daad3d740b09173f9aae035dc62cb106"
94
91
  }
@@ -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';
@@ -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; } });
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -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/index.js DELETED
@@ -1,108 +0,0 @@
1
- import { createPrompt, useMemo, useState, useKeypress, usePrefix, isEnterKey, makeTheme, Separator, } from '@inquirer/core';
2
- import colors from 'yoctocolors-cjs';
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(`"${colors.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 = `${colors.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';
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }