jqtree 1.7.5 → 1.8.1
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 +13 -3
- package/.github/workflows/ci.yml +6 -6
- package/.github/workflows/codeql-analysis.yml +4 -4
- package/.github/workflows/size.yml +3 -3
- package/.github/workflows/static.yml +1 -1
- package/bower.json +1 -1
- package/config/babel.config.json +1 -1
- package/config/jest.config.js +4 -0
- package/config/jest.polyfills.js +14 -0
- package/config/production +2 -0
- package/devserver/devserver_scroll.js +8 -0
- package/devserver/test_index.html +9 -0
- package/devserver/test_scroll.html +28 -0
- package/devserver/test_scroll_container.html +39 -0
- package/docs/.ruby-version +1 -1
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +11 -0
- package/docs/_entries/multiple_selection/get-selected-nodes.md +1 -1
- package/docs/_entries/node/getnextnode.md +3 -6
- package/docs/_entries/node/getnextsibling.md +1 -1
- package/docs/_entries/node/getnextvisiblenode.md +8 -5
- package/docs/_entries/node/getpreviousnode.md +12 -0
- package/docs/_entries/node/getprevioussibling.md +1 -1
- package/docs/_entries/node/getpreviousvisiblenode.md +6 -5
- package/package.json +35 -29
- package/src/dataLoader.ts +57 -34
- package/src/dragAndDropHandler/dragElement.ts +54 -0
- package/src/dragAndDropHandler/generateHitAreas.ts +176 -0
- package/src/dragAndDropHandler/index.ts +454 -0
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
- package/src/dragAndDropHandler/types.ts +13 -0
- package/src/elementsRenderer.ts +75 -40
- package/src/jqtreeMethodTypes.ts +40 -0
- package/src/jqtreeOptions.ts +43 -25
- package/src/keyHandler.ts +59 -30
- package/src/mouseHandler.ts +385 -0
- package/src/mouseUtils.ts +23 -0
- package/src/node.ts +1 -29
- package/src/nodeElement/borderDropHint.ts +32 -0
- package/src/nodeElement/folderElement.ts +133 -0
- package/src/nodeElement/ghostDropHint.ts +69 -0
- package/src/nodeElement/index.ts +102 -0
- package/src/playwright/coverage.ts +4 -7
- package/src/playwright/playwright.test.ts +150 -53
- package/src/playwright/testUtils.ts +28 -5
- package/src/position.ts +28 -0
- package/src/saveStateHandler.ts +75 -26
- package/src/scrollHandler/containerScrollParent.ts +13 -23
- package/src/scrollHandler/createScrollParent.ts +22 -22
- package/src/scrollHandler/documentScrollParent.ts +16 -13
- package/src/scrollHandler.ts +13 -15
- package/src/selectNodeHandler.ts +10 -16
- package/src/test/jqTree/events.test.ts +97 -30
- package/src/test/jqTree/keyboard.test.ts +18 -23
- package/src/test/jqTree/loadOnDemand.test.ts +22 -15
- package/src/test/jqTree/methods.test.ts +40 -14
- package/src/test/jqTree/mouse.test.ts +82 -0
- package/src/test/jqTree/options.test.ts +24 -12
- package/src/test/node.test.ts +3 -2
- package/src/test/{nodeUtil.test.ts → position.test.ts} +1 -1
- package/src/tree.jquery.ts +314 -208
- package/src/util.ts +12 -0
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +2594 -3419
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +3 -3
- package/tree.jquery.js.map +1 -1
- package/tsconfig.json +5 -3
- package/docs/_entries/functions/get-selected-nodes.md +0 -10
- package/lib/dataLoader.js +0 -123
- package/lib/dragAndDropHandler.js +0 -588
- package/lib/elementsRenderer.js +0 -267
- package/lib/jqtreeOptions.js +0 -1
- package/lib/keyHandler.js +0 -111
- package/lib/mouse.widget.js +0 -255
- package/lib/node.js +0 -708
- package/lib/nodeElement.js +0 -274
- package/lib/nodeUtils.js +0 -10
- package/lib/playwright/coverage.js +0 -99
- package/lib/playwright/playwright.test.js +0 -606
- package/lib/playwright/testUtils.js +0 -210
- package/lib/saveStateHandler.js +0 -277
- package/lib/scrollHandler/containerScrollParent.js +0 -160
- package/lib/scrollHandler/createScrollParent.js +0 -57
- package/lib/scrollHandler/documentScrollParent.js +0 -169
- package/lib/scrollHandler/scrollParent.js +0 -58
- package/lib/scrollHandler/types.js +0 -1
- package/lib/scrollHandler.js +0 -71
- package/lib/selectNodeHandler.js +0 -128
- package/lib/simple.widget.js +0 -158
- package/lib/test/global.d.js +0 -3
- package/lib/test/jqTree/accessibility.test.js +0 -37
- package/lib/test/jqTree/create.test.js +0 -48
- package/lib/test/jqTree/events.test.js +0 -210
- package/lib/test/jqTree/keyboard.test.js +0 -225
- package/lib/test/jqTree/loadOnDemand.test.js +0 -218
- package/lib/test/jqTree/methods.test.js +0 -1348
- package/lib/test/jqTree/options.test.js +0 -548
- package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +0 -94
- package/lib/test/node.test.js +0 -1202
- package/lib/test/nodeUtil.test.js +0 -27
- package/lib/test/nodeUtils.test.js +0 -20
- package/lib/test/support/exampleData.js +0 -35
- package/lib/test/support/jqTreeMatchers.js +0 -70
- package/lib/test/support/matchers.d.js +0 -1
- package/lib/test/support/setupTests.js +0 -7
- package/lib/test/support/testUtil.js +0 -29
- package/lib/test/support/treeStructure.js +0 -38
- package/lib/test/util.test.js +0 -26
- package/lib/tree.jquery.d.js +0 -1
- package/lib/tree.jquery.js +0 -1105
- package/lib/types.js +0 -1
- package/lib/typings.d.js +0 -2
- package/lib/util.js +0 -15
- package/lib/version.js +0 -8
- package/src/dragAndDropHandler.ts +0 -713
- package/src/mouse.widget.ts +0 -266
- package/src/nodeElement.ts +0 -272
- package/src/types.ts +0 -19
package/src/saveStateHandler.ts
CHANGED
|
@@ -1,25 +1,76 @@
|
|
|
1
1
|
import { isInt } from "./util";
|
|
2
|
-
import { JqTreeWidget } from "./tree.jquery";
|
|
3
2
|
import { Node } from "./node";
|
|
3
|
+
import { OnGetStateFromStorage, OnSetStateFromStorage } from "./jqtreeOptions";
|
|
4
|
+
import {
|
|
5
|
+
AddToSelection,
|
|
6
|
+
GetNodeById,
|
|
7
|
+
GetSelectedNodes,
|
|
8
|
+
GetTree,
|
|
9
|
+
OpenNode,
|
|
10
|
+
RefreshElements,
|
|
11
|
+
RemoveFromSelection,
|
|
12
|
+
} from "./jqtreeMethodTypes";
|
|
4
13
|
|
|
5
14
|
export interface SavedState {
|
|
6
15
|
open_nodes: NodeId[];
|
|
7
16
|
selected_node: NodeId[];
|
|
8
17
|
}
|
|
9
18
|
|
|
19
|
+
interface SaveStateHandlerParams {
|
|
20
|
+
addToSelection: AddToSelection;
|
|
21
|
+
getNodeById: GetNodeById;
|
|
22
|
+
getSelectedNodes: GetSelectedNodes;
|
|
23
|
+
getTree: GetTree;
|
|
24
|
+
onGetStateFromStorage?: OnGetStateFromStorage;
|
|
25
|
+
onSetStateFromStorage?: OnSetStateFromStorage;
|
|
26
|
+
openNode: OpenNode;
|
|
27
|
+
refreshElements: RefreshElements;
|
|
28
|
+
removeFromSelection: RemoveFromSelection;
|
|
29
|
+
saveState: boolean | string;
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
export default class SaveStateHandler {
|
|
11
|
-
private
|
|
33
|
+
private addToSelection: AddToSelection;
|
|
34
|
+
private getNodeById: GetNodeById;
|
|
35
|
+
private getSelectedNodes: GetSelectedNodes;
|
|
36
|
+
private getTree: GetTree;
|
|
37
|
+
private onGetStateFromStorage?: OnGetStateFromStorage;
|
|
38
|
+
private onSetStateFromStorage?: OnSetStateFromStorage;
|
|
39
|
+
private openNode: OpenNode;
|
|
40
|
+
private refreshElements: RefreshElements;
|
|
41
|
+
private removeFromSelection: RemoveFromSelection;
|
|
42
|
+
private saveStateOption: boolean | string;
|
|
12
43
|
private _supportsLocalStorage: boolean | null;
|
|
13
44
|
|
|
14
|
-
constructor(
|
|
15
|
-
|
|
45
|
+
constructor({
|
|
46
|
+
addToSelection,
|
|
47
|
+
getNodeById,
|
|
48
|
+
getSelectedNodes,
|
|
49
|
+
getTree,
|
|
50
|
+
onGetStateFromStorage,
|
|
51
|
+
onSetStateFromStorage,
|
|
52
|
+
openNode,
|
|
53
|
+
refreshElements,
|
|
54
|
+
removeFromSelection,
|
|
55
|
+
saveState,
|
|
56
|
+
}: SaveStateHandlerParams) {
|
|
57
|
+
this.addToSelection = addToSelection;
|
|
58
|
+
this.getNodeById = getNodeById;
|
|
59
|
+
this.getSelectedNodes = getSelectedNodes;
|
|
60
|
+
this.getTree = getTree;
|
|
61
|
+
this.onGetStateFromStorage = onGetStateFromStorage;
|
|
62
|
+
this.onSetStateFromStorage = onSetStateFromStorage;
|
|
63
|
+
this.openNode = openNode;
|
|
64
|
+
this.refreshElements = refreshElements;
|
|
65
|
+
this.removeFromSelection = removeFromSelection;
|
|
66
|
+
this.saveStateOption = saveState;
|
|
16
67
|
}
|
|
17
68
|
|
|
18
69
|
public saveState(): void {
|
|
19
70
|
const state = JSON.stringify(this.getState());
|
|
20
71
|
|
|
21
|
-
if (this.
|
|
22
|
-
this.
|
|
72
|
+
if (this.onSetStateFromStorage) {
|
|
73
|
+
this.onSetStateFromStorage(state);
|
|
23
74
|
} else if (this.supportsLocalStorage()) {
|
|
24
75
|
localStorage.setItem(this.getKeyName(), state);
|
|
25
76
|
}
|
|
@@ -39,7 +90,7 @@ export default class SaveStateHandler {
|
|
|
39
90
|
const getOpenNodeIds = (): NodeId[] => {
|
|
40
91
|
const openNodes: NodeId[] = [];
|
|
41
92
|
|
|
42
|
-
this.
|
|
93
|
+
this.getTree()?.iterate((node: Node) => {
|
|
43
94
|
if (node.is_open && node.id && node.hasChildren()) {
|
|
44
95
|
openNodes.push(node.id);
|
|
45
96
|
}
|
|
@@ -52,7 +103,7 @@ export default class SaveStateHandler {
|
|
|
52
103
|
const getSelectedNodeIds = (): NodeId[] => {
|
|
53
104
|
const selectedNodeIds: NodeId[] = [];
|
|
54
105
|
|
|
55
|
-
this.
|
|
106
|
+
this.getSelectedNodes().forEach((node) => {
|
|
56
107
|
if (node.id != null) {
|
|
57
108
|
selectedNodeIds.push(node.id);
|
|
58
109
|
}
|
|
@@ -94,13 +145,13 @@ export default class SaveStateHandler {
|
|
|
94
145
|
|
|
95
146
|
public setInitialStateOnDemand(
|
|
96
147
|
state: SavedState,
|
|
97
|
-
cbFinished: () => void
|
|
148
|
+
cbFinished: () => void,
|
|
98
149
|
): void {
|
|
99
150
|
if (state) {
|
|
100
151
|
this.doSetInitialStateOnDemand(
|
|
101
152
|
state.open_nodes,
|
|
102
153
|
state.selected_node,
|
|
103
|
-
cbFinished
|
|
154
|
+
cbFinished,
|
|
104
155
|
);
|
|
105
156
|
} else {
|
|
106
157
|
cbFinished();
|
|
@@ -130,8 +181,8 @@ export default class SaveStateHandler {
|
|
|
130
181
|
}
|
|
131
182
|
|
|
132
183
|
private loadFromStorage(): string | null {
|
|
133
|
-
if (this.
|
|
134
|
-
return this.
|
|
184
|
+
if (this.onGetStateFromStorage) {
|
|
185
|
+
return this.onGetStateFromStorage();
|
|
135
186
|
} else if (this.supportsLocalStorage()) {
|
|
136
187
|
return localStorage.getItem(this.getKeyName());
|
|
137
188
|
} else {
|
|
@@ -143,7 +194,7 @@ export default class SaveStateHandler {
|
|
|
143
194
|
let mustLoadOnDemand = false;
|
|
144
195
|
|
|
145
196
|
for (const nodeId of nodeIds) {
|
|
146
|
-
const node = this.
|
|
197
|
+
const node = this.getNodeById(nodeId);
|
|
147
198
|
|
|
148
199
|
if (node) {
|
|
149
200
|
if (!node.load_on_demand) {
|
|
@@ -161,12 +212,12 @@ export default class SaveStateHandler {
|
|
|
161
212
|
let selectCount = 0;
|
|
162
213
|
|
|
163
214
|
for (const nodeId of nodeIds) {
|
|
164
|
-
const node = this.
|
|
215
|
+
const node = this.getNodeById(nodeId);
|
|
165
216
|
|
|
166
217
|
if (node) {
|
|
167
218
|
selectCount += 1;
|
|
168
219
|
|
|
169
|
-
this.
|
|
220
|
+
this.addToSelection(node);
|
|
170
221
|
}
|
|
171
222
|
}
|
|
172
223
|
|
|
@@ -174,19 +225,17 @@ export default class SaveStateHandler {
|
|
|
174
225
|
}
|
|
175
226
|
|
|
176
227
|
private resetSelection(): void {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
const selectedNodes = selectNodeHandler.getSelectedNodes();
|
|
228
|
+
const selectedNodes = this.getSelectedNodes();
|
|
180
229
|
|
|
181
230
|
selectedNodes.forEach((node) => {
|
|
182
|
-
|
|
231
|
+
this.removeFromSelection(node);
|
|
183
232
|
});
|
|
184
233
|
}
|
|
185
234
|
|
|
186
235
|
private doSetInitialStateOnDemand(
|
|
187
236
|
nodeIdsParam: NodeId[],
|
|
188
237
|
selectedNodes: NodeId[],
|
|
189
|
-
cbFinished: () => void
|
|
238
|
+
cbFinished: () => void,
|
|
190
239
|
): void {
|
|
191
240
|
let loadingCount = 0;
|
|
192
241
|
let nodeIds = nodeIdsParam;
|
|
@@ -195,7 +244,7 @@ export default class SaveStateHandler {
|
|
|
195
244
|
const newNodesIds = [];
|
|
196
245
|
|
|
197
246
|
for (const nodeId of nodeIds) {
|
|
198
|
-
const node = this.
|
|
247
|
+
const node = this.getNodeById(nodeId);
|
|
199
248
|
|
|
200
249
|
if (!node) {
|
|
201
250
|
newNodesIds.push(nodeId);
|
|
@@ -204,7 +253,7 @@ export default class SaveStateHandler {
|
|
|
204
253
|
if (node.load_on_demand) {
|
|
205
254
|
loadAndOpenNode(node);
|
|
206
255
|
} else {
|
|
207
|
-
this.
|
|
256
|
+
this.openNode(node, false);
|
|
208
257
|
}
|
|
209
258
|
}
|
|
210
259
|
}
|
|
@@ -213,7 +262,7 @@ export default class SaveStateHandler {
|
|
|
213
262
|
nodeIds = newNodesIds;
|
|
214
263
|
|
|
215
264
|
if (this.selectInitialNodes(selectedNodes)) {
|
|
216
|
-
this.
|
|
265
|
+
this.refreshElements(null);
|
|
217
266
|
}
|
|
218
267
|
|
|
219
268
|
if (loadingCount === 0) {
|
|
@@ -223,7 +272,7 @@ export default class SaveStateHandler {
|
|
|
223
272
|
|
|
224
273
|
const loadAndOpenNode = (node: Node): void => {
|
|
225
274
|
loadingCount += 1;
|
|
226
|
-
this.
|
|
275
|
+
this.openNode(node, false, () => {
|
|
227
276
|
loadingCount -= 1;
|
|
228
277
|
openNodes();
|
|
229
278
|
});
|
|
@@ -233,8 +282,8 @@ export default class SaveStateHandler {
|
|
|
233
282
|
}
|
|
234
283
|
|
|
235
284
|
private getKeyName(): string {
|
|
236
|
-
if (typeof this.
|
|
237
|
-
return this.
|
|
285
|
+
if (typeof this.saveStateOption === "string") {
|
|
286
|
+
return this.saveStateOption;
|
|
238
287
|
} else {
|
|
239
288
|
return "tree";
|
|
240
289
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { ScrollParent } from "./types";
|
|
2
|
+
import { getElementPosition, getOffsetTop } from '../util'
|
|
2
3
|
|
|
3
4
|
type HorizontalScrollDirection = "left" | "right";
|
|
4
5
|
type VerticalScrollDirection = "bottom" | "top";
|
|
5
6
|
|
|
6
7
|
interface Params {
|
|
7
|
-
|
|
8
|
+
container: HTMLElement;
|
|
8
9
|
refreshHitAreas: () => void;
|
|
9
|
-
$treeElement: JQuery<HTMLElement>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export default class ContainerScrollParent implements ScrollParent {
|
|
13
|
-
private
|
|
13
|
+
private container: HTMLElement;
|
|
14
14
|
private horizontalScrollDirection?: HorizontalScrollDirection;
|
|
15
15
|
private horizontalScrollTimeout?: number;
|
|
16
16
|
private refreshHitAreas: () => void;
|
|
@@ -19,8 +19,8 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
19
19
|
private verticalScrollTimeout?: number;
|
|
20
20
|
private verticalScrollDirection?: VerticalScrollDirection;
|
|
21
21
|
|
|
22
|
-
constructor({
|
|
23
|
-
this
|
|
22
|
+
constructor({ container, refreshHitAreas }: Params) {
|
|
23
|
+
this.container = container;
|
|
24
24
|
this.refreshHitAreas = refreshHitAreas;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -66,12 +66,11 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
public getScrollLeft(): number {
|
|
69
|
-
return this
|
|
69
|
+
return this.container.scrollLeft;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
public scrollToY(top: number): void {
|
|
73
|
-
|
|
74
|
-
container.scrollTop = top;
|
|
73
|
+
this.container.scrollTop = top;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
public stopScrolling() {
|
|
@@ -84,14 +83,9 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
84
83
|
private getNewHorizontalScrollDirection(
|
|
85
84
|
pageX: number,
|
|
86
85
|
): HorizontalScrollDirection | undefined {
|
|
87
|
-
const scrollParentOffset = this
|
|
88
|
-
if (!scrollParentOffset) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const container = this.$container.get(0) as HTMLElement;
|
|
86
|
+
const scrollParentOffset = getElementPosition(this.container);
|
|
93
87
|
|
|
94
|
-
const rightEdge = scrollParentOffset.left + container.clientWidth;
|
|
88
|
+
const rightEdge = scrollParentOffset.left + this.container.clientWidth;
|
|
95
89
|
const leftEdge = scrollParentOffset.left;
|
|
96
90
|
const isNearRightEdge = pageX > rightEdge - 20;
|
|
97
91
|
const isNearLeftEdge = pageX < leftEdge + 20;
|
|
@@ -125,9 +119,8 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
125
119
|
}
|
|
126
120
|
|
|
127
121
|
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
128
|
-
const container = this.$container.get(0) as HTMLElement;
|
|
129
122
|
|
|
130
|
-
container.scrollBy({
|
|
123
|
+
this.container.scrollBy({
|
|
131
124
|
left: distance,
|
|
132
125
|
top: 0,
|
|
133
126
|
behavior: "instant",
|
|
@@ -144,9 +137,8 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
144
137
|
}
|
|
145
138
|
|
|
146
139
|
const distance = this.verticalScrollDirection === "top" ? -20 : 20;
|
|
147
|
-
const container = this.$container.get(0) as HTMLElement;
|
|
148
140
|
|
|
149
|
-
container.scrollBy({
|
|
141
|
+
this.container.scrollBy({
|
|
150
142
|
left: 0,
|
|
151
143
|
top: distance,
|
|
152
144
|
behavior: "instant",
|
|
@@ -159,7 +151,7 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
159
151
|
|
|
160
152
|
private getScrollParentTop() {
|
|
161
153
|
if (this.scrollParentTop == null) {
|
|
162
|
-
this.scrollParentTop = this
|
|
154
|
+
this.scrollParentTop = getOffsetTop(this.container)
|
|
163
155
|
}
|
|
164
156
|
|
|
165
157
|
return this.scrollParentTop;
|
|
@@ -167,9 +159,7 @@ export default class ContainerScrollParent implements ScrollParent {
|
|
|
167
159
|
|
|
168
160
|
private getScrollParentBottom() {
|
|
169
161
|
if (this.scrollParentBottom == null) {
|
|
170
|
-
this.scrollParentBottom =
|
|
171
|
-
this.getScrollParentTop() +
|
|
172
|
-
(this.$container.innerHeight() ?? 0);
|
|
162
|
+
this.scrollParentBottom = this.getScrollParentTop() + this.container.clientHeight;
|
|
173
163
|
}
|
|
174
164
|
|
|
175
165
|
return this.scrollParentBottom;
|
|
@@ -2,48 +2,48 @@ import type { ScrollParent } from "./types";
|
|
|
2
2
|
import ContainerScrollParent from "./containerScrollParent";
|
|
3
3
|
import DocumentScrollParent from "./documentScrollParent";
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
}
|
|
5
|
+
const isOverflow = (overflowValue: string) =>
|
|
6
|
+
overflowValue === "auto" || overflowValue === "scroll";
|
|
7
|
+
|
|
8
|
+
const hasOverFlow = (element: HTMLElement): boolean => {
|
|
9
|
+
const style = getComputedStyle(element);
|
|
12
10
|
|
|
13
|
-
return
|
|
11
|
+
return isOverflow(style.overflowX) || isOverflow(style.overflowY);
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
const getParentWithOverflow = (
|
|
17
|
-
|
|
18
|
-
):
|
|
19
|
-
if (hasOverFlow(
|
|
20
|
-
return
|
|
15
|
+
treeElement: HTMLElement,
|
|
16
|
+
): HTMLElement | null => {
|
|
17
|
+
if (hasOverFlow(treeElement)) {
|
|
18
|
+
return treeElement;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
let parent = treeElement.parentElement;
|
|
22
|
+
|
|
23
|
+
while (parent) {
|
|
24
|
+
if (hasOverFlow(parent)) {
|
|
25
|
+
return parent;
|
|
27
26
|
}
|
|
27
|
+
|
|
28
|
+
parent = parent.parentElement;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
return null;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
const createScrollParent = (
|
|
34
|
-
|
|
35
|
+
treeElement: HTMLElement,
|
|
35
36
|
refreshHitAreas: () => void,
|
|
36
37
|
): ScrollParent => {
|
|
37
|
-
const
|
|
38
|
+
const container = getParentWithOverflow(treeElement);
|
|
38
39
|
|
|
39
|
-
if (
|
|
40
|
+
if (container && container.tagName !== "HTML") {
|
|
40
41
|
return new ContainerScrollParent({
|
|
41
|
-
|
|
42
|
+
container,
|
|
42
43
|
refreshHitAreas,
|
|
43
|
-
$treeElement,
|
|
44
44
|
});
|
|
45
45
|
} else {
|
|
46
|
-
return new DocumentScrollParent(
|
|
46
|
+
return new DocumentScrollParent({ refreshHitAreas, treeElement });
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import type { ScrollParent } from "./types";
|
|
2
|
+
import { getOffsetTop } from '../util'
|
|
2
3
|
|
|
3
4
|
type HorizontalScrollDirection = "left" | "right";
|
|
4
5
|
type VerticalScrollDirection = "bottom" | "top";
|
|
5
6
|
|
|
7
|
+
interface Params {
|
|
8
|
+
refreshHitAreas: () => void;
|
|
9
|
+
treeElement: HTMLElement;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
export default class DocumentScrollParent implements ScrollParent {
|
|
7
|
-
private
|
|
13
|
+
private documentScrollHeight?: number;
|
|
14
|
+
private documentScrollWidth?: number;
|
|
8
15
|
private horizontalScrollDirection?: HorizontalScrollDirection;
|
|
9
16
|
private horizontalScrollTimeout?: number;
|
|
10
17
|
private refreshHitAreas: () => void;
|
|
18
|
+
private treeElement: HTMLElement;
|
|
11
19
|
private verticalScrollDirection?: VerticalScrollDirection;
|
|
12
20
|
private verticalScrollTimeout?: number;
|
|
13
|
-
private documentScrollHeight?: number;
|
|
14
|
-
private documentScrollWidth?: number;
|
|
15
21
|
|
|
16
|
-
constructor(
|
|
17
|
-
this.$element = $element;
|
|
22
|
+
constructor({ refreshHitAreas, treeElement }: Params) {
|
|
18
23
|
this.refreshHitAreas = refreshHitAreas;
|
|
24
|
+
this.treeElement = treeElement;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
public checkHorizontalScrolling(pageX: number): void {
|
|
@@ -64,10 +70,9 @@ export default class DocumentScrollParent implements ScrollParent {
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
public scrollToY(top: number): void {
|
|
67
|
-
const
|
|
68
|
-
const treeTop = offset ? offset.top : 0;
|
|
73
|
+
const treeTop = getOffsetTop(this.treeElement);
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
document.documentElement.scrollTop = top + treeTop;
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
public stopScrolling() {
|
|
@@ -80,10 +85,8 @@ export default class DocumentScrollParent implements ScrollParent {
|
|
|
80
85
|
private getNewHorizontalScrollDirection(
|
|
81
86
|
pageX: number,
|
|
82
87
|
): HorizontalScrollDirection | undefined {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const scrollLeft = $document.scrollLeft() || 0;
|
|
86
|
-
const windowWidth = jQuery(window).width() || 0;
|
|
88
|
+
const scrollLeft = document.documentElement.scrollLeft;
|
|
89
|
+
const windowWidth = window.innerWidth;
|
|
87
90
|
|
|
88
91
|
const isNearRightEdge = pageX > windowWidth - 20;
|
|
89
92
|
const isNearLeftEdge = pageX - scrollLeft < 20;
|
|
@@ -145,7 +148,7 @@ export default class DocumentScrollParent implements ScrollParent {
|
|
|
145
148
|
return "top";
|
|
146
149
|
}
|
|
147
150
|
|
|
148
|
-
const windowHeight =
|
|
151
|
+
const windowHeight = window.innerHeight;
|
|
149
152
|
|
|
150
153
|
if (windowHeight - (pageY - scrollTop) < 20 && this.canScrollDown()) {
|
|
151
154
|
return "bottom";
|
package/src/scrollHandler.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PositionInfo } from "./types";
|
|
1
|
+
import { PositionInfo } from "./mouseUtils";
|
|
3
2
|
import { ScrollParent } from "./scrollHandler/types";
|
|
4
3
|
import createScrollParent from "./scrollHandler/createScrollParent";
|
|
5
4
|
|
|
5
|
+
interface ScrollHandlerParams {
|
|
6
|
+
refreshHitAreas: () => void;
|
|
7
|
+
treeElement: HTMLElement;
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
export default class ScrollHandler {
|
|
7
|
-
private
|
|
11
|
+
private refreshHitAreas: () => void;
|
|
8
12
|
private scrollParent?: ScrollParent;
|
|
13
|
+
private treeElement: HTMLElement;
|
|
9
14
|
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
15
|
+
constructor({ refreshHitAreas, treeElement }: ScrollHandlerParams) {
|
|
16
|
+
this.refreshHitAreas = refreshHitAreas;
|
|
12
17
|
this.scrollParent = undefined;
|
|
18
|
+
this.treeElement = treeElement;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
public checkScrolling(positionInfo: PositionInfo): void {
|
|
@@ -30,26 +36,18 @@ export default class ScrollHandler {
|
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
private checkVerticalScrolling(positionInfo: PositionInfo): void {
|
|
33
|
-
if (positionInfo.pageY == null) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
39
|
this.getScrollParent().checkVerticalScrolling(positionInfo.pageY);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
private checkHorizontalScrolling(positionInfo: PositionInfo): void {
|
|
41
|
-
if (positionInfo.pageX == null) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
43
|
this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
private getScrollParent(): ScrollParent {
|
|
49
47
|
if (!this.scrollParent) {
|
|
50
48
|
this.scrollParent = createScrollParent(
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
49
|
+
this.treeElement,
|
|
50
|
+
this.refreshHitAreas,
|
|
53
51
|
);
|
|
54
52
|
}
|
|
55
53
|
|
package/src/selectNodeHandler.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Node } from "./node";
|
|
2
|
-
import {
|
|
2
|
+
import { GetNodeById } from "./jqtreeMethodTypes";
|
|
3
|
+
|
|
4
|
+
interface SelectNodeHandlerParameters {
|
|
5
|
+
getNodeById: GetNodeById;
|
|
6
|
+
}
|
|
3
7
|
|
|
4
8
|
export default class SelectNodeHandler {
|
|
5
|
-
private
|
|
9
|
+
private getNodeById: GetNodeById;
|
|
6
10
|
private selectedNodes: Set<NodeId>;
|
|
7
11
|
private selectedSingleNode: Node | null;
|
|
8
12
|
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
13
|
+
constructor({ getNodeById }: SelectNodeHandlerParameters) {
|
|
14
|
+
this.getNodeById = getNodeById;
|
|
11
15
|
this.selectedNodes = new Set<NodeId>();
|
|
12
16
|
this.clear();
|
|
13
17
|
}
|
|
@@ -29,7 +33,7 @@ export default class SelectNodeHandler {
|
|
|
29
33
|
const selectedNodes: Node[] = [];
|
|
30
34
|
|
|
31
35
|
this.selectedNodes.forEach((id) => {
|
|
32
|
-
const node = this.
|
|
36
|
+
const node = this.getNodeById(id);
|
|
33
37
|
if (node) {
|
|
34
38
|
selectedNodes.push(node);
|
|
35
39
|
}
|
|
@@ -53,7 +57,7 @@ export default class SelectNodeHandler {
|
|
|
53
57
|
if (
|
|
54
58
|
Object.prototype.hasOwnProperty.call(this.selectedNodes, id)
|
|
55
59
|
) {
|
|
56
|
-
const node = this.
|
|
60
|
+
const node = this.getNodeById(id);
|
|
57
61
|
if (node && parent.isParentOf(node)) {
|
|
58
62
|
selectedNodes.push(node);
|
|
59
63
|
}
|
|
@@ -108,14 +112,4 @@ export default class SelectNodeHandler {
|
|
|
108
112
|
this.selectedSingleNode = node;
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
|
-
|
|
112
|
-
public isFocusOnTree(): boolean {
|
|
113
|
-
const activeElement = document.activeElement;
|
|
114
|
-
|
|
115
|
-
return Boolean(
|
|
116
|
-
activeElement &&
|
|
117
|
-
activeElement.tagName === "SPAN" &&
|
|
118
|
-
this.treeWidget._containsElement(activeElement as HTMLElement)
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
115
|
}
|