@inquirer/expand 0.0.27-alpha.0 → 0.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.
@@ -0,0 +1,89 @@
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
+ const core_1 = require("@inquirer/core");
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const helpChoice = {
9
+ key: 'h',
10
+ name: 'Help, list all options',
11
+ value: undefined,
12
+ };
13
+ exports.default = (0, core_1.createPrompt)((config, done) => {
14
+ const { choices, default: defaultKey = 'h', expanded: defaultExpandState = false, } = config;
15
+ const [status, setStatus] = (0, core_1.useState)('pending');
16
+ const [value, setValue] = (0, core_1.useState)('');
17
+ const [expanded, setExpanded] = (0, core_1.useState)(defaultExpandState);
18
+ const [errorMsg, setError] = (0, core_1.useState)(undefined);
19
+ const prefix = (0, core_1.usePrefix)();
20
+ (0, core_1.useKeypress)((key, rl) => {
21
+ if ((0, core_1.isEnterKey)(key)) {
22
+ const answer = (value || defaultKey).toLowerCase();
23
+ if (answer === 'h' && !expanded) {
24
+ setExpanded(true);
25
+ }
26
+ else {
27
+ const selectedChoice = choices.find(({ key }) => key === answer);
28
+ if (selectedChoice) {
29
+ const finalValue = selectedChoice.value || selectedChoice.name;
30
+ setValue(finalValue);
31
+ setStatus('done');
32
+ done(finalValue);
33
+ }
34
+ else if (value === '') {
35
+ setError('Please input a value');
36
+ }
37
+ else {
38
+ setError(`"${chalk_1.default.red(value)}" isn't an available option`);
39
+ }
40
+ }
41
+ }
42
+ else {
43
+ setValue(rl.line);
44
+ setError(undefined);
45
+ }
46
+ });
47
+ const message = chalk_1.default.bold(config.message);
48
+ if (status === 'done') {
49
+ return `${prefix} ${message} ${chalk_1.default.cyan(value)}`;
50
+ }
51
+ const allChoices = expanded ? choices : [...choices, helpChoice];
52
+ // Collapsed display style
53
+ let longChoices = '';
54
+ let shortChoices = allChoices
55
+ .map((choice) => {
56
+ if (choice.key === defaultKey) {
57
+ return choice.key.toUpperCase();
58
+ }
59
+ return choice.key;
60
+ })
61
+ .join('');
62
+ shortChoices = chalk_1.default.dim(` (${shortChoices})`);
63
+ // Expanded display style
64
+ if (expanded) {
65
+ shortChoices = '';
66
+ longChoices = allChoices
67
+ .map((choice) => {
68
+ const line = ` ${choice.key}) ${choice.name || choice.value}`;
69
+ if (choice.key === value.toLowerCase()) {
70
+ return chalk_1.default.cyan(line);
71
+ }
72
+ return line;
73
+ })
74
+ .join('\n');
75
+ }
76
+ let helpTip = '';
77
+ const currentOption = allChoices.find(({ key }) => key === value.toLowerCase());
78
+ if (currentOption) {
79
+ helpTip = `${chalk_1.default.cyan('>>')} ${currentOption.name || currentOption.value}`;
80
+ }
81
+ let error = '';
82
+ if (errorMsg) {
83
+ error = chalk_1.default.red(`> ${errorMsg}`);
84
+ }
85
+ return [
86
+ `${prefix} ${message}${shortChoices} ${value}`,
87
+ [longChoices, helpTip, error].filter(Boolean).join('\n'),
88
+ ];
89
+ });
@@ -1,5 +1,5 @@
1
1
  import { AsyncPromptConfig } from '@inquirer/core';
2
- declare type ExpandConfig = AsyncPromptConfig & {
2
+ type ExpandConfig = AsyncPromptConfig & {
3
3
  choices: {
4
4
  key: string;
5
5
  name: string;
@@ -8,5 +8,5 @@ declare type ExpandConfig = AsyncPromptConfig & {
8
8
  default?: string;
9
9
  expanded?: boolean;
10
10
  };
11
- declare const _default: import("@inquirer/core").Prompt<string, ExpandConfig>;
11
+ declare const _default: import("@inquirer/type").Prompt<string, ExpandConfig>;
12
12
  export default _default;
@@ -0,0 +1,12 @@
1
+ import { AsyncPromptConfig } from '@inquirer/core';
2
+ type ExpandConfig = AsyncPromptConfig & {
3
+ choices: {
4
+ key: string;
5
+ name: string;
6
+ value?: string;
7
+ }[];
8
+ default?: string;
9
+ expanded?: boolean;
10
+ };
11
+ declare const _default: import("@inquirer/type").Prompt<string, ExpandConfig>;
12
+ export default _default;
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "@inquirer/expand",
3
- "type": "module",
4
- "version": "0.0.27-alpha.0",
3
+ "version": "0.1.0",
5
4
  "description": "Inquirer checkbox prompt",
6
- "main": "dist/index.js",
7
- "typings": "dist/index.d.ts",
5
+ "main": "./dist/cjs/index.js",
6
+ "typings": "./dist/cjs/types/index.d.mts",
8
7
  "files": [
9
- "dist/"
8
+ "dist/**/*"
10
9
  ],
11
- "repository": "SBoudrias/Inquirer.js",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/SBoudrias/Inquirer.js.git"
13
+ },
12
14
  "keywords": [
13
15
  "answer",
14
16
  "answers",
15
17
  "ask",
16
18
  "base",
17
19
  "cli",
18
- "cli",
19
20
  "command",
20
21
  "command-line",
21
22
  "confirm",
@@ -49,19 +50,39 @@
49
50
  "yo",
50
51
  "zsh"
51
52
  ],
52
- "author": "Simon Boudrias",
53
+ "author": "Simon Boudrias <admin@simonboudrias.com>",
53
54
  "license": "MIT",
54
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/expand/README.md",
55
56
  "dependencies": {
56
- "@inquirer/core": "^0.0.26-alpha.0",
57
- "chalk": "^5.0.1",
57
+ "@inquirer/core": "^1.0.0",
58
+ "@inquirer/type": "^0.1.0",
59
+ "chalk": "^5.2.0",
58
60
  "figures": "^5.0.0"
59
61
  },
60
62
  "scripts": {
61
- "tsc": "tsc"
63
+ "tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
64
+ "clean": "rm -rf dist",
65
+ "tsc:esm": "tsc -p ./tsconfig.esm.json",
66
+ "tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
67
+ "fix-ext": "ts-node ../../tools/rename-ext.ts"
62
68
  },
63
69
  "publishConfig": {
64
70
  "access": "public"
65
71
  },
66
- "gitHead": "0e3ef8e31fc34b5fa5308be95af77ba9f5ede8fa"
72
+ "engines": {
73
+ "node": ">=14.18.0"
74
+ },
75
+ "exports": {
76
+ ".": {
77
+ "import": {
78
+ "types": "./dist/esm/types/index.d.mts",
79
+ "default": "./dist/esm/index.mjs"
80
+ },
81
+ "require": {
82
+ "types": "./dist/cjs/types/index.d.mts",
83
+ "default": "./dist/cjs/index.js"
84
+ }
85
+ }
86
+ },
87
+ "gitHead": "bd58130dd8204945a31b062070b829003b8385fc"
67
88
  }
File without changes