jqtree 1.6.0 → 1.6.3

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 (301) hide show
  1. package/.eslintrc +3 -11
  2. package/.github/workflows/ci.yml +48 -23
  3. package/.github/workflows/codeql-analysis.yml +9 -5
  4. package/.prettier +3 -0
  5. package/README.md +11 -8
  6. package/bower.json +1 -1
  7. package/{.postcssrc → config/.postcssrc} +0 -0
  8. package/config/babel.config.json +11 -0
  9. package/config/babel.coverage.config.json +4 -0
  10. package/{jest-jsdom.config.js → config/jest.config.js} +9 -5
  11. package/config/playwright.config.js +18 -0
  12. package/config/production +4 -0
  13. package/{rollup.config.js → config/rollup.config.js} +19 -14
  14. package/{jqtree.postcss → css/jqtree.postcss} +3 -0
  15. package/devserver/index.html +1 -9
  16. package/docs/Gemfile +2 -0
  17. package/docs/Gemfile.lock +263 -0
  18. package/{_config.yml → docs/_config.yml} +8 -1
  19. package/{_entries → docs/_entries}/01_general.md +0 -0
  20. package/{_entries → docs/_entries}/02_introduction.md +0 -0
  21. package/{_entries → docs/_entries}/03_features.md +1 -1
  22. package/{_entries → docs/_entries}/04_demo.html +1 -7
  23. package/{_entries → docs/_entries}/05_requirements.md +0 -0
  24. package/{_entries → docs/_entries}/06_downloads.md +0 -0
  25. package/{_entries → docs/_entries}/07_tutorial.md +0 -0
  26. package/{_entries → docs/_entries}/08_examples.md +0 -0
  27. package/{_entries → docs/_entries}/09_usecases.md +0 -0
  28. package/{_entries → docs/_entries}/10_changelog.md +14 -0
  29. package/{_entries → docs/_entries}/11_options.md +0 -0
  30. package/{_entries → docs/_entries}/12_animationspeed.md +0 -0
  31. package/{_entries → docs/_entries}/13_autoescape.md +0 -0
  32. package/{_entries → docs/_entries}/14_autoopen.md +0 -0
  33. package/{_entries → docs/_entries}/15_buttonleft.md +0 -0
  34. package/{_entries → docs/_entries}/16_closedicon.md +0 -0
  35. package/{_entries → docs/_entries}/17_data.md +0 -0
  36. package/{_entries → docs/_entries}/18_datafilter.md +0 -0
  37. package/{_entries → docs/_entries}/19_data-url.md +0 -0
  38. package/{_entries → docs/_entries}/20_draganddrop.md +0 -0
  39. package/{_entries → docs/_entries}/21_keyboardsupport.md +0 -0
  40. package/{_entries → docs/_entries}/22_oncanmove.md +0 -0
  41. package/{_entries → docs/_entries}/23_oncanmoveto.md +2 -2
  42. package/{_entries → docs/_entries}/24_oncanselectnode.md +0 -0
  43. package/{_entries → docs/_entries}/25_oncreateli.md +2 -2
  44. package/{_entries → docs/_entries}/26_ondragmove.md +0 -0
  45. package/{_entries → docs/_entries}/27_ondragstop.md +0 -0
  46. package/{_entries → docs/_entries}/28_onismovehandle.md +0 -0
  47. package/{_entries → docs/_entries}/29_onloadfailed.md +0 -0
  48. package/{_entries → docs/_entries}/30_onloading.md +2 -2
  49. package/{_entries → docs/_entries}/31_openedicon.md +0 -0
  50. package/{_entries → docs/_entries}/32_openfolderdelay.md +2 -0
  51. package/{_entries → docs/_entries}/33_rtl.md +0 -0
  52. package/{_entries → docs/_entries}/34_savestate.md +0 -0
  53. package/{_entries → docs/_entries}/35_selectable.md +0 -0
  54. package/{_entries → docs/_entries}/36_showemptyfolder.md +0 -0
  55. package/{_entries → docs/_entries}/37_slide.md +0 -0
  56. package/{_entries → docs/_entries}/38_start_dnd_delay.md +0 -0
  57. package/{_entries → docs/_entries}/39_tabindex.md +0 -0
  58. package/{_entries → docs/_entries}/40_usecontextmenu.md +0 -0
  59. package/{_entries → docs/_entries}/41_functions.md +0 -0
  60. package/{_entries → docs/_entries}/42_addparentnode.md +1 -1
  61. package/{_entries → docs/_entries}/43_addnodeafter.md +1 -1
  62. package/{_entries → docs/_entries}/44_addnodebefore.md +1 -1
  63. package/{_entries → docs/_entries}/45_appendnode.md +5 -5
  64. package/{_entries → docs/_entries}/46_closenode.md +0 -0
  65. package/{_entries → docs/_entries}/47_destroy.md +0 -0
  66. package/{_entries → docs/_entries}/48_getnodebycallback.md +0 -0
  67. package/{_entries → docs/_entries}/49_getnodebyid.md +0 -0
  68. package/{_entries → docs/_entries}/50_getnodebyhtmlelement.md +2 -2
  69. package/{_entries → docs/_entries}/51_getselectednode.md +0 -0
  70. package/{_entries → docs/_entries}/52_getstate.md +0 -0
  71. package/{_entries → docs/_entries}/53_gettree.md +1 -1
  72. package/{_entries → docs/_entries}/54_isdragging.md +1 -1
  73. package/{_entries → docs/_entries}/55_loaddata.md +3 -3
  74. package/{_entries → docs/_entries}/56_loaddatafromurl.md +4 -4
  75. package/{_entries → docs/_entries}/57_movedown.md +0 -0
  76. package/{_entries → docs/_entries}/58_movenode.md +3 -3
  77. package/{_entries → docs/_entries}/59_moveup.md +0 -0
  78. package/{_entries → docs/_entries}/60_opennode.md +3 -3
  79. package/docs/_entries/61_prependnode.md +21 -0
  80. package/docs/_entries/62_refresh.md +12 -0
  81. package/{_entries/62_reload.md → docs/_entries/63_reload.md} +2 -2
  82. package/{_entries/63_removenode.md → docs/_entries/64_removenode.md} +0 -0
  83. package/{_entries/64_selectnode.md → docs/_entries/65_selectnode.md} +0 -0
  84. package/{_entries/65_scrolltonode.md → docs/_entries/66_scrolltonode.md} +0 -0
  85. package/{_entries/66_setoption.md → docs/_entries/67_setoption.md} +0 -0
  86. package/{_entries/67_setstate.md → docs/_entries/68_setstate.md} +0 -0
  87. package/{_entries/68_toggle.md → docs/_entries/69_toggle.md} +0 -0
  88. package/{_entries/69_tojson.md → docs/_entries/70_tojson.md} +0 -0
  89. package/{_entries/70_updatenode.md → docs/_entries/71_updatenode.md} +1 -1
  90. package/{_entries/71_events.md → docs/_entries/72_events.md} +0 -0
  91. package/{_entries/72_tree-click.md → docs/_entries/73_tree-click.md} +0 -0
  92. package/{_entries/73_tree-close.md → docs/_entries/74_tree-close.md} +0 -0
  93. package/{_entries/74_tree-contextmenu.md → docs/_entries/75_tree-contextmenu.md} +0 -0
  94. package/{_entries/75_tree-dblclick.md → docs/_entries/76_tree-dblclick.md} +0 -0
  95. package/{_entries/76_tree-init.md → docs/_entries/77_tree-init.md} +0 -0
  96. package/{_entries/77_tree-load-data.md → docs/_entries/78_tree-load-data.md} +0 -0
  97. package/{_entries/78_tree-loading-data.md → docs/_entries/79_tree-loading-data.md} +0 -0
  98. package/{_entries/79_tree-move.md → docs/_entries/80_tree-move.md} +0 -0
  99. package/{_entries/80_tree-refresh.md → docs/_entries/81_tree-refresh.md} +0 -0
  100. package/{_entries/81_tree-open.md → docs/_entries/82_tree-open.md} +0 -0
  101. package/{_entries/82_tree-select.md → docs/_entries/83_tree-select.md} +0 -0
  102. package/{_entries/83_multiple-selection.md → docs/_entries/84_multiple-selection.md} +0 -0
  103. package/{_entries/84_add-to-selection.md → docs/_entries/85_add-to-selection.md} +0 -0
  104. package/{_entries/85_get-selected-nodes.md → docs/_entries/86_get-selected-nodes.md} +0 -0
  105. package/{_entries/86_is-node-selected.md → docs/_entries/87_is-node-selected.md} +1 -1
  106. package/{_entries/87_remove-from-selection.md → docs/_entries/88_remove-from-selection.md} +0 -0
  107. package/{_entries/88_node-functions.md → docs/_entries/89_node-functions.md} +0 -0
  108. package/{_entries/89_children.md → docs/_entries/90_children.md} +0 -0
  109. package/{_entries/90_getdata.md → docs/_entries/91_getdata.md} +2 -2
  110. package/{_entries/91_getlevel.md → docs/_entries/92_getlevel.md} +0 -0
  111. package/{_entries/92_getnextnode.md → docs/_entries/93_getnextnode.md} +0 -0
  112. package/{_entries/93_getnextsibling.md → docs/_entries/94_getnextsibling.md} +0 -0
  113. package/{_entries/94_getpreviousnode.md → docs/_entries/95_getpreviousnode.md} +0 -0
  114. package/{_entries/95_getprevioussibling.md → docs/_entries/96_getprevioussibling.md} +0 -0
  115. package/{_entries/96_parent.md → docs/_entries/97_parent.md} +1 -1
  116. package/{_entries → docs/_entries}/insert.py +0 -0
  117. package/{_entries → docs/_entries}/renumber.py +0 -0
  118. package/{_examples → docs/_examples}/01_load_json_data.html +3 -5
  119. package/{_examples → docs/_examples}/02_load_json_data_from_server.html +3 -5
  120. package/{_examples → docs/_examples}/03_drag_and_drop.html +3 -5
  121. package/{_examples → docs/_examples}/04_save_state.html +3 -5
  122. package/{_examples → docs/_examples}/05_load_on_demand.html +3 -5
  123. package/{_examples → docs/_examples}/06_autoescape.html +3 -5
  124. package/{_examples → docs/_examples}/07_autoscroll.html +3 -5
  125. package/{_examples → docs/_examples}/08_multiple_select.html +3 -5
  126. package/{_examples → docs/_examples}/09_custom_html.html +3 -5
  127. package/{_examples → docs/_examples}/10_icon_buttons.html +3 -5
  128. package/{_examples → docs/_examples}/11_right-to-left.html +3 -5
  129. package/{_examples → docs/_examples}/12_button_on_right.html +3 -5
  130. package/docs/_examples/13_drag_outside.html +48 -0
  131. package/docs/_examples/14_filter.html +111 -0
  132. package/docs/_layouts/example.html +7 -0
  133. package/docs/_layouts/page.html +26 -0
  134. package/docs/documentation.css +3 -0
  135. package/docs/index.html +65 -0
  136. package/docs/jqtree.css +189 -0
  137. package/docs/package.json +22 -0
  138. package/docs/pnpm-lock.yaml +768 -0
  139. package/docs/postcss.config.js +7 -0
  140. package/docs/static/bower.json +8 -0
  141. package/docs/static/bower_components/fontawesome/css/all.min.css +5 -0
  142. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-brands-400.eot +0 -0
  143. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-brands-400.svg +774 -627
  144. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-brands-400.ttf +0 -0
  145. package/docs/static/bower_components/fontawesome/webfonts/fa-brands-400.woff +0 -0
  146. package/docs/static/bower_components/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
  147. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-regular-400.eot +0 -0
  148. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-regular-400.svg +93 -95
  149. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-regular-400.ttf +0 -0
  150. package/docs/static/bower_components/fontawesome/webfonts/fa-regular-400.woff +0 -0
  151. package/docs/static/bower_components/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
  152. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-solid-900.eot +0 -0
  153. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-solid-900.svg +1164 -1074
  154. package/{static → docs/static}/bower_components/fontawesome/webfonts/fa-solid-900.ttf +0 -0
  155. package/docs/static/bower_components/fontawesome/webfonts/fa-solid-900.woff +0 -0
  156. package/docs/static/bower_components/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
  157. package/{static → docs/static}/bower_components/jquery/dist/jquery.js +118 -109
  158. package/docs/static/bower_components/jquery/dist/jquery.min.js +2 -0
  159. package/{static → docs/static}/bower_components/jquery-mockjax/dist/jquery.mockjax.js +15 -9
  160. package/docs/static/documentation.css +1313 -0
  161. package/docs/static/documentation.js +26 -0
  162. package/{static → docs/static}/example.css +14 -33
  163. package/{static → docs/static}/example.postcss +15 -32
  164. package/{static → docs/static}/example_data.js +33 -36
  165. package/{static → docs/static}/examples/autoescape.js +0 -0
  166. package/{static → docs/static}/examples/autoscroll.js +0 -0
  167. package/{static → docs/static}/examples/button-on-right.js +0 -0
  168. package/{static → docs/static}/examples/custom_html.js +5 -9
  169. package/{static → docs/static}/examples/drag-outside.js +0 -0
  170. package/{static → docs/static}/examples/drag_and_drop.js +0 -0
  171. package/docs/static/examples/filter.js +63 -0
  172. package/{static → docs/static}/examples/icon_buttons.js +0 -0
  173. package/{static → docs/static}/examples/load_json_data.js +0 -0
  174. package/{static → docs/static}/examples/load_json_data_from_server.js +0 -0
  175. package/{static → docs/static}/examples/load_on_demand.js +0 -0
  176. package/{static → docs/static}/examples/multiple_select.js +0 -0
  177. package/{static → docs/static}/examples/right-to-left.js +0 -0
  178. package/{static → docs/static}/examples/save_state.js +0 -0
  179. package/{static → docs/static}/monokai.css +0 -0
  180. package/{static → docs/static}/spinner.gif +0 -0
  181. package/docs/tailwind.config.js +16 -0
  182. package/docs/tree.jquery.js +21 -0
  183. package/jqtree.css +4 -1
  184. package/lib/dataLoader.js +146 -98
  185. package/lib/dragAndDropHandler.js +672 -470
  186. package/lib/elementsRenderer.js +282 -197
  187. package/lib/jqtreeOptions.js +1 -2
  188. package/lib/keyHandler.js +134 -87
  189. package/lib/mouse.widget.js +285 -184
  190. package/lib/node.js +691 -505
  191. package/lib/nodeElement.js +329 -205
  192. package/lib/playwright/coverage.js +140 -0
  193. package/lib/playwright/playwright.test.js +298 -179
  194. package/lib/playwright/testUtils.js +267 -0
  195. package/lib/saveStateHandler.js +311 -204
  196. package/lib/scrollHandler.js +293 -199
  197. package/lib/selectNodeHandler.js +140 -100
  198. package/lib/simple.widget.js +184 -109
  199. package/lib/test/global.d.js +3 -0
  200. package/lib/test/jqTree/create.test.js +44 -40
  201. package/lib/test/jqTree/events.test.js +186 -138
  202. package/lib/test/jqTree/keyboard.test.js +216 -199
  203. package/lib/test/jqTree/loadOnDemand.test.js +238 -157
  204. package/lib/test/jqTree/methods.test.js +1289 -1019
  205. package/lib/test/jqTree/options.test.js +491 -410
  206. package/lib/test/node.test.js +1036 -873
  207. package/lib/test/nodeUtil.test.js +21 -20
  208. package/lib/test/support/exampleData.js +35 -23
  209. package/lib/test/support/jqTreeMatchers.js +72 -54
  210. package/lib/test/support/matchers.d.js +1 -0
  211. package/lib/test/support/setupTests.js +9 -3
  212. package/lib/test/support/testUtil.js +35 -15
  213. package/lib/test/support/treeStructure.js +41 -32
  214. package/lib/test/util.test.js +21 -20
  215. package/lib/tree.jquery.d.js +1 -0
  216. package/lib/tree.jquery.js +1264 -886
  217. package/lib/types.js +1 -2
  218. package/lib/typings.d.js +2 -0
  219. package/lib/util.js +19 -8
  220. package/lib/version.js +8 -3
  221. package/package.json +54 -47
  222. package/src/dataLoader.ts +6 -6
  223. package/src/dragAndDropHandler.ts +8 -8
  224. package/src/elementsRenderer.ts +4 -0
  225. package/src/jqtreeOptions.ts +2 -2
  226. package/src/mouse.widget.ts +19 -15
  227. package/src/node.ts +27 -41
  228. package/src/nodeElement.ts +17 -9
  229. package/src/playwright/.eslintrc +5 -0
  230. package/src/playwright/coverage.ts +41 -0
  231. package/src/playwright/playwright.test.ts +75 -77
  232. package/src/playwright/playwright.test.ts-snapshots/with-dragAndDrop-moves-a-node-1-Chromium-darwin.png +0 -0
  233. package/src/playwright/playwright.test.ts-snapshots/with-dragAndDrop-moves-a-node-1-Chromium-linux.png +0 -0
  234. package/src/playwright/playwright.test.ts-snapshots/without-dragAndDrop-displays-a-tree-1-Chromium-darwin.png +0 -0
  235. package/src/playwright/playwright.test.ts-snapshots/without-dragAndDrop-displays-a-tree-1-Chromium-linux.png +0 -0
  236. package/src/playwright/playwright.test.ts-snapshots/without-dragAndDrop-selects-a-node-1-Chromium-darwin.png +0 -0
  237. package/src/playwright/playwright.test.ts-snapshots/without-dragAndDrop-selects-a-node-1-Chromium-linux.png +0 -0
  238. package/src/playwright/testUtils.ts +122 -0
  239. package/src/saveStateHandler.ts +11 -6
  240. package/src/selectNodeHandler.ts +1 -1
  241. package/src/simple.widget.ts +1 -1
  242. package/src/test/.eslintrc +14 -0
  243. package/src/test/jqTree/create.test.ts +0 -1
  244. package/src/test/jqTree/events.test.ts +10 -10
  245. package/src/test/jqTree/keyboard.test.ts +0 -1
  246. package/src/test/jqTree/loadOnDemand.test.ts +56 -11
  247. package/src/test/jqTree/methods.test.ts +72 -55
  248. package/src/test/jqTree/options.test.ts +30 -33
  249. package/src/test/node.test.ts +2 -2
  250. package/src/test/support/jqTreeMatchers.ts +8 -9
  251. package/src/test/support/matchers.d.ts +2 -4
  252. package/src/test/support/setupTests.ts +2 -1
  253. package/src/tree.jquery.d.ts +19 -13
  254. package/src/tree.jquery.ts +35 -28
  255. package/src/version.ts +1 -1
  256. package/tree.jquery.debug.js +4810 -3325
  257. package/tree.jquery.debug.js.map +1 -1
  258. package/tree.jquery.js +3 -3
  259. package/tree.jquery.js.map +1 -1
  260. package/tsconfig.json +1 -0
  261. package/_entries/61_prependnode.md +0 -21
  262. package/_examples/13_drag_outside.html +0 -25
  263. package/_layouts/base.html +0 -55
  264. package/_layouts/frontpage.html +0 -20
  265. package/_layouts/page.html +0 -7
  266. package/index.html +0 -48
  267. package/jest-browser.config.js +0 -18
  268. package/jest-playwright.config.js +0 -21
  269. package/jest.config.js +0 -8
  270. package/lib/playwright/testUtil.js +0 -223
  271. package/lib/playwright/visualRegression.js +0 -128
  272. package/production +0 -5
  273. package/src/playwright/screenshots/displays_a_tree_Desktop.png +0 -0
  274. package/src/playwright/screenshots/displays_a_tree_iPhone 6.png +0 -0
  275. package/src/playwright/screenshots/moves_a_node_Desktop.png +0 -0
  276. package/src/playwright/screenshots/moves_a_node_iPhone 6.png +0 -0
  277. package/src/playwright/screenshots/opens_a_node_Desktop.png +0 -0
  278. package/src/playwright/screenshots/opens_a_node_iPhone 6.png +0 -0
  279. package/src/playwright/screenshots/selects_a_node_Desktop.png +0 -0
  280. package/src/playwright/screenshots/selects_a_node_iPhone 6.png +0 -0
  281. package/src/playwright/testUtil.ts +0 -171
  282. package/src/playwright/visualRegression.ts +0 -88
  283. package/static/bower.json +0 -9
  284. package/static/bower_components/bootstrap/dist/css/bootstrap-theme.min.css +0 -6
  285. package/static/bower_components/bootstrap/dist/css/bootstrap.min.css +0 -6
  286. package/static/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  287. package/static/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +0 -288
  288. package/static/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  289. package/static/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  290. package/static/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
  291. package/static/bower_components/bootstrap/dist/js/bootstrap.min.js +0 -6
  292. package/static/bower_components/fontawesome/css/all.min.css +0 -5
  293. package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff +0 -0
  294. package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
  295. package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff +0 -0
  296. package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
  297. package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff +0 -0
  298. package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
  299. package/static/bower_components/jquery/dist/jquery.min.js +0 -2
  300. package/static/documentation.css +0 -171
  301. package/static/documentation.js +0 -48
