@inertiajs/core 3.0.2 → 3.1.0

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) {
@@ -863,6 +860,9 @@ function decode(value) {
863
860
  }
864
861
  function set2(target, key, value) {
865
862
  const keys = parseKey(key);
863
+ if (keys.some((k) => k === "__proto__")) {
864
+ return;
865
+ }
866
866
  let current = target;
867
867
  while (keys.length > 1) {
868
868
  const segment = keys.shift();
@@ -999,24 +999,26 @@ function urlToString(url, absolute) {
999
999
 
1000
1000
  // src/page.ts
1001
1001
  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
- }
1002
+ page;
1003
+ swapComponent;
1004
+ resolveComponent;
1005
+ onFlashCallback;
1006
+ componentId = {};
1007
+ listeners = [];
1008
+ isFirstPageLoad = true;
1009
+ cleared = false;
1010
+ pendingDeferredProps = null;
1011
+ historyQuotaExceeded = false;
1012
+ optimisticBaseline = {};
1013
+ pendingOptimistics = [];
1014
+ optimisticCounter = 0;
1013
1015
  init({
1014
1016
  initialPage,
1015
1017
  swapComponent,
1016
1018
  resolveComponent,
1017
1019
  onFlash
1018
1020
  }) {
1019
- this.page = { ...initialPage, flash: initialPage.flash ?? {} };
1021
+ this.page = { ...initialPage, flash: initialPage.flash ?? {}, rescuedProps: initialPage.rescuedProps ?? [] };
1020
1022
  this.swapComponent = swapComponent;
1021
1023
  this.resolveComponent = resolveComponent;
1022
1024
  this.onFlashCallback = onFlash;
@@ -1245,10 +1247,8 @@ var page = new CurrentPage();
1245
1247
 
1246
1248
  // src/queue.ts
1247
1249
  var Queue = class {
1248
- constructor() {
1249
- this.items = [];
1250
- this.processingPromise = null;
1251
- }
1250
+ items = [];
1251
+ processingPromise = null;
1252
1252
  add(item) {
1253
1253
  this.items.push(item);
1254
1254
  return this.process();
@@ -1273,14 +1273,12 @@ var isServer2 = typeof window === "undefined";
1273
1273
  var queue = new Queue();
1274
1274
  var isChromeIOS = !isServer2 && /CriOS/.test(window.navigator.userAgent);
1275
1275
  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
- }
1276
+ rememberedState = "rememberedState";
1277
+ scrollRegions = "scrollRegions";
1278
+ preserveUrl = false;
1279
+ current = {};
1280
+ // We need initialState for `restore`
1281
+ initialState = null;
1284
1282
  remember(data, key) {
1285
1283
  this.replaceState({
1286
1284
  ...page.getWithoutFlashData(),
@@ -1502,9 +1500,7 @@ var history = new History();
1502
1500
 
1503
1501
  // src/eventHandler.ts
1504
1502
  var EventHandler = class {
1505
- constructor() {
1506
- this.internalListeners = [];
1507
- }
1503
+ internalListeners = [];
1508
1504
  init() {
1509
1505
  if (typeof window !== "undefined") {
1510
1506
  window.addEventListener("popstate", this.handlePopstateEvent.bind(this));
@@ -1591,6 +1587,7 @@ var eventHandler = new EventHandler();
1591
1587
 
1592
1588
  // src/navigationType.ts
1593
1589
  var NavigationType = class {
1590
+ type;
1594
1591
  constructor() {
1595
1592
  this.type = this.resolveType();
1596
1593
  }
@@ -1664,7 +1661,7 @@ var InitialVisit = class {
1664
1661
  if (locationVisit.preserveScroll) {
1665
1662
  Scroll.restore(scrollRegions);
1666
1663
  }
1667
- fireNavigateEvent(page.get());
1664
+ this.fireInitialEvents();
1668
1665
  });
1669
1666
  }).catch(() => {
1670
1667
  eventHandler.onMissingHistoryItem();
@@ -1681,23 +1678,27 @@ var InitialVisit = class {
1681
1678
  } else {
1682
1679
  Scroll.scrollToAnchor();
1683
1680
  }
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
- }
1681
+ this.fireInitialEvents();
1690
1682
  });
1691
1683
  }
1684
+ static fireInitialEvents() {
1685
+ const page2 = page.get();
1686
+ fireNavigateEvent(page2);
1687
+ if (Object.keys(page2.flash).length > 0) {
1688
+ queueMicrotask(() => fireFlashEvent(page2.flash));
1689
+ }
1690
+ }
1692
1691
  };
1693
1692
 
1694
1693
  // src/poll.ts
1695
1694
  var Poll = class {
1695
+ id = null;
1696
+ throttle = false;
1697
+ keepAlive = false;
1698
+ cb;
1699
+ interval;
1700
+ cbCount = 0;
1696
1701
  constructor(interval, cb, options) {
1697
- this.id = null;
1698
- this.throttle = false;
1699
- this.keepAlive = false;
1700
- this.cbCount = 0;
1701
1702
  this.keepAlive = options.keepAlive ?? false;
1702
1703
  this.cb = cb;
1703
1704
  this.interval = interval;
@@ -1734,8 +1735,8 @@ var Poll = class {
1734
1735
 
1735
1736
  // src/polls.ts
1736
1737
  var Polls = class {
1738
+ polls = [];
1737
1739
  constructor() {
1738
- this.polls = [];
1739
1740
  this.setupVisibilityListener();
1740
1741
  }
1741
1742
  add(interval, cb, options) {
@@ -1773,11 +1774,9 @@ import { client as precognitionClient } from "laravel-precognition";
1773
1774
 
1774
1775
  // src/httpHandlers.ts
1775
1776
  var HttpHandlers = class {
1776
- constructor() {
1777
- this.requestHandlers = [];
1778
- this.responseHandlers = [];
1779
- this.errorHandlers = [];
1780
- }
1777
+ requestHandlers = [];
1778
+ responseHandlers = [];
1779
+ errorHandlers = [];
1781
1780
  onRequest(handler) {
1782
1781
  this.requestHandlers.push(handler);
1783
1782
  return () => {
@@ -1820,6 +1819,8 @@ var httpHandlers = new HttpHandlers();
1820
1819
 
1821
1820
  // src/httpErrors.ts
1822
1821
  var HttpError = class extends Error {
1822
+ code;
1823
+ url;
1823
1824
  constructor(message, code, url) {
1824
1825
  super(url ? `${message} (${url})` : message);
1825
1826
  this.name = "HttpError";
@@ -1828,6 +1829,7 @@ var HttpError = class extends Error {
1828
1829
  }
1829
1830
  };
1830
1831
  var HttpResponseError = class extends HttpError {
1832
+ response;
1831
1833
  constructor(message, response, url) {
1832
1834
  super(message, "ERR_HTTP_RESPONSE", url);
1833
1835
  this.name = "HttpResponseError";
@@ -1841,6 +1843,7 @@ var HttpCancelledError = class extends HttpError {
1841
1843
  }
1842
1844
  };
1843
1845
  var HttpNetworkError = class extends HttpError {
1846
+ cause;
1844
1847
  constructor(message, url, cause) {
1845
1848
  super(message, "ERR_NETWORK", url);
1846
1849
  this.name = "HttpNetworkError";
@@ -1882,6 +1885,8 @@ function buildUrlWithParams(url, params) {
1882
1885
  return urlWithParams;
1883
1886
  }
1884
1887
  var XhrHttpClient = class {
1888
+ xsrfCookieName;
1889
+ xsrfHeaderName;
1885
1890
  constructor(options = {}) {
1886
1891
  this.xsrfCookieName = options.xsrfCookieName ?? "XSRF-TOKEN";
1887
1892
  this.xsrfHeaderName = options.xsrfHeaderName ?? "X-XSRF-TOKEN";
@@ -2014,8 +2019,9 @@ var http = {
2014
2019
 
2015
2020
  // src/requestParams.ts
2016
2021
  var RequestParams = class _RequestParams {
2022
+ callbacks = [];
2023
+ params;
2017
2024
  constructor(params) {
2018
- this.callbacks = [];
2019
2025
  if (!params.prefetch) {
2020
2026
  this.params = params;
2021
2027
  } else {
@@ -2181,6 +2187,7 @@ var dialog_default = {
2181
2187
  iframe.style.borderRadius = "5px";
2182
2188
  iframe.style.width = "100%";
2183
2189
  iframe.style.height = "100%";
2190
+ iframe.setAttribute("sandbox", "allow-scripts");
2184
2191
  return { iframe, page: page2 };
2185
2192
  },
2186
2193
  show(html) {
@@ -2207,6 +2214,10 @@ var dialog_default = {
2207
2214
  outline: none;
2208
2215
  }
2209
2216
  `;
2217
+ const nonce = config.get("nonce");
2218
+ if (nonce) {
2219
+ dialogStyleElement.nonce = nonce;
2220
+ }
2210
2221
  document.head.appendChild(dialogStyleElement);
2211
2222
  dialog.addEventListener("click", (event) => {
2212
2223
  if (event.target === dialog) {
@@ -2221,13 +2232,29 @@ var dialog_default = {
2221
2232
  document.body.prepend(dialog);
2222
2233
  dialog.showModal();
2223
2234
  dialog.focus();
2224
- if (!iframe.contentWindow) {
2225
- throw new Error("iframe not yet ready.");
2226
- }
2227
- iframe.contentWindow.document.open();
2228
- iframe.contentWindow.document.write(page2.outerHTML);
2229
- iframe.contentWindow.document.close();
2235
+ iframe.srcdoc = page2.outerHTML;
2236
+ }
2237
+ };
2238
+
2239
+ // src/partialReload.ts
2240
+ var isPathOrSubPath = (path, candidate) => {
2241
+ return path === candidate || path.startsWith(`${candidate}.`);
2242
+ };
2243
+ var partialReloadRequestsProp = (visit, prop) => {
2244
+ const { only, except } = visit;
2245
+ if (only.length === 0 && except.length === 0) {
2246
+ return false;
2247
+ }
2248
+ if (only.length > 0 && !only.some((candidate) => isPathOrSubPath(prop, candidate))) {
2249
+ return false;
2250
+ }
2251
+ if (except.length > 0 && except.some((candidate) => isPathOrSubPath(prop, candidate))) {
2252
+ return false;
2230
2253
  }
2254
+ return true;
2255
+ };
2256
+ var partialReloadRequestsSomeProps = (visit, props) => {
2257
+ return props.some((prop) => partialReloadRequestsProp(visit, prop));
2231
2258
  };
2232
2259
 
2233
2260
  // src/response.ts
@@ -2237,9 +2264,9 @@ var Response = class _Response {
2237
2264
  this.requestParams = requestParams;
2238
2265
  this.response = response;
2239
2266
  this.originatingPage = originatingPage;
2240
- this.wasPrefetched = false;
2241
- this.processed = false;
2242
2267
  }
2268
+ wasPrefetched = false;
2269
+ processed = false;
2243
2270
  static create(params, response, originatingPage) {
2244
2271
  return new _Response(params, response, originatingPage);
2245
2272
  }
@@ -2282,6 +2309,11 @@ var Response = class _Response {
2282
2309
  await history.processQueue();
2283
2310
  history.preserveUrl = this.requestParams.all().preserveUrl;
2284
2311
  await this.setPage();
2312
+ const { flash } = page.get();
2313
+ if (Object.keys(flash).length > 0 && !this.requestParams.isDeferredPropsRequest()) {
2314
+ fireFlashEvent(flash);
2315
+ this.requestParams.all().onFlash(flash);
2316
+ }
2285
2317
  const errors = page.get().props.errors || {};
2286
2318
  if (Object.keys(errors).length > 0) {
2287
2319
  const scopedErrors = this.getScopedErrors(errors);
@@ -2292,11 +2324,6 @@ var Response = class _Response {
2292
2324
  if (!this.wasPrefetched) {
2293
2325
  router.flush(page.get().url);
2294
2326
  }
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
2327
  fireSuccessEvent(page.get());
2301
2328
  await this.requestParams.all().onSuccess(page.get());
2302
2329
  history.preserveUrl = false;
@@ -2307,7 +2334,7 @@ var Response = class _Response {
2307
2334
  getPageResponse() {
2308
2335
  const data = this.getDataFromResponse(this.response.data);
2309
2336
  if (typeof data === "object") {
2310
- return this.response.data = { ...data, flash: data.flash ?? {} };
2337
+ return this.response.data = { ...data, flash: data.flash ?? {}, rescuedProps: data.rescuedProps ?? [] };
2311
2338
  }
2312
2339
  return this.response.data = data;
2313
2340
  }
@@ -2535,6 +2562,16 @@ var Response = class _Response {
2535
2562
  if (currentOriginalDeferred && Object.keys(currentOriginalDeferred).length > 0) {
2536
2563
  pageResponse.initialDeferredProps = currentOriginalDeferred;
2537
2564
  }
2565
+ pageResponse.rescuedProps = this.mergeRescuedProps(pageResponse);
2566
+ }
2567
+ mergeRescuedProps(pageResponse) {
2568
+ const currentRescued = page.get().rescuedProps ?? [];
2569
+ const incomingRescued = pageResponse.rescuedProps ?? [];
2570
+ const newRescued = new Set(
2571
+ currentRescued.filter((prop) => !partialReloadRequestsProp(this.requestParams.all(), prop))
2572
+ );
2573
+ incomingRescued.forEach((prop) => newRescued.add(prop));
2574
+ return Array.from(newRescued);
2538
2575
  }
2539
2576
  /**
2540
2577
  * By default, the Laravel adapter shares validation errors via Inertia::always(),
@@ -2637,11 +2674,15 @@ var Response = class _Response {
2637
2674
  var Request = class _Request {
2638
2675
  constructor(params, page2, { optimistic = false } = {}) {
2639
2676
  this.page = page2;
2640
- this.requestHasFinished = false;
2641
2677
  this.requestParams = RequestParams.create(params);
2642
2678
  this.cancelToken = new AbortController();
2643
2679
  this.optimistic = optimistic;
2644
2680
  }
2681
+ response;
2682
+ cancelToken;
2683
+ requestParams;
2684
+ requestHasFinished = false;
2685
+ optimistic;
2645
2686
  static create(params, page2, options) {
2646
2687
  return new _Request(params, page2, options);
2647
2688
  }
@@ -2754,8 +2795,10 @@ var Request = class _Request {
2754
2795
 
2755
2796
  // src/requestStream.ts
2756
2797
  var RequestStream = class {
2798
+ requests = [];
2799
+ maxConcurrent;
2800
+ interruptible;
2757
2801
  constructor({ maxConcurrent, interruptible }) {
2758
- this.requests = [];
2759
2802
  this.maxConcurrent = maxConcurrent;
2760
2803
  this.interruptible = interruptible;
2761
2804
  }
@@ -2790,18 +2833,16 @@ var RequestStream = class {
2790
2833
  var noop = () => {
2791
2834
  };
2792
2835
  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
- }
2836
+ syncRequestStream = new RequestStream({
2837
+ maxConcurrent: 1,
2838
+ interruptible: true
2839
+ });
2840
+ asyncRequestStream = new RequestStream({
2841
+ maxConcurrent: Infinity,
2842
+ interruptible: false
2843
+ });
2844
+ clientVisitQueue = new Queue();
2845
+ pendingOptimisticCallback = void 0;
2805
2846
  init({
2806
2847
  initialPage,
2807
2848
  resolveComponent,
@@ -3153,6 +3194,7 @@ var Router = class {
3153
3194
  errors: {}
3154
3195
  },
3155
3196
  flash: {},
3197
+ rescuedProps: [],
3156
3198
  clearHistory: false,
3157
3199
  encryptHistory: current.encryptHistory,
3158
3200
  sharedProps: current.sharedProps,
@@ -3446,6 +3488,7 @@ function loadAxiosModule() {
3446
3488
  return axiosModulePromise;
3447
3489
  }
3448
3490
  var AxiosHttpClient = class {
3491
+ axiosInstance;
3449
3492
  constructor(instance) {
3450
3493
  this.axiosInstance = instance ? Promise.resolve(instance) : loadAxiosModule().then((module) => module.default);
3451
3494
  }
@@ -3685,7 +3728,7 @@ function createHeadManager(isServer3, titleCallback, onUpdate) {
3685
3728
  return carry;
3686
3729
  }
3687
3730
  if (element.indexOf("<title ") === 0) {
3688
- const title2 = element.match(/(<title [^>]+>)(.*?)(<\/title>)/);
3731
+ const title2 = element.match(/(<title [^>]+>)(.*?)(<\/title>)/s);
3689
3732
  carry.title = title2 ? `${title2[1]}${titleCallback(title2[2])}${title2[3]}` : element;
3690
3733
  return carry;
3691
3734
  }
@@ -4283,16 +4326,29 @@ function isPlainObject(value) {
4283
4326
  function hasComponentKey(value) {
4284
4327
  return isPlainObject(value) && "component" in value;
4285
4328
  }
4329
+ function hasComponentEntry(value, isComponent) {
4330
+ return "component" in value && isComponent(value.component);
4331
+ }
4286
4332
  function isNamedLayouts(value, isComponent) {
4287
- if (!isPlainObject(value) || isComponent(value) || "component" in value) {
4333
+ if (!isPlainObject(value) || isComponent(value) || hasComponentEntry(value, isComponent)) {
4288
4334
  return false;
4289
4335
  }
4290
- return Object.values(value).some(
4336
+ return Object.values(value).every(
4291
4337
  (v) => isComponent(v) || Array.isArray(v) && isComponent(v[0]) || hasComponentKey(v) && isComponent(v.component)
4292
4338
  );
4293
4339
  }
4294
4340
  function isPropsObject(value, isComponent) {
4295
- return isPlainObject(value) && !isComponent(value) && !("component" in value) && !isNamedLayouts(value, isComponent);
4341
+ return isPlainObject(value) && !isComponent(value) && !hasComponentEntry(value, isComponent) && !isNamedLayouts(value, isComponent);
4342
+ }
4343
+ function isPropsObjectOrCallback(value, isComponent) {
4344
+ if (isPropsObject(value, isComponent)) {
4345
+ return true;
4346
+ }
4347
+ if (!isPlainObject(value) || isComponent(value) || hasComponentEntry(value, isComponent)) {
4348
+ return false;
4349
+ }
4350
+ const values = Object.values(value);
4351
+ return values.length > 0 && values.every((v) => typeof v === "function");
4296
4352
  }
4297
4353
  function isTuple(value, isComponent) {
4298
4354
  return Array.isArray(value) && value.length === 2 && isComponent(value[0]) && isPlainObject(value[1]) && !isComponent(value[1]);
@@ -4544,6 +4600,10 @@ var queue4 = /* @__PURE__ */ (() => {
4544
4600
  })();
4545
4601
  var injectCSS = (color) => {
4546
4602
  const element = document.createElement("style");
4603
+ const nonce = config.get("nonce");
4604
+ if (nonce) {
4605
+ element.nonce = nonce;
4606
+ }
4547
4607
  element.textContent = `
4548
4608
  #${baseComponentSelector} {
4549
4609
  pointer-events: none;
@@ -4668,9 +4728,7 @@ var progress_component_default = {
4668
4728
 
4669
4729
  // src/progress.ts
4670
4730
  var Progress = class {
4671
- constructor() {
4672
- this.hideCount = 0;
4673
- }
4731
+ hideCount = 0;
4674
4732
  start() {
4675
4733
  progress_component_default.start();
4676
4734
  }
@@ -4742,7 +4800,12 @@ function setupProgress({
4742
4800
  popover = null
4743
4801
  } = {}) {
4744
4802
  addEventListeners(delay);
4745
- progress_component_default.configure({ showSpinner, includeCSS, color, popover });
4803
+ progress_component_default.configure({
4804
+ showSpinner,
4805
+ includeCSS,
4806
+ color,
4807
+ popover
4808
+ });
4746
4809
  }
4747
4810
 
4748
4811
  // src/resetFormFields.ts
@@ -4910,12 +4973,16 @@ export {
4910
4973
  hasFiles,
4911
4974
  hrefToUrl,
4912
4975
  http,
4976
+ isPathOrSubPath,
4913
4977
  isPropsObject,
4978
+ isPropsObjectOrCallback,
4914
4979
  isSameUrlWithoutQueryOrHash,
4915
4980
  isUrlMethodPair,
4916
4981
  mergeDataIntoQueryString,
4917
4982
  normalizeLayouts,
4918
4983
  objectToFormData,
4984
+ partialReloadRequestsProp,
4985
+ partialReloadRequestsSomeProps,
4919
4986
  progress,
4920
4987
  resetFormFields,
4921
4988
  resolveUrlMethodPairComponent,