jqtree 1.8.0 → 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/jest.config.js +4 -0
- package/config/jest.polyfills.js +14 -0
- package/devserver/test_index.html +9 -0
- package/docs/.ruby-version +1 -1
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +4 -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 +32 -30
- package/src/dataLoader.ts +19 -21
- package/src/dragAndDropHandler/dragElement.ts +37 -25
- package/src/dragAndDropHandler/generateHitAreas.ts +176 -0
- package/src/dragAndDropHandler/index.ts +32 -48
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
- package/src/dragAndDropHandler/types.ts +2 -1
- package/src/mouseHandler.ts +385 -0
- package/src/mouseUtils.ts +23 -0
- package/src/node.ts +1 -29
- package/src/nodeElement/folderElement.ts +1 -1
- package/src/nodeElement/ghostDropHint.ts +2 -1
- package/src/nodeElement/index.ts +2 -1
- package/src/playwright/coverage.ts +3 -3
- package/src/playwright/playwright.test.ts +150 -49
- package/src/playwright/testUtils.ts +28 -5
- package/src/position.ts +28 -0
- 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 +6 -14
- package/src/test/jqTree/events.test.ts +97 -30
- package/src/test/jqTree/loadOnDemand.test.ts +22 -15
- package/src/test/jqTree/methods.test.ts +8 -11
- package/src/test/jqTree/mouse.test.ts +82 -0
- package/src/test/jqTree/options.test.ts +9 -8
- package/src/test/node.test.ts +2 -1
- package/src/test/{nodeUtil.test.ts → position.test.ts} +1 -1
- package/src/tree.jquery.ts +108 -184
- package/src/util.ts +10 -1
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +2158 -2135
- 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/src/dragAndDropHandler/hitAreasGenerator.ts +0 -175
- package/src/dragAndDropHandler/visibleNodeIterator.ts +0 -97
- package/src/mouse.widget.ts +0 -266
- package/src/mouseWidgetTypes.ts +0 -6
package/src/tree.jquery.ts
CHANGED
|
@@ -3,24 +3,20 @@ import { DragAndDropHandler } from "./dragAndDropHandler";
|
|
|
3
3
|
import ElementsRenderer from "./elementsRenderer";
|
|
4
4
|
import DataLoader, { HandleFinishedLoading } from "./dataLoader";
|
|
5
5
|
import KeyHandler from "./keyHandler";
|
|
6
|
-
import
|
|
7
|
-
import { PositionInfo } from "./
|
|
6
|
+
import MouseHandler from "./mouseHandler";
|
|
7
|
+
import { PositionInfo } from "./mouseUtils";
|
|
8
8
|
import SaveStateHandler, { SavedState } from "./saveStateHandler";
|
|
9
9
|
import ScrollHandler from "./scrollHandler";
|
|
10
10
|
import SelectNodeHandler from "./selectNodeHandler";
|
|
11
11
|
import SimpleWidget from "./simple.widget";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { getOffsetTop, isFunction } from "./util";
|
|
13
|
+
import { Node } from "./node";
|
|
14
|
+
import { getPosition } from "./position";
|
|
14
15
|
import NodeElement from "./nodeElement";
|
|
15
16
|
import FolderElement from "./nodeElement/folderElement";
|
|
16
17
|
import { OnFinishOpenNode } from "./jqtreeMethodTypes";
|
|
17
18
|
import { JQTreeOptions } from "./jqtreeOptions";
|
|
18
19
|
|
|
19
|
-
interface ClickTarget {
|
|
20
|
-
node: Node;
|
|
21
|
-
type: "button" | "label";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
interface SelectNodeOptions {
|
|
25
21
|
mustToggle?: boolean;
|
|
26
22
|
mustSetFocus?: boolean;
|
|
@@ -29,7 +25,7 @@ interface SelectNodeOptions {
|
|
|
29
25
|
const NODE_PARAM_IS_EMPTY = "Node parameter is empty";
|
|
30
26
|
const PARAM_IS_EMPTY = "Parameter is empty: ";
|
|
31
27
|
|
|
32
|
-
export class JqTreeWidget extends
|
|
28
|
+
export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
33
29
|
protected static defaults: JQTreeOptions = {
|
|
34
30
|
animationSpeed: "fast",
|
|
35
31
|
autoEscape: true,
|
|
@@ -69,17 +65,18 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
69
65
|
useContextMenu: true,
|
|
70
66
|
};
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
public tree: Node;
|
|
74
|
-
public dndHandler: DragAndDropHandler;
|
|
75
|
-
public renderer: ElementsRenderer;
|
|
76
|
-
public dataLoader: DataLoader;
|
|
77
|
-
public scrollHandler: ScrollHandler;
|
|
78
|
-
public selectNodeHandler: SelectNodeHandler;
|
|
79
|
-
|
|
68
|
+
private element: JQuery;
|
|
80
69
|
private isInitialized: boolean;
|
|
81
|
-
private
|
|
70
|
+
private tree: Node;
|
|
71
|
+
|
|
72
|
+
private dataLoader: DataLoader;
|
|
73
|
+
private dndHandler: DragAndDropHandler;
|
|
82
74
|
private keyHandler: KeyHandler;
|
|
75
|
+
private mouseHandler: MouseHandler;
|
|
76
|
+
private renderer: ElementsRenderer;
|
|
77
|
+
private saveStateHandler: SaveStateHandler;
|
|
78
|
+
private scrollHandler: ScrollHandler;
|
|
79
|
+
private selectNodeHandler: SelectNodeHandler;
|
|
83
80
|
|
|
84
81
|
public toggle(node: Node, slideParam: null | boolean = null): JQuery {
|
|
85
82
|
if (!node) {
|
|
@@ -166,7 +163,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
public refresh(): JQuery {
|
|
169
|
-
this.
|
|
166
|
+
this.refreshElements(null);
|
|
170
167
|
return this.element;
|
|
171
168
|
}
|
|
172
169
|
|
|
@@ -235,7 +232,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
235
232
|
|
|
236
233
|
const [slide, onFinished] = parseParams();
|
|
237
234
|
|
|
238
|
-
this.
|
|
235
|
+
this.openNodeInternal(node, slide, onFinished);
|
|
239
236
|
return this.element;
|
|
240
237
|
}
|
|
241
238
|
|
|
@@ -274,7 +271,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
274
271
|
const newNode = existingNode.addAfter(newNodeInfo);
|
|
275
272
|
|
|
276
273
|
if (newNode) {
|
|
277
|
-
this.
|
|
274
|
+
this.refreshElements(existingNode.parent);
|
|
278
275
|
}
|
|
279
276
|
|
|
280
277
|
return newNode;
|
|
@@ -291,7 +288,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
291
288
|
const newNode = existingNode.addBefore(newNodeInfo);
|
|
292
289
|
|
|
293
290
|
if (newNode) {
|
|
294
|
-
this.
|
|
291
|
+
this.refreshElements(existingNode.parent);
|
|
295
292
|
}
|
|
296
293
|
|
|
297
294
|
return newNode;
|
|
@@ -308,7 +305,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
308
305
|
const newNode = existingNode.addParent(newNodeInfo);
|
|
309
306
|
|
|
310
307
|
if (newNode) {
|
|
311
|
-
this.
|
|
308
|
+
this.refreshElements(newNode.parent);
|
|
312
309
|
}
|
|
313
310
|
|
|
314
311
|
return newNode;
|
|
@@ -327,7 +324,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
327
324
|
|
|
328
325
|
const parent = node.parent;
|
|
329
326
|
node.remove();
|
|
330
|
-
this.
|
|
327
|
+
this.refreshElements(parent);
|
|
331
328
|
|
|
332
329
|
return this.element;
|
|
333
330
|
}
|
|
@@ -337,7 +334,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
337
334
|
|
|
338
335
|
const node = parentNode.append(newNodeInfo);
|
|
339
336
|
|
|
340
|
-
this.
|
|
337
|
+
this.refreshElements(parentNode);
|
|
341
338
|
|
|
342
339
|
return node;
|
|
343
340
|
}
|
|
@@ -347,7 +344,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
347
344
|
|
|
348
345
|
const node = parentNode.prepend(newNodeInfo);
|
|
349
346
|
|
|
350
|
-
this.
|
|
347
|
+
this.refreshElements(parentNode);
|
|
351
348
|
|
|
352
349
|
return node;
|
|
353
350
|
}
|
|
@@ -382,7 +379,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
382
379
|
}
|
|
383
380
|
}
|
|
384
381
|
|
|
385
|
-
this.
|
|
382
|
+
this.refreshElements(node);
|
|
386
383
|
|
|
387
384
|
return this.element;
|
|
388
385
|
}
|
|
@@ -410,7 +407,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
410
407
|
|
|
411
408
|
if (positionIndex !== undefined) {
|
|
412
409
|
this.tree.moveNode(node, targetNode, positionIndex);
|
|
413
|
-
this.
|
|
410
|
+
this.refreshElements(null);
|
|
414
411
|
}
|
|
415
412
|
|
|
416
413
|
return this.element;
|
|
@@ -428,7 +425,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
428
425
|
this.selectNodeHandler.addToSelection(node);
|
|
429
426
|
this.openParents(node);
|
|
430
427
|
|
|
431
|
-
this.
|
|
428
|
+
this.getNodeElementForNode(node).select(
|
|
432
429
|
mustSetFocus === undefined ? true : mustSetFocus,
|
|
433
430
|
);
|
|
434
431
|
|
|
@@ -456,7 +453,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
456
453
|
|
|
457
454
|
this.selectNodeHandler.removeFromSelection(node);
|
|
458
455
|
|
|
459
|
-
this.
|
|
456
|
+
this.getNodeElementForNode(node).deselect();
|
|
460
457
|
this.saveState();
|
|
461
458
|
|
|
462
459
|
return this.element;
|
|
@@ -467,9 +464,9 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
467
464
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
468
465
|
}
|
|
469
466
|
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
467
|
+
const top =
|
|
468
|
+
getOffsetTop(node.element) -
|
|
469
|
+
getOffsetTop(this.$el.get(0) as HTMLElement);
|
|
473
470
|
|
|
474
471
|
this.scrollHandler.scrollToY(top);
|
|
475
472
|
|
|
@@ -482,7 +479,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
482
479
|
|
|
483
480
|
public setState(state: SavedState): JQuery {
|
|
484
481
|
this.saveStateHandler.setInitialState(state);
|
|
485
|
-
this.
|
|
482
|
+
this.refreshElements(null);
|
|
486
483
|
|
|
487
484
|
return this.element;
|
|
488
485
|
}
|
|
@@ -514,16 +511,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
514
511
|
return __version__;
|
|
515
512
|
}
|
|
516
513
|
|
|
517
|
-
|
|
518
|
-
eventName: string,
|
|
519
|
-
values?: Record<string, unknown>,
|
|
520
|
-
): JQuery.Event {
|
|
521
|
-
const event = jQuery.Event(eventName, values);
|
|
522
|
-
this.element.trigger(event);
|
|
523
|
-
return event;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
public _openNode(
|
|
514
|
+
private openNodeInternal(
|
|
527
515
|
node: Node,
|
|
528
516
|
slide = true,
|
|
529
517
|
onFinished?: OnFinishOpenNode,
|
|
@@ -565,7 +553,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
565
553
|
Redraw the tree or part of the tree.
|
|
566
554
|
from_node: redraw this subtree
|
|
567
555
|
*/
|
|
568
|
-
|
|
556
|
+
private refreshElements(fromNode: Node | null): void {
|
|
569
557
|
const mustSetFocus = this.isFocusOnTree();
|
|
570
558
|
const mustSelect = fromNode
|
|
571
559
|
? this.isSelectedNodeInSubtree(fromNode)
|
|
@@ -577,10 +565,10 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
577
565
|
this.selectCurrentNode(mustSetFocus);
|
|
578
566
|
}
|
|
579
567
|
|
|
580
|
-
this.
|
|
568
|
+
this.triggerEvent("tree.refresh");
|
|
581
569
|
}
|
|
582
570
|
|
|
583
|
-
|
|
571
|
+
private getNodeElementForNode(node: Node): NodeElement {
|
|
584
572
|
if (node.isFolder()) {
|
|
585
573
|
return this.createFolderElement(node);
|
|
586
574
|
} else {
|
|
@@ -588,19 +576,15 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
588
576
|
}
|
|
589
577
|
}
|
|
590
578
|
|
|
591
|
-
|
|
579
|
+
private getNodeElement(element: HTMLElement): NodeElement | null {
|
|
592
580
|
const node = this.getNode(element);
|
|
593
581
|
if (node) {
|
|
594
|
-
return this.
|
|
582
|
+
return this.getNodeElementForNode(node);
|
|
595
583
|
} else {
|
|
596
584
|
return null;
|
|
597
585
|
}
|
|
598
586
|
}
|
|
599
587
|
|
|
600
|
-
public _getScrollLeft(): number {
|
|
601
|
-
return this.scrollHandler.getScrollLeft();
|
|
602
|
-
}
|
|
603
|
-
|
|
604
588
|
public init(): void {
|
|
605
589
|
super.init();
|
|
606
590
|
|
|
@@ -616,13 +600,6 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
616
600
|
this.connectHandlers();
|
|
617
601
|
|
|
618
602
|
this.initData();
|
|
619
|
-
|
|
620
|
-
this.element.on("click", this.handleClick);
|
|
621
|
-
this.element.on("dblclick", this.handleDblclick);
|
|
622
|
-
|
|
623
|
-
if (this.options.useContextMenu) {
|
|
624
|
-
this.element.on("contextmenu", this.handleContextmenu);
|
|
625
|
-
}
|
|
626
603
|
}
|
|
627
604
|
|
|
628
605
|
public deinit(): void {
|
|
@@ -630,13 +607,23 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
630
607
|
this.element.off();
|
|
631
608
|
|
|
632
609
|
this.keyHandler.deinit();
|
|
610
|
+
this.mouseHandler.deinit();
|
|
633
611
|
|
|
634
612
|
this.tree = new Node({}, true);
|
|
635
613
|
|
|
636
614
|
super.deinit();
|
|
637
615
|
}
|
|
638
616
|
|
|
639
|
-
|
|
617
|
+
private triggerEvent(
|
|
618
|
+
eventName: string,
|
|
619
|
+
values?: Record<string, unknown>,
|
|
620
|
+
): JQuery.Event {
|
|
621
|
+
const event = jQuery.Event(eventName, values);
|
|
622
|
+
this.element.trigger(event);
|
|
623
|
+
return event;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
private mouseCapture(positionInfo: PositionInfo): boolean | null {
|
|
640
627
|
if (this.options.dragAndDrop) {
|
|
641
628
|
return this.dndHandler.mouseCapture(positionInfo);
|
|
642
629
|
} else {
|
|
@@ -644,7 +631,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
644
631
|
}
|
|
645
632
|
}
|
|
646
633
|
|
|
647
|
-
|
|
634
|
+
private mouseStart(positionInfo: PositionInfo): boolean {
|
|
648
635
|
if (this.options.dragAndDrop) {
|
|
649
636
|
return this.dndHandler.mouseStart(positionInfo);
|
|
650
637
|
} else {
|
|
@@ -652,7 +639,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
652
639
|
}
|
|
653
640
|
}
|
|
654
641
|
|
|
655
|
-
|
|
642
|
+
private mouseDrag(positionInfo: PositionInfo): boolean {
|
|
656
643
|
if (this.options.dragAndDrop) {
|
|
657
644
|
const result = this.dndHandler.mouseDrag(positionInfo);
|
|
658
645
|
|
|
@@ -663,7 +650,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
663
650
|
}
|
|
664
651
|
}
|
|
665
652
|
|
|
666
|
-
|
|
653
|
+
private mouseStop(positionInfo: PositionInfo): boolean {
|
|
667
654
|
if (this.options.dragAndDrop) {
|
|
668
655
|
this.scrollHandler.stopScrolling();
|
|
669
656
|
return this.dndHandler.mouseStop(positionInfo);
|
|
@@ -672,10 +659,6 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
672
659
|
}
|
|
673
660
|
}
|
|
674
661
|
|
|
675
|
-
protected getMouseDelay(): number {
|
|
676
|
-
return this.options.startDndDelay ?? 0;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
662
|
private initData(): void {
|
|
680
663
|
if (this.options.data) {
|
|
681
664
|
this.doLoadData(this.options.data, null);
|
|
@@ -741,7 +724,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
741
724
|
const doInit = (): void => {
|
|
742
725
|
if (!this.isInitialized) {
|
|
743
726
|
this.isInitialized = true;
|
|
744
|
-
this.
|
|
727
|
+
this.triggerEvent("tree.init");
|
|
745
728
|
}
|
|
746
729
|
};
|
|
747
730
|
|
|
@@ -761,7 +744,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
761
744
|
|
|
762
745
|
const mustLoadOnDemand = this.setInitialState();
|
|
763
746
|
|
|
764
|
-
this.
|
|
747
|
+
this.refreshElements(null);
|
|
765
748
|
|
|
766
749
|
if (!mustLoadOnDemand) {
|
|
767
750
|
doInit();
|
|
@@ -854,7 +837,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
854
837
|
|
|
855
838
|
const loadAndOpenNode = (node: Node): void => {
|
|
856
839
|
loadingCount += 1;
|
|
857
|
-
this.
|
|
840
|
+
this.openNodeInternal(node, false, () => {
|
|
858
841
|
loadingCount -= 1;
|
|
859
842
|
openNodes();
|
|
860
843
|
});
|
|
@@ -869,7 +852,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
869
852
|
|
|
870
853
|
return false;
|
|
871
854
|
} else {
|
|
872
|
-
this.
|
|
855
|
+
this.openNodeInternal(node, false);
|
|
873
856
|
|
|
874
857
|
return level !== maxLevel;
|
|
875
858
|
}
|
|
@@ -900,73 +883,6 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
900
883
|
}
|
|
901
884
|
}
|
|
902
885
|
|
|
903
|
-
private handleClick = (
|
|
904
|
-
e: JQuery.ClickEvent<HTMLElement, any, HTMLElement, HTMLElement>,
|
|
905
|
-
): void => {
|
|
906
|
-
const clickTarget = this.getClickTarget(e.target);
|
|
907
|
-
|
|
908
|
-
if (clickTarget) {
|
|
909
|
-
if (clickTarget.type === "button") {
|
|
910
|
-
this.toggle(clickTarget.node, this.options.slide);
|
|
911
|
-
|
|
912
|
-
e.preventDefault();
|
|
913
|
-
e.stopPropagation();
|
|
914
|
-
} else if (clickTarget.type === "label") {
|
|
915
|
-
const node = clickTarget.node;
|
|
916
|
-
const event = this._triggerEvent("tree.click", {
|
|
917
|
-
node,
|
|
918
|
-
click_event: e,
|
|
919
|
-
});
|
|
920
|
-
|
|
921
|
-
if (!event.isDefaultPrevented()) {
|
|
922
|
-
this.doSelectNode(node);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
private handleDblclick = (
|
|
929
|
-
e: JQuery.DoubleClickEvent<HTMLElement, any, HTMLElement, HTMLElement>,
|
|
930
|
-
): void => {
|
|
931
|
-
const clickTarget = this.getClickTarget(e.target);
|
|
932
|
-
|
|
933
|
-
if (clickTarget?.type === "label") {
|
|
934
|
-
this._triggerEvent("tree.dblclick", {
|
|
935
|
-
node: clickTarget.node,
|
|
936
|
-
click_event: e,
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
|
|
941
|
-
private getClickTarget(element: HTMLElement): ClickTarget | null {
|
|
942
|
-
const button = element.closest(".jqtree-toggler");
|
|
943
|
-
|
|
944
|
-
if (button) {
|
|
945
|
-
const node = this.getNode(button as HTMLElement);
|
|
946
|
-
|
|
947
|
-
if (node) {
|
|
948
|
-
return {
|
|
949
|
-
type: "button",
|
|
950
|
-
node,
|
|
951
|
-
};
|
|
952
|
-
}
|
|
953
|
-
} else {
|
|
954
|
-
const jqTreeElement = element.closest(".jqtree-element");
|
|
955
|
-
|
|
956
|
-
if (jqTreeElement) {
|
|
957
|
-
const node = this.getNode(jqTreeElement as HTMLElement);
|
|
958
|
-
if (node) {
|
|
959
|
-
return {
|
|
960
|
-
type: "label",
|
|
961
|
-
node,
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
return null;
|
|
968
|
-
}
|
|
969
|
-
|
|
970
886
|
private getNode(element: HTMLElement): null | Node {
|
|
971
887
|
const liElement = element.closest("li.jqtree_common");
|
|
972
888
|
|
|
@@ -977,28 +893,6 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
977
893
|
}
|
|
978
894
|
}
|
|
979
895
|
|
|
980
|
-
private handleContextmenu = (
|
|
981
|
-
e: JQuery.ContextMenuEvent<HTMLElement, any, HTMLElement, HTMLElement>,
|
|
982
|
-
) => {
|
|
983
|
-
const div = e.target.closest("ul.jqtree-tree .jqtree-element");
|
|
984
|
-
|
|
985
|
-
if (div) {
|
|
986
|
-
const node = this.getNode(div as HTMLElement);
|
|
987
|
-
if (node) {
|
|
988
|
-
e.preventDefault();
|
|
989
|
-
e.stopPropagation();
|
|
990
|
-
|
|
991
|
-
this._triggerEvent("tree.contextmenu", {
|
|
992
|
-
node,
|
|
993
|
-
click_event: e,
|
|
994
|
-
});
|
|
995
|
-
return false;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
return null;
|
|
1000
|
-
};
|
|
1001
|
-
|
|
1002
896
|
private saveState(): void {
|
|
1003
897
|
if (this.options.saveState) {
|
|
1004
898
|
this.saveStateHandler.saveState();
|
|
@@ -1008,7 +902,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1008
902
|
private selectCurrentNode(mustSetFocus: boolean): void {
|
|
1009
903
|
const node = this.getSelectedNode();
|
|
1010
904
|
if (node) {
|
|
1011
|
-
const nodeElement = this.
|
|
905
|
+
const nodeElement = this.getNodeElementForNode(node);
|
|
1012
906
|
if (nodeElement) {
|
|
1013
907
|
nodeElement.select(mustSetFocus);
|
|
1014
908
|
}
|
|
@@ -1087,7 +981,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1087
981
|
if (this.selectNodeHandler.isNodeSelected(node)) {
|
|
1088
982
|
if (selectOptions.mustToggle) {
|
|
1089
983
|
this.deselectCurrentNode();
|
|
1090
|
-
this.
|
|
984
|
+
this.triggerEvent("tree.select", {
|
|
1091
985
|
node: null,
|
|
1092
986
|
previous_node: node,
|
|
1093
987
|
});
|
|
@@ -1097,7 +991,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1097
991
|
this.deselectCurrentNode();
|
|
1098
992
|
this.addToSelection(node, selectOptions.mustSetFocus);
|
|
1099
993
|
|
|
1100
|
-
this.
|
|
994
|
+
this.triggerEvent("tree.select", {
|
|
1101
995
|
node,
|
|
1102
996
|
deselected_node: deselectedNode,
|
|
1103
997
|
});
|
|
@@ -1121,7 +1015,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1121
1015
|
}
|
|
1122
1016
|
}
|
|
1123
1017
|
|
|
1124
|
-
this.
|
|
1018
|
+
this.triggerEvent("tree.load_data", {
|
|
1125
1019
|
tree_data: data,
|
|
1126
1020
|
parent_node: parentNode,
|
|
1127
1021
|
});
|
|
@@ -1141,7 +1035,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1141
1035
|
parentNode.load_on_demand = false;
|
|
1142
1036
|
parentNode.is_loading = false;
|
|
1143
1037
|
|
|
1144
|
-
this.
|
|
1038
|
+
this.refreshElements(parentNode);
|
|
1145
1039
|
}
|
|
1146
1040
|
|
|
1147
1041
|
private doLoadDataFromUrl(
|
|
@@ -1162,7 +1056,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1162
1056
|
node.is_loading = true;
|
|
1163
1057
|
|
|
1164
1058
|
this.doLoadDataFromUrl(null, node, () => {
|
|
1165
|
-
this.
|
|
1059
|
+
this.openNodeInternal(node, slide, onFinished);
|
|
1166
1060
|
});
|
|
1167
1061
|
}
|
|
1168
1062
|
|
|
@@ -1191,6 +1085,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1191
1085
|
dragAndDrop,
|
|
1192
1086
|
keyboardSupport,
|
|
1193
1087
|
onCanMove,
|
|
1088
|
+
onCanMoveTo,
|
|
1194
1089
|
onCreateLi,
|
|
1195
1090
|
onDragMove,
|
|
1196
1091
|
onDragStop,
|
|
@@ -1209,20 +1104,20 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1209
1104
|
} = this.options;
|
|
1210
1105
|
|
|
1211
1106
|
const closeNode = this.closeNode.bind(this);
|
|
1212
|
-
const getNodeElement = this.
|
|
1213
|
-
const getNodeElementForNode = this.
|
|
1107
|
+
const getNodeElement = this.getNodeElement.bind(this);
|
|
1108
|
+
const getNodeElementForNode = this.getNodeElementForNode.bind(this);
|
|
1214
1109
|
const getNodeById = this.getNodeById.bind(this);
|
|
1215
|
-
const getScrollLeft = this._getScrollLeft.bind(this);
|
|
1216
1110
|
const getSelectedNode = this.getSelectedNode.bind(this);
|
|
1217
1111
|
const getTree = this.getTree.bind(this);
|
|
1218
1112
|
const isFocusOnTree = this.isFocusOnTree.bind(this);
|
|
1219
1113
|
const loadData = this.loadData.bind(this);
|
|
1220
|
-
const openNode = this.
|
|
1221
|
-
const refreshElements = this.
|
|
1114
|
+
const openNode = this.openNodeInternal.bind(this);
|
|
1115
|
+
const refreshElements = this.refreshElements.bind(this);
|
|
1222
1116
|
const refreshHitAreas = this.refreshHitAreas.bind(this);
|
|
1223
1117
|
const selectNode = this.selectNode.bind(this);
|
|
1224
1118
|
const $treeElement = this.element;
|
|
1225
|
-
const
|
|
1119
|
+
const treeElement = this.element.get(0) as HTMLElement;
|
|
1120
|
+
const triggerEvent = this.triggerEvent.bind(this);
|
|
1226
1121
|
|
|
1227
1122
|
const selectNodeHandler = new SelectNodeHandler({
|
|
1228
1123
|
getNodeById,
|
|
@@ -1236,13 +1131,14 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1236
1131
|
selectNodeHandler.isNodeSelected.bind(selectNodeHandler);
|
|
1237
1132
|
const removeFromSelection =
|
|
1238
1133
|
selectNodeHandler.removeFromSelection.bind(selectNodeHandler);
|
|
1134
|
+
const getMouseDelay = () => this.options.startDndDelay ?? 0;
|
|
1239
1135
|
|
|
1240
1136
|
const dataLoader = new DataLoader({
|
|
1241
1137
|
dataFilter,
|
|
1242
1138
|
loadData,
|
|
1243
1139
|
onLoadFailed,
|
|
1244
1140
|
onLoading,
|
|
1245
|
-
|
|
1141
|
+
treeElement,
|
|
1246
1142
|
triggerEvent,
|
|
1247
1143
|
});
|
|
1248
1144
|
|
|
@@ -1259,6 +1155,13 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1259
1155
|
saveState,
|
|
1260
1156
|
});
|
|
1261
1157
|
|
|
1158
|
+
const scrollHandler = new ScrollHandler({
|
|
1159
|
+
refreshHitAreas,
|
|
1160
|
+
treeElement,
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
const getScrollLeft = scrollHandler.getScrollLeft.bind(scrollHandler);
|
|
1164
|
+
|
|
1262
1165
|
const dndHandler = new DragAndDropHandler({
|
|
1263
1166
|
autoEscape,
|
|
1264
1167
|
getNodeElement,
|
|
@@ -1266,6 +1169,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1266
1169
|
getScrollLeft,
|
|
1267
1170
|
getTree,
|
|
1268
1171
|
onCanMove,
|
|
1172
|
+
onCanMoveTo,
|
|
1269
1173
|
onDragMove,
|
|
1270
1174
|
onDragStop,
|
|
1271
1175
|
onIsMoveHandle,
|
|
@@ -1273,15 +1177,10 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1273
1177
|
openNode,
|
|
1274
1178
|
refreshElements,
|
|
1275
1179
|
slide,
|
|
1276
|
-
|
|
1180
|
+
treeElement,
|
|
1277
1181
|
triggerEvent,
|
|
1278
1182
|
});
|
|
1279
1183
|
|
|
1280
|
-
const scrollHandler = new ScrollHandler({
|
|
1281
|
-
refreshHitAreas,
|
|
1282
|
-
$treeElement,
|
|
1283
|
-
});
|
|
1284
|
-
|
|
1285
1184
|
const keyHandler = new KeyHandler({
|
|
1286
1185
|
closeNode,
|
|
1287
1186
|
getSelectedNode,
|
|
@@ -1306,9 +1205,30 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1306
1205
|
tabIndex,
|
|
1307
1206
|
});
|
|
1308
1207
|
|
|
1208
|
+
const getNode = this.getNode.bind(this);
|
|
1209
|
+
const onMouseCapture = this.mouseCapture.bind(this);
|
|
1210
|
+
const onMouseDrag = this.mouseDrag.bind(this);
|
|
1211
|
+
const onMouseStart = this.mouseStart.bind(this);
|
|
1212
|
+
const onMouseStop = this.mouseStop.bind(this);
|
|
1213
|
+
|
|
1214
|
+
const mouseHandler = new MouseHandler({
|
|
1215
|
+
element: treeElement,
|
|
1216
|
+
getMouseDelay,
|
|
1217
|
+
getNode,
|
|
1218
|
+
onClickButton: this.toggle.bind(this),
|
|
1219
|
+
onClickTitle: this.doSelectNode.bind(this),
|
|
1220
|
+
onMouseCapture,
|
|
1221
|
+
onMouseDrag,
|
|
1222
|
+
onMouseStart,
|
|
1223
|
+
onMouseStop,
|
|
1224
|
+
triggerEvent,
|
|
1225
|
+
useContextMenu: this.options.useContextMenu,
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1309
1228
|
this.dataLoader = dataLoader;
|
|
1310
1229
|
this.dndHandler = dndHandler;
|
|
1311
1230
|
this.keyHandler = keyHandler;
|
|
1231
|
+
this.mouseHandler = mouseHandler;
|
|
1312
1232
|
this.renderer = renderer;
|
|
1313
1233
|
this.saveStateHandler = saveStateHandler;
|
|
1314
1234
|
this.scrollHandler = scrollHandler;
|
|
@@ -1317,11 +1237,13 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1317
1237
|
|
|
1318
1238
|
private createFolderElement(node: Node) {
|
|
1319
1239
|
const closedIconElement = this.renderer.closedIconElement;
|
|
1320
|
-
const getScrollLeft = this.
|
|
1240
|
+
const getScrollLeft = this.scrollHandler.getScrollLeft.bind(
|
|
1241
|
+
this.scrollHandler,
|
|
1242
|
+
);
|
|
1321
1243
|
const openedIconElement = this.renderer.openedIconElement;
|
|
1322
1244
|
const tabIndex = this.options.tabIndex;
|
|
1323
1245
|
const $treeElement = this.element;
|
|
1324
|
-
const triggerEvent = this.
|
|
1246
|
+
const triggerEvent = this.triggerEvent.bind(this);
|
|
1325
1247
|
|
|
1326
1248
|
return new FolderElement({
|
|
1327
1249
|
closedIconElement,
|
|
@@ -1335,7 +1257,9 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
|
|
|
1335
1257
|
}
|
|
1336
1258
|
|
|
1337
1259
|
private createNodeElement(node: Node) {
|
|
1338
|
-
const getScrollLeft = this.
|
|
1260
|
+
const getScrollLeft = this.scrollHandler.getScrollLeft.bind(
|
|
1261
|
+
this.scrollHandler,
|
|
1262
|
+
);
|
|
1339
1263
|
const tabIndex = this.options.tabIndex;
|
|
1340
1264
|
const $treeElement = this.element;
|
|
1341
1265
|
|
package/src/util.ts
CHANGED
|
@@ -7,4 +7,13 @@ export const getBoolString = (value: unknown): string =>
|
|
|
7
7
|
value ? "true" : "false";
|
|
8
8
|
|
|
9
9
|
export const getOffsetTop = (element: HTMLElement) =>
|
|
10
|
-
element
|
|
10
|
+
getElementPosition(element).top;
|
|
11
|
+
|
|
12
|
+
export const getElementPosition = (element: HTMLElement) => {
|
|
13
|
+
const rect = element.getBoundingClientRect();
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
left: rect.x + window.scrollX,
|
|
17
|
+
top: rect.y + window.scrollY,
|
|
18
|
+
};
|
|
19
|
+
};
|
package/src/version.ts
CHANGED