package/lib/node.js CHANGED
@@ -1,96 +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
- var 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
  };
52
+
27
53
  exports.getPositionName = getPositionName;
28
- var getPosition = function (name) {
29
- return positionNames[name];
54
+
55
+ var getPosition = function getPosition(name) {
56
+ return positionNames[name];
30
57
  };
58
+
31
59
  exports.getPosition = getPosition;
32
- var Node = /** @class */ (function () {
33
- function Node(o, isRoot, nodeClass) {
34
- if (o === void 0) { o = null; }
35
- if (isRoot === void 0) { isRoot = false; }
36
- if (nodeClass === void 0) { nodeClass = Node; }
37
- this.name = "";
38
- this.isEmptyFolder = false;
39
- this.load_on_demand = false;
40
- this.setData(o);
41
- this.children = [];
42
- this.parent = null;
43
- if (isRoot) {
44
- this.idMapping = new Map();
45
- this.tree = this;
46
- this.nodeClass = nodeClass;
47
- }
48
- }
49
- /*
50
- Set the data of this node.
51
60
 
52
- setData(string): set the name of the node
53
- setdata(object): set attributes of the node
61
+ var isNodeRecordWithChildren = function isNodeRecordWithChildren(data) {
62
+ return _typeof(data) === "object" && "children" in data && data["children"] instanceof Array;
63
+ };
54
64
 
55
- Examples:
56
- setdata('node1')
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: 'node1', id: 1});
71
+ _classCallCheck(this, Node);
59
72
 
60
- setData({ name: 'node2', id: 2, color: 'green'});
73
+ _defineProperty(this, "id", void 0);
61
74
 
62
- * This is an internal function; it is not in the docs
63
- * Does not remove existing node values
64
- */
65
- Node.prototype.setData = function (o) {
66
- if (!o) {
67
- return;
68
- }
69
- else if (typeof o === "string") {
70
- this.name = o;
71
- }
72
- else if (typeof o === "object") {
73
- for (var key in o) {
74
- if (Object.prototype.hasOwnProperty.call(o, key)) {
75
- var value = o[key];
76
- if (key === "label" || key === "name") {
77
- // You can use the 'label' key instead of 'name'; this is a legacy feature
78
- if (typeof value === "string") {
79
- this.name = value;
80
- }
81
- }
82
- else if (key !== "children" && key !== "parent") {
83
- // You can't update the children or the parent using this function
84
- this[key] = value;
85
- }
86
- }
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;
87
143
  }
144
+ }
88
145
  }
89
- };
146
+ }
147
+ }
90
148
  /*
91
149
  Create tree from data.
92
-
93
- Structure of data is:
150
+ Structure of data is:
94
151
  [
95
152
  {
96
153
  name: 'node1',
@@ -104,490 +161,619 @@ var Node = /** @class */ (function () {
104
161
  }
105
162
  ]
