aport-tools 4.4.40 → 4.4.41

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.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.40 | ISC */
1
+ /*! aport-tools v4.4.41 | ISC */
2
2
  import React, { useContext, useState, createContext, useRef, useEffect, useMemo, useCallback } from 'react';
3
3
  import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
4
4
  import { ThemeContext } from 'aport-themes';
@@ -377,15 +377,9 @@ var styles$9 = StyleSheet.create({
377
377
  });
378
378
 
379
379
  // src/forms/FormContext.tsx
380
- // Create a ref to hold the global `setFormValue` function
381
- var globalSetFormValueRef = {
382
- current: null
383
- };
384
380
  // Utility to use `setFormValue` globally
385
381
  var setFormValueGlobal = function setFormValueGlobal(name, value, firstValue) {
386
- if (globalSetFormValueRef.current) {
387
- globalSetFormValueRef.current(name, value, firstValue);
388
- } else {
382
+ {
389
383
  console.warn("setFormValueGlobal was called before the Form was rendered.");
390
384
  }
391
385
  };
@@ -410,19 +404,14 @@ var Form = function Form(_a) {
410
404
  var _d = useState({}),
411
405
  firstValues = _d[0],
412
406
  setFirstValues = _d[1]; // Track firstValues
413
- // Assign the local `setFormValue` to the global ref on first render
414
- React.useEffect(function () {
415
- globalSetFormValueRef.current = setFormValue;
416
- return function () {
417
- globalSetFormValueRef.current = null; // Cleanup on unmount
418
- };
419
- }, []);
420
407
  var setFormValue = function setFormValue(name, value, firstValue) {
408
+ // Update formValues with the latest value
421
409
  setFormValues(function (prev) {
422
410
  var _a;
423
411
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
424
412
  });
425
- if (firstValue !== undefined) {
413
+ // If firstValue exists and is not empty, set it in firstValues
414
+ if (firstValue !== undefined && firstValue !== null && firstValue !== "") {
426
415
  setFirstValues(function (prev) {
427
416
  var _a;
428
417
  return __assign(__assign({}, prev), (_a = {}, _a[name] = firstValue, _a));
@@ -439,8 +428,14 @@ var Form = function Form(_a) {
439
428
  var hasFirstValue = key in firstValues;
440
429
  var isModified = hasFirstValue && formValues[key] !== firstValues[key];
441
430
  var isNewValue = !hasFirstValue;
431
+ // If the field was modified or is a new value, include it in the modified values
442
432
  if (isModified || isNewValue) {
443
433
  result[key] = formValues[key];
434
+ } else {
435
+ // If there were no changes, use the firstValue
436
+ if (hasFirstValue && firstValues[key] !== undefined) {
437
+ result[key] = firstValues[key];
438
+ }
444
439
  }
445
440
  return result;
446
441
  }, {});
@@ -571,14 +566,16 @@ var Input = function Input(_a) {
571
566
  var isFirstRender = useRef(true); // Track the first render
572
567
  // Initialize the internal value when `firstValue` changes or on first render
573
568
  useEffect(function () {
574
- var _a;
575
569
  if (isFirstRender.current) {
576
570
  isFirstRender.current = false;
577
- var initialValue = (_a = firstValue !== null && firstValue !== void 0 ? firstValue : formValues[name]) !== null && _a !== void 0 ? _a : ""; // Priority: firstValue > formValues[name] > ""
578
- setInternalValue(initialValue);
579
- setFormValue(name, initialValue, firstValue); // Initialize the form value globally
571
+ if (firstValue !== undefined) {
572
+ setInternalValue(firstValue);
573
+ setFormValue(name, firstValue, firstValue); // Pass firstValue here
574
+ } else {
575
+ setInternalValue(formValues[name] || "");
576
+ }
580
577
  }
581
- }, [firstValue, formValues, name, setFormValue]);
578
+ }, [firstValue]);
582
579
  /**
583
580
  * Handles text changes in the input field, applying formatting based on the inputType.
584
581
  *