@inertiajs/react 2.2.15 → 2.2.17
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 +50 -33
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +39 -22
- package/dist/index.js.map +4 -4
- package/package.json +6 -6
- package/types/index.d.ts +2 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { config as coreConfig, progress as Progress2, router as Router } from "@inertiajs/core";
|
|
3
3
|
|
|
4
|
-
// src/createInertiaApp.ts
|
|
5
|
-
import {
|
|
6
|
-
router as router2,
|
|
7
|
-
setupProgress
|
|
8
|
-
} from "@inertiajs/core";
|
|
9
|
-
import { createElement as createElement2 } from "react";
|
|
10
|
-
|
|
11
4
|
// src/App.ts
|
|
12
5
|
import {
|
|
13
6
|
createHeadManager,
|
|
@@ -110,6 +103,11 @@ function App({
|
|
|
110
103
|
App.displayName = "Inertia";
|
|
111
104
|
|
|
112
105
|
// src/createInertiaApp.ts
|
|
106
|
+
import {
|
|
107
|
+
router as router2,
|
|
108
|
+
setupProgress
|
|
109
|
+
} from "@inertiajs/core";
|
|
110
|
+
import { createElement as createElement2 } from "react";
|
|
113
111
|
async function createInertiaApp({
|
|
114
112
|
id = "app",
|
|
115
113
|
resolve,
|
|
@@ -174,9 +172,9 @@ async function createInertiaApp({
|
|
|
174
172
|
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
175
173
|
|
|
176
174
|
// src/usePage.ts
|
|
177
|
-
import
|
|
175
|
+
import React from "react";
|
|
178
176
|
function usePage() {
|
|
179
|
-
const page = useContext(PageContext_default);
|
|
177
|
+
const page = typeof React.use === "function" ? React.use(PageContext_default) : React.useContext(PageContext_default);
|
|
180
178
|
if (!page) {
|
|
181
179
|
throw new Error("usePage must be used within the Inertia component");
|
|
182
180
|
}
|
|
@@ -230,7 +228,7 @@ import {
|
|
|
230
228
|
resetFormFields
|
|
231
229
|
} from "@inertiajs/core";
|
|
232
230
|
import { isEqual as isEqual2 } from "lodash-es";
|
|
233
|
-
import
|
|
231
|
+
import React2, {
|
|
234
232
|
createElement as createElement3,
|
|
235
233
|
forwardRef,
|
|
236
234
|
useEffect as useEffect6,
|
|
@@ -527,7 +525,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
527
525
|
|
|
528
526
|
// src/Form.ts
|
|
529
527
|
var deferStateUpdate = (callback) => {
|
|
530
|
-
typeof
|
|
528
|
+
typeof React2.startTransition === "function" ? React2.startTransition(callback) : setTimeout(callback, 0);
|
|
531
529
|
};
|
|
532
530
|
var noop = () => void 0;
|
|
533
531
|
var Form = forwardRef(
|
|
@@ -603,6 +601,7 @@ var Form = forwardRef(
|
|
|
603
601
|
);
|
|
604
602
|
const submitOptions = {
|
|
605
603
|
headers,
|
|
604
|
+
queryStringArrayFormat,
|
|
606
605
|
errorBag,
|
|
607
606
|
showProgress,
|
|
608
607
|
invalidateCacheTags,
|
|
@@ -680,9 +679,9 @@ var Form_default = Form;
|
|
|
680
679
|
|
|
681
680
|
// src/Head.ts
|
|
682
681
|
import { escape } from "lodash-es";
|
|
683
|
-
import
|
|
682
|
+
import React3, { useContext, useEffect as useEffect7, useMemo as useMemo5 } from "react";
|
|
684
683
|
var Head = function({ children, title }) {
|
|
685
|
-
const headManager =
|
|
684
|
+
const headManager = useContext(HeadContext_default);
|
|
686
685
|
const provider = useMemo5(() => headManager.createProvider(), [headManager]);
|
|
687
686
|
const isServer = typeof window === "undefined";
|
|
688
687
|
useEffect7(() => {
|
|
@@ -748,7 +747,7 @@ var Head = function({ children, title }) {
|
|
|
748
747
|
return html;
|
|
749
748
|
}
|
|
750
749
|
function ensureNodeHasInertiaProp(node) {
|
|
751
|
-
return
|
|
750
|
+
return React3.cloneElement(node, {
|
|
752
751
|
[provider.preferredAttribute()]: node.props["head-key"] !== void 0 ? node.props["head-key"] : ""
|
|
753
752
|
});
|
|
754
753
|
}
|
|
@@ -756,7 +755,7 @@ var Head = function({ children, title }) {
|
|
|
756
755
|
return renderTag(ensureNodeHasInertiaProp(node));
|
|
757
756
|
}
|
|
758
757
|
function renderNodes(nodes) {
|
|
759
|
-
const elements =
|
|
758
|
+
const elements = React3.Children.toArray(nodes).filter((node) => node).map((node) => renderNode(node));
|
|
760
759
|
if (title && !elements.find((tag) => tag.startsWith("<title"))) {
|
|
761
760
|
elements.push(`<title ${provider.preferredAttribute()}>${title}</title>`);
|
|
762
761
|
}
|
|
@@ -774,7 +773,7 @@ import {
|
|
|
774
773
|
getScrollableParent,
|
|
775
774
|
useInfiniteScroll
|
|
776
775
|
} from "@inertiajs/core";
|
|
777
|
-
import
|
|
776
|
+
import React4, {
|
|
778
777
|
createElement as createElement4,
|
|
779
778
|
forwardRef as forwardRef2,
|
|
780
779
|
useCallback as useCallback2,
|
|
@@ -1005,7 +1004,7 @@ var InfiniteScroll = forwardRef2(
|
|
|
1005
1004
|
)
|
|
1006
1005
|
);
|
|
1007
1006
|
}
|
|
1008
|
-
return createElement4(
|
|
1007
|
+
return createElement4(React4.Fragment, {}, ...reverse ? [...renderElements].reverse() : renderElements);
|
|
1009
1008
|
}
|
|
1010
1009
|
);
|
|
1011
1010
|
InfiniteScroll.displayName = "InertiaInfiniteScroll";
|
|
@@ -1199,8 +1198,10 @@ var Link = forwardRef3(
|
|
|
1199
1198
|
}
|
|
1200
1199
|
},
|
|
1201
1200
|
onMouseUp: (event) => {
|
|
1202
|
-
event
|
|
1203
|
-
|
|
1201
|
+
if (shouldIntercept(event)) {
|
|
1202
|
+
event.preventDefault();
|
|
1203
|
+
router6.visit(url, visitParams);
|
|
1204
|
+
}
|
|
1204
1205
|
},
|
|
1205
1206
|
onKeyUp: (event) => {
|
|
1206
1207
|
if (shouldNavigate(event)) {
|
|
@@ -1316,9 +1317,21 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1316
1317
|
as = as ?? "div";
|
|
1317
1318
|
fallback = fallback ?? null;
|
|
1318
1319
|
const [loaded, setLoaded] = useState9(false);
|
|
1319
|
-
const hasFetched = useRef6(false);
|
|
1320
1320
|
const fetching = useRef6(false);
|
|
1321
1321
|
const ref = useRef6(null);
|
|
1322
|
+
const observer = useRef6(null);
|
|
1323
|
+
const page = usePage();
|
|
1324
|
+
useEffect12(() => {
|
|
1325
|
+
if (Array.isArray(data)) {
|
|
1326
|
+
if (data.some((key) => page.props[key] === void 0)) {
|
|
1327
|
+
setLoaded(false);
|
|
1328
|
+
}
|
|
1329
|
+
} else if (data) {
|
|
1330
|
+
if (page.props[data] === void 0) {
|
|
1331
|
+
setLoaded(false);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}, [data, ...Array.isArray(data) ? data.map((key) => page.props[key]) : [page.props[data]]]);
|
|
1322
1335
|
const getReloadParams = useCallback3(() => {
|
|
1323
1336
|
if (data) {
|
|
1324
1337
|
return {
|
|
@@ -1330,22 +1343,19 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1330
1343
|
}
|
|
1331
1344
|
return params;
|
|
1332
1345
|
}, [params, data]);
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
}
|
|
1337
|
-
const observer = new IntersectionObserver(
|
|
1346
|
+
const registerObserver = () => {
|
|
1347
|
+
observer.current?.disconnect();
|
|
1348
|
+
observer.current = new IntersectionObserver(
|
|
1338
1349
|
(entries) => {
|
|
1339
1350
|
if (!entries[0].isIntersecting) {
|
|
1340
1351
|
return;
|
|
1341
1352
|
}
|
|
1342
|
-
if (!always && hasFetched.current) {
|
|
1343
|
-
observer.disconnect();
|
|
1344
|
-
}
|
|
1345
1353
|
if (fetching.current) {
|
|
1346
1354
|
return;
|
|
1347
1355
|
}
|
|
1348
|
-
|
|
1356
|
+
if (!always && loaded) {
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1349
1359
|
fetching.current = true;
|
|
1350
1360
|
const reloadParams = getReloadParams();
|
|
1351
1361
|
router9.reload({
|
|
@@ -1359,7 +1369,7 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1359
1369
|
fetching.current = false;
|
|
1360
1370
|
reloadParams.onFinish?.(e);
|
|
1361
1371
|
if (!always) {
|
|
1362
|
-
observer.disconnect();
|
|
1372
|
+
observer.current?.disconnect();
|
|
1363
1373
|
}
|
|
1364
1374
|
}
|
|
1365
1375
|
});
|
|
@@ -1368,11 +1378,17 @@ var WhenVisible = ({ children, data, params, buffer, as, always, fallback }) =>
|
|
|
1368
1378
|
rootMargin: `${buffer || 0}px`
|
|
1369
1379
|
}
|
|
1370
1380
|
);
|
|
1371
|
-
observer.observe(ref.current);
|
|
1381
|
+
observer.current.observe(ref.current);
|
|
1382
|
+
};
|
|
1383
|
+
useEffect12(() => {
|
|
1384
|
+
if (!ref.current) {
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
registerObserver();
|
|
1372
1388
|
return () => {
|
|
1373
|
-
observer.disconnect();
|
|
1389
|
+
observer.current?.disconnect();
|
|
1374
1390
|
};
|
|
1375
|
-
}, [ref, getReloadParams, buffer]);
|
|
1391
|
+
}, [loaded, ref, getReloadParams, buffer]);
|
|
1376
1392
|
const resolveChildren = () => typeof children === "function" ? children() : children;
|
|
1377
1393
|
const resolveFallback = () => typeof fallback === "function" ? fallback() : fallback;
|
|
1378
1394
|
if (always || !loaded) {
|
|
@@ -1395,6 +1411,7 @@ var progress = Progress2;
|
|
|
1395
1411
|
var router3 = Router;
|
|
1396
1412
|
var config = coreConfig.extend();
|
|
1397
1413
|
export {
|
|
1414
|
+
App,
|
|
1398
1415
|
Deferred_default as Deferred,
|
|
1399
1416
|
Form_default as Form,
|
|
1400
1417
|
Head_default as Head,
|