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.
Files changed (174) hide show
  1. package/.eslintrc +1 -0
  2. package/.github/workflows/ci.yml +54 -0
  3. package/.github/workflows/codeql-analysis.yml +28 -0
  4. package/README.md +1 -1
  5. package/_config.yml +1 -1
  6. package/_entries/10_changelog.md +20 -0
  7. package/_entries/{36_showemptynode.md → 36_showemptyfolder.md} +5 -5
  8. package/_entries/38_start_dnd_delay.md +13 -0
  9. package/_entries/{38_tabindex.md → 39_tabindex.md} +0 -0
  10. package/_entries/{39_usecontextmenu.md → 40_usecontextmenu.md} +0 -0
  11. package/_entries/{40_functions.md → 41_functions.md} +0 -0
  12. package/_entries/{41_addparentnode.md → 42_addparentnode.md} +0 -0
  13. package/_entries/{42_addnodeafter.md → 43_addnodeafter.md} +0 -0
  14. package/_entries/{43_addnodebefore.md → 44_addnodebefore.md} +0 -0
  15. package/_entries/{44_appendnode.md → 45_appendnode.md} +0 -0
  16. package/_entries/{45_closenode.md → 46_closenode.md} +0 -0
  17. package/_entries/{46_destroy.md → 47_destroy.md} +0 -0
  18. package/_entries/{47_getnodebycallback.md → 48_getnodebycallback.md} +0 -0
  19. package/_entries/{48_getnodebyid.md → 49_getnodebyid.md} +0 -0
  20. package/_entries/{49_getnodebyhtmlelement.md → 50_getnodebyhtmlelement.md} +0 -0
  21. package/_entries/{50_getselectednode.md → 51_getselectednode.md} +0 -0
  22. package/_entries/{51_getstate.md → 52_getstate.md} +0 -0
  23. package/_entries/{52_gettree.md → 53_gettree.md} +0 -0
  24. package/_entries/{53_isdragging.md → 54_isdragging.md} +0 -0
  25. package/_entries/{54_loaddata.md → 55_loaddata.md} +0 -0
  26. package/_entries/{55_loaddatafromurl.md → 56_loaddatafromurl.md} +0 -0
  27. package/_entries/{56_movedown.md → 57_movedown.md} +0 -0
  28. package/_entries/{57_movenode.md → 58_movenode.md} +0 -0
  29. package/_entries/{58_moveup.md → 59_moveup.md} +0 -0
  30. package/_entries/{59_opennode.md → 60_opennode.md} +0 -0
  31. package/_entries/{60_prependnode.md → 61_prependnode.md} +0 -0
  32. package/_entries/62_refresh.md +12 -0
  33. package/_entries/{61_reload.md → 63_reload.md} +0 -0
  34. package/_entries/{62_removenode.md → 64_removenode.md} +0 -0
  35. package/_entries/{63_selectnode.md → 65_selectnode.md} +0 -0
  36. package/_entries/{64_scrolltonode.md → 66_scrolltonode.md} +0 -0
  37. package/_entries/{65_setoption.md → 67_setoption.md} +0 -0
  38. package/_entries/{66_setstate.md → 68_setstate.md} +0 -0
  39. package/_entries/{67_toggle.md → 69_toggle.md} +0 -0
  40. package/_entries/{68_tojson.md → 70_tojson.md} +0 -0
  41. package/_entries/{69_updatenode.md → 71_updatenode.md} +0 -0
  42. package/_entries/{70_events.md → 72_events.md} +0 -0
  43. package/_entries/{71_tree-click.md → 73_tree-click.md} +0 -0
  44. package/_entries/{72_tree-close.md → 74_tree-close.md} +0 -0
  45. package/_entries/{73_tree-contextmenu.md → 75_tree-contextmenu.md} +0 -0
  46. package/_entries/{74_tree-dblclick.md → 76_tree-dblclick.md} +0 -0
  47. package/_entries/{75_tree-init.md → 77_tree-init.md} +0 -0
  48. package/_entries/{76_tree-load-data.md → 78_tree-load-data.md} +0 -0
  49. package/_entries/{77_tree-loading-data.md → 79_tree-loading-data.md} +0 -0
  50. package/_entries/{78_tree-move.md → 80_tree-move.md} +0 -0
  51. package/_entries/{79_tree-refresh.md → 81_tree-refresh.md} +0 -0
  52. package/_entries/{80_tree-open.md → 82_tree-open.md} +0 -0
  53. package/_entries/{81_tree-select.md → 83_tree-select.md} +0 -0
  54. package/_entries/{82_multiple-selection.md → 84_multiple-selection.md} +0 -0
  55. package/_entries/{83_add-to-selection.md → 85_add-to-selection.md} +0 -0
  56. package/_entries/{84_get-selected-nodes.md → 86_get-selected-nodes.md} +0 -0
  57. package/_entries/{85_is-node-selected.md → 87_is-node-selected.md} +0 -0
  58. package/_entries/{86_remove-from-selection.md → 88_remove-from-selection.md} +0 -0
  59. package/_entries/{87_node-functions.md → 89_node-functions.md} +0 -0
  60. package/_entries/{88_children.md → 90_children.md} +0 -0
  61. package/_entries/{89_getdata.md → 91_getdata.md} +0 -0
  62. package/_entries/{90_getlevel.md → 92_getlevel.md} +0 -0
  63. package/_entries/{91_getnextnode.md → 93_getnextnode.md} +0 -0
  64. package/_entries/{92_getnextsibling.md → 94_getnextsibling.md} +0 -0
  65. package/_entries/{93_getpreviousnode.md → 95_getpreviousnode.md} +0 -0
  66. package/_entries/{94_getprevioussibling.md → 96_getprevioussibling.md} +0 -0
  67. package/_entries/{95_parent.md → 97_parent.md} +0 -0
  68. package/_examples/13_drag_outside.html +2 -1
  69. package/_examples/14_filter.html +113 -0
  70. package/_layouts/base.html +1 -23
  71. package/babel.config.json +11 -0
  72. package/babel.coverage.config.json +4 -0
  73. package/bower.json +1 -1
  74. package/jest-browser.config.js +0 -3
  75. package/jest-jsdom.config.js +1 -2
  76. package/jqtree.css +4 -1
  77. package/jqtree.postcss +3 -0
  78. package/lib/dataLoader.js +146 -98
  79. package/lib/dragAndDropHandler.js +668 -470
  80. package/lib/elementsRenderer.js +282 -197
  81. package/lib/jqtreeOptions.js +1 -2
  82. package/lib/keyHandler.js +134 -87
  83. package/lib/mouse.widget.js +288 -165
  84. package/lib/node.js +693 -505
  85. package/lib/nodeElement.js +329 -205
  86. package/lib/playwright/playwright.test.js +216 -189
  87. package/lib/playwright/testUtil.js +437 -192
  88. package/lib/playwright/visualRegression.js +183 -117
  89. package/lib/saveStateHandler.js +311 -204
  90. package/lib/scrollHandler.js +293 -199
  91. package/lib/selectNodeHandler.js +140 -105
  92. package/lib/simple.widget.js +184 -109
  93. package/lib/test/global.d.js +3 -0
  94. package/lib/test/jqTree/create.test.js +44 -40
  95. package/lib/test/jqTree/events.test.js +185 -138
  96. package/lib/test/jqTree/keyboard.test.js +216 -199
  97. package/lib/test/jqTree/loadOnDemand.test.js +233 -157
  98. package/lib/test/jqTree/methods.test.js +1269 -1000
  99. package/lib/test/jqTree/options.test.js +467 -398
  100. package/lib/test/node.test.js +1036 -873
  101. package/lib/test/nodeUtil.test.js +21 -20
  102. package/lib/test/support/exampleData.js +35 -23
  103. package/lib/test/support/jqTreeMatchers.js +72 -54
  104. package/lib/test/support/matchers.d.js +1 -0
  105. package/lib/test/support/setupTests.js +9 -3
  106. package/lib/test/support/testUtil.js +38 -15
  107. package/lib/test/support/treeStructure.js +41 -32
  108. package/lib/test/util.test.js +21 -20
  109. package/lib/tree.jquery.d.js +1 -0
  110. package/lib/tree.jquery.js +1264 -883
  111. package/lib/types.js +1 -2
  112. package/lib/typings.d.js +2 -0
  113. package/lib/util.js +21 -7
  114. package/lib/version.js +8 -3
  115. package/package.json +43 -36
  116. package/production +4 -4
  117. package/rollup.config.js +16 -11
  118. package/src/dataLoader.ts +6 -6
  119. package/src/dragAndDropHandler.ts +0 -4
  120. package/src/elementsRenderer.ts +4 -0
  121. package/src/jqtreeOptions.ts +33 -32
  122. package/src/mouse.widget.ts +58 -29
  123. package/src/node.ts +32 -46
  124. package/src/nodeElement.ts +17 -9
  125. package/src/playwright/.eslintrc +5 -0
  126. package/src/playwright/playwright.test.ts +30 -30
  127. package/src/playwright/testUtil.ts +36 -37
  128. package/src/saveStateHandler.ts +11 -6
  129. package/src/selectNodeHandler.ts +14 -21
  130. package/src/simple.widget.ts +1 -1
  131. package/src/test/.eslintrc +4 -0
  132. package/src/test/jqTree/create.test.ts +0 -1
  133. package/src/test/jqTree/events.test.ts +12 -13
  134. package/src/test/jqTree/keyboard.test.ts +0 -1
  135. package/src/test/jqTree/loadOnDemand.test.ts +46 -1
  136. package/src/test/jqTree/methods.test.ts +67 -18
  137. package/src/test/jqTree/options.test.ts +5 -6
  138. package/src/test/node.test.ts +2 -2
  139. package/src/test/support/jqTreeMatchers.ts +8 -9
  140. package/src/test/support/matchers.d.ts +2 -4
  141. package/src/test/support/setupTests.ts +2 -1
  142. package/src/tree.jquery.d.ts +19 -13
  143. package/src/tree.jquery.ts +63 -57
  144. package/src/version.ts +1 -1
  145. package/static/bower.json +3 -3
  146. package/static/bower_components/fontawesome/css/all.min.css +2 -2
  147. package/static/bower_components/fontawesome/webfonts/fa-brands-400.eot +0 -0
  148. package/static/bower_components/fontawesome/webfonts/fa-brands-400.svg +774 -627
  149. package/static/bower_components/fontawesome/webfonts/fa-brands-400.ttf +0 -0
  150. package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff +0 -0
  151. package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
  152. package/static/bower_components/fontawesome/webfonts/fa-regular-400.eot +0 -0
  153. package/static/bower_components/fontawesome/webfonts/fa-regular-400.svg +93 -95
  154. package/static/bower_components/fontawesome/webfonts/fa-regular-400.ttf +0 -0
  155. package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff +0 -0
  156. package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
  157. package/static/bower_components/fontawesome/webfonts/fa-solid-900.eot +0 -0
  158. package/static/bower_components/fontawesome/webfonts/fa-solid-900.svg +1164 -1074
  159. package/static/bower_components/fontawesome/webfonts/fa-solid-900.ttf +0 -0
  160. package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff +0 -0
  161. package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
  162. package/static/bower_components/jquery/dist/jquery.js +118 -109
  163. package/static/bower_components/jquery/dist/jquery.min.js +2 -2
  164. package/static/bower_components/jquery-mockjax/dist/jquery.mockjax.js +15 -9
  165. package/static/example.css +13 -0
  166. package/static/example.postcss +13 -0
  167. package/static/example_data.js +33 -36
  168. package/static/examples/filter.js +63 -0
  169. package/tree.jquery.debug.js +4809 -3305
  170. package/tree.jquery.debug.js.map +1 -1
  171. package/tree.jquery.js +3 -3
  172. package/tree.jquery.js.map +1 -1
  173. package/tsconfig.json +1 -0
  174. package/.travis.yml +0 -18
