@dnd-kit/dom 0.5.2-beta-20261029020134 → 0.5.2
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/package.json +5 -5
- package/utilities.cjs +82 -61
- package/utilities.cjs.map +1 -1
- package/utilities.d.cts +4 -0
- package/utilities.d.ts +4 -0
- package/utilities.js +82 -61
- package/utilities.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnd-kit/dom",
|
|
3
|
-
"version": "0.5.2
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@dnd-kit/abstract": "0.5.2
|
|
79
|
-
"@dnd-kit/collision": "0.5.2
|
|
80
|
-
"@dnd-kit/geometry": "0.5.2
|
|
81
|
-
"@dnd-kit/state": "0.5.2
|
|
78
|
+
"@dnd-kit/abstract": "^0.5.2",
|
|
79
|
+
"@dnd-kit/collision": "^0.5.2",
|
|
80
|
+
"@dnd-kit/geometry": "^0.5.2",
|
|
81
|
+
"@dnd-kit/state": "^0.5.2",
|
|
82
82
|
"tslib": "^2.6.2"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
package/utilities.cjs
CHANGED
|
@@ -749,6 +749,60 @@ function hidePopover(element) {
|
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
|
|
752
|
+
// src/utilities/scheduling/scheduler.ts
|
|
753
|
+
var Scheduler = class {
|
|
754
|
+
constructor(scheduler4) {
|
|
755
|
+
this.scheduler = scheduler4;
|
|
756
|
+
this.pending = false;
|
|
757
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
758
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
759
|
+
this.flush = () => {
|
|
760
|
+
const { tasks, resolvers } = this;
|
|
761
|
+
this.pending = false;
|
|
762
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
763
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
764
|
+
for (const task of tasks) {
|
|
765
|
+
task();
|
|
766
|
+
}
|
|
767
|
+
for (const resolve of resolvers) {
|
|
768
|
+
resolve();
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
schedule(task) {
|
|
773
|
+
this.tasks.add(task);
|
|
774
|
+
if (!this.pending) {
|
|
775
|
+
this.pending = true;
|
|
776
|
+
this.scheduler(this.flush);
|
|
777
|
+
}
|
|
778
|
+
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
var scheduler = new Scheduler((callback) => {
|
|
782
|
+
if (typeof requestAnimationFrame === "function") {
|
|
783
|
+
requestAnimationFrame(callback);
|
|
784
|
+
} else {
|
|
785
|
+
callback();
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
// src/utilities/styles/getComputedStyles.ts
|
|
790
|
+
var scheduler2 = new Scheduler((callback) => setTimeout(callback, 50));
|
|
791
|
+
var cachedStyles = /* @__PURE__ */ new Map();
|
|
792
|
+
var clear = cachedStyles.clear.bind(cachedStyles);
|
|
793
|
+
function getComputedStyles(element, cached = false) {
|
|
794
|
+
if (!cached) return computeStyles(element);
|
|
795
|
+
let styles = cachedStyles.get(element);
|
|
796
|
+
if (styles) return styles;
|
|
797
|
+
styles = computeStyles(element);
|
|
798
|
+
cachedStyles.set(element, styles);
|
|
799
|
+
scheduler2.schedule(clear);
|
|
800
|
+
return styles;
|
|
801
|
+
}
|
|
802
|
+
function computeStyles(element) {
|
|
803
|
+
return getWindow(element).getComputedStyle(element);
|
|
804
|
+
}
|
|
805
|
+
|
|
752
806
|
// src/utilities/scroll/documentScrollingElement.ts
|
|
753
807
|
function isDocumentScrollingElement(element) {
|
|
754
808
|
if (!canUseDOM || !element) {
|
|
@@ -761,27 +815,35 @@ function isDocumentScrollingElement(element) {
|
|
|
761
815
|
function getScrollPosition(scrollableElement) {
|
|
762
816
|
var _a, _b;
|
|
763
817
|
const window2 = getWindow(scrollableElement);
|
|
764
|
-
const
|
|
818
|
+
const isDocument2 = isDocumentScrollingElement(scrollableElement);
|
|
819
|
+
const rect = isDocument2 ? getViewportBoundingRectangle(scrollableElement) : getBoundingRectangle(scrollableElement);
|
|
765
820
|
const vv = window2.visualViewport;
|
|
766
|
-
const dimensions =
|
|
821
|
+
const dimensions = isDocument2 ? {
|
|
767
822
|
height: (_a = vv == null ? void 0 : vv.height) != null ? _a : window2.innerHeight,
|
|
768
823
|
width: (_b = vv == null ? void 0 : vv.width) != null ? _b : window2.innerWidth
|
|
769
824
|
} : {
|
|
770
825
|
height: scrollableElement.clientHeight,
|
|
771
826
|
width: scrollableElement.clientWidth
|
|
772
827
|
};
|
|
828
|
+
const rangeX = scrollableElement.scrollWidth - dimensions.width;
|
|
829
|
+
const styles = getComputedStyles(scrollableElement, true);
|
|
830
|
+
const hasNegativeScrollLeft = isDocument2 ? styles.direction === "rtl" : isHorizontalScrollReversed(styles);
|
|
773
831
|
const position = {
|
|
774
832
|
current: {
|
|
775
833
|
x: scrollableElement.scrollLeft,
|
|
776
834
|
y: scrollableElement.scrollTop
|
|
777
835
|
},
|
|
836
|
+
min: {
|
|
837
|
+
x: hasNegativeScrollLeft ? -rangeX : 0,
|
|
838
|
+
y: 0
|
|
839
|
+
},
|
|
778
840
|
max: {
|
|
779
|
-
x:
|
|
841
|
+
x: hasNegativeScrollLeft ? 0 : rangeX,
|
|
780
842
|
y: scrollableElement.scrollHeight - dimensions.height
|
|
781
843
|
}
|
|
782
844
|
};
|
|
783
|
-
const isTop = position.current.y <=
|
|
784
|
-
const isLeft = position.current.x <=
|
|
845
|
+
const isTop = position.current.y <= position.min.y;
|
|
846
|
+
const isLeft = position.current.x <= position.min.x;
|
|
785
847
|
const isBottom = position.current.y >= position.max.y;
|
|
786
848
|
const isRight = position.current.x >= position.max.x;
|
|
787
849
|
return {
|
|
@@ -793,14 +855,27 @@ function getScrollPosition(scrollableElement) {
|
|
|
793
855
|
isRight
|
|
794
856
|
};
|
|
795
857
|
}
|
|
858
|
+
function isHorizontalScrollReversed(styles) {
|
|
859
|
+
const { direction, display, writingMode } = styles;
|
|
860
|
+
const isVertical = writingMode === "vertical-lr" || writingMode === "vertical-rl" || writingMode === "sideways-lr" || writingMode === "sideways-rl";
|
|
861
|
+
const isReversed = isVertical ? writingMode === "vertical-rl" || writingMode === "sideways-rl" : direction === "rtl";
|
|
862
|
+
if (display !== "flex" && display !== "inline-flex") {
|
|
863
|
+
return isReversed;
|
|
864
|
+
}
|
|
865
|
+
const { flexDirection, flexWrap } = styles;
|
|
866
|
+
const isRow = flexDirection === "row" || flexDirection === "row-reverse";
|
|
867
|
+
const isHorizontalMainAxis = isVertical ? !isRow : isRow;
|
|
868
|
+
const isFlexReversed = isHorizontalMainAxis ? flexDirection === "row-reverse" || flexDirection === "column-reverse" : flexWrap === "wrap-reverse";
|
|
869
|
+
return isReversed !== isFlexReversed;
|
|
870
|
+
}
|
|
796
871
|
|
|
797
872
|
// src/utilities/scroll/canScroll.ts
|
|
798
873
|
function canScroll(scrollableElement, by, scrollPosition = getScrollPosition(scrollableElement)) {
|
|
799
874
|
const { isTop, isBottom, isLeft, isRight, position } = scrollPosition;
|
|
800
875
|
const { x, y } = by != null ? by : { x: 0, y: 0 };
|
|
801
|
-
const top = !isTop && position.current.y + y >
|
|
876
|
+
const top = !isTop && position.current.y + y > position.min.y;
|
|
802
877
|
const bottom = !isBottom && position.current.y + y < position.max.y;
|
|
803
|
-
const left = !isLeft && position.current.x + x >
|
|
878
|
+
const left = !isLeft && position.current.x + x > position.min.x;
|
|
804
879
|
const right = !isRight && position.current.x + x < position.max.x;
|
|
805
880
|
return {
|
|
806
881
|
top,
|
|
@@ -812,60 +887,6 @@ function canScroll(scrollableElement, by, scrollPosition = getScrollPosition(scr
|
|
|
812
887
|
};
|
|
813
888
|
}
|
|
814
889
|
|
|
815
|
-
// src/utilities/scheduling/scheduler.ts
|
|
816
|
-
var Scheduler = class {
|
|
817
|
-
constructor(scheduler4) {
|
|
818
|
-
this.scheduler = scheduler4;
|
|
819
|
-
this.pending = false;
|
|
820
|
-
this.tasks = /* @__PURE__ */ new Set();
|
|
821
|
-
this.resolvers = /* @__PURE__ */ new Set();
|
|
822
|
-
this.flush = () => {
|
|
823
|
-
const { tasks, resolvers } = this;
|
|
824
|
-
this.pending = false;
|
|
825
|
-
this.tasks = /* @__PURE__ */ new Set();
|
|
826
|
-
this.resolvers = /* @__PURE__ */ new Set();
|
|
827
|
-
for (const task of tasks) {
|
|
828
|
-
task();
|
|
829
|
-
}
|
|
830
|
-
for (const resolve of resolvers) {
|
|
831
|
-
resolve();
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
schedule(task) {
|
|
836
|
-
this.tasks.add(task);
|
|
837
|
-
if (!this.pending) {
|
|
838
|
-
this.pending = true;
|
|
839
|
-
this.scheduler(this.flush);
|
|
840
|
-
}
|
|
841
|
-
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
var scheduler = new Scheduler((callback) => {
|
|
845
|
-
if (typeof requestAnimationFrame === "function") {
|
|
846
|
-
requestAnimationFrame(callback);
|
|
847
|
-
} else {
|
|
848
|
-
callback();
|
|
849
|
-
}
|
|
850
|
-
});
|
|
851
|
-
|
|
852
|
-
// src/utilities/styles/getComputedStyles.ts
|
|
853
|
-
var scheduler2 = new Scheduler((callback) => setTimeout(callback, 50));
|
|
854
|
-
var cachedStyles = /* @__PURE__ */ new Map();
|
|
855
|
-
var clear = cachedStyles.clear.bind(cachedStyles);
|
|
856
|
-
function getComputedStyles(element, cached = false) {
|
|
857
|
-
if (!cached) return computeStyles(element);
|
|
858
|
-
let styles = cachedStyles.get(element);
|
|
859
|
-
if (styles) return styles;
|
|
860
|
-
styles = computeStyles(element);
|
|
861
|
-
cachedStyles.set(element, styles);
|
|
862
|
-
scheduler2.schedule(clear);
|
|
863
|
-
return styles;
|
|
864
|
-
}
|
|
865
|
-
function computeStyles(element) {
|
|
866
|
-
return getWindow(element).getComputedStyle(element);
|
|
867
|
-
}
|
|
868
|
-
|
|
869
890
|
// src/utilities/scroll/isFixed.ts
|
|
870
891
|
function isFixed(node, computedStyle = getComputedStyles(node, true)) {
|
|
871
892
|
return computedStyle.position === "fixed" || computedStyle.position === "sticky";
|