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.
- package/dist/forms/Form.d.ts +1 -1
- package/dist/forms/FormContext.d.ts +1 -0
- package/dist/forms/index.d.ts +1 -1
- package/dist/index.esm.js +26 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
1
|
+
/*! aport-tools v4.4.33 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
@@ -398,6 +398,18 @@ 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
|
+
// Utility to use `setFormValue` globally
|
406
|
+
var setFormValueGlobal = function setFormValueGlobal(name, value, firstValue) {
|
407
|
+
if (globalSetFormValueRef.current) {
|
408
|
+
globalSetFormValueRef.current(name, value, firstValue);
|
409
|
+
} else {
|
410
|
+
console.warn("setFormValueGlobal was called before the Form was rendered.");
|
411
|
+
}
|
412
|
+
};
|
401
413
|
var FormContext = /*#__PURE__*/React.createContext(undefined);
|
402
414
|
var useFormContext = function useFormContext() {
|
403
415
|
var context = React.useContext(FormContext);
|
@@ -419,6 +431,13 @@ var Form = function Form(_a) {
|
|
419
431
|
var _d = React.useState({}),
|
420
432
|
firstValues = _d[0],
|
421
433
|
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
|
+
}, []);
|
422
441
|
var setFormValue = function setFormValue(name, value, firstValue) {
|
423
442
|
setFormValues(function (prev) {
|
424
443
|
var _a;
|
@@ -573,16 +592,14 @@ var Input = function Input(_a) {
|
|
573
592
|
var isFirstRender = React.useRef(true); // Track the first render
|
574
593
|
// Initialize the internal value when `firstValue` changes or on first render
|
575
594
|
React.useEffect(function () {
|
595
|
+
var _a;
|
576
596
|
if (isFirstRender.current) {
|
577
597
|
isFirstRender.current = false;
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
} else {
|
582
|
-
setInternalValue(formValues[name] || "");
|
583
|
-
}
|
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
|
584
601
|
}
|
585
|
-
}, [firstValue]);
|
602
|
+
}, [firstValue, formValues, name, setFormValue]);
|
586
603
|
/**
|
587
604
|
* Handles text changes in the input field, applying formatting based on the inputType.
|
588
605
|
*
|
@@ -1494,5 +1511,6 @@ exports.InputList = InputList;
|
|
1494
1511
|
exports.Label = Label;
|
1495
1512
|
exports.Text = Text;
|
1496
1513
|
exports.TextArea = TextArea;
|
1514
|
+
exports.setFormValueGlobal = setFormValueGlobal;
|
1497
1515
|
exports.useFormContext = useFormContext;
|
1498
1516
|
//# sourceMappingURL=index.js.map
|