aport-tools 4.4.28 → 4.4.29

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.28 | ISC */
1
+ /*! aport-tools v4.4.29 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -416,42 +416,66 @@ var Form = function Form(_a) {
416
416
  var _c = React.useState({}),
417
417
  errors = _c[0],
418
418
  setErrors = _c[1];
419
+ // Ref to store the initial form values (firstValue).
420
+ var initialFormValues = React.useRef({});
419
421
  var setFormValue = function setFormValue(name, value) {
420
422
  setFormValues(function (prev) {
421
423
  var _a;
422
424
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
423
425
  });
426
+ if (!initialFormValues.current[name]) {
427
+ initialFormValues.current[name] = value; // Set the initial value once.
428
+ }
424
429
  };
425
430
  var handleSubmit = function handleSubmit() {
426
431
  return __awaiter(void 0, void 0, void 0, function () {
427
- var validationErrors;
432
+ var modifiedFields, validationErrors;
428
433
  return __generator(this, function (_a) {
429
434
  switch (_a.label) {
430
435
  case 0:
431
- return [4 /*yield*/, onSubmit(formValues)];
436
+ modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
437
+ var currentField = formValues[key]; // currentField is FormField
438
+ var initialField = currentField.firstValue; // Get initial value
439
+ // Compare current value with initial value
440
+ if (currentField.value !== initialField) {
441
+ acc[key] = currentField.value; // Include only modified fields
442
+ }
443
+ return acc;
444
+ }, {});
445
+ return [4 /*yield*/, onSubmit(modifiedFields)];
432
446
  case 1:
433
447
  validationErrors = _a.sent();
434
448
  // Set the validation errors in state
435
449
  setErrors(validationErrors);
436
- // Prevent submission if there are any errors
450
+ // Prevent submission if there are validation errors
437
451
  if (Object.keys(validationErrors).length > 0) {
438
- return [2 /*return*/]; // Prevent submission
452
+ return [2 /*return*/]; // Exit early if errors are present
439
453
  }
440
454
  return [2 /*return*/];
441
455
  }
442
456
  });
443
457
  });
444
458
  };
445
- var handleFormSubmit = function handleFormSubmit(formValues) {
459
+ var handleFormSubmit = function handleFormSubmit() {
446
460
  return __awaiter(void 0, void 0, void 0, function () {
447
- var validationErrors;
461
+ var modifiedFields, validationErrors;
448
462
  return __generator(this, function (_a) {
449
463
  switch (_a.label) {
450
464
  case 0:
451
- return [4 /*yield*/, onSubmit(formValues)];
465
+ modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
466
+ var currentField = formValues[key];
467
+ var initialField = currentField === null || currentField === void 0 ? void 0 : currentField.firstValue; // Get initial value
468
+ if (currentField.value !== initialField) {
469
+ acc[key] = currentField.value; // Include only modified fields
470
+ }
471
+ return acc;
472
+ }, {});
473
+ return [4 /*yield*/, onSubmit(modifiedFields)];
452
474
  case 1:
453
475
  validationErrors = _a.sent();
476
+ // Set the validation errors in state
454
477
  setErrors(validationErrors);
478
+ // Return validation errors to allow further actions if needed
455
479
  return [2 /*return*/, validationErrors];
456
480
  }
457
481
  });