jqtree 1.7.5 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.eslintrc +13 -3
  2. package/.github/workflows/ci.yml +6 -6
  3. package/.github/workflows/codeql-analysis.yml +4 -4
  4. package/.github/workflows/size.yml +3 -3
  5. package/.github/workflows/static.yml +1 -1
  6. package/bower.json +1 -1
  7. package/config/babel.config.json +1 -1
  8. package/config/jest.config.js +4 -0
  9. package/config/jest.polyfills.js +14 -0
  10. package/config/production +2 -0
  11. package/devserver/devserver_scroll.js +8 -0
  12. package/devserver/test_index.html +9 -0
  13. package/devserver/test_scroll.html +28 -0
  14. package/devserver/test_scroll_container.html +39 -0
  15. package/docs/.ruby-version +1 -1
  16. package/docs/_config.yml +1 -1
  17. package/docs/_entries/general/changelog.md +11 -0
  18. package/docs/_entries/multiple_selection/get-selected-nodes.md +1 -1
  19. package/docs/_entries/node/getnextnode.md +3 -6
  20. package/docs/_entries/node/getnextsibling.md +1 -1
  21. package/docs/_entries/node/getnextvisiblenode.md +8 -5
  22. package/docs/_entries/node/getpreviousnode.md +12 -0
  23. package/docs/_entries/node/getprevioussibling.md +1 -1
  24. package/docs/_entries/node/getpreviousvisiblenode.md +6 -5
  25. package/package.json +35 -29
  26. package/src/dataLoader.ts +57 -34
  27. package/src/dragAndDropHandler/dragElement.ts +54 -0
  28. package/src/dragAndDropHandler/generateHitAreas.ts +176 -0
  29. package/src/dragAndDropHandler/index.ts +454 -0
  30. package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
  31. package/src/dragAndDropHandler/types.ts +13 -0
  32. package/src/elementsRenderer.ts +75 -40
  33. package/src/jqtreeMethodTypes.ts +40 -0
  34. package/src/jqtreeOptions.ts +43 -25
  35. package/src/keyHandler.ts +59 -30
  36. package/src/mouseHandler.ts +385 -0
  37. package/src/mouseUtils.ts +23 -0
  38. package/src/node.ts +1 -29
  39. package/src/nodeElement/borderDropHint.ts +32 -0
  40. package/src/nodeElement/folderElement.ts +133 -0
  41. package/src/nodeElement/ghostDropHint.ts +69 -0
  42. package/src/nodeElement/index.ts +102 -0
  43. package/src/playwright/coverage.ts +4 -7
  44. package/src/playwright/playwright.test.ts +150 -53
  45. package/src/playwright/testUtils.ts +28 -5
  46. package/src/position.ts +28 -0
  47. package/src/saveStateHandler.ts +75 -26
  48. package/src/scrollHandler/containerScrollParent.ts +13 -23
  49. package/src/scrollHandler/createScrollParent.ts +22 -22
  50. package/src/scrollHandler/documentScrollParent.ts +16 -13
  51. package/src/scrollHandler.ts +13 -15
  52. package/src/selectNodeHandler.ts +10 -16
  53. package/src/test/jqTree/events.test.ts +97 -30
  54. package/src/test/jqTree/keyboard.test.ts +18 -23
  55. package/src/test/jqTree/loadOnDemand.test.ts +22 -15
  56. package/src/test/jqTree/methods.test.ts +40 -14
  57. package/src/test/jqTree/mouse.test.ts +82 -0
  58. package/src/test/jqTree/options.test.ts +24 -12
  59. package/src/test/node.test.ts +3 -2
  60. package/src/test/{nodeUtil.test.ts → position.test.ts} +1 -1
  61. package/src/tree.jquery.ts +314 -208
  62. package/src/util.ts +12 -0
  63. package/src/version.ts +1 -1
  64. package/tree.jquery.debug.js +2594 -3419
  65. package/tree.jquery.debug.js.map +1 -1
  66. package/tree.jquery.js +3 -3
  67. package/tree.jquery.js.map +1 -1
  68. package/tsconfig.json +5 -3
  69. package/docs/_entries/functions/get-selected-nodes.md +0 -10
  70. package/lib/dataLoader.js +0 -123
  71. package/lib/dragAndDropHandler.js +0 -588
  72. package/lib/elementsRenderer.js +0 -267
  73. package/lib/jqtreeOptions.js +0 -1
  74. package/lib/keyHandler.js +0 -111
  75. package/lib/mouse.widget.js +0 -255
  76. package/lib/node.js +0 -708
  77. package/lib/nodeElement.js +0 -274
  78. package/lib/nodeUtils.js +0 -10
  79. package/lib/playwright/coverage.js +0 -99
  80. package/lib/playwright/playwright.test.js +0 -606
  81. package/lib/playwright/testUtils.js +0 -210
  82. package/lib/saveStateHandler.js +0 -277
  83. package/lib/scrollHandler/containerScrollParent.js +0 -160
  84. package/lib/scrollHandler/createScrollParent.js +0 -57
  85. package/lib/scrollHandler/documentScrollParent.js +0 -169
  86. package/lib/scrollHandler/scrollParent.js +0 -58
  87. package/lib/scrollHandler/types.js +0 -1
  88. package/lib/scrollHandler.js +0 -71
  89. package/lib/selectNodeHandler.js +0 -128
  90. package/lib/simple.widget.js +0 -158
  91. package/lib/test/global.d.js +0 -3
  92. package/lib/test/jqTree/accessibility.test.js +0 -37
  93. package/lib/test/jqTree/create.test.js +0 -48
  94. package/lib/test/jqTree/events.test.js +0 -210
  95. package/lib/test/jqTree/keyboard.test.js +0 -225
  96. package/lib/test/jqTree/loadOnDemand.test.js +0 -218
  97. package/lib/test/jqTree/methods.test.js +0 -1348
  98. package/lib/test/jqTree/options.test.js +0 -548
  99. package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +0 -94
  100. package/lib/test/node.test.js +0 -1202
  101. package/lib/test/nodeUtil.test.js +0 -27
  102. package/lib/test/nodeUtils.test.js +0 -20
  103. package/lib/test/support/exampleData.js +0 -35
  104. package/lib/test/support/jqTreeMatchers.js +0 -70
  105. package/lib/test/support/matchers.d.js +0 -1
  106. package/lib/test/support/setupTests.js +0 -7
  107. package/lib/test/support/testUtil.js +0 -29
  108. package/lib/test/support/treeStructure.js +0 -38
  109. package/lib/test/util.test.js +0 -26
  110. package/lib/tree.jquery.d.js +0 -1
  111. package/lib/tree.jquery.js +0 -1105
  112. package/lib/types.js +0 -1
  113. package/lib/typings.d.js +0 -2
  114. package/lib/util.js +0 -15
  115. package/lib/version.js +0 -8
  116. package/src/dragAndDropHandler.ts +0 -713
  117. package/src/mouse.widget.ts +0 -266
  118. package/src/nodeElement.ts +0 -272
  119. package/src/types.ts +0 -19
