@inquirer/rawlist 5.2.4 → 5.2.5

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/rawlist",
3
- "version": "5.2.4",
3
+ "version": "5.2.5",
4
4
  "description": "Inquirer rawlist prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -67,11 +67,10 @@
67
67
  "tsc": "tsc"
68
68
  },
69
69
  "dependencies": {
70
- "@inquirer/core": "^11.1.5",
70
+ "@inquirer/core": "^11.1.6",
71
71
  "@inquirer/type": "^4.0.3"
72
72
  },
73
73
  "devDependencies": {
74
- "@inquirer/testing": "^3.3.0",
75
74
  "typescript": "^5.9.3"
76
75
  },
77
76
  "peerDependencies": {
@@ -87,5 +86,5 @@
87
86
  },
88
87
  "main": "./dist/index.js",
89
88
  "types": "./dist/index.d.ts",
90
- "gitHead": "526eca2e64853510821ffd457561840ec0cbfb93"
89
+ "gitHead": "1ce03199b82b4a5fb6f7c97ce374c6da5087444f"
91
90
  }
package/dist/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Separator, type Theme } from '@inquirer/core';
2
- import type { PartialDeep } from '@inquirer/type';
3
- type RawlistTheme = {
4
- style: {
5
- description: (text: string) => string;
6
- };
7
- };
8
- type Choice<Value> = {
9
- value: Value;
10
- name?: string;
11
- short?: string;
12
- key?: string;
13
- description?: string;
14
- };
15
- declare const _default: <Value>(config: {
16
- message: string;
17
- choices: readonly (Separator | Value | Choice<Value>)[];
18
- loop?: boolean | undefined;
19
- theme?: PartialDeep<Theme<RawlistTheme>> | undefined;
20
- default?: NoInfer<Value> | undefined;
21
- }, context?: import("@inquirer/type").Context) => Promise<Value>;
22
- export default _default;
23
- export { Separator } from '@inquirer/core';
package/dist/index.js DELETED
@@ -1,142 +0,0 @@
1
- import { createPrompt, useMemo, useState, useKeypress, usePrefix, isDownKey, isEnterKey, isUpKey, Separator, makeTheme, ValidationError, } from '@inquirer/core';
2
- import { styleText } from 'node:util';
3
- const numberRegex = /\d+/;
4
- const rawlistTheme = {
5
- style: {
6
- description: (text) => styleText('cyan', text),
7
- },
8
- };
9
- function isSelectableChoice(choice) {
10
- return choice != null && !Separator.isSeparator(choice);
11
- }
12
- function normalizeChoices(choices) {
13
- let index = 0;
14
- return choices.map((choice) => {
15
- if (Separator.isSeparator(choice))
16
- return choice;
17
- index += 1;
18
- if (typeof choice !== 'object' || choice === null || !('value' in choice)) {
19
- const name = String(choice);
20
- return {
21
- value: choice,
22
- name,
23
- short: name,
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
- description: choice.description,
34
- };
35
- });
36
- }
37
- function getSelectedChoice(input, choices) {
38
- let selectedChoice;
39
- const selectableChoices = choices.filter(isSelectableChoice);
40
- // First, try to match by custom key (exact match)
41
- selectedChoice = selectableChoices.find((choice) => choice.key === input);
42
- // If no custom key match and input is numeric, try 1-based index
43
- if (!selectedChoice && numberRegex.test(input)) {
44
- const answer = Number.parseInt(input, 10) - 1;
45
- selectedChoice = selectableChoices[answer];
46
- }
47
- return selectedChoice
48
- ? [selectedChoice, choices.indexOf(selectedChoice)]
49
- : [undefined, undefined];
50
- }
51
- export default createPrompt((config, done) => {
52
- const { loop = true } = config;
53
- const choices = useMemo(() => normalizeChoices(config.choices), [config.choices]);
54
- const [status, setStatus] = useState('idle');
55
- const [value, setValue] = useState(() => {
56
- const defaultChoice = config.default == null
57
- ? undefined
58
- : choices.find((choice) => isSelectableChoice(choice) && choice.value === config.default);
59
- return defaultChoice?.key ?? '';
60
- });
61
- const [errorMsg, setError] = useState();
62
- const theme = makeTheme(rawlistTheme, config.theme);
63
- const prefix = usePrefix({ status, theme });
64
- const bounds = useMemo(() => {
65
- const first = choices.findIndex(isSelectableChoice);
66
- const last = choices.findLastIndex(isSelectableChoice);
67
- if (first === -1) {
68
- throw new ValidationError('[select prompt] No selectable choices. All choices are disabled.');
69
- }
70
- return { first, last };
71
- }, [choices]);
72
- useKeypress((key, rl) => {
73
- if (isEnterKey(key)) {
74
- const [selectedChoice] = getSelectedChoice(value, choices);
75
- if (isSelectableChoice(selectedChoice)) {
76
- setValue(selectedChoice.short);
77
- setStatus('done');
78
- done(selectedChoice.value);
79
- }
80
- else if (value === '') {
81
- setError('Please input a value');
82
- }
83
- else {
84
- setError(`"${styleText('red', value)}" isn't an available option`);
85
- }
86
- }
87
- else if (isUpKey(key) || isDownKey(key)) {
88
- rl.clearLine(0);
89
- const [selectedChoice, active] = getSelectedChoice(value, choices);
90
- if (!selectedChoice) {
91
- const firstChoice = isDownKey(key)
92
- ? choices.find(isSelectableChoice)
93
- : choices.findLast(isSelectableChoice);
94
- setValue(firstChoice.key);
95
- }
96
- else if (loop ||
97
- (isUpKey(key) && active !== bounds.first) ||
98
- (isDownKey(key) && active !== bounds.last)) {
99
- const offset = isUpKey(key) ? -1 : 1;
100
- let next = active;
101
- do {
102
- next = (next + offset + choices.length) % choices.length;
103
- } while (!isSelectableChoice(choices[next]));
104
- setValue(choices[next].key);
105
- }
106
- }
107
- else {
108
- setValue(rl.line);
109
- setError(undefined);
110
- }
111
- });
112
- const message = theme.style.message(config.message, status);
113
- if (status === 'done') {
114
- return `${prefix} ${message} ${theme.style.answer(value)}`;
115
- }
116
- const choicesStr = choices
117
- .map((choice) => {
118
- if (Separator.isSeparator(choice)) {
119
- return ` ${choice.separator}`;
120
- }
121
- const line = ` ${choice.key}) ${choice.name}`;
122
- if (choice.key === value) {
123
- return theme.style.highlight(line);
124
- }
125
- return line;
126
- })
127
- .join('\n');
128
- let error = '';
129
- if (errorMsg) {
130
- error = theme.style.error(errorMsg);
131
- }
132
- const [selectedChoice] = getSelectedChoice(value, choices);
133
- let description = '';
134
- if (!errorMsg && selectedChoice?.description) {
135
- description = theme.style.description(selectedChoice.description);
136
- }
137
- return [
138
- `${prefix} ${message} ${value}`,
139
- [choicesStr, error, description].filter(Boolean).join('\n'),
140
- ];
141
- });
142
- export { Separator } from '@inquirer/core';