jqtree 1.8.10 → 1.9.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/bower.json +3 -10
- package/eslint.config.mjs +47 -9
- package/package.json +50 -53
- package/pnpm-workspace.yaml +4 -0
- package/src/animation.ts +48 -0
- package/src/dataLoader.ts +38 -48
- package/src/dragAndDropHandler/dragElement.ts +11 -11
- package/src/dragAndDropHandler/generateHitAreas.ts +4 -3
- package/src/dragAndDropHandler/index.ts +119 -120
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +1 -1
- package/src/dragAndDropHandler/types.ts +1 -1
- package/src/elementsRenderer.ts +71 -78
- package/src/jqtreeMethodTypes.ts +2 -2
- package/src/jqtreeOptions.ts +3 -2
- package/src/keyHandler.ts +34 -34
- package/src/mouseHandler.ts +125 -123
- package/src/node.ts +23 -27
- package/src/nodeElement/borderDropHint.ts +6 -6
- package/src/nodeElement/folderElement.ts +30 -22
- package/src/nodeElement/ghostDropHint.ts +24 -24
- package/src/nodeElement/index.ts +13 -14
- package/src/positionUtils.ts +18 -0
- package/src/saveStateHandler.ts +56 -55
- package/src/scrollHandler/containerScrollParent.ts +27 -124
- package/src/scrollHandler/createScrollParent.ts +1 -1
- package/src/scrollHandler/documentScrollParent.ts +43 -125
- package/src/scrollHandler/scrollParent.ts +117 -0
- package/src/scrollHandler.ts +24 -25
- package/src/selectNodeHandler.ts +28 -28
- package/src/simple.widget.ts +1 -3
- package/src/tree.jquery.ts +253 -279
- package/src/util.ts +0 -14
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +1044 -998
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +3 -3
- package/tree.jquery.js.map +1 -1
- package/.tool-versions +0 -2
- package/src/scrollHandler/types.ts +0 -7
|
@@ -1,92 +1,30 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
HorizontalScrollDirection,
|
|
3
|
+
VerticalScrollDirection,
|
|
4
|
+
} from "./scrollParent";
|
|
2
5
|
|
|
3
|
-
import { getElementPosition, getOffsetTop } from
|
|
6
|
+
import { getElementPosition, getOffsetTop } from "../positionUtils";
|
|
7
|
+
import { ScrollParent } from "./scrollParent";
|
|
4
8
|
|
|
5
|
-
type HorizontalScrollDirection = "left" | "right";
|
|
6
|
-
interface Params {
|
|
7
|
-
container: HTMLElement;
|
|
8
|
-
refreshHitAreas: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type VerticalScrollDirection = "bottom" | "top";
|
|
12
|
-
|
|
13
|
-
export default class ContainerScrollParent implements ScrollParent {
|
|
14
|
-
private container: HTMLElement;
|
|
15
|
-
private horizontalScrollDirection?: HorizontalScrollDirection;
|
|
16
|
-
private horizontalScrollTimeout?: number;
|
|
17
|
-
private refreshHitAreas: () => void;
|
|
18
|
-
private scrollParentBottom?: number;
|
|
19
|
-
private scrollParentTop?: number;
|
|
20
|
-
private verticalScrollDirection?: VerticalScrollDirection;
|
|
21
|
-
private verticalScrollTimeout?: number;
|
|
22
|
-
|
|
23
|
-
constructor({ container, refreshHitAreas }: Params) {
|
|
24
|
-
this.container = container;
|
|
25
|
-
this.refreshHitAreas = refreshHitAreas;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public checkHorizontalScrolling(pageX: number): void {
|
|
29
|
-
const newHorizontalScrollDirection =
|
|
30
|
-
this.getNewHorizontalScrollDirection(pageX);
|
|
31
|
-
|
|
32
|
-
if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
|
|
33
|
-
this.horizontalScrollDirection = newHorizontalScrollDirection;
|
|
34
|
-
|
|
35
|
-
if (this.horizontalScrollTimeout != null) {
|
|
36
|
-
window.clearTimeout(this.verticalScrollTimeout);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (newHorizontalScrollDirection) {
|
|
40
|
-
this.horizontalScrollTimeout = window.setTimeout(
|
|
41
|
-
this.scrollHorizontally.bind(this),
|
|
42
|
-
40,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public checkVerticalScrolling(pageY: number) {
|
|
49
|
-
const newVerticalScrollDirection =
|
|
50
|
-
this.getNewVerticalScrollDirection(pageY);
|
|
51
|
-
|
|
52
|
-
if (this.verticalScrollDirection !== newVerticalScrollDirection) {
|
|
53
|
-
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
54
|
-
|
|
55
|
-
if (this.verticalScrollTimeout != null) {
|
|
56
|
-
window.clearTimeout(this.verticalScrollTimeout);
|
|
57
|
-
this.verticalScrollTimeout = undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (newVerticalScrollDirection) {
|
|
61
|
-
this.verticalScrollTimeout = window.setTimeout(
|
|
62
|
-
this.scrollVertically.bind(this),
|
|
63
|
-
40,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public getScrollLeft(): number {
|
|
70
|
-
return this.container.scrollLeft;
|
|
71
|
-
}
|
|
72
9
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
10
|
+
export default class ContainerScrollParent extends ScrollParent {
|
|
11
|
+
private _scrollParentBottom?: number;
|
|
12
|
+
private _scrollParentTop?: number;
|
|
76
13
|
|
|
77
14
|
public stopScrolling() {
|
|
15
|
+
super.stopScrolling();
|
|
16
|
+
|
|
78
17
|
this.horizontalScrollDirection = undefined;
|
|
79
18
|
this.verticalScrollDirection = undefined;
|
|
80
|
-
this.scrollParentTop = undefined;
|
|
81
|
-
this.scrollParentBottom = undefined;
|
|
82
19
|
}
|
|
83
20
|
|
|
84
|
-
|
|
21
|
+
protected getNewHorizontalScrollDirection(
|
|
85
22
|
pageX: number,
|
|
86
23
|
): HorizontalScrollDirection | undefined {
|
|
87
24
|
const scrollParentOffset = getElementPosition(this.container);
|
|
25
|
+
const containerWidth = this.container.getBoundingClientRect().width;
|
|
88
26
|
|
|
89
|
-
const rightEdge = scrollParentOffset.left +
|
|
27
|
+
const rightEdge = scrollParentOffset.left + containerWidth;
|
|
90
28
|
const leftEdge = scrollParentOffset.left;
|
|
91
29
|
const isNearRightEdge = pageX > rightEdge - 20;
|
|
92
30
|
const isNearLeftEdge = pageX < leftEdge + 20;
|
|
@@ -100,69 +38,34 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
100
38
|
return undefined;
|
|
101
39
|
}
|
|
102
40
|
|
|
103
|
-
|
|
41
|
+
protected getNewVerticalScrollDirection(
|
|
104
42
|
pageY: number,
|
|
105
43
|
): undefined | VerticalScrollDirection {
|
|
106
|
-
if (pageY < this.
|
|
44
|
+
if (pageY < this._getScrollParentTop()) {
|
|
107
45
|
return "top";
|
|
108
46
|
}
|
|
109
47
|
|
|
110
|
-
if (pageY > this.
|
|
48
|
+
if (pageY > this._getScrollParentBottom()) {
|
|
111
49
|
return "bottom";
|
|
112
50
|
}
|
|
113
51
|
|
|
114
52
|
return undefined;
|
|
115
53
|
}
|
|
116
54
|
|
|
117
|
-
private
|
|
118
|
-
if (this.
|
|
119
|
-
|
|
55
|
+
private _getScrollParentBottom() {
|
|
56
|
+
if (this._scrollParentBottom == null) {
|
|
57
|
+
const containerHeight =
|
|
58
|
+
this.container.getBoundingClientRect().height;
|
|
59
|
+
this._scrollParentBottom =
|
|
60
|
+
this._getScrollParentTop() + containerHeight;
|
|
120
61
|
}
|
|
121
62
|
|
|
122
|
-
return this.
|
|
63
|
+
return this._scrollParentBottom;
|
|
123
64
|
}
|
|
124
65
|
|
|
125
|
-
private
|
|
126
|
-
|
|
127
|
-
this.scrollParentTop = getOffsetTop(this.container)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return this.scrollParentTop;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private scrollHorizontally() {
|
|
134
|
-
if (!this.horizontalScrollDirection) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
139
|
-
|
|
140
|
-
this.container.scrollBy({
|
|
141
|
-
behavior: "instant",
|
|
142
|
-
left: distance,
|
|
143
|
-
top: 0,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
this.refreshHitAreas();
|
|
147
|
-
|
|
148
|
-
setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private scrollVertically() {
|
|
152
|
-
if (!this.verticalScrollDirection) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const distance = this.verticalScrollDirection === "top" ? -20 : 20;
|
|
157
|
-
|
|
158
|
-
this.container.scrollBy({
|
|
159
|
-
behavior: "instant",
|
|
160
|
-
left: 0,
|
|
161
|
-
top: distance,
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
this.refreshHitAreas();
|
|
66
|
+
private _getScrollParentTop() {
|
|
67
|
+
this._scrollParentTop ??= getOffsetTop(this.container);
|
|
165
68
|
|
|
166
|
-
|
|
69
|
+
return this._scrollParentTop;
|
|
167
70
|
}
|
|
168
71
|
}
|
|
@@ -1,134 +1,50 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
HorizontalScrollDirection,
|
|
3
|
+
VerticalScrollDirection,
|
|
4
|
+
} from "./scrollParent";
|
|
2
5
|
|
|
3
|
-
import { getOffsetTop } from "../
|
|
6
|
+
import { getOffsetTop } from "../positionUtils";
|
|
7
|
+
import { ScrollParent } from "./scrollParent";
|
|
4
8
|
|
|
5
|
-
type HorizontalScrollDirection = "left" | "right";
|
|
6
9
|
interface Params {
|
|
7
10
|
refreshHitAreas: () => void;
|
|
8
11
|
treeElement: HTMLElement;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
private documentScrollWidth?: number;
|
|
16
|
-
private horizontalScrollDirection?: HorizontalScrollDirection;
|
|
17
|
-
private horizontalScrollTimeout?: number;
|
|
18
|
-
private refreshHitAreas: () => void;
|
|
19
|
-
private treeElement: HTMLElement;
|
|
20
|
-
private verticalScrollDirection?: VerticalScrollDirection;
|
|
21
|
-
private verticalScrollTimeout?: number;
|
|
14
|
+
export default class DocumentScrollParent extends ScrollParent {
|
|
15
|
+
private _documentScrollHeight?: number;
|
|
16
|
+
private _documentScrollWidth?: number;
|
|
17
|
+
private _treeElement: HTMLElement;
|
|
22
18
|
|
|
23
19
|
constructor({ refreshHitAreas, treeElement }: Params) {
|
|
24
|
-
|
|
25
|
-
this.treeElement = treeElement;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public checkHorizontalScrolling(pageX: number): void {
|
|
29
|
-
const newHorizontalScrollDirection =
|
|
30
|
-
this.getNewHorizontalScrollDirection(pageX);
|
|
31
|
-
|
|
32
|
-
if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
|
|
33
|
-
this.horizontalScrollDirection = newHorizontalScrollDirection;
|
|
34
|
-
|
|
35
|
-
if (this.horizontalScrollTimeout != null) {
|
|
36
|
-
window.clearTimeout(this.horizontalScrollTimeout);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (newHorizontalScrollDirection) {
|
|
40
|
-
this.horizontalScrollTimeout = window.setTimeout(
|
|
41
|
-
this.scrollHorizontally.bind(this),
|
|
42
|
-
40,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public checkVerticalScrolling(pageY: number) {
|
|
49
|
-
const newVerticalScrollDirection =
|
|
50
|
-
this.getNewVerticalScrollDirection(pageY);
|
|
20
|
+
super({ container: document.documentElement, refreshHitAreas });
|
|
51
21
|
|
|
52
|
-
|
|
53
|
-
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
54
|
-
|
|
55
|
-
if (this.verticalScrollTimeout != null) {
|
|
56
|
-
window.clearTimeout(this.verticalScrollTimeout);
|
|
57
|
-
this.verticalScrollTimeout = undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (newVerticalScrollDirection) {
|
|
61
|
-
this.verticalScrollTimeout = window.setTimeout(
|
|
62
|
-
this.scrollVertically.bind(this),
|
|
63
|
-
40,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public getScrollLeft(): number {
|
|
70
|
-
return document.documentElement.scrollLeft;
|
|
22
|
+
this._treeElement = treeElement;
|
|
71
23
|
}
|
|
72
24
|
|
|
73
25
|
public scrollToY(top: number): void {
|
|
74
|
-
const treeTop = getOffsetTop(this.
|
|
26
|
+
const treeTop = getOffsetTop(this._treeElement);
|
|
75
27
|
|
|
76
|
-
|
|
28
|
+
super.scrollToY(top + treeTop);
|
|
77
29
|
}
|
|
78
30
|
|
|
79
31
|
public stopScrolling() {
|
|
80
|
-
|
|
81
|
-
this.verticalScrollDirection = undefined;
|
|
82
|
-
this.documentScrollHeight = undefined;
|
|
83
|
-
this.documentScrollWidth = undefined;
|
|
84
|
-
}
|
|
32
|
+
super.stopScrolling();
|
|
85
33
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
documentElement.scrollTop + documentElement.clientHeight <
|
|
91
|
-
this.getDocumentScrollHeight()
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private canScrollRight() {
|
|
96
|
-
const documentElement = document.documentElement;
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
documentElement.scrollLeft + documentElement.clientWidth <
|
|
100
|
-
this.getDocumentScrollWidth()
|
|
101
|
-
);
|
|
34
|
+
this._documentScrollHeight = undefined;
|
|
35
|
+
this._documentScrollWidth = undefined;
|
|
102
36
|
}
|
|
103
37
|
|
|
104
|
-
|
|
105
|
-
// Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
|
|
106
|
-
if (this.documentScrollHeight == null) {
|
|
107
|
-
this.documentScrollHeight = document.documentElement.scrollHeight;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return this.documentScrollHeight;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private getDocumentScrollWidth() {
|
|
114
|
-
// Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
|
|
115
|
-
if (this.documentScrollWidth == null) {
|
|
116
|
-
this.documentScrollWidth = document.documentElement.scrollWidth;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return this.documentScrollWidth;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private getNewHorizontalScrollDirection(
|
|
38
|
+
protected getNewHorizontalScrollDirection(
|
|
123
39
|
pageX: number,
|
|
124
40
|
): HorizontalScrollDirection | undefined {
|
|
125
|
-
const scrollLeft =
|
|
41
|
+
const scrollLeft = this.container.scrollLeft;
|
|
126
42
|
const windowWidth = window.innerWidth;
|
|
127
43
|
|
|
128
44
|
const isNearRightEdge = pageX > windowWidth - 20;
|
|
129
45
|
const isNearLeftEdge = pageX - scrollLeft < 20;
|
|
130
46
|
|
|
131
|
-
if (isNearRightEdge && this.
|
|
47
|
+
if (isNearRightEdge && this._canScrollRight()) {
|
|
132
48
|
return "right";
|
|
133
49
|
}
|
|
134
50
|
|
|
@@ -139,10 +55,10 @@ export default class DocumentScrollParent implements ScrollParent {
|
|
|
139
55
|
return undefined;
|
|
140
56
|
}
|
|
141
57
|
|
|
142
|
-
|
|
58
|
+
protected getNewVerticalScrollDirection(
|
|
143
59
|
pageY: number,
|
|
144
60
|
): undefined | VerticalScrollDirection {
|
|
145
|
-
const scrollTop =
|
|
61
|
+
const scrollTop = this.container.scrollTop;
|
|
146
62
|
const distanceTop = pageY - scrollTop;
|
|
147
63
|
|
|
148
64
|
if (distanceTop < 20) {
|
|
@@ -151,36 +67,38 @@ export default class DocumentScrollParent implements ScrollParent {
|
|
|
151
67
|
|
|
152
68
|
const windowHeight = window.innerHeight;
|
|
153
69
|
|
|
154
|
-
if (windowHeight - (pageY - scrollTop) < 20 && this.
|
|
70
|
+
if (windowHeight - (pageY - scrollTop) < 20 && this._canScrollDown()) {
|
|
155
71
|
return "bottom";
|
|
156
72
|
}
|
|
157
73
|
|
|
158
74
|
return undefined;
|
|
159
75
|
}
|
|
160
76
|
|
|
161
|
-
private
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
window.scrollBy({ behavior: "instant", left: distance, top: 0 });
|
|
168
|
-
|
|
169
|
-
this.refreshHitAreas();
|
|
77
|
+
private _canScrollDown() {
|
|
78
|
+
return (
|
|
79
|
+
this.container.scrollTop + this.container.clientHeight <
|
|
80
|
+
this._getDocumentScrollHeight()
|
|
81
|
+
);
|
|
82
|
+
}
|
|
170
83
|
|
|
171
|
-
|
|
84
|
+
private _canScrollRight() {
|
|
85
|
+
return (
|
|
86
|
+
this.container.scrollLeft + this.container.clientWidth <
|
|
87
|
+
this._getDocumentScrollWidth()
|
|
88
|
+
);
|
|
172
89
|
}
|
|
173
90
|
|
|
174
|
-
private
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
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;
|
|
178
94
|
|
|
179
|
-
|
|
180
|
-
|
|
95
|
+
return this._documentScrollHeight;
|
|
96
|
+
}
|
|
181
97
|
|
|
182
|
-
|
|
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;
|
|
183
101
|
|
|
184
|
-
|
|
102
|
+
return this._documentScrollWidth;
|
|
185
103
|
}
|
|
186
104
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export type HorizontalScrollDirection = "left" | "right";
|
|
2
|
+
export type VerticalScrollDirection = "bottom" | "top";
|
|
3
|
+
|
|
4
|
+
interface ConstructorParams {
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
refreshHitAreas: () => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export abstract class ScrollParent {
|
|
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
|
+
}
|
|
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;
|
|
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;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
90
|
+
this.container.scrollBy({
|
|
91
|
+
behavior: "instant",
|
|
92
|
+
left: distance,
|
|
93
|
+
top: 0,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.refreshHitAreas();
|
|
97
|
+
|
|
98
|
+
setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected scrollVertically() {
|
|
102
|
+
if (!this.verticalScrollDirection) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const distance = this.verticalScrollDirection === "top" ? -20 : 20;
|
|
107
|
+
this.container.scrollBy({
|
|
108
|
+
behavior: "instant",
|
|
109
|
+
left: 0,
|
|
110
|
+
top: distance,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
this.refreshHitAreas();
|
|
114
|
+
|
|
115
|
+
setTimeout(this.scrollVertically.bind(this), 40);
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/scrollHandler.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { PositionInfo } from "./mouseUtils";
|
|
1
|
+
import type { PositionInfo } from "./mouseUtils";
|
|
2
|
+
import type { ScrollParent } from "./scrollHandler/scrollParent";
|
|
3
|
+
|
|
2
4
|
import createScrollParent from "./scrollHandler/createScrollParent";
|
|
3
|
-
import { ScrollParent } from "./scrollHandler/types";
|
|
4
5
|
|
|
5
6
|
interface ScrollHandlerParams {
|
|
6
7
|
refreshHitAreas: () => void;
|
|
@@ -8,49 +9,47 @@ interface ScrollHandlerParams {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export default class ScrollHandler {
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
12
|
+
private _refreshHitAreas: () => void;
|
|
13
|
+
private _scrollParent?: ScrollParent;
|
|
14
|
+
private _treeElement: HTMLElement;
|
|
14
15
|
|
|
15
16
|
constructor({ refreshHitAreas, treeElement }: ScrollHandlerParams) {
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this._refreshHitAreas = refreshHitAreas;
|
|
18
|
+
this._scrollParent = undefined;
|
|
19
|
+
this._treeElement = treeElement;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
public checkScrolling(positionInfo: PositionInfo): void {
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
23
|
+
this._checkVerticalScrolling(positionInfo);
|
|
24
|
+
this._checkHorizontalScrolling(positionInfo);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
public getScrollLeft(): number {
|
|
27
|
-
return this.
|
|
28
|
+
return this._getScrollParent().getScrollLeft();
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
public scrollToY(top: number): void {
|
|
31
|
-
this.
|
|
32
|
+
this._getScrollParent().scrollToY(top);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
public stopScrolling() {
|
|
35
|
-
this.
|
|
36
|
+
this._getScrollParent().stopScrolling();
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
private
|
|
39
|
-
this.
|
|
39
|
+
private _checkHorizontalScrolling(positionInfo: PositionInfo): void {
|
|
40
|
+
this._getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
private
|
|
43
|
-
this.
|
|
43
|
+
private _checkVerticalScrolling(positionInfo: PositionInfo): void {
|
|
44
|
+
this._getScrollParent().checkVerticalScrolling(positionInfo.pageY);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
);
|
|
52
|
-
}
|
|
47
|
+
private _getScrollParent(): ScrollParent {
|
|
48
|
+
this._scrollParent ??= createScrollParent(
|
|
49
|
+
this._treeElement,
|
|
50
|
+
this._refreshHitAreas,
|
|
51
|
+
);
|
|
53
52
|
|
|
54
|
-
return this.
|
|
53
|
+
return this._scrollParent;
|
|
55
54
|
}
|
|
56
55
|
}
|