106
163
  */
107
- Node.prototype.loadFromData = function (data) {
108
- this.removeChildren();
109
- for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
110
- var o = data_1[_i];
111
- var node = this.createNode(o);
112
- this.addChild(node);
113
- if (typeof o === "object" &&
114
- o["children"] &&
115
- o["children"] instanceof Array) {
116
- if (o["children"].length === 0) {
117
- node.isEmptyFolder = true;
118
- }
119
- else {
120
- node.loadFromData(o["children"]);
121
- }
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);
122
186
  }
187
+ }
123
188
  }
124
- return this;
125
- };
189
+ } catch (err) {
190
+ _iterator.e(err);
191
+ } finally {
192
+ _iterator.f();
193
+ }
194
+
195
+ return this;
196
+ }
126
197
  /*
127
198
  Add child.
128
-
129
- tree.addChild(
199
+ tree.addChild(
130
200
  new Node('child1')
131
201
  );
132
202
  */
133
- Node.prototype.addChild = function (node) {
134
- this.children.push(node);
135
- node.setParent(this);
136
- };
203
+
204
+ }, {
205
+ key: "addChild",
206
+ value: function addChild(node) {
207
+ this.children.push(node);
208
+ node.setParent(this);
209
+ }
137
210
  /*
138
211
  Add child at position. Index starts at 0.
139
-
140
- tree.addChildAtPosition(
212
+ tree.addChildAtPosition(
141
213
  new Node('abc'),
142
214
  1
143
215
  );
144
216
  */
145
- Node.prototype.addChildAtPosition = function (node, index) {
146
- this.children.splice(index, 0, node);
147
- node.setParent(this);
148
- };
217
+
218
+ }, {
219
+ key: "addChildAtPosition",
220
+ value: function addChildAtPosition(node, index) {
221
+ this.children.splice(index, 0, node);
222
+ node.setParent(this);
223
+ }
149
224
  /*
150
225
  Remove child. This also removes the children of the node.
151
-
152
- tree.removeChild(tree.children[0]);
226
+ tree.removeChild(tree.children[0]);
153
227
  */
154
- Node.prototype.removeChild = function (node) {
155
- // remove children from the index
156
- node.removeChildren();
157
- this.doRemoveChild(node);
158
- };
228
+
229
+ }, {
230
+ key: "removeChild",
231
+ value: function removeChild(node) {
232
+ // remove children from the index
233
+ node.removeChildren();
234
+ this.doRemoveChild(node);
235
+ }
159
236
  /*
160
237
  Get child index.
161
-
162
- var index = getChildIndex(node);
238
+ var index = getChildIndex(node);
163
239
  */
164
- Node.prototype.getChildIndex = function (node) {
165
- return this.children.indexOf(node);
166
- };
240
+
241
+ }, {
242
+ key: "getChildIndex",
243
+ value: function getChildIndex(node) {
244
+ return this.children.indexOf(node);
245
+ }
167
246
  /*
168
247
  Does the tree have children?
169
-
170
- if (tree.hasChildren()) {
248
+ if (tree.hasChildren()) {
171
249
  //
172
250
  }
173
251
  */
174
- Node.prototype.hasChildren = function () {
175
- return this.children.length !== 0;
176
- };
177
- Node.prototype.isFolder = function () {
178
- return this.hasChildren() || this.load_on_demand;
179
- };
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
+ }
180
263
  /*
181
264
  Iterate over all the nodes in the tree.
182
-
183
- Calls callback with (node, level).
184
-
185
- The callback must return true to continue the iteration on current node.
186
-
187
- tree.iterate(
265
+ Calls callback with (node, level).
266
+ The callback must return true to continue the iteration on current node.
267
+ tree.iterate(
188
268
  function(node, level) {
189
269
  console.log(node.name);
190
-
191
- // stop iteration after level 2
270
+ // stop iteration after level 2
192
271
  return (level <= 2);
193
272
  }
194
273
  );
274
+ */
195
275
 
