@inertiajs/core 2.2.21 → 2.3.1
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 +114 -9
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +114 -9
- package/dist/index.js.map +4 -4
- package/package.json +2 -1
- package/types/index.d.ts +1 -0
- package/types/scroll.d.ts +1 -0
- package/types/types.d.ts +18 -0
- package/types/useFormUtils.d.ts +47 -0
package/dist/index.esm.js
CHANGED
|
@@ -574,12 +574,13 @@ var prefetchedRequests = new PrefetchedRequests();
|
|
|
574
574
|
// src/scroll.ts
|
|
575
575
|
var Scroll = class {
|
|
576
576
|
static save() {
|
|
577
|
-
history.saveScrollPositions(
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
577
|
+
history.saveScrollPositions(this.getScrollRegions());
|
|
578
|
+
}
|
|
579
|
+
static getScrollRegions() {
|
|
580
|
+
return Array.from(this.regions()).map((region) => ({
|
|
581
|
+
top: region.scrollTop,
|
|
582
|
+
left: region.scrollLeft
|
|
583
|
+
}));
|
|
583
584
|
}
|
|
584
585
|
static regions() {
|
|
585
586
|
return document.querySelectorAll("[scroll-region]");
|
|
@@ -818,7 +819,7 @@ var CurrentPage = class {
|
|
|
818
819
|
page2.rememberedState ?? (page2.rememberedState = {});
|
|
819
820
|
const isServer2 = typeof window === "undefined";
|
|
820
821
|
const location = !isServer2 ? window.location : new URL(page2.url);
|
|
821
|
-
const scrollRegions = !isServer2 && preserveScroll ?
|
|
822
|
+
const scrollRegions = !isServer2 && preserveScroll ? Scroll.getScrollRegions() : [];
|
|
822
823
|
replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), location);
|
|
823
824
|
return new Promise((resolve) => {
|
|
824
825
|
replace ? history.replaceState(page2, () => resolve(null)) : history.pushState(page2, () => resolve(null));
|
|
@@ -2469,6 +2470,108 @@ var Router = class {
|
|
|
2469
2470
|
}
|
|
2470
2471
|
};
|
|
2471
2472
|
|
|
2473
|
+
// src/useFormUtils.ts
|
|
2474
|
+
var UseFormUtils = class {
|
|
2475
|
+
/**
|
|
2476
|
+
* Creates a callback that returns a UrlMethodPair.
|
|
2477
|
+
*
|
|
2478
|
+
* createWayfinderCallback(urlMethodPair)
|
|
2479
|
+
* createWayfinderCallback(method, url)
|
|
2480
|
+
* createWayfinderCallback(() => urlMethodPair)
|
|
2481
|
+
* createWayfinderCallback(() => method, () => url)
|
|
2482
|
+
*/
|
|
2483
|
+
static createWayfinderCallback(...args) {
|
|
2484
|
+
return () => {
|
|
2485
|
+
if (args.length === 1) {
|
|
2486
|
+
return isUrlMethodPair(args[0]) ? args[0] : args[0]();
|
|
2487
|
+
}
|
|
2488
|
+
return {
|
|
2489
|
+
method: typeof args[0] === "function" ? args[0]() : args[0],
|
|
2490
|
+
url: typeof args[1] === "function" ? args[1]() : args[1]
|
|
2491
|
+
};
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* Parses all useForm() arguments into { rememberKey, data, precognitionEndpoint }.
|
|
2496
|
+
*
|
|
2497
|
+
* useForm(data)
|
|
2498
|
+
* useForm(rememberKey, data)
|
|
2499
|
+
* useForm(method, url, data)
|
|
2500
|
+
* useForm(urlMethodPair, data)
|
|
2501
|
+
*
|
|
2502
|
+
*/
|
|
2503
|
+
static parseUseFormArguments(...args) {
|
|
2504
|
+
if (args.length === 1) {
|
|
2505
|
+
return {
|
|
2506
|
+
rememberKey: null,
|
|
2507
|
+
data: args[0],
|
|
2508
|
+
precognitionEndpoint: null
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
if (args.length === 2) {
|
|
2512
|
+
if (typeof args[0] === "string") {
|
|
2513
|
+
return {
|
|
2514
|
+
rememberKey: args[0],
|
|
2515
|
+
data: args[1],
|
|
2516
|
+
precognitionEndpoint: null
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
return {
|
|
2520
|
+
rememberKey: null,
|
|
2521
|
+
data: args[1],
|
|
2522
|
+
precognitionEndpoint: this.createWayfinderCallback(args[0])
|
|
2523
|
+
};
|
|
2524
|
+
}
|
|
2525
|
+
return {
|
|
2526
|
+
rememberKey: null,
|
|
2527
|
+
data: args[2],
|
|
2528
|
+
precognitionEndpoint: this.createWayfinderCallback(args[0], args[1])
|
|
2529
|
+
};
|
|
2530
|
+
}
|
|
2531
|
+
/**
|
|
2532
|
+
* Parses all submission arguments into { method, url, options }.
|
|
2533
|
+
* It uses the Precognition endpoint if no explicit method/url are provided.
|
|
2534
|
+
*
|
|
2535
|
+
* form.submit(method, url)
|
|
2536
|
+
* form.submit(method, url, options)
|
|
2537
|
+
* form.submit(urlMethodPair)
|
|
2538
|
+
* form.submit(urlMethodPair, options)
|
|
2539
|
+
* form.submit()
|
|
2540
|
+
* form.submit(options)
|
|
2541
|
+
*/
|
|
2542
|
+
static parseSubmitArguments(args, precognitionEndpoint) {
|
|
2543
|
+
if (args.length === 3 || args.length === 2 && typeof args[0] === "string") {
|
|
2544
|
+
return { method: args[0], url: args[1], options: args[2] ?? {} };
|
|
2545
|
+
}
|
|
2546
|
+
if (isUrlMethodPair(args[0])) {
|
|
2547
|
+
return { ...args[0], options: args[1] ?? {} };
|
|
2548
|
+
}
|
|
2549
|
+
return { ...precognitionEndpoint(), options: args[0] ?? {} };
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Merges headers into the Precognition validate() arguments.
|
|
2553
|
+
*/
|
|
2554
|
+
static mergeHeadersForValidation(field, config2, headers) {
|
|
2555
|
+
const merge = (config3) => {
|
|
2556
|
+
config3.headers = {
|
|
2557
|
+
...headers ?? {},
|
|
2558
|
+
...config3.headers ?? {}
|
|
2559
|
+
};
|
|
2560
|
+
return config3;
|
|
2561
|
+
};
|
|
2562
|
+
if (field && typeof field === "object" && !("target" in field)) {
|
|
2563
|
+
field = merge(field);
|
|
2564
|
+
} else if (config2 && typeof config2 === "object") {
|
|
2565
|
+
config2 = merge(config2);
|
|
2566
|
+
} else if (typeof field === "string") {
|
|
2567
|
+
config2 = merge(config2 ?? {});
|
|
2568
|
+
} else {
|
|
2569
|
+
field = merge(field ?? {});
|
|
2570
|
+
}
|
|
2571
|
+
return [field, config2];
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
|
|
2472
2575
|
// src/domUtils.ts
|
|
2473
2576
|
var elementInViewport = (el) => {
|
|
2474
2577
|
if (el.offsetParent === null) {
|
|
@@ -3777,7 +3880,8 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3777
3880
|
if (!formElement) {
|
|
3778
3881
|
return;
|
|
3779
3882
|
}
|
|
3780
|
-
|
|
3883
|
+
const resetEntireForm = !fieldNames || fieldNames.length === 0;
|
|
3884
|
+
if (resetEntireForm) {
|
|
3781
3885
|
const formData = new FormData(formElement);
|
|
3782
3886
|
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
3783
3887
|
fieldNames = [.../* @__PURE__ */ new Set([...defaults.keys(), ...formData.keys(), ...formElementNames])];
|
|
@@ -3791,7 +3895,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3791
3895
|
}
|
|
3792
3896
|
}
|
|
3793
3897
|
});
|
|
3794
|
-
if (hasChanged) {
|
|
3898
|
+
if (hasChanged && resetEntireForm) {
|
|
3795
3899
|
formElement.dispatchEvent(new Event("reset", { bubbles: true }));
|
|
3796
3900
|
}
|
|
3797
3901
|
}
|
|
@@ -3799,6 +3903,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3799
3903
|
// src/index.ts
|
|
3800
3904
|
var router = new Router();
|
|
3801
3905
|
export {
|
|
3906
|
+
UseFormUtils,
|
|
3802
3907
|
config,
|
|
3803
3908
|
createHeadManager,
|
|
3804
3909
|
formDataToObject,
|