jqtree 1.7.4 → 1.7.5

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 (59) hide show
  1. package/.eslintrc +5 -1
  2. package/bower.json +1 -1
  3. package/docs/_config.yml +1 -1
  4. package/docs/_entries/general/changelog.md +5 -0
  5. package/docs/package.json +1 -1
  6. package/docs/pnpm-lock.yaml +30 -30
  7. package/lib/dataLoader.js +2 -3
  8. package/lib/dragAndDropHandler.js +5 -13
  9. package/lib/elementsRenderer.js +2 -3
  10. package/lib/keyHandler.js +1 -5
  11. package/lib/mouse.widget.js +1 -2
  12. package/lib/node.js +30 -39
  13. package/lib/nodeElement.js +3 -6
  14. package/lib/nodeUtils.js +10 -0
  15. package/lib/playwright/coverage.js +14 -11
  16. package/lib/playwright/playwright.test.js +482 -104
  17. package/lib/playwright/testUtils.js +75 -49
  18. package/lib/saveStateHandler.js +2 -3
  19. package/lib/scrollHandler/containerScrollParent.js +160 -0
  20. package/lib/scrollHandler/createScrollParent.js +57 -0
  21. package/lib/scrollHandler/documentScrollParent.js +169 -0
  22. package/lib/scrollHandler/scrollParent.js +58 -0
  23. package/lib/scrollHandler/types.js +1 -0
  24. package/lib/scrollHandler.js +28 -207
  25. package/lib/selectNodeHandler.js +2 -3
  26. package/lib/simple.widget.js +1 -2
  27. package/lib/test/jqTree/loadOnDemand.test.js +3 -3
  28. package/lib/test/jqTree/methods.test.js +2 -1
  29. package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +94 -0
  30. package/lib/test/node.test.js +49 -7
  31. package/lib/test/nodeUtils.test.js +20 -0
  32. package/lib/test/support/exampleData.js +1 -2
  33. package/lib/test/support/testUtil.js +3 -6
  34. package/lib/test/support/treeStructure.js +1 -2
  35. package/lib/tree.jquery.js +6 -7
  36. package/lib/util.js +4 -7
  37. package/lib/version.js +2 -3
  38. package/package.json +27 -27
  39. package/src/dragAndDropHandler.ts +27 -33
  40. package/src/keyHandler.ts +0 -8
  41. package/src/node.ts +32 -48
  42. package/src/nodeUtils.ts +10 -0
  43. package/src/playwright/playwright.test.ts +207 -15
  44. package/src/playwright/testUtils.ts +23 -15
  45. package/src/scrollHandler/containerScrollParent.ts +177 -0
  46. package/src/scrollHandler/createScrollParent.ts +50 -0
  47. package/src/scrollHandler/documentScrollParent.ts +182 -0
  48. package/src/scrollHandler/types.ts +7 -0
  49. package/src/scrollHandler.ts +25 -243
  50. package/src/test/jqTree/loadOnDemand.test.ts +2 -3
  51. package/src/test/jqTree/methods.test.ts +1 -1
  52. package/src/test/node.test.ts +84 -25
  53. package/src/test/nodeUtils.test.ts +21 -0
  54. package/src/tree.jquery.ts +27 -30
  55. package/src/version.ts +1 -1
  56. package/tree.jquery.debug.js +391 -229
  57. package/tree.jquery.debug.js.map +1 -1
  58. package/tree.jquery.js +2 -2
  59. package/tree.jquery.js.map +1 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- JqTree 1.7.4
2
+ JqTree 1.7.5
3
3
 
4
4
  Copyright 2023 Marco Braak
5
5
 
