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