@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.js CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ FormComponentResetSymbol: () => FormComponentResetSymbol,
33
34
  UseFormUtils: () => UseFormUtils,
34
35
  config: () => config,
35
36
  createHeadManager: () => createHeadManager,
@@ -632,7 +633,116 @@ var PrefetchedRequests = class {
632
633
  };
633
634
  var prefetchedRequests = new PrefetchedRequests();
634
635
 
636
+ // src/domUtils.ts
637
+ var elementInViewport = (el) => {
638
+ if (el.offsetParent === null) {
639
+ return false;
640
+ }
641
+ const rect = el.getBoundingClientRect();
642
+ const verticallyVisible = rect.top < window.innerHeight && rect.bottom >= 0;
643
+ const horizontallyVisible = rect.left < window.innerWidth && rect.right >= 0;
644
+ return verticallyVisible && horizontallyVisible;
645
+ };
646
+ var getScrollableParent = (element) => {
647
+ const allowsVerticalScroll = (el) => {
648
+ const computedStyle = window.getComputedStyle(el);
649
+ if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
650
+ return true;
651
+ }
652
+ if (computedStyle.overflowY !== "auto") {
653
+ return false;
654
+ }
655
+ if (["visible", "clip"].includes(computedStyle.overflowX)) {
656
+ return true;
657
+ }
658
+ return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
659
+ };
660
+ const allowsHorizontalScroll = (el) => {
661
+ const computedStyle = window.getComputedStyle(el);
662
+ if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
663
+ return true;
664
+ }
665
+ if (computedStyle.overflowX !== "auto") {
666
+ return false;
667
+ }
668
+ if (["visible", "clip"].includes(computedStyle.overflowY)) {
669
+ return true;
670
+ }
671
+ return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
672
+ };
673
+ const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
674
+ if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
675
+ return true;
676
+ }
677
+ if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
678
+ return true;
679
+ }
680
+ return false;
681
+ };
682
+ let parent = element?.parentElement;
683
+ while (parent) {
684
+ const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
685
+ if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
686
+ return parent;
687
+ }
688
+ parent = parent.parentElement;
689
+ }
690
+ return null;
691
+ };
692
+ var getElementsInViewportFromCollection = (elements, referenceElement) => {
693
+ if (!referenceElement) {
694
+ return elements.filter((element) => elementInViewport(element));
695
+ }
696
+ const referenceIndex = elements.indexOf(referenceElement);
697
+ const upwardElements = [];
698
+ const downwardElements = [];
699
+ for (let i = referenceIndex; i >= 0; i--) {
700
+ const element = elements[i];
701
+ if (elementInViewport(element)) {
702
+ upwardElements.push(element);
703
+ } else {
704
+ break;
705
+ }
706
+ }
707
+ for (let i = referenceIndex + 1; i < elements.length; i++) {
708
+ const element = elements[i];
709
+ if (elementInViewport(element)) {
710
+ downwardElements.push(element);
711
+ } else {
712
+ break;
713
+ }
714
+ }
715
+ return [...upwardElements.reverse(), ...downwardElements];
716
+ };
717
+ var requestAnimationFrame = (cb, times = 1) => {
718
+ window.requestAnimationFrame(() => {
719
+ if (times > 1) {
720
+ requestAnimationFrame(cb, times - 1);
721
+ } else {
722
+ cb();
723
+ }
724
+ });
725
+ };
726
+ var getInitialPageFromDOM = (id, useScriptElement = false) => {
727
+ if (typeof window === "undefined") {
728
+ return null;
729
+ }
730
+ if (!useScriptElement) {
731
+ const el = document.getElementById(id);
732
+ if (el?.dataset.page) {
733
+ return JSON.parse(el.dataset.page);
734
+ }
735
+ }
736
+ const scriptEl = document.querySelector(`script[data-page="${id}"][type="application/json"]`);
737
+ if (scriptEl?.textContent) {
738
+ return JSON.parse(scriptEl.textContent);
739
+ }
740
+ return null;
741
+ };
742
+
635
743
  // src/scroll.ts
