aport-tools 4.4.31 → 4.4.33

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.
@@ -1 +1 @@
1
- export { Form, useFormContext } from './FormContext';
1
+ export { Form, useFormContext, setFormValueGlobal } from './FormContext';
@@ -45,6 +45,7 @@ interface FormContextProps {
45
45
  handleSubmit: () => void;
46
46
  handleFormSubmit: (formValues: Record<string, any>) => Promise<Record<string, string[]>>;
47
47
  }
48
+ export declare const setFormValueGlobal: (name: string, value: any, firstValue?: any) => void;
48
49
  export declare const useFormContext: () => FormContextProps;
49
50
  interface StepperProps {
50
51
  /**
@@ -1,5 +1,5 @@
1
1
  export { Input } from './Input';
2
- export { Form, useFormContext } from './FormContext';
2
+ export { Form, useFormContext, setFormValueGlobal } from './FormContext';
3
3
  export { default as TextArea } from './TextArea';
4
4
  export { default as Label } from './Label';
5
5
  export { default as ErrorList } from './ErrorList';
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.31 | ISC */
1
+ /*! aport-tools v4.4.33 | 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,6 +377,18 @@ 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
+ // Utility to use `setFormValue` globally
385
+ var setFormValueGlobal = function setFormValueGlobal(name, value, firstValue) {
386
+ if (globalSetFormValueRef.current) {
387
+ globalSetFormValueRef.current(name, value, firstValue);
388
+ } else {
389
+ console.warn("setFormValueGlobal was called before the Form was rendered.");
390
+ }
391
+ };
380
392
  var FormContext = /*#__PURE__*/createContext(undefined);
381
393
  var useFormContext = function useFormContext() {
382
394
  var context = useContext(FormContext);
@@ -398,6 +410,13 @@ var Form = function Form(_a) {
398
410
  var _d = useState({}),
399
411
  firstValues = _d[0],
400
412
  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
+ }, []);
401
420
  var setFormValue = function setFormValue(name, value, firstValue) {
402
421
  setFormValues(function (prev) {
403
422
  var _a;
@@ -552,16 +571,14 @@ var Input = function Input(_a) {
552
571
  var isFirstRender = useRef(true); // Track the first render
553
572
  // Initialize the internal value when `firstValue` changes or on first render
554
573
  useEffect(function () {
574
+ var _a;
555
575
  if (isFirstRender.current) {
556
576
  isFirstRender.current = false;
557
- if (firstValue !== undefined) {
558
- setInternalValue(firstValue);
559
- setFormValue(name, firstValue, firstValue); // Pass firstValue here
560
- } else {
561
- setInternalValue(formValues[name] || "");
562
- }
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
563
580
  }
564
- }, [firstValue]);
581
+ }, [firstValue, formValues, name, setFormValue]);
565
582
  /**
566
583
  * Handles text changes in the input field, applying formatting based on the inputType.
567
584
  *
@@ -1462,5 +1479,5 @@ var styles = StyleSheet.create({
1462
1479
  }
1463
1480
  });
1464
1481
 
1465
- export { Button, Card, ErrorList, Form, Input, InputAttach, InputCheck, InputList, Label, Text, TextArea, useFormContext };
1482
+ export { Button, Card, ErrorList, Form, Input, InputAttach, InputCheck, InputList, Label, Text, TextArea, setFormValueGlobal, useFormContext };
1466
1483
  //# sourceMappingURL=index.esm.js.map