@reliverse/relinka 1.1.7 → 1.1.8

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.
Files changed (121) hide show
  1. package/dist-npm/components/anykey/index.js +57 -77
  2. package/dist-npm/components/block/block.js +48 -61
  3. package/dist-npm/components/checkbox/index.js +178 -211
  4. package/dist-npm/components/confirm/confirm-main.js +85 -122
  5. package/dist-npm/components/confirm/confirm-three.js +24 -27
  6. package/dist-npm/components/confirm/index.js +36 -45
  7. package/dist-npm/components/core/Separator.js +15 -17
  8. package/dist-npm/components/core/create-prompt.js +101 -124
  9. package/dist-npm/components/core/errors.js +19 -15
  10. package/dist-npm/components/core/hook-engine.js +91 -120
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +16 -6
  13. package/dist-npm/components/core/lines.js +45 -54
  14. package/dist-npm/components/core/make-theme.js +21 -30
  15. package/dist-npm/components/core/position.js +27 -23
  16. package/dist-npm/components/core/promise-polyfill.js +11 -14
  17. package/dist-npm/components/core/screen-manager.js +59 -74
  18. package/dist-npm/components/core/theme.js +22 -32
  19. package/dist-npm/components/core/use-effect.js +9 -15
  20. package/dist-npm/components/core/use-keypress.js +19 -23
  21. package/dist-npm/components/core/use-memo.js +10 -16
  22. package/dist-npm/components/core/use-pagination.js +33 -32
  23. package/dist-npm/components/core/use-prefix.js +40 -38
  24. package/dist-npm/components/core/use-ref.js +2 -5
  25. package/dist-npm/components/core/use-state.js +15 -23
  26. package/dist-npm/components/core/useKeyPress.js +14 -17
  27. package/dist-npm/components/core/usePromptState.js +8 -14
  28. package/dist-npm/components/core/utils.js +7 -16
  29. package/dist-npm/components/date/date.js +173 -204
  30. package/dist-npm/components/editor/index.js +71 -92
  31. package/dist-npm/components/expand/index.js +96 -124
  32. package/dist-npm/components/figures/index.js +283 -294
  33. package/dist-npm/components/input/index.js +61 -87
  34. package/dist-npm/components/input/text-main.js +97 -124
  35. package/dist-npm/components/input/text.js +24 -28
  36. package/dist-npm/components/instance/basic.js +17 -25
  37. package/dist-npm/components/instance/browser.js +14 -18
  38. package/dist-npm/components/instance/reporter/basic.js +46 -65
  39. package/dist-npm/components/instance/reporter/browser.js +44 -47
  40. package/dist-npm/components/instance/reporter/fancy.js +83 -96
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +52 -62
  43. package/dist-npm/components/mono/monoTwo.js +35 -49
  44. package/dist-npm/components/multiselect/group-multiselect.js +55 -71
  45. package/dist-npm/components/multiselect/multi-select-two.js +97 -130
  46. package/dist-npm/components/multiselect/multi-select.js +43 -49
  47. package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
  48. package/dist-npm/components/multiselect/multiselect-main.js +158 -145
  49. package/dist-npm/components/multiselect/num-multi-select.js +97 -130
  50. package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
  51. package/dist-npm/components/next-steps/next-steps.js +23 -25
  52. package/dist-npm/components/number/index.js +78 -112
  53. package/dist-npm/components/number/number-main.js +95 -2
  54. package/dist-npm/components/password/index.js +54 -73
  55. package/dist-npm/components/password/password-main.js +119 -2
  56. package/dist-npm/components/password/password-three.js +26 -30
  57. package/dist-npm/components/progressbar/ProgressBar.js +45 -64
  58. package/dist-npm/components/progressbar/helper.js +33 -40
  59. package/dist-npm/components/progressbar/index.js +1 -1
  60. package/dist-npm/components/prompts/create.js +29 -44
  61. package/dist-npm/components/prompts/index.d.ts +1 -0
  62. package/dist-npm/components/prompts/index.js +46 -45
  63. package/dist-npm/components/prompts/prompt.js +211 -260
  64. package/dist-npm/components/prompts/promptTwo.js +561 -605
  65. package/dist-npm/components/prompts/relinka.js +237 -295
  66. package/dist-npm/components/range/range.js +247 -294
  67. package/dist-npm/components/rawlist/index.js +87 -107
  68. package/dist-npm/components/results/results.js +31 -37
  69. package/dist-npm/components/search/index.js +148 -193
  70. package/dist-npm/components/select/index.js +148 -186
  71. package/dist-npm/components/select/num-select-main.js +27 -27
  72. package/dist-npm/components/select/num-select.js +124 -5
  73. package/dist-npm/components/select/select-key.js +24 -25
  74. package/dist-npm/components/select/select-main.d.ts +1 -0
  75. package/dist-npm/components/select/select-main.js +143 -133
  76. package/dist-npm/components/select/select-three.js +32 -36
  77. package/dist-npm/components/select/select-two.js +94 -87
  78. package/dist-npm/components/spinner/index.js +107 -136
  79. package/dist-npm/components/st-end/end.js +34 -26
  80. package/dist-npm/components/st-end/start.js +29 -15
  81. package/dist-npm/components/toggle/index.js +113 -137
  82. package/dist-npm/components/visual/animate/animate.js +53 -10
  83. package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
  84. package/dist-npm/main.js +1 -0
  85. package/dist-npm/testing/index.js +58 -83
  86. package/dist-npm/types/general.d.ts +1 -1
  87. package/dist-npm/types/general.js +0 -1
  88. package/dist-npm/types/index.js +2 -3
  89. package/dist-npm/types/keypress.js +35 -36
  90. package/dist-npm/types/readline.js +0 -1
  91. package/dist-npm/types/relinka.js +0 -1
  92. package/dist-npm/types/utils.js +0 -1
  93. package/dist-npm/utils/box.js +135 -137
  94. package/dist-npm/utils/color.js +65 -74
  95. package/dist-npm/utils/colorize.js +124 -156
  96. package/dist-npm/utils/component.js +532 -657
  97. package/dist-npm/utils/constants.js +64 -63
  98. package/dist-npm/utils/core.js +2 -3
  99. package/dist-npm/utils/decoder.js +244 -223
  100. package/dist-npm/utils/error.js +4 -9
  101. package/dist-npm/utils/errors.js +14 -4
  102. package/dist-npm/utils/format.js +19 -24
  103. package/dist-npm/utils/keypress.js +316 -414
  104. package/dist-npm/utils/log.js +11 -15
  105. package/dist-npm/utils/mapping.js +45 -52
  106. package/dist-npm/utils/messages.js +196 -183
  107. package/dist-npm/utils/platforms.js +16 -20
  108. package/dist-npm/utils/prompt-tmp.js +235 -286
  109. package/dist-npm/utils/prompt-two.js +235 -286
  110. package/dist-npm/utils/readline.js +5 -7
  111. package/dist-npm/utils/skeleton.js +130 -170
  112. package/dist-npm/utils/stream.js +2 -2
  113. package/dist-npm/utils/string.js +44 -58
  114. package/dist-npm/utils/terminal.js +23 -34
  115. package/dist-npm/utils/tree.js +30 -41
  116. package/dist-npm/utils/types.js +0 -1
  117. package/dist-npm/utils/utils.js +8 -8
  118. package/dist-npm/utils/variants.js +36 -44
  119. package/package.json +14 -14
  120. package/dist-npm/mod.js +0 -2
  121. /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
