@reliverse/relinka 1.1.5 → 1.1.7

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 (115) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -85
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -167
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -97
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -97
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -97
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -23
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -95
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -119
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -124
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -94
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.js +26 -34
  77. package/dist-npm/components/st-end/start.js +15 -29
  78. package/dist-npm/components/toggle/index.js +137 -113
  79. package/dist-npm/components/visual/animate/animate.js +10 -53
  80. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  81. package/dist-npm/mod.js +2 -1
  82. package/dist-npm/testing/index.js +83 -58
  83. package/dist-npm/types/general.js +1 -0
  84. package/dist-npm/types/index.js +3 -2
  85. package/dist-npm/types/keypress.js +36 -35
  86. package/dist-npm/types/readline.js +1 -0
  87. package/dist-npm/types/relinka.js +1 -0
  88. package/dist-npm/types/utils.js +1 -0
  89. package/dist-npm/utils/box.js +137 -135
  90. package/dist-npm/utils/color.js +74 -65
  91. package/dist-npm/utils/colorize.js +156 -124
  92. package/dist-npm/utils/component.js +657 -532
  93. package/dist-npm/utils/constants.js +63 -64
  94. package/dist-npm/utils/core.js +3 -2
  95. package/dist-npm/utils/decoder.js +223 -244
  96. package/dist-npm/utils/error.js +9 -4
  97. package/dist-npm/utils/errors.js +4 -14
  98. package/dist-npm/utils/format.js +24 -19
  99. package/dist-npm/utils/keypress.js +414 -316
  100. package/dist-npm/utils/log.js +15 -11
  101. package/dist-npm/utils/mapping.js +52 -45
  102. package/dist-npm/utils/messages.js +183 -183
  103. package/dist-npm/utils/platforms.js +20 -16
  104. package/dist-npm/utils/prompt-tmp.js +286 -235
  105. package/dist-npm/utils/prompt-two.js +286 -235
  106. package/dist-npm/utils/readline.js +7 -5
  107. package/dist-npm/utils/skeleton.js +170 -130
  108. package/dist-npm/utils/stream.js +2 -2
  109. package/dist-npm/utils/string.js +58 -44
  110. package/dist-npm/utils/terminal.js +34 -23
  111. package/dist-npm/utils/tree.js +41 -30
  112. package/dist-npm/utils/types.js +1 -0
  113. package/dist-npm/utils/utils.js +8 -8
  114. package/dist-npm/utils/variants.js +44 -36
  115. package/package.json +20 -28
@@ -1,119 +1,147 @@
1
- import colors from "picocolors";
1
+ import colors from 'picocolors';
2
2
  import {
3
- createPrompt,
4
- useMemo,
5
- useState,
6
- useKeypress,
7
- usePrefix,
8
- isEnterKey,
9
- makeTheme,
10
- Separator
11
- } from "../../components/core/index.js";
3
+ createPrompt,
4
+ useMemo,
5
+ useState,
6
+ useKeypress,
7
+ usePrefix,
8
+ isEnterKey,
9
+ makeTheme,
10
+ Separator,
11
+ } from '../../components/core/index.js';
12
+
12
13
  function normalizeChoices(choices) {
13
- return choices.map((choice) => {
14
- if (Separator.isSeparator(choice)) {
15
- return choice;
16
- }
17
- const name = "name" in choice ? choice.name : String(choice.value);
18
- const value = "value" in choice ? choice.value : name;
19
- return {
20
- value,
21
- name,
22
- key: choice.key.toLowerCase()
23
- };
24
- });
14
+ return choices.map((choice) => {
15
+ if (Separator.isSeparator(choice)) {
16
+ return choice;
17
+ }
18
+
19
+ const name = 'name' in choice ? choice.name : String(choice.value);
20
+ const value = 'value' in choice ? choice.value : name;
21
+
22
+ return {
23
+ value,
24
+ name,
25
+ key: choice.key.toLowerCase(),
26
+ };
27
+ });
25
28
  }
29
+
26
30
  const helpChoice = {
27
- key: "h",
28
- name: "Help, list all options",
29
- value: void 0
31
+ key: 'h',
32
+ name: 'Help, list all options',
33
+ value: void 0,
30
34
  };
