aport-tools 4.4.30 → 4.4.31

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.30 | ISC */
1
+ /*! aport-tools v4.4.31 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -416,40 +416,44 @@ var Form = function Form(_a) {
416
416
  var _c = React.useState({}),
417
417
  errors = _c[0],
418
418
  setErrors = _c[1];
419
- var setFormValue = function setFormValue(name, value) {
419
+ var _d = React.useState({}),
420
+ firstValues = _d[0],
421
+ setFirstValues = _d[1]; // Track firstValues
422
+ var setFormValue = function setFormValue(name, value, firstValue) {
420
423
  setFormValues(function (prev) {
421
424
  var _a;
422
425
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
423
426
  });
427
+ if (firstValue !== undefined) {
428
+ setFirstValues(function (prev) {
429
+ var _a;
430
+ return __assign(__assign({}, prev), (_a = {}, _a[name] = firstValue, _a));
431
+ });
432
+ }
424
433
  };
425
434
  var handleSubmit = function handleSubmit() {
426
435
  return __awaiter(void 0, void 0, void 0, function () {
427
- var modifiedFields, validationErrors;
436
+ var modifiedValues, validationErrors;
428
437
  return __generator(this, function (_a) {
429
438
  switch (_a.label) {
430
439
  case 0:
431
- modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
432
- var currentField = formValues[key];
433
- // Check if firstValue exists
434
- if ((currentField === null || currentField === void 0 ? void 0 : currentField.firstValue) !== undefined) {
435
- // Only include the field if the value has changed
436
- if (currentField.value !== currentField.firstValue) {
437
- acc[key] = currentField.value;
438
- }
439
- } else {
440
- // Include the field if firstValue is not defined
441
- acc[key] = currentField.value;
440
+ modifiedValues = Object.keys(formValues).reduce(function (result, key) {
441
+ var hasFirstValue = key in firstValues;
442
+ var isModified = hasFirstValue && formValues[key] !== firstValues[key];
443
+ var isNewValue = !hasFirstValue;
444
+ if (isModified || isNewValue) {
445
+ result[key] = formValues[key];
442
446
  }
443
- return acc;
447
+ return result;
444
448
  }, {});
445
- return [4 /*yield*/, onSubmit(modifiedFields)];
449
+ return [4 /*yield*/, onSubmit(modifiedValues)];
446
450
  case 1:
447
451
  validationErrors = _a.sent();
448
452
  // Set the validation errors in state
449
453
  setErrors(validationErrors);
450
- // Prevent submission if there are validation errors
454
+ // Prevent submission if there are any errors
451
455
  if (Object.keys(validationErrors).length > 0) {
452
- return [2 /*return*/]; // Exit early if errors are present
456
+ return [2 /*return*/]; // Prevent submission
453
457
  }
454
458
  return [2 /*return*/];
455
459
  }
@@ -573,12 +577,12 @@ var Input = function Input(_a) {
573
577
  isFirstRender.current = false;
574
578
  if (firstValue !== undefined) {
575
579
  setInternalValue(firstValue);
576
- setFormValue(name, firstValue);
580
+ setFormValue(name, firstValue, firstValue); // Pass firstValue here
577
581
  } else {
578
582
  setInternalValue(formValues[name] || "");
579
583
  }
580
584
  }
581
- }, [firstValue]); // Only re-run if `firstValue` changes
585
+ }, [firstValue]);
582
586
  /**
583
587
  * Handles text changes in the input field, applying formatting based on the inputType.
584
588
  *