funda-ui 4.7.562 → 4.7.570
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/Chatbox/index.js +14 -12
- package/Checkbox/index.d.ts +1 -1
- package/Checkbox/index.js +3 -3
- package/Date/index.js +74 -51
- package/Input/index.d.ts +23 -23
- package/Input/index.js +72 -46
- package/NumberInput/index.d.ts +1 -1
- package/Radio/index.d.ts +1 -1
- package/Radio/index.js +12 -6
- package/RangeSlider/index.js +72 -46
- package/Select/index.d.ts +1 -1
- package/Select/index.js +22 -0
- package/TagInput/index.d.ts +1 -1
- package/Textarea/index.d.ts +17 -17
- package/Textarea/index.js +14 -12
- package/lib/cjs/Chatbox/index.js +14 -12
- package/lib/cjs/Checkbox/index.d.ts +1 -1
- package/lib/cjs/Checkbox/index.js +3 -3
- package/lib/cjs/Date/index.js +74 -51
- package/lib/cjs/Input/index.d.ts +23 -23
- package/lib/cjs/Input/index.js +72 -46
- package/lib/cjs/NumberInput/index.d.ts +1 -1
- package/lib/cjs/Radio/index.d.ts +1 -1
- package/lib/cjs/Radio/index.js +12 -6
- package/lib/cjs/RangeSlider/index.js +72 -46
- package/lib/cjs/Select/index.d.ts +1 -1
- package/lib/cjs/Select/index.js +22 -0
- package/lib/cjs/TagInput/index.d.ts +1 -1
- package/lib/cjs/Textarea/index.d.ts +17 -17
- package/lib/cjs/Textarea/index.js +14 -12
- package/lib/esm/Chatbox/index.tsx +1 -1
- package/lib/esm/Checkbox/index.tsx +4 -4
- package/lib/esm/Date/index.tsx +2 -4
- package/lib/esm/Input/index.tsx +102 -84
- package/lib/esm/NumberInput/index.tsx +1 -1
- package/lib/esm/Radio/index.tsx +16 -8
- package/lib/esm/Select/index.tsx +34 -1
- package/lib/esm/TagInput/index.tsx +1 -1
- package/lib/esm/Textarea/index.tsx +75 -70
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ChangeEvent, KeyboardEvent, FocusEvent } from 'react';
|
|
2
2
|
export declare type TextareaProps = {
|
|
3
3
|
contentRef?: React.ForwardedRef<any>;
|
|
4
4
|
wrapperClassName?: string;
|
|
@@ -11,13 +11,13 @@ export declare type TextareaProps = {
|
|
|
11
11
|
requiredLabel?: React.ReactNode | string;
|
|
12
12
|
label?: React.ReactNode | string;
|
|
13
13
|
name?: string;
|
|
14
|
-
minLength?:
|
|
15
|
-
maxLength?:
|
|
14
|
+
minLength?: number;
|
|
15
|
+
maxLength?: number;
|
|
16
16
|
cols?: number;
|
|
17
17
|
rows?: number;
|
|
18
|
-
disabled?:
|
|
19
|
-
required?:
|
|
20
|
-
readOnly?:
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
readOnly?: boolean;
|
|
21
21
|
placeholder?: string;
|
|
22
22
|
autoSize?: boolean;
|
|
23
23
|
autoSizeMaxHeight?: number;
|
|
@@ -28,23 +28,23 @@ export declare type TextareaProps = {
|
|
|
28
28
|
aiPredictConfirmKey?: Array<string[]>;
|
|
29
29
|
aiPredictFetchFuncAsync?: any;
|
|
30
30
|
aiPredictFetchFuncMethod?: string;
|
|
31
|
-
aiPredictFetchFuncMethodParams?:
|
|
31
|
+
aiPredictFetchFuncMethodParams?: unknown[];
|
|
32
32
|
aiPredictFetchCallback?: (data: any) => void;
|
|
33
33
|
/** -- */
|
|
34
34
|
id?: string;
|
|
35
35
|
style?: React.CSSProperties;
|
|
36
36
|
tabIndex?: number;
|
|
37
37
|
[key: `data-${string}`]: string | undefined;
|
|
38
|
-
onChangeCallback?: (e:
|
|
39
|
-
onInputCallback?: (e:
|
|
40
|
-
onKeyPressedCallback?: (e:
|
|
41
|
-
onChange?: (e:
|
|
42
|
-
onBlur?: (e:
|
|
43
|
-
onFocus?: (e:
|
|
44
|
-
onPressEnter?: (e:
|
|
45
|
-
onKeyDown?: (e:
|
|
46
|
-
onKeyUp?: (e:
|
|
47
|
-
onResize?: (el:
|
|
38
|
+
onChangeCallback?: (e: ChangeEvent<HTMLTextAreaElement> | FocusEvent, el: HTMLTextAreaElement) => string | void;
|
|
39
|
+
onInputCallback?: (e: ChangeEvent<HTMLTextAreaElement> | KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => string | void;
|
|
40
|
+
onKeyPressedCallback?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => string | void;
|
|
41
|
+
onChange?: (e: ChangeEvent<HTMLTextAreaElement> | KeyboardEvent<HTMLTextAreaElement> | null, el: HTMLTextAreaElement, value: string) => void;
|
|
42
|
+
onBlur?: (e: FocusEvent, el: HTMLTextAreaElement) => void;
|
|
43
|
+
onFocus?: (e: FocusEvent, el: HTMLTextAreaElement) => void;
|
|
44
|
+
onPressEnter?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => void;
|
|
45
|
+
onKeyDown?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => void;
|
|
46
|
+
onKeyUp?: (e: KeyboardEvent<HTMLTextAreaElement>, el: HTMLTextAreaElement) => void;
|
|
47
|
+
onResize?: (el: HTMLTextAreaElement, params: number[]) => void;
|
|
48
48
|
};
|
|
49
49
|
declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<unknown>>;
|
|
50
50
|
export default Textarea;
|
|
@@ -1392,7 +1392,7 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1392
1392
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1393
1393
|
while (1) switch (_context.prev = _context.next) {
|
|
1394
1394
|
case 0:
|
|
1395
|
-
if (!(_typeof(aiPredictFetchFuncAsync) === 'object')) {
|
|
1395
|
+
if (!(_typeof(aiPredictFetchFuncAsync) === 'object' && aiPredictFetchFuncMethod)) {
|
|
1396
1396
|
_context.next = 11;
|
|
1397
1397
|
break;
|
|
1398
1398
|
}
|
|
@@ -1429,8 +1429,10 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1429
1429
|
if (valRef.current) {
|
|
1430
1430
|
var canvas = document.createElement('canvas');
|
|
1431
1431
|
var context = canvas.getContext('2d');
|
|
1432
|
-
|
|
1433
|
-
|
|
1432
|
+
if (context) {
|
|
1433
|
+
context.font = "".concat(originInputComputedStyle.current.fontSize, "px ").concat(originInputComputedStyle.current.fontFamily);
|
|
1434
|
+
return context.measureText(text).width;
|
|
1435
|
+
}
|
|
1434
1436
|
}
|
|
1435
1437
|
return 0;
|
|
1436
1438
|
};
|
|
@@ -1449,7 +1451,7 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1449
1451
|
// Match exactly from the start
|
|
1450
1452
|
//----------------
|
|
1451
1453
|
var preciseMatch = function preciseMatch(input, suggestions) {
|
|
1452
|
-
if (!input) return
|
|
1454
|
+
if (!input) return [];
|
|
1453
1455
|
var filtered = suggestions.filter(function (s) {
|
|
1454
1456
|
return s.toLowerCase().startsWith(input.toLowerCase());
|
|
1455
1457
|
});
|
|
@@ -1460,7 +1462,7 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1460
1462
|
// Fuzzy matching
|
|
1461
1463
|
//----------------
|
|
1462
1464
|
var fuzzyMatch = function fuzzyMatch(input, suggestions) {
|
|
1463
|
-
if (!input) return
|
|
1465
|
+
if (!input) return [];
|
|
1464
1466
|
|
|
1465
1467
|
// Convert input to a regular expression pattern with support for arbitrary position matching
|
|
1466
1468
|
var pattern = input.split('').map(function (_char) {
|
|
@@ -1580,7 +1582,7 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1580
1582
|
onChange === null || onChange === void 0 ? void 0 : onChange(event, valRef.current, curVal);
|
|
1581
1583
|
|
|
1582
1584
|
// It fires in real time as the user enters
|
|
1583
|
-
if (typeof onInputCallback === 'function') {
|
|
1585
|
+
if (typeof onInputCallback === 'function' && event) {
|
|
1584
1586
|
var newData = onInputCallback(event, valRef.current);
|
|
1585
1587
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
1586
1588
|
}
|
|
@@ -1588,7 +1590,7 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1588
1590
|
|
|
1589
1591
|
function handleBlur(event) {
|
|
1590
1592
|
var el = event.target;
|
|
1591
|
-
var val =
|
|
1593
|
+
var val = el.value;
|
|
1592
1594
|
|
|
1593
1595
|
//----
|
|
1594
1596
|
//remove focus style
|
|
@@ -1743,8 +1745,8 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1743
1745
|
placeholder: placeholder || '',
|
|
1744
1746
|
defaultValue: defaultValue,
|
|
1745
1747
|
value: changedVal,
|
|
1746
|
-
minLength: minLength ||
|
|
1747
|
-
maxLength: maxLength ||
|
|
1748
|
+
minLength: minLength || undefined,
|
|
1749
|
+
maxLength: maxLength || undefined,
|
|
1748
1750
|
onFocus: handleFocus,
|
|
1749
1751
|
onBlur: handleBlur,
|
|
1750
1752
|
onChange: function onChange(e) {
|
|
@@ -1757,9 +1759,9 @@ var Textarea = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(fu
|
|
|
1757
1759
|
},
|
|
1758
1760
|
onKeyDown: handleKeyPressed,
|
|
1759
1761
|
onKeyUp: handleKeyUp,
|
|
1760
|
-
disabled: disabled ||
|
|
1761
|
-
required: required ||
|
|
1762
|
-
readOnly: readOnly ||
|
|
1762
|
+
disabled: disabled || undefined,
|
|
1763
|
+
required: required || undefined,
|
|
1764
|
+
readOnly: readOnly || undefined,
|
|
1763
1765
|
cols: cols || 20,
|
|
1764
1766
|
rows: rows || 2,
|
|
1765
1767
|
style: style
|
|
@@ -1582,7 +1582,7 @@ const Chatbox = (props: ChatboxProps) => {
|
|
|
1582
1582
|
}
|
|
1583
1583
|
|
|
1584
1584
|
}}
|
|
1585
|
-
onChange={(e: React.
|
|
1585
|
+
onChange={(e: React.ChangeEvent<HTMLTextAreaElement> | React.KeyboardEvent<HTMLTextAreaElement> | null, el: HTMLTextAreaElement | null, value: string) => {
|
|
1586
1586
|
args().onInputChange?.(inputContentRef.current, value);
|
|
1587
1587
|
}}
|
|
1588
1588
|
onFocus={() => {
|
|
@@ -4,7 +4,7 @@ import useComId from 'funda-utils/dist/cjs/useComId';
|
|
|
4
4
|
import { clsWrite, combinedCls } from 'funda-utils/dist/cjs/cls';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export type CheckboxOptionChangeFnType = (
|
|
7
|
+
export type CheckboxOptionChangeFnType = (e: React.ChangeEvent<HTMLInputElement> | null, val: boolean, element: HTMLElement) => void;
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
export type CheckboxProps = {
|
|
@@ -75,7 +75,7 @@ const Checkbox = forwardRef((props: CheckboxProps, externalRef: any) => {
|
|
|
75
75
|
cb?.();
|
|
76
76
|
|
|
77
77
|
if (typeof (onChange) === 'function') {
|
|
78
|
-
onChange(null, false);
|
|
78
|
+
onChange(null, false, valRef.current);
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
set: (value: boolean, cb?: any) => {
|
|
@@ -83,7 +83,7 @@ const Checkbox = forwardRef((props: CheckboxProps, externalRef: any) => {
|
|
|
83
83
|
cb?.();
|
|
84
84
|
|
|
85
85
|
if (typeof (onChange) === 'function') {
|
|
86
|
-
onChange(null, value);
|
|
86
|
+
onChange(null, value, valRef.current);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}),
|
|
@@ -111,7 +111,7 @@ const Checkbox = forwardRef((props: CheckboxProps, externalRef: any) => {
|
|
|
111
111
|
|
|
112
112
|
//
|
|
113
113
|
if (typeof (onChange) === 'function') {
|
|
114
|
-
onChange(event, _val);
|
|
114
|
+
onChange(event, _val, valRef.current);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
|
package/lib/esm/Date/index.tsx
CHANGED
|
@@ -617,11 +617,9 @@ const Date = forwardRef((props: DateProps, externalRef: any) => {
|
|
|
617
617
|
|
|
618
618
|
}
|
|
619
619
|
|
|
620
|
-
function handleChange(
|
|
621
|
-
const val = event.target.value;
|
|
620
|
+
function handleChange(e: React.ChangeEvent<HTMLInputElement> | React.KeyboardEvent<HTMLInputElement> | null, isComposition: boolean, el: HTMLInputElement, value: string) {
|
|
622
621
|
|
|
623
|
-
|
|
624
|
-
onChange?.(inputRef.current, val, isValidDate(val), getAllSplittingInputs());
|
|
622
|
+
onChange?.(inputRef.current, value, isValidDate(value), getAllSplittingInputs());
|
|
625
623
|
|
|
626
624
|
}
|
|
627
625
|
|
package/lib/esm/Input/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef, forwardRef, ChangeEvent, CompositionEvent, KeyboardEvent, FocusEvent, useImperativeHandle } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useRef, forwardRef, ChangeEvent, CompositionEvent, KeyboardEvent, FocusEvent, useImperativeHandle, MutableRefObject } from 'react';
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import useComId from 'funda-utils/dist/cjs/useComId';
|
|
@@ -22,20 +22,20 @@ export type InputProps = {
|
|
|
22
22
|
label?: React.ReactNode | string;
|
|
23
23
|
units?: React.ReactNode | string;
|
|
24
24
|
name?: string;
|
|
25
|
-
step?:
|
|
26
|
-
min?:
|
|
27
|
-
max?:
|
|
28
|
-
src?:
|
|
29
|
-
size?:
|
|
30
|
-
minLength?:
|
|
31
|
-
maxLength?:
|
|
32
|
-
alt?:
|
|
25
|
+
step?: string | number;
|
|
26
|
+
min?: string | number;
|
|
27
|
+
max?: string | number;
|
|
28
|
+
src?: string;
|
|
29
|
+
size?: string | number;
|
|
30
|
+
minLength?: string | number;
|
|
31
|
+
maxLength?: string | number;
|
|
32
|
+
alt?: string;
|
|
33
33
|
inputMode?: "search" | "text" | "email" | "tel" | "url" | "none" | "numeric" | "decimal" | undefined;
|
|
34
|
-
disabled?:
|
|
35
|
-
required?:
|
|
36
|
-
readOnly?:
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
required?: boolean;
|
|
36
|
+
readOnly?: boolean;
|
|
37
37
|
placeholder?: string;
|
|
38
|
-
pattern?:
|
|
38
|
+
pattern?: string;
|
|
39
39
|
iconLeft?: React.ReactNode | string;
|
|
40
40
|
iconRight?: React.ReactNode | string;
|
|
41
41
|
appendControl?: React.ReactNode;
|
|
@@ -44,7 +44,7 @@ export type InputProps = {
|
|
|
44
44
|
aiPredictConfirmKey?: Array<string[]>;
|
|
45
45
|
aiPredictFetchFuncAsync?: any;
|
|
46
46
|
aiPredictFetchFuncMethod?: string;
|
|
47
|
-
aiPredictFetchFuncMethodParams?:
|
|
47
|
+
aiPredictFetchFuncMethodParams?: (string | number)[];
|
|
48
48
|
aiPredictFetchCallback?: (data: any) => void;
|
|
49
49
|
/** -- */
|
|
50
50
|
id?: string;
|
|
@@ -54,19 +54,17 @@ export type InputProps = {
|
|
|
54
54
|
spellCheck?: boolean;
|
|
55
55
|
tabIndex?: number;
|
|
56
56
|
[key: `data-${string}`]: string | undefined;
|
|
57
|
-
onChangeCallback?: (e:
|
|
58
|
-
onInputCallback?: (e:
|
|
59
|
-
onKeyPressedCallback?: (e:
|
|
60
|
-
onChange?: (e:
|
|
61
|
-
onBlur?: (e:
|
|
62
|
-
onFocus?: (e:
|
|
63
|
-
onPressEnter?: (e:
|
|
64
|
-
onKeyDown?: (e:
|
|
65
|
-
onKeyUp?: (e:
|
|
66
|
-
|
|
57
|
+
onChangeCallback?: (e: ChangeEvent<HTMLInputElement> | FocusEvent<HTMLInputElement>, el: HTMLInputElement) => string | void;
|
|
58
|
+
onInputCallback?: (e: ChangeEvent<HTMLInputElement>, el: HTMLInputElement) => string | void;
|
|
59
|
+
onKeyPressedCallback?: (e: KeyboardEvent<HTMLInputElement>, el: HTMLInputElement) => string | void;
|
|
60
|
+
onChange?: (e: ChangeEvent<HTMLInputElement> | KeyboardEvent<HTMLInputElement> | null, isComposition: boolean, el: HTMLInputElement, value: string) => void;
|
|
61
|
+
onBlur?: (e: FocusEvent<HTMLInputElement>, param: boolean, el: HTMLInputElement) => void;
|
|
62
|
+
onFocus?: (e: FocusEvent<HTMLInputElement>, param: boolean, el: HTMLInputElement) => void;
|
|
63
|
+
onPressEnter?: (e: KeyboardEvent<HTMLInputElement>, el: HTMLInputElement) => void;
|
|
64
|
+
onKeyDown?: (e: KeyboardEvent<HTMLInputElement>, el: HTMLInputElement) => void;
|
|
65
|
+
onKeyUp?: (e: KeyboardEvent<HTMLInputElement>, el: HTMLInputElement) => void;
|
|
67
66
|
};
|
|
68
67
|
|
|
69
|
-
|
|
70
68
|
const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
71
69
|
const {
|
|
72
70
|
contentRef,
|
|
@@ -127,8 +125,8 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
127
125
|
|
|
128
126
|
const uniqueID = useComId();
|
|
129
127
|
const idRes = id || uniqueID;
|
|
130
|
-
const rootRef = useRef<
|
|
131
|
-
const valRef = useRef<
|
|
128
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
129
|
+
const valRef = useRef<HTMLInputElement | null>(null);
|
|
132
130
|
const typeRes = typeof (type) === 'undefined' ? 'text' : type;
|
|
133
131
|
const [onComposition, setOnComposition] = useState<boolean>(false);
|
|
134
132
|
const [changedVal, setChangedVal] = useState<string>(value || '');
|
|
@@ -140,15 +138,15 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
140
138
|
const [currentSuggestion, setCurrentSuggestion] = useState<string>('');
|
|
141
139
|
const [tempMatchedSuggestion, setTempMatchedSuggestion] = useState<string[]>([]);
|
|
142
140
|
const [textWidth, setTextWidth] = useState<number>(0);
|
|
143
|
-
const aiInputRef = useRef<
|
|
144
|
-
const originInputComputedStyle = useRef<Record<string,
|
|
141
|
+
const aiInputRef = useRef<HTMLDivElement>(null);
|
|
142
|
+
const originInputComputedStyle = useRef<Record<string, string | number>>({
|
|
145
143
|
fontSize: 16,
|
|
146
144
|
fontFamily: 'inherit',
|
|
147
145
|
letterSpacing: 'normal',
|
|
148
146
|
textTop: 10
|
|
149
147
|
});
|
|
150
148
|
const [hasErr, setHasErr] = useState<boolean>(false);
|
|
151
|
-
const currentSuggestionIndex =
|
|
149
|
+
const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState<number>(0);
|
|
152
150
|
|
|
153
151
|
|
|
154
152
|
|
|
@@ -158,20 +156,20 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
158
156
|
const [suggestions, setSuggestions] = useState<string[]>([]);
|
|
159
157
|
|
|
160
158
|
//performance
|
|
161
|
-
const handleChangeSuggestionsFetchSafe = useDebounce((e:
|
|
162
|
-
const _oparams:
|
|
163
|
-
const _params:
|
|
159
|
+
const handleChangeSuggestionsFetchSafe = useDebounce((e: ChangeEvent<HTMLInputElement>, curVal: string) => {
|
|
160
|
+
const _oparams: (string | number)[] = aiPredictFetchFuncMethodParams || [];
|
|
161
|
+
const _params: (string | number)[] = _oparams.map((item: string | number) => item !== '$QUERY_STRING' ? item : curVal);
|
|
164
162
|
fetchSuggestionsData((_params).join(',')).then((resSuggestions: string[]) => {
|
|
165
163
|
handleInputAiPredictChange(curVal, resSuggestions);
|
|
166
164
|
});
|
|
167
165
|
}, 350, []);
|
|
168
166
|
|
|
169
|
-
async function fetchSuggestionsData(params:
|
|
167
|
+
async function fetchSuggestionsData(params: string): Promise<string[]> {
|
|
170
168
|
|
|
171
169
|
if (typeof aiPredictFetchFuncAsync === 'object') {
|
|
172
170
|
|
|
173
|
-
const response:
|
|
174
|
-
let _ORGIN_DATA = response.data;
|
|
171
|
+
const response: { data: unknown } = await aiPredictFetchFuncAsync[`${aiPredictFetchFuncMethod}`](...params.split(','));
|
|
172
|
+
let _ORGIN_DATA: unknown = response.data;
|
|
175
173
|
|
|
176
174
|
// reset data structure
|
|
177
175
|
if (typeof (aiPredictFetchCallback) === 'function') {
|
|
@@ -185,11 +183,13 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
185
183
|
_ORGIN_DATA = [];
|
|
186
184
|
}
|
|
187
185
|
|
|
186
|
+
// Type assertion since we've verified it's an array
|
|
187
|
+
const suggestionsArray = _ORGIN_DATA as string[];
|
|
188
188
|
|
|
189
189
|
//
|
|
190
|
-
setSuggestions(
|
|
190
|
+
setSuggestions(suggestionsArray);
|
|
191
191
|
|
|
192
|
-
return
|
|
192
|
+
return suggestionsArray;
|
|
193
193
|
} else {
|
|
194
194
|
return [];
|
|
195
195
|
}
|
|
@@ -204,9 +204,11 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
204
204
|
const calculateTextWidth = (text: string) => {
|
|
205
205
|
if (valRef.current) {
|
|
206
206
|
const canvas = document.createElement('canvas');
|
|
207
|
-
const context:
|
|
208
|
-
context
|
|
209
|
-
|
|
207
|
+
const context: CanvasRenderingContext2D | null = canvas.getContext('2d');
|
|
208
|
+
if (context) {
|
|
209
|
+
context.font = `${originInputComputedStyle.current.fontSize}px ${originInputComputedStyle.current.fontFamily}`;
|
|
210
|
+
return context.measureText(text).width;
|
|
211
|
+
}
|
|
210
212
|
}
|
|
211
213
|
return 0;
|
|
212
214
|
};
|
|
@@ -227,7 +229,7 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
227
229
|
|
|
228
230
|
// Match exactly from the start
|
|
229
231
|
//----------------
|
|
230
|
-
const preciseMatch = (input:
|
|
232
|
+
const preciseMatch = (input: string, suggestions: string[]) => {
|
|
231
233
|
if (!input) return '';
|
|
232
234
|
|
|
233
235
|
const filtered = suggestions.filter(s =>
|
|
@@ -241,7 +243,7 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
241
243
|
|
|
242
244
|
// Fuzzy matching
|
|
243
245
|
//----------------
|
|
244
|
-
const fuzzyMatch = (input:
|
|
246
|
+
const fuzzyMatch = (input: string, suggestions: string[]) => {
|
|
245
247
|
if (!input) return '';
|
|
246
248
|
|
|
247
249
|
// Convert input to a regular expression pattern with support for arbitrary position matching
|
|
@@ -312,17 +314,21 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
312
314
|
getLatestVal: () => {
|
|
313
315
|
return changedVal || '';
|
|
314
316
|
},
|
|
315
|
-
clear: (cb?:
|
|
317
|
+
clear: (cb?: () => void) => {
|
|
316
318
|
setChangedVal('');
|
|
317
319
|
cb?.();
|
|
318
320
|
|
|
319
|
-
|
|
321
|
+
if (valRef.current) {
|
|
322
|
+
onChange?.(null, onComposition, valRef.current, '');
|
|
323
|
+
}
|
|
320
324
|
},
|
|
321
|
-
set: (value: string, cb?:
|
|
325
|
+
set: (value: string, cb?: () => void) => {
|
|
322
326
|
setChangedVal(`${value}`);
|
|
323
327
|
cb?.();
|
|
324
328
|
|
|
325
|
-
|
|
329
|
+
if (valRef.current) {
|
|
330
|
+
onChange?.(null, onComposition, valRef.current, `${value}`);
|
|
331
|
+
}
|
|
326
332
|
},
|
|
327
333
|
aiPredictReset: () => {
|
|
328
334
|
setTimeout(() => { // Avoid conflicts with other asynchronous states, resulting in invalid clearing
|
|
@@ -333,7 +339,7 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
333
339
|
[contentRef, onComposition, changedVal],
|
|
334
340
|
);
|
|
335
341
|
|
|
336
|
-
const propExist = (p:
|
|
342
|
+
const propExist = (p: unknown) => {
|
|
337
343
|
return typeof p !== 'undefined' && p !== null && p !== '';
|
|
338
344
|
};
|
|
339
345
|
|
|
@@ -351,7 +357,9 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
351
357
|
rootRef.current?.classList.add('focus');
|
|
352
358
|
|
|
353
359
|
//
|
|
354
|
-
|
|
360
|
+
if (valRef.current) {
|
|
361
|
+
onFocus?.(event, onComposition, valRef.current);
|
|
362
|
+
}
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
function handleChange(event: ChangeEvent<HTMLInputElement> | KeyboardEvent<HTMLInputElement> | null, curVal: string) {
|
|
@@ -365,11 +373,13 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
365
373
|
}
|
|
366
374
|
|
|
367
375
|
//
|
|
368
|
-
|
|
376
|
+
if (valRef.current) {
|
|
377
|
+
onChange?.(event, onComposition, valRef.current, curVal);
|
|
378
|
+
}
|
|
369
379
|
|
|
370
380
|
// It fires in real time as the user enters
|
|
371
|
-
if (typeof (onInputCallback) === 'function') {
|
|
372
|
-
const newData:
|
|
381
|
+
if (typeof (onInputCallback) === 'function' && event && valRef.current) {
|
|
382
|
+
const newData: string | void = onInputCallback(event as ChangeEvent<HTMLInputElement>, valRef.current);
|
|
373
383
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
374
384
|
}
|
|
375
385
|
|
|
@@ -388,11 +398,13 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
388
398
|
}
|
|
389
399
|
|
|
390
400
|
//
|
|
391
|
-
|
|
401
|
+
if (valRef.current) {
|
|
402
|
+
onBlur?.(event, onComposition, valRef.current);
|
|
403
|
+
}
|
|
392
404
|
|
|
393
405
|
// It fires when focus is lost
|
|
394
|
-
if (typeof (onChangeCallback) === 'function') {
|
|
395
|
-
const newData:
|
|
406
|
+
if (typeof (onChangeCallback) === 'function' && valRef.current) {
|
|
407
|
+
const newData: string | void = onChangeCallback(event, valRef.current);
|
|
396
408
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
397
409
|
}
|
|
398
410
|
}
|
|
@@ -400,17 +412,21 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
400
412
|
|
|
401
413
|
function handleKeyPressed(event: KeyboardEvent<HTMLInputElement>) {
|
|
402
414
|
|
|
403
|
-
|
|
415
|
+
if (valRef.current) {
|
|
416
|
+
onKeyDown?.(event, valRef.current);
|
|
417
|
+
}
|
|
404
418
|
|
|
405
|
-
if (typeof (onKeyPressedCallback) === 'function') {
|
|
406
|
-
const newData:
|
|
419
|
+
if (typeof (onKeyPressedCallback) === 'function' && valRef.current) {
|
|
420
|
+
const newData: string | void = onKeyPressedCallback(event, valRef.current);
|
|
407
421
|
if (newData) setChangedVal(newData); // Avoid the error "react checkbox changing an uncontrolled input to be controlled"
|
|
408
422
|
}
|
|
409
423
|
|
|
410
424
|
|
|
411
425
|
if (event.key === 'Enter' || event.key === 'NumpadEnter' ) {
|
|
412
426
|
// DO NOT USE "preventDefault()"
|
|
413
|
-
|
|
427
|
+
if (valRef.current) {
|
|
428
|
+
onPressEnter?.(event, valRef.current);
|
|
429
|
+
}
|
|
414
430
|
}
|
|
415
431
|
|
|
416
432
|
|
|
@@ -420,7 +436,7 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
420
436
|
const keyBindings: Array<string[]> = aiPredictConfirmKey;
|
|
421
437
|
// The parameter 'registerKeyEvents' is an array, and each element is an object
|
|
422
438
|
// eg. { keys: ["Control", "S"], action: () => { console.log("Ctrl+S"); } }
|
|
423
|
-
const registerKeyEvents:
|
|
439
|
+
const registerKeyEvents: Array<{ keys: string[]; action: () => void }> = keyBindings.map((s: string[]) => {
|
|
424
440
|
return {
|
|
425
441
|
keys: s,
|
|
426
442
|
action: () => {
|
|
@@ -429,7 +445,7 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
429
445
|
};
|
|
430
446
|
});
|
|
431
447
|
|
|
432
|
-
registerKeyEvents.forEach((binding:
|
|
448
|
+
registerKeyEvents.forEach((binding: { keys: string[]; action: () => void }) => {
|
|
433
449
|
const keysPressed = binding.keys.every((key: string) =>
|
|
434
450
|
key === "Shift" ? event.shiftKey :
|
|
435
451
|
key === "Control" ? event.ctrlKey :
|
|
@@ -446,13 +462,13 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
446
462
|
|
|
447
463
|
// switch result of suggestions
|
|
448
464
|
if (event.code === 'ArrowUp') {
|
|
449
|
-
|
|
465
|
+
setCurrentSuggestionIndex((prev) => (prev - 1 + tempMatchedSuggestion.length) % tempMatchedSuggestion.length);
|
|
450
466
|
}
|
|
451
467
|
|
|
452
468
|
if (event.code === 'ArrowDown') {
|
|
453
|
-
|
|
469
|
+
setCurrentSuggestionIndex((prev) => (prev + 1) % tempMatchedSuggestion.length);
|
|
454
470
|
}
|
|
455
|
-
setCurrentSuggestion(tempMatchedSuggestion[currentSuggestionIndex
|
|
471
|
+
setCurrentSuggestion(tempMatchedSuggestion[currentSuggestionIndex] || '');
|
|
456
472
|
|
|
457
473
|
}
|
|
458
474
|
|
|
@@ -460,7 +476,9 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
460
476
|
}
|
|
461
477
|
|
|
462
478
|
function handleKeyUp(event: KeyboardEvent<HTMLInputElement>) {
|
|
463
|
-
|
|
479
|
+
if (valRef.current) {
|
|
480
|
+
onKeyUp?.(event, valRef.current);
|
|
481
|
+
}
|
|
464
482
|
}
|
|
465
483
|
|
|
466
484
|
useEffect(() => {
|
|
@@ -539,24 +557,24 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
539
557
|
)}
|
|
540
558
|
id={idRes}
|
|
541
559
|
name={name}
|
|
542
|
-
step={step ||
|
|
543
|
-
min={min ||
|
|
544
|
-
max={max ||
|
|
545
|
-
src={src ||
|
|
546
|
-
size={size
|
|
547
|
-
alt={alt ||
|
|
548
|
-
inputMode={inputMode ||
|
|
549
|
-
pattern={pattern ||
|
|
560
|
+
step={step || undefined}
|
|
561
|
+
min={min || undefined}
|
|
562
|
+
max={max || undefined}
|
|
563
|
+
src={src || undefined}
|
|
564
|
+
size={typeof size === 'number' ? size : undefined}
|
|
565
|
+
alt={alt || undefined}
|
|
566
|
+
inputMode={inputMode || undefined}
|
|
567
|
+
pattern={pattern || undefined}
|
|
550
568
|
placeholder={placeholder || ''}
|
|
551
569
|
value={changedVal}
|
|
552
|
-
minLength={minLength
|
|
553
|
-
maxLength={maxLength
|
|
570
|
+
minLength={typeof minLength === 'number' ? minLength : undefined}
|
|
571
|
+
maxLength={typeof maxLength === 'number' ? maxLength : undefined}
|
|
554
572
|
autoComplete={typeof autoComplete === 'undefined' ? 'on' : autoComplete}
|
|
555
573
|
autoCapitalize={typeof autoCapitalize === 'undefined' ? 'off' : autoCapitalize}
|
|
556
574
|
spellCheck={typeof spellCheck === 'undefined' ? false : spellCheck}
|
|
557
575
|
onFocus={handleFocus}
|
|
558
576
|
onBlur={handleBlur}
|
|
559
|
-
onChange={(e:
|
|
577
|
+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
560
578
|
handleChange(e, e.target.value);
|
|
561
579
|
|
|
562
580
|
// AI Predict
|
|
@@ -570,9 +588,9 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
570
588
|
onCompositionStart={handleComposition}
|
|
571
589
|
onCompositionUpdate={handleComposition}
|
|
572
590
|
onCompositionEnd={handleComposition}
|
|
573
|
-
disabled={disabled ||
|
|
574
|
-
required={required ||
|
|
575
|
-
readOnly={readOnly ||
|
|
591
|
+
disabled={disabled || undefined}
|
|
592
|
+
required={required || undefined}
|
|
593
|
+
readOnly={readOnly || undefined}
|
|
576
594
|
style={style}
|
|
577
595
|
{...attributes}
|
|
578
596
|
/>
|
|
@@ -586,13 +604,13 @@ const Input = forwardRef((props: InputProps, externalRef: any) => {
|
|
|
586
604
|
className="position-absolute z-1"
|
|
587
605
|
data-ai="predict"
|
|
588
606
|
style={{
|
|
589
|
-
left: `${originInputComputedStyle.current.fontSize + textWidth}px`,
|
|
590
|
-
top: originInputComputedStyle.current.textTop + 'px',
|
|
607
|
+
left: `${(typeof originInputComputedStyle.current.fontSize === 'number' ? originInputComputedStyle.current.fontSize : 16) + textWidth}px`,
|
|
608
|
+
top: (typeof originInputComputedStyle.current.textTop === 'number' ? originInputComputedStyle.current.textTop : 10) + 'px',
|
|
591
609
|
color: `rgba(${aiPredictRemainingTextRGB[0]}, ${aiPredictRemainingTextRGB[1]}, ${aiPredictRemainingTextRGB[2]}, ${calculateOpacity()})`,
|
|
592
610
|
pointerEvents: 'none',
|
|
593
|
-
fontSize: originInputComputedStyle.current.fontSize + 'px',
|
|
594
|
-
fontFamily: originInputComputedStyle.current.fontFamily,
|
|
595
|
-
letterSpacing: originInputComputedStyle.current.letterSpacing
|
|
611
|
+
fontSize: (typeof originInputComputedStyle.current.fontSize === 'number' ? originInputComputedStyle.current.fontSize : 16) + 'px',
|
|
612
|
+
fontFamily: typeof originInputComputedStyle.current.fontFamily === 'string' ? originInputComputedStyle.current.fontFamily : 'inherit',
|
|
613
|
+
letterSpacing: typeof originInputComputedStyle.current.letterSpacing === 'string' ? originInputComputedStyle.current.letterSpacing : 'normal'
|
|
596
614
|
}}
|
|
597
615
|
>
|
|
598
616
|
{remainingText}
|
|
@@ -45,7 +45,7 @@ export type NumberInputProps = {
|
|
|
45
45
|
style?: React.CSSProperties;
|
|
46
46
|
tabIndex?: number;
|
|
47
47
|
[key: `data-${string}`]: string | undefined;
|
|
48
|
-
onChange?: (e: any, el:
|
|
48
|
+
onChange?: (e: any, el: HTMLElement, val: number) => void;
|
|
49
49
|
onBlur?: (e: any, el: any) => void;
|
|
50
50
|
onFocus?: (e: any, el: any) => void;
|
|
51
51
|
|