intelicoreact 1.1.48 → 1.1.50

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.
@@ -83,30 +83,20 @@ var InputAddress = function InputAddress(_ref) {
83
83
  isLoading = _useState8[0],
84
84
  setIsLoading = _useState8[1];
85
85
 
86
- var _useState9 = (0, _react.useState)(false),
86
+ var _useState9 = (0, _react.useState)(null),
87
87
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
88
- internalError = _useState10[0],
89
- setInternalError = _useState10[1];
88
+ hightlightedIndex = _useState10[0],
89
+ setHightlightedIndex = _useState10[1];
90
90
 
91
91
  var _useState11 = (0, _react.useState)(false),
92
92
  _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
93
- isSelectedFromList = _useState12[0],
94
- setIsSelectedFromList = _useState12[1];
93
+ isFocused = _useState12[0],
94
+ setIsFocused = _useState12[1];
95
95
 
96
- var _useState13 = (0, _react.useState)(null),
96
+ var _useState13 = (0, _react.useState)(false),
97
97
  _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
98
- hightlightedIndex = _useState14[0],
99
- setHightlightedIndex = _useState14[1];
100
-
101
- var _useState15 = (0, _react.useState)(false),
102
- _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
103
- isFocused = _useState16[0],
104
- setIsFocused = _useState16[1];
105
-
106
- var _useState17 = (0, _react.useState)(false),
107
- _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
108
- isListVisible = _useState18[0],
109
- setIsListVisible = _useState18[1];
98
+ isListVisible = _useState14[0],
99
+ setIsListVisible = _useState14[1];
110
100
 
111
101
  var isWrongAddress = (0, _react.useMemo)(function () {
112
102
  var _query$street;
@@ -120,7 +110,6 @@ var InputAddress = function InputAddress(_ref) {
120
110
 
121
111
  var setQueryAsItem = function setQueryAsItem(e, item) {
122
112
  if (e) e === null || e === void 0 ? void 0 : e.stopPropagation();
123
- setIsSelectedFromList(true);
124
113
  setTimeout(function () {
125
114
  return setQuery(item);
126
115
  }, 1);
@@ -161,19 +150,18 @@ var InputAddress = function InputAddress(_ref) {
161
150
  setHightlightedIndex(null);
162
151
  inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.blur();
163
152
  } else {
164
- var _listRef$current, _listRef$current$getB, _listRef$current2, _listRef$current2$get, _listRef$current3, _newHightlightedEleme;
153
+ var _listRef$current, _listRef$current$getB, _listRef$current2, _newHightlightedEleme;
165
154
 
166
- var prevHightlightedIndex = hightlightedIndex;
167
155
  var newHightlightedIndex = null;
168
156
  var listItemsElements = document.getElementsByClassName('input-address__list--item');
169
- var listTop = listRef === null || listRef === void 0 ? void 0 : (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : (_listRef$current$getB = _listRef$current.getBoundingClientRect()) === null || _listRef$current$getB === void 0 ? void 0 : _listRef$current$getB.top;
170
- var listHeight = listRef === null || listRef === void 0 ? void 0 : (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : (_listRef$current2$get = _listRef$current2.getBoundingClientRect()) === null || _listRef$current2$get === void 0 ? void 0 : _listRef$current2$get.height;
171
- var listScrollTop = (listRef === null || listRef === void 0 ? void 0 : (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.scrollTop) || 0;
157
+ var listHeight = listRef === null || listRef === void 0 ? void 0 : (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : (_listRef$current$getB = _listRef$current.getBoundingClientRect()) === null || _listRef$current$getB === void 0 ? void 0 : _listRef$current$getB.height;
158
+ var listScrollTop = (listRef === null || listRef === void 0 ? void 0 : (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.scrollTop) || 0;
159
+ var lastItemIndex = parseInt(listItems === null || listItems === void 0 ? void 0 : listItems.length) - 1;
172
160
  /** Arrows Controllers **/
173
161
 
174
162
  if (keyCode === 40) {
175
163
  // Down Key Controller
176
- if (hightlightedIndex === null || hightlightedIndex === (listItems === null || listItems === void 0 ? void 0 : listItems.length) - 1) {
164
+ if (hightlightedIndex === null || hightlightedIndex === lastItemIndex) {
177
165
  newHightlightedIndex = 0;
178
166
  } else if (hightlightedIndex + 1 < (listItems === null || listItems === void 0 ? void 0 : listItems.length)) {
179
167
  newHightlightedIndex = hightlightedIndex + 1;
@@ -181,7 +169,7 @@ var InputAddress = function InputAddress(_ref) {
181
169
  } else if (keyCode === 38) {
182
170
  // Up Key Controller
183
171
  if (hightlightedIndex === null || hightlightedIndex === 0) {
184
- newHightlightedIndex = (listItems === null || listItems === void 0 ? void 0 : listItems.length) - 1;
172
+ newHightlightedIndex = lastItemIndex;
185
173
  } else if (hightlightedIndex - 1 >= 0) {
186
174
  newHightlightedIndex = hightlightedIndex - 1;
187
175
  }
@@ -194,23 +182,23 @@ var InputAddress = function InputAddress(_ref) {
194
182
 
195
183
  if (newHightlightedElementTopInList + newHightlightedElementHeight > listScrollTop + listHeight) {
196
184
  if (Math.abs(newHightlightedElementTopInList + newHightlightedElementHeight - (listScrollTop + listHeight)) <= newHightlightedElementHeight) {
197
- var _listRef$current4;
185
+ var _listRef$current3;
198
186
 
199
- listRef === null || listRef === void 0 ? void 0 : (_listRef$current4 = listRef.current) === null || _listRef$current4 === void 0 ? void 0 : _listRef$current4.scrollTo(0, listScrollTop + newHightlightedElementHeight);
187
+ listRef === null || listRef === void 0 ? void 0 : (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.scrollTo(0, listScrollTop + newHightlightedElementHeight);
200
188
  } else {
201
- var _listRef$current5;
189
+ var _listRef$current4;
202
190
 
203
- listRef === null || listRef === void 0 ? void 0 : (_listRef$current5 = listRef.current) === null || _listRef$current5 === void 0 ? void 0 : _listRef$current5.scrollTo(0, newHightlightedElementTopInList);
191
+ listRef === null || listRef === void 0 ? void 0 : (_listRef$current4 = listRef.current) === null || _listRef$current4 === void 0 ? void 0 : _listRef$current4.scrollTo(0, newHightlightedElementTopInList);
204
192
  }
205
193
  } else if (newHightlightedElementTopInList < listScrollTop) {
206
194
  if (Math.abs(newHightlightedElementTopInList - listScrollTop) < newHightlightedElementHeight) {
207
- var _listRef$current6;
195
+ var _listRef$current5;
208
196
 
209
- listRef === null || listRef === void 0 ? void 0 : (_listRef$current6 = listRef.current) === null || _listRef$current6 === void 0 ? void 0 : _listRef$current6.scrollTo(0, listScrollTop - newHightlightedElementHeight);
197
+ listRef === null || listRef === void 0 ? void 0 : (_listRef$current5 = listRef.current) === null || _listRef$current5 === void 0 ? void 0 : _listRef$current5.scrollTo(0, listScrollTop - newHightlightedElementHeight);
210
198
  } else {
211
- var _listRef$current7;
199
+ var _listRef$current6;
212
200
 
213
- listRef === null || listRef === void 0 ? void 0 : (_listRef$current7 = listRef.current) === null || _listRef$current7 === void 0 ? void 0 : _listRef$current7.scrollTo(0, newHightlightedElementTopInList);
201
+ listRef === null || listRef === void 0 ? void 0 : (_listRef$current6 = listRef.current) === null || _listRef$current6 === void 0 ? void 0 : _listRef$current6.scrollTo(0, newHightlightedElementTopInList);
214
202
  }
215
203
  }
216
204
 
@@ -220,23 +208,6 @@ var InputAddress = function InputAddress(_ref) {
220
208
 
221
209
  var onChangeInternal = function onChangeInternal(value) {
222
210
  setQuery(value);
223
- setIsSelectedFromList(false);
224
- };
225
-
226
- var onFocus = function onFocus() {
227
- setIsFocused(true);
228
- setInternalError(false);
229
- };
230
-
231
- var onBlur = function onBlur() {
232
- if (typeof query === 'string' && isWrongAddress) {
233
- onChange('');
234
- setInternalError(true);
235
- }
236
-
237
- setTimeout(function () {
238
- return setIsFocused(false);
239
- }, 50);
240
211
  };
241
212
 
242
213
  var getHintMessage = function getHintMessage() {
@@ -247,18 +218,19 @@ var InputAddress = function InputAddress(_ref) {
247
218
  var getSelectedItemLabel = function getSelectedItemLabel() {
248
219
  var _query$street2;
249
220
 
250
- if (typeof query === "string") return query;
221
+ if (typeof query === 'string') return query;
251
222
  if (!renderSelectedItem || typeof renderSelectedItem !== 'function') return "".concat((query === null || query === void 0 ? void 0 : query.streetNumber) || '', " ").concat((query === null || query === void 0 ? void 0 : (_query$street2 = query.street) === null || _query$street2 === void 0 ? void 0 : _query$street2.fullName) || '');
252
223
  return renderSelectedItem(query);
253
224
  };
254
225
 
255
226
  var getListItemLabel = function getListItemLabel(item) {
256
- if (typeof item === "string") return item;
227
+ if (typeof item === 'string') return item;
257
228
  if (!renderListItem || typeof renderListItem !== 'function') return item === null || item === void 0 ? void 0 : item.fullPrediction;
258
229
  return renderListItem(item);
259
230
  };
260
231
 
261
232
  var preparedValue = (0, _react.useMemo)(function () {
233
+ if (!value) return '';
262
234
  if (typeof value === 'string') return value === null || value === void 0 ? void 0 : value.trim();
263
235
  return value;
264
236
  }, [value]);
@@ -296,8 +268,12 @@ var InputAddress = function InputAddress(_ref) {
296
268
  className: (0, _classnames.default)('input-address__input', className),
297
269
  value: value,
298
270
  onChange: onChangeInternal,
299
- onFocus: onFocus,
300
- onBlur: onBlur,
271
+ onFocus: function onFocus() {
272
+ return setIsFocused(true);
273
+ },
274
+ onBlur: function onBlur() {
275
+ return setIsFocused(false);
276
+ },
301
277
  onKeyDown: onKeyDown
302
278
  }), isWrongAddress && /*#__PURE__*/_react.default.createElement("div", {
303
279
  className: (0, _classnames.default)('input-address__alert', {
@@ -350,7 +326,7 @@ var InputAddress = function InputAddress(_ref) {
350
326
 
351
327
  return /*#__PURE__*/_react.default.createElement("div", {
352
328
  className: (0, _classnames.default)('input-address', {
353
- 'input-address--error': error || internalError || isWrongAddress && !isFocused
329
+ 'input-address--error': error || isWrongAddress && !isFocused
354
330
  })
355
331
  }, renderInput(), isListVisible && renderList());
356
332
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.1.48",
3
+ "version": "1.1.50",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [