@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.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
UseFormUtils: () => UseFormUtils,
|
|
33
34
|
config: () => config,
|
|
34
35
|
createHeadManager: () => createHeadManager,
|
|
35
36
|
formDataToObject: () => formDataToObject,
|
|
@@ -595,6 +596,14 @@ var PrefetchedRequests = class {
|
|
|
595
596
|
prefetched.response.then((response) => {
|
|
596
597
|
const pageResponse = response.getPageResponse();
|
|
597
598
|
page.mergeOncePropsIntoResponse(pageResponse, { force: true });
|
|
599
|
+
for (const [group, deferredProps] of Object.entries(pageResponse.deferredProps ?? {})) {
|
|
600
|
+
const remaining = deferredProps.filter((prop) => pageResponse.props[prop] === void 0);
|
|
601
|
+
if (remaining.length > 0) {
|
|
602
|
+
pageResponse.deferredProps[group] = remaining;
|
|
603
|
+
} else {
|
|
604
|
+
delete pageResponse.deferredProps[group];
|
|
605
|
+
}
|
|
606
|
+
}
|
|
598
607
|
const oncePropExpiresIn = this.getShortestOncePropTtl(pageResponse);
|
|
599
608
|
if (oncePropExpiresIn === null) {
|
|
600
609
|
return;
|
|
@@ -1936,6 +1945,12 @@ var Response = class _Response {
|
|
|
1936
1945
|
...pageResponse.scrollProps || {}
|
|
1937
1946
|
};
|
|
1938
1947
|
}
|
|
1948
|
+
if (page.hasOnceProps()) {
|
|
1949
|
+
pageResponse.onceProps = {
|
|
1950
|
+
...page.get().onceProps || {},
|
|
1951
|
+
...pageResponse.onceProps || {}
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1939
1954
|
}
|
|
1940
1955
|
mergeOrMatchItems(existingItems, newItems, matchProp, matchPropsOn, shouldAppend = true) {
|
|
1941
1956
|
const items = Array.isArray(existingItems) ? existingItems : [];
|
|
@@ -2096,7 +2111,12 @@ var Request = class _Request {
|
|
|
2096
2111
|
if (page2.version) {
|
|
2097
2112
|
headers["X-Inertia-Version"] = page2.version;
|
|
2098
2113
|
}
|
|
2099
|
-
const onceProps = Object.entries(page2.onceProps || {}).filter(([, onceProp]) =>
|
|
2114
|
+
const onceProps = Object.entries(page2.onceProps || {}).filter(([, onceProp]) => {
|
|
2115
|
+
if (page2.props[onceProp.prop] === void 0) {
|
|
2116
|
+
return false;
|
|
2117
|
+
}
|
|
2118
|
+
return !onceProp.expiresAt || onceProp.expiresAt > Date.now();
|
|
2119
|
+
}).map(([key]) => key);
|
|
2100
2120
|
if (onceProps.length > 0) {
|
|
2101
2121
|
headers["X-Inertia-Except-Once-Props"] = onceProps.join(",");
|
|
2102
2122
|
}
|
|
@@ -2506,6 +2526,108 @@ var Router = class {
|
|
|
2506
2526
|
}
|
|
2507
2527
|
};
|
|
2508
2528
|
|
|
2529
|
+
// src/useFormUtils.ts
|
|
2530
|
+
var UseFormUtils = class {
|
|
2531
|
+
/**
|
|
2532
|
+
* Creates a callback that returns a UrlMethodPair.
|
|
2533
|
+
*
|
|
2534
|
+
* createWayfinderCallback(urlMethodPair)
|
|
2535
|
+
* createWayfinderCallback(method, url)
|
|
2536
|
+
* createWayfinderCallback(() => urlMethodPair)
|
|
2537
|
+
* createWayfinderCallback(() => method, () => url)
|
|
2538
|
+
*/
|
|
2539
|
+
static createWayfinderCallback(...args) {
|
|
2540
|
+
return () => {
|
|
2541
|
+
if (args.length === 1) {
|
|
2542
|
+
return isUrlMethodPair(args[0]) ? args[0] : args[0]();
|
|
2543
|
+
}
|
|
2544
|
+
return {
|
|
2545
|
+
method: typeof args[0] === "function" ? args[0]() : args[0],
|
|
2546
|
+
url: typeof args[1] === "function" ? args[1]() : args[1]
|
|
2547
|
+
};
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Parses all useForm() arguments into { rememberKey, data, precognitionEndpoint }.
|
|
2552
|
+
*
|
|
2553
|
+
* useForm(data)
|
|
2554
|
+
* useForm(rememberKey, data)
|
|
2555
|
+
* useForm(method, url, data)
|
|
2556
|
+
* useForm(urlMethodPair, data)
|
|
2557
|
+
*
|
|
2558
|
+
*/
|
|
2559
|
+
static parseUseFormArguments(...args) {
|
|
2560
|
+
if (args.length === 1) {
|
|
2561
|
+
return {
|
|
2562
|
+
rememberKey: null,
|
|
2563
|
+
data: args[0],
|
|
2564
|
+
precognitionEndpoint: null
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
if (args.length === 2) {
|
|
2568
|
+
if (typeof args[0] === "string") {
|
|
2569
|
+
return {
|
|
2570
|
+
rememberKey: args[0],
|
|
2571
|
+
data: args[1],
|
|
2572
|
+
precognitionEndpoint: null
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
return {
|
|
2576
|
+
rememberKey: null,
|
|
2577
|
+
data: args[1],
|
|
2578
|
+
precognitionEndpoint: this.createWayfinderCallback(args[0])
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
return {
|
|
2582
|
+
rememberKey: null,
|
|
2583
|
+
data: args[2],
|
|
2584
|
+
precognitionEndpoint: this.createWayfinderCallback(args[0], args[1])
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
* Parses all submission arguments into { method, url, options }.
|
|
2589
|
+
* It uses the Precognition endpoint if no explicit method/url are provided.
|
|
2590
|
+
*
|
|
2591
|
+
* form.submit(method, url)
|
|
2592
|
+
* form.submit(method, url, options)
|
|
2593
|
+
* form.submit(urlMethodPair)
|
|
2594
|
+
* form.submit(urlMethodPair, options)
|
|
2595
|
+
* form.submit()
|
|
2596
|
+
* form.submit(options)
|
|
2597
|
+
*/
|
|
2598
|
+
static parseSubmitArguments(args, precognitionEndpoint) {
|
|
2599
|
+
if (args.length === 3 || args.length === 2 && typeof args[0] === "string") {
|
|
2600
|
+
return { method: args[0], url: args[1], options: args[2] ?? {} };
|
|
2601
|
+
}
|
|
2602
|
+
if (isUrlMethodPair(args[0])) {
|
|
2603
|
+
return { ...args[0], options: args[1] ?? {} };
|
|
2604
|
+
}
|
|
2605
|
+
return { ...precognitionEndpoint(), options: args[0] ?? {} };
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Merges headers into the Precognition validate() arguments.
|
|
2609
|
+
*/
|
|
2610
|
+
static mergeHeadersForValidation(field, config2, headers) {
|
|
2611
|
+
const merge = (config3) => {
|
|
2612
|
+
config3.headers = {
|
|
2613
|
+
...headers ?? {},
|
|
2614
|
+
...config3.headers ?? {}
|
|
2615
|
+
};
|
|
2616
|
+
return config3;
|
|
2617
|
+
};
|
|
2618
|
+
if (field && typeof field === "object" && !("target" in field)) {
|
|
2619
|
+
field = merge(field);
|
|
2620
|
+
} else if (config2 && typeof config2 === "object") {
|
|
2621
|
+
config2 = merge(config2);
|
|
2622
|
+
} else if (typeof field === "string") {
|
|
2623
|
+
config2 = merge(config2 ?? {});
|
|
2624
|
+
} else {
|
|
2625
|
+
field = merge(field ?? {});
|
|
2626
|
+
}
|
|
2627
|
+
return [field, config2];
|
|
2628
|
+
}
|
|
2629
|
+
};
|
|
2630
|
+
|
|
2509
2631
|
// src/domUtils.ts
|
|
2510
2632
|
var elementInViewport = (el) => {
|
|
2511
2633
|
if (el.offsetParent === null) {
|
|
@@ -3814,7 +3936,8 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3814
3936
|
if (!formElement) {
|
|
3815
3937
|
return;
|
|
3816
3938
|
}
|
|
3817
|
-
|
|
3939
|
+
const resetEntireForm = !fieldNames || fieldNames.length === 0;
|
|
3940
|
+
if (resetEntireForm) {
|
|
3818
3941
|
const formData = new FormData(formElement);
|
|
3819
3942
|
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
3820
3943
|
fieldNames = [.../* @__PURE__ */ new Set([...defaults.keys(), ...formData.keys(), ...formElementNames])];
|
|
@@ -3828,7 +3951,7 @@ function resetFormFields(formElement, defaults, fieldNames) {
|
|
|
3828
3951
|
}
|
|
3829
3952
|
}
|
|
3830
3953
|
});
|
|
3831
|
-
if (hasChanged) {
|
|
3954
|
+
if (hasChanged && resetEntireForm) {
|
|
3832
3955
|
formElement.dispatchEvent(new Event("reset", { bubbles: true }));
|
|
3833
3956
|
}
|
|
3834
3957
|
}
|