@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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { configurator, Sensor, Plugin, CorePlugin, DragDropManager as DragDropManager$1, Draggable as Draggable$1, Droppable as Droppable$1, descriptor } from '@dnd-kit/abstract';
|
|
2
|
-
import { ScrollDirection, Listeners, isElement, scrollIntoViewIfNeeded, DOMRectangle, getDocument, isHTMLElement, getFrameTransform, scheduler, isTextInput, isKeyboardEvent, isPointerEvent, canScroll, detectScrollIntent, getElementFromPoint, getScrollableAncestors, generateUniqueId, isSafari, Styles, getComputedStyles, parseTranslate, supportsPopover, showPopover, getWindow, supportsStyle, getFrameElement, cloneElement, getFinalKeyframe, animateTransform, ProxiedElements, PositionObserver } from '@dnd-kit/dom/utilities';
|
|
1
|
+
import { configurator, Sensor, ActivationController, Plugin, CorePlugin, DragDropManager as DragDropManager$1, Draggable as Draggable$1, Droppable as Droppable$1, ActivationConstraint, descriptor } from '@dnd-kit/abstract';
|
|
2
|
+
import { ScrollDirection, Listeners, isElement, scrollIntoViewIfNeeded, DOMRectangle, getDocument, isHTMLElement, getFrameTransform, getEventCoordinates, getDocuments, scheduler, isTextInput, isKeyboardEvent, isPointerEvent, canScroll, detectScrollIntent, getElementFromPoint, getScrollableAncestors, generateUniqueId, isSafari, Styles, getComputedStyles, parseTranslate, supportsPopover, showPopover, getWindow, supportsStyle, getFrameElement, cloneElement, getFinalKeyframe, animateTransform, ProxiedElements, PositionObserver } from '@dnd-kit/dom/utilities';
|
|
3
3
|
import { effect, computed, deepEqual, signal, batch, untracked, effects, reactive } from '@dnd-kit/state';
|
|
4
|
-
import {
|
|
4
|
+
import { Axes, Point, Rectangle, exceedsDistance } from '@dnd-kit/geometry';
|
|
5
5
|
import { defaultCollisionDetection } from '@dnd-kit/collision';
|
|
6
6
|
|
|
7
7
|
var __create = Object.create;
|
|
@@ -1525,6 +1525,93 @@ var KeyboardSensor = _KeyboardSensor;
|
|
|
1525
1525
|
function isKeycode(event, codes) {
|
|
1526
1526
|
return codes.includes(event.code);
|
|
1527
1527
|
}
|
|
1528
|
+
var _coordinates;
|
|
1529
|
+
var DistanceConstraint = class extends ActivationConstraint {
|
|
1530
|
+
constructor() {
|
|
1531
|
+
super(...arguments);
|
|
1532
|
+
__privateAdd(this, _coordinates);
|
|
1533
|
+
}
|
|
1534
|
+
onEvent(event) {
|
|
1535
|
+
switch (event.type) {
|
|
1536
|
+
case "pointerdown":
|
|
1537
|
+
__privateSet(this, _coordinates, getEventCoordinates(event));
|
|
1538
|
+
break;
|
|
1539
|
+
case "pointermove":
|
|
1540
|
+
if (!__privateGet(this, _coordinates)) return;
|
|
1541
|
+
const { x, y } = getEventCoordinates(event);
|
|
1542
|
+
const delta = {
|
|
1543
|
+
x: x - __privateGet(this, _coordinates).x,
|
|
1544
|
+
y: y - __privateGet(this, _coordinates).y
|
|
1545
|
+
};
|
|
1546
|
+
const { tolerance } = this.options;
|
|
1547
|
+
if (tolerance && exceedsDistance(delta, tolerance)) {
|
|
1548
|
+
this.abort();
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (exceedsDistance(delta, this.options.value)) {
|
|
1552
|
+
this.activate(event);
|
|
1553
|
+
}
|
|
1554
|
+
break;
|
|
1555
|
+
case "pointerup":
|
|
1556
|
+
this.abort();
|
|
1557
|
+
break;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
abort() {
|
|
1561
|
+
__privateSet(this, _coordinates, void 0);
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
_coordinates = new WeakMap();
|
|
1565
|
+
var _timeout2, _coordinates2;
|
|
1566
|
+
var DelayConstraint = class extends ActivationConstraint {
|
|
1567
|
+
constructor() {
|
|
1568
|
+
super(...arguments);
|
|
1569
|
+
__privateAdd(this, _timeout2);
|
|
1570
|
+
__privateAdd(this, _coordinates2);
|
|
1571
|
+
}
|
|
1572
|
+
onEvent(event) {
|
|
1573
|
+
switch (event.type) {
|
|
1574
|
+
case "pointerdown":
|
|
1575
|
+
__privateSet(this, _coordinates2, getEventCoordinates(event));
|
|
1576
|
+
__privateSet(this, _timeout2, setTimeout(
|
|
1577
|
+
() => this.activate(event),
|
|
1578
|
+
this.options.value
|
|
1579
|
+
));
|
|
1580
|
+
break;
|
|
1581
|
+
case "pointermove":
|
|
1582
|
+
if (!__privateGet(this, _coordinates2)) return;
|
|
1583
|
+
const { x, y } = getEventCoordinates(event);
|
|
1584
|
+
const delta = {
|
|
1585
|
+
x: x - __privateGet(this, _coordinates2).x,
|
|
1586
|
+
y: y - __privateGet(this, _coordinates2).y
|
|
1587
|
+
};
|
|
1588
|
+
if (exceedsDistance(delta, this.options.tolerance)) {
|
|
1589
|
+
this.abort();
|
|
1590
|
+
}
|
|
1591
|
+
break;
|
|
1592
|
+
case "pointerup":
|
|
1593
|
+
this.abort();
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
abort() {
|
|
1598
|
+
if (__privateGet(this, _timeout2)) {
|
|
1599
|
+
clearTimeout(__privateGet(this, _timeout2));
|
|
1600
|
+
__privateSet(this, _coordinates2, void 0);
|
|
1601
|
+
__privateSet(this, _timeout2, void 0);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
_timeout2 = new WeakMap();
|
|
1606
|
+
_coordinates2 = new WeakMap();
|
|
1607
|
+
|
|
1608
|
+
// src/core/sensors/pointer/PointerActivationConstraints.ts
|
|
1609
|
+
var PointerActivationConstraints = class {
|
|
1610
|
+
};
|
|
1611
|
+
PointerActivationConstraints.Delay = DelayConstraint;
|
|
1612
|
+
PointerActivationConstraints.Distance = DistanceConstraint;
|
|
1613
|
+
|
|
1614
|
+
// src/core/sensors/pointer/PointerSensor.ts
|
|
1528
1615
|
var defaults2 = Object.freeze({
|
|
1529
1616
|
activationConstraints(event, source) {
|
|
1530
1617
|
var _a4;
|
|
@@ -1533,29 +1620,28 @@ var defaults2 = Object.freeze({
|
|
|
1533
1620
|
return void 0;
|
|
1534
1621
|
}
|
|
1535
1622
|
if (pointerType === "touch") {
|
|
1536
|
-
return
|
|
1537
|
-
|
|
1538
|
-
|
|
1623
|
+
return [
|
|
1624
|
+
new PointerActivationConstraints.Delay({ value: 250, tolerance: 5 })
|
|
1625
|
+
];
|
|
1539
1626
|
}
|
|
1540
1627
|
if (isTextInput(target) && !event.defaultPrevented) {
|
|
1541
|
-
return
|
|
1542
|
-
|
|
1543
|
-
|
|
1628
|
+
return [
|
|
1629
|
+
new PointerActivationConstraints.Delay({ value: 200, tolerance: 0 })
|
|
1630
|
+
];
|
|
1544
1631
|
}
|
|
1545
|
-
return
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1632
|
+
return [
|
|
1633
|
+
new PointerActivationConstraints.Delay({ value: 200, tolerance: 10 }),
|
|
1634
|
+
new PointerActivationConstraints.Distance({ value: 5 })
|
|
1635
|
+
];
|
|
1549
1636
|
}
|
|
1550
1637
|
});
|
|
1551
|
-
var _cleanup
|
|
1638
|
+
var _cleanup;
|
|
1552
1639
|
var _PointerSensor = class _PointerSensor extends Sensor {
|
|
1553
1640
|
constructor(manager, options) {
|
|
1554
1641
|
super(manager);
|
|
1555
1642
|
this.manager = manager;
|
|
1556
1643
|
this.options = options;
|
|
1557
1644
|
__privateAdd(this, _cleanup, /* @__PURE__ */ new Set());
|
|
1558
|
-
__privateAdd(this, _clearTimeout);
|
|
1559
1645
|
this.listeners = new Listeners();
|
|
1560
1646
|
this.latest = {
|
|
1561
1647
|
event: void 0,
|
|
@@ -1612,29 +1698,22 @@ var _PointerSensor = class _PointerSensor extends Sensor {
|
|
|
1612
1698
|
const { target } = event;
|
|
1613
1699
|
const isNativeDraggable = isHTMLElement(target) && target.draggable && target.getAttribute("draggable") === "true";
|
|
1614
1700
|
const offset = getFrameTransform(source.element);
|
|
1701
|
+
const { x, y } = getEventCoordinates(event);
|
|
1615
1702
|
this.initialCoordinates = {
|
|
1616
|
-
x:
|
|
1617
|
-
y:
|
|
1703
|
+
x: x * offset.scaleX + offset.x,
|
|
1704
|
+
y: y * offset.scaleY + offset.y
|
|
1618
1705
|
};
|
|
1619
1706
|
const constraints = this.activationConstraints(event, source);
|
|
1620
1707
|
event.sensor = this;
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
__privateSet(this, _clearTimeout, () => {
|
|
1631
|
-
clearTimeout(timeout);
|
|
1632
|
-
__privateSet(this, _clearTimeout, void 0);
|
|
1633
|
-
});
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
const ownerDocument = getDocument(event.target);
|
|
1637
|
-
const unbindListeners = this.listeners.bind(ownerDocument, [
|
|
1708
|
+
const controller = new ActivationController(
|
|
1709
|
+
constraints,
|
|
1710
|
+
(event2) => this.handleStart(source, event2)
|
|
1711
|
+
);
|
|
1712
|
+
controller.signal.onabort = () => this.handleCancel(event);
|
|
1713
|
+
controller.onEvent(event);
|
|
1714
|
+
this.controller = controller;
|
|
1715
|
+
const documents = getDocuments();
|
|
1716
|
+
const unbindListeners = this.listeners.bind(documents, [
|
|
1638
1717
|
{
|
|
1639
1718
|
type: "pointermove",
|
|
1640
1719
|
listener: (event2) => this.handlePointerMove(event2, source)
|
|
@@ -1656,50 +1735,27 @@ var _PointerSensor = class _PointerSensor extends Sensor {
|
|
|
1656
1735
|
}
|
|
1657
1736
|
]);
|
|
1658
1737
|
const cleanup = () => {
|
|
1659
|
-
var _a4;
|
|
1660
1738
|
unbindListeners();
|
|
1661
|
-
(_a4 = __privateGet(this, _clearTimeout)) == null ? void 0 : _a4.call(this);
|
|
1662
1739
|
this.initialCoordinates = void 0;
|
|
1663
1740
|
};
|
|
1664
1741
|
__privateGet(this, _cleanup).add(cleanup);
|
|
1665
1742
|
}
|
|
1666
1743
|
handlePointerMove(event, source) {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
coordinates.x = coordinates.x * offset.scaleX + offset.x;
|
|
1673
|
-
coordinates.y = coordinates.y * offset.scaleY + offset.y;
|
|
1744
|
+
var _a4, _b2;
|
|
1745
|
+
if (((_a4 = this.controller) == null ? void 0 : _a4.activated) === false) {
|
|
1746
|
+
(_b2 = this.controller) == null ? void 0 : _b2.onEvent(event);
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1674
1749
|
if (this.manager.dragOperation.status.dragging) {
|
|
1750
|
+
const coordinates = getEventCoordinates(event);
|
|
1751
|
+
const offset = getFrameTransform(source.element);
|
|
1752
|
+
coordinates.x = coordinates.x * offset.scaleX + offset.x;
|
|
1753
|
+
coordinates.y = coordinates.y * offset.scaleY + offset.y;
|
|
1675
1754
|
event.preventDefault();
|
|
1676
1755
|
event.stopPropagation();
|
|
1677
1756
|
this.latest.event = event;
|
|
1678
1757
|
this.latest.coordinates = coordinates;
|
|
1679
1758
|
scheduler.schedule(this.handleMove);
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
if (!this.initialCoordinates) {
|
|
1683
|
-
return;
|
|
1684
|
-
}
|
|
1685
|
-
const delta = {
|
|
1686
|
-
x: coordinates.x - this.initialCoordinates.x,
|
|
1687
|
-
y: coordinates.y - this.initialCoordinates.y
|
|
1688
|
-
};
|
|
1689
|
-
const constraints = this.activationConstraints(event, source);
|
|
1690
|
-
const { distance, delay } = constraints != null ? constraints : {};
|
|
1691
|
-
if (distance) {
|
|
1692
|
-
if (distance.tolerance != null && exceedsDistance(delta, distance.tolerance)) {
|
|
1693
|
-
return this.handleCancel(event);
|
|
1694
|
-
}
|
|
1695
|
-
if (exceedsDistance(delta, distance.value)) {
|
|
1696
|
-
return this.handleStart(source, event);
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
if (delay) {
|
|
1700
|
-
if (exceedsDistance(delta, delay.tolerance)) {
|
|
1701
|
-
return this.handleCancel(event);
|
|
1702
|
-
}
|
|
1703
1759
|
}
|
|
1704
1760
|
}
|
|
1705
1761
|
handlePointerUp(event) {
|
|
@@ -1719,9 +1775,7 @@ var _PointerSensor = class _PointerSensor extends Sensor {
|
|
|
1719
1775
|
}
|
|
1720
1776
|
}
|
|
1721
1777
|
handleStart(source, event) {
|
|
1722
|
-
var _a4;
|
|
1723
1778
|
const { manager, initialCoordinates } = this;
|
|
1724
|
-
(_a4 = __privateGet(this, _clearTimeout)) == null ? void 0 : _a4.call(this);
|
|
1725
1779
|
if (!initialCoordinates || !manager.dragOperation.status.idle) {
|
|
1726
1780
|
return;
|
|
1727
1781
|
}
|
|
@@ -1738,7 +1792,8 @@ var _PointerSensor = class _PointerSensor extends Sensor {
|
|
|
1738
1792
|
const ownerDocument = getDocument(event.target);
|
|
1739
1793
|
const pointerCaptureTarget = ownerDocument.body;
|
|
1740
1794
|
pointerCaptureTarget.setPointerCapture(event.pointerId);
|
|
1741
|
-
const
|
|
1795
|
+
const listenerTargets = isElement(event.target) ? [event.target, ownerDocument.body] : ownerDocument.body;
|
|
1796
|
+
const unbind = this.listeners.bind(listenerTargets, [
|
|
1742
1797
|
{
|
|
1743
1798
|
// Prevent scrolling on touch devices
|
|
1744
1799
|
type: "touchmove",
|
|
@@ -1759,13 +1814,6 @@ var _PointerSensor = class _PointerSensor extends Sensor {
|
|
|
1759
1814
|
{
|
|
1760
1815
|
type: "keydown",
|
|
1761
1816
|
listener: this.handleKeyDown
|
|
1762
|
-
},
|
|
1763
|
-
{
|
|
1764
|
-
type: "lostpointercapture",
|
|
1765
|
-
listener: (event2) => {
|
|
1766
|
-
if (event2.target !== pointerCaptureTarget) return;
|
|
1767
|
-
this.handlePointerUp(event2);
|
|
1768
|
-
}
|
|
1769
1817
|
}
|
|
1770
1818
|
]);
|
|
1771
1819
|
__privateGet(this, _cleanup).add(unbind);
|
|
@@ -1791,7 +1839,6 @@ var _PointerSensor = class _PointerSensor extends Sensor {
|
|
|
1791
1839
|
}
|
|
1792
1840
|
};
|
|
1793
1841
|
_cleanup = new WeakMap();
|
|
1794
|
-
_clearTimeout = new WeakMap();
|
|
1795
1842
|
_PointerSensor.configure = configurator(_PointerSensor);
|
|
1796
1843
|
_PointerSensor.defaults = defaults2;
|
|
1797
1844
|
var PointerSensor = _PointerSensor;
|
|
@@ -1972,6 +2019,6 @@ _d = __decorateElement(_init5, 20, "#element", _element_dec2, _Droppable_instanc
|
|
|
1972
2019
|
__decorateElement(_init5, 4, "proxy", _proxy_dec, Droppable, _proxy);
|
|
1973
2020
|
__decoratorMetadata(_init5, Droppable);
|
|
1974
2021
|
|
|
1975
|
-
export { Accessibility, AutoScroller, Cursor, DragDropManager, Draggable, Droppable, Feedback, KeyboardSensor, PointerSensor, PreventSelection, ScrollListener, Scroller, defaultPreset };
|
|
2022
|
+
export { Accessibility, AutoScroller, Cursor, DragDropManager, Draggable, Droppable, Feedback, KeyboardSensor, PointerActivationConstraints, PointerSensor, PreventSelection, ScrollListener, Scroller, defaultPreset };
|
|
1976
2023
|
//# sourceMappingURL=index.js.map
|
|
1977
2024
|
//# sourceMappingURL=index.js.map
|