@danikokonn/yarik-frontend-lib 2.0.58-test13 → 2.0.58-test14
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichFilterTextField.d.ts","sourceRoot":"","sources":["../../../src/components/RichFilterTextField/RichFilterTextField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAUf,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAKlE,QAAA,MAAM,mBAAmB,GAAI,4HAS1B,wBAAwB,
|
|
1
|
+
{"version":3,"file":"RichFilterTextField.d.ts","sourceRoot":"","sources":["../../../src/components/RichFilterTextField/RichFilterTextField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAUf,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAKlE,QAAA,MAAM,mBAAmB,GAAI,4HAS1B,wBAAwB,sBAkQ1B,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -15,21 +15,17 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
15
15
|
const instant = _instant ?? true;
|
|
16
16
|
const [searchHist, setSearchHist] = useState(filterExprHist);
|
|
17
17
|
// const [inputAnchor, setInputAnchor] = useState<HTMLDivElement | null>(null);
|
|
18
|
-
const [
|
|
19
|
-
// const [cursorPos, setCursorPos] = useState<number | null>(null);
|
|
18
|
+
const [cursorPos, setCursorPos] = useState(null);
|
|
20
19
|
// const [currentHintOptions, setCurrentHintOptions] = useState<
|
|
21
20
|
// Map<string, string | undefined>
|
|
22
21
|
// >(() => new Map());
|
|
23
22
|
const [focusIdx, setFocusIdx] = useState(0);
|
|
24
23
|
const inputRef = useRef(null);
|
|
25
24
|
const textFieldRef = useRef(null);
|
|
26
|
-
const
|
|
27
|
-
console.log(cursorPos);
|
|
28
|
-
const currentHintOptions = (cursorPos != null && hintMenuOpen
|
|
25
|
+
const currentHintOptions = (cursorPos != null
|
|
29
26
|
? getHints(search, cursorPos, fields, operators)
|
|
30
27
|
: null) ?? new Map();
|
|
31
|
-
|
|
32
|
-
const inputAnchor = currentHintOptions?.size > 0 && hintMenuOpen ? textFieldRef.current : null;
|
|
28
|
+
const inputAnchor = currentHintOptions?.size > 0 ? textFieldRef.current : null;
|
|
33
29
|
useEffect(() => {
|
|
34
30
|
if (cursorPos == null)
|
|
35
31
|
return;
|
|
@@ -45,6 +41,12 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
45
41
|
// inputRef.current.selectionEnd = cursorPos;
|
|
46
42
|
// }
|
|
47
43
|
// }, [cursorPos]);
|
|
44
|
+
if (cursorPos != null &&
|
|
45
|
+
inputRef.current &&
|
|
46
|
+
cursorPos !== inputRef.current.selectionStart) {
|
|
47
|
+
inputRef.current.selectionStart = cursorPos;
|
|
48
|
+
inputRef.current.selectionEnd = cursorPos;
|
|
49
|
+
}
|
|
48
50
|
// Принудительное изменение состояния, если изменился пропс
|
|
49
51
|
// useEffect(() => setSearch(filterExpr), [filterExpr]);
|
|
50
52
|
const handleChange = (value, _idx) => {
|
|
@@ -65,11 +67,12 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
65
67
|
}
|
|
66
68
|
const { newSearch, newPos } = insertInStrPos(search, cursorPos, hint, fields);
|
|
67
69
|
handleChange(newSearch);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
|
|
71
|
+
setCursorPos(newPos - 1);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
setCursorPos(newPos);
|
|
75
|
+
}
|
|
73
76
|
};
|
|
74
77
|
const handleKeyUp = (e) => {
|
|
75
78
|
switch (e.code) {
|
|
@@ -95,13 +98,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
95
98
|
case "Escape":
|
|
96
99
|
case "Tab": {
|
|
97
100
|
// setInputAnchor(null);
|
|
98
|
-
|
|
99
|
-
setHintMenuOpen(false);
|
|
101
|
+
setCursorPos(null);
|
|
100
102
|
break;
|
|
101
103
|
}
|
|
102
104
|
default: {
|
|
103
|
-
|
|
104
|
-
setHintMenuOpen(true);
|
|
105
|
+
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
};
|
|
@@ -111,8 +112,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
111
112
|
case "ArrowRight":
|
|
112
113
|
case "Space":
|
|
113
114
|
case "Backspace": {
|
|
114
|
-
|
|
115
|
-
setHintMenuOpen(true);
|
|
115
|
+
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
case "ArrowDown": {
|
|
@@ -146,13 +146,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
146
146
|
case "Escape":
|
|
147
147
|
case "Tab": {
|
|
148
148
|
// setInputAnchor(null);
|
|
149
|
-
|
|
150
|
-
setHintMenuOpen(false);
|
|
149
|
+
setCursorPos(null);
|
|
151
150
|
break;
|
|
152
151
|
}
|
|
153
152
|
default: {
|
|
154
|
-
|
|
155
|
-
setHintMenuOpen(true);
|
|
153
|
+
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
156
154
|
}
|
|
157
155
|
}
|
|
158
156
|
};
|
|
@@ -167,8 +165,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
167
165
|
onClick: (e) => {
|
|
168
166
|
if (Object(e).target !== Object(e).currentTarget)
|
|
169
167
|
return;
|
|
170
|
-
|
|
171
|
-
setHintMenuOpen(true);
|
|
168
|
+
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
172
169
|
},
|
|
173
170
|
},
|
|
174
171
|
input: {
|
|
@@ -191,8 +188,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
191
188
|
} }),
|
|
192
189
|
React.createElement(HintOptionsMenu, { inputAnchor: inputAnchor, inputRef: inputRef, textFieldRef: textFieldRef, options: currentHintOptions, focusIdx: focusIdx, onSelectHint: insertHint, onClose: () => {
|
|
193
190
|
// setInputAnchor(null);
|
|
194
|
-
|
|
195
|
-
setHintMenuOpen(false);
|
|
191
|
+
setCursorPos(null);
|
|
196
192
|
} })));
|
|
197
193
|
};
|
|
198
194
|
export default RichFilterTextField;
|