jqtree 1.5.2 → 1.6.2
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 +1 -0
- package/.github/workflows/ci.yml +54 -0
- package/.github/workflows/codeql-analysis.yml +28 -0
- package/README.md +1 -1
- package/_config.yml +1 -1
- package/_entries/10_changelog.md +20 -0
- package/_entries/{36_showemptynode.md → 36_showemptyfolder.md} +5 -5
- package/_entries/38_start_dnd_delay.md +13 -0
- package/_entries/{38_tabindex.md → 39_tabindex.md} +0 -0
- package/_entries/{39_usecontextmenu.md → 40_usecontextmenu.md} +0 -0
- package/_entries/{40_functions.md → 41_functions.md} +0 -0
- package/_entries/{41_addparentnode.md → 42_addparentnode.md} +0 -0
- package/_entries/{42_addnodeafter.md → 43_addnodeafter.md} +0 -0
- package/_entries/{43_addnodebefore.md → 44_addnodebefore.md} +0 -0
- package/_entries/{44_appendnode.md → 45_appendnode.md} +0 -0
- package/_entries/{45_closenode.md → 46_closenode.md} +0 -0
- package/_entries/{46_destroy.md → 47_destroy.md} +0 -0
- package/_entries/{47_getnodebycallback.md → 48_getnodebycallback.md} +0 -0
- package/_entries/{48_getnodebyid.md → 49_getnodebyid.md} +0 -0
- package/_entries/{49_getnodebyhtmlelement.md → 50_getnodebyhtmlelement.md} +0 -0
- package/_entries/{50_getselectednode.md → 51_getselectednode.md} +0 -0
- package/_entries/{51_getstate.md → 52_getstate.md} +0 -0
- package/_entries/{52_gettree.md → 53_gettree.md} +0 -0
- package/_entries/{53_isdragging.md → 54_isdragging.md} +0 -0
- package/_entries/{54_loaddata.md → 55_loaddata.md} +0 -0
- package/_entries/{55_loaddatafromurl.md → 56_loaddatafromurl.md} +0 -0
- package/_entries/{56_movedown.md → 57_movedown.md} +0 -0
- package/_entries/{57_movenode.md → 58_movenode.md} +0 -0
- package/_entries/{58_moveup.md → 59_moveup.md} +0 -0
- package/_entries/{59_opennode.md → 60_opennode.md} +0 -0
- package/_entries/{60_prependnode.md → 61_prependnode.md} +0 -0
- package/_entries/62_refresh.md +12 -0
- package/_entries/{61_reload.md → 63_reload.md} +0 -0
- package/_entries/{62_removenode.md → 64_removenode.md} +0 -0
- package/_entries/{63_selectnode.md → 65_selectnode.md} +0 -0
- package/_entries/{64_scrolltonode.md → 66_scrolltonode.md} +0 -0
- package/_entries/{65_setoption.md → 67_setoption.md} +0 -0
- package/_entries/{66_setstate.md → 68_setstate.md} +0 -0
- package/_entries/{67_toggle.md → 69_toggle.md} +0 -0
- package/_entries/{68_tojson.md → 70_tojson.md} +0 -0
- package/_entries/{69_updatenode.md → 71_updatenode.md} +0 -0
- package/_entries/{70_events.md → 72_events.md} +0 -0
- package/_entries/{71_tree-click.md → 73_tree-click.md} +0 -0
- package/_entries/{72_tree-close.md → 74_tree-close.md} +0 -0
- package/_entries/{73_tree-contextmenu.md → 75_tree-contextmenu.md} +0 -0
- package/_entries/{74_tree-dblclick.md → 76_tree-dblclick.md} +0 -0
- package/_entries/{75_tree-init.md → 77_tree-init.md} +0 -0
- package/_entries/{76_tree-load-data.md → 78_tree-load-data.md} +0 -0
- package/_entries/{77_tree-loading-data.md → 79_tree-loading-data.md} +0 -0
- package/_entries/{78_tree-move.md → 80_tree-move.md} +0 -0
- package/_entries/{79_tree-refresh.md → 81_tree-refresh.md} +0 -0
- package/_entries/{80_tree-open.md → 82_tree-open.md} +0 -0
- package/_entries/{81_tree-select.md → 83_tree-select.md} +0 -0
- package/_entries/{82_multiple-selection.md → 84_multiple-selection.md} +0 -0
- package/_entries/{83_add-to-selection.md → 85_add-to-selection.md} +0 -0
- package/_entries/{84_get-selected-nodes.md → 86_get-selected-nodes.md} +0 -0
- package/_entries/{85_is-node-selected.md → 87_is-node-selected.md} +0 -0
- package/_entries/{86_remove-from-selection.md → 88_remove-from-selection.md} +0 -0
- package/_entries/{87_node-functions.md → 89_node-functions.md} +0 -0
- package/_entries/{88_children.md → 90_children.md} +0 -0
- package/_entries/{89_getdata.md → 91_getdata.md} +0 -0
- package/_entries/{90_getlevel.md → 92_getlevel.md} +0 -0
- package/_entries/{91_getnextnode.md → 93_getnextnode.md} +0 -0
- package/_entries/{92_getnextsibling.md → 94_getnextsibling.md} +0 -0
- package/_entries/{93_getpreviousnode.md → 95_getpreviousnode.md} +0 -0
- package/_entries/{94_getprevioussibling.md → 96_getprevioussibling.md} +0 -0
- package/_entries/{95_parent.md → 97_parent.md} +0 -0
- package/_examples/13_drag_outside.html +2 -1
- package/_examples/14_filter.html +113 -0
- package/_layouts/base.html +1 -23
- package/babel.config.json +11 -0
- package/babel.coverage.config.json +4 -0
- package/bower.json +1 -1
- package/jest-browser.config.js +0 -3
- package/jest-jsdom.config.js +1 -2
- package/jqtree.css +4 -1
- package/jqtree.postcss +3 -0
- package/lib/dataLoader.js +146 -98
- package/lib/dragAndDropHandler.js +668 -470
- package/lib/elementsRenderer.js +282 -197
- package/lib/jqtreeOptions.js +1 -2
- package/lib/keyHandler.js +134 -87
- package/lib/mouse.widget.js +288 -165
- package/lib/node.js +693 -505
- package/lib/nodeElement.js +329 -205
- package/lib/playwright/playwright.test.js +216 -189
- package/lib/playwright/testUtil.js +437 -192
- package/lib/playwright/visualRegression.js +183 -117
- package/lib/saveStateHandler.js +311 -204
- package/lib/scrollHandler.js +293 -199
- package/lib/selectNodeHandler.js +140 -105
- package/lib/simple.widget.js +184 -109
- package/lib/test/global.d.js +3 -0
- package/lib/test/jqTree/create.test.js +44 -40
- package/lib/test/jqTree/events.test.js +185 -138
- package/lib/test/jqTree/keyboard.test.js +216 -199
- package/lib/test/jqTree/loadOnDemand.test.js +233 -157
- package/lib/test/jqTree/methods.test.js +1269 -1000
- package/lib/test/jqTree/options.test.js +467 -398
- package/lib/test/node.test.js +1036 -873
- package/lib/test/nodeUtil.test.js +21 -20
- package/lib/test/support/exampleData.js +35 -23
- package/lib/test/support/jqTreeMatchers.js +72 -54
- package/lib/test/support/matchers.d.js +1 -0
- package/lib/test/support/setupTests.js +9 -3
- package/lib/test/support/testUtil.js +38 -15
- package/lib/test/support/treeStructure.js +41 -32
- package/lib/test/util.test.js +21 -20
- package/lib/tree.jquery.d.js +1 -0
- package/lib/tree.jquery.js +1264 -883
- package/lib/types.js +1 -2
- package/lib/typings.d.js +2 -0
- package/lib/util.js +21 -7
- package/lib/version.js +8 -3
- package/package.json +43 -36
- package/production +4 -4
- package/rollup.config.js +16 -11
- package/src/dataLoader.ts +6 -6
- package/src/dragAndDropHandler.ts +0 -4
- package/src/elementsRenderer.ts +4 -0
- package/src/jqtreeOptions.ts +33 -32
- package/src/mouse.widget.ts +58 -29
- package/src/node.ts +32 -46
- package/src/nodeElement.ts +17 -9
- package/src/playwright/.eslintrc +5 -0
- package/src/playwright/playwright.test.ts +30 -30
- package/src/playwright/testUtil.ts +36 -37
- package/src/saveStateHandler.ts +11 -6
- package/src/selectNodeHandler.ts +14 -21
- package/src/simple.widget.ts +1 -1
- package/src/test/.eslintrc +4 -0
- package/src/test/jqTree/create.test.ts +0 -1
- package/src/test/jqTree/events.test.ts +12 -13
- package/src/test/jqTree/keyboard.test.ts +0 -1
- package/src/test/jqTree/loadOnDemand.test.ts +46 -1
- package/src/test/jqTree/methods.test.ts +67 -18
- package/src/test/jqTree/options.test.ts +5 -6
- package/src/test/node.test.ts +2 -2
- package/src/test/support/jqTreeMatchers.ts +8 -9
- package/src/test/support/matchers.d.ts +2 -4
- package/src/test/support/setupTests.ts +2 -1
- package/src/tree.jquery.d.ts +19 -13
- package/src/tree.jquery.ts +63 -57
- package/src/version.ts +1 -1
- package/static/bower.json +3 -3
- package/static/bower_components/fontawesome/css/all.min.css +2 -2
- package/static/bower_components/fontawesome/webfonts/fa-brands-400.eot +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-brands-400.svg +774 -627
- package/static/bower_components/fontawesome/webfonts/fa-brands-400.ttf +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-regular-400.eot +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-regular-400.svg +93 -95
- package/static/bower_components/fontawesome/webfonts/fa-regular-400.ttf +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-solid-900.eot +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-solid-900.svg +1164 -1074
- package/static/bower_components/fontawesome/webfonts/fa-solid-900.ttf +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff +0 -0
- package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
- package/static/bower_components/jquery/dist/jquery.js +118 -109
- package/static/bower_components/jquery/dist/jquery.min.js +2 -2
- package/static/bower_components/jquery-mockjax/dist/jquery.mockjax.js +15 -9
- package/static/example.css +13 -0
- package/static/example.postcss +13 -0
- package/static/example_data.js +33 -36
- package/static/examples/filter.js +63 -0
- package/tree.jquery.debug.js +4809 -3305
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +3 -3
- package/tree.jquery.js.map +1 -1
- package/tsconfig.json +1 -0
- package/.travis.yml +0 -18
package/lib/node.js
CHANGED
|
@@ -1,94 +1,153 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPositionName = exports.getPosition = exports.Position = exports.Node = void 0;
|
|
7
|
+
|
|
8
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
9
|
+
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
13
|
+
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
|
|
16
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
17
|
+
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
|
+
|
|
20
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
|
|
22
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
23
|
+
|
|
4
24
|
var Position;
|
|
25
|
+
exports.Position = Position;
|
|
26
|
+
|
|
5
27
|
(function (Position) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})(Position
|
|
28
|
+
Position[Position["Before"] = 1] = "Before";
|
|
29
|
+
Position[Position["After"] = 2] = "After";
|
|
30
|
+
Position[Position["Inside"] = 3] = "Inside";
|
|
31
|
+
Position[Position["None"] = 4] = "None";
|
|
32
|
+
})(Position || (exports.Position = Position = {}));
|
|
33
|
+
|
|
11
34
|
var positionNames = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
35
|
+
before: Position.Before,
|
|
36
|
+
after: Position.After,
|
|
37
|
+
inside: Position.Inside,
|
|
38
|
+
none: Position.None
|
|
16
39
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
40
|
+
|
|
41
|
+
var getPositionName = function getPositionName(position) {
|
|
42
|
+
for (var name in positionNames) {
|
|
43
|
+
if (Object.prototype.hasOwnProperty.call(positionNames, name)) {
|
|
44
|
+
if (positionNames[name] === position) {
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
24
47
|
}
|
|
25
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return "";
|
|
26
51
|
};
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
|
|
53
|
+
exports.getPositionName = getPositionName;
|
|
54
|
+
|
|
55
|
+
var getPosition = function getPosition(name) {
|
|
56
|
+
return positionNames[name];
|
|
29
57
|
};
|
|
30
|
-
var Node = /** @class */ (function () {
|
|
31
|
-
function Node(o, isRoot, nodeClass) {
|
|
32
|
-
if (o === void 0) { o = null; }
|
|
33
|
-
if (isRoot === void 0) { isRoot = false; }
|
|
34
|
-
if (nodeClass === void 0) { nodeClass = Node; }
|
|
35
|
-
this.name = "";
|
|
36
|
-
this.isEmptyFolder = false;
|
|
37
|
-
this.load_on_demand = false;
|
|
38
|
-
this.setData(o);
|
|
39
|
-
this.children = [];
|
|
40
|
-
this.parent = null;
|
|
41
|
-
if (isRoot) {
|
|
42
|
-
this.idMapping = {};
|
|
43
|
-
this.tree = this;
|
|
44
|
-
this.nodeClass = nodeClass;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/*
|
|
48
|
-
Set the data of this node.
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
setdata(object): set attributes of the node
|
|
59
|
+
exports.getPosition = getPosition;
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
var isNodeRecordWithChildren = function isNodeRecordWithChildren(data) {
|
|
62
|
+
return _typeof(data) === "object" && "children" in data && data["children"] instanceof Array;
|
|
63
|
+
};
|
|
55
64
|
|
|
56
|
-
|
|
65
|
+
var Node = /*#__PURE__*/function () {
|
|
66
|
+
function Node() {
|
|
67
|
+
var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
68
|
+
var isRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
69
|
+
var nodeClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Node;
|
|
57
70
|
|
|
58
|
-
|
|
71
|
+
_classCallCheck(this, Node);
|
|
59
72
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
_defineProperty(this, "id", void 0);
|
|
74
|
+
|
|
75
|
+
_defineProperty(this, "name", void 0);
|
|
76
|
+
|
|
77
|
+
_defineProperty(this, "children", void 0);
|
|
78
|
+
|
|
79
|
+
_defineProperty(this, "parent", void 0);
|
|
80
|
+
|
|
81
|
+
_defineProperty(this, "idMapping", void 0);
|
|
82
|
+
|
|
83
|
+
_defineProperty(this, "tree", void 0);
|
|
84
|
+
|
|
85
|
+
_defineProperty(this, "nodeClass", void 0);
|
|
86
|
+
|
|
87
|
+
_defineProperty(this, "load_on_demand", void 0);
|
|
88
|
+
|
|
89
|
+
_defineProperty(this, "is_open", void 0);
|
|
90
|
+
|
|
91
|
+
_defineProperty(this, "element", void 0);
|
|
92
|
+
|
|
93
|
+
_defineProperty(this, "is_loading", void 0);
|
|
94
|
+
|
|
95
|
+
_defineProperty(this, "isEmptyFolder", void 0);
|
|
96
|
+
|
|
97
|
+
this.name = "";
|
|
98
|
+
this.isEmptyFolder = false;
|
|
99
|
+
this.load_on_demand = false;
|
|
100
|
+
this.setData(o);
|
|
101
|
+
this.children = [];
|
|
102
|
+
this.parent = null;
|
|
103
|
+
|
|
104
|
+
if (isRoot) {
|
|
105
|
+
this.idMapping = new Map();
|
|
106
|
+
this.tree = this;
|
|
107
|
+
this.nodeClass = nodeClass;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/*
|
|
111
|
+
Set the data of this node.
|
|
112
|
+
setData(string): set the name of the node
|
|
113
|
+
setdata(object): set attributes of the node
|
|
114
|
+
Examples:
|
|
115
|
+
setdata('node1')
|
|
116
|
+
setData({ name: 'node1', id: 1});
|
|
117
|
+
setData({ name: 'node2', id: 2, color: 'green'});
|
|
118
|
+
* This is an internal function; it is not in the docs
|
|
119
|
+
* Does not remove existing node values
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
_createClass(Node, [{
|
|
124
|
+
key: "setData",
|
|
125
|
+
value: function setData(o) {
|
|
126
|
+
if (!o) {
|
|
127
|
+
return;
|
|
128
|
+
} else if (typeof o === "string") {
|
|
129
|
+
this.name = o;
|
|
130
|
+
} else if (_typeof(o) === "object") {
|
|
131
|
+
for (var _key in o) {
|
|
132
|
+
if (Object.prototype.hasOwnProperty.call(o, _key)) {
|
|
133
|
+
var value = o[_key];
|
|
134
|
+
|
|
135
|
+
if (_key === "label" || _key === "name") {
|
|
136
|
+
// You can use the 'label' key instead of 'name'; this is a legacy feature
|
|
137
|
+
if (typeof value === "string") {
|
|
138
|
+
this.name = value;
|
|
139
|
+
}
|
|
140
|
+
} else if (_key !== "children" && _key !== "parent") {
|
|
141
|
+
// You can't update the children or the parent using this function
|
|
142
|
+
this[_key] = value;
|
|
85
143
|
}
|
|
144
|
+
}
|
|
86
145
|
}
|
|
87
|
-
|
|
146
|
+
}
|
|
147
|
+
}
|
|
88
148
|
/*
|
|
89
149
|
Create tree from data.
|
|
90
|
-
|
|
91
|
-
Structure of data is:
|
|
150
|
+
Structure of data is:
|
|
92
151
|
[
|
|
93
152
|
{
|
|
94
153
|
name: 'node1',
|
|
@@ -102,490 +161,619 @@ var Node = /** @class */ (function () {
|
|
|
102
161
|
}
|
|
103
162
|
]
|
|
104
163
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
164
|
+
|
|
165
|
+
}, {
|
|
166
|
+
key: "loadFromData",
|
|
167
|
+
value: function loadFromData(data) {
|
|
168
|
+
this.removeChildren();
|
|
169
|
+
|
|
170
|
+
var _iterator = _createForOfIteratorHelper(data),
|
|
171
|
+
_step;
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
175
|
+
var o = _step.value;
|
|
176
|
+
|
|
177
|
+
var _node = this.createNode(o);
|
|
178
|
+
|
|
179
|
+
this.addChild(_node);
|
|
180
|
+
|
|
181
|
+
if (isNodeRecordWithChildren(o)) {
|
|
182
|
+
if (o.children.length === 0) {
|
|
183
|
+
_node.isEmptyFolder = true;
|
|
184
|
+
} else {
|
|
185
|
+
_node.loadFromData(o.children);
|
|
120
186
|
}
|
|
187
|
+
}
|
|
121
188
|
}
|
|
122
|
-
|
|
123
|
-
|
|
189
|
+
} catch (err) {
|
|
190
|
+
_iterator.e(err);
|
|
191
|
+
} finally {
|
|
192
|
+
_iterator.f();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
124
197
|
/*
|
|
125
198
|
Add child.
|
|
126
|
-
|
|
127
|
-
tree.addChild(
|
|
199
|
+
tree.addChild(
|
|
128
200
|
new Node('child1')
|
|
129
201
|
);
|
|
130
202
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
203
|
+
|
|
204
|
+
}, {
|
|
205
|
+
key: "addChild",
|
|
206
|
+
value: function addChild(node) {
|
|
207
|
+
this.children.push(node);
|
|
208
|
+
node.setParent(this);
|
|
209
|
+
}
|
|
135
210
|
/*
|
|
136
211
|
Add child at position. Index starts at 0.
|
|
137
|
-
|
|
138
|
-
tree.addChildAtPosition(
|
|
212
|
+
tree.addChildAtPosition(
|
|
139
213
|
new Node('abc'),
|
|
140
214
|
1
|
|
141
215
|
);
|
|
142
216
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
217
|
+
|
|
218
|
+
}, {
|
|
219
|
+
key: "addChildAtPosition",
|
|
220
|
+
value: function addChildAtPosition(node, index) {
|
|
221
|
+
this.children.splice(index, 0, node);
|
|
222
|
+
node.setParent(this);
|
|
223
|
+
}
|
|
147
224
|
/*
|
|
148
225
|
Remove child. This also removes the children of the node.
|
|
149
|
-
|
|
150
|
-
tree.removeChild(tree.children[0]);
|
|
226
|
+
tree.removeChild(tree.children[0]);
|
|
151
227
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
228
|
+
|
|
229
|
+
}, {
|
|
230
|
+
key: "removeChild",
|
|
231
|
+
value: function removeChild(node) {
|
|
232
|
+
// remove children from the index
|
|
233
|
+
node.removeChildren();
|
|
234
|
+
this.doRemoveChild(node);
|
|
235
|
+
}
|
|
157
236
|
/*
|
|
158
237
|
Get child index.
|
|
159
|
-
|
|
160
|
-
var index = getChildIndex(node);
|
|
238
|
+
var index = getChildIndex(node);
|
|
161
239
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
240
|
+
|
|
241
|
+
}, {
|
|
242
|
+
key: "getChildIndex",
|
|
243
|
+
value: function getChildIndex(node) {
|
|
244
|
+
return this.children.indexOf(node);
|
|
245
|
+
}
|
|
165
246
|
/*
|
|
166
247
|
Does the tree have children?
|
|
167
|
-
|
|
168
|
-
if (tree.hasChildren()) {
|
|
248
|
+
if (tree.hasChildren()) {
|
|
169
249
|
//
|
|
170
250
|
}
|
|
171
251
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
252
|
+
|
|
253
|
+
}, {
|
|
254
|
+
key: "hasChildren",
|
|
255
|
+
value: function hasChildren() {
|
|
256
|
+
return this.children.length !== 0;
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "isFolder",
|
|
260
|
+
value: function isFolder() {
|
|
261
|
+
return this.hasChildren() || this.load_on_demand;
|
|
262
|
+
}
|
|
178
263
|
/*
|
|
179
264
|
Iterate over all the nodes in the tree.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
The callback must return true to continue the iteration on current node.
|
|
184
|
-
|
|
185
|
-
tree.iterate(
|
|
265
|
+
Calls callback with (node, level).
|
|
266
|
+
The callback must return true to continue the iteration on current node.
|
|
267
|
+
tree.iterate(
|
|
186
268
|
function(node, level) {
|
|
187
269
|
console.log(node.name);
|
|
188
|
-
|
|
189
|
-
// stop iteration after level 2
|
|
270
|
+
// stop iteration after level 2
|
|
190
271
|
return (level <= 2);
|
|
191
272
|
}
|
|
192
273
|
);
|
|
274
|
+
*/
|
|
193
275
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (result && child.hasChildren()) {
|
|
202
|
-
_iterate(child, level + 1);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
_iterate(this, 0);
|
|
208
|
-
};
|
|
209
|
-
/*
|
|
210
|
-
Move node relative to another node.
|
|
276
|
+
}, {
|
|
277
|
+
key: "iterate",
|
|
278
|
+
value: function iterate(callback) {
|
|
279
|
+
var _iterate = function _iterate(node, level) {
|
|
280
|
+
if (node.children) {
|
|
281
|
+
var _iterator2 = _createForOfIteratorHelper(node.children),
|
|
282
|
+
_step2;
|
|
211
283
|
|
|
212
|
-
|
|
284
|
+
try {
|
|
285
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
286
|
+
var child = _step2.value;
|
|
287
|
+
var result = callback(child, level);
|
|
213
288
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Node.prototype.moveNode = function (movedNode, targetNode, position) {
|
|
218
|
-
if (!movedNode.parent || movedNode.isParentOf(targetNode)) {
|
|
219
|
-
// - Node is parent of target node
|
|
220
|
-
// - Or, parent is empty
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
movedNode.parent.doRemoveChild(movedNode);
|
|
225
|
-
switch (position) {
|
|
226
|
-
case Position.After: {
|
|
227
|
-
if (targetNode.parent) {
|
|
228
|
-
targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode) + 1);
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
case Position.Before: {
|
|
234
|
-
if (targetNode.parent) {
|
|
235
|
-
targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode));
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
case Position.Inside: {
|
|
241
|
-
// move inside as first child
|
|
242
|
-
targetNode.addChildAtPosition(movedNode, 0);
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
default:
|
|
246
|
-
return false;
|
|
289
|
+
if (result && child.hasChildren()) {
|
|
290
|
+
_iterate(child, level + 1);
|
|
291
|
+
}
|
|
247
292
|
}
|
|
293
|
+
} catch (err) {
|
|
294
|
+
_iterator2.e(err);
|
|
295
|
+
} finally {
|
|
296
|
+
_iterator2.f();
|
|
297
|
+
}
|
|
248
298
|
}
|
|
249
|
-
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
_iterate(this, 0);
|
|
302
|
+
}
|
|
250
303
|
/*
|
|
251
|
-
|
|
304
|
+
Move node relative to another node.
|
|
305
|
+
Argument position: Position.BEFORE, Position.AFTER or Position.Inside
|
|
306
|
+
// move node1 after node2
|
|
307
|
+
tree.moveNode(node1, node2, Position.AFTER);
|
|
252
308
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
Object.prototype.hasOwnProperty.call(node, k)) {
|
|
270
|
-
var v = node[k];
|
|
271
|
-
tmpNode[k] = v;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (node.hasChildren()) {
|
|
275
|
-
tmpNode["children"] = getDataFromNodes(node.children);
|
|
276
|
-
}
|
|
277
|
-
return tmpNode;
|
|
278
|
-
});
|
|
279
|
-
};
|
|
280
|
-
if (includeParent) {
|
|
281
|
-
return getDataFromNodes([this]);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
return getDataFromNodes(this.children);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
Node.prototype.getNodeByName = function (name) {
|
|
288
|
-
return this.getNodeByCallback(function (node) { return node.name === name; });
|
|
289
|
-
};
|
|
290
|
-
Node.prototype.getNodeByNameMustExist = function (name) {
|
|
291
|
-
var node = this.getNodeByCallback(function (n) { return n.name === name; });
|
|
292
|
-
if (!node) {
|
|
293
|
-
throw "Node with name " + name + " not found";
|
|
294
|
-
}
|
|
295
|
-
return node;
|
|
296
|
-
};
|
|
297
|
-
Node.prototype.getNodeByCallback = function (callback) {
|
|
298
|
-
var result = null;
|
|
299
|
-
this.iterate(function (node) {
|
|
300
|
-
if (result) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
else if (callback(node)) {
|
|
304
|
-
result = node;
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
309
|
+
|
|
310
|
+
}, {
|
|
311
|
+
key: "moveNode",
|
|
312
|
+
value: function moveNode(movedNode, targetNode, position) {
|
|
313
|
+
if (!movedNode.parent || movedNode.isParentOf(targetNode)) {
|
|
314
|
+
// - Node is parent of target node
|
|
315
|
+
// - Or, parent is empty
|
|
316
|
+
return false;
|
|
317
|
+
} else {
|
|
318
|
+
movedNode.parent.doRemoveChild(movedNode);
|
|
319
|
+
|
|
320
|
+
switch (position) {
|
|
321
|
+
case Position.After:
|
|
322
|
+
{
|
|
323
|
+
if (targetNode.parent) {
|
|
324
|
+
targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode) + 1);
|
|
308
325
|
return true;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return false;
|
|
309
329
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
var childIndex = this.parent.getChildIndex(this);
|
|
320
|
-
this.parent.addChildAtPosition(node, childIndex + 1);
|
|
321
|
-
if (typeof nodeInfo === "object" &&
|
|
322
|
-
nodeInfo["children"] &&
|
|
323
|
-
nodeInfo["children"] instanceof Array &&
|
|
324
|
-
nodeInfo["children"].length) {
|
|
325
|
-
node.loadFromData(nodeInfo["children"]);
|
|
326
|
-
}
|
|
327
|
-
return node;
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
Node.prototype.addBefore = function (nodeInfo) {
|
|
331
|
-
if (!this.parent) {
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
var node = this.createNode(nodeInfo);
|
|
336
|
-
var childIndex = this.parent.getChildIndex(this);
|
|
337
|
-
this.parent.addChildAtPosition(node, childIndex);
|
|
338
|
-
if (typeof nodeInfo === "object" &&
|
|
339
|
-
nodeInfo["children"] &&
|
|
340
|
-
nodeInfo["children"] instanceof Array &&
|
|
341
|
-
nodeInfo["children"].length) {
|
|
342
|
-
node.loadFromData(nodeInfo["children"]);
|
|
343
|
-
}
|
|
344
|
-
return node;
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
Node.prototype.addParent = function (nodeInfo) {
|
|
348
|
-
if (!this.parent) {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
var newParent = this.createNode(nodeInfo);
|
|
353
|
-
if (this.tree) {
|
|
354
|
-
newParent.setParent(this.tree);
|
|
330
|
+
|
|
331
|
+
case Position.Before:
|
|
332
|
+
{
|
|
333
|
+
if (targetNode.parent) {
|
|
334
|
+
targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode));
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return false;
|
|
355
339
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
340
|
+
|
|
341
|
+
case Position.Inside:
|
|
342
|
+
{
|
|
343
|
+
// move inside as first child
|
|
344
|
+
targetNode.addChildAtPosition(movedNode, 0);
|
|
345
|
+
return true;
|
|
360
346
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
Node.prototype.remove = function () {
|
|
367
|
-
if (this.parent) {
|
|
368
|
-
this.parent.removeChild(this);
|
|
369
|
-
this.parent = null;
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
Node.prototype.append = function (nodeInfo) {
|
|
373
|
-
var node = this.createNode(nodeInfo);
|
|
374
|
-
this.addChild(node);
|
|
375
|
-
if (typeof nodeInfo === "object" &&
|
|
376
|
-
nodeInfo["children"] &&
|
|
377
|
-
nodeInfo["children"] instanceof Array &&
|
|
378
|
-
nodeInfo["children"].length) {
|
|
379
|
-
node.loadFromData(nodeInfo["children"]);
|
|
380
|
-
}
|
|
381
|
-
return node;
|
|
382
|
-
};
|
|
383
|
-
Node.prototype.prepend = function (nodeInfo) {
|
|
384
|
-
var node = this.createNode(nodeInfo);
|
|
385
|
-
this.addChildAtPosition(node, 0);
|
|
386
|
-
if (typeof nodeInfo === "object" &&
|
|
387
|
-
nodeInfo["children"] &&
|
|
388
|
-
nodeInfo["children"] instanceof Array &&
|
|
389
|
-
nodeInfo["children"].length) {
|
|
390
|
-
node.loadFromData(nodeInfo["children"]);
|
|
347
|
+
|
|
348
|
+
default:
|
|
349
|
+
return false;
|
|
391
350
|
}
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/*
|
|
354
|
+
Get the tree as data.
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
}, {
|
|
358
|
+
key: "getData",
|
|
359
|
+
value: function getData() {
|
|
360
|
+
var includeParent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
361
|
+
|
|
362
|
+
var getDataFromNodes = function getDataFromNodes(nodes) {
|
|
363
|
+
return nodes.map(function (node) {
|
|
364
|
+
var tmpNode = {};
|
|
365
|
+
|
|
366
|
+
for (var k in node) {
|
|
367
|
+
if (["parent", "children", "element", "idMapping", "load_on_demand", "nodeClass", "tree", "isEmptyFolder"].indexOf(k) === -1 && Object.prototype.hasOwnProperty.call(node, k)) {
|
|
368
|
+
var v = node[k];
|
|
369
|
+
tmpNode[k] = v;
|
|
399
370
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
while (node.parent) {
|
|
408
|
-
level += 1;
|
|
409
|
-
node = node.parent;
|
|
410
|
-
}
|
|
411
|
-
return level;
|
|
412
|
-
};
|
|
413
|
-
Node.prototype.getNodeById = function (nodeId) {
|
|
414
|
-
return this.idMapping[nodeId] || null;
|
|
415
|
-
};
|
|
416
|
-
Node.prototype.addNodeToIndex = function (node) {
|
|
417
|
-
if (node.id != null) {
|
|
418
|
-
this.idMapping[node.id] = node;
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
Node.prototype.removeNodeFromIndex = function (node) {
|
|
422
|
-
if (node.id != null) {
|
|
423
|
-
delete this.idMapping[node.id];
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
Node.prototype.removeChildren = function () {
|
|
427
|
-
var _this = this;
|
|
428
|
-
this.iterate(function (child) {
|
|
429
|
-
var _a;
|
|
430
|
-
(_a = _this.tree) === null || _a === void 0 ? void 0 : _a.removeNodeFromIndex(child);
|
|
431
|
-
return true;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (node.hasChildren()) {
|
|
374
|
+
tmpNode["children"] = getDataFromNodes(node.children);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return tmpNode;
|
|
432
378
|
});
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
if (includeParent) {
|
|
382
|
+
return getDataFromNodes([this]);
|
|
383
|
+
} else {
|
|
384
|
+
return getDataFromNodes(this.children);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}, {
|
|
388
|
+
key: "getNodeByName",
|
|
389
|
+
value: function getNodeByName(name) {
|
|
390
|
+
return this.getNodeByCallback(function (node) {
|
|
391
|
+
return node.name === name;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}, {
|
|
395
|
+
key: "getNodeByNameMustExist",
|
|
396
|
+
value: function getNodeByNameMustExist(name) {
|
|
397
|
+
var node = this.getNodeByCallback(function (n) {
|
|
398
|
+
return n.name === name;
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
if (!node) {
|
|
402
|
+
throw "Node with name ".concat(name, " not found");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return node;
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "getNodeByCallback",
|
|
409
|
+
value: function getNodeByCallback(callback) {
|
|
410
|
+
var result = null;
|
|
411
|
+
this.iterate(function (node) {
|
|
412
|
+
if (result) {
|
|
413
|
+
return false;
|
|
414
|
+
} else if (callback(node)) {
|
|
415
|
+
result = node;
|
|
416
|
+
return false;
|
|
417
|
+
} else {
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
423
|
+
}, {
|
|
424
|
+
key: "addAfter",
|
|
425
|
+
value: function addAfter(nodeInfo) {
|
|
426
|
+
if (!this.parent) {
|
|
427
|
+
return null;
|
|
428
|
+
} else {
|
|
429
|
+
var _node2 = this.createNode(nodeInfo);
|
|
430
|
+
|
|
431
|
+
var childIndex = this.parent.getChildIndex(this);
|
|
432
|
+
this.parent.addChildAtPosition(_node2, childIndex + 1);
|
|
433
|
+
|
|
434
|
+
if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
|
|
435
|
+
_node2.loadFromData(nodeInfo.children);
|
|
438
436
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
437
|
+
|
|
438
|
+
return _node2;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}, {
|
|
442
|
+
key: "addBefore",
|
|
443
|
+
value: function addBefore(nodeInfo) {
|
|
444
|
+
if (!this.parent) {
|
|
445
|
+
return null;
|
|
446
|
+
} else {
|
|
447
|
+
var _node3 = this.createNode(nodeInfo);
|
|
448
|
+
|
|
449
|
+
var childIndex = this.parent.getChildIndex(this);
|
|
450
|
+
this.parent.addChildAtPosition(_node3, childIndex);
|
|
451
|
+
|
|
452
|
+
if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
|
|
453
|
+
_node3.loadFromData(nodeInfo.children);
|
|
447
454
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
455
|
+
|
|
456
|
+
return _node3;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}, {
|
|
460
|
+
key: "addParent",
|
|
461
|
+
value: function addParent(nodeInfo) {
|
|
462
|
+
if (!this.parent) {
|
|
463
|
+
return null;
|
|
464
|
+
} else {
|
|
465
|
+
var newParent = this.createNode(nodeInfo);
|
|
466
|
+
|
|
467
|
+
if (this.tree) {
|
|
468
|
+
newParent.setParent(this.tree);
|
|
452
469
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
470
|
+
|
|
471
|
+
var originalParent = this.parent;
|
|
472
|
+
|
|
473
|
+
var _iterator3 = _createForOfIteratorHelper(originalParent.children),
|
|
474
|
+
_step3;
|
|
475
|
+
|
|
476
|
+
try {
|
|
477
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
478
|
+
var child = _step3.value;
|
|
479
|
+
newParent.addChild(child);
|
|
480
|
+
}
|
|
481
|
+
} catch (err) {
|
|
482
|
+
_iterator3.e(err);
|
|
483
|
+
} finally {
|
|
484
|
+
_iterator3.f();
|
|
461
485
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
486
|
+
|
|
487
|
+
originalParent.children = [];
|
|
488
|
+
originalParent.addChild(newParent);
|
|
489
|
+
return newParent;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}, {
|
|
493
|
+
key: "remove",
|
|
494
|
+
value: function remove() {
|
|
495
|
+
if (this.parent) {
|
|
496
|
+
this.parent.removeChild(this);
|
|
497
|
+
this.parent = null;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}, {
|
|
501
|
+
key: "append",
|
|
502
|
+
value: function append(nodeInfo) {
|
|
503
|
+
var node = this.createNode(nodeInfo);
|
|
504
|
+
this.addChild(node);
|
|
505
|
+
|
|
506
|
+
if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
|
|
507
|
+
node.loadFromData(nodeInfo.children);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return node;
|
|
511
|
+
}
|
|
512
|
+
}, {
|
|
513
|
+
key: "prepend",
|
|
514
|
+
value: function prepend(nodeInfo) {
|
|
515
|
+
var node = this.createNode(nodeInfo);
|
|
516
|
+
this.addChildAtPosition(node, 0);
|
|
517
|
+
|
|
518
|
+
if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
|
|
519
|
+
node.loadFromData(nodeInfo.children);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return node;
|
|
523
|
+
}
|
|
524
|
+
}, {
|
|
525
|
+
key: "isParentOf",
|
|
526
|
+
value: function isParentOf(node) {
|
|
527
|
+
var parent = node.parent;
|
|
528
|
+
|
|
529
|
+
while (parent) {
|
|
530
|
+
if (parent === this) {
|
|
531
|
+
return true;
|
|
481
532
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
533
|
+
|
|
534
|
+
parent = parent.parent;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}, {
|
|
540
|
+
key: "getLevel",
|
|
541
|
+
value: function getLevel() {
|
|
542
|
+
var level = 0;
|
|
543
|
+
var node = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
544
|
+
|
|
545
|
+
while (node.parent) {
|
|
546
|
+
level += 1;
|
|
547
|
+
node = node.parent;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return level;
|
|
551
|
+
}
|
|
552
|
+
}, {
|
|
553
|
+
key: "getNodeById",
|
|
554
|
+
value: function getNodeById(nodeId) {
|
|
555
|
+
return this.idMapping.get(nodeId) || null;
|
|
556
|
+
}
|
|
557
|
+
}, {
|
|
558
|
+
key: "addNodeToIndex",
|
|
559
|
+
value: function addNodeToIndex(node) {
|
|
560
|
+
if (node.id != null) {
|
|
561
|
+
this.idMapping.set(node.id, node);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}, {
|
|
565
|
+
key: "removeNodeFromIndex",
|
|
566
|
+
value: function removeNodeFromIndex(node) {
|
|
567
|
+
if (node.id != null) {
|
|
568
|
+
this.idMapping["delete"](node.id);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}, {
|
|
572
|
+
key: "removeChildren",
|
|
573
|
+
value: function removeChildren() {
|
|
574
|
+
var _this = this;
|
|
575
|
+
|
|
576
|
+
this.iterate(function (child) {
|
|
577
|
+
var _this$tree;
|
|
578
|
+
|
|
579
|
+
(_this$tree = _this.tree) === null || _this$tree === void 0 ? void 0 : _this$tree.removeNodeFromIndex(child);
|
|
580
|
+
return true;
|
|
581
|
+
});
|
|
582
|
+
this.children = [];
|
|
583
|
+
}
|
|
584
|
+
}, {
|
|
585
|
+
key: "getPreviousSibling",
|
|
586
|
+
value: function getPreviousSibling() {
|
|
587
|
+
if (!this.parent) {
|
|
588
|
+
return null;
|
|
589
|
+
} else {
|
|
590
|
+
var previousIndex = this.parent.getChildIndex(this) - 1;
|
|
591
|
+
|
|
592
|
+
if (previousIndex >= 0) {
|
|
593
|
+
return this.parent.children[previousIndex];
|
|
594
|
+
} else {
|
|
595
|
+
return null;
|
|
497
596
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}, {
|
|
600
|
+
key: "getNextSibling",
|
|
601
|
+
value: function getNextSibling() {
|
|
602
|
+
if (!this.parent) {
|
|
603
|
+
return null;
|
|
604
|
+
} else {
|
|
605
|
+
var nextIndex = this.parent.getChildIndex(this) + 1;
|
|
606
|
+
|
|
607
|
+
if (nextIndex < this.parent.children.length) {
|
|
608
|
+
return this.parent.children[nextIndex];
|
|
609
|
+
} else {
|
|
610
|
+
return null;
|
|
502
611
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}, {
|
|
615
|
+
key: "getNodesByProperty",
|
|
616
|
+
value: function getNodesByProperty(key, value) {
|
|
617
|
+
return this.filter(function (node) {
|
|
618
|
+
return node[key] === value;
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}, {
|
|
622
|
+
key: "filter",
|
|
623
|
+
value: function filter(f) {
|
|
624
|
+
var result = [];
|
|
625
|
+
this.iterate(function (node) {
|
|
626
|
+
if (f(node)) {
|
|
627
|
+
result.push(node);
|
|
519
628
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
629
|
+
|
|
630
|
+
return true;
|
|
631
|
+
});
|
|
632
|
+
return result;
|
|
633
|
+
}
|
|
634
|
+
}, {
|
|
635
|
+
key: "getNextNode",
|
|
636
|
+
value: function getNextNode() {
|
|
637
|
+
var includeChildren = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
638
|
+
|
|
639
|
+
if (includeChildren && this.hasChildren() && this.is_open) {
|
|
640
|
+
// First child
|
|
641
|
+
return this.children[0];
|
|
642
|
+
} else {
|
|
523
643
|
if (!this.parent) {
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
644
|
+
return null;
|
|
645
|
+
} else {
|
|
646
|
+
var nextSibling = this.getNextSibling();
|
|
647
|
+
|
|
648
|
+
if (nextSibling) {
|
|
649
|
+
// Next sibling
|
|
650
|
+
return nextSibling;
|
|
651
|
+
} else {
|
|
652
|
+
// Next node of parent
|
|
653
|
+
return this.parent.getNextNode(false);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}, {
|
|
659
|
+
key: "getPreviousNode",
|
|
660
|
+
value: function getPreviousNode() {
|
|
661
|
+
if (!this.parent) {
|
|
662
|
+
return null;
|
|
663
|
+
} else {
|
|
664
|
+
var previousSibling = this.getPreviousSibling();
|
|
665
|
+
|
|
666
|
+
if (previousSibling) {
|
|
667
|
+
if (!previousSibling.hasChildren() || !previousSibling.is_open) {
|
|
668
|
+
// Previous sibling
|
|
669
|
+
return previousSibling;
|
|
670
|
+
} else {
|
|
671
|
+
// Last child of previous sibling
|
|
672
|
+
return previousSibling.getLastChild();
|
|
673
|
+
}
|
|
674
|
+
} else {
|
|
675
|
+
return this.getParent();
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}, {
|
|
680
|
+
key: "getParent",
|
|
681
|
+
value: function getParent() {
|
|
682
|
+
// Return parent except if it is the root node
|
|
683
|
+
if (!this.parent) {
|
|
684
|
+
return null;
|
|
685
|
+
} else if (!this.parent.parent) {
|
|
686
|
+
// Root node -> null
|
|
687
|
+
return null;
|
|
688
|
+
} else {
|
|
689
|
+
return this.parent;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}, {
|
|
693
|
+
key: "getLastChild",
|
|
694
|
+
value: function getLastChild() {
|
|
695
|
+
if (!this.hasChildren()) {
|
|
696
|
+
return null;
|
|
697
|
+
} else {
|
|
698
|
+
var lastChild = this.children[this.children.length - 1];
|
|
699
|
+
|
|
700
|
+
if (!(lastChild.hasChildren() && lastChild.is_open)) {
|
|
701
|
+
return lastChild;
|
|
702
|
+
} else {
|
|
703
|
+
return lastChild.getLastChild();
|
|
537
704
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
705
|
+
}
|
|
706
|
+
} // Init Node from data without making it the root of the tree
|
|
707
|
+
|
|
708
|
+
}, {
|
|
709
|
+
key: "initFromData",
|
|
710
|
+
value: function initFromData(data) {
|
|
711
|
+
var _this2 = this;
|
|
712
|
+
|
|
713
|
+
var addNode = function addNode(nodeData) {
|
|
714
|
+
_this2.setData(nodeData);
|
|
715
|
+
|
|
716
|
+
if (isNodeRecordWithChildren(nodeData) && nodeData.children.length) {
|
|
717
|
+
addChildren(nodeData.children);
|
|
546
718
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
var
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
var addChildren = function addChildren(childrenData) {
|
|
722
|
+
var _iterator4 = _createForOfIteratorHelper(childrenData),
|
|
723
|
+
_step4;
|
|
724
|
+
|
|
725
|
+
try {
|
|
726
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
727
|
+
var child = _step4.value;
|
|
728
|
+
|
|
729
|
+
var _node4 = _this2.createNode();
|
|
730
|
+
|
|
731
|
+
_node4.initFromData(child);
|
|
732
|
+
|
|
733
|
+
_this2.addChild(_node4);
|
|
734
|
+
}
|
|
735
|
+
} catch (err) {
|
|
736
|
+
_iterator4.e(err);
|
|
737
|
+
} finally {
|
|
738
|
+
_iterator4.f();
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
addNode(data);
|
|
743
|
+
}
|
|
744
|
+
}, {
|
|
745
|
+
key: "setParent",
|
|
746
|
+
value: function setParent(parent) {
|
|
747
|
+
var _this$tree2;
|
|
748
|
+
|
|
749
|
+
this.parent = parent;
|
|
750
|
+
this.tree = parent.tree;
|
|
751
|
+
(_this$tree2 = this.tree) === null || _this$tree2 === void 0 ? void 0 : _this$tree2.addNodeToIndex(this);
|
|
752
|
+
}
|
|
753
|
+
}, {
|
|
754
|
+
key: "doRemoveChild",
|
|
755
|
+
value: function doRemoveChild(node) {
|
|
756
|
+
var _this$tree3;
|
|
757
|
+
|
|
758
|
+
this.children.splice(this.getChildIndex(node), 1);
|
|
759
|
+
(_this$tree3 = this.tree) === null || _this$tree3 === void 0 ? void 0 : _this$tree3.removeNodeFromIndex(node);
|
|
760
|
+
}
|
|
761
|
+
}, {
|
|
762
|
+
key: "getNodeClass",
|
|
763
|
+
value: function getNodeClass() {
|
|
764
|
+
var _this$tree4;
|
|
765
|
+
|
|
766
|
+
return this.nodeClass || (this === null || this === void 0 ? void 0 : (_this$tree4 = this.tree) === null || _this$tree4 === void 0 ? void 0 : _this$tree4.nodeClass) || Node;
|
|
767
|
+
}
|
|
768
|
+
}, {
|
|
769
|
+
key: "createNode",
|
|
770
|
+
value: function createNode(nodeData) {
|
|
771
|
+
var nodeClass = this.getNodeClass();
|
|
772
|
+
return new nodeClass(nodeData);
|
|
773
|
+
}
|
|
774
|
+
}]);
|
|
775
|
+
|
|
776
|
+
return Node;
|
|
777
|
+
}();
|
|
778
|
+
|
|
779
|
+
exports.Node = Node;
|