jqtree 1.7.4 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +5 -1
- package/bower.json +1 -1
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +5 -0
- package/docs/package.json +1 -1
- package/docs/pnpm-lock.yaml +30 -30
- package/lib/dataLoader.js +2 -3
- package/lib/dragAndDropHandler.js +5 -13
- package/lib/elementsRenderer.js +2 -3
- package/lib/keyHandler.js +1 -5
- package/lib/mouse.widget.js +1 -2
- package/lib/node.js +30 -39
- package/lib/nodeElement.js +3 -6
- package/lib/nodeUtils.js +10 -0
- package/lib/playwright/coverage.js +14 -11
- package/lib/playwright/playwright.test.js +482 -104
- package/lib/playwright/testUtils.js +75 -49
- package/lib/saveStateHandler.js +2 -3
- package/lib/scrollHandler/containerScrollParent.js +160 -0
- package/lib/scrollHandler/createScrollParent.js +57 -0
- package/lib/scrollHandler/documentScrollParent.js +169 -0
- package/lib/scrollHandler/scrollParent.js +58 -0
- package/lib/scrollHandler/types.js +1 -0
- package/lib/scrollHandler.js +28 -207
- package/lib/selectNodeHandler.js +2 -3
- package/lib/simple.widget.js +1 -2
- package/lib/test/jqTree/loadOnDemand.test.js +3 -3
- package/lib/test/jqTree/methods.test.js +2 -1
- package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +94 -0
- package/lib/test/node.test.js +49 -7
- package/lib/test/nodeUtils.test.js +20 -0
- package/lib/test/support/exampleData.js +1 -2
- package/lib/test/support/testUtil.js +3 -6
- package/lib/test/support/treeStructure.js +1 -2
- package/lib/tree.jquery.js +6 -7
- package/lib/util.js +4 -7
- package/lib/version.js +2 -3
- package/package.json +27 -27
- package/src/dragAndDropHandler.ts +27 -33
- package/src/keyHandler.ts +0 -8
- package/src/node.ts +32 -48
- package/src/nodeUtils.ts +10 -0
- package/src/playwright/playwright.test.ts +207 -15
- package/src/playwright/testUtils.ts +23 -15
- package/src/scrollHandler/containerScrollParent.ts +177 -0
- package/src/scrollHandler/createScrollParent.ts +50 -0
- package/src/scrollHandler/documentScrollParent.ts +182 -0
- package/src/scrollHandler/types.ts +7 -0
- package/src/scrollHandler.ts +25 -243
- package/src/test/jqTree/loadOnDemand.test.ts +2 -3
- package/src/test/jqTree/methods.test.ts +1 -1
- package/src/test/node.test.ts +84 -25
- package/src/test/nodeUtils.test.ts +21 -0
- package/src/tree.jquery.ts +27 -30
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +391 -229
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
package/lib/tree.jquery.js
CHANGED
|
@@ -45,7 +45,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
45
45
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
46
46
|
var NODE_PARAM_IS_EMPTY = "Node parameter is empty";
|
|
47
47
|
var PARAM_IS_EMPTY = "Parameter is empty: ";
|
|
48
|
-
var JqTreeWidget = /*#__PURE__*/function (_MouseWidget) {
|
|
48
|
+
var JqTreeWidget = exports.JqTreeWidget = /*#__PURE__*/function (_MouseWidget) {
|
|
49
49
|
_inherits(JqTreeWidget, _MouseWidget);
|
|
50
50
|
var _super = _createSuper(JqTreeWidget);
|
|
51
51
|
function JqTreeWidget() {
|
|
@@ -432,13 +432,12 @@ var JqTreeWidget = /*#__PURE__*/function (_MouseWidget) {
|
|
|
432
432
|
}, {
|
|
433
433
|
key: "scrollToNode",
|
|
434
434
|
value: function scrollToNode(node) {
|
|
435
|
+
var _jQuery$offset$top, _jQuery$offset, _this$$el$offset$top, _this$$el$offset;
|
|
435
436
|
if (!node) {
|
|
436
437
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
437
438
|
}
|
|
438
|
-
var
|
|
439
|
-
var
|
|
440
|
-
var treeOffset = this.$el.offset();
|
|
441
|
-
var treeTop = treeOffset ? treeOffset.top : 0;
|
|
439
|
+
var nodeTop = (_jQuery$offset$top = (_jQuery$offset = jQuery(node.element).offset()) === null || _jQuery$offset === void 0 ? void 0 : _jQuery$offset.top) !== null && _jQuery$offset$top !== void 0 ? _jQuery$offset$top : 0;
|
|
440
|
+
var treeTop = (_this$$el$offset$top = (_this$$el$offset = this.$el.offset()) === null || _this$$el$offset === void 0 ? void 0 : _this$$el$offset.top) !== null && _this$$el$offset$top !== void 0 ? _this$$el$offset$top : 0;
|
|
442
441
|
var top = nodeTop - treeTop;
|
|
443
442
|
this.scrollHandler.scrollToY(top);
|
|
444
443
|
return this.element;
|
|
@@ -620,7 +619,7 @@ var JqTreeWidget = /*#__PURE__*/function (_MouseWidget) {
|
|
|
620
619
|
value: function mouseDrag(positionInfo) {
|
|
621
620
|
if (this.options.dragAndDrop) {
|
|
622
621
|
var result = this.dndHandler.mouseDrag(positionInfo);
|
|
623
|
-
this.scrollHandler.checkScrolling();
|
|
622
|
+
this.scrollHandler.checkScrolling(positionInfo);
|
|
624
623
|
return result;
|
|
625
624
|
} else {
|
|
626
625
|
return false;
|
|
@@ -630,6 +629,7 @@ var JqTreeWidget = /*#__PURE__*/function (_MouseWidget) {
|
|
|
630
629
|
key: "mouseStop",
|
|
631
630
|
value: function mouseStop(positionInfo) {
|
|
632
631
|
if (this.options.dragAndDrop) {
|
|
632
|
+
this.scrollHandler.stopScrolling();
|
|
633
633
|
return this.dndHandler.mouseStop(positionInfo);
|
|
634
634
|
} else {
|
|
635
635
|
return false;
|
|
@@ -1056,7 +1056,6 @@ var JqTreeWidget = /*#__PURE__*/function (_MouseWidget) {
|
|
|
1056
1056
|
}]);
|
|
1057
1057
|
return JqTreeWidget;
|
|
1058
1058
|
}(_mouse["default"]);
|
|
1059
|
-
exports.JqTreeWidget = JqTreeWidget;
|
|
1060
1059
|
_defineProperty(JqTreeWidget, "defaults", {
|
|
1061
1060
|
animationSpeed: "fast",
|
|
1062
1061
|
autoEscape: true,
|
package/lib/util.js
CHANGED
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isInt = exports.isFunction = exports.getBoolString = void 0;
|
|
7
|
-
var isInt = function isInt(n) {
|
|
7
|
+
var isInt = exports.isInt = function isInt(n) {
|
|
8
8
|
return typeof n === "number" && n % 1 === 0;
|
|
9
9
|
};
|
|
10
|
-
exports.
|
|
11
|
-
var isFunction = function isFunction(v) {
|
|
10
|
+
var isFunction = exports.isFunction = function isFunction(v) {
|
|
12
11
|
return typeof v === "function";
|
|
13
12
|
};
|
|
14
|
-
exports.
|
|
15
|
-
var getBoolString = function getBoolString(value) {
|
|
13
|
+
var getBoolString = exports.getBoolString = function getBoolString(value) {
|
|
16
14
|
return value ? "true" : "false";
|
|
17
|
-
};
|
|
18
|
-
exports.getBoolString = getBoolString;
|
|
15
|
+
};
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jqtree",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "Tree widget for jQuery",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jquery-plugin",
|
|
@@ -32,46 +32,46 @@
|
|
|
32
32
|
"jquery": "^3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@babel/cli": "^7.
|
|
36
|
-
"@babel/core": "^7.
|
|
37
|
-
"@babel/preset-env": "^7.
|
|
38
|
-
"@babel/preset-typescript": "^7.
|
|
39
|
-
"@playwright/test": "^1.
|
|
40
|
-
"@rollup/plugin-babel": "^6.0.
|
|
41
|
-
"@rollup/plugin-node-resolve": "^15.2.
|
|
42
|
-
"@rollup/plugin-terser": "^0.4.
|
|
43
|
-
"@testing-library/dom": "^9.3.
|
|
44
|
-
"@types/debug": "^4.1.
|
|
45
|
-
"@types/jest": "^29.5.
|
|
46
|
-
"@types/jest-axe": "^3.5.
|
|
47
|
-
"@types/jquery": "^3.5.
|
|
48
|
-
"@types/node": "^20.
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
50
|
-
"@typescript-eslint/parser": "^6.
|
|
51
|
-
"autoprefixer": "^10.4.
|
|
35
|
+
"@babel/cli": "^7.23.0",
|
|
36
|
+
"@babel/core": "^7.23.2",
|
|
37
|
+
"@babel/preset-env": "^7.23.2",
|
|
38
|
+
"@babel/preset-typescript": "^7.23.2",
|
|
39
|
+
"@playwright/test": "^1.39.0",
|
|
40
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
42
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
43
|
+
"@testing-library/dom": "^9.3.3",
|
|
44
|
+
"@types/debug": "^4.1.10",
|
|
45
|
+
"@types/jest": "^29.5.6",
|
|
46
|
+
"@types/jest-axe": "^3.5.7",
|
|
47
|
+
"@types/jquery": "^3.5.24",
|
|
48
|
+
"@types/node": "^20.8.7",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
50
|
+
"@typescript-eslint/parser": "^6.8.0",
|
|
51
|
+
"autoprefixer": "^10.4.16",
|
|
52
52
|
"babel-jest": "^29.7.0",
|
|
53
53
|
"babel-plugin-istanbul": "^6.1.1",
|
|
54
|
-
"eslint": "^8.
|
|
54
|
+
"eslint": "^8.52.0",
|
|
55
55
|
"eslint-plugin-import": "^2.28.1",
|
|
56
|
-
"eslint-plugin-jest": "^27.
|
|
57
|
-
"eslint-plugin-playwright": "^0.
|
|
58
|
-
"eslint-plugin-testing-library": "^6.0
|
|
56
|
+
"eslint-plugin-jest": "^27.4.3",
|
|
57
|
+
"eslint-plugin-playwright": "^0.17.0",
|
|
58
|
+
"eslint-plugin-testing-library": "^6.1.0",
|
|
59
59
|
"givens": "^1.3.9",
|
|
60
|
-
"graphql": "^16.8.
|
|
60
|
+
"graphql": "^16.8.1",
|
|
61
61
|
"jest": "^29.7.0",
|
|
62
62
|
"jest-axe": "^8.0.0",
|
|
63
63
|
"jest-environment-jsdom": "^29.7.0",
|
|
64
|
-
"jest-extended": "^4.0.
|
|
64
|
+
"jest-extended": "^4.0.2",
|
|
65
65
|
"jsonfile": "^6.1.0",
|
|
66
66
|
"lodash.template": "^4.5.0",
|
|
67
|
-
"msw": "^1.3.
|
|
68
|
-
"postcss": "^8.4.
|
|
67
|
+
"msw": "^1.3.2",
|
|
68
|
+
"postcss": "^8.4.31",
|
|
69
69
|
"postcss-cli": "^10.1.0",
|
|
70
70
|
"postcss-import": "^15.1.0",
|
|
71
71
|
"postcss-load-config": "^4.0.1",
|
|
72
72
|
"postcss-nested": "^6.0.1",
|
|
73
73
|
"prettier": "^3.0.3",
|
|
74
|
-
"rollup": "^
|
|
74
|
+
"rollup": "^4.1.4",
|
|
75
75
|
"rollup-plugin-serve": "^2.0.2",
|
|
76
76
|
"tslib": "^2.6.2",
|
|
77
77
|
"typescript": "^5.2.2"
|
|
@@ -15,7 +15,6 @@ export class DragAndDropHandler {
|
|
|
15
15
|
public isDragging: boolean;
|
|
16
16
|
public currentItem: NodeElement | null;
|
|
17
17
|
public hoveredArea: HitArea | null;
|
|
18
|
-
public positionInfo: PositionInfo | null;
|
|
19
18
|
|
|
20
19
|
private treeWidget: JqTreeWidget;
|
|
21
20
|
private dragElement: DragElement | null;
|
|
@@ -29,7 +28,6 @@ export class DragAndDropHandler {
|
|
|
29
28
|
this.hitAreas = [];
|
|
30
29
|
this.isDragging = false;
|
|
31
30
|
this.currentItem = null;
|
|
32
|
-
this.positionInfo = null;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
public mouseCapture(positionInfo: PositionInfo): boolean | null {
|
|
@@ -80,12 +78,12 @@ export class DragAndDropHandler {
|
|
|
80
78
|
positionInfo.pageX - left,
|
|
81
79
|
positionInfo.pageY - top,
|
|
82
80
|
this.treeWidget.element,
|
|
83
|
-
this.treeWidget.options.autoEscape ?? true
|
|
81
|
+
this.treeWidget.options.autoEscape ?? true,
|
|
84
82
|
);
|
|
85
83
|
|
|
86
84
|
this.isDragging = true;
|
|
87
|
-
this.positionInfo = positionInfo;
|
|
88
85
|
this.currentItem.$element.addClass("jqtree-moving");
|
|
86
|
+
|
|
89
87
|
return true;
|
|
90
88
|
}
|
|
91
89
|
|
|
@@ -100,11 +98,10 @@ export class DragAndDropHandler {
|
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
this.dragElement.move(positionInfo.pageX, positionInfo.pageY);
|
|
103
|
-
this.positionInfo = positionInfo;
|
|
104
101
|
|
|
105
102
|
const area = this.findHoveredArea(
|
|
106
103
|
positionInfo.pageX,
|
|
107
|
-
positionInfo.pageY
|
|
104
|
+
positionInfo.pageY,
|
|
108
105
|
);
|
|
109
106
|
|
|
110
107
|
if (area && this.canMoveToArea(area)) {
|
|
@@ -134,7 +131,7 @@ export class DragAndDropHandler {
|
|
|
134
131
|
if (this.treeWidget.options.onDragMove) {
|
|
135
132
|
this.treeWidget.options.onDragMove(
|
|
136
133
|
this.currentItem.node,
|
|
137
|
-
positionInfo.originalEvent
|
|
134
|
+
positionInfo.originalEvent,
|
|
138
135
|
);
|
|
139
136
|
}
|
|
140
137
|
}
|
|
@@ -157,13 +154,12 @@ export class DragAndDropHandler {
|
|
|
157
154
|
}
|
|
158
155
|
|
|
159
156
|
this.isDragging = false;
|
|
160
|
-
this.positionInfo = null;
|
|
161
157
|
|
|
162
158
|
if (!this.hoveredArea && currentItem) {
|
|
163
159
|
if (this.treeWidget.options.onDragStop) {
|
|
164
160
|
this.treeWidget.options.onDragStop(
|
|
165
161
|
currentItem.node,
|
|
166
|
-
positionInfo.originalEvent
|
|
162
|
+
positionInfo.originalEvent,
|
|
167
163
|
);
|
|
168
164
|
}
|
|
169
165
|
}
|
|
@@ -178,7 +174,7 @@ export class DragAndDropHandler {
|
|
|
178
174
|
this.generateHitAreas();
|
|
179
175
|
|
|
180
176
|
this.currentItem = this.treeWidget._getNodeElementForNode(
|
|
181
|
-
this.currentItem.node
|
|
177
|
+
this.currentItem.node,
|
|
182
178
|
);
|
|
183
179
|
|
|
184
180
|
if (this.isDragging) {
|
|
@@ -194,7 +190,7 @@ export class DragAndDropHandler {
|
|
|
194
190
|
const hitAreasGenerator = new HitAreasGenerator(
|
|
195
191
|
this.treeWidget.tree,
|
|
196
192
|
this.currentItem.node,
|
|
197
|
-
this.getTreeDimensions().bottom
|
|
193
|
+
this.getTreeDimensions().bottom,
|
|
198
194
|
);
|
|
199
195
|
this.hitAreas = hitAreasGenerator.generate();
|
|
200
196
|
}
|
|
@@ -218,7 +214,7 @@ export class DragAndDropHandler {
|
|
|
218
214
|
return this.treeWidget.options.onCanMoveTo(
|
|
219
215
|
this.currentItem.node,
|
|
220
216
|
area.node,
|
|
221
|
-
positionName
|
|
217
|
+
positionName,
|
|
222
218
|
);
|
|
223
219
|
}
|
|
224
220
|
|
|
@@ -297,7 +293,7 @@ export class DragAndDropHandler {
|
|
|
297
293
|
|
|
298
294
|
// add new drop hint
|
|
299
295
|
const nodeElement = this.treeWidget._getNodeElementForNode(
|
|
300
|
-
this.hoveredArea.node
|
|
296
|
+
this.hoveredArea.node,
|
|
301
297
|
);
|
|
302
298
|
this.previousGhost = nodeElement.addDropHint(this.hoveredArea.position);
|
|
303
299
|
}
|
|
@@ -310,7 +306,7 @@ export class DragAndDropHandler {
|
|
|
310
306
|
() => {
|
|
311
307
|
this.refresh();
|
|
312
308
|
this.updateDropHint();
|
|
313
|
-
}
|
|
309
|
+
},
|
|
314
310
|
);
|
|
315
311
|
};
|
|
316
312
|
|
|
@@ -321,7 +317,7 @@ export class DragAndDropHandler {
|
|
|
321
317
|
if (openFolderDelay !== false) {
|
|
322
318
|
this.openFolderTimer = window.setTimeout(
|
|
323
319
|
openFolder,
|
|
324
|
-
openFolderDelay
|
|
320
|
+
openFolderDelay,
|
|
325
321
|
);
|
|
326
322
|
}
|
|
327
323
|
}
|
|
@@ -464,7 +460,7 @@ abstract class VisibleNodeIterator {
|
|
|
464
460
|
protected abstract handleNode(
|
|
465
461
|
node: Node,
|
|
466
462
|
nextNode: Node | null,
|
|
467
|
-
$element: JQuery
|
|
463
|
+
$element: JQuery,
|
|
468
464
|
): void;
|
|
469
465
|
|
|
470
466
|
/*
|
|
@@ -478,12 +474,12 @@ abstract class VisibleNodeIterator {
|
|
|
478
474
|
protected abstract handleClosedFolder(
|
|
479
475
|
node: Node,
|
|
480
476
|
nextNode: Node | null,
|
|
481
|
-
$element: JQuery
|
|
477
|
+
$element: JQuery,
|
|
482
478
|
): void;
|
|
483
479
|
|
|
484
480
|
protected abstract handleAfterOpenFolder(
|
|
485
481
|
node: Node,
|
|
486
|
-
nextNode: Node | null
|
|
482
|
+
nextNode: Node | null,
|
|
487
483
|
): void;
|
|
488
484
|
|
|
489
485
|
protected abstract handleFirstNode(node: Node): void;
|
|
@@ -512,20 +508,18 @@ export class HitAreasGenerator extends VisibleNodeIterator {
|
|
|
512
508
|
}
|
|
513
509
|
|
|
514
510
|
protected generateHitAreas(positions: HitArea[]): HitArea[] {
|
|
515
|
-
let previousTop =
|
|
511
|
+
let previousTop = positions[0]?.top ?? 0;
|
|
516
512
|
let group = [];
|
|
517
513
|
const hitAreas: HitArea[] = [];
|
|
518
514
|
|
|
519
515
|
for (const position of positions) {
|
|
520
516
|
if (position.top !== previousTop && group.length) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
);
|
|
528
|
-
}
|
|
517
|
+
this.generateHitAreasForGroup(
|
|
518
|
+
hitAreas,
|
|
519
|
+
group,
|
|
520
|
+
previousTop,
|
|
521
|
+
position.top,
|
|
522
|
+
);
|
|
529
523
|
|
|
530
524
|
previousTop = position.top;
|
|
531
525
|
group = [];
|
|
@@ -538,7 +532,7 @@ export class HitAreasGenerator extends VisibleNodeIterator {
|
|
|
538
532
|
hitAreas,
|
|
539
533
|
group,
|
|
540
534
|
previousTop,
|
|
541
|
-
this.treeBottom
|
|
535
|
+
this.treeBottom,
|
|
542
536
|
);
|
|
543
537
|
|
|
544
538
|
return hitAreas;
|
|
@@ -574,7 +568,7 @@ export class HitAreasGenerator extends VisibleNodeIterator {
|
|
|
574
568
|
protected handleClosedFolder(
|
|
575
569
|
node: Node,
|
|
576
570
|
nextNode: Node,
|
|
577
|
-
$element: JQuery
|
|
571
|
+
$element: JQuery,
|
|
578
572
|
): void {
|
|
579
573
|
const top = this.getTop($element);
|
|
580
574
|
|
|
@@ -596,7 +590,7 @@ export class HitAreasGenerator extends VisibleNodeIterator {
|
|
|
596
590
|
this.addPosition(
|
|
597
591
|
node,
|
|
598
592
|
Position.Before,
|
|
599
|
-
this.getTop(jQuery(node.element))
|
|
593
|
+
this.getTop(jQuery(node.element)),
|
|
600
594
|
);
|
|
601
595
|
}
|
|
602
596
|
}
|
|
@@ -650,7 +644,7 @@ export class HitAreasGenerator extends VisibleNodeIterator {
|
|
|
650
644
|
hitAreas: HitArea[],
|
|
651
645
|
positionsInGroup: HitArea[],
|
|
652
646
|
top: number,
|
|
653
|
-
bottom: number
|
|
647
|
+
bottom: number,
|
|
654
648
|
): void {
|
|
655
649
|
// limit positions in group
|
|
656
650
|
const positionCount = Math.min(positionsInGroup.length, 4);
|
|
@@ -687,13 +681,13 @@ class DragElement {
|
|
|
687
681
|
offsetX: number,
|
|
688
682
|
offsetY: number,
|
|
689
683
|
$tree: JQuery,
|
|
690
|
-
autoEscape: boolean
|
|
684
|
+
autoEscape: boolean,
|
|
691
685
|
) {
|
|
692
686
|
this.offsetX = offsetX;
|
|
693
687
|
this.offsetY = offsetY;
|
|
694
688
|
|
|
695
689
|
this.$element = jQuery("<span>").addClass(
|
|
696
|
-
"jqtree-title jqtree-dragging"
|
|
690
|
+
"jqtree-title jqtree-dragging",
|
|
697
691
|
);
|
|
698
692
|
|
|
699
693
|
if (autoEscape) {
|
package/src/keyHandler.ts
CHANGED
|
@@ -62,14 +62,6 @@ export default class KeyHandler {
|
|
|
62
62
|
} else {
|
|
63
63
|
this.treeWidget.selectNode(node);
|
|
64
64
|
|
|
65
|
-
if (
|
|
66
|
-
!this.treeWidget.scrollHandler.isScrolledIntoView(
|
|
67
|
-
jQuery(node.element).find(".jqtree-element")
|
|
68
|
-
)
|
|
69
|
-
) {
|
|
70
|
-
this.treeWidget.scrollToNode(node);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
65
|
return false;
|
|
74
66
|
}
|
|
75
67
|
}
|
package/src/node.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
children: NodeData[];
|
|
3
|
-
}
|
|
1
|
+
import { isNodeRecordWithChildren } from "./nodeUtils";
|
|
4
2
|
|
|
5
3
|
export enum Position {
|
|
6
4
|
Before = 1,
|
|
@@ -33,13 +31,6 @@ export const getPositionName = (position: Position): string => {
|
|
|
33
31
|
export const getPosition = (name: string): Position | undefined =>
|
|
34
32
|
positionNames[name];
|
|
35
33
|
|
|
36
|
-
const isNodeRecordWithChildren = (
|
|
37
|
-
data: NodeData
|
|
38
|
-
): data is NodeRecordWithChildren =>
|
|
39
|
-
typeof data === "object" &&
|
|
40
|
-
"children" in data &&
|
|
41
|
-
data["children"] instanceof Array;
|
|
42
|
-
|
|
43
34
|
export class Node implements INode {
|
|
44
35
|
public id?: NodeId;
|
|
45
36
|
public name: string;
|
|
@@ -56,12 +47,20 @@ export class Node implements INode {
|
|
|
56
47
|
|
|
57
48
|
[key: string]: unknown;
|
|
58
49
|
|
|
59
|
-
constructor(
|
|
50
|
+
constructor(
|
|
51
|
+
nodeData: NodeData | null = null,
|
|
52
|
+
isRoot = false,
|
|
53
|
+
nodeClass = Node,
|
|
54
|
+
) {
|
|
60
55
|
this.name = "";
|
|
61
|
-
this.isEmptyFolder = false;
|
|
62
56
|
this.load_on_demand = false;
|
|
63
57
|
|
|
64
|
-
this.
|
|
58
|
+
this.isEmptyFolder =
|
|
59
|
+
nodeData != null &&
|
|
60
|
+
isNodeRecordWithChildren(nodeData) &&
|
|
61
|
+
nodeData.children.length === 0;
|
|
62
|
+
|
|
63
|
+
this.setData(nodeData);
|
|
65
64
|
|
|
66
65
|
this.children = [];
|
|
67
66
|
this.parent = null;
|
|
@@ -77,10 +76,10 @@ export class Node implements INode {
|
|
|
77
76
|
Set the data of this node.
|
|
78
77
|
|
|
79
78
|
setData(string): set the name of the node
|
|
80
|
-
|
|
79
|
+
setData(object): set attributes of the node
|
|
81
80
|
|
|
82
81
|
Examples:
|
|
83
|
-
|
|
82
|
+
setData('node1')
|
|
84
83
|
|
|
85
84
|
setData({ name: 'node1', id: 1});
|
|
86
85
|
|
|
@@ -133,16 +132,12 @@ export class Node implements INode {
|
|
|
133
132
|
public loadFromData(data: NodeData[]): Node {
|
|
134
133
|
this.removeChildren();
|
|
135
134
|
|
|
136
|
-
for (const
|
|
137
|
-
const node = this.createNode(
|
|
135
|
+
for (const childData of data) {
|
|
136
|
+
const node = this.createNode(childData);
|
|
138
137
|
this.addChild(node);
|
|
139
138
|
|
|
140
|
-
if (isNodeRecordWithChildren(
|
|
141
|
-
|
|
142
|
-
node.isEmptyFolder = true;
|
|
143
|
-
} else {
|
|
144
|
-
node.loadFromData(o.children);
|
|
145
|
-
}
|
|
139
|
+
if (isNodeRecordWithChildren(childData)) {
|
|
140
|
+
node.loadFromData(childData.children);
|
|
146
141
|
}
|
|
147
142
|
}
|
|
148
143
|
|
|
@@ -254,7 +249,7 @@ export class Node implements INode {
|
|
|
254
249
|
public moveNode(
|
|
255
250
|
movedNode: Node,
|
|
256
251
|
targetNode: Node,
|
|
257
|
-
position: Position
|
|
252
|
+
position: Position,
|
|
258
253
|
): boolean {
|
|
259
254
|
if (!movedNode.parent || movedNode.isParentOf(targetNode)) {
|
|
260
255
|
// - Node is parent of target node
|
|
@@ -268,7 +263,7 @@ export class Node implements INode {
|
|
|
268
263
|
if (targetNode.parent) {
|
|
269
264
|
targetNode.parent.addChildAtPosition(
|
|
270
265
|
movedNode,
|
|
271
|
-
targetNode.parent.getChildIndex(targetNode) + 1
|
|
266
|
+
targetNode.parent.getChildIndex(targetNode) + 1,
|
|
272
267
|
);
|
|
273
268
|
return true;
|
|
274
269
|
}
|
|
@@ -279,7 +274,7 @@ export class Node implements INode {
|
|
|
279
274
|
if (targetNode.parent) {
|
|
280
275
|
targetNode.parent.addChildAtPosition(
|
|
281
276
|
movedNode,
|
|
282
|
-
targetNode.parent.getChildIndex(targetNode)
|
|
277
|
+
targetNode.parent.getChildIndex(targetNode),
|
|
283
278
|
);
|
|
284
279
|
return true;
|
|
285
280
|
}
|
|
@@ -380,13 +375,7 @@ export class Node implements INode {
|
|
|
380
375
|
const childIndex = this.parent.getChildIndex(this);
|
|
381
376
|
this.parent.addChildAtPosition(node, childIndex + 1);
|
|
382
377
|
|
|
383
|
-
|
|
384
|
-
isNodeRecordWithChildren(nodeInfo) &&
|
|
385
|
-
nodeInfo.children.length
|
|
386
|
-
) {
|
|
387
|
-
node.loadFromData(nodeInfo.children);
|
|
388
|
-
}
|
|
389
|
-
|
|
378
|
+
node.loadChildrenFromData(nodeInfo);
|
|
390
379
|
return node;
|
|
391
380
|
}
|
|
392
381
|
}
|
|
@@ -400,13 +389,7 @@ export class Node implements INode {
|
|
|
400
389
|
const childIndex = this.parent.getChildIndex(this);
|
|
401
390
|
this.parent.addChildAtPosition(node, childIndex);
|
|
402
391
|
|
|
403
|
-
|
|
404
|
-
isNodeRecordWithChildren(nodeInfo) &&
|
|
405
|
-
nodeInfo.children.length
|
|
406
|
-
) {
|
|
407
|
-
node.loadFromData(nodeInfo.children);
|
|
408
|
-
}
|
|
409
|
-
|
|
392
|
+
node.loadChildrenFromData(nodeInfo);
|
|
410
393
|
return node;
|
|
411
394
|
}
|
|
412
395
|
}
|
|
@@ -443,10 +426,7 @@ export class Node implements INode {
|
|
|
443
426
|
const node = this.createNode(nodeInfo);
|
|
444
427
|
this.addChild(node);
|
|
445
428
|
|
|
446
|
-
|
|
447
|
-
node.loadFromData(nodeInfo.children);
|
|
448
|
-
}
|
|
449
|
-
|
|
429
|
+
node.loadChildrenFromData(nodeInfo);
|
|
450
430
|
return node;
|
|
451
431
|
}
|
|
452
432
|
|
|
@@ -454,10 +434,7 @@ export class Node implements INode {
|
|
|
454
434
|
const node = this.createNode(nodeInfo);
|
|
455
435
|
this.addChildAtPosition(node, 0);
|
|
456
436
|
|
|
457
|
-
|
|
458
|
-
node.loadFromData(nodeInfo.children);
|
|
459
|
-
}
|
|
460
|
-
|
|
437
|
+
node.loadChildrenFromData(nodeInfo);
|
|
461
438
|
return node;
|
|
462
439
|
}
|
|
463
440
|
|
|
@@ -702,4 +679,11 @@ export class Node implements INode {
|
|
|
702
679
|
const nodeClass = this.getNodeClass();
|
|
703
680
|
return new nodeClass(nodeData);
|
|
704
681
|
}
|
|
682
|
+
|
|
683
|
+
// Load children data from nodeInfo if it has children
|
|
684
|
+
private loadChildrenFromData(nodeInfo: NodeData) {
|
|
685
|
+
if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
|
|
686
|
+
this.loadFromData(nodeInfo.children);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
705
689
|
}
|
package/src/nodeUtils.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface NodeRecordWithChildren extends NodeRecord {
|
|
2
|
+
children: NodeData[];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const isNodeRecordWithChildren = (
|
|
6
|
+
data: NodeData,
|
|
7
|
+
): data is NodeRecordWithChildren =>
|
|
8
|
+
typeof data === "object" &&
|
|
9
|
+
"children" in data &&
|
|
10
|
+
data["children"] instanceof Array;
|