jqtree 1.7.4 → 1.7.5
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/.eslintrc +5 -1
- package/bower.json +1 -1
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +5 -0
- package/docs/package.json +1 -1
- package/docs/pnpm-lock.yaml +30 -30
- package/lib/dataLoader.js +2 -3
- package/lib/dragAndDropHandler.js +5 -13
- package/lib/elementsRenderer.js +2 -3
- package/lib/keyHandler.js +1 -5
- package/lib/mouse.widget.js +1 -2
- package/lib/node.js +30 -39
- package/lib/nodeElement.js +3 -6
- package/lib/nodeUtils.js +10 -0
- package/lib/playwright/coverage.js +14 -11
- package/lib/playwright/playwright.test.js +482 -104
- package/lib/playwright/testUtils.js +75 -49
- package/lib/saveStateHandler.js +2 -3
- package/lib/scrollHandler/containerScrollParent.js +160 -0
- package/lib/scrollHandler/createScrollParent.js +57 -0
- package/lib/scrollHandler/documentScrollParent.js +169 -0
- package/lib/scrollHandler/scrollParent.js +58 -0
- package/lib/scrollHandler/types.js +1 -0
- package/lib/scrollHandler.js +28 -207
- package/lib/selectNodeHandler.js +2 -3
- package/lib/simple.widget.js +1 -2
- package/lib/test/jqTree/loadOnDemand.test.js +3 -3
- package/lib/test/jqTree/methods.test.js +2 -1
- package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +94 -0
- package/lib/test/node.test.js +49 -7
- package/lib/test/nodeUtils.test.js +20 -0
- package/lib/test/support/exampleData.js +1 -2
- package/lib/test/support/testUtil.js +3 -6
- package/lib/test/support/treeStructure.js +1 -2
- package/lib/tree.jquery.js +6 -7
- package/lib/util.js +4 -7
- package/lib/version.js +2 -3
- package/package.json +27 -27
- package/src/dragAndDropHandler.ts +27 -33
- package/src/keyHandler.ts +0 -8
- package/src/node.ts +32 -48
- package/src/nodeUtils.ts +10 -0
- package/src/playwright/playwright.test.ts +207 -15
- package/src/playwright/testUtils.ts +23 -15
- package/src/scrollHandler/containerScrollParent.ts +177 -0
- package/src/scrollHandler/createScrollParent.ts +50 -0
- package/src/scrollHandler/documentScrollParent.ts +182 -0
- package/src/scrollHandler/types.ts +7 -0
- package/src/scrollHandler.ts +25 -243
- package/src/test/jqTree/loadOnDemand.test.ts +2 -3
- package/src/test/jqTree/methods.test.ts +1 -1
- package/src/test/node.test.ts +84 -25
- package/src/test/nodeUtils.test.ts +21 -0
- package/src/tree.jquery.ts +27 -30
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +391 -229
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { ScrollParent } from "./types";
|
|
2
|
+
|
|
3
|
+
type HorizontalScrollDirection = "left" | "right";
|
|
4
|
+
type VerticalScrollDirection = "bottom" | "top";
|
|
5
|
+
|
|
6
|
+
export default class DocumentScrollParent implements ScrollParent {
|
|
7
|
+
private $element: JQuery<HTMLElement>;
|
|
8
|
+
private horizontalScrollDirection?: HorizontalScrollDirection;
|
|
9
|
+
private horizontalScrollTimeout?: number;
|
|
10
|
+
private refreshHitAreas: () => void;
|
|
11
|
+
private verticalScrollDirection?: VerticalScrollDirection;
|
|
12
|
+
private verticalScrollTimeout?: number;
|
|
13
|
+
private documentScrollHeight?: number;
|
|
14
|
+
private documentScrollWidth?: number;
|
|
15
|
+
|
|
16
|
+
constructor($element: JQuery<HTMLElement>, refreshHitAreas: () => void) {
|
|
17
|
+
this.$element = $element;
|
|
18
|
+
this.refreshHitAreas = refreshHitAreas;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public checkHorizontalScrolling(pageX: number): void {
|
|
22
|
+
const newHorizontalScrollDirection =
|
|
23
|
+
this.getNewHorizontalScrollDirection(pageX);
|
|
24
|
+
|
|
25
|
+
if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
|
|
26
|
+
this.horizontalScrollDirection = newHorizontalScrollDirection;
|
|
27
|
+
|
|
28
|
+
if (this.horizontalScrollTimeout != null) {
|
|
29
|
+
window.clearTimeout(this.horizontalScrollTimeout);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (newHorizontalScrollDirection) {
|
|
33
|
+
this.horizontalScrollTimeout = window.setTimeout(
|
|
34
|
+
this.scrollHorizontally.bind(this),
|
|
35
|
+
40,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public checkVerticalScrolling(pageY: number) {
|
|
42
|
+
const newVerticalScrollDirection =
|
|
43
|
+
this.getNewVerticalScrollDirection(pageY);
|
|
44
|
+
|
|
45
|
+
if (this.verticalScrollDirection !== newVerticalScrollDirection) {
|
|
46
|
+
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
47
|
+
|
|
48
|
+
if (this.verticalScrollTimeout != null) {
|
|
49
|
+
window.clearTimeout(this.verticalScrollTimeout);
|
|
50
|
+
this.verticalScrollTimeout = undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (newVerticalScrollDirection) {
|
|
54
|
+
this.verticalScrollTimeout = window.setTimeout(
|
|
55
|
+
this.scrollVertically.bind(this),
|
|
56
|
+
40,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public getScrollLeft(): number {
|
|
63
|
+
return document.documentElement.scrollLeft;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public scrollToY(top: number): void {
|
|
67
|
+
const offset = this.$element.offset();
|
|
68
|
+
const treeTop = offset ? offset.top : 0;
|
|
69
|
+
|
|
70
|
+
jQuery(document).scrollTop(top + treeTop);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public stopScrolling() {
|
|
74
|
+
this.horizontalScrollDirection = undefined;
|
|
75
|
+
this.verticalScrollDirection = undefined;
|
|
76
|
+
this.documentScrollHeight = undefined;
|
|
77
|
+
this.documentScrollWidth = undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private getNewHorizontalScrollDirection(
|
|
81
|
+
pageX: number,
|
|
82
|
+
): HorizontalScrollDirection | undefined {
|
|
83
|
+
const $document = jQuery(document);
|
|
84
|
+
|
|
85
|
+
const scrollLeft = $document.scrollLeft() || 0;
|
|
86
|
+
const windowWidth = jQuery(window).width() || 0;
|
|
87
|
+
|
|
88
|
+
const isNearRightEdge = pageX > windowWidth - 20;
|
|
89
|
+
const isNearLeftEdge = pageX - scrollLeft < 20;
|
|
90
|
+
|
|
91
|
+
if (isNearRightEdge && this.canScrollRight()) {
|
|
92
|
+
return "right";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (isNearLeftEdge) {
|
|
96
|
+
return "left";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private canScrollRight() {
|
|
103
|
+
const documentElement = document.documentElement;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
documentElement.scrollLeft + documentElement.clientWidth <
|
|
107
|
+
this.getDocumentScrollWidth()
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private canScrollDown() {
|
|
112
|
+
const documentElement = document.documentElement;
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
documentElement.scrollTop + documentElement.clientHeight <
|
|
116
|
+
this.getDocumentScrollHeight()
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private getDocumentScrollHeight() {
|
|
121
|
+
// Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
|
|
122
|
+
if (this.documentScrollHeight == null) {
|
|
123
|
+
this.documentScrollHeight = document.documentElement.scrollHeight;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return this.documentScrollHeight;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private getDocumentScrollWidth() {
|
|
130
|
+
// Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
|
|
131
|
+
if (this.documentScrollWidth == null) {
|
|
132
|
+
this.documentScrollWidth = document.documentElement.scrollWidth;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return this.documentScrollWidth;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private getNewVerticalScrollDirection(
|
|
139
|
+
pageY: number,
|
|
140
|
+
): VerticalScrollDirection | undefined {
|
|
141
|
+
const scrollTop = jQuery(document).scrollTop() || 0;
|
|
142
|
+
const distanceTop = pageY - scrollTop;
|
|
143
|
+
|
|
144
|
+
if (distanceTop < 20) {
|
|
145
|
+
return "top";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const windowHeight = jQuery(window).height() || 0;
|
|
149
|
+
|
|
150
|
+
if (windowHeight - (pageY - scrollTop) < 20 && this.canScrollDown()) {
|
|
151
|
+
return "bottom";
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private scrollHorizontally() {
|
|
158
|
+
if (!this.horizontalScrollDirection) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
163
|
+
window.scrollBy({ left: distance, top: 0, behavior: "instant" });
|
|
164
|
+
|
|
165
|
+
this.refreshHitAreas();
|
|
166
|
+
|
|
167
|
+
setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private scrollVertically() {
|
|
171
|
+
if (!this.verticalScrollDirection) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const distance = this.verticalScrollDirection === "top" ? -20 : 20;
|
|
176
|
+
window.scrollBy({ left: 0, top: distance, behavior: "instant" });
|
|
177
|
+
|
|
178
|
+
this.refreshHitAreas();
|
|
179
|
+
|
|
180
|
+
setTimeout(this.scrollVertically.bind(this), 40);
|
|
181
|
+
}
|
|
182
|
+
}
|
package/src/scrollHandler.ts
CHANGED
|
@@ -1,276 +1,58 @@
|
|
|
1
1
|
import { JqTreeWidget } from "./tree.jquery";
|
|
2
|
-
import {
|
|
2
|
+
import { PositionInfo } from "./types";
|
|
3
|
+
import { ScrollParent } from "./scrollHandler/types";
|
|
4
|
+
import createScrollParent from "./scrollHandler/createScrollParent";
|
|
3
5
|
|
|
4
6
|
export default class ScrollHandler {
|
|
5
7
|
private treeWidget: JqTreeWidget;
|
|
6
|
-
private
|
|
7
|
-
private isInitialized: boolean;
|
|
8
|
-
private $scrollParent: JQuery | null;
|
|
9
|
-
private scrollParentTop: number;
|
|
8
|
+
private scrollParent?: ScrollParent;
|
|
10
9
|
|
|
11
10
|
constructor(treeWidget: JqTreeWidget) {
|
|
12
11
|
this.treeWidget = treeWidget;
|
|
13
|
-
this.
|
|
14
|
-
this.isInitialized = false;
|
|
12
|
+
this.scrollParent = undefined;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
public checkScrolling(): void {
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.checkHorizontalScrolling();
|
|
15
|
+
public checkScrolling(positionInfo: PositionInfo): void {
|
|
16
|
+
this.checkVerticalScrolling(positionInfo);
|
|
17
|
+
this.checkHorizontalScrolling(positionInfo);
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
public
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
if (this.$scrollParent && this.$scrollParent[0]) {
|
|
27
|
-
this.$scrollParent[0].scrollTop = top;
|
|
28
|
-
} else {
|
|
29
|
-
const offset = this.treeWidget.$el.offset();
|
|
30
|
-
const treeTop = offset ? offset.top : 0;
|
|
31
|
-
|
|
32
|
-
jQuery(document).scrollTop(top + treeTop);
|
|
33
|
-
}
|
|
20
|
+
public stopScrolling() {
|
|
21
|
+
this.getScrollParent().stopScrolling();
|
|
34
22
|
}
|
|
35
23
|
|
|
36
|
-
public
|
|
37
|
-
this.
|
|
38
|
-
|
|
39
|
-
let elementBottom: number;
|
|
40
|
-
let viewBottom: number;
|
|
41
|
-
let elementTop: number;
|
|
42
|
-
let viewTop: number;
|
|
43
|
-
|
|
44
|
-
const elHeight = $element.height() || 0;
|
|
45
|
-
|
|
46
|
-
if (this.$scrollParent) {
|
|
47
|
-
viewTop = 0;
|
|
48
|
-
viewBottom = this.$scrollParent.height() || 0;
|
|
49
|
-
|
|
50
|
-
const offset = $element.offset();
|
|
51
|
-
const originalTop = offset ? offset.top : 0;
|
|
52
|
-
|
|
53
|
-
elementTop = originalTop - this.scrollParentTop;
|
|
54
|
-
elementBottom = elementTop + elHeight;
|
|
55
|
-
} else {
|
|
56
|
-
viewTop = jQuery(window).scrollTop() || 0;
|
|
57
|
-
|
|
58
|
-
const windowHeight = jQuery(window).height() || 0;
|
|
59
|
-
viewBottom = viewTop + windowHeight;
|
|
60
|
-
|
|
61
|
-
const offset = $element.offset();
|
|
62
|
-
|
|
63
|
-
elementTop = offset ? offset.top : 0;
|
|
64
|
-
elementBottom = elementTop + elHeight;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return elementBottom <= viewBottom && elementTop >= viewTop;
|
|
24
|
+
public scrollToY(top: number): void {
|
|
25
|
+
this.getScrollParent().scrollToY(top);
|
|
68
26
|
}
|
|
69
27
|
|
|
70
28
|
public getScrollLeft(): number {
|
|
71
|
-
|
|
72
|
-
return 0;
|
|
73
|
-
} else {
|
|
74
|
-
return this.$scrollParent.scrollLeft() || 0;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private initScrollParent(): void {
|
|
79
|
-
const getParentWithOverflow = (): JQuery | null => {
|
|
80
|
-
const cssAttributes = ["overflow", "overflow-y"];
|
|
81
|
-
|
|
82
|
-
const hasOverFlow = ($el: JQuery): boolean => {
|
|
83
|
-
for (const attr of cssAttributes) {
|
|
84
|
-
const overflowValue = $el.css(attr);
|
|
85
|
-
if (
|
|
86
|
-
overflowValue === "auto" ||
|
|
87
|
-
overflowValue === "scroll"
|
|
88
|
-
) {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return false;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (hasOverFlow(this.treeWidget.$el)) {
|
|
97
|
-
return this.treeWidget.$el;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
for (const el of this.treeWidget.$el.parents().get()) {
|
|
101
|
-
const $el = jQuery(el);
|
|
102
|
-
if (hasOverFlow($el)) {
|
|
103
|
-
return $el;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return null;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const setDocumentAsScrollParent = (): void => {
|
|
111
|
-
this.scrollParentTop = 0;
|
|
112
|
-
this.$scrollParent = null;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (this.treeWidget.$el.css("position") === "fixed") {
|
|
116
|
-
setDocumentAsScrollParent();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const $scrollParent = getParentWithOverflow();
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
$scrollParent &&
|
|
123
|
-
$scrollParent.length &&
|
|
124
|
-
$scrollParent[0]?.tagName !== "HTML"
|
|
125
|
-
) {
|
|
126
|
-
this.$scrollParent = $scrollParent;
|
|
127
|
-
|
|
128
|
-
const offset = this.$scrollParent.offset();
|
|
129
|
-
this.scrollParentTop = offset ? offset.top : 0;
|
|
130
|
-
} else {
|
|
131
|
-
setDocumentAsScrollParent();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
this.isInitialized = true;
|
|
29
|
+
return this.getScrollParent().getScrollLeft();
|
|
135
30
|
}
|
|
136
31
|
|
|
137
|
-
private
|
|
138
|
-
if (
|
|
139
|
-
this.initScrollParent();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private handleVerticalScrollingWithScrollParent(area: HitArea): void {
|
|
144
|
-
const scrollParent = this.$scrollParent && this.$scrollParent[0];
|
|
145
|
-
|
|
146
|
-
if (!scrollParent) {
|
|
32
|
+
private checkVerticalScrolling(positionInfo: PositionInfo): void {
|
|
33
|
+
if (positionInfo.pageY == null) {
|
|
147
34
|
return;
|
|
148
35
|
}
|
|
149
36
|
|
|
150
|
-
|
|
151
|
-
this.scrollParentTop + scrollParent.offsetHeight - area.bottom;
|
|
152
|
-
|
|
153
|
-
if (distanceBottom < 20) {
|
|
154
|
-
scrollParent.scrollTop += 20;
|
|
155
|
-
this.treeWidget.refreshHitAreas();
|
|
156
|
-
this.previousTop = -1;
|
|
157
|
-
} else if (area.top - this.scrollParentTop < 20) {
|
|
158
|
-
scrollParent.scrollTop -= 20;
|
|
159
|
-
this.treeWidget.refreshHitAreas();
|
|
160
|
-
this.previousTop = -1;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private handleVerticalScrollingWithDocument(area: HitArea): void {
|
|
165
|
-
const scrollTop = jQuery(document).scrollTop() || 0;
|
|
166
|
-
const distanceTop = area.top - scrollTop;
|
|
167
|
-
|
|
168
|
-
if (distanceTop < 20) {
|
|
169
|
-
jQuery(document).scrollTop(scrollTop - 20);
|
|
170
|
-
} else {
|
|
171
|
-
const windowHeight = jQuery(window).height() || 0;
|
|
172
|
-
|
|
173
|
-
if (windowHeight - (area.bottom - scrollTop) < 20) {
|
|
174
|
-
jQuery(document).scrollTop(scrollTop + 20);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private checkVerticalScrolling(): void {
|
|
180
|
-
const hoveredArea = this.treeWidget.dndHandler.hoveredArea;
|
|
181
|
-
|
|
182
|
-
if (hoveredArea && hoveredArea.top !== this.previousTop) {
|
|
183
|
-
this.previousTop = hoveredArea.top;
|
|
184
|
-
|
|
185
|
-
if (this.$scrollParent) {
|
|
186
|
-
this.handleVerticalScrollingWithScrollParent(hoveredArea);
|
|
187
|
-
} else {
|
|
188
|
-
this.handleVerticalScrollingWithDocument(hoveredArea);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
37
|
+
this.getScrollParent().checkVerticalScrolling(positionInfo.pageY);
|
|
191
38
|
}
|
|
192
39
|
|
|
193
|
-
private checkHorizontalScrolling(): void {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (!positionInfo) {
|
|
40
|
+
private checkHorizontalScrolling(positionInfo: PositionInfo): void {
|
|
41
|
+
if (positionInfo.pageX == null) {
|
|
197
42
|
return;
|
|
198
43
|
}
|
|
199
44
|
|
|
200
|
-
|
|
201
|
-
this.handleHorizontalScrollingWithParent(positionInfo);
|
|
202
|
-
} else {
|
|
203
|
-
this.handleHorizontalScrollingWithDocument(positionInfo);
|
|
204
|
-
}
|
|
45
|
+
this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
|
|
205
46
|
}
|
|
206
47
|
|
|
207
|
-
private
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
positionInfo.pageY === undefined
|
|
213
|
-
) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const $scrollParent = this.$scrollParent;
|
|
218
|
-
const scrollParentOffset = $scrollParent && $scrollParent.offset();
|
|
219
|
-
|
|
220
|
-
if (!($scrollParent && scrollParentOffset)) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const scrollParent = $scrollParent[0];
|
|
225
|
-
|
|
226
|
-
if (!scrollParent) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const canScrollRight =
|
|
231
|
-
scrollParent.scrollLeft + scrollParent.clientWidth <
|
|
232
|
-
scrollParent.scrollWidth;
|
|
233
|
-
const canScrollLeft = scrollParent.scrollLeft > 0;
|
|
234
|
-
|
|
235
|
-
const rightEdge = scrollParentOffset.left + scrollParent.clientWidth;
|
|
236
|
-
const leftEdge = scrollParentOffset.left;
|
|
237
|
-
const isNearRightEdge = positionInfo.pageX > rightEdge - 20;
|
|
238
|
-
const isNearLeftEdge = positionInfo.pageX < leftEdge + 20;
|
|
239
|
-
|
|
240
|
-
if (isNearRightEdge && canScrollRight) {
|
|
241
|
-
scrollParent.scrollLeft = Math.min(
|
|
242
|
-
scrollParent.scrollLeft + 20,
|
|
243
|
-
scrollParent.scrollWidth
|
|
48
|
+
private getScrollParent(): ScrollParent {
|
|
49
|
+
if (!this.scrollParent) {
|
|
50
|
+
this.scrollParent = createScrollParent(
|
|
51
|
+
this.treeWidget.$el,
|
|
52
|
+
this.treeWidget.refreshHitAreas.bind(this.treeWidget),
|
|
244
53
|
);
|
|
245
|
-
} else if (isNearLeftEdge && canScrollLeft) {
|
|
246
|
-
scrollParent.scrollLeft = Math.max(scrollParent.scrollLeft - 20, 0);
|
|
247
54
|
}
|
|
248
|
-
}
|
|
249
55
|
|
|
250
|
-
|
|
251
|
-
positionInfo: PositionInfo
|
|
252
|
-
): void {
|
|
253
|
-
if (
|
|
254
|
-
positionInfo.pageX === undefined ||
|
|
255
|
-
positionInfo.pageY === undefined
|
|
256
|
-
) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const $document = jQuery(document);
|
|
261
|
-
|
|
262
|
-
const scrollLeft = $document.scrollLeft() || 0;
|
|
263
|
-
const windowWidth = jQuery(window).width() || 0;
|
|
264
|
-
|
|
265
|
-
const canScrollLeft = scrollLeft > 0;
|
|
266
|
-
|
|
267
|
-
const isNearRightEdge = positionInfo.pageX > windowWidth - 20;
|
|
268
|
-
const isNearLeftEdge = positionInfo.pageX - scrollLeft < 20;
|
|
269
|
-
|
|
270
|
-
if (isNearRightEdge) {
|
|
271
|
-
$document.scrollLeft(scrollLeft + 20);
|
|
272
|
-
} else if (isNearLeftEdge && canScrollLeft) {
|
|
273
|
-
$document.scrollLeft(Math.max(scrollLeft - 20, 0));
|
|
274
|
-
}
|
|
56
|
+
return this.scrollParent;
|
|
275
57
|
}
|
|
276
58
|
}
|
|
@@ -136,9 +136,8 @@ context("when a node has load_on_demand in the data", () => {
|
|
|
136
136
|
|
|
137
137
|
context("when the node is selected and doesn't have the focus", () => {
|
|
138
138
|
beforeEach(() => {
|
|
139
|
-
given.$tree.tree("selectNode", given.node
|
|
140
|
-
|
|
141
|
-
});
|
|
139
|
+
given.$tree.tree("selectNode", given.node);
|
|
140
|
+
(document.activeElement as HTMLElement).blur(); // eslint-disable-line testing-library/no-node-access
|
|
142
141
|
});
|
|
143
142
|
|
|
144
143
|
it("keeps the node selected and not focused", async () => {
|
|
@@ -984,7 +984,7 @@ describe("refresh", () => {
|
|
|
984
984
|
|
|
985
985
|
it("rerenders the tree", () => {
|
|
986
986
|
const tree = given.$tree.tree("getTree");
|
|
987
|
-
(tree.children[0] as INode).name = "node1a";
|
|
987
|
+
(tree.children[0] as INode).name = "node1a"; // eslint-disable-line testing-library/no-node-access
|
|
988
988
|
|
|
989
989
|
expect(given.$tree).toHaveTreeStructure([
|
|
990
990
|
expect.objectContaining({ name: "node1" }),
|