@inquirer/rawlist 4.1.11 → 5.0.1

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.
@@ -11,8 +11,6 @@ declare const _default: <Value>(config: {
11
11
  choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
12
12
  loop?: boolean | undefined;
13
13
  theme?: PartialDeep<Theme> | undefined;
14
- }, context?: import("@inquirer/type").Context) => Promise<Value> & {
15
- cancel: () => void;
16
- };
14
+ }, context?: import("@inquirer/type").Context) => Promise<Value>;
17
15
  export default _default;
18
16
  export { Separator } from '@inquirer/core';
@@ -1,5 +1,5 @@
1
1
  import { createPrompt, useMemo, useState, useKeypress, usePrefix, isDownKey, isEnterKey, isUpKey, Separator, makeTheme, ValidationError, } from '@inquirer/core';
2
- import colors from 'yoctocolors-cjs';
2
+ import { styleText } from 'node:util';
3
3
  const numberRegex = /\d+/;
4
4
  function isSelectableChoice(choice) {
5
5
  return choice != null && !Separator.isSeparator(choice);
@@ -69,7 +69,7 @@ export default createPrompt((config, done) => {
69
69
  setError('Please input a value');
70
70
  }
71
71
  else {
72
- setError(`"${colors.red(value)}" isn't an available option`);
72
+ setError(`"${styleText('red', value)}" isn't an available option`);
73
73
  }
74
74
  }
75
75
  else if (isUpKey(key) || isDownKey(key)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/rawlist",
3
- "version": "4.1.11",
3
+ "version": "5.0.1",
4
4
  "description": "Inquirer rawlist prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -53,52 +53,30 @@
53
53
  "exports": {
54
54
  "./package.json": "./package.json",
55
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
- }
56
+ "types": "./dist/index.d.ts",
57
+ "default": "./dist/index.js"
64
58
  }
65
59
  },
66
- "main": "./dist/commonjs/index.js",
67
- "module": "./dist/esm/index.js",
68
- "types": "./dist/commonjs/index.d.ts",
69
60
  "files": [
70
61
  "dist"
71
62
  ],
72
63
  "scripts": {
73
- "attw": "attw --pack",
74
- "tsc": "tshy"
64
+ "tsc": "tsc"
75
65
  },
76
66
  "dependencies": {
77
- "@inquirer/core": "^10.3.2",
78
- "@inquirer/type": "^3.0.10",
79
- "yoctocolors-cjs": "^2.1.3"
67
+ "@inquirer/core": "^11.0.1",
68
+ "@inquirer/type": "^4.0.1"
80
69
  },
81
70
  "devDependencies": {
82
- "@arethetypeswrong/cli": "^0.18.2",
83
- "@inquirer/testing": "^2.1.53",
84
- "@repo/tsconfig": "0.0.0",
85
- "tshy": "^3.0.3"
71
+ "@inquirer/testing": "^3.0.1",
72
+ "typescript": "^5.9.3"
86
73
  },
87
74
  "engines": {
88
- "node": ">=18"
75
+ "node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
89
76
  },
90
77
  "publishConfig": {
91
78
  "access": "public"
92
79
  },
93
- "tshy": {
94
- "exclude": [
95
- "src/**/*.test.ts"
96
- ],
97
- "exports": {
98
- "./package.json": "./package.json",
99
- ".": "./src/index.ts"
100
- }
101
- },
102
80
  "peerDependencies": {
103
81
  "@types/node": ">=18"
104
82
  },
@@ -107,5 +85,5 @@
107
85
  "optional": true
108
86
  }
109
87
  },
110
- "gitHead": "4731a373881368e2f701c41adc67bc83244bf89f"
88
+ "gitHead": "cce79ce3b9bbdfb4dbb798078cf3b94b9adc7d1b"
111
89
  }
