aport-tools 4.4.21 → 4.4.23

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