@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.js
CHANGED
|
@@ -87,7 +87,8 @@ var Config = class {
|
|
|
87
87
|
};
|
|
88
88
|
var config = new Config({
|
|
89
89
|
form: {
|
|
90
|
-
recentlySuccessfulDuration: 2e3
|
|
90
|
+
recentlySuccessfulDuration: 2e3,
|
|
91
|
+
forceIndicesArrayFormatInFormData: true
|
|
91
92
|
},
|
|
92
93
|
future: {
|
|
93
94
|
preserveEqualProps: false,
|
|
@@ -404,27 +405,33 @@ var Scroll = class {
|
|
|
404
405
|
var qs = __toESM(require("qs"), 1);
|
|
405
406
|
|
|
406
407
|
// src/files.ts
|
|
408
|
+
var isFile = (value) => typeof File !== "undefined" && value instanceof File || value instanceof Blob || typeof FileList !== "undefined" && value instanceof FileList && value.length > 0;
|
|
407
409
|
function hasFiles(data) {
|
|
408
|
-
return data
|
|
410
|
+
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));
|
|
409
411
|
}
|
|
410
412
|
|
|
411
413
|
// src/formData.ts
|
|
412
414
|
var isFormData = (value) => value instanceof FormData;
|
|
413
|
-
function objectToFormData(source, form = new FormData(), parentKey = null) {
|
|
415
|
+
function objectToFormData(source, form = new FormData(), parentKey = null, queryStringArrayFormat = "brackets") {
|
|
414
416
|
source = source || {};
|
|
415
417
|
for (const key in source) {
|
|
416
418
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
417
|
-
append(form, composeKey(parentKey, key), source[key]);
|
|
419
|
+
append(form, composeKey(parentKey, key, "indices"), source[key], queryStringArrayFormat);
|
|
418
420
|
}
|
|
419
421
|
}
|
|
420
422
|
return form;
|
|
421
423
|
}
|
|
422
|
-
function composeKey(parent, key) {
|
|
423
|
-
|
|
424
|
+
function composeKey(parent, key, format) {
|
|
425
|
+
if (!parent) {
|
|
426
|
+
return key;
|
|
427
|
+
}
|
|
428
|
+
return format === "brackets" ? `${parent}[]` : `${parent}[${key}]`;
|
|
424
429
|
}
|
|
425
|
-
function append(form, key, value) {
|
|
430
|
+
function append(form, key, value, format) {
|
|
426
431
|
if (Array.isArray(value)) {
|
|
427
|
-
return Array.from(value.keys()).forEach(
|
|
432
|
+
return Array.from(value.keys()).forEach(
|
|
433
|
+
(index) => append(form, composeKey(key, index.toString(), format), value[index], format)
|
|
434
|
+
);
|
|
428
435
|
} else if (value instanceof Date) {
|
|
429
436
|
return form.append(key, value.toISOString());
|
|
430
437
|
} else if (value instanceof File) {
|
|
@@ -440,7 +447,7 @@ function append(form, key, value) {
|
|
|
440
447
|
} else if (value === null || value === void 0) {
|
|
441
448
|
return form.append(key, "");
|
|
442
449
|
}
|
|
443
|
-
objectToFormData(value, form, key);
|
|
450
|
+
objectToFormData(value, form, key, format);
|
|
444
451
|
}
|
|
445
452
|
|
|
446
453
|
// src/url.ts
|
|
@@ -450,7 +457,10 @@ function hrefToUrl(href) {
|
|
|
450
457
|
var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFormat) => {
|
|
451
458
|
let url = typeof href === "string" ? hrefToUrl(href) : href;
|
|
452
459
|
if ((hasFiles(data) || forceFormData) && !isFormData(data)) {
|
|
453
|
-
|
|
460
|
+
if (config.get("form.forceIndicesArrayFormatInFormData")) {
|
|
461
|
+
queryStringArrayFormat = "indices";
|
|
462
|
+
}
|
|
463
|
+
data = objectToFormData(data, new FormData(), null, queryStringArrayFormat);
|
|
454
464
|
}
|
|
455
465
|
if (isFormData(data)) {
|
|
456
466
|
return [url, data];
|
|
@@ -709,7 +719,7 @@ var History = class {
|
|
|
709
719
|
}
|
|
710
720
|
restore(key) {
|
|
711
721
|
if (!isServer) {
|
|
712
|
-
return this.current[this.rememberedState] ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
|
|
722
|
+
return this.current[this.rememberedState]?.[key] !== void 0 ? this.current[this.rememberedState]?.[key] : this.initialState?.[this.rememberedState]?.[key];
|
|
713
723
|
}
|
|
714
724
|
}
|
|
715
725
|
pushState(page2, cb = null) {
|
|
@@ -1357,6 +1367,8 @@ var PrefetchedRequests = class {
|
|
|
1357
1367
|
"showProgress",
|
|
1358
1368
|
"replace",
|
|
1359
1369
|
"prefetch",
|
|
1370
|
+
"preserveScroll",
|
|
1371
|
+
"preserveState",
|
|
1360
1372
|
"onBefore",
|
|
1361
1373
|
"onBeforeUpdate",
|
|
1362
1374
|
"onStart",
|
|
@@ -2403,6 +2415,9 @@ var Router = class {
|
|
|
2403
2415
|
|
|
2404
2416
|
// src/domUtils.ts
|
|
2405
2417
|
var elementInViewport = (el) => {
|
|
2418
|
+
if (el.offsetParent === null) {
|
|
2419
|
+
return false;
|
|
2420
|
+
}
|
|
2406
2421
|
const rect = el.getBoundingClientRect();
|
|
2407
2422
|
const verticallyVisible = rect.top < window.innerHeight && rect.bottom >= 0;
|
|
2408
2423
|
const horizontallyVisible = rect.left < window.innerWidth && rect.right >= 0;
|
|
@@ -2454,7 +2469,10 @@ var getScrollableParent = (element) => {
|
|
|
2454
2469
|
}
|
|
2455
2470
|
return null;
|
|
2456
2471
|
};
|
|
2457
|
-
var getElementsInViewportFromCollection = (
|
|
2472
|
+
var getElementsInViewportFromCollection = (elements, referenceElement) => {
|
|
2473
|
+
if (!referenceElement) {
|
|
2474
|
+
return elements.filter((element) => elementInViewport(element));
|
|
2475
|
+
}
|
|
2458
2476
|
const referenceIndex = elements.indexOf(referenceElement);
|
|
2459
2477
|
const upwardElements = [];
|
|
2460
2478
|
const downwardElements = [];
|
|
@@ -2476,6 +2494,15 @@ var getElementsInViewportFromCollection = (referenceElement, elements) => {
|
|
|
2476
2494
|
}
|
|
2477
2495
|
return [...upwardElements.reverse(), ...downwardElements];
|
|
2478
2496
|
};
|
|
2497
|
+
var requestAnimationFrame = (cb, times = 1) => {
|
|
2498
|
+
window.requestAnimationFrame(() => {
|
|
2499
|
+
if (times > 1) {
|
|
2500
|
+
requestAnimationFrame(cb, times - 1);
|
|
2501
|
+
} else {
|
|
2502
|
+
cb();
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
};
|
|
2479
2506
|
|
|
2480
2507
|
// src/formObject.ts
|
|
2481
2508
|
var import_lodash_es6 = require("lodash-es");
|
|
@@ -2504,6 +2531,41 @@ function parseKey(key) {
|
|
|
2504
2531
|
}
|
|
2505
2532
|
return path;
|
|
2506
2533
|
}
|
|
2534
|
+
function setNestedObject(obj, path, value) {
|
|
2535
|
+
let current = obj;
|
|
2536
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
2537
|
+
if (!(path[i] in current)) {
|
|
2538
|
+
current[path[i]] = {};
|
|
2539
|
+
}
|
|
2540
|
+
current = current[path[i]];
|
|
2541
|
+
}
|
|
2542
|
+
current[path[path.length - 1]] = value;
|
|
2543
|
+
}
|
|
2544
|
+
function objectHasSequentialNumericKeys(value) {
|
|
2545
|
+
const keys = Object.keys(value);
|
|
2546
|
+
const numericKeys = keys.filter((k) => /^\d+$/.test(k)).map(Number).sort((a, b) => a - b);
|
|
2547
|
+
return keys.length === numericKeys.length && numericKeys.length > 0 && numericKeys[0] === 0 && numericKeys.every((n, i) => n === i);
|
|
2548
|
+
}
|
|
2549
|
+
function convertSequentialObjectsToArrays(value) {
|
|
2550
|
+
if (Array.isArray(value)) {
|
|
2551
|
+
return value.map(convertSequentialObjectsToArrays);
|
|
2552
|
+
}
|
|
2553
|
+
if (typeof value !== "object" || value === null || isFile(value)) {
|
|
2554
|
+
return value;
|
|
2555
|
+
}
|
|
2556
|
+
if (objectHasSequentialNumericKeys(value)) {
|
|
2557
|
+
const result2 = [];
|
|
2558
|
+
for (let i = 0; i < Object.keys(value).length; i++) {
|
|
2559
|
+
result2[i] = convertSequentialObjectsToArrays(value[i]);
|
|
2560
|
+
}
|
|
2561
|
+
return result2;
|
|
2562
|
+
}
|
|
2563
|
+
const result = {};
|
|
2564
|
+
for (const key in value) {
|
|
2565
|
+
result[key] = convertSequentialObjectsToArrays(value[key]);
|
|
2566
|
+
}
|
|
2567
|
+
return result;
|
|
2568
|
+
}
|
|
2507
2569
|
function formDataToObject(source) {
|
|
2508
2570
|
const form = {};
|
|
2509
2571
|
for (const [key, value] of source.entries()) {
|
|
@@ -2516,14 +2578,17 @@ function formDataToObject(source) {
|
|
|
2516
2578
|
const existing = (0, import_lodash_es6.get)(form, arrayPath);
|
|
2517
2579
|
if (Array.isArray(existing)) {
|
|
2518
2580
|
existing.push(value);
|
|
2581
|
+
} else if (existing && typeof existing === "object" && !isFile(existing)) {
|
|
2582
|
+
const numericKeys = Object.keys(existing).filter((k) => /^\d+$/.test(k)).map(Number).sort((a, b) => a - b);
|
|
2583
|
+
(0, import_lodash_es6.set)(form, arrayPath, numericKeys.length > 0 ? [...numericKeys.map((k) => existing[k]), value] : [value]);
|
|
2519
2584
|
} else {
|
|
2520
2585
|
(0, import_lodash_es6.set)(form, arrayPath, [value]);
|
|
2521
2586
|
}
|
|
2522
2587
|
continue;
|
|
2523
2588
|
}
|
|
2524
|
-
(
|
|
2589
|
+
setNestedObject(form, path.map(String), value);
|
|
2525
2590
|
}
|
|
2526
|
-
return form;
|
|
2591
|
+
return convertSequentialObjectsToArrays(form);
|
|
2527
2592
|
}
|
|
2528
2593
|
|
|
2529
2594
|
// src/head.ts
|
|
@@ -2998,7 +3063,7 @@ var useInfiniteScrollQueryString = (options) => {
|
|
|
2998
3063
|
}
|
|
2999
3064
|
const pageMap = /* @__PURE__ */ new Map();
|
|
3000
3065
|
const elements = [...itemsElement.children];
|
|
3001
|
-
getElementsInViewportFromCollection(
|
|
3066
|
+
getElementsInViewportFromCollection(elements, itemElement).forEach((element) => {
|
|
3002
3067
|
const page2 = getPageFromElement(element) ?? "1";
|
|
3003
3068
|
if (pageMap.has(page2)) {
|
|
3004
3069
|
pageMap.set(page2, pageMap.get(page2) + 1);
|
|
@@ -3028,10 +3093,7 @@ var useInfiniteScrollPreservation = (options) => {
|
|
|
3028
3093
|
const scrollableContainer = options.getScrollableParent();
|
|
3029
3094
|
const itemsElement = options.getItemsElement();
|
|
3030
3095
|
currentScrollTop = scrollableContainer?.scrollTop || window.scrollY;
|
|
3031
|
-
const visibleElements = getElementsInViewportFromCollection(
|
|
3032
|
-
itemsElement.firstElementChild,
|
|
3033
|
-
[...itemsElement.children]
|
|
3034
|
-
);
|
|
3096
|
+
const visibleElements = getElementsInViewportFromCollection([...itemsElement.children]);
|
|
3035
3097
|
if (visibleElements.length > 0) {
|
|
3036
3098
|
referenceElement = visibleElements[0];
|
|
3037
3099
|
const containerRect = scrollableContainer?.getBoundingClientRect() || { top: 0 };
|
|
@@ -3068,7 +3130,7 @@ var useInfiniteScrollPreservation = (options) => {
|
|
|
3068
3130
|
}
|
|
3069
3131
|
restored = true;
|
|
3070
3132
|
};
|
|
3071
|
-
restore
|
|
3133
|
+
window.requestAnimationFrame(restore);
|
|
3072
3134
|
};
|
|
3073
3135
|
return {
|
|
3074
3136
|
captureScrollPosition,
|
|
@@ -3098,18 +3160,18 @@ function useInfiniteScroll(options) {
|
|
|
3098
3160
|
onBeforeUpdate: elementManager.processManuallyAddedElements,
|
|
3099
3161
|
// After successful request, tag new server content
|
|
3100
3162
|
onCompletePreviousRequest: (loadedPage) => {
|
|
3101
|
-
|
|
3163
|
+
options.onCompletePreviousRequest();
|
|
3164
|
+
requestAnimationFrame(() => {
|
|
3102
3165
|
elementManager.processServerLoadedElements(loadedPage);
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
});
|
|
3166
|
+
elementManager.refreshTriggers();
|
|
3167
|
+
}, 2);
|
|
3106
3168
|
},
|
|
3107
3169
|
onCompleteNextRequest: (loadedPage) => {
|
|
3108
|
-
|
|
3170
|
+
options.onCompleteNextRequest();
|
|
3171
|
+
requestAnimationFrame(() => {
|
|
3109
3172
|
elementManager.processServerLoadedElements(loadedPage);
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
});
|
|
3173
|
+
elementManager.refreshTriggers();
|
|
3174
|
+
}, 2);
|
|
3113
3175
|
}
|
|
3114
3176
|
});
|
|
3115
3177
|
const addScrollPreservationCallbacks = (reloadOptions) => {
|