744
+ var isServer = typeof window === "undefined";
745
+ var isFirefox = !isServer && /Firefox/i.test(window.navigator.userAgent);
636
746
  var Scroll = class {
637
747
  static save() {
638
748
  history.saveScrollPositions(this.getScrollRegions());
@@ -646,10 +756,16 @@ var Scroll = class {
646
756
  static regions() {
647
757
  return document.querySelectorAll("[scroll-region]");
648
758
  }
759
+ static scrollToTop() {
760
+ if (isFirefox && getComputedStyle(document.documentElement).scrollBehavior === "smooth") {
761
+ return requestAnimationFrame(() => window.scrollTo(0, 0), 2);
762
+ }
763
+ window.scrollTo(0, 0);
764
+ }
649
765
  static reset() {
650
- const anchorHash = typeof window !== "undefined" ? window.location.hash : null;
766
+ const anchorHash = isServer ? null : window.location.hash;
651
767
  if (!anchorHash) {
652
- window.scrollTo(0, 0);
768
+ this.scrollToTop();
653
769
  }
654
770
  this.regions().forEach((region) => {
655
771
  if (typeof region.scrollTo === "function") {
@@ -663,16 +779,16 @@ var Scroll = class {
663
779
  this.scrollToAnchor();
664
780
  }
665
781
  static scrollToAnchor() {
666
- const anchorHash = typeof window !== "undefined" ? window.location.hash : null;
782
+ const anchorHash = isServer ? null : window.location.hash;
667
783
  if (anchorHash) {
668
784
  setTimeout(() => {
669
785
  const anchorElement = document.getElementById(anchorHash.slice(1));
670
- anchorElement ? anchorElement.scrollIntoView() : window.scrollTo(0, 0);
786
+ anchorElement ? anchorElement.scrollIntoView() : this.scrollToTop();
671
787
  });
672
788
  }
673
789
  }
674
790
  static restore(scrollRegions) {
675
- if (typeof window === "undefined") {
791
+ if (isServer) {
676
792
  return;
677
793
  }
678
794
  window.requestAnimationFrame(() => {
@@ -681,7 +797,7 @@ var Scroll = class {
681
797
  });
682
798
  }
683
799
  static restoreScrollRegions(scrollRegions) {
684
- if (typeof window === "undefined") {
800
+ if (isServer) {
685
801
  return;
686
802
  }
687
803
  this.regions().forEach((region, index) => {
@@ -888,9 +1004,9 @@ var CurrentPage = class {
888
1004
  return;
889
1005
  }
890
1006
  page2.rememberedState ?? (page2.rememberedState = {});
891
- const isServer2 = typeof window === "undefined";
892
- const location = !isServer2 ? window.location : new URL(page2.url);
893
- const scrollRegions = !isServer2 && preserveScroll ? Scroll.getScrollRegions() : [];
1007
+ const isServer3 = typeof window === "undefined";
1008
+ const location = !isServer3 ? window.location : new URL(page2.url);
1009
+ const scrollRegions = !isServer3 && preserveScroll ? Scroll.getScrollRegions() : [];
894
1010
  replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
895
1011
  const pageForHistory = { ...page2, flash: {} };
896
1012
  return new Promise(
@@ -1050,9 +1166,9 @@ var Queue = class {
1050
1166
  };
1051
1167
 
1052
1168
  // src/history.ts
1053
- var isServer = typeof window === "undefined";
1169
+ var isServer2 = typeof window === "undefined";
1054
1170
  var queue = new Queue();
1055
- var isChromeIOS = !isServer && /CriOS/.test(window.navigator.userAgent);
1171
+ var isChromeIOS = !isServer2 && /CriOS/.test(window.navigator.userAgent);
1056
1172
  var History = class {
1057
1173
  constructor() {
1058
1174
  this.rememberedState = "rememberedState";
@@ -1072,12 +1188,12 @@ var History = class {
1072
1188
  });
1073
1189
  }
1074
1190
  restore(key) {
1075
- if (!isServer) {
1191
+ if (!isServer2) {
1076
1192
  return this.current[this.rememberedState]?.[key] !== void 0 ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
1077
1193
  }
1078
1194
  }
1079
1195
  pushState(page2, cb = null) {
1080
- if (isServer) {
1196
+ if (isServer2) {
1081
1197
  return;
1082
1198
  }
1083
1199
  if (this.preserveUrl) {
@@ -1118,7 +1234,7 @@ var History = class {
1118
1234
  return queue.process();
1119
1235
  }
1120
1236
  decrypt(page2 = null) {
1121
- if (isServer) {
1237
+ if (isServer2) {
1122
1238
  return Promise.resolve(page2 ?? page.get());
1123
1239
  }
1124
1240
  const pageData = page2 ?? window.history.state?.page;
@@ -1181,7 +1297,7 @@ var History = class {
1181
1297
  return;
1182
1298
  }
1183
1299
  page.merge(page2);
1184
- if (isServer) {
1300
+ if (isServer2) {
1185
1301
  return;
1186
1302
  }
1187
1303
  if (this.preserveUrl) {
@@ -1259,7 +1375,7 @@ var History = class {
1259
1375
  }
1260
1376
  }
1261
1377
  browserHasHistoryEntry() {
1262
- return !isServer && !!window.history.state?.page;
1378
+ return !isServer2 && !!window.history.state?.page;
1263
1379
  }
1264
1380
  clear() {
1265
1381
  SessionStorage.remove(historySessionStorageKeys.key);
@@ -1856,7 +1972,10 @@ var Response = class _Response {
1856
1972
  }
1857
1973
  getPageResponse() {
1858
1974
  const data = this.getDataFromResponse(this.response.data);
1859
- return this.response.data = { ...data, flash: data.flash ?? {} };
1975
+ if (typeof data === "object") {
1976
+ return this.response.data = { ...data, flash: data.flash ?? {} };
1977
+ }
1978
+ return this.response.data = data;
1860
1979
  }
1861
1980
  async handleNonInertiaResponse() {
1862
1981
  if (this.isLocationVisit()) {
@@ -2342,9 +2461,13 @@ var Router = class {
2342
2461
  cancel() {
2343
2462
  this.syncRequestStream.cancelInFlight();
2344
2463
  }
2345
- cancelAll({ prefetch = true } = {}) {
2346
- this.asyncRequestStream.cancelInFlight({ prefetch });
2347
- this.syncRequestStream.cancelInFlight();
2464
+ cancelAll({ async = true, prefetch = true, sync = true } = {}) {
2465
+ if (async) {
2466
+ this.asyncRequestStream.cancelInFlight({ prefetch });
2467
+ }
2468
+ if (sync) {
2469
+ this.syncRequestStream.cancelInFlight();
2470
+ }
2348
2471
  }
2349
2472
  poll(interval, requestOptions = {}, options = {}) {
2350
2473
  return polls.add(interval, () => this.reload(requestOptions), {
@@ -2526,7 +2649,10 @@ var Router = class {
2526
2649
  }
2527
2650
  performClientVisit(params, { replace = false } = {}) {
2528
2651
  const current = page.get();
2529
- const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
2652
+ const onceProps = typeof params.props === "function" ? Object.fromEntries(
2653
+ Object.values(current.onceProps ?? {}).map((onceProp) => [onceProp.prop, current.props[onceProp.prop]])
2654
+ ) : {};
2655
+ const props = typeof params.props === "function" ? params.props(current.props, onceProps) : params.props ?? current.props;
2530
2656
  const flash = typeof params.flash === "function" ? params.flash(current.flash) : params.flash;
2531
2657
  const { viewTransition, onError, onFinish, onFlash, onSuccess, ...pageParams } = params;
2532
2658
  const page2 = {
@@ -2760,113 +2886,6 @@ var UseFormUtils = class {
2760
2886
  }
2761
2887
  };
2762
2888
 
2763
- // src/domUtils.ts
2764
- var elementInViewport = (el) => {
2765
- if (el.offsetParent === null) {
2766
- return false;
2767
- }
2768
- const rect = el.getBoundingClientRect();
2769
- const verticallyVisible = rect.top < window.innerHeight && rect.bottom >= 0;
2770
- const horizontallyVisible = rect.left < window.innerWidth && rect.right >= 0;
2771
- return verticallyVisible && horizontallyVisible;
2772
- };
2773
- var getScrollableParent = (element) => {
2774
- const allowsVerticalScroll = (el) => {
2775
- const computedStyle = window.getComputedStyle(el);
2776
- if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
2777
- return true;
2778
- }
2779
- if (computedStyle.overflowY !== "auto") {
2780
- return false;
2781
- }
2782
- if (["visible", "clip"].includes(computedStyle.overflowX)) {
2783
- return true;
2784
- }
2785
- return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
2786
- };
2787
- const allowsHorizontalScroll = (el) => {
2788
- const computedStyle = window.getComputedStyle(el);
2789
- if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
2790
- return true;
2791
- }
2792
- if (computedStyle.overflowX !== "auto") {
2793
- return false;
2794
- }
2795
- if (["visible", "clip"].includes(computedStyle.overflowY)) {
2796
- return true;
2797
- }
2798
- return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
2799
- };
2800
- const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
2801
- if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
2802
- return true;
2803
- }
2804
- if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
2805
- return true;
2806
- }
2807
- return false;
2808
- };
2809
- let parent = element?.parentElement;
2810
- while (parent) {
2811
- const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
2812
- if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
2813
- return parent;
2814
- }
2815
- parent = parent.parentElement;
2816
- }
2817
- return null;
2818
- };
2819
- var getElementsInViewportFromCollection = (elements, referenceElement) => {
2820
- if (!referenceElement) {
2821
- return elements.filter((element) => elementInViewport(element));
2822
- }
2823
- const referenceIndex = elements.indexOf(referenceElement);
2824
- const upwardElements = [];
2825
- const downwardElements = [];
2826
- for (let i = referenceIndex; i >= 0; i--) {
2827
- const element = elements[i];
2828
- if (elementInViewport(element)) {
2829
- upwardElements.push(element);
2830
- } else {
2831
- break;
2832
- }
2833
- }
2834
- for (let i = referenceIndex + 1; i < elements.length; i++) {
2835
- const element = elements[i];
2836
- if (elementInViewport(element)) {
2837
- downwardElements.push(element);
2838
- } else {
2839
- break;
2840
- }
2841
- }
2842
- return [...upwardElements.reverse(), ...downwardElements];
2843
- };
2844
- var requestAnimationFrame = (cb, times = 1) => {
2845
- window.requestAnimationFrame(() => {
2846
- if (times > 1) {
2847
- requestAnimationFrame(cb, times - 1);
2848
- } else {
2849
- cb();
2850
- }
2851
- });
2852
- };
2853
- var getInitialPageFromDOM = (id, useScriptElement = false) => {
2854
- if (typeof window === "undefined") {
2855
- return null;
2856
- }
2857
- if (!useScriptElement) {
2858
- const el = document.getElementById(id);
2859
- if (el?.dataset.page) {
2860
- return JSON.parse(el.dataset.page);
2861
- }
2862
- }
2863
- const scriptEl = document.querySelector(`script[data-page="${id}"][type="application/json"]`);
2864
- if (scriptEl?.textContent) {
2865
- return JSON.parse(scriptEl.textContent);
2866
- }
2867
- return null;
2868
- };
2869
-
2870
2889
  // src/formObject.ts
2871
2890
  var import_lodash_es6 = require("lodash-es");
2872
2891
  function undotKey(key) {
@@ -3003,7 +3022,7 @@ var Renderer = {
3003
3022
  sourceElements.forEach((element) => document.head.appendChild(element));
3004
3023
  }, 1)
3005
3024
  };
3006
- function createHeadManager(isServer2, titleCallback, onUpdate) {
3025
+ function createHeadManager(isServer3, titleCallback, onUpdate) {
3007
3026
  const states = {};
3008
3027
  let lastProviderId = 0;
3009
3028
  function connect() {
@@ -3055,7 +3074,7 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
3055
3074
  return Object.values(elements);
3056
3075
  }
3057
3076
  function commit() {
3058
- isServer2 ? onUpdate(collect()) : Renderer.update(collect());
3077
+ isServer3 ? onUpdate(collect()) : Renderer.update(collect());
3059
3078
  }
3060
3079
  commit();
3061
3080
  return {
@@ -3952,6 +3971,7 @@ function setupProgress({
3952
3971
  }
3953
3972
 
3954
3973
  // src/resetFormFields.ts
3974
+ var FormComponentResetSymbol = Symbol("FormComponentReset");
3955
3975
  function isFormElement(element) {
3956
3976
  return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
3957
3977
  }
@@ -4082,7 +4102,9 @@ function resetFormFields(formElement, defaults, fieldNames) {
4082
4102
  }
4083
4103
  });
4084
4104
  if (hasChanged && resetEntireForm) {
4085
- formElement.dispatchEvent(new Event("reset", { bubbles: true }));
4105
+ formElement.dispatchEvent(
4106
+ new CustomEvent("reset", { bubbles: true, cancelable: true, detail: { [FormComponentResetSymbol]: true } })
4107
+ );
4086
4108
  }
4087
4109
  }
4088
4110