@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.esm.js +76 -19
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +81 -24
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/config.d.ts +19 -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 cloneDeep2, get as
|
|
2
|
+
import { cloneDeep as cloneDeep2, 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) {
|
|
@@ -1390,7 +1431,7 @@ var RequestParams = class _RequestParams {
|
|
|
1390
1431
|
};
|
|
1391
1432
|
|
|
1392
1433
|
// src/response.ts
|
|
1393
|
-
import { get, set } from "lodash-es";
|
|
1434
|
+
import { get as get2, isEqual as isEqual2, set as set2 } from "lodash-es";
|
|
1394
1435
|
|
|
1395
1436
|
// src/modal.ts
|
|
1396
1437
|
var modal_default = {
|
|
@@ -1551,6 +1592,7 @@ var Response = class _Response {
|
|
|
1551
1592
|
return Promise.resolve();
|
|
1552
1593
|
}
|
|
1553
1594
|
this.mergeProps(pageResponse);
|
|
1595
|
+
this.preserveEqualProps(pageResponse);
|
|
1554
1596
|
await this.setRememberedState(pageResponse);
|
|
1555
1597
|
this.requestParams.setPreserveOptions(pageResponse);
|
|
1556
1598
|
pageResponse.url = history.preserveUrl ? page.get().url : this.pageUrl(pageResponse);
|
|
@@ -1591,6 +1633,17 @@ var Response = class _Response {
|
|
|
1591
1633
|
setHashIfSameUrl(this.requestParams.all().url, responseUrl);
|
|
1592
1634
|
return responseUrl.pathname + responseUrl.search + responseUrl.hash;
|
|
1593
1635
|
}
|
|
1636
|
+
preserveEqualProps(pageResponse) {
|
|
1637
|
+
if (pageResponse.component !== page.get().component || config.get("future.preserveEqualProps") !== true) {
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
const currentPageProps = page.get().props;
|
|
1641
|
+
Object.entries(pageResponse.props).forEach(([key, value]) => {
|
|
1642
|
+
if (isEqual2(value, currentPageProps[key])) {
|
|
1643
|
+
pageResponse.props[key] = currentPageProps[key];
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1594
1647
|
mergeProps(pageResponse) {
|
|
1595
1648
|
if (!this.requestParams.isPartial() || pageResponse.component !== page.get().component) {
|
|
1596
1649
|
return;
|
|
@@ -1600,8 +1653,8 @@ var Response = class _Response {
|
|
|
1600
1653
|
const propsToDeepMerge = pageResponse.deepMergeProps || [];
|
|
1601
1654
|
const matchPropsOn = pageResponse.matchPropsOn || [];
|
|
1602
1655
|
const mergeProp = (prop, shouldAppend) => {
|
|
1603
|
-
const currentProp =
|
|
1604
|
-
const incomingProp =
|
|
1656
|
+
const currentProp = get2(page.get().props, prop);
|
|
1657
|
+
const incomingProp = get2(pageResponse.props, prop);
|
|
1605
1658
|
if (Array.isArray(incomingProp)) {
|
|
1606
1659
|
const newArray = this.mergeOrMatchItems(
|
|
1607
1660
|
currentProp || [],
|
|
@@ -1610,13 +1663,13 @@ var Response = class _Response {
|
|
|
1610
1663
|
matchPropsOn,
|
|
1611
1664
|
shouldAppend
|
|
1612
1665
|
);
|
|
1613
|
-
|
|
1666
|
+
set2(pageResponse.props, prop, newArray);
|
|
1614
1667
|
} else if (typeof incomingProp === "object" && incomingProp !== null) {
|
|
1615
1668
|
const newObject = {
|
|
1616
1669
|
...currentProp || {},
|
|
1617
1670
|
...incomingProp
|
|
1618
1671
|
};
|
|
1619
|
-
|
|
1672
|
+
set2(pageResponse.props, prop, newObject);
|
|
1620
1673
|
}
|
|
1621
1674
|
};
|
|
1622
1675
|
propsToAppend.forEach((prop) => mergeProp(prop, true));
|
|
@@ -2021,7 +2074,7 @@ var Router = class {
|
|
|
2021
2074
|
this.asyncRequestStream.send(Request.create(params, page.get()));
|
|
2022
2075
|
},
|
|
2023
2076
|
{
|
|
2024
|
-
cacheFor:
|
|
2077
|
+
cacheFor: config.get("prefetch.cacheFor"),
|
|
2025
2078
|
cacheTags: [],
|
|
2026
2079
|
...prefetchOptions
|
|
2027
2080
|
}
|
|
@@ -2045,8 +2098,8 @@ var Router = class {
|
|
|
2045
2098
|
preserveScroll: true,
|
|
2046
2099
|
preserveState: true,
|
|
2047
2100
|
props(currentProps) {
|
|
2048
|
-
const newValue = typeof value === "function" ? value(
|
|
2049
|
-
return
|
|
2101
|
+
const newValue = typeof value === "function" ? value(get3(currentProps, name), currentProps) : value;
|
|
2102
|
+
return set3(cloneDeep2(currentProps), name, newValue);
|
|
2050
2103
|
},
|
|
2051
2104
|
...options || {}
|
|
2052
2105
|
});
|
|
@@ -2121,6 +2174,8 @@ var Router = class {
|
|
|
2121
2174
|
href = urlMethodPair.url;
|
|
2122
2175
|
options.method = options.method ?? urlMethodPair.method;
|
|
2123
2176
|
}
|
|
2177
|
+
const defaultVisitOptionsCallback = config.get("visitOptions");
|
|
2178
|
+
const configuredOptions = defaultVisitOptionsCallback ? defaultVisitOptionsCallback(href.toString(), cloneDeep2(options)) || {} : {};
|
|
2124
2179
|
const mergedOptions = {
|
|
2125
2180
|
method: "get",
|
|
2126
2181
|
data: {},
|
|
@@ -2140,7 +2195,8 @@ var Router = class {
|
|
|
2140
2195
|
preserveUrl: false,
|
|
2141
2196
|
prefetch: false,
|
|
2142
2197
|
invalidateCacheTags: [],
|
|
2143
|
-
...options
|
|
2198
|
+
...options,
|
|
2199
|
+
...configuredOptions
|
|
2144
2200
|
};
|
|
2145
2201
|
const [url, _data] = transformUrlAndData(
|
|
2146
2202
|
href,
|
|
@@ -2275,7 +2331,7 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
|
|
|
2275
2331
|
};
|
|
2276
2332
|
|
|
2277
2333
|
// src/formObject.ts
|
|
2278
|
-
import { get as
|
|
2334
|
+
import { get as get4, set as set4 } from "lodash-es";
|
|
2279
2335
|
function undotKey(key) {
|
|
2280
2336
|
if (!key.includes(".")) {
|
|
2281
2337
|
return key;
|
|
@@ -2310,15 +2366,15 @@ function formDataToObject(source) {
|
|
|
2310
2366
|
const path = parseKey(undotKey(key));
|
|
2311
2367
|
if (path[path.length - 1] === "") {
|
|
2312
2368
|
const arrayPath = path.slice(0, -1);
|
|
2313
|
-
const existing =
|
|
2369
|
+
const existing = get4(form, arrayPath);
|
|
2314
2370
|
if (Array.isArray(existing)) {
|
|
2315
2371
|
existing.push(value);
|
|
2316
2372
|
} else {
|
|
2317
|
-
|
|
2373
|
+
set4(form, arrayPath, [value]);
|
|
2318
2374
|
}
|
|
2319
2375
|
continue;
|
|
2320
2376
|
}
|
|
2321
|
-
|
|
2377
|
+
set4(form, path, value);
|
|
2322
2378
|
}
|
|
2323
2379
|
return form;
|
|
2324
2380
|
}
|
|
@@ -2992,7 +3048,7 @@ var configure = (options) => {
|
|
|
2992
3048
|
progress2.id = baseComponentSelector;
|
|
2993
3049
|
progress2.innerHTML = settings.template;
|
|
2994
3050
|
};
|
|
2995
|
-
var
|
|
3051
|
+
var set5 = (n) => {
|
|
2996
3052
|
const started = isStarted();
|
|
2997
3053
|
n = clamp(n, settings.minimum, 1);
|
|
2998
3054
|
status = n === 1 ? null : n;
|
|
@@ -3041,7 +3097,7 @@ var set4 = (n) => {
|
|
|
3041
3097
|
var isStarted = () => typeof status === "number";
|
|
3042
3098
|
var start = () => {
|
|
3043
3099
|
if (!status) {
|
|
3044
|
-
|
|
3100
|
+
set5(0);
|
|
3045
3101
|
}
|
|
3046
3102
|
const work = function() {
|
|
3047
3103
|
setTimeout(function() {
|
|
@@ -3061,7 +3117,7 @@ var done = (force) => {
|
|
|
3061
3117
|
return;
|
|
3062
3118
|
}
|
|
3063
3119
|
increaseByRandom(0.3 + 0.5 * Math.random());
|
|
3064
|
-
|
|
3120
|
+
set5(1);
|
|
3065
3121
|
};
|
|
3066
3122
|
var increaseByRandom = (amount) => {
|
|
3067
3123
|
const n = status;
|
|
@@ -3085,7 +3141,7 @@ var increaseByRandom = (amount) => {
|
|
|
3085
3141
|
}
|
|
3086
3142
|
return 0;
|
|
3087
3143
|
})();
|
|
3088
|
-
return
|
|
3144
|
+
return set5(clamp(n + amount, 0, 0.994));
|
|
3089
3145
|
};
|
|
3090
3146
|
var render = (fromStart) => {
|
|
3091
3147
|
if (isRendered()) {
|
|
@@ -3231,7 +3287,7 @@ var progress_component_default = {
|
|
|
3231
3287
|
configure,
|
|
3232
3288
|
isStarted,
|
|
3233
3289
|
done,
|
|
3234
|
-
set:
|
|
3290
|
+
set: set5,
|
|
3235
3291
|
remove,
|
|
3236
3292
|
start,
|
|
3237
3293
|
status,
|
|
@@ -3456,6 +3512,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3456
3512
|
// src/index.ts
|
|
3457
3513
|
var router = new Router();
|
|
3458
3514
|
export {
|
|
3515
|
+
config,
|
|
3459
3516
|
createHeadManager,
|
|
3460
3517
|
formDataToObject,
|
|
3461
3518
|
getScrollableParent,
|