@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.esm.js
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
// src/router.ts
|
|
2
|
-
import { cloneDeep as
|
|
2
|
+
import { cloneDeep as cloneDeep3, get as get3, set as set3 } from "lodash-es";
|
|
3
|
+
|
|
4
|
+
// src/config.ts
|
|
5
|
+
import { get, has, set } from "lodash-es";
|
|
6
|
+
var Config = class {
|
|
7
|
+
constructor(defaults) {
|
|
8
|
+
this.config = {};
|
|
9
|
+
this.defaults = defaults;
|
|
10
|
+
}
|
|
11
|
+
extend(defaults) {
|
|
12
|
+
if (defaults) {
|
|
13
|
+
this.defaults = { ...this.defaults, ...defaults };
|
|
14
|
+
}
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
replace(newConfig) {
|
|
18
|
+
this.config = newConfig;
|
|
19
|
+
}
|
|
20
|
+
get(key) {
|
|
21
|
+
return has(this.config, key) ? get(this.config, key) : get(this.defaults, key);
|
|
22
|
+
}
|
|
23
|
+
set(keyOrValues, value) {
|
|
24
|
+
if (typeof keyOrValues === "string") {
|
|
25
|
+
set(this.config, keyOrValues, value);
|
|
26
|
+
} else {
|
|
27
|
+
Object.entries(keyOrValues).forEach(([key, val]) => {
|
|
28
|
+
set(this.config, key, val);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var config = new Config({
|
|
34
|
+
form: {
|
|
35
|
+
recentlySuccessfulDuration: 2e3
|
|
36
|
+
},
|
|
37
|
+
future: {
|
|
38
|
+
preserveEqualProps: false
|
|
39
|
+
},
|
|
40
|
+
prefetch: {
|
|
41
|
+
cacheFor: 3e4
|
|
42
|
+
}
|
|
43
|
+
});
|
|
3
44
|
|
|
4
45
|
// src/debounce.ts
|
|
5
46
|
function debounce(fn, delay) {
|
|
@@ -52,7 +93,7 @@ var firePrefetchingEvent = (visit) => {
|
|
|
52
93
|
};
|
|
53
94
|
|
|
54
95
|
// src/history.ts
|
|
55
|
-
import { isEqual } from "lodash-es";
|
|
96
|
+
import { cloneDeep, isEqual } from "lodash-es";
|
|
56
97
|
|
|
57
98
|
// src/sessionStorage.ts
|
|
58
99
|
var SessionStorage = class {
|
|
@@ -616,9 +657,21 @@ var History = class {
|
|
|
616
657
|
});
|
|
617
658
|
});
|
|
618
659
|
}
|
|
660
|
+
clonePageProps(page2) {
|
|
661
|
+
try {
|
|
662
|
+
structuredClone(page2.props);
|
|
663
|
+
return page2;
|
|
664
|
+
} catch {
|
|
665
|
+
return {
|
|
666
|
+
...page2,
|
|
667
|
+
props: cloneDeep(page2.props)
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
}
|
|
619
671
|
getPageData(page2) {
|
|
672
|
+
const pageWithClonedProps = this.clonePageProps(page2);
|
|
620
673
|
return new Promise((resolve) => {
|
|
621
|
-
return page2.encryptHistory ? encryptHistory(
|
|
674
|
+
return page2.encryptHistory ? encryptHistory(pageWithClonedProps).then(resolve) : resolve(pageWithClonedProps);
|
|
622
675
|
});
|
|
623
676
|
}
|
|
624
677
|
processQueue() {
|
|
@@ -997,7 +1050,7 @@ var Polls = class {
|
|
|
997
1050
|
var polls = new Polls();
|
|
998
1051
|
|
|
999
1052
|
// src/prefetched.ts
|
|
1000
|
-
import { cloneDeep } from "lodash-es";
|
|
1053
|
+
import { cloneDeep as cloneDeep2 } from "lodash-es";
|
|
1001
1054
|
|
|
1002
1055
|
// src/objectUtils.ts
|
|
1003
1056
|
var objectsAreEqual = (obj1, obj2, excludeKeys) => {
|
|
@@ -1214,7 +1267,7 @@ var PrefetchedRequests = class {
|
|
|
1214
1267
|
}) || null;
|
|
1215
1268
|
}
|
|
1216
1269
|
withoutPurposePrefetchHeader(params) {
|
|
1217
|
-
const newParams =
|
|
1270
|
+
const newParams = cloneDeep2(params);
|
|
1218
1271
|
if (newParams.headers["Purpose"] === "prefetch") {
|
|
1219
1272
|
delete newParams.headers["Purpose"];
|
|
1220
1273
|
}
|
|
@@ -1390,7 +1443,7 @@ var RequestParams = class _RequestParams {
|
|
|
1390
1443
|
};
|
|
1391
1444
|
|
|
1392
1445
|
// src/response.ts
|
|
1393
|
-
import { get, set } from "lodash-es";
|
|
1446
|
+
import { get as get2, isEqual as isEqual2, set as set2 } from "lodash-es";
|
|
1394
1447
|
|
|
1395
1448
|
// src/modal.ts
|
|
1396
1449
|
var modal_default = {
|
|
@@ -1551,6 +1604,7 @@ var Response = class _Response {
|
|
|
1551
1604
|
return Promise.resolve();
|
|
1552
1605
|
}
|
|
1553
1606
|
this.mergeProps(pageResponse);
|
|
1607
|
+
this.preserveEqualProps(pageResponse);
|
|
1554
1608
|
await this.setRememberedState(pageResponse);
|
|
1555
1609
|
this.requestParams.setPreserveOptions(pageResponse);
|
|
1556
1610
|
pageResponse.url = history.preserveUrl ? page.get().url : this.pageUrl(pageResponse);
|
|
@@ -1591,6 +1645,17 @@ var Response = class _Response {
|
|
|
1591
1645
|
setHashIfSameUrl(this.requestParams.all().url, responseUrl);
|
|
1592
1646
|
return responseUrl.pathname + responseUrl.search + responseUrl.hash;
|
|
1593
1647
|
}
|
|
1648
|
+
preserveEqualProps(pageResponse) {
|
|
1649
|
+
if (pageResponse.component !== page.get().component || config.get("future.preserveEqualProps") !== true) {
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
const currentPageProps = page.get().props;
|
|
1653
|
+
Object.entries(pageResponse.props).forEach(([key, value]) => {
|
|
1654
|
+
if (isEqual2(value, currentPageProps[key])) {
|
|
1655
|
+
pageResponse.props[key] = currentPageProps[key];
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1594
1659
|
mergeProps(pageResponse) {
|
|
1595
1660
|
if (!this.requestParams.isPartial() || pageResponse.component !== page.get().component) {
|
|
1596
1661
|
return;
|
|
@@ -1600,8 +1665,8 @@ var Response = class _Response {
|
|
|
1600
1665
|
const propsToDeepMerge = pageResponse.deepMergeProps || [];
|
|
1601
1666
|
const matchPropsOn = pageResponse.matchPropsOn || [];
|
|
1602
1667
|
const mergeProp = (prop, shouldAppend) => {
|
|
1603
|
-
const currentProp =
|
|
1604
|
-
const incomingProp =
|
|
1668
|
+
const currentProp = get2(page.get().props, prop);
|
|
1669
|
+
const incomingProp = get2(pageResponse.props, prop);
|
|
1605
1670
|
if (Array.isArray(incomingProp)) {
|
|
1606
1671
|
const newArray = this.mergeOrMatchItems(
|
|
1607
1672
|
currentProp || [],
|
|
@@ -1610,13 +1675,13 @@ var Response = class _Response {
|
|
|
1610
1675
|
matchPropsOn,
|
|
1611
1676
|
shouldAppend
|
|
1612
1677
|
);
|
|
1613
|
-
|
|
1678
|
+
set2(pageResponse.props, prop, newArray);
|
|
1614
1679
|
} else if (typeof incomingProp === "object" && incomingProp !== null) {
|
|
1615
1680
|
const newObject = {
|
|
1616
1681
|
...currentProp || {},
|
|
1617
1682
|
...incomingProp
|
|
1618
1683
|
};
|
|
1619
|
-
|
|
1684
|
+
set2(pageResponse.props, prop, newObject);
|
|
1620
1685
|
}
|
|
1621
1686
|
};
|
|
1622
1687
|
propsToAppend.forEach((prop) => mergeProp(prop, true));
|
|
@@ -2021,7 +2086,7 @@ var Router = class {
|
|
|
2021
2086
|
this.asyncRequestStream.send(Request.create(params, page.get()));
|
|
2022
2087
|
},
|
|
2023
2088
|
{
|
|
2024
|
-
cacheFor:
|
|
2089
|
+
cacheFor: config.get("prefetch.cacheFor"),
|
|
2025
2090
|
cacheTags: [],
|
|
2026
2091
|
...prefetchOptions
|
|
2027
2092
|
}
|
|
@@ -2045,8 +2110,8 @@ var Router = class {
|
|
|
2045
2110
|
preserveScroll: true,
|
|
2046
2111
|
preserveState: true,
|
|
2047
2112
|
props(currentProps) {
|
|
2048
|
-
const newValue = typeof value === "function" ? value(
|
|
2049
|
-
return
|
|
2113
|
+
const newValue = typeof value === "function" ? value(get3(currentProps, name), currentProps) : value;
|
|
2114
|
+
return set3(cloneDeep3(currentProps), name, newValue);
|
|
2050
2115
|
},
|
|
2051
2116
|
...options || {}
|
|
2052
2117
|
});
|
|
@@ -2121,6 +2186,8 @@ var Router = class {
|
|
|
2121
2186
|
href = urlMethodPair.url;
|
|
2122
2187
|
options.method = options.method ?? urlMethodPair.method;
|
|
2123
2188
|
}
|
|
2189
|
+
const defaultVisitOptionsCallback = config.get("visitOptions");
|
|
2190
|
+
const configuredOptions = defaultVisitOptionsCallback ? defaultVisitOptionsCallback(href.toString(), cloneDeep3(options)) || {} : {};
|
|
2124
2191
|
const mergedOptions = {
|
|
2125
2192
|
method: "get",
|
|
2126
2193
|
data: {},
|
|
@@ -2140,7 +2207,8 @@ var Router = class {
|
|
|
2140
2207
|
preserveUrl: false,
|
|
2141
2208
|
prefetch: false,
|
|
2142
2209
|
invalidateCacheTags: [],
|
|
2143
|
-
...options
|
|
2210
|
+
...options,
|
|
2211
|
+
...configuredOptions
|
|
2144
2212
|
};
|
|
2145
2213
|
const [url, _data] = transformUrlAndData(
|
|
2146
2214
|
href,
|
|
@@ -2275,7 +2343,7 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
|
|
|
2275
2343
|
};
|
|
2276
2344
|
|
|
2277
2345
|
// src/formObject.ts
|
|
2278
|
-
import { get as
|
|
2346
|
+
import { get as get4, set as set4 } from "lodash-es";
|
|
2279
2347
|
function undotKey(key) {
|
|
2280
2348
|
if (!key.includes(".")) {
|
|
2281
2349
|
return key;
|
|
@@ -2310,15 +2378,15 @@ function formDataToObject(source) {
|
|
|
2310
2378
|
const path = parseKey(undotKey(key));
|
|
2311
2379
|
if (path[path.length - 1] === "") {
|
|
2312
2380
|
const arrayPath = path.slice(0, -1);
|
|
2313
|
-
const existing =
|
|
2381
|
+
const existing = get4(form, arrayPath);
|
|
2314
2382
|
if (Array.isArray(existing)) {
|
|
2315
2383
|
existing.push(value);
|
|
2316
2384
|
} else {
|
|
2317
|
-
|
|
2385
|
+
set4(form, arrayPath, [value]);
|
|
2318
2386
|
}
|
|
2319
2387
|
continue;
|
|
2320
2388
|
}
|
|
2321
|
-
|
|
2389
|
+
set4(form, path, value);
|
|
2322
2390
|
}
|
|
2323
2391
|
return form;
|
|
2324
2392
|
}
|
|
@@ -2992,7 +3060,7 @@ var configure = (options) => {
|
|
|
2992
3060
|
progress2.id = baseComponentSelector;
|
|
2993
3061
|
progress2.innerHTML = settings.template;
|
|
2994
3062
|
};
|
|
2995
|
-
var
|
|
3063
|
+
var set5 = (n) => {
|
|
2996
3064
|
const started = isStarted();
|
|
2997
3065
|
n = clamp(n, settings.minimum, 1);
|
|
2998
3066
|
status = n === 1 ? null : n;
|
|
@@ -3041,7 +3109,7 @@ var set4 = (n) => {
|
|
|
3041
3109
|
var isStarted = () => typeof status === "number";
|
|
3042
3110
|
var start = () => {
|
|
3043
3111
|
if (!status) {
|
|
3044
|
-
|
|
3112
|
+
set5(0);
|
|
3045
3113
|
}
|
|
3046
3114
|
const work = function() {
|
|
3047
3115
|
setTimeout(function() {
|
|
@@ -3061,7 +3129,7 @@ var done = (force) => {
|
|
|
3061
3129
|
return;
|
|
3062
3130
|
}
|
|
3063
3131
|
increaseByRandom(0.3 + 0.5 * Math.random());
|
|
3064
|
-
|
|
3132
|
+
set5(1);
|
|
3065
3133
|
};
|
|
3066
3134
|
var increaseByRandom = (amount) => {
|
|
3067
3135
|
const n = status;
|
|
@@ -3085,7 +3153,7 @@ var increaseByRandom = (amount) => {
|
|
|
3085
3153
|
}
|
|
3086
3154
|
return 0;
|
|
3087
3155
|
})();
|
|
3088
|
-
return
|
|
3156
|
+
return set5(clamp(n + amount, 0, 0.994));
|
|
3089
3157
|
};
|
|
3090
3158
|
var render = (fromStart) => {
|
|
3091
3159
|
if (isRendered()) {
|
|
@@ -3231,7 +3299,7 @@ var progress_component_default = {
|
|
|
3231
3299
|
configure,
|
|
3232
3300
|
isStarted,
|
|
3233
3301
|
done,
|
|
3234
|
-
set:
|
|
3302
|
+
set: set5,
|
|
3235
3303
|
remove,
|
|
3236
3304
|
start,
|
|
3237
3305
|
status,
|
|
@@ -3456,6 +3524,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3456
3524
|
// src/index.ts
|
|
3457
3525
|
var router = new Router();
|
|
3458
3526
|
export {
|
|
3527
|
+
config,
|
|
3459
3528
|
createHeadManager,
|
|
3460
3529
|
formDataToObject,
|
|
3461
3530
|
getScrollableParent,
|