@inertiajs/core 2.1.1 → 2.1.3
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 +183 -154
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +187 -158
- package/dist/index.js.map +4 -4
- package/dist/server.esm.js +4 -2
- package/dist/server.esm.js.map +2 -2
- package/dist/server.js +4 -2
- package/dist/server.js.map +2 -2
- package/package.json +9 -5
- package/types/index.d.ts +3 -3
- package/types/navigationEvents.d.ts +12 -0
- package/types/prefetched.d.ts +2 -1
- package/types/router.d.ts +14 -13
- package/types/types.d.ts +15 -10
- package/types/url.d.ts +2 -1
- package/types/shouldIntercept.d.ts +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -384,6 +384,9 @@ var setHashIfSameUrl = (originUrl, destinationUrl) => {
|
|
|
384
384
|
var isSameUrlWithoutHash = (url1, url2) => {
|
|
385
385
|
return urlWithoutHash(url1).href === urlWithoutHash(url2).href;
|
|
386
386
|
};
|
|
387
|
+
function isUrlMethodPair(href) {
|
|
388
|
+
return href !== null && typeof href === "object" && href !== void 0 && "url" in href && "method" in href;
|
|
389
|
+
}
|
|
387
390
|
|
|
388
391
|
// src/page.ts
|
|
389
392
|
var CurrentPage = class {
|
|
@@ -605,12 +608,10 @@ var History = class {
|
|
|
605
608
|
if (!window.history.state?.page) {
|
|
606
609
|
return;
|
|
607
610
|
}
|
|
608
|
-
this.doReplaceState(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
);
|
|
611
|
+
this.doReplaceState({
|
|
612
|
+
page: window.history.state.page,
|
|
613
|
+
scrollRegions
|
|
614
|
+
});
|
|
614
615
|
});
|
|
615
616
|
});
|
|
616
617
|
}
|
|
@@ -620,12 +621,10 @@ var History = class {
|
|
|
620
621
|
if (!window.history.state?.page) {
|
|
621
622
|
return;
|
|
622
623
|
}
|
|
623
|
-
this.doReplaceState(
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
628
|
-
);
|
|
624
|
+
this.doReplaceState({
|
|
625
|
+
page: window.history.state.page,
|
|
626
|
+
documentScrollPosition: scrollRegion
|
|
627
|
+
});
|
|
629
628
|
});
|
|
630
629
|
});
|
|
631
630
|
}
|
|
@@ -946,7 +945,7 @@ var Polls = class {
|
|
|
946
945
|
var polls = new Polls();
|
|
947
946
|
|
|
948
947
|
// src/prefetched.ts
|
|
949
|
-
import { cloneDeep } from "es
|
|
948
|
+
import { cloneDeep } from "lodash-es";
|
|
950
949
|
|
|
951
950
|
// src/objectUtils.ts
|
|
952
951
|
var objectsAreEqual = (obj1, obj2, excludeKeys) => {
|
|
@@ -1005,7 +1004,7 @@ var PrefetchedRequests = class {
|
|
|
1005
1004
|
this.removalTimers = [];
|
|
1006
1005
|
this.currentUseId = null;
|
|
1007
1006
|
}
|
|
1008
|
-
add(params, sendFunc, { cacheFor }) {
|
|
1007
|
+
add(params, sendFunc, { cacheFor, cacheTags }) {
|
|
1009
1008
|
const inFlight = this.findInFlight(params);
|
|
1010
1009
|
if (inFlight) {
|
|
1011
1010
|
return Promise.resolve();
|
|
@@ -1050,7 +1049,8 @@ var PrefetchedRequests = class {
|
|
|
1050
1049
|
response: promise,
|
|
1051
1050
|
singleUse: expires === 0,
|
|
1052
1051
|
timestamp: Date.now(),
|
|
1053
|
-
inFlight: false
|
|
1052
|
+
inFlight: false,
|
|
1053
|
+
tags: Array.isArray(cacheTags) ? cacheTags : [cacheTags]
|
|
1054
1054
|
});
|
|
1055
1055
|
this.scheduleForRemoval(params, expires);
|
|
1056
1056
|
this.removeFromInFlight(params);
|
|
@@ -1072,6 +1072,11 @@ var PrefetchedRequests = class {
|
|
|
1072
1072
|
});
|
|
1073
1073
|
this.removalTimers = [];
|
|
1074
1074
|
}
|
|
1075
|
+
removeByTags(tags) {
|
|
1076
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
1077
|
+
return !prefetched.tags.some((tag) => tags.includes(tag));
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1075
1080
|
remove(params) {
|
|
1076
1081
|
this.cached = this.cached.filter((prefetched) => {
|
|
1077
1082
|
return !this.paramsAreEqual(prefetched.params, params);
|
|
@@ -1421,6 +1426,7 @@ var Response = class _Response {
|
|
|
1421
1426
|
fireErrorEvent(scopedErrors);
|
|
1422
1427
|
return this.requestParams.all().onError(scopedErrors);
|
|
1423
1428
|
}
|
|
1429
|
+
router.flushByCacheTags(this.requestParams.all().invalidateCacheTags || []);
|
|
1424
1430
|
fireSuccessEvent(page.get());
|
|
1425
1431
|
await this.requestParams.all().onSuccess(page.get());
|
|
1426
1432
|
history.preserveUrl = false;
|
|
@@ -1863,11 +1869,15 @@ var Router = class {
|
|
|
1863
1869
|
flushAll() {
|
|
1864
1870
|
prefetchedRequests.removeAll();
|
|
1865
1871
|
}
|
|
1872
|
+
flushByCacheTags(tags) {
|
|
1873
|
+
prefetchedRequests.removeByTags(Array.isArray(tags) ? tags : [tags]);
|
|
1874
|
+
}
|
|
1866
1875
|
getPrefetching(href, options = {}) {
|
|
1867
1876
|
return prefetchedRequests.findInFlight(this.getPrefetchParams(href, options));
|
|
1868
1877
|
}
|
|
1869
|
-
prefetch(href, options = {},
|
|
1870
|
-
|
|
1878
|
+
prefetch(href, options = {}, prefetchOptions = {}) {
|
|
1879
|
+
const method = options.method ?? (isUrlMethodPair(href) ? href.method : "get");
|
|
1880
|
+
if (method !== "get") {
|
|
1871
1881
|
throw new Error("Prefetch requests must use the GET method");
|
|
1872
1882
|
}
|
|
1873
1883
|
const visit = this.getPendingVisit(href, {
|
|
@@ -1909,7 +1919,11 @@ var Router = class {
|
|
|
1909
1919
|
(params) => {
|
|
1910
1920
|
this.asyncRequestStream.send(Request.create(params, page.get()));
|
|
1911
1921
|
},
|
|
1912
|
-
{
|
|
1922
|
+
{
|
|
1923
|
+
cacheFor: 3e4,
|
|
1924
|
+
cacheTags: [],
|
|
1925
|
+
...prefetchOptions
|
|
1926
|
+
}
|
|
1913
1927
|
);
|
|
1914
1928
|
});
|
|
1915
1929
|
}
|
|
@@ -1964,6 +1978,11 @@ var Router = class {
|
|
|
1964
1978
|
};
|
|
1965
1979
|
}
|
|
1966
1980
|
getPendingVisit(href, options, pendingVisitOptions = {}) {
|
|
1981
|
+
if (isUrlMethodPair(href)) {
|
|
1982
|
+
const urlMethodPair = href;
|
|
1983
|
+
href = urlMethodPair.url;
|
|
1984
|
+
options.method = options.method ?? urlMethodPair.method;
|
|
1985
|
+
}
|
|
1967
1986
|
const mergedOptions = {
|
|
1968
1987
|
method: "get",
|
|
1969
1988
|
data: {},
|
|
@@ -1982,6 +2001,7 @@ var Router = class {
|
|
|
1982
2001
|
reset: [],
|
|
1983
2002
|
preserveUrl: false,
|
|
1984
2003
|
prefetch: false,
|
|
2004
|
+
invalidateCacheTags: [],
|
|
1985
2005
|
...options
|
|
1986
2006
|
};
|
|
1987
2007
|
const [url, _data] = transformUrlAndData(
|
|
@@ -2040,7 +2060,7 @@ var Router = class {
|
|
|
2040
2060
|
};
|
|
2041
2061
|
|
|
2042
2062
|
// src/formObject.ts
|
|
2043
|
-
import { get, set } from "es
|
|
2063
|
+
import { get, set } from "lodash-es";
|
|
2044
2064
|
function undotKey(key) {
|
|
2045
2065
|
if (!key.includes(".")) {
|
|
2046
2066
|
return key;
|
|
@@ -2088,137 +2108,6 @@ function formDataToObject(source) {
|
|
|
2088
2108
|
return form;
|
|
2089
2109
|
}
|
|
2090
2110
|
|
|
2091
|
-
// src/resetFormFields.ts
|
|
2092
|
-
function isFormElement(element) {
|
|
2093
|
-
return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
|
|
2094
|
-
}
|
|
2095
|
-
function resetInputElement(input, defaultValues) {
|
|
2096
|
-
const oldValue = input.value;
|
|
2097
|
-
const oldChecked = input.checked;
|
|
2098
|
-
switch (input.type.toLowerCase()) {
|
|
2099
|
-
case "checkbox":
|
|
2100
|
-
input.checked = defaultValues.includes(input.value);
|
|
2101
|
-
break;
|
|
2102
|
-
case "radio":
|
|
2103
|
-
input.checked = defaultValues[0] === input.value;
|
|
2104
|
-
break;
|
|
2105
|
-
case "file":
|
|
2106
|
-
input.value = "";
|
|
2107
|
-
break;
|
|
2108
|
-
case "button":
|
|
2109
|
-
case "submit":
|
|
2110
|
-
case "reset":
|
|
2111
|
-
case "image":
|
|
2112
|
-
break;
|
|
2113
|
-
default:
|
|
2114
|
-
input.value = defaultValues[0] !== null && defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2115
|
-
}
|
|
2116
|
-
return input.value !== oldValue || input.checked !== oldChecked;
|
|
2117
|
-
}
|
|
2118
|
-
function resetSelectElement(select, defaultValues) {
|
|
2119
|
-
const oldValue = select.value;
|
|
2120
|
-
const oldSelectedOptions = Array.from(select.selectedOptions).map((opt) => opt.value);
|
|
2121
|
-
if (select.multiple) {
|
|
2122
|
-
const defaultStrings = defaultValues.map((value) => String(value));
|
|
2123
|
-
Array.from(select.options).forEach((option) => {
|
|
2124
|
-
option.selected = defaultStrings.includes(option.value);
|
|
2125
|
-
});
|
|
2126
|
-
} else {
|
|
2127
|
-
select.value = defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2128
|
-
}
|
|
2129
|
-
const newSelectedOptions = Array.from(select.selectedOptions).map((opt) => opt.value);
|
|
2130
|
-
const hasChanged = select.multiple ? JSON.stringify(oldSelectedOptions.sort()) !== JSON.stringify(newSelectedOptions.sort()) : select.value !== oldValue;
|
|
2131
|
-
return hasChanged;
|
|
2132
|
-
}
|
|
2133
|
-
function resetFormElement(element, defaultValues) {
|
|
2134
|
-
if (element.disabled) {
|
|
2135
|
-
if (element instanceof HTMLInputElement) {
|
|
2136
|
-
const oldValue = element.value;
|
|
2137
|
-
const oldChecked = element.checked;
|
|
2138
|
-
switch (element.type.toLowerCase()) {
|
|
2139
|
-
case "checkbox":
|
|
2140
|
-
case "radio":
|
|
2141
|
-
element.checked = element.defaultChecked;
|
|
2142
|
-
return element.checked !== oldChecked;
|
|
2143
|
-
case "file":
|
|
2144
|
-
element.value = "";
|
|
2145
|
-
return oldValue !== "";
|
|
2146
|
-
case "button":
|
|
2147
|
-
case "submit":
|
|
2148
|
-
case "reset":
|
|
2149
|
-
case "image":
|
|
2150
|
-
return false;
|
|
2151
|
-
default:
|
|
2152
|
-
element.value = element.defaultValue;
|
|
2153
|
-
return element.value !== oldValue;
|
|
2154
|
-
}
|
|
2155
|
-
} else if (element instanceof HTMLSelectElement) {
|
|
2156
|
-
const oldSelectedOptions = Array.from(element.selectedOptions).map((opt) => opt.value);
|
|
2157
|
-
Array.from(element.options).forEach((option) => {
|
|
2158
|
-
option.selected = option.defaultSelected;
|
|
2159
|
-
});
|
|
2160
|
-
const newSelectedOptions = Array.from(element.selectedOptions).map((opt) => opt.value);
|
|
2161
|
-
return JSON.stringify(oldSelectedOptions.sort()) !== JSON.stringify(newSelectedOptions.sort());
|
|
2162
|
-
} else if (element instanceof HTMLTextAreaElement) {
|
|
2163
|
-
const oldValue = element.value;
|
|
2164
|
-
element.value = element.defaultValue;
|
|
2165
|
-
return element.value !== oldValue;
|
|
2166
|
-
}
|
|
2167
|
-
return false;
|
|
2168
|
-
}
|
|
2169
|
-
if (element instanceof HTMLInputElement) {
|
|
2170
|
-
return resetInputElement(element, defaultValues);
|
|
2171
|
-
} else if (element instanceof HTMLSelectElement) {
|
|
2172
|
-
return resetSelectElement(element, defaultValues);
|
|
2173
|
-
} else if (element instanceof HTMLTextAreaElement) {
|
|
2174
|
-
const oldValue = element.value;
|
|
2175
|
-
element.value = defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2176
|
-
return element.value !== oldValue;
|
|
2177
|
-
}
|
|
2178
|
-
return false;
|
|
2179
|
-
}
|
|
2180
|
-
function resetFieldElements(elements, defaultValues) {
|
|
2181
|
-
let hasChanged = false;
|
|
2182
|
-
if (elements instanceof RadioNodeList || elements instanceof HTMLCollection) {
|
|
2183
|
-
Array.from(elements).forEach((node, index) => {
|
|
2184
|
-
if (node instanceof Element && isFormElement(node)) {
|
|
2185
|
-
if (node instanceof HTMLInputElement && ["checkbox", "radio"].includes(node.type.toLowerCase())) {
|
|
2186
|
-
if (resetFormElement(node, defaultValues)) {
|
|
2187
|
-
hasChanged = true;
|
|
2188
|
-
}
|
|
2189
|
-
} else {
|
|
2190
|
-
const indexedDefaultValues = defaultValues[index] !== void 0 ? [defaultValues[index]] : [defaultValues[0] ?? null].filter(Boolean);
|
|
2191
|
-
if (resetFormElement(node, indexedDefaultValues)) {
|
|
2192
|
-
hasChanged = true;
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
});
|
|
2197
|
-
} else if (isFormElement(elements)) {
|
|
2198
|
-
hasChanged = resetFormElement(elements, defaultValues);
|
|
2199
|
-
}
|
|
2200
|
-
return hasChanged;
|
|
2201
|
-
}
|
|
2202
|
-
function resetFormFields(formElement, defaults, fieldNames) {
|
|
2203
|
-
if (!fieldNames || fieldNames.length === 0) {
|
|
2204
|
-
const formData = new FormData(formElement);
|
|
2205
|
-
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
2206
|
-
fieldNames = [.../* @__PURE__ */ new Set([...defaults.keys(), ...formData.keys(), ...formElementNames])];
|
|
2207
|
-
}
|
|
2208
|
-
let hasChanged = false;
|
|
2209
|
-
fieldNames.forEach((fieldName) => {
|
|
2210
|
-
const elements = formElement.elements.namedItem(fieldName);
|
|
2211
|
-
if (elements) {
|
|
2212
|
-
if (resetFieldElements(elements, defaults.getAll(fieldName))) {
|
|
2213
|
-
hasChanged = true;
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
});
|
|
2217
|
-
if (hasChanged) {
|
|
2218
|
-
formElement.dispatchEvent(new Event("reset", { bubbles: true }));
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
2111
|
// src/head.ts
|
|
2223
2112
|
var Renderer = {
|
|
2224
2113
|
buildDOMElement(tag) {
|
|
@@ -2331,6 +2220,16 @@ function createHeadManager(isServer2, titleCallback, onUpdate) {
|
|
|
2331
2220
|
};
|
|
2332
2221
|
}
|
|
2333
2222
|
|
|
2223
|
+
// src/navigationEvents.ts
|
|
2224
|
+
function shouldIntercept(event) {
|
|
2225
|
+
const isLink = event.currentTarget.tagName.toLowerCase() === "a";
|
|
2226
|
+
return !(event.target && (event?.target).isContentEditable || event.defaultPrevented || isLink && event.altKey || isLink && event.ctrlKey || isLink && event.metaKey || isLink && event.shiftKey || isLink && "button" in event && event.button !== 0);
|
|
2227
|
+
}
|
|
2228
|
+
function shouldNavigate(event) {
|
|
2229
|
+
const isButton = event.currentTarget.tagName.toLowerCase() === "button";
|
|
2230
|
+
return event.key === "Enter" || isButton && event.key === " ";
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2334
2233
|
// src/progress-component.ts
|
|
2335
2234
|
var baseComponentSelector = "nprogress";
|
|
2336
2235
|
var progress;
|
|
@@ -2665,10 +2564,138 @@ function setupProgress({
|
|
|
2665
2564
|
progress_component_default.configure({ showSpinner, includeCSS, color });
|
|
2666
2565
|
}
|
|
2667
2566
|
|
|
2668
|
-
// src/
|
|
2669
|
-
function
|
|
2670
|
-
|
|
2671
|
-
|
|
2567
|
+
// src/resetFormFields.ts
|
|
2568
|
+
function isFormElement(element) {
|
|
2569
|
+
return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
|
|
2570
|
+
}
|
|
2571
|
+
function resetInputElement(input, defaultValues) {
|
|
2572
|
+
const oldValue = input.value;
|
|
2573
|
+
const oldChecked = input.checked;
|
|
2574
|
+
switch (input.type.toLowerCase()) {
|
|
2575
|
+
case "checkbox":
|
|
2576
|
+
input.checked = defaultValues.includes(input.value);
|
|
2577
|
+
break;
|
|
2578
|
+
case "radio":
|
|
2579
|
+
input.checked = defaultValues[0] === input.value;
|
|
2580
|
+
break;
|
|
2581
|
+
case "file":
|
|
2582
|
+
input.value = "";
|
|
2583
|
+
break;
|
|
2584
|
+
case "button":
|
|
2585
|
+
case "submit":
|
|
2586
|
+
case "reset":
|
|
2587
|
+
case "image":
|
|
2588
|
+
break;
|
|
2589
|
+
default:
|
|
2590
|
+
input.value = defaultValues[0] !== null && defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2591
|
+
}
|
|
2592
|
+
return input.value !== oldValue || input.checked !== oldChecked;
|
|
2593
|
+
}
|
|
2594
|
+
function resetSelectElement(select, defaultValues) {
|
|
2595
|
+
const oldValue = select.value;
|
|
2596
|
+
const oldSelectedOptions = Array.from(select.selectedOptions).map((opt) => opt.value);
|
|
2597
|
+
if (select.multiple) {
|
|
2598
|
+
const defaultStrings = defaultValues.map((value) => String(value));
|
|
2599
|
+
Array.from(select.options).forEach((option) => {
|
|
2600
|
+
option.selected = defaultStrings.includes(option.value);
|
|
2601
|
+
});
|
|
2602
|
+
} else {
|
|
2603
|
+
select.value = defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2604
|
+
}
|
|
2605
|
+
const newSelectedOptions = Array.from(select.selectedOptions).map((opt) => opt.value);
|
|
2606
|
+
const hasChanged = select.multiple ? JSON.stringify(oldSelectedOptions.sort()) !== JSON.stringify(newSelectedOptions.sort()) : select.value !== oldValue;
|
|
2607
|
+
return hasChanged;
|
|
2608
|
+
}
|
|
2609
|
+
function resetFormElement(element, defaultValues) {
|
|
2610
|
+
if (element.disabled) {
|
|
2611
|
+
if (element instanceof HTMLInputElement) {
|
|
2612
|
+
const oldValue = element.value;
|
|
2613
|
+
const oldChecked = element.checked;
|
|
2614
|
+
switch (element.type.toLowerCase()) {
|
|
2615
|
+
case "checkbox":
|
|
2616
|
+
case "radio":
|
|
2617
|
+
element.checked = element.defaultChecked;
|
|
2618
|
+
return element.checked !== oldChecked;
|
|
2619
|
+
case "file":
|
|
2620
|
+
element.value = "";
|
|
2621
|
+
return oldValue !== "";
|
|
2622
|
+
case "button":
|
|
2623
|
+
case "submit":
|
|
2624
|
+
case "reset":
|
|
2625
|
+
case "image":
|
|
2626
|
+
return false;
|
|
2627
|
+
default:
|
|
2628
|
+
element.value = element.defaultValue;
|
|
2629
|
+
return element.value !== oldValue;
|
|
2630
|
+
}
|
|
2631
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
2632
|
+
const oldSelectedOptions = Array.from(element.selectedOptions).map((opt) => opt.value);
|
|
2633
|
+
Array.from(element.options).forEach((option) => {
|
|
2634
|
+
option.selected = option.defaultSelected;
|
|
2635
|
+
});
|
|
2636
|
+
const newSelectedOptions = Array.from(element.selectedOptions).map((opt) => opt.value);
|
|
2637
|
+
return JSON.stringify(oldSelectedOptions.sort()) !== JSON.stringify(newSelectedOptions.sort());
|
|
2638
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
2639
|
+
const oldValue = element.value;
|
|
2640
|
+
element.value = element.defaultValue;
|
|
2641
|
+
return element.value !== oldValue;
|
|
2642
|
+
}
|
|
2643
|
+
return false;
|
|
2644
|
+
}
|
|
2645
|
+
if (element instanceof HTMLInputElement) {
|
|
2646
|
+
return resetInputElement(element, defaultValues);
|
|
2647
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
2648
|
+
return resetSelectElement(element, defaultValues);
|
|
2649
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
2650
|
+
const oldValue = element.value;
|
|
2651
|
+
element.value = defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2652
|
+
return element.value !== oldValue;
|
|
2653
|
+
}
|
|
2654
|
+
return false;
|
|
2655
|
+
}
|
|
2656
|
+
function resetFieldElements(elements, defaultValues) {
|
|
2657
|
+
let hasChanged = false;
|
|
2658
|
+
if (elements instanceof RadioNodeList || elements instanceof HTMLCollection) {
|
|
2659
|
+
Array.from(elements).forEach((node, index) => {
|
|
2660
|
+
if (node instanceof Element && isFormElement(node)) {
|
|
2661
|
+
if (node instanceof HTMLInputElement && ["checkbox", "radio"].includes(node.type.toLowerCase())) {
|
|
2662
|
+
if (resetFormElement(node, defaultValues)) {
|
|
2663
|
+
hasChanged = true;
|
|
2664
|
+
}
|
|
2665
|
+
} else {
|
|
2666
|
+
const indexedDefaultValues = defaultValues[index] !== void 0 ? [defaultValues[index]] : [defaultValues[0] ?? null].filter(Boolean);
|
|
2667
|
+
if (resetFormElement(node, indexedDefaultValues)) {
|
|
2668
|
+
hasChanged = true;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
} else if (isFormElement(elements)) {
|
|
2674
|
+
hasChanged = resetFormElement(elements, defaultValues);
|
|
2675
|
+
}
|
|
2676
|
+
return hasChanged;
|
|
2677
|
+
}
|
|
2678
|
+
function resetFormFields(formElement, defaults, fieldNames) {
|
|
2679
|
+
if (!formElement) {
|
|
2680
|
+
return;
|
|
2681
|
+
}
|
|
2682
|
+
if (!fieldNames || fieldNames.length === 0) {
|
|
2683
|
+
const formData = new FormData(formElement);
|
|
2684
|
+
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
2685
|
+
fieldNames = [.../* @__PURE__ */ new Set([...defaults.keys(), ...formData.keys(), ...formElementNames])];
|
|
2686
|
+
}
|
|
2687
|
+
let hasChanged = false;
|
|
2688
|
+
fieldNames.forEach((fieldName) => {
|
|
2689
|
+
const elements = formElement.elements.namedItem(fieldName);
|
|
2690
|
+
if (elements) {
|
|
2691
|
+
if (resetFieldElements(elements, defaults.getAll(fieldName))) {
|
|
2692
|
+
hasChanged = true;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
});
|
|
2696
|
+
if (hasChanged) {
|
|
2697
|
+
formElement.dispatchEvent(new Event("reset", { bubbles: true }));
|
|
2698
|
+
}
|
|
2672
2699
|
}
|
|
2673
2700
|
|
|
2674
2701
|
// src/index.ts
|
|
@@ -2678,6 +2705,7 @@ export {
|
|
|
2678
2705
|
formDataToObject,
|
|
2679
2706
|
hide as hideProgress,
|
|
2680
2707
|
hrefToUrl,
|
|
2708
|
+
isUrlMethodPair,
|
|
2681
2709
|
mergeDataIntoQueryString,
|
|
2682
2710
|
objectToFormData,
|
|
2683
2711
|
resetFormFields,
|
|
@@ -2685,6 +2713,7 @@ export {
|
|
|
2685
2713
|
router,
|
|
2686
2714
|
setupProgress,
|
|
2687
2715
|
shouldIntercept,
|
|
2716
|
+
shouldNavigate,
|
|
2688
2717
|
urlWithoutHash
|
|
2689
2718
|
};
|
|
2690
2719
|
/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
|