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.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.21 | ISC */
1
+ /*! aport-tools v4.4.22 | ISC */
2
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';
@@ -747,73 +747,71 @@ var InputList = function InputList(_a) {
747
747
  var colors = theme.colors;
748
748
  // Initialize selected options based on firstValue
749
749
  // Filter initial selections from options based on `firstValue`
750
- useMemo(function () {
750
+ var initialSelections = useMemo(function () {
751
751
  return options.filter(function (opt) {
752
752
  return firstValue.includes(opt.value);
753
753
  });
754
754
  }, [options, firstValue]);
755
755
  // State for selected options
756
- var _l = useState(multi ? firstValue : firstValue.length > 0 ? firstValue[0] : null),
756
+ var _l = useState(multi ? initialSelections : initialSelections[0] || null),
757
757
  selectedOptions = _l[0],
758
758
  setSelectedOptions = _l[1];
759
759
  // Update form value on mount if firstValue is provided
760
- // Update form value and internal state on mount or `firstValue` change
761
760
  useEffect(function () {
762
- var isDifferent = multi ? Array.isArray(selectedOptions) && (selectedOptions.length !== firstValue.length || !selectedOptions.every(function (opt) {
763
- return firstValue.includes(opt);
764
- })) : selectedOptions !== firstValue[0];
765
- if (firstValue && isDifferent) {
766
- setSelectedOptions(multi ? firstValue : firstValue[0] || null);
761
+ if (firstValue && selectedOptions !== firstValue) {
762
+ setSelectedOptions(firstValue); // Only update if necessary
767
763
  }
768
- }, [firstValue, selectedOptions, multi]);
769
- // Handle option selection
764
+ }, [firstValue, selectedOptions]);
770
765
  var handleSelectOption = function handleSelectOption(option) {
771
766
  var updatedSelections;
772
767
  if (multi) {
773
- var alreadySelected = Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
768
+ // Ensure selectedOptions is treated as an array
769
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
770
+ var alreadySelected = selectedArray.some(function (opt) {
774
771
  return opt.id === option.id;
775
772
  });
776
- updatedSelections = alreadySelected ? selectedOptions.filter(function (opt) {
773
+ updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
777
774
  return opt.id !== option.id;
778
- }) : Array.isArray(selectedOptions) ? __spreadArray(__spreadArray([], selectedOptions, true), [option], false) : [option];
775
+ }) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
779
776
  if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
780
777
  setIsDropdownVisible(false);
781
778
  }
779
+ setFormValue(name, updatedSelections);
782
780
  } else {
781
+ // Handle single-selection case
783
782
  updatedSelections = option;
783
+ setFormValue(name, option);
784
784
  if (closeOnSelect) setIsDropdownVisible(false);
785
785
  }
786
- setSelectedOptions(updatedSelections);
787
- setFormValue(name, updatedSelections);
786
+ // Trigger onChange callback with the updated selection
788
787
  if (onChange) {
789
788
  onChange(updatedSelections);
790
789
  }
791
790
  };
792
- // Check if an option should be disabled
793
791
  var isItemDisabled = function isItemDisabled(option) {
794
- if (!multi) return false;
795
- return maxSelection && Array.isArray(selectedOptions) && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
792
+ if (!multi) return false; // Disable check only applies for multi-select
793
+ // Ensure selectedOptions is treated as an array
794
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
795
+ return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
796
796
  return opt.id === option.id;
797
797
  });
798
798
  };
799
- // Render selected text
800
799
  var renderSelectedText = function renderSelectedText() {
801
800
  if (multi) {
801
+ // Ensure selectedOptions is treated as an array
802
802
  var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
803
803
  return selectedArray.map(function (opt) {
804
804
  return opt.label;
805
- }).join(", ") || placeholder;
805
+ }).join(', ') || placeholder;
806
806
  }
807
807
  return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
808
808
  };
809
- // Toggle dropdown visibility
810
809
  var toggleDropdown = function toggleDropdown() {
811
810
  if (!disabled) {
812
811
  setIsDropdownVisible(!isDropdownVisible);
813
812
  if (!isDropdownVisible) Keyboard.dismiss();
814
813
  }
815
814
  };
816
- // Close dropdown
817
815
  var handleCloseDropdown = useCallback(function () {
818
816
  if (isDropdownVisible) setIsDropdownVisible(false);
819
817
  }, [isDropdownVisible]);