196
- */
197
- Node.prototype.iterate = function (callback) {
198
- var _iterate = function (node, level) {
199
- if (node.children) {
200
- for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
201
- var child = _a[_i];
202
- var result = callback(child, level);
203
- if (result && child.hasChildren()) {
204
- _iterate(child, level + 1);
205
- }
206
- }
207
- }
208
- };
209
- _iterate(this, 0);
210
- };
211
- /*
212
- 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;
213
283
 
214
- 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);
215
288
 
216
- // move node1 after node2
217
- tree.moveNode(node1, node2, Position.AFTER);
218
- */
219
- Node.prototype.moveNode = function (movedNode, targetNode, position) {
220
- if (!movedNode.parent || movedNode.isParentOf(targetNode)) {
221
- // - Node is parent of target node
222
- // - Or, parent is empty
223
- return false;
224
- }
225
- else {
226
- movedNode.parent.doRemoveChild(movedNode);
227
- switch (position) {
228
- case Position.After: {
229
- if (targetNode.parent) {
230
- targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode) + 1);
231
- return true;
232
- }
233
- return false;
234
- }
235
- case Position.Before: {
236
- if (targetNode.parent) {
237
- targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode));
238
- return true;
239
- }
240
- return false;
241
- }
242
- case Position.Inside: {
243
- // move inside as first child
244
- targetNode.addChildAtPosition(movedNode, 0);
245
- return true;
246
- }
247
- default:
248
- return false;
289
+ if (result && child.hasChildren()) {
290
+ _iterate(child, level + 1);
291
+ }
249
292
  }