package/lib/node.js DELETED
@@ -1,708 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getPositionName = exports.getPosition = exports.Position = exports.Node = void 0;
7
- var _nodeUtils = require("./nodeUtils");
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
- 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); }
10
- 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; }
11
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
- 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, _toPropertyKey(descriptor.key), descriptor); } }
14
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- var Position = exports.Position = /*#__PURE__*/function (Position) {
19
- Position[Position["Before"] = 1] = "Before";
20
- Position[Position["After"] = 2] = "After";
21
- Position[Position["Inside"] = 3] = "Inside";
22
- Position[Position["None"] = 4] = "None";
23
- return Position;
24
- }({});
25
- var positionNames = {
26
- before: Position.Before,
27
- after: Position.After,
28
- inside: Position.Inside,
29
- none: Position.None
30
- };
31
- var getPositionName = exports.getPositionName = function getPositionName(position) {
32
- for (var name in positionNames) {
33
- if (Object.prototype.hasOwnProperty.call(positionNames, name)) {
34
- if (positionNames[name] === position) {
35
- return name;
36
- }
37
- }
38
- }
39
- return "";
40
- };
41
- var getPosition = exports.getPosition = function getPosition(name) {
42
- return positionNames[name];
43
- };
44
- var Node = exports.Node = /*#__PURE__*/function () {
45
- function Node() {
46
- var nodeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
47
- var isRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
48
- var nodeClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Node;
49
- _classCallCheck(this, Node);
50
- _defineProperty(this, "id", void 0);
51
- _defineProperty(this, "name", void 0);
52
- _defineProperty(this, "children", void 0);
53
- _defineProperty(this, "parent", void 0);
54
- _defineProperty(this, "idMapping", void 0);
55
- _defineProperty(this, "tree", void 0);
56
- _defineProperty(this, "nodeClass", void 0);
57
- _defineProperty(this, "load_on_demand", void 0);
58
- _defineProperty(this, "is_open", void 0);
59
- _defineProperty(this, "element", void 0);
60
- _defineProperty(this, "is_loading", void 0);
61
- _defineProperty(this, "isEmptyFolder", void 0);
62
- this.name = "";
63
- this.load_on_demand = false;
64
- this.isEmptyFolder = nodeData != null && (0, _nodeUtils.isNodeRecordWithChildren)(nodeData) && nodeData.children.length === 0;
65
- this.setData(nodeData);
66
- this.children = [];
67
- this.parent = null;
68
- if (isRoot) {
69
- this.idMapping = new Map();
70
- this.tree = this;
71
- this.nodeClass = nodeClass;
72
- }
73
- }
74
-
75
- /*
76
- Set the data of this node.
77
- setData(string): set the name of the node
78
- setData(object): set attributes of the node
79
- Examples:
80
- setData('node1')
81
- setData({ name: 'node1', id: 1});
82
- setData({ name: 'node2', id: 2, color: 'green'});
83
- * This is an internal function; it is not in the docs
84
- * Does not remove existing node values
85
- */
86
- _createClass(Node, [{
87
- key: "setData",
88
- value: function setData(o) {
89
- if (!o) {
90
- return;
91
- } else if (typeof o === "string") {
92
- this.name = o;
93
- } else if (_typeof(o) === "object") {
94
- for (var _key in o) {
95
- if (Object.prototype.hasOwnProperty.call(o, _key)) {
96
- var value = o[_key];
97
- if (_key === "label" || _key === "name") {
98
- // You can use the 'label' key instead of 'name'; this is a legacy feature
99
- if (typeof value === "string") {
100
- this.name = value;
101
- }
102
- } else if (_key !== "children" && _key !== "parent") {
103
- // You can't update the children or the parent using this function
104
- this[_key] = value;
105
- }
106
- }
107
- }
108
- }
109
- }
110
-
111
- /*
112
- Create tree from data.
113
- Structure of data is:
114
- [
115
- {
116
- name: 'node1',
117
- children: [
118
- { name: 'child1' },
119
- { name: 'child2' }
120
- ]
121
- },
122
- {
123
- name: 'node2'
124
- }
125
- ]
126
- */
127
- }, {
128
- key: "loadFromData",
129
- value: function loadFromData(data) {
130
- this.removeChildren();
131
- var _iterator = _createForOfIteratorHelper(data),
132
- _step;
133
- try {
134
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
135
- var childData = _step.value;
136
- var _node = this.createNode(childData);
137
- this.addChild(_node);
138
- if ((0, _nodeUtils.isNodeRecordWithChildren)(childData)) {
139
- _node.loadFromData(childData.children);
140
- }
141
- }
142
- } catch (err) {
143
- _iterator.e(err);
144
- } finally {
145
- _iterator.f();
146
- }
147
- return this;
148
- }
149
-
150
- /*
151
- Add child.
152
- tree.addChild(
153
- new Node('child1')
154
- );
155
- */
156
- }, {
157
- key: "addChild",
158
- value: function addChild(node) {
159
- this.children.push(node);
160
- node.setParent(this);
161
- }
162
-
163
- /*
164
- Add child at position. Index starts at 0.
165
- tree.addChildAtPosition(
166
- new Node('abc'),
167
- 1
168
- );
169
- */
170
- }, {
171
- key: "addChildAtPosition",
172
- value: function addChildAtPosition(node, index) {
173
- this.children.splice(index, 0, node);
174
- node.setParent(this);
175
- }
176
-
177
- /*
178
- Remove child. This also removes the children of the node.
179
- tree.removeChild(tree.children[0]);
180
- */
181
- }, {
182
- key: "removeChild",
183
- value: function removeChild(node) {
184
- // remove children from the index
185
- node.removeChildren();
186
- this.doRemoveChild(node);
187
- }
188
-
189
- /*
190
- Get child index.
191
- var index = getChildIndex(node);
192
- */
193
- }, {
194
- key: "getChildIndex",
195
- value: function getChildIndex(node) {
196
- return this.children.indexOf(node);
197
- }
198
-
199
- /*
200
- Does the tree have children?
201
- if (tree.hasChildren()) {
202
- //
203
- }
204
- */
205
- }, {
206
- key: "hasChildren",
207
- value: function hasChildren() {
208
- return this.children.length !== 0;
209
- }
210
- }, {
211
- key: "isFolder",
212
- value: function isFolder() {
213
- return this.hasChildren() || this.load_on_demand;
214
- }
215
-
216
- /*
217
- Iterate over all the nodes in the tree.
218
- Calls callback with (node, level).
219
- The callback must return true to continue the iteration on current node.
220
- tree.iterate(
221
- function(node, level) {
222
- console.log(node.name);
223
- // stop iteration after level 2
224
- return (level <= 2);
225
- }
226
- );
227
- */
228
- }, {
229
- key: "iterate",
230
- value: function iterate(callback) {
231
- var _iterate = function _iterate(node, level) {
232
- if (node.children) {
233
- var _iterator2 = _createForOfIteratorHelper(node.children),
234
- _step2;
235
- try {
236
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
237
- var child = _step2.value;
238
- var result = callback(child, level);
239
- if (result && child.hasChildren()) {
240
- _iterate(child, level + 1);
241
- }
242
- }
243
- } catch (err) {
244
- _iterator2.e(err);
245
- } finally {
246
- _iterator2.f();
247
- }
248
- }
249
- };
250
- _iterate(this, 0);
251
- }
252
-
253
- /*
254
- Move node relative to another node.
255
- Argument position: Position.BEFORE, Position.AFTER or Position.Inside
256
- // move node1 after node2
257
- tree.moveNode(node1, node2, Position.AFTER);
258
- */
259
- }, {
260
- key: "moveNode",
261
- value: function moveNode(movedNode, targetNode, position) {
262
- if (!movedNode.parent || movedNode.isParentOf(targetNode)) {
263
- // - Node is parent of target node
264
- // - Or, parent is empty
265
- return false;
266
- } else {
267
- movedNode.parent.doRemoveChild(movedNode);
268
- switch (position) {
269
- case Position.After:
270
- {
271
- if (targetNode.parent) {
272
- targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode) + 1);
273
- return true;
274
- }
275
- return false;
276
- }
277
- case Position.Before:
278
- {
279
- if (targetNode.parent) {
280
- targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode));
281
- return true;
282
- }
283
- return false;
284
- }
285
- case Position.Inside:
286
- {
287
- // move inside as first child
288
- targetNode.addChildAtPosition(movedNode, 0);
289
- return true;
290
- }
291
- default:
292
- return false;
293
- }
294
- }
295
- }
296
-
297
- /*
298
- Get the tree as data.
299
- */
300
- }, {
301
- key: "getData",
302
- value: function getData() {
303
- var includeParent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
304
- var getDataFromNodes = function getDataFromNodes(nodes) {
305
- return nodes.map(function (node) {
306
- var tmpNode = {};
307
- for (var k in node) {
308
- if (["parent", "children", "element", "idMapping", "load_on_demand", "nodeClass", "tree", "isEmptyFolder"].indexOf(k) === -1 && Object.prototype.hasOwnProperty.call(node, k)) {
309
- var v = node[k];
310
- tmpNode[k] = v;
311
- }
312
- }
313
- if (node.hasChildren()) {
314
- tmpNode["children"] = getDataFromNodes(node.children);
315
- }
316
- return tmpNode;
317
- });
318
- };
319
- if (includeParent) {
320
- return getDataFromNodes([this]);
321
- } else {
322
- return getDataFromNodes(this.children);
323
- }
324
- }
325
- }, {
326
- key: "getNodeByName",
327
- value: function getNodeByName(name) {
328
- return this.getNodeByCallback(function (node) {
329
- return node.name === name;
330
- });
331
- }
332
- }, {
333
- key: "getNodeByNameMustExist",
334
- value: function getNodeByNameMustExist(name) {
335
- var node = this.getNodeByCallback(function (n) {
336
- return n.name === name;
337
- });
338
- if (!node) {
339
- throw "Node with name ".concat(name, " not found");
340
- }
341
- return node;
342
- }
343
- }, {
344
- key: "getNodeByCallback",
345
- value: function getNodeByCallback(callback) {
346
- var result = null;
347
- this.iterate(function (node) {
348
- if (result) {
349
- return false;
350
- } else if (callback(node)) {
351
- result = node;
352
- return false;
353
- } else {
354
- return true;
355
- }
356
- });
357
- return result;
358
- }
359
- }, {
360
- key: "addAfter",
361
- value: function addAfter(nodeInfo) {
362
- if (!this.parent) {
363
- return null;
364
- } else {
365
- var _node2 = this.createNode(nodeInfo);
366
- var childIndex = this.parent.getChildIndex(this);
367
- this.parent.addChildAtPosition(_node2, childIndex + 1);
368
- _node2.loadChildrenFromData(nodeInfo);
369
- return _node2;
370
- }
371
- }
372
- }, {
373
- key: "addBefore",
374
- value: function addBefore(nodeInfo) {
375
- if (!this.parent) {
376
- return null;
377
- } else {
378
- var _node3 = this.createNode(nodeInfo);
379
- var childIndex = this.parent.getChildIndex(this);
380
- this.parent.addChildAtPosition(_node3, childIndex);
381
- _node3.loadChildrenFromData(nodeInfo);
382
- return _node3;
383
- }
384
- }
385
- }, {
386
- key: "addParent",
387
- value: function addParent(nodeInfo) {
388
- if (!this.parent) {
389
- return null;
390
- } else {
391
- var newParent = this.createNode(nodeInfo);
392
- if (this.tree) {
393
- newParent.setParent(this.tree);
394
- }
395
- var originalParent = this.parent;
396
- var _iterator3 = _createForOfIteratorHelper(originalParent.children),
397
- _step3;
398
- try {
399
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
400
- var child = _step3.value;
401
- newParent.addChild(child);
402
- }
403
- } catch (err) {
404
- _iterator3.e(err);
405
- } finally {
406
- _iterator3.f();
407
- }
408
- originalParent.children = [];
409
- originalParent.addChild(newParent);
410
- return newParent;
411
- }
412
- }
413
- }, {
414
- key: "remove",
415
- value: function remove() {
416
- if (this.parent) {
417
- this.parent.removeChild(this);
418
- this.parent = null;
419
- }
420
- }
421
- }, {
422
- key: "append",
423
- value: function append(nodeInfo) {
424
- var node = this.createNode(nodeInfo);
425
- this.addChild(node);
426
- node.loadChildrenFromData(nodeInfo);
427
- return node;
428
- }
429
- }, {
430
- key: "prepend",
431
- value: function prepend(nodeInfo) {
432
- var node = this.createNode(nodeInfo);
433
- this.addChildAtPosition(node, 0);
434
- node.loadChildrenFromData(nodeInfo);
435
- return node;
436
- }
437
- }, {
438
- key: "isParentOf",
439
- value: function isParentOf(node) {
440
- var parent = node.parent;
441
- while (parent) {
442
- if (parent === this) {
443
- return true;
444
- }
445
- parent = parent.parent;
446
- }
447
- return false;
448
- }
449
- }, {
450
- key: "getLevel",
451
- value: function getLevel() {
452
- var level = 0;
453
- var node = this; // eslint-disable-line @typescript-eslint/no-this-alias
454
-
455
- while (node.parent) {
456
- level += 1;
457
- node = node.parent;
458
- }
459
- return level;
460
- }
461
- }, {
462
- key: "getNodeById",
463
- value: function getNodeById(nodeId) {
464
- return this.idMapping.get(nodeId) || null;
465
- }
466
- }, {
467
- key: "addNodeToIndex",
468
- value: function addNodeToIndex(node) {
469
- if (node.id != null) {
470
- this.idMapping.set(node.id, node);
471
- }
472
- }
473
- }, {
474
- key: "removeNodeFromIndex",
475
- value: function removeNodeFromIndex(node) {
476
- if (node.id != null) {
477
- this.idMapping["delete"](node.id);
478
- }
479
- }
480
- }, {
481
- key: "removeChildren",
482
- value: function removeChildren() {
483
- var _this = this;
484
- this.iterate(function (child) {
485
- var _this$tree;
486
- (_this$tree = _this.tree) === null || _this$tree === void 0 || _this$tree.removeNodeFromIndex(child);
487
- return true;
488
- });
489
- this.children = [];
490
- }
491
- }, {
492
- key: "getPreviousSibling",
493
- value: function getPreviousSibling() {
494
- if (!this.parent) {
495
- return null;
496
- } else {
497
- var previousIndex = this.parent.getChildIndex(this) - 1;
498
- if (previousIndex >= 0) {
499
- return this.parent.children[previousIndex] || null;
500
- } else {
501
- return null;
502
- }
503
- }
504
- }
505
- }, {
506
- key: "getNextSibling",
507
- value: function getNextSibling() {
508
- if (!this.parent) {
509
- return null;
510
- } else {
511
- var nextIndex = this.parent.getChildIndex(this) + 1;
512
- if (nextIndex < this.parent.children.length) {
513
- return this.parent.children[nextIndex] || null;
514
- } else {
515
- return null;
516
- }
517
- }
518
- }
519
- }, {
520
- key: "getNodesByProperty",
521
- value: function getNodesByProperty(key, value) {
522
- return this.filter(function (node) {
523
- return node[key] === value;
524
- });
525
- }
526
- }, {
527
- key: "filter",
528
- value: function filter(f) {
529
- var result = [];
530
- this.iterate(function (node) {
531
- if (f(node)) {
532
- result.push(node);
533
- }
534
- return true;
535
- });
536
- return result;
537
- }
538
- }, {
539
- key: "getNextNode",
540
- value: function getNextNode() {
541
- var includeChildren = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
542
- if (includeChildren && this.hasChildren()) {
543
- return this.children[0] || null;
544
- } else if (!this.parent) {
545
- return null;
546
- } else {
547
- var nextSibling = this.getNextSibling();
548
- if (nextSibling) {
549
- return nextSibling;
550
- } else {
551
- return this.parent.getNextNode(false);
552
- }
553
- }
554
- }
555
- }, {
556
- key: "getNextVisibleNode",
557
- value: function getNextVisibleNode() {
558
- if (this.hasChildren() && this.is_open) {
559
- // First child
560
- return this.children[0] || null;
561
- } else {
562
- if (!this.parent) {
563
- return null;
564
- } else {
565
- var nextSibling = this.getNextSibling();
566
- if (nextSibling) {
567
- // Next sibling
568
- return nextSibling;
569
- } else {
570
- // Next node of parent
571
- return this.parent.getNextNode(false);
572
- }
573
- }
574
- }
575
- }
576
- }, {
577
- key: "getPreviousNode",
578
- value: function getPreviousNode() {
579
- if (!this.parent) {
580
- return null;
581
- } else {
582
- var previousSibling = this.getPreviousSibling();
583
- if (!previousSibling) {
584
- return this.getParent();
585
- } else if (previousSibling.hasChildren()) {
586
- return previousSibling.getLastChild();
587
- } else {
588
- return previousSibling;
589
- }
590
- }
591
- }
592
- }, {
593
- key: "getPreviousVisibleNode",
594
- value: function getPreviousVisibleNode() {
595
- if (!this.parent) {
596
- return null;
597
- } else {
598
- var previousSibling = this.getPreviousSibling();
599
- if (!previousSibling) {
600
- return this.getParent();
601
- } else if (!previousSibling.hasChildren() || !previousSibling.is_open) {
602
- // Previous sibling
603
- return previousSibling;
604
- } else {
605
- // Last child of previous sibling
606
- return previousSibling.getLastChild();
607
- }
608
- }
609
- }
610
- }, {
611
- key: "getParent",
612
- value: function getParent() {
613
- // Return parent except if it is the root node
614
- if (!this.parent) {
615
- return null;
616
- } else if (!this.parent.parent) {
617
- // Root node -> null
618
- return null;
619
- } else {
620
- return this.parent;
621
- }
622
- }
623
- }, {
624
- key: "getLastChild",
625
- value: function getLastChild() {
626
- if (!this.hasChildren()) {
627
- return null;
628
- } else {
629
- var lastChild = this.children[this.children.length - 1];
630
- if (!lastChild) {
631
- return null;
632
- }
633
- if (!(lastChild.hasChildren() && lastChild.is_open)) {
634
- return lastChild;
635
- } else {
636
- return lastChild === null || lastChild === void 0 ? void 0 : lastChild.getLastChild();
637
- }
638
- }
639
- }
640
-
641
- // Init Node from data without making it the root of the tree
642
- }, {
643
- key: "initFromData",
644
- value: function initFromData(data) {
645
- var _this2 = this;
646
- var addNode = function addNode(nodeData) {
647
- _this2.setData(nodeData);
648
- if ((0, _nodeUtils.isNodeRecordWithChildren)(nodeData) && nodeData.children.length) {
649
- addChildren(nodeData.children);
650
- }
651
- };
652
- var addChildren = function addChildren(childrenData) {
653
- var _iterator4 = _createForOfIteratorHelper(childrenData),
654
- _step4;
655
- try {
656
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
657
- var child = _step4.value;
658
- var _node4 = _this2.createNode();
659
- _node4.initFromData(child);
660
- _this2.addChild(_node4);
661
- }
662
- } catch (err) {
663
- _iterator4.e(err);
664
- } finally {
665
- _iterator4.f();
666
- }
667
- };
668
- addNode(data);
669
- }
670
- }, {
671
- key: "setParent",
672
- value: function setParent(parent) {
673
- var _this$tree2;
674
- this.parent = parent;
675
- this.tree = parent.tree;
676
- (_this$tree2 = this.tree) === null || _this$tree2 === void 0 || _this$tree2.addNodeToIndex(this);
677
- }
678
- }, {
679
- key: "doRemoveChild",
680
- value: function doRemoveChild(node) {
681
- var _this$tree3;
682
- this.children.splice(this.getChildIndex(node), 1);
683
- (_this$tree3 = this.tree) === null || _this$tree3 === void 0 || _this$tree3.removeNodeFromIndex(node);
684
- }
685
- }, {
686
- key: "getNodeClass",
687
- value: function getNodeClass() {
688
- var _this$tree4;
689
- return this.nodeClass || (this === null || this === void 0 || (_this$tree4 = this.tree) === null || _this$tree4 === void 0 ? void 0 : _this$tree4.nodeClass) || Node;
690
- }
691
- }, {
692
- key: "createNode",
693
- value: function createNode(nodeData) {
694
- var nodeClass = this.getNodeClass();
695
- return new nodeClass(nodeData);
696
- }
697
-
698
- // Load children data from nodeInfo if it has children
699
- }, {
700
- key: "loadChildrenFromData",
701
- value: function loadChildrenFromData(nodeInfo) {
702
- if ((0, _nodeUtils.isNodeRecordWithChildren)(nodeInfo) && nodeInfo.children.length) {
703
- this.loadFromData(nodeInfo.children);
704
- }
705
- }
706
- }]);
707
- return Node;
708
- }();