@inertiajs/core 2.3.9 → 2.3.10
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 +153 -131
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +153 -131
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/index.d.ts +1 -1
- package/types/resetFormFields.d.ts +1 -0
- package/types/router.d.ts +3 -1
- package/types/scroll.d.ts +1 -0
- package/types/types.d.ts +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -575,7 +575,116 @@ var PrefetchedRequests = class {
|
|
|
575
575
|
};
|
|
576
576
|
var prefetchedRequests = new PrefetchedRequests();
|
|
577
577
|
|
|
578
|
+
// src/domUtils.ts
|
|
579
|
+
var elementInViewport = (el) => {
|
|
580
|
+
if (el.offsetParent === null) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
const rect = el.getBoundingClientRect();
|
|
584
|
+
const verticallyVisible = rect.top < window.innerHeight && rect.bottom >= 0;
|
|
585
|
+
const horizontallyVisible = rect.left < window.innerWidth && rect.right >= 0;
|
|
586
|
+
return verticallyVisible && horizontallyVisible;
|
|
587
|
+
};
|
|
588
|
+
var getScrollableParent = (element) => {
|
|
589
|
+
const allowsVerticalScroll = (el) => {
|
|
590
|
+
const computedStyle = window.getComputedStyle(el);
|
|
591
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
if (computedStyle.overflowY !== "auto") {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
if (["visible", "clip"].includes(computedStyle.overflowX)) {
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
|
|
601
|
+
};
|
|
602
|
+
const allowsHorizontalScroll = (el) => {
|
|
603
|
+
const computedStyle = window.getComputedStyle(el);
|
|
604
|
+
if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
if (computedStyle.overflowX !== "auto") {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
if (["visible", "clip"].includes(computedStyle.overflowY)) {
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
|
|
614
|
+
};
|
|
615
|
+
const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
|
|
616
|
+
if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
return false;
|
|
623
|
+
};
|
|
624
|
+
let parent = element?.parentElement;
|
|
625
|
+
while (parent) {
|
|
626
|
+
const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
|
|
627
|
+
if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
|
|
628
|
+
return parent;
|
|
629
|
+
}
|
|
630
|
+
parent = parent.parentElement;
|
|
631
|
+
}
|
|
632
|
+
return null;
|
|
633
|
+
};
|
|
634
|
+
var getElementsInViewportFromCollection = (elements, referenceElement) => {
|
|
635
|
+
if (!referenceElement) {
|
|
636
|
+
return elements.filter((element) => elementInViewport(element));
|
|
637
|
+
}
|
|
638
|
+
const referenceIndex = elements.indexOf(referenceElement);
|
|
639
|
+
const upwardElements = [];
|
|
640
|
+
const downwardElements = [];
|
|
641
|
+
for (let i = referenceIndex; i >= 0; i--) {
|
|
642
|
+
const element = elements[i];
|
|
643
|
+
if (elementInViewport(element)) {
|
|
644
|
+
upwardElements.push(element);
|
|
645
|
+
} else {
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
for (let i = referenceIndex + 1; i < elements.length; i++) {
|
|
650
|
+
const element = elements[i];
|
|
651
|
+
if (elementInViewport(element)) {
|
|
652
|
+
downwardElements.push(element);
|
|
653
|
+
} else {
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return [...upwardElements.reverse(), ...downwardElements];
|
|
658
|
+
};
|
|
659
|
+
var requestAnimationFrame = (cb, times = 1) => {
|
|
660
|
+
window.requestAnimationFrame(() => {
|
|
661
|
+
if (times > 1) {
|
|
662
|
+
requestAnimationFrame(cb, times - 1);
|
|
663
|
+
} else {
|
|
664
|
+
cb();
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
var getInitialPageFromDOM = (id, useScriptElement = false) => {
|
|
669
|
+
if (typeof window === "undefined") {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
if (!useScriptElement) {
|
|
673
|
+
const el = document.getElementById(id);
|
|
674
|
+
if (el?.dataset.page) {
|
|
675
|
+
return JSON.parse(el.dataset.page);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const scriptEl = document.querySelector(`script[data-page="${id}"][type="application/json"]`);
|
|
679
|
+
if (scriptEl?.textContent) {
|
|
680
|
+
return JSON.parse(scriptEl.textContent);
|
|
681
|
+
}
|
|
682
|
+
return null;
|
|
683
|
+
};
|
|
684
|
+
|
|
578
685
|
// src/scroll.ts
|
|
686
|
+
var isServer = typeof window === "undefined";
|
|
687
|
+
var isFirefox = !isServer && /Firefox/i.test(window.navigator.userAgent);
|
|
579
688
|
var Scroll = class {
|
|
580
689
|
static save() {
|
|
581
690
|
history.saveScrollPositions(this.getScrollRegions());
|
|
@@ -589,10 +698,16 @@ var Scroll = class {
|
|
|
589
698
|
static regions() {
|
|
590
699
|
return document.querySelectorAll("[scroll-region]");
|
|
591
700
|
}
|
|
701
|
+
static scrollToTop() {
|
|
702
|
+
if (isFirefox && getComputedStyle(document.documentElement).scrollBehavior === "smooth") {
|
|
703
|
+
return requestAnimationFrame(() => window.scrollTo(0, 0), 2);
|
|
704
|
+
}
|
|
705
|
+
window.scrollTo(0, 0);
|
|
706
|
+
}
|
|
592
707
|
static reset() {
|
|
593
|
-
const anchorHash =
|
|
708
|
+
const anchorHash = isServer ? null : window.location.hash;
|
|
594
709
|
if (!anchorHash) {
|
|
595
|
-
|
|
710
|
+
this.scrollToTop();
|
|
596
711
|
}
|
|
597
712
|
this.regions().forEach((region) => {
|
|
598
713
|
if (typeof region.scrollTo === "function") {
|
|
@@ -606,16 +721,16 @@ var Scroll = class {
|
|
|
606
721
|
this.scrollToAnchor();
|
|
607
722
|
}
|
|
608
723
|
static scrollToAnchor() {
|
|
609
|
-
const anchorHash =
|
|
724
|
+
const anchorHash = isServer ? null : window.location.hash;
|
|
610
725
|
if (anchorHash) {
|
|
611
726
|
setTimeout(() => {
|
|
612
727
|
const anchorElement = document.getElementById(anchorHash.slice(1));
|
|
613
|
-
anchorElement ? anchorElement.scrollIntoView() :
|
|
728
|
+
anchorElement ? anchorElement.scrollIntoView() : this.scrollToTop();
|
|
614
729
|
});
|
|
615
730
|
}
|
|
616
731
|
}
|
|
617
732
|
static restore(scrollRegions) {
|
|
618
|
-
if (
|
|
733
|
+
if (isServer) {
|
|
619
734
|
return;
|
|
620
735
|
}
|
|
621
736
|
window.requestAnimationFrame(() => {
|
|
@@ -624,7 +739,7 @@ var Scroll = class {
|
|
|
624
739
|
});
|
|
625
740
|
}
|
|
626
741
|
static restoreScrollRegions(scrollRegions) {
|
|
627
|
-
if (
|
|
742
|
+
if (isServer) {
|
|
628
743
|
return;
|
|
629
744
|
}
|
|
630
745
|
this.regions().forEach((region, index) => {
|
|
@@ -831,9 +946,9 @@ var CurrentPage = class {
|
|
|
831
946
|
return;
|
|
832
947
|
}
|
|
833
948
|
page2.rememberedState ?? (page2.rememberedState = {});
|
|
834
|
-
const
|
|
835
|
-
const location = !
|
|
836
|
-
const scrollRegions = !
|
|
949
|
+
const isServer3 = typeof window === "undefined";
|
|
950
|
+
const location = !isServer3 ? window.location : new URL(page2.url);
|
|
951
|
+
const scrollRegions = !isServer3 && preserveScroll ? Scroll.getScrollRegions() : [];
|
|
837
952
|
replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
|
|
838
953
|
const pageForHistory = { ...page2, flash: {} };
|
|
839
954
|
return new Promise(
|
|
@@ -993,9 +1108,9 @@ var Queue = class {
|
|
|
993
1108
|
};
|
|
994
1109
|
|
|
995
1110
|
// src/history.ts
|
|
996
|
-
var
|
|
1111
|
+
var isServer2 = typeof window === "undefined";
|
|
997
1112
|
var queue = new Queue();
|
|
998
|
-
var isChromeIOS = !
|
|
1113
|
+
var isChromeIOS = !isServer2 && /CriOS/.test(window.navigator.userAgent);
|
|
999
1114
|
var History = class {
|
|
1000
1115
|
constructor() {
|
|
1001
1116
|
this.rememberedState = "rememberedState";
|
|
@@ -1015,12 +1130,12 @@ var History = class {
|
|
|
1015
1130
|
});
|
|
1016
1131
|
}
|
|
1017
1132
|
restore(key) {
|
|
1018
|
-
if (!
|
|
1133
|
+
if (!isServer2) {
|
|
1019
1134
|
return this.current[this.rememberedState]?.[key] !== void 0 ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
|
|
1020
1135
|
}
|
|
1021
1136
|
}
|
|
1022
1137
|
pushState(page2, cb = null) {
|
|
1023
|
-
if (
|
|
1138
|
+
if (isServer2) {
|
|
1024
1139
|
return;
|
|
1025
1140
|
}
|
|
1026
1141
|
if (this.preserveUrl) {
|
|
@@ -1061,7 +1176,7 @@ var History = class {
|
|
|
1061
1176
|
return queue.process();
|
|
1062
1177
|
}
|
|
1063
1178
|
decrypt(page2 = null) {
|
|
1064
|
-
if (
|
|
1179
|
+
if (isServer2) {
|
|
1065
1180
|
return Promise.resolve(page2 ?? page.get());
|
|
1066
1181
|
}
|
|
1067
1182
|
const pageData = page2 ?? window.history.state?.page;
|
|
@@ -1124,7 +1239,7 @@ var History = class {
|
|
|
1124
1239
|
return;
|
|
1125
1240
|
}
|
|
1126
1241
|
page.merge(page2);
|
|
1127
|
-
if (
|
|
1242
|
+
if (isServer2) {
|
|
1128
1243
|
return;
|
|
1129
1244
|
}
|
|
1130
1245
|
if (this.preserveUrl) {
|
|
@@ -1202,7 +1317,7 @@ var History = class {
|
|
|
1202
1317
|
}
|
|
1203
1318
|
}
|
|
1204
1319
|
browserHasHistoryEntry() {
|
|
1205
|
-
return !
|
|
1320
|
+
return !isServer2 && !!window.history.state?.page;
|
|
1206
1321
|
}
|
|
1207
1322
|
clear() {
|
|
1208
1323
|
SessionStorage.remove(historySessionStorageKeys.key);
|
|
@@ -1799,7 +1914,10 @@ var Response = class _Response {
|
|
|
1799
1914
|
}
|
|
1800
1915
|
getPageResponse() {
|
|
1801
1916
|
const data = this.getDataFromResponse(this.response.data);
|
|
1802
|
-
|
|
1917
|
+
if (typeof data === "object") {
|
|
1918
|
+
return this.response.data = { ...data, flash: data.flash ?? {} };
|
|
1919
|
+
}
|
|
1920
|
+
return this.response.data = data;
|
|
1803
1921
|
}
|
|
1804
1922
|
async handleNonInertiaResponse() {
|
|
1805
1923
|
if (this.isLocationVisit()) {
|
|
@@ -2285,9 +2403,13 @@ var Router = class {
|
|
|
2285
2403
|
cancel() {
|
|
2286
2404
|
this.syncRequestStream.cancelInFlight();
|
|
2287
2405
|
}
|
|
2288
|
-
cancelAll({ prefetch = true } = {}) {
|
|
2289
|
-
|
|
2290
|
-
|
|
2406
|
+
cancelAll({ async = true, prefetch = true, sync = true } = {}) {
|
|
2407
|
+
if (async) {
|
|
2408
|
+
this.asyncRequestStream.cancelInFlight({ prefetch });
|
|
2409
|
+
}
|
|
2410
|
+
if (sync) {
|
|
2411
|
+
this.syncRequestStream.cancelInFlight();
|
|
2412
|
+
}
|
|
2291
2413
|
}
|
|
2292
2414
|
poll(interval, requestOptions = {}, options = {}) {
|
|
2293
2415
|
return polls.add(interval, () => this.reload(requestOptions), {
|
|
@@ -2469,7 +2591,10 @@ var Router = class {
|
|
|
2469
2591
|
}
|
|
2470
2592
|
performClientVisit(params, { replace = false } = {}) {
|
|
2471
2593
|
const current = page.get();
|
|
2472
|
-
const
|
|
2594
|
+
const onceProps = typeof params.props === "function" ? Object.fromEntries(
|
|
2595
|
+
Object.values(current.onceProps ?? {}).map((onceProp) => [onceProp.prop, current.props[onceProp.prop]])
|
|
2596
|
+
) : {};
|
|
2597
|
+
const props = typeof params.props === "function" ? params.props(current.props, onceProps) : params.props ?? current.props;
|
|
2473
2598
|
const flash = typeof params.flash === "function" ? params.flash(current.flash) : params.flash;
|
|
2474
2599
|
const { viewTransition, onError, onFinish, onFlash, onSuccess, ...pageParams } = params;
|
|
2475
2600
|
const page2 = {
|
|
@@ -2703,113 +2828,6 @@ var UseFormUtils = class {
|
|
|
2703
2828
|
}
|
|
2704
2829
|
};
|
|
2705
2830
|
|
|
2706
|
-
// src/domUtils.ts
|
|
2707
|
-
var elementInViewport = (el) => {
|
|
2708
|
-
if (el.offsetParent === null) {
|
|
2709
|
-
return false;
|
|
2710
|
-
}
|
|
2711
|
-
const rect = el.getBoundingClientRect();
|
|
2712
|
-
const verticallyVisible = rect.top < window.innerHeight && rect.bottom >= 0;
|
|
2713
|
-
const horizontallyVisible = rect.left < window.innerWidth && rect.right >= 0;
|
|
2714
|
-
return verticallyVisible && horizontallyVisible;
|
|
2715
|
-
};
|
|
2716
|
-
var getScrollableParent = (element) => {
|
|
2717
|
-
const allowsVerticalScroll = (el) => {
|
|
2718
|
-
const computedStyle = window.getComputedStyle(el);
|
|
2719
|
-
if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
|
|
2720
|
-
return true;
|
|
2721
|
-
}
|
|
2722
|
-
if (computedStyle.overflowY !== "auto") {
|
|
2723
|
-
return false;
|
|
2724
|
-
}
|
|
2725
|
-
if (["visible", "clip"].includes(computedStyle.overflowX)) {
|
|
2726
|
-
return true;
|
|
2727
|
-
}
|
|
2728
|
-
return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
|
|
2729
|
-
};
|
|
2730
|
-
const allowsHorizontalScroll = (el) => {
|
|
2731
|
-
const computedStyle = window.getComputedStyle(el);
|
|
2732
|
-
if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
|
|
2733
|
-
return true;
|
|
2734
|
-
}
|
|
2735
|
-
if (computedStyle.overflowX !== "auto") {
|
|
2736
|
-
return false;
|
|
2737
|
-
}
|
|
2738
|
-
if (["visible", "clip"].includes(computedStyle.overflowY)) {
|
|
2739
|
-
return true;
|
|
2740
|
-
}
|
|
2741
|
-
return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
|
|
2742
|
-
};
|
|
2743
|
-
const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
|
|
2744
|
-
if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
|
|
2745
|
-
return true;
|
|
2746
|
-
}
|
|
2747
|
-
if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
|
|
2748
|
-
return true;
|
|
2749
|
-
}
|
|
2750
|
-
return false;
|
|
2751
|
-
};
|
|
2752
|
-
let parent = element?.parentElement;
|
|
2753
|
-
while (parent) {
|
|
2754
|
-
const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
|
|
2755
|
-
if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
|
|
2756
|
-
return parent;
|
|
2757
|
-
}
|
|
2758
|
-
parent = parent.parentElement;
|
|
2759
|
-
}
|
|
2760
|
-
return null;
|
|
2761
|
-
};
|
|
2762
|
-
var getElementsInViewportFromCollection = (elements, referenceElement) => {
|
|
2763
|
-
if (!referenceElement) {
|
|
2764
|
-
return elements.filter((element) => elementInViewport(element));
|
|
2765
|
-
}
|
|
2766
|
-
const referenceIndex = elements.indexOf(referenceElement);
|
|
2767
|
-
const upwardElements = [];
|
|
2768
|
-
const downwardElements = [];
|
|
2769
|
-
for (let i = referenceIndex; i >= 0; i--) {
|
|
2770
|
-
const element = elements[i];
|
|
2771
|
-
if (elementInViewport(element)) {
|
|
2772
|
-
upwardElements.push(element);
|
|
2773
|
-
} else {
|
|
2774
|
-
break;
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
for (let i = referenceIndex + 1; i < elements.length; i++) {
|
|
2778
|
-
const element = elements[i];
|
|
2779
|
-
if (elementInViewport(element)) {
|
|
2780
|
-
downwardElements.push(element);
|
|
2781
|
-
} else {
|
|
2782
|
-
break;
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
return [...upwardElements.reverse(), ...downwardElements];
|
|
2786
|
-
};
|
|
2787
|
-
var requestAnimationFrame = (cb, times = 1) => {
|
|
2788
|
-
window.requestAnimationFrame(() => {
|
|
2789
|
-
if (times > 1) {
|
|
2790
|
-
requestAnimationFrame(cb, times - 1);
|
|
2791
|
-
} else {
|
|
2792
|
-
cb();
|
|
2793
|
-
}
|
|
2794
|
-
});
|
|
2795
|
-
};
|
|
2796
|
-
var getInitialPageFromDOM = (id, useScriptElement = false) => {
|
|
2797
|
-
if (typeof window === "undefined") {
|
|
2798
|
-
return null;
|
|
2799
|
-
}
|
|
2800
|
-
if (!useScriptElement) {
|
|
2801
|
-
const el = document.getElementById(id);
|
|
2802
|
-
if (el?.dataset.page) {
|
|
2803
|
-
return JSON.parse(el.dataset.page);
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
const scriptEl = document.querySelector(`script[data-page="${id}"][type="application/json"]`);
|
|
2807
|
-
if (scriptEl?.textContent) {
|
|
2808
|
-
return JSON.parse(scriptEl.textContent);
|
|
2809
|
-
}
|
|
2810
|
-
return null;
|
|
2811
|
-
};
|
|
2812
|
-
|
|
2813
2831
|
// src/formObject.ts
|
|
2814
2832
|
import { get as get4, set as set4 } from "lodash-es";
|
|
2815
2833
|
function undotKey(key) {
|
|
@@ -2946,7 +2964,7 @@ var Renderer = {
|
|
|
2946
2964
|
sourceElements.forEach((element) => document.head.appendChild(element));
|
|
2947
2965
|
}, 1)
|
|
2948
2966
|
};
|
|
2949
|
-
function createHeadManager(
|
|
2967
|
+
function createHeadManager(isServer3, titleCallback, onUpdate) {
|
|
2950
2968
|
const states = {};
|
|
2951
2969
|
let lastProviderId = 0;
|
|
2952
2970
|
function connect() {
|
|
@@ -2998,7 +3016,7 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2998
3016
|
return Object.values(elements);
|
|
2999
3017
|
}
|
|
3000
3018
|
function commit() {
|
|
3001
|
-
|
|
3019
|
+
isServer3 ? onUpdate(collect()) : Renderer.update(collect());
|
|
3002
3020
|
}
|
|
3003
3021
|
commit();
|
|
3004
3022
|
return {
|
|
@@ -3895,6 +3913,7 @@ function setupProgress({
|
|
|
3895
3913
|
}
|
|
3896
3914
|
|
|
3897
3915
|
// src/resetFormFields.ts
|
|
3916
|
+
var FormComponentResetSymbol = Symbol("FormComponentReset");
|
|
3898
3917
|
function isFormElement(element) {
|
|
3899
3918
|
return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
|
|
3900
3919
|
}
|
|
@@ -4025,13 +4044,16 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
4025
4044
|
}
|
|
4026
4045
|
});
|
|
4027
4046
|
if (hasChanged && resetEntireForm) {
|
|
4028
|
-
formElement.dispatchEvent(
|
|
4047
|
+
formElement.dispatchEvent(
|
|
4048
|
+
new CustomEvent("reset", { bubbles: true, cancelable: true, detail: { [FormComponentResetSymbol]: true } })
|
|
4049
|
+
);
|
|
4029
4050
|
}
|
|
4030
4051
|
}
|
|
4031
4052
|
|
|
4032
4053
|
// src/index.ts
|
|
4033
4054
|
var router = new Router();
|
|
4034
4055
|
export {
|
|
4056
|
+
FormComponentResetSymbol,
|
|
4035
4057
|
UseFormUtils,
|
|
4036
4058
|
config,
|
|
4037
4059
|
createHeadManager,
|