aport-tools 4.4.12 → 4.4.14
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/Input.d.ts +4 -0
- package/dist/forms/InputList.d.ts +4 -0
- package/dist/forms/TextArea.d.ts +4 -0
- package/dist/index.esm.js +87 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +86 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.14 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -538,14 +538,27 @@ var Input = function Input(_a) {
|
|
538
538
|
var name = _a.name,
|
539
539
|
label = _a.label,
|
540
540
|
inputType = _a.inputType,
|
541
|
+
firstValue = _a.firstValue,
|
541
542
|
style = _a.style,
|
542
|
-
rest = __rest(_a, ["name", "label", "inputType", "style"]);
|
543
|
+
rest = __rest(_a, ["name", "label", "inputType", "firstValue", "style"]);
|
543
544
|
var _b = useFormContext(),
|
544
545
|
formValues = _b.formValues,
|
545
546
|
setFormValue = _b.setFormValue,
|
546
547
|
formErrors = _b.errors;
|
547
548
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
548
549
|
var colors = theme.colors;
|
550
|
+
var _c = React.useState(""),
|
551
|
+
internalValue = _c[0],
|
552
|
+
setInternalValue = _c[1];
|
553
|
+
// Initialize the internal value based on `firstValue` or `formValues`
|
554
|
+
React.useEffect(function () {
|
555
|
+
if (firstValue) {
|
556
|
+
setInternalValue(firstValue);
|
557
|
+
setFormValue(name, firstValue);
|
558
|
+
} else {
|
559
|
+
setInternalValue(formValues[name] || "");
|
560
|
+
}
|
561
|
+
}, [firstValue, formValues[name]]);
|
549
562
|
/**
|
550
563
|
* Handles text changes in the input field, applying formatting based on the inputType.
|
551
564
|
*
|
@@ -575,6 +588,7 @@ var Input = function Input(_a) {
|
|
575
588
|
formattedText = text.replace(/\D/g, "");
|
576
589
|
break;
|
577
590
|
}
|
591
|
+
setInternalValue(formattedText);
|
578
592
|
setFormValue(name, formattedText);
|
579
593
|
};
|
580
594
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
@@ -589,7 +603,7 @@ var Input = function Input(_a) {
|
|
589
603
|
borderColor: formErrors[name] ? colors.error.hex : "#CCC",
|
590
604
|
color: colors.text.hex
|
591
605
|
}, style],
|
592
|
-
value:
|
606
|
+
value: internalValue,
|
593
607
|
onChangeText: handleChange,
|
594
608
|
placeholder: label,
|
595
609
|
placeholderTextColor: colors.placeHolder.hex
|
@@ -618,15 +632,29 @@ var TextArea = function TextArea(_a) {
|
|
618
632
|
var name = _a.name,
|
619
633
|
label = _a.label;
|
620
634
|
_a.errors;
|
621
|
-
var
|
622
|
-
|
635
|
+
var firstValue = _a.firstValue,
|
636
|
+
style = _a.style,
|
637
|
+
rest = __rest(_a, ["name", "label", "errors", "firstValue", "style"]);
|
623
638
|
var _b = useFormContext(),
|
624
639
|
formValues = _b.formValues,
|
625
640
|
setFormValue = _b.setFormValue,
|
626
641
|
formErrors = _b.errors;
|
627
642
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
628
643
|
var colors = theme.colors;
|
644
|
+
var _c = React.useState(""),
|
645
|
+
internalValue = _c[0],
|
646
|
+
setInternalValue = _c[1];
|
647
|
+
// Initialize the internal value based on `firstValue` or `formValues`
|
648
|
+
React.useEffect(function () {
|
649
|
+
if (firstValue) {
|
650
|
+
setInternalValue(firstValue);
|
651
|
+
setFormValue(name, firstValue);
|
652
|
+
} else {
|
653
|
+
setInternalValue(formValues[name] || "");
|
654
|
+
}
|
655
|
+
}, [firstValue, formValues[name]]);
|
629
656
|
var handleChange = function handleChange(text) {
|
657
|
+
setInternalValue(text);
|
630
658
|
setFormValue(name, text);
|
631
659
|
};
|
632
660
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
@@ -641,7 +669,7 @@ var TextArea = function TextArea(_a) {
|
|
641
669
|
color: colors.text.hex,
|
642
670
|
borderColor: formErrors[name] ? colors.error.hex : "#CCC"
|
643
671
|
}],
|
644
|
-
value:
|
672
|
+
value: internalValue,
|
645
673
|
onChangeText: handleChange,
|
646
674
|
placeholder: label,
|
647
675
|
placeholderTextColor: colors.placeHolder.hex,
|
@@ -713,27 +741,39 @@ var InputList = function InputList(_a) {
|
|
713
741
|
_d = _a.disabled,
|
714
742
|
disabled = _d === void 0 ? false : _d,
|
715
743
|
sortBy = _a.sortBy,
|
716
|
-
_e = _a.
|
717
|
-
|
718
|
-
_f = _a.
|
719
|
-
|
720
|
-
_g = _a.
|
721
|
-
|
744
|
+
_e = _a.firstValue,
|
745
|
+
firstValue = _e === void 0 ? [] : _e,
|
746
|
+
_f = _a.separator,
|
747
|
+
separator = _f === void 0 ? false : _f,
|
748
|
+
_g = _a.closeOnScroll,
|
749
|
+
closeOnScroll = _g === void 0 ? false : _g,
|
750
|
+
_h = _a.closeOnSelect,
|
751
|
+
closeOnSelect = _h === void 0 ? true : _h,
|
722
752
|
maxSelection = _a.maxSelection,
|
723
753
|
onChange = _a.onChange;
|
724
|
-
var
|
725
|
-
|
726
|
-
setFormValue =
|
727
|
-
formErrors =
|
728
|
-
var
|
729
|
-
isDropdownVisible =
|
730
|
-
setIsDropdownVisible =
|
731
|
-
var selectedOptions = formValues[name] || (multi ? [] : null);
|
754
|
+
var _j = useFormContext();
|
755
|
+
_j.formValues;
|
756
|
+
var setFormValue = _j.setFormValue,
|
757
|
+
formErrors = _j.errors;
|
758
|
+
var _k = React.useState(false),
|
759
|
+
isDropdownVisible = _k[0],
|
760
|
+
setIsDropdownVisible = _k[1];
|
732
761
|
var sortedOptions = sortBy ? __spreadArray([], options, true).sort(function (a, b) {
|
733
762
|
return a[sortBy] > b[sortBy] ? 1 : -1;
|
734
763
|
}) : options;
|
735
764
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
736
765
|
var colors = theme.colors;
|
766
|
+
// Initialize selected options based on firstValue
|
767
|
+
var initialSelections = options.filter(function (opt) {
|
768
|
+
return firstValue.includes(opt.value);
|
769
|
+
});
|
770
|
+
var _l = React.useState(multi ? initialSelections : initialSelections[0] || null),
|
771
|
+
selectedOptions = _l[0];
|
772
|
+
_l[1];
|
773
|
+
// Update form value on mount if firstValue is provided
|
774
|
+
React.useEffect(function () {
|
775
|
+
setFormValue(name, multi ? initialSelections : initialSelections[0] || null);
|
776
|
+
}, [firstValue]);
|
737
777
|
/**
|
738
778
|
* Handles selection of an option. Adds or removes the option from selectedOptions based on
|
739
779
|
* multi-selection and maxSelection criteria.
|
@@ -742,17 +782,20 @@ var InputList = function InputList(_a) {
|
|
742
782
|
var handleSelectOption = function handleSelectOption(option) {
|
743
783
|
var updatedSelections;
|
744
784
|
if (multi) {
|
745
|
-
|
785
|
+
// Ensure selectedOptions is treated as an array
|
786
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
787
|
+
var alreadySelected = selectedArray.some(function (opt) {
|
746
788
|
return opt.id === option.id;
|
747
789
|
});
|
748
|
-
updatedSelections = alreadySelected ?
|
790
|
+
updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
|
749
791
|
return opt.id !== option.id;
|
750
|
-
}) : __spreadArray(__spreadArray([],
|
792
|
+
}) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
|
751
793
|
if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
|
752
794
|
setIsDropdownVisible(false);
|
753
795
|
}
|
754
796
|
setFormValue(name, updatedSelections);
|
755
797
|
} else {
|
798
|
+
// Handle single-selection case
|
756
799
|
updatedSelections = option;
|
757
800
|
setFormValue(name, option);
|
758
801
|
if (closeOnSelect) setIsDropdownVisible(false);
|
@@ -762,14 +805,26 @@ var InputList = function InputList(_a) {
|
|
762
805
|
onChange(updatedSelections);
|
763
806
|
}
|
764
807
|
};
|
808
|
+
var isItemDisabled = function isItemDisabled(option) {
|
809
|
+
if (!multi) return false; // Disable check only applies for multi-select
|
810
|
+
// Ensure selectedOptions is treated as an array
|
811
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
812
|
+
return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
|
813
|
+
return opt.id === option.id;
|
814
|
+
});
|
815
|
+
};
|
765
816
|
/**
|
766
|
-
|
767
|
-
|
768
|
-
|
817
|
+
* Renders selected options as a comma-separated string or the placeholder if none selected.
|
818
|
+
* @returns {string} - The display text for selected options or placeholder.
|
819
|
+
*/
|
769
820
|
var renderSelectedText = function renderSelectedText() {
|
770
|
-
if (multi)
|
771
|
-
|
772
|
-
|
821
|
+
if (multi) {
|
822
|
+
// Ensure selectedOptions is treated as an array
|
823
|
+
var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
|
824
|
+
return selectedArray.map(function (opt) {
|
825
|
+
return opt.label;
|
826
|
+
}).join(', ') || placeholder;
|
827
|
+
}
|
773
828
|
return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
|
774
829
|
};
|
775
830
|
/**
|
@@ -788,11 +843,6 @@ var InputList = function InputList(_a) {
|
|
788
843
|
if (isDropdownVisible) setIsDropdownVisible(false);
|
789
844
|
}, [isDropdownVisible]);
|
790
845
|
// Conditionally render item as disabled if max selection reached and item is unselected
|
791
|
-
var isItemDisabled = function isItemDisabled(option) {
|
792
|
-
return multi && maxSelection && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
|
793
|
-
return opt.id === option.id;
|
794
|
-
});
|
795
|
-
};
|
796
846
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
797
847
|
style: [styles$4.container, style]
|
798
848
|
}, /*#__PURE__*/React.createElement(reactNative.Text, {
|
@@ -830,9 +880,9 @@ var InputList = function InputList(_a) {
|
|
830
880
|
},
|
831
881
|
renderItem: function renderItem(_a) {
|
832
882
|
var item = _a.item;
|
833
|
-
var isSelected = multi ? selectedOptions.some(function (opt) {
|
883
|
+
var isSelected = multi ? Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
|
834
884
|
return opt.id === item.id;
|
835
|
-
}) :
|
885
|
+
}) : selectedOptions && 'id' in selectedOptions && selectedOptions.id === item.id;
|
836
886
|
var isDisabled = isItemDisabled(item);
|
837
887
|
return /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
838
888
|
onPress: function onPress() {
|