@inertiajs/core 2.2.10 → 2.2.12
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 +92 -23
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +94 -25
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/config.d.ts +19 -0
- package/types/history.d.ts +1 -0
- package/types/index.d.ts +3 -1
- package/types/response.d.ts +1 -0
- package/types/time.d.ts +2 -1
- package/types/types.d.ts +18 -4
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
|
|
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
|
|
151
|
+
var import_lodash_es2 = require("lodash-es");
|
|
110
152
|
|
|
111
153
|
// src/sessionStorage.ts
|
|
112
154
|
var SessionStorage = class {
|
|
@@ -670,9 +712,21 @@ var History = class {
|
|
|
670
712
|
});
|
|
671
713
|
});
|
|
672
714
|
}
|
|
715
|
+
clonePageProps(page2) {
|
|
716
|
+
try {
|
|
717
|
+
structuredClone(page2.props);
|
|
718
|
+
return page2;
|
|
719
|
+
} catch {
|
|
720
|
+
return {
|
|
721
|
+
...page2,
|
|
722
|
+
props: (0, import_lodash_es2.cloneDeep)(page2.props)
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
}
|
|
673
726
|
getPageData(page2) {
|
|
727
|
+
const pageWithClonedProps = this.clonePageProps(page2);
|
|
674
728
|
return new Promise((resolve) => {
|
|
675
|
-
return page2.encryptHistory ? encryptHistory(
|
|
729
|
+
return page2.encryptHistory ? encryptHistory(pageWithClonedProps).then(resolve) : resolve(pageWithClonedProps);
|
|
676
730
|
});
|
|
677
731
|
}
|
|
678
732
|
processQueue() {
|
|
@@ -704,7 +758,7 @@ var History = class {
|
|
|
704
758
|
if (!window.history.state?.page) {
|
|
705
759
|
return;
|
|
706
760
|
}
|
|
707
|
-
if ((0,
|
|
761
|
+
if ((0, import_lodash_es2.isEqual)(this.getScrollRegions(), scrollRegions)) {
|
|
708
762
|
return;
|
|
709
763
|
}
|
|
710
764
|
return this.doReplaceState({
|
|
@@ -720,7 +774,7 @@ var History = class {
|
|
|
720
774
|
if (!window.history.state?.page) {
|
|
721
775
|
return;
|
|
722
776
|
}
|
|
723
|
-
if ((0,
|
|
777
|
+
if ((0, import_lodash_es2.isEqual)(this.getDocumentScrollPosition(), scrollRegion)) {
|
|
724
778
|
return;
|
|
725
779
|
}
|
|
726
780
|
return this.doReplaceState({
|
|
@@ -1051,7 +1105,7 @@ var Polls = class {
|
|
|
1051
1105
|
var polls = new Polls();
|
|
1052
1106
|
|
|
1053
1107
|
// src/prefetched.ts
|
|
1054
|
-
var
|
|
1108
|
+
var import_lodash_es3 = require("lodash-es");
|
|
1055
1109
|
|
|
1056
1110
|
// src/objectUtils.ts
|
|
1057
1111
|
var objectsAreEqual = (obj1, obj2, excludeKeys) => {
|
|
@@ -1268,7 +1322,7 @@ var PrefetchedRequests = class {
|
|
|
1268
1322
|
}) || null;
|
|
1269
1323
|
}
|
|
1270
1324
|
withoutPurposePrefetchHeader(params) {
|
|
1271
|
-
const newParams = (0,
|
|
1325
|
+
const newParams = (0, import_lodash_es3.cloneDeep)(params);
|
|
1272
1326
|
if (newParams.headers["Purpose"] === "prefetch") {
|
|
1273
1327
|
delete newParams.headers["Purpose"];
|
|
1274
1328
|
}
|
|
@@ -1444,7 +1498,7 @@ var RequestParams = class _RequestParams {
|
|
|
1444
1498
|
};
|
|
1445
1499
|
|
|
1446
1500
|
// src/response.ts
|
|
1447
|
-
var
|
|
1501
|
+
var import_lodash_es4 = require("lodash-es");
|
|
1448
1502
|
|
|
1449
1503
|
// src/modal.ts
|
|
1450
1504
|
var modal_default = {
|
|
@@ -1605,6 +1659,7 @@ var Response = class _Response {
|
|
|
1605
1659
|
return Promise.resolve();
|
|
1606
1660
|
}
|
|
1607
1661
|
this.mergeProps(pageResponse);
|
|
1662
|
+
this.preserveEqualProps(pageResponse);
|
|
1608
1663
|
await this.setRememberedState(pageResponse);
|
|
1609
1664
|
this.requestParams.setPreserveOptions(pageResponse);
|
|
1610
1665
|
pageResponse.url = history.preserveUrl ? page.get().url : this.pageUrl(pageResponse);
|
|
@@ -1645,6 +1700,17 @@ var Response = class _Response {
|
|
|
1645
1700
|
setHashIfSameUrl(this.requestParams.all().url, responseUrl);
|
|
1646
1701
|
return responseUrl.pathname + responseUrl.search + responseUrl.hash;
|
|
1647
1702
|
}
|
|
1703
|
+
preserveEqualProps(pageResponse) {
|
|
1704
|
+
if (pageResponse.component !== page.get().component || config.get("future.preserveEqualProps") !== true) {
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
const currentPageProps = page.get().props;
|
|
1708
|
+
Object.entries(pageResponse.props).forEach(([key, value]) => {
|
|
1709
|
+
if ((0, import_lodash_es4.isEqual)(value, currentPageProps[key])) {
|
|
1710
|
+
pageResponse.props[key] = currentPageProps[key];
|
|
1711
|
+
}
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1648
1714
|
mergeProps(pageResponse) {
|
|
1649
1715
|
if (!this.requestParams.isPartial() || pageResponse.component !== page.get().component) {
|
|
1650
1716
|
return;
|
|
@@ -1654,8 +1720,8 @@ var Response = class _Response {
|
|
|
1654
1720
|
const propsToDeepMerge = pageResponse.deepMergeProps || [];
|
|
1655
1721
|
const matchPropsOn = pageResponse.matchPropsOn || [];
|
|
1656
1722
|
const mergeProp = (prop, shouldAppend) => {
|
|
1657
|
-
const currentProp = (0,
|
|
1658
|
-
const incomingProp = (0,
|
|
1723
|
+
const currentProp = (0, import_lodash_es4.get)(page.get().props, prop);
|
|
1724
|
+
const incomingProp = (0, import_lodash_es4.get)(pageResponse.props, prop);
|
|
1659
1725
|
if (Array.isArray(incomingProp)) {
|
|
1660
1726
|
const newArray = this.mergeOrMatchItems(
|
|
1661
1727
|
currentProp || [],
|
|
@@ -1664,13 +1730,13 @@ var Response = class _Response {
|
|
|
1664
1730
|
matchPropsOn,
|
|
1665
1731
|
shouldAppend
|
|
1666
1732
|
);
|
|
1667
|
-
(0,
|
|
1733
|
+
(0, import_lodash_es4.set)(pageResponse.props, prop, newArray);
|
|
1668
1734
|
} else if (typeof incomingProp === "object" && incomingProp !== null) {
|
|
1669
1735
|
const newObject = {
|
|
1670
1736
|
...currentProp || {},
|
|
1671
1737
|
...incomingProp
|
|
1672
1738
|
};
|
|
1673
|
-
(0,
|
|
1739
|
+
(0, import_lodash_es4.set)(pageResponse.props, prop, newObject);
|
|
1674
1740
|
}
|
|
1675
1741
|
};
|
|
1676
1742
|
propsToAppend.forEach((prop) => mergeProp(prop, true));
|
|
@@ -2075,7 +2141,7 @@ var Router = class {
|
|
|
2075
2141
|
this.asyncRequestStream.send(Request.create(params, page.get()));
|
|
2076
2142
|
},
|
|
2077
2143
|
{
|
|
2078
|
-
cacheFor:
|
|
2144
|
+
cacheFor: config.get("prefetch.cacheFor"),
|
|
2079
2145
|
cacheTags: [],
|
|
2080
2146
|
...prefetchOptions
|
|
2081
2147
|
}
|
|
@@ -2099,8 +2165,8 @@ var Router = class {
|
|
|
2099
2165
|
preserveScroll: true,
|
|
2100
2166
|
preserveState: true,
|
|
2101
2167
|
props(currentProps) {
|
|
2102
|
-
const newValue = typeof value === "function" ? value((0,
|
|
2103
|
-
return (0,
|
|
2168
|
+
const newValue = typeof value === "function" ? value((0, import_lodash_es5.get)(currentProps, name), currentProps) : value;
|
|
2169
|
+
return (0, import_lodash_es5.set)((0, import_lodash_es5.cloneDeep)(currentProps), name, newValue);
|
|
2104
2170
|
},
|
|
2105
2171
|
...options || {}
|
|
2106
2172
|
});
|
|
@@ -2175,6 +2241,8 @@ var Router = class {
|
|
|
2175
2241
|
href = urlMethodPair.url;
|
|
2176
2242
|
options.method = options.method ?? urlMethodPair.method;
|
|
2177
2243
|
}
|
|
2244
|
+
const defaultVisitOptionsCallback = config.get("visitOptions");
|
|
2245
|
+
const configuredOptions = defaultVisitOptionsCallback ? defaultVisitOptionsCallback(href.toString(), (0, import_lodash_es5.cloneDeep)(options)) || {} : {};
|
|
2178
2246
|
const mergedOptions = {
|
|
2179
2247
|
method: "get",
|
|
2180
2248
|
data: {},
|
|
@@ -2194,7 +2262,8 @@ var Router = class {
|
|
|
2194
2262
|
preserveUrl: false,
|
|
2195
2263
|
prefetch: false,
|
|
2196
2264
|
invalidateCacheTags: [],
|
|
2197
|
-
...options
|
|
2265
|
+
...options,
|
|
2266
|
+
...configuredOptions
|
|
2198
2267
|
};
|
|
2199
2268
|
const [url, _data] = transformUrlAndData(
|
|
2200
2269
|
href,
|
|
@@ -2329,7 +2398,7 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
|
|
|
2329
2398
|
};
|
|
2330
2399
|
|
|
2331
2400
|
// src/formObject.ts
|
|
2332
|
-
var
|
|
2401
|
+
var import_lodash_es6 = require("lodash-es");
|
|
2333
2402
|
function undotKey(key) {
|
|
2334
2403
|
if (!key.includes(".")) {
|
|
2335
2404
|
return key;
|
|
@@ -2364,15 +2433,15 @@ function formDataToObject(source) {
|
|
|
2364
2433
|
const path = parseKey(undotKey(key));
|
|
2365
2434
|
if (path[path.length - 1] === "") {
|
|
2366
2435
|
const arrayPath = path.slice(0, -1);
|
|
2367
|
-
const existing = (0,
|
|
2436
|
+
const existing = (0, import_lodash_es6.get)(form, arrayPath);
|
|
2368
2437
|
if (Array.isArray(existing)) {
|
|
2369
2438
|
existing.push(value);
|
|
2370
2439
|
} else {
|
|
2371
|
-
(0,
|
|
2440
|
+
(0, import_lodash_es6.set)(form, arrayPath, [value]);
|
|
2372
2441
|
}
|
|
2373
2442
|
continue;
|
|
2374
2443
|
}
|
|
2375
|
-
(0,
|
|
2444
|
+
(0, import_lodash_es6.set)(form, path, value);
|
|
2376
2445
|
}
|
|
2377
2446
|
return form;
|
|
2378
2447
|
}
|
|
@@ -3046,7 +3115,7 @@ var configure = (options) => {
|
|
|
3046
3115
|
progress2.id = baseComponentSelector;
|
|
3047
3116
|
progress2.innerHTML = settings.template;
|
|
3048
3117
|
};
|
|
3049
|
-
var
|
|
3118
|
+
var set5 = (n) => {
|
|
3050
3119
|
const started = isStarted();
|
|
3051
3120
|
n = clamp(n, settings.minimum, 1);
|
|
3052
3121
|
status = n === 1 ? null : n;
|
|
@@ -3095,7 +3164,7 @@ var set4 = (n) => {
|
|
|
3095
3164
|
var isStarted = () => typeof status === "number";
|
|
3096
3165
|
var start = () => {
|
|
3097
3166
|
if (!status) {
|
|
3098
|
-
|
|
3167
|
+
set5(0);
|
|
3099
3168
|
}
|
|
3100
3169
|
const work = function() {
|
|
3101
3170
|
setTimeout(function() {
|
|
@@ -3115,7 +3184,7 @@ var done = (force) => {
|
|
|
3115
3184
|
return;
|
|
3116
3185
|
}
|
|
3117
3186
|
increaseByRandom(0.3 + 0.5 * Math.random());
|
|
3118
|
-
|
|
3187
|
+
set5(1);
|
|
3119
3188
|
};
|
|
3120
3189
|
var increaseByRandom = (amount) => {
|
|
3121
3190
|
const n = status;
|
|
@@ -3139,7 +3208,7 @@ var increaseByRandom = (amount) => {
|
|
|
3139
3208
|
}
|
|
3140
3209
|
return 0;
|
|
3141
3210
|
})();
|
|
3142
|
-
return
|
|
3211
|
+
return set5(clamp(n + amount, 0, 0.994));
|
|
3143
3212
|
};
|
|
3144
3213
|
var render = (fromStart) => {
|
|
3145
3214
|
if (isRendered()) {
|
|
@@ -3285,7 +3354,7 @@ var progress_component_default = {
|
|
|
3285
3354
|
configure,
|
|
3286
3355
|
isStarted,
|
|
3287
3356
|
done,
|
|
3288
|
-
set:
|
|
3357
|
+
set: set5,
|
|
3289
3358
|
remove,
|
|
3290
3359
|
start,
|
|
3291
3360
|
status,
|