tree-element 0.1.0 → 0.2.0
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/README.md +49 -29
- package/lib/animation.js +5 -5
- package/lib/animation.js.map +1 -1
- package/lib/classNames.d.ts.map +1 -1
- package/lib/classNames.js +2 -2
- package/lib/classNames.js.map +1 -1
- package/lib/dataLoader.d.ts.map +1 -1
- package/lib/dataLoader.js +18 -21
- package/lib/dataLoader.js.map +1 -1
- package/lib/dragAndDropHandler/binarySearch.js +3 -3
- package/lib/dragAndDropHandler/binarySearch.js.map +1 -1
- package/lib/dragAndDropHandler/dragElement.d.ts.map +1 -1
- package/lib/dragAndDropHandler/dragElement.js +9 -12
- package/lib/dragAndDropHandler/dragElement.js.map +1 -1
- package/lib/dragAndDropHandler/generateHitAreas.d.ts.map +1 -1
- package/lib/dragAndDropHandler/generateHitAreas.js +25 -25
- package/lib/dragAndDropHandler/generateHitAreas.js.map +1 -1
- package/lib/dragAndDropHandler/index.d.ts.map +1 -1
- package/lib/dragAndDropHandler/index.js +90 -114
- package/lib/dragAndDropHandler/index.js.map +1 -1
- package/lib/dragAndDropHandler/iterateVisibleNodes.d.ts.map +1 -1
- package/lib/dragAndDropHandler/iterateVisibleNodes.js +10 -10
- package/lib/dragAndDropHandler/iterateVisibleNodes.js.map +1 -1
- package/lib/dragAndDropHandler/types.d.ts.map +1 -1
- package/lib/elementsRenderer.d.ts +15 -6
- package/lib/elementsRenderer.d.ts.map +1 -1
- package/lib/elementsRenderer.js +157 -121
- package/lib/elementsRenderer.js.map +1 -1
- package/lib/events.d.ts +11 -4
- package/lib/events.d.ts.map +1 -1
- package/lib/index.d.ts +5 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +249 -252
- package/lib/index.js.map +1 -1
- package/lib/keyHandler.d.ts +2 -3
- package/lib/keyHandler.d.ts.map +1 -1
- package/lib/keyHandler.js +26 -25
- package/lib/keyHandler.js.map +1 -1
- package/lib/methodTypes.d.ts +1 -1
- package/lib/methodTypes.d.ts.map +1 -1
- package/lib/mouseHandler.d.ts.map +1 -1
- package/lib/mouseHandler.js +26 -42
- package/lib/mouseHandler.js.map +1 -1
- package/lib/mouseUtils.d.ts.map +1 -1
- package/lib/mouseUtils.js +2 -2
- package/lib/mouseUtils.js.map +1 -1
- package/lib/node.d.ts +2 -1
- package/lib/node.d.ts.map +1 -1
- package/lib/node.js +36 -35
- package/lib/node.js.map +1 -1
- package/lib/nodeElement/borderDropHint.d.ts.map +1 -1
- package/lib/nodeElement/borderDropHint.js +4 -5
- package/lib/nodeElement/borderDropHint.js.map +1 -1
- package/lib/nodeElement/folderElement.d.ts +7 -4
- package/lib/nodeElement/folderElement.d.ts.map +1 -1
- package/lib/nodeElement/folderElement.js +61 -42
- package/lib/nodeElement/folderElement.js.map +1 -1
- package/lib/nodeElement/ghostDropHint.d.ts.map +1 -1
- package/lib/nodeElement/ghostDropHint.js +5 -9
- package/lib/nodeElement/ghostDropHint.js.map +1 -1
- package/lib/nodeElement/index.d.ts +2 -1
- package/lib/nodeElement/index.d.ts.map +1 -1
- package/lib/nodeElement/index.js +34 -26
- package/lib/nodeElement/index.js.map +1 -1
- package/lib/nodeUtils.d.ts.map +1 -1
- package/lib/nodeUtils.js +1 -1
- package/lib/nodeUtils.js.map +1 -1
- package/lib/options.d.ts.map +1 -1
- package/lib/positionUtils.js +3 -3
- package/lib/positionUtils.js.map +1 -1
- package/lib/requestUrl.d.ts +1 -1
- package/lib/requestUrl.d.ts.map +1 -1
- package/lib/requestUrl.js +4 -6
- package/lib/requestUrl.js.map +1 -1
- package/lib/saveStateHandler.d.ts.map +1 -1
- package/lib/saveStateHandler.js +38 -48
- package/lib/saveStateHandler.js.map +1 -1
- package/lib/scrollHandler/containerScrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/containerScrollParent.js +9 -11
- package/lib/scrollHandler/containerScrollParent.js.map +1 -1
- package/lib/scrollHandler/createScrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/createScrollParent.js +10 -10
- package/lib/scrollHandler/createScrollParent.js.map +1 -1
- package/lib/scrollHandler/documentScrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/documentScrollParent.js +16 -19
- package/lib/scrollHandler/documentScrollParent.js.map +1 -1
- package/lib/scrollHandler/scrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/scrollParent.js +11 -17
- package/lib/scrollHandler/scrollParent.js.map +1 -1
- package/lib/scrollHandler.d.ts.map +1 -1
- package/lib/scrollHandler.js +11 -14
- package/lib/scrollHandler.js.map +1 -1
- package/lib/selectNodeHandler.d.ts +2 -2
- package/lib/selectNodeHandler.d.ts.map +1 -1
- package/lib/selectNodeHandler.js +45 -54
- package/lib/selectNodeHandler.js.map +1 -1
- package/lib/setDefaultOptions.d.ts.map +1 -1
- package/lib/setDefaultOptions.js +23 -28
- package/lib/setDefaultOptions.js.map +1 -1
- package/lib/triggerCustomEvent.d.ts.map +1 -1
- package/lib/triggerCustomEvent.js +2 -2
- package/lib/triggerCustomEvent.js.map +1 -1
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +2 -2
- package/lib/util.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +7 -3
- package/src/animation.ts +1 -1
- package/src/classNames.ts +52 -52
- package/src/dataLoader.ts +68 -70
- package/src/dragAndDropHandler/binarySearch.ts +17 -17
- package/src/dragAndDropHandler/dragElement.ts +50 -50
- package/src/dragAndDropHandler/generateHitAreas.ts +156 -161
- package/src/dragAndDropHandler/index.ts +342 -351
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +59 -63
- package/src/dragAndDropHandler/types.ts +5 -5
- package/src/elementsRenderer.ts +351 -298
- package/src/events.ts +216 -209
- package/src/header.txt +1 -1
- package/src/index.ts +52 -82
- package/src/keyHandler.ts +125 -115
- package/src/methodTypes.ts +4 -7
- package/src/mouseHandler.ts +314 -317
- package/src/mouseUtils.ts +14 -14
- package/src/node.ts +761 -766
- package/src/nodeElement/borderDropHint.ts +25 -25
- package/src/nodeElement/folderElement.ts +135 -112
- package/src/nodeElement/ghostDropHint.ts +62 -62
- package/src/nodeElement/index.ts +88 -74
- package/src/nodeUtils.ts +5 -5
- package/src/options.ts +6 -2
- package/src/requestUrl.ts +3 -3
- package/src/saveStateHandler.ts +204 -206
- package/src/scrollHandler/containerScrollParent.ts +49 -52
- package/src/scrollHandler/createScrollParent.ts +27 -27
- package/src/scrollHandler/documentScrollParent.ts +70 -70
- package/src/scrollHandler/scrollParent.ts +98 -98
- package/src/scrollHandler.ts +45 -45
- package/src/selectNodeHandler.ts +176 -166
- package/src/setDefaultOptions.ts +25 -22
- package/src/triggerCustomEvent.ts +7 -3
- package/src/util.ts +2 -2
- package/src/version.ts +1 -1
- package/tree_element.debug.js +3770 -3799
- package/tree_element.debug.js.map +1 -1
- package/tree_element.js +2 -2
- package/tree_element.js.map +1 -1
|
@@ -4,48 +4,48 @@ import ContainerScrollParent from "./containerScrollParent";
|
|
|
4
4
|
import DocumentScrollParent from "./documentScrollParent";
|
|
5
5
|
|
|
6
6
|
const isOverflow = (overflowValue: string) =>
|
|
7
|
-
|
|
7
|
+
overflowValue === "auto" || overflowValue === "scroll";
|
|
8
8
|
|
|
9
9
|
const hasOverFlow = (element: HTMLElement): boolean => {
|
|
10
|
-
|
|
10
|
+
const style = getComputedStyle(element);
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
return isOverflow(style.overflowX) || isOverflow(style.overflowY);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const getParentWithOverflow = (
|
|
16
|
-
|
|
16
|
+
treeElement: HTMLElement,
|
|
17
17
|
): HTMLElement | null => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let parent = treeElement.parentElement;
|
|
18
|
+
if (hasOverFlow(treeElement)) {
|
|
19
|
+
return treeElement;
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
if (hasOverFlow(parent)) {
|
|
26
|
-
return parent;
|
|
27
|
-
}
|
|
22
|
+
let parent = treeElement.parentElement;
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
while (parent) {
|
|
25
|
+
if (hasOverFlow(parent)) {
|
|
26
|
+
return parent;
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
parent = parent.parentElement;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const createScrollParent = (
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
treeElement: HTMLElement,
|
|
37
|
+
refreshHitAreas: () => void,
|
|
38
38
|
): ScrollParent => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
const container = getParentWithOverflow(treeElement);
|
|
40
|
+
|
|
41
|
+
if (container && container.tagName !== "HTML") {
|
|
42
|
+
return new ContainerScrollParent({
|
|
43
|
+
container,
|
|
44
|
+
refreshHitAreas,
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
return new DocumentScrollParent({ refreshHitAreas, treeElement });
|
|
48
|
+
}
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export default createScrollParent;
|
|
@@ -1,104 +1,104 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
HorizontalScrollDirection,
|
|
3
|
+
VerticalScrollDirection,
|
|
4
4
|
} from "./scrollParent";
|
|
5
5
|
|
|
6
6
|
import { getOffsetTop } from "../positionUtils";
|
|
7
7
|
import { ScrollParent } from "./scrollParent";
|
|
8
8
|
|
|
9
9
|
interface Params {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
refreshHitAreas: () => void;
|
|
11
|
+
treeElement: HTMLElement;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export default class DocumentScrollParent extends ScrollParent {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
private documentScrollHeight?: number;
|
|
16
|
+
private documentScrollWidth?: number;
|
|
17
|
+
private treeElement: HTMLElement;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
constructor({ refreshHitAreas, treeElement }: Params) {
|
|
20
|
+
super({ container: document.documentElement, refreshHitAreas });
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
public scrollToY(top: number): void {
|
|
26
|
-
const treeTop = getOffsetTop(this.treeElement);
|
|
22
|
+
this.treeElement = treeElement;
|
|
23
|
+
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
public scrollToY(top: number): void {
|
|
26
|
+
const treeTop = getOffsetTop(this.treeElement);
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
super.scrollToY(top + treeTop);
|
|
29
|
+
}
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
31
|
+
public stopScrolling() {
|
|
32
|
+
super.stopScrolling();
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const scrollLeft = this.container.scrollLeft;
|
|
42
|
-
const windowWidth = window.innerWidth;
|
|
34
|
+
this.documentScrollHeight = undefined;
|
|
35
|
+
this.documentScrollWidth = undefined;
|
|
36
|
+
}
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
protected getNewHorizontalScrollDirection(
|
|
39
|
+
pageX: number,
|
|
40
|
+
): HorizontalScrollDirection | undefined {
|
|
41
|
+
const scrollLeft = this.container.scrollLeft;
|
|
42
|
+
const windowWidth = window.innerWidth;
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
44
|
+
const isNearRightEdge = pageX > windowWidth - 20;
|
|
45
|
+
const isNearLeftEdge = pageX - scrollLeft < 20;
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
if (isNearRightEdge && this.canScrollRight()) {
|
|
48
|
+
return "right";
|
|
49
|
+
}
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
if (isNearLeftEdge) {
|
|
52
|
+
return "left";
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
): undefined | VerticalScrollDirection {
|
|
61
|
-
const scrollTop = this.container.scrollTop;
|
|
62
|
-
const distanceTop = pageY - scrollTop;
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
protected getNewVerticalScrollDirection(
|
|
59
|
+
pageY: number,
|
|
60
|
+
): undefined | VerticalScrollDirection {
|
|
61
|
+
const scrollTop = this.container.scrollTop;
|
|
62
|
+
const distanceTop = pageY - scrollTop;
|
|
67
63
|
|
|
68
|
-
|
|
64
|
+
if (distanceTop < 20) {
|
|
65
|
+
return "top";
|
|
66
|
+
}
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
return "bottom";
|
|
72
|
-
}
|
|
68
|
+
const windowHeight = window.innerHeight;
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
if (windowHeight - (pageY - scrollTop) < 20 && this.canScrollDown()) {
|
|
71
|
+
return "bottom";
|
|
75
72
|
}
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.container.scrollTop + this.container.clientHeight <
|
|
80
|
-
this.getDocumentScrollHeight()
|
|
81
|
-
);
|
|
82
|
-
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
83
76
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
private canScrollDown() {
|
|
78
|
+
return (
|
|
79
|
+
this.container.scrollTop + this.container.clientHeight <
|
|
80
|
+
this.getDocumentScrollHeight()
|
|
81
|
+
);
|
|
82
|
+
}
|
|
90
83
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
private canScrollRight() {
|
|
85
|
+
return (
|
|
86
|
+
this.container.scrollLeft + this.container.clientWidth <
|
|
87
|
+
this.getDocumentScrollWidth()
|
|
88
|
+
);
|
|
89
|
+
}
|
|
94
90
|
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
private getDocumentScrollHeight() {
|
|
92
|
+
// Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
|
|
93
|
+
this.documentScrollHeight ??= this.container.scrollHeight;
|
|
97
94
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.documentScrollWidth ??= this.container.scrollWidth;
|
|
95
|
+
return this.documentScrollHeight;
|
|
96
|
+
}
|
|
101
97
|
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
private getDocumentScrollWidth() {
|
|
99
|
+
// Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
|
|
100
|
+
this.documentScrollWidth ??= this.container.scrollWidth;
|
|
101
|
+
|
|
102
|
+
return this.documentScrollWidth;
|
|
103
|
+
}
|
|
104
104
|
}
|
|
@@ -2,116 +2,116 @@ export type HorizontalScrollDirection = "left" | "right";
|
|
|
2
2
|
export type VerticalScrollDirection = "bottom" | "top";
|
|
3
3
|
|
|
4
4
|
interface ConstructorParams {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
refreshHitAreas: () => void;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export abstract class ScrollParent {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public checkVerticalScrolling(pageY: number) {
|
|
44
|
-
const newVerticalScrollDirection =
|
|
45
|
-
this.getNewVerticalScrollDirection(pageY);
|
|
46
|
-
|
|
47
|
-
if (this.verticalScrollDirection !== newVerticalScrollDirection) {
|
|
48
|
-
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
49
|
-
|
|
50
|
-
if (this.verticalScrollTimeout != null) {
|
|
51
|
-
window.clearTimeout(this.verticalScrollTimeout);
|
|
52
|
-
this.verticalScrollTimeout = undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (newVerticalScrollDirection) {
|
|
56
|
-
this.verticalScrollTimeout = window.setTimeout(
|
|
57
|
-
this.scrollVertically.bind(this),
|
|
58
|
-
40,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public getScrollLeft(): number {
|
|
65
|
-
return this.container.scrollLeft;
|
|
10
|
+
protected container: HTMLElement;
|
|
11
|
+
protected horizontalScrollDirection?: HorizontalScrollDirection;
|
|
12
|
+
protected horizontalScrollTimeout?: number;
|
|
13
|
+
|
|
14
|
+
protected refreshHitAreas: () => void;
|
|
15
|
+
protected verticalScrollDirection?: VerticalScrollDirection;
|
|
16
|
+
protected verticalScrollTimeout?: number;
|
|
17
|
+
|
|
18
|
+
constructor({ container, refreshHitAreas }: ConstructorParams) {
|
|
19
|
+
this.container = container;
|
|
20
|
+
this.refreshHitAreas = refreshHitAreas;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public checkHorizontalScrolling(pageX: number): void {
|
|
24
|
+
const newHorizontalScrollDirection =
|
|
25
|
+
this.getNewHorizontalScrollDirection(pageX);
|
|
26
|
+
|
|
27
|
+
if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
|
|
28
|
+
this.horizontalScrollDirection = newHorizontalScrollDirection;
|
|
29
|
+
|
|
30
|
+
if (this.horizontalScrollTimeout != null) {
|
|
31
|
+
window.clearTimeout(this.horizontalScrollTimeout);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (newHorizontalScrollDirection) {
|
|
35
|
+
this.horizontalScrollTimeout = window.setTimeout(
|
|
36
|
+
this.scrollHorizontally.bind(this),
|
|
37
|
+
40,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
66
40
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public checkVerticalScrolling(pageY: number) {
|
|
44
|
+
const newVerticalScrollDirection =
|
|
45
|
+
this.getNewVerticalScrollDirection(pageY);
|
|
46
|
+
|
|
47
|
+
if (this.verticalScrollDirection !== newVerticalScrollDirection) {
|
|
48
|
+
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
49
|
+
|
|
50
|
+
if (this.verticalScrollTimeout != null) {
|
|
51
|
+
window.clearTimeout(this.verticalScrollTimeout);
|
|
52
|
+
this.verticalScrollTimeout = undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (newVerticalScrollDirection) {
|
|
56
|
+
this.verticalScrollTimeout = window.setTimeout(
|
|
57
|
+
this.scrollVertically.bind(this),
|
|
58
|
+
40,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
70
61
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public getScrollLeft(): number {
|
|
65
|
+
return this.container.scrollLeft;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public scrollToY(top: number): void {
|
|
69
|
+
this.container.scrollTop = top;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public stopScrolling() {
|
|
73
|
+
this.horizontalScrollDirection = undefined;
|
|
74
|
+
this.verticalScrollDirection = undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected abstract getNewHorizontalScrollDirection(
|
|
78
|
+
pageX: number,
|
|
79
|
+
): HorizontalScrollDirection | undefined;
|
|
80
|
+
protected abstract getNewVerticalScrollDirection(
|
|
81
|
+
pageY: number,
|
|
82
|
+
): undefined | VerticalScrollDirection;
|
|
83
|
+
|
|
84
|
+
protected scrollHorizontally() {
|
|
85
|
+
if (!this.horizontalScrollDirection) {
|
|
86
|
+
return;
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
protected scrollHorizontally() {
|
|
85
|
-
if (!this.horizontalScrollDirection) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
89
|
+
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
90
|
+
this.container.scrollBy({
|
|
91
|
+
behavior: "instant",
|
|
92
|
+
left: distance,
|
|
93
|
+
top: 0,
|
|
94
|
+
});
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
this.container.scrollBy({
|
|
91
|
-
behavior: "instant",
|
|
92
|
-
left: distance,
|
|
93
|
-
top: 0,
|
|
94
|
-
});
|
|
96
|
+
this.refreshHitAreas();
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
99
|
+
}
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
protected scrollVertically() {
|
|
102
|
+
if (!this.verticalScrollDirection) {
|
|
103
|
+
return;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
const distance = this.verticalScrollDirection === "top" ? -20 : 20;
|
|
107
|
+
this.container.scrollBy({
|
|
108
|
+
behavior: "instant",
|
|
109
|
+
left: 0,
|
|
110
|
+
top: distance,
|
|
111
|
+
});
|
|
105
112
|
|
|
106
|
-
|
|
107
|
-
this.container.scrollBy({
|
|
108
|
-
behavior: "instant",
|
|
109
|
-
left: 0,
|
|
110
|
-
top: distance,
|
|
111
|
-
});
|
|
113
|
+
this.refreshHitAreas();
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
setTimeout(this.scrollVertically.bind(this), 40);
|
|
116
|
-
}
|
|
115
|
+
setTimeout(this.scrollVertically.bind(this), 40);
|
|
116
|
+
}
|
|
117
117
|
}
|
package/src/scrollHandler.ts
CHANGED
|
@@ -4,52 +4,52 @@ import type { ScrollParent } from "./scrollHandler/scrollParent";
|
|
|
4
4
|
import createScrollParent from "./scrollHandler/createScrollParent";
|
|
5
5
|
|
|
6
6
|
interface ScrollHandlerParams {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
refreshHitAreas: () => void;
|
|
8
|
+
treeElement: HTMLElement;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export default class ScrollHandler {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
12
|
+
private refreshHitAreas: () => void;
|
|
13
|
+
private scrollParent?: ScrollParent;
|
|
14
|
+
private treeElement: HTMLElement;
|
|
15
|
+
|
|
16
|
+
constructor({ refreshHitAreas, treeElement }: ScrollHandlerParams) {
|
|
17
|
+
this.refreshHitAreas = refreshHitAreas;
|
|
18
|
+
this.scrollParent = undefined;
|
|
19
|
+
this.treeElement = treeElement;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public checkScrolling(positionInfo: PositionInfo): void {
|
|
23
|
+
this.checkVerticalScrolling(positionInfo);
|
|
24
|
+
this.checkHorizontalScrolling(positionInfo);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public getScrollLeft(): number {
|
|
28
|
+
return this.getScrollParent().getScrollLeft();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public scrollToY(top: number): void {
|
|
32
|
+
this.getScrollParent().scrollToY(top);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public stopScrolling() {
|
|
36
|
+
this.getScrollParent().stopScrolling();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private checkHorizontalScrolling(positionInfo: PositionInfo): void {
|
|
40
|
+
this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private checkVerticalScrolling(positionInfo: PositionInfo): void {
|
|
44
|
+
this.getScrollParent().checkVerticalScrolling(positionInfo.pageY);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private getScrollParent(): ScrollParent {
|
|
48
|
+
this.scrollParent ??= createScrollParent(
|
|
49
|
+
this.treeElement,
|
|
50
|
+
this.refreshHitAreas,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return this.scrollParent;
|
|
54
|
+
}
|
|
55
55
|
}
|