@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.js
CHANGED
|
@@ -31,9 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
createHeadManager: () => createHeadManager,
|
|
34
|
+
formDataToObject: () => formDataToObject,
|
|
34
35
|
hideProgress: () => hide,
|
|
35
36
|
hrefToUrl: () => hrefToUrl,
|
|
36
37
|
mergeDataIntoQueryString: () => mergeDataIntoQueryString,
|
|
38
|
+
objectToFormData: () => objectToFormData,
|
|
39
|
+
resetFormFields: () => resetFormFields,
|
|
37
40
|
revealProgress: () => reveal,
|
|
38
41
|
router: () => router,
|
|
39
42
|
setupProgress: () => setupProgress,
|
|
@@ -386,14 +389,15 @@ var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFo
|
|
|
386
389
|
return [hrefToUrl(_href), _data];
|
|
387
390
|
};
|
|
388
391
|
function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets") {
|
|
392
|
+
const hasDataForQueryString = method === "get" && !isFormData(data) && Object.keys(data).length > 0;
|
|
389
393
|
const hasHost = /^[a-z][a-z0-9+.-]*:\/\//i.test(href.toString());
|
|
390
|
-
const hasAbsolutePath = hasHost || href.toString().startsWith("/");
|
|
394
|
+
const hasAbsolutePath = hasHost || href.toString().startsWith("/") || href.toString() === "";
|
|
391
395
|
const hasRelativePath = !hasAbsolutePath && !href.toString().startsWith("#") && !href.toString().startsWith("?");
|
|
392
396
|
const hasRelativePathWithDotPrefix = /^[.]{1,2}([/]|$)/.test(href.toString());
|
|
393
|
-
const hasSearch = href.toString().includes("?") ||
|
|
397
|
+
const hasSearch = href.toString().includes("?") || hasDataForQueryString;
|
|
394
398
|
const hasHash = href.toString().includes("#");
|
|
395
399
|
const url = new URL(href.toString(), typeof window === "undefined" ? "http://localhost" : window.location.toString());
|
|
396
|
-
if (
|
|
400
|
+
if (hasDataForQueryString) {
|
|
397
401
|
const parseOptions = { ignoreQueryPrefix: true, parseArrays: false };
|
|
398
402
|
url.search = qs.stringify(
|
|
399
403
|
{ ...qs.parse(url.search, parseOptions), ...data },
|
|
@@ -402,7 +406,6 @@ function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets"
|
|
|
402
406
|
arrayFormat: qsArrayFormat
|
|
403
407
|
}
|
|
404
408
|
);
|
|
405
|
-
data = {};
|
|
406
409
|
}
|
|
407
410
|
return [
|
|
408
411
|
[
|
|
@@ -412,7 +415,7 @@ function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets"
|
|
|
412
415
|
hasSearch ? url.search : "",
|
|
413
416
|
hasHash ? url.hash : ""
|
|
414
417
|
].join(""),
|
|
415
|
-
data
|
|
418
|
+
hasDataForQueryString ? {} : data
|
|
416
419
|
];
|
|
417
420
|
}
|
|
418
421
|
function urlWithoutHash(url) {
|
|
@@ -551,7 +554,7 @@ var Queue = class {
|
|
|
551
554
|
return this.process();
|
|
552
555
|
}
|
|
553
556
|
process() {
|
|
554
|
-
this.processingPromise ?? (this.processingPromise = this.processNext().
|
|
557
|
+
this.processingPromise ?? (this.processingPromise = this.processNext().finally(() => {
|
|
555
558
|
this.processingPromise = null;
|
|
556
559
|
}));
|
|
557
560
|
return this.processingPromise;
|
|
@@ -1080,6 +1083,10 @@ var PrefetchedRequests = class {
|
|
|
1080
1083
|
},
|
|
1081
1084
|
onPrefetchResponse(response) {
|
|
1082
1085
|
resolve(response);
|
|
1086
|
+
},
|
|
1087
|
+
onPrefetchError(error) {
|
|
1088
|
+
prefetchedRequests.removeFromInFlight(params);
|
|
1089
|
+
reject(error);
|
|
1083
1090
|
}
|
|
1084
1091
|
});
|
|
1085
1092
|
}).then((response) => {
|
|
@@ -1093,9 +1100,7 @@ var PrefetchedRequests = class {
|
|
|
1093
1100
|
inFlight: false
|
|
1094
1101
|
});
|
|
1095
1102
|
this.scheduleForRemoval(params, expires);
|
|
1096
|
-
this.
|
|
1097
|
-
return !this.paramsAreEqual(prefetching.params, params);
|
|
1098
|
-
});
|
|
1103
|
+
this.removeFromInFlight(params);
|
|
1099
1104
|
response.handlePrefetch();
|
|
1100
1105
|
return response;
|
|
1101
1106
|
});
|
|
@@ -1120,6 +1125,11 @@ var PrefetchedRequests = class {
|
|
|
1120
1125
|
});
|
|
1121
1126
|
this.clearTimer(params);
|
|
1122
1127
|
}
|
|
1128
|
+
removeFromInFlight(params) {
|
|
1129
|
+
this.inFlightRequests = this.inFlightRequests.filter((prefetching) => {
|
|
1130
|
+
return !this.paramsAreEqual(prefetching.params, params);
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1123
1133
|
extractStaleValues(cacheFor) {
|
|
1124
1134
|
const [stale, expires] = this.cacheForToStaleAndExpires(cacheFor);
|
|
1125
1135
|
return [timeToMs(stale), timeToMs(expires)];
|
|
@@ -1251,6 +1261,8 @@ var RequestParams = class _RequestParams {
|
|
|
1251
1261
|
...params,
|
|
1252
1262
|
...wrappedCallbacks,
|
|
1253
1263
|
onPrefetchResponse: params.onPrefetchResponse || (() => {
|
|
1264
|
+
}),
|
|
1265
|
+
onPrefetchError: params.onPrefetchError || (() => {
|
|
1254
1266
|
})
|
|
1255
1267
|
};
|
|
1256
1268
|
}
|
|
@@ -1300,6 +1312,11 @@ var RequestParams = class _RequestParams {
|
|
|
1300
1312
|
this.params.onPrefetchResponse(response);
|
|
1301
1313
|
}
|
|
1302
1314
|
}
|
|
1315
|
+
onPrefetchError(error) {
|
|
1316
|
+
if (this.params.onPrefetchError) {
|
|
1317
|
+
this.params.onPrefetchError(error);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1303
1320
|
all() {
|
|
1304
1321
|
return this.params;
|
|
1305
1322
|
}
|
|
@@ -1682,6 +1699,9 @@ var Request = class _Request {
|
|
|
1682
1699
|
return;
|
|
1683
1700
|
}
|
|
1684
1701
|
if (fireExceptionEvent(error)) {
|
|
1702
|
+
if (originallyPrefetch) {
|
|
1703
|
+
this.requestParams.onPrefetchError(error);
|
|
1704
|
+
}
|
|
1685
1705
|
return Promise.reject(error);
|
|
1686
1706
|
}
|
|
1687
1707
|
}).finally(() => {
|
|
@@ -2066,6 +2086,186 @@ var Router = class {
|
|
|
2066
2086
|
}
|
|
2067
2087
|
};
|
|
2068
2088
|
|
|
2089
|
+
// src/formObject.ts
|
|
2090
|
+
var import_compat = require("es-toolkit/compat");
|
|
2091
|
+
function undotKey(key) {
|
|
2092
|
+
if (!key.includes(".")) {
|
|
2093
|
+
return key;
|
|
2094
|
+
}
|
|
2095
|
+
const transformSegment = (segment) => {
|
|
2096
|
+
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
2097
|
+
return segment;
|
|
2098
|
+
}
|
|
2099
|
+
return segment.split(".").reduce((result, part, index) => index === 0 ? part : `${result}[${part}]`);
|
|
2100
|
+
};
|
|
2101
|
+
return key.replace(/\\\./g, "__ESCAPED_DOT__").split(/(\[[^\]]*\])/).filter(Boolean).map(transformSegment).join("").replace(/__ESCAPED_DOT__/g, ".");
|
|
2102
|
+
}
|
|
2103
|
+
function parseKey(key) {
|
|
2104
|
+
const path = [];
|
|
2105
|
+
const pattern = /([^\[\]]+)|\[(\d*)\]/g;
|
|
2106
|
+
let match;
|
|
2107
|
+
while ((match = pattern.exec(key)) !== null) {
|
|
2108
|
+
if (match[1] !== void 0) {
|
|
2109
|
+
path.push(match[1]);
|
|
2110
|
+
} else if (match[2] !== void 0) {
|
|
2111
|
+
path.push(match[2] === "" ? "" : Number(match[2]));
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
return path;
|
|
2115
|
+
}
|
|
2116
|
+
function formDataToObject(source) {
|
|
2117
|
+
const form = {};
|
|
2118
|
+
for (const [key, value] of source.entries()) {
|
|
2119
|
+
if (value instanceof File && value.size === 0 && value.name === "") {
|
|
2120
|
+
continue;
|
|
2121
|
+
}
|
|
2122
|
+
const path = parseKey(undotKey(key));
|
|
2123
|
+
if (path[path.length - 1] === "") {
|
|
2124
|
+
const arrayPath = path.slice(0, -1);
|
|
2125
|
+
const existing = (0, import_compat.get)(form, arrayPath);
|
|
2126
|
+
if (Array.isArray(existing)) {
|
|
2127
|
+
existing.push(value);
|
|
2128
|
+
} else {
|
|
2129
|
+
(0, import_compat.set)(form, arrayPath, [value]);
|
|
2130
|
+
}
|
|
2131
|
+
continue;
|
|
2132
|
+
}
|
|
2133
|
+
(0, import_compat.set)(form, path, value);
|
|
2134
|
+
}
|
|
2135
|
+
return form;
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
// src/resetFormFields.ts
|
|
2139
|
+
function isFormElement(element) {
|
|
2140
|
+
return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
|
|
2141
|
+
}
|
|
2142
|
+
function resetInputElement(input, defaultValues) {
|
|
2143
|
+
const oldValue = input.value;
|
|
2144
|
+
const oldChecked = input.checked;
|
|
2145
|
+
switch (input.type.toLowerCase()) {
|
|
2146
|
+
case "checkbox":
|
|
2147
|
+
input.checked = defaultValues.includes(input.value);
|
|
2148
|
+
break;
|
|
2149
|
+
case "radio":
|
|
2150
|
+
input.checked = defaultValues[0] === input.value;
|
|
2151
|
+
break;
|
|
2152
|
+
case "file":
|
|
2153
|
+
input.value = "";
|
|
2154
|
+
break;
|
|
2155
|
+
case "button":
|
|
2156
|
+
case "submit":
|
|
2157
|
+
case "reset":
|
|
2158
|
+
case "image":
|
|
2159
|
+
break;
|
|
2160
|
+
default:
|
|
2161
|
+
input.value = defaultValues[0] !== null && defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2162
|
+
}
|
|
2163
|
+
return input.value !== oldValue || input.checked !== oldChecked;
|
|
2164
|
+
}
|
|
2165
|
+
function resetSelectElement(select, defaultValues) {
|
|
2166
|
+
const oldValue = select.value;
|
|
2167
|
+
const oldSelectedOptions = Array.from(select.selectedOptions).map((opt) => opt.value);
|
|
2168
|
+
if (select.multiple) {
|
|
2169
|
+
const defaultStrings = defaultValues.map((value) => String(value));
|
|
2170
|
+
Array.from(select.options).forEach((option) => {
|
|
2171
|
+
option.selected = defaultStrings.includes(option.value);
|
|
2172
|
+
});
|
|
2173
|
+
} else {
|
|
2174
|
+
select.value = defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2175
|
+
}
|
|
2176
|
+
const newSelectedOptions = Array.from(select.selectedOptions).map((opt) => opt.value);
|
|
2177
|
+
const hasChanged = select.multiple ? JSON.stringify(oldSelectedOptions.sort()) !== JSON.stringify(newSelectedOptions.sort()) : select.value !== oldValue;
|
|
2178
|
+
return hasChanged;
|
|
2179
|
+
}
|
|
2180
|
+
function resetFormElement(element, defaultValues) {
|
|
2181
|
+
if (element.disabled) {
|
|
2182
|
+
if (element instanceof HTMLInputElement) {
|
|
2183
|
+
const oldValue = element.value;
|
|
2184
|
+
const oldChecked = element.checked;
|
|
2185
|
+
switch (element.type.toLowerCase()) {
|
|
2186
|
+
case "checkbox":
|
|
2187
|
+
case "radio":
|
|
2188
|
+
element.checked = element.defaultChecked;
|
|
2189
|
+
return element.checked !== oldChecked;
|
|
2190
|
+
case "file":
|
|
2191
|
+
element.value = "";
|
|
2192
|
+
return oldValue !== "";
|
|
2193
|
+
case "button":
|
|
2194
|
+
case "submit":
|
|
2195
|
+
case "reset":
|
|
2196
|
+
case "image":
|
|
2197
|
+
return false;
|
|
2198
|
+
default:
|
|
2199
|
+
element.value = element.defaultValue;
|
|
2200
|
+
return element.value !== oldValue;
|
|
2201
|
+
}
|
|
2202
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
2203
|
+
const oldSelectedOptions = Array.from(element.selectedOptions).map((opt) => opt.value);
|
|
2204
|
+
Array.from(element.options).forEach((option) => {
|
|
2205
|
+
option.selected = option.defaultSelected;
|
|
2206
|
+
});
|
|
2207
|
+
const newSelectedOptions = Array.from(element.selectedOptions).map((opt) => opt.value);
|
|
2208
|
+
return JSON.stringify(oldSelectedOptions.sort()) !== JSON.stringify(newSelectedOptions.sort());
|
|
2209
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
2210
|
+
const oldValue = element.value;
|
|
2211
|
+
element.value = element.defaultValue;
|
|
2212
|
+
return element.value !== oldValue;
|
|
2213
|
+
}
|
|
2214
|
+
return false;
|
|
2215
|
+
}
|
|
2216
|
+
if (element instanceof HTMLInputElement) {
|
|
2217
|
+
return resetInputElement(element, defaultValues);
|
|
2218
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
2219
|
+
return resetSelectElement(element, defaultValues);
|
|
2220
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
2221
|
+
const oldValue = element.value;
|
|
2222
|
+
element.value = defaultValues[0] !== void 0 ? String(defaultValues[0]) : "";
|
|
2223
|
+
return element.value !== oldValue;
|
|
2224
|
+
}
|
|
2225
|
+
return false;
|
|
2226
|
+
}
|
|
2227
|
+
function resetFieldElements(elements, defaultValues) {
|
|
2228
|
+
let hasChanged = false;
|
|
2229
|
+
if (elements instanceof RadioNodeList || elements instanceof HTMLCollection) {
|
|
2230
|
+
Array.from(elements).forEach((node, index) => {
|
|
2231
|
+
if (node instanceof Element && isFormElement(node)) {
|
|
2232
|
+
if (node instanceof HTMLInputElement && ["checkbox", "radio"].includes(node.type.toLowerCase())) {
|
|
2233
|
+
if (resetFormElement(node, defaultValues)) {
|
|
2234
|
+
hasChanged = true;
|
|
2235
|
+
}
|
|
2236
|
+
} else {
|
|
2237
|
+
const indexedDefaultValues = defaultValues[index] !== void 0 ? [defaultValues[index]] : [defaultValues[0] ?? null].filter(Boolean);
|
|
2238
|
+
if (resetFormElement(node, indexedDefaultValues)) {
|
|
2239
|
+
hasChanged = true;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
} else if (isFormElement(elements)) {
|
|
2245
|
+
hasChanged = resetFormElement(elements, defaultValues);
|
|
2246
|
+
}
|
|
2247
|
+
return hasChanged;
|
|
2248
|
+
}
|
|
2249
|
+
function resetFormFields(formElement, defaults, fieldNames) {
|
|
2250
|
+
if (!fieldNames || fieldNames.length === 0) {
|
|
2251
|
+
const formData = new FormData(formElement);
|
|
2252
|
+
const formElementNames = Array.from(formElement.elements).map((el) => isFormElement(el) ? el.name : "").filter(Boolean);
|
|
2253
|
+
fieldNames = [.../* @__PURE__ */ new Set([...defaults.keys(), ...formData.keys(), ...formElementNames])];
|
|
2254
|
+
}
|
|
2255
|
+
let hasChanged = false;
|
|
2256
|
+
fieldNames.forEach((fieldName) => {
|
|
2257
|
+
const elements = formElement.elements.namedItem(fieldName);
|
|
2258
|
+
if (elements) {
|
|
2259
|
+
if (resetFieldElements(elements, defaults.getAll(fieldName))) {
|
|
2260
|
+
hasChanged = true;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
});
|
|
2264
|
+
if (hasChanged) {
|
|
2265
|
+
formElement.dispatchEvent(new Event("reset", { bubbles: true }));
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2069
2269
|
// src/head.ts
|
|
2070
2270
|
var Renderer = {
|
|
2071
2271
|
buildDOMElement(tag) {
|
|
@@ -2213,7 +2413,7 @@ var configure = (options) => {
|
|
|
2213
2413
|
progress.id = baseComponentSelector;
|
|
2214
2414
|
progress.innerHTML = settings.template;
|
|
2215
2415
|
};
|
|
2216
|
-
var
|
|
2416
|
+
var set2 = (n) => {
|
|
2217
2417
|
const started = isStarted();
|
|
2218
2418
|
n = clamp(n, settings.minimum, 1);
|
|
2219
2419
|
status = n === 1 ? null : n;
|
|
@@ -2262,7 +2462,7 @@ var set = (n) => {
|
|
|
2262
2462
|
var isStarted = () => typeof status === "number";
|
|
2263
2463
|
var start = () => {
|
|
2264
2464
|
if (!status) {
|
|
2265
|
-
|
|
2465
|
+
set2(0);
|
|
2266
2466
|
}
|
|
2267
2467
|
const work = function() {
|
|
2268
2468
|
setTimeout(function() {
|
|
@@ -2282,7 +2482,7 @@ var done = (force) => {
|
|
|
2282
2482
|
return;
|
|
2283
2483
|
}
|
|
2284
2484
|
increaseByRandom(0.3 + 0.5 * Math.random());
|
|
2285
|
-
|
|
2485
|
+
set2(1);
|
|
2286
2486
|
};
|
|
2287
2487
|
var increaseByRandom = (amount) => {
|
|
2288
2488
|
const n = status;
|
|
@@ -2306,7 +2506,7 @@ var increaseByRandom = (amount) => {
|
|
|
2306
2506
|
}
|
|
2307
2507
|
return 0;
|
|
2308
2508
|
})();
|
|
2309
|
-
return
|
|
2509
|
+
return set2(clamp(n + amount, 0, 0.994));
|
|
2310
2510
|
};
|
|
2311
2511
|
var render = (fromStart) => {
|
|
2312
2512
|
if (isRendered()) {
|
|
@@ -2452,7 +2652,7 @@ var progress_component_default = {
|
|
|
2452
2652
|
configure,
|
|
2453
2653
|
isStarted,
|
|
2454
2654
|
done,
|
|
2455
|
-
set,
|
|
2655
|
+
set: set2,
|
|
2456
2656
|
remove,
|
|
2457
2657
|
start,
|
|
2458
2658
|
status,
|