@rolster/react-components 18.13.4 → 18.13.5
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.
- package/dist/cjs/index.js +69 -32
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +69 -32
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js +41 -19
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js.map +1 -1
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.js +28 -13
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1371,41 +1371,63 @@ const MAX_ELEMENTS = 6;
|
|
|
1371
1371
|
function useAutocompleteField({ disabled, formControl, onSelect, onValue, suggestions }) {
|
|
1372
1372
|
const [pattern, setPattern] = react.useState('');
|
|
1373
1373
|
const [coincidences, setCoincidences] = react.useState([]);
|
|
1374
|
-
const
|
|
1374
|
+
const currentStore = react.useRef({
|
|
1375
1375
|
pattern: '',
|
|
1376
1376
|
coincidences: [],
|
|
1377
1377
|
previous: null
|
|
1378
1378
|
});
|
|
1379
1379
|
const listControl = useListControl({ suggestions, formControl });
|
|
1380
1380
|
const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
|
|
1381
|
+
const initializedState = react.useRef(false);
|
|
1382
|
+
const initializedCollection = react.useRef(false);
|
|
1381
1383
|
const changeInternal = react.useRef(false);
|
|
1382
|
-
react.useEffect(() => filterSuggestions(pattern, true), [suggestions]);
|
|
1383
|
-
react.useEffect(() => filterSuggestions(pattern), [pattern]);
|
|
1384
1384
|
react.useEffect(() => {
|
|
1385
|
+
refreshCoincidences(pattern, true);
|
|
1386
|
+
}, [suggestions]);
|
|
1387
|
+
react.useEffect(() => {
|
|
1388
|
+
refreshCoincidences(pattern);
|
|
1389
|
+
}, [pattern]);
|
|
1390
|
+
react.useEffect(() => {
|
|
1391
|
+
if (!initializedState.current || !initializedCollection.current) {
|
|
1392
|
+
initializedState.current = true;
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1385
1395
|
if (changeInternal.current) {
|
|
1386
1396
|
changeInternal.current = false;
|
|
1397
|
+
return;
|
|
1387
1398
|
}
|
|
1388
|
-
|
|
1389
|
-
resetState(formControl?.state);
|
|
1390
|
-
}
|
|
1399
|
+
refresh(collection, formControl?.state);
|
|
1391
1400
|
}, [formControl?.state]);
|
|
1392
|
-
react.useEffect(() =>
|
|
1401
|
+
react.useEffect(() => {
|
|
1402
|
+
if (!initializedCollection.current || !initializedState.current) {
|
|
1403
|
+
initializedCollection.current = true;
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
refresh(collection, formControl?.state);
|
|
1407
|
+
}, [collection]);
|
|
1408
|
+
function refresh(collection, state) {
|
|
1409
|
+
if (!state) {
|
|
1410
|
+
return setValue('');
|
|
1411
|
+
}
|
|
1412
|
+
const element = collection.find(state);
|
|
1413
|
+
if (element) {
|
|
1414
|
+
return setValue(element.description);
|
|
1415
|
+
}
|
|
1416
|
+
setValue('');
|
|
1417
|
+
setFormState(undefined);
|
|
1418
|
+
}
|
|
1393
1419
|
function setFormState(value) {
|
|
1394
1420
|
if (formControl) {
|
|
1395
1421
|
changeInternal.current = true;
|
|
1396
1422
|
formControl.setState(value);
|
|
1397
1423
|
}
|
|
1398
1424
|
}
|
|
1399
|
-
function resetCollection(collection, state) {
|
|
1400
|
-
setValue(state ? collection.find(state)?.description || '' : '');
|
|
1401
|
-
}
|
|
1402
|
-
function resetState(state) {
|
|
1403
|
-
resetCollection(collection, state);
|
|
1404
|
-
}
|
|
1405
1425
|
function onClickControl() {
|
|
1406
1426
|
if (!disabled) {
|
|
1407
1427
|
setVisible(true);
|
|
1408
|
-
setTimeout(() =>
|
|
1428
|
+
setTimeout(() => {
|
|
1429
|
+
inputRef?.current?.focus();
|
|
1430
|
+
}, DURATION_ANIMATION$1);
|
|
1409
1431
|
}
|
|
1410
1432
|
}
|
|
1411
1433
|
function onFocusInput() {
|
|
@@ -1459,15 +1481,15 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1459
1481
|
onValue(value);
|
|
1460
1482
|
}
|
|
1461
1483
|
}
|
|
1462
|
-
function
|
|
1463
|
-
const
|
|
1484
|
+
function refreshCoincidences(pattern, reboot = false) {
|
|
1485
|
+
const { collection, store } = createStoreAutocomplete({
|
|
1464
1486
|
pattern,
|
|
1465
1487
|
suggestions,
|
|
1466
1488
|
reboot,
|
|
1467
|
-
store
|
|
1489
|
+
store: currentStore.current
|
|
1468
1490
|
});
|
|
1469
|
-
|
|
1470
|
-
|
|
1491
|
+
currentStore.current = store;
|
|
1492
|
+
setCoincidences(collection.slice(0, MAX_ELEMENTS));
|
|
1471
1493
|
}
|
|
1472
1494
|
return {
|
|
1473
1495
|
coincidences,
|
|
@@ -1908,28 +1930,44 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
|
|
|
1908
1930
|
function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
1909
1931
|
const listControl = useListControl({ suggestions, formControl });
|
|
1910
1932
|
const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
|
|
1933
|
+
const initializedState = react.useRef(false);
|
|
1934
|
+
const initializedCollection = react.useRef(false);
|
|
1911
1935
|
const changeInternal = react.useRef(false);
|
|
1912
1936
|
react.useEffect(() => {
|
|
1937
|
+
if (!initializedState.current || !initializedCollection.current) {
|
|
1938
|
+
initializedState.current = true;
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1913
1941
|
if (changeInternal.current) {
|
|
1914
1942
|
changeInternal.current = false;
|
|
1943
|
+
return;
|
|
1915
1944
|
}
|
|
1916
|
-
|
|
1917
|
-
resetState(formControl?.state);
|
|
1918
|
-
}
|
|
1945
|
+
refresh(collection, formControl?.state);
|
|
1919
1946
|
}, [formControl?.state]);
|
|
1920
|
-
react.useEffect(() =>
|
|
1947
|
+
react.useEffect(() => {
|
|
1948
|
+
if (!initializedCollection.current || !initializedState.current) {
|
|
1949
|
+
initializedCollection.current = true;
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
refresh(collection, formControl?.state);
|
|
1953
|
+
}, [collection]);
|
|
1954
|
+
function refresh(collection, state) {
|
|
1955
|
+
if (!state) {
|
|
1956
|
+
return setValue('');
|
|
1957
|
+
}
|
|
1958
|
+
const element = collection.find(state);
|
|
1959
|
+
if (element) {
|
|
1960
|
+
return setValue(element.description);
|
|
1961
|
+
}
|
|
1962
|
+
setValue('');
|
|
1963
|
+
setFormState(undefined);
|
|
1964
|
+
}
|
|
1921
1965
|
function setFormState(value) {
|
|
1922
1966
|
if (formControl) {
|
|
1923
1967
|
changeInternal.current = true;
|
|
1924
1968
|
formControl.setState(value);
|
|
1925
1969
|
}
|
|
1926
1970
|
}
|
|
1927
|
-
function resetCollection(collection, state) {
|
|
1928
|
-
setValue(state ? collection.find(state)?.description || '' : '');
|
|
1929
|
-
}
|
|
1930
|
-
function resetState(state) {
|
|
1931
|
-
resetCollection(collection, state);
|
|
1932
|
-
}
|
|
1933
1971
|
function onFocusInput() {
|
|
1934
1972
|
setFocused(true);
|
|
1935
1973
|
}
|
|
@@ -1955,9 +1993,8 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
|
1955
1993
|
}
|
|
1956
1994
|
}
|
|
1957
1995
|
function onClickAction() {
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
if (newVisible) {
|
|
1996
|
+
setVisible(!visible);
|
|
1997
|
+
if (!visible) {
|
|
1961
1998
|
inputRef?.current?.focus();
|
|
1962
1999
|
}
|
|
1963
2000
|
}
|