aport-tools 4.4.19 → 4.4.21
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/index.esm.js +39 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +38 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.21 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -758,72 +758,83 @@ var InputList = function InputList(_a) {
|
|
758
758
|
var _k = React.useState(false),
|
759
759
|
isDropdownVisible = _k[0],
|
760
760
|
setIsDropdownVisible = _k[1];
|
761
|
-
|
762
|
-
|
763
|
-
|
761
|
+
// Memoize sorted options for performance
|
762
|
+
var sortedOptions = React.useMemo(function () {
|
763
|
+
return sortBy ? __spreadArray([], options, true).sort(function (a, b) {
|
764
|
+
return a[sortBy] > b[sortBy] ? 1 : -1;
|
765
|
+
}) : options;
|
766
|
+
}, [options, sortBy]);
|
764
767
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
765
768
|
var colors = theme.colors;
|
766
769
|
// Initialize selected options based on firstValue
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
770
|
+
// Filter initial selections from options based on `firstValue`
|
771
|
+
React.useMemo(function () {
|
772
|
+
return options.filter(function (opt) {
|
773
|
+
return firstValue.includes(opt.value);
|
774
|
+
});
|
775
|
+
}, [options, firstValue]);
|
776
|
+
// State for selected options
|
777
|
+
var _l = React.useState(multi ? firstValue : firstValue.length > 0 ? firstValue[0] : null),
|
778
|
+
selectedOptions = _l[0],
|
779
|
+
setSelectedOptions = _l[1];
|
773
780
|
// Update form value on mount if firstValue is provided
|
781
|
+
// Update form value and internal state on mount or `firstValue` change
|
774
782
|
React.useEffect(function () {
|
775
|
-
|
776
|
-
|
783
|
+
var isDifferent = multi ? Array.isArray(selectedOptions) && (selectedOptions.length !== firstValue.length || !selectedOptions.every(function (opt) {
|
784
|
+
return firstValue.includes(opt);
|
785
|
+
})) : selectedOptions !== firstValue[0];
|
786
|
+
if (firstValue && isDifferent) {
|
787
|
+
setSelectedOptions(multi ? firstValue : firstValue[0] || null);
|
788
|
+
}
|
789
|
+
}, [firstValue, selectedOptions, multi]);
|
790
|
+
// Handle option selection
|
777
791
|
var handleSelectOption = function handleSelectOption(option) {
|
778
792
|
var updatedSelections;
|
779
793
|
if (multi) {
|
780
|
-
|
781
|
-
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
782
|
-
var alreadySelected = selectedArray.some(function (opt) {
|
794
|
+
var alreadySelected = Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
|
783
795
|
return opt.id === option.id;
|
784
796
|
});
|
785
|
-
updatedSelections = alreadySelected ?
|
797
|
+
updatedSelections = alreadySelected ? selectedOptions.filter(function (opt) {
|
786
798
|
return opt.id !== option.id;
|
787
|
-
}) : __spreadArray(__spreadArray([],
|
799
|
+
}) : Array.isArray(selectedOptions) ? __spreadArray(__spreadArray([], selectedOptions, true), [option], false) : [option];
|
788
800
|
if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
|
789
801
|
setIsDropdownVisible(false);
|
790
802
|
}
|
791
|
-
setFormValue(name, updatedSelections);
|
792
803
|
} else {
|
793
|
-
// Handle single-selection case
|
794
804
|
updatedSelections = option;
|
795
|
-
setFormValue(name, option);
|
796
805
|
if (closeOnSelect) setIsDropdownVisible(false);
|
797
806
|
}
|
798
|
-
|
807
|
+
setSelectedOptions(updatedSelections);
|
808
|
+
setFormValue(name, updatedSelections);
|
799
809
|
if (onChange) {
|
800
810
|
onChange(updatedSelections);
|
801
811
|
}
|
802
812
|
};
|
813
|
+
// Check if an option should be disabled
|
803
814
|
var isItemDisabled = function isItemDisabled(option) {
|
804
|
-
if (!multi) return false;
|
805
|
-
|
806
|
-
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
807
|
-
return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
|
815
|
+
if (!multi) return false;
|
816
|
+
return maxSelection && Array.isArray(selectedOptions) && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
|
808
817
|
return opt.id === option.id;
|
809
818
|
});
|
810
819
|
};
|
820
|
+
// Render selected text
|
811
821
|
var renderSelectedText = function renderSelectedText() {
|
812
822
|
if (multi) {
|
813
|
-
// Ensure selectedOptions is treated as an array
|
814
823
|
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
815
824
|
return selectedArray.map(function (opt) {
|
816
825
|
return opt.label;
|
817
|
-
}).join(
|
826
|
+
}).join(", ") || placeholder;
|
818
827
|
}
|
819
828
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
820
829
|
};
|
830
|
+
// Toggle dropdown visibility
|
821
831
|
var toggleDropdown = function toggleDropdown() {
|
822
832
|
if (!disabled) {
|
823
833
|
setIsDropdownVisible(!isDropdownVisible);
|
824
834
|
if (!isDropdownVisible) reactNative.Keyboard.dismiss();
|
825
835
|
}
|
826
836
|
};
|
837
|
+
// Close dropdown
|
827
838
|
var handleCloseDropdown = React.useCallback(function () {
|
828
839
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
829
840
|
}, [isDropdownVisible]);
|