-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathvue-draggable-nested-tree.cjs.js
1605 lines (1403 loc) · 48.9 KB
/
vue-draggable-nested-tree.cjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* vue-draggable-nested-tree v2.3.0-beta.1
* (c) 2018-present phphe <phphe@outlook.com>
* Released under the MIT License.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault(ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var keys = _interopDefault(require('core-js/library/fn/object/keys'));
var assign = _interopDefault(require('core-js/library/fn/object/assign'));
var th = require('tree-helper');
require('core-js/modules/web.dom.iterable');
require('core-js/modules/es6.number.constructor');
var hp = require('helper-js');
var defineProperty = _interopDefault(require('core-js/library/fn/object/define-property'));
require('core-js/modules/es6.function.name');
var getIterator = _interopDefault(require('core-js/library/fn/get-iterator'));
require('core-js/modules/es6.array.find');
var vf = require('vue-functions');
require('core-js/modules/es6.regexp.replace');
var draggableHelper = _interopDefault(require('draggable-helper'));
var keys$1 = keys;
var assign$1 = assign;
//
var script = {
name: 'TreeNode',
props: {
data: {},
store: {},
level: {
default: 0
} // readonly
},
data: function data() {
return {
vm: this
};
},
computed: {
childrenLevel: function childrenLevel() {
return this.level + 1;
},
isRoot: function isRoot() {
return this.data && this.data.isRoot;
},
childrenVisible: function childrenVisible() {
var data = this.data;
return this.isRoot || data && data.children && data.children.length && data.open;
},
innerBackStyle: function innerBackStyle() {
var r = {
marginBottom: this.store.space + 'px'
};
if (!this.isRoot && this.level > 1) {
if (this.store.dir === 'rtl') {
r.paddingRight = (this.level - 1) * this.store.indent + 'px';
} else {
r.paddingLeft = (this.level - 1) * this.store.indent + 'px';
}
}
return r;
}
},
watch: {
data: {
immediate: true,
handler: function handler(data) {
if (data) {
data._vm = this;
if (!data._treeNodePropertiesCompleted && !data.isRoot) {
this.store.compeleteNode(data, this.$parent.data);
}
}
}
}
} // methods: {},
// created() {},
// mounted() {},
};
/* script */
const __vue_script__ = script;
/* template */
var __vue_render__ = function () { var _vm = this; var _h = _vm.$createElement; var _c = _vm._self._c || _h; return _c('div', { staticClass: "tree-node", class: [_vm.data.active ? _vm.store.activatedClass : '', _vm.data.open ? _vm.store.openedClass : '', _vm.data.class], style: (_vm.data.style), attrs: { "id": _vm.data._id } }, [(!_vm.isRoot) ? _vm._t("node-inner-back", [_c('div', { staticClass: "tree-node-inner-back", class: [_vm.data.innerBackClass], style: ([_vm.innerBackStyle, _vm.data.innerBackStyle]) }, [_c('div', { staticClass: "tree-node-inner", class: [_vm.data.innerClass], style: ([_vm.data.innerStyle]) }, [_vm._t("default", null, { data: _vm.data, store: _vm.store, vm: _vm.vm })], 2)])], { styleObj: _vm.innerBackStyle, data: _vm.data, store: _vm.store, vm: _vm.vm }) : _vm._e(), _c('transition', { attrs: { "name": _vm.store.childrenTransitionName } }, [(_vm.childrenVisible) ? _c('div', { staticClass: "tree-node-children" }, _vm._l((_vm.data.children), function (child) { return _c('TreeNode', { key: child._id, attrs: { "data": child, "store": _vm.store, "level": _vm.childrenLevel }, scopedSlots: _vm._u([{ key: "default", fn: function (props) { return [_vm._t("default", null, { data: props.data, store: props.store, vm: props.vm })] } }, { key: "node-inner-back", fn: function (props) { return (_vm.store.customInnerBack) ? [_vm._t("node-inner-back", null, { styleObj: props.styleObj, data: props.data, store: props.store, vm: props.vm })] : undefined } }]) }) }), 1) : _vm._e()])], 2) };
var __vue_staticRenderFns__ = [];
/* style */
const __vue_inject_styles__ = undefined;
/* scoped */
const __vue_scope_id__ = undefined;
/* module identifier */
const __vue_module_identifier__ = undefined;
/* functional template */
const __vue_is_functional_template__ = false;
/* component normalizer */
function __vue_normalize__(
template, style, script$$1,
scope, functional, moduleIdentifier,
createInjector, createInjectorSSR
) {
const component = (typeof script$$1 === 'function' ? script$$1.options : script$$1) || {};
// For security concerns, we use only base name in production mode.
component.__file = "TreeNode.vue";
if (!component.render) {
component.render = template.render;
component.staticRenderFns = template.staticRenderFns;
component._compiled = true;
if (functional) component.functional = true;
}
component._scopeId = scope;
return component
}
/* style inject */
/* style inject SSR */
var TreeNode = __vue_normalize__(
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
__vue_inject_styles__,
__vue_script__,
__vue_scope_id__,
__vue_is_functional_template__,
__vue_module_identifier__,
undefined,
undefined
);
var script$1 = {
props: {
data: {},
idLength: {
type: Number,
default: 5
},
indent: {
type: Number,
default: 16
},
activatedClass: {
default: 'active'
},
openedClass: {
default: 'open'
},
space: {
type: Number,
default: 10
},
// space between node, unit px
childrenTransitionName: {},
// there are issues under draggable tree
customInnerBack: {}
},
components: {
TreeNode: TreeNode
},
data: function data() {
return {
store: this,
rootData: null
};
},
// computed: {},
watch: {
data: {
immediate: true,
handler: function handler(data, old) {
var _this = this;
if (data === old) {
return;
} // make rootData always use a same object
this.rootData = this.rootData || {
isRoot: true,
_id: "tree_".concat(this._uid, "_node_root"),
children: []
};
th.breadthFirstSearch(data, function (node, k, parent) {
_this.compeleteNode(node, parent);
});
this.rootData.children = data;
}
}
},
methods: {
compeleteNode: function compeleteNode(node, parent) {
var compeletedData = {
open: true,
children: [],
active: false,
style: {},
class: '',
innerStyle: {},
innerClass: '',
innerBackStyle: {},
innerBackClass: {}
};
for (var key in compeletedData) {
if (!node.hasOwnProperty(key)) {
this.$set(node, key, compeletedData[key]);
}
}
this.$set(node, 'parent', parent || this.rootData);
if (!node.hasOwnProperty('_id')) {
node._id = "tree_".concat(this._uid, "_node_").concat(hp.strRand(this.idLength));
}
node._treeNodePropertiesCompleted = true;
},
// pure node self
pure: function pure(node, withChildren, after) {
var _this2 = this;
var t = assign$1({}, node);
delete t._id;
delete t.parent;
delete t.children;
delete t.open;
delete t.active;
delete t.style;
delete t.class;
delete t.innerStyle;
delete t.innerClass;
delete t.innerBackStyle;
delete t.innerBackClass;
var _arr = keys$1(t);
for (var _i = 0; _i < _arr.length; _i++) {
var key = _arr[_i];
if (key[0] === '_') {
delete t[key];
}
}
if (withChildren && node.children) {
t.children = node.children.slice();
t.children.forEach(function (v, k) {
t.children[k] = _this2.pure(v, withChildren);
});
}
if (after) {
return after(t, node) || t;
}
return t;
},
getNodeById: function getNodeById(id) {
var r;
th.breadthFirstSearch(this.rootData.children, function (node) {
if (node._id === id) {
r = node;
return false;
}
});
return r;
},
getActivated: function getActivated() {
var r = [];
th.breadthFirstSearch(this.rootData.children, function (node) {
if (node.active) {
r.push(node);
}
});
return r;
},
getOpened: function getOpened() {
var r = [];
th.breadthFirstSearch(this.rootData.children, function (node) {
if (node.open) {
r.push(node);
}
});
return r;
},
activeNode: function activeNode(node, inactiveOld) {
var activated = this.activated;
if (inactiveOld) {
this.getActivated().forEach(function (node2) {
node2.active = false;
});
}
node.active = true;
},
toggleActive: function toggleActive(node, inactiveOld) {
if (node.active) {
node.active = false;
} else {
this.activeNode(node, inactiveOld);
}
},
openNode: function openNode(node, closeOld) {
var _this3 = this;
var opened = this.opened;
if (closeOld) {
this.getOpened().forEach(function (node2) {
node2.open = false;
_this3.$emit('nodeOpenChanged', node2);
});
}
node.open = true;
this.$emit('nodeOpenChanged', node);
},
toggleOpen: function toggleOpen(node, closeOld) {
if (node.open) {
node.open = false;
this.$emit('nodeOpenChanged', node);
} else {
this.openNode(node, closeOld);
}
},
getPureData: function getPureData(after) {
return this.pure(this.rootData, true, after).children;
},
deleteNode: function deleteNode(node) {
return hp.arrayRemove(node.parent.children, node);
}
} // created() {},
// mounted() {},
};
/* script */
const __vue_script__$1 = script$1;
/* template */
var __vue_render__$1 = function () { var _vm = this; var _h = _vm.$createElement; var _c = _vm._self._c || _h; return _c('div', { staticClass: "he-tree tree" }, [_c('TreeNode', { attrs: { "data": _vm.rootData, "store": _vm.store }, scopedSlots: _vm._u([{ key: "default", fn: function (props) { return [_vm._t("default", null, { data: props.data, store: _vm.store, vm: props.vm })] } }, { key: "node-inner-back", fn: function (props) { return (_vm.customInnerBack) ? [_vm._t("node-inner-back", null, { styleObj: props.styleObj, data: props.data, store: props.store, vm: props.vm })] : undefined } }]) })], 1) };
var __vue_staticRenderFns__$1 = [];
/* style */
const __vue_inject_styles__$1 = undefined;
/* scoped */
const __vue_scope_id__$1 = undefined;
/* module identifier */
const __vue_module_identifier__$1 = undefined;
/* functional template */
const __vue_is_functional_template__$1 = false;
/* component normalizer */
function __vue_normalize__$1(
template, style, script,
scope, functional, moduleIdentifier,
createInjector, createInjectorSSR
) {
const component = (typeof script === 'function' ? script.options : script) || {};
// For security concerns, we use only base name in production mode.
component.__file = "Tree.vue";
if (!component.render) {
component.render = template.render;
component.staticRenderFns = template.staticRenderFns;
component._compiled = true;
if (functional) component.functional = true;
}
component._scopeId = scope;
return component
}
/* style inject */
/* style inject SSR */
var Tree = __vue_normalize__$1(
{ render: __vue_render__$1, staticRenderFns: __vue_staticRenderFns__$1 },
__vue_inject_styles__$1,
__vue_script__$1,
__vue_scope_id__$1,
__vue_is_functional_template__$1,
__vue_module_identifier__$1,
undefined,
undefined
);
var defineProperty$1 = defineProperty;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
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;
defineProperty$1(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
defineProperty$1(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var Cache =
/*#__PURE__*/
function () {
function Cache() {
_classCallCheck(this, Cache);
_defineProperty(this, "store", {});
}
_createClass(Cache, [{
key: "has",
value: function has(name) {
return this.store.hasOwnProperty(name);
}
}, {
key: "remember",
value: function remember(name, getter) {
if (!this.has(name)) {
this.store[name] = {
value: getter()
};
}
return this.store[name].value;
}
}, {
key: "forget",
value: function forget(name) {
if (name) {
if (this.has(name)) {
delete this.store[name];
}
} else {
this.store = {};
}
}
}]);
return Cache;
}();
function attachCache(obj, cache, toCache) {
var _loop = function _loop(key) {
defineProperty$1(obj, key, {
get: function get() {
var _this = this;
return cache.remember(key, function () {
return toCache[key].call(_this);
});
}
});
};
for (var key in toCache) {
_loop(key);
}
}
var getIterator$1 = getIterator;
// from https://gist.github.com/iddan/54d5d9e58311b0495a91bf06de661380
if (!document.elementsFromPoint) {
document.elementsFromPoint = elementsFromPoint;
}
function elementsFromPoint(x, y) {
var parents = [];
var parent = void 0;
do {
if (parent !== document.elementFromPoint(x, y)) {
parent = document.elementFromPoint(x, y);
parents.push(parent);
parent.style.pointerEvents = 'none';
} else {
parent = false;
}
} while (parent);
parents.forEach(function (parent) {
return parent.style.pointerEvents = 'all';
});
return parents;
}
function getTreeByPoint(x, y, trees) {
var els = document.elementsFromPoint(x, y);
var treeEl;
var nodeEl;
var betweenEls = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = getIterator$1(els), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _el = _step.value;
if (!nodeEl) {
if (hp.hasClass(_el, 'tree-node')) {
nodeEl = _el;
}
} else {
// console.log(el);
if (hp.hasClass(_el, 'tree')) {
treeEl = _el;
break;
}
betweenEls.push(_el);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (treeEl) {
// is target tree is another tree, and be covered by other element, like modal, popup
var covered = false;
if (!isParent(nodeEl, treeEl)) {
// cross tree
for (var _i = 0; _i < betweenEls.length; _i++) {
var el = betweenEls[_i];
if (!isParent(el, treeEl)) {
covered = true;
break;
}
}
} //
if (!covered) {
return trees.find(function (v) {
return v.$el === treeEl;
});
}
}
}
function isParent(child, parent) {
var cur = child;
while (cur) {
cur = cur.parentNode;
if (cur === parent) {
return true;
}
}
}
// 对 drag placeholder进行的操作
var targets = {
'nothing': function nothing(info) { },
'after': function after(info) {
insertDplhAfterTo(info.dplh, info.targetNode, info);
},
'before': function before(info) {
if (isNodeDroppable(info.targetNode.parent)) {
th.insertBefore(info.dplh, info.targetNode);
} else {
insertDplhAfterTo(info.dplh, info.targetNode.parent, info);
}
},
'append': function append(info) {
if (isNodeDroppable(info.targetNode)) {
th.appendTo(info.dplh, info.targetNode);
if (!info.targetNode.open) info.store.toggleOpen(info.targetNode);
} else {
insertDplhAfterTo(info.dplh, info.targetNode, info);
}
},
'prepend': function prepend(info) {
if (isNodeDroppable(info.targetNode)) {
th.prependTo(info.dplh, info.targetNode);
if (!info.targetNode.open) info.store.toggleOpen(info.targetNode);
} else {
insertDplhAfterTo(info.dplh, info.targetNode, info);
}
},
'after target parent': function afterTargetParent(info) {
insertDplhAfterTo(info.dplh, info.targetNode.parent, info);
},
// append to prev sibling
'append prev': function appendPrev(info) {
if (isNodeDroppable(info.targetPrev)) {
th.appendTo(info.dplh, info.targetPrev);
if (!info.targetPrev.open) info.store.toggleOpen(info.targetPrev);
} else {
insertDplhAfterTo(info.dplh, info.targetPrev, info);
}
},
// append to current tree
'append current tree': function appendCurrentTree(info) {
if (isNodeDroppable(info.currentTree.rootData)) {
th.appendTo(info.dplh, info.currentTree.rootData);
}
}
};
function insertDplhAfterTo(dplh, targetNode, info) {
if (!targetNode) {
return false;
} else {
var closest = findParent(targetNode, function (node) {
return node.parent && isNodeDroppable(node.parent);
});
if (closest) {
th.insertAfter(dplh, closest);
} else {
return false;
}
}
return true;
}
function isNodeDraggable(node) {
if (!draggableIds.hasOwnProperty(node._id)) {
var r;
if (node.hasOwnProperty('draggable')) {
r = node.draggable;
} else if (node.parent) {
r = isNodeDraggable(node.parent);
} else {
r = true;
}
draggableIds[node._id] = r;
}
return draggableIds[node._id];
}
function isNodeDroppable(node) {
if (!droppableIds.hasOwnProperty(node._id)) {
var r;
if (node.hasOwnProperty('droppable')) {
r = node.droppable;
} else if (node.parent) {
r = isNodeDroppable(node.parent);
} else {
r = true;
}
droppableIds[node._id] = r;
}
return droppableIds[node._id];
} // find child, excluding dragging node default
function findChild(info, children, handler, reverse) {
var len = children.length;
if (reverse) {
for (var i = len - 1; i >= 0; i--) {
var item = children[i]; // excluding dragging node
if (item !== info.node) {
if (handler(item, i)) {
return item;
}
}
}
} else {
for (var _i = 0; _i < len; _i++) {
var _item = children[_i]; // excluding dragging node
if (_item !== info.node) {
if (handler(_item, _i)) {
return _item;
}
}
}
}
} // start from node self
function findParent(node, handle) {
var current = node;
while (current) {
if (handle(current)) {
return current;
}
current = current.parent;
}
}
var rules = {
// 另一节点存在
'targetNode existed': function targetNodeExisted(info) {
return info.targetNode;
},
// 另一节点是拖动占位节点
'targetNode is placeholder': function targetNodeIsPlaceholder(info) {
return info.targetNode.isDragPlaceHolder;
},
// 另一节点在最上面
'targetNode at top': function targetNodeAtTop(info) {
return info.targetAtTop;
},
// 另一节点在最下面
'targetNode at bottom': function targetNodeAtBottom(info) {
return info.targetAtBottom;
},
// 另一节点是根节点第二个子
'targetNode is the second child of root': function targetNodeIsTheSecondChildOfRoot(info) {
return info.currentTreeRootSecondChildExcludingDragging === info.targetNode;
},
// 拖动点坐标在任一树中, 同时, 起始树要可拖出, 当前树要可拖入
'currentTree existed': function currentTreeExisted(info) {
return info.currentTree;
},
// 当前树为空(不包括占位节点)
'currentTree empty': function currentTreeEmpty(info) {
return !findChild(info, info.currentTree.rootData.children, function (v) {
return v;
});
},
// 占位节点存在
'placeholder existed': function placeholderExisted(info) {
return info.dplhEl;
},
// 占位节点在当前树中
'placeholder in currentTree': function placeholderInCurrentTree(info) {
return info.dplhElInCurrentTree;
},
// 占位节点在最上面
'placeholder at top': function placeholderAtTop(info) {
return info.dplhAtTop;
},
// 另一节点是打开的
'targetNode is open': function targetNodeIsOpen(info) {
return info.targetNode.open;
},
// 另一节点有子(不包括占位节点)
'targetNode has children excluding placeholder': function targetNodeHasChildrenExcludingPlaceholder(info) {
return findChild(info, info.targetNode.children, function (v) {
return v !== info.dplh;
});
},
// 另一节点是第一个节点
'targetNode is 1st child': function targetNodeIs1stChild(info) {
return findChild(info, info.targetNode.parent.children, function (v) {
return v;
}) === info.targetNode;
},
// 另一节点是最后节点
'targetNode is last child': function targetNodeIsLastChild(info) {
return findChild(info, info.targetNode.parent.children, function (v) {
return v;
}, true) === info.targetNode;
},
// 当前位置在另一节点inner垂直中线上
'on targetNode middle': function onTargetNodeMiddle(info) {
return info.offset.y <= info.tiMiddleY;
},
// 当前位置在另一节点inner左边
'at left': function atLeft(info) {
return info.offset.x < info.tiOffset.x;
},
'at right': function atRight(info) {
return info.offset.x > info.tiOffset.x;
},
// 当前位置在另一节点innner indent位置右边
'at indent right': function atIndentRight(info) {
return info.offset.x > info.tiOffset.x + info.currentTree.indent;
},
'at indent left': function atIndentLeft(info) {
return info.offset.x < info.tiOffset.x + info.currentTree.indent;
} // convert rule output to Boolean
};
var _arr = keys$1(rules);
var _loop = function _loop() {
var key = _arr[_i2];
var old = rules[key];
rules[key] = function () {
return Boolean(old.apply(void 0, arguments));
};
};
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
_loop();
}
var prevTree;
var droppableIds = {};
var draggableIds = {}; // context is vm
function autoMoveDragPlaceHolder(draggableHelperInfo) {
var trees = this.store.trees;
var dhStore = draggableHelperInfo.store; // make info
var info = {
event: draggableHelperInfo.event,
el: dhStore.el,
vm: this,
node: this.data,
store: this.store,
dplh: this.store.dplh,
draggableHelperData: {
opt: draggableHelperInfo.options,
store: dhStore
} //
};
attachCache(info, new Cache(), {
// dragging node coordinate
// 拖动中的节点相关坐标
nodeInnerEl: function nodeInnerEl() {
return this.el.querySelector('.tree-node-inner');
},
offset: function offset() {
return hp.getOffset(this.nodeInnerEl);
},
// left top point
offset2: function offset2() {
return {
x: this.offset.x + this.nodeInnerEl.offsetWidth,
y: this.offset.y + this.nodeInnerEl.offsetHeight
};
},
// right bottom point
offsetToViewPort: function offsetToViewPort() {
var r = this.nodeInnerEl.getBoundingClientRect();
r.x = this.store.dir === 'rtl' ? r.right : r.left;
r.y = r.top;
return r;
},
// tree
currentTree: function currentTree() {
// const currentTree = trees.find(tree => hp.isOffsetInEl(this.offset.x, this.offset.y, tree.$el))
var currentTree = getTreeByPoint(this.offsetToViewPort.x, this.offsetToViewPort.y, trees);
if (currentTree) {
var dragStartTree = this.store;
if (prevTree == null) {
prevTree = dragStartTree;
}
if (prevTree !== currentTree) {
if (!vf.isPropTrue(dragStartTree.crossTree) || !vf.isPropTrue(currentTree.crossTree)) {
return;
}
prevTree = currentTree;
}
if (!vf.isPropTrue(currentTree.droppable)) {
return;
}
return currentTree;
}
},
currentTreeRootEl: function currentTreeRootEl() {
return document.getElementById(this.currentTree.rootData._id);
},
currentTreeRootOf4: function currentTreeRootOf4() {
return getOf4(this.currentTreeRootEl, this.currentTree.space);
},
// the second child of currentTree root, excluding dragging node
currentTreeRootSecondChildExcludingDragging: function currentTreeRootSecondChildExcludingDragging() {
var _this = this;
return this.currentTree.rootData.children.slice(0, 3).filter(function (v) {
return v !== _this.node;
})[1];
},
// placeholder
dplhEl: function dplhEl() {
return document.getElementById(this.dplh._id);
},
dplhElInCurrentTree: function dplhElInCurrentTree() {
return Boolean(this.currentTree.$el.querySelector("#".concat(this.dplh._id)));
},
dplhOf4: function dplhOf4() {
return getOf4(this.dplhEl, this.currentTree.space);
},
dplhAtTop: function dplhAtTop() {
return Math.abs(this.dplhOf4.y - this.currentTreeRootOf4.y) < 5;
},
targetAtTop: function targetAtTop() {
return Math.abs(this.tiOf4.y - this.currentTreeRootOf4.y) < 5;
},
targetAtBottom: function targetAtBottom() {
return Math.abs(this.tiOf4.y2 - this.currentTreeRootOf4.y2) < 5;
},
// most related node
// 最相关的另一个节点
targetNode: function targetNode() {
var currentTree = this.currentTree;
if (!currentTree) {
throw 'no currentTree';
} //
var _this$offset = this.offset,
x = _this$offset.x,
y = _this$offset.y;
var currentNode = currentTree.rootData;
while (true) {
var children = currentNode.children;
if (!children) {
break;
}
if (this.node.parent === currentNode) {
// dragging node is in currentNode children, remove it first
children = children.slice();
children.splice(children.indexOf(this.node), 1);
}
if (children.length === 0) {
break;
}
var t = hp.binarySearch(children, function (node) {
var el = document.getElementById(node._id);
var ty = hp.getOffset(el).y;
var ty2 = ty + el.offsetHeight + currentTree.space;
if (ty2 < y) {