@@ -1,132 +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
- const numberRegex = /\d+/;
10
- function isSelectableChoice(choice) {
11
- return choice != null && !core_1.Separator.isSeparator(choice);
12
- }
13
- function normalizeChoices(choices) {
14
- let index = 0;
15
- return choices.map((choice) => {
16
- if (core_1.Separator.isSeparator(choice))
17
- return choice;
18
- index += 1;
19
- if (typeof choice === 'string') {
20
- return {
21
- value: choice,
22
- name: choice,
23
- short: choice,
24
- key: String(index),
25
- };
26
- }
27
- const name = choice.name ?? String(choice.value);
28
- return {
29
- value: choice.value,
30
- name,
31
- short: choice.short ?? name,
32
- key: choice.key ?? String(index),
33
- };
34
- });
35
- }
36
- function getSelectedChoice(input, choices) {
37
- let selectedChoice;
38
- const selectableChoices = choices.filter(isSelectableChoice);
39
- // First, try to match by custom key (exact match)
40
- selectedChoice = selectableChoices.find((choice) => choice.key === input);
41
- // If no custom key match and input is numeric, try 1-based index
42
- if (!selectedChoice && numberRegex.test(input)) {
43
- const answer = Number.parseInt(input, 10) - 1;
44
- selectedChoice = selectableChoices[answer];
45
- }
46
- return selectedChoice
47
- ? [selectedChoice, choices.indexOf(selectedChoice)]
48
- : [undefined, undefined];
49
- }
50
- exports.default = (0, core_1.createPrompt)((config, done) => {
51
- const { loop = true } = config;
52
- const choices = (0, core_1.useMemo)(() => normalizeChoices(config.choices), [config.choices]);
53
- const [status, setStatus] = (0, core_1.useState)('idle');
54
- const [value, setValue] = (0, core_1.useState)('');
55
- const [errorMsg, setError] = (0, core_1.useState)();
56
- const theme = (0, core_1.makeTheme)(config.theme);
57
- const prefix = (0, core_1.usePrefix)({ status, theme });
58
- const bounds = (0, core_1.useMemo)(() => {
59
- const first = choices.findIndex(isSelectableChoice);
60
- const last = choices.findLastIndex(isSelectableChoice);
61
- if (first === -1) {
62
- throw new core_1.ValidationError('[select prompt] No selectable choices. All choices are disabled.');
63
- }
64
- return { first, last };
65
- }, [choices]);
66
- (0, core_1.useKeypress)((key, rl) => {
67
- if ((0, core_1.isEnterKey)(key)) {
68
- const [selectedChoice] = getSelectedChoice(value, choices);
69
- if (isSelectableChoice(selectedChoice)) {
70
- setValue(selectedChoice.short);
71
- setStatus('done');
72
- done(selectedChoice.value);
73
- }
74
- else if (value === '') {
75
- setError('Please input a value');
76
- }
77
- else {
78
- setError(`"${yoctocolors_cjs_1.default.red(value)}" isn't an available option`);
79
- }
80
- }
81
- else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) {
82
- rl.clearLine(0);
83
- const [selectedChoice, active] = getSelectedChoice(value, choices);
84
- if (!selectedChoice) {
85
- const firstChoice = (0, core_1.isDownKey)(key)
86
- ? choices.find(isSelectableChoice)
87
- : choices.findLast(isSelectableChoice);
88
- setValue(firstChoice.key);
89
- }
90
- else if (loop ||
91
- ((0, core_1.isUpKey)(key) && active !== bounds.first) ||
92
- ((0, core_1.isDownKey)(key) && active !== bounds.last)) {
93
- const offset = (0, core_1.isUpKey)(key) ? -1 : 1;
94
- let next = active;
95
- do {
96
- next = (next + offset + choices.length) % choices.length;
97
- } while (!isSelectableChoice(choices[next]));
98
- setValue(choices[next].key);
99
- }
100
- }
101
- else {
102
- setValue(rl.line);
103
- setError(undefined);
104
- }
105
- });
106
- const message = theme.style.message(config.message, status);
107
- if (status === 'done') {
108
- return `${prefix} ${message} ${theme.style.answer(value)}`;
109
- }
110
- const choicesStr = choices
111
- .map((choice) => {
112
- if (core_1.Separator.isSeparator(choice)) {
113
- return ` ${choice.separator}`;
114
- }
115
- const line = ` ${choice.key}) ${choice.name}`;
116
- if (choice.key === value.toLowerCase()) {
117
- return theme.style.highlight(line);
118
- }
119
- return line;
120
- })
121
- .join('\n');
122
- let error = '';
123
- if (errorMsg) {
124
- error = theme.style.error(errorMsg);
125
- }
126
- return [
127
- `${prefix} ${message} ${value}`,
128
- [choicesStr, error].filter(Boolean).join('\n'),
129
- ];
130
- });
131
- var core_2 = require("@inquirer/core");
132
- Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_2.Separator; } });
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,18 +0,0 @@
1
- import { Separator, type Theme } from '@inquirer/core';
2
- import type { PartialDeep } from '@inquirer/type';
3
- type Choice<Value> = {
4
- value: Value;
5
- name?: string;
6
- short?: string;
7
- key?: string;
8
- };
9
- declare const _default: <Value>(config: {
10
- message: string;
11
- choices: readonly (string | Separator)[] | readonly (Separator | Choice<Value>)[];
12
- loop?: boolean | undefined;
13
- theme?: PartialDeep<Theme> | undefined;
14
- }, context?: import("@inquirer/type").Context) => Promise<Value> & {
15
- cancel: () => void;
16
- };
17
- export default _default;
18
- export { Separator } from '@inquirer/core';
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }