intelicoreact 1.8.6 → 1.8.8

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.
Files changed (130) hide show
  1. package/dist/Atomic/FormElements/Dropdown/components/DropdownLoader.jsx +1 -18
  2. package/dist/Atomic/FormElements/FormattedRawSSN/FormattedRawSSN_old.jsx +1 -121
  3. package/dist/Atomic/FormElements/MobileCalendar/MobileCalendar.jsx +1 -507
  4. package/dist/Atomic/FormElements/MultiSelect/MultiSelect.jsx +1 -46
  5. package/dist/Atomic/FormElements/NumericInput/NumericInput.jsx +1 -337
  6. package/dist/Atomic/FormElements/RadioGroup/RadioGroup.jsx +1 -66
  7. package/dist/Atomic/FormElements/RadioGroupWithInput/RadioGroupWithInput.jsx +1 -78
  8. package/dist/Atomic/FormElements/RadioRowSwitcher/RadioRowSwitcher.jsx +1 -54
  9. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.jsx +1 -183
  10. package/dist/Atomic/FormElements/RangeList/RangeList.jsx +1 -181
  11. package/dist/Atomic/FormElements/RangeList/partial/RangeListRow.jsx +1 -41
  12. package/dist/Atomic/FormElements/RangeSlider/RangeSlider.jsx +1 -449
  13. package/dist/Atomic/FormElements/RangeSlider2/RangeSlider2.jsx +1 -865
  14. package/dist/Atomic/FormElements/SwitchableRow/SwitchableRow.jsx +1 -37
  15. package/dist/Atomic/FormElements/SwitcherCheckbox/SwitcherCheckbox.jsx +1 -48
  16. package/dist/Atomic/FormElements/SwitcherRangeList/SwitcherRangeList.jsx +1 -62
  17. package/dist/Atomic/FormElements/SwitcherTagsDropdown/SwitcherTagsDropdown.jsx +1 -175
  18. package/dist/Atomic/FormElements/SwitcherTextarea/SwitcherTextarea.jsx +1 -65
  19. package/dist/Atomic/FormElements/TagListToDropdown/TagListToDropdown.jsx +1 -118
  20. package/dist/Atomic/FormElements/Text/Text.jsx +1 -126
  21. package/dist/Atomic/FormElements/Textarea/Textarea.jsx +1 -61
  22. package/dist/Atomic/FormElements/TieredCheckboxes/TieredCheckboxes.jsx +1 -181
  23. package/dist/Atomic/FormElements/TieredCheckboxes/partial/AccordionWithCheckbox.jsx +1 -60
  24. package/dist/Atomic/FormElements/VariantsListRadio/VariantsListRadio.jsx +1 -83
  25. package/dist/Atomic/FormElements/VariantsListRadio/partials/VariantsListRadioItem.jsx +1 -80
  26. package/dist/Atomic/FormElements/WidgetPseudoTable/WidgetPseudoTable.jsx +1 -103
  27. package/dist/Atomic/FormElements/WidgetWithSwitchableRows/WidgetWithSwitchableRows.jsx +1 -115
  28. package/dist/Atomic/Layout/Header/Header.jsx +1 -86
  29. package/dist/Atomic/Layout/MainMenu/MainMenu.jsx +1 -164
  30. package/dist/Atomic/UI/AccordionTable/AccordionTable.jsx +1 -250
  31. package/dist/Atomic/UI/AccordionText/AccordionText.jsx +1 -68
  32. package/dist/Atomic/UI/Arrow/Arrow.jsx +1 -134
  33. package/dist/Atomic/UI/Box/Box.jsx +1 -53
  34. package/dist/Atomic/UI/Chart/Chart.jsx +1 -178
  35. package/dist/Atomic/UI/Chart/partial/ChartTypeSwitcherIcon/ChartTypeSwitcherIcon.jsx +1 -78
  36. package/dist/Atomic/UI/Chart/partial/optionsConstructor.jsx +1 -334
  37. package/dist/Atomic/UI/CircleProgressBar/CircleProgressBar.jsx +1 -111
  38. package/dist/Atomic/UI/DateTime/DateTime.jsx +1 -57
  39. package/dist/Atomic/UI/DebugContainer/DebugContainer.jsx +1 -44
  40. package/dist/Atomic/UI/DebugContainer/useDebugContainer.jsx +1 -15
  41. package/dist/Atomic/UI/ExampleChartIntegration/ExampleChartIntegration.jsx +1 -223
  42. package/dist/Atomic/UI/MonoAccordion/MonoAccordion._test.jsx +1 -75
  43. package/dist/Atomic/UI/MonoAccordion/MonoAccordion.jsx +1 -86
  44. package/dist/Atomic/UI/PieChart/PieChart.jsx +1 -41
  45. package/dist/Atomic/UI/Table/Partials/TdCell.jsx +1 -87
  46. package/dist/Atomic/UI/Table/Partials/TdHeader.jsx +1 -36
  47. package/dist/Atomic/UI/Table/Partials/TdRow.jsx +1 -103
  48. package/dist/Atomic/UI/Table/Partials/TdTitle.jsx +1 -55
  49. package/dist/Atomic/UI/Table/Table.jsx +1 -63
  50. package/dist/Atomic/UI/Table/TdTypes/TdActions.jsx +1 -80
  51. package/dist/Atomic/UI/Table/TdTypes/TdPriority.jsx +1 -26
  52. package/dist/Atomic/UI/Table/TdTypes/TdRange.jsx +1 -13
  53. package/dist/Atomic/UI/Table/TdTypes/TdWeight.jsx +1 -56
  54. package/dist/Atomic/UI/TagList/TagList.jsx +1 -256
  55. package/dist/Atomic/UI/WizardStepper/constructor.jsx +1 -86
  56. package/dist/Classes/RESTAPI/partials/CredentialsProcessing.jsx +1 -254
  57. package/dist/Functions/customEventListener.jsx +1 -96
  58. package/dist/Functions/operations.jsx +1 -138
  59. package/dist/Functions/useFormTools/functions/RenderFields.jsx +1 -108
  60. package/dist/Functions/useFormTools/index.jsx +1 -777
  61. package/dist/Functions/usePasswordChecker.jsx +1 -128
  62. package/dist/Functions/utils.jsx +1 -492
  63. package/dist/Molecular/CustomIcons/components/AffiliateNetworks.jsx +1 -22
  64. package/dist/Molecular/CustomIcons/components/AlertCircle.jsx +1 -24
  65. package/dist/Molecular/CustomIcons/components/AppStore.jsx +1 -30
  66. package/dist/Molecular/CustomIcons/components/Arrow.jsx +1 -33
  67. package/dist/Molecular/CustomIcons/components/ArrowDown.jsx +1 -18
  68. package/dist/Molecular/CustomIcons/components/ArrowLeft.jsx +1 -23
  69. package/dist/Molecular/CustomIcons/components/ArrowRight.jsx +1 -23
  70. package/dist/Molecular/CustomIcons/components/ArrowUp.jsx +1 -18
  71. package/dist/Molecular/CustomIcons/components/Bell.jsx +1 -16
  72. package/dist/Molecular/CustomIcons/components/Button.jsx +1 -13
  73. package/dist/Molecular/CustomIcons/components/Campaigns.jsx +1 -17
  74. package/dist/Molecular/CustomIcons/components/Check.jsx +1 -15
  75. package/dist/Molecular/CustomIcons/components/Check2.jsx +1 -13
  76. package/dist/Molecular/CustomIcons/components/ChevronDown.jsx +1 -13
  77. package/dist/Molecular/CustomIcons/components/ChevronDownDisabled.jsx +1 -12
  78. package/dist/Molecular/CustomIcons/components/ChevronLeft.jsx +1 -12
  79. package/dist/Molecular/CustomIcons/components/ChevronRight.jsx +1 -12
  80. package/dist/Molecular/CustomIcons/components/ChevronUp.jsx +1 -12
  81. package/dist/Molecular/CustomIcons/components/ChevronUpDown.jsx +1 -28
  82. package/dist/Molecular/CustomIcons/components/Close.jsx +1 -15
  83. package/dist/Molecular/CustomIcons/components/ColumnsOrder.jsx +1 -18
  84. package/dist/Molecular/CustomIcons/components/Delete.jsx +1 -17
  85. package/dist/Molecular/CustomIcons/components/Edit.jsx +1 -16
  86. package/dist/Molecular/CustomIcons/components/Email.jsx +1 -32
  87. package/dist/Molecular/CustomIcons/components/FinturfLogo.jsx +1 -19
  88. package/dist/Molecular/CustomIcons/components/FinturfLogo2.jsx +1 -36
  89. package/dist/Molecular/CustomIcons/components/Flows.jsx +1 -16
  90. package/dist/Molecular/CustomIcons/components/Gift.jsx +1 -26
  91. package/dist/Molecular/CustomIcons/components/GoogleAuth.jsx +1 -30
  92. package/dist/Molecular/CustomIcons/components/GooglePlay.jsx +1 -30
  93. package/dist/Molecular/CustomIcons/components/HelpCircle.jsx +1 -20
  94. package/dist/Molecular/CustomIcons/components/HelpCircle2.jsx +1 -21
  95. package/dist/Molecular/CustomIcons/components/HelpCircleFilled.jsx +1 -20
  96. package/dist/Molecular/CustomIcons/components/Home.jsx +1 -17
  97. package/dist/Molecular/CustomIcons/components/Home2.jsx +1 -23
  98. package/dist/Molecular/CustomIcons/components/Key.jsx +1 -24
  99. package/dist/Molecular/CustomIcons/components/Landers.jsx +1 -21
  100. package/dist/Molecular/CustomIcons/components/Lock.jsx +1 -16
  101. package/dist/Molecular/CustomIcons/components/Mail.jsx +1 -27
  102. package/dist/Molecular/CustomIcons/components/Mastercard.jsx +1 -74
  103. package/dist/Molecular/CustomIcons/components/Minus.jsx +1 -26
  104. package/dist/Molecular/CustomIcons/components/Offers.jsx +1 -17
  105. package/dist/Molecular/CustomIcons/components/Pause.jsx +1 -29
  106. package/dist/Molecular/CustomIcons/components/PayPal.jsx +1 -42
  107. package/dist/Molecular/CustomIcons/components/PayPalLightLarge.jsx +1 -29
  108. package/dist/Molecular/CustomIcons/components/Phone.jsx +1 -31
  109. package/dist/Molecular/CustomIcons/components/Play.jsx +1 -26
  110. package/dist/Molecular/CustomIcons/components/Plus.jsx +1 -26
  111. package/dist/Molecular/CustomIcons/components/Profile.jsx +1 -17
  112. package/dist/Molecular/CustomIcons/components/QRCode.jsx +1 -30
  113. package/dist/Molecular/CustomIcons/components/Rectangle.jsx +1 -13
  114. package/dist/Molecular/CustomIcons/components/Revert.jsx +1 -14
  115. package/dist/Molecular/CustomIcons/components/Star.jsx +1 -15
  116. package/dist/Molecular/CustomIcons/components/Star2.jsx +1 -17
  117. package/dist/Molecular/CustomIcons/components/TrafficSources.jsx +1 -15
  118. package/dist/Molecular/CustomIcons/components/Trash.jsx +1 -16
  119. package/dist/Molecular/CustomIcons/components/TrashRed.jsx +1 -16
  120. package/dist/Molecular/CustomIcons/components/Triggers.jsx +1 -16
  121. package/dist/Molecular/CustomIcons/components/User.jsx +1 -26
  122. package/dist/Molecular/CustomIcons/components/Visa.jsx +1 -32
  123. package/dist/Molecular/CustomIcons/components/X.jsx +1 -13
  124. package/dist/Molecular/FormElement/FormElement.jsx +1 -52
  125. package/dist/Molecular/FormWithDependOn/FormWithDependOn.jsx +1 -161
  126. package/dist/Molecular/InputAddress/InputAddress.jsx +1 -641
  127. package/dist/Molecular/InputPassword/InputPassword.jsx +1 -50
  128. package/package.json +1 -1
  129. package/dist/Atomic/FormElements/RangeInputs/RangeInputs.d.ts +0 -5
  130. package/dist/Atomic/FormElements/RangeInputs/RangeInputs.js.map +0 -1
