@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.esm.js CHANGED
@@ -277,6 +277,15 @@ var getKeyFromSessionStorage = async () => {
277
277
  import { cloneDeep } from "lodash-es";
278
278
 
279
279
  // src/objectUtils.ts
280
+ var stripTopLevelUndefined = (obj) => {
281
+ const result = {};
282
+ for (const key of Object.keys(obj)) {
283
+ if (obj[key] !== void 0) {
284
+ result[key] = obj[key];
285
+ }
286
+ }
287
+ return result;
288
+ };
280
289
  var objectsAreEqual = (obj1, obj2, excludeKeys) => {
281
290
  if (obj1 === obj2) {
282
291
  return true;
@@ -1551,11 +1560,17 @@ var InitialVisit = class {
1551
1560
  // src/poll.ts
1552
1561
  var Poll = class {
1553
1562
  constructor(interval, cb, options) {
1554
- this.id = null;
1563
+ this.intervalId = null;
1564
+ this.timeoutId = null;
1555
1565
  this.throttle = false;
1556
1566
  this.keepAlive = false;
1557
1567
  this.cbCount = 0;
1568
+ this.inFlight = false;
1569
+ this.currentCancel = null;
1570
+ this.stopped = true;
1571
+ this.instanceId = 0;
1558
1572
  this.keepAlive = options.keepAlive ?? false;
1573
+ this.mode = options.mode ?? "overlap";
1559
1574
  this.cb = cb;
1560
1575
  this.interval = interval;
1561
1576
  if (options.autoStart ?? true) {
@@ -1563,8 +1578,17 @@ var Poll = class {
1563
1578
  }
1564
1579
  }
1565
1580
  stop() {
1566
- if (this.id) {
1567
- clearInterval(this.id);
1581
+ this.stopped = true;
1582
+ this.instanceId++;
1583
+ this.inFlight = false;
1584
+ this.currentCancel = null;
1585
+ if (this.intervalId) {
1586
+ clearInterval(this.intervalId);
1587
+ this.intervalId = null;
1588
+ }
1589
+ if (this.timeoutId) {
1590
+ clearTimeout(this.timeoutId);
1591
+ this.timeoutId = null;
1568
1592
  }
1569
1593
  }
1570
1594
  start() {
@@ -1572,14 +1596,12 @@ var Poll = class {
1572
1596
  return;
1573
1597
  }
1574
1598
  this.stop();
1575
- this.id = window.setInterval(() => {
1576
- if (!this.throttle || this.cbCount % 10 === 0) {
1577
- this.cb();
1578
- }
1579
- if (this.throttle) {
1580
- this.cbCount++;
1581
- }
1582
- }, this.interval);
1599
+ this.stopped = false;
1600
+ if (this.mode === "rest") {
1601
+ this.scheduleNext();
1602
+ return;
1603
+ }
1604
+ this.intervalId = window.setInterval(() => this.tick(), this.interval);
1583
1605
  }
1584
1606
  isInBackground(hidden) {
1585
1607
  this.throttle = this.keepAlive ? false : hidden;
@@ -1587,6 +1609,50 @@ var Poll = class {
1587
1609
  this.cbCount = 0;
1588
1610
  }
1589
1611
  }
1612
+ scheduleNext() {
1613
+ if (this.stopped) {
1614
+ return;
1615
+ }
1616
+ this.timeoutId = window.setTimeout(() => {
1617
+ this.timeoutId = null;
1618
+ this.tick();
1619
+ }, this.interval);
1620
+ }
1621
+ tick() {
1622
+ if (!this.throttle || this.cbCount % 10 === 0) {
1623
+ this.fire();
1624
+ } else if (this.mode === "rest") {
1625
+ this.scheduleNext();
1626
+ }
1627
+ if (this.throttle) {
1628
+ this.cbCount++;
1629
+ }
1630
+ }
1631
+ fire() {
1632
+ if (this.inFlight && this.mode === "cancel") {
1633
+ this.currentCancel?.();
1634
+ }
1635
+ const instance = this.instanceId;
1636
+ this.cb({
1637
+ onStart: (cancel) => {
1638
+ if (instance !== this.instanceId) {
1639
+ return;
1640
+ }
1641
+ this.inFlight = true;
1642
+ this.currentCancel = cancel;
1643
+ },
1644
+ onFinish: () => {
1645
+ if (instance !== this.instanceId) {
1646
+ return;
1647
+ }
1648
+ this.inFlight = false;
1649
+ this.currentCancel = null;
1650
+ if (this.mode === "rest") {
1651
+ this.scheduleNext();
1652
+ }
1653
+ }
1654
+ });
1655
+ }
1590
1656
  };
1591
1657
 
1592
1658
  // src/polls.ts
@@ -1595,12 +1661,19 @@ var Polls = class {
1595
1661
  this.polls = [];
1596
1662
  this.setupVisibilityListener();
1597
1663
  }
1664
+ get count() {
1665
+ return this.polls.length;
1666
+ }
1598
1667
  add(interval, cb, options) {
1599
1668
  const poll = new Poll(interval, cb, options);
1600
1669
  this.polls.push(poll);
1601
1670
  return {
1602
1671
  stop: () => poll.stop(),
1603
- start: () => poll.start()
1672
+ start: () => poll.start(),
1673
+ destroy: () => {
1674
+ poll.stop();
1675
+ this.polls = this.polls.filter((p) => p !== poll);
1676
+ }
1604
1677
  };
1605
1678
  }
1606
1679
  clear() {
@@ -1779,6 +1852,7 @@ import { get as get2, isEqual as isEqual2, set as set2 } from "lodash-es";
1779
1852
  var modal_default = {
1780
1853
  modal: null,
1781
1854
  listener: null,
1855
+ previousBodyOverflow: null,
1782
1856
  createIframeAndPage(html) {
1783
1857
  if (typeof html === "object") {
1784
1858
  html = `All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(
@@ -1809,6 +1883,7 @@ var modal_default = {
1809
1883
  this.modal.addEventListener("click", () => this.hide());
1810
1884
  this.modal.appendChild(iframe);
1811
1885
  document.body.prepend(this.modal);
1886
+ this.previousBodyOverflow = document.body.style.overflow;
1812
1887
  document.body.style.overflow = "hidden";
1813
1888
  iframe.srcdoc = page2.outerHTML;
1814
1889
  this.listener = this.hideOnEscape.bind(this);
@@ -1817,7 +1892,8 @@ var modal_default = {
1817
1892
  hide() {
1818
1893
  this.modal.outerHTML = "";
1819
1894
  this.modal = null;
1820
- document.body.style.overflow = "visible";
1895
+ document.body.style.overflow = this.previousBodyOverflow ?? "";
1896
+ this.previousBodyOverflow = null;
1821
1897
  document.removeEventListener("keydown", this.listener);
1822
1898
  },
1823
1899
  hideOnEscape(event) {
@@ -2418,6 +2494,9 @@ var Router = class {
2418
2494
  cancel() {
2419
2495
  this.syncRequestStream.cancelInFlight();
2420
2496
  }
2497
+ get activePolls() {
2498
+ return polls.count;
2499
+ }
2421
2500
  cancelAll({ async = true, prefetch = true, sync = true } = {}) {
2422
2501
  if (async) {
2423
2502
  this.asyncRequestStream.cancelInFlight({ prefetch });
@@ -2427,10 +2506,28 @@ var Router = class {
2427
2506
  }
2428
2507
  }
2429
2508
  poll(interval, requestOptions = {}, options = {}) {
2430
- return polls.add(interval, () => this.reload(requestOptions), {
2431
- autoStart: options.autoStart ?? true,
2432
- keepAlive: options.keepAlive ?? false
2433
- });
2509
+ return polls.add(
2510
+ interval,
2511
+ ({ onStart, onFinish }) => {
2512
+ const resolved = typeof requestOptions === "function" ? requestOptions() : requestOptions;
2513
+ this.reload({
2514
+ ...resolved,
2515
+ onCancelToken: (token) => {
2516
+ onStart(token.cancel);
2517
+ resolved.onCancelToken?.(token);
2518
+ },
2519
+ onFinish: (visit) => {
2520
+ onFinish();
2521
+ resolved.onFinish?.(visit);
2522
+ }
2523
+ });
2524
+ },
2525
+ {
2526
+ autoStart: options.autoStart ?? true,
2527
+ keepAlive: options.keepAlive ?? false,
2528
+ mode: options.mode
2529
+ }
2530
+ );
2434
2531
  }
2435
2532
  visit(href, options = {}) {
2436
2533
  const visit = this.getPendingVisit(href, {
@@ -2683,8 +2780,8 @@ var Router = class {
2683
2780
  prefetch: false,
2684
2781
  invalidateCacheTags: [],
2685
2782
  viewTransition: false,
2686
- ...options,
2687
- ...configuredOptions
2783
+ ...stripTopLevelUndefined(options),
2784
+ ...stripTopLevelUndefined(configuredOptions)
2688
2785
  };
2689
2786
  const [url, _data] = transformUrlAndData(
2690
2787
  href,
@@ -3158,7 +3255,9 @@ var useInfiniteScrollData = (options) => {
3158
3255
  },
3159
3256
  onFinish: (visit) => {
3160
3257
  state.loading = false;
3161
- side === "next" ? options.onCompleteNextRequest(state.lastLoadedPage) : options.onCompletePreviousRequest(state.lastLoadedPage);
3258
+ const completed = visit.completed;
3259
+ const page3 = completed ? state.lastLoadedPage : null;
3260
+ side === "next" ? options.onCompleteNextRequest(page3, { page: page3, completed }) : options.onCompletePreviousRequest(page3, { page: page3, completed });
3162
3261
  reloadOptions.onFinish?.(visit);
3163
3262
  }
3164
3263
  });
@@ -3510,13 +3609,17 @@ function useInfiniteScroll(options) {
3510
3609
  // so they don't get confused with server-loaded content
3511
3610
  onBeforeUpdate: elementManager.processManuallyAddedElements,
3512
3611
  // After successful request, tag new server content
3513
- onCompletePreviousRequest: (loadedPage) => {
3514
- options.onCompletePreviousRequest();
3515
- requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
3612
+ onCompletePreviousRequest: (_, details) => {
3613
+ options.onCompletePreviousRequest(details);
3614
+ if (details.completed) {
3615
+ requestAnimationFrame(() => elementManager.processServerLoadedElements(details.page), 2);
3616
+ }
3516
3617
  },
3517
- onCompleteNextRequest: (loadedPage) => {
3518
- options.onCompleteNextRequest();
3519
- requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
3618
+ onCompleteNextRequest: (_, details) => {
3619
+ options.onCompleteNextRequest(details);
3620
+ if (details.completed) {
3621
+ requestAnimationFrame(() => elementManager.processServerLoadedElements(details.page), 2);
3622
+ }
3520
3623
  },
3521
3624
  onReset: options.onDataReset
3522
3625
  });
@@ -3939,7 +4042,7 @@ function setupProgress({
3939
4042
  }
3940
4043
 
3941
4044
  // src/resetFormFields.ts
3942
- var FormComponentResetSymbol = /* @__PURE__ */ Symbol("FormComponentReset");
4045
+ var FormComponentResetSymbol = Symbol("FormComponentReset");
3943
4046
  function isFormElement(element) {
3944
4047
  return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
3945
4048
  }