@inertiajs/core 2.2.15 → 2.2.17
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 +90 -28
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +90 -28
- package/dist/index.js.map +3 -3
- package/package.json +4 -4
- package/types/domUtils.d.ts +2 -1
- package/types/files.d.ts +1 -0
- package/types/formData.d.ts +2 -2
- package/types/types.d.ts +3 -1
- package/types/url.d.ts +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -32,7 +32,8 @@ var Config = class {
|
|
|
32
32
|
};
|
|
33
33
|
var config = new Config({
|
|
34
34
|
form: {
|
|
35
|
-
recentlySuccessfulDuration: 2e3
|
|
35
|
+
recentlySuccessfulDuration: 2e3,
|
|
36
|
+
forceIndicesArrayFormatInFormData: true
|
|
36
37
|
},
|
|
37
38
|
future: {
|
|
38
39
|
preserveEqualProps: false,
|
|
@@ -349,27 +350,33 @@ var Scroll = class {
|
|
|
349
350
|
import * as qs from "qs";
|
|
350
351
|
|
|
351
352
|
// src/files.ts
|
|
353
|
+
var isFile = (value) => typeof File !== "undefined" && value instanceof File || value instanceof Blob || typeof FileList !== "undefined" && value instanceof FileList && value.length > 0;
|
|
352
354
|
function hasFiles(data) {
|
|
353
|
-
return data
|
|
355
|
+
return isFile(data) || data instanceof FormData && Array.from(data.values()).some((value) => hasFiles(value)) || typeof data === "object" && data !== null && Object.values(data).some((value) => hasFiles(value));
|
|
354
356
|
}
|
|
355
357
|
|
|
356
358
|
// src/formData.ts
|
|
357
359
|
var isFormData = (value) => value instanceof FormData;
|
|
358
|
-
function objectToFormData(source, form = new FormData(), parentKey = null) {
|
|
360
|
+
function objectToFormData(source, form = new FormData(), parentKey = null, queryStringArrayFormat = "brackets") {
|
|
359
361
|
source = source || {};
|
|
360
362
|
for (const key in source) {
|
|
361
363
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
362
|
-
append(form, composeKey(parentKey, key), source[key]);
|
|
364
|
+
append(form, composeKey(parentKey, key, "indices"), source[key], queryStringArrayFormat);
|
|
363
365
|
}
|
|
364
366
|
}
|
|
365
367
|
return form;
|
|
366
368
|
}
|
|
367
|
-
function composeKey(parent, key) {
|
|
368
|
-
|
|
369
|
+
function composeKey(parent, key, format) {
|
|
370
|
+
if (!parent) {
|
|
371
|
+
return key;
|
|
372
|
+
}
|
|
373
|
+
return format === "brackets" ? `${parent}[]` : `${parent}[${key}]`;
|
|
369
374
|
}
|
|
370
|
-
function append(form, key, value) {
|
|
375
|
+
function append(form, key, value, format) {
|
|
371
376
|
if (Array.isArray(value)) {
|
|
372
|
-
return Array.from(value.keys()).forEach(
|
|
377
|
+
return Array.from(value.keys()).forEach(
|
|
378
|
+
(index) => append(form, composeKey(key, index.toString(), format), value[index], format)
|
|
379
|
+
);
|
|
373
380
|
} else if (value instanceof Date) {
|
|
374
381
|
return form.append(key, value.toISOString());
|
|
375
382
|
} else if (value instanceof File) {
|
|
@@ -385,7 +392,7 @@ function append(form, key, value) {
|
|
|
385
392
|
} else if (value === null || value === void 0) {
|
|
386
393
|
return form.append(key, "");
|
|
387
394
|
}
|
|
388
|
-
objectToFormData(value, form, key);
|
|
395
|
+
objectToFormData(value, form, key, format);
|
|
389
396
|
}
|
|
390
397
|
|
|
391
398
|
// src/url.ts
|
|
@@ -395,7 +402,10 @@ function hrefToUrl(href) {
|
|
|
395
402
|
var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFormat) => {
|
|
396
403
|
let url = typeof href === "string" ? hrefToUrl(href) : href;
|
|
397
404
|
if ((hasFiles(data) || forceFormData) && !isFormData(data)) {
|
|
398
|
-
|
|
405
|
+
if (config.get("form.forceIndicesArrayFormatInFormData")) {
|
|
406
|
+
queryStringArrayFormat = "indices";
|
|
407
|
+
}
|
|
408
|
+
data = objectToFormData(data, new FormData(), null, queryStringArrayFormat);
|
|
399
409
|
}
|
|
400
410
|
if (isFormData(data)) {
|
|
401
411
|
return [url, data];
|
|
@@ -654,7 +664,7 @@ var History = class {
|
|
|
654
664
|
}
|
|
655
665
|
restore(key) {
|
|
656
666
|
if (!isServer) {
|
|
657
|
-
return this.current[this.rememberedState] ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
|
|
667
|
+
return this.current[this.rememberedState]?.[key] !== void 0 ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
|
|
658
668
|
}
|
|
659
669
|
}
|
|
660
670
|
pushState(page2, cb = null) {
|
|
@@ -1302,6 +1312,8 @@ var PrefetchedRequests = class {
|
|
|
1302
1312
|
"showProgress",
|
|
1303
1313
|
"replace",
|
|
1304
1314
|
"prefetch",
|
|
1315
|
+
"preserveScroll",
|
|
1316
|
+
"preserveState",
|
|
1305
1317
|
"onBefore",
|
|
1306
1318
|
"onBeforeUpdate",
|
|
1307
1319
|
"onStart",
|
|
@@ -2348,6 +2360,9 @@ var Router = class {
|
|
|
2348
2360
|
|
|
2349
2361
|
// src/domUtils.ts
|
|
2350
2362
|
var elementInViewport = (el) => {
|
|
2363
|
+
if (el.offsetParent === null) {
|
|
2364
|
+
return false;
|
|
2365
|
+
}
|
|
2351
2366
|
const rect = el.getBoundingClientRect();
|
|
2352
2367
|
const verticallyVisible = rect.top < window.innerHeight && rect.bottom >= 0;
|
|
2353
2368
|
const horizontallyVisible = rect.left < window.innerWidth && rect.right >= 0;
|
|
@@ -2399,7 +2414,10 @@ var getScrollableParent = (element) => {
|
|
|
2399
2414
|
}
|
|
2400
2415
|
return null;
|
|
2401
2416
|
};
|
|
2402
|
-
var getElementsInViewportFromCollection = (
|
|
2417
|
+
var getElementsInViewportFromCollection = (elements, referenceElement) => {
|
|
2418
|
+
if (!referenceElement) {
|
|
2419
|
+
return elements.filter((element) => elementInViewport(element));
|
|
2420
|
+
}
|
|
2403
2421
|
const referenceIndex = elements.indexOf(referenceElement);
|
|
2404
2422
|
const upwardElements = [];
|
|
2405
2423
|
const downwardElements = [];
|
|
@@ -2421,6 +2439,15 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
|
|
|
2421
2439
|
}
|
|
2422
2440
|
return [...upwardElements.reverse(), ...downwardElements];
|
|
2423
2441
|
};
|
|
2442
|
+
var requestAnimationFrame = (cb, times = 1) => {
|
|
2443
|
+
window.requestAnimationFrame(() => {
|
|
2444
|
+
if (times > 1) {
|
|
2445
|
+
requestAnimationFrame(cb, times - 1);
|
|
2446
|
+
} else {
|
|
2447
|
+
cb();
|
|
2448
|
+
}
|
|
2449
|
+
});
|
|
2450
|
+
};
|
|
2424
2451
|
|
|
2425
2452
|
// src/formObject.ts
|
|
2426
2453
|
import { get as get4, set as set4 } from "lodash-es";
|
|
@@ -2449,6 +2476,41 @@ function parseKey(key) {
|
|
|
2449
2476
|
}
|
|
2450
2477
|
return path;
|
|
2451
2478
|
}
|
|
2479
|
+
function setNestedObject(obj, path, value) {
|
|
2480
|
+
let current = obj;
|
|
2481
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
2482
|
+
if (!(path[i] in current)) {
|
|
2483
|
+
current[path[i]] = {};
|
|
2484
|
+
}
|
|
2485
|
+
current = current[path[i]];
|
|
2486
|
+
}
|
|
2487
|
+
current[path[path.length - 1]] = value;
|
|
2488
|
+
}
|
|
2489
|
+
function objectHasSequentialNumericKeys(value) {
|
|
2490
|
+
const keys = Object.keys(value);
|
|
2491
|
+
const numericKeys = keys.filter((k) => /^\d+$/.test(k)).map(Number).sort((a, b) => a - b);
|
|
2492
|
+
return keys.length === numericKeys.length && numericKeys.length > 0 && numericKeys[0] === 0 && numericKeys.every((n, i) => n === i);
|
|
2493
|
+
}
|
|
2494
|
+
function convertSequentialObjectsToArrays(value) {
|
|
2495
|
+
if (Array.isArray(value)) {
|
|
2496
|
+
return value.map(convertSequentialObjectsToArrays);
|
|
2497
|
+
}
|
|
2498
|
+
if (typeof value !== "object" || value === null || isFile(value)) {
|
|
2499
|
+
return value;
|
|
2500
|
+
}
|
|
2501
|
+
if (objectHasSequentialNumericKeys(value)) {
|
|
2502
|
+
const result2 = [];
|
|
2503
|
+
for (let i = 0; i < Object.keys(value).length; i++) {
|
|
2504
|
+
result2[i] = convertSequentialObjectsToArrays(value[i]);
|
|
2505
|
+
}
|
|
2506
|
+
return result2;
|
|
2507
|
+
}
|
|
2508
|
+
const result = {};
|
|
2509
|
+
for (const key in value) {
|
|
2510
|
+
result[key] = convertSequentialObjectsToArrays(value[key]);
|
|
2511
|
+
}
|
|
2512
|
+
return result;
|
|
2513
|
+
}
|
|
2452
2514
|
function formDataToObject(source) {
|
|
2453
2515
|
const form = {};
|
|
2454
2516
|
for (const [key, value] of source.entries()) {
|
|
@@ -2461,14 +2523,17 @@ function formDataToObject(source) {
|
|
|
2461
2523
|
const existing = get4(form, arrayPath);
|
|
2462
2524
|
if (Array.isArray(existing)) {
|
|
2463
2525
|
existing.push(value);
|
|
2526
|
+
} else if (existing && typeof existing === "object" && !isFile(existing)) {
|
|
2527
|
+
const numericKeys = Object.keys(existing).filter((k) => /^\d+$/.test(k)).map(Number).sort((a, b) => a - b);
|
|
2528
|
+
set4(form, arrayPath, numericKeys.length > 0 ? [...numericKeys.map((k) => existing[k]), value] : [value]);
|
|
2464
2529
|
} else {
|
|
2465
2530
|
set4(form, arrayPath, [value]);
|
|
2466
2531
|
}
|
|
2467
2532
|
continue;
|
|
2468
2533
|
}
|
|
2469
|
-
|
|
2534
|
+
setNestedObject(form, path.map(String), value);
|
|
2470
2535
|
}
|
|
2471
|
-
return form;
|
|
2536
|
+
return convertSequentialObjectsToArrays(form);
|
|
2472
2537
|
}
|
|
2473
2538
|
|
|
2474
2539
|
// src/head.ts
|
|
@@ -2943,7 +3008,7 @@ var useInfiniteScrollQueryString = (options) => {
|
|
|
2943
3008
|
}
|
|
2944
3009
|
const pageMap = /* @__PURE__ */ new Map();
|
|
2945
3010
|
const elements = [...itemsElement.children];
|
|
2946
|
-
getElementsInViewportFromCollection(
|
|
3011
|
+
getElementsInViewportFromCollection(elements, itemElement).forEach((element) => {
|
|
2947
3012
|
const page2 = getPageFromElement(element) ?? "1";
|
|
2948
3013
|
if (pageMap.has(page2)) {
|
|
2949
3014
|
pageMap.set(page2, pageMap.get(page2) + 1);
|
|
@@ -2973,10 +3038,7 @@ var useInfiniteScrollPreservation = (options) => {
|
|
|
2973
3038
|
const scrollableContainer = options.getScrollableParent();
|
|
2974
3039
|
const itemsElement = options.getItemsElement();
|
|
2975
3040
|
currentScrollTop = scrollableContainer?.scrollTop || window.scrollY;
|
|
2976
|
-
const visibleElements = getElementsInViewportFromCollection(
|
|
2977
|
-
itemsElement.firstElementChild,
|
|
2978
|
-
[...itemsElement.children]
|
|
2979
|
-
);
|
|
3041
|
+
const visibleElements = getElementsInViewportFromCollection([...itemsElement.children]);
|
|
2980
3042
|
if (visibleElements.length > 0) {
|
|
2981
3043
|
referenceElement = visibleElements[0];
|
|
2982
3044
|
const containerRect = scrollableContainer?.getBoundingClientRect() || { top: 0 };
|
|
@@ -3013,7 +3075,7 @@ var useInfiniteScrollPreservation = (options) => {
|
|
|
3013
3075
|
}
|
|
3014
3076
|
restored = true;
|
|
3015
3077
|
};
|
|
3016
|
-
restore
|
|
3078
|
+
window.requestAnimationFrame(restore);
|
|
3017
3079
|
};
|
|
3018
3080
|
return {
|
|
3019
3081
|
captureScrollPosition,
|
|
@@ -3043,18 +3105,18 @@ function useInfiniteScroll(options) {
|
|
|
3043
3105
|
onBeforeUpdate: elementManager.processManuallyAddedElements,
|
|
3044
3106
|
// After successful request, tag new server content
|
|
3045
3107
|
onCompletePreviousRequest: (loadedPage) => {
|
|
3046
|
-
|
|
3108
|
+
options.onCompletePreviousRequest();
|
|
3109
|
+
requestAnimationFrame(() => {
|
|
3047
3110
|
elementManager.processServerLoadedElements(loadedPage);
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
});
|
|
3111
|
+
elementManager.refreshTriggers();
|
|
3112
|
+
}, 2);
|
|
3051
3113
|
},
|
|
3052
3114
|
onCompleteNextRequest: (loadedPage) => {
|
|
3053
|
-
|
|
3115
|
+
options.onCompleteNextRequest();
|
|
3116
|
+
requestAnimationFrame(() => {
|
|
3054
3117
|
elementManager.processServerLoadedElements(loadedPage);
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
});
|
|
3118
|
+
elementManager.refreshTriggers();
|
|
3119
|
+
}, 2);
|
|
3058
3120
|
}
|
|
3059
3121
|
});
|
|
3060
3122
|
const addScrollPreservationCallbacks = (reloadOptions) => {
|