aport-tools 4.4.14 → 4.4.16
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/forms/InputList.d.ts +1 -1
- package/dist/index.esm.js +49 -53
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +48 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
2
|
-
import React, { useContext, useState, createContext, useEffect,
|
1
|
+
/*! aport-tools v4.4.16 | ISC */
|
2
|
+
import React, { useContext, useState, createContext, useEffect, useMemo, useCallback } from 'react';
|
3
3
|
import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
|
4
4
|
import { ThemeContext } from 'aport-themes';
|
5
5
|
import * as ImagePicker from 'expo-image-picker';
|
@@ -730,29 +730,34 @@ var InputList = function InputList(_a) {
|
|
730
730
|
closeOnSelect = _h === void 0 ? true : _h,
|
731
731
|
maxSelection = _a.maxSelection,
|
732
732
|
onChange = _a.onChange;
|
733
|
-
var _j = useFormContext()
|
734
|
-
_j.formValues
|
735
|
-
|
733
|
+
var _j = useFormContext(),
|
734
|
+
formValues = _j.formValues,
|
735
|
+
setFormValue = _j.setFormValue,
|
736
736
|
formErrors = _j.errors;
|
737
737
|
var _k = useState(false),
|
738
738
|
isDropdownVisible = _k[0],
|
739
739
|
setIsDropdownVisible = _k[1];
|
740
|
-
var
|
741
|
-
|
742
|
-
|
740
|
+
var selectedOptions = formValues[name] || (multi ? [] : null);
|
741
|
+
var sortedOptions = useMemo(function () {
|
742
|
+
return sortBy ? __spreadArray([], options, true).sort(function (a, b) {
|
743
|
+
return a[sortBy] > b[sortBy] ? 1 : -1;
|
744
|
+
}) : options;
|
745
|
+
}, [options, sortBy]);
|
743
746
|
var theme = useContext(ThemeContext).theme;
|
744
747
|
var colors = theme.colors;
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
var _l = useState(multi ? initialSelections : initialSelections[0] || null),
|
750
|
-
selectedOptions = _l[0];
|
751
|
-
_l[1];
|
752
|
-
// Update form value on mount if firstValue is provided
|
748
|
+
var _l = useState([]);
|
749
|
+
_l[0];
|
750
|
+
var setInternalValue = _l[1];
|
751
|
+
// Initialize the internal value based on `firstValue` or `formValues`
|
753
752
|
useEffect(function () {
|
754
|
-
|
755
|
-
|
753
|
+
var selectedValue = formValues[name];
|
754
|
+
if (firstValue) {
|
755
|
+
setInternalValue(firstValue);
|
756
|
+
setFormValue(name, firstValue);
|
757
|
+
} else {
|
758
|
+
setInternalValue(selectedValue || "");
|
759
|
+
}
|
760
|
+
}, [firstValue, formValues[name]]);
|
756
761
|
/**
|
757
762
|
* Handles selection of an option. Adds or removes the option from selectedOptions based on
|
758
763
|
* multi-selection and maxSelection criteria.
|
@@ -761,49 +766,35 @@ var InputList = function InputList(_a) {
|
|
761
766
|
var handleSelectOption = function handleSelectOption(option) {
|
762
767
|
var updatedSelections;
|
763
768
|
if (multi) {
|
764
|
-
|
765
|
-
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
766
|
-
var alreadySelected = selectedArray.some(function (opt) {
|
769
|
+
var alreadySelected = (selectedOptions || []).some(function (opt) {
|
767
770
|
return opt.id === option.id;
|
768
771
|
});
|
769
|
-
updatedSelections = alreadySelected ?
|
772
|
+
updatedSelections = alreadySelected ? (selectedOptions || []).filter(function (opt) {
|
770
773
|
return opt.id !== option.id;
|
771
|
-
}) : __spreadArray(__spreadArray([],
|
774
|
+
}) : __spreadArray(__spreadArray([], selectedOptions || [], true), [option], false);
|
772
775
|
if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
|
773
776
|
setIsDropdownVisible(false);
|
774
777
|
}
|
778
|
+
setInternalValue(updatedSelections);
|
775
779
|
setFormValue(name, updatedSelections);
|
776
780
|
} else {
|
777
|
-
// Handle single-selection case
|
778
781
|
updatedSelections = option;
|
782
|
+
setInternalValue(option);
|
779
783
|
setFormValue(name, option);
|
780
784
|
if (closeOnSelect) setIsDropdownVisible(false);
|
781
785
|
}
|
782
|
-
// Trigger onChange callback with the updated selection
|
783
786
|
if (onChange) {
|
784
787
|
onChange(updatedSelections);
|
785
788
|
}
|
786
789
|
};
|
787
|
-
var isItemDisabled = function isItemDisabled(option) {
|
788
|
-
if (!multi) return false; // Disable check only applies for multi-select
|
789
|
-
// Ensure selectedOptions is treated as an array
|
790
|
-
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
791
|
-
return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
|
792
|
-
return opt.id === option.id;
|
793
|
-
});
|
794
|
-
};
|
795
790
|
/**
|
796
|
-
|
797
|
-
|
798
|
-
|
791
|
+
* Renders selected options as a comma-separated string or the placeholder if none selected.
|
792
|
+
* @returns {string} - The display text for selected options or placeholder.
|
793
|
+
*/
|
799
794
|
var renderSelectedText = function renderSelectedText() {
|
800
|
-
if (multi) {
|
801
|
-
|
802
|
-
|
803
|
-
return selectedArray.map(function (opt) {
|
804
|
-
return opt.label;
|
805
|
-
}).join(', ') || placeholder;
|
806
|
-
}
|
795
|
+
if (multi) return (selectedOptions || []).map(function (opt) {
|
796
|
+
return opt.label;
|
797
|
+
}).join(", ") || placeholder;
|
807
798
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
808
799
|
};
|
809
800
|
/**
|
@@ -822,6 +813,11 @@ var InputList = function InputList(_a) {
|
|
822
813
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
823
814
|
}, [isDropdownVisible]);
|
824
815
|
// Conditionally render item as disabled if max selection reached and item is unselected
|
816
|
+
var isItemDisabled = function isItemDisabled(option) {
|
817
|
+
return multi && maxSelection && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
|
818
|
+
return opt.id === option.id;
|
819
|
+
});
|
820
|
+
};
|
825
821
|
return /*#__PURE__*/React.createElement(View, {
|
826
822
|
style: [styles$4.container, style]
|
827
823
|
}, /*#__PURE__*/React.createElement(Text$1, {
|
@@ -859,9 +855,9 @@ var InputList = function InputList(_a) {
|
|
859
855
|
},
|
860
856
|
renderItem: function renderItem(_a) {
|
861
857
|
var item = _a.item;
|
862
|
-
var isSelected = multi ?
|
858
|
+
var isSelected = multi ? selectedOptions.some(function (opt) {
|
863
859
|
return opt.id === item.id;
|
864
|
-
}) : selectedOptions
|
860
|
+
}) : (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.id) === item.id;
|
865
861
|
var isDisabled = isItemDisabled(item);
|
866
862
|
return /*#__PURE__*/React.createElement(TouchableOpacity, {
|
867
863
|
onPress: function onPress() {
|
@@ -899,12 +895,12 @@ var styles$4 = StyleSheet.create({
|
|
899
895
|
borderRadius: 5
|
900
896
|
},
|
901
897
|
dropdownContainer: {
|
902
|
-
position:
|
903
|
-
top:
|
898
|
+
position: "absolute",
|
899
|
+
top: "30%",
|
904
900
|
// Center the dropdown vertically
|
905
|
-
alignSelf:
|
906
|
-
width:
|
907
|
-
backgroundColor:
|
901
|
+
alignSelf: "center",
|
902
|
+
width: "90%",
|
903
|
+
backgroundColor: "#fff",
|
908
904
|
borderRadius: 8,
|
909
905
|
elevation: 5,
|
910
906
|
paddingVertical: 10
|
@@ -913,16 +909,16 @@ var styles$4 = StyleSheet.create({
|
|
913
909
|
padding: 12
|
914
910
|
},
|
915
911
|
disabledText: {
|
916
|
-
color:
|
912
|
+
color: "#999"
|
917
913
|
},
|
918
914
|
separator: {
|
919
915
|
height: 1,
|
920
|
-
backgroundColor:
|
916
|
+
backgroundColor: "#ddd",
|
921
917
|
marginHorizontal: 8
|
922
918
|
},
|
923
919
|
overlay: {
|
924
920
|
flex: 1,
|
925
|
-
backgroundColor:
|
921
|
+
backgroundColor: "rgba(0,0,0,0.3)"
|
926
922
|
}
|
927
923
|
});
|
928
924
|
|