@inertiajs/core 2.2.11 → 2.2.13
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 +128 -31
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +122 -25
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/dialog.d.ts +4 -0
- package/types/history.d.ts +1 -0
- package/types/modal.d.ts +4 -0
- package/types/page.d.ts +5 -3
- package/types/types.d.ts +9 -2
package/dist/index.js
CHANGED
|
@@ -90,7 +90,9 @@ var config = new Config({
|
|
|
90
90
|
recentlySuccessfulDuration: 2e3
|
|
91
91
|
},
|
|
92
92
|
future: {
|
|
93
|
-
preserveEqualProps: false
|
|
93
|
+
preserveEqualProps: false,
|
|
94
|
+
useDataInertiaHeadAttribute: false,
|
|
95
|
+
useDialogForErrorModal: false
|
|
94
96
|
},
|
|
95
97
|
prefetch: {
|
|
96
98
|
cacheFor: 3e4
|
|
@@ -531,7 +533,8 @@ var CurrentPage = class {
|
|
|
531
533
|
set(page2, {
|
|
532
534
|
replace = false,
|
|
533
535
|
preserveScroll = false,
|
|
534
|
-
preserveState = false
|
|
536
|
+
preserveState = false,
|
|
537
|
+
viewTransition = false
|
|
535
538
|
} = {}) {
|
|
536
539
|
if (Object.keys(page2.deferredProps || {}).length) {
|
|
537
540
|
this.pendingDeferredProps = {
|
|
@@ -558,6 +561,9 @@ var CurrentPage = class {
|
|
|
558
561
|
replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
|
|
559
562
|
}).then(() => {
|
|
560
563
|
const isNewComponent = !this.isTheSame(page2);
|
|
564
|
+
if (!isNewComponent && Object.keys(page2.props.errors || {}).length > 0) {
|
|
565
|
+
viewTransition = false;
|
|
566
|
+
}
|
|
561
567
|
this.page = page2;
|
|
562
568
|
this.cleared = false;
|
|
563
569
|
if (isNewComponent) {
|
|
@@ -567,7 +573,12 @@ var CurrentPage = class {
|
|
|
567
573
|
this.fireEventsFor("firstLoad");
|
|
568
574
|
}
|
|
569
575
|
this.isFirstPageLoad = false;
|
|
570
|
-
return this.swap({
|
|
576
|
+
return this.swap({
|
|
577
|
+
component,
|
|
578
|
+
page: page2,
|
|
579
|
+
preserveState,
|
|
580
|
+
viewTransition
|
|
581
|
+
}).then(() => {
|
|
571
582
|
if (preserveScroll) {
|
|
572
583
|
window.requestAnimationFrame(() => Scroll.restoreScrollRegions(scrollRegions));
|
|
573
584
|
} else {
|
|
@@ -591,7 +602,7 @@ var CurrentPage = class {
|
|
|
591
602
|
this.page = page2;
|
|
592
603
|
this.cleared = false;
|
|
593
604
|
history.setCurrent(page2);
|
|
594
|
-
return this.swap({ component, page: page2, preserveState });
|
|
605
|
+
return this.swap({ component, page: page2, preserveState, viewTransition: false });
|
|
595
606
|
});
|
|
596
607
|
}
|
|
597
608
|
clear() {
|
|
@@ -617,9 +628,18 @@ var CurrentPage = class {
|
|
|
617
628
|
swap({
|
|
618
629
|
component,
|
|
619
630
|
page: page2,
|
|
620
|
-
preserveState
|
|
631
|
+
preserveState,
|
|
632
|
+
viewTransition
|
|
621
633
|
}) {
|
|
622
|
-
|
|
634
|
+
const doSwap = () => this.swapComponent({ component, page: page2, preserveState });
|
|
635
|
+
if (!viewTransition || !document?.startViewTransition) {
|
|
636
|
+
return doSwap();
|
|
637
|
+
}
|
|
638
|
+
const viewTransitionCallback = typeof viewTransition === "boolean" ? () => null : viewTransition;
|
|
639
|
+
return new Promise((resolve) => {
|
|
640
|
+
const transitionResult = document.startViewTransition(() => doSwap().then(resolve));
|
|
641
|
+
viewTransitionCallback(transitionResult);
|
|
642
|
+
});
|
|
623
643
|
}
|
|
624
644
|
resolve(component) {
|
|
625
645
|
return Promise.resolve(this.resolveComponent(component));
|
|
@@ -712,9 +732,21 @@ var History = class {
|
|
|
712
732
|
});
|
|
713
733
|
});
|
|
714
734
|
}
|
|
735
|
+
clonePageProps(page2) {
|
|
736
|
+
try {
|
|
737
|
+
structuredClone(page2.props);
|
|
738
|
+
return page2;
|
|
739
|
+
} catch {
|
|
740
|
+
return {
|
|
741
|
+
...page2,
|
|
742
|
+
props: (0, import_lodash_es2.cloneDeep)(page2.props)
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
}
|
|
715
746
|
getPageData(page2) {
|
|
747
|
+
const pageWithClonedProps = this.clonePageProps(page2);
|
|
716
748
|
return new Promise((resolve) => {
|
|
717
|
-
return page2.encryptHistory ? encryptHistory(
|
|
749
|
+
return page2.encryptHistory ? encryptHistory(pageWithClonedProps).then(resolve) : resolve(pageWithClonedProps);
|
|
718
750
|
});
|
|
719
751
|
}
|
|
720
752
|
processQueue() {
|
|
@@ -1335,7 +1367,8 @@ var PrefetchedRequests = class {
|
|
|
1335
1367
|
"onPrefetched",
|
|
1336
1368
|
"onCancelToken",
|
|
1337
1369
|
"onPrefetching",
|
|
1338
|
-
"async"
|
|
1370
|
+
"async",
|
|
1371
|
+
"viewTransition"
|
|
1339
1372
|
]
|
|
1340
1373
|
);
|
|
1341
1374
|
}
|
|
@@ -1492,7 +1525,7 @@ var import_lodash_es4 = require("lodash-es");
|
|
|
1492
1525
|
var modal_default = {
|
|
1493
1526
|
modal: null,
|
|
1494
1527
|
listener: null,
|
|
1495
|
-
|
|
1528
|
+
createIframeAndPage(html) {
|
|
1496
1529
|
if (typeof html === "object") {
|
|
1497
1530
|
html = `All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(
|
|
1498
1531
|
html
|
|
@@ -1501,6 +1534,15 @@ var modal_default = {
|
|
|
1501
1534
|
const page2 = document.createElement("html");
|
|
1502
1535
|
page2.innerHTML = html;
|
|
1503
1536
|
page2.querySelectorAll("a").forEach((a) => a.setAttribute("target", "_top"));
|
|
1537
|
+
const iframe = document.createElement("iframe");
|
|
1538
|
+
iframe.style.backgroundColor = "white";
|
|
1539
|
+
iframe.style.borderRadius = "5px";
|
|
1540
|
+
iframe.style.width = "100%";
|
|
1541
|
+
iframe.style.height = "100%";
|
|
1542
|
+
return { iframe, page: page2 };
|
|
1543
|
+
},
|
|
1544
|
+
show(html) {
|
|
1545
|
+
const { iframe, page: page2 } = this.createIframeAndPage(html);
|
|
1504
1546
|
this.modal = document.createElement("div");
|
|
1505
1547
|
this.modal.style.position = "fixed";
|
|
1506
1548
|
this.modal.style.width = "100vw";
|
|
@@ -1510,11 +1552,6 @@ var modal_default = {
|
|
|
1510
1552
|
this.modal.style.backgroundColor = "rgba(0, 0, 0, .6)";
|
|
1511
1553
|
this.modal.style.zIndex = 2e5;
|
|
1512
1554
|
this.modal.addEventListener("click", () => this.hide());
|
|
1513
|
-
const iframe = document.createElement("iframe");
|
|
1514
|
-
iframe.style.backgroundColor = "white";
|
|
1515
|
-
iframe.style.borderRadius = "5px";
|
|
1516
|
-
iframe.style.width = "100%";
|
|
1517
|
-
iframe.style.height = "100%";
|
|
1518
1555
|
this.modal.appendChild(iframe);
|
|
1519
1556
|
document.body.prepend(this.modal);
|
|
1520
1557
|
document.body.style.overflow = "hidden";
|
|
@@ -1540,6 +1577,55 @@ var modal_default = {
|
|
|
1540
1577
|
}
|
|
1541
1578
|
};
|
|
1542
1579
|
|
|
1580
|
+
// src/dialog.ts
|
|
1581
|
+
var dialog_default = {
|
|
1582
|
+
show(html) {
|
|
1583
|
+
const { iframe, page: page2 } = modal_default.createIframeAndPage(html);
|
|
1584
|
+
iframe.style.boxSizing = "border-box";
|
|
1585
|
+
iframe.style.display = "block";
|
|
1586
|
+
const dialog = document.createElement("dialog");
|
|
1587
|
+
dialog.id = "inertia-error-dialog";
|
|
1588
|
+
Object.assign(dialog.style, {
|
|
1589
|
+
width: "calc(100vw - 100px)",
|
|
1590
|
+
height: "calc(100vh - 100px)",
|
|
1591
|
+
padding: "0",
|
|
1592
|
+
margin: "auto",
|
|
1593
|
+
border: "none",
|
|
1594
|
+
backgroundColor: "transparent"
|
|
1595
|
+
});
|
|
1596
|
+
const dialogStyleElement = document.createElement("style");
|
|
1597
|
+
dialogStyleElement.textContent = `
|
|
1598
|
+
dialog#inertia-error-dialog::backdrop {
|
|
1599
|
+
background-color: rgba(0, 0, 0, 0.6);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
dialog#inertia-error-dialog:focus {
|
|
1603
|
+
outline: none;
|
|
1604
|
+
}
|
|
1605
|
+
`;
|
|
1606
|
+
document.head.appendChild(dialogStyleElement);
|
|
1607
|
+
dialog.addEventListener("click", (event) => {
|
|
1608
|
+
if (event.target === dialog) {
|
|
1609
|
+
dialog.close();
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
dialog.addEventListener("close", () => {
|
|
1613
|
+
dialogStyleElement.remove();
|
|
1614
|
+
dialog.remove();
|
|
1615
|
+
});
|
|
1616
|
+
dialog.appendChild(iframe);
|
|
1617
|
+
document.body.prepend(dialog);
|
|
1618
|
+
dialog.showModal();
|
|
1619
|
+
dialog.focus();
|
|
1620
|
+
if (!iframe.contentWindow) {
|
|
1621
|
+
throw new Error("iframe not yet ready.");
|
|
1622
|
+
}
|
|
1623
|
+
iframe.contentWindow.document.open();
|
|
1624
|
+
iframe.contentWindow.document.write(page2.outerHTML);
|
|
1625
|
+
iframe.contentWindow.document.close();
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1543
1629
|
// src/response.ts
|
|
1544
1630
|
var queue2 = new Queue();
|
|
1545
1631
|
var Response = class _Response {
|
|
@@ -1603,7 +1689,7 @@ var Response = class _Response {
|
|
|
1603
1689
|
data: this.getDataFromResponse(this.response.data)
|
|
1604
1690
|
};
|
|
1605
1691
|
if (fireInvalidEvent(response)) {
|
|
1606
|
-
return modal_default.show(response.data);
|
|
1692
|
+
return config.get("future.useDialogForErrorModal") ? dialog_default.show(response.data) : modal_default.show(response.data);
|
|
1607
1693
|
}
|
|
1608
1694
|
}
|
|
1609
1695
|
isInertiaResponse() {
|
|
@@ -1656,7 +1742,8 @@ var Response = class _Response {
|
|
|
1656
1742
|
return page.set(pageResponse, {
|
|
1657
1743
|
replace: this.requestParams.all().replace,
|
|
1658
1744
|
preserveScroll: this.requestParams.all().preserveScroll,
|
|
1659
|
-
preserveState: this.requestParams.all().preserveState
|
|
1745
|
+
preserveState: this.requestParams.all().preserveState,
|
|
1746
|
+
viewTransition: this.requestParams.all().viewTransition
|
|
1660
1747
|
});
|
|
1661
1748
|
}
|
|
1662
1749
|
getDataFromResponse(response) {
|
|
@@ -2093,7 +2180,8 @@ var Router = class {
|
|
|
2093
2180
|
...options,
|
|
2094
2181
|
async: true,
|
|
2095
2182
|
showProgress: false,
|
|
2096
|
-
prefetch: true
|
|
2183
|
+
prefetch: true,
|
|
2184
|
+
viewTransition: false
|
|
2097
2185
|
});
|
|
2098
2186
|
const visitUrl = visit.url.origin + visit.url.pathname + visit.url.search;
|
|
2099
2187
|
const currentUrl = window.location.origin + window.location.pathname + window.location.search;
|
|
@@ -2191,7 +2279,7 @@ var Router = class {
|
|
|
2191
2279
|
clientVisit(params, { replace = false } = {}) {
|
|
2192
2280
|
const current = page.get();
|
|
2193
2281
|
const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
|
|
2194
|
-
const { onError, onFinish, onSuccess, ...pageParams } = params;
|
|
2282
|
+
const { viewTransition, onError, onFinish, onSuccess, ...pageParams } = params;
|
|
2195
2283
|
const page2 = {
|
|
2196
2284
|
...current,
|
|
2197
2285
|
...pageParams,
|
|
@@ -2202,7 +2290,8 @@ var Router = class {
|
|
|
2202
2290
|
page.set(page2, {
|
|
2203
2291
|
replace,
|
|
2204
2292
|
preserveScroll,
|
|
2205
|
-
preserveState
|
|
2293
|
+
preserveState,
|
|
2294
|
+
viewTransition
|
|
2206
2295
|
}).then(() => {
|
|
2207
2296
|
const errors = page.get().props.errors || {};
|
|
2208
2297
|
if (Object.keys(errors).length === 0) {
|
|
@@ -2218,7 +2307,8 @@ var Router = class {
|
|
|
2218
2307
|
...options,
|
|
2219
2308
|
async: true,
|
|
2220
2309
|
showProgress: false,
|
|
2221
|
-
prefetch: true
|
|
2310
|
+
prefetch: true,
|
|
2311
|
+
viewTransition: false
|
|
2222
2312
|
}),
|
|
2223
2313
|
...this.getVisitEvents(options)
|
|
2224
2314
|
};
|
|
@@ -2250,6 +2340,7 @@ var Router = class {
|
|
|
2250
2340
|
preserveUrl: false,
|
|
2251
2341
|
prefetch: false,
|
|
2252
2342
|
invalidateCacheTags: [],
|
|
2343
|
+
viewTransition: false,
|
|
2253
2344
|
...options,
|
|
2254
2345
|
...configuredOptions
|
|
2255
2346
|
};
|
|
@@ -2436,6 +2527,9 @@ function formDataToObject(source) {
|
|
|
2436
2527
|
|
|
2437
2528
|
// src/head.ts
|
|
2438
2529
|
var Renderer = {
|
|
2530
|
+
preferredAttribute() {
|
|
2531
|
+
return config.get("future.useDataInertiaHeadAttribute") ? "data-inertia" : "inertia";
|
|
2532
|
+
},
|
|
2439
2533
|
buildDOMElement(tag) {
|
|
2440
2534
|
const template = document.createElement("template");
|
|
2441
2535
|
template.innerHTML = tag;
|
|
@@ -2451,12 +2545,13 @@ var Renderer = {
|
|
|
2451
2545
|
return script;
|
|
2452
2546
|
},
|
|
2453
2547
|
isInertiaManagedElement(element) {
|
|
2454
|
-
return element.nodeType === Node.ELEMENT_NODE && element.getAttribute(
|
|
2548
|
+
return element.nodeType === Node.ELEMENT_NODE && element.getAttribute(this.preferredAttribute()) !== null;
|
|
2455
2549
|
},
|
|
2456
2550
|
findMatchingElementIndex(element, elements) {
|
|
2457
|
-
const
|
|
2551
|
+
const attribute = this.preferredAttribute();
|
|
2552
|
+
const key = element.getAttribute(attribute);
|
|
2458
2553
|
if (key !== null) {
|
|
2459
|
-
return elements.findIndex((element2) => element2.getAttribute(
|
|
2554
|
+
return elements.findIndex((element2) => element2.getAttribute(attribute) === key);
|
|
2460
2555
|
}
|
|
2461
2556
|
return -1;
|
|
2462
2557
|
},
|
|
@@ -2507,8 +2602,9 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2507
2602
|
}
|
|
2508
2603
|
function collect() {
|
|
2509
2604
|
const title = titleCallback("");
|
|
2605
|
+
const attribute = Renderer.preferredAttribute();
|
|
2510
2606
|
const defaults = {
|
|
2511
|
-
...title ? { title: `<title
|
|
2607
|
+
...title ? { title: `<title ${attribute}="">${title}</title>` } : {}
|
|
2512
2608
|
};
|
|
2513
2609
|
const elements = Object.values(states).reduce((carry, elements2) => carry.concat(elements2), []).reduce((carry, element) => {
|
|
2514
2610
|
if (element.indexOf("<") === -1) {
|
|
@@ -2519,7 +2615,7 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2519
2615
|
carry.title = title2 ? `${title2[1]}${titleCallback(title2[2])}${title2[3]}` : element;
|
|
2520
2616
|
return carry;
|
|
2521
2617
|
}
|
|
2522
|
-
const match = element.match(/ inertia="[^"]+"/);
|
|
2618
|
+
const match = element.match(attribute === "inertia" ? / inertia="[^"]+"/ : / data-inertia="[^"]+"/);
|
|
2523
2619
|
if (match) {
|
|
2524
2620
|
carry[match[0]] = element;
|
|
2525
2621
|
} else {
|
|
@@ -2538,6 +2634,7 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2538
2634
|
createProvider: function() {
|
|
2539
2635
|
const id = connect();
|
|
2540
2636
|
return {
|
|
2637
|
+
preferredAttribute: Renderer.preferredAttribute,
|
|
2541
2638
|
reconnect: () => reconnect(id),
|
|
2542
2639
|
update: (elements) => update(id, elements),
|
|
2543
2640
|
disconnect: () => disconnect(id)
|