@inertiajs/core 2.2.7 → 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 +100 -35
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +114 -49
- package/dist/index.js.map +4 -4
- package/package.json +5 -5
- package/types/debug.d.ts +1 -1
- package/types/head.d.ts +2 -7
- package/types/navigationEvents.d.ts +5 -2
- package/types/page.d.ts +10 -6
- package/types/requestParams.d.ts +1 -1
- package/types/router.d.ts +1 -1
- package/types/scroll.d.ts +1 -0
- package/types/types.d.ts +53 -15
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
module.exports = __toCommonJS(index_exports);
|
|
54
54
|
|
|
55
55
|
// src/router.ts
|
|
56
|
-
var
|
|
56
|
+
var import_lodash_es4 = require("lodash-es");
|
|
57
57
|
|
|
58
58
|
// src/debounce.ts
|
|
59
59
|
function debounce(fn, delay) {
|
|
@@ -105,6 +105,9 @@ var firePrefetchingEvent = (visit) => {
|
|
|
105
105
|
return fireEvent("prefetching", { detail: { visit } });
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
+
// src/history.ts
|
|
109
|
+
var import_lodash_es = require("lodash-es");
|
|
110
|
+
|
|
108
111
|
// src/sessionStorage.ts
|
|
109
112
|
var SessionStorage = class {
|
|
110
113
|
static set(key, value) {
|
|
@@ -314,18 +317,24 @@ var Scroll = class {
|
|
|
314
317
|
}
|
|
315
318
|
window.requestAnimationFrame(() => {
|
|
316
319
|
this.restoreDocument();
|
|
317
|
-
this.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
320
|
+
this.restoreScrollRegions(scrollRegions);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
static restoreScrollRegions(scrollRegions) {
|
|
324
|
+
if (typeof window === "undefined") {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
this.regions().forEach((region, index) => {
|
|
328
|
+
const scrollPosition = scrollRegions[index];
|
|
329
|
+
if (!scrollPosition) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (typeof region.scrollTo === "function") {
|
|
333
|
+
region.scrollTo(scrollPosition.left, scrollPosition.top);
|
|
334
|
+
} else {
|
|
335
|
+
region.scrollTop = scrollPosition.top;
|
|
336
|
+
region.scrollLeft = scrollPosition.left;
|
|
337
|
+
}
|
|
329
338
|
});
|
|
330
339
|
}
|
|
331
340
|
static restoreDocument() {
|
|
@@ -467,7 +476,11 @@ var CurrentPage = class {
|
|
|
467
476
|
this.cleared = false;
|
|
468
477
|
this.pendingDeferredProps = null;
|
|
469
478
|
}
|
|
470
|
-
init({
|
|
479
|
+
init({
|
|
480
|
+
initialPage,
|
|
481
|
+
swapComponent,
|
|
482
|
+
resolveComponent
|
|
483
|
+
}) {
|
|
471
484
|
this.page = initialPage;
|
|
472
485
|
this.swapComponent = swapComponent;
|
|
473
486
|
this.resolveComponent = resolveComponent;
|
|
@@ -495,7 +508,9 @@ var CurrentPage = class {
|
|
|
495
508
|
return;
|
|
496
509
|
}
|
|
497
510
|
page2.rememberedState ?? (page2.rememberedState = {});
|
|
498
|
-
const
|
|
511
|
+
const isServer2 = typeof window === "undefined";
|
|
512
|
+
const location = !isServer2 ? window.location : new URL(page2.url);
|
|
513
|
+
const scrollRegions = !isServer2 && preserveScroll ? history.getScrollRegions() : [];
|
|
499
514
|
replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
|
|
500
515
|
return new Promise((resolve) => {
|
|
501
516
|
replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
|
|
@@ -511,7 +526,9 @@ var CurrentPage = class {
|
|
|
511
526
|
}
|
|
512
527
|
this.isFirstPageLoad = false;
|
|
513
528
|
return this.swap({ component, page: page2, preserveState }).then(() => {
|
|
514
|
-
if (
|
|
529
|
+
if (preserveScroll) {
|
|
530
|
+
window.requestAnimationFrame(() => Scroll.restoreScrollRegions(scrollRegions));
|
|
531
|
+
} else {
|
|
515
532
|
Scroll.reset();
|
|
516
533
|
}
|
|
517
534
|
if (this.pendingDeferredProps && this.pendingDeferredProps.component === page2.component && this.pendingDeferredProps.url === page2.url) {
|
|
@@ -687,6 +704,9 @@ var History = class {
|
|
|
687
704
|
if (!window.history.state?.page) {
|
|
688
705
|
return;
|
|
689
706
|
}
|
|
707
|
+
if ((0, import_lodash_es.isEqual)(this.getScrollRegions(), scrollRegions)) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
690
710
|
return this.doReplaceState({
|
|
691
711
|
page: window.history.state.page,
|
|
692
712
|
scrollRegions
|
|
@@ -700,6 +720,9 @@ var History = class {
|
|
|
700
720
|
if (!window.history.state?.page) {
|
|
701
721
|
return;
|
|
702
722
|
}
|
|
723
|
+
if ((0, import_lodash_es.isEqual)(this.getDocumentScrollPosition(), scrollRegion)) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
703
726
|
return this.doReplaceState({
|
|
704
727
|
page: window.history.state.page,
|
|
705
728
|
documentScrollPosition: scrollRegion
|
|
@@ -1028,7 +1051,7 @@ var Polls = class {
|
|
|
1028
1051
|
var polls = new Polls();
|
|
1029
1052
|
|
|
1030
1053
|
// src/prefetched.ts
|
|
1031
|
-
var
|
|
1054
|
+
var import_lodash_es2 = require("lodash-es");
|
|
1032
1055
|
|
|
1033
1056
|
// src/objectUtils.ts
|
|
1034
1057
|
var objectsAreEqual = (obj1, obj2, excludeKeys) => {
|
|
@@ -1245,7 +1268,7 @@ var PrefetchedRequests = class {
|
|
|
1245
1268
|
}) || null;
|
|
1246
1269
|
}
|
|
1247
1270
|
withoutPurposePrefetchHeader(params) {
|
|
1248
|
-
const newParams = (0,
|
|
1271
|
+
const newParams = (0, import_lodash_es2.cloneDeep)(params);
|
|
1249
1272
|
if (newParams.headers["Purpose"] === "prefetch") {
|
|
1250
1273
|
delete newParams.headers["Purpose"];
|
|
1251
1274
|
}
|
|
@@ -1386,8 +1409,8 @@ var RequestParams = class _RequestParams {
|
|
|
1386
1409
|
return headers;
|
|
1387
1410
|
}
|
|
1388
1411
|
setPreserveOptions(page2) {
|
|
1389
|
-
this.params.preserveScroll =
|
|
1390
|
-
this.params.preserveState =
|
|
1412
|
+
this.params.preserveScroll = _RequestParams.resolvePreserveOption(this.params.preserveScroll, page2);
|
|
1413
|
+
this.params.preserveState = _RequestParams.resolvePreserveOption(this.params.preserveState, page2);
|
|
1391
1414
|
}
|
|
1392
1415
|
runCallbacks() {
|
|
1393
1416
|
this.callbacks.forEach(({ name, args }) => {
|
|
@@ -1409,7 +1432,7 @@ var RequestParams = class _RequestParams {
|
|
|
1409
1432
|
recordCallback(name, args) {
|
|
1410
1433
|
this.callbacks.push({ name, args });
|
|
1411
1434
|
}
|
|
1412
|
-
resolvePreserveOption(value, page2) {
|
|
1435
|
+
static resolvePreserveOption(value, page2) {
|
|
1413
1436
|
if (typeof value === "function") {
|
|
1414
1437
|
return value(page2);
|
|
1415
1438
|
}
|
|
@@ -1421,7 +1444,7 @@ var RequestParams = class _RequestParams {
|
|
|
1421
1444
|
};
|
|
1422
1445
|
|
|
1423
1446
|
// src/response.ts
|
|
1424
|
-
var
|
|
1447
|
+
var import_lodash_es3 = require("lodash-es");
|
|
1425
1448
|
|
|
1426
1449
|
// src/modal.ts
|
|
1427
1450
|
var modal_default = {
|
|
@@ -1631,8 +1654,8 @@ var Response = class _Response {
|
|
|
1631
1654
|
const propsToDeepMerge = pageResponse.deepMergeProps || [];
|
|
1632
1655
|
const matchPropsOn = pageResponse.matchPropsOn || [];
|
|
1633
1656
|
const mergeProp = (prop, shouldAppend) => {
|
|
1634
|
-
const currentProp = (0,
|
|
1635
|
-
const incomingProp = (0,
|
|
1657
|
+
const currentProp = (0, import_lodash_es3.get)(page.get().props, prop);
|
|
1658
|
+
const incomingProp = (0, import_lodash_es3.get)(pageResponse.props, prop);
|
|
1636
1659
|
if (Array.isArray(incomingProp)) {
|
|
1637
1660
|
const newArray = this.mergeOrMatchItems(
|
|
1638
1661
|
currentProp || [],
|
|
@@ -1641,13 +1664,13 @@ var Response = class _Response {
|
|
|
1641
1664
|
matchPropsOn,
|
|
1642
1665
|
shouldAppend
|
|
1643
1666
|
);
|
|
1644
|
-
(0,
|
|
1667
|
+
(0, import_lodash_es3.set)(pageResponse.props, prop, newArray);
|
|
1645
1668
|
} else if (typeof incomingProp === "object" && incomingProp !== null) {
|
|
1646
1669
|
const newObject = {
|
|
1647
1670
|
...currentProp || {},
|
|
1648
1671
|
...incomingProp
|
|
1649
1672
|
};
|
|
1650
|
-
(0,
|
|
1673
|
+
(0, import_lodash_es3.set)(pageResponse.props, prop, newObject);
|
|
1651
1674
|
}
|
|
1652
1675
|
};
|
|
1653
1676
|
propsToAppend.forEach((prop) => mergeProp(prop, true));
|
|
@@ -1888,7 +1911,11 @@ var Router = class {
|
|
|
1888
1911
|
interruptible: false
|
|
1889
1912
|
});
|
|
1890
1913
|
}
|
|
1891
|
-
init({
|
|
1914
|
+
init({
|
|
1915
|
+
initialPage,
|
|
1916
|
+
resolveComponent,
|
|
1917
|
+
swapComponent
|
|
1918
|
+
}) {
|
|
1892
1919
|
page.init({
|
|
1893
1920
|
initialPage,
|
|
1894
1921
|
resolveComponent,
|
|
@@ -2072,8 +2099,8 @@ var Router = class {
|
|
|
2072
2099
|
preserveScroll: true,
|
|
2073
2100
|
preserveState: true,
|
|
2074
2101
|
props(currentProps) {
|
|
2075
|
-
const newValue = typeof value === "function" ? value((0,
|
|
2076
|
-
return (0,
|
|
2102
|
+
const newValue = typeof value === "function" ? value((0, import_lodash_es4.get)(currentProps, name), currentProps) : value;
|
|
2103
|
+
return (0, import_lodash_es4.set)((0, import_lodash_es4.cloneDeep)(currentProps), name, newValue);
|
|
2077
2104
|
},
|
|
2078
2105
|
...options || {}
|
|
2079
2106
|
});
|
|
@@ -2111,18 +2138,18 @@ var Router = class {
|
|
|
2111
2138
|
const current = page.get();
|
|
2112
2139
|
const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
|
|
2113
2140
|
const { onError, onFinish, onSuccess, ...pageParams } = params;
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
).then(() => {
|
|
2141
|
+
const page2 = {
|
|
2142
|
+
...current,
|
|
2143
|
+
...pageParams,
|
|
2144
|
+
props
|
|
2145
|
+
};
|
|
2146
|
+
const preserveScroll = RequestParams.resolvePreserveOption(params.preserveScroll ?? false, page2);
|
|
2147
|
+
const preserveState = RequestParams.resolvePreserveOption(params.preserveState ?? false, page2);
|
|
2148
|
+
page.set(page2, {
|
|
2149
|
+
replace,
|
|
2150
|
+
preserveScroll,
|
|
2151
|
+
preserveState
|
|
2152
|
+
}).then(() => {
|
|
2126
2153
|
const errors = page.get().props.errors || {};
|
|
2127
2154
|
if (Object.keys(errors).length === 0) {
|
|
2128
2155
|
return onSuccess?.(page.get());
|
|
@@ -2233,10 +2260,45 @@ var elementInViewport = (el) => {
|
|
|
2233
2260
|
return verticallyVisible && horizontallyVisible;
|
|
2234
2261
|
};
|
|
2235
2262
|
var getScrollableParent = (element) => {
|
|
2263
|
+
const allowsVerticalScroll = (el) => {
|
|
2264
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2265
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
|
|
2266
|
+
return true;
|
|
2267
|
+
}
|
|
2268
|
+
if (computedStyle.overflowY !== "auto") {
|
|
2269
|
+
return false;
|
|
2270
|
+
}
|
|
2271
|
+
if (["visible", "clip"].includes(computedStyle.overflowX)) {
|
|
2272
|
+
return true;
|
|
2273
|
+
}
|
|
2274
|
+
return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
|
|
2275
|
+
};
|
|
2276
|
+
const allowsHorizontalScroll = (el) => {
|
|
2277
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2278
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
|
|
2279
|
+
return true;
|
|
2280
|
+
}
|
|
2281
|
+
if (computedStyle.overflowX !== "auto") {
|
|
2282
|
+
return false;
|
|
2283
|
+
}
|
|
2284
|
+
if (["visible", "clip"].includes(computedStyle.overflowY)) {
|
|
2285
|
+
return true;
|
|
2286
|
+
}
|
|
2287
|
+
return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
|
|
2288
|
+
};
|
|
2289
|
+
const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
|
|
2290
|
+
if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
|
|
2291
|
+
return true;
|
|
2292
|
+
}
|
|
2293
|
+
if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
|
|
2294
|
+
return true;
|
|
2295
|
+
}
|
|
2296
|
+
return false;
|
|
2297
|
+
};
|
|
2236
2298
|
let parent = element?.parentElement;
|
|
2237
2299
|
while (parent) {
|
|
2238
|
-
const
|
|
2239
|
-
if (
|
|
2300
|
+
const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
|
|
2301
|
+
if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
|
|
2240
2302
|
return parent;
|
|
2241
2303
|
}
|
|
2242
2304
|
parent = parent.parentElement;
|
|
@@ -2267,7 +2329,7 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
|
|
|
2267
2329
|
};
|
|
2268
2330
|
|
|
2269
2331
|
// src/formObject.ts
|
|
2270
|
-
var
|
|
2332
|
+
var import_lodash_es5 = require("lodash-es");
|
|
2271
2333
|
function undotKey(key) {
|
|
2272
2334
|
if (!key.includes(".")) {
|
|
2273
2335
|
return key;
|
|
@@ -2302,15 +2364,15 @@ function formDataToObject(source) {
|
|
|
2302
2364
|
const path = parseKey(undotKey(key));
|
|
2303
2365
|
if (path[path.length - 1] === "") {
|
|
2304
2366
|
const arrayPath = path.slice(0, -1);
|
|
2305
|
-
const existing = (0,
|
|
2367
|
+
const existing = (0, import_lodash_es5.get)(form, arrayPath);
|
|
2306
2368
|
if (Array.isArray(existing)) {
|
|
2307
2369
|
existing.push(value);
|
|
2308
2370
|
} else {
|
|
2309
|
-
(0,
|
|
2371
|
+
(0, import_lodash_es5.set)(form, arrayPath, [value]);
|
|
2310
2372
|
}
|
|
2311
2373
|
continue;
|
|
2312
2374
|
}
|
|
2313
|
-
(0,
|
|
2375
|
+
(0, import_lodash_es5.set)(form, path, value);
|
|
2314
2376
|
}
|
|
2315
2377
|
return form;
|
|
2316
2378
|
}
|
|
@@ -2937,13 +2999,16 @@ function useInfiniteScroll(options) {
|
|
|
2937
2999
|
}
|
|
2938
3000
|
|
|
2939
3001
|
// src/navigationEvents.ts
|
|
3002
|
+
function isContentEditableOrPrevented(event) {
|
|
3003
|
+
return event.target instanceof HTMLElement && event.target.isContentEditable || event.defaultPrevented;
|
|
3004
|
+
}
|
|
2940
3005
|
function shouldIntercept(event) {
|
|
2941
3006
|
const isLink = event.currentTarget.tagName.toLowerCase() === "a";
|
|
2942
|
-
return !(
|
|
3007
|
+
return !(isContentEditableOrPrevented(event) || isLink && event.altKey || isLink && event.ctrlKey || isLink && event.metaKey || isLink && event.shiftKey || isLink && "button" in event && event.button !== 0);
|
|
2943
3008
|
}
|
|
2944
3009
|
function shouldNavigate(event) {
|
|
2945
3010
|
const isButton = event.currentTarget.tagName.toLowerCase() === "button";
|
|
2946
|
-
return event.key === "Enter" || isButton && event.key === " ";
|
|
3011
|
+
return !isContentEditableOrPrevented(event) && (event.key === "Enter" || isButton && event.key === " ");
|
|
2947
3012
|
}
|
|
2948
3013
|
|
|
2949
3014
|
// src/progress-component.ts
|