@inertiajs/core 2.2.12 → 2.2.14
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 +109 -24
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +109 -24
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/dialog.d.ts +4 -0
- package/types/modal.d.ts +4 -0
- package/types/page.d.ts +5 -3
- package/types/types.d.ts +12 -5
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));
|
|
@@ -1347,7 +1367,8 @@ var PrefetchedRequests = class {
|
|
|
1347
1367
|
"onPrefetched",
|
|
1348
1368
|
"onCancelToken",
|
|
1349
1369
|
"onPrefetching",
|
|
1350
|
-
"async"
|
|
1370
|
+
"async",
|
|
1371
|
+
"viewTransition"
|
|
1351
1372
|
]
|
|
1352
1373
|
);
|
|
1353
1374
|
}
|
|
@@ -1504,7 +1525,7 @@ var import_lodash_es4 = require("lodash-es");
|
|
|
1504
1525
|
var modal_default = {
|
|
1505
1526
|
modal: null,
|
|
1506
1527
|
listener: null,
|
|
1507
|
-
|
|
1528
|
+
createIframeAndPage(html) {
|
|
1508
1529
|
if (typeof html === "object") {
|
|
1509
1530
|
html = `All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(
|
|
1510
1531
|
html
|
|
@@ -1513,6 +1534,15 @@ var modal_default = {
|
|
|
1513
1534
|
const page2 = document.createElement("html");
|
|
1514
1535
|
page2.innerHTML = html;
|
|
1515
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);
|
|
1516
1546
|
this.modal = document.createElement("div");
|
|
1517
1547
|
this.modal.style.position = "fixed";
|
|
1518
1548
|
this.modal.style.width = "100vw";
|
|
@@ -1522,11 +1552,6 @@ var modal_default = {
|
|
|
1522
1552
|
this.modal.style.backgroundColor = "rgba(0, 0, 0, .6)";
|
|
1523
1553
|
this.modal.style.zIndex = 2e5;
|
|
1524
1554
|
this.modal.addEventListener("click", () => this.hide());
|
|
1525
|
-
const iframe = document.createElement("iframe");
|
|
1526
|
-
iframe.style.backgroundColor = "white";
|
|
1527
|
-
iframe.style.borderRadius = "5px";
|
|
1528
|
-
iframe.style.width = "100%";
|
|
1529
|
-
iframe.style.height = "100%";
|
|
1530
1555
|
this.modal.appendChild(iframe);
|
|
1531
1556
|
document.body.prepend(this.modal);
|
|
1532
1557
|
document.body.style.overflow = "hidden";
|
|
@@ -1552,6 +1577,55 @@ var modal_default = {
|
|
|
1552
1577
|
}
|
|
1553
1578
|
};
|
|
1554
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
|
+
|
|
1555
1629
|
// src/response.ts
|
|
1556
1630
|
var queue2 = new Queue();
|
|
1557
1631
|
var Response = class _Response {
|
|
@@ -1615,7 +1689,7 @@ var Response = class _Response {
|
|
|
1615
1689
|
data: this.getDataFromResponse(this.response.data)
|
|
1616
1690
|
};
|
|
1617
1691
|
if (fireInvalidEvent(response)) {
|
|
1618
|
-
return modal_default.show(response.data);
|
|
1692
|
+
return config.get("future.useDialogForErrorModal") ? dialog_default.show(response.data) : modal_default.show(response.data);
|
|
1619
1693
|
}
|
|
1620
1694
|
}
|
|
1621
1695
|
isInertiaResponse() {
|
|
@@ -1668,7 +1742,8 @@ var Response = class _Response {
|
|
|
1668
1742
|
return page.set(pageResponse, {
|
|
1669
1743
|
replace: this.requestParams.all().replace,
|
|
1670
1744
|
preserveScroll: this.requestParams.all().preserveScroll,
|
|
1671
|
-
preserveState: this.requestParams.all().preserveState
|
|
1745
|
+
preserveState: this.requestParams.all().preserveState,
|
|
1746
|
+
viewTransition: this.requestParams.all().viewTransition
|
|
1672
1747
|
});
|
|
1673
1748
|
}
|
|
1674
1749
|
getDataFromResponse(response) {
|
|
@@ -2105,7 +2180,8 @@ var Router = class {
|
|
|
2105
2180
|
...options,
|
|
2106
2181
|
async: true,
|
|
2107
2182
|
showProgress: false,
|
|
2108
|
-
prefetch: true
|
|
2183
|
+
prefetch: true,
|
|
2184
|
+
viewTransition: false
|
|
2109
2185
|
});
|
|
2110
2186
|
const visitUrl = visit.url.origin + visit.url.pathname + visit.url.search;
|
|
2111
2187
|
const currentUrl = window.location.origin + window.location.pathname + window.location.search;
|
|
@@ -2203,7 +2279,7 @@ var Router = class {
|
|
|
2203
2279
|
clientVisit(params, { replace = false } = {}) {
|
|
2204
2280
|
const current = page.get();
|
|
2205
2281
|
const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
|
|
2206
|
-
const { onError, onFinish, onSuccess, ...pageParams } = params;
|
|
2282
|
+
const { viewTransition, onError, onFinish, onSuccess, ...pageParams } = params;
|
|
2207
2283
|
const page2 = {
|
|
2208
2284
|
...current,
|
|
2209
2285
|
...pageParams,
|
|
@@ -2214,7 +2290,8 @@ var Router = class {
|
|
|
2214
2290
|
page.set(page2, {
|
|
2215
2291
|
replace,
|
|
2216
2292
|
preserveScroll,
|
|
2217
|
-
preserveState
|
|
2293
|
+
preserveState,
|
|
2294
|
+
viewTransition
|
|
2218
2295
|
}).then(() => {
|
|
2219
2296
|
const errors = page.get().props.errors || {};
|
|
2220
2297
|
if (Object.keys(errors).length === 0) {
|
|
@@ -2230,7 +2307,8 @@ var Router = class {
|
|
|
2230
2307
|
...options,
|
|
2231
2308
|
async: true,
|
|
2232
2309
|
showProgress: false,
|
|
2233
|
-
prefetch: true
|
|
2310
|
+
prefetch: true,
|
|
2311
|
+
viewTransition: false
|
|
2234
2312
|
}),
|
|
2235
2313
|
...this.getVisitEvents(options)
|
|
2236
2314
|
};
|
|
@@ -2262,6 +2340,7 @@ var Router = class {
|
|
|
2262
2340
|
preserveUrl: false,
|
|
2263
2341
|
prefetch: false,
|
|
2264
2342
|
invalidateCacheTags: [],
|
|
2343
|
+
viewTransition: false,
|
|
2265
2344
|
...options,
|
|
2266
2345
|
...configuredOptions
|
|
2267
2346
|
};
|
|
@@ -2448,6 +2527,9 @@ function formDataToObject(source) {
|
|
|
2448
2527
|
|
|
2449
2528
|
// src/head.ts
|
|
2450
2529
|
var Renderer = {
|
|
2530
|
+
preferredAttribute() {
|
|
2531
|
+
return config.get("future.useDataInertiaHeadAttribute") ? "data-inertia" : "inertia";
|
|
2532
|
+
},
|
|
2451
2533
|
buildDOMElement(tag) {
|
|
2452
2534
|
const template = document.createElement("template");
|
|
2453
2535
|
template.innerHTML = tag;
|
|
@@ -2463,12 +2545,13 @@ var Renderer = {
|
|
|
2463
2545
|
return script;
|
|
2464
2546
|
},
|
|
2465
2547
|
isInertiaManagedElement(element) {
|
|
2466
|
-
return element.nodeType === Node.ELEMENT_NODE && element.getAttribute(
|
|
2548
|
+
return element.nodeType === Node.ELEMENT_NODE && element.getAttribute(this.preferredAttribute()) !== null;
|
|
2467
2549
|
},
|
|
2468
2550
|
findMatchingElementIndex(element, elements) {
|
|
2469
|
-
const
|
|
2551
|
+
const attribute = this.preferredAttribute();
|
|
2552
|
+
const key = element.getAttribute(attribute);
|
|
2470
2553
|
if (key !== null) {
|
|
2471
|
-
return elements.findIndex((element2) => element2.getAttribute(
|
|
2554
|
+
return elements.findIndex((element2) => element2.getAttribute(attribute) === key);
|
|
2472
2555
|
}
|
|
2473
2556
|
return -1;
|
|
2474
2557
|
},
|
|
@@ -2519,8 +2602,9 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2519
2602
|
}
|
|
2520
2603
|
function collect() {
|
|
2521
2604
|
const title = titleCallback("");
|
|
2605
|
+
const attribute = Renderer.preferredAttribute();
|
|
2522
2606
|
const defaults = {
|
|
2523
|
-
...title ? { title: `<title
|
|
2607
|
+
...title ? { title: `<title ${attribute}="">${title}</title>` } : {}
|
|
2524
2608
|
};
|
|
2525
2609
|
const elements = Object.values(states).reduce((carry, elements2) => carry.concat(elements2), []).reduce((carry, element) => {
|
|
2526
2610
|
if (element.indexOf("<") === -1) {
|
|
@@ -2531,7 +2615,7 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2531
2615
|
carry.title = title2 ? `${title2[1]}${titleCallback(title2[2])}${title2[3]}` : element;
|
|
2532
2616
|
return carry;
|
|
2533
2617
|
}
|
|
2534
|
-
const match = element.match(/ inertia="[^"]+"/);
|
|
2618
|
+
const match = element.match(attribute === "inertia" ? / inertia="[^"]+"/ : / data-inertia="[^"]+"/);
|
|
2535
2619
|
if (match) {
|
|
2536
2620
|
carry[match[0]] = element;
|
|
2537
2621
|
} else {
|
|
@@ -2550,6 +2634,7 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2550
2634
|
createProvider: function() {
|
|
2551
2635
|
const id = connect();
|
|
2552
2636
|
return {
|
|
2637
|
+
preferredAttribute: Renderer.preferredAttribute,
|
|
2553
2638
|
reconnect: () => reconnect(id),
|
|
2554
2639
|
update: (elements) => update(id, elements),
|
|
2555
2640
|
disconnect: () => disconnect(id)
|