@dnd-kit/dom 0.1.21 → 0.2.0-beta-20251026132120
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/index.cjs +122 -74
- package/index.cjs.map +1 -1
- package/index.d.cts +104 -96
- package/index.d.ts +104 -96
- package/index.js +125 -78
- package/index.js.map +1 -1
- package/package.json +5 -5
- package/utilities.cjs +51 -9
- package/utilities.cjs.map +1 -1
- package/utilities.d.cts +16 -2
- package/utilities.d.ts +16 -2
- package/utilities.js +50 -10
- package/utilities.js.map +1 -1
package/index.cjs
CHANGED
|
@@ -1527,6 +1527,93 @@ var KeyboardSensor = _KeyboardSensor;
|
|
|
1527
1527
|
function isKeycode(event, codes) {
|
|
1528
1528
|
return codes.includes(event.code);
|
|
1529
1529
|
}
|
|
1530
|
+
var _coordinates;
|
|
1531
|
+
var DistanceConstraint = class extends abstract.ActivationConstraint {
|
|
1532
|
+
constructor() {
|
|
1533
|
+
super(...arguments);
|
|
1534
|
+
__privateAdd(this, _coordinates);
|
|
1535
|
+
}
|
|
1536
|
+
onEvent(event) {
|
|
1537
|
+
switch (event.type) {
|
|
1538
|
+
case "pointerdown":
|
|
1539
|
+
__privateSet(this, _coordinates, utilities.getEventCoordinates(event));
|
|
1540
|
+
break;
|
|
1541
|
+
case "pointermove":
|
|
1542
|
+
if (!__privateGet(this, _coordinates)) return;
|
|
1543
|
+
const { x, y } = utilities.getEventCoordinates(event);
|
|
1544
|
+
const delta = {
|
|
1545
|
+
x: x - __privateGet(this, _coordinates).x,
|
|
1546
|
+
y: y - __privateGet(this, _coordinates).y
|
|
1547
|
+
};
|
|
1548
|
+
const { tolerance } = this.options;
|
|
1549
|
+
if (tolerance && geometry.exceedsDistance(delta, tolerance)) {
|
|
1550
|
+
this.abort();
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
if (geometry.exceedsDistance(delta, this.options.value)) {
|
|
1554
|
+
this.activate(event);
|
|
1555
|
+
}
|
|
1556
|
+
break;
|
|
1557
|
+
case "pointerup":
|
|
1558
|
+
this.abort();
|
|
1559
|
+
break;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
abort() {
|
|
1563
|
+
__privateSet(this, _coordinates, void 0);
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
_coordinates = new WeakMap();
|
|
1567
|
+
var _timeout2, _coordinates2;
|
|
1568
|
+
var DelayConstraint = class extends abstract.ActivationConstraint {
|
|
1569
|
+
constructor() {
|
|
1570
|
+
super(...arguments);
|
|
1571
|
+
__privateAdd(this, _timeout2);
|
|
1572
|
+
__privateAdd(this, _coordinates2);
|
|
1573
|
+
}
|
|
1574
|
+
onEvent(event) {
|
|
1575
|
+
switch (event.type) {
|
|
1576
|
+
case "pointerdown":
|
|
1577
|
+
__privateSet(this, _coordinates2, utilities.getEventCoordinates(event));
|
|
1578
|
+
__privateSet(this, _timeout2, setTimeout(
|
|
1579
|
+
() => this.activate(event),
|
|
1580
|
+
this.options.value
|
|
1581
|
+
));
|
|
1582
|
+
break;
|
|
1583
|
+
case "pointermove":
|
|
1584
|
+
if (!__privateGet(this, _coordinates2)) return;
|
|
1585
|
+
const { x, y } = utilities.getEventCoordinates(event);
|
|
1586
|
+
const delta = {
|
|
1587
|
+
x: x - __privateGet(this, _coordinates2).x,
|
|
1588
|
+
y: y - __privateGet(this, _coordinates2).y
|
|
1589
|
+
};
|
|
1590
|
+
if (geometry.exceedsDistance(delta, this.options.tolerance)) {
|
|
1591
|
+
this.abort();
|
|
1592
|
+
}
|
|
1593
|
+
break;
|
|
1594
|
+
case "pointerup":
|
|
1595
|
+
this.abort();
|
|
1596
|
+
break;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
abort() {
|
|
1600
|
+
if (__privateGet(this, _timeout2)) {
|
|
1601
|
+
clearTimeout(__privateGet(this, _timeout2));
|
|
1602
|
+
__privateSet(this, _coordinates2, void 0);
|
|
1603
|
+
__privateSet(this, _timeout2, void 0);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
_timeout2 = new WeakMap();
|
|
1608
|
+
_coordinates2 = new WeakMap();
|
|
1609
|
+
|
|
1610
|
+
// src/core/sensors/pointer/PointerActivationConstraints.ts
|
|
1611
|
+
var PointerActivationConstraints = class {
|
|
1612
|
+
};
|
|
1613
|
+
PointerActivationConstraints.Delay = DelayConstraint;
|
|
1614
|
+
PointerActivationConstraints.Distance = DistanceConstraint;
|
|
1615
|
+
|
|
1616
|
+
// src/core/sensors/pointer/PointerSensor.ts
|
|
1530
1617
|
var defaults2 = Object.freeze({
|
|
1531
1618
|
activationConstraints(event, source) {
|
|
1532
1619
|
var _a4;
|
|
@@ -1535,29 +1622,28 @@ var defaults2 = Object.freeze({
|
|
|
1535
1622
|
return void 0;
|
|
1536
1623
|
}
|
|
1537
1624
|
if (pointerType === "touch") {
|
|
1538
|
-
return
|
|
1539
|
-
|
|
1540
|
-
|
|
1625
|
+
return [
|
|
1626
|
+
new PointerActivationConstraints.Delay({ value: 250, tolerance: 5 })
|
|
1627
|
+
];
|
|
1541
1628
|
}
|
|
1542
1629
|
if (utilities.isTextInput(target) && !event.defaultPrevented) {
|
|
1543
|
-
return
|
|
1544
|
-
|
|
1545
|
-
|
|
1630
|
+
return [
|
|
1631
|
+
new PointerActivationConstraints.Delay({ value: 200, tolerance: 0 })
|
|
1632
|
+
];
|
|
1546
1633
|
}
|
|
1547
|
-
return
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1634
|
+
return [
|
|
1635
|
+
new PointerActivationConstraints.Delay({ value: 200, tolerance: 10 }),
|
|
1636
|
+
new PointerActivationConstraints.Distance({ value: 5 })
|
|
1637
|
+
];
|
|
1551
1638
|
}
|
|
1552
1639
|
});
|
|
1553
|
-
var _cleanup
|
|
1640
|
+
var _cleanup;
|
|
1554
1641
|
var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
1555
1642
|
constructor(manager, options) {
|
|
1556
1643
|
super(manager);
|
|
1557
1644
|
this.manager = manager;
|
|
1558
1645
|
this.options = options;
|
|
1559
1646
|
__privateAdd(this, _cleanup, /* @__PURE__ */ new Set());
|
|
1560
|
-
__privateAdd(this, _clearTimeout);
|
|
1561
1647
|
this.listeners = new utilities.Listeners();
|
|
1562
1648
|
this.latest = {
|
|
1563
1649
|
event: void 0,
|
|
@@ -1614,29 +1700,22 @@ var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
|
1614
1700
|
const { target } = event;
|
|
1615
1701
|
const isNativeDraggable = utilities.isHTMLElement(target) && target.draggable && target.getAttribute("draggable") === "true";
|
|
1616
1702
|
const offset = utilities.getFrameTransform(source.element);
|
|
1703
|
+
const { x, y } = utilities.getEventCoordinates(event);
|
|
1617
1704
|
this.initialCoordinates = {
|
|
1618
|
-
x:
|
|
1619
|
-
y:
|
|
1705
|
+
x: x * offset.scaleX + offset.x,
|
|
1706
|
+
y: y * offset.scaleY + offset.y
|
|
1620
1707
|
};
|
|
1621
1708
|
const constraints = this.activationConstraints(event, source);
|
|
1622
1709
|
event.sensor = this;
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
__privateSet(this, _clearTimeout, () => {
|
|
1633
|
-
clearTimeout(timeout);
|
|
1634
|
-
__privateSet(this, _clearTimeout, void 0);
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
const ownerDocument = utilities.getDocument(event.target);
|
|
1639
|
-
const unbindListeners = this.listeners.bind(ownerDocument, [
|
|
1710
|
+
const controller = new abstract.ActivationController(
|
|
1711
|
+
constraints,
|
|
1712
|
+
(event2) => this.handleStart(source, event2)
|
|
1713
|
+
);
|
|
1714
|
+
controller.signal.onabort = () => this.handleCancel(event);
|
|
1715
|
+
controller.onEvent(event);
|
|
1716
|
+
this.controller = controller;
|
|
1717
|
+
const documents = utilities.getDocuments();
|
|
1718
|
+
const unbindListeners = this.listeners.bind(documents, [
|
|
1640
1719
|
{
|
|
1641
1720
|
type: "pointermove",
|
|
1642
1721
|
listener: (event2) => this.handlePointerMove(event2, source)
|
|
@@ -1658,50 +1737,27 @@ var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
|
1658
1737
|
}
|
|
1659
1738
|
]);
|
|
1660
1739
|
const cleanup = () => {
|
|
1661
|
-
var _a4;
|
|
1662
1740
|
unbindListeners();
|
|
1663
|
-
(_a4 = __privateGet(this, _clearTimeout)) == null ? void 0 : _a4.call(this);
|
|
1664
1741
|
this.initialCoordinates = void 0;
|
|
1665
1742
|
};
|
|
1666
1743
|
__privateGet(this, _cleanup).add(cleanup);
|
|
1667
1744
|
}
|
|
1668
1745
|
handlePointerMove(event, source) {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
coordinates.x = coordinates.x * offset.scaleX + offset.x;
|
|
1675
|
-
coordinates.y = coordinates.y * offset.scaleY + offset.y;
|
|
1746
|
+
var _a4, _b2;
|
|
1747
|
+
if (((_a4 = this.controller) == null ? void 0 : _a4.activated) === false) {
|
|
1748
|
+
(_b2 = this.controller) == null ? void 0 : _b2.onEvent(event);
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1676
1751
|
if (this.manager.dragOperation.status.dragging) {
|
|
1752
|
+
const coordinates = utilities.getEventCoordinates(event);
|
|
1753
|
+
const offset = utilities.getFrameTransform(source.element);
|
|
1754
|
+
coordinates.x = coordinates.x * offset.scaleX + offset.x;
|
|
1755
|
+
coordinates.y = coordinates.y * offset.scaleY + offset.y;
|
|
1677
1756
|
event.preventDefault();
|
|
1678
1757
|
event.stopPropagation();
|
|
1679
1758
|
this.latest.event = event;
|
|
1680
1759
|
this.latest.coordinates = coordinates;
|
|
1681
1760
|
utilities.scheduler.schedule(this.handleMove);
|
|
1682
|
-
return;
|
|
1683
|
-
}
|
|
1684
|
-
if (!this.initialCoordinates) {
|
|
1685
|
-
return;
|
|
1686
|
-
}
|
|
1687
|
-
const delta = {
|
|
1688
|
-
x: coordinates.x - this.initialCoordinates.x,
|
|
1689
|
-
y: coordinates.y - this.initialCoordinates.y
|
|
1690
|
-
};
|
|
1691
|
-
const constraints = this.activationConstraints(event, source);
|
|
1692
|
-
const { distance, delay } = constraints != null ? constraints : {};
|
|
1693
|
-
if (distance) {
|
|
1694
|
-
if (distance.tolerance != null && geometry.exceedsDistance(delta, distance.tolerance)) {
|
|
1695
|
-
return this.handleCancel(event);
|
|
1696
|
-
}
|
|
1697
|
-
if (geometry.exceedsDistance(delta, distance.value)) {
|
|
1698
|
-
return this.handleStart(source, event);
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
if (delay) {
|
|
1702
|
-
if (geometry.exceedsDistance(delta, delay.tolerance)) {
|
|
1703
|
-
return this.handleCancel(event);
|
|
1704
|
-
}
|
|
1705
1761
|
}
|
|
1706
1762
|
}
|
|
1707
1763
|
handlePointerUp(event) {
|
|
@@ -1721,9 +1777,7 @@ var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
|
1721
1777
|
}
|
|
1722
1778
|
}
|
|
1723
1779
|
handleStart(source, event) {
|
|
1724
|
-
var _a4;
|
|
1725
1780
|
const { manager, initialCoordinates } = this;
|
|
1726
|
-
(_a4 = __privateGet(this, _clearTimeout)) == null ? void 0 : _a4.call(this);
|
|
1727
1781
|
if (!initialCoordinates || !manager.dragOperation.status.idle) {
|
|
1728
1782
|
return;
|
|
1729
1783
|
}
|
|
@@ -1740,7 +1794,8 @@ var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
|
1740
1794
|
const ownerDocument = utilities.getDocument(event.target);
|
|
1741
1795
|
const pointerCaptureTarget = ownerDocument.body;
|
|
1742
1796
|
pointerCaptureTarget.setPointerCapture(event.pointerId);
|
|
1743
|
-
const
|
|
1797
|
+
const listenerTargets = utilities.isElement(event.target) ? [event.target, ownerDocument.body] : ownerDocument.body;
|
|
1798
|
+
const unbind = this.listeners.bind(listenerTargets, [
|
|
1744
1799
|
{
|
|
1745
1800
|
// Prevent scrolling on touch devices
|
|
1746
1801
|
type: "touchmove",
|
|
@@ -1761,13 +1816,6 @@ var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
|
1761
1816
|
{
|
|
1762
1817
|
type: "keydown",
|
|
1763
1818
|
listener: this.handleKeyDown
|
|
1764
|
-
},
|
|
1765
|
-
{
|
|
1766
|
-
type: "lostpointercapture",
|
|
1767
|
-
listener: (event2) => {
|
|
1768
|
-
if (event2.target !== pointerCaptureTarget) return;
|
|
1769
|
-
this.handlePointerUp(event2);
|
|
1770
|
-
}
|
|
1771
1819
|
}
|
|
1772
1820
|
]);
|
|
1773
1821
|
__privateGet(this, _cleanup).add(unbind);
|
|
@@ -1793,7 +1841,6 @@ var _PointerSensor = class _PointerSensor extends abstract.Sensor {
|
|
|
1793
1841
|
}
|
|
1794
1842
|
};
|
|
1795
1843
|
_cleanup = new WeakMap();
|
|
1796
|
-
_clearTimeout = new WeakMap();
|
|
1797
1844
|
_PointerSensor.configure = abstract.configurator(_PointerSensor);
|
|
1798
1845
|
_PointerSensor.defaults = defaults2;
|
|
1799
1846
|
var PointerSensor = _PointerSensor;
|
|
@@ -1982,6 +2029,7 @@ exports.Draggable = Draggable;
|
|
|
1982
2029
|
exports.Droppable = Droppable;
|
|
1983
2030
|
exports.Feedback = Feedback;
|
|
1984
2031
|
exports.KeyboardSensor = KeyboardSensor;
|
|
2032
|
+
exports.PointerActivationConstraints = PointerActivationConstraints;
|
|
1985
2033
|
exports.PointerSensor = PointerSensor;
|
|
1986
2034
|
exports.PreventSelection = PreventSelection;
|
|
1987
2035
|
exports.ScrollListener = ScrollListener;
|