jqtree 1.7.4 → 1.8.0

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