Skip to content

Commit 84e6053

Browse files
committed
2.2.7 Temporarily fix overlapping tree issue
1 parent 83924cf commit 84e6053

6 files changed

+255
-158
lines changed

dist/vue-draggable-nested-tree.cjs.js

+44-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-draggable-nested-tree v2.2.6
2+
* vue-draggable-nested-tree v2.2.7
33
* (c) 2018-present phphe <phphe@outlook.com>
44
* Released under the MIT License.
55
*/
@@ -498,6 +498,45 @@ function attachCache(obj, cache, toCache) {
498498
}
499499
}
500500

501+
// from https://gist.github.com/iddan/54d5d9e58311b0495a91bf06de661380
502+
503+
if (!document.elementsFromPoint) {
504+
document.elementsFromPoint = elementsFromPoint;
505+
}
506+
507+
function elementsFromPoint(x, y) {
508+
var parents = [];
509+
var parent = void 0;
510+
511+
do {
512+
if (parent !== document.elementFromPoint(x, y)) {
513+
parent = document.elementFromPoint(x, y);
514+
parents.push(parent);
515+
parent.style.pointerEvents = 'none';
516+
} else {
517+
parent = false;
518+
}
519+
} while (parent);
520+
521+
parents.forEach(function (parent) {
522+
return parent.style.pointerEvents = 'all';
523+
});
524+
return parents;
525+
}
526+
527+
function getTreeByPoint(x, y, trees) {
528+
var els = document.elementsFromPoint(x, y);
529+
var treeEL = els.find(function (el) {
530+
return hp.hasClass(el, 'tree');
531+
});
532+
533+
if (treeEL) {
534+
return trees.find(function (v) {
535+
return v.$el === treeEL;
536+
});
537+
}
538+
}
539+
501540
// 对 drag placeholder进行的操作
502541

503542
var targets = {
@@ -775,11 +814,8 @@ function autoMoveDragPlaceHolder(draggableHelperInfo) {
775814
// right bottom point
776815
// tree
777816
currentTree: function currentTree() {
778-
var _this = this;
779-
780-
var currentTree = trees.find(function (tree) {
781-
return hp.isOffsetInEl(_this.offset.x, _this.offset.y, tree.$el);
782-
});
817+
// const currentTree = trees.find(tree => hp.isOffsetInEl(this.offset.x, this.offset.y, tree.$el))
818+
var currentTree = getTreeByPoint(this.offset.x, this.offset.y, trees);
783819

784820
if (currentTree) {
785821
var dragStartTree = this.store;
@@ -811,10 +847,10 @@ function autoMoveDragPlaceHolder(draggableHelperInfo) {
811847
},
812848
// the second child of currentTree root, excluding dragging node
813849
currentTreeRootSecondChildExcludingDragging: function currentTreeRootSecondChildExcludingDragging() {
814-
var _this2 = this;
850+
var _this = this;
815851

816852
return this.currentTree.rootData.children.slice(0, 3).filter(function (v) {
817-
return v !== _this2.node;
853+
return v !== _this.node;
818854
})[1];
819855
},
820856
// placeholder

dist/vue-draggable-nested-tree.es.js

+45-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-draggable-nested-tree v2.2.6
2+
* vue-draggable-nested-tree v2.2.7
33
* (c) 2018-present phphe <phphe@outlook.com>
44
* Released under the MIT License.
55
*/
@@ -8,7 +8,7 @@ import assign from 'core-js/library/fn/object/assign';
88
import { breadthFirstSearch, insertAfter, insertBefore, appendTo, prependTo } from 'tree-helper';
99
import 'core-js/modules/web.dom.iterable';
1010
import 'core-js/modules/es6.number.constructor';
11-
import { strRand, arrayRemove, getOffset, isOffsetInEl, binarySearch, hasClass } from 'helper-js';
11+
import { strRand, arrayRemove, getOffset, binarySearch, hasClass } from 'helper-js';
1212
import defineProperty from 'core-js/library/fn/object/define-property';
1313
import 'core-js/modules/es6.function.name';
1414
import 'core-js/modules/es6.array.find';
@@ -492,6 +492,45 @@ function attachCache(obj, cache, toCache) {
492492
}
493493
}
494494

495+
// from https://gist.github.com/iddan/54d5d9e58311b0495a91bf06de661380
496+
497+
if (!document.elementsFromPoint) {
498+
document.elementsFromPoint = elementsFromPoint;
499+
}
500+
501+
function elementsFromPoint(x, y) {
502+
var parents = [];
503+
var parent = void 0;
504+
505+
do {
506+
if (parent !== document.elementFromPoint(x, y)) {
507+
parent = document.elementFromPoint(x, y);
508+
parents.push(parent);
509+
parent.style.pointerEvents = 'none';
510+
} else {
511+
parent = false;
512+
}
513+
} while (parent);
514+
515+
parents.forEach(function (parent) {
516+
return parent.style.pointerEvents = 'all';
517+
});
518+
return parents;
519+
}
520+
521+
function getTreeByPoint(x, y, trees) {
522+
var els = document.elementsFromPoint(x, y);
523+
var treeEL = els.find(function (el) {
524+
return hasClass(el, 'tree');
525+
});
526+
527+
if (treeEL) {
528+
return trees.find(function (v) {
529+
return v.$el === treeEL;
530+
});
531+
}
532+
}
533+
495534
// 对 drag placeholder进行的操作
496535

497536
var targets = {
@@ -769,11 +808,8 @@ function autoMoveDragPlaceHolder(draggableHelperInfo) {
769808
// right bottom point
770809
// tree
771810
currentTree: function currentTree() {
772-
var _this = this;
773-
774-
var currentTree = trees.find(function (tree) {
775-
return isOffsetInEl(_this.offset.x, _this.offset.y, tree.$el);
776-
});
811+
// const currentTree = trees.find(tree => hp.isOffsetInEl(this.offset.x, this.offset.y, tree.$el))
812+
var currentTree = getTreeByPoint(this.offset.x, this.offset.y, trees);
777813

778814
if (currentTree) {
779815
var dragStartTree = this.store;
@@ -805,10 +841,10 @@ function autoMoveDragPlaceHolder(draggableHelperInfo) {
805841
},
806842
// the second child of currentTree root, excluding dragging node
807843
currentTreeRootSecondChildExcludingDragging: function currentTreeRootSecondChildExcludingDragging() {
808-
var _this2 = this;
844+
var _this = this;
809845

810846
return this.currentTree.rootData.children.slice(0, 3).filter(function (v) {
811-
return v !== _this2.node;
847+
return v !== _this.node;
812848
})[1];
813849
},
814850
// placeholder

0 commit comments

Comments
 (0)