31
- const expand = createPrompt(
32
- (config, done) => {
33
- const { default: defaultKey = "h" } = config;
34
- const choices = useMemo(
35
-
36
- () => normalizeChoices(config.choices),
37
- [config.choices]
38
- );
39
- const [status, setStatus] = useState("idle");
40
- const [value, setValue] = useState("");
35
+
36
+ const expand = createPrompt((config, done) => {
37
+ const {default: defaultKey = 'h'} = config;
38
+ const choices = useMemo(() => normalizeChoices(config.choices), [config.choices]);
39
+
40
+ const [status, setStatus] = useState('idle');
41
+ const [value, setValue] = useState('');
41
42
  const [expanded, setExpanded] = useState(config.expanded ?? false);
42
43
  const [errorMsg, setError] = useState();
43
44
  const theme = makeTheme(config.theme);
44
- const prefix = usePrefix({ theme, status });
45
+ const prefix = usePrefix({
46
+ theme,
47
+ status,
48
+ });
49
+
45
50
  useKeypress((event, rl) => {
46
- if (isEnterKey(event)) {
47
- const answer = (value || defaultKey).toLowerCase();
48
- if (answer === "h" && !expanded) {
49
- setExpanded(true);
51
+ if (isEnterKey(event)) {
52
+ const answer = (value || defaultKey).toLowerCase();
53
+
54
+ if (answer === 'h' && !expanded) {
55
+ setExpanded(true);
56
+ } else {
57
+ const selectedChoice = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === answer);
58
+
59
+ if (selectedChoice) {
60
+ setStatus('done');
61
+ setValue(answer);
62
+ done(selectedChoice.value);
63
+ } else if (value === '') {
64
+ setError('Please input a value');
65
+ } else {
66
+ setError(`"${colors.red(value)}" isn't an available option`);
67
+ }
68
+ }
50
69
  } else {
51
- const selectedChoice = choices.find(
52
- (choice) => !Separator.isSeparator(choice) && choice.key === answer
53
- );
54
- if (selectedChoice) {
55
- setStatus("done");
56
- setValue(answer);
57
- done(selectedChoice.value);
58
- } else if (value === "") {
59
- setError("Please input a value");
60
- } else {
61
- setError(`"${colors.red(value)}" isn't an available option`);
62
- }
70
+ setValue(rl.line);
71
+ setError(void 0);
63
72
  }
64
- } else {
65
- setValue(rl.line);
66
- setError(void 0);
67
- }
68
73
  });
69
74
  const message = theme.style.message(config.message, status);
70
- if (status === "done") {
71
- const selectedChoice = choices.find(
72
- (choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase()
73
- );
74
- return `${prefix} ${message} ${theme.style.answer(selectedChoice.name)}`;
75
+
76
+ if (status === 'done') {
77
+ const selectedChoice = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase());
78
+
79
+ return `${prefix} ${message} ${theme.style.answer(selectedChoice.name)}`;
75
80
  }
76
- const allChoices = expanded ? choices : [...choices, helpChoice];
77
- let longChoices = "";
78
- let shortChoices = allChoices.map((choice) => {
79
- if (Separator.isSeparator(choice)) {
80
- return "";
81
- }
82
- if (choice.key === defaultKey) {
83
- return choice.key.toUpperCase();
84
- }
85
- return choice.key;
86
- }).join("");
87
- shortChoices = ` ${theme.style.defaultAnswer(shortChoices)}`;
88
- if (expanded) {
89
- shortChoices = "";
90
- longChoices = allChoices.map((choice) => {
81
+
82
+ const allChoices = expanded ? choices : [
83
+ ...choices,
84
+ helpChoice,
85
+ ];
86
+ let longChoices = '';
87
+
88
+ let shortChoices = allChoices
89
+ .map((choice) => {
91
90
  if (Separator.isSeparator(choice)) {
92
- return ` ${choice.separator}`;
91
+ return '';
93
92
  }
94
- const line = ` ${choice.key}) ${choice.name}`;
95
- if (choice.key === value.toLowerCase()) {
96
- return theme.style.highlight(line);
93
+
94
+ if (choice.key === defaultKey) {
95
+ return choice.key.toUpperCase();
97
96
  }
98
- return line;
99
- }).join("\n");
97
+
98
+ return choice.key;
99
+ })
100
+ .join('');
101
+
102
+ shortChoices = ` ${theme.style.defaultAnswer(shortChoices)}`;
103
+ if (expanded) {
104
+ shortChoices = '';
105
+ longChoices = allChoices
106
+ .map((choice) => {
107
+ if (Separator.isSeparator(choice)) {
108
+ return ` ${choice.separator}`;
109
+ }
110
+
111
+ const line = ` ${choice.key}) ${choice.name}`;
112
+
113
+ if (choice.key === value.toLowerCase()) {
114
+ return theme.style.highlight(line);
115
+ }
116
+
117
+ return line;
118
+ })
119
+ .join('\n');
100
120
  }
101
- let helpTip = "";
102
- const currentOption = choices.find(
103
- (choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase()
104
- );
121
+
122
+ let helpTip = '';
123
+
124
+ const currentOption = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase());
125
+
105
126
  if (currentOption) {
106
- helpTip = `${colors.cyan(">>")} ${currentOption.name}`;
127
+ helpTip = `${colors.cyan('>>')} ${currentOption.name}`;
107
128
  }
108
- let error = "";
129
+
130
+ let error = '';
131
+
109
132
  if (errorMsg) {
110
- error = theme.style.error(errorMsg);
133
+ error = theme.style.error(errorMsg);
111
134
  }
112
- return [
113
- `${prefix} ${message}${shortChoices} ${value}`,
114
- [longChoices, helpTip, error].filter(Boolean).join("\n")
115
- ];
116
- }
117
- );
135
+
136
+ return [`${prefix} ${message}${shortChoices} ${value}`, [
137
+ longChoices,
138
+ helpTip,
139
+ error,
140
+ ]
141
+ .filter(Boolean)
142
+ .join('\n')];
143
+ });
144
+
118
145
  export default expand;
119
- export { Separator } from "../../components/core/index.js";
146
+
147
+ export {Separator} from '../../components/core/index.js';