aport-tools 4.4.20 → 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.20 | 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';
@@ -757,61 +757,61 @@ var InputList = function InputList(_a) {
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
761
  if (firstValue && selectedOptions !== firstValue) {
763
- setSelectedOptions(multi ? initialSelections : initialSelections[0] || null);
764
- setFormValue(name, multi ? initialSelections : initialSelections[0] || null);
762
+ setSelectedOptions(firstValue); // Only update if necessary
765
763
  }
766
- }, [firstValue, initialSelections, multi, name, selectedOptions, setFormValue]);
767
- // Handle option selection
764
+ }, [firstValue, selectedOptions]);
768
765
  var handleSelectOption = function handleSelectOption(option) {
769
766
  var updatedSelections;
770
767
  if (multi) {
771
- 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) {
772
771
  return opt.id === option.id;
773
772
  });
774
- updatedSelections = alreadySelected ? selectedOptions.filter(function (opt) {
773
+ updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
775
774
  return opt.id !== option.id;
776
- }) : Array.isArray(selectedOptions) ? __spreadArray(__spreadArray([], selectedOptions, true), [option], false) : [option];
775
+ }) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
777
776
  if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
778
777
  setIsDropdownVisible(false);
779
778
  }
779
+ setFormValue(name, updatedSelections);
780
780
  } else {
781
+ // Handle single-selection case
781
782
  updatedSelections = option;
783
+ setFormValue(name, option);
782
784
  if (closeOnSelect) setIsDropdownVisible(false);
783
785
  }
784
- setSelectedOptions(updatedSelections);
785
- setFormValue(name, updatedSelections);
786
+ // Trigger onChange callback with the updated selection
786
787
  if (onChange) {
787
788
  onChange(updatedSelections);
788
789
  }
789
790
  };
790
- // Check if an option should be disabled
791
791
  var isItemDisabled = function isItemDisabled(option) {
792
- if (!multi) return false;
793
- 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) {
794
796
  return opt.id === option.id;
795
797
  });
796
798
  };
797
- // Render selected text
798
799
  var renderSelectedText = function renderSelectedText() {
799
800
  if (multi) {
801
+ // Ensure selectedOptions is treated as an array
800
802
  var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
801
803
  return selectedArray.map(function (opt) {
802
804
  return opt.label;
803
- }).join(", ") || placeholder;
805
+ }).join(', ') || placeholder;
804
806
  }
805
807
  return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
806
808
  };
807
- // Toggle dropdown visibility
808
809
  var toggleDropdown = function toggleDropdown() {
809
810
  if (!disabled) {
810
811
  setIsDropdownVisible(!isDropdownVisible);
811
812
  if (!isDropdownVisible) Keyboard.dismiss();
812
813
  }
813
814
  };
814
- // Close dropdown
815
815
  var handleCloseDropdown = useCallback(function () {
816
816
  if (isDropdownVisible) setIsDropdownVisible(false);
817
817
  }, [isDropdownVisible]);