jqtree 1.8.10 → 1.9.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.
- package/bower.json +3 -10
- package/eslint.config.mjs +47 -9
- package/package.json +50 -53
- package/pnpm-workspace.yaml +4 -0
- package/src/animation.ts +48 -0
- package/src/dataLoader.ts +38 -48
- package/src/dragAndDropHandler/dragElement.ts +11 -11
- package/src/dragAndDropHandler/generateHitAreas.ts +4 -3
- package/src/dragAndDropHandler/index.ts +119 -120
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +1 -1
- package/src/dragAndDropHandler/types.ts +1 -1
- package/src/elementsRenderer.ts +71 -78
- package/src/jqtreeMethodTypes.ts +2 -2
- package/src/jqtreeOptions.ts +3 -2
- package/src/keyHandler.ts +34 -34
- package/src/mouseHandler.ts +125 -123
- package/src/node.ts +23 -27
- package/src/nodeElement/borderDropHint.ts +6 -6
- package/src/nodeElement/folderElement.ts +30 -22
- package/src/nodeElement/ghostDropHint.ts +24 -24
- package/src/nodeElement/index.ts +13 -14
- package/src/positionUtils.ts +18 -0
- package/src/saveStateHandler.ts +56 -55
- package/src/scrollHandler/containerScrollParent.ts +27 -124
- package/src/scrollHandler/createScrollParent.ts +1 -1
- package/src/scrollHandler/documentScrollParent.ts +43 -125
- package/src/scrollHandler/scrollParent.ts +117 -0
- package/src/scrollHandler.ts +24 -25
- package/src/selectNodeHandler.ts +28 -28
- package/src/simple.widget.ts +1 -3
- package/src/tree.jquery.ts +253 -279
- package/src/util.ts +0 -14
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +1044 -998
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +3 -3
- package/tree.jquery.js.map +1 -1
- package/.tool-versions +0 -2
- package/src/scrollHandler/types.ts +0 -7
package/tree.jquery.debug.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
JqTree 1.
|
|
2
|
+
JqTree 1.9.0
|
|
3
3
|
|
|
4
|
-
Copyright
|
|
4
|
+
Copyright 2026 Marco Braak
|
|
5
5
|
|
|
6
6
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
you may not use this file except in compliance with the License.
|
|
@@ -21,88 +21,85 @@ var jqtree = (function (exports) {
|
|
|
21
21
|
'use strict';
|
|
22
22
|
|
|
23
23
|
class DataLoader {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.
|
|
24
|
+
_dataFilter;
|
|
25
|
+
_loadData;
|
|
26
|
+
_onLoadFailed;
|
|
27
|
+
_onLoading;
|
|
28
|
+
_treeElement;
|
|
29
|
+
_triggerEvent;
|
|
30
|
+
constructor({
|
|
31
|
+
dataFilter,
|
|
32
|
+
loadData,
|
|
33
|
+
onLoadFailed,
|
|
34
|
+
onLoading,
|
|
35
|
+
treeElement,
|
|
36
|
+
triggerEvent
|
|
37
|
+
}) {
|
|
38
|
+
this._dataFilter = dataFilter;
|
|
39
|
+
this._loadData = loadData;
|
|
40
|
+
this._onLoadFailed = onLoadFailed;
|
|
41
|
+
this._onLoading = onLoading;
|
|
42
|
+
this._treeElement = treeElement;
|
|
43
|
+
this._triggerEvent = triggerEvent;
|
|
39
44
|
}
|
|
40
45
|
loadFromUrl(urlInfo, parentNode, onFinished) {
|
|
41
46
|
if (!urlInfo) {
|
|
42
47
|
return;
|
|
43
48
|
}
|
|
44
|
-
const element = this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
49
|
+
const element = this._getDomElement(parentNode);
|
|
50
|
+
this._addLoadingClass(element);
|
|
51
|
+
this._notifyLoading(true, parentNode, element);
|
|
47
52
|
const stopLoading = () => {
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
53
|
+
this._removeLoadingClass(element);
|
|
54
|
+
this._notifyLoading(false, parentNode, element);
|
|
50
55
|
};
|
|
51
56
|
const handleSuccess = data => {
|
|
52
57
|
stopLoading();
|
|
53
|
-
this.
|
|
58
|
+
this._loadData(this._parseData(data), parentNode);
|
|
54
59
|
if (onFinished && typeof onFinished === "function") {
|
|
55
60
|
onFinished();
|
|
56
61
|
}
|
|
57
62
|
};
|
|
58
63
|
const handleError = jqXHR => {
|
|
59
64
|
stopLoading();
|
|
60
|
-
if (this.
|
|
61
|
-
this.
|
|
65
|
+
if (this._onLoadFailed) {
|
|
66
|
+
this._onLoadFailed(jqXHR);
|
|
62
67
|
}
|
|
63
68
|
};
|
|
64
|
-
this.
|
|
69
|
+
this._submitRequest(urlInfo, handleSuccess, handleError);
|
|
65
70
|
}
|
|
66
|
-
|
|
71
|
+
_addLoadingClass(element) {
|
|
67
72
|
element.classList.add("jqtree-loading");
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
_getDomElement(parentNode) {
|
|
70
75
|
if (parentNode?.element) {
|
|
71
76
|
return parentNode.element;
|
|
72
77
|
} else {
|
|
73
|
-
return this.
|
|
78
|
+
return this._treeElement;
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
|
-
|
|
81
|
+
_notifyLoading(isLoading, node, element) {
|
|
77
82
|
const $el = jQuery(element);
|
|
78
|
-
if (this.
|
|
79
|
-
this.
|
|
83
|
+
if (this._onLoading) {
|
|
84
|
+
this._onLoading(isLoading, node, $el);
|
|
80
85
|
}
|
|
81
|
-
this.
|
|
86
|
+
this._triggerEvent("tree.loading_data", {
|
|
82
87
|
$el,
|
|
83
88
|
isLoading,
|
|
84
89
|
node
|
|
85
90
|
});
|
|
86
91
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return JSON.parse(data);
|
|
91
|
-
} else {
|
|
92
|
-
return data;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const parsedData = getParsedData();
|
|
96
|
-
if (this.dataFilter) {
|
|
97
|
-
return this.dataFilter(parsedData);
|
|
92
|
+
_parseData(data) {
|
|
93
|
+
if (this._dataFilter) {
|
|
94
|
+
return this._dataFilter(data);
|
|
98
95
|
} else {
|
|
99
|
-
return
|
|
96
|
+
return data;
|
|
100
97
|
}
|
|
101
98
|
}
|
|
102
|
-
|
|
99
|
+
_removeLoadingClass(element) {
|
|
103
100
|
element.classList.remove("jqtree-loading");
|
|
104
101
|
}
|
|
105
|
-
|
|
102
|
+
_submitRequest(urlInfoInput, handleSuccess, handleError) {
|
|
106
103
|
const urlInfo = typeof urlInfoInput === "string" ? {
|
|
107
104
|
url: urlInfoInput
|
|
108
105
|
} : urlInfoInput;
|
|
@@ -119,10 +116,10 @@ var jqtree = (function (exports) {
|
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
118
|
|
|
122
|
-
|
|
123
|
-
const isFunction = v => typeof v === "function";
|
|
124
|
-
const getBoolString = value => value ? "true" : "false";
|
|
119
|
+
// Get the top position of the HTML element.
|
|
125
120
|
const getOffsetTop = element => getElementPosition(element).top;
|
|
121
|
+
|
|
122
|
+
// Get the top left position of the HTML element.
|
|
126
123
|
const getElementPosition = element => {
|
|
127
124
|
const rect = element.getBoundingClientRect();
|
|
128
125
|
return {
|
|
@@ -153,27 +150,29 @@ var jqtree = (function (exports) {
|
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
class DragElement {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
|
|
153
|
+
_element;
|
|
154
|
+
_offsetX;
|
|
155
|
+
_offsetY;
|
|
156
|
+
constructor({
|
|
157
|
+
autoEscape,
|
|
158
|
+
nodeName,
|
|
159
|
+
offsetX,
|
|
160
|
+
offsetY,
|
|
161
|
+
treeElement
|
|
162
|
+
}) {
|
|
163
|
+
this._offsetX = offsetX;
|
|
164
|
+
this._offsetY = offsetY;
|
|
165
|
+
this._element = this._createElement(nodeName, autoEscape);
|
|
166
|
+
treeElement.appendChild(this._element);
|
|
168
167
|
}
|
|
169
168
|
move(pageX, pageY) {
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
169
|
+
this._element.style.left = `${pageX - this._offsetX}px`;
|
|
170
|
+
this._element.style.top = `${pageY - this._offsetY}px`;
|
|
172
171
|
}
|
|
173
172
|
remove() {
|
|
174
|
-
this.
|
|
173
|
+
this._element.remove();
|
|
175
174
|
}
|
|
176
|
-
|
|
175
|
+
_createElement(nodeName, autoEscape) {
|
|
177
176
|
const element = document.createElement("span");
|
|
178
177
|
element.classList.add("jqtree-title", "jqtree-dragging");
|
|
179
178
|
if (autoEscape) {
|
|
@@ -186,14 +185,13 @@ var jqtree = (function (exports) {
|
|
|
186
185
|
}
|
|
187
186
|
}
|
|
188
187
|
|
|
189
|
-
const iterateVisibleNodes = (tree,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} = _ref;
|
|
188
|
+
const iterateVisibleNodes = (tree, {
|
|
189
|
+
handleAfterOpenFolder,
|
|
190
|
+
handleClosedFolder,
|
|
191
|
+
handleFirstNode,
|
|
192
|
+
handleNode,
|
|
193
|
+
handleOpenFolder
|
|
194
|
+
}) => {
|
|
197
195
|
let isFirstNode = true;
|
|
198
196
|
const iterate = (node, nextNode) => {
|
|
199
197
|
let mustIterateInside = (node.is_open || !node.element) && node.hasChildren();
|
|
@@ -365,41 +363,63 @@ var jqtree = (function (exports) {
|
|
|
365
363
|
const generateHitAreas = (tree, currentNode, treeBottom) => generateHitAreasFromPositions(generateHitPositions(tree, currentNode), treeBottom);
|
|
366
364
|
|
|
367
365
|
class DragAndDropHandler {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
366
|
+
currentItem;
|
|
367
|
+
hitAreas;
|
|
368
|
+
hoveredArea;
|
|
369
|
+
isDragging;
|
|
370
|
+
_autoEscape;
|
|
371
|
+
_dragElement;
|
|
372
|
+
_getNodeElement;
|
|
373
|
+
_getNodeElementForNode;
|
|
374
|
+
_getScrollLeft;
|
|
375
|
+
_getTree;
|
|
376
|
+
_onCanMove;
|
|
377
|
+
_onCanMoveTo;
|
|
378
|
+
_onDragMove;
|
|
379
|
+
_onDragStop;
|
|
380
|
+
_onIsMoveHandle;
|
|
381
|
+
_openFolderDelay;
|
|
382
|
+
_openFolderTimer;
|
|
383
|
+
_openNode;
|
|
384
|
+
_previousGhost;
|
|
385
|
+
_refreshElements;
|
|
386
|
+
_slide;
|
|
387
|
+
_treeElement;
|
|
388
|
+
_triggerEvent;
|
|
389
|
+
constructor({
|
|
390
|
+
autoEscape,
|
|
391
|
+
getNodeElement,
|
|
392
|
+
getNodeElementForNode,
|
|
393
|
+
getScrollLeft,
|
|
394
|
+
getTree,
|
|
395
|
+
onCanMove,
|
|
396
|
+
onCanMoveTo,
|
|
397
|
+
onDragMove,
|
|
398
|
+
onDragStop,
|
|
399
|
+
onIsMoveHandle,
|
|
400
|
+
openFolderDelay,
|
|
401
|
+
openNode,
|
|
402
|
+
refreshElements,
|
|
403
|
+
slide,
|
|
404
|
+
treeElement,
|
|
405
|
+
triggerEvent
|
|
406
|
+
}) {
|
|
407
|
+
this._autoEscape = autoEscape;
|
|
408
|
+
this._getNodeElement = getNodeElement;
|
|
409
|
+
this._getNodeElementForNode = getNodeElementForNode;
|
|
410
|
+
this._getScrollLeft = getScrollLeft;
|
|
411
|
+
this._getTree = getTree;
|
|
412
|
+
this._onCanMove = onCanMove;
|
|
413
|
+
this._onCanMoveTo = onCanMoveTo;
|
|
414
|
+
this._onDragMove = onDragMove;
|
|
415
|
+
this._onDragStop = onDragStop;
|
|
416
|
+
this._onIsMoveHandle = onIsMoveHandle;
|
|
417
|
+
this._openFolderDelay = openFolderDelay;
|
|
418
|
+
this._openNode = openNode;
|
|
419
|
+
this._refreshElements = refreshElements;
|
|
420
|
+
this._slide = slide;
|
|
421
|
+
this._treeElement = treeElement;
|
|
422
|
+
this._triggerEvent = triggerEvent;
|
|
403
423
|
this.hoveredArea = null;
|
|
404
424
|
this.hitAreas = [];
|
|
405
425
|
this.isDragging = false;
|
|
@@ -407,15 +427,15 @@ var jqtree = (function (exports) {
|
|
|
407
427
|
}
|
|
408
428
|
mouseCapture(positionInfo) {
|
|
409
429
|
const element = positionInfo.target;
|
|
410
|
-
if (!this.
|
|
430
|
+
if (!this._mustCaptureElement(element)) {
|
|
411
431
|
return null;
|
|
412
432
|
}
|
|
413
|
-
if (this.
|
|
433
|
+
if (this._onIsMoveHandle && !this._onIsMoveHandle(jQuery(element))) {
|
|
414
434
|
return null;
|
|
415
435
|
}
|
|
416
|
-
let nodeElement = this.
|
|
417
|
-
if (nodeElement && this.
|
|
418
|
-
if (!this.
|
|
436
|
+
let nodeElement = this._getNodeElement(element);
|
|
437
|
+
if (nodeElement && this._onCanMove) {
|
|
438
|
+
if (!this._onCanMove(nodeElement.node)) {
|
|
419
439
|
nodeElement = null;
|
|
420
440
|
}
|
|
421
441
|
}
|
|
@@ -423,34 +443,34 @@ var jqtree = (function (exports) {
|
|
|
423
443
|
return this.currentItem != null;
|
|
424
444
|
}
|
|
425
445
|
mouseDrag(positionInfo) {
|
|
426
|
-
if (!this.currentItem || !this.
|
|
446
|
+
if (!this.currentItem || !this._dragElement) {
|
|
427
447
|
return false;
|
|
428
448
|
}
|
|
429
|
-
this.
|
|
430
|
-
const area = this.
|
|
431
|
-
if (area && this.
|
|
449
|
+
this._dragElement.move(positionInfo.pageX, positionInfo.pageY);
|
|
450
|
+
const area = this._findHoveredArea(positionInfo.pageX, positionInfo.pageY);
|
|
451
|
+
if (area && this._canMoveToArea(area, this.currentItem)) {
|
|
432
452
|
if (!area.node.isFolder()) {
|
|
433
|
-
this.
|
|
453
|
+
this._stopOpenFolderTimer();
|
|
434
454
|
}
|
|
435
455
|
if (this.hoveredArea !== area) {
|
|
436
456
|
this.hoveredArea = area;
|
|
437
457
|
|
|
438
458
|
// If this is a closed folder, start timer to open it
|
|
439
|
-
if (this.
|
|
440
|
-
this.
|
|
459
|
+
if (this._mustOpenFolderTimer(area)) {
|
|
460
|
+
this._startOpenFolderTimer(area.node);
|
|
441
461
|
} else {
|
|
442
|
-
this.
|
|
462
|
+
this._stopOpenFolderTimer();
|
|
443
463
|
}
|
|
444
|
-
this.
|
|
464
|
+
this._updateDropHint();
|
|
445
465
|
}
|
|
446
466
|
} else {
|
|
447
|
-
this.
|
|
448
|
-
this.
|
|
467
|
+
this._removeDropHint();
|
|
468
|
+
this._stopOpenFolderTimer();
|
|
449
469
|
this.hoveredArea = area;
|
|
450
470
|
}
|
|
451
471
|
if (!area) {
|
|
452
|
-
if (this.
|
|
453
|
-
this.
|
|
472
|
+
if (this._onDragMove) {
|
|
473
|
+
this._onDragMove(this.currentItem.node, positionInfo.originalEvent);
|
|
454
474
|
}
|
|
455
475
|
}
|
|
456
476
|
return true;
|
|
@@ -465,23 +485,23 @@ var jqtree = (function (exports) {
|
|
|
465
485
|
top
|
|
466
486
|
} = getElementPosition(positionInfo.target);
|
|
467
487
|
const node = this.currentItem.node;
|
|
468
|
-
this.
|
|
469
|
-
autoEscape: this.
|
|
488
|
+
this._dragElement = new DragElement({
|
|
489
|
+
autoEscape: this._autoEscape ?? true,
|
|
470
490
|
nodeName: node.name,
|
|
471
491
|
offsetX: positionInfo.pageX - left,
|
|
472
492
|
offsetY: positionInfo.pageY - top,
|
|
473
|
-
treeElement: this.
|
|
493
|
+
treeElement: this._treeElement
|
|
474
494
|
});
|
|
475
495
|
this.isDragging = true;
|
|
476
496
|
this.currentItem.element.classList.add("jqtree-moving");
|
|
477
497
|
return true;
|
|
478
498
|
}
|
|
479
499
|
mouseStop(positionInfo) {
|
|
480
|
-
this.
|
|
481
|
-
this.
|
|
482
|
-
this.
|
|
483
|
-
this.
|
|
484
|
-
this.
|
|
500
|
+
this._moveItem(positionInfo);
|
|
501
|
+
this._clear();
|
|
502
|
+
this._removeHover();
|
|
503
|
+
this._removeDropHint();
|
|
504
|
+
this._removeHitAreas();
|
|
485
505
|
const currentItem = this.currentItem;
|
|
486
506
|
if (this.currentItem) {
|
|
487
507
|
this.currentItem.element.classList.remove("jqtree-moving");
|
|
@@ -489,37 +509,37 @@ var jqtree = (function (exports) {
|
|
|
489
509
|
}
|
|
490
510
|
this.isDragging = false;
|
|
491
511
|
if (!this.hoveredArea && currentItem) {
|
|
492
|
-
if (this.
|
|
493
|
-
this.
|
|
512
|
+
if (this._onDragStop) {
|
|
513
|
+
this._onDragStop(currentItem.node, positionInfo.originalEvent);
|
|
494
514
|
}
|
|
495
515
|
}
|
|
496
516
|
return false;
|
|
497
517
|
}
|
|
498
518
|
refresh() {
|
|
499
|
-
this.
|
|
519
|
+
this._removeHitAreas();
|
|
500
520
|
if (this.currentItem) {
|
|
501
521
|
const currentNode = this.currentItem.node;
|
|
502
|
-
this.
|
|
503
|
-
this.currentItem = this.
|
|
522
|
+
this._generateHitAreas(currentNode);
|
|
523
|
+
this.currentItem = this._getNodeElementForNode(currentNode);
|
|
504
524
|
if (this.isDragging) {
|
|
505
525
|
this.currentItem.element.classList.add("jqtree-moving");
|
|
506
526
|
}
|
|
507
527
|
}
|
|
508
528
|
}
|
|
509
|
-
|
|
510
|
-
if (!this.
|
|
529
|
+
_canMoveToArea(area, currentItem) {
|
|
530
|
+
if (!this._onCanMoveTo) {
|
|
511
531
|
return true;
|
|
512
532
|
}
|
|
513
|
-
return this.
|
|
533
|
+
return this._onCanMoveTo(currentItem.node, area.node, area.position);
|
|
514
534
|
}
|
|
515
|
-
|
|
516
|
-
if (this.
|
|
517
|
-
this.
|
|
518
|
-
this.
|
|
535
|
+
_clear() {
|
|
536
|
+
if (this._dragElement) {
|
|
537
|
+
this._dragElement.remove();
|
|
538
|
+
this._dragElement = null;
|
|
519
539
|
}
|
|
520
540
|
}
|
|
521
|
-
|
|
522
|
-
const dimensions = this.
|
|
541
|
+
_findHoveredArea(x, y) {
|
|
542
|
+
const dimensions = this._getTreeDimensions();
|
|
523
543
|
if (x < dimensions.left || y < dimensions.top || x > dimensions.right || y > dimensions.bottom) {
|
|
524
544
|
return null;
|
|
525
545
|
}
|
|
@@ -533,31 +553,31 @@ var jqtree = (function (exports) {
|
|
|
533
553
|
}
|
|
534
554
|
});
|
|
535
555
|
}
|
|
536
|
-
|
|
537
|
-
const tree = this.
|
|
556
|
+
_generateHitAreas(currentNode) {
|
|
557
|
+
const tree = this._getTree();
|
|
538
558
|
if (!tree) {
|
|
539
559
|
this.hitAreas = [];
|
|
540
560
|
} else {
|
|
541
|
-
this.hitAreas = generateHitAreas(tree, currentNode, this.
|
|
561
|
+
this.hitAreas = generateHitAreas(tree, currentNode, this._getTreeDimensions().bottom);
|
|
542
562
|
}
|
|
543
563
|
}
|
|
544
|
-
|
|
564
|
+
_getTreeDimensions() {
|
|
545
565
|
// Return the dimensions of the tree. Add a margin to the bottom to allow
|
|
546
566
|
// to drag-and-drop after the last element.
|
|
547
|
-
const treePosition = getElementPosition(this.
|
|
548
|
-
const left = treePosition.left + this.
|
|
567
|
+
const treePosition = getElementPosition(this._treeElement);
|
|
568
|
+
const left = treePosition.left + this._getScrollLeft();
|
|
549
569
|
const top = treePosition.top;
|
|
550
570
|
return {
|
|
551
|
-
bottom: top + this.
|
|
571
|
+
bottom: top + this._treeElement.clientHeight + 16,
|
|
552
572
|
left,
|
|
553
|
-
right: left + this.
|
|
573
|
+
right: left + this._treeElement.clientWidth,
|
|
554
574
|
top
|
|
555
575
|
};
|
|
556
576
|
}
|
|
557
577
|
|
|
558
578
|
/* Move the dragged node to the selected position in the tree. */
|
|
559
|
-
|
|
560
|
-
if (this.currentItem && this.hoveredArea?.position && this.
|
|
579
|
+
_moveItem(positionInfo) {
|
|
580
|
+
if (this.currentItem && this.hoveredArea?.position && this._canMoveToArea(this.hoveredArea, this.currentItem)) {
|
|
561
581
|
const movedNode = this.currentItem.node;
|
|
562
582
|
const targetNode = this.hoveredArea.node;
|
|
563
583
|
const position = this.hoveredArea.position;
|
|
@@ -566,14 +586,14 @@ var jqtree = (function (exports) {
|
|
|
566
586
|
this.hoveredArea.node.is_open = true;
|
|
567
587
|
}
|
|
568
588
|
const doMove = () => {
|
|
569
|
-
const tree = this.
|
|
589
|
+
const tree = this._getTree();
|
|
570
590
|
if (tree) {
|
|
571
591
|
tree.moveNode(movedNode, targetNode, position);
|
|
572
|
-
this.
|
|
573
|
-
this.
|
|
592
|
+
this._treeElement.textContent = "";
|
|
593
|
+
this._refreshElements(null);
|
|
574
594
|
}
|
|
575
595
|
};
|
|
576
|
-
|
|
596
|
+
if (this._triggerEvent("tree.move", {
|
|
577
597
|
move_info: {
|
|
578
598
|
do_move: doMove,
|
|
579
599
|
moved_node: movedNode,
|
|
@@ -582,92 +602,105 @@ var jqtree = (function (exports) {
|
|
|
582
602
|
previous_parent: previousParent,
|
|
583
603
|
target_node: targetNode
|
|
584
604
|
}
|
|
585
|
-
})
|
|
586
|
-
if (!event.isDefaultPrevented()) {
|
|
605
|
+
})) {
|
|
587
606
|
doMove();
|
|
588
607
|
}
|
|
589
608
|
}
|
|
590
609
|
}
|
|
591
|
-
|
|
610
|
+
_mustCaptureElement(element) {
|
|
592
611
|
const nodeName = element.nodeName;
|
|
593
612
|
return nodeName !== "INPUT" && nodeName !== "SELECT" && nodeName !== "TEXTAREA";
|
|
594
613
|
}
|
|
595
|
-
|
|
614
|
+
_mustOpenFolderTimer(area) {
|
|
596
615
|
const node = area.node;
|
|
597
616
|
return node.isFolder() && !node.is_open && area.position === "inside";
|
|
598
617
|
}
|
|
599
|
-
|
|
600
|
-
if (this.
|
|
601
|
-
this.
|
|
618
|
+
_removeDropHint() {
|
|
619
|
+
if (this._previousGhost) {
|
|
620
|
+
this._previousGhost.remove();
|
|
602
621
|
}
|
|
603
622
|
}
|
|
604
|
-
|
|
623
|
+
_removeHitAreas() {
|
|
605
624
|
this.hitAreas = [];
|
|
606
625
|
}
|
|
607
|
-
|
|
626
|
+
_removeHover() {
|
|
608
627
|
this.hoveredArea = null;
|
|
609
628
|
}
|
|
610
|
-
|
|
629
|
+
_startOpenFolderTimer(folder) {
|
|
611
630
|
const openFolder = () => {
|
|
612
|
-
this.
|
|
631
|
+
this._openNode(folder, this._slide, () => {
|
|
613
632
|
this.refresh();
|
|
614
|
-
this.
|
|
633
|
+
this._updateDropHint();
|
|
615
634
|
});
|
|
616
635
|
};
|
|
617
|
-
this.
|
|
618
|
-
const openFolderDelay = this.
|
|
636
|
+
this._stopOpenFolderTimer();
|
|
637
|
+
const openFolderDelay = this._openFolderDelay;
|
|
619
638
|
if (openFolderDelay !== false) {
|
|
620
|
-
this.
|
|
639
|
+
this._openFolderTimer = window.setTimeout(openFolder, openFolderDelay);
|
|
621
640
|
}
|
|
622
641
|
}
|
|
623
|
-
|
|
624
|
-
if (this.
|
|
625
|
-
clearTimeout(this.
|
|
626
|
-
this.
|
|
642
|
+
_stopOpenFolderTimer() {
|
|
643
|
+
if (this._openFolderTimer) {
|
|
644
|
+
clearTimeout(this._openFolderTimer);
|
|
645
|
+
this._openFolderTimer = null;
|
|
627
646
|
}
|
|
628
647
|
}
|
|
629
|
-
|
|
648
|
+
_updateDropHint() {
|
|
630
649
|
if (!this.hoveredArea) {
|
|
631
650
|
return;
|
|
632
651
|
}
|
|
633
652
|
|
|
634
653
|
// remove previous drop hint
|
|
635
|
-
this.
|
|
654
|
+
this._removeDropHint();
|
|
636
655
|
|
|
637
656
|
// add new drop hint
|
|
638
|
-
const nodeElement = this.
|
|
639
|
-
this.
|
|
657
|
+
const nodeElement = this._getNodeElementForNode(this.hoveredArea.node);
|
|
658
|
+
this._previousGhost = nodeElement.addDropHint(this.hoveredArea.position);
|
|
640
659
|
}
|
|
641
660
|
}
|
|
642
661
|
|
|
662
|
+
const isInt = n => typeof n === "number" && n % 1 === 0;
|
|
663
|
+
const getBoolString = value => value ? "true" : "false";
|
|
664
|
+
|
|
643
665
|
class ElementsRenderer {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
this.
|
|
666
|
+
closedIconElement;
|
|
667
|
+
openedIconElement;
|
|
668
|
+
_autoEscape;
|
|
669
|
+
_buttonLeft;
|
|
670
|
+
_dragAndDrop;
|
|
671
|
+
_getTree;
|
|
672
|
+
_htmlElement;
|
|
673
|
+
_isNodeSelected;
|
|
674
|
+
_onCreateLi;
|
|
675
|
+
_rtl;
|
|
676
|
+
_showEmptyFolder;
|
|
677
|
+
_tabIndex;
|
|
678
|
+
constructor({
|
|
679
|
+
autoEscape,
|
|
680
|
+
buttonLeft,
|
|
681
|
+
closedIcon,
|
|
682
|
+
dragAndDrop,
|
|
683
|
+
getTree,
|
|
684
|
+
htmlElement,
|
|
685
|
+
isNodeSelected,
|
|
686
|
+
onCreateLi,
|
|
687
|
+
openedIcon,
|
|
688
|
+
rtl,
|
|
689
|
+
showEmptyFolder,
|
|
690
|
+
tabIndex
|
|
691
|
+
}) {
|
|
692
|
+
this._autoEscape = autoEscape;
|
|
693
|
+
this._buttonLeft = buttonLeft;
|
|
694
|
+
this._dragAndDrop = dragAndDrop;
|
|
695
|
+
this._getTree = getTree;
|
|
696
|
+
this._htmlElement = htmlElement;
|
|
697
|
+
this._isNodeSelected = isNodeSelected;
|
|
698
|
+
this._onCreateLi = onCreateLi;
|
|
699
|
+
this._rtl = rtl;
|
|
700
|
+
this._showEmptyFolder = showEmptyFolder;
|
|
701
|
+
this._tabIndex = tabIndex;
|
|
702
|
+
this.openedIconElement = this._createButtonElement(openedIcon ?? "+");
|
|
703
|
+
this.closedIconElement = this._createButtonElement(closedIcon ?? "-");
|
|
671
704
|
}
|
|
672
705
|
render(fromNode) {
|
|
673
706
|
if (fromNode?.parent) {
|
|
@@ -680,34 +713,25 @@ var jqtree = (function (exports) {
|
|
|
680
713
|
if (!node.element) {
|
|
681
714
|
return;
|
|
682
715
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
// create element
|
|
688
|
-
const li = this.createLi(node, node.getLevel());
|
|
689
|
-
|
|
690
|
-
// add element to dom
|
|
691
|
-
$previousLi.after(li);
|
|
692
|
-
|
|
693
|
-
// remove previous li
|
|
694
|
-
$previousLi.remove();
|
|
716
|
+
const currentLi = node.element;
|
|
717
|
+
const newLi = this._createLi(node, node.getLevel());
|
|
718
|
+
currentLi.replaceWith(newLi);
|
|
695
719
|
|
|
696
720
|
// create children
|
|
697
|
-
this.
|
|
721
|
+
this._createDomElements(newLi, node.children, false, node.getLevel() + 1);
|
|
698
722
|
}
|
|
699
723
|
renderFromRoot() {
|
|
700
|
-
this
|
|
701
|
-
const tree = this.
|
|
702
|
-
if (
|
|
703
|
-
this.
|
|
724
|
+
this._htmlElement.textContent = '';
|
|
725
|
+
const tree = this._getTree();
|
|
726
|
+
if (tree) {
|
|
727
|
+
this._createDomElements(this._htmlElement, tree.children, true, 1);
|
|
704
728
|
}
|
|
705
729
|
}
|
|
706
|
-
|
|
730
|
+
_attachNodeData(node, li) {
|
|
707
731
|
node.element = li;
|
|
708
732
|
jQuery(li).data("node", node);
|
|
709
733
|
}
|
|
710
|
-
|
|
734
|
+
_createButtonElement(value) {
|
|
711
735
|
if (typeof value === "string") {
|
|
712
736
|
// convert value to html
|
|
713
737
|
const div = document.createElement("div");
|
|
@@ -719,20 +743,20 @@ var jqtree = (function (exports) {
|
|
|
719
743
|
return jQuery(value)[0];
|
|
720
744
|
}
|
|
721
745
|
}
|
|
722
|
-
|
|
723
|
-
const ul = this.
|
|
746
|
+
_createDomElements(element, children, isRootNode, level) {
|
|
747
|
+
const ul = this._createUl(isRootNode);
|
|
724
748
|
element.appendChild(ul);
|
|
725
749
|
for (const child of children) {
|
|
726
|
-
const li = this.
|
|
750
|
+
const li = this._createLi(child, level);
|
|
727
751
|
ul.appendChild(li);
|
|
728
752
|
if (child.hasChildren()) {
|
|
729
|
-
this.
|
|
753
|
+
this._createDomElements(li, child.children, false, level + 1);
|
|
730
754
|
}
|
|
731
755
|
}
|
|
732
756
|
}
|
|
733
|
-
|
|
734
|
-
const buttonClasses = this.
|
|
735
|
-
const folderClasses = this.
|
|
757
|
+
_createFolderLi(node, level, isSelected) {
|
|
758
|
+
const buttonClasses = this._getButtonClasses(node);
|
|
759
|
+
const folderClasses = this._getFolderClasses(node, isSelected);
|
|
736
760
|
const iconElement = node.is_open ? this.openedIconElement : this.closedIconElement;
|
|
737
761
|
|
|
738
762
|
// li
|
|
@@ -752,15 +776,15 @@ var jqtree = (function (exports) {
|
|
|
752
776
|
if (iconElement) {
|
|
753
777
|
buttonLink.appendChild(iconElement.cloneNode(true));
|
|
754
778
|
}
|
|
755
|
-
if (this.
|
|
779
|
+
if (this._buttonLeft) {
|
|
756
780
|
div.appendChild(buttonLink);
|
|
757
781
|
}
|
|
758
782
|
|
|
759
783
|
// title span
|
|
760
|
-
const titleSpan = this.
|
|
784
|
+
const titleSpan = this._createTitleSpan(node.name, isSelected, true, level);
|
|
761
785
|
titleSpan.setAttribute("aria-expanded", getBoolString(node.is_open));
|
|
762
786
|
div.appendChild(titleSpan);
|
|
763
|
-
if (!this.
|
|
787
|
+
if (!this._buttonLeft) {
|
|
764
788
|
div.appendChild(buttonLink);
|
|
765
789
|
}
|
|
766
790
|
return li;
|
|
@@ -770,17 +794,17 @@ var jqtree = (function (exports) {
|
|
|
770
794
|
* Attach it to node.element.
|
|
771
795
|
* Call onCreateLi
|
|
772
796
|
*/
|
|
773
|
-
|
|
774
|
-
const isSelected =
|
|
775
|
-
const mustShowFolder = node.isFolder() || node.isEmptyFolder && this.
|
|
776
|
-
const li = mustShowFolder ? this.
|
|
777
|
-
this.
|
|
778
|
-
if (this.
|
|
779
|
-
this.
|
|
797
|
+
_createLi(node, level) {
|
|
798
|
+
const isSelected = this._isNodeSelected(node);
|
|
799
|
+
const mustShowFolder = node.isFolder() || node.isEmptyFolder && this._showEmptyFolder;
|
|
800
|
+
const li = mustShowFolder ? this._createFolderLi(node, level, isSelected) : this._createNodeLi(node, level, isSelected);
|
|
801
|
+
this._attachNodeData(node, li);
|
|
802
|
+
if (this._onCreateLi) {
|
|
803
|
+
this._onCreateLi(node, jQuery(li), isSelected);
|
|
780
804
|
}
|
|
781
805
|
return li;
|
|
782
806
|
}
|
|
783
|
-
|
|
807
|
+
_createNodeLi(node, level, isSelected) {
|
|
784
808
|
const liClasses = ["jqtree_common"];
|
|
785
809
|
if (isSelected) {
|
|
786
810
|
liClasses.push("jqtree-selected");
|
|
@@ -799,33 +823,33 @@ var jqtree = (function (exports) {
|
|
|
799
823
|
li.appendChild(div);
|
|
800
824
|
|
|
801
825
|
// title span
|
|
802
|
-
const titleSpan = this.
|
|
826
|
+
const titleSpan = this._createTitleSpan(node.name, isSelected, false, level);
|
|
803
827
|
div.appendChild(titleSpan);
|
|
804
828
|
return li;
|
|
805
829
|
}
|
|
806
|
-
|
|
830
|
+
_createTitleSpan(nodeName, isSelected, isFolder, level) {
|
|
807
831
|
const titleSpan = document.createElement("span");
|
|
808
832
|
let classes = "jqtree-title jqtree_common";
|
|
809
833
|
if (isFolder) {
|
|
810
834
|
classes += " jqtree-title-folder";
|
|
811
835
|
}
|
|
812
|
-
classes += ` jqtree-title-button-${this.
|
|
836
|
+
classes += ` jqtree-title-button-${this._buttonLeft ? "left" : "right"}`;
|
|
813
837
|
titleSpan.className = classes;
|
|
814
838
|
if (isSelected) {
|
|
815
|
-
const tabIndex = this.
|
|
839
|
+
const tabIndex = this._tabIndex;
|
|
816
840
|
if (tabIndex !== undefined) {
|
|
817
841
|
titleSpan.setAttribute("tabindex", `${tabIndex}`);
|
|
818
842
|
}
|
|
819
843
|
}
|
|
820
|
-
this.
|
|
821
|
-
if (this.
|
|
844
|
+
this._setTreeItemAriaAttributes(titleSpan, nodeName, level, isSelected);
|
|
845
|
+
if (this._autoEscape) {
|
|
822
846
|
titleSpan.textContent = nodeName;
|
|
823
847
|
} else {
|
|
824
848
|
titleSpan.innerHTML = nodeName;
|
|
825
849
|
}
|
|
826
850
|
return titleSpan;
|
|
827
851
|
}
|
|
828
|
-
|
|
852
|
+
_createUl(isRootNode) {
|
|
829
853
|
let classString;
|
|
830
854
|
let role;
|
|
831
855
|
if (!isRootNode) {
|
|
@@ -834,11 +858,11 @@ var jqtree = (function (exports) {
|
|
|
834
858
|
} else {
|
|
835
859
|
classString = "jqtree-tree";
|
|
836
860
|
role = "tree";
|
|
837
|
-
if (this.
|
|
861
|
+
if (this._rtl) {
|
|
838
862
|
classString += " jqtree-rtl";
|
|
839
863
|
}
|
|
840
864
|
}
|
|
841
|
-
if (this.
|
|
865
|
+
if (this._dragAndDrop) {
|
|
842
866
|
classString += " jqtree-dnd";
|
|
843
867
|
}
|
|
844
868
|
const ul = document.createElement("ul");
|
|
@@ -846,19 +870,19 @@ var jqtree = (function (exports) {
|
|
|
846
870
|
ul.setAttribute("role", role);
|
|
847
871
|
return ul;
|
|
848
872
|
}
|
|
849
|
-
|
|
873
|
+
_getButtonClasses(node) {
|
|
850
874
|
const classes = ["jqtree-toggler", "jqtree_common"];
|
|
851
875
|
if (!node.is_open) {
|
|
852
876
|
classes.push("jqtree-closed");
|
|
853
877
|
}
|
|
854
|
-
if (this.
|
|
878
|
+
if (this._buttonLeft) {
|
|
855
879
|
classes.push("jqtree-toggler-left");
|
|
856
880
|
} else {
|
|
857
881
|
classes.push("jqtree-toggler-right");
|
|
858
882
|
}
|
|
859
883
|
return classes.join(" ");
|
|
860
884
|
}
|
|
861
|
-
|
|
885
|
+
_getFolderClasses(node, isSelected) {
|
|
862
886
|
const classes = ["jqtree-folder"];
|
|
863
887
|
if (!node.is_open) {
|
|
864
888
|
classes.push("jqtree-closed");
|
|
@@ -871,7 +895,7 @@ var jqtree = (function (exports) {
|
|
|
871
895
|
}
|
|
872
896
|
return classes.join(" ");
|
|
873
897
|
}
|
|
874
|
-
|
|
898
|
+
_setTreeItemAriaAttributes(element, name, level, isSelected) {
|
|
875
899
|
element.setAttribute("aria-label", name);
|
|
876
900
|
element.setAttribute("aria-level", `${level}`);
|
|
877
901
|
element.setAttribute("aria-selected", getBoolString(isSelected));
|
|
@@ -880,55 +904,60 @@ var jqtree = (function (exports) {
|
|
|
880
904
|
}
|
|
881
905
|
|
|
882
906
|
class KeyHandler {
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
this.
|
|
907
|
+
_closeNode;
|
|
908
|
+
_getSelectedNode;
|
|
909
|
+
_isFocusOnTree;
|
|
910
|
+
_keyboardSupport;
|
|
911
|
+
_openNode;
|
|
912
|
+
_originalSelectNode;
|
|
913
|
+
constructor({
|
|
914
|
+
closeNode,
|
|
915
|
+
getSelectedNode,
|
|
916
|
+
isFocusOnTree,
|
|
917
|
+
keyboardSupport,
|
|
918
|
+
openNode,
|
|
919
|
+
selectNode
|
|
920
|
+
}) {
|
|
921
|
+
this._closeNode = closeNode;
|
|
922
|
+
this._getSelectedNode = getSelectedNode;
|
|
923
|
+
this._isFocusOnTree = isFocusOnTree;
|
|
924
|
+
this._keyboardSupport = keyboardSupport;
|
|
925
|
+
this._openNode = openNode;
|
|
926
|
+
this._originalSelectNode = selectNode;
|
|
898
927
|
if (keyboardSupport) {
|
|
899
|
-
document.addEventListener("keydown", this.
|
|
928
|
+
document.addEventListener("keydown", this._handleKeyDown);
|
|
900
929
|
}
|
|
901
930
|
}
|
|
902
931
|
deinit() {
|
|
903
|
-
if (this.
|
|
904
|
-
document.removeEventListener("keydown", this.
|
|
932
|
+
if (this._keyboardSupport) {
|
|
933
|
+
document.removeEventListener("keydown", this._handleKeyDown);
|
|
905
934
|
}
|
|
906
935
|
}
|
|
907
936
|
moveDown(selectedNode) {
|
|
908
|
-
return this.
|
|
937
|
+
return this._selectNode(selectedNode.getNextVisibleNode());
|
|
909
938
|
}
|
|
910
939
|
moveUp(selectedNode) {
|
|
911
|
-
return this.
|
|
940
|
+
return this._selectNode(selectedNode.getPreviousVisibleNode());
|
|
912
941
|
}
|
|
913
|
-
|
|
914
|
-
return this.
|
|
942
|
+
_canHandleKeyboard() {
|
|
943
|
+
return this._keyboardSupport && this._isFocusOnTree();
|
|
915
944
|
}
|
|
916
|
-
|
|
917
|
-
if (!this.
|
|
945
|
+
_handleKeyDown = e => {
|
|
946
|
+
if (!this._canHandleKeyboard()) {
|
|
918
947
|
return;
|
|
919
948
|
}
|
|
920
949
|
let isKeyHandled = false;
|
|
921
|
-
const selectedNode = this.
|
|
950
|
+
const selectedNode = this._getSelectedNode();
|
|
922
951
|
if (selectedNode) {
|
|
923
952
|
switch (e.key) {
|
|
924
953
|
case "ArrowDown":
|
|
925
954
|
isKeyHandled = this.moveDown(selectedNode);
|
|
926
955
|
break;
|
|
927
956
|
case "ArrowLeft":
|
|
928
|
-
isKeyHandled = this.
|
|
957
|
+
isKeyHandled = this._moveLeft(selectedNode);
|
|
929
958
|
break;
|
|
930
959
|
case "ArrowRight":
|
|
931
|
-
isKeyHandled = this.
|
|
960
|
+
isKeyHandled = this._moveRight(selectedNode);
|
|
932
961
|
break;
|
|
933
962
|
case "ArrowUp":
|
|
934
963
|
isKeyHandled = this.moveUp(selectedNode);
|
|
@@ -939,27 +968,27 @@ var jqtree = (function (exports) {
|
|
|
939
968
|
e.preventDefault();
|
|
940
969
|
}
|
|
941
970
|
};
|
|
942
|
-
|
|
971
|
+
_moveLeft(selectedNode) {
|
|
943
972
|
if (selectedNode.isFolder() && selectedNode.is_open) {
|
|
944
973
|
// Left on an open node closes the node
|
|
945
|
-
this.
|
|
974
|
+
this._closeNode(selectedNode);
|
|
946
975
|
return true;
|
|
947
976
|
} else {
|
|
948
977
|
// Left on a closed or end node moves focus to the node's parent
|
|
949
|
-
return this.
|
|
978
|
+
return this._selectNode(selectedNode.getParent());
|
|
950
979
|
}
|
|
951
980
|
}
|
|
952
|
-
|
|
981
|
+
_moveRight(selectedNode) {
|
|
953
982
|
if (!selectedNode.isFolder()) {
|
|
954
983
|
return false;
|
|
955
984
|
} else {
|
|
956
985
|
// folder node
|
|
957
986
|
if (selectedNode.is_open) {
|
|
958
987
|
// Right moves to the first child of an open node
|
|
959
|
-
return this.
|
|
988
|
+
return this._selectNode(selectedNode.getNextVisibleNode());
|
|
960
989
|
} else {
|
|
961
990
|
// Right expands a closed node
|
|
962
|
-
this.
|
|
991
|
+
this._openNode(selectedNode);
|
|
963
992
|
return true;
|
|
964
993
|
}
|
|
965
994
|
}
|
|
@@ -969,11 +998,11 @@ var jqtree = (function (exports) {
|
|
|
969
998
|
* Don't do anything if the node is null.
|
|
970
999
|
* Result: a different node was selected.
|
|
971
1000
|
*/
|
|
972
|
-
|
|
1001
|
+
_selectNode(node) {
|
|
973
1002
|
if (!node) {
|
|
974
1003
|
return false;
|
|
975
1004
|
} else {
|
|
976
|
-
this.
|
|
1005
|
+
this._originalSelectNode(node);
|
|
977
1006
|
return true;
|
|
978
1007
|
}
|
|
979
1008
|
}
|
|
@@ -993,61 +1022,75 @@ var jqtree = (function (exports) {
|
|
|
993
1022
|
});
|
|
994
1023
|
|
|
995
1024
|
class MouseHandler {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1025
|
+
_element;
|
|
1026
|
+
_getMouseDelay;
|
|
1027
|
+
_getNode;
|
|
1028
|
+
_isMouseDelayMet;
|
|
1029
|
+
_isMouseStarted;
|
|
1030
|
+
_mouseDelayTimer;
|
|
1031
|
+
_mouseDownInfo;
|
|
1032
|
+
_onClickButton;
|
|
1033
|
+
_onClickTitle;
|
|
1034
|
+
_onMouseCapture;
|
|
1035
|
+
_onMouseDrag;
|
|
1036
|
+
_onMouseStart;
|
|
1037
|
+
_onMouseStop;
|
|
1038
|
+
_triggerEvent;
|
|
1039
|
+
_useContextMenu;
|
|
1040
|
+
constructor({
|
|
1041
|
+
element,
|
|
1042
|
+
getMouseDelay,
|
|
1043
|
+
getNode,
|
|
1044
|
+
onClickButton,
|
|
1045
|
+
onClickTitle,
|
|
1046
|
+
onMouseCapture,
|
|
1047
|
+
onMouseDrag,
|
|
1048
|
+
onMouseStart,
|
|
1049
|
+
onMouseStop,
|
|
1050
|
+
triggerEvent,
|
|
1051
|
+
useContextMenu
|
|
1052
|
+
}) {
|
|
1053
|
+
this._element = element;
|
|
1054
|
+
this._getMouseDelay = getMouseDelay;
|
|
1055
|
+
this._getNode = getNode;
|
|
1056
|
+
this._onClickButton = onClickButton;
|
|
1057
|
+
this._onClickTitle = onClickTitle;
|
|
1058
|
+
this._onMouseCapture = onMouseCapture;
|
|
1059
|
+
this._onMouseDrag = onMouseDrag;
|
|
1060
|
+
this._onMouseStart = onMouseStart;
|
|
1061
|
+
this._onMouseStop = onMouseStop;
|
|
1062
|
+
this._triggerEvent = triggerEvent;
|
|
1063
|
+
this._useContextMenu = useContextMenu;
|
|
1064
|
+
element.addEventListener("click", this._handleClick);
|
|
1065
|
+
element.addEventListener("dblclick", this._handleDblclick);
|
|
1066
|
+
element.addEventListener("mousedown", this._mouseDown, {
|
|
1024
1067
|
passive: false
|
|
1025
1068
|
});
|
|
1026
|
-
element.addEventListener("touchstart", this.
|
|
1069
|
+
element.addEventListener("touchstart", this._touchStart, {
|
|
1027
1070
|
passive: false
|
|
1028
1071
|
});
|
|
1029
1072
|
if (useContextMenu) {
|
|
1030
|
-
element.addEventListener("contextmenu", this.
|
|
1073
|
+
element.addEventListener("contextmenu", this._handleContextmenu);
|
|
1031
1074
|
}
|
|
1032
|
-
this.
|
|
1033
|
-
this.
|
|
1034
|
-
this.
|
|
1035
|
-
this.
|
|
1075
|
+
this._isMouseStarted = false;
|
|
1076
|
+
this._mouseDelayTimer = null;
|
|
1077
|
+
this._isMouseDelayMet = false;
|
|
1078
|
+
this._mouseDownInfo = null;
|
|
1036
1079
|
}
|
|
1037
1080
|
deinit() {
|
|
1038
|
-
this.
|
|
1039
|
-
this.
|
|
1040
|
-
if (this.
|
|
1041
|
-
this.
|
|
1081
|
+
this._element.removeEventListener("click", this._handleClick);
|
|
1082
|
+
this._element.removeEventListener("dblclick", this._handleDblclick);
|
|
1083
|
+
if (this._useContextMenu) {
|
|
1084
|
+
this._element.removeEventListener("contextmenu", this._handleContextmenu);
|
|
1042
1085
|
}
|
|
1043
|
-
this.
|
|
1044
|
-
this.
|
|
1045
|
-
this.
|
|
1086
|
+
this._element.removeEventListener("mousedown", this._mouseDown);
|
|
1087
|
+
this._element.removeEventListener("touchstart", this._touchStart);
|
|
1088
|
+
this._removeMouseMoveEventListeners();
|
|
1046
1089
|
}
|
|
1047
|
-
|
|
1090
|
+
_getClickTarget(element) {
|
|
1048
1091
|
const button = element.closest(".jqtree-toggler");
|
|
1049
1092
|
if (button) {
|
|
1050
|
-
const node = this.
|
|
1093
|
+
const node = this._getNode(button);
|
|
1051
1094
|
if (node) {
|
|
1052
1095
|
return {
|
|
1053
1096
|
node,
|
|
@@ -1057,7 +1100,7 @@ var jqtree = (function (exports) {
|
|
|
1057
1100
|
} else {
|
|
1058
1101
|
const jqTreeElement = element.closest(".jqtree-element");
|
|
1059
1102
|
if (jqTreeElement) {
|
|
1060
|
-
const node = this.
|
|
1103
|
+
const node = this._getNode(jqTreeElement);
|
|
1061
1104
|
if (node) {
|
|
1062
1105
|
return {
|
|
1063
1106
|
node,
|
|
@@ -1068,44 +1111,43 @@ var jqtree = (function (exports) {
|
|
|
1068
1111
|
}
|
|
1069
1112
|
return null;
|
|
1070
1113
|
}
|
|
1071
|
-
|
|
1114
|
+
_handleClick = e => {
|
|
1072
1115
|
if (!e.target) {
|
|
1073
1116
|
return;
|
|
1074
1117
|
}
|
|
1075
|
-
const clickTarget = this.
|
|
1118
|
+
const clickTarget = this._getClickTarget(e.target);
|
|
1076
1119
|
if (!clickTarget) {
|
|
1077
1120
|
return;
|
|
1078
1121
|
}
|
|
1079
1122
|
switch (clickTarget.type) {
|
|
1080
1123
|
case "button":
|
|
1081
|
-
this.
|
|
1124
|
+
this._onClickButton(clickTarget.node);
|
|
1082
1125
|
e.preventDefault();
|
|
1083
1126
|
e.stopPropagation();
|
|
1084
1127
|
break;
|
|
1085
1128
|
case "label":
|
|
1086
1129
|
{
|
|
1087
|
-
|
|
1130
|
+
if (this._triggerEvent("tree.click", {
|
|
1088
1131
|
click_event: e,
|
|
1089
1132
|
node: clickTarget.node
|
|
1090
|
-
})
|
|
1091
|
-
|
|
1092
|
-
this.onClickTitle(clickTarget.node);
|
|
1133
|
+
})) {
|
|
1134
|
+
this._onClickTitle(clickTarget.node);
|
|
1093
1135
|
}
|
|
1094
1136
|
break;
|
|
1095
1137
|
}
|
|
1096
1138
|
}
|
|
1097
1139
|
};
|
|
1098
|
-
|
|
1140
|
+
_handleContextmenu = e => {
|
|
1099
1141
|
if (!e.target) {
|
|
1100
1142
|
return;
|
|
1101
1143
|
}
|
|
1102
1144
|
const div = e.target.closest("ul.jqtree-tree .jqtree-element");
|
|
1103
1145
|
if (div) {
|
|
1104
|
-
const node = this.
|
|
1146
|
+
const node = this._getNode(div);
|
|
1105
1147
|
if (node) {
|
|
1106
1148
|
e.preventDefault();
|
|
1107
1149
|
e.stopPropagation();
|
|
1108
|
-
this.
|
|
1150
|
+
this._triggerEvent("tree.contextmenu", {
|
|
1109
1151
|
click_event: e,
|
|
1110
1152
|
node
|
|
1111
1153
|
});
|
|
@@ -1114,116 +1156,116 @@ var jqtree = (function (exports) {
|
|
|
1114
1156
|
}
|
|
1115
1157
|
return null;
|
|
1116
1158
|
};
|
|
1117
|
-
|
|
1159
|
+
_handleDblclick = e => {
|
|
1118
1160
|
if (!e.target) {
|
|
1119
1161
|
return;
|
|
1120
1162
|
}
|
|
1121
|
-
const clickTarget = this.
|
|
1163
|
+
const clickTarget = this._getClickTarget(e.target);
|
|
1122
1164
|
if (clickTarget?.type === "label") {
|
|
1123
|
-
this.
|
|
1165
|
+
this._triggerEvent("tree.dblclick", {
|
|
1124
1166
|
click_event: e,
|
|
1125
1167
|
node: clickTarget.node
|
|
1126
1168
|
});
|
|
1127
1169
|
}
|
|
1128
1170
|
};
|
|
1129
|
-
|
|
1171
|
+
_handleMouseDown(positionInfo) {
|
|
1130
1172
|
// We may have missed mouseup (out of window)
|
|
1131
|
-
if (this.
|
|
1132
|
-
this.
|
|
1173
|
+
if (this._isMouseStarted) {
|
|
1174
|
+
this._handleMouseUp(positionInfo);
|
|
1133
1175
|
}
|
|
1134
|
-
this.
|
|
1135
|
-
if (!this.
|
|
1176
|
+
this._mouseDownInfo = positionInfo;
|
|
1177
|
+
if (!this._onMouseCapture(positionInfo)) {
|
|
1136
1178
|
return false;
|
|
1137
1179
|
}
|
|
1138
|
-
this.
|
|
1180
|
+
this._handleStartMouse();
|
|
1139
1181
|
return true;
|
|
1140
1182
|
}
|
|
1141
|
-
|
|
1142
|
-
if (this.
|
|
1143
|
-
this.
|
|
1183
|
+
_handleMouseMove(e, positionInfo) {
|
|
1184
|
+
if (this._isMouseStarted) {
|
|
1185
|
+
this._onMouseDrag(positionInfo);
|
|
1144
1186
|
if (e.cancelable) {
|
|
1145
1187
|
e.preventDefault();
|
|
1146
1188
|
}
|
|
1147
1189
|
return;
|
|
1148
1190
|
}
|
|
1149
|
-
if (!this.
|
|
1191
|
+
if (!this._isMouseDelayMet) {
|
|
1150
1192
|
return;
|
|
1151
1193
|
}
|
|
1152
|
-
if (this.
|
|
1153
|
-
this.
|
|
1194
|
+
if (this._mouseDownInfo) {
|
|
1195
|
+
this._isMouseStarted = this._onMouseStart(this._mouseDownInfo);
|
|
1154
1196
|
}
|
|
1155
|
-
if (this.
|
|
1156
|
-
this.
|
|
1197
|
+
if (this._isMouseStarted) {
|
|
1198
|
+
this._onMouseDrag(positionInfo);
|
|
1157
1199
|
if (e.cancelable) {
|
|
1158
1200
|
e.preventDefault();
|
|
1159
1201
|
}
|
|
1160
1202
|
} else {
|
|
1161
|
-
this.
|
|
1203
|
+
this._handleMouseUp(positionInfo);
|
|
1162
1204
|
}
|
|
1163
1205
|
}
|
|
1164
|
-
|
|
1165
|
-
this.
|
|
1166
|
-
this.
|
|
1167
|
-
this.
|
|
1168
|
-
if (this.
|
|
1169
|
-
this.
|
|
1170
|
-
this.
|
|
1206
|
+
_handleMouseUp(positionInfo) {
|
|
1207
|
+
this._removeMouseMoveEventListeners();
|
|
1208
|
+
this._isMouseDelayMet = false;
|
|
1209
|
+
this._mouseDownInfo = null;
|
|
1210
|
+
if (this._isMouseStarted) {
|
|
1211
|
+
this._isMouseStarted = false;
|
|
1212
|
+
this._onMouseStop(positionInfo);
|
|
1171
1213
|
}
|
|
1172
1214
|
}
|
|
1173
|
-
|
|
1174
|
-
document.addEventListener("mousemove", this.
|
|
1215
|
+
_handleStartMouse() {
|
|
1216
|
+
document.addEventListener("mousemove", this._mouseMove, {
|
|
1175
1217
|
passive: false
|
|
1176
1218
|
});
|
|
1177
|
-
document.addEventListener("touchmove", this.
|
|
1219
|
+
document.addEventListener("touchmove", this._touchMove, {
|
|
1178
1220
|
passive: false
|
|
1179
1221
|
});
|
|
1180
|
-
document.addEventListener("mouseup", this.
|
|
1222
|
+
document.addEventListener("mouseup", this._mouseUp, {
|
|
1181
1223
|
passive: false
|
|
1182
1224
|
});
|
|
1183
|
-
document.addEventListener("touchend", this.
|
|
1225
|
+
document.addEventListener("touchend", this._touchEnd, {
|
|
1184
1226
|
passive: false
|
|
1185
1227
|
});
|
|
1186
|
-
const mouseDelay = this.
|
|
1228
|
+
const mouseDelay = this._getMouseDelay();
|
|
1187
1229
|
if (mouseDelay) {
|
|
1188
|
-
this.
|
|
1230
|
+
this._startMouseDelayTimer(mouseDelay);
|
|
1189
1231
|
} else {
|
|
1190
|
-
this.
|
|
1232
|
+
this._isMouseDelayMet = true;
|
|
1191
1233
|
}
|
|
1192
1234
|
}
|
|
1193
|
-
|
|
1235
|
+
_mouseDown = e => {
|
|
1194
1236
|
// Left mouse button?
|
|
1195
1237
|
if (e.button !== 0) {
|
|
1196
1238
|
return;
|
|
1197
1239
|
}
|
|
1198
|
-
const result = this.
|
|
1240
|
+
const result = this._handleMouseDown(getPositionInfoFromMouseEvent(e));
|
|
1199
1241
|
if (result && e.cancelable) {
|
|
1200
1242
|
e.preventDefault();
|
|
1201
1243
|
}
|
|
1202
1244
|
};
|
|
1203
|
-
|
|
1204
|
-
this.
|
|
1245
|
+
_mouseMove = e => {
|
|
1246
|
+
this._handleMouseMove(e, getPositionInfoFromMouseEvent(e));
|
|
1205
1247
|
};
|
|
1206
|
-
|
|
1207
|
-
this.
|
|
1248
|
+
_mouseUp = e => {
|
|
1249
|
+
this._handleMouseUp(getPositionInfoFromMouseEvent(e));
|
|
1208
1250
|
};
|
|
1209
|
-
|
|
1210
|
-
document.removeEventListener("mousemove", this.
|
|
1211
|
-
document.removeEventListener("touchmove", this.
|
|
1212
|
-
document.removeEventListener("mouseup", this.
|
|
1213
|
-
document.removeEventListener("touchend", this.
|
|
1251
|
+
_removeMouseMoveEventListeners() {
|
|
1252
|
+
document.removeEventListener("mousemove", this._mouseMove);
|
|
1253
|
+
document.removeEventListener("touchmove", this._touchMove);
|
|
1254
|
+
document.removeEventListener("mouseup", this._mouseUp);
|
|
1255
|
+
document.removeEventListener("touchend", this._touchEnd);
|
|
1214
1256
|
}
|
|
1215
|
-
|
|
1216
|
-
if (this.
|
|
1217
|
-
clearTimeout(this.
|
|
1257
|
+
_startMouseDelayTimer(mouseDelay) {
|
|
1258
|
+
if (this._mouseDelayTimer) {
|
|
1259
|
+
clearTimeout(this._mouseDelayTimer);
|
|
1218
1260
|
}
|
|
1219
|
-
this.
|
|
1220
|
-
if (this.
|
|
1221
|
-
this.
|
|
1261
|
+
this._mouseDelayTimer = window.setTimeout(() => {
|
|
1262
|
+
if (this._mouseDownInfo) {
|
|
1263
|
+
this._isMouseDelayMet = true;
|
|
1222
1264
|
}
|
|
1223
1265
|
}, mouseDelay);
|
|
1224
|
-
this.
|
|
1266
|
+
this._isMouseDelayMet = false;
|
|
1225
1267
|
}
|
|
1226
|
-
|
|
1268
|
+
_touchEnd = e => {
|
|
1227
1269
|
if (e.touches.length > 1) {
|
|
1228
1270
|
return;
|
|
1229
1271
|
}
|
|
@@ -1231,9 +1273,9 @@ var jqtree = (function (exports) {
|
|
|
1231
1273
|
if (!touch) {
|
|
1232
1274
|
return;
|
|
1233
1275
|
}
|
|
1234
|
-
this.
|
|
1276
|
+
this._handleMouseUp(getPositionInfoFromTouch(touch, e));
|
|
1235
1277
|
};
|
|
1236
|
-
|
|
1278
|
+
_touchMove = e => {
|
|
1237
1279
|
if (e.touches.length > 1) {
|
|
1238
1280
|
return;
|
|
1239
1281
|
}
|
|
@@ -1241,9 +1283,9 @@ var jqtree = (function (exports) {
|
|
|
1241
1283
|
if (!touch) {
|
|
1242
1284
|
return;
|
|
1243
1285
|
}
|
|
1244
|
-
this.
|
|
1286
|
+
this._handleMouseMove(e, getPositionInfoFromTouch(touch, e));
|
|
1245
1287
|
};
|
|
1246
|
-
|
|
1288
|
+
_touchStart = e => {
|
|
1247
1289
|
if (e.touches.length > 1) {
|
|
1248
1290
|
return;
|
|
1249
1291
|
}
|
|
@@ -1251,17 +1293,26 @@ var jqtree = (function (exports) {
|
|
|
1251
1293
|
if (!touch) {
|
|
1252
1294
|
return;
|
|
1253
1295
|
}
|
|
1254
|
-
this.
|
|
1296
|
+
this._handleMouseDown(getPositionInfoFromTouch(touch, e));
|
|
1255
1297
|
};
|
|
1256
1298
|
}
|
|
1257
1299
|
|
|
1258
1300
|
const isNodeRecordWithChildren = data => typeof data === "object" && "children" in data && data.children instanceof Array;
|
|
1259
1301
|
|
|
1260
1302
|
class Node {
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1303
|
+
children;
|
|
1304
|
+
element;
|
|
1305
|
+
id;
|
|
1306
|
+
idMapping;
|
|
1307
|
+
is_loading;
|
|
1308
|
+
is_open;
|
|
1309
|
+
isEmptyFolder;
|
|
1310
|
+
load_on_demand;
|
|
1311
|
+
name;
|
|
1312
|
+
nodeClass;
|
|
1313
|
+
parent;
|
|
1314
|
+
tree;
|
|
1315
|
+
constructor(nodeData = null, isRoot = false, nodeClass = Node) {
|
|
1265
1316
|
this.name = "";
|
|
1266
1317
|
this.load_on_demand = false;
|
|
1267
1318
|
this.isEmptyFolder = nodeData != null && isNodeRecordWithChildren(nodeData) && nodeData.children.length === 0;
|
|
@@ -1278,10 +1329,10 @@ var jqtree = (function (exports) {
|
|
|
1278
1329
|
if (!this.parent) {
|
|
1279
1330
|
return null;
|
|
1280
1331
|
} else {
|
|
1281
|
-
const node = this.
|
|
1332
|
+
const node = this._createNode(nodeInfo);
|
|
1282
1333
|
const childIndex = this.parent.getChildIndex(this);
|
|
1283
1334
|
this.parent.addChildAtPosition(node, childIndex + 1);
|
|
1284
|
-
node.
|
|
1335
|
+
node._loadChildrenFromData(nodeInfo);
|
|
1285
1336
|
return node;
|
|
1286
1337
|
}
|
|
1287
1338
|
}
|
|
@@ -1289,10 +1340,10 @@ var jqtree = (function (exports) {
|
|
|
1289
1340
|
if (!this.parent) {
|
|
1290
1341
|
return null;
|
|
1291
1342
|
} else {
|
|
1292
|
-
const node = this.
|
|
1343
|
+
const node = this._createNode(nodeInfo);
|
|
1293
1344
|
const childIndex = this.parent.getChildIndex(this);
|
|
1294
1345
|
this.parent.addChildAtPosition(node, childIndex);
|
|
1295
|
-
node.
|
|
1346
|
+
node._loadChildrenFromData(nodeInfo);
|
|
1296
1347
|
return node;
|
|
1297
1348
|
}
|
|
1298
1349
|
}
|
|
@@ -1305,7 +1356,7 @@ var jqtree = (function (exports) {
|
|
|
1305
1356
|
*/
|
|
1306
1357
|
addChild(node) {
|
|
1307
1358
|
this.children.push(node);
|
|
1308
|
-
node.
|
|
1359
|
+
node._setParent(this);
|
|
1309
1360
|
}
|
|
1310
1361
|
|
|
1311
1362
|
/*
|
|
@@ -1317,7 +1368,7 @@ var jqtree = (function (exports) {
|
|
|
1317
1368
|
*/
|
|
1318
1369
|
addChildAtPosition(node, index) {
|
|
1319
1370
|
this.children.splice(index, 0, node);
|
|
1320
|
-
node.
|
|
1371
|
+
node._setParent(this);
|
|
1321
1372
|
}
|
|
1322
1373
|
addNodeToIndex(node) {
|
|
1323
1374
|
if (node.id != null) {
|
|
@@ -1328,9 +1379,9 @@ var jqtree = (function (exports) {
|
|
|
1328
1379
|
if (!this.parent) {
|
|
1329
1380
|
return null;
|
|
1330
1381
|
} else {
|
|
1331
|
-
const newParent = this.
|
|
1382
|
+
const newParent = this._createNode(nodeInfo);
|
|
1332
1383
|
if (this.tree) {
|
|
1333
|
-
newParent.
|
|
1384
|
+
newParent._setParent(this.tree);
|
|
1334
1385
|
}
|
|
1335
1386
|
const originalParent = this.parent;
|
|
1336
1387
|
for (const child of originalParent.children) {
|
|
@@ -1342,9 +1393,9 @@ var jqtree = (function (exports) {
|
|
|
1342
1393
|
}
|
|
1343
1394
|
}
|
|
1344
1395
|
append(nodeInfo) {
|
|
1345
|
-
const node = this.
|
|
1396
|
+
const node = this._createNode(nodeInfo);
|
|
1346
1397
|
this.addChild(node);
|
|
1347
|
-
node.
|
|
1398
|
+
node._loadChildrenFromData(nodeInfo);
|
|
1348
1399
|
return node;
|
|
1349
1400
|
}
|
|
1350
1401
|
filter(f) {
|
|
@@ -1369,8 +1420,7 @@ var jqtree = (function (exports) {
|
|
|
1369
1420
|
/*
|
|
1370
1421
|
Get the tree as data.
|
|
1371
1422
|
*/
|
|
1372
|
-
getData() {
|
|
1373
|
-
let includeParent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1423
|
+
getData(includeParent = false) {
|
|
1374
1424
|
const getDataFromNodes = nodes => {
|
|
1375
1425
|
return nodes.map(node => {
|
|
1376
1426
|
const tmpNode = {};
|
|
@@ -1397,9 +1447,6 @@ var jqtree = (function (exports) {
|
|
|
1397
1447
|
return null;
|
|
1398
1448
|
} else {
|
|
1399
1449
|
const lastChild = this.children[this.children.length - 1];
|
|
1400
|
-
if (!lastChild) {
|
|
1401
|
-
return null;
|
|
1402
|
-
}
|
|
1403
1450
|
if (!(lastChild.hasChildren() && lastChild.is_open)) {
|
|
1404
1451
|
return lastChild;
|
|
1405
1452
|
} else {
|
|
@@ -1417,8 +1464,7 @@ var jqtree = (function (exports) {
|
|
|
1417
1464
|
}
|
|
1418
1465
|
return level;
|
|
1419
1466
|
}
|
|
1420
|
-
getNextNode() {
|
|
1421
|
-
let includeChildren = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1467
|
+
getNextNode(includeChildren = true) {
|
|
1422
1468
|
if (includeChildren && this.hasChildren()) {
|
|
1423
1469
|
return this.children[0] ?? null;
|
|
1424
1470
|
} else if (!this.parent) {
|
|
@@ -1567,7 +1613,7 @@ var jqtree = (function (exports) {
|
|
|
1567
1613
|
};
|
|
1568
1614
|
const addChildren = childrenData => {
|
|
1569
1615
|
for (const child of childrenData) {
|
|
1570
|
-
const node = this.
|
|
1616
|
+
const node = this._createNode();
|
|
1571
1617
|
node.initFromData(child);
|
|
1572
1618
|
this.addChild(node);
|
|
1573
1619
|
}
|
|
@@ -1631,7 +1677,7 @@ var jqtree = (function (exports) {
|
|
|
1631
1677
|
loadFromData(data) {
|
|
1632
1678
|
this.removeChildren();
|
|
1633
1679
|
for (const childData of data) {
|
|
1634
|
-
const node = this.
|
|
1680
|
+
const node = this._createNode(childData);
|
|
1635
1681
|
this.addChild(node);
|
|
1636
1682
|
if (isNodeRecordWithChildren(childData)) {
|
|
1637
1683
|
node.loadFromData(childData.children);
|
|
@@ -1652,7 +1698,7 @@ var jqtree = (function (exports) {
|
|
|
1652
1698
|
// - Or, parent is empty
|
|
1653
1699
|
return false;
|
|
1654
1700
|
} else {
|
|
1655
|
-
movedNode.parent.
|
|
1701
|
+
movedNode.parent._doRemoveChild(movedNode);
|
|
1656
1702
|
switch (position) {
|
|
1657
1703
|
case "after":
|
|
1658
1704
|
{
|
|
@@ -1680,9 +1726,9 @@ var jqtree = (function (exports) {
|
|
|
1680
1726
|
}
|
|
1681
1727
|
}
|
|
1682
1728
|
prepend(nodeInfo) {
|
|
1683
|
-
const node = this.
|
|
1729
|
+
const node = this._createNode(nodeInfo);
|
|
1684
1730
|
this.addChildAtPosition(node, 0);
|
|
1685
|
-
node.
|
|
1731
|
+
node._loadChildrenFromData(nodeInfo);
|
|
1686
1732
|
return node;
|
|
1687
1733
|
}
|
|
1688
1734
|
remove() {
|
|
@@ -1699,7 +1745,7 @@ var jqtree = (function (exports) {
|
|
|
1699
1745
|
removeChild(node) {
|
|
1700
1746
|
// remove children from the index
|
|
1701
1747
|
node.removeChildren();
|
|
1702
|
-
this.
|
|
1748
|
+
this._doRemoveChild(node);
|
|
1703
1749
|
}
|
|
1704
1750
|
removeChildren() {
|
|
1705
1751
|
this.iterate(child => {
|
|
@@ -1747,25 +1793,25 @@ var jqtree = (function (exports) {
|
|
|
1747
1793
|
}
|
|
1748
1794
|
}
|
|
1749
1795
|
}
|
|
1750
|
-
|
|
1751
|
-
const nodeClass = this.
|
|
1796
|
+
_createNode(nodeData) {
|
|
1797
|
+
const nodeClass = this._getNodeClass();
|
|
1752
1798
|
return new nodeClass(nodeData);
|
|
1753
1799
|
}
|
|
1754
|
-
|
|
1800
|
+
_doRemoveChild(node) {
|
|
1755
1801
|
this.children.splice(this.getChildIndex(node), 1);
|
|
1756
1802
|
this.tree?.removeNodeFromIndex(node);
|
|
1757
1803
|
}
|
|
1758
|
-
|
|
1804
|
+
_getNodeClass() {
|
|
1759
1805
|
return this.nodeClass ?? this.tree?.nodeClass ?? Node;
|
|
1760
1806
|
}
|
|
1761
1807
|
|
|
1762
1808
|
// Load children data from nodeInfo if it has children
|
|
1763
|
-
|
|
1809
|
+
_loadChildrenFromData(nodeInfo) {
|
|
1764
1810
|
if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
|
|
1765
1811
|
this.loadFromData(nodeInfo.children);
|
|
1766
1812
|
}
|
|
1767
1813
|
}
|
|
1768
|
-
|
|
1814
|
+
_setParent(parent) {
|
|
1769
1815
|
this.parent = parent;
|
|
1770
1816
|
this.tree = parent.tree;
|
|
1771
1817
|
this.tree?.addNodeToIndex(this);
|
|
@@ -1773,10 +1819,11 @@ var jqtree = (function (exports) {
|
|
|
1773
1819
|
}
|
|
1774
1820
|
|
|
1775
1821
|
class BorderDropHint {
|
|
1822
|
+
_hint;
|
|
1776
1823
|
constructor(element, scrollLeft) {
|
|
1777
1824
|
const div = element.querySelector(":scope > .jqtree-element");
|
|
1778
1825
|
if (!div) {
|
|
1779
|
-
this.
|
|
1826
|
+
this._hint = undefined;
|
|
1780
1827
|
return;
|
|
1781
1828
|
}
|
|
1782
1829
|
const width = Math.max(element.offsetWidth + scrollLeft - 4, 0);
|
|
@@ -1785,40 +1832,43 @@ var jqtree = (function (exports) {
|
|
|
1785
1832
|
hint.className = "jqtree-border";
|
|
1786
1833
|
hint.style.width = `${width}px`;
|
|
1787
1834
|
hint.style.height = `${height}px`;
|
|
1788
|
-
this.
|
|
1789
|
-
div.append(this.
|
|
1835
|
+
this._hint = hint;
|
|
1836
|
+
div.append(this._hint);
|
|
1790
1837
|
}
|
|
1791
1838
|
remove() {
|
|
1792
|
-
this.
|
|
1839
|
+
this._hint?.remove();
|
|
1793
1840
|
}
|
|
1794
1841
|
}
|
|
1795
1842
|
|
|
1796
1843
|
class GhostDropHint {
|
|
1844
|
+
_element;
|
|
1845
|
+
_ghost;
|
|
1846
|
+
_node;
|
|
1797
1847
|
constructor(node, element, position) {
|
|
1798
|
-
this.
|
|
1799
|
-
this.
|
|
1800
|
-
this.
|
|
1848
|
+
this._element = element;
|
|
1849
|
+
this._node = node;
|
|
1850
|
+
this._ghost = this._createGhostElement();
|
|
1801
1851
|
switch (position) {
|
|
1802
1852
|
case "after":
|
|
1803
|
-
this.
|
|
1853
|
+
this._moveAfter();
|
|
1804
1854
|
break;
|
|
1805
1855
|
case "before":
|
|
1806
|
-
this.
|
|
1856
|
+
this._moveBefore();
|
|
1807
1857
|
break;
|
|
1808
1858
|
case "inside":
|
|
1809
1859
|
{
|
|
1810
1860
|
if (node.isFolder() && node.is_open) {
|
|
1811
|
-
this.
|
|
1861
|
+
this._moveInsideOpenFolder();
|
|
1812
1862
|
} else {
|
|
1813
|
-
this.
|
|
1863
|
+
this._moveInside();
|
|
1814
1864
|
}
|
|
1815
1865
|
}
|
|
1816
1866
|
}
|
|
1817
1867
|
}
|
|
1818
1868
|
remove() {
|
|
1819
|
-
this.
|
|
1869
|
+
this._ghost.remove();
|
|
1820
1870
|
}
|
|
1821
|
-
|
|
1871
|
+
_createGhostElement() {
|
|
1822
1872
|
const ghost = document.createElement("li");
|
|
1823
1873
|
ghost.className = "jqtree_common jqtree-ghost";
|
|
1824
1874
|
const circleSpan = document.createElement("span");
|
|
@@ -1829,40 +1879,44 @@ var jqtree = (function (exports) {
|
|
|
1829
1879
|
ghost.append(lineSpan);
|
|
1830
1880
|
return ghost;
|
|
1831
1881
|
}
|
|
1832
|
-
|
|
1833
|
-
this.
|
|
1882
|
+
_moveAfter() {
|
|
1883
|
+
this._element.after(this._ghost);
|
|
1834
1884
|
}
|
|
1835
|
-
|
|
1836
|
-
this.
|
|
1885
|
+
_moveBefore() {
|
|
1886
|
+
this._element.before(this._ghost);
|
|
1837
1887
|
}
|
|
1838
|
-
|
|
1839
|
-
this.
|
|
1840
|
-
this.
|
|
1888
|
+
_moveInside() {
|
|
1889
|
+
this._element.after(this._ghost);
|
|
1890
|
+
this._ghost.classList.add("jqtree-inside");
|
|
1841
1891
|
}
|
|
1842
|
-
|
|
1843
|
-
const childElement = this.
|
|
1892
|
+
_moveInsideOpenFolder() {
|
|
1893
|
+
const childElement = this._node.children[0]?.element;
|
|
1844
1894
|
if (childElement) {
|
|
1845
|
-
childElement.before(this.
|
|
1895
|
+
childElement.before(this._ghost);
|
|
1846
1896
|
}
|
|
1847
1897
|
}
|
|
1848
1898
|
}
|
|
1849
1899
|
|
|
1850
1900
|
class NodeElement {
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1901
|
+
element;
|
|
1902
|
+
node;
|
|
1903
|
+
_getScrollLeft;
|
|
1904
|
+
_tabIndex;
|
|
1905
|
+
_treeElement;
|
|
1906
|
+
constructor({
|
|
1907
|
+
getScrollLeft,
|
|
1908
|
+
node,
|
|
1909
|
+
tabIndex,
|
|
1910
|
+
treeElement
|
|
1911
|
+
}) {
|
|
1912
|
+
this._getScrollLeft = getScrollLeft;
|
|
1913
|
+
this._tabIndex = tabIndex;
|
|
1914
|
+
this._treeElement = treeElement;
|
|
1861
1915
|
this.init(node);
|
|
1862
1916
|
}
|
|
1863
1917
|
addDropHint(position) {
|
|
1864
1918
|
if (this.mustShowBorderDropHint(position)) {
|
|
1865
|
-
return new BorderDropHint(this.element, this.
|
|
1919
|
+
return new BorderDropHint(this.element, this._getScrollLeft());
|
|
1866
1920
|
} else {
|
|
1867
1921
|
return new GhostDropHint(this.node, this.element, position);
|
|
1868
1922
|
}
|
|
@@ -1876,15 +1930,13 @@ var jqtree = (function (exports) {
|
|
|
1876
1930
|
}
|
|
1877
1931
|
init(node) {
|
|
1878
1932
|
this.node = node;
|
|
1879
|
-
|
|
1880
|
-
node.element = this.treeElement;
|
|
1881
|
-
}
|
|
1933
|
+
node.element ??= this._treeElement;
|
|
1882
1934
|
this.element = node.element;
|
|
1883
1935
|
}
|
|
1884
1936
|
select(mustSetFocus) {
|
|
1885
1937
|
this.element.classList.add("jqtree-selected");
|
|
1886
1938
|
const titleSpan = this.getTitleSpan();
|
|
1887
|
-
const tabIndex = this.
|
|
1939
|
+
const tabIndex = this._tabIndex;
|
|
1888
1940
|
|
|
1889
1941
|
// Check for null or undefined
|
|
1890
1942
|
if (tabIndex != null) {
|
|
@@ -1906,36 +1958,75 @@ var jqtree = (function (exports) {
|
|
|
1906
1958
|
}
|
|
1907
1959
|
}
|
|
1908
1960
|
|
|
1961
|
+
const getAnimationDuration = duration => {
|
|
1962
|
+
if (typeof duration === "number") {
|
|
1963
|
+
return duration;
|
|
1964
|
+
}
|
|
1965
|
+
return duration === "slow" ? 600 : 200;
|
|
1966
|
+
};
|
|
1967
|
+
const slideDown = (element, animationSpeed, onFinished) => {
|
|
1968
|
+
element.style.display = "block";
|
|
1969
|
+
const animation = element.animate([{
|
|
1970
|
+
height: "0",
|
|
1971
|
+
overflow: "hidden"
|
|
1972
|
+
}, {
|
|
1973
|
+
height: `${element.scrollHeight}px`,
|
|
1974
|
+
overflow: "hidden"
|
|
1975
|
+
}], {
|
|
1976
|
+
duration: getAnimationDuration(animationSpeed)
|
|
1977
|
+
});
|
|
1978
|
+
animation.onfinish = () => {
|
|
1979
|
+
onFinished();
|
|
1980
|
+
};
|
|
1981
|
+
};
|
|
1982
|
+
const slideUp = (element, animationSpeed, onFinished) => {
|
|
1983
|
+
const animation = element.animate([{
|
|
1984
|
+
height: `${element.scrollHeight}px`,
|
|
1985
|
+
overflow: "hidden"
|
|
1986
|
+
}, {
|
|
1987
|
+
height: "0",
|
|
1988
|
+
overflow: "hidden"
|
|
1989
|
+
}], {
|
|
1990
|
+
duration: getAnimationDuration(animationSpeed)
|
|
1991
|
+
});
|
|
1992
|
+
animation.onfinish = () => {
|
|
1993
|
+
element.style.display = "none";
|
|
1994
|
+
onFinished();
|
|
1995
|
+
};
|
|
1996
|
+
};
|
|
1997
|
+
|
|
1909
1998
|
class FolderElement extends NodeElement {
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1999
|
+
_closedIconElement;
|
|
2000
|
+
_openedIconElement;
|
|
2001
|
+
_triggerEvent;
|
|
2002
|
+
constructor({
|
|
2003
|
+
closedIconElement,
|
|
2004
|
+
getScrollLeft,
|
|
2005
|
+
node,
|
|
2006
|
+
openedIconElement,
|
|
2007
|
+
tabIndex,
|
|
2008
|
+
treeElement,
|
|
2009
|
+
triggerEvent
|
|
2010
|
+
}) {
|
|
1920
2011
|
super({
|
|
1921
2012
|
getScrollLeft,
|
|
1922
2013
|
node,
|
|
1923
2014
|
tabIndex,
|
|
1924
2015
|
treeElement
|
|
1925
2016
|
});
|
|
1926
|
-
this.
|
|
1927
|
-
this.
|
|
1928
|
-
this.
|
|
2017
|
+
this._closedIconElement = closedIconElement;
|
|
2018
|
+
this._openedIconElement = openedIconElement;
|
|
2019
|
+
this._triggerEvent = triggerEvent;
|
|
1929
2020
|
}
|
|
1930
2021
|
close(slide, animationSpeed) {
|
|
1931
2022
|
if (!this.node.is_open) {
|
|
1932
2023
|
return;
|
|
1933
2024
|
}
|
|
1934
2025
|
this.node.is_open = false;
|
|
1935
|
-
const button = this.
|
|
2026
|
+
const button = this._getButton();
|
|
1936
2027
|
button.classList.add("jqtree-closed");
|
|
1937
2028
|
button.innerHTML = "";
|
|
1938
|
-
const closedIconElement = this.
|
|
2029
|
+
const closedIconElement = this._closedIconElement;
|
|
1939
2030
|
if (closedIconElement) {
|
|
1940
2031
|
const icon = closedIconElement.cloneNode(true);
|
|
1941
2032
|
button.appendChild(icon);
|
|
@@ -1944,14 +2035,15 @@ var jqtree = (function (exports) {
|
|
|
1944
2035
|
this.element.classList.add("jqtree-closed");
|
|
1945
2036
|
const titleSpan = this.getTitleSpan();
|
|
1946
2037
|
titleSpan.setAttribute("aria-expanded", "false");
|
|
1947
|
-
this.
|
|
2038
|
+
this._triggerEvent("tree.close", {
|
|
1948
2039
|
node: this.node
|
|
1949
2040
|
});
|
|
1950
2041
|
};
|
|
2042
|
+
const ul = this.getUl();
|
|
1951
2043
|
if (slide) {
|
|
1952
|
-
|
|
2044
|
+
slideUp(ul, animationSpeed, doClose);
|
|
1953
2045
|
} else {
|
|
1954
|
-
|
|
2046
|
+
ul.style.display = "none";
|
|
1955
2047
|
doClose();
|
|
1956
2048
|
}
|
|
1957
2049
|
}
|
|
@@ -1960,10 +2052,10 @@ var jqtree = (function (exports) {
|
|
|
1960
2052
|
return;
|
|
1961
2053
|
}
|
|
1962
2054
|
this.node.is_open = true;
|
|
1963
|
-
const button = this.
|
|
2055
|
+
const button = this._getButton();
|
|
1964
2056
|
button.classList.remove("jqtree-closed");
|
|
1965
2057
|
button.innerHTML = "";
|
|
1966
|
-
const openedIconElement = this.
|
|
2058
|
+
const openedIconElement = this._openedIconElement;
|
|
1967
2059
|
if (openedIconElement) {
|
|
1968
2060
|
const icon = openedIconElement.cloneNode(true);
|
|
1969
2061
|
button.appendChild(icon);
|
|
@@ -1975,49 +2067,59 @@ var jqtree = (function (exports) {
|
|
|
1975
2067
|
if (onFinished) {
|
|
1976
2068
|
onFinished(this.node);
|
|
1977
2069
|
}
|
|
1978
|
-
this.
|
|
2070
|
+
this._triggerEvent("tree.open", {
|
|
1979
2071
|
node: this.node
|
|
1980
2072
|
});
|
|
1981
2073
|
};
|
|
2074
|
+
const ul = this.getUl();
|
|
1982
2075
|
if (slide) {
|
|
1983
|
-
|
|
2076
|
+
slideDown(ul, animationSpeed, doOpen);
|
|
1984
2077
|
} else {
|
|
1985
|
-
|
|
2078
|
+
ul.style.display = "block";
|
|
1986
2079
|
doOpen();
|
|
1987
2080
|
}
|
|
1988
2081
|
}
|
|
1989
2082
|
mustShowBorderDropHint(position) {
|
|
1990
2083
|
return !this.node.is_open && position === "inside";
|
|
1991
2084
|
}
|
|
1992
|
-
|
|
2085
|
+
_getButton() {
|
|
1993
2086
|
return this.element.querySelector(":scope > .jqtree-element > a.jqtree-toggler");
|
|
1994
2087
|
}
|
|
1995
2088
|
}
|
|
1996
2089
|
|
|
1997
2090
|
class SaveStateHandler {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
this.
|
|
2091
|
+
_addToSelection;
|
|
2092
|
+
_getNodeById;
|
|
2093
|
+
_getSelectedNodes;
|
|
2094
|
+
_getTree;
|
|
2095
|
+
_onGetStateFromStorage;
|
|
2096
|
+
_onSetStateFromStorage;
|
|
2097
|
+
_openNode;
|
|
2098
|
+
_refreshElements;
|
|
2099
|
+
_removeFromSelection;
|
|
2100
|
+
_saveStateOption;
|
|
2101
|
+
constructor({
|
|
2102
|
+
addToSelection,
|
|
2103
|
+
getNodeById,
|
|
2104
|
+
getSelectedNodes,
|
|
2105
|
+
getTree,
|
|
2106
|
+
onGetStateFromStorage,
|
|
2107
|
+
onSetStateFromStorage,
|
|
2108
|
+
openNode,
|
|
2109
|
+
refreshElements,
|
|
2110
|
+
removeFromSelection,
|
|
2111
|
+
saveState
|
|
2112
|
+
}) {
|
|
2113
|
+
this._addToSelection = addToSelection;
|
|
2114
|
+
this._getNodeById = getNodeById;
|
|
2115
|
+
this._getSelectedNodes = getSelectedNodes;
|
|
2116
|
+
this._getTree = getTree;
|
|
2117
|
+
this._onGetStateFromStorage = onGetStateFromStorage;
|
|
2118
|
+
this._onSetStateFromStorage = onSetStateFromStorage;
|
|
2119
|
+
this._openNode = openNode;
|
|
2120
|
+
this._refreshElements = refreshElements;
|
|
2121
|
+
this._removeFromSelection = removeFromSelection;
|
|
2122
|
+
this._saveStateOption = saveState;
|
|
2021
2123
|
}
|
|
2022
2124
|
getNodeIdToBeSelected() {
|
|
2023
2125
|
const state = this.getStateFromStorage();
|
|
@@ -2030,7 +2132,7 @@ var jqtree = (function (exports) {
|
|
|
2030
2132
|
getState() {
|
|
2031
2133
|
const getOpenNodeIds = () => {
|
|
2032
2134
|
const openNodes = [];
|
|
2033
|
-
this.
|
|
2135
|
+
this._getTree()?.iterate(node => {
|
|
2034
2136
|
if (node.is_open && node.id && node.hasChildren()) {
|
|
2035
2137
|
openNodes.push(node.id);
|
|
2036
2138
|
}
|
|
@@ -2040,7 +2142,7 @@ var jqtree = (function (exports) {
|
|
|
2040
2142
|
};
|
|
2041
2143
|
const getSelectedNodeIds = () => {
|
|
2042
2144
|
const selectedNodeIds = [];
|
|
2043
|
-
this.
|
|
2145
|
+
this._getSelectedNodes().forEach(node => {
|
|
2044
2146
|
if (node.id != null) {
|
|
2045
2147
|
selectedNodeIds.push(node.id);
|
|
2046
2148
|
}
|
|
@@ -2053,19 +2155,19 @@ var jqtree = (function (exports) {
|
|
|
2053
2155
|
};
|
|
2054
2156
|
}
|
|
2055
2157
|
getStateFromStorage() {
|
|
2056
|
-
const jsonData = this.
|
|
2158
|
+
const jsonData = this._loadFromStorage();
|
|
2057
2159
|
if (jsonData) {
|
|
2058
|
-
return this.
|
|
2160
|
+
return this._parseState(jsonData);
|
|
2059
2161
|
} else {
|
|
2060
2162
|
return null;
|
|
2061
2163
|
}
|
|
2062
2164
|
}
|
|
2063
2165
|
saveState() {
|
|
2064
2166
|
const state = JSON.stringify(this.getState());
|
|
2065
|
-
if (this.
|
|
2066
|
-
this.
|
|
2167
|
+
if (this._onSetStateFromStorage) {
|
|
2168
|
+
this._onSetStateFromStorage(state);
|
|
2067
2169
|
} else {
|
|
2068
|
-
localStorage.setItem(this.
|
|
2170
|
+
localStorage.setItem(this._getKeyName(), state);
|
|
2069
2171
|
}
|
|
2070
2172
|
}
|
|
2071
2173
|
|
|
@@ -2077,11 +2179,11 @@ var jqtree = (function (exports) {
|
|
|
2077
2179
|
setInitialState(state) {
|
|
2078
2180
|
let mustLoadOnDemand = false;
|
|
2079
2181
|
if (state.open_nodes) {
|
|
2080
|
-
mustLoadOnDemand = this.
|
|
2182
|
+
mustLoadOnDemand = this._openInitialNodes(state.open_nodes);
|
|
2081
2183
|
}
|
|
2082
|
-
this.
|
|
2184
|
+
this._resetSelection();
|
|
2083
2185
|
if (state.selected_node) {
|
|
2084
|
-
this.
|
|
2186
|
+
this._selectInitialNodes(state.selected_node);
|
|
2085
2187
|
}
|
|
2086
2188
|
return mustLoadOnDemand;
|
|
2087
2189
|
}
|
|
@@ -2094,7 +2196,7 @@ var jqtree = (function (exports) {
|
|
|
2094
2196
|
}
|
|
2095
2197
|
const newNodesIds = [];
|
|
2096
2198
|
for (const nodeId of nodeIds) {
|
|
2097
|
-
const node = this.
|
|
2199
|
+
const node = this._getNodeById(nodeId);
|
|
2098
2200
|
if (!node) {
|
|
2099
2201
|
newNodesIds.push(nodeId);
|
|
2100
2202
|
} else {
|
|
@@ -2102,15 +2204,15 @@ var jqtree = (function (exports) {
|
|
|
2102
2204
|
if (node.load_on_demand) {
|
|
2103
2205
|
loadAndOpenNode(node);
|
|
2104
2206
|
} else {
|
|
2105
|
-
this.
|
|
2207
|
+
this._openNode(node, false);
|
|
2106
2208
|
}
|
|
2107
2209
|
}
|
|
2108
2210
|
}
|
|
2109
2211
|
}
|
|
2110
2212
|
nodeIds = newNodesIds;
|
|
2111
2213
|
if (state.selected_node) {
|
|
2112
|
-
if (this.
|
|
2113
|
-
this.
|
|
2214
|
+
if (this._selectInitialNodes(state.selected_node)) {
|
|
2215
|
+
this._refreshElements(null);
|
|
2114
2216
|
}
|
|
2115
2217
|
}
|
|
2116
2218
|
if (loadingCount === 0) {
|
|
@@ -2119,31 +2221,31 @@ var jqtree = (function (exports) {
|
|
|
2119
2221
|
};
|
|
2120
2222
|
const loadAndOpenNode = node => {
|
|
2121
2223
|
loadingCount += 1;
|
|
2122
|
-
this.
|
|
2224
|
+
this._openNode(node, false, () => {
|
|
2123
2225
|
loadingCount -= 1;
|
|
2124
2226
|
openNodes();
|
|
2125
2227
|
});
|
|
2126
2228
|
};
|
|
2127
2229
|
openNodes();
|
|
2128
2230
|
}
|
|
2129
|
-
|
|
2130
|
-
if (typeof this.
|
|
2131
|
-
return this.
|
|
2231
|
+
_getKeyName() {
|
|
2232
|
+
if (typeof this._saveStateOption === "string") {
|
|
2233
|
+
return this._saveStateOption;
|
|
2132
2234
|
} else {
|
|
2133
2235
|
return "tree";
|
|
2134
2236
|
}
|
|
2135
2237
|
}
|
|
2136
|
-
|
|
2137
|
-
if (this.
|
|
2138
|
-
return this.
|
|
2238
|
+
_loadFromStorage() {
|
|
2239
|
+
if (this._onGetStateFromStorage) {
|
|
2240
|
+
return this._onGetStateFromStorage();
|
|
2139
2241
|
} else {
|
|
2140
|
-
return localStorage.getItem(this.
|
|
2242
|
+
return localStorage.getItem(this._getKeyName());
|
|
2141
2243
|
}
|
|
2142
2244
|
}
|
|
2143
|
-
|
|
2245
|
+
_openInitialNodes(nodeIds) {
|
|
2144
2246
|
let mustLoadOnDemand = false;
|
|
2145
2247
|
for (const nodeId of nodeIds) {
|
|
2146
|
-
const node = this.
|
|
2248
|
+
const node = this._getNodeById(nodeId);
|
|
2147
2249
|
if (node) {
|
|
2148
2250
|
if (!node.load_on_demand) {
|
|
2149
2251
|
node.is_open = true;
|
|
@@ -2154,7 +2256,7 @@ var jqtree = (function (exports) {
|
|
|
2154
2256
|
}
|
|
2155
2257
|
return mustLoadOnDemand;
|
|
2156
2258
|
}
|
|
2157
|
-
|
|
2259
|
+
_parseState(jsonData) {
|
|
2158
2260
|
const state = JSON.parse(jsonData);
|
|
2159
2261
|
|
|
2160
2262
|
// Check if selected_node is an int (instead of an array)
|
|
@@ -2164,31 +2266,36 @@ var jqtree = (function (exports) {
|
|
|
2164
2266
|
}
|
|
2165
2267
|
return state;
|
|
2166
2268
|
}
|
|
2167
|
-
|
|
2168
|
-
const selectedNodes = this.
|
|
2269
|
+
_resetSelection() {
|
|
2270
|
+
const selectedNodes = this._getSelectedNodes();
|
|
2169
2271
|
selectedNodes.forEach(node => {
|
|
2170
|
-
this.
|
|
2272
|
+
this._removeFromSelection(node);
|
|
2171
2273
|
});
|
|
2172
2274
|
}
|
|
2173
|
-
|
|
2275
|
+
_selectInitialNodes(nodeIds) {
|
|
2174
2276
|
let selectCount = 0;
|
|
2175
2277
|
for (const nodeId of nodeIds) {
|
|
2176
|
-
const node = this.
|
|
2278
|
+
const node = this._getNodeById(nodeId);
|
|
2177
2279
|
if (node) {
|
|
2178
2280
|
selectCount += 1;
|
|
2179
|
-
this.
|
|
2281
|
+
this._addToSelection(node);
|
|
2180
2282
|
}
|
|
2181
2283
|
}
|
|
2182
2284
|
return selectCount !== 0;
|
|
2183
2285
|
}
|
|
2184
2286
|
}
|
|
2185
2287
|
|
|
2186
|
-
class
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2288
|
+
class ScrollParent {
|
|
2289
|
+
container;
|
|
2290
|
+
horizontalScrollDirection;
|
|
2291
|
+
horizontalScrollTimeout;
|
|
2292
|
+
refreshHitAreas;
|
|
2293
|
+
verticalScrollDirection;
|
|
2294
|
+
verticalScrollTimeout;
|
|
2295
|
+
constructor({
|
|
2296
|
+
container,
|
|
2297
|
+
refreshHitAreas
|
|
2298
|
+
}) {
|
|
2192
2299
|
this.container = container;
|
|
2193
2300
|
this.refreshHitAreas = refreshHitAreas;
|
|
2194
2301
|
}
|
|
@@ -2197,7 +2304,7 @@ var jqtree = (function (exports) {
|
|
|
2197
2304
|
if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
|
|
2198
2305
|
this.horizontalScrollDirection = newHorizontalScrollDirection;
|
|
2199
2306
|
if (this.horizontalScrollTimeout != null) {
|
|
2200
|
-
window.clearTimeout(this.
|
|
2307
|
+
window.clearTimeout(this.horizontalScrollTimeout);
|
|
2201
2308
|
}
|
|
2202
2309
|
if (newHorizontalScrollDirection) {
|
|
2203
2310
|
this.horizontalScrollTimeout = window.setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
@@ -2226,42 +2333,6 @@ var jqtree = (function (exports) {
|
|
|
2226
2333
|
stopScrolling() {
|
|
2227
2334
|
this.horizontalScrollDirection = undefined;
|
|
2228
2335
|
this.verticalScrollDirection = undefined;
|
|
2229
|
-
this.scrollParentTop = undefined;
|
|
2230
|
-
this.scrollParentBottom = undefined;
|
|
2231
|
-
}
|
|
2232
|
-
getNewHorizontalScrollDirection(pageX) {
|
|
2233
|
-
const scrollParentOffset = getElementPosition(this.container);
|
|
2234
|
-
const rightEdge = scrollParentOffset.left + this.container.clientWidth;
|
|
2235
|
-
const leftEdge = scrollParentOffset.left;
|
|
2236
|
-
const isNearRightEdge = pageX > rightEdge - 20;
|
|
2237
|
-
const isNearLeftEdge = pageX < leftEdge + 20;
|
|
2238
|
-
if (isNearRightEdge) {
|
|
2239
|
-
return "right";
|
|
2240
|
-
} else if (isNearLeftEdge) {
|
|
2241
|
-
return "left";
|
|
2242
|
-
}
|
|
2243
|
-
return undefined;
|
|
2244
|
-
}
|
|
2245
|
-
getNewVerticalScrollDirection(pageY) {
|
|
2246
|
-
if (pageY < this.getScrollParentTop()) {
|
|
2247
|
-
return "top";
|
|
2248
|
-
}
|
|
2249
|
-
if (pageY > this.getScrollParentBottom()) {
|
|
2250
|
-
return "bottom";
|
|
2251
|
-
}
|
|
2252
|
-
return undefined;
|
|
2253
|
-
}
|
|
2254
|
-
getScrollParentBottom() {
|
|
2255
|
-
if (this.scrollParentBottom == null) {
|
|
2256
|
-
this.scrollParentBottom = this.getScrollParentTop() + this.container.clientHeight;
|
|
2257
|
-
}
|
|
2258
|
-
return this.scrollParentBottom;
|
|
2259
|
-
}
|
|
2260
|
-
getScrollParentTop() {
|
|
2261
|
-
if (this.scrollParentTop == null) {
|
|
2262
|
-
this.scrollParentTop = getOffsetTop(this.container);
|
|
2263
|
-
}
|
|
2264
|
-
return this.scrollParentTop;
|
|
2265
2336
|
}
|
|
2266
2337
|
scrollHorizontally() {
|
|
2267
2338
|
if (!this.horizontalScrollDirection) {
|
|
@@ -2291,81 +2362,79 @@ var jqtree = (function (exports) {
|
|
|
2291
2362
|
}
|
|
2292
2363
|
}
|
|
2293
2364
|
|
|
2294
|
-
class
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
this.
|
|
2301
|
-
this.treeElement = treeElement;
|
|
2365
|
+
class ContainerScrollParent extends ScrollParent {
|
|
2366
|
+
_scrollParentBottom;
|
|
2367
|
+
_scrollParentTop;
|
|
2368
|
+
stopScrolling() {
|
|
2369
|
+
super.stopScrolling();
|
|
2370
|
+
this.horizontalScrollDirection = undefined;
|
|
2371
|
+
this.verticalScrollDirection = undefined;
|
|
2302
2372
|
}
|
|
2303
|
-
|
|
2304
|
-
const
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2373
|
+
getNewHorizontalScrollDirection(pageX) {
|
|
2374
|
+
const scrollParentOffset = getElementPosition(this.container);
|
|
2375
|
+
const containerWidth = this.container.getBoundingClientRect().width;
|
|
2376
|
+
const rightEdge = scrollParentOffset.left + containerWidth;
|
|
2377
|
+
const leftEdge = scrollParentOffset.left;
|
|
2378
|
+
const isNearRightEdge = pageX > rightEdge - 20;
|
|
2379
|
+
const isNearLeftEdge = pageX < leftEdge + 20;
|
|
2380
|
+
if (isNearRightEdge) {
|
|
2381
|
+
return "right";
|
|
2382
|
+
} else if (isNearLeftEdge) {
|
|
2383
|
+
return "left";
|
|
2313
2384
|
}
|
|
2385
|
+
return undefined;
|
|
2314
2386
|
}
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
this.verticalScrollDirection = newVerticalScrollDirection;
|
|
2319
|
-
if (this.verticalScrollTimeout != null) {
|
|
2320
|
-
window.clearTimeout(this.verticalScrollTimeout);
|
|
2321
|
-
this.verticalScrollTimeout = undefined;
|
|
2322
|
-
}
|
|
2323
|
-
if (newVerticalScrollDirection) {
|
|
2324
|
-
this.verticalScrollTimeout = window.setTimeout(this.scrollVertically.bind(this), 40);
|
|
2325
|
-
}
|
|
2387
|
+
getNewVerticalScrollDirection(pageY) {
|
|
2388
|
+
if (pageY < this._getScrollParentTop()) {
|
|
2389
|
+
return "top";
|
|
2326
2390
|
}
|
|
2391
|
+
if (pageY > this._getScrollParentBottom()) {
|
|
2392
|
+
return "bottom";
|
|
2393
|
+
}
|
|
2394
|
+
return undefined;
|
|
2327
2395
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
}
|
|
2335
|
-
stopScrolling() {
|
|
2336
|
-
this.horizontalScrollDirection = undefined;
|
|
2337
|
-
this.verticalScrollDirection = undefined;
|
|
2338
|
-
this.documentScrollHeight = undefined;
|
|
2339
|
-
this.documentScrollWidth = undefined;
|
|
2396
|
+
_getScrollParentBottom() {
|
|
2397
|
+
if (this._scrollParentBottom == null) {
|
|
2398
|
+
const containerHeight = this.container.getBoundingClientRect().height;
|
|
2399
|
+
this._scrollParentBottom = this._getScrollParentTop() + containerHeight;
|
|
2400
|
+
}
|
|
2401
|
+
return this._scrollParentBottom;
|
|
2340
2402
|
}
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
return
|
|
2403
|
+
_getScrollParentTop() {
|
|
2404
|
+
this._scrollParentTop ??= getOffsetTop(this.container);
|
|
2405
|
+
return this._scrollParentTop;
|
|
2344
2406
|
}
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
class DocumentScrollParent extends ScrollParent {
|
|
2410
|
+
_documentScrollHeight;
|
|
2411
|
+
_documentScrollWidth;
|
|
2412
|
+
_treeElement;
|
|
2413
|
+
constructor({
|
|
2414
|
+
refreshHitAreas,
|
|
2415
|
+
treeElement
|
|
2416
|
+
}) {
|
|
2417
|
+
super({
|
|
2418
|
+
container: document.documentElement,
|
|
2419
|
+
refreshHitAreas
|
|
2420
|
+
});
|
|
2421
|
+
this._treeElement = treeElement;
|
|
2348
2422
|
}
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
this.documentScrollHeight = document.documentElement.scrollHeight;
|
|
2353
|
-
}
|
|
2354
|
-
return this.documentScrollHeight;
|
|
2423
|
+
scrollToY(top) {
|
|
2424
|
+
const treeTop = getOffsetTop(this._treeElement);
|
|
2425
|
+
super.scrollToY(top + treeTop);
|
|
2355
2426
|
}
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
}
|
|
2361
|
-
return this.documentScrollWidth;
|
|
2427
|
+
stopScrolling() {
|
|
2428
|
+
super.stopScrolling();
|
|
2429
|
+
this._documentScrollHeight = undefined;
|
|
2430
|
+
this._documentScrollWidth = undefined;
|
|
2362
2431
|
}
|
|
2363
2432
|
getNewHorizontalScrollDirection(pageX) {
|
|
2364
|
-
const scrollLeft =
|
|
2433
|
+
const scrollLeft = this.container.scrollLeft;
|
|
2365
2434
|
const windowWidth = window.innerWidth;
|
|
2366
2435
|
const isNearRightEdge = pageX > windowWidth - 20;
|
|
2367
2436
|
const isNearLeftEdge = pageX - scrollLeft < 20;
|
|
2368
|
-
if (isNearRightEdge && this.
|
|
2437
|
+
if (isNearRightEdge && this._canScrollRight()) {
|
|
2369
2438
|
return "right";
|
|
2370
2439
|
}
|
|
2371
2440
|
if (isNearLeftEdge) {
|
|
@@ -2374,42 +2443,32 @@ var jqtree = (function (exports) {
|
|
|
2374
2443
|
return undefined;
|
|
2375
2444
|
}
|
|
2376
2445
|
getNewVerticalScrollDirection(pageY) {
|
|
2377
|
-
const scrollTop =
|
|
2446
|
+
const scrollTop = this.container.scrollTop;
|
|
2378
2447
|
const distanceTop = pageY - scrollTop;
|
|
2379
2448
|
if (distanceTop < 20) {
|
|
2380
2449
|
return "top";
|
|
2381
2450
|
}
|
|
2382
2451
|
const windowHeight = window.innerHeight;
|
|
2383
|
-
if (windowHeight - (pageY - scrollTop) < 20 && this.
|
|
2452
|
+
if (windowHeight - (pageY - scrollTop) < 20 && this._canScrollDown()) {
|
|
2384
2453
|
return "bottom";
|
|
2385
2454
|
}
|
|
2386
2455
|
return undefined;
|
|
2387
2456
|
}
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
return;
|
|
2391
|
-
}
|
|
2392
|
-
const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
|
|
2393
|
-
window.scrollBy({
|
|
2394
|
-
behavior: "instant",
|
|
2395
|
-
left: distance,
|
|
2396
|
-
top: 0
|
|
2397
|
-
});
|
|
2398
|
-
this.refreshHitAreas();
|
|
2399
|
-
setTimeout(this.scrollHorizontally.bind(this), 40);
|
|
2457
|
+
_canScrollDown() {
|
|
2458
|
+
return this.container.scrollTop + this.container.clientHeight < this._getDocumentScrollHeight();
|
|
2400
2459
|
}
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
this.
|
|
2412
|
-
|
|
2460
|
+
_canScrollRight() {
|
|
2461
|
+
return this.container.scrollLeft + this.container.clientWidth < this._getDocumentScrollWidth();
|
|
2462
|
+
}
|
|
2463
|
+
_getDocumentScrollHeight() {
|
|
2464
|
+
// Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
|
|
2465
|
+
this._documentScrollHeight ??= this.container.scrollHeight;
|
|
2466
|
+
return this._documentScrollHeight;
|
|
2467
|
+
}
|
|
2468
|
+
_getDocumentScrollWidth() {
|
|
2469
|
+
// Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
|
|
2470
|
+
this._documentScrollWidth ??= this.container.scrollWidth;
|
|
2471
|
+
return this._documentScrollWidth;
|
|
2413
2472
|
}
|
|
2414
2473
|
}
|
|
2415
2474
|
|
|
@@ -2447,61 +2506,63 @@ var jqtree = (function (exports) {
|
|
|
2447
2506
|
};
|
|
2448
2507
|
|
|
2449
2508
|
class ScrollHandler {
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
this.
|
|
2509
|
+
_refreshHitAreas;
|
|
2510
|
+
_scrollParent;
|
|
2511
|
+
_treeElement;
|
|
2512
|
+
constructor({
|
|
2513
|
+
refreshHitAreas,
|
|
2514
|
+
treeElement
|
|
2515
|
+
}) {
|
|
2516
|
+
this._refreshHitAreas = refreshHitAreas;
|
|
2517
|
+
this._scrollParent = undefined;
|
|
2518
|
+
this._treeElement = treeElement;
|
|
2458
2519
|
}
|
|
2459
2520
|
checkScrolling(positionInfo) {
|
|
2460
|
-
this.
|
|
2461
|
-
this.
|
|
2521
|
+
this._checkVerticalScrolling(positionInfo);
|
|
2522
|
+
this._checkHorizontalScrolling(positionInfo);
|
|
2462
2523
|
}
|
|
2463
2524
|
getScrollLeft() {
|
|
2464
|
-
return this.
|
|
2525
|
+
return this._getScrollParent().getScrollLeft();
|
|
2465
2526
|
}
|
|
2466
2527
|
scrollToY(top) {
|
|
2467
|
-
this.
|
|
2528
|
+
this._getScrollParent().scrollToY(top);
|
|
2468
2529
|
}
|
|
2469
2530
|
stopScrolling() {
|
|
2470
|
-
this.
|
|
2531
|
+
this._getScrollParent().stopScrolling();
|
|
2471
2532
|
}
|
|
2472
|
-
|
|
2473
|
-
this.
|
|
2533
|
+
_checkHorizontalScrolling(positionInfo) {
|
|
2534
|
+
this._getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
|
|
2474
2535
|
}
|
|
2475
|
-
|
|
2476
|
-
this.
|
|
2536
|
+
_checkVerticalScrolling(positionInfo) {
|
|
2537
|
+
this._getScrollParent().checkVerticalScrolling(positionInfo.pageY);
|
|
2477
2538
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
}
|
|
2482
|
-
return this.scrollParent;
|
|
2539
|
+
_getScrollParent() {
|
|
2540
|
+
this._scrollParent ??= createScrollParent(this._treeElement, this._refreshHitAreas);
|
|
2541
|
+
return this._scrollParent;
|
|
2483
2542
|
}
|
|
2484
2543
|
}
|
|
2485
2544
|
|
|
2486
2545
|
class SelectNodeHandler {
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2546
|
+
_getNodeById;
|
|
2547
|
+
_selectedNodes;
|
|
2548
|
+
_selectedSingleNode;
|
|
2549
|
+
constructor({
|
|
2550
|
+
getNodeById
|
|
2551
|
+
}) {
|
|
2552
|
+
this._getNodeById = getNodeById;
|
|
2553
|
+
this._selectedNodes = new Set();
|
|
2493
2554
|
this.clear();
|
|
2494
2555
|
}
|
|
2495
2556
|
addToSelection(node) {
|
|
2496
2557
|
if (node.id != null) {
|
|
2497
|
-
this.
|
|
2558
|
+
this._selectedNodes.add(node.id);
|
|
2498
2559
|
} else {
|
|
2499
|
-
this.
|
|
2560
|
+
this._selectedSingleNode = node;
|
|
2500
2561
|
}
|
|
2501
2562
|
}
|
|
2502
2563
|
clear() {
|
|
2503
|
-
this.
|
|
2504
|
-
this.
|
|
2564
|
+
this._selectedNodes.clear();
|
|
2565
|
+
this._selectedSingleNode = null;
|
|
2505
2566
|
}
|
|
2506
2567
|
getSelectedNode() {
|
|
2507
2568
|
const selectedNodes = this.getSelectedNodes();
|
|
@@ -2512,12 +2573,12 @@ var jqtree = (function (exports) {
|
|
|
2512
2573
|
}
|
|
2513
2574
|
}
|
|
2514
2575
|
getSelectedNodes() {
|
|
2515
|
-
if (this.
|
|
2516
|
-
return [this.
|
|
2576
|
+
if (this._selectedSingleNode) {
|
|
2577
|
+
return [this._selectedSingleNode];
|
|
2517
2578
|
} else {
|
|
2518
2579
|
const selectedNodes = [];
|
|
2519
|
-
this.
|
|
2520
|
-
const node = this.
|
|
2580
|
+
this._selectedNodes.forEach(id => {
|
|
2581
|
+
const node = this._getNodeById(id);
|
|
2521
2582
|
if (node) {
|
|
2522
2583
|
selectedNodes.push(node);
|
|
2523
2584
|
}
|
|
@@ -2526,16 +2587,16 @@ var jqtree = (function (exports) {
|
|
|
2526
2587
|
}
|
|
2527
2588
|
}
|
|
2528
2589
|
getSelectedNodesUnder(parent) {
|
|
2529
|
-
if (this.
|
|
2530
|
-
if (parent.isParentOf(this.
|
|
2531
|
-
return [this.
|
|
2590
|
+
if (this._selectedSingleNode) {
|
|
2591
|
+
if (parent.isParentOf(this._selectedSingleNode)) {
|
|
2592
|
+
return [this._selectedSingleNode];
|
|
2532
2593
|
} else {
|
|
2533
2594
|
return [];
|
|
2534
2595
|
}
|
|
2535
2596
|
} else {
|
|
2536
2597
|
const selectedNodes = [];
|
|
2537
|
-
this.
|
|
2538
|
-
const node = this.
|
|
2598
|
+
this._selectedNodes.forEach(id => {
|
|
2599
|
+
const node = this._getNodeById(id);
|
|
2539
2600
|
if (node && parent.isParentOf(node)) {
|
|
2540
2601
|
selectedNodes.push(node);
|
|
2541
2602
|
}
|
|
@@ -2545,25 +2606,24 @@ var jqtree = (function (exports) {
|
|
|
2545
2606
|
}
|
|
2546
2607
|
isNodeSelected(node) {
|
|
2547
2608
|
if (node.id != null) {
|
|
2548
|
-
return this.
|
|
2549
|
-
} else if (this.
|
|
2550
|
-
return this.
|
|
2609
|
+
return this._selectedNodes.has(node.id);
|
|
2610
|
+
} else if (this._selectedSingleNode) {
|
|
2611
|
+
return this._selectedSingleNode.element === node.element;
|
|
2551
2612
|
} else {
|
|
2552
2613
|
return false;
|
|
2553
2614
|
}
|
|
2554
2615
|
}
|
|
2555
|
-
removeFromSelection(node) {
|
|
2556
|
-
let includeChildren = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2616
|
+
removeFromSelection(node, includeChildren = false) {
|
|
2557
2617
|
if (node.id == null) {
|
|
2558
|
-
if (this.
|
|
2559
|
-
this.
|
|
2618
|
+
if (this._selectedSingleNode && node.element === this._selectedSingleNode.element) {
|
|
2619
|
+
this._selectedSingleNode = null;
|
|
2560
2620
|
}
|
|
2561
2621
|
} else {
|
|
2562
|
-
this.
|
|
2622
|
+
this._selectedNodes.delete(node.id);
|
|
2563
2623
|
if (includeChildren) {
|
|
2564
2624
|
node.iterate(() => {
|
|
2565
2625
|
if (node.id != null) {
|
|
2566
|
-
this.
|
|
2626
|
+
this._selectedNodes.delete(node.id);
|
|
2567
2627
|
}
|
|
2568
2628
|
return true;
|
|
2569
2629
|
});
|
|
@@ -2625,7 +2685,7 @@ var jqtree = (function (exports) {
|
|
|
2625
2685
|
};
|
|
2626
2686
|
|
|
2627
2687
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
2628
|
-
jQuery.fn[widgetName] = function (argument1) {
|
|
2688
|
+
jQuery.fn[widgetName] = function (argument1, ...args) {
|
|
2629
2689
|
if (!argument1) {
|
|
2630
2690
|
return createWidget(this, null);
|
|
2631
2691
|
} else if (typeof argument1 === "object") {
|
|
@@ -2633,15 +2693,10 @@ var jqtree = (function (exports) {
|
|
|
2633
2693
|
return createWidget(this, options);
|
|
2634
2694
|
} else if (typeof argument1 === "string" && argument1[0] !== "_") {
|
|
2635
2695
|
const functionName = argument1;
|
|
2636
|
-
if (
|
|
2696
|
+
if (argument1 === "destroy") {
|
|
2637
2697
|
destroyWidget(this);
|
|
2638
2698
|
return undefined;
|
|
2639
|
-
} else if (functionName === "get_widget_class") {
|
|
2640
|
-
return widgetClass;
|
|
2641
2699
|
} else {
|
|
2642
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2643
|
-
args[_key - 1] = arguments[_key];
|
|
2644
|
-
}
|
|
2645
2700
|
return callFunction(this, functionName, args);
|
|
2646
2701
|
}
|
|
2647
2702
|
} else {
|
|
@@ -2651,6 +2706,8 @@ var jqtree = (function (exports) {
|
|
|
2651
2706
|
};
|
|
2652
2707
|
class SimpleWidget {
|
|
2653
2708
|
static defaults = {};
|
|
2709
|
+
$el;
|
|
2710
|
+
options;
|
|
2654
2711
|
constructor(el, options) {
|
|
2655
2712
|
this.$el = jQuery(el);
|
|
2656
2713
|
|
|
@@ -2675,12 +2732,12 @@ var jqtree = (function (exports) {
|
|
|
2675
2732
|
}
|
|
2676
2733
|
}
|
|
2677
2734
|
|
|
2678
|
-
const version = "1.
|
|
2735
|
+
const version = "1.9.0";
|
|
2679
2736
|
|
|
2680
2737
|
const NODE_PARAM_IS_EMPTY = "Node parameter is empty";
|
|
2681
2738
|
const PARAM_IS_EMPTY = "Parameter is empty: ";
|
|
2682
2739
|
class JqTreeWidget extends SimpleWidget {
|
|
2683
|
-
static defaults =
|
|
2740
|
+
static defaults = {
|
|
2684
2741
|
animationSpeed: "fast",
|
|
2685
2742
|
autoEscape: true,
|
|
2686
2743
|
autoOpen: false,
|
|
@@ -2725,11 +2782,23 @@ var jqtree = (function (exports) {
|
|
|
2725
2782
|
// The delay for starting dnd (in milliseconds)
|
|
2726
2783
|
tabIndex: 0,
|
|
2727
2784
|
useContextMenu: true
|
|
2728
|
-
}
|
|
2785
|
+
};
|
|
2786
|
+
_dataLoader;
|
|
2787
|
+
_dndHandler;
|
|
2788
|
+
_element;
|
|
2789
|
+
_htmlElement;
|
|
2790
|
+
_isInitialized;
|
|
2791
|
+
_keyHandler;
|
|
2792
|
+
_mouseHandler;
|
|
2793
|
+
_renderer;
|
|
2794
|
+
_saveStateHandler;
|
|
2795
|
+
_scrollHandler;
|
|
2796
|
+
_selectNodeHandler;
|
|
2797
|
+
_tree;
|
|
2729
2798
|
addNodeAfter(newNodeInfo, existingNode) {
|
|
2730
2799
|
const newNode = existingNode.addAfter(newNodeInfo);
|
|
2731
2800
|
if (newNode) {
|
|
2732
|
-
this.
|
|
2801
|
+
this._refreshElements(existingNode.parent);
|
|
2733
2802
|
}
|
|
2734
2803
|
return newNode;
|
|
2735
2804
|
}
|
|
@@ -2739,7 +2808,7 @@ var jqtree = (function (exports) {
|
|
|
2739
2808
|
}
|
|
2740
2809
|
const newNode = existingNode.addBefore(newNodeInfo);
|
|
2741
2810
|
if (newNode) {
|
|
2742
|
-
this.
|
|
2811
|
+
this._refreshElements(existingNode.parent);
|
|
2743
2812
|
}
|
|
2744
2813
|
return newNode;
|
|
2745
2814
|
}
|
|
@@ -2749,7 +2818,7 @@ var jqtree = (function (exports) {
|
|
|
2749
2818
|
}
|
|
2750
2819
|
const newNode = existingNode.addParent(newNodeInfo);
|
|
2751
2820
|
if (newNode) {
|
|
2752
|
-
this.
|
|
2821
|
+
this._refreshElements(newNode.parent);
|
|
2753
2822
|
}
|
|
2754
2823
|
return newNode;
|
|
2755
2824
|
}
|
|
@@ -2757,16 +2826,16 @@ var jqtree = (function (exports) {
|
|
|
2757
2826
|
if (!node) {
|
|
2758
2827
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
2759
2828
|
}
|
|
2760
|
-
this.
|
|
2761
|
-
this.
|
|
2762
|
-
this.
|
|
2763
|
-
this.
|
|
2764
|
-
return this.
|
|
2829
|
+
this._selectNodeHandler.addToSelection(node);
|
|
2830
|
+
this._openParents(node);
|
|
2831
|
+
this._getNodeElementForNode(node).select(mustSetFocus ?? true);
|
|
2832
|
+
this._saveState();
|
|
2833
|
+
return this._element;
|
|
2765
2834
|
}
|
|
2766
2835
|
appendNode(newNodeInfo, parentNodeParam) {
|
|
2767
|
-
const parentNode = parentNodeParam ?? this.
|
|
2836
|
+
const parentNode = parentNodeParam ?? this._tree;
|
|
2768
2837
|
const node = parentNode.append(newNodeInfo);
|
|
2769
|
-
this.
|
|
2838
|
+
this._refreshElements(parentNode);
|
|
2770
2839
|
return node;
|
|
2771
2840
|
}
|
|
2772
2841
|
closeNode(node, slideParam) {
|
|
@@ -2775,82 +2844,83 @@ var jqtree = (function (exports) {
|
|
|
2775
2844
|
}
|
|
2776
2845
|
const slide = slideParam ?? this.options.slide;
|
|
2777
2846
|
if (node.isFolder() || node.isEmptyFolder) {
|
|
2778
|
-
this.
|
|
2779
|
-
this.
|
|
2847
|
+
this._createFolderElement(node).close(slide, this.options.animationSpeed);
|
|
2848
|
+
this._saveState();
|
|
2780
2849
|
}
|
|
2781
|
-
return this.
|
|
2850
|
+
return this._element;
|
|
2782
2851
|
}
|
|
2783
2852
|
deinit() {
|
|
2784
|
-
this.
|
|
2785
|
-
this.
|
|
2786
|
-
this.
|
|
2787
|
-
this.
|
|
2788
|
-
this.
|
|
2853
|
+
this._htmlElement.textContent = "";
|
|
2854
|
+
this._element.off();
|
|
2855
|
+
this._keyHandler.deinit();
|
|
2856
|
+
this._mouseHandler.deinit();
|
|
2857
|
+
this._tree = new Node({}, true);
|
|
2789
2858
|
super.deinit();
|
|
2790
2859
|
}
|
|
2791
2860
|
getNodeByCallback(callback) {
|
|
2792
|
-
return this.
|
|
2861
|
+
return this._tree.getNodeByCallback(callback);
|
|
2793
2862
|
}
|
|
2794
2863
|
getNodeByHtmlElement(inputElement) {
|
|
2795
|
-
const element = inputElement instanceof HTMLElement ? inputElement : inputElement
|
|
2864
|
+
const element = inputElement instanceof HTMLElement ? inputElement : inputElement.get(0);
|
|
2796
2865
|
if (!element) {
|
|
2797
2866
|
return null;
|
|
2798
2867
|
}
|
|
2799
|
-
return this.
|
|
2868
|
+
return this._getNode(element);
|
|
2800
2869
|
}
|
|
2801
2870
|
getNodeById(nodeId) {
|
|
2802
|
-
return this.
|
|
2871
|
+
return this._tree.getNodeById(nodeId);
|
|
2803
2872
|
}
|
|
2804
2873
|
getNodeByName(name) {
|
|
2805
|
-
return this.
|
|
2874
|
+
return this._tree.getNodeByName(name);
|
|
2806
2875
|
}
|
|
2807
2876
|
getNodeByNameMustExist(name) {
|
|
2808
|
-
return this.
|
|
2877
|
+
return this._tree.getNodeByNameMustExist(name);
|
|
2809
2878
|
}
|
|
2810
2879
|
getNodesByProperty(key, value) {
|
|
2811
|
-
return this.
|
|
2880
|
+
return this._tree.getNodesByProperty(key, value);
|
|
2812
2881
|
}
|
|
2813
2882
|
getSelectedNode() {
|
|
2814
|
-
return this.
|
|
2883
|
+
return this._selectNodeHandler.getSelectedNode();
|
|
2815
2884
|
}
|
|
2816
2885
|
getSelectedNodes() {
|
|
2817
|
-
return this.
|
|
2886
|
+
return this._selectNodeHandler.getSelectedNodes();
|
|
2818
2887
|
}
|
|
2819
2888
|
getState() {
|
|
2820
|
-
return this.
|
|
2889
|
+
return this._saveStateHandler.getState();
|
|
2821
2890
|
}
|
|
2822
2891
|
getStateFromStorage() {
|
|
2823
|
-
return this.
|
|
2892
|
+
return this._saveStateHandler.getStateFromStorage();
|
|
2824
2893
|
}
|
|
2825
2894
|
getTree() {
|
|
2826
|
-
return this.
|
|
2895
|
+
return this._tree;
|
|
2827
2896
|
}
|
|
2828
2897
|
getVersion() {
|
|
2829
2898
|
return version;
|
|
2830
2899
|
}
|
|
2831
2900
|
init() {
|
|
2832
2901
|
super.init();
|
|
2833
|
-
this.
|
|
2834
|
-
this.
|
|
2835
|
-
this.
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
this.
|
|
2840
|
-
this.
|
|
2902
|
+
this._element = this.$el;
|
|
2903
|
+
this._htmlElement = this._element.get(0);
|
|
2904
|
+
this._isInitialized = false;
|
|
2905
|
+
this.options.dataUrl ??= this._element.data("url");
|
|
2906
|
+
const dataRtl = this._element.data("rtl");
|
|
2907
|
+
this.options.rtl ??= dataRtl === '' ? true : Boolean(dataRtl);
|
|
2908
|
+
this.options.closedIcon ??= this._getDefaultClosedIcon();
|
|
2909
|
+
this._connectHandlers();
|
|
2910
|
+
this._initData();
|
|
2841
2911
|
}
|
|
2842
2912
|
isDragging() {
|
|
2843
|
-
return this.
|
|
2913
|
+
return this._dndHandler.isDragging;
|
|
2844
2914
|
}
|
|
2845
2915
|
isNodeSelected(node) {
|
|
2846
2916
|
if (!node) {
|
|
2847
2917
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
2848
2918
|
}
|
|
2849
|
-
return this.
|
|
2919
|
+
return this._selectNodeHandler.isNodeSelected(node);
|
|
2850
2920
|
}
|
|
2851
2921
|
loadData(data, parentNode) {
|
|
2852
|
-
this.
|
|
2853
|
-
return this.
|
|
2922
|
+
this._doLoadData(data, parentNode);
|
|
2923
|
+
return this._element;
|
|
2854
2924
|
}
|
|
2855
2925
|
|
|
2856
2926
|
/*
|
|
@@ -2869,19 +2939,19 @@ var jqtree = (function (exports) {
|
|
|
2869
2939
|
loadDataFromUrl(param1, param2, param3) {
|
|
2870
2940
|
if (typeof param1 === "string") {
|
|
2871
2941
|
// first parameter is url
|
|
2872
|
-
this.
|
|
2942
|
+
this._doLoadDataFromUrl(param1, param2, param3 ?? null);
|
|
2873
2943
|
} else {
|
|
2874
2944
|
// first parameter is not url
|
|
2875
|
-
this.
|
|
2945
|
+
this._doLoadDataFromUrl(null, param1, param2);
|
|
2876
2946
|
}
|
|
2877
|
-
return this.
|
|
2947
|
+
return this._element;
|
|
2878
2948
|
}
|
|
2879
2949
|
moveDown() {
|
|
2880
2950
|
const selectedNode = this.getSelectedNode();
|
|
2881
2951
|
if (selectedNode) {
|
|
2882
|
-
this.
|
|
2952
|
+
this._keyHandler.moveDown(selectedNode);
|
|
2883
2953
|
}
|
|
2884
|
-
return this.
|
|
2954
|
+
return this._element;
|
|
2885
2955
|
}
|
|
2886
2956
|
moveNode(node, targetNode, position) {
|
|
2887
2957
|
if (!node) {
|
|
@@ -2893,16 +2963,16 @@ var jqtree = (function (exports) {
|
|
|
2893
2963
|
if (!position) {
|
|
2894
2964
|
throw Error(PARAM_IS_EMPTY + "position");
|
|
2895
2965
|
}
|
|
2896
|
-
this.
|
|
2897
|
-
this.
|
|
2898
|
-
return this.
|
|
2966
|
+
this._tree.moveNode(node, targetNode, position);
|
|
2967
|
+
this._refreshElements(null);
|
|
2968
|
+
return this._element;
|
|
2899
2969
|
}
|
|
2900
2970
|
moveUp() {
|
|
2901
2971
|
const selectedNode = this.getSelectedNode();
|
|
2902
2972
|
if (selectedNode) {
|
|
2903
|
-
this.
|
|
2973
|
+
this._keyHandler.moveUp(selectedNode);
|
|
2904
2974
|
}
|
|
2905
|
-
return this.
|
|
2975
|
+
return this._element;
|
|
2906
2976
|
}
|
|
2907
2977
|
openNode(node, param1, param2) {
|
|
2908
2978
|
if (!node) {
|
|
@@ -2911,48 +2981,42 @@ var jqtree = (function (exports) {
|
|
|
2911
2981
|
const parseParams = () => {
|
|
2912
2982
|
let onFinished;
|
|
2913
2983
|
let slide;
|
|
2914
|
-
if (
|
|
2984
|
+
if (typeof param1 === "function") {
|
|
2915
2985
|
onFinished = param1;
|
|
2916
2986
|
slide = null;
|
|
2917
2987
|
} else {
|
|
2918
2988
|
slide = param1;
|
|
2919
2989
|
onFinished = param2;
|
|
2920
2990
|
}
|
|
2921
|
-
|
|
2922
|
-
slide = this.options.slide;
|
|
2923
|
-
}
|
|
2991
|
+
slide ??= this.options.slide;
|
|
2924
2992
|
return [slide, onFinished];
|
|
2925
2993
|
};
|
|
2926
2994
|
const [slide, onFinished] = parseParams();
|
|
2927
|
-
this.
|
|
2928
|
-
return this.
|
|
2995
|
+
this._openNodeInternal(node, slide, onFinished);
|
|
2996
|
+
return this._element;
|
|
2929
2997
|
}
|
|
2930
2998
|
prependNode(newNodeInfo, parentNodeParam) {
|
|
2931
|
-
const parentNode = parentNodeParam ?? this.
|
|
2999
|
+
const parentNode = parentNodeParam ?? this._tree;
|
|
2932
3000
|
const node = parentNode.prepend(newNodeInfo);
|
|
2933
|
-
this.
|
|
3001
|
+
this._refreshElements(parentNode);
|
|
2934
3002
|
return node;
|
|
2935
3003
|
}
|
|
2936
3004
|
refresh() {
|
|
2937
|
-
this.
|
|
2938
|
-
return this.
|
|
2939
|
-
}
|
|
2940
|
-
refreshHitAreas() {
|
|
2941
|
-
this.dndHandler.refresh();
|
|
2942
|
-
return this.element;
|
|
3005
|
+
this._refreshElements(null);
|
|
3006
|
+
return this._element;
|
|
2943
3007
|
}
|
|
2944
3008
|
reload(onFinished) {
|
|
2945
|
-
this.
|
|
2946
|
-
return this.
|
|
3009
|
+
this._doLoadDataFromUrl(null, null, onFinished);
|
|
3010
|
+
return this._element;
|
|
2947
3011
|
}
|
|
2948
3012
|
removeFromSelection(node) {
|
|
2949
3013
|
if (!node) {
|
|
2950
3014
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
2951
3015
|
}
|
|
2952
|
-
this.
|
|
2953
|
-
this.
|
|
2954
|
-
this.
|
|
2955
|
-
return this.
|
|
3016
|
+
this._selectNodeHandler.removeFromSelection(node);
|
|
3017
|
+
this._getNodeElementForNode(node).deselect();
|
|
3018
|
+
this._saveState();
|
|
3019
|
+
return this._element;
|
|
2956
3020
|
}
|
|
2957
3021
|
removeNode(node) {
|
|
2958
3022
|
if (!node) {
|
|
@@ -2961,41 +3025,40 @@ var jqtree = (function (exports) {
|
|
|
2961
3025
|
if (!node.parent) {
|
|
2962
3026
|
throw Error("Node has no parent");
|
|
2963
3027
|
}
|
|
2964
|
-
this.
|
|
3028
|
+
this._selectNodeHandler.removeFromSelection(node, true); // including children
|
|
2965
3029
|
|
|
2966
3030
|
const parent = node.parent;
|
|
2967
3031
|
node.remove();
|
|
2968
|
-
this.
|
|
2969
|
-
return this.
|
|
3032
|
+
this._refreshElements(parent);
|
|
3033
|
+
return this._element;
|
|
2970
3034
|
}
|
|
2971
3035
|
scrollToNode(node) {
|
|
2972
3036
|
if (!node) {
|
|
2973
3037
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
2974
3038
|
}
|
|
2975
3039
|
if (!node.element) {
|
|
2976
|
-
return this.
|
|
3040
|
+
return this._element;
|
|
2977
3041
|
}
|
|
2978
|
-
const top = getOffsetTop(node.element) - getOffsetTop(this
|
|
2979
|
-
this.
|
|
2980
|
-
return this.
|
|
3042
|
+
const top = getOffsetTop(node.element) - getOffsetTop(this._htmlElement);
|
|
3043
|
+
this._scrollHandler.scrollToY(top);
|
|
3044
|
+
return this._element;
|
|
2981
3045
|
}
|
|
2982
3046
|
selectNode(node, optionsParam) {
|
|
2983
|
-
this.
|
|
2984
|
-
return this.
|
|
3047
|
+
this._doSelectNode(node, optionsParam);
|
|
3048
|
+
return this._element;
|
|
2985
3049
|
}
|
|
2986
3050
|
setOption(option, value) {
|
|
2987
3051
|
this.options[option] = value;
|
|
2988
|
-
return this.
|
|
3052
|
+
return this._element;
|
|
2989
3053
|
}
|
|
2990
3054
|
setState(state) {
|
|
2991
3055
|
if (state) {
|
|
2992
|
-
this.
|
|
2993
|
-
this.
|
|
3056
|
+
this._saveStateHandler.setInitialState(state);
|
|
3057
|
+
this._refreshElements(null);
|
|
2994
3058
|
}
|
|
2995
|
-
return this.
|
|
3059
|
+
return this._element;
|
|
2996
3060
|
}
|
|
2997
|
-
toggle(node) {
|
|
2998
|
-
let slideParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
3061
|
+
toggle(node, slideParam = null) {
|
|
2999
3062
|
if (!node) {
|
|
3000
3063
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
3001
3064
|
}
|
|
@@ -3005,25 +3068,25 @@ var jqtree = (function (exports) {
|
|
|
3005
3068
|
} else {
|
|
3006
3069
|
this.openNode(node, slide);
|
|
3007
3070
|
}
|
|
3008
|
-
return this.
|
|
3071
|
+
return this._element;
|
|
3009
3072
|
}
|
|
3010
3073
|
toJson() {
|
|
3011
|
-
return JSON.stringify(this.
|
|
3074
|
+
return JSON.stringify(this._tree.getData());
|
|
3012
3075
|
}
|
|
3013
3076
|
updateNode(node, data) {
|
|
3014
3077
|
if (!node) {
|
|
3015
3078
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
3016
3079
|
}
|
|
3017
3080
|
if (!data) {
|
|
3018
|
-
return this.
|
|
3081
|
+
return this._element;
|
|
3019
3082
|
}
|
|
3020
3083
|
const idIsChanged = typeof data === "object" && data.id && data.id !== node.id;
|
|
3021
3084
|
if (idIsChanged) {
|
|
3022
|
-
this.
|
|
3085
|
+
this._tree.removeNodeFromIndex(node);
|
|
3023
3086
|
}
|
|
3024
3087
|
node.setData(data);
|
|
3025
3088
|
if (idIsChanged) {
|
|
3026
|
-
this.
|
|
3089
|
+
this._tree.addNodeToIndex(node);
|
|
3027
3090
|
}
|
|
3028
3091
|
if (typeof data === "object" && data.children && data.children instanceof Array) {
|
|
3029
3092
|
node.removeChildren();
|
|
@@ -3031,10 +3094,10 @@ var jqtree = (function (exports) {
|
|
|
3031
3094
|
node.loadFromData(data.children);
|
|
3032
3095
|
}
|
|
3033
3096
|
}
|
|
3034
|
-
this.
|
|
3035
|
-
return this.
|
|
3097
|
+
this._refreshElements(node);
|
|
3098
|
+
return this._element;
|
|
3036
3099
|
}
|
|
3037
|
-
|
|
3100
|
+
_connectHandlers() {
|
|
3038
3101
|
const {
|
|
3039
3102
|
autoEscape,
|
|
3040
3103
|
buttonLeft,
|
|
@@ -3061,20 +3124,18 @@ var jqtree = (function (exports) {
|
|
|
3061
3124
|
tabIndex
|
|
3062
3125
|
} = this.options;
|
|
3063
3126
|
const closeNode = this.closeNode.bind(this);
|
|
3064
|
-
const getNodeElement = this.
|
|
3065
|
-
const getNodeElementForNode = this.
|
|
3127
|
+
const getNodeElement = this._getNodeElement.bind(this);
|
|
3128
|
+
const getNodeElementForNode = this._getNodeElementForNode.bind(this);
|
|
3066
3129
|
const getNodeById = this.getNodeById.bind(this);
|
|
3067
3130
|
const getSelectedNode = this.getSelectedNode.bind(this);
|
|
3068
3131
|
const getTree = this.getTree.bind(this);
|
|
3069
|
-
const isFocusOnTree = this.
|
|
3132
|
+
const isFocusOnTree = this._isFocusOnTree.bind(this);
|
|
3070
3133
|
const loadData = this.loadData.bind(this);
|
|
3071
|
-
const openNode = this.
|
|
3072
|
-
const refreshElements = this.
|
|
3073
|
-
const refreshHitAreas = this.refreshHitAreas.bind(this);
|
|
3134
|
+
const openNode = this._openNodeInternal.bind(this);
|
|
3135
|
+
const refreshElements = this._refreshElements.bind(this);
|
|
3074
3136
|
const selectNode = this.selectNode.bind(this);
|
|
3075
|
-
const
|
|
3076
|
-
const
|
|
3077
|
-
const triggerEvent = this.triggerEvent.bind(this);
|
|
3137
|
+
const treeElement = this._htmlElement;
|
|
3138
|
+
const triggerEvent = this._triggerEvent.bind(this);
|
|
3078
3139
|
const selectNodeHandler = new SelectNodeHandler({
|
|
3079
3140
|
getNodeById
|
|
3080
3141
|
});
|
|
@@ -3083,6 +3144,9 @@ var jqtree = (function (exports) {
|
|
|
3083
3144
|
const isNodeSelected = selectNodeHandler.isNodeSelected.bind(selectNodeHandler);
|
|
3084
3145
|
const removeFromSelection = selectNodeHandler.removeFromSelection.bind(selectNodeHandler);
|
|
3085
3146
|
const getMouseDelay = () => this.options.startDndDelay ?? 0;
|
|
3147
|
+
const refreshHitAreas = () => {
|
|
3148
|
+
dndHandler.refresh();
|
|
3149
|
+
};
|
|
3086
3150
|
const dataLoader = new DataLoader({
|
|
3087
3151
|
dataFilter,
|
|
3088
3152
|
loadData,
|
|
@@ -3135,12 +3199,12 @@ var jqtree = (function (exports) {
|
|
|
3135
3199
|
selectNode
|
|
3136
3200
|
});
|
|
3137
3201
|
const renderer = new ElementsRenderer({
|
|
3138
|
-
$element: $treeElement,
|
|
3139
3202
|
autoEscape,
|
|
3140
3203
|
buttonLeft,
|
|
3141
3204
|
closedIcon,
|
|
3142
3205
|
dragAndDrop,
|
|
3143
3206
|
getTree,
|
|
3207
|
+
htmlElement: treeElement,
|
|
3144
3208
|
isNodeSelected,
|
|
3145
3209
|
onCreateLi,
|
|
3146
3210
|
openedIcon,
|
|
@@ -3148,17 +3212,17 @@ var jqtree = (function (exports) {
|
|
|
3148
3212
|
showEmptyFolder,
|
|
3149
3213
|
tabIndex
|
|
3150
3214
|
});
|
|
3151
|
-
const getNode = this.
|
|
3152
|
-
const onMouseCapture = this.
|
|
3153
|
-
const onMouseDrag = this.
|
|
3154
|
-
const onMouseStart = this.
|
|
3155
|
-
const onMouseStop = this.
|
|
3215
|
+
const getNode = this._getNode.bind(this);
|
|
3216
|
+
const onMouseCapture = this._mouseCapture.bind(this);
|
|
3217
|
+
const onMouseDrag = this._mouseDrag.bind(this);
|
|
3218
|
+
const onMouseStart = this._mouseStart.bind(this);
|
|
3219
|
+
const onMouseStop = this._mouseStop.bind(this);
|
|
3156
3220
|
const mouseHandler = new MouseHandler({
|
|
3157
3221
|
element: treeElement,
|
|
3158
3222
|
getMouseDelay,
|
|
3159
3223
|
getNode,
|
|
3160
3224
|
onClickButton: this.toggle.bind(this),
|
|
3161
|
-
onClickTitle: this.
|
|
3225
|
+
onClickTitle: this._doSelectNode.bind(this),
|
|
3162
3226
|
onMouseCapture,
|
|
3163
3227
|
onMouseDrag,
|
|
3164
3228
|
onMouseStart,
|
|
@@ -3166,89 +3230,87 @@ var jqtree = (function (exports) {
|
|
|
3166
3230
|
triggerEvent,
|
|
3167
3231
|
useContextMenu: this.options.useContextMenu
|
|
3168
3232
|
});
|
|
3169
|
-
this.
|
|
3170
|
-
this.
|
|
3171
|
-
this.
|
|
3172
|
-
this.
|
|
3173
|
-
this.
|
|
3174
|
-
this.
|
|
3175
|
-
this.
|
|
3176
|
-
this.
|
|
3177
|
-
}
|
|
3178
|
-
|
|
3179
|
-
const node = this.
|
|
3180
|
-
return node
|
|
3181
|
-
}
|
|
3182
|
-
|
|
3183
|
-
const closedIconElement = this.
|
|
3184
|
-
const getScrollLeft = this.
|
|
3185
|
-
const openedIconElement = this.
|
|
3233
|
+
this._dataLoader = dataLoader;
|
|
3234
|
+
this._dndHandler = dndHandler;
|
|
3235
|
+
this._keyHandler = keyHandler;
|
|
3236
|
+
this._mouseHandler = mouseHandler;
|
|
3237
|
+
this._renderer = renderer;
|
|
3238
|
+
this._saveStateHandler = saveStateHandler;
|
|
3239
|
+
this._scrollHandler = scrollHandler;
|
|
3240
|
+
this._selectNodeHandler = selectNodeHandler;
|
|
3241
|
+
}
|
|
3242
|
+
_containsElement(element) {
|
|
3243
|
+
const node = this._getNode(element);
|
|
3244
|
+
return node?.tree === this._tree;
|
|
3245
|
+
}
|
|
3246
|
+
_createFolderElement(node) {
|
|
3247
|
+
const closedIconElement = this._renderer.closedIconElement;
|
|
3248
|
+
const getScrollLeft = this._scrollHandler.getScrollLeft.bind(this._scrollHandler);
|
|
3249
|
+
const openedIconElement = this._renderer.openedIconElement;
|
|
3186
3250
|
const tabIndex = this.options.tabIndex;
|
|
3187
|
-
const
|
|
3188
|
-
const triggerEvent = this.triggerEvent.bind(this);
|
|
3251
|
+
const triggerEvent = this._triggerEvent.bind(this);
|
|
3189
3252
|
return new FolderElement({
|
|
3190
3253
|
closedIconElement,
|
|
3191
3254
|
getScrollLeft,
|
|
3192
3255
|
node,
|
|
3193
3256
|
openedIconElement,
|
|
3194
3257
|
tabIndex,
|
|
3195
|
-
treeElement,
|
|
3258
|
+
treeElement: this._htmlElement,
|
|
3196
3259
|
triggerEvent
|
|
3197
3260
|
});
|
|
3198
3261
|
}
|
|
3199
|
-
|
|
3200
|
-
const getScrollLeft = this.
|
|
3262
|
+
_createNodeElement(node) {
|
|
3263
|
+
const getScrollLeft = this._scrollHandler.getScrollLeft.bind(this._scrollHandler);
|
|
3201
3264
|
const tabIndex = this.options.tabIndex;
|
|
3202
|
-
const treeElement = this.element.get(0);
|
|
3203
3265
|
return new NodeElement({
|
|
3204
3266
|
getScrollLeft,
|
|
3205
3267
|
node,
|
|
3206
3268
|
tabIndex,
|
|
3207
|
-
treeElement
|
|
3269
|
+
treeElement: this._htmlElement
|
|
3208
3270
|
});
|
|
3209
3271
|
}
|
|
3210
|
-
|
|
3272
|
+
_deselectCurrentNode() {
|
|
3211
3273
|
const node = this.getSelectedNode();
|
|
3212
3274
|
if (node) {
|
|
3213
3275
|
this.removeFromSelection(node);
|
|
3214
3276
|
}
|
|
3215
3277
|
}
|
|
3216
|
-
|
|
3217
|
-
const selectedNodesUnderParent = this.
|
|
3278
|
+
_deselectNodes(parentNode) {
|
|
3279
|
+
const selectedNodesUnderParent = this._selectNodeHandler.getSelectedNodesUnder(parentNode);
|
|
3218
3280
|
for (const n of selectedNodesUnderParent) {
|
|
3219
|
-
this.
|
|
3281
|
+
this._selectNodeHandler.removeFromSelection(n);
|
|
3220
3282
|
}
|
|
3221
3283
|
}
|
|
3222
|
-
|
|
3284
|
+
_doLoadData(data, parentNode) {
|
|
3223
3285
|
if (data) {
|
|
3224
3286
|
if (parentNode) {
|
|
3225
|
-
this.
|
|
3226
|
-
this.
|
|
3287
|
+
this._deselectNodes(parentNode);
|
|
3288
|
+
this._loadSubtree(data, parentNode);
|
|
3227
3289
|
} else {
|
|
3228
|
-
this.
|
|
3290
|
+
this._initTree(data);
|
|
3229
3291
|
}
|
|
3230
3292
|
if (this.isDragging()) {
|
|
3231
|
-
this.
|
|
3293
|
+
this._dndHandler.refresh();
|
|
3232
3294
|
}
|
|
3233
3295
|
}
|
|
3234
|
-
this.
|
|
3296
|
+
this._triggerEvent("tree.load_data", {
|
|
3235
3297
|
parent_node: parentNode,
|
|
3236
3298
|
tree_data: data
|
|
3237
3299
|
});
|
|
3238
3300
|
}
|
|
3239
|
-
|
|
3240
|
-
const urlInfo = urlInfoParam ?? this.
|
|
3241
|
-
this.
|
|
3301
|
+
_doLoadDataFromUrl(urlInfoParam, parentNode, onFinished) {
|
|
3302
|
+
const urlInfo = urlInfoParam ?? this._getDataUrlInfo(parentNode);
|
|
3303
|
+
this._dataLoader.loadFromUrl(urlInfo, parentNode, onFinished);
|
|
3242
3304
|
}
|
|
3243
|
-
|
|
3305
|
+
_doSelectNode(node, optionsParam) {
|
|
3244
3306
|
const saveState = () => {
|
|
3245
3307
|
if (this.options.saveState) {
|
|
3246
|
-
this.
|
|
3308
|
+
this._saveStateHandler.saveState();
|
|
3247
3309
|
}
|
|
3248
3310
|
};
|
|
3249
3311
|
if (!node) {
|
|
3250
3312
|
// Called with empty node -> deselect current node
|
|
3251
|
-
this.
|
|
3313
|
+
this._deselectCurrentNode();
|
|
3252
3314
|
saveState();
|
|
3253
3315
|
return;
|
|
3254
3316
|
}
|
|
@@ -3270,27 +3332,27 @@ var jqtree = (function (exports) {
|
|
|
3270
3332
|
if (!canSelect()) {
|
|
3271
3333
|
return;
|
|
3272
3334
|
}
|
|
3273
|
-
if (this.
|
|
3335
|
+
if (this._selectNodeHandler.isNodeSelected(node)) {
|
|
3274
3336
|
if (selectOptions.mustToggle) {
|
|
3275
|
-
this.
|
|
3276
|
-
this.
|
|
3337
|
+
this._deselectCurrentNode();
|
|
3338
|
+
this._triggerEvent("tree.select", {
|
|
3277
3339
|
node: null,
|
|
3278
3340
|
previous_node: node
|
|
3279
3341
|
});
|
|
3280
3342
|
}
|
|
3281
3343
|
} else {
|
|
3282
3344
|
const deselectedNode = this.getSelectedNode() || null;
|
|
3283
|
-
this.
|
|
3345
|
+
this._deselectCurrentNode();
|
|
3284
3346
|
this.addToSelection(node, selectOptions.mustSetFocus);
|
|
3285
|
-
this.
|
|
3347
|
+
this._triggerEvent("tree.select", {
|
|
3286
3348
|
deselected_node: deselectedNode,
|
|
3287
3349
|
node
|
|
3288
3350
|
});
|
|
3289
|
-
this.
|
|
3351
|
+
this._openParents(node);
|
|
3290
3352
|
}
|
|
3291
3353
|
saveState();
|
|
3292
3354
|
}
|
|
3293
|
-
|
|
3355
|
+
_getAutoOpenMaxLevel() {
|
|
3294
3356
|
if (this.options.autoOpen === true) {
|
|
3295
3357
|
return -1;
|
|
3296
3358
|
} else if (typeof this.options.autoOpen === "number") {
|
|
@@ -3301,8 +3363,7 @@ var jqtree = (function (exports) {
|
|
|
3301
3363
|
return 0;
|
|
3302
3364
|
}
|
|
3303
3365
|
}
|
|
3304
|
-
|
|
3305
|
-
const dataUrl = this.options.dataUrl ?? this.element.data("url");
|
|
3366
|
+
_getDataUrlInfo(node) {
|
|
3306
3367
|
const getUrlFromString = url => {
|
|
3307
3368
|
const urlInfo = {
|
|
3308
3369
|
url
|
|
@@ -3319,7 +3380,7 @@ var jqtree = (function (exports) {
|
|
|
3319
3380
|
urlInfo.data = data;
|
|
3320
3381
|
} else {
|
|
3321
3382
|
// Add selected_node parameter
|
|
3322
|
-
const selectedNodeId = this.
|
|
3383
|
+
const selectedNodeId = this._getNodeIdToBeSelected();
|
|
3323
3384
|
if (selectedNodeId) {
|
|
3324
3385
|
const data = {
|
|
3325
3386
|
selected_node: selectedNodeId
|
|
@@ -3328,6 +3389,7 @@ var jqtree = (function (exports) {
|
|
|
3328
3389
|
}
|
|
3329
3390
|
}
|
|
3330
3391
|
};
|
|
3392
|
+
const dataUrl = this.options.dataUrl;
|
|
3331
3393
|
if (typeof dataUrl === "function") {
|
|
3332
3394
|
return dataUrl(node);
|
|
3333
3395
|
} else if (typeof dataUrl === "string") {
|
|
@@ -3339,7 +3401,7 @@ var jqtree = (function (exports) {
|
|
|
3339
3401
|
return null;
|
|
3340
3402
|
}
|
|
3341
3403
|
}
|
|
3342
|
-
|
|
3404
|
+
_getDefaultClosedIcon() {
|
|
3343
3405
|
if (this.options.rtl) {
|
|
3344
3406
|
// triangle to the left
|
|
3345
3407
|
return "◀";
|
|
@@ -3348,7 +3410,7 @@ var jqtree = (function (exports) {
|
|
|
3348
3410
|
return "►";
|
|
3349
3411
|
}
|
|
3350
3412
|
}
|
|
3351
|
-
|
|
3413
|
+
_getNode(element) {
|
|
3352
3414
|
const liElement = element.closest("li.jqtree_common");
|
|
3353
3415
|
if (liElement) {
|
|
3354
3416
|
return jQuery(liElement).data("node");
|
|
@@ -3356,76 +3418,64 @@ var jqtree = (function (exports) {
|
|
|
3356
3418
|
return null;
|
|
3357
3419
|
}
|
|
3358
3420
|
}
|
|
3359
|
-
|
|
3360
|
-
const node = this.
|
|
3421
|
+
_getNodeElement(element) {
|
|
3422
|
+
const node = this._getNode(element);
|
|
3361
3423
|
if (node) {
|
|
3362
|
-
return this.
|
|
3424
|
+
return this._getNodeElementForNode(node);
|
|
3363
3425
|
} else {
|
|
3364
3426
|
return null;
|
|
3365
3427
|
}
|
|
3366
3428
|
}
|
|
3367
|
-
|
|
3429
|
+
_getNodeElementForNode(node) {
|
|
3368
3430
|
if (node.isFolder()) {
|
|
3369
|
-
return this.
|
|
3431
|
+
return this._createFolderElement(node);
|
|
3370
3432
|
} else {
|
|
3371
|
-
return this.
|
|
3433
|
+
return this._createNodeElement(node);
|
|
3372
3434
|
}
|
|
3373
3435
|
}
|
|
3374
|
-
|
|
3436
|
+
_getNodeIdToBeSelected() {
|
|
3375
3437
|
if (this.options.saveState) {
|
|
3376
|
-
return this.
|
|
3438
|
+
return this._saveStateHandler.getNodeIdToBeSelected();
|
|
3377
3439
|
} else {
|
|
3378
3440
|
return null;
|
|
3379
3441
|
}
|
|
3380
3442
|
}
|
|
3381
|
-
|
|
3382
|
-
if (this.options.rtl != null) {
|
|
3383
|
-
return this.options.rtl;
|
|
3384
|
-
} else {
|
|
3385
|
-
const dataRtl = this.element.data("rtl");
|
|
3386
|
-
if (dataRtl !== null && dataRtl !== false && dataRtl !== undefined) {
|
|
3387
|
-
return true;
|
|
3388
|
-
} else {
|
|
3389
|
-
return false;
|
|
3390
|
-
}
|
|
3391
|
-
}
|
|
3392
|
-
}
|
|
3393
|
-
initData() {
|
|
3443
|
+
_initData() {
|
|
3394
3444
|
if (this.options.data) {
|
|
3395
|
-
this.
|
|
3445
|
+
this._doLoadData(this.options.data, null);
|
|
3396
3446
|
} else {
|
|
3397
|
-
const dataUrl = this.
|
|
3447
|
+
const dataUrl = this._getDataUrlInfo(null);
|
|
3398
3448
|
if (dataUrl) {
|
|
3399
|
-
this.
|
|
3449
|
+
this._doLoadDataFromUrl(null, null, null);
|
|
3400
3450
|
} else {
|
|
3401
|
-
this.
|
|
3451
|
+
this._doLoadData([], null);
|
|
3402
3452
|
}
|
|
3403
3453
|
}
|
|
3404
3454
|
}
|
|
3405
|
-
|
|
3455
|
+
_initTree(data) {
|
|
3406
3456
|
const doInit = () => {
|
|
3407
|
-
if (!this.
|
|
3408
|
-
this.
|
|
3409
|
-
this.
|
|
3457
|
+
if (!this._isInitialized) {
|
|
3458
|
+
this._isInitialized = true;
|
|
3459
|
+
this._triggerEvent("tree.init");
|
|
3410
3460
|
}
|
|
3411
3461
|
};
|
|
3412
|
-
this.
|
|
3413
|
-
this.
|
|
3414
|
-
this.
|
|
3415
|
-
const mustLoadOnDemand = this.
|
|
3416
|
-
this.
|
|
3462
|
+
this._tree = new this.options.nodeClass(null, true, this.options.nodeClass);
|
|
3463
|
+
this._selectNodeHandler.clear();
|
|
3464
|
+
this._tree.loadFromData(data);
|
|
3465
|
+
const mustLoadOnDemand = this._setInitialState();
|
|
3466
|
+
this._refreshElements(null);
|
|
3417
3467
|
if (!mustLoadOnDemand) {
|
|
3418
3468
|
doInit();
|
|
3419
3469
|
} else {
|
|
3420
3470
|
// Load data on demand and then init the tree
|
|
3421
|
-
this.
|
|
3471
|
+
this._setInitialStateOnDemand(doInit);
|
|
3422
3472
|
}
|
|
3423
3473
|
}
|
|
3424
|
-
|
|
3474
|
+
_isFocusOnTree() {
|
|
3425
3475
|
const activeElement = document.activeElement;
|
|
3426
|
-
return
|
|
3476
|
+
return activeElement?.tagName === "SPAN" && this._containsElement(activeElement);
|
|
3427
3477
|
}
|
|
3428
|
-
|
|
3478
|
+
_isSelectedNodeInSubtree(subtree) {
|
|
3429
3479
|
const selectedNode = this.getSelectedNode();
|
|
3430
3480
|
if (!selectedNode) {
|
|
3431
3481
|
return false;
|
|
@@ -3433,64 +3483,60 @@ var jqtree = (function (exports) {
|
|
|
3433
3483
|
return subtree === selectedNode || subtree.isParentOf(selectedNode);
|
|
3434
3484
|
}
|
|
3435
3485
|
}
|
|
3436
|
-
|
|
3437
|
-
let slide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
3438
|
-
let onFinished = arguments.length > 2 ? arguments[2] : undefined;
|
|
3486
|
+
_loadFolderOnDemand(node, slide = true, onFinished) {
|
|
3439
3487
|
node.is_loading = true;
|
|
3440
|
-
this.
|
|
3441
|
-
this.
|
|
3488
|
+
this._doLoadDataFromUrl(null, node, () => {
|
|
3489
|
+
this._openNodeInternal(node, slide, onFinished);
|
|
3442
3490
|
});
|
|
3443
3491
|
}
|
|
3444
|
-
|
|
3492
|
+
_loadSubtree(data, parentNode) {
|
|
3445
3493
|
parentNode.loadFromData(data);
|
|
3446
3494
|
parentNode.load_on_demand = false;
|
|
3447
3495
|
parentNode.is_loading = false;
|
|
3448
|
-
this.
|
|
3496
|
+
this._refreshElements(parentNode);
|
|
3449
3497
|
}
|
|
3450
|
-
|
|
3498
|
+
_mouseCapture(positionInfo) {
|
|
3451
3499
|
if (this.options.dragAndDrop) {
|
|
3452
|
-
return this.
|
|
3500
|
+
return this._dndHandler.mouseCapture(positionInfo);
|
|
3453
3501
|
} else {
|
|
3454
3502
|
return false;
|
|
3455
3503
|
}
|
|
3456
3504
|
}
|
|
3457
|
-
|
|
3505
|
+
_mouseDrag(positionInfo) {
|
|
3458
3506
|
if (this.options.dragAndDrop) {
|
|
3459
|
-
const result = this.
|
|
3460
|
-
this.
|
|
3507
|
+
const result = this._dndHandler.mouseDrag(positionInfo);
|
|
3508
|
+
this._scrollHandler.checkScrolling(positionInfo);
|
|
3461
3509
|
return result;
|
|
3462
3510
|
} else {
|
|
3463
3511
|
return false;
|
|
3464
3512
|
}
|
|
3465
3513
|
}
|
|
3466
|
-
|
|
3514
|
+
_mouseStart(positionInfo) {
|
|
3467
3515
|
if (this.options.dragAndDrop) {
|
|
3468
|
-
return this.
|
|
3516
|
+
return this._dndHandler.mouseStart(positionInfo);
|
|
3469
3517
|
} else {
|
|
3470
3518
|
return false;
|
|
3471
3519
|
}
|
|
3472
3520
|
}
|
|
3473
|
-
|
|
3521
|
+
_mouseStop(positionInfo) {
|
|
3474
3522
|
if (this.options.dragAndDrop) {
|
|
3475
|
-
this.
|
|
3476
|
-
return this.
|
|
3523
|
+
this._scrollHandler.stopScrolling();
|
|
3524
|
+
return this._dndHandler.mouseStop(positionInfo);
|
|
3477
3525
|
} else {
|
|
3478
3526
|
return false;
|
|
3479
3527
|
}
|
|
3480
3528
|
}
|
|
3481
|
-
|
|
3482
|
-
let slide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
3483
|
-
let onFinished = arguments.length > 2 ? arguments[2] : undefined;
|
|
3529
|
+
_openNodeInternal(node, slide = true, onFinished) {
|
|
3484
3530
|
const doOpenNode = (_node, _slide, _onFinished) => {
|
|
3485
3531
|
if (!node.children.length) {
|
|
3486
3532
|
return;
|
|
3487
3533
|
}
|
|
3488
|
-
const folderElement = this.
|
|
3534
|
+
const folderElement = this._createFolderElement(_node);
|
|
3489
3535
|
folderElement.open(_onFinished, _slide, this.options.animationSpeed);
|
|
3490
3536
|
};
|
|
3491
3537
|
if (node.isFolder() || node.isEmptyFolder) {
|
|
3492
3538
|
if (node.load_on_demand) {
|
|
3493
|
-
this.
|
|
3539
|
+
this._loadFolderOnDemand(node, slide, onFinished);
|
|
3494
3540
|
} else {
|
|
3495
3541
|
let parent = node.parent;
|
|
3496
3542
|
while (parent) {
|
|
@@ -3501,11 +3547,11 @@ var jqtree = (function (exports) {
|
|
|
3501
3547
|
parent = parent.parent;
|
|
3502
3548
|
}
|
|
3503
3549
|
doOpenNode(node, slide, onFinished);
|
|
3504
|
-
this.
|
|
3550
|
+
this._saveState();
|
|
3505
3551
|
}
|
|
3506
3552
|
}
|
|
3507
3553
|
}
|
|
3508
|
-
|
|
3554
|
+
_openParents(node) {
|
|
3509
3555
|
const parent = node.parent;
|
|
3510
3556
|
if (parent?.parent && !parent.is_open) {
|
|
3511
3557
|
this.openNode(parent, false);
|
|
@@ -3516,41 +3562,41 @@ var jqtree = (function (exports) {
|
|
|
3516
3562
|
Redraw the tree or part of the tree.
|
|
3517
3563
|
from_node: redraw this subtree
|
|
3518
3564
|
*/
|
|
3519
|
-
|
|
3520
|
-
const mustSetFocus = this.
|
|
3521
|
-
const mustSelect = fromNode ? this.
|
|
3522
|
-
this.
|
|
3565
|
+
_refreshElements(fromNode) {
|
|
3566
|
+
const mustSetFocus = this._isFocusOnTree();
|
|
3567
|
+
const mustSelect = fromNode ? this._isSelectedNodeInSubtree(fromNode) : false;
|
|
3568
|
+
this._renderer.render(fromNode);
|
|
3523
3569
|
if (mustSelect) {
|
|
3524
|
-
this.
|
|
3570
|
+
this._selectCurrentNode(mustSetFocus);
|
|
3525
3571
|
}
|
|
3526
|
-
this.
|
|
3572
|
+
this._triggerEvent("tree.refresh");
|
|
3527
3573
|
}
|
|
3528
|
-
|
|
3574
|
+
_saveState() {
|
|
3529
3575
|
if (this.options.saveState) {
|
|
3530
|
-
this.
|
|
3576
|
+
this._saveStateHandler.saveState();
|
|
3531
3577
|
}
|
|
3532
3578
|
}
|
|
3533
|
-
|
|
3579
|
+
_selectCurrentNode(mustSetFocus) {
|
|
3534
3580
|
const node = this.getSelectedNode();
|
|
3535
3581
|
if (node) {
|
|
3536
|
-
const nodeElement = this.
|
|
3582
|
+
const nodeElement = this._getNodeElementForNode(node);
|
|
3537
3583
|
nodeElement.select(mustSetFocus);
|
|
3538
3584
|
}
|
|
3539
3585
|
}
|
|
3540
3586
|
|
|
3541
3587
|
// Set initial state, either by restoring the state or auto-opening nodes
|
|
3542
3588
|
// result: must load nodes on demand?
|
|
3543
|
-
|
|
3589
|
+
_setInitialState() {
|
|
3544
3590
|
const restoreState = () => {
|
|
3545
3591
|
// result: is state restored, must load on demand?
|
|
3546
3592
|
if (!this.options.saveState) {
|
|
3547
3593
|
return [false, false];
|
|
3548
3594
|
} else {
|
|
3549
|
-
const state = this.
|
|
3595
|
+
const state = this._saveStateHandler.getStateFromStorage();
|
|
3550
3596
|
if (!state) {
|
|
3551
3597
|
return [false, false];
|
|
3552
3598
|
} else {
|
|
3553
|
-
const mustLoadOnDemand = this.
|
|
3599
|
+
const mustLoadOnDemand = this._saveStateHandler.setInitialState(state);
|
|
3554
3600
|
|
|
3555
3601
|
// return true: the state is restored
|
|
3556
3602
|
return [true, mustLoadOnDemand];
|
|
@@ -3562,9 +3608,9 @@ var jqtree = (function (exports) {
|
|
|
3562
3608
|
if (this.options.autoOpen === false) {
|
|
3563
3609
|
return false;
|
|
3564
3610
|
}
|
|
3565
|
-
const maxLevel = this.
|
|
3611
|
+
const maxLevel = this._getAutoOpenMaxLevel();
|
|
3566
3612
|
let mustLoadOnDemand = false;
|
|
3567
|
-
this.
|
|
3613
|
+
this._tree.iterate((node, level) => {
|
|
3568
3614
|
if (node.load_on_demand) {
|
|
3569
3615
|
mustLoadOnDemand = true;
|
|
3570
3616
|
return false;
|
|
@@ -3587,39 +3633,39 @@ var jqtree = (function (exports) {
|
|
|
3587
3633
|
|
|
3588
3634
|
// Set the initial state for nodes that are loaded on demand
|
|
3589
3635
|
// Call cb_finished when done
|
|
3590
|
-
|
|
3636
|
+
_setInitialStateOnDemand(cbFinished) {
|
|
3591
3637
|
const restoreState = () => {
|
|
3592
3638
|
if (!this.options.saveState) {
|
|
3593
3639
|
return false;
|
|
3594
3640
|
} else {
|
|
3595
|
-
const state = this.
|
|
3641
|
+
const state = this._saveStateHandler.getStateFromStorage();
|
|
3596
3642
|
if (!state) {
|
|
3597
3643
|
return false;
|
|
3598
3644
|
} else {
|
|
3599
|
-
this.
|
|
3645
|
+
this._saveStateHandler.setInitialStateOnDemand(state, cbFinished);
|
|
3600
3646
|
return true;
|
|
3601
3647
|
}
|
|
3602
3648
|
}
|
|
3603
3649
|
};
|
|
3604
3650
|
const autoOpenNodes = () => {
|
|
3605
|
-
const maxLevel = this.
|
|
3651
|
+
const maxLevel = this._getAutoOpenMaxLevel();
|
|
3606
3652
|
let loadingCount = 0;
|
|
3607
3653
|
const loadAndOpenNode = node => {
|
|
3608
3654
|
loadingCount += 1;
|
|
3609
|
-
this.
|
|
3655
|
+
this._openNodeInternal(node, false, () => {
|
|
3610
3656
|
loadingCount -= 1;
|
|
3611
3657
|
openNodes();
|
|
3612
3658
|
});
|
|
3613
3659
|
};
|
|
3614
3660
|
const openNodes = () => {
|
|
3615
|
-
this.
|
|
3661
|
+
this._tree.iterate((node, level) => {
|
|
3616
3662
|
if (node.load_on_demand) {
|
|
3617
3663
|
if (!node.is_loading) {
|
|
3618
3664
|
loadAndOpenNode(node);
|
|
3619
3665
|
}
|
|
3620
3666
|
return false;
|
|
3621
3667
|
} else {
|
|
3622
|
-
this.
|
|
3668
|
+
this._openNodeInternal(node, false);
|
|
3623
3669
|
return level !== maxLevel;
|
|
3624
3670
|
}
|
|
3625
3671
|
});
|
|
@@ -3633,10 +3679,10 @@ var jqtree = (function (exports) {
|
|
|
3633
3679
|
autoOpenNodes();
|
|
3634
3680
|
}
|
|
3635
3681
|
}
|
|
3636
|
-
|
|
3682
|
+
_triggerEvent(eventName, values) {
|
|
3637
3683
|
const event = jQuery.Event(eventName, values);
|
|
3638
|
-
this.
|
|
3639
|
-
return event;
|
|
3684
|
+
this._element.trigger(event);
|
|
3685
|
+
return !event.isDefaultPrevented();
|
|
3640
3686
|
}
|
|
3641
3687
|
}
|
|
3642
3688
|
SimpleWidget.register(JqTreeWidget, "tree");
|