293
+ } catch (err) {
294
+ _iterator2.e(err);
295
+ } finally {
296
+ _iterator2.f();
297
+ }
250
298
  }
251
- };
299
+ };
300
+
301
+ _iterate(this, 0);
302
+ }
252
303
  /*
253
- 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);
254
308
  */
255
- Node.prototype.getData = function (includeParent) {
256
- if (includeParent === void 0) { includeParent = false; }
257
- var getDataFromNodes = function (nodes) {
258
- return nodes.map(function (node) {
259
- var tmpNode = {};
260
- for (var k in node) {
261
- if ([
262
- "parent",
263
- "children",
264
- "element",
265
- "idMapping",
266
- "load_on_demand",
267
- "nodeClass",
268
- "tree",
269
- "isEmptyFolder",
270
- ].indexOf(k) === -1 &&
271
- Object.prototype.hasOwnProperty.call(node, k)) {
272
- var v = node[k];
273
- tmpNode[k] = v;
274
- }
275
- }
276
- if (node.hasChildren()) {
277
- tmpNode["children"] = getDataFromNodes(node.children);
278
- }
279
- return tmpNode;
280
- });
281
- };
282
- if (includeParent) {
283
- return getDataFromNodes([this]);
284
- }
285
- else {
286
- return getDataFromNodes(this.children);
287
- }
288
- };
289
- Node.prototype.getNodeByName = function (name) {
290
- return this.getNodeByCallback(function (node) { return node.name === name; });
291
- };
292
- Node.prototype.getNodeByNameMustExist = function (name) {
293
- var node = this.getNodeByCallback(function (n) { return n.name === name; });
294
- if (!node) {
295
- throw "Node with name " + name + " not found";
296
- }
297
- return node;
298
- };
299
- Node.prototype.getNodeByCallback = function (callback) {
300
- var result = null;
301
- this.iterate(function (node) {
302
- if (result) {
303
- return false;
304
- }
305
- else if (callback(node)) {
306
- result = node;
307
- return false;
308
- }
309
- 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);
310
325
  return true;
326
+ }
327
+
328
+ return false;
311
329
  }
