aport-tools 4.4.21 → 4.4.22

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.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.21 | ISC */
1
+ /*! aport-tools v4.4.22 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -768,73 +768,71 @@ var InputList = function InputList(_a) {
768
768
  var colors = theme.colors;
769
769
  // Initialize selected options based on firstValue
770
770
  // Filter initial selections from options based on `firstValue`
771
- React.useMemo(function () {
771
+ var initialSelections = React.useMemo(function () {
772
772
  return options.filter(function (opt) {
773
773
  return firstValue.includes(opt.value);
774
774
  });
775
775
  }, [options, firstValue]);
776
776
  // State for selected options
777
- var _l = React.useState(multi ? firstValue : firstValue.length > 0 ? firstValue[0] : null),
777
+ var _l = React.useState(multi ? initialSelections : initialSelections[0] || null),
778
778
  selectedOptions = _l[0],
779
779
  setSelectedOptions = _l[1];
780
780
  // Update form value on mount if firstValue is provided
781
- // Update form value and internal state on mount or `firstValue` change
782
781
  React.useEffect(function () {
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);
782
+ if (firstValue && selectedOptions !== firstValue) {
783
+ setSelectedOptions(firstValue); // Only update if necessary
788
784
  }
789
- }, [firstValue, selectedOptions, multi]);
790
- // Handle option selection
785
+ }, [firstValue, selectedOptions]);
791
786
  var handleSelectOption = function handleSelectOption(option) {
792
787
  var updatedSelections;
793
788
  if (multi) {
794
- var alreadySelected = Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
789
+ // Ensure selectedOptions is treated as an array
790
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
791
+ var alreadySelected = selectedArray.some(function (opt) {
795
792
  return opt.id === option.id;
796
793
  });
797
- updatedSelections = alreadySelected ? selectedOptions.filter(function (opt) {
794
+ updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
798
795
  return opt.id !== option.id;
799
- }) : Array.isArray(selectedOptions) ? __spreadArray(__spreadArray([], selectedOptions, true), [option], false) : [option];
796
+ }) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
800
797
  if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
801
798
  setIsDropdownVisible(false);
802
799
  }
800
+ setFormValue(name, updatedSelections);
803
801
  } else {
802
+ // Handle single-selection case
804
803
  updatedSelections = option;
804
+ setFormValue(name, option);
805
805
  if (closeOnSelect) setIsDropdownVisible(false);
806
806
  }
807
- setSelectedOptions(updatedSelections);
808
- setFormValue(name, updatedSelections);
807
+ // Trigger onChange callback with the updated selection
809
808
  if (onChange) {
810
809
  onChange(updatedSelections);
811
810
  }
812
811
  };
813
- // Check if an option should be disabled
814
812
  var isItemDisabled = function isItemDisabled(option) {
815
- if (!multi) return false;
816
- return maxSelection && Array.isArray(selectedOptions) && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
813
+ if (!multi) return false; // Disable check only applies for multi-select
814
+ // Ensure selectedOptions is treated as an array
815
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
816
+ return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
817
817
  return opt.id === option.id;
818
818
  });
819
819
  };
820
- // Render selected text
821
820
  var renderSelectedText = function renderSelectedText() {
822
821
  if (multi) {
822
+ // Ensure selectedOptions is treated as an array
823
823
  var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
824
824
  return selectedArray.map(function (opt) {
825
825
  return opt.label;
826
- }).join(", ") || placeholder;
826
+ }).join(', ') || placeholder;
827
827
  }
828
828
  return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
829
829
  };
830
- // Toggle dropdown visibility
831
830
  var toggleDropdown = function toggleDropdown() {
832
831
  if (!disabled) {
833
832
  setIsDropdownVisible(!isDropdownVisible);
834
833
  if (!isDropdownVisible) reactNative.Keyboard.dismiss();
835
834
  }
836
835
  };
837
- // Close dropdown
838
836
  var handleCloseDropdown = React.useCallback(function () {
839
837
  if (isDropdownVisible) setIsDropdownVisible(false);
840
838
  }, [isDropdownVisible]);