@danikokonn/yarik-frontend-lib 2.0.58-test12 → 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,sBAuQ1B,CAAC;AAEF,eAAe,mBAAmB,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,sBAkQ1B,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -15,20 +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 [hintMenuOpen, setHintMenuOpen] = useState(false);
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 cursorPos = inputRef.current?.selectionStart;
27
- const currentHintOptions = (cursorPos != null && hintMenuOpen
25
+ const currentHintOptions = (cursorPos != null
28
26
  ? getHints(search, cursorPos, fields, operators)
29
27
  : null) ?? new Map();
30
- console.log(currentHintOptions);
31
- const inputAnchor = currentHintOptions?.size > 0 && hintMenuOpen ? textFieldRef.current : null;
28
+ const inputAnchor = currentHintOptions?.size > 0 ? textFieldRef.current : null;
32
29
  useEffect(() => {
33
30
  if (cursorPos == null)
34
31
  return;
@@ -44,6 +41,12 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
44
41
  // inputRef.current.selectionEnd = cursorPos;
45
42
  // }
46
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
+ }
47
50
  // Принудительное изменение состояния, если изменился пропс
48
51
  // useEffect(() => setSearch(filterExpr), [filterExpr]);
49
52
  const handleChange = (value, _idx) => {
@@ -64,11 +67,12 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
64
67
  }
65
68
  const { newSearch, newPos } = insertInStrPos(search, cursorPos, hint, fields);
66
69
  handleChange(newSearch);
67
- // if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
68
- // setCursorPos(newPos - 1);
69
- // } else {
70
- // setCursorPos(newPos);
71
- // }
70
+ if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
71
+ setCursorPos(newPos - 1);
72
+ }
73
+ else {
74
+ setCursorPos(newPos);
75
+ }
72
76
  };
73
77
  const handleKeyUp = (e) => {
74
78
  switch (e.code) {
@@ -94,13 +98,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
94
98
  case "Escape":
95
99
  case "Tab": {
96
100
  // setInputAnchor(null);
97
- // setCursorPos(null);
98
- setHintMenuOpen(false);
101
+ setCursorPos(null);
99
102
  break;
100
103
  }
101
104
  default: {
102
- // setCursorPos(inputRef.current?.selectionStart ?? null);
103
- setHintMenuOpen(true);
105
+ setCursorPos(inputRef.current?.selectionStart ?? null);
104
106
  }
105
107
  }
106
108
  };
@@ -110,8 +112,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
110
112
  case "ArrowRight":
111
113
  case "Space":
112
114
  case "Backspace": {
113
- // setCursorPos(inputRef.current?.selectionStart ?? null);
114
- setHintMenuOpen(true);
115
+ setCursorPos(inputRef.current?.selectionStart ?? null);
115
116
  return;
116
117
  }
117
118
  case "ArrowDown": {
@@ -145,13 +146,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
145
146
  case "Escape":
146
147
  case "Tab": {
147
148
  // setInputAnchor(null);
148
- // setCursorPos(null);
149
- setHintMenuOpen(false);
149
+ setCursorPos(null);
150
150
  break;
151
151
  }
152
152
  default: {
153
- // setCursorPos(inputRef.current?.selectionStart ?? null);
154
- setHintMenuOpen(true);
153
+ setCursorPos(inputRef.current?.selectionStart ?? null);
155
154
  }
156
155
  }
157
156
  };
@@ -166,8 +165,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
166
165
  onClick: (e) => {
167
166
  if (Object(e).target !== Object(e).currentTarget)
168
167
  return;
169
- // setCursorPos(inputRef.current?.selectionStart ?? null);
170
- setHintMenuOpen(true);
168
+ setCursorPos(inputRef.current?.selectionStart ?? null);
171
169
  },
172
170
  },
173
171
  input: {
@@ -190,8 +188,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
190
188
  } }),
191
189
  React.createElement(HintOptionsMenu, { inputAnchor: inputAnchor, inputRef: inputRef, textFieldRef: textFieldRef, options: currentHintOptions, focusIdx: focusIdx, onSelectHint: insertHint, onClose: () => {
192
190
  // setInputAnchor(null);
193
- // setCursorPos(null);
194
- setHintMenuOpen(false);
191
+ setCursorPos(null);
195
192
  } })));
196
193
  };
197
194
  export default RichFilterTextField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danikokonn/yarik-frontend-lib",
3
- "version": "2.0.58-test12",
3
+ "version": "2.0.58-test14",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "author": "",