312
- });
313
- return result;
314
- };
315
- Node.prototype.addAfter = function (nodeInfo) {
316
- if (!this.parent) {
317
- return null;
318
- }
319
- else {
320
- var node = this.createNode(nodeInfo);
321
- var childIndex = this.parent.getChildIndex(this);
322
- this.parent.addChildAtPosition(node, childIndex + 1);
323
- if (typeof nodeInfo === "object" &&
324
- nodeInfo["children"] &&
325
- nodeInfo["children"] instanceof Array &&
326
- nodeInfo["children"].length) {
327
- node.loadFromData(nodeInfo["children"]);
328
- }
329
- return node;
330
- }
331
- };
332
- Node.prototype.addBefore = function (nodeInfo) {
333
- if (!this.parent) {
334
- return null;
335
- }
336
- else {
337
- var node = this.createNode(nodeInfo);
338
- var childIndex = this.parent.getChildIndex(this);
339
- this.parent.addChildAtPosition(node, childIndex);
340
- if (typeof nodeInfo === "object" &&
341
- nodeInfo["children"] &&
342
- nodeInfo["children"] instanceof Array &&
343
- nodeInfo["children"].length) {
344
- node.loadFromData(nodeInfo["children"]);
345
- }
346
- return node;
347
- }
348
- };
349
- Node.prototype.addParent = function (nodeInfo) {
350
- if (!this.parent) {
351
- return null;
352
- }
353
- else {
354
- var newParent = this.createNode(nodeInfo);
355
- if (this.tree) {
356
- 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;
357
339
  }
358
- var originalParent = this.parent;
359
- for (var _i = 0, _a = originalParent.children; _i < _a.length; _i++) {
360
- var child = _a[_i];
361
- newParent.addChild(child);
340
+
341
+ case Position.Inside:
342
+ {
343
+ // move inside as first child
344
+ targetNode.addChildAtPosition(movedNode, 0);
345
+ return true;
362
346
  }
363
- originalParent.children = [];
364
- originalParent.addChild(newParent);
365
- return newParent;
366
- }
367
- };
368
- Node.prototype.remove = function () {
369
- if (this.parent) {
370
- this.parent.removeChild(this);
371
- this.parent = null;
372
- }
373
- };
374
- Node.prototype.append = function (nodeInfo) {
375
- var node = this.createNode(nodeInfo);
376
- this.addChild(node);
377
- if (typeof nodeInfo === "object" &&
378
- nodeInfo["children"] &&
379
- nodeInfo["children"] instanceof Array &&
380
- nodeInfo["children"].length) {
381
- node.loadFromData(nodeInfo["children"]);
382
- }
383
- return node;
384
- };
385
- Node.prototype.prepend = function (nodeInfo) {
386
- var node = this.createNode(nodeInfo);
387
- this.addChildAtPosition(node, 0);
388
- if (typeof nodeInfo === "object" &&
389
- nodeInfo["children"] &&
390
- nodeInfo["children"] instanceof Array &&
391
- nodeInfo["children"].length) {
392
- node.loadFromData(nodeInfo["children"]);
347
+
348
+ default:
349
+ return false;
393
350
  }
394
- return node;
395
- };
396
- Node.prototype.isParentOf = function (node) {
397
- var parent = node.parent;
398
- while (parent) {
399
- if (parent === this) {
400
- 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;
401
370
  }
402
- parent = parent.parent;
403
- }
404
- return false;
405
- };
406
- Node.prototype.getLevel = function () {
407
- var level = 0;
408
- var node = this; // eslint-disable-line @typescript-eslint/no-this-alias
409
- while (node.parent) {
410
- level += 1;
411
- node = node.parent;
412
- }
413
- return level;
414
- };
415
- Node.prototype.getNodeById = function (nodeId) {
416
- return this.idMapping.get(nodeId) || null;
417
- };
418
- Node.prototype.addNodeToIndex = function (node) {
419
- if (node.id != null) {
420
- this.idMapping.set(node.id, node);
421
- }
422
- };
423
- Node.prototype.removeNodeFromIndex = function (node) {
424
- if (node.id != null) {
425
- this.idMapping["delete"](node.id);
426
- }
427
- };
428
- Node.prototype.removeChildren = function () {
429
- var _this = this;
430
- this.iterate(function (child) {
431
- var _a;
432
- (_a = _this.tree) === null || _a === void 0 ? void 0 : _a.removeNodeFromIndex(child);
433
- return true;
371
+ }
372
+
373
+ if (node.hasChildren()) {
374
+ tmpNode["children"] = getDataFromNodes(node.children);
375
+ }
376
+
377
+ return tmpNode;
434
378
  });
435
- this.children = [];
436
- };
437
- Node.prototype.getPreviousSibling = function () {
438
- if (!this.parent) {
439
- 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);
440
436
  }
