@danikokonn/yarik-frontend-lib 2.0.58-test13 → 2.0.58-test15

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,sBAwQ1B,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,sBAuQ1B,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -15,21 +15,21 @@ 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
- 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();
28
+ console.log("######## RENDER ########");
29
+ console.log(search);
30
+ console.log(cursorPos);
31
31
  console.log(currentHintOptions);
32
- const inputAnchor = currentHintOptions?.size > 0 && hintMenuOpen ? textFieldRef.current : null;
32
+ const inputAnchor = currentHintOptions?.size > 0 ? textFieldRef.current : null;
33
33
  useEffect(() => {
34
34
  if (cursorPos == null)
35
35
  return;
@@ -45,6 +45,12 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
45
45
  // inputRef.current.selectionEnd = cursorPos;
46
46
  // }
47
47
  // }, [cursorPos]);
48
+ if (cursorPos != null &&
49
+ inputRef.current &&
50
+ cursorPos !== inputRef.current.selectionStart) {
51
+ inputRef.current.selectionStart = cursorPos;
52
+ inputRef.current.selectionEnd = cursorPos;
53
+ }
48
54
  // Принудительное изменение состояния, если изменился пропс
49
55
  // useEffect(() => setSearch(filterExpr), [filterExpr]);
50
56
  const handleChange = (value, _idx) => {
@@ -65,11 +71,12 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
65
71
  }
66
72
  const { newSearch, newPos } = insertInStrPos(search, cursorPos, hint, fields);
67
73
  handleChange(newSearch);
68
- // if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
69
- // setCursorPos(newPos - 1);
70
- // } else {
71
- // setCursorPos(newPos);
72
- // }
74
+ if (hint.includes("[") || hint.includes("(") || hint.includes("/")) {
75
+ setCursorPos(newPos - 1);
76
+ }
77
+ else {
78
+ setCursorPos(newPos);
79
+ }
73
80
  };
74
81
  const handleKeyUp = (e) => {
75
82
  switch (e.code) {
@@ -95,13 +102,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
95
102
  case "Escape":
96
103
  case "Tab": {
97
104
  // setInputAnchor(null);
98
- // setCursorPos(null);
99
- setHintMenuOpen(false);
105
+ setCursorPos(null);
100
106
  break;
101
107
  }
102
108
  default: {
103
- // setCursorPos(inputRef.current?.selectionStart ?? null);
104
- setHintMenuOpen(true);
109
+ setCursorPos(inputRef.current?.selectionStart ?? null);
105
110
  }
106
111
  }
107
112
  };
@@ -111,8 +116,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
111
116
  case "ArrowRight":
112
117
  case "Space":
113
118
  case "Backspace": {
114
- // setCursorPos(inputRef.current?.selectionStart ?? null);
115
- setHintMenuOpen(true);
119
+ setCursorPos(inputRef.current?.selectionStart ?? null);
116
120
  return;
117
121
  }
118
122
  case "ArrowDown": {
@@ -146,13 +150,11 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
146
150
  case "Escape":
147
151
  case "Tab": {
148
152
  // setInputAnchor(null);
149
- // setCursorPos(null);
150
- setHintMenuOpen(false);
153
+ setCursorPos(null);
151
154
  break;
152
155
  }
153
156
  default: {
154
- // setCursorPos(inputRef.current?.selectionStart ?? null);
155
- setHintMenuOpen(true);
157
+ setCursorPos(inputRef.current?.selectionStart ?? null);
156
158
  }
157
159
  }
158
160
  };
@@ -167,8 +169,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
167
169
  onClick: (e) => {
168
170
  if (Object(e).target !== Object(e).currentTarget)
169
171
  return;
170
- // setCursorPos(inputRef.current?.selectionStart ?? null);
171
- setHintMenuOpen(true);
172
+ setCursorPos(inputRef.current?.selectionStart ?? null);
172
173
  },
173
174
  },
174
175
  input: {
@@ -191,8 +192,7 @@ const RichFilterTextField = ({ filterExpr, filterExprHist, fields, operators, ad
191
192
  } }),
192
193
  React.createElement(HintOptionsMenu, { inputAnchor: inputAnchor, inputRef: inputRef, textFieldRef: textFieldRef, options: currentHintOptions, focusIdx: focusIdx, onSelectHint: insertHint, onClose: () => {
193
194
  // setInputAnchor(null);
194
- // setCursorPos(null);
195
- setHintMenuOpen(false);
195
+ setCursorPos(null);
196
196
  } })));
197
197
  };
198
198
  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-test13",
3
+ "version": "2.0.58-test15",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "author": "",