aport-tools 4.4.40 → 4.4.44

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.40 | ISC */
1
+ /*! aport-tools v4.4.44 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -398,15 +398,9 @@ var styles$9 = reactNative.StyleSheet.create({
398
398
  });
399
399
 
400
400
  // src/forms/FormContext.tsx
401
- // Create a ref to hold the global `setFormValue` function
402
- var globalSetFormValueRef = {
403
- current: null
404
- };
405
401
  // Utility to use `setFormValue` globally
406
402
  var setFormValueGlobal = function setFormValueGlobal(name, value, firstValue) {
407
- if (globalSetFormValueRef.current) {
408
- globalSetFormValueRef.current(name, value, firstValue);
409
- } else {
403
+ {
410
404
  console.warn("setFormValueGlobal was called before the Form was rendered.");
411
405
  }
412
406
  };
@@ -431,19 +425,14 @@ var Form = function Form(_a) {
431
425
  var _d = React.useState({}),
432
426
  firstValues = _d[0],
433
427
  setFirstValues = _d[1]; // Track firstValues
434
- // Assign the local `setFormValue` to the global ref on first render
435
- React.useEffect(function () {
436
- globalSetFormValueRef.current = setFormValue;
437
- return function () {
438
- globalSetFormValueRef.current = null; // Cleanup on unmount
439
- };
440
- }, []);
441
428
  var setFormValue = function setFormValue(name, value, firstValue) {
429
+ // Update formValues with the latest value
442
430
  setFormValues(function (prev) {
443
431
  var _a;
444
432
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
445
433
  });
446
- if (firstValue !== undefined) {
434
+ // If firstValue exists and is not empty, set it in firstValues
435
+ if (firstValue !== undefined && firstValue !== null && firstValue !== "") {
447
436
  setFirstValues(function (prev) {
448
437
  var _a;
449
438
  return __assign(__assign({}, prev), (_a = {}, _a[name] = firstValue, _a));
@@ -460,8 +449,14 @@ var Form = function Form(_a) {
460
449
  var hasFirstValue = key in firstValues;
461
450
  var isModified = hasFirstValue && formValues[key] !== firstValues[key];
462
451
  var isNewValue = !hasFirstValue;
452
+ // If the field was modified or is a new value, include it in the modified values
463
453
  if (isModified || isNewValue) {
464
454
  result[key] = formValues[key];
455
+ } else {
456
+ // If there were no changes, use the firstValue
457
+ if (hasFirstValue && firstValues[key] !== undefined) {
458
+ result[key] = firstValues[key];
459
+ }
465
460
  }
466
461
  return result;
467
462
  }, {});
@@ -592,14 +587,16 @@ var Input = function Input(_a) {
592
587
  var isFirstRender = React.useRef(true); // Track the first render
593
588
  // Initialize the internal value when `firstValue` changes or on first render
594
589
  React.useEffect(function () {
595
- var _a;
596
590
  if (isFirstRender.current) {
597
591
  isFirstRender.current = false;
598
- var initialValue = (_a = firstValue !== null && firstValue !== void 0 ? firstValue : formValues[name]) !== null && _a !== void 0 ? _a : ""; // Priority: firstValue > formValues[name] > ""
599
- setInternalValue(initialValue);
600
- setFormValue(name, initialValue, firstValue); // Initialize the form value globally
592
+ if (firstValue !== undefined) {
593
+ setInternalValue(firstValue);
594
+ setFormValue(name, firstValue, firstValue); // Pass firstValue here
595
+ } else {
596
+ setInternalValue(formValues[name] || "");
597
+ }
601
598
  }
602
- }, [firstValue, formValues, name, setFormValue]);
599
+ }, [firstValue]);
603
600
  /**
604
601
  * Handles text changes in the input field, applying formatting based on the inputType.
605
602
  *