@inquirer/expand 2.2.0 → 2.3.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 CHANGED
@@ -94,6 +94,8 @@ const answer = await expand({
94
94
  | expanded | `boolean` | no | Expand the choices by default |
95
95
  | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
96
96
 
97
+ `Separator` objects can be used in the `choices` array to render non-selectable lines in the choice list. By default it'll render a line, but you can provide the text as argument (`new Separator('-- Dependencies --')`). This option is often used to add labels to groups within long list of options.
98
+
97
99
  ### `Choice` object
98
100
 
99
101
  The `Choice` object is typed as
package/dist/cjs/index.js CHANGED
@@ -3,10 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Separator = void 0;
6
7
  const core_1 = require("@inquirer/core");
7
8
  const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
8
9
  function normalizeChoices(choices) {
9
10
  return choices.map((choice) => {
11
+ if (core_1.Separator.isSeparator(choice)) {
12
+ return choice;
13
+ }
10
14
  const name = 'name' in choice ? choice.name : String(choice.value);
11
15
  const value = 'value' in choice ? choice.value : name;
12
16
  return {
@@ -38,7 +42,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
38
42
  setExpanded(true);
39
43
  }
40
44
  else {
41
- const selectedChoice = choices.find(({ key }) => key === answer);
45
+ const selectedChoice = choices.find((choice) => !core_1.Separator.isSeparator(choice) && choice.key === answer);
42
46
  if (selectedChoice) {
43
47
  setStatus('done');
44
48
  // Set the value as we might've selected the default one.
@@ -61,7 +65,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
61
65
  const message = theme.style.message(config.message);
62
66
  if (status === 'done') {
63
67
  // If the prompt is done, it's safe to assume there is a selected value.
64
- const selectedChoice = choices.find(({ key }) => key === value);
68
+ const selectedChoice = choices.find((choice) => !core_1.Separator.isSeparator(choice) && choice.key === value.toLowerCase());
65
69
  return `${prefix} ${message} ${theme.style.answer(selectedChoice.name)}`;
66
70
  }
67
71
  const allChoices = expanded ? choices : [...choices, helpChoice];
@@ -69,6 +73,8 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
69
73
  let longChoices = '';
70
74
  let shortChoices = allChoices
71
75
  .map((choice) => {
76
+ if (core_1.Separator.isSeparator(choice))
77
+ return '';
72
78
  if (choice.key === defaultKey) {
73
79
  return choice.key.toUpperCase();
74
80
  }
@@ -81,6 +87,9 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
81
87
  shortChoices = '';
82
88
  longChoices = allChoices
83
89
  .map((choice) => {
90
+ if (core_1.Separator.isSeparator(choice)) {
91
+ return ` ${choice.separator}`;
92
+ }
84
93
  const line = ` ${choice.key}) ${choice.name}`;
85
94
  if (choice.key === value.toLowerCase()) {
86
95
  return theme.style.highlight(line);
@@ -90,7 +99,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
90
99
  .join('\n');
91
100
  }
92
101
  let helpTip = '';
93
- const currentOption = allChoices.find(({ key }) => key === value.toLowerCase());
102
+ const currentOption = choices.find((choice) => !core_1.Separator.isSeparator(choice) && choice.key === value.toLowerCase());
94
103
  if (currentOption) {
95
104
  helpTip = `${yoctocolors_cjs_1.default.cyan('>>')} ${currentOption.name}`;
96
105
  }
@@ -103,3 +112,5 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
103
112
  [longChoices, helpTip, error].filter(Boolean).join('\n'),
104
113
  ];
105
114
  });
115
+ var core_2 = require("@inquirer/core");
116
+ Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_2.Separator; } });
@@ -1,4 +1,4 @@
1
- import { type Theme } from '@inquirer/core';
1
+ import { Separator, type Theme } from '@inquirer/core';
2
2
  import type { PartialDeep } from '@inquirer/type';
3
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
4
  type Choice<Value> = {
@@ -14,9 +14,10 @@ declare const _default: <Value>(config: {
14
14
  choices: readonly {
15
15
  key: Key;
16
16
  name: string;
17
- }[] | readonly Choice<Value>[];
17
+ }[] | readonly (Separator | Choice<Value>)[];
18
18
  default?: (Key | "h") | undefined;
19
19
  expanded?: boolean | undefined;
20
20
  theme?: PartialDeep<Theme> | undefined;
21
21
  }, context?: import("@inquirer/type").Context) => import("@inquirer/type").CancelablePromise<Value>;
22
22
  export default _default;
23
+ export { Separator } from '@inquirer/core';
@@ -1,7 +1,10 @@
1
- import { createPrompt, useMemo, useState, useKeypress, usePrefix, isEnterKey, makeTheme, } from '@inquirer/core';
1
+ import { createPrompt, useMemo, useState, useKeypress, usePrefix, isEnterKey, makeTheme, Separator, } from '@inquirer/core';
2
2
  import colors from 'yoctocolors-cjs';
3
3
  function normalizeChoices(choices) {
4
4
  return choices.map((choice) => {
5
+ if (Separator.isSeparator(choice)) {
6
+ return choice;
7
+ }
5
8
  const name = 'name' in choice ? choice.name : String(choice.value);
6
9
  const value = 'value' in choice ? choice.value : name;
7
10
  return {
@@ -32,7 +35,7 @@ export default createPrompt((config, done) => {
32
35
  setExpanded(true);
33
36
  }
34
37
  else {
35
- const selectedChoice = choices.find(({ key }) => key === answer);
38
+ const selectedChoice = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === answer);
36
39
  if (selectedChoice) {
37
40
  setStatus('done');
38
41
  // Set the value as we might've selected the default one.
@@ -55,7 +58,7 @@ export default createPrompt((config, done) => {
55
58
  const message = theme.style.message(config.message);
56
59
  if (status === 'done') {
57
60
  // If the prompt is done, it's safe to assume there is a selected value.
58
- const selectedChoice = choices.find(({ key }) => key === value);
61
+ const selectedChoice = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase());
59
62
  return `${prefix} ${message} ${theme.style.answer(selectedChoice.name)}`;
60
63
  }
61
64
  const allChoices = expanded ? choices : [...choices, helpChoice];
@@ -63,6 +66,8 @@ export default createPrompt((config, done) => {
63
66
  let longChoices = '';
64
67
  let shortChoices = allChoices
65
68
  .map((choice) => {
69
+ if (Separator.isSeparator(choice))
70
+ return '';
66
71
  if (choice.key === defaultKey) {
67
72
  return choice.key.toUpperCase();
68
73
  }
@@ -75,6 +80,9 @@ export default createPrompt((config, done) => {
75
80
  shortChoices = '';
76
81
  longChoices = allChoices
77
82
  .map((choice) => {
83
+ if (Separator.isSeparator(choice)) {
84
+ return ` ${choice.separator}`;
85
+ }
78
86
  const line = ` ${choice.key}) ${choice.name}`;
79
87
  if (choice.key === value.toLowerCase()) {
80
88
  return theme.style.highlight(line);
@@ -84,7 +92,7 @@ export default createPrompt((config, done) => {
84
92
  .join('\n');
85
93
  }
86
94
  let helpTip = '';
87
- const currentOption = allChoices.find(({ key }) => key === value.toLowerCase());
95
+ const currentOption = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase());
88
96
  if (currentOption) {
89
97
  helpTip = `${colors.cyan('>>')} ${currentOption.name}`;
90
98
  }
@@ -97,3 +105,4 @@ export default createPrompt((config, done) => {
97
105
  [longChoices, helpTip, error].filter(Boolean).join('\n'),
98
106
  ];
99
107
  });
108
+ export { Separator } from '@inquirer/core';
@@ -1,4 +1,4 @@
1
- import { type Theme } from '@inquirer/core';
1
+ import { Separator, type Theme } from '@inquirer/core';
2
2
  import type { PartialDeep } from '@inquirer/type';
3
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
4
  type Choice<Value> = {
@@ -14,9 +14,10 @@ declare const _default: <Value>(config: {
14
14
  choices: readonly {
15
15
  key: Key;
16
16
  name: string;
17
- }[] | readonly Choice<Value>[];
17
+ }[] | readonly (Separator | Choice<Value>)[];
18
18
  default?: (Key | "h") | undefined;
19
19
  expanded?: boolean | undefined;
20
20
  theme?: PartialDeep<Theme> | undefined;
21
21
  }, context?: import("@inquirer/type").Context) => import("@inquirer/type").CancelablePromise<Value>;
22
22
  export default _default;
23
+ export { Separator } from '@inquirer/core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/expand",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Inquirer checkbox prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -86,5 +86,5 @@
86
86
  }
87
87
  },
88
88
  "sideEffects": false,
89
- "gitHead": "0c039599ef88fe9eb804fe083ee386ec906a856f"
89
+ "gitHead": "4937ea3a74152b59bf4198dbaa803119ed4ef8e2"
90
90
  }