package/lib/node.js CHANGED
@@ -1,94 +1,153 @@
1
1
  "use strict";
2
- exports.__esModule = true;
3
- exports.Node = exports.getPosition = exports.getPositionName = exports.Position = void 0;
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
- Position[Position["Before"] = 1] = "Before";
7
- Position[Position["After"] = 2] = "After";
8
- Position[Position["Inside"] = 3] = "Inside";
9
- Position[Position["None"] = 4] = "None";
10
- })(Position = exports.Position || (exports.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
- before: Position.Before,
13
- after: Position.After,
14
- inside: Position.Inside,
15
- none: Position.None
35
+ before: Position.Before,
36
+ after: Position.After,
37
+ inside: Position.Inside,
38
+ none: Position.None
16
39
  };
17
- exports.getPositionName = function (position) {
18
- for (var name_1 in positionNames) {
19
- if (Object.prototype.hasOwnProperty.call(positionNames, name_1)) {
20
- if (positionNames[name_1] === position) {
21
- return name_1;
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
- return "";
48
+ }
49
+
50
+ return "";
26
51
  };
27
- exports.getPosition = function (name) {
28
- return positionNames[name];
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
- setData(string): set the name of the node
51
- setdata(object): set attributes of the node
59
+ exports.getPosition = getPosition;
52
60
 
53
- Examples:
54
- setdata('node1')
61
+ var isNodeRecordWithChildren = function isNodeRecordWithChildren(data) {
62
+ return _typeof(data) === "object" && "children" in data && data["children"] instanceof Array;
63
+ };
55
64
 
56
- setData({ name: 'node1', id: 1});
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
- setData({ name: 'node2', id: 2, color: 'green'});
71
+ _classCallCheck(this, Node);
59
72
 
60
- * This is an internal function; it is not in the docs
61
- * Does not remove existing node values
62
- */
63
- Node.prototype.setData = function (o) {
64
- if (!o) {
65
- return;
66
- }
67
- else if (typeof o === "string") {
68
- this.name = o;
69
- }
70
- else if (typeof o === "object") {
71
- for (var key in o) {
72
- if (Object.prototype.hasOwnProperty.call(o, key)) {
73
- var value = o[key];
74
- if (key === "label" || key === "name") {
75
- // You can use the 'label' key instead of 'name'; this is a legacy feature
76
- if (typeof value === "string") {
77
- this.name = value;
78
- }
79
- }
80
- else if (key !== "children" && key !== "parent") {
81
- // You can't update the children or the parent using this function
82
- this[key] = value;
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
- Node.prototype.loadFromData = function (data) {
106
- this.removeChildren();
107
- for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
108
- var o = data_1[_i];
109
- var node = this.createNode(o);
110
- this.addChild(node);
111
- if (typeof o === "object" &&
112
- o["children"] &&
113
- o["children"] instanceof Array) {
114
- if (o["children"].length === 0) {
115
- node.isEmptyFolder = true;
116
- }
117
- else {
118
- node.loadFromData(o["children"]);
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
- return this;
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
- Node.prototype.addChild = function (node) {
132
- this.children.push(node);
133
- node.setParent(this);
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
- Node.prototype.addChildAtPosition = function (node, index) {
144
- this.children.splice(index, 0, node);
145
- node.setParent(this);
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
- Node.prototype.removeChild = function (node) {
153
- // remove children from the index
154
- node.removeChildren();
155
- this.doRemoveChild(node);
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
- Node.prototype.getChildIndex = function (node) {
163
- return this.children.indexOf(node);
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
- Node.prototype.hasChildren = function () {
173
- return this.children.length !== 0;
174
- };
175
- Node.prototype.isFolder = function () {
176
- return this.hasChildren() || this.load_on_demand;
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
- Calls callback with (node, level).
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
- Node.prototype.iterate = function (callback) {
196
- var _iterate = function (node, level) {
197
- if (node.children) {
198
- for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
199
- var child = _a[_i];
200
- var result = callback(child, level);
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
- Argument position: Position.BEFORE, Position.AFTER or Position.Inside
284
+ try {
285
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
286
+ var child = _step2.value;
287
+ var result = callback(child, level);
213
288
 
214
- // move node1 after node2
215
- tree.moveNode(node1, node2, Position.AFTER);
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
- Get the tree as data.
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
- Node.prototype.getData = function (includeParent) {
254
- if (includeParent === void 0) { includeParent = false; }
255
- var getDataFromNodes = function (nodes) {
256
- return nodes.map(function (node) {
257
- var tmpNode = {};
258
- for (var k in node) {
259
- if ([
260
- "parent",
261
- "children",
262
- "element",
263
- "idMapping",
264
- "load_on_demand",
265
- "nodeClass",
266
- "tree",
267
- "isEmptyFolder",
268
- ].indexOf(k) === -1 &&
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
- return result;
312
- };
313
- Node.prototype.addAfter = function (nodeInfo) {
314
- if (!this.parent) {
315
- return null;
316
- }
317
- else {
318
- var node = this.createNode(nodeInfo);
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
- var originalParent = this.parent;
357
- for (var _i = 0, _a = originalParent.children; _i < _a.length; _i++) {
358
- var child = _a[_i];
359
- newParent.addChild(child);
340
+
341
+ case Position.Inside:
342
+ {
343
+ // move inside as first child
344
+ targetNode.addChildAtPosition(movedNode, 0);
345
+ return true;
360
346
  }
361
- originalParent.children = [];
362
- originalParent.addChild(newParent);
363
- return newParent;
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
- return node;
393
- };
394
- Node.prototype.isParentOf = function (node) {
395
- var parent = node.parent;
396
- while (parent) {
397
- if (parent === this) {
398
- return true;
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
- parent = parent.parent;
401
- }
402
- return false;
403
- };
404
- Node.prototype.getLevel = function () {
405
- var level = 0;
406
- var node = this; // eslint-disable-line @typescript-eslint/no-this-alias
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
- this.children = [];
434
- };
435
- Node.prototype.getPreviousSibling = function () {
436
- if (!this.parent) {
437
- return null;
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
- else {
440
- var previousIndex = this.parent.getChildIndex(this) - 1;
441
- if (previousIndex >= 0) {
442
- return this.parent.children[previousIndex];
443
- }
444
- else {
445
- return null;
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
- Node.prototype.getNextSibling = function () {
450
- if (!this.parent) {
451
- return null;
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
- else {
454
- var nextIndex = this.parent.getChildIndex(this) + 1;
455
- if (nextIndex < this.parent.children.length) {
456
- return this.parent.children[nextIndex];
457
- }
458
- else {
459
- return null;
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
- Node.prototype.getNodesByProperty = function (key, value) {
464
- return this.filter(function (node) { return node[key] === value; });
465
- };
466
- Node.prototype.filter = function (f) {
467
- var result = [];
468
- this.iterate(function (node) {
469
- if (f(node)) {
470
- result.push(node);
471
- }
472
- return true;
473
- });
474
- return result;
475
- };
476
- Node.prototype.getNextNode = function (includeChildren) {
477
- if (includeChildren === void 0) { includeChildren = true; }
478
- if (includeChildren && this.hasChildren() && this.is_open) {
479
- // First child
480
- return this.children[0];
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
- else {
483
- if (!this.parent) {
484
- return null;
485
- }
486
- else {
487
- var nextSibling = this.getNextSibling();
488
- if (nextSibling) {
489
- // Next sibling
490
- return nextSibling;
491
- }
492
- else {
493
- // Next node of parent
494
- return this.parent.getNextNode(false);
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
- Node.prototype.getPreviousNode = function () {
500
- if (!this.parent) {
501
- return null;
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
- else {
504
- var previousSibling = this.getPreviousSibling();
505
- if (previousSibling) {
506
- if (!previousSibling.hasChildren() ||
507
- !previousSibling.is_open) {
508
- // Previous sibling
509
- return previousSibling;
510
- }
511
- else {
512
- // Last child of previous sibling
513
- return previousSibling.getLastChild();
514
- }
515
- }
516
- else {
517
- return this.getParent();
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
- Node.prototype.getParent = function () {
522
- // Return parent except if it is the root node
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
- return null;
525
- }
526
- else if (!this.parent.parent) {
527
- // Root node -> null
528
- return null;
529
- }
530
- else {
531
- return this.parent;
532
- }
533
- };
534
- Node.prototype.getLastChild = function () {
535
- if (!this.hasChildren()) {
536
- return null;
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
- else {
539
- var lastChild = this.children[this.children.length - 1];
540
- if (!(lastChild.hasChildren() && lastChild.is_open)) {
541
- return lastChild;
542
- }
543
- else {
544
- return lastChild.getLastChild();
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
- // Init Node from data without making it the root of the tree
549
- Node.prototype.initFromData = function (data) {
550
- var _this = this;
551
- var addNode = function (nodeData) {
552
- _this.setData(nodeData);
553
- if (typeof nodeData === "object" &&
554
- nodeData["children"] &&
555
- nodeData["children"] instanceof Array &&
556
- nodeData["children"].length) {
557
- addChildren(nodeData["children"]);
558
- }
559
- };
560
- var addChildren = function (childrenData) {
561
- for (var _i = 0, childrenData_1 = childrenData; _i < childrenData_1.length; _i++) {
562
- var child = childrenData_1[_i];
563
- var node = _this.createNode();
564
- node.initFromData(child);
565
- _this.addChild(node);
566
- }
567
- };
568
- addNode(data);
569
- };
570
- Node.prototype.setParent = function (parent) {
571
- var _a;
572
- this.parent = parent;
573
- this.tree = parent.tree;
574
- (_a = this.tree) === null || _a === void 0 ? void 0 : _a.addNodeToIndex(this);
575
- };
576
- Node.prototype.doRemoveChild = function (node) {
577
- var _a;
578
- this.children.splice(this.getChildIndex(node), 1);
579
- (_a = this.tree) === null || _a === void 0 ? void 0 : _a.removeNodeFromIndex(node);
580
- };
581
- Node.prototype.getNodeClass = function () {
582
- var _a;
583
- return this.nodeClass || ((_a = this === null || this === void 0 ? void 0 : this.tree) === null || _a === void 0 ? void 0 : _a.nodeClass) || Node;
584
- };
585
- Node.prototype.createNode = function (nodeData) {
586
- var nodeClass = this.getNodeClass();
587
- return new nodeClass(nodeData);
588
- };
589
- return Node;
590
- }());
591
- exports.Node = Node;
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;