@inertiajs/core 3.0.2 → 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 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
- constructor() {
344
- this.cached = [];
345
- this.inFlightRequests = [];
346
- this.removalTimers = [];
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
- constructor() {
1003
- this.componentId = {};
1004
- this.listeners = [];
1005
- this.isFirstPageLoad = true;
1006
- this.cleared = false;
1007
- this.pendingDeferredProps = null;
1008
- this.historyQuotaExceeded = false;
1009
- this.optimisticBaseline = {};
1010
- this.pendingOptimistics = [];
1011
- this.optimisticCounter = 0;
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
- constructor() {
1249
- this.items = [];
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
- constructor() {
1277
- this.rememberedState = "rememberedState";
1278
- this.scrollRegions = "scrollRegions";
1279
- this.preserveUrl = false;
1280
- this.current = {};
1281
- // We need initialState for `restore`
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
- constructor() {
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
- fireNavigateEvent(page.get());
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
- const page2 = page.get();
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
- constructor() {
1777
- this.requestHandlers = [];
1778
- this.responseHandlers = [];
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";
@@ -2014,8 +2016,9 @@ var http = {
2014
2016
 
2015
2017
  // src/requestParams.ts
2016
2018
  var RequestParams = class _RequestParams {
2019
+ callbacks = [];
2020
+ params;
2017
2021
  constructor(params) {
2018
- this.callbacks = [];
2019
2022
  if (!params.prefetch) {
2020
2023
  this.params = params;
2021
2024
  } else {
@@ -2237,9 +2240,9 @@ var Response = class _Response {
2237
2240
  this.requestParams = requestParams;
2238
2241
  this.response = response;
2239
2242
  this.originatingPage = originatingPage;
2240
- this.wasPrefetched = false;
2241
- this.processed = false;
2242
2243
  }
2244
+ wasPrefetched = false;
2245
+ processed = false;
2243
2246
  static create(params, response, originatingPage) {
2244
2247
  return new _Response(params, response, originatingPage);
2245
2248
  }
@@ -2282,6 +2285,11 @@ var Response = class _Response {
2282
2285
  await history.processQueue();
2283
2286
  history.preserveUrl = this.requestParams.all().preserveUrl;
2284
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
+ }
2285
2293
  const errors = page.get().props.errors || {};
2286
2294
  if (Object.keys(errors).length > 0) {
2287
2295
  const scopedErrors = this.getScopedErrors(errors);
@@ -2292,11 +2300,6 @@ var Response = class _Response {
2292
2300
  if (!this.wasPrefetched) {
2293
2301
  router.flush(page.get().url);
2294
2302
  }
2295
- const { flash } = page.get();
2296
- if (Object.keys(flash).length > 0 && !this.requestParams.isDeferredPropsRequest()) {
2297
- fireFlashEvent(flash);
2298
- this.requestParams.all().onFlash(flash);
2299
- }
2300
2303
  fireSuccessEvent(page.get());
2301
2304
  await this.requestParams.all().onSuccess(page.get());
2302
2305
  history.preserveUrl = false;
@@ -2637,11 +2640,15 @@ var Response = class _Response {
2637
2640
  var Request = class _Request {
2638
2641
  constructor(params, page2, { optimistic = false } = {}) {
2639
2642
  this.page = page2;
2640
- this.requestHasFinished = false;
2641
2643
  this.requestParams = RequestParams.create(params);
2642
2644
  this.cancelToken = new AbortController();
2643
2645
  this.optimistic = optimistic;
2644
2646
  }
2647
+ response;
2648
+ cancelToken;
2649
+ requestParams;
2650
+ requestHasFinished = false;
2651
+ optimistic;
2645
2652
  static create(params, page2, options) {
2646
2653
  return new _Request(params, page2, options);
2647
2654
  }
@@ -2754,8 +2761,10 @@ var Request = class _Request {
2754
2761
 
2755
2762
  // src/requestStream.ts
2756
2763
  var RequestStream = class {
2764
+ requests = [];
2765
+ maxConcurrent;
2766
+ interruptible;
2757
2767
  constructor({ maxConcurrent, interruptible }) {
2758
- this.requests = [];
2759
2768
  this.maxConcurrent = maxConcurrent;
2760
2769
  this.interruptible = interruptible;
2761
2770
  }
@@ -2790,18 +2799,16 @@ var RequestStream = class {
2790
2799
  var noop = () => {
2791
2800
  };
2792
2801
  var Router = class {
2793
- constructor() {
2794
- this.syncRequestStream = new RequestStream({
2795
- maxConcurrent: 1,
2796
- interruptible: true
2797
- });
2798
- this.asyncRequestStream = new RequestStream({
2799
- maxConcurrent: Infinity,
2800
- interruptible: false
2801
- });
2802
- this.clientVisitQueue = new Queue();
2803
- this.pendingOptimisticCallback = void 0;
2804
- }
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;
2805
2812
  init({
2806
2813
  initialPage,
2807
2814
  resolveComponent,
@@ -3446,6 +3453,7 @@ function loadAxiosModule() {
3446
3453
  return axiosModulePromise;
3447
3454
  }
3448
3455
  var AxiosHttpClient = class {
3456
+ axiosInstance;
3449
3457
  constructor(instance) {
3450
3458
  this.axiosInstance = instance ? Promise.resolve(instance) : loadAxiosModule().then((module) => module.default);
3451
3459
  }
@@ -4283,16 +4291,29 @@ function isPlainObject(value) {
4283
4291
  function hasComponentKey(value) {
4284
4292
  return isPlainObject(value) && "component" in value;
4285
4293
  }
4294
+ function hasComponentEntry(value, isComponent) {
4295
+ return "component" in value && isComponent(value.component);
4296
+ }
4286
4297
  function isNamedLayouts(value, isComponent) {
4287
- if (!isPlainObject(value) || isComponent(value) || "component" in value) {
4298
+ if (!isPlainObject(value) || isComponent(value) || hasComponentEntry(value, isComponent)) {
4288
4299
  return false;
4289
4300
  }
4290
- return Object.values(value).some(
4301
+ return Object.values(value).every(
4291
4302
  (v) => isComponent(v) || Array.isArray(v) && isComponent(v[0]) || hasComponentKey(v) && isComponent(v.component)
4292
4303
  );
4293
4304
  }
4294
4305
  function isPropsObject(value, isComponent) {
4295
- return isPlainObject(value) && !isComponent(value) && !("component" in value) && !isNamedLayouts(value, isComponent);
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");
4296
4317
  }
4297
4318
  function isTuple(value, isComponent) {
4298
4319
  return Array.isArray(value) && value.length === 2 && isComponent(value[0]) && isPlainObject(value[1]) && !isComponent(value[1]);
@@ -4668,9 +4689,7 @@ var progress_component_default = {
4668
4689
 
4669
4690
  // src/progress.ts
4670
4691
  var Progress = class {
4671
- constructor() {
4672
- this.hideCount = 0;
4673
- }
4692
+ hideCount = 0;
4674
4693
  start() {
4675
4694
  progress_component_default.start();
4676
4695
  }
@@ -4911,6 +4930,7 @@ export {
4911
4930
  hrefToUrl,
4912
4931
  http,
4913
4932
  isPropsObject,
4933
+ isPropsObjectOrCallback,
4914
4934
  isSameUrlWithoutQueryOrHash,
4915
4935
  isUrlMethodPair,
4916
4936
  mergeDataIntoQueryString,