@@ -292,7 +292,11 @@ var jqtree = (function (exports) {
292
292
  return typeof key === "symbol" ? key : String(key);
293
293
  }
294
294
 
295
- var version = "1.7.4";
295
+ var version = "1.7.5";
296
+
297
+ var isNodeRecordWithChildren = function isNodeRecordWithChildren(data) {
298
+ return _typeof(data) === "object" && "children" in data && data["children"] instanceof Array;
299
+ };
296
300
 
297
301
  var Position = /*#__PURE__*/function (Position) {
298
302
  Position[Position["Before"] = 1] = "Before";
@@ -320,12 +324,9 @@ var jqtree = (function (exports) {
320
324
  var getPosition = function getPosition(name) {
321
325
  return positionNames[name];
322
326
  };
323
- var isNodeRecordWithChildren = function isNodeRecordWithChildren(data) {
324
- return _typeof(data) === "object" && "children" in data && data["children"] instanceof Array;
325
- };
326
327
  var Node = /*#__PURE__*/function () {
327
328
  function Node() {
328
- var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
329
+ var nodeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
329
330
  var isRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
330
331
  var nodeClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Node;
331
332
  _classCallCheck(this, Node);
@@ -342,9 +343,9 @@ var jqtree = (function (exports) {
342
343
  _defineProperty(this, "is_loading", void 0);
343
344
  _defineProperty(this, "isEmptyFolder", void 0);
344
345
  this.name = "";
345
- this.isEmptyFolder = false;
346
346
  this.load_on_demand = false;
347
- this.setData(o);
347
+ this.isEmptyFolder = nodeData != null && isNodeRecordWithChildren(nodeData) && nodeData.children.length === 0;
348
+ this.setData(nodeData);
348
349
  this.children = [];
349
350
  this.parent = null;
350
351
  if (isRoot) {
@@ -357,9 +358,9 @@ var jqtree = (function (exports) {
357
358
  /*
358
359
  Set the data of this node.
359
360
  setData(string): set the name of the node
360
- setdata(object): set attributes of the node
361
+ setData(object): set attributes of the node
361
362
  Examples:
362
- setdata('node1')
363
+ setData('node1')
363
364
  setData({ name: 'node1', id: 1});
364
365
  setData({ name: 'node2', id: 2, color: 'green'});
365
366
  * This is an internal function; it is not in the docs
@@ -414,15 +415,11 @@ var jqtree = (function (exports) {
414
415
  _step;
415
416
  try {
416
417
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
417
- var o = _step.value;
418
- var _node = this.createNode(o);
418
+ var childData = _step.value;
419
+ var _node = this.createNode(childData);
419
420
  this.addChild(_node);
420
- if (isNodeRecordWithChildren(o)) {
421
- if (o.children.length === 0) {
422
- _node.isEmptyFolder = true;
423
- } else {
424
- _node.loadFromData(o.children);
425
- }
421
+ if (isNodeRecordWithChildren(childData)) {
422
+ _node.loadFromData(childData.children);
426
423
  }
427
424
  }
428
425
  } catch (err) {
@@ -651,9 +648,7 @@ var jqtree = (function (exports) {
651
648
  var _node2 = this.createNode(nodeInfo);
652
649
  var childIndex = this.parent.getChildIndex(this);
653
650
  this.parent.addChildAtPosition(_node2, childIndex + 1);
654
- if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
655
- _node2.loadFromData(nodeInfo.children);
656
- }
651
+ _node2.loadChildrenFromData(nodeInfo);
657
652
  return _node2;
658
653
  }
659
654
  }
@@ -666,9 +661,7 @@ var jqtree = (function (exports) {
666
661
  var _node3 = this.createNode(nodeInfo);
667
662
  var childIndex = this.parent.getChildIndex(this);
668
663
  this.parent.addChildAtPosition(_node3, childIndex);
669
- if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
670
- _node3.loadFromData(nodeInfo.children);
671
- }
664
+ _node3.loadChildrenFromData(nodeInfo);
672
665
  return _node3;
673
666
  }
674
667
  }
@@ -713,9 +706,7 @@ var jqtree = (function (exports) {
713
706
  value: function append(nodeInfo) {
714
707
  var node = this.createNode(nodeInfo);
715
708
  this.addChild(node);
716
- if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
717
- node.loadFromData(nodeInfo.children);
718
- }
709
+ node.loadChildrenFromData(nodeInfo);
719
710
  return node;
720
711
  }
721
712
  }, {
@@ -723,9 +714,7 @@ var jqtree = (function (exports) {
723
714
  value: function prepend(nodeInfo) {
724
715
  var node = this.createNode(nodeInfo);
725
716
  this.addChildAtPosition(node, 0);
726
- if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
727
- node.loadFromData(nodeInfo.children);
728
- }
717
+ node.loadChildrenFromData(nodeInfo);
729
718
  return node;
730
719
  }
731
720
  }, {
@@ -988,6 +977,15 @@ var jqtree = (function (exports) {
988
977
  var nodeClass = this.getNodeClass();
989
978
  return new nodeClass(nodeData);
990
979
  }
980
+
981
+ // Load children data from nodeInfo if it has children
982
+ }, {
983
+ key: "loadChildrenFromData",
984
+ value: function loadChildrenFromData(nodeInfo) {
985
+ if (isNodeRecordWithChildren(nodeInfo) && nodeInfo.children.length) {
986
+ this.loadFromData(nodeInfo.children);
987
+ }
988
+ }
991
989
  }]);
992
990
  return Node;
993
991
  }();
@@ -999,7 +997,6 @@ var jqtree = (function (exports) {
999
997
  _defineProperty(this, "isDragging", void 0);
1000
998
  _defineProperty(this, "currentItem", void 0);
1001
999
  _defineProperty(this, "hoveredArea", void 0);
1002
- _defineProperty(this, "positionInfo", void 0);
1003
1000
  _defineProperty(this, "treeWidget", void 0);
1004
1001
  _defineProperty(this, "dragElement", void 0);
1005
1002
  _defineProperty(this, "previousGhost", void 0);
@@ -1009,7 +1006,6 @@ var jqtree = (function (exports) {
1009
1006
  this.hitAreas = [];
1010
1007
  this.isDragging = false;
1011
1008
  this.currentItem = null;
1012
- this.positionInfo = null;
1013
1009
  }
1014
1010
  _createClass(DragAndDropHandler, [{
1015
1011
  key: "mouseCapture",
@@ -1044,7 +1040,6 @@ var jqtree = (function (exports) {
1044
1040
  var node = this.currentItem.node;
1045
1041
  this.dragElement = new DragElement(node.name, positionInfo.pageX - left, positionInfo.pageY - top, this.treeWidget.element, (_this$treeWidget$opti = this.treeWidget.options.autoEscape) !== null && _this$treeWidget$opti !== void 0 ? _this$treeWidget$opti : true);
1046
1042
  this.isDragging = true;
1047
- this.positionInfo = positionInfo;
1048
1043
  this.currentItem.$element.addClass("jqtree-moving");
1049
1044
  return true;
1050
1045
  }
@@ -1055,7 +1050,6 @@ var jqtree = (function (exports) {
1055
1050
  return false;
1056
1051
  }
1057
1052
  this.dragElement.move(positionInfo.pageX, positionInfo.pageY);
1058
- this.positionInfo = positionInfo;
1059
1053
  var area = this.findHoveredArea(positionInfo.pageX, positionInfo.pageY);
1060
1054
  if (area && this.canMoveToArea(area)) {
1061
1055
  if (!area.node.isFolder()) {
@@ -1098,7 +1092,6 @@ var jqtree = (function (exports) {
1098
1092
  this.currentItem = null;
1099
1093
  }
1100
1094
  this.isDragging = false;
1101
- this.positionInfo = null;
1102
1095
  if (!this.hoveredArea && currentItem) {
1103
1096
  if (this.treeWidget.options.onDragStop) {
1104
1097
  this.treeWidget.options.onDragStop(currentItem.node, positionInfo.originalEvent);
@@ -1384,7 +1377,8 @@ var jqtree = (function (exports) {
1384
1377
  }, {
1385
1378
  key: "generateHitAreas",
1386
1379
  value: function generateHitAreas(positions) {
1387
- var previousTop = -1;
1380
+ var _positions$0$top, _positions$;
1381
+ var previousTop = (_positions$0$top = (_positions$ = positions[0]) === null || _positions$ === void 0 ? void 0 : _positions$.top) !== null && _positions$0$top !== void 0 ? _positions$0$top : 0;
1388
1382
  var group = [];
1389
1383
  var hitAreas = [];
1390
1384
  var _iterator = _createForOfIteratorHelper(positions),
@@ -1393,9 +1387,7 @@ var jqtree = (function (exports) {
1393
1387
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
1394
1388
  var position = _step.value;
1395
1389
  if (position.top !== previousTop && group.length) {
1396
- if (group.length) {
1397
- this.generateHitAreasForGroup(hitAreas, group, previousTop, position.top);
1398
- }
1390
+ this.generateHitAreasForGroup(hitAreas, group, previousTop, position.top);
1399
1391
  previousTop = position.top;
1400
1392
  group = [];
1401
1393
  }
@@ -2016,9 +2008,6 @@ var jqtree = (function (exports) {
2016
2008
  return true;
2017
2009
  } else {
2018
2010
  this.treeWidget.selectNode(node);
2019
- if (!this.treeWidget.scrollHandler.isScrolledIntoView(jQuery(node.element).find(".jqtree-element"))) {
2020
- this.treeWidget.scrollToNode(node);
2021
- }
2022
2011
  return false;
2023
2012
  }
2024
2013
  }
@@ -2668,235 +2657,408 @@ var jqtree = (function (exports) {
2668
2657
  return SaveStateHandler;
2669
2658
  }();
2670
2659
 
2671
- var ScrollHandler = /*#__PURE__*/function () {
2672
- function ScrollHandler(treeWidget) {
2673
- _classCallCheck(this, ScrollHandler);
2674
- _defineProperty(this, "treeWidget", void 0);
2675
- _defineProperty(this, "previousTop", void 0);
2676
- _defineProperty(this, "isInitialized", void 0);
2677
- _defineProperty(this, "$scrollParent", void 0);
2660
+ var ContainerScrollParent = /*#__PURE__*/function () {
2661
+ function ContainerScrollParent(_ref) {
2662
+ var $container = _ref.$container,
2663
+ refreshHitAreas = _ref.refreshHitAreas;
2664
+ _classCallCheck(this, ContainerScrollParent);
2665
+ _defineProperty(this, "$container", void 0);
2666
+ _defineProperty(this, "horizontalScrollDirection", void 0);
2667
+ _defineProperty(this, "horizontalScrollTimeout", void 0);
2668
+ _defineProperty(this, "refreshHitAreas", void 0);
2669
+ _defineProperty(this, "scrollParentBottom", void 0);
2678
2670
  _defineProperty(this, "scrollParentTop", void 0);
2679
- this.treeWidget = treeWidget;
2680
- this.previousTop = -1;
2681
- this.isInitialized = false;
2671
+ _defineProperty(this, "verticalScrollTimeout", void 0);
2672
+ _defineProperty(this, "verticalScrollDirection", void 0);
2673
+ this.$container = $container;
2674
+ this.refreshHitAreas = refreshHitAreas;
2682
2675
  }
2683
- _createClass(ScrollHandler, [{
2684
- key: "checkScrolling",
2685
- value: function checkScrolling() {
2686
- this.ensureInit();
2687
- this.checkVerticalScrolling();
2688
- this.checkHorizontalScrolling();
2676
+ _createClass(ContainerScrollParent, [{
2677
+ key: "checkHorizontalScrolling",
2678
+ value: function checkHorizontalScrolling(pageX) {
2679
+ var newHorizontalScrollDirection = this.getNewHorizontalScrollDirection(pageX);
2680
+ if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
2681
+ this.horizontalScrollDirection = newHorizontalScrollDirection;
2682
+ if (this.horizontalScrollTimeout != null) {
2683
+ window.clearTimeout(this.verticalScrollTimeout);
2684
+ }
2685
+ if (newHorizontalScrollDirection) {
2686
+ this.horizontalScrollTimeout = window.setTimeout(this.scrollHorizontally.bind(this), 40);
2687
+ }
2688
+ }
2689
2689
  }
2690
2690
  }, {
2691
- key: "scrollToY",
2692
- value: function scrollToY(top) {
2693
- this.ensureInit();
2694
- if (this.$scrollParent && this.$scrollParent[0]) {
2695
- this.$scrollParent[0].scrollTop = top;
2696
- } else {
2697
- var offset = this.treeWidget.$el.offset();
2698
- var treeTop = offset ? offset.top : 0;
2699
- jQuery(document).scrollTop(top + treeTop);
2700
- }
2701
- }
2702
- }, {
2703
- key: "isScrolledIntoView",
2704
- value: function isScrolledIntoView($element) {
2705
- this.ensureInit();
2706
- var elementBottom;
2707
- var viewBottom;
2708
- var elementTop;
2709
- var viewTop;
2710
- var elHeight = $element.height() || 0;
2711
- if (this.$scrollParent) {
2712
- viewTop = 0;
2713
- viewBottom = this.$scrollParent.height() || 0;
2714
- var offset = $element.offset();
2715
- var originalTop = offset ? offset.top : 0;
2716
- elementTop = originalTop - this.scrollParentTop;
2717
- elementBottom = elementTop + elHeight;
2718
- } else {
2719
- viewTop = jQuery(window).scrollTop() || 0;
2720
- var windowHeight = jQuery(window).height() || 0;
2721
- viewBottom = viewTop + windowHeight;
2722
- var _offset = $element.offset();
2723
- elementTop = _offset ? _offset.top : 0;
2724
- elementBottom = elementTop + elHeight;
2691
+ key: "checkVerticalScrolling",
2692
+ value: function checkVerticalScrolling(pageY) {
2693
+ var newVerticalScrollDirection = this.getNewVerticalScrollDirection(pageY);
2694
+ if (this.verticalScrollDirection !== newVerticalScrollDirection) {
2695
+ this.verticalScrollDirection = newVerticalScrollDirection;
2696
+ if (this.verticalScrollTimeout != null) {
2697
+ window.clearTimeout(this.verticalScrollTimeout);
2698
+ this.verticalScrollTimeout = undefined;
2699
+ }
2700
+ if (newVerticalScrollDirection) {
2701
+ this.verticalScrollTimeout = window.setTimeout(this.scrollVertically.bind(this), 40);
2702
+ }
2725
2703
  }
2726
- return elementBottom <= viewBottom && elementTop >= viewTop;
2727
2704
  }
2728
2705
  }, {
2729
2706
  key: "getScrollLeft",
2730
2707
  value: function getScrollLeft() {
2731
- if (!this.$scrollParent) {
2732
- return 0;
2733
- } else {
2734
- return this.$scrollParent.scrollLeft() || 0;
2708
+ return this.$container.scrollLeft() || 0;
2709
+ }
2710
+ }, {
2711
+ key: "scrollToY",
2712
+ value: function scrollToY(top) {
2713
+ var container = this.$container.get(0);
2714
+ container.scrollTop = top;
2715
+ }
2716
+ }, {
2717
+ key: "stopScrolling",
2718
+ value: function stopScrolling() {
2719
+ this.horizontalScrollDirection = undefined;
2720
+ this.verticalScrollDirection = undefined;
2721
+ this.scrollParentTop = undefined;
2722
+ this.scrollParentBottom = undefined;
2723
+ }
2724
+ }, {
2725
+ key: "getNewHorizontalScrollDirection",
2726
+ value: function getNewHorizontalScrollDirection(pageX) {
2727
+ var scrollParentOffset = this.$container.offset();
2728
+ if (!scrollParentOffset) {
2729
+ return undefined;
2730
+ }
2731
+ var container = this.$container.get(0);
2732
+ var rightEdge = scrollParentOffset.left + container.clientWidth;
2733
+ var leftEdge = scrollParentOffset.left;
2734
+ var isNearRightEdge = pageX > rightEdge - 20;
2735
+ var isNearLeftEdge = pageX < leftEdge + 20;
2736
+ if (isNearRightEdge) {
2737
+ return "right";
2738
+ } else if (isNearLeftEdge) {
2739
+ return "left";
2735
2740
  }
2741
+ return undefined;
2736
2742
  }
2737
2743
  }, {
2738
- key: "initScrollParent",
2739
- value: function initScrollParent() {
2740
- var _this = this,
2741
- _$scrollParent$;
2742
- var getParentWithOverflow = function getParentWithOverflow() {
2743
- var cssAttributes = ["overflow", "overflow-y"];
2744
- var hasOverFlow = function hasOverFlow($el) {
2745
- for (var _i = 0, _cssAttributes = cssAttributes; _i < _cssAttributes.length; _i++) {
2746
- var attr = _cssAttributes[_i];
2747
- var overflowValue = $el.css(attr);
2748
- if (overflowValue === "auto" || overflowValue === "scroll") {
2749
- return true;
2750
- }
2751
- }
2752
- return false;
2753
- };
2754
- if (hasOverFlow(_this.treeWidget.$el)) {
2755
- return _this.treeWidget.$el;
2756
- }
2757
- var _iterator = _createForOfIteratorHelper(_this.treeWidget.$el.parents().get()),
2758
- _step;
2759
- try {
2760
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2761
- var el = _step.value;
2762
- var $el = jQuery(el);
2763
- if (hasOverFlow($el)) {
2764
- return $el;
2765
- }
2766
- }
2767
- } catch (err) {
2768
- _iterator.e(err);
2769
- } finally {
2770
- _iterator.f();
2771
- }
2772
- return null;
2773
- };
2774
- var setDocumentAsScrollParent = function setDocumentAsScrollParent() {
2775
- _this.scrollParentTop = 0;
2776
- _this.$scrollParent = null;
2777
- };
2778
- if (this.treeWidget.$el.css("position") === "fixed") {
2779
- setDocumentAsScrollParent();
2780
- }
2781
- var $scrollParent = getParentWithOverflow();
2782
- if ($scrollParent && $scrollParent.length && ((_$scrollParent$ = $scrollParent[0]) === null || _$scrollParent$ === void 0 ? void 0 : _$scrollParent$.tagName) !== "HTML") {
2783
- this.$scrollParent = $scrollParent;
2784
- var offset = this.$scrollParent.offset();
2785
- this.scrollParentTop = offset ? offset.top : 0;
2786
- } else {
2787
- setDocumentAsScrollParent();
2744
+ key: "getNewVerticalScrollDirection",
2745
+ value: function getNewVerticalScrollDirection(pageY) {
2746
+ if (pageY < this.getScrollParentTop()) {
2747
+ return "top";
2748
+ }
2749
+ if (pageY > this.getScrollParentBottom()) {
2750
+ return "bottom";
2788
2751
  }
2789
- this.isInitialized = true;
2752
+ return undefined;
2790
2753
  }
2791
2754
  }, {
2792
- key: "ensureInit",
2793
- value: function ensureInit() {
2794
- if (!this.isInitialized) {
2795
- this.initScrollParent();
2755
+ key: "scrollHorizontally",
2756
+ value: function scrollHorizontally() {
2757
+ if (!this.horizontalScrollDirection) {
2758
+ return;
2796
2759
  }
2760
+ var distance = this.horizontalScrollDirection === "left" ? -20 : 20;
2761
+ var container = this.$container.get(0);
2762
+ container.scrollBy({
2763
+ left: distance,
2764
+ top: 0,
2765
+ behavior: "instant"
2766
+ });
2767
+ this.refreshHitAreas();
2768
+ setTimeout(this.scrollHorizontally.bind(this), 40);
2797
2769
  }
2798
2770
  }, {
2799
- key: "handleVerticalScrollingWithScrollParent",
2800
- value: function handleVerticalScrollingWithScrollParent(area) {
2801
- var scrollParent = this.$scrollParent && this.$scrollParent[0];
2802
- if (!scrollParent) {
2771
+ key: "scrollVertically",
2772
+ value: function scrollVertically() {
2773
+ if (!this.verticalScrollDirection) {
2803
2774
  return;
2804
2775
  }
2805
- var distanceBottom = this.scrollParentTop + scrollParent.offsetHeight - area.bottom;
2806
- if (distanceBottom < 20) {
2807
- scrollParent.scrollTop += 20;
2808
- this.treeWidget.refreshHitAreas();
2809
- this.previousTop = -1;
2810
- } else if (area.top - this.scrollParentTop < 20) {
2811
- scrollParent.scrollTop -= 20;
2812
- this.treeWidget.refreshHitAreas();
2813
- this.previousTop = -1;
2776
+ var distance = this.verticalScrollDirection === "top" ? -20 : 20;
2777
+ var container = this.$container.get(0);
2778
+ container.scrollBy({
2779
+ left: 0,
2780
+ top: distance,
2781
+ behavior: "instant"
2782
+ });
2783
+ this.refreshHitAreas();
2784
+ setTimeout(this.scrollVertically.bind(this), 40);
2785
+ }
2786
+ }, {
2787
+ key: "getScrollParentTop",
2788
+ value: function getScrollParentTop() {
2789
+ if (this.scrollParentTop == null) {
2790
+ var _this$$container$offs;
2791
+ this.scrollParentTop = ((_this$$container$offs = this.$container.offset()) === null || _this$$container$offs === void 0 ? void 0 : _this$$container$offs.top) || 0;
2814
2792
  }
2793
+ return this.scrollParentTop;
2815
2794
  }
2816
2795
  }, {
2817
- key: "handleVerticalScrollingWithDocument",
2818
- value: function handleVerticalScrollingWithDocument(area) {
2819
- var scrollTop = jQuery(document).scrollTop() || 0;
2820
- var distanceTop = area.top - scrollTop;
2821
- if (distanceTop < 20) {
2822
- jQuery(document).scrollTop(scrollTop - 20);
2823
- } else {
2824
- var windowHeight = jQuery(window).height() || 0;
2825
- if (windowHeight - (area.bottom - scrollTop) < 20) {
2826
- jQuery(document).scrollTop(scrollTop + 20);
2796
+ key: "getScrollParentBottom",
2797
+ value: function getScrollParentBottom() {
2798
+ if (this.scrollParentBottom == null) {
2799
+ var _this$$container$inne;
2800
+ this.scrollParentBottom = this.getScrollParentTop() + ((_this$$container$inne = this.$container.innerHeight()) !== null && _this$$container$inne !== void 0 ? _this$$container$inne : 0);
2801
+ }
2802
+ return this.scrollParentBottom;
2803
+ }
2804
+ }]);
2805
+ return ContainerScrollParent;
2806
+ }();
2807
+
2808
+ var DocumentScrollParent = /*#__PURE__*/function () {
2809
+ function DocumentScrollParent($element, refreshHitAreas) {
2810
+ _classCallCheck(this, DocumentScrollParent);
2811
+ _defineProperty(this, "$element", void 0);
2812
+ _defineProperty(this, "horizontalScrollDirection", void 0);
2813
+ _defineProperty(this, "horizontalScrollTimeout", void 0);
2814
+ _defineProperty(this, "refreshHitAreas", void 0);
2815
+ _defineProperty(this, "verticalScrollDirection", void 0);
2816
+ _defineProperty(this, "verticalScrollTimeout", void 0);
2817
+ _defineProperty(this, "documentScrollHeight", void 0);
2818
+ _defineProperty(this, "documentScrollWidth", void 0);
2819
+ this.$element = $element;
2820
+ this.refreshHitAreas = refreshHitAreas;
2821
+ }
2822
+ _createClass(DocumentScrollParent, [{
2823
+ key: "checkHorizontalScrolling",
2824
+ value: function checkHorizontalScrolling(pageX) {
2825
+ var newHorizontalScrollDirection = this.getNewHorizontalScrollDirection(pageX);
2826
+ if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
2827
+ this.horizontalScrollDirection = newHorizontalScrollDirection;
2828
+ if (this.horizontalScrollTimeout != null) {
2829
+ window.clearTimeout(this.horizontalScrollTimeout);
2830
+ }
2831
+ if (newHorizontalScrollDirection) {
2832
+ this.horizontalScrollTimeout = window.setTimeout(this.scrollHorizontally.bind(this), 40);
2827
2833
  }
2828
2834
  }
2829
2835
  }
2830
2836
  }, {
2831
2837
  key: "checkVerticalScrolling",
2832
- value: function checkVerticalScrolling() {
2833
- var hoveredArea = this.treeWidget.dndHandler.hoveredArea;
2834
- if (hoveredArea && hoveredArea.top !== this.previousTop) {
2835
- this.previousTop = hoveredArea.top;
2836
- if (this.$scrollParent) {
2837
- this.handleVerticalScrollingWithScrollParent(hoveredArea);
2838
- } else {
2839
- this.handleVerticalScrollingWithDocument(hoveredArea);
2838
+ value: function checkVerticalScrolling(pageY) {
2839
+ var newVerticalScrollDirection = this.getNewVerticalScrollDirection(pageY);
2840
+ if (this.verticalScrollDirection !== newVerticalScrollDirection) {
2841
+ this.verticalScrollDirection = newVerticalScrollDirection;
2842
+ if (this.verticalScrollTimeout != null) {
2843
+ window.clearTimeout(this.verticalScrollTimeout);
2844
+ this.verticalScrollTimeout = undefined;
2845
+ }
2846
+ if (newVerticalScrollDirection) {
2847
+ this.verticalScrollTimeout = window.setTimeout(this.scrollVertically.bind(this), 40);
2840
2848
  }
2841
2849
  }
2842
2850
  }
2843
2851
  }, {
2844
- key: "checkHorizontalScrolling",
2845
- value: function checkHorizontalScrolling() {
2846
- var positionInfo = this.treeWidget.dndHandler.positionInfo;
2847
- if (!positionInfo) {
2848
- return;
2852
+ key: "getScrollLeft",
2853
+ value: function getScrollLeft() {
2854
+ return document.documentElement.scrollLeft;
2855
+ }
2856
+ }, {
2857
+ key: "scrollToY",
2858
+ value: function scrollToY(top) {
2859
+ var offset = this.$element.offset();
2860
+ var treeTop = offset ? offset.top : 0;
2861
+ jQuery(document).scrollTop(top + treeTop);
2862
+ }
2863
+ }, {
2864
+ key: "stopScrolling",
2865
+ value: function stopScrolling() {
2866
+ this.horizontalScrollDirection = undefined;
2867
+ this.verticalScrollDirection = undefined;
2868
+ this.documentScrollHeight = undefined;
2869
+ this.documentScrollWidth = undefined;
2870
+ }
2871
+ }, {
2872
+ key: "getNewHorizontalScrollDirection",
2873
+ value: function getNewHorizontalScrollDirection(pageX) {
2874
+ var $document = jQuery(document);
2875
+ var scrollLeft = $document.scrollLeft() || 0;
2876
+ var windowWidth = jQuery(window).width() || 0;
2877
+ var isNearRightEdge = pageX > windowWidth - 20;
2878
+ var isNearLeftEdge = pageX - scrollLeft < 20;
2879
+ if (isNearRightEdge && this.canScrollRight()) {
2880
+ return "right";
2849
2881
  }
2850
- if (this.$scrollParent) {
2851
- this.handleHorizontalScrollingWithParent(positionInfo);
2852
- } else {
2853
- this.handleHorizontalScrollingWithDocument(positionInfo);
2882
+ if (isNearLeftEdge) {
2883
+ return "left";
2854
2884
  }
2885
+ return undefined;
2855
2886
  }
2856
2887
  }, {
2857
- key: "handleHorizontalScrollingWithParent",
2858
- value: function handleHorizontalScrollingWithParent(positionInfo) {
2859
- if (positionInfo.pageX === undefined || positionInfo.pageY === undefined) {
2860
- return;
2888
+ key: "canScrollRight",
2889
+ value: function canScrollRight() {
2890
+ var documentElement = document.documentElement;
2891
+ return documentElement.scrollLeft + documentElement.clientWidth < this.getDocumentScrollWidth();
2892
+ }
2893
+ }, {
2894
+ key: "canScrollDown",
2895
+ value: function canScrollDown() {
2896
+ var documentElement = document.documentElement;
2897
+ return documentElement.scrollTop + documentElement.clientHeight < this.getDocumentScrollHeight();
2898
+ }
2899
+ }, {
2900
+ key: "getDocumentScrollHeight",
2901
+ value: function getDocumentScrollHeight() {
2902
+ // Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
2903
+ if (this.documentScrollHeight == null) {
2904
+ this.documentScrollHeight = document.documentElement.scrollHeight;
2905
+ }
2906
+ return this.documentScrollHeight;
2907
+ }
2908
+ }, {
2909
+ key: "getDocumentScrollWidth",
2910
+ value: function getDocumentScrollWidth() {
2911
+ // Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
2912
+ if (this.documentScrollWidth == null) {
2913
+ this.documentScrollWidth = document.documentElement.scrollWidth;
2861
2914
  }
2862
- var $scrollParent = this.$scrollParent;
2863
- var scrollParentOffset = $scrollParent && $scrollParent.offset();
2864
- if (!($scrollParent && scrollParentOffset)) {
2915
+ return this.documentScrollWidth;
2916
+ }
2917
+ }, {
2918
+ key: "getNewVerticalScrollDirection",
2919
+ value: function getNewVerticalScrollDirection(pageY) {
2920
+ var scrollTop = jQuery(document).scrollTop() || 0;
2921
+ var distanceTop = pageY - scrollTop;
2922
+ if (distanceTop < 20) {
2923
+ return "top";
2924
+ }
2925
+ var windowHeight = jQuery(window).height() || 0;
2926
+ if (windowHeight - (pageY - scrollTop) < 20 && this.canScrollDown()) {
2927
+ return "bottom";
2928
+ }
2929
+ return undefined;
2930
+ }
2931
+ }, {
2932
+ key: "scrollHorizontally",
2933
+ value: function scrollHorizontally() {
2934
+ if (!this.horizontalScrollDirection) {
2865
2935
  return;
2866
2936
  }
2867
- var scrollParent = $scrollParent[0];
2868
- if (!scrollParent) {
2937
+ var distance = this.horizontalScrollDirection === "left" ? -20 : 20;
2938
+ window.scrollBy({
2939
+ left: distance,
2940
+ top: 0,
2941
+ behavior: "instant"
2942
+ });
2943
+ this.refreshHitAreas();
2944
+ setTimeout(this.scrollHorizontally.bind(this), 40);
2945
+ }
2946
+ }, {
2947
+ key: "scrollVertically",
2948
+ value: function scrollVertically() {
2949
+ if (!this.verticalScrollDirection) {
2869
2950
  return;
2870
2951
  }
2871
- var canScrollRight = scrollParent.scrollLeft + scrollParent.clientWidth < scrollParent.scrollWidth;
2872
- var canScrollLeft = scrollParent.scrollLeft > 0;
2873
- var rightEdge = scrollParentOffset.left + scrollParent.clientWidth;
2874
- var leftEdge = scrollParentOffset.left;
2875
- var isNearRightEdge = positionInfo.pageX > rightEdge - 20;
2876
- var isNearLeftEdge = positionInfo.pageX < leftEdge + 20;
2877
- if (isNearRightEdge && canScrollRight) {
2878
- scrollParent.scrollLeft = Math.min(scrollParent.scrollLeft + 20, scrollParent.scrollWidth);
2879
- } else if (isNearLeftEdge && canScrollLeft) {
2880
- scrollParent.scrollLeft = Math.max(scrollParent.scrollLeft - 20, 0);
2952
+ var distance = this.verticalScrollDirection === "top" ? -20 : 20;
2953
+ window.scrollBy({
2954
+ left: 0,
2955
+ top: distance,
2956
+ behavior: "instant"
2957
+ });
2958
+ this.refreshHitAreas();
2959
+ setTimeout(this.scrollVertically.bind(this), 40);
2960
+ }
2961
+ }]);
2962
+ return DocumentScrollParent;
2963
+ }();
2964
+
2965
+ var hasOverFlow = function hasOverFlow($element) {
2966
+ for (var _i = 0, _arr = ["overflow", "overflow-y"]; _i < _arr.length; _i++) {
2967
+ var attr = _arr[_i];
2968
+ var overflowValue = $element.css(attr);
2969
+ if (overflowValue === "auto" || overflowValue === "scroll") {
2970
+ return true;
2971
+ }
2972
+ }
2973
+ return false;
2974
+ };
2975
+ var getParentWithOverflow = function getParentWithOverflow($treeElement) {
2976
+ if (hasOverFlow($treeElement)) {
2977
+ return $treeElement;
2978
+ }
2979
+ var _iterator = _createForOfIteratorHelper($treeElement.parents().get()),
2980
+ _step;
2981
+ try {
2982
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2983
+ var element = _step.value;
2984
+ var $element = jQuery(element);
2985
+ if (hasOverFlow($element)) {
2986
+ return $element;
2987
+ }
2988
+ }
2989
+ } catch (err) {
2990
+ _iterator.e(err);
2991
+ } finally {
2992
+ _iterator.f();
2993
+ }
2994
+ return null;
2995
+ };
2996
+ var createScrollParent = function createScrollParent($treeElement, refreshHitAreas) {
2997
+ var _$container$;
2998
+ var $container = getParentWithOverflow($treeElement);
2999
+ if ($container !== null && $container !== void 0 && $container.length && ((_$container$ = $container[0]) === null || _$container$ === void 0 ? void 0 : _$container$.tagName) !== "HTML") {
3000
+ return new ContainerScrollParent({
3001
+ $container: $container,
3002
+ refreshHitAreas: refreshHitAreas,
3003
+ $treeElement: $treeElement
3004
+ });
3005
+ } else {
3006
+ return new DocumentScrollParent($treeElement, refreshHitAreas);
3007
+ }
3008
+ };
3009
+
3010
+ var ScrollHandler = /*#__PURE__*/function () {
3011
+ function ScrollHandler(treeWidget) {
3012
+ _classCallCheck(this, ScrollHandler);
3013
+ _defineProperty(this, "treeWidget", void 0);
3014
+ _defineProperty(this, "scrollParent", void 0);
3015
+ this.treeWidget = treeWidget;
3016
+ this.scrollParent = undefined;
3017
+ }
3018
+ _createClass(ScrollHandler, [{
3019
+ key: "checkScrolling",
3020
+ value: function checkScrolling(positionInfo) {
3021
+ this.checkVerticalScrolling(positionInfo);
3022
+ this.checkHorizontalScrolling(positionInfo);
3023
+ }
3024
+ }, {
3025
+ key: "stopScrolling",
3026
+ value: function stopScrolling() {
3027
+ this.getScrollParent().stopScrolling();
3028
+ }
3029
+ }, {
3030
+ key: "scrollToY",
3031
+ value: function scrollToY(top) {
3032
+ this.getScrollParent().scrollToY(top);
3033
+ }
3034
+ }, {
3035
+ key: "getScrollLeft",
3036
+ value: function getScrollLeft() {
3037
+ return this.getScrollParent().getScrollLeft();
3038
+ }
3039
+ }, {
3040
+ key: "checkVerticalScrolling",
3041
+ value: function checkVerticalScrolling(positionInfo) {
3042
+ if (positionInfo.pageY == null) {
3043
+ return;
2881
3044
  }
3045
+ this.getScrollParent().checkVerticalScrolling(positionInfo.pageY);
2882
3046
  }
2883
3047
  }, {
2884
- key: "handleHorizontalScrollingWithDocument",
2885
- value: function handleHorizontalScrollingWithDocument(positionInfo) {
2886
- if (positionInfo.pageX === undefined || positionInfo.pageY === undefined) {
3048
+ key: "checkHorizontalScrolling",
3049
+ value: function checkHorizontalScrolling(positionInfo) {
3050
+ if (positionInfo.pageX == null) {
2887
3051
  return;
2888
3052
  }
2889
- var $document = jQuery(document);
2890
- var scrollLeft = $document.scrollLeft() || 0;
2891
- var windowWidth = jQuery(window).width() || 0;
2892
- var canScrollLeft = scrollLeft > 0;
2893
- var isNearRightEdge = positionInfo.pageX > windowWidth - 20;
2894
- var isNearLeftEdge = positionInfo.pageX - scrollLeft < 20;
2895
- if (isNearRightEdge) {
2896
- $document.scrollLeft(scrollLeft + 20);
2897
- } else if (isNearLeftEdge && canScrollLeft) {
2898
- $document.scrollLeft(Math.max(scrollLeft - 20, 0));
3053
+ this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
3054
+ }
3055
+ }, {
3056
+ key: "getScrollParent",
3057
+ value: function getScrollParent() {
3058
+ if (!this.scrollParent) {
3059
+ this.scrollParent = createScrollParent(this.treeWidget.$el, this.treeWidget.refreshHitAreas.bind(this.treeWidget));
2899
3060
  }
3061
+ return this.scrollParent;
2900
3062
  }
2901
3063
  }]);
2902
3064
  return ScrollHandler;
@@ -3661,13 +3823,12 @@ var jqtree = (function (exports) {
3661
3823
  }, {
3662
3824
  key: "scrollToNode",
3663
3825
  value: function scrollToNode(node) {
3826
+ var _jQuery$offset$top, _jQuery$offset, _this$$el$offset$top, _this$$el$offset;
3664
3827
  if (!node) {
3665
3828
  throw Error(NODE_PARAM_IS_EMPTY);
3666
3829
  }
3667
- var nodeOffset = jQuery(node.element).offset();
3668
- var nodeTop = nodeOffset ? nodeOffset.top : 0;
3669
- var treeOffset = this.$el.offset();
3670
- var treeTop = treeOffset ? treeOffset.top : 0;
3830
+ var nodeTop = (_jQuery$offset$top = (_jQuery$offset = jQuery(node.element).offset()) === null || _jQuery$offset === void 0 ? void 0 : _jQuery$offset.top) !== null && _jQuery$offset$top !== void 0 ? _jQuery$offset$top : 0;
3831
+ var treeTop = (_this$$el$offset$top = (_this$$el$offset = this.$el.offset()) === null || _this$$el$offset === void 0 ? void 0 : _this$$el$offset.top) !== null && _this$$el$offset$top !== void 0 ? _this$$el$offset$top : 0;
3671
3832
  var top = nodeTop - treeTop;
3672
3833
  this.scrollHandler.scrollToY(top);
3673
3834
  return this.element;
@@ -3849,7 +4010,7 @@ var jqtree = (function (exports) {
3849
4010
  value: function mouseDrag(positionInfo) {
3850
4011
  if (this.options.dragAndDrop) {
3851
4012
  var result = this.dndHandler.mouseDrag(positionInfo);
3852
- this.scrollHandler.checkScrolling();
4013
+ this.scrollHandler.checkScrolling(positionInfo);
3853
4014
  return result;
3854
4015
  } else {
3855
4016
  return false;
@@ -3859,6 +4020,7 @@ var jqtree = (function (exports) {
3859
4020
  key: "mouseStop",
3860
4021
  value: function mouseStop(positionInfo) {
3861
4022
  if (this.options.dragAndDrop) {
4023
+ this.scrollHandler.stopScrolling();
3862
4024
  return this.dndHandler.mouseStop(positionInfo);
3863
4025
  } else {
3864
4026
  return false;