@inertiajs/core 2.2.7 → 2.2.8

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
@@ -53,7 +53,7 @@ __export(index_exports, {
53
53
  module.exports = __toCommonJS(index_exports);
54
54
 
55
55
  // src/router.ts
56
- var import_lodash_es3 = require("lodash-es");
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.regions().forEach((region, index) => {
318
- const scrollPosition = scrollRegions[index];
319
- if (!scrollPosition) {
320
- return;
321
- }
322
- if (typeof region.scrollTo === "function") {
323
- region.scrollTo(scrollPosition.left, scrollPosition.top);
324
- } else {
325
- region.scrollTop = scrollPosition.top;
326
- region.scrollLeft = scrollPosition.left;
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() {
@@ -495,7 +504,9 @@ var CurrentPage = class {
495
504
  return;
496
505
  }
497
506
  page2.rememberedState ?? (page2.rememberedState = {});
498
- const location = typeof window !== "undefined" ? window.location : new URL(page2.url);
507
+ const isServer2 = typeof window === "undefined";
508
+ const location = !isServer2 ? window.location : new URL(page2.url);
509
+ const scrollRegions = !isServer2 && preserveScroll ? history.getScrollRegions() : [];
499
510
  replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
500
511
  return new Promise((resolve) => {
501
512
  replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
@@ -511,7 +522,9 @@ var CurrentPage = class {
511
522
  }
512
523
  this.isFirstPageLoad = false;
513
524
  return this.swap({ component, page: page2, preserveState }).then(() => {
514
- if (!preserveScroll) {
525
+ if (preserveScroll) {
526
+ window.requestAnimationFrame(() => Scroll.restoreScrollRegions(scrollRegions));
527
+ } else {
515
528
  Scroll.reset();
516
529
  }
517
530
  if (this.pendingDeferredProps && this.pendingDeferredProps.component === page2.component && this.pendingDeferredProps.url === page2.url) {
@@ -687,6 +700,9 @@ var History = class {
687
700
  if (!window.history.state?.page) {
688
701
  return;
689
702
  }
703
+ if ((0, import_lodash_es.isEqual)(this.getScrollRegions(), scrollRegions)) {
704
+ return;
705
+ }
690
706
  return this.doReplaceState({
691
707
  page: window.history.state.page,
692
708
  scrollRegions
@@ -700,6 +716,9 @@ var History = class {
700
716
  if (!window.history.state?.page) {
701
717
  return;
702
718
  }
719
+ if ((0, import_lodash_es.isEqual)(this.getDocumentScrollPosition(), scrollRegion)) {
720
+ return;
721
+ }
703
722
  return this.doReplaceState({
704
723
  page: window.history.state.page,
705
724
  documentScrollPosition: scrollRegion
@@ -1028,7 +1047,7 @@ var Polls = class {
1028
1047
  var polls = new Polls();
1029
1048
 
1030
1049
  // src/prefetched.ts
1031
- var import_lodash_es = require("lodash-es");
1050
+ var import_lodash_es2 = require("lodash-es");
1032
1051
 
1033
1052
  // src/objectUtils.ts
1034
1053
  var objectsAreEqual = (obj1, obj2, excludeKeys) => {
@@ -1245,7 +1264,7 @@ var PrefetchedRequests = class {
1245
1264
  }) || null;
1246
1265
  }
1247
1266
  withoutPurposePrefetchHeader(params) {
1248
- const newParams = (0, import_lodash_es.cloneDeep)(params);
1267
+ const newParams = (0, import_lodash_es2.cloneDeep)(params);
1249
1268
  if (newParams.headers["Purpose"] === "prefetch") {
1250
1269
  delete newParams.headers["Purpose"];
1251
1270
  }
@@ -1421,7 +1440,7 @@ var RequestParams = class _RequestParams {
1421
1440
  };
1422
1441
 
1423
1442
  // src/response.ts
1424
- var import_lodash_es2 = require("lodash-es");
1443
+ var import_lodash_es3 = require("lodash-es");
1425
1444
 
1426
1445
  // src/modal.ts
1427
1446
  var modal_default = {
@@ -1631,8 +1650,8 @@ var Response = class _Response {
1631
1650
  const propsToDeepMerge = pageResponse.deepMergeProps || [];
1632
1651
  const matchPropsOn = pageResponse.matchPropsOn || [];
1633
1652
  const mergeProp = (prop, shouldAppend) => {
1634
- const currentProp = (0, import_lodash_es2.get)(page.get().props, prop);
1635
- const incomingProp = (0, import_lodash_es2.get)(pageResponse.props, prop);
1653
+ const currentProp = (0, import_lodash_es3.get)(page.get().props, prop);
1654
+ const incomingProp = (0, import_lodash_es3.get)(pageResponse.props, prop);
1636
1655
  if (Array.isArray(incomingProp)) {
1637
1656
  const newArray = this.mergeOrMatchItems(
1638
1657
  currentProp || [],
@@ -1641,13 +1660,13 @@ var Response = class _Response {
1641
1660
  matchPropsOn,
1642
1661
  shouldAppend
1643
1662
  );
1644
- (0, import_lodash_es2.set)(pageResponse.props, prop, newArray);
1663
+ (0, import_lodash_es3.set)(pageResponse.props, prop, newArray);
1645
1664
  } else if (typeof incomingProp === "object" && incomingProp !== null) {
1646
1665
  const newObject = {
1647
1666
  ...currentProp || {},
1648
1667
  ...incomingProp
1649
1668
  };
1650
- (0, import_lodash_es2.set)(pageResponse.props, prop, newObject);
1669
+ (0, import_lodash_es3.set)(pageResponse.props, prop, newObject);
1651
1670
  }
1652
1671
  };
1653
1672
  propsToAppend.forEach((prop) => mergeProp(prop, true));
@@ -2072,8 +2091,8 @@ var Router = class {
2072
2091
  preserveScroll: true,
2073
2092
  preserveState: true,
2074
2093
  props(currentProps) {
2075
- const newValue = typeof value === "function" ? value((0, import_lodash_es3.get)(currentProps, name), currentProps) : value;
2076
- return (0, import_lodash_es3.set)((0, import_lodash_es3.cloneDeep)(currentProps), name, newValue);
2094
+ const newValue = typeof value === "function" ? value((0, import_lodash_es4.get)(currentProps, name), currentProps) : value;
2095
+ return (0, import_lodash_es4.set)((0, import_lodash_es4.cloneDeep)(currentProps), name, newValue);
2077
2096
  },
2078
2097
  ...options || {}
2079
2098
  });
@@ -2233,10 +2252,45 @@ var elementInViewport = (el) => {
2233
2252
  return verticallyVisible && horizontallyVisible;
2234
2253
  };
2235
2254
  var getScrollableParent = (element) => {
2255
+ const allowsVerticalScroll = (el) => {
2256
+ const computedStyle = window.getComputedStyle(el);
2257
+ if (["scroll", "overlay"].includes(computedStyle.overflowY)) {
2258
+ return true;
2259
+ }
2260
+ if (computedStyle.overflowY !== "auto") {
2261
+ return false;
2262
+ }
2263
+ if (["visible", "clip"].includes(computedStyle.overflowX)) {
2264
+ return true;
2265
+ }
2266
+ return hasDimensionConstraint(computedStyle.maxHeight, el.style.height);
2267
+ };
2268
+ const allowsHorizontalScroll = (el) => {
2269
+ const computedStyle = window.getComputedStyle(el);
2270
+ if (["scroll", "overlay"].includes(computedStyle.overflowX)) {
2271
+ return true;
2272
+ }
2273
+ if (computedStyle.overflowX !== "auto") {
2274
+ return false;
2275
+ }
2276
+ if (["visible", "clip"].includes(computedStyle.overflowY)) {
2277
+ return true;
2278
+ }
2279
+ return hasDimensionConstraint(computedStyle.maxWidth, el.style.width);
2280
+ };
2281
+ const hasDimensionConstraint = (computedMaxDimension, inlineStyleDimension) => {
2282
+ if (computedMaxDimension && computedMaxDimension !== "none" && computedMaxDimension !== "0px") {
2283
+ return true;
2284
+ }
2285
+ if (inlineStyleDimension && inlineStyleDimension !== "auto" && inlineStyleDimension !== "0") {
2286
+ return true;
2287
+ }
2288
+ return false;
2289
+ };
2236
2290
  let parent = element?.parentElement;
2237
2291
  while (parent) {
2238
- const overflowY = window.getComputedStyle(parent).overflowY;
2239
- if (overflowY === "auto" || overflowY === "scroll") {
2292
+ const allowsScroll = allowsVerticalScroll(parent) || allowsHorizontalScroll(parent);
2293
+ if (window.getComputedStyle(parent).display !== "contents" && allowsScroll) {
2240
2294
  return parent;
2241
2295
  }
2242
2296
  parent = parent.parentElement;
@@ -2267,7 +2321,7 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
2267
2321
  };
2268
2322
 
2269
2323
  // src/formObject.ts
2270
- var import_lodash_es4 = require("lodash-es");
2324
+ var import_lodash_es5 = require("lodash-es");
2271
2325
  function undotKey(key) {
2272
2326
  if (!key.includes(".")) {
2273
2327
  return key;
@@ -2302,15 +2356,15 @@ function formDataToObject(source) {
2302
2356
  const path = parseKey(undotKey(key));
2303
2357
  if (path[path.length - 1] === "") {
2304
2358
  const arrayPath = path.slice(0, -1);
2305
- const existing = (0, import_lodash_es4.get)(form, arrayPath);
2359
+ const existing = (0, import_lodash_es5.get)(form, arrayPath);
2306
2360
  if (Array.isArray(existing)) {
2307
2361
  existing.push(value);
2308
2362
  } else {
2309
- (0, import_lodash_es4.set)(form, arrayPath, [value]);
2363
+ (0, import_lodash_es5.set)(form, arrayPath, [value]);
2310
2364
  }
2311
2365
  continue;
2312
2366
  }
2313
- (0, import_lodash_es4.set)(form, path, value);
2367
+ (0, import_lodash_es5.set)(form, path, value);
2314
2368
  }
2315
2369
  return form;
2316
2370
  }