tree-element 0.1.1 → 0.3.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 +43 -31
- package/lib/animation.d.ts +2 -2
- package/lib/animation.d.ts.map +1 -1
- package/lib/animation.js +16 -12
- 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 +1 -0
- package/lib/dataLoader.d.ts.map +1 -1
- package/lib/dataLoader.js +22 -20
- 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 +11 -13
- 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 +125 -158
- package/lib/dragAndDropHandler/index.js.map +1 -1
- package/lib/dragAndDropHandler/iterateVisibleNodes.d.ts.map +1 -1
- package/lib/dragAndDropHandler/iterateVisibleNodes.js +23 -22
- package/lib/dragAndDropHandler/iterateVisibleNodes.js.map +1 -1
- package/lib/dragAndDropHandler/types.d.ts.map +1 -1
- package/lib/elementsRenderer.d.ts +20 -7
- package/lib/elementsRenderer.d.ts.map +1 -1
- package/lib/elementsRenderer.js +195 -136
- package/lib/elementsRenderer.js.map +1 -1
- package/lib/events.d.ts +44 -11
- package/lib/events.d.ts.map +1 -1
- package/lib/index.d.ts +36 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +386 -349
- package/lib/index.js.map +1 -1
- package/lib/keyHandler.d.ts +13 -8
- package/lib/keyHandler.d.ts.map +1 -1
- package/lib/keyHandler.js +106 -51
- package/lib/keyHandler.js.map +1 -1
- package/lib/methodTypes.d.ts +3 -3
- package/lib/methodTypes.d.ts.map +1 -1
- package/lib/mouseHandler.d.ts +1 -1
- package/lib/mouseHandler.d.ts.map +1 -1
- package/lib/mouseHandler.js +36 -49
- 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 +47 -16
- package/lib/node.d.ts.map +1 -1
- package/lib/node.js +169 -171
- 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 +8 -5
- package/lib/nodeElement/folderElement.d.ts.map +1 -1
- package/lib/nodeElement/folderElement.js +75 -67
- package/lib/nodeElement/folderElement.js.map +1 -1
- package/lib/nodeElement/ghostDropHint.d.ts.map +1 -1
- package/lib/nodeElement/ghostDropHint.js +13 -13
- 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 +38 -30
- 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 +19 -3
- 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 +6 -17
- package/lib/requestUrl.js.map +1 -1
- package/lib/saveStateHandler.d.ts.map +1 -1
- package/lib/saveStateHandler.js +59 -89
- package/lib/saveStateHandler.js.map +1 -1
- package/lib/scrollHandler/containerScrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/containerScrollParent.js +11 -18
- package/lib/scrollHandler/containerScrollParent.js.map +1 -1
- package/lib/scrollHandler/createScrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/createScrollParent.js +12 -13
- package/lib/scrollHandler/createScrollParent.js.map +1 -1
- package/lib/scrollHandler/documentScrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/documentScrollParent.js +18 -27
- package/lib/scrollHandler/documentScrollParent.js.map +1 -1
- package/lib/scrollHandler/scrollParent.d.ts.map +1 -1
- package/lib/scrollHandler/scrollParent.js +30 -34
- 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 +4 -2
- package/lib/selectNodeHandler.d.ts.map +1 -1
- package/lib/selectNodeHandler.js +64 -83
- package/lib/selectNodeHandler.js.map +1 -1
- package/lib/setDefaultOptions.d.ts.map +1 -1
- package/lib/setDefaultOptions.js +34 -38
- 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 +43 -32
- package/src/animation.ts +14 -12
- package/src/classNames.ts +52 -52
- package/src/dataLoader.ts +79 -71
- package/src/dragAndDropHandler/binarySearch.ts +17 -17
- package/src/dragAndDropHandler/dragElement.ts +51 -50
- package/src/dragAndDropHandler/generateHitAreas.ts +156 -161
- package/src/dragAndDropHandler/index.ts +334 -348
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +61 -63
- package/src/dragAndDropHandler/types.ts +5 -5
- package/src/elementsRenderer.ts +377 -294
- package/src/events.ts +241 -208
- package/src/header.txt +1 -1
- package/src/index.ts +259 -229
- package/src/keyHandler.ts +179 -115
- package/src/methodTypes.ts +7 -10
- package/src/mouseHandler.ts +316 -316
- package/src/mouseUtils.ts +14 -14
- package/src/node.ts +773 -771
- package/src/nodeElement/borderDropHint.ts +25 -25
- package/src/nodeElement/folderElement.ts +116 -102
- package/src/nodeElement/ghostDropHint.ts +64 -62
- package/src/nodeElement/index.ts +81 -73
- package/src/nodeUtils.ts +5 -5
- package/src/options.ts +25 -5
- package/src/requestUrl.ts +7 -14
- package/src/saveStateHandler.ts +191 -207
- package/src/scrollHandler/containerScrollParent.ts +40 -49
- package/src/scrollHandler/createScrollParent.ts +26 -27
- package/src/scrollHandler/documentScrollParent.ts +66 -72
- package/src/scrollHandler/scrollParent.ts +90 -86
- package/src/scrollHandler.ts +45 -45
- package/src/selectNodeHandler.ts +171 -165
- package/src/setDefaultOptions.ts +44 -32
- package/src/triggerCustomEvent.ts +7 -3
- package/src/util.ts +2 -3
- package/src/version.ts +1 -1
- package/tree_element.css +87 -69
- package/tree_element.debug.js +3866 -3831
- package/tree_element.debug.js.map +1 -1
- package/tree_element.js +2 -2
- package/tree_element.js.map +1 -1
|
@@ -4,48 +4,47 @@ 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
|
+
}
|
|
47
|
+
return new DocumentScrollParent({ refreshHitAreas, treeElement });
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
export default createScrollParent;
|
|
@@ -1,104 +1,98 @@
|
|
|
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);
|
|
27
|
-
|
|
28
|
-
super.scrollToY(top + treeTop);
|
|
29
|
-
}
|
|
22
|
+
this.treeElement = treeElement;
|
|
23
|
+
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
public scrollToY(top: number): void {
|
|
26
|
+
const treeTop = getOffsetTop(this.treeElement);
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
28
|
+
super.scrollToY(top + treeTop);
|
|
29
|
+
}
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
): HorizontalScrollDirection | undefined {
|
|
41
|
-
const scrollLeft = this.container.scrollLeft;
|
|
42
|
-
const windowWidth = window.innerWidth;
|
|
31
|
+
public stopScrolling() {
|
|
32
|
+
super.stopScrolling();
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
this.documentScrollHeight = undefined;
|
|
35
|
+
this.documentScrollWidth = undefined;
|
|
36
|
+
}
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
protected getNewHorizontalScrollDirection(
|
|
39
|
+
pageX: number,
|
|
40
|
+
): HorizontalScrollDirection | undefined {
|
|
41
|
+
const scrollLeft = this.container.scrollLeft;
|
|
42
|
+
const windowWidth = window.innerWidth;
|
|
50
43
|
|
|
51
|
-
|
|
52
|
-
return "left";
|
|
53
|
-
}
|
|
44
|
+
const isNearRightEdge = pageX > windowWidth - 20;
|
|
54
45
|
|
|
55
|
-
|
|
46
|
+
if (isNearRightEdge && this.canScrollRight()) {
|
|
47
|
+
return "right";
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const scrollTop = this.container.scrollTop;
|
|
62
|
-
const distanceTop = pageY - scrollTop;
|
|
50
|
+
const isNearLeftEdge = pageX - scrollLeft < 20;
|
|
51
|
+
return isNearLeftEdge ? "left" : undefined;
|
|
52
|
+
}
|
|
63
53
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
protected getNewVerticalScrollDirection(
|
|
55
|
+
pageY: number,
|
|
56
|
+
): undefined | VerticalScrollDirection {
|
|
57
|
+
const scrollTop = this.container.scrollTop;
|
|
58
|
+
const distanceTop = pageY - scrollTop;
|
|
67
59
|
|
|
68
|
-
|
|
60
|
+
if (distanceTop < 20) {
|
|
61
|
+
return "top";
|
|
62
|
+
}
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
return "bottom";
|
|
72
|
-
}
|
|
64
|
+
const windowHeight = window.innerHeight;
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
return windowHeight - (pageY - scrollTop) < 20 && this.canScrollDown()
|
|
67
|
+
? "bottom"
|
|
68
|
+
: undefined;
|
|
69
|
+
}
|
|
76
70
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
private canScrollDown() {
|
|
72
|
+
return (
|
|
73
|
+
this.container.scrollTop + this.container.clientHeight <
|
|
74
|
+
this.getDocumentScrollHeight()
|
|
75
|
+
);
|
|
76
|
+
}
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
private canScrollRight() {
|
|
79
|
+
return (
|
|
80
|
+
this.container.scrollLeft + this.container.clientWidth <
|
|
81
|
+
this.getDocumentScrollWidth()
|
|
82
|
+
);
|
|
83
|
+
}
|
|
90
84
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
private getDocumentScrollHeight() {
|
|
86
|
+
// Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
|
|
87
|
+
this.documentScrollHeight ??= this.container.scrollHeight;
|
|
94
88
|
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
return this.documentScrollHeight;
|
|
90
|
+
}
|
|
97
91
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
private getDocumentScrollWidth() {
|
|
93
|
+
// Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
|
|
94
|
+
this.documentScrollWidth ??= this.container.scrollWidth;
|
|
101
95
|
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
return this.documentScrollWidth;
|
|
97
|
+
}
|
|
104
98
|
}
|
|
@@ -2,116 +2,120 @@ 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
|
-
|
|
10
|
+
protected container: HTMLElement;
|
|
11
|
+
protected horizontalScrollDirection?: HorizontalScrollDirection;
|
|
12
|
+
protected horizontalScrollTimeout?: number;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
protected refreshHitAreas: () => void;
|
|
15
|
+
protected verticalScrollDirection?: VerticalScrollDirection;
|
|
16
|
+
protected verticalScrollTimeout?: number;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
constructor({ container, refreshHitAreas }: ConstructorParams) {
|
|
19
|
+
this.container = container;
|
|
20
|
+
this.refreshHitAreas = refreshHitAreas;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
public checkHorizontalScrolling(pageX: number): void {
|
|
24
|
+
const newHorizontalScrollDirection =
|
|
25
|
+
this.getNewHorizontalScrollDirection(pageX);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (this.horizontalScrollDirection === newHorizontalScrollDirection) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
window.clearTimeout(this.horizontalScrollTimeout);
|
|
32
|
-
}
|
|
31
|
+
this.horizontalScrollDirection = newHorizontalScrollDirection;
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.scrollHorizontally.bind(this),
|
|
37
|
-
40,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
33
|
+
if (this.horizontalScrollTimeout != null) {
|
|
34
|
+
window.clearTimeout(this.horizontalScrollTimeout);
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
}
|
|
37
|
+
if (newHorizontalScrollDirection) {
|
|
38
|
+
this.horizontalScrollTimeout = window.setTimeout(
|
|
39
|
+
this.scrollHorizontally.bind(this),
|
|
40
|
+
40,
|
|
41
|
+
);
|
|
62
42
|
}
|
|
43
|
+
}
|
|
63
44
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
public checkVerticalScrolling(pageY: number) {
|
|
46
|
+
const newVerticalScrollDirection =
|
|
47
|
+
this.getNewVerticalScrollDirection(pageY);
|
|
67
48
|
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
if (this.verticalScrollDirection === newVerticalScrollDirection) {
|
|
50
|
+
return;
|
|
70
51
|
}
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
53
|
+
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
54
|
+
|
|
55
|
+
if (this.verticalScrollTimeout != null) {
|
|
56
|
+
window.clearTimeout(this.verticalScrollTimeout);
|
|
57
|
+
this.verticalScrollTimeout = undefined;
|
|
75
58
|
}
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
60
|
+
if (newVerticalScrollDirection) {
|
|
61
|
+
this.verticalScrollTimeout = window.setTimeout(
|
|
62
|
+
this.scrollVertically.bind(this),
|
|
63
|
+
40,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public getScrollLeft(): number {
|
|
69
|
+
return this.container.scrollLeft;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public scrollToY(top: number): void {
|
|
73
|
+
this.container.scrollTop = top;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public stopScrolling() {
|
|
77
|
+
this.horizontalScrollDirection = undefined;
|
|
78
|
+
this.verticalScrollDirection = undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected abstract getNewHorizontalScrollDirection(
|
|
82
|
+
pageX: number,
|
|
83
|
+
): HorizontalScrollDirection | undefined;
|
|
84
|
+
protected abstract getNewVerticalScrollDirection(
|
|
85
|
+
pageY: number,
|
|
86
|
+
): undefined | VerticalScrollDirection;
|
|
87
|
+
|
|
88
|
+
protected scrollHorizontally() {
|
|
89
|
+
if (!this.horizontalScrollDirection) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
83
92
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
94
|
+
this.container.scrollBy({
|
|
95
|
+
behavior: "instant",
|
|
96
|
+
left: distance,
|
|
97
|
+
top: 0,
|
|
98
|
+
});
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
this.container.scrollBy({
|
|
91
|
-
behavior: "instant",
|
|
92
|
-
left: distance,
|
|
93
|
-
top: 0,
|
|
94
|
-
});
|
|
100
|
+
this.refreshHitAreas();
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
103
|
+
}
|
|
97
104
|
|
|
98
|
-
|
|
105
|
+
protected scrollVertically() {
|
|
106
|
+
if (!this.verticalScrollDirection) {
|
|
107
|
+
return;
|
|
99
108
|
}
|
|
100
109
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
const distance = this.verticalScrollDirection === "top" ? -20 : 20;
|
|
111
|
+
this.container.scrollBy({
|
|
112
|
+
behavior: "instant",
|
|
113
|
+
left: 0,
|
|
114
|
+
top: distance,
|
|
115
|
+
});
|
|
105
116
|
|
|
106
|
-
|
|
107
|
-
this.container.scrollBy({
|
|
108
|
-
behavior: "instant",
|
|
109
|
-
left: 0,
|
|
110
|
-
top: distance,
|
|
111
|
-
});
|
|
117
|
+
this.refreshHitAreas();
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
setTimeout(this.scrollVertically.bind(this), 40);
|
|
116
|
-
}
|
|
119
|
+
setTimeout(this.scrollVertically.bind(this), 40);
|
|
120
|
+
}
|
|
117
121
|
}
|
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
|
}
|