@inertiajs/core 2.2.9 → 2.2.11

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
+ config: () => config,
33
34
  createHeadManager: () => createHeadManager,
34
35
  formDataToObject: () => formDataToObject,
35
36
  getScrollableParent: () => getScrollableParent,
@@ -53,7 +54,48 @@ __export(index_exports, {
53
54
  module.exports = __toCommonJS(index_exports);
54
55
 
55
56
  // src/router.ts
56
- var import_lodash_es4 = require("lodash-es");
57
+ var import_lodash_es5 = require("lodash-es");
58
+
59
+ // src/config.ts
60
+ var import_lodash_es = require("lodash-es");
61
+ var Config = class {
62
+ constructor(defaults) {
63
+ this.config = {};
64
+ this.defaults = defaults;
65
+ }
66
+ extend(defaults) {
67
+ if (defaults) {
68
+ this.defaults = { ...this.defaults, ...defaults };
69
+ }
70
+ return this;
71
+ }
72
+ replace(newConfig) {
73
+ this.config = newConfig;
74
+ }
75
+ get(key) {
76
+ return (0, import_lodash_es.has)(this.config, key) ? (0, import_lodash_es.get)(this.config, key) : (0, import_lodash_es.get)(this.defaults, key);
77
+ }
78
+ set(keyOrValues, value) {
79
+ if (typeof keyOrValues === "string") {
80
+ (0, import_lodash_es.set)(this.config, keyOrValues, value);
81
+ } else {
82
+ Object.entries(keyOrValues).forEach(([key, val]) => {
83
+ (0, import_lodash_es.set)(this.config, key, val);
84
+ });
85
+ }
86
+ }
87
+ };
88
+ var config = new Config({
89
+ form: {
90
+ recentlySuccessfulDuration: 2e3
91
+ },
92
+ future: {
93
+ preserveEqualProps: false
94
+ },
95
+ prefetch: {
96
+ cacheFor: 3e4
97
+ }
98
+ });
57
99
 
58
100
  // src/debounce.ts
59
101
  function debounce(fn, delay) {
@@ -106,7 +148,7 @@ var firePrefetchingEvent = (visit) => {
106
148
  };
107
149
 
108
150
  // src/history.ts
109
- var import_lodash_es = require("lodash-es");
151
+ var import_lodash_es2 = require("lodash-es");
110
152
 
111
153
  // src/sessionStorage.ts
112
154
  var SessionStorage = class {
@@ -704,7 +746,7 @@ var History = class {
704
746
  if (!window.history.state?.page) {
705
747
  return;
706
748
  }
707
- if ((0, import_lodash_es.isEqual)(this.getScrollRegions(), scrollRegions)) {
749
+ if ((0, import_lodash_es2.isEqual)(this.getScrollRegions(), scrollRegions)) {
708
750
  return;
709
751
  }
710
752
  return this.doReplaceState({
@@ -720,7 +762,7 @@ var History = class {
720
762
  if (!window.history.state?.page) {
721
763
  return;
722
764
  }
723
- if ((0, import_lodash_es.isEqual)(this.getDocumentScrollPosition(), scrollRegion)) {
765
+ if ((0, import_lodash_es2.isEqual)(this.getDocumentScrollPosition(), scrollRegion)) {
724
766
  return;
725
767
  }
726
768
  return this.doReplaceState({
@@ -1051,7 +1093,7 @@ var Polls = class {
1051
1093
  var polls = new Polls();
1052
1094
 
1053
1095
  // src/prefetched.ts
1054
- var import_lodash_es2 = require("lodash-es");
1096
+ var import_lodash_es3 = require("lodash-es");
1055
1097
 
1056
1098
  // src/objectUtils.ts
1057
1099
  var objectsAreEqual = (obj1, obj2, excludeKeys) => {
@@ -1268,7 +1310,7 @@ var PrefetchedRequests = class {
1268
1310
  }) || null;
1269
1311
  }
1270
1312
  withoutPurposePrefetchHeader(params) {
1271
- const newParams = (0, import_lodash_es2.cloneDeep)(params);
1313
+ const newParams = (0, import_lodash_es3.cloneDeep)(params);
1272
1314
  if (newParams.headers["Purpose"] === "prefetch") {
1273
1315
  delete newParams.headers["Purpose"];
1274
1316
  }
@@ -1444,7 +1486,7 @@ var RequestParams = class _RequestParams {
1444
1486
  };
1445
1487
 
1446
1488
  // src/response.ts
1447
- var import_lodash_es3 = require("lodash-es");
1489
+ var import_lodash_es4 = require("lodash-es");
1448
1490
 
1449
1491
  // src/modal.ts
1450
1492
  var modal_default = {
@@ -1605,6 +1647,7 @@ var Response = class _Response {
1605
1647
  return Promise.resolve();
1606
1648
  }
1607
1649
  this.mergeProps(pageResponse);
1650
+ this.preserveEqualProps(pageResponse);
1608
1651
  await this.setRememberedState(pageResponse);
1609
1652
  this.requestParams.setPreserveOptions(pageResponse);
1610
1653
  pageResponse.url = history.preserveUrl ? page.get().url : this.pageUrl(pageResponse);
@@ -1645,6 +1688,17 @@ var Response = class _Response {
1645
1688
  setHashIfSameUrl(this.requestParams.all().url, responseUrl);
1646
1689
  return responseUrl.pathname + responseUrl.search + responseUrl.hash;
1647
1690
  }
1691
+ preserveEqualProps(pageResponse) {
1692
+ if (pageResponse.component !== page.get().component || config.get("future.preserveEqualProps") !== true) {
1693
+ return;
1694
+ }
1695
+ const currentPageProps = page.get().props;
1696
+ Object.entries(pageResponse.props).forEach(([key, value]) => {
1697
+ if ((0, import_lodash_es4.isEqual)(value, currentPageProps[key])) {
1698
+ pageResponse.props[key] = currentPageProps[key];
1699
+ }
1700
+ });
1701
+ }
1648
1702
  mergeProps(pageResponse) {
1649
1703
  if (!this.requestParams.isPartial() || pageResponse.component !== page.get().component) {
1650
1704
  return;
@@ -1654,8 +1708,8 @@ var Response = class _Response {
1654
1708
  const propsToDeepMerge = pageResponse.deepMergeProps || [];
1655
1709
  const matchPropsOn = pageResponse.matchPropsOn || [];
1656
1710
  const mergeProp = (prop, shouldAppend) => {
1657
- const currentProp = (0, import_lodash_es3.get)(page.get().props, prop);
1658
- const incomingProp = (0, import_lodash_es3.get)(pageResponse.props, prop);
1711
+ const currentProp = (0, import_lodash_es4.get)(page.get().props, prop);
1712
+ const incomingProp = (0, import_lodash_es4.get)(pageResponse.props, prop);
1659
1713
  if (Array.isArray(incomingProp)) {
1660
1714
  const newArray = this.mergeOrMatchItems(
1661
1715
  currentProp || [],
@@ -1664,13 +1718,13 @@ var Response = class _Response {
1664
1718
  matchPropsOn,
1665
1719
  shouldAppend
1666
1720
  );
1667
- (0, import_lodash_es3.set)(pageResponse.props, prop, newArray);
1721
+ (0, import_lodash_es4.set)(pageResponse.props, prop, newArray);
1668
1722
  } else if (typeof incomingProp === "object" && incomingProp !== null) {
1669
1723
  const newObject = {
1670
1724
  ...currentProp || {},
1671
1725
  ...incomingProp
1672
1726
  };
1673
- (0, import_lodash_es3.set)(pageResponse.props, prop, newObject);
1727
+ (0, import_lodash_es4.set)(pageResponse.props, prop, newObject);
1674
1728
  }
1675
1729
  };
1676
1730
  propsToAppend.forEach((prop) => mergeProp(prop, true));
@@ -2075,7 +2129,7 @@ var Router = class {
2075
2129
  this.asyncRequestStream.send(Request.create(params, page.get()));
2076
2130
  },
2077
2131
  {
2078
- cacheFor: 3e4,
2132
+ cacheFor: config.get("prefetch.cacheFor"),
2079
2133
  cacheTags: [],
2080
2134
  ...prefetchOptions
2081
2135
  }
@@ -2099,8 +2153,8 @@ var Router = class {
2099
2153
  preserveScroll: true,
2100
2154
  preserveState: true,
2101
2155
  props(currentProps) {
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);
2156
+ const newValue = typeof value === "function" ? value((0, import_lodash_es5.get)(currentProps, name), currentProps) : value;
2157
+ return (0, import_lodash_es5.set)((0, import_lodash_es5.cloneDeep)(currentProps), name, newValue);
2104
2158
  },
2105
2159
  ...options || {}
2106
2160
  });
@@ -2175,6 +2229,8 @@ var Router = class {
2175
2229
  href = urlMethodPair.url;
2176
2230
  options.method = options.method ?? urlMethodPair.method;
2177
2231
  }
2232
+ const defaultVisitOptionsCallback = config.get("visitOptions");
2233
+ const configuredOptions = defaultVisitOptionsCallback ? defaultVisitOptionsCallback(href.toString(), (0, import_lodash_es5.cloneDeep)(options)) || {} : {};
2178
2234
  const mergedOptions = {
2179
2235
  method: "get",
2180
2236
  data: {},
@@ -2194,7 +2250,8 @@ var Router = class {
2194
2250
  preserveUrl: false,
2195
2251
  prefetch: false,
2196
2252
  invalidateCacheTags: [],
2197
- ...options
2253
+ ...options,
2254
+ ...configuredOptions
2198
2255
  };
2199
2256
  const [url, _data] = transformUrlAndData(
2200
2257
  href,
@@ -2329,7 +2386,7 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
2329
2386
  };
2330
2387
 
2331
2388
  // src/formObject.ts
2332
- var import_lodash_es5 = require("lodash-es");
2389
+ var import_lodash_es6 = require("lodash-es");
2333
2390
  function undotKey(key) {
2334
2391
  if (!key.includes(".")) {
2335
2392
  return key;
@@ -2364,15 +2421,15 @@ function formDataToObject(source) {
2364
2421
  const path = parseKey(undotKey(key));
2365
2422
  if (path[path.length - 1] === "") {
2366
2423
  const arrayPath = path.slice(0, -1);
2367
- const existing = (0, import_lodash_es5.get)(form, arrayPath);
2424
+ const existing = (0, import_lodash_es6.get)(form, arrayPath);
2368
2425
  if (Array.isArray(existing)) {
2369
2426
  existing.push(value);
2370
2427
  } else {
2371
- (0, import_lodash_es5.set)(form, arrayPath, [value]);
2428
+ (0, import_lodash_es6.set)(form, arrayPath, [value]);
2372
2429
  }
2373
2430
  continue;
2374
2431
  }
2375
- (0, import_lodash_es5.set)(form, path, value);
2432
+ (0, import_lodash_es6.set)(form, path, value);
2376
2433
  }
2377
2434
  return form;
2378
2435
  }
@@ -3046,7 +3103,7 @@ var configure = (options) => {
3046
3103
  progress2.id = baseComponentSelector;
3047
3104
  progress2.innerHTML = settings.template;
3048
3105
  };
3049
- var set4 = (n) => {
3106
+ var set5 = (n) => {
3050
3107
  const started = isStarted();
3051
3108
  n = clamp(n, settings.minimum, 1);
3052
3109
  status = n === 1 ? null : n;
@@ -3095,7 +3152,7 @@ var set4 = (n) => {
3095
3152
  var isStarted = () => typeof status === "number";
3096
3153
  var start = () => {
3097
3154
  if (!status) {
3098
- set4(0);
3155
+ set5(0);
3099
3156
  }
3100
3157
  const work = function() {
3101
3158
  setTimeout(function() {
@@ -3115,7 +3172,7 @@ var done = (force) => {
3115
3172
  return;
3116
3173
  }
3117
3174
  increaseByRandom(0.3 + 0.5 * Math.random());
3118
- set4(1);
3175
+ set5(1);
3119
3176
  };
3120
3177
  var increaseByRandom = (amount) => {
3121
3178
  const n = status;
@@ -3139,7 +3196,7 @@ var increaseByRandom = (amount) => {
3139
3196
  }
3140
3197
  return 0;
3141
3198
  })();
3142
- return set4(clamp(n + amount, 0, 0.994));
3199
+ return set5(clamp(n + amount, 0, 0.994));
3143
3200
  };
3144
3201
  var render = (fromStart) => {
3145
3202
  if (isRendered()) {
@@ -3285,7 +3342,7 @@ var progress_component_default = {
3285
3342
  configure,
3286
3343
  isStarted,
3287
3344
  done,
3288
- set: set4,
3345
+ set: set5,
3289
3346
  remove,
3290
3347
  start,
3291
3348
  status,