@inertiajs/react 2.3.1 → 2.3.3
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 +22 -10
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +22 -10
- package/dist/index.js.map +2 -2
- package/package.json +2 -2
- package/types/Form.d.ts +1 -1
- package/types/WhenVisible.d.ts +4 -1
- package/types/index.d.ts +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -37,7 +37,7 @@ function App({
|
|
|
37
37
|
}) {
|
|
38
38
|
const [current, setCurrent] = useState({
|
|
39
39
|
component: initialComponent || null,
|
|
40
|
-
page: initialPage,
|
|
40
|
+
page: { ...initialPage, flash: initialPage.flash ?? {} },
|
|
41
41
|
key: null
|
|
42
42
|
});
|
|
43
43
|
const headManager = useMemo(() => {
|
|
@@ -52,7 +52,13 @@ function App({
|
|
|
52
52
|
router.init({
|
|
53
53
|
initialPage,
|
|
54
54
|
resolveComponent,
|
|
55
|
-
swapComponent: async (args) => swapComponent(args)
|
|
55
|
+
swapComponent: async (args) => swapComponent(args),
|
|
56
|
+
onFlash: (flash) => {
|
|
57
|
+
setCurrent((current2) => ({
|
|
58
|
+
...current2,
|
|
59
|
+
page: { ...current2.page, flash }
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
56
62
|
});
|
|
57
63
|
routerIsInitialized = true;
|
|
58
64
|
}
|
|
@@ -702,13 +708,13 @@ var Form = forwardRef(
|
|
|
702
708
|
}, [action, method]);
|
|
703
709
|
const [isDirty, setIsDirty] = useState5(false);
|
|
704
710
|
const defaultData = useRef2(new FormData());
|
|
705
|
-
const getFormData = () => new FormData(formElement.current);
|
|
706
|
-
const getData = () => formDataToObject(getFormData());
|
|
707
|
-
const getUrlAndData = () => {
|
|
711
|
+
const getFormData = (submitter) => new FormData(formElement.current, submitter);
|
|
712
|
+
const getData = (submitter) => formDataToObject(getFormData(submitter));
|
|
713
|
+
const getUrlAndData = (submitter) => {
|
|
708
714
|
return mergeDataIntoQueryString(
|
|
709
715
|
resolvedMethod,
|
|
710
716
|
isUrlMethodPair(action) ? action.url : action,
|
|
711
|
-
getData(),
|
|
717
|
+
getData(submitter),
|
|
712
718
|
queryStringArrayFormat
|
|
713
719
|
);
|
|
714
720
|
};
|
|
@@ -758,8 +764,8 @@ var Form = forwardRef(
|
|
|
758
764
|
reset(...resetOption);
|
|
759
765
|
}
|
|
760
766
|
};
|
|
761
|
-
const submit = () => {
|
|
762
|
-
const [url,
|
|
767
|
+
const submit = (submitter) => {
|
|
768
|
+
const [url, data] = getUrlAndData(submitter);
|
|
763
769
|
const submitOptions = {
|
|
764
770
|
headers,
|
|
765
771
|
queryStringArrayFormat,
|
|
@@ -789,7 +795,9 @@ var Form = forwardRef(
|
|
|
789
795
|
},
|
|
790
796
|
...options
|
|
791
797
|
};
|
|
798
|
+
form.transform(() => transform(data));
|
|
792
799
|
form.submit(resolvedMethod, url, submitOptions);
|
|
800
|
+
form.transform(getTransformedData);
|
|
793
801
|
};
|
|
794
802
|
const defaults = () => {
|
|
795
803
|
defaultData.current = getFormData();
|
|
@@ -830,7 +838,7 @@ var Form = forwardRef(
|
|
|
830
838
|
method: resolvedMethod,
|
|
831
839
|
onSubmit: (event) => {
|
|
832
840
|
event.preventDefault();
|
|
833
|
-
submit();
|
|
841
|
+
submit(event.nativeEvent.submitter);
|
|
834
842
|
},
|
|
835
843
|
// Only React 19 supports passing a boolean to the `inert` attribute.
|
|
836
844
|
// To support earlier versions as well, we use the string 'true'.
|
|
@@ -1487,6 +1495,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1487
1495
|
const pageProps = usePage().props;
|
|
1488
1496
|
const keys = useMemo8(() => data ? Array.isArray(data) ? data : [data] : [], [data]);
|
|
1489
1497
|
const [loaded, setLoaded] = useState9(() => keys.length > 0 && keys.every((key) => pageProps[key] !== void 0));
|
|
1498
|
+
const [isFetching, setIsFetching] = useState9(false);
|
|
1490
1499
|
const fetching = useRef6(false);
|
|
1491
1500
|
const ref = useRef6(null);
|
|
1492
1501
|
const observer = useRef6(null);
|
|
@@ -1520,16 +1529,19 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1520
1529
|
return;
|
|
1521
1530
|
}
|
|
1522
1531
|
fetching.current = true;
|
|
1532
|
+
setIsFetching(true);
|
|
1523
1533
|
const reloadParams = getReloadParams();
|
|
1524
1534
|
router9.reload({
|
|
1525
1535
|
...reloadParams,
|
|
1526
1536
|
onStart: (e) => {
|
|
1527
1537
|
fetching.current = true;
|
|
1538
|
+
setIsFetching(true);
|
|
1528
1539
|
reloadParams.onStart?.(e);
|
|
1529
1540
|
},
|
|
1530
1541
|
onFinish: (e) => {
|
|
1531
1542
|
setLoaded(true);
|
|
1532
1543
|
fetching.current = false;
|
|
1544
|
+
setIsFetching(false);
|
|
1533
1545
|
reloadParams.onFinish?.(e);
|
|
1534
1546
|
if (!always) {
|
|
1535
1547
|
observer.current?.disconnect();
|
|
@@ -1555,7 +1567,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1555
1567
|
observer.current?.disconnect();
|
|
1556
1568
|
};
|
|
1557
1569
|
}, [always, loaded, ref, getReloadParams, buffer]);
|
|
1558
|
-
const resolveChildren = () => typeof children === "function" ? children() : children;
|
|
1570
|
+
const resolveChildren = () => typeof children === "function" ? children({ fetching: isFetching }) : children;
|
|
1559
1571
|
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1560
1572
|
if (always || !loaded) {
|
|
1561
1573
|
return createElement6(
|