@@ -1,81 +1,61 @@
1
- import logUpdate from 'log-update';
2
- import process from 'node:process';
3
- import {fmt} from '../../utils/messages.js';
4
- import {restoreCursor} from '../../utils/terminal.js';
5
-
6
- const isNumber = (a) => typeof a === 'number';
7
- const isFn = (a) => typeof a === 'function';
8
- const DEFAULT_MESSAGE = 'Press any key to continue...';
1
+ import logUpdate from "log-update";
2
+ import { fmt } from "../../utils/messages.js";
3
+ import { restoreCursor } from "../../utils/terminal.js";
4
+ const DEFAULT_MESSAGE = "Press any key to continue...";
9
5
  const CTRL_C_CODE = 3;
10
-
11
6
  export async function anykeyPrompt(message = DEFAULT_MESSAGE, options = {}) {
12
- const {
13
- ctrlC = 1,
14
- preserveLog = false,
15
- hideMessage = false,
16
- } = options;
17
-
18
- if (message) {
19
- message = fmt({
20
- type: 'M_GENERAL',
21
- title: message,
22
- titleColor: 'dim',
23
- dontRemoveBar: true,
24
- });
25
- }
26
-
27
- if (message && !hideMessage) {
28
- logUpdate(message);
29
- }
30
-
31
- return new Promise((resolve, reject) => {
32
- const cleanup = () => {
33
- process.stdin.removeListener('data', handler);
34
- if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
35
- process.stdin.setRawMode(false);
36
- }
37
-
38
- process.stdin.pause();
39
- restoreCursor();
40
- };
41
-
42
- const handleCtrlC = () => {
43
- cleanup();
44
- if (ctrlC === 'reject') {
45
- reject(Error('User pressed CTRL+C'));
46
- } else if (!ctrlC) {
47
- resolve();
48
- } else if (isNumber(ctrlC)) {
49
- process.exit(ctrlC);
50
- } else {
51
- throw TypeError('Invalid ctrlC option');
52
- }
53
-
54
- };
55
-
56
- const handler = (buffer) => {
57
- cleanup();
58
- if (message && !preserveLog) {
59
- logUpdate.clear();
60
- } else {
61
- logUpdate.done();
62
- process.stdout.write('\n');
63
- }
64
-
65
- const [firstByte] = buffer;
66
-
67
- if (firstByte === CTRL_C_CODE) {
68
- handleCtrlC();
69
- } else {
70
- resolve();
71
- }
72
- };
73
-
74
- process.stdin.resume();
75
- if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
76
- process.stdin.setRawMode(true);
77
- }
78
-
79
- process.stdin.once('data', handler);
7
+ const { ctrlC = 1, preserveLog = false, hideMessage = false } = options;
8
+ if (message) {
9
+ message = fmt({
10
+ type: "M_GENERAL",
11
+ title: message,
12
+ titleColor: "dim",
13
+ dontRemoveBar: true
80
14
  });
15
+ }
16
+ if (message && !hideMessage) {
17
+ logUpdate(message);
18
+ }
19
+ return new Promise((resolve, reject) => {
20
+ const cleanup = () => {
21
+ process.stdin.removeListener("data", handler);
22
+ if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
23
+ process.stdin.setRawMode(false);
24
+ }
25
+ process.stdin.pause();
26
+ restoreCursor();
27
+ };
28
+ const handleCtrlC = () => {
29
+ cleanup();
30
+ if (ctrlC === "reject") {
31
+ reject(new Error("User pressed CTRL+C"));
32
+ } else if (ctrlC === false) {
33
+ resolve();
34
+ } else if (typeof ctrlC === "number") {
35
+ process.exit(ctrlC);
36
+ } else {
37
+ throw new TypeError("Invalid ctrlC option");
38
+ }
39
+ };
40
+ const handler = (buffer) => {
41
+ cleanup();
42
+ if (message && !preserveLog) {
43
+ logUpdate.clear();
44
+ } else {
45
+ logUpdate.done();
46
+ process.stdout.write("\n");
47
+ }
48
+ const [firstByte] = buffer;
49
+ if (firstByte === CTRL_C_CODE) {
50
+ handleCtrlC();
51
+ } else {
52
+ resolve();
53
+ }
54
+ };
55
+ process.stdin.resume();
56
+ if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
57
+ process.stdin.setRawMode(true);
58
+ }
59
+ process.stdin.once("data", handler);
60
+ });
81
61
  }
