@inertiajs/core 3.0.1 → 3.0.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.js +105 -83
- package/dist/index.js.map +3 -3
- package/package.json +3 -3
- package/types/index.d.ts +1 -1
- package/types/initialVisit.d.ts +1 -0
- package/types/layout.d.ts +1 -0
- package/types/types.d.ts +6 -4
package/dist/index.js
CHANGED
|
@@ -5,8 +5,9 @@ import { get as get7, set as set5 } from "es-toolkit/compat";
|
|
|
5
5
|
// src/config.ts
|
|
6
6
|
import { get, has, set } from "es-toolkit/compat";
|
|
7
7
|
var Config = class {
|
|
8
|
+
config = {};
|
|
9
|
+
defaults;
|
|
8
10
|
constructor(defaults) {
|
|
9
|
-
this.config = {};
|
|
10
11
|
this.defaults = defaults;
|
|
11
12
|
}
|
|
12
13
|
extend(defaults) {
|
|
@@ -104,9 +105,7 @@ import { cloneDeep as cloneDeep3, isEqual } from "es-toolkit";
|
|
|
104
105
|
|
|
105
106
|
// src/sessionStorage.ts
|
|
106
107
|
var SessionStorage = class {
|
|
107
|
-
static
|
|
108
|
-
this.locationVisitKey = "inertiaLocationVisit";
|
|
109
|
-
}
|
|
108
|
+
static locationVisitKey = "inertiaLocationVisit";
|
|
110
109
|
static set(key, value) {
|
|
111
110
|
if (typeof window !== "undefined") {
|
|
112
111
|
window.sessionStorage.setItem(key, JSON.stringify(value));
|
|
@@ -340,12 +339,10 @@ var timeToMs = (time) => {
|
|
|
340
339
|
|
|
341
340
|
// src/prefetched.ts
|
|
342
341
|
var PrefetchedRequests = class {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
this.currentUseId = null;
|
|
348
|
-
}
|
|
342
|
+
cached = [];
|
|
343
|
+
inFlightRequests = [];
|
|
344
|
+
removalTimers = [];
|
|
345
|
+
currentUseId = null;
|
|
349
346
|
add(params, sendFunc, { cacheFor, cacheTags }) {
|
|
350
347
|
const inFlight = this.findInFlight(params);
|
|
351
348
|
if (inFlight) {
|
|
@@ -999,17 +996,19 @@ function urlToString(url, absolute) {
|
|
|
999
996
|
|
|
1000
997
|
// src/page.ts
|
|
1001
998
|
var CurrentPage = class {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
999
|
+
page;
|
|
1000
|
+
swapComponent;
|
|
1001
|
+
resolveComponent;
|
|
1002
|
+
onFlashCallback;
|
|
1003
|
+
componentId = {};
|
|
1004
|
+
listeners = [];
|
|
1005
|
+
isFirstPageLoad = true;
|
|
1006
|
+
cleared = false;
|
|
1007
|
+
pendingDeferredProps = null;
|
|
1008
|
+
historyQuotaExceeded = false;
|
|
1009
|
+
optimisticBaseline = {};
|
|
1010
|
+
pendingOptimistics = [];
|
|
1011
|
+
optimisticCounter = 0;
|
|
1013
1012
|
init({
|
|
1014
1013
|
initialPage,
|
|
1015
1014
|
swapComponent,
|
|
@@ -1245,10 +1244,8 @@ var page = new CurrentPage();
|
|
|
1245
1244
|
|
|
1246
1245
|
// src/queue.ts
|
|
1247
1246
|
var Queue = class {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
this.processingPromise = null;
|
|
1251
|
-
}
|
|
1247
|
+
items = [];
|
|
1248
|
+
processingPromise = null;
|
|
1252
1249
|
add(item) {
|
|
1253
1250
|
this.items.push(item);
|
|
1254
1251
|
return this.process();
|
|
@@ -1273,14 +1270,12 @@ var isServer2 = typeof window === "undefined";
|
|
|
1273
1270
|
var queue = new Queue();
|
|
1274
1271
|
var isChromeIOS = !isServer2 && /CriOS/.test(window.navigator.userAgent);
|
|
1275
1272
|
var History = class {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
this.initialState = null;
|
|
1283
|
-
}
|
|
1273
|
+
rememberedState = "rememberedState";
|
|
1274
|
+
scrollRegions = "scrollRegions";
|
|
1275
|
+
preserveUrl = false;
|
|
1276
|
+
current = {};
|
|
1277
|
+
// We need initialState for `restore`
|
|
1278
|
+
initialState = null;
|
|
1284
1279
|
remember(data, key) {
|
|
1285
1280
|
this.replaceState({
|
|
1286
1281
|
...page.getWithoutFlashData(),
|
|
@@ -1502,9 +1497,7 @@ var history = new History();
|
|
|
1502
1497
|
|
|
1503
1498
|
// src/eventHandler.ts
|
|
1504
1499
|
var EventHandler = class {
|
|
1505
|
-
|
|
1506
|
-
this.internalListeners = [];
|
|
1507
|
-
}
|
|
1500
|
+
internalListeners = [];
|
|
1508
1501
|
init() {
|
|
1509
1502
|
if (typeof window !== "undefined") {
|
|
1510
1503
|
window.addEventListener("popstate", this.handlePopstateEvent.bind(this));
|
|
@@ -1591,6 +1584,7 @@ var eventHandler = new EventHandler();
|
|
|
1591
1584
|
|
|
1592
1585
|
// src/navigationType.ts
|
|
1593
1586
|
var NavigationType = class {
|
|
1587
|
+
type;
|
|
1594
1588
|
constructor() {
|
|
1595
1589
|
this.type = this.resolveType();
|
|
1596
1590
|
}
|
|
@@ -1664,7 +1658,7 @@ var InitialVisit = class {
|
|
|
1664
1658
|
if (locationVisit.preserveScroll) {
|
|
1665
1659
|
Scroll.restore(scrollRegions);
|
|
1666
1660
|
}
|
|
1667
|
-
|
|
1661
|
+
this.fireInitialEvents();
|
|
1668
1662
|
});
|
|
1669
1663
|
}).catch(() => {
|
|
1670
1664
|
eventHandler.onMissingHistoryItem();
|
|
@@ -1681,23 +1675,27 @@ var InitialVisit = class {
|
|
|
1681
1675
|
} else {
|
|
1682
1676
|
Scroll.scrollToAnchor();
|
|
1683
1677
|
}
|
|
1684
|
-
|
|
1685
|
-
fireNavigateEvent(page2);
|
|
1686
|
-
const flash = page2.flash;
|
|
1687
|
-
if (Object.keys(flash).length > 0) {
|
|
1688
|
-
queueMicrotask(() => fireFlashEvent(flash));
|
|
1689
|
-
}
|
|
1678
|
+
this.fireInitialEvents();
|
|
1690
1679
|
});
|
|
1691
1680
|
}
|
|
1681
|
+
static fireInitialEvents() {
|
|
1682
|
+
const page2 = page.get();
|
|
1683
|
+
fireNavigateEvent(page2);
|
|
1684
|
+
if (Object.keys(page2.flash).length > 0) {
|
|
1685
|
+
queueMicrotask(() => fireFlashEvent(page2.flash));
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1692
1688
|
};
|
|
1693
1689
|
|
|
1694
1690
|
// src/poll.ts
|
|
1695
1691
|
var Poll = class {
|
|
1692
|
+
id = null;
|
|
1693
|
+
throttle = false;
|
|
1694
|
+
keepAlive = false;
|
|
1695
|
+
cb;
|
|
1696
|
+
interval;
|
|
1697
|
+
cbCount = 0;
|
|
1696
1698
|
constructor(interval, cb, options) {
|
|
1697
|
-
this.id = null;
|
|
1698
|
-
this.throttle = false;
|
|
1699
|
-
this.keepAlive = false;
|
|
1700
|
-
this.cbCount = 0;
|
|
1701
1699
|
this.keepAlive = options.keepAlive ?? false;
|
|
1702
1700
|
this.cb = cb;
|
|
1703
1701
|
this.interval = interval;
|
|
@@ -1734,8 +1732,8 @@ var Poll = class {
|
|
|
1734
1732
|
|
|
1735
1733
|
// src/polls.ts
|
|
1736
1734
|
var Polls = class {
|
|
1735
|
+
polls = [];
|
|
1737
1736
|
constructor() {
|
|
1738
|
-
this.polls = [];
|
|
1739
1737
|
this.setupVisibilityListener();
|
|
1740
1738
|
}
|
|
1741
1739
|
add(interval, cb, options) {
|
|
@@ -1773,11 +1771,9 @@ import { client as precognitionClient } from "laravel-precognition";
|
|
|
1773
1771
|
|
|
1774
1772
|
// src/httpHandlers.ts
|
|
1775
1773
|
var HttpHandlers = class {
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
this.errorHandlers = [];
|
|
1780
|
-
}
|
|
1774
|
+
requestHandlers = [];
|
|
1775
|
+
responseHandlers = [];
|
|
1776
|
+
errorHandlers = [];
|
|
1781
1777
|
onRequest(handler) {
|
|
1782
1778
|
this.requestHandlers.push(handler);
|
|
1783
1779
|
return () => {
|
|
@@ -1820,6 +1816,8 @@ var httpHandlers = new HttpHandlers();
|
|
|
1820
1816
|
|
|
1821
1817
|
// src/httpErrors.ts
|
|
1822
1818
|
var HttpError = class extends Error {
|
|
1819
|
+
code;
|
|
1820
|
+
url;
|
|
1823
1821
|
constructor(message, code, url) {
|
|
1824
1822
|
super(url ? `${message} (${url})` : message);
|
|
1825
1823
|
this.name = "HttpError";
|
|
@@ -1828,6 +1826,7 @@ var HttpError = class extends Error {
|
|
|
1828
1826
|
}
|
|
1829
1827
|
};
|
|
1830
1828
|
var HttpResponseError = class extends HttpError {
|
|
1829
|
+
response;
|
|
1831
1830
|
constructor(message, response, url) {
|
|
1832
1831
|
super(message, "ERR_HTTP_RESPONSE", url);
|
|
1833
1832
|
this.name = "HttpResponseError";
|
|
@@ -1841,6 +1840,7 @@ var HttpCancelledError = class extends HttpError {
|
|
|
1841
1840
|
}
|
|
1842
1841
|
};
|
|
1843
1842
|
var HttpNetworkError = class extends HttpError {
|
|
1843
|
+
cause;
|
|
1844
1844
|
constructor(message, url, cause) {
|
|
1845
1845
|
super(message, "ERR_NETWORK", url);
|
|
1846
1846
|
this.name = "HttpNetworkError";
|
|
@@ -1882,6 +1882,8 @@ function buildUrlWithParams(url, params) {
|
|
|
1882
1882
|
return urlWithParams;
|
|
1883
1883
|
}
|
|
1884
1884
|
var XhrHttpClient = class {
|
|
1885
|
+
xsrfCookieName;
|
|
1886
|
+
xsrfHeaderName;
|
|
1885
1887
|
constructor(options = {}) {
|
|
1886
1888
|
this.xsrfCookieName = options.xsrfCookieName ?? "XSRF-TOKEN";
|
|
1887
1889
|
this.xsrfHeaderName = options.xsrfHeaderName ?? "X-XSRF-TOKEN";
|
|
@@ -1923,8 +1925,10 @@ var XhrHttpClient = class {
|
|
|
1923
1925
|
setHeaders(xhr, config2);
|
|
1924
1926
|
if (config2.onUploadProgress) {
|
|
1925
1927
|
xhr.upload.onprogress = (event) => {
|
|
1928
|
+
const progress3 = event.lengthComputable ? event.loaded / event.total : void 0;
|
|
1926
1929
|
config2.onUploadProgress({
|
|
1927
|
-
progress:
|
|
1930
|
+
progress: progress3,
|
|
1931
|
+
percentage: progress3 ? Math.round(progress3 * 100) : 0,
|
|
1928
1932
|
loaded: event.loaded,
|
|
1929
1933
|
total: event.lengthComputable ? event.total : void 0
|
|
1930
1934
|
});
|
|
@@ -2012,8 +2016,9 @@ var http = {
|
|
|
2012
2016
|
|
|
2013
2017
|
// src/requestParams.ts
|
|
2014
2018
|
var RequestParams = class _RequestParams {
|
|
2019
|
+
callbacks = [];
|
|
2020
|
+
params;
|
|
2015
2021
|
constructor(params) {
|
|
2016
|
-
this.callbacks = [];
|
|
2017
2022
|
if (!params.prefetch) {
|
|
2018
2023
|
this.params = params;
|
|
2019
2024
|
} else {
|
|
@@ -2235,9 +2240,9 @@ var Response = class _Response {
|
|
|
2235
2240
|
this.requestParams = requestParams;
|
|
2236
2241
|
this.response = response;
|
|
2237
2242
|
this.originatingPage = originatingPage;
|
|
2238
|
-
this.wasPrefetched = false;
|
|
2239
|
-
this.processed = false;
|
|
2240
2243
|
}
|
|
2244
|
+
wasPrefetched = false;
|
|
2245
|
+
processed = false;
|
|
2241
2246
|
static create(params, response, originatingPage) {
|
|
2242
2247
|
return new _Response(params, response, originatingPage);
|
|
2243
2248
|
}
|
|
@@ -2280,6 +2285,11 @@ var Response = class _Response {
|
|
|
2280
2285
|
await history.processQueue();
|
|
2281
2286
|
history.preserveUrl = this.requestParams.all().preserveUrl;
|
|
2282
2287
|
await this.setPage();
|
|
2288
|
+
const { flash } = page.get();
|
|
2289
|
+
if (Object.keys(flash).length > 0 && !this.requestParams.isDeferredPropsRequest()) {
|
|
2290
|
+
fireFlashEvent(flash);
|
|
2291
|
+
this.requestParams.all().onFlash(flash);
|
|
2292
|
+
}
|
|
2283
2293
|
const errors = page.get().props.errors || {};
|
|
2284
2294
|
if (Object.keys(errors).length > 0) {
|
|
2285
2295
|
const scopedErrors = this.getScopedErrors(errors);
|
|
@@ -2290,11 +2300,6 @@ var Response = class _Response {
|
|
|
2290
2300
|
if (!this.wasPrefetched) {
|
|
2291
2301
|
router.flush(page.get().url);
|
|
2292
2302
|
}
|
|
2293
|
-
const { flash } = page.get();
|
|
2294
|
-
if (Object.keys(flash).length > 0 && !this.requestParams.isDeferredPropsRequest()) {
|
|
2295
|
-
fireFlashEvent(flash);
|
|
2296
|
-
this.requestParams.all().onFlash(flash);
|
|
2297
|
-
}
|
|
2298
2303
|
fireSuccessEvent(page.get());
|
|
2299
2304
|
await this.requestParams.all().onSuccess(page.get());
|
|
2300
2305
|
history.preserveUrl = false;
|
|
@@ -2635,11 +2640,15 @@ var Response = class _Response {
|
|
|
2635
2640
|
var Request = class _Request {
|
|
2636
2641
|
constructor(params, page2, { optimistic = false } = {}) {
|
|
2637
2642
|
this.page = page2;
|
|
2638
|
-
this.requestHasFinished = false;
|
|
2639
2643
|
this.requestParams = RequestParams.create(params);
|
|
2640
2644
|
this.cancelToken = new AbortController();
|
|
2641
2645
|
this.optimistic = optimistic;
|
|
2642
2646
|
}
|
|
2647
|
+
response;
|
|
2648
|
+
cancelToken;
|
|
2649
|
+
requestParams;
|
|
2650
|
+
requestHasFinished = false;
|
|
2651
|
+
optimistic;
|
|
2643
2652
|
static create(params, page2, options) {
|
|
2644
2653
|
return new _Request(params, page2, options);
|
|
2645
2654
|
}
|
|
@@ -2722,7 +2731,6 @@ var Request = class _Request {
|
|
|
2722
2731
|
}
|
|
2723
2732
|
onProgress(progress3) {
|
|
2724
2733
|
if (this.requestParams.data() instanceof FormData) {
|
|
2725
|
-
progress3.percentage = progress3.progress ? Math.round(progress3.progress * 100) : 0;
|
|
2726
2734
|
fireProgressEvent(progress3);
|
|
2727
2735
|
this.requestParams.all().onProgress(progress3);
|
|
2728
2736
|
}
|
|
@@ -2753,8 +2761,10 @@ var Request = class _Request {
|
|
|
2753
2761
|
|
|
2754
2762
|
// src/requestStream.ts
|
|
2755
2763
|
var RequestStream = class {
|
|
2764
|
+
requests = [];
|
|
2765
|
+
maxConcurrent;
|
|
2766
|
+
interruptible;
|
|
2756
2767
|
constructor({ maxConcurrent, interruptible }) {
|
|
2757
|
-
this.requests = [];
|
|
2758
2768
|
this.maxConcurrent = maxConcurrent;
|
|
2759
2769
|
this.interruptible = interruptible;
|
|
2760
2770
|
}
|
|
@@ -2789,18 +2799,16 @@ var RequestStream = class {
|
|
|
2789
2799
|
var noop = () => {
|
|
2790
2800
|
};
|
|
2791
2801
|
var Router = class {
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
this.pendingOptimisticCallback = void 0;
|
|
2803
|
-
}
|
|
2802
|
+
syncRequestStream = new RequestStream({
|
|
2803
|
+
maxConcurrent: 1,
|
|
2804
|
+
interruptible: true
|
|
2805
|
+
});
|
|
2806
|
+
asyncRequestStream = new RequestStream({
|
|
2807
|
+
maxConcurrent: Infinity,
|
|
2808
|
+
interruptible: false
|
|
2809
|
+
});
|
|
2810
|
+
clientVisitQueue = new Queue();
|
|
2811
|
+
pendingOptimisticCallback = void 0;
|
|
2804
2812
|
init({
|
|
2805
2813
|
initialPage,
|
|
2806
2814
|
resolveComponent,
|
|
@@ -3429,6 +3437,7 @@ function normalizeHeaders(headers) {
|
|
|
3429
3437
|
function toHttpProgressEvent(axiosEvent) {
|
|
3430
3438
|
return {
|
|
3431
3439
|
progress: axiosEvent.progress,
|
|
3440
|
+
percentage: axiosEvent.progress ? Math.round(axiosEvent.progress * 100) : 0,
|
|
3432
3441
|
loaded: axiosEvent.loaded,
|
|
3433
3442
|
total: axiosEvent.total
|
|
3434
3443
|
};
|
|
@@ -3444,6 +3453,7 @@ function loadAxiosModule() {
|
|
|
3444
3453
|
return axiosModulePromise;
|
|
3445
3454
|
}
|
|
3446
3455
|
var AxiosHttpClient = class {
|
|
3456
|
+
axiosInstance;
|
|
3447
3457
|
constructor(instance) {
|
|
3448
3458
|
this.axiosInstance = instance ? Promise.resolve(instance) : loadAxiosModule().then((module) => module.default);
|
|
3449
3459
|
}
|
|
@@ -4281,16 +4291,29 @@ function isPlainObject(value) {
|
|
|
4281
4291
|
function hasComponentKey(value) {
|
|
4282
4292
|
return isPlainObject(value) && "component" in value;
|
|
4283
4293
|
}
|
|
4294
|
+
function hasComponentEntry(value, isComponent) {
|
|
4295
|
+
return "component" in value && isComponent(value.component);
|
|
4296
|
+
}
|
|
4284
4297
|
function isNamedLayouts(value, isComponent) {
|
|
4285
|
-
if (!isPlainObject(value) || isComponent(value) ||
|
|
4298
|
+
if (!isPlainObject(value) || isComponent(value) || hasComponentEntry(value, isComponent)) {
|
|
4286
4299
|
return false;
|
|
4287
4300
|
}
|
|
4288
|
-
return Object.values(value).
|
|
4301
|
+
return Object.values(value).every(
|
|
4289
4302
|
(v) => isComponent(v) || Array.isArray(v) && isComponent(v[0]) || hasComponentKey(v) && isComponent(v.component)
|
|
4290
4303
|
);
|
|
4291
4304
|
}
|
|
4292
4305
|
function isPropsObject(value, isComponent) {
|
|
4293
|
-
return isPlainObject(value) && !isComponent(value) && !(
|
|
4306
|
+
return isPlainObject(value) && !isComponent(value) && !hasComponentEntry(value, isComponent) && !isNamedLayouts(value, isComponent);
|
|
4307
|
+
}
|
|
4308
|
+
function isPropsObjectOrCallback(value, isComponent) {
|
|
4309
|
+
if (isPropsObject(value, isComponent)) {
|
|
4310
|
+
return true;
|
|
4311
|
+
}
|
|
4312
|
+
if (!isPlainObject(value) || isComponent(value) || hasComponentEntry(value, isComponent)) {
|
|
4313
|
+
return false;
|
|
4314
|
+
}
|
|
4315
|
+
const values = Object.values(value);
|
|
4316
|
+
return values.length > 0 && values.every((v) => typeof v === "function");
|
|
4294
4317
|
}
|
|
4295
4318
|
function isTuple(value, isComponent) {
|
|
4296
4319
|
return Array.isArray(value) && value.length === 2 && isComponent(value[0]) && isPlainObject(value[1]) && !isComponent(value[1]);
|
|
@@ -4666,9 +4689,7 @@ var progress_component_default = {
|
|
|
4666
4689
|
|
|
4667
4690
|
// src/progress.ts
|
|
4668
4691
|
var Progress = class {
|
|
4669
|
-
|
|
4670
|
-
this.hideCount = 0;
|
|
4671
|
-
}
|
|
4692
|
+
hideCount = 0;
|
|
4672
4693
|
start() {
|
|
4673
4694
|
progress_component_default.start();
|
|
4674
4695
|
}
|
|
@@ -4909,6 +4930,7 @@ export {
|
|
|
4909
4930
|
hrefToUrl,
|
|
4910
4931
|
http,
|
|
4911
4932
|
isPropsObject,
|
|
4933
|
+
isPropsObjectOrCallback,
|
|
4912
4934
|
isSameUrlWithoutQueryOrHash,
|
|
4913
4935
|
isUrlMethodPair,
|
|
4914
4936
|
mergeDataIntoQueryString,
|