441
- else {
442
- var previousIndex = this.parent.getChildIndex(this) - 1;
443
- if (previousIndex >= 0) {
444
- return this.parent.children[previousIndex];
445
- }
446
- else {
447
- return null;
448
- }
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);
449
454
  }
450
- };
451
- Node.prototype.getNextSibling = function () {
452
- if (!this.parent) {
453
- 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);
454
469
  }
455
- else {
456
- var nextIndex = this.parent.getChildIndex(this) + 1;
457
- if (nextIndex < this.parent.children.length) {
458
- return this.parent.children[nextIndex];
459
- }
460
- else {
461
- return null;
462
- }
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();
463
485
  }
464
- };
465
- Node.prototype.getNodesByProperty = function (key, value) {
466
- return this.filter(function (node) { return node[key] === value; });
467
- };
468
- Node.prototype.filter = function (f) {
469
- var result = [];
470
- this.iterate(function (node) {
471
- if (f(node)) {
472
- result.push(node);
473
- }
474
- return true;
475
- });
476
- return result;
477
- };
478
- Node.prototype.getNextNode = function (includeChildren) {
479
- if (includeChildren === void 0) { includeChildren = true; }
480
- if (includeChildren && this.hasChildren() && this.is_open) {
481
- // First child
482
- 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;
483
532
  }
484
- else {
485
- if (!this.parent) {
486
- return null;
487
- }
488
- else {
489
- var nextSibling = this.getNextSibling();
490
- if (nextSibling) {
491
- // Next sibling
492
- return nextSibling;
493
- }
494
- else {
495
- // Next node of parent
496
- return this.parent.getNextNode(false);
497
- }
498
- }
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;
499
596
  }
500
- };
501
- Node.prototype.getPreviousNode = function () {
502
- if (!this.parent) {
503
- 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;
504
611
  }
505
- else {
506
- var previousSibling = this.getPreviousSibling();
507
- if (previousSibling) {
508
- if (!previousSibling.hasChildren() ||
509
- !previousSibling.is_open) {
510
- // Previous sibling
511
- return previousSibling;
512
- }
513
- else {
514
- // Last child of previous sibling
515
- return previousSibling.getLastChild();
516
- }
517
- }
518
- else {
519
- return this.getParent();
520
- }
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);
521
628
  }
