@reliverse/relinka 1.1.7 → 1.1.9

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 +187 -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,147 +1,119 @@
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';
12
-
3
+ createPrompt,
4
+ useMemo,
5
+ useState,
6
+ useKeypress,
7
+ usePrefix,
8
+ isEnterKey,
9
+ makeTheme,
10
+ Separator
11
+ } from "../../components/core/index.js";
13
12
  function normalizeChoices(choices) {
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
- });
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
+ });
28
25
  }
29
-
30
26
  const helpChoice = {
31
- key: 'h',
32
- name: 'Help, list all options',
33
- value: void 0,
27
+ key: "h",
28
+ name: "Help, list all options",
29
+ value: void 0
34
30
  };
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('');
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("");
42
41
  const [expanded, setExpanded] = useState(config.expanded ?? false);
43
42
  const [errorMsg, setError] = useState();
44
43
  const theme = makeTheme(config.theme);
45
- const prefix = usePrefix({
46
- theme,
47
- status,
48
- });
49
-
44
+ const prefix = usePrefix({ theme, status });
50
45
  useKeypress((event, rl) => {
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
- }
46
+ if (isEnterKey(event)) {
47
+ const answer = (value || defaultKey).toLowerCase();
48
+ if (answer === "h" && !expanded) {
49
+ setExpanded(true);
69
50
  } else {
70
- setValue(rl.line);
71
- setError(void 0);
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
+ }
72
63
  }
64
+ } else {
65
+ setValue(rl.line);
66
+ setError(void 0);
67
+ }
73
68
  });
74
69
  const message = theme.style.message(config.message, status);
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)}`;
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)}`;
80
75
  }
81
-
82
- const allChoices = expanded ? choices : [
83
- ...choices,
84
- helpChoice,
85
- ];
86
- let longChoices = '';
87
-
88
- let shortChoices = allChoices
89
- .map((choice) => {
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) => {
90
91
  if (Separator.isSeparator(choice)) {
91
- return '';
92
+ return ` ${choice.separator}`;
92
93
  }
93
-
94
- if (choice.key === defaultKey) {
95
- return choice.key.toUpperCase();
94
+ const line = ` ${choice.key}) ${choice.name}`;
95
+ if (choice.key === value.toLowerCase()) {
96
+ return theme.style.highlight(line);
96
97
  }
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');
98
+ return line;
99
+ }).join("\n");
120
100
  }
121
-
122
- let helpTip = '';
123
-
124
- const currentOption = choices.find((choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase());
125
-
101
+ let helpTip = "";
102
+ const currentOption = choices.find(
103
+ (choice) => !Separator.isSeparator(choice) && choice.key === value.toLowerCase()
104
+ );
126
105
  if (currentOption) {
127
- helpTip = `${colors.cyan('>>')} ${currentOption.name}`;
106
+ helpTip = `${colors.cyan(">>")} ${currentOption.name}`;
128
107
  }
129
-
130
- let error = '';
131
-
108
+ let error = "";
132
109
  if (errorMsg) {
133
- error = theme.style.error(errorMsg);
110
+ error = theme.style.error(errorMsg);
134
111
  }
135
-
136
- return [`${prefix} ${message}${shortChoices} ${value}`, [
137
- longChoices,
138
- helpTip,
139
- error,
140
- ]
141
- .filter(Boolean)
142
- .join('\n')];
143
- });
144
-
112
+ return [
113
+ `${prefix} ${message}${shortChoices} ${value}`,
114
+ [longChoices, helpTip, error].filter(Boolean).join("\n")
115
+ ];
116
+ }
117
+ );
145
118
  export default expand;
146
-
147
- export {Separator} from '../../components/core/index.js';
119
+ export { Separator } from "../../components/core/index.js";