@danikokonn/yarik-frontend-lib 2.0.58-test1 → 2.0.58-test10
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;
|
|
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,sBAqQ1B,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -7,29 +7,35 @@ import SearchRoundedIcon from "@mui/icons-material/SearchRounded";
|
|
|
7
7
|
import HintOptionsMenu from "./HintOptionsMenu";
|
|
8
8
|
import { getHints, insertInStrPos } from "./utils";
|
|
9
9
|
import { useSnackbarContext } from "../../providers";
|
|
10
|
-
import { useDebounce } from "../../utils";
|
|
11
10
|
import FilterHistoryMenu from "./FilterHistoryMenu";
|
|
12
11
|
import { Stack } from "@mui/material";
|
|
13
12
|
const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, additionalComponents, instant: _instant, onChange, onSelectFromHistory, }) => {
|
|
14
13
|
const { enqueueSnackbar } = useSnackbarContext();
|
|
15
14
|
const [search, setSearch] = useState(filterExpr);
|
|
16
15
|
const instant = _instant ?? true;
|
|
17
|
-
useEffect(() => setSearch(filterExpr), [filterExpr]);
|
|
18
16
|
const [searchHist, setSearchHist] = useState(filterExprHist);
|
|
19
|
-
const [inputAnchor, setInputAnchor] = useState(null);
|
|
20
|
-
const [
|
|
21
|
-
const [
|
|
17
|
+
// const [inputAnchor, setInputAnchor] = useState<HTMLDivElement | null>(null);
|
|
18
|
+
const [hintMenuOpen, setHintMenuOpen] = useState(false);
|
|
19
|
+
// const [cursorPos, setCursorPos] = useState<number | null>(null);
|
|
20
|
+
// const [currentHintOptions, setCurrentHintOptions] = useState<
|
|
21
|
+
// Map<string, string | undefined>
|
|
22
|
+
// >(() => new Map());
|
|
22
23
|
const [focusIdx, setFocusIdx] = useState(0);
|
|
23
24
|
const inputRef = useRef(null);
|
|
24
25
|
const textFieldRef = useRef(null);
|
|
25
|
-
const
|
|
26
|
+
const cursorPos = inputRef.current?.selectionStart;
|
|
27
|
+
const currentHintOptions = (cursorPos != null && hintMenuOpen
|
|
28
|
+
? getHints(search, cursorPos, fields, operators)
|
|
29
|
+
: null) ?? new Map();
|
|
30
|
+
const inputAnchor = currentHintOptions?.size > 0 && hintMenuOpen ? textFieldRef.current : null;
|
|
31
|
+
useEffect(() => {
|
|
26
32
|
if (cursorPos == null)
|
|
27
33
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
if (currentHintOptions === getHints(search, cursorPos, fields, operators))
|
|
35
|
+
return;
|
|
30
36
|
setFocusIdx(0);
|
|
31
|
-
setInputAnchor(
|
|
32
|
-
},
|
|
37
|
+
// setInputAnchor(currentHintOptions?.size > 0 ? textFieldRef.current : null);
|
|
38
|
+
}, [search, cursorPos]);
|
|
33
39
|
useEffect(() => {
|
|
34
40
|
if (cursorPos == null)
|
|
35
41
|
return;
|
|
@@ -37,8 +43,9 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
37
43
|
inputRef.current.selectionStart = cursorPos;
|
|
38
44
|
inputRef.current.selectionEnd = cursorPos;
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
}, [cursorPos]);
|
|
47
|
+
// Принудительное изменение состояния, если изменился пропс
|
|
48
|
+
// useEffect(() => setSearch(filterExpr), [filterExpr]);
|
|
42
49
|
const handleChange = (value, _idx) => {
|
|
43
50
|
setSearch(value);
|
|
44
51
|
onChange(value, (v) => setSearchHist(v));
|
|
@@ -57,12 +64,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
57
64
|
}
|
|
58
65
|
const { newSearch, newPos } = insertInStrPos(search, cursorPos, hint, fields);
|
|
59
66
|
handleChange(newSearch);
|
|
60
|
-
if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
67
|
+
// if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
|
|
68
|
+
// setCursorPos(newPos - 1);
|
|
69
|
+
// } else {
|
|
70
|
+
// setCursorPos(newPos);
|
|
71
|
+
// }
|
|
66
72
|
};
|
|
67
73
|
const handleKeyUp = (e) => {
|
|
68
74
|
switch (e.code) {
|
|
@@ -87,12 +93,14 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
87
93
|
}
|
|
88
94
|
case "Escape":
|
|
89
95
|
case "Tab": {
|
|
90
|
-
setInputAnchor(null);
|
|
91
|
-
setCursorPos(null);
|
|
96
|
+
// setInputAnchor(null);
|
|
97
|
+
// setCursorPos(null);
|
|
98
|
+
setHintMenuOpen(false);
|
|
92
99
|
break;
|
|
93
100
|
}
|
|
94
101
|
default: {
|
|
95
|
-
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
102
|
+
// setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
103
|
+
setHintMenuOpen(true);
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
};
|
|
@@ -102,8 +110,8 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
102
110
|
case "ArrowRight":
|
|
103
111
|
case "Space":
|
|
104
112
|
case "Backspace": {
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
// setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
114
|
+
setHintMenuOpen(true);
|
|
107
115
|
return;
|
|
108
116
|
}
|
|
109
117
|
case "ArrowDown": {
|
|
@@ -136,12 +144,14 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
136
144
|
}
|
|
137
145
|
case "Escape":
|
|
138
146
|
case "Tab": {
|
|
139
|
-
setInputAnchor(null);
|
|
140
|
-
setCursorPos(null);
|
|
147
|
+
// setInputAnchor(null);
|
|
148
|
+
// setCursorPos(null);
|
|
149
|
+
setHintMenuOpen(false);
|
|
141
150
|
break;
|
|
142
151
|
}
|
|
143
152
|
default: {
|
|
144
|
-
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
153
|
+
// setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
154
|
+
setHintMenuOpen(true);
|
|
145
155
|
}
|
|
146
156
|
}
|
|
147
157
|
};
|
|
@@ -156,7 +166,8 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
156
166
|
onClick: (e) => {
|
|
157
167
|
if (Object(e).target !== Object(e).currentTarget)
|
|
158
168
|
return;
|
|
159
|
-
setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
169
|
+
// setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
170
|
+
setHintMenuOpen(true);
|
|
160
171
|
},
|
|
161
172
|
},
|
|
162
173
|
input: {
|
|
@@ -178,8 +189,9 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
178
189
|
},
|
|
179
190
|
} }),
|
|
180
191
|
React.createElement(HintOptionsMenu, { inputAnchor: inputAnchor, inputRef: inputRef, textFieldRef: textFieldRef, options: currentHintOptions, focusIdx: focusIdx, onSelectHint: insertHint, onClose: () => {
|
|
181
|
-
setInputAnchor(null);
|
|
182
|
-
setCursorPos(null);
|
|
192
|
+
// setInputAnchor(null);
|
|
193
|
+
// setCursorPos(null);
|
|
194
|
+
setHintMenuOpen(false);
|
|
183
195
|
} })));
|
|
184
196
|
};
|
|
185
197
|
export default RichFilterTextField;
|