@inertiajs/core 2.3.22 → 2.3.24

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
@@ -335,6 +335,15 @@ var getKeyFromSessionStorage = async () => {
335
335
  var import_lodash_es2 = require("lodash-es");
336
336
 
337
337
  // src/objectUtils.ts
338
+ var stripTopLevelUndefined = (obj) => {
339
+ const result = {};
340
+ for (const key of Object.keys(obj)) {
341
+ if (obj[key] !== void 0) {
342
+ result[key] = obj[key];
343
+ }
344
+ }
345
+ return result;
346
+ };
338
347
  var objectsAreEqual = (obj1, obj2, excludeKeys) => {
339
348
  if (obj1 === obj2) {
340
349
  return true;
@@ -1609,11 +1618,17 @@ var InitialVisit = class {
1609
1618
  // src/poll.ts
1610
1619
  var Poll = class {
1611
1620
  constructor(interval, cb, options) {
1612
- this.id = null;
1621
+ this.intervalId = null;
1622
+ this.timeoutId = null;
1613
1623
  this.throttle = false;
1614
1624
  this.keepAlive = false;
1615
1625
  this.cbCount = 0;
1626
+ this.inFlight = false;
1627
+ this.currentCancel = null;
1628
+ this.stopped = true;
1629
+ this.instanceId = 0;
1616
1630
  this.keepAlive = options.keepAlive ?? false;
1631
+ this.mode = options.mode ?? "overlap";
1617
1632
  this.cb = cb;
1618
1633
  this.interval = interval;
1619
1634
  if (options.autoStart ?? true) {
@@ -1621,8 +1636,17 @@ var Poll = class {
1621
1636
  }
1622
1637
  }
1623
1638
  stop() {
1624
- if (this.id) {
1625
- clearInterval(this.id);
1639
+ this.stopped = true;
1640
+ this.instanceId++;
1641
+ this.inFlight = false;
1642
+ this.currentCancel = null;
1643
+ if (this.intervalId) {
1644
+ clearInterval(this.intervalId);
1645
+ this.intervalId = null;
1646
+ }
1647
+ if (this.timeoutId) {
1648
+ clearTimeout(this.timeoutId);
1649
+ this.timeoutId = null;
1626
1650
  }
1627
1651
  }
1628
1652
  start() {
@@ -1630,14 +1654,12 @@ var Poll = class {
1630
1654
  return;
1631
1655
  }
1632
1656
  this.stop();
1633
- this.id = window.setInterval(() => {
1634
- if (!this.throttle || this.cbCount % 10 === 0) {
1635
- this.cb();
1636
- }
1637
- if (this.throttle) {
1638
- this.cbCount++;
1639
- }
1640
- }, this.interval);
1657
+ this.stopped = false;
1658
+ if (this.mode === "rest") {
1659
+ this.scheduleNext();
1660
+ return;
1661
+ }
1662
+ this.intervalId = window.setInterval(() => this.tick(), this.interval);
1641
1663
  }
1642
1664
  isInBackground(hidden) {
1643
1665
  this.throttle = this.keepAlive ? false : hidden;
@@ -1645,6 +1667,50 @@ var Poll = class {
1645
1667
  this.cbCount = 0;
1646
1668
  }
1647
1669
  }
1670
+ scheduleNext() {
1671
+ if (this.stopped) {
1672
+ return;
1673
+ }
1674
+ this.timeoutId = window.setTimeout(() => {
1675
+ this.timeoutId = null;
1676
+ this.tick();
1677
+ }, this.interval);
1678
+ }
1679
+ tick() {
1680
+ if (!this.throttle || this.cbCount % 10 === 0) {
1681
+ this.fire();
1682
+ } else if (this.mode === "rest") {
1683
+ this.scheduleNext();
1684
+ }
1685
+ if (this.throttle) {
1686
+ this.cbCount++;
1687
+ }
1688
+ }
1689
+ fire() {
1690
+ if (this.inFlight && this.mode === "cancel") {
1691
+ this.currentCancel?.();
1692
+ }
1693
+ const instance = this.instanceId;
1694
+ this.cb({
1695
+ onStart: (cancel) => {
1696
+ if (instance !== this.instanceId) {
1697
+ return;
1698
+ }
1699
+ this.inFlight = true;
1700
+ this.currentCancel = cancel;
1701
+ },
1702
+ onFinish: () => {
1703
+ if (instance !== this.instanceId) {
1704
+ return;
1705
+ }
1706
+ this.inFlight = false;
1707
+ this.currentCancel = null;
1708
+ if (this.mode === "rest") {
1709
+ this.scheduleNext();
1710
+ }
1711
+ }
1712
+ });
1713
+ }
1648
1714
  };
1649
1715
 
1650
1716
  // src/polls.ts
@@ -1653,12 +1719,19 @@ var Polls = class {
1653
1719
  this.polls = [];
1654
1720
  this.setupVisibilityListener();
1655
1721
  }
1722
+ get count() {
1723
+ return this.polls.length;
1724
+ }
1656
1725
  add(interval, cb, options) {
1657
1726
  const poll = new Poll(interval, cb, options);
1658
1727
  this.polls.push(poll);
1659
1728
  return {
1660
1729
  stop: () => poll.stop(),
1661
- start: () => poll.start()
1730
+ start: () => poll.start(),
1731
+ destroy: () => {
1732
+ poll.stop();
1733
+ this.polls = this.polls.filter((p) => p !== poll);
1734
+ }
1662
1735
  };
1663
1736
  }
1664
1737
  clear() {
@@ -1837,6 +1910,7 @@ var import_lodash_es4 = require("lodash-es");
1837
1910
  var modal_default = {
1838
1911
  modal: null,
1839
1912
  listener: null,
1913
+ previousBodyOverflow: null,
1840
1914
  createIframeAndPage(html) {
1841
1915
  if (typeof html === "object") {
1842
1916
  html = `All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(
@@ -1867,6 +1941,7 @@ var modal_default = {
1867
1941
  this.modal.addEventListener("click", () => this.hide());
1868
1942
  this.modal.appendChild(iframe);
1869
1943
  document.body.prepend(this.modal);
1944
+ this.previousBodyOverflow = document.body.style.overflow;
1870
1945
  document.body.style.overflow = "hidden";
1871
1946
  iframe.srcdoc = page2.outerHTML;
1872
1947
  this.listener = this.hideOnEscape.bind(this);
@@ -1875,7 +1950,8 @@ var modal_default = {
1875
1950
  hide() {
1876
1951
  this.modal.outerHTML = "";
1877
1952
  this.modal = null;
1878
- document.body.style.overflow = "visible";
1953
+ document.body.style.overflow = this.previousBodyOverflow ?? "";
1954
+ this.previousBodyOverflow = null;
1879
1955
  document.removeEventListener("keydown", this.listener);
1880
1956
  },
1881
1957
  hideOnEscape(event) {
@@ -2476,6 +2552,9 @@ var Router = class {
2476
2552
  cancel() {
2477
2553
  this.syncRequestStream.cancelInFlight();
2478
2554
  }
2555
+ get activePolls() {
2556
+ return polls.count;
2557
+ }
2479
2558
  cancelAll({ async = true, prefetch = true, sync = true } = {}) {
2480
2559
  if (async) {
2481
2560
  this.asyncRequestStream.cancelInFlight({ prefetch });
@@ -2485,10 +2564,28 @@ var Router = class {
2485
2564
  }
2486
2565
  }
2487
2566
  poll(interval, requestOptions = {}, options = {}) {
2488
- return polls.add(interval, () => this.reload(requestOptions), {
2489
- autoStart: options.autoStart ?? true,
2490
- keepAlive: options.keepAlive ?? false
2491
- });
2567
+ return polls.add(
2568
+ interval,
2569
+ ({ onStart, onFinish }) => {
2570
+ const resolved = typeof requestOptions === "function" ? requestOptions() : requestOptions;
2571
+ this.reload({
2572
+ ...resolved,
2573
+ onCancelToken: (token) => {
2574
+ onStart(token.cancel);
2575
+ resolved.onCancelToken?.(token);
2576
+ },
2577
+ onFinish: (visit) => {
2578
+ onFinish();
2579
+ resolved.onFinish?.(visit);
2580
+ }
2581
+ });
2582
+ },
2583
+ {
2584
+ autoStart: options.autoStart ?? true,
2585
+ keepAlive: options.keepAlive ?? false,
2586
+ mode: options.mode
2587
+ }
2588
+ );
2492
2589
  }
2493
2590
  visit(href, options = {}) {
2494
2591
  const visit = this.getPendingVisit(href, {
@@ -2741,8 +2838,8 @@ var Router = class {
2741
2838
  prefetch: false,
2742
2839
  invalidateCacheTags: [],
2743
2840
  viewTransition: false,
2744
- ...options,
2745
- ...configuredOptions
2841
+ ...stripTopLevelUndefined(options),
2842
+ ...stripTopLevelUndefined(configuredOptions)
2746
2843
  };
2747
2844
  const [url, _data] = transformUrlAndData(
2748
2845
  href,
@@ -3216,7 +3313,9 @@ var useInfiniteScrollData = (options) => {
3216
3313
  },
3217
3314
  onFinish: (visit) => {
3218
3315
  state.loading = false;
3219
- side === "next" ? options.onCompleteNextRequest(state.lastLoadedPage) : options.onCompletePreviousRequest(state.lastLoadedPage);
3316
+ const completed = visit.completed;
3317
+ const page3 = completed ? state.lastLoadedPage : null;
3318
+ side === "next" ? options.onCompleteNextRequest(page3, { page: page3, completed }) : options.onCompletePreviousRequest(page3, { page: page3, completed });
3220
3319
  reloadOptions.onFinish?.(visit);
3221
3320
  }
3222
3321
  });
@@ -3568,13 +3667,17 @@ function useInfiniteScroll(options) {
3568
3667
  // so they don't get confused with server-loaded content
3569
3668
  onBeforeUpdate: elementManager.processManuallyAddedElements,
3570
3669
  // After successful request, tag new server content
3571
- onCompletePreviousRequest: (loadedPage) => {
3572
- options.onCompletePreviousRequest();
3573
- requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
3670
+ onCompletePreviousRequest: (_, details) => {
3671
+ options.onCompletePreviousRequest(details);
3672
+ if (details.completed) {
3673
+ requestAnimationFrame(() => elementManager.processServerLoadedElements(details.page), 2);
3674
+ }
3574
3675
  },
3575
- onCompleteNextRequest: (loadedPage) => {
3576
- options.onCompleteNextRequest();
3577
- requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
3676
+ onCompleteNextRequest: (_, details) => {
3677
+ options.onCompleteNextRequest(details);
3678
+ if (details.completed) {
3679
+ requestAnimationFrame(() => elementManager.processServerLoadedElements(details.page), 2);
3680
+ }
3578
3681
  },
3579
3682
  onReset: options.onDataReset
3580
3683
  });
@@ -3997,7 +4100,7 @@ function setupProgress({
3997
4100
  }
3998
4101
 
3999
4102
  // src/resetFormFields.ts
4000
- var FormComponentResetSymbol = /* @__PURE__ */ Symbol("FormComponentReset");
4103
+ var FormComponentResetSymbol = Symbol("FormComponentReset");
4001
4104
  function isFormElement(element) {
4002
4105
  return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
4003
4106
  }