aport-tools 4.4.29 → 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.29 | ISC */
1
+ /*! aport-tools v4.4.31 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -416,66 +416,60 @@ 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({});
421
- 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) {
422
423
  setFormValues(function (prev) {
423
424
  var _a;
424
425
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
425
426
  });
426
- if (!initialFormValues.current[name]) {
427
- initialFormValues.current[name] = value; // Set the initial value once.
427
+ if (firstValue !== undefined) {
428
+ setFirstValues(function (prev) {
429
+ var _a;
430
+ return __assign(__assign({}, prev), (_a = {}, _a[name] = firstValue, _a));
431
+ });
428
432
  }
429
433
  };
430
434
  var handleSubmit = function handleSubmit() {
431
435
  return __awaiter(void 0, void 0, void 0, function () {
432
- var modifiedFields, validationErrors;
436
+ var modifiedValues, validationErrors;
433
437
  return __generator(this, function (_a) {
434
438
  switch (_a.label) {
435
439
  case 0:
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
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
  }
456
460
  });
457
461
  });
458
462
  };
459
- var handleFormSubmit = function handleFormSubmit() {
463
+ var handleFormSubmit = function handleFormSubmit(formValues) {
460
464
  return __awaiter(void 0, void 0, void 0, function () {
461
- var modifiedFields, validationErrors;
465
+ var validationErrors;
462
466
  return __generator(this, function (_a) {
463
467
  switch (_a.label) {
464
468
  case 0:
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)];
469
+ return [4 /*yield*/, onSubmit(formValues)];
474
470
  case 1:
475
471
  validationErrors = _a.sent();
476
- // Set the validation errors in state
477
472
  setErrors(validationErrors);
478
- // Return validation errors to allow further actions if needed
479
473
  return [2 /*return*/, validationErrors];
480
474
  }
481
475
  });
@@ -583,12 +577,12 @@ var Input = function Input(_a) {
583
577
  isFirstRender.current = false;
584
578
  if (firstValue !== undefined) {
585
579
  setInternalValue(firstValue);
586
- setFormValue(name, firstValue);
580
+ setFormValue(name, firstValue, firstValue); // Pass firstValue here
587
581
  } else {
588
582
  setInternalValue(formValues[name] || "");
589
583
  }
590
584
  }
591
- }, [firstValue]); // Only re-run if `firstValue` changes
585
+ }, [firstValue]);
592
586
  /**
593
587
  * Handles text changes in the input field, applying formatting based on the inputType.
594
588
  *