@danikokonn/yarik-frontend-lib 2.0.58-test19 → 2.0.58-test22
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,KAKN,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,KAKN,MAAM,OAAO,CAAC;AAUf,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAKlE,QAAA,MAAM,mBAAmB,GAAI,4HAS1B,wBAAwB,sBAwR1B,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -12,21 +12,24 @@ import { Stack } from "@mui/material";
|
|
|
12
12
|
const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, additionalComponents, instant: _instant, onChange, onSelectFromHistory, }) => {
|
|
13
13
|
const { enqueueSnackbar } = useSnackbarContext();
|
|
14
14
|
const [search, setSearch] = useState(filterExpr);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
setSearch(filterExpr);
|
|
18
|
-
prevFilterExpr.current = filterExpr;
|
|
19
|
-
}
|
|
20
|
-
const instant = _instant ?? true;
|
|
21
|
-
const [searchHist, setSearchHist] = useState(filterExprHist);
|
|
15
|
+
// const [searchHist, setSearchHist] = useState<string[]>(filterExprHist);
|
|
16
|
+
const searchHist = filterExprHist;
|
|
22
17
|
const [cursorPos, setCursorPos] = useState(null);
|
|
23
18
|
const [focusIdx, setFocusIdx] = useState(0);
|
|
24
19
|
const inputRef = useRef(null);
|
|
25
20
|
const textFieldRef = useRef(null);
|
|
21
|
+
const prevFilterExpr = useRef(filterExpr);
|
|
22
|
+
const instant = _instant ?? true;
|
|
26
23
|
const currentHintOptions = (cursorPos != null
|
|
27
24
|
? getHints(search, cursorPos, fields, operators)
|
|
28
25
|
: null) ?? new Map();
|
|
29
26
|
const inputAnchor = currentHintOptions?.size > 0 ? textFieldRef.current : null;
|
|
27
|
+
if (prevFilterExpr.current !== filterExpr && filterExpr !== search) {
|
|
28
|
+
setSearch(filterExpr);
|
|
29
|
+
setCursorPos(null);
|
|
30
|
+
setFocusIdx(0);
|
|
31
|
+
prevFilterExpr.current = filterExpr;
|
|
32
|
+
}
|
|
30
33
|
if (cursorPos != null &&
|
|
31
34
|
inputRef.current &&
|
|
32
35
|
cursorPos !== inputRef.current.selectionStart) {
|
|
@@ -38,7 +41,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
38
41
|
if (cursorPos &&
|
|
39
42
|
getHints(value, cursorPos, fields, operators) !== currentHintOptions)
|
|
40
43
|
setFocusIdx(0);
|
|
41
|
-
onChange(value
|
|
44
|
+
onChange(value /*(v: unknown) => setSearchHist(v as string[])*/);
|
|
42
45
|
};
|
|
43
46
|
const insertHint = (hint) => {
|
|
44
47
|
if (cursorPos == null)
|
|
@@ -54,7 +57,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
54
57
|
}
|
|
55
58
|
const { newSearch, newPos } = insertInStrPos(search, cursorPos, hint, fields);
|
|
56
59
|
setSearch(newSearch);
|
|
57
|
-
onChange(newSearch
|
|
60
|
+
onChange(newSearch);
|
|
58
61
|
let newCursorPos = newPos;
|
|
59
62
|
if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
|
|
60
63
|
newCursorPos--;
|
|
@@ -82,13 +85,13 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
82
85
|
insertHint(focusedHint);
|
|
83
86
|
}
|
|
84
87
|
else {
|
|
85
|
-
onChange(search
|
|
88
|
+
onChange(search);
|
|
89
|
+
inputRef.current?.blur();
|
|
86
90
|
}
|
|
87
91
|
break;
|
|
88
92
|
}
|
|
89
93
|
case "Escape":
|
|
90
94
|
case "Tab": {
|
|
91
|
-
// setInputAnchor(null);
|
|
92
95
|
setCursorPos(null);
|
|
93
96
|
break;
|
|
94
97
|
}
|
|
@@ -141,7 +144,6 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
141
144
|
}
|
|
142
145
|
case "Escape":
|
|
143
146
|
case "Tab": {
|
|
144
|
-
// setInputAnchor(null);
|
|
145
147
|
setCursorPos(null);
|
|
146
148
|
setFocusIdx(0);
|
|
147
149
|
break;
|
|
@@ -165,12 +167,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
165
167
|
getHints(e.target.value, newCursorPos, fields, operators) !==
|
|
166
168
|
currentHintOptions)
|
|
167
169
|
setFocusIdx(0);
|
|
168
|
-
},
|
|
169
|
-
// onClick={(e) => {
|
|
170
|
-
// if (e.target !== e.currentTarget) return;
|
|
171
|
-
// setCursorPos(inputRef.current?.selectionStart ?? null);
|
|
172
|
-
// }}
|
|
173
|
-
onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, slotProps: {
|
|
170
|
+
}, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, slotProps: {
|
|
174
171
|
htmlInput: {
|
|
175
172
|
onClick: (e) => {
|
|
176
173
|
if (Object(e).target !== Object(e).currentTarget)
|
|
@@ -187,7 +184,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
187
184
|
startAdornment: (React.createElement(InputAdornment, { position: "start" },
|
|
188
185
|
React.createElement(Stack, { direction: "row", sx: { alignItems: "center" } },
|
|
189
186
|
!instant && (React.createElement(IconButton, { onClick: (e) => {
|
|
190
|
-
onChange(search
|
|
187
|
+
onChange(search);
|
|
191
188
|
e.stopPropagation();
|
|
192
189
|
}, title: "\u041F\u043E\u0438\u0441\u043A" },
|
|
193
190
|
React.createElement(SearchRoundedIcon, null))),
|
|
@@ -202,7 +199,6 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
|
|
|
202
199
|
},
|
|
203
200
|
} }),
|
|
204
201
|
React.createElement(HintOptionsMenu, { inputAnchor: inputAnchor, inputRef: inputRef, textFieldRef: textFieldRef, options: currentHintOptions, focusIdx: focusIdx, onSelectHint: insertHint, onClose: () => {
|
|
205
|
-
// setInputAnchor(null);
|
|
206
202
|
setCursorPos(null);
|
|
207
203
|
setFocusIdx(0);
|
|
208
204
|
} })));
|