@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.
- package/dist-npm/components/anykey/index.js +77 -57
- package/dist-npm/components/block/block.js +61 -48
- package/dist-npm/components/checkbox/index.js +211 -178
- package/dist-npm/components/confirm/confirm-main.js +122 -85
- package/dist-npm/components/confirm/confirm-three.js +27 -24
- package/dist-npm/components/confirm/index.js +45 -36
- package/dist-npm/components/core/Separator.js +17 -15
- package/dist-npm/components/core/create-prompt.js +124 -101
- package/dist-npm/components/core/errors.js +15 -19
- package/dist-npm/components/core/hook-engine.js +120 -91
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +6 -16
- package/dist-npm/components/core/lines.js +54 -45
- package/dist-npm/components/core/make-theme.js +30 -21
- package/dist-npm/components/core/position.js +23 -27
- package/dist-npm/components/core/promise-polyfill.js +14 -11
- package/dist-npm/components/core/screen-manager.js +74 -59
- package/dist-npm/components/core/theme.js +32 -22
- package/dist-npm/components/core/use-effect.js +15 -9
- package/dist-npm/components/core/use-keypress.js +23 -19
- package/dist-npm/components/core/use-memo.js +16 -10
- package/dist-npm/components/core/use-pagination.js +32 -33
- package/dist-npm/components/core/use-prefix.js +38 -40
- package/dist-npm/components/core/use-ref.js +5 -2
- package/dist-npm/components/core/use-state.js +23 -15
- package/dist-npm/components/core/useKeyPress.js +17 -14
- package/dist-npm/components/core/usePromptState.js +14 -8
- package/dist-npm/components/core/utils.js +16 -7
- package/dist-npm/components/date/date.js +204 -167
- package/dist-npm/components/editor/index.js +92 -71
- package/dist-npm/components/expand/index.js +124 -96
- package/dist-npm/components/figures/index.js +294 -283
- package/dist-npm/components/input/index.js +87 -61
- package/dist-npm/components/input/text-main.js +124 -97
- package/dist-npm/components/input/text.js +28 -24
- package/dist-npm/components/instance/basic.js +25 -17
- package/dist-npm/components/instance/browser.js +18 -14
- package/dist-npm/components/instance/reporter/basic.js +65 -46
- package/dist-npm/components/instance/reporter/browser.js +47 -44
- package/dist-npm/components/instance/reporter/fancy.js +96 -83
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +62 -52
- package/dist-npm/components/mono/monoTwo.js +49 -35
- package/dist-npm/components/multiselect/group-multiselect.js +71 -55
- package/dist-npm/components/multiselect/multi-select-two.js +130 -97
- package/dist-npm/components/multiselect/multi-select.js +49 -43
- package/dist-npm/components/multiselect/multiselect-main.js +146 -120
- package/dist-npm/components/multiselect/num-multi-select.js +130 -97
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -23
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -95
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -119
- package/dist-npm/components/password/password-three.js +30 -26
- package/dist-npm/components/progressbar/ProgressBar.js +64 -45
- package/dist-npm/components/progressbar/helper.js +40 -33
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +44 -29
- package/dist-npm/components/prompts/index.js +45 -45
- package/dist-npm/components/prompts/prompt.js +260 -211
- package/dist-npm/components/prompts/promptTwo.js +605 -561
- package/dist-npm/components/prompts/relinka.js +295 -237
- package/dist-npm/components/range/range.js +294 -247
- package/dist-npm/components/rawlist/index.js +107 -87
- package/dist-npm/components/results/results.js +37 -31
- package/dist-npm/components/search/index.js +193 -148
- package/dist-npm/components/select/index.js +186 -148
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +5 -124
- package/dist-npm/components/select/select-key.js +25 -24
- package/dist-npm/components/select/select-main.js +133 -109
- package/dist-npm/components/select/select-three.js +36 -32
- package/dist-npm/components/select/select-two.js +87 -94
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.js +26 -34
- package/dist-npm/components/st-end/start.js +15 -29
- package/dist-npm/components/toggle/index.js +137 -113
- package/dist-npm/components/visual/animate/animate.js +10 -53
- package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
- package/dist-npm/mod.js +2 -1
- package/dist-npm/testing/index.js +83 -58
- package/dist-npm/types/general.js +1 -0
- package/dist-npm/types/index.js +3 -2
- package/dist-npm/types/keypress.js +36 -35
- package/dist-npm/types/readline.js +1 -0
- package/dist-npm/types/relinka.js +1 -0
- package/dist-npm/types/utils.js +1 -0
- package/dist-npm/utils/box.js +137 -135
- package/dist-npm/utils/color.js +74 -65
- package/dist-npm/utils/colorize.js +156 -124
- package/dist-npm/utils/component.js +657 -532
- package/dist-npm/utils/constants.js +63 -64
- package/dist-npm/utils/core.js +3 -2
- package/dist-npm/utils/decoder.js +223 -244
- package/dist-npm/utils/error.js +9 -4
- package/dist-npm/utils/errors.js +4 -14
- package/dist-npm/utils/format.js +24 -19
- package/dist-npm/utils/keypress.js +414 -316
- package/dist-npm/utils/log.js +15 -11
- package/dist-npm/utils/mapping.js +52 -45
- package/dist-npm/utils/messages.js +183 -183
- package/dist-npm/utils/platforms.js +20 -16
- package/dist-npm/utils/prompt-tmp.js +286 -235
- package/dist-npm/utils/prompt-two.js +286 -235
- package/dist-npm/utils/readline.js +7 -5
- package/dist-npm/utils/skeleton.js +170 -130
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +58 -44
- package/dist-npm/utils/terminal.js +34 -23
- package/dist-npm/utils/tree.js +41 -30
- package/dist-npm/utils/types.js +1 -0
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +44 -36
- package/package.json +20 -28
|
@@ -1,190 +1,227 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
4
|
-
import readline from "node:readline/promises";
|
|
1
|
+
import {Type} from '@sinclair/typebox';
|
|
2
|
+
import {Value} from '@sinclair/typebox/value';
|
|
5
3
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
startOfString
|
|
11
|
-
} from "ts-regex-builder";
|
|
12
|
-
import { fmt, msg } from "../../utils/messages.js";
|
|
4
|
+
stdin as input,
|
|
5
|
+
stdout as output,
|
|
6
|
+
} from 'node:process';
|
|
7
|
+
import readline from 'node:readline/promises';
|
|
13
8
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
buildRegExp,
|
|
10
|
+
digit,
|
|
11
|
+
endOfString,
|
|
12
|
+
repeat,
|
|
13
|
+
startOfString,
|
|
14
|
+
} from 'ts-regex-builder';
|
|
15
|
+
import {fmt, msg} from '../../utils/messages.js';
|
|
16
|
+
import {
|
|
17
|
+
countLines,
|
|
18
|
+
deleteLastLine,
|
|
19
|
+
deleteLastLines,
|
|
20
|
+
} from '../../utils/terminal.js';
|
|
21
|
+
|
|
22
|
+
const isString = (a) => typeof a === 'string';
|
|
23
|
+
|
|
18
24
|
const twoDigits = repeat(digit, 2);
|
|
19
25
|
const fourDigits = repeat(digit, 4);
|
|
20
|
-
const separatorDot =
|
|
21
|
-
const separatorSlash =
|
|
26
|
+
const separatorDot = '.';
|
|
27
|
+
const separatorSlash = '/';
|
|
28
|
+
|
|
22
29
|
const regexDDMMYYYY = buildRegExp([
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
fourDigits,
|
|
31
|
-
|
|
32
|
-
endOfString
|
|
30
|
+
startOfString,
|
|
31
|
+
twoDigits,
|
|
32
|
+
separatorDot,
|
|
33
|
+
twoDigits,
|
|
34
|
+
separatorDot,
|
|
35
|
+
fourDigits,
|
|
36
|
+
endOfString,
|
|
33
37
|
]);
|
|
38
|
+
|
|
34
39
|
const regexMMDDYYYY = buildRegExp([
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
fourDigits,
|
|
43
|
-
|
|
44
|
-
endOfString
|
|
40
|
+
startOfString,
|
|
41
|
+
twoDigits,
|
|
42
|
+
separatorSlash,
|
|
43
|
+
twoDigits,
|
|
44
|
+
separatorSlash,
|
|
45
|
+
fourDigits,
|
|
46
|
+
endOfString,
|
|
45
47
|
]);
|
|
48
|
+
|
|
46
49
|
const regexYYYYMMDD = buildRegExp([
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
twoDigits,
|
|
55
|
-
|
|
56
|
-
endOfString
|
|
50
|
+
startOfString,
|
|
51
|
+
fourDigits,
|
|
52
|
+
separatorDot,
|
|
53
|
+
twoDigits,
|
|
54
|
+
separatorDot,
|
|
55
|
+
twoDigits,
|
|
56
|
+
endOfString,
|
|
57
57
|
]);
|
|
58
|
+
|
|
58
59
|
const dateFormatSchema = Type.Union([
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
Type.RegExp(regexDDMMYYYY, {
|
|
61
|
+
description: 'DD.MM.YYYY',
|
|
62
|
+
}),
|
|
63
|
+
Type.RegExp(regexMMDDYYYY, {
|
|
64
|
+
description: 'MM/DD/YYYY',
|
|
65
|
+
}),
|
|
66
|
+
Type.RegExp(regexYYYYMMDD, {
|
|
67
|
+
description: 'YYYY.MM.DD',
|
|
68
|
+
}),
|
|
62
69
|
]);
|
|
70
|
+
|
|
63
71
|
export async function datePrompt(options) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
titleVariant,
|
|
75
|
-
content,
|
|
76
|
-
contentColor,
|
|
77
|
-
contentTypography,
|
|
78
|
-
contentVariant,
|
|
79
|
-
borderColor = "viceGradient",
|
|
80
|
-
variantOptions
|
|
81
|
-
} = options;
|
|
82
|
-
const rl = readline.createInterface({ input, output });
|
|
83
|
-
let linesToDelete = 0;
|
|
84
|
-
let errorMessage = "";
|
|
85
|
-
try {
|
|
86
|
-
while (true) {
|
|
87
|
-
if (linesToDelete > 0) {
|
|
88
|
-
deleteLastLines(linesToDelete);
|
|
89
|
-
}
|
|
90
|
-
const questionText = fmt({
|
|
91
|
-
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
92
|
-
title: `${title} [Format: ${dateFormat}]`,
|
|
93
|
-
titleColor,
|
|
94
|
-
titleTypography,
|
|
72
|
+
const {
|
|
73
|
+
title,
|
|
74
|
+
dateFormat,
|
|
75
|
+
dateKind,
|
|
76
|
+
hint,
|
|
77
|
+
validate,
|
|
78
|
+
defaultValue,
|
|
79
|
+
schema,
|
|
80
|
+
titleColor = 'cyanBright',
|
|
81
|
+
titleTypography = 'bold',
|
|
95
82
|
titleVariant,
|
|
96
83
|
content,
|
|
97
84
|
contentColor,
|
|
98
85
|
contentTypography,
|
|
99
86
|
contentVariant,
|
|
100
|
-
borderColor,
|
|
101
|
-
hint,
|
|
87
|
+
borderColor = 'viceGradient',
|
|
102
88
|
variantOptions,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
89
|
+
} = options;
|
|
90
|
+
|
|
91
|
+
const rl = readline.createInterface({
|
|
92
|
+
input,
|
|
93
|
+
output,
|
|
94
|
+
});
|
|
95
|
+
let linesToDelete = 0;
|
|
96
|
+
let errorMessage = '';
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
while (true) {
|
|
100
|
+
if (linesToDelete > 0) {
|
|
101
|
+
deleteLastLines(linesToDelete);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const questionText = fmt({
|
|
105
|
+
type: errorMessage !== '' ? 'M_ERROR' : 'M_GENERAL',
|
|
106
|
+
title: `${title} [Format: ${dateFormat}]`,
|
|
107
|
+
titleColor,
|
|
108
|
+
titleTypography,
|
|
109
|
+
titleVariant,
|
|
110
|
+
content,
|
|
111
|
+
contentColor,
|
|
112
|
+
contentTypography,
|
|
113
|
+
contentVariant,
|
|
114
|
+
borderColor,
|
|
115
|
+
hint,
|
|
116
|
+
variantOptions,
|
|
117
|
+
errorMessage,
|
|
118
|
+
addNewLineBefore: false,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const questionLines = countLines(questionText);
|
|
122
|
+
|
|
123
|
+
linesToDelete = questionLines + 1;
|
|
124
|
+
msg({
|
|
125
|
+
type: 'M_GENERAL',
|
|
126
|
+
title: questionText,
|
|
127
|
+
});
|
|
128
|
+
const answer = (await rl.question('> ')).trim() || defaultValue;
|
|
129
|
+
|
|
130
|
+
if (answer === defaultValue && defaultValue) {
|
|
131
|
+
deleteLastLine();
|
|
132
|
+
msg({
|
|
133
|
+
type: 'M_MIDDLE',
|
|
134
|
+
title: ` ${defaultValue}`,
|
|
135
|
+
titleColor: 'none',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!Value.Check(dateFormatSchema, answer)) {
|
|
140
|
+
errorMessage = `Please enter a valid date in ${dateFormat} format.`;
|
|
141
|
+
msg({
|
|
142
|
+
type: 'M_ERROR',
|
|
143
|
+
title: errorMessage,
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let matchedFormat = null;
|
|
149
|
+
|
|
150
|
+
if (regexDDMMYYYY.test(answer)) {
|
|
151
|
+
matchedFormat = 'DD.MM.YYYY';
|
|
152
|
+
} else if (regexMMDDYYYY.test(answer)) {
|
|
153
|
+
matchedFormat = 'MM/DD/YYYY';
|
|
154
|
+
} else if (regexYYYYMMDD.test(answer)) {
|
|
155
|
+
matchedFormat = 'YYYY.MM.DD';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if (dateKind === 'birthday' && matchedFormat) {
|
|
160
|
+
const parts = answer.split(/[./-]/);
|
|
161
|
+
let date;
|
|
162
|
+
|
|
163
|
+
if (matchedFormat === 'DD.MM.YYYY') {
|
|
164
|
+
date = new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));
|
|
165
|
+
} else if (matchedFormat === 'MM/DD/YYYY') {
|
|
166
|
+
date = new Date(Number(parts[2]), Number(parts[0]) - 1, Number(parts[1]));
|
|
167
|
+
} else if (matchedFormat === 'YYYY.MM.DD') {
|
|
168
|
+
date = new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]));
|
|
169
|
+
} else {
|
|
170
|
+
date = new Date(answer);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if (isNaN(date.getTime()) || date.getFullYear() < 1900 || date > new Date()) {
|
|
175
|
+
errorMessage = 'Please enter a valid birthday date (e.g., 14.09.1999).';
|
|
176
|
+
msg({
|
|
177
|
+
type: 'M_ERROR',
|
|
178
|
+
title: errorMessage,
|
|
179
|
+
});
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let isValid = true;
|
|
185
|
+
|
|
186
|
+
errorMessage = '';
|
|
187
|
+
if (schema) {
|
|
188
|
+
isValid = Value.Check(schema, answer);
|
|
189
|
+
if (!isValid) {
|
|
190
|
+
const errors = Value.Errors(schema, answer);
|
|
191
|
+
|
|
192
|
+
errorMessage = errors[0]?.message ?? 'Invalid input.';
|
|
193
|
+
msg({
|
|
194
|
+
type: 'M_ERROR',
|
|
195
|
+
title: errorMessage,
|
|
196
|
+
});
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (validate && isValid) {
|
|
202
|
+
const validation = await validate(answer);
|
|
203
|
+
|
|
204
|
+
if (!validation) {
|
|
205
|
+
isValid = false;
|
|
206
|
+
errorMessage = isString(validation) ? validation : 'Invalid input.';
|
|
207
|
+
msg({
|
|
208
|
+
type: 'M_ERROR',
|
|
209
|
+
title: errorMessage,
|
|
210
|
+
});
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (isValid) {
|
|
216
|
+
msg({
|
|
217
|
+
type: 'M_NEWLINE',
|
|
218
|
+
title: '',
|
|
219
|
+
});
|
|
220
|
+
rl.close();
|
|
221
|
+
return answer;
|
|
222
|
+
}
|
|
179
223
|
}
|
|
180
|
-
|
|
181
|
-
if (isValid) {
|
|
182
|
-
msg({ type: "M_NEWLINE", title: "" });
|
|
224
|
+
} finally {
|
|
183
225
|
rl.close();
|
|
184
|
-
return answer;
|
|
185
|
-
}
|
|
186
226
|
}
|
|
187
|
-
} finally {
|
|
188
|
-
rl.close();
|
|
189
|
-
}
|
|
190
227
|
}
|
|
@@ -1,78 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {editAsync} from 'external-editor';
|
|
2
|
+
import {AsyncResource} from 'node:async_hooks';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from
|
|
4
|
+
createPrompt,
|
|
5
|
+
useEffect,
|
|
6
|
+
useState,
|
|
7
|
+
useKeypress,
|
|
8
|
+
usePrefix,
|
|
9
|
+
isEnterKey,
|
|
10
|
+
makeTheme,
|
|
11
|
+
} from '../../components/core/index.js';
|
|
12
|
+
|
|
12
13
|
export default createPrompt((config, done) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
async (error2, answer) => {
|
|
27
|
-
rl.resume();
|
|
28
|
-
if (error2) {
|
|
29
|
-
setError(error2.toString());
|
|
30
|
-
} else {
|
|
31
|
-
setStatus("loading");
|
|
32
|
-
const isValid = await validate(answer);
|
|
33
|
-
if (isValid === true) {
|
|
34
|
-
setError(void 0);
|
|
35
|
-
setStatus("done");
|
|
36
|
-
done(answer);
|
|
37
|
-
} else {
|
|
38
|
-
setValue(answer);
|
|
39
|
-
setError(isValid || "You must provide a valid value");
|
|
40
|
-
setStatus("idle");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
editAsync(value, (error2, answer) => void editCallback(error2, answer), {
|
|
46
|
-
postfix,
|
|
47
|
-
...fileProps
|
|
14
|
+
const {
|
|
15
|
+
waitForUseInput = true,
|
|
16
|
+
file: {postfix = config.postfix ?? '.txt', ...fileProps} = {},
|
|
17
|
+
validate = () => true,
|
|
18
|
+
} = config;
|
|
19
|
+
|
|
20
|
+
const theme = makeTheme(config.theme);
|
|
21
|
+
const [status, setStatus] = useState('idle');
|
|
22
|
+
const [value, setValue] = useState(config.default || '');
|
|
23
|
+
const [errorMsg, setError] = useState();
|
|
24
|
+
const prefix = usePrefix({
|
|
25
|
+
status,
|
|
26
|
+
theme,
|
|
48
27
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
|
|
29
|
+
function startEditor(rl) {
|
|
30
|
+
rl.pause();
|
|
31
|
+
const editCallback = AsyncResource.bind(async (error2, answer) => {
|
|
32
|
+
rl.resume();
|
|
33
|
+
if (error2) {
|
|
34
|
+
setError(error2.toString());
|
|
35
|
+
} else {
|
|
36
|
+
setStatus('loading');
|
|
37
|
+
const isValid = await validate(answer);
|
|
38
|
+
|
|
39
|
+
if (isValid) {
|
|
40
|
+
setError(void 0);
|
|
41
|
+
setStatus('done');
|
|
42
|
+
done(answer);
|
|
43
|
+
} else {
|
|
44
|
+
setValue(answer);
|
|
45
|
+
setError(isValid || 'You must provide a valid value');
|
|
46
|
+
setStatus('idle');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
editAsync(value, (error2, answer) => void editCallback(error2, answer), {
|
|
52
|
+
postfix,
|
|
53
|
+
...fileProps,
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
|
|
57
|
+
useEffect((rl) => {
|
|
58
|
+
if (!waitForUseInput) {
|
|
59
|
+
startEditor(rl);
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
useKeypress((key, rl) => {
|
|
63
|
+
if (status !== 'idle') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isEnterKey(key)) {
|
|
68
|
+
startEditor(rl);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const message = theme.style.message(config.message, status);
|
|
72
|
+
let helpTip = '';
|
|
73
|
+
|
|
74
|
+
if (status === 'loading') {
|
|
75
|
+
helpTip = theme.style.help('Received');
|
|
76
|
+
} else if (status === 'idle') {
|
|
77
|
+
const enterKey = theme.style.key('enter');
|
|
78
|
+
|
|
79
|
+
helpTip = theme.style.help(`Press ${enterKey} to launch your preferred editor.`);
|
|
58
80
|
}
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
let error = '';
|
|
84
|
+
|
|
85
|
+
if (errorMsg) {
|
|
86
|
+
error = theme.style.error(errorMsg);
|
|
61
87
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let error = "";
|
|
74
|
-
if (errorMsg) {
|
|
75
|
-
error = theme.style.error(errorMsg);
|
|
76
|
-
}
|
|
77
|
-
return [[prefix, message, helpTip].filter(Boolean).join(" "), error];
|
|
88
|
+
|
|
89
|
+
return [
|
|
90
|
+
[
|
|
91
|
+
prefix,
|
|
92
|
+
message,
|
|
93
|
+
helpTip,
|
|
94
|
+
]
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.join(' '),
|
|
97
|
+
error,
|
|
98
|
+
];
|
|
78
99
|
});
|