522
- };
523
- Node.prototype.getParent = function () {
524
- // 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 {
525
643
  if (!this.parent) {
526
- return null;
527
- }
528
- else if (!this.parent.parent) {
529
- // Root node -> null
530
- return null;
531
- }
532
- else {
533
- return this.parent;
534
- }
535
- };
536
- Node.prototype.getLastChild = function () {
537
- if (!this.hasChildren()) {
538
- 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();
539
704
  }
540
- else {
541
- var lastChild = this.children[this.children.length - 1];
542
- if (!(lastChild.hasChildren() && lastChild.is_open)) {
543
- return lastChild;
544
- }
545
- else {
546
- return lastChild.getLastChild();
547
- }
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);
548
718
  }
549
- };
550
- // Init Node from data without making it the root of the tree
551
- Node.prototype.initFromData = function (data) {
552
- var _this = this;
553
- var addNode = function (nodeData) {
554
- _this.setData(nodeData);
555
- if (typeof nodeData === "object" &&
556
- nodeData["children"] &&
557
- nodeData["children"] instanceof Array &&
558
- nodeData["children"].length) {
559
- addChildren(nodeData["children"]);
560
- }
561
- };
562
- var addChildren = function (childrenData) {
563
- for (var _i = 0, childrenData_1 = childrenData; _i < childrenData_1.length; _i++) {
564
- var child = childrenData_1[_i];
565
- var node = _this.createNode();
566
- node.initFromData(child);
567
- _this.addChild(node);
568
- }
569
- };
570
- addNode(data);
571
- };
572
- Node.prototype.setParent = function (parent) {
573
- var _a;
574
- this.parent = parent;
575
- this.tree = parent.tree;
576
- (_a = this.tree) === null || _a === void 0 ? void 0 : _a.addNodeToIndex(this);
577
- };
578
- Node.prototype.doRemoveChild = function (node) {
579
- var _a;
580
- this.children.splice(this.getChildIndex(node), 1);
581
- (_a = this.tree) === null || _a === void 0 ? void 0 : _a.removeNodeFromIndex(node);
582
- };
583
- Node.prototype.getNodeClass = function () {
584
- var _a;
585
- return this.nodeClass || ((_a = this === null || this === void 0 ? void 0 : this.tree) === null || _a === void 0 ? void 0 : _a.nodeClass) || Node;
586
- };
587
- Node.prototype.createNode = function (nodeData) {
588
- var nodeClass = this.getNodeClass();
589
- return new nodeClass(nodeData);
590
- };
591
- return Node;
592
- }());
593
- 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;