@inertiajs/core 2.2.20 → 2.3.0
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 +126 -3
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +126 -3
- package/dist/index.js.map +4 -4
- package/package.json +2 -1
- package/types/index.d.ts +1 -0
- package/types/types.d.ts +20 -2
- package/types/useFormUtils.d.ts +47 -0
package/dist/index.esm.js
CHANGED
|
@@ -539,6 +539,14 @@ var PrefetchedRequests = class {
|
|
|
539
539
|
prefetched.response.then((response) => {
|
|
540
540
|
const pageResponse = response.getPageResponse();
|
|
541
541
|
page.mergeOncePropsIntoResponse(pageResponse, { force: true });
|
|
542
|
+
for (const [group, deferredProps] of Object.entries(pageResponse.deferredProps ?? {})) {
|
|
543
|
+
const remaining = deferredProps.filter((prop) => pageResponse.props[prop] === void 0);
|
|
544
|
+
if (remaining.length > 0) {
|
|
545
|
+
pageResponse.deferredProps[group] = remaining;
|
|
546
|
+
} else {
|
|
547
|
+
delete pageResponse.deferredProps[group];
|
|
548
|
+
}
|
|
549
|
+
}
|
|
542
550
|
const oncePropExpiresIn = this.getShortestOncePropTtl(pageResponse);
|
|
543
551
|
if (oncePropExpiresIn === null) {
|
|
544
552
|
return;
|
|
@@ -1880,6 +1888,12 @@ var Response = class _Response {
|
|
|
1880
1888
|
...pageResponse.scrollProps || {}
|
|
1881
1889
|
};
|
|
1882
1890
|
}
|
|
1891
|
+
if (page.hasOnceProps()) {
|
|
1892
|
+
pageResponse.onceProps = {
|
|
1893
|
+
...page.get().onceProps || {},
|
|
1894
|
+
...pageResponse.onceProps || {}
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1883
1897
|
}
|
|
1884
1898
|
mergeOrMatchItems(existingItems, newItems, matchProp, matchPropsOn, shouldAppend = true) {
|
|
1885
1899
|
const items = Array.isArray(existingItems) ? existingItems : [];
|
|
@@ -2040,7 +2054,12 @@ var Request = class _Request {
|
|
|
2040
2054
|
if (page2.version) {
|
|
2041
2055
|
headers["X-Inertia-Version"] = page2.version;
|
|
2042
2056
|
}
|
|
2043
|
-
const onceProps = Object.entries(page2.onceProps || {}).filter(([, onceProp]) =>
|
|
2057
|
+
const onceProps = Object.entries(page2.onceProps || {}).filter(([, onceProp]) => {
|
|
2058
|
+
if (page2.props[onceProp.prop] === void 0) {
|
|
2059
|
+
return false;
|
|
2060
|
+
}
|
|
2061
|
+
return !onceProp.expiresAt || onceProp.expiresAt > Date.now();
|
|
2062
|
+
}).map(([key]) => key);
|
|
2044
2063
|
if (onceProps.length > 0) {
|
|
2045
2064
|
headers["X-Inertia-Except-Once-Props"] = onceProps.join(",");
|
|
2046
2065
|
}
|
|
@@ -2450,6 +2469,108 @@ var Router = class {
|
|
|
2450
2469
|
}
|
|
2451
2470
|
};
|
|
2452
2471
|
|
|
2472
|
+
// src/useFormUtils.ts
|
|
2473
|
+
var UseFormUtils = class {
|
|
2474
|
+
/**
|
|
2475
|
+
* Creates a callback that returns a UrlMethodPair.
|
|
2476
|
+
*
|
|
2477
|
+
* createWayfinderCallback(urlMethodPair)
|
|
2478
|
+
* createWayfinderCallback(method, url)
|
|
2479
|
+
* createWayfinderCallback(() => urlMethodPair)
|
|
2480
|
+
* createWayfinderCallback(() => method, () => url)
|
|
2481
|
+
*/
|
|
2482
|
+
static createWayfinderCallback(...args) {
|
|
2483
|
+
return () => {
|
|
2484
|
+
if (args.length === 1) {
|
|
2485
|
+
return isUrlMethodPair(args[0]) ? args[0] : args[0]();
|
|
2486
|
+
}
|
|
2487
|
+
return {
|
|
2488
|
+
method: typeof args[0] === "function" ? args[0]() : args[0],
|
|
2489
|
+
url: typeof args[1] === "function" ? args[1]() : args[1]
|
|
2490
|
+
};
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Parses all useForm() arguments into { rememberKey, data, precognitionEndpoint }.
|
|
2495
|
+
*
|
|
2496
|
+
* useForm(data)
|
|
2497
|
+
* useForm(rememberKey, data)
|
|
2498
|
+
* useForm(method, url, data)
|
|
2499
|
+
* useForm(urlMethodPair, data)
|
|
2500
|
+
*
|
|
2501
|
+
*/
|
|
2502
|
+
static parseUseFormArguments(...args) {
|
|
2503
|
+
if (args.length === 1) {
|
|
2504
|
+
return {
|
|
2505
|
+
rememberKey: null,
|
|
2506
|
+
data: args[0],
|
|
2507
|
+
precognitionEndpoint: null
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
if (args.length === 2) {
|
|
2511
|
+
if (typeof args[0] === "string") {
|
|
2512
|
+
return {
|
|
2513
|
+
rememberKey: args[0],
|
|
2514
|
+
data: args[1],
|
|
2515
|
+
precognitionEndpoint: null
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
return {
|
|
2519
|
+
rememberKey: null,
|
|
2520
|
+
data: args[1],
|
|
2521
|
+
precognitionEndpoint: this.createWayfinderCallback(args[0])
|
|
2522
|
+
};
|
|
2523
|
+
}
|
|
2524
|
+
return {
|
|
2525
|
+
rememberKey: null,
|
|
2526
|
+
data: args[2],
|
|
2527
|
+
precognitionEndpoint: this.createWayfinderCallback(args[0], args[1])
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
/**
|
|
2531
|
+
* Parses all submission arguments into { method, url, options }.
|
|
2532
|
+
* It uses the Precognition endpoint if no explicit method/url are provided.
|
|
2533
|
+
*
|
|
2534
|
+
* form.submit(method, url)
|
|
2535
|
+
* form.submit(method, url, options)
|
|
2536
|
+
* form.submit(urlMethodPair)
|
|
2537
|
+
* form.submit(urlMethodPair, options)
|
|
2538
|
+
* form.submit()
|
|
2539
|
+
* form.submit(options)
|
|
2540
|
+
*/
|
|
2541
|
+
static parseSubmitArguments(args, precognitionEndpoint) {
|
|
2542
|
+
if (args.length === 3 || args.length === 2 && typeof args[0] === "string") {
|
|
2543
|
+
return { method: args[0], url: args[1], options: args[2] ?? {} };
|
|
2544
|
+
}
|
|
2545
|
+
if (isUrlMethodPair(args[0])) {
|
|
2546
|
+
return { ...args[0], options: args[1] ?? {} };
|
|
2547
|
+
}
|
|
2548
|
+
return { ...precognitionEndpoint(), options: args[0] ?? {} };
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Merges headers into the Precognition validate() arguments.
|
|
2552
|
+
*/
|
|
2553
|
+
static mergeHeadersForValidation(field, config2, headers) {
|
|
2554
|
+
const merge = (config3) => {
|
|
2555
|
+
config3.headers = {
|
|
2556
|
+
...headers ?? {},
|
|
2557
|
+
...config3.headers ?? {}
|
|
2558
|
+
};
|
|
2559
|
+
return config3;
|
|
2560
|
+
};
|
|
2561
|
+
if (field && typeof field === "object" && !("target" in field)) {
|
|
2562
|
+
field = merge(field);
|
|
2563
|
+
} else if (config2 && typeof config2 === "object") {
|
|
2564
|
+
config2 = merge(config2);
|
|
2565
|
+
} else if (typeof field === "string") {
|
|
2566
|
+
config2 = merge(config2 ?? {});
|
|
2567
|
+
} else {
|
|
2568
|
+
field = merge(field ?? {});
|
|
2569
|
+
}
|
|
2570
|
+
return [field, config2];
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
|
|
2453
2574
|
// src/domUtils.ts
|
|
2454
2575
|
var elementInViewport = (el) => {
|
|
2455
2576
|
if (el.offsetParent === null) {
|
|
@@ -3758,7 +3879,8 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3758
3879
|
if (!formElement) {
|
|
3759
3880
|
return;
|
|
3760
3881
|
}
|
|
3761
|
-
|
|
3882
|
+
const resetEntireForm = !fieldNames || fieldNames.length === 0;
|
|
3883
|
+
if (resetEntireForm) {
|
|
3762
3884
|
const formData = new FormData(formElement);
|
|
3763
3885
|
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
3764
3886
|
fieldNames = [.../* @__PURE__ */ new Set([...defaults.keys(), ...formData.keys(), ...formElementNames])];
|
|
@@ -3772,7 +3894,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3772
3894
|
}
|
|
3773
3895
|
}
|
|
3774
3896
|
});
|
|
3775
|
-
if (hasChanged) {
|
|
3897
|
+
if (hasChanged && resetEntireForm) {
|
|
3776
3898
|
formElement.dispatchEvent(new Event("reset", { bubbles: true }));
|
|
3777
3899
|
}
|
|
3778
3900
|
}
|
|
@@ -3780,6 +3902,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3780
3902
|
// src/index.ts
|
|
3781
3903
|
var router = new Router();
|
|
3782
3904
|
export {
|
|
3905
|
+
UseFormUtils,
|
|
3783
3906
|
config,
|
|
3784
3907
|
createHeadManager,
|
|
3785
3908
|
formDataToObject,
|