@inertiajs/core 2.0.17 → 2.1.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 +214 -14
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +214 -14
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/formObject.d.ts +5 -0
- package/types/index.d.ts +3 -0
- package/types/prefetched.d.ts +1 -0
- package/types/requestParams.d.ts +1 -0
- package/types/resetFormFields.d.ts +1 -0
- package/types/router.d.ts +4 -4
- package/types/types.d.ts +118 -38
- package/types/url.d.ts +3 -1
package/dist/index.esm.js
CHANGED
|
@@ -342,14 +342,15 @@ var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFo
|
|
|
342
342
|
return [hrefToUrl(_href), _data];
|
|
343
343
|
};
|
|
344
344
|
function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets") {
|
|
345
|
+
const hasDataForQueryString = method === "get" && !isFormData(data) && Object.keys(data).length > 0;
|
|
345
346
|
const hasHost = /^[a-z][a-z0-9+.-]*:\/\//i.test(href.toString());
|
|
346
|
-
const hasAbsolutePath = hasHost || href.toString().startsWith("/");
|
|
347
|
+
const hasAbsolutePath = hasHost || href.toString().startsWith("/") || href.toString() === "";
|
|
347
348
|
const hasRelativePath = !hasAbsolutePath && !href.toString().startsWith("#") && !href.toString().startsWith("?");
|
|
348
349
|
const hasRelativePathWithDotPrefix = /^[.]{1,2}([/]|$)/.test(href.toString());
|
|
349
|
-
const hasSearch = href.toString().includes("?") ||
|
|
350
|
+
const hasSearch = href.toString().includes("?") || hasDataForQueryString;
|
|
350
351
|
const hasHash = href.toString().includes("#");
|
|
351
352
|
const url = new URL(href.toString(), typeof window === "undefined" ? "http://localhost" : window.location.toString());
|
|
352
|
-
if (
|
|
353
|
+
if (hasDataForQueryString) {
|
|
353
354
|
const parseOptions = { ignoreQueryPrefix: true, parseArrays: false };
|
|
354
355
|
url.search = qs.stringify(
|
|
355
356
|
{ ...qs.parse(url.search, parseOptions), ...data },
|
|
@@ -358,7 +359,6 @@ function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets"
|
|
|
358
359
|
arrayFormat: qsArrayFormat
|
|
359
360
|
}
|
|
360
361
|
);
|
|
361
|
-
data = {};
|
|
362
362
|
}
|
|
363
363
|
return [
|
|
364
364
|
[
|
|
@@ -368,7 +368,7 @@ function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets"
|
|
|
368
368
|
hasSearch ? url.search : "",
|
|
369
369
|
hasHash ? url.hash : ""
|
|
370
370
|
].join(""),
|
|
371
|
-
data
|
|
371
|
+
hasDataForQueryString ? {} : data
|
|
372
372
|
];
|
|
373
373
|
}
|
|
374
374
|
function urlWithoutHash(url) {
|
|
@@ -507,7 +507,7 @@ var Queue = class {
|
|
|
507
507
|
return this.process();
|
|
508
508
|
}
|
|
509
509
|
process() {
|
|
510
|
-
this.processingPromise ?? (this.processingPromise = this.processNext().
|
|
510
|
+
this.processingPromise ?? (this.processingPromise = this.processNext().finally(() => {
|
|
511
511
|
this.processingPromise = null;
|
|
512
512
|
}));
|
|
513
513
|
return this.processingPromise;
|
|
@@ -1036,6 +1036,10 @@ var PrefetchedRequests = class {
|
|
|
1036
1036
|
},
|
|
1037
1037
|
onPrefetchResponse(response) {
|
|
1038
1038
|
resolve(response);
|
|
1039
|
+
},
|
|
1040
|
+
onPrefetchError(error) {
|
|
1041
|
+
prefetchedRequests.removeFromInFlight(params);
|
|
1042
|
+
reject(error);
|
|
1039
1043
|
}
|
|
1040
1044
|
});
|
|
1041
1045
|
}).then((response) => {
|
|
@@ -1049,9 +1053,7 @@ var PrefetchedRequests = class {
|
|
|
1049
1053
|
inFlight: false
|
|
1050
1054
|
});
|
|
1051
1055
|
this.scheduleForRemoval(params, expires);
|
|
1052
|
-
this.
|
|
1053
|
-
return !this.paramsAreEqual(prefetching.params, params);
|
|
1054
|
-
});
|
|
1056
|
+
this.removeFromInFlight(params);
|
|
1055
1057
|
response.handlePrefetch();
|
|
1056
1058
|
return response;
|
|
1057
1059
|
});
|
|
@@ -1076,6 +1078,11 @@ var PrefetchedRequests = class {
|
|
|
1076
1078
|
});
|
|
1077
1079
|
this.clearTimer(params);
|
|
1078
1080
|
}
|
|
1081
|
+
removeFromInFlight(params) {
|
|
1082
|
+
this.inFlightRequests = this.inFlightRequests.filter((prefetching) => {
|
|
1083
|
+
return !this.paramsAreEqual(prefetching.params, params);
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1079
1086
|
extractStaleValues(cacheFor) {
|
|
1080
1087
|
const [stale, expires] = this.cacheForToStaleAndExpires(cacheFor);
|
|
1081
1088
|
return [timeToMs(stale), timeToMs(expires)];
|
|
@@ -1207,6 +1214,8 @@ var RequestParams = class _RequestParams {
|
|
|
1207
1214
|
...params,
|
|
1208
1215
|
...wrappedCallbacks,
|
|
1209
1216
|
onPrefetchResponse: params.onPrefetchResponse || (() => {
|
|
1217
|
+
}),
|
|
1218
|
+
onPrefetchError: params.onPrefetchError || (() => {
|
|
1210
1219
|
})
|
|
1211
1220
|
};
|
|
1212
1221
|
}
|
|
@@ -1256,6 +1265,11 @@ var RequestParams = class _RequestParams {
|
|
|
1256
1265
|
this.params.onPrefetchResponse(response);
|
|
1257
1266
|
}
|
|
1258
1267
|
}
|
|
1268
|
+
onPrefetchError(error) {
|
|
1269
|
+
if (this.params.onPrefetchError) {
|
|
1270
|
+
this.params.onPrefetchError(error);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1259
1273
|
all() {
|
|
1260
1274
|
return this.params;
|
|
1261
1275
|
}
|
|
@@ -1638,6 +1652,9 @@ var Request = class _Request {
|
|
|
1638
1652
|
return;
|
|
1639
1653
|
}
|
|
1640
1654
|
if (fireExceptionEvent(error)) {
|
|
1655
|
+
if (originallyPrefetch) {
|
|
1656
|
+
this.requestParams.onPrefetchError(error);
|
|
1657
|
+
}
|
|
1641
1658
|
return Promise.reject(error);
|
|
1642
1659
|
}
|
|
1643
1660
|
}).finally(() => {
|
|
@@ -2022,6 +2039,186 @@ var Router = class {
|
|
|
2022
2039
|
}
|
|
2023
2040
|
};
|
|
2024
2041
|
|
|
2042
|
+
// src/formObject.ts
|
|
2043
|
+
import { get, set } from "es-toolkit/compat";
|
|
2044
|
+
function undotKey(key) {
|
|
2045
|
+
if (!key.includes(".")) {
|
|
2046
|
+
return key;
|
|
2047
|
+
}
|
|
2048
|
+
const transformSegment = (segment) => {
|
|
2049
|
+
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
2050
|
+
return segment;
|
|
2051
|
+
}
|
|
2052
|
+
return segment.split(".").reduce((result, part, index) => index === 0 ? part : `${result}[${part}]`);
|
|
2053
|
+
};
|
|
2054
|
+
return key.replace(/\\\./g, "__ESCAPED_DOT__").split(/(\[[^\]]*\])/).filter(Boolean).map(transformSegment).join("").replace(/__ESCAPED_DOT__/g, ".");
|
|
2055
|
+
}
|
|
2056
|
+
function parseKey(key) {
|
|
2057
|
+
const path = [];
|
|
2058
|
+
const pattern = /([^\[\]]+)|\[(\d*)\]/g;
|
|
2059
|
+
let match;
|
|
2060
|
+
while ((match = pattern.exec(key)) !== null) {
|
|
2061
|
+
if (match[1] !== void 0) {
|
|
2062
|
+
path.push(match[1]);
|
|
2063
|
+
} else if (match[2] !== void 0) {
|
|
2064
|
+
path.push(match[2] === "" ? "" : Number(match[2]));
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
return path;
|
|
2068
|
+
}
|
|
2069
|
+
function formDataToObject(source) {
|
|
2070
|
+
const form = {};
|
|
2071
|
+
for (const [key, value] of source.entries()) {
|
|
2072
|
+
if (value instanceof File && value.size === 0 && value.name === "") {
|
|
2073
|
+
continue;
|
|
2074
|
+
}
|
|
2075
|
+
const path = parseKey(undotKey(key));
|
|
2076
|
+
if (path[path.length - 1] === "") {
|
|
2077
|
+
const arrayPath = path.slice(0, -1);
|
|
2078
|
+
const existing = get(form, arrayPath);
|
|
2079
|
+
if (Array.isArray(existing)) {
|
|
2080
|
+
existing.push(value);
|
|
2081
|
+
} else {
|
|
2082
|
+
set(form, arrayPath, [value]);
|
|
2083
|
+
}
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
set(form, path, value);
|
|
2087
|
+
}
|
|
2088
|
+
return form;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
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
|
+
|
|
2025
2222
|
// src/head.ts
|
|
2026
2223
|
var Renderer = {
|
|
2027
2224
|
buildDOMElement(tag) {
|
|
@@ -2169,7 +2366,7 @@ var configure = (options) => {
|
|
|
2169
2366
|
progress.id = baseComponentSelector;
|
|
2170
2367
|
progress.innerHTML = settings.template;
|
|
2171
2368
|
};
|
|
2172
|
-
var
|
|
2369
|
+
var set2 = (n) => {
|
|
2173
2370
|
const started = isStarted();
|
|
2174
2371
|
n = clamp(n, settings.minimum, 1);
|
|
2175
2372
|
status = n === 1 ? null : n;
|
|
@@ -2218,7 +2415,7 @@ var set = (n) => {
|
|
|
2218
2415
|
var isStarted = () => typeof status === "number";
|
|
2219
2416
|
var start = () => {
|
|
2220
2417
|
if (!status) {
|
|
2221
|
-
|
|
2418
|
+
set2(0);
|
|
2222
2419
|
}
|
|
2223
2420
|
const work = function() {
|
|
2224
2421
|
setTimeout(function() {
|
|
@@ -2238,7 +2435,7 @@ var done = (force) => {
|
|
|
2238
2435
|
return;
|
|
2239
2436
|
}
|
|
2240
2437
|
increaseByRandom(0.3 + 0.5 * Math.random());
|
|
2241
|
-
|
|
2438
|
+
set2(1);
|
|
2242
2439
|
};
|
|
2243
2440
|
var increaseByRandom = (amount) => {
|
|
2244
2441
|
const n = status;
|
|
@@ -2262,7 +2459,7 @@ var increaseByRandom = (amount) => {
|
|
|
2262
2459
|
}
|
|
2263
2460
|
return 0;
|
|
2264
2461
|
})();
|
|
2265
|
-
return
|
|
2462
|
+
return set2(clamp(n + amount, 0, 0.994));
|
|
2266
2463
|
};
|
|
2267
2464
|
var render = (fromStart) => {
|
|
2268
2465
|
if (isRendered()) {
|
|
@@ -2408,7 +2605,7 @@ var progress_component_default = {
|
|
|
2408
2605
|
configure,
|
|
2409
2606
|
isStarted,
|
|
2410
2607
|
done,
|
|
2411
|
-
set,
|
|
2608
|
+
set: set2,
|
|
2412
2609
|
remove,
|
|
2413
2610
|
start,
|
|
2414
2611
|
status,
|
|
@@ -2478,9 +2675,12 @@ function shouldIntercept(event) {
|
|
|
2478
2675
|
var router = new Router();
|
|
2479
2676
|
export {
|
|
2480
2677
|
createHeadManager,
|
|
2678
|
+
formDataToObject,
|
|
2481
2679
|
hide as hideProgress,
|
|
2482
2680
|
hrefToUrl,
|
|
2483
2681
|
mergeDataIntoQueryString,
|
|
2682
|
+
objectToFormData,
|
|
2683
|
+
resetFormFields,
|
|
2484
2684
|
reveal as revealProgress,
|
|
2485
2685
|
router,
|
|
2486
2686
|
setupProgress,
|