@inertiajs/core 2.3.23 → 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 +119 -25
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +119 -25
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/types/infiniteScroll/data.d.ts +11 -2
- package/types/modal.d.ts +1 -0
- package/types/poll.d.ts +18 -3
- package/types/polls.d.ts +4 -2
- package/types/router.d.ts +3 -1
- package/types/types.d.ts +9 -7
package/dist/index.esm.js
CHANGED
|
@@ -1560,11 +1560,17 @@ var InitialVisit = class {
|
|
|
1560
1560
|
// src/poll.ts
|
|
1561
1561
|
var Poll = class {
|
|
1562
1562
|
constructor(interval, cb, options) {
|
|
1563
|
-
this.
|
|
1563
|
+
this.intervalId = null;
|
|
1564
|
+
this.timeoutId = null;
|
|
1564
1565
|
this.throttle = false;
|
|
1565
1566
|
this.keepAlive = false;
|
|
1566
1567
|
this.cbCount = 0;
|
|
1568
|
+
this.inFlight = false;
|
|
1569
|
+
this.currentCancel = null;
|
|
1570
|
+
this.stopped = true;
|
|
1571
|
+
this.instanceId = 0;
|
|
1567
1572
|
this.keepAlive = options.keepAlive ?? false;
|
|
1573
|
+
this.mode = options.mode ?? "overlap";
|
|
1568
1574
|
this.cb = cb;
|
|
1569
1575
|
this.interval = interval;
|
|
1570
1576
|
if (options.autoStart ?? true) {
|
|
@@ -1572,8 +1578,17 @@ var Poll = class {
|
|
|
1572
1578
|
}
|
|
1573
1579
|
}
|
|
1574
1580
|
stop() {
|
|
1575
|
-
|
|
1576
|
-
|
|
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;
|
|
1577
1592
|
}
|
|
1578
1593
|
}
|
|
1579
1594
|
start() {
|
|
@@ -1581,14 +1596,12 @@ var Poll = class {
|
|
|
1581
1596
|
return;
|
|
1582
1597
|
}
|
|
1583
1598
|
this.stop();
|
|
1584
|
-
this.
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
}
|
|
1591
|
-
}, 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);
|
|
1592
1605
|
}
|
|
1593
1606
|
isInBackground(hidden) {
|
|
1594
1607
|
this.throttle = this.keepAlive ? false : hidden;
|
|
@@ -1596,6 +1609,50 @@ var Poll = class {
|
|
|
1596
1609
|
this.cbCount = 0;
|
|
1597
1610
|
}
|
|
1598
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
|
+
}
|
|
1599
1656
|
};
|
|
1600
1657
|
|
|
1601
1658
|
// src/polls.ts
|
|
@@ -1604,12 +1661,19 @@ var Polls = class {
|
|
|
1604
1661
|
this.polls = [];
|
|
1605
1662
|
this.setupVisibilityListener();
|
|
1606
1663
|
}
|
|
1664
|
+
get count() {
|
|
1665
|
+
return this.polls.length;
|
|
1666
|
+
}
|
|
1607
1667
|
add(interval, cb, options) {
|
|
1608
1668
|
const poll = new Poll(interval, cb, options);
|
|
1609
1669
|
this.polls.push(poll);
|
|
1610
1670
|
return {
|
|
1611
1671
|
stop: () => poll.stop(),
|
|
1612
|
-
start: () => poll.start()
|
|
1672
|
+
start: () => poll.start(),
|
|
1673
|
+
destroy: () => {
|
|
1674
|
+
poll.stop();
|
|
1675
|
+
this.polls = this.polls.filter((p) => p !== poll);
|
|
1676
|
+
}
|
|
1613
1677
|
};
|
|
1614
1678
|
}
|
|
1615
1679
|
clear() {
|
|
@@ -1788,6 +1852,7 @@ import { get as get2, isEqual as isEqual2, set as set2 } from "lodash-es";
|
|
|
1788
1852
|
var modal_default = {
|
|
1789
1853
|
modal: null,
|
|
1790
1854
|
listener: null,
|
|
1855
|
+
previousBodyOverflow: null,
|
|
1791
1856
|
createIframeAndPage(html) {
|
|
1792
1857
|
if (typeof html === "object") {
|
|
1793
1858
|
html = `All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(
|
|
@@ -1818,6 +1883,7 @@ var modal_default = {
|
|
|
1818
1883
|
this.modal.addEventListener("click", () => this.hide());
|
|
1819
1884
|
this.modal.appendChild(iframe);
|
|
1820
1885
|
document.body.prepend(this.modal);
|
|
1886
|
+
this.previousBodyOverflow = document.body.style.overflow;
|
|
1821
1887
|
document.body.style.overflow = "hidden";
|
|
1822
1888
|
iframe.srcdoc = page2.outerHTML;
|
|
1823
1889
|
this.listener = this.hideOnEscape.bind(this);
|
|
@@ -1826,7 +1892,8 @@ var modal_default = {
|
|
|
1826
1892
|
hide() {
|
|
1827
1893
|
this.modal.outerHTML = "";
|
|
1828
1894
|
this.modal = null;
|
|
1829
|
-
document.body.style.overflow = "
|
|
1895
|
+
document.body.style.overflow = this.previousBodyOverflow ?? "";
|
|
1896
|
+
this.previousBodyOverflow = null;
|
|
1830
1897
|
document.removeEventListener("keydown", this.listener);
|
|
1831
1898
|
},
|
|
1832
1899
|
hideOnEscape(event) {
|
|
@@ -2427,6 +2494,9 @@ var Router = class {
|
|
|
2427
2494
|
cancel() {
|
|
2428
2495
|
this.syncRequestStream.cancelInFlight();
|
|
2429
2496
|
}
|
|
2497
|
+
get activePolls() {
|
|
2498
|
+
return polls.count;
|
|
2499
|
+
}
|
|
2430
2500
|
cancelAll({ async = true, prefetch = true, sync = true } = {}) {
|
|
2431
2501
|
if (async) {
|
|
2432
2502
|
this.asyncRequestStream.cancelInFlight({ prefetch });
|
|
@@ -2436,10 +2506,28 @@ var Router = class {
|
|
|
2436
2506
|
}
|
|
2437
2507
|
}
|
|
2438
2508
|
poll(interval, requestOptions = {}, options = {}) {
|
|
2439
|
-
return polls.add(
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
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
|
+
);
|
|
2443
2531
|
}
|
|
2444
2532
|
visit(href, options = {}) {
|
|
2445
2533
|
const visit = this.getPendingVisit(href, {
|
|
@@ -3167,7 +3255,9 @@ var useInfiniteScrollData = (options) => {
|
|
|
3167
3255
|
},
|
|
3168
3256
|
onFinish: (visit) => {
|
|
3169
3257
|
state.loading = false;
|
|
3170
|
-
|
|
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 });
|
|
3171
3261
|
reloadOptions.onFinish?.(visit);
|
|
3172
3262
|
}
|
|
3173
3263
|
});
|
|
@@ -3519,13 +3609,17 @@ function useInfiniteScroll(options) {
|
|
|
3519
3609
|
// so they don't get confused with server-loaded content
|
|
3520
3610
|
onBeforeUpdate: elementManager.processManuallyAddedElements,
|
|
3521
3611
|
// After successful request, tag new server content
|
|
3522
|
-
onCompletePreviousRequest: (
|
|
3523
|
-
options.onCompletePreviousRequest();
|
|
3524
|
-
|
|
3612
|
+
onCompletePreviousRequest: (_, details) => {
|
|
3613
|
+
options.onCompletePreviousRequest(details);
|
|
3614
|
+
if (details.completed) {
|
|
3615
|
+
requestAnimationFrame(() => elementManager.processServerLoadedElements(details.page), 2);
|
|
3616
|
+
}
|
|
3525
3617
|
},
|
|
3526
|
-
onCompleteNextRequest: (
|
|
3527
|
-
options.onCompleteNextRequest();
|
|
3528
|
-
|
|
3618
|
+
onCompleteNextRequest: (_, details) => {
|
|
3619
|
+
options.onCompleteNextRequest(details);
|
|
3620
|
+
if (details.completed) {
|
|
3621
|
+
requestAnimationFrame(() => elementManager.processServerLoadedElements(details.page), 2);
|
|
3622
|
+
}
|
|
3529
3623
|
},
|
|
3530
3624
|
onReset: options.onDataReset
|
|
3531
3625
|
});
|
|
@@ -3948,7 +4042,7 @@ function setupProgress({
|
|
|
3948
4042
|
}
|
|
3949
4043
|
|
|
3950
4044
|
// src/resetFormFields.ts
|
|
3951
|
-
var FormComponentResetSymbol =
|
|
4045
|
+
var FormComponentResetSymbol = Symbol("FormComponentReset");
|
|
3952
4046
|
function isFormElement(element) {
|
|
3953
4047
|
return element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement;
|
|
3954
4048
|
}
|