@trendify/cli 0.1.11 → 0.1.12
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/cli.entry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-field.component.d.ts","sourceRoot":"","sources":["../../../src/shared/components/text-field.component.tsx"],"names":[],"mappings":"AAGA,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;
|
|
1
|
+
{"version":3,"file":"text-field.component.d.ts","sourceRoot":"","sources":["../../../src/shared/components/text-field.component.tsx"],"names":[],"mappings":"AAGA,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAsBF,wBAAgB,SAAS,CAAC,EAAE,KAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE,cAAc,2CA4FnH"}
|
|
@@ -1,6 +1,74 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Box } from 'ink';
|
|
3
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text, useInput } from 'ink';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
const ANSI_ESCAPE_SEQUENCE_PATTERN = /\u001b(?:\[[0-9;:?]*[ -/]*[@-~]|O[A-Za-z])/gu;
|
|
5
|
+
const NON_PRINTABLE_CHARACTER_PATTERN = /[\u0000-\u0008\u000b-\u001f\u007f]/gu;
|
|
6
|
+
const SUSPICIOUS_TERMINAL_FRAGMENT_PATTERN = /^(?:O[A-Za-z~]|BO[A-Za-z~]|\[[A-Za-z0-9;:~]+)$/u;
|
|
7
|
+
function sanitizeInputFragment(input) {
|
|
8
|
+
const trimmedControlSequences = input
|
|
9
|
+
.replace(ANSI_ESCAPE_SEQUENCE_PATTERN, '')
|
|
10
|
+
.replace(NON_PRINTABLE_CHARACTER_PATTERN, '');
|
|
11
|
+
if (!trimmedControlSequences) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
if (trimmedControlSequences.length <= 6 && SUSPICIOUS_TERMINAL_FRAGMENT_PATTERN.test(trimmedControlSequences)) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
return trimmedControlSequences;
|
|
18
|
+
}
|
|
4
19
|
export function TextField({ focus = true, mask, onChange, onSubmit, placeholder, value, width = 72 }) {
|
|
5
|
-
|
|
20
|
+
const [cursorOffset, setCursorOffset] = useState(value.length);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setCursorOffset((current) => Math.max(0, Math.min(current, value.length)));
|
|
23
|
+
}, [value]);
|
|
24
|
+
useInput((input, key) => {
|
|
25
|
+
if (key.eventType && key.eventType !== 'press') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (key.return) {
|
|
29
|
+
onSubmit?.(value);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (key.upArrow || key.downArrow || key.tab || key.escape || key.ctrl || key.meta) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (key.leftArrow) {
|
|
36
|
+
setCursorOffset((current) => Math.max(0, current - 1));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (key.rightArrow) {
|
|
40
|
+
setCursorOffset((current) => Math.min(value.length, current + 1));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (key.home) {
|
|
44
|
+
setCursorOffset(0);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (key.end) {
|
|
48
|
+
setCursorOffset(value.length);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (key.backspace || key.delete) {
|
|
52
|
+
if (cursorOffset === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const nextValue = value.slice(0, cursorOffset - 1) + value.slice(cursorOffset);
|
|
56
|
+
setCursorOffset((current) => Math.max(0, current - 1));
|
|
57
|
+
onChange(nextValue);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const sanitizedInput = sanitizeInputFragment(input);
|
|
61
|
+
if (!sanitizedInput) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const nextValue = value.slice(0, cursorOffset) + sanitizedInput + value.slice(cursorOffset);
|
|
65
|
+
setCursorOffset((current) => current + sanitizedInput.length);
|
|
66
|
+
onChange(nextValue);
|
|
67
|
+
}, { isActive: focus });
|
|
68
|
+
const maskedValue = mask ? mask.repeat(value.length) : value;
|
|
69
|
+
const safeCursorOffset = Math.max(0, Math.min(cursorOffset, maskedValue.length));
|
|
70
|
+
const prefix = maskedValue.slice(0, safeCursorOffset);
|
|
71
|
+
const cursorCharacter = maskedValue[safeCursorOffset] ?? ' ';
|
|
72
|
+
const suffix = maskedValue.slice(safeCursorOffset + (safeCursorOffset < maskedValue.length ? 1 : 0));
|
|
73
|
+
return (_jsx(Box, { borderStyle: "round", borderColor: "green", paddingX: 1, width: width, children: focus && !maskedValue ? (_jsxs(Text, { children: [_jsx(Text, { inverse: true, children: placeholder[0] ?? ' ' }), _jsx(Text, { dimColor: true, children: placeholder.slice(1) })] })) : focus ? (_jsxs(Text, { children: [prefix, _jsx(Text, { inverse: true, children: cursorCharacter }), suffix] })) : value ? (_jsx(Text, { children: mask ? mask.repeat(value.length) : value })) : (_jsx(Text, { dimColor: true, children: placeholder })) }));
|
|
6
74
|
}
|