@@ -1,641 +1 @@
1
- import cn from 'classnames';
2
-
3
- import { useEffect, useMemo, useRef, useState } from 'react';
4
- import { AlertTriangle, X } from 'react-feather';
5
-
6
- import Input from '../../Atomic/FormElements/Input/Input';
7
- import Spinner from '../../Atomic/Layout/Spinner/Spinner';
8
- import Hint from '../../Atomic/UI/Hint/Hint';
9
- import useIsMobile from '../../Functions/useIsMobile/useIsMobile';
10
- import { compare, getIsOnlyAnObject } from '../../Functions/utils';
11
-
12
- import './InputAddress.scss';
13
-
14
- const DEFAULT_HINT_MESSAGE
15
- = 'Select the correct address from the list of suggestions (must contains house number and street name)';
16
-
17
- const RC = 'input-address';
18
-
19
- // ? Если равны - true
20
- function compareValues(val1, val2) {
21
- return (
22
- typeof val1 === typeof val2
23
- && (getIsOnlyAnObject(val1) ? compare(val1, val2) : val1 === val2)
24
- );
25
- }
26
-
27
- function throttle(fn, ms) {
28
- let id = null;
29
- return (...args) => {
30
- if (id) clearTimeout(id);
31
-
32
- id = setTimeout(() => {
33
- fn(...args);
34
- }, ms);
35
- };
36
- }
37
-
38
- // Отдает true если value валидное НЕ нулевое число
39
- function getIsValidNumber(value) {
40
- return Boolean(value) && typeof value === 'number' && !Number.isNaN(value)
41
- }
42
-
43
- function InputAddress({
44
- label,
45
- className = '',
46
- isClearable = true,
47
- isKeyboardControlled = true,
48
- fieldKey = '',
49
- testId = '',
50
- throttle: throttleTime = 500, // ms
51
- additionalThrottleTimeForListingRequest = 0, // ms
52
- loader = '',
53
- noItemsMessage = '',
54
- error,
55
- value = '',
56
- onChange = () => {},
57
- onChangeValueTransformer,
58
- disabled,
59
- isDisabled,
60
-
61
- getListItems = () => {},
62
- clarifyAddressInfo, // ! Не делать дефолтного значения! Это и метод и флаг
63
-
64
- noValidate = false,
65
-
66
- renderSelectedItem,
67
- renderListItem,
68
- renderHintMessage,
69
-
70
- attributesOfNativeInput,
71
- }) {
72
- const { isMobile } = useIsMobile();
73
-
74
- const inputRef = useRef(null);
75
- const listRef = useRef(null);
76
- const listOverlayRef = useRef(null);
77
- const listWrapperRef = useRef(null);
78
- const listHeaderRef = useRef(null);
79
- const previousValueRef = useRef(value);
80
-
81
- const [isValueInited, setIsValueInited] = useState(false);
82
-
83
- const [isScrollableList, setIsScrollableList] = useState(null);
84
- const [scrollTop, setScrollTop] = useState(0);
85
- const [scrollHeight, setScrollHeight] = useState(1);
86
-
87
- const [innerValue, setInnerValue] = useState(value);
88
-
89
- const [tempInnerValue, setTempInnerValue] = useState(null);
90
- const [tempValue, setTempValue] = useState(null);
91
-
92
- const [listItems, setListItems] = useState([]);
93
- const [isLoading, setIsLoading] = useState(false);
94
- const [isListLoading, setIsListLoading] = useState(false);
95
-
96
- const [hightlightedIndex, setHightlightedIndex] = useState(null);
97
-
98
- const [isFocused, setIsFocused] = useState(false);
99
- const [isListVisible, setIsListVisible] = useState(false);
100
-
101
- const isWrongAddress = useMemo(() => {
102
- if (noValidate) return false;
103
-
104
- if (innerValue === '') return false;
105
-
106
- if (
107
- !innerValue?.hasOwnProperty('streetNumber')
108
- || !innerValue?.streetNumber
109
- ) {
110
- return true;
111
- }
112
-
113
- // eslint-disable-next-line no-prototype-builtins
114
- if (!innerValue?.hasOwnProperty('street') || !innerValue?.street?.fullName)
115
- return true;
116
-
117
- return false;
118
- }, [innerValue]);
119
-
120
- const setItemAsInnerValue = (e, item) => {
121
- if (e instanceof Event) {
122
- e.preventDefault();
123
- e.stopPropagation();
124
- }
125
-
126
- setTimeout(() => {
127
- setInnerValue(item);
128
-
129
- if (isMobile) {
130
- setIsListVisible(false);
131
- }
132
- }, 0);
133
- };
134
-
135
- // ? Базовый метод получения списка вариантов адреса
136
- const getAddressVariants = useMemo(
137
- () => innerValue =>
138
- getListItems(innerValue)
139
- ?.then(setListItems)
140
- .finally(() => setIsListLoading(false)),
141
- [getListItems],
142
- );
143
-
144
- // ? Метод получения списка вариантов адреса с тротлингом (основным и, если нужно, дополнительным)
145
- // ? Без useMemo работать НЕ будет (т.к. на каждом перерендере будет создаваться новая ф-я и будет теряться замкнутая переменная id из throttle)
146
- const getAddressVariantsWithThrottling = useMemo(() => {
147
- const execute = getIsValidNumber(additionalThrottleTimeForListingRequest)
148
- ? throttle(getAddressVariants, additionalThrottleTimeForListingRequest)
149
- : getAddressVariants;
150
-
151
- return getIsValidNumber(throttleTime)
152
- ? throttle(execute, throttleTime)
153
- : execute;
154
- }, [
155
- getAddressVariants,
156
- additionalThrottleTimeForListingRequest,
157
- throttleTime,
158
- ]);
159
-
160
- // ? Итоговый "получатель" списка вариантов адресов
161
- const getAddressVariantsList = () => {
162
- if (!innerValue?.length) return null;
163
-
164
- // ? Вообще с учетом надпись "Loading" в списке вариантов включается в этом месте (т.е. сразу при начале набора),
165
- // ? то, наверное, можно было НЕ мутить с дополнительным тротлингом )).
166
- // ? Наверное, можно было увеличить время первичного тротлинга и, наверное, работало бы так же ))
167
- // ? НО, раз уже сделал )) оставлю, может будет в будущем полезно )
168
- setIsListLoading(true);
169
- getAddressVariantsWithThrottling(innerValue);
170
-
171
- return null;
172
- };
173
-
174
- const onClearClick = (e) => {
175
- e.preventDefault();
176
- e.stopPropagation();
177
-
178
- if (!isMobile) {
179
- setIsListVisible(false);
180
- }
181
-
182
- setInnerValue('');
183
-
184
- inputRef?.current?.focus();
185
- setTimeout(() => setIsFocused(true), 0);
186
- };
187
-
188
- const onOverlayClick = (e) => {
189
- if (e.target === listOverlayRef?.current) {
190
- e.stopPropagation();
191
- e.preventDefault();
192
- setIsListVisible(false);
193
- setInnerValue(tempInnerValue);
194
- onChange(
195
- typeof innerValue === 'string'
196
- || !onChangeValueTransformer
197
- || typeof onChangeValueTransformer !== 'function'
198
- ? innerValue
199
- : onChangeValueTransformer(innerValue),
200
- );
201
- }
202
- };
203
-
204
- const onKeyDown = (keyCode) => {
205
- if (!isListVisible || !isKeyboardControlled) return false;
206
-
207
- if (keyCode === 13) {
208
- // Enter Controller
209
- setItemAsInnerValue(null, listItems[hightlightedIndex]);
210
- setHightlightedIndex(null);
211
- inputRef?.current?.blur();
212
- }
213
- else {
214
- let newHightlightedIndex = null;
215
- const listItemsElements = document.getElementsByClassName(
216
- 'input-address__list--item',
217
- );
218
-
219
- const listHeight = listRef?.current?.getBoundingClientRect()?.height;
220
- const listScrollTop = listRef?.current?.scrollTop || 0;
221
- const lastItemIndex = Number.parseInt(listItems?.length, 10) - 1;
222
-
223
- /** Arrows Controllers */
224
- if (keyCode === 40) {
225
- // Down Key Controller
226
- if (hightlightedIndex === null || hightlightedIndex === lastItemIndex) {
227
- newHightlightedIndex = 0;
228
- }
229
- else if (hightlightedIndex + 1 < listItems?.length) {
230
- newHightlightedIndex = hightlightedIndex + 1;
231
- }
232
- }
233
- else if (keyCode === 38) {
234
- // Up Key Controller
235
- if (hightlightedIndex === null || hightlightedIndex === 0) {
236
- newHightlightedIndex = lastItemIndex;
237
- }
238
- else if (hightlightedIndex - 1 >= 0) {
239
- newHightlightedIndex = hightlightedIndex - 1;
240
- }
241
- }
242
-
243
- // Scroll to Element
244
- const newHightlightedElement = listItemsElements[newHightlightedIndex];
245
- const newHightlightedElementHeight
246
- = newHightlightedElement?.getBoundingClientRect()?.height;
247
-
248
- const newHightlightedElementTopInList = newHightlightedElement?.offsetTop;
249
-
250
- if (
251
- newHightlightedElementTopInList + newHightlightedElementHeight
252
- > listScrollTop + listHeight
253
- ) {
254
- if (
255
- Math.abs(
256
- newHightlightedElementTopInList
257
- + newHightlightedElementHeight
258
- - (listScrollTop + listHeight),
259
- ) <= newHightlightedElementHeight
260
- ) {
261
- listRef?.current?.scrollTo(
262
- 0,
263
- listScrollTop + newHightlightedElementHeight,
264
- );
265
- }
266
- else {
267
- listRef?.current?.scrollTo(0, newHightlightedElementTopInList);
268
- }
269
- }
270
- else if (newHightlightedElementTopInList < listScrollTop) {
271
- if (
272
- Math.abs(newHightlightedElementTopInList - listScrollTop)
273
- < newHightlightedElementHeight
274
- ) {
275
- listRef?.current?.scrollTo(
276
- 0,
277
- listScrollTop - newHightlightedElementHeight,
278
- );
279
- }
280
- else {
281
- listRef?.current?.scrollTo(0, newHightlightedElementTopInList);
282
- }
283
- }
284
-
285
- if (!isMobile) setHightlightedIndex(newHightlightedIndex);
286
- }
287
- };
288
-
289
- const getHintMessage = () => {
290
- if (!renderHintMessage || typeof renderHintMessage !== 'function')
291
- return DEFAULT_HINT_MESSAGE;
292
-
293
- return renderHintMessage(innerValue);
294
- };
295
-
296
- const getSelectedItemLabel = (value = innerValue) => {
297
- if (!value) return '';
298
- if (typeof value === 'string') return value;
299
- if (typeof renderSelectedItem === 'function') renderSelectedItem(value);
300
-
301
- const label
302
- = `${value?.streetNumber || ''} ${value?.street?.fullName || ''}`.trim();
303
- return !label && isLoading ? previousValueRef.current : label;
304
- };
305
-
306
- const getListItemLabel = (item) => {
307
- if (typeof item === 'string') return item;
308
-
309
- if (!renderListItem || typeof renderListItem !== 'function')
310
- return item?.fullPrediction;
311
-
312
- return renderListItem(item);
313
- };
314
-
315
- const setListHeight = () => {
316
- if (listWrapperRef?.current && listHeaderRef?.current && listRef.current) {
317
- const listWrapperHeight
318
- = listWrapperRef?.current?.getBoundingClientRect()?.height;
319
- const listWrapperStyles = getComputedStyle(listWrapperRef?.current);
320
-
321
- const listHeaderHeight
322
- = listHeaderRef?.current?.getBoundingClientRect()?.height;
323
-
324
- const listHeight
325
- = listWrapperHeight
326
- - listHeaderHeight
327
- - Number.parseInt(listWrapperStyles.paddingBottom, 10);
328
-
329
- listRef.current.style.maxHeight = `${listHeight}px`;
330
- }
331
- };
332
-
333
- const resetListHeight = () => {
334
- if (listRef.current) {
335
- listRef.current.style.maxHeight = `initial`;
336
- }
337
- };
338
-
339
- // ? Основной блок работы со значениями адреса
340
- // ? Не меняйте вызовы setInnerValue и onChange не разобравшись в логике вызовов
341
- useEffect(() => {
342
- // ? Исключение инициализации - равны только при первом рендере компонента,
343
- // ? т.к. рефка и стейт инициализируются верхним value
344
- if (!compareValues(innerValue, previousValueRef.current)) {
345
- const isObject = getIsOnlyAnObject(innerValue);
346
-
347
- // ? innerValue меняется либо от ручного ввода, либо от выбора из списка
348
- // ? Полная информация или нет - напрямую зависит от ответа getListItems
349
- const isFullInfo
350
- = isObject
351
- && 'streetNumber' in innerValue
352
- && 'street' in innerValue
353
- && 'city' in innerValue
354
- && 'state' in innerValue
355
- && 'country' in innerValue
356
- && 'zipCode' in innerValue;
357
-
358
- // ? Для старого эндпоинта возвращается список с полной информацией, поэтому на проектах ничего не поменяется,
359
- // ? если не менять запросник (getListItems), все будет проходить по этой if-ке или по 3-й (для строчных значений)
360
- if (isFullInfo) {
361
- onChange(innerValue);
362
- setIsLoading(false);
363
- }
364
-
365
- // ? Неполная информация может быть только в том случае, когда метод getListItems использует уже новый эндпоинт гугл-апи.
366
- // ? Предполагается, что при этом в компонент будет прокинута ф-я "уточнятель" (clarifyAddressInfo)
367
- if (isObject && !isFullInfo) {
368
- if (typeof clarifyAddressInfo === 'function') {
369
- setIsLoading(true);
370
- // ? Предполагается, что clarifyAddressInfo - асинхронная ф-я, запросник уточнения опции
371
- // ? Никаких await-ов НЕ нужно (тем более что в useEffect и нельзя для нового React),
372
- // ? промис "выплюнется в пустоту", но НЕ будет отчищен до резолва, а useEffect (и итерация рендера в целом) при этом будет закончен(а)
373
- clarifyAddressInfo(innerValue)?.then?.((res) => {
374
- if (res) {
375
- setInnerValue(res);
376
- }
377
- else {
378
- setInnerValue(previousValueRef.current);
379
- setTimeout(() => {
380
- inputRef.current.focus();
381
- inputRef.current.setSelectionRange(
382
- previousValueRef.current.length,
383
- previousValueRef.current.length,
384
- );
385
- }, 0);
386
- }
387
-
388
- setIsLoading(false);
389
- return res;
390
- });
391
- }
392
- // ! Если сверху поменяли эндпоинт и он выдает "облегченный листинг" (айтемы с неполной инфой),
393
- // ! и НЕ пробросили clarifyAddressInfo, то на этом кейсе велью инпута будет просто зануляться
394
- // ! (getSelectedItemLabel вернет пустую строку если вкинуть innerValue без всей инфы)
395
- else {
396
- setInnerValue(getSelectedItemLabel(innerValue));
397
- }
398
- }
399
-
400
- // ? Кейс для строчных значений
401
- if (!isObject) {
402
- // ? Вызываем верхний onChange если innerValue есть или если нету, но это не после логики уточнения
403
- if (innerValue || !isLoading) onChange(innerValue);
404
- // ? Если innerValue есть и еще не открыт листинг - открываем
405
- if (innerValue && !isListVisible) setIsListVisible(true);
406
- // ? Если инпут сфокусирован и значение есть - запрашиваем список вариантов
407
- if (isFocused && Boolean(innerValue)) getAddressVariantsList();
408
- }
409
- }
410
- }, [innerValue]);
411
-
412
- useEffect(() => {
413
- if (!isFocused && !isMobile) {
414
- setIsListVisible(false);
415
- setHightlightedIndex(null);
416
- }
417
- }, [isFocused]);
418
-
419
- useEffect(() => {
420
- if (!isListVisible) {
421
- setListItems([]);
422
- resetListHeight();
423
- }
424
-
425
- if (isMobile && isListVisible) {
426
- setTempInnerValue(innerValue);
427
- setListHeight();
428
- }
429
- }, [isListVisible]);
430
-
431
- useEffect(() => {
432
- // ? учет изменения value сверху (верхние переназначения велью)
433
- if (!compareValues(value, innerValue)) setInnerValue(value);
434
-
435
- // ? useEffect должен быть последним, т.к. рефка меняется в рамках текущей итерации
436
- previousValueRef.current = value;
437
- }, [value]);
438
-
439
- const renderSearchableInput = () => {
440
- const inputValue = getSelectedItemLabel();
441
-
442
- return (
443
- <div className={cn('input-address__input-wrapper')}>
444
- <Input
445
- ref={inputRef}
446
- testId={`inputAddress--input--key-${testId || fieldKey}`}
447
- className={cn('input-address__input', className)}
448
- value={inputValue}
449
- onChange={setInnerValue}
450
- onFocus={(e) => {
451
- setIsFocused(true);
452
- }}
453
- onBlur={() => setIsFocused(false)}
454
- onKeyDown={onKeyDown}
455
- attributesOfNativeInput={attributesOfNativeInput}
456
- disabled={disabled || isDisabled}
457
- isDisabled={disabled || isDisabled}
458
- />
459
- {isWrongAddress && (
460
- <div
461
- className={cn('input-address__alert', {
462
- 'input-address__alert--visible': !isFocused,
463
- })}
464
- >
465
- <Hint
466
- side="left"
467
- hint={getHintMessage()}
468
- icon={<AlertTriangle />}
469
- handleOpenType="hover"
470
- />
471
- </div>
472
- )}
473
- {isClearable && (!isWrongAddress || isFocused) && !(disabled || isDisabled) && (
474
- <div
475
- className={cn('input-address__clear-query', {
476
- 'input-address__clear-query--input-focused': isFocused,
477
- })}
478
- >
479
- <X onClick={onClearClick} />
480
- </div>
481
- )}
482
- </div>
483
- );
484
- };
485
-
486
- const renderInput = () => {
487
- const inputValue = getSelectedItemLabel(
488
- isListVisible ? tempInnerValue : innerValue,
489
- );
490
-
491
- return (
492
- <div className={cn('input-address__input-wrapper')}>
493
- <Input
494
- testId={`inputAddress--input--key-${testId || fieldKey}`}
495
- className={cn('input-address__input', className)}
496
- value={inputValue}
497
- onChange={setInnerValue}
498
- onFocus={(e) => {
499
- setIsListVisible(true);
500
- e?.target?.blur();
501
- setTimeout(() => inputRef?.current?.focus(), 200);
502
- }}
503
- disabled={disabled || isDisabled}
504
- isDisabled={disabled || isDisabled}
505
- />
506
- </div>
507
- );
508
- };
509
-
510
- const renderLoader = () => {
511
- return (
512
- <div className="input-address__list--loader">
513
- {loader || 'Loading...'}
514
- </div>
515
- );
516
- };
517
-
518
- const renderList = () => {
519
- const renderListItem = (item, i) => {
520
- return (
521
- <div
522
- key={`input-address__list-item${i}`}
523
- className={cn('input-address__list--item', {
524
- 'input-address__list--item-hightlighted': i === hightlightedIndex,
525
- })}
526
- onMouseDown={e => setItemAsInnerValue(e, item)}
527
- >
528
- {getListItemLabel(item)}
529
- </div>
530
- );
531
- };
532
- const renderListItemCustom = () => {
533
- return (
534
- <div
535
- key="input-address__list-item--custom"
536
- className={cn(
537
- 'input-address__list--item',
538
- 'input-address__list--item-custom',
539
- )}
540
- onMouseDown={e => setItemAsInnerValue(e, getSelectedItemLabel())}
541
- >
542
- {getSelectedItemLabel()}
543
- <AlertTriangle />
544
- <span>Choose this only if your address is not listed below</span>
545
- </div>
546
- );
547
- };
548
- const renderNoItems = () => {
549
- return (
550
- <div className="input-address__list--no-items">
551
- {isMobile && !innerValue?.length
552
- ? 'Please begin entering your address'
553
- : noItemsMessage || 'No Items'}
554
- </div>
555
- );
556
- };
557
-
558
- const renderListDesktop = () => {
559
- return (
560
- <div className="input-address__list-wrapper" ref={listWrapperRef}>
561
- <div className="input-address__list" ref={listRef}>
562
- {isListLoading
563
- ? renderLoader()
564
- : listItems?.length
565
- ? listItems?.map(renderListItem)
566
- : renderNoItems()}
567
- </div>
568
- </div>
569
- );
570
- };
571
- const renderListMobile = () => {
572
- return (
573
- <div
574
- className="input-address__list-overlay"
575
- ref={listOverlayRef}
576
- onClick={onOverlayClick}
577
- >
578
- <div className="input-address__list-wrapper" ref={listWrapperRef}>
579
- {isMobile && (
580
- <div
581
- ref={listHeaderRef}
582
- className={cn(`${RC}__list-header`, {
583
- [`${RC}__list-header-with-shadow`]:
584
- isScrollableList && isMobile,
585
- [`${RC}__list-header-with-shadow-hidden`]: scrollTop === 0,
586
- })}
587
- >
588
- <div className={cn(`${RC}__list-header-row`)}>
589
- <div className={cn(`${RC}__list-label`)}>
590
- {label || 'Address'}
591
- </div>
592
- <div
593
- className={cn(`${RC}__list-close-icon`)}
594
- onClick={() => setIsListVisible(false)}
595
- >
596
- <X onClick={() => setIsListVisible(false)} />
597
- </div>
598
- </div>
599
- <div className={cn(`${RC}__list-header-row`)}>
600
- {renderSearchableInput()}
601
- </div>
602
- </div>
603
- )}
604
- <div className="input-address__list" ref={listRef}>
605
- {isListLoading
606
- ? (
607
- renderLoader()
608
- )
609
- : (
610
- <>
611
- {getSelectedItemLabel() && renderListItemCustom()}
612
- {listItems?.map(renderListItem)}
613
- {!listItems?.length
614
- && !getSelectedItemLabel()
615
- && renderNoItems()}
616
- </>
617
- )}
618
- </div>
619
- </div>
620
- </div>
621
- );
622
- };
623
-
624
- return isMobile ? renderListMobile() : renderListDesktop();
625
- };
626
-
627
- return (
628
- <div
629
- className={cn('input-address', {
630
- 'input-address--error': error || (isWrongAddress && !isFocused),
631
- 'input-address--disabled': disabled || isDisabled,
632
- })}
633
- >
634
- {isLoading && <Spinner size="small" />}
635
- {isMobile ? renderInput() : renderSearchableInput()}
636
- {isListVisible && renderList()}
637
- </div>
638
- );
639
- }
640
-
641
- export default InputAddress;
1
+ function n(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=Array(e);t<e;t++)r[t]=n[t];return r}function e(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function t(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var t,r,i=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=i){var l=[],o=!0,u=!1;try{for(i=i.call(n);!(o=(t=i.next()).done)&&(l.push(t.value),!e||l.length!==e);o=!0);}catch(n){u=!0,r=n}finally{try{o||null==i.return||i.return()}finally{if(u)throw r}}return l}}(n,e)||i(n,e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(n){return n&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n}function i(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}}import{jsx as l,jsxs as o,Fragment as u}from"react/jsx-runtime";import s from"classnames";import{useEffect as a,useMemo as d,useRef as c,useState as f}from"react";import{AlertTriangle as m,X as p}from"react-feather";import v from"../../Atomic/FormElements/Input/Input";import h from"../../Atomic/Layout/Spinner/Spinner";import y from"../../Atomic/UI/Hint/Hint";import g from"../../Functions/useIsMobile/useIsMobile";import{compare as b,getIsOnlyAnObject as _}from"../../Functions/utils";import"./InputAddress.scss";var N="input-address";function I(n,e){return(void 0===n?"undefined":r(n))===(void 0===e?"undefined":r(e))&&(_(n)?b(n,e):n===e)}function w(e,t){var r=null;return function(){for(var l=arguments.length,o=Array(l),u=0;u<l;u++)o[u]=arguments[u];r&&clearTimeout(r),r=setTimeout(function(){e.apply(void 0,function(e){if(Array.isArray(e))return n(e)}(o)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(o)||i(o)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())},t)}}function C(n){return!!n&&"number"==typeof n&&!Number.isNaN(n)}export default function(n){var r,i,b,S,A=n.label,T=n.className,M=void 0===T?"":T,D=n.isClearable,j=void 0===D||D,x=n.isKeyboardControlled,O=void 0===x||x,P=n.fieldKey,B=void 0===P?"":P,F=n.testId,k=void 0===F?"":F,R=n.throttle,E=void 0===R?500:R,H=n.additionalThrottleTimeForListingRequest,L=void 0===H?0:H,q=n.loader,K=void 0===q?"":q,z=n.noItemsMessage,U=void 0===z?"":z,V=n.error,$=n.value,G=void 0===$?"":$,J=n.onChange,Q=void 0===J?function(){}:J,W=n.onChangeValueTransformer,X=n.disabled,Y=n.isDisabled,Z=n.getListItems,nn=void 0===Z?function(){}:Z,ne=n.clarifyAddressInfo,nt=n.noValidate,nr=void 0!==nt&&nt,ni=n.renderSelectedItem,nl=n.renderListItem,no=n.renderHintMessage,nu=n.attributesOfNativeInput,ns=g().isMobile,na=c(null),nd=c(null),nc=c(null),nf=c(null),nm=c(null),np=c(G),nv=t(f(!1),2);nv[0],nv[1];var nh=t(f(null),2),ny=nh[0];nh[1];var ng=t(f(0),2),nb=ng[0];ng[1];var n_=t(f(1),2);n_[0],n_[1];var nN=t(f(G),2),nI=nN[0],nw=nN[1],nC=t(f(null),2),nS=nC[0],nA=nC[1],nT=t(f(null),2);nT[0],nT[1];var nM=t(f([]),2),nD=nM[0],nj=nM[1],nx=t(f(!1),2),nO=nx[0],nP=nx[1],nB=t(f(!1),2),nF=nB[0],nk=nB[1],nR=t(f(null),2),nE=nR[0],nH=nR[1],nL=t(f(!1),2),nq=nL[0],nK=nL[1],nz=t(f(!1),2),nU=nz[0],nV=nz[1],n$=d(function(){var n;return!nr&&""!==nI&&!((null==nI?void 0:nI.hasOwnProperty("streetNumber"))&&(null==nI?void 0:nI.streetNumber)&&(null==nI?void 0:nI.hasOwnProperty("street"))&&(null==nI||null==(n=nI.street)?void 0:n.fullName))},[nI]),nG=function(n,e){var t;(null!=(t=Event)&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](n):n instanceof t)&&(n.preventDefault(),n.stopPropagation()),setTimeout(function(){nw(e),ns&&nV(!1)},0)},nJ=d(function(){return function(n){var e;return null==(e=nn(n))?void 0:e.then(nj).finally(function(){return nk(!1)})}},[nn]),nQ=d(function(){var n=C(L)?w(nJ,L):nJ;return C(E)?w(n,E):n},[nJ,L,E]),nW=function(n){var e;n.preventDefault(),n.stopPropagation(),ns||nV(!1),nw(""),null==na||null==(e=na.current)||e.focus(),setTimeout(function(){return nK(!0)},0)},nX=function(n){if(!nU||!O)return!1;if(13===n){var e;nG(null,nD[nE]),nH(null),null==na||null==(e=na.current)||e.blur()}else{var t,r,i,l,o,u,s,a,d=null,c=document.getElementsByClassName("input-address__list--item"),f=null==nd||null==(r=nd.current)||null==(t=r.getBoundingClientRect())?void 0:t.height,m=(null==nd||null==(i=nd.current)?void 0:i.scrollTop)||0,p=Number.parseInt(null==nD?void 0:nD.length,10)-1;40===n?null===nE||nE===p?d=0:nE+1<(null==nD?void 0:nD.length)&&(d=nE+1):38===n&&(null===nE||0===nE?d=p:nE-1>=0&&(d=nE-1));var v=c[d],h=null==v||null==(l=v.getBoundingClientRect())?void 0:l.height,y=null==v?void 0:v.offsetTop;y+h>m+f?Math.abs(y+h-(m+f))<=h?null==nd||null==(o=nd.current)||o.scrollTo(0,m+h):null==nd||null==(u=nd.current)||u.scrollTo(0,y):y<m&&(Math.abs(y-m)<h?null==nd||null==(s=nd.current)||s.scrollTo(0,m-h):null==nd||null==(a=nd.current)||a.scrollTo(0,y)),ns||nH(d)}},nY=function(){var n,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:nI;if(!e)return"";if("string"==typeof e)return e;"function"==typeof ni&&ni(e);var t="".concat((null==e?void 0:e.streetNumber)||""," ").concat((null==e||null==(n=e.street)?void 0:n.fullName)||"").trim();return!t&&nO?np.current:t},nZ=function(){if((null==nf?void 0:nf.current)&&(null==nm?void 0:nm.current)&&nd.current){var n,e,t,r,i=null==nf||null==(e=nf.current)||null==(n=e.getBoundingClientRect())?void 0:n.height,l=getComputedStyle(null==nf?void 0:nf.current),o=i-(null==nm||null==(r=nm.current)||null==(t=r.getBoundingClientRect())?void 0:t.height)-Number.parseInt(l.paddingBottom,10);nd.current.style.maxHeight="".concat(o,"px")}},n0=function(){nd.current&&(nd.current.style.maxHeight="initial")};a(function(){if(!I(nI,np.current)){var n,e,t=_(nI),r=t&&"streetNumber"in nI&&"street"in nI&&"city"in nI&&"state"in nI&&"country"in nI&&"zipCode"in nI;r&&(Q(nI),nP(!1)),t&&!r&&("function"==typeof ne?(nP(!0),null==(e=ne(nI))||null==(n=e.then)||n.call(e,function(n){return n?nw(n):(nw(np.current),setTimeout(function(){na.current.focus(),na.current.setSelectionRange(np.current.length,np.current.length)},0)),nP(!1),n})):nw(nY(nI))),!t&&((nI||!nO)&&Q(nI),nI&&!nU&&nV(!0),nq&&nI&&(null==nI?void 0:nI.length)&&(nk(!0),nQ(nI)))}},[nI]),a(function(){nq||ns||(nV(!1),nH(null))},[nq]),a(function(){nU||(nj([]),n0()),ns&&nU&&(nA(nI),nZ())},[nU]),a(function(){I(G,nI)||nw(G),np.current=G},[G]);var n1=function(){var n=nY();return o("div",{className:s("input-address__input-wrapper"),children:[l(v,{ref:na,testId:"inputAddress--input--key-".concat(k||B),className:s("input-address__input",M),value:n,onChange:nw,onFocus:function(n){nK(!0)},onBlur:function(){return nK(!1)},onKeyDown:nX,attributesOfNativeInput:nu,disabled:X||Y,isDisabled:X||Y}),n$&&l("div",{className:s("input-address__alert",{"input-address__alert--visible":!nq}),children:l(y,{side:"left",hint:no&&"function"==typeof no?no(nI):"Select the correct address from the list of suggestions (must contains house number and street name)",icon:l(m,{}),handleOpenType:"hover"})}),j&&(!n$||nq)&&!(X||Y)&&l("div",{className:s("input-address__clear-query",{"input-address__clear-query--input-focused":nq}),children:l(p,{onClick:nW})})]})},n2=function(){return l("div",{className:"input-address__list--loader",children:K||"Loading..."})};return o("div",{className:s("input-address",{"input-address--error":V||n$&&!nq,"input-address--disabled":X||Y}),children:[nO&&l(h,{size:"small"}),ns?(r=nY(nU?nS:nI),l("div",{className:s("input-address__input-wrapper"),children:l(v,{testId:"inputAddress--input--key-".concat(k||B),className:s("input-address__input",M),value:r,onChange:nw,onFocus:function(n){var e;nV(!0),null==n||null==(e=n.target)||e.blur(),setTimeout(function(){var n;return null==na||null==(n=na.current)?void 0:n.focus()},200)},disabled:X||Y,isDisabled:X||Y})})):n1(),nU&&(i=function(n,e){return l("div",{className:s("input-address__list--item",{"input-address__list--item-hightlighted":e===nE}),onMouseDown:function(e){return nG(e,n)},children:"string"==typeof n?n:nl&&"function"==typeof nl?nl(n):null==n?void 0:n.fullPrediction},"input-address__list-item".concat(e))},b=function(){return l("div",{className:"input-address__list--no-items",children:!ns||(null==nI?void 0:nI.length)?U||"No Items":"Please begin entering your address"})},ns?l("div",{className:"input-address__list-overlay",ref:nc,onClick:function(n){n.target===(null==nc?void 0:nc.current)&&(n.stopPropagation(),n.preventDefault(),nV(!1),nw(nS),Q("string"!=typeof nI&&W&&"function"==typeof W?W(nI):nI))},children:o("div",{className:"input-address__list-wrapper",ref:nf,children:[ns&&o("div",{ref:nm,className:s("".concat(N,"__list-header"),(e(S={},"".concat(N,"__list-header-with-shadow"),ny&&ns),e(S,"".concat(N,"__list-header-with-shadow-hidden"),0===nb),S)),children:[o("div",{className:s("".concat(N,"__list-header-row")),children:[l("div",{className:s("".concat(N,"__list-label")),children:A||"Address"}),l("div",{className:s("".concat(N,"__list-close-icon")),onClick:function(){return nV(!1)},children:l(p,{onClick:function(){return nV(!1)}})})]}),l("div",{className:s("".concat(N,"__list-header-row")),children:n1()})]}),l("div",{className:"input-address__list",ref:nd,children:nF?n2():o(u,{children:[nY()&&o("div",{className:s("input-address__list--item","input-address__list--item-custom"),onMouseDown:function(n){return nG(n,nY())},children:[nY(),l(m,{}),l("span",{children:"Choose this only if your address is not listed below"})]},"input-address__list-item--custom"),null==nD?void 0:nD.map(i),!(null==nD?void 0:nD.length)&&!nY()&&b()]})})]})}):l("div",{className:"input-address__list-wrapper",ref:nf,children:l("div",{className:"input-address__list",ref:nd,children:nF?n2():(null==nD?void 0:nD.length)?null==nD?void 0:nD.map(i):b()})}))]})}