@inertiajs/react 2.2.8 → 2.2.9
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 +65 -43
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +58 -41
- package/dist/index.js.map +3 -3
- package/dist/server.js +1 -0
- package/dist/server.js.map +1 -1
- package/package.json +8 -8
- package/types/App.d.ts +17 -8
- package/types/Head.d.ts +2 -2
- package/types/HeadContext.d.ts +2 -1
- package/types/Link.d.ts +1 -1
- package/types/PageContext.d.ts +2 -1
- package/types/createInertiaApp.d.ts +13 -49
- package/types/types.d.ts +10 -0
- package/types/useForm.d.ts +4 -2
- package/types/usePage.d.ts +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -2,22 +2,28 @@
|
|
|
2
2
|
import { progress as Progress2, router as Router } from "@inertiajs/core";
|
|
3
3
|
|
|
4
4
|
// src/createInertiaApp.ts
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
router as router2,
|
|
7
|
+
setupProgress
|
|
8
|
+
} from "@inertiajs/core";
|
|
6
9
|
import { createElement as createElement2 } from "react";
|
|
7
10
|
|
|
8
11
|
// src/App.ts
|
|
9
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
createHeadManager,
|
|
14
|
+
router
|
|
15
|
+
} from "@inertiajs/core";
|
|
10
16
|
import { createElement, useEffect, useMemo, useState } from "react";
|
|
11
17
|
|
|
12
18
|
// src/HeadContext.ts
|
|
13
19
|
import { createContext } from "react";
|
|
14
|
-
var headContext = createContext(
|
|
20
|
+
var headContext = createContext(null);
|
|
15
21
|
headContext.displayName = "InertiaHeadContext";
|
|
16
22
|
var HeadContext_default = headContext;
|
|
17
23
|
|
|
18
24
|
// src/PageContext.ts
|
|
19
25
|
import { createContext as createContext2 } from "react";
|
|
20
|
-
var pageContext = createContext2(
|
|
26
|
+
var pageContext = createContext2(null);
|
|
21
27
|
pageContext.displayName = "InertiaPageContext";
|
|
22
28
|
var PageContext_default = pageContext;
|
|
23
29
|
|
|
@@ -77,13 +83,13 @@ function App({
|
|
|
77
83
|
createElement(PageContext_default.Provider, { value: current.page }, null)
|
|
78
84
|
);
|
|
79
85
|
}
|
|
80
|
-
const renderChildren = children || (({
|
|
81
|
-
const child = createElement(
|
|
82
|
-
if (typeof
|
|
83
|
-
return
|
|
86
|
+
const renderChildren = children || (({ component, props, key }) => {
|
|
87
|
+
const child = createElement(component, { key, ...props });
|
|
88
|
+
if (typeof component.layout === "function") {
|
|
89
|
+
return component.layout(child);
|
|
84
90
|
}
|
|
85
|
-
if (Array.isArray(
|
|
86
|
-
return
|
|
91
|
+
if (Array.isArray(component.layout)) {
|
|
92
|
+
return component.layout.concat(child).reverse().reduce((children2, Layout) => createElement(Layout, { children: children2, ...props }));
|
|
87
93
|
}
|
|
88
94
|
return child;
|
|
89
95
|
});
|
|
@@ -94,7 +100,7 @@ function App({
|
|
|
94
100
|
PageContext_default.Provider,
|
|
95
101
|
{ value: current.page },
|
|
96
102
|
renderChildren({
|
|
97
|
-
|
|
103
|
+
component: current.component,
|
|
98
104
|
key: current.key,
|
|
99
105
|
props: current.page.props
|
|
100
106
|
})
|
|
@@ -115,7 +121,7 @@ async function createInertiaApp({
|
|
|
115
121
|
}) {
|
|
116
122
|
const isServer = typeof window === "undefined";
|
|
117
123
|
const el = isServer ? null : document.getElementById(id);
|
|
118
|
-
const initialPage = page || JSON.parse(el
|
|
124
|
+
const initialPage = page || JSON.parse(el?.dataset.page || "{}");
|
|
119
125
|
const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module);
|
|
120
126
|
let head = [];
|
|
121
127
|
const reactApp = await Promise.all([
|
|
@@ -123,23 +129,31 @@ async function createInertiaApp({
|
|
|
123
129
|
router2.decryptHistory().catch(() => {
|
|
124
130
|
})
|
|
125
131
|
]).then(([initialComponent]) => {
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
const props = {
|
|
133
|
+
initialPage,
|
|
134
|
+
initialComponent,
|
|
135
|
+
resolveComponent,
|
|
136
|
+
titleCallback: title
|
|
137
|
+
};
|
|
138
|
+
if (isServer) {
|
|
139
|
+
const ssrSetup = setup;
|
|
140
|
+
return ssrSetup({
|
|
141
|
+
el: null,
|
|
142
|
+
App,
|
|
143
|
+
props: { ...props, onHeadUpdate: (elements) => head = elements }
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const csrSetup = setup;
|
|
147
|
+
return csrSetup({
|
|
128
148
|
el,
|
|
129
149
|
App,
|
|
130
|
-
props
|
|
131
|
-
initialPage,
|
|
132
|
-
initialComponent,
|
|
133
|
-
resolveComponent,
|
|
134
|
-
titleCallback: title,
|
|
135
|
-
onHeadUpdate: isServer ? (elements) => head = elements : null
|
|
136
|
-
}
|
|
150
|
+
props
|
|
137
151
|
});
|
|
138
152
|
});
|
|
139
153
|
if (!isServer && progress2) {
|
|
140
154
|
setupProgress(progress2);
|
|
141
155
|
}
|
|
142
|
-
if (isServer) {
|
|
156
|
+
if (isServer && render) {
|
|
143
157
|
const body = await render(
|
|
144
158
|
createElement2(
|
|
145
159
|
"div",
|
|
@@ -147,7 +161,6 @@ async function createInertiaApp({
|
|
|
147
161
|
id,
|
|
148
162
|
"data-page": JSON.stringify(initialPage)
|
|
149
163
|
},
|
|
150
|
-
// @ts-expect-error
|
|
151
164
|
reactApp
|
|
152
165
|
)
|
|
153
166
|
);
|
|
@@ -254,13 +267,13 @@ function useRemember(initialState, key) {
|
|
|
254
267
|
|
|
255
268
|
// src/useForm.ts
|
|
256
269
|
function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
257
|
-
const isMounted = useRef(
|
|
270
|
+
const isMounted = useRef(false);
|
|
258
271
|
const rememberKey = typeof rememberKeyOrInitialValues === "string" ? rememberKeyOrInitialValues : null;
|
|
259
272
|
const [defaults, setDefaults] = useState4(
|
|
260
273
|
(typeof rememberKeyOrInitialValues === "string" ? maybeInitialValues : rememberKeyOrInitialValues) || {}
|
|
261
274
|
);
|
|
262
275
|
const cancelToken = useRef(null);
|
|
263
|
-
const recentlySuccessfulTimeoutId = useRef(
|
|
276
|
+
const recentlySuccessfulTimeoutId = useRef(void 0);
|
|
264
277
|
const [data, setData] = rememberKey ? useRemember(defaults, `${rememberKey}:data`) : useState4(defaults);
|
|
265
278
|
const [errors, setErrors] = rememberKey ? useRemember({}, `${rememberKey}:errors`) : useState4({});
|
|
266
279
|
const [hasErrors, setHasErrors] = useState4(false);
|
|
@@ -307,7 +320,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
307
320
|
}
|
|
308
321
|
},
|
|
309
322
|
onProgress: (event) => {
|
|
310
|
-
setProgress(event);
|
|
323
|
+
setProgress(event || null);
|
|
311
324
|
if (options.onProgress) {
|
|
312
325
|
return options.onProgress(event);
|
|
313
326
|
}
|
|
@@ -366,10 +379,11 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
366
379
|
}
|
|
367
380
|
}
|
|
368
381
|
};
|
|
382
|
+
const transformedData = transform.current(data);
|
|
369
383
|
if (method === "delete") {
|
|
370
|
-
router5.delete(url, { ..._options, data:
|
|
384
|
+
router5.delete(url, { ..._options, data: transformedData });
|
|
371
385
|
} else {
|
|
372
|
-
router5[method](url,
|
|
386
|
+
router5[method](url, transformedData, _options);
|
|
373
387
|
}
|
|
374
388
|
},
|
|
375
389
|
[data, setErrors, transform]
|
|
@@ -467,7 +481,7 @@ function useForm(rememberKeyOrInitialValues, maybeInitialValues) {
|
|
|
467
481
|
},
|
|
468
482
|
[reset, clearErrors]
|
|
469
483
|
);
|
|
470
|
-
const createSubmitMethod = (method) => (url, options) => {
|
|
484
|
+
const createSubmitMethod = (method) => (url, options = {}) => {
|
|
471
485
|
submit(method, url, options);
|
|
472
486
|
};
|
|
473
487
|
const getMethod = useCallback(createSubmitMethod("get"), [submit]);
|
|
@@ -542,7 +556,7 @@ var Form = forwardRef(
|
|
|
542
556
|
...props
|
|
543
557
|
}, ref) => {
|
|
544
558
|
const form = useForm({});
|
|
545
|
-
const formElement = useRef2(
|
|
559
|
+
const formElement = useRef2(void 0);
|
|
546
560
|
const resolvedMethod = useMemo4(() => {
|
|
547
561
|
return isUrlMethodPair(action) ? action.method : method.toLowerCase();
|
|
548
562
|
}, [action, method]);
|
|
@@ -560,7 +574,9 @@ var Form = forwardRef(
|
|
|
560
574
|
return () => formEvents.forEach((e) => formElement.current?.removeEventListener(e, updateDirtyState));
|
|
561
575
|
}, []);
|
|
562
576
|
const reset = (...fields) => {
|
|
563
|
-
|
|
577
|
+
if (formElement.current) {
|
|
578
|
+
resetFormFields(formElement.current, defaultData.current, fields);
|
|
579
|
+
}
|
|
564
580
|
};
|
|
565
581
|
const resetAndClearErrors = (...fields) => {
|
|
566
582
|
form.clearErrors(...fields);
|
|
@@ -673,7 +689,7 @@ var Head = function({ children, title }) {
|
|
|
673
689
|
};
|
|
674
690
|
}, [provider, children, title]);
|
|
675
691
|
function isUnaryTag(node) {
|
|
676
|
-
return [
|
|
692
|
+
return typeof node.type === "string" && [
|
|
677
693
|
"area",
|
|
678
694
|
"base",
|
|
679
695
|
"br",
|
|
@@ -699,14 +715,20 @@ var Head = function({ children, title }) {
|
|
|
699
715
|
const value = String(node.props[name]);
|
|
700
716
|
if (value === "") {
|
|
701
717
|
return carry + ` ${name}`;
|
|
702
|
-
} else {
|
|
703
|
-
return carry + ` ${name}="${escape(value)}"`;
|
|
704
718
|
}
|
|
719
|
+
return carry + ` ${name}="${escape(value)}"`;
|
|
705
720
|
}, "");
|
|
706
|
-
return `<${node.type}${attrs}>`;
|
|
721
|
+
return `<${String(node.type)}${attrs}>`;
|
|
707
722
|
}
|
|
708
723
|
function renderTagChildren(node) {
|
|
709
|
-
|
|
724
|
+
const { children: children2 } = node.props;
|
|
725
|
+
if (typeof children2 === "string") {
|
|
726
|
+
return children2;
|
|
727
|
+
}
|
|
728
|
+
if (Array.isArray(children2)) {
|
|
729
|
+
return children2.reduce((html, child) => html + renderTag(child), "");
|
|
730
|
+
}
|
|
731
|
+
return "";
|
|
710
732
|
}
|
|
711
733
|
function renderTag(node) {
|
|
712
734
|
let html = renderTagStart(node);
|
|
@@ -717,7 +739,7 @@ var Head = function({ children, title }) {
|
|
|
717
739
|
html += node.props.dangerouslySetInnerHTML.__html;
|
|
718
740
|
}
|
|
719
741
|
if (!isUnaryTag(node)) {
|
|
720
|
-
html += `</${node.type}>`;
|
|
742
|
+
html += `</${String(node.type)}>`;
|
|
721
743
|
}
|
|
722
744
|
return html;
|
|
723
745
|
}
|
|
@@ -730,11 +752,11 @@ var Head = function({ children, title }) {
|
|
|
730
752
|
return renderTag(ensureNodeHasInertiaProp(node));
|
|
731
753
|
}
|
|
732
754
|
function renderNodes(nodes) {
|
|
733
|
-
const
|
|
734
|
-
if (title && !
|
|
735
|
-
|
|
755
|
+
const elements = React2.Children.toArray(nodes).filter((node) => node).map((node) => renderNode(node));
|
|
756
|
+
if (title && !elements.find((tag) => tag.startsWith("<title"))) {
|
|
757
|
+
elements.push(`<title inertia>${title}</title>`);
|
|
736
758
|
}
|
|
737
|
-
return
|
|
759
|
+
return elements;
|
|
738
760
|
}
|
|
739
761
|
if (isServer) {
|
|
740
762
|
provider.update(renderNodes(children));
|
|
@@ -1028,7 +1050,7 @@ var Link = forwardRef3(
|
|
|
1028
1050
|
...props
|
|
1029
1051
|
}, ref) => {
|
|
1030
1052
|
const [inFlightCount, setInFlightCount] = useState7(0);
|
|
1031
|
-
const hoverTimeout = useRef4(
|
|
1053
|
+
const hoverTimeout = useRef4(void 0);
|
|
1032
1054
|
const _method = useMemo7(() => {
|
|
1033
1055
|
return isUrlMethodPair2(href) ? href.method : method.toLowerCase();
|
|
1034
1056
|
}, [href, method]);
|
|
@@ -1154,7 +1176,7 @@ var Link = forwardRef3(
|
|
|
1154
1176
|
}
|
|
1155
1177
|
},
|
|
1156
1178
|
onKeyDown: (event) => {
|
|
1157
|
-
if (
|
|
1179
|
+
if (shouldNavigate(event)) {
|
|
1158
1180
|
event.preventDefault();
|
|
1159
1181
|
doPrefetch();
|
|
1160
1182
|
}
|