aport-tools 4.4.25 → 4.4.27

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.25 | ISC */
1
+ /*! aport-tools v4.4.27 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -1036,19 +1036,39 @@ var InputCheck = function InputCheck(_a) {
1036
1036
  max = _a.max,
1037
1037
  _c = _a.rowAmount,
1038
1038
  rowAmount = _c === void 0 ? 3 : _c,
1039
- _d = _a.iconPosition,
1040
- iconPosition = _d === void 0 ? "row" : _d,
1041
- _e = _a.disabled,
1042
- disabled = _e === void 0 ? false : _e;
1043
- var _f = useFormContext(),
1044
- formValues = _f.formValues,
1045
- setFormValue = _f.setFormValue,
1046
- formErrors = _f.errors;
1047
- var _g = React.useState(formValues[name] || []),
1048
- selectedValues = _g[0],
1049
- setSelectedValues = _g[1];
1039
+ _d = _a.firstValue,
1040
+ firstValue = _d === void 0 ? [] : _d,
1041
+ _e = _a.iconPosition,
1042
+ iconPosition = _e === void 0 ? "row" : _e,
1043
+ _f = _a.disabled,
1044
+ disabled = _f === void 0 ? false : _f;
1045
+ var _g = useFormContext(),
1046
+ formValues = _g.formValues,
1047
+ setFormValue = _g.setFormValue,
1048
+ formErrors = _g.errors;
1049
+ var _h = React.useState(formValues[name] || []),
1050
+ selectedValues = _h[0],
1051
+ setSelectedValues = _h[1];
1050
1052
  var theme = React.useContext(aportThemes.ThemeContext).theme;
1051
1053
  var colors = theme.colors;
1054
+ // Sync firstValue with selectedValues on mount or when firstValue changes
1055
+ React.useEffect(function () {
1056
+ var initialSelectedValues = options.filter(function (option) {
1057
+ return firstValue.some(function (fv) {
1058
+ return fv.value === option.value;
1059
+ });
1060
+ });
1061
+ var formattedValues = initialSelectedValues.map(function (_a) {
1062
+ var id = _a.id,
1063
+ value = _a.value;
1064
+ return {
1065
+ id: id,
1066
+ value: value
1067
+ };
1068
+ });
1069
+ setSelectedValues(formattedValues);
1070
+ setFormValue(name, formattedValues); // Update form context
1071
+ }, [firstValue, name, options, setFormValue]);
1052
1072
  var handleSelect = function handleSelect(id, value) {
1053
1073
  if (disabled) return;
1054
1074
  var updatedSelection;
@@ -1096,11 +1116,11 @@ var InputCheck = function InputCheck(_a) {
1096
1116
  uri: item.icon
1097
1117
  },
1098
1118
  style: [styles$2.icon, iconPosition === "column" && styles$2.iconColumn]
1099
- })), /*#__PURE__*/React.createElement(Text, {
1119
+ })), item.label && (/*#__PURE__*/React.createElement(Text, {
1100
1120
  style: [styles$2.label, {
1101
1121
  color: isSelected ? colors.textButton.hex : colors.text.hex
1102
1122
  }]
1103
- }, item.label));
1123
+ }, item.label)));
1104
1124
  };
1105
1125
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
1106
1126
  style: styles$2.title
@@ -1168,18 +1188,19 @@ var InputAttach = function InputAttach(_a) {
1168
1188
  var _g = useFormContext(),
1169
1189
  setFormValue = _g.setFormValue,
1170
1190
  formErrors = _g.errors;
1171
- // Initialize with firstValue or an empty array
1172
- var _h = React.useState(function () {
1173
- return Array.isArray(firstValue) ? firstValue.slice(0, amount) : [];
1174
- }),
1191
+ var _h = React.useState([]),
1175
1192
  selectedFiles = _h[0],
1176
1193
  setSelectedFiles = _h[1];
1177
- // Update the form context on mount with firstValue if provided
1194
+ // Ref to track initialization
1195
+ var isInitialized = React.useRef(false);
1196
+ // Sync firstValue with selectedFiles when it changes
1178
1197
  React.useEffect(function () {
1179
- if (firstValue.length > 0) {
1180
- setFormValue(name, firstValue.slice(0, amount));
1198
+ if (!isInitialized.current) {
1199
+ setSelectedFiles(firstValue);
1200
+ setFormValue(name, firstValue); // Update form context
1201
+ isInitialized.current = true;
1181
1202
  }
1182
- }, [firstValue, name, setFormValue, amount]);
1203
+ }, [firstValue, name, setFormValue]);
1183
1204
  var theme = React.useContext(aportThemes.ThemeContext).theme;
1184
1205
  var colors = theme.colors;
1185
1206
  var pickImage = function pickImage() {