@@ -1,65 +1,52 @@
1
- import process, {stdin, stdout} from 'node:process';
2
- import * as readline from 'node:readline';
3
- import {removeCursor, restoreCursor} from '../../utils/terminal.js';
4
-
5
- const isWindows = globalThis.process.platform.startsWith('win');
6
-
7
- export default function block(overrides = {}) {
8
- const {
9
- input = stdin,
10
- output = stdout,
11
- overwrite = true,
12
- hideCursor = true,
13
- } = overrides;
14
- const rl = readline.createInterface({
15
- input,
16
- output,
17
- prompt: '',
18
- tabSize: 1,
19
- });
20
-
21
- readline.emitKeypressEvents(input, rl);
22
- if (input.isTTY) {
23
- input.setRawMode(true);
1
+ import { stdin, stdout } from "node:process";
2
+ import * as readline from "node:readline";
3
+ import { removeCursor, restoreCursor } from "../../utils/terminal.js";
4
+ const isWindows = globalThis.process.platform.startsWith("win");
5
+ export default function block({
6
+ input = stdin,
7
+ output = stdout,
8
+ overwrite = true,
9
+ hideCursor = true
10
+ } = {}) {
11
+ const rl = readline.createInterface({
12
+ input,
13
+ output,
14
+ prompt: "",
15
+ tabSize: 1
16
+ });
17
+ readline.emitKeypressEvents(input, rl);
18
+ if (input.isTTY) {
19
+ input.setRawMode(true);
20
+ }
21
+ const clear = (data, { name }) => {
22
+ const str = String(data);
23
+ if (str === "") {
24
+ process.exit(0);
25
+ }
26
+ if (!overwrite) {
27
+ return;
24
28
  }
25
-
26
- const clear = (data, {name}) => {
27
- const str = String(data);
28
-
29
- if (str === '') {
30
- process.exit(0);
31
- }
32
-
33
- if (!overwrite) {
34
- return;
35
- }
36
-
37
- const dx = name === 'return' ? 0 : -1;
38
- const dy = name === 'return' ? -1 : 0;
39
-
40
- readline.moveCursor(output, dx, dy, () => {
41
- readline.clearLine(output, 1, () => {
42
- input.once('keypress', clear);
43
- });
44
- });
45
- };
46
-
29
+ const dx = name === "return" ? 0 : -1;
30
+ const dy = name === "return" ? -1 : 0;
31
+ readline.moveCursor(output, dx, dy, () => {
32
+ readline.clearLine(output, 1, () => {
33
+ input.once("keypress", clear);
34
+ });
35
+ });
36
+ };
37
+ if (hideCursor) {
38
+ removeCursor();
39
+ }
40
+ input.once("keypress", clear);
41
+ return () => {
42
+ input.off("keypress", clear);
47
43
  if (hideCursor) {
48
- removeCursor();
44
+ restoreCursor();
45
+ }
46
+ if (input.isTTY && !isWindows) {
47
+ input.setRawMode(false);
49
48
  }
50
-
51
- input.once('keypress', clear);
52
- return () => {
53
- input.off('keypress', clear);
54
- if (hideCursor) {
55
- restoreCursor();
56
- }
57
-
58
- if (input.isTTY && !isWindows) {
59
- input.setRawMode(false);
60
- }
61
-
62
- rl.terminal = false;
63
- rl.close();
64
- };
49
+ rl.terminal = false;
50
+ rl.close();
51
+ };
65
52
  }
@@ -1,250 +1,217 @@
1
- import ansiEscapes from 'ansi-escapes';
2
- import colors from 'picocolors';
1
+ import ansiEscapes from "ansi-escapes";
2
+ import colors from "picocolors";
3
3
  import {
4
- createPrompt,
5
- useState,
6
- useKeypress,
7
- usePrefix,
8
- usePagination,
9
- useRef,
10
- useMemo,
11
- makeTheme,
12
- isUpKey,
13
- isDownKey,
14
- isSpaceKey,
15
- isNumberKey,
16
- isEnterKey,
17
- ValidationError,
18
- Separator,
19
- } from '../../components/core/index.js';
20
- import figures from '../../components/figures/index.js';
21
-
22
- const isString = (a) => typeof a === 'string';
23
-
4
+ createPrompt,
5
+ useState,
6
+ useKeypress,
7
+ usePrefix,
8
+ usePagination,
9
+ useRef,
10
+ useMemo,
11
+ makeTheme,
12
+ isUpKey,
13
+ isDownKey,
14
+ isSpaceKey,
15
+ isNumberKey,
16
+ isEnterKey,
17
+ ValidationError,
18
+ Separator
19
+ } from "../../components/core/index.js";
20
+ import figures from "../../components/figures/index.js";
24
21
  const checkboxTheme = {
25
- icon: {
26
- checked: colors.green(figures.circleFilled),
27
- unchecked: figures.circle,
28
- cursor: figures.pointer,
29
- },
30
- style: {
31
- disabledChoice: (text) => colors.dim(`- ${text}`),
32
- renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(', '),
33
- description: (text) => colors.cyan(text),
34
- },
35
- helpMode: 'auto',
22
+ icon: {
23
+ checked: colors.green(figures.circleFilled),
24
+ unchecked: figures.circle,
25
+ cursor: figures.pointer
26
+ },
27
+ style: {
28
+ disabledChoice: (text) => colors.dim(`- ${text}`),
29
+ renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(", "),
30
+ description: (text) => colors.cyan(text)
31
+ },
32
+ helpMode: "auto"
36
33
  };
37
-
38
34
  function isSelectable(item) {
39
- return !Separator.isSeparator(item) && !item.disabled;
35
+ return !Separator.isSeparator(item) && !item.disabled;
40
36
  }
41
-
42
37
  function isChecked(item) {
43
- return isSelectable(item) && Boolean(item.checked);
38
+ return isSelectable(item) && Boolean(item.checked);
44
39
  }
45
-
46
40
  function toggle(item) {
47
- return isSelectable(item) ? { ...item,
48
- checked: !item.checked} : item;
41
+ return isSelectable(item) ? { ...item, checked: !item.checked } : item;
49
42
  }
50
-
51
43
  function check(checked) {
52
- return (item) => isSelectable(item) ? { ...item,
53
- checked} : item;
44
+ return function(item) {
45
+ return isSelectable(item) ? { ...item, checked } : item;
46
+ };
54
47
  }
55
-
56
48
  function normalizeChoices(choices) {
57
- return choices.map((choice) => {
58
- if (Separator.isSeparator(choice)) {
59
- return choice;
60
- }
61
-
62
- if (isString(choice)) {
63
- return {
64
- value: choice,
65
- name: choice,
66
- short: choice,
67
- disabled: false,
68
- checked: false,
69
- };
70
- }
71
-
72
- const name = choice.name ?? String(choice.value);
73
-
74
- return {
75
- value: choice.value,
76
- name,
77
-
78
- short: choice.short ?? name,
79
-
80
- description: choice.description,
81
-
82
- disabled: choice.disabled ?? false,
83
-
84
- checked: choice.checked ?? false,
85
- };
86
- });
49
+ return choices.map((choice) => {
50
+ if (Separator.isSeparator(choice)) {
51
+ return choice;
52
+ }
53
+ if (typeof choice === "string") {
54
+ return {
55
+ value: choice,
56
+ name: choice,
57
+ short: choice,
58
+ disabled: false,
59
+ checked: false
60
+ };
61
+ }
62
+ const name = choice.name ?? String(choice.value);
63
+ return {
64
+
65
+ value: choice.value,
66
+ name,
67
+
68
+ short: choice.short ?? name,
69
+
70
+ description: choice.description,
71
+
72
+ disabled: choice.disabled ?? false,
73
+
74
+ checked: choice.checked ?? false
75
+ };
76
+ });
87
77
  }
88
-
89
- const checkbox = createPrompt((config, done) => {
78
+ const checkbox = createPrompt(
79
+ (config, done) => {
90
80
  const {
91
- instructions,
92
- pageSize = 7,
93
- loop = true,
94
- required,
95
- validate = () => true,
81
+ instructions,
82
+ pageSize = 7,
83
+ loop = true,
84
+ required,
85
+ validate = () => true
96
86
  } = config;
97
-
98
87
  const theme = makeTheme(checkboxTheme, config.theme);
99
88
  const firstRender = useRef(true);
100
- const [status, setStatus] = useState('idle');
101
- const prefix = usePrefix({
102
- status,
103
- theme,
104
- });
105
-
106
- const [items, setItems] = useState(normalizeChoices(config.choices));
107
-
89
+ const [status, setStatus] = useState("idle");
90
+ const prefix = usePrefix({ status, theme });
91
+ const [items, setItems] = useState(
92
+ normalizeChoices(config.choices)
93
+ );
108
94
  const bounds = useMemo(() => {
109
- const first = items.findIndex(isSelectable);
110
- const last = items.findLastIndex(isSelectable);
111
-
112
- if (first === -1) {
113
- throw new ValidationError('[checkbox prompt] No selectable choices. All choices are disabled.');
114
- }
115
-
116
- return {
117
- first,
118
- last,
119
- };
95
+ const first = items.findIndex(isSelectable);
96
+ const last = items.findLastIndex(isSelectable);
97
+ if (first === -1) {
98
+ throw new ValidationError(
99
+ "[checkbox prompt] No selectable choices. All choices are disabled."
100
+ );
101
+ }
102
+ return { first, last };
120
103
  }, [items]);
121
-
122
104
  const [active, setActive] = useState(bounds.first);
123
105
  const [showHelpTip, setShowHelpTip] = useState(true);
124
106
  const [errorMsg, setError] = useState();
125
-
126
107
  useKeypress(async (key) => {
127
- if (isEnterKey(key)) {
128
- const selection = items.filter(isChecked);
129
- const isValid = await validate(selection.slice());
130
-
131
- if (required && !items.some(isChecked)) {
132
- setError('At least one choice must be selected');
133
- } else if (isValid) {
134
- setStatus('done');
135
- done(selection.map((choice) => choice.value));
136
- } else {
137
- setError(isValid || 'You must select a valid value');
138
- }
139
- } else if (isUpKey(key) || isDownKey(key)) {
140
- if (loop || isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
141
- const offset = isUpKey(key) ? -1 : 1;
142
- let next = active;
143
-
144
- do {
145
- next = (next + offset + items.length) % items.length;
146
- } while (!isSelectable(items[next]))
147
- setActive(next);
148
- }
149
- } else if (isSpaceKey(key)) {
150
- setError(void 0);
151
- setShowHelpTip(false);
152
- setItems(items.map((choice, i) => i === active ? toggle(choice) : choice));
153
- } else if (key.name === 'a') {
154
- const selectAll = items.some((choice) => isSelectable(choice) && !choice.checked);
155
-
156
- setItems(items.map(check(selectAll)));
157
- } else if (key.name === 'i') {
158
- setItems(items.map(toggle));
159
- } else if (isNumberKey(key)) {
160
- const position = Number(key.name) - 1;
161
- const item = items[position];
162
-
163
- if (item != null && isSelectable(item)) {
164
- setActive(position);
165
- setItems(items.map((choice, i) => i === position ? toggle(choice) : choice));
166
- }
108
+ if (isEnterKey(key)) {
109
+ const selection = items.filter(isChecked);
110
+ const isValid = await validate([...selection]);
111
+ if (required && !items.some(isChecked)) {
112
+ setError("At least one choice must be selected");
113
+ } else if (isValid === true) {
114
+ setStatus("done");
115
+ done(selection.map((choice) => choice.value));
116
+ } else {
117
+ setError(isValid || "You must select a valid value");
167
118
  }
168
-
169
-
170
-
171
-
119
+ } else if (isUpKey(key) || isDownKey(key)) {
120
+ if (loop || isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
121
+ const offset = isUpKey(key) ? -1 : 1;
122
+ let next = active;
123
+ do {
124
+ next = (next + offset + items.length) % items.length;
125
+ } while (!isSelectable(items[next]));
126
+ setActive(next);
127
+ }
128
+ } else if (isSpaceKey(key)) {
129
+ setError(void 0);
130
+ setShowHelpTip(false);
131
+ setItems(
132
+ items.map((choice, i) => i === active ? toggle(choice) : choice)
133
+ );
134
+ } else if (key.name === "a") {
135
+ const selectAll = items.some(
136
+ (choice) => isSelectable(choice) && !choice.checked
137
+ );
138
+ setItems(items.map(check(selectAll)));
139
+ } else if (key.name === "i") {
140
+ setItems(items.map(toggle));
141
+ } else if (isNumberKey(key)) {
142
+ const position = Number(key.name) - 1;
143
+ const item = items[position];
144
+ if (item != null && isSelectable(item)) {
145
+ setActive(position);
146
+ setItems(
147
+ items.map(
148
+ (choice, i) => i === position ? toggle(choice) : choice
149
+ )
150
+ );
151
+ }
152
+ }
172
153
  });
173
154
  const message = theme.style.message(config.message, status);
174
155
  let description;
175
-
176
156
  const page = usePagination({
177
- items,
178
- active,
179
- renderItem({item, isActive}) {
180
- if (Separator.isSeparator(item)) {
181
- return ` ${item.separator}`;
182
- }
183
-
184
- if (item.disabled) {
185
- const disabledLabel = isString(item.disabled) ? item.disabled : '(disabled)';
186
- return theme.style.disabledChoice(`${item.name} ${disabledLabel}`);
187
- }
188
-
189
- if (isActive) {
190
- description = item.description;
191
- }
192
-
193
- const checkbox2 = item.checked ? theme.icon.checked : theme.icon.unchecked;
194
- const color = isActive ? theme.style.highlight : (x) => x;
195
- const cursor = isActive ? theme.icon.cursor : ' ';
196
-
197
- return color(`${cursor}${checkbox2} ${item.name}`);
198
- },
199
- pageSize,
200
- loop,
201
- });
202
-
203
- if (status === 'done') {
204
- const selection = items.filter(isChecked);
205
- const answer = theme.style.answer(theme.style.renderSelectedChoices(selection, items));
206
-
207
- return `${prefix} ${message} ${answer}`;
208
- }
209
-
210
- let helpTipTop = '';
211
- let helpTipBottom = '';
212
-
213
- if (theme.helpMode === 'always' || theme.helpMode === 'auto' && showHelpTip && (instructions === void 0 || instructions)) {
214
- if (isString(instructions)) {
215
- helpTipTop = instructions;
216
- } else {
217
- const keys = [
218
- `${theme.style.key('space')} to select`,
219
- `${theme.style.key('a')} to toggle all`,
220
- `${theme.style.key('i')} to invert selection`,
221
- `and ${theme.style.key('enter')} to proceed`,
222
- ];
223
-
224
- helpTipTop = ` (Press ${keys.join(', ')})`;
157
+ items,
158
+ active,
159
+ renderItem({ item, isActive }) {
160
+ if (Separator.isSeparator(item)) {
161
+ return ` ${item.separator}`;
162
+ }
163
+ if (item.disabled) {
164
+ const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
165
+ return theme.style.disabledChoice(`${item.name} ${disabledLabel}`);
225
166
  }
226
-
227
- if (items.length > pageSize && (theme.helpMode === 'always' || theme.helpMode === 'auto' && firstRender.current)) {
228
- helpTipBottom = `
229
- ${theme.style.help('(Use arrow keys to reveal more choices)')}`;
230
- firstRender.current = false;
167
+ if (isActive) {
168
+ description = item.description;
231
169
  }
170
+ const checkbox2 = item.checked ? theme.icon.checked : theme.icon.unchecked;
171
+ const color = isActive ? theme.style.highlight : (x) => x;
172
+ const cursor = isActive ? theme.icon.cursor : " ";
173
+ return color(`${cursor}${checkbox2} ${item.name}`);
174
+ },
175
+ pageSize,
176
+ loop
177
+ });
178
+ if (status === "done") {
179
+ const selection = items.filter(isChecked);
180
+ const answer = theme.style.answer(
181
+ theme.style.renderSelectedChoices(selection, items)
182
+ );
183
+ return `${prefix} ${message} ${answer}`;
184
+ }
185
+ let helpTipTop = "";
186
+ let helpTipBottom = "";
187
+ if (theme.helpMode === "always" || theme.helpMode === "auto" && showHelpTip && (instructions === void 0 || instructions)) {
188
+ if (typeof instructions === "string") {
189
+ helpTipTop = instructions;
190
+ } else {
191
+ const keys = [
192
+ `${theme.style.key("space")} to select`,
193
+ `${theme.style.key("a")} to toggle all`,
194
+ `${theme.style.key("i")} to invert selection`,
195
+ `and ${theme.style.key("enter")} to proceed`
196
+ ];
197
+ helpTipTop = ` (Press ${keys.join(", ")})`;
198
+ }
199
+ if (items.length > pageSize && (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current)) {
200
+ helpTipBottom = `
201
+ ${theme.style.help("(Use arrow keys to reveal more choices)")}`;
202
+ firstRender.current = false;
203
+ }
232
204
  }
233
-
234
205
  const choiceDescription = description ? `
235
206
  ${theme.style.description(description)}` : ``;
236
-
237
- let error = '';
238
-
207
+ let error = "";
239
208
  if (errorMsg) {
240
- error = `
209
+ error = `
241
210
  ${theme.style.error(errorMsg)}`;
242
211
  }
243
-
244
212
  return `${prefix} ${message}${helpTipTop}
245
213
  ${page}${helpTipBottom}${choiceDescription}${error}${ansiEscapes.cursorHide}`;
246
- });
247
-
214
+ }
215
+ );
248
216
  export default checkbox;
249
-
250
- export {Separator} from '../../components/core/index.js';
217
+ export { Separator } from "../../components/core/index.js";