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