reneco-hierarchized-picker 0.4.2-beta.5 → 0.4.2-beta.7
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.
- package/dist/cjs/reneco-hierarchized-picker_2.cjs.entry.js +102 -8
- package/dist/collection/components/hierarchized-picker/hierarchized-picker.js +2 -1
- package/dist/collection/components/treejs/index.js +10 -6
- package/dist/collection/features/tree/tree-utils.js +1 -1
- package/dist/custom-elements/index.js +102 -8
- package/dist/esm/reneco-hierarchized-picker_2.entry.js +102 -8
- package/dist/esm-es5/reneco-hierarchized-picker_2.entry.js +1 -1
- package/dist/reneco-hierarchized-picker/p-0e6a220c.entry.js +1 -0
- package/dist/reneco-hierarchized-picker/p-73168a50.system.js +1 -1
- package/dist/reneco-hierarchized-picker/p-83e6a880.system.entry.js +3 -0
- package/dist/reneco-hierarchized-picker/reneco-hierarchized-picker.esm.js +1 -1
- package/package.json +1 -1
- package/dist/reneco-hierarchized-picker/p-0854c67d.entry.js +0 -1
- package/dist/reneco-hierarchized-picker/p-66a01206.system.entry.js +0 -3
|
@@ -44,6 +44,96 @@ var vanillaContextMenu = createCommonjsModule(function (module, exports) {
|
|
|
44
44
|
|
|
45
45
|
const VanillaContextMenu = /*@__PURE__*/getDefaultExportFromCjs(vanillaContextMenu);
|
|
46
46
|
|
|
47
|
+
let curDraggingItem = null;
|
|
48
|
+
let lastDraggedOverNodeId = null;
|
|
49
|
+
let lastDraggedOverTimeForAscendent = new Date().getTime();
|
|
50
|
+
let lastDraggedOverTimeForLevel = new Date().getTime();
|
|
51
|
+
const acceptableDelayBetweenSimilarActions = 300;
|
|
52
|
+
/**
|
|
53
|
+
* Handles the drag start event.
|
|
54
|
+
*/
|
|
55
|
+
function onItemDragStart(el, e) {
|
|
56
|
+
curDraggingItem = el;
|
|
57
|
+
el.classList.add('dragging');
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Handles the drag end event.
|
|
62
|
+
*/
|
|
63
|
+
function onItemDragEnd(el, e) {
|
|
64
|
+
el.classList.remove('dragging');
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
clearDragOverStyles(el.parentElement);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handles the drag over event.
|
|
70
|
+
*/
|
|
71
|
+
function onItemDragOver(el, e) {
|
|
72
|
+
const now = new Date().getTime();
|
|
73
|
+
if (now - lastDraggedOverTimeForAscendent < 50 && el.dataset.nodeId !== lastDraggedOverNodeId) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
lastDraggedOverTimeForAscendent = now;
|
|
77
|
+
if (el.dataset.nodeId === lastDraggedOverNodeId) {
|
|
78
|
+
if (now - lastDraggedOverTimeForLevel < acceptableDelayBetweenSimilarActions) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
lastDraggedOverTimeForLevel = now;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
lastDraggedOverNodeId = el.dataset.nodeId;
|
|
85
|
+
}
|
|
86
|
+
clearDragOverStyles(el);
|
|
87
|
+
if (el === curDraggingItem) {
|
|
88
|
+
el.classList.remove('dragover');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const pos = getDragOverPosition(el, e);
|
|
92
|
+
el.classList.add(`dragover-${pos}`);
|
|
93
|
+
el.classList.add('dragover');
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Handles the drag leave event.
|
|
99
|
+
*/
|
|
100
|
+
function onItemDragLeave(el, e) {
|
|
101
|
+
clearDragOverStyles(el);
|
|
102
|
+
el.classList.remove('dragover');
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Handles the drop event.
|
|
107
|
+
*/
|
|
108
|
+
function onItemDrop(el, e, dropCallback) {
|
|
109
|
+
clearDragOverStyles(el);
|
|
110
|
+
el.classList.remove('dragover');
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
if (curDraggingItem) {
|
|
113
|
+
const pos = getDragOverPosition(el, e);
|
|
114
|
+
dropCallback(curDraggingItem, el, pos);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Determines the drop position based on the mouse event.
|
|
119
|
+
*/
|
|
120
|
+
function getDragOverPosition(el, e) {
|
|
121
|
+
const h = el.offsetHeight;
|
|
122
|
+
const before = h / 4;
|
|
123
|
+
const after = h - before;
|
|
124
|
+
const y = e.offsetY;
|
|
125
|
+
return y <= before ? 'before' : y >= after ? 'after' : 'over';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Clears the drag-over styles from the element.
|
|
129
|
+
*/
|
|
130
|
+
function clearDragOverStyles(el) {
|
|
131
|
+
if (!el)
|
|
132
|
+
return;
|
|
133
|
+
const prevClasses = Array.from(el.classList).filter(name => name.startsWith('dragover-'));
|
|
134
|
+
prevClasses.forEach(name => el.classList.remove(name));
|
|
135
|
+
}
|
|
136
|
+
|
|
47
137
|
function deepClone(obj) {
|
|
48
138
|
return JSON.parse(JSON.stringify(obj));
|
|
49
139
|
}
|
|
@@ -199,7 +289,8 @@ Tree.prototype.bindEvent = function (ele) {
|
|
|
199
289
|
return typeof item === 'string'
|
|
200
290
|
? item
|
|
201
291
|
: Object.assign(Object.assign({}, item), { callback: e => {
|
|
202
|
-
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId]
|
|
292
|
+
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId] && that.nodesById[e.target.nodeId].children &&
|
|
293
|
+
that.nodesById[e.target.nodeId].children.length && that.nodesById[e.target.nodeId].children.length > 0 });
|
|
203
294
|
delete targetOutput.children;
|
|
204
295
|
this.options.parentApi.onItemContextMenuItemClick(Object.assign(Object.assign({}, e), { target: targetOutput, contextMenuItem: item }));
|
|
205
296
|
} });
|
|
@@ -575,19 +666,21 @@ Tree.prototype.createLiEle = function (node, closed) {
|
|
|
575
666
|
if (this.options.parentApi.theOptions.dragAndDropEnabled) {
|
|
576
667
|
li.setAttribute('draggable', 'true');
|
|
577
668
|
li.addEventListener('dragstart', e => {
|
|
578
|
-
|
|
669
|
+
onItemDragStart(li, e);
|
|
579
670
|
});
|
|
580
671
|
li.addEventListener('dragend', e => {
|
|
581
|
-
|
|
672
|
+
onItemDragEnd(li, e);
|
|
582
673
|
});
|
|
583
674
|
li.addEventListener('dragover', e => {
|
|
584
|
-
|
|
675
|
+
onItemDragOver(li, e);
|
|
585
676
|
});
|
|
586
677
|
li.addEventListener('dragleave', e => {
|
|
587
|
-
|
|
678
|
+
onItemDragLeave(li, e);
|
|
588
679
|
});
|
|
589
680
|
li.addEventListener('drop', e => {
|
|
590
|
-
|
|
681
|
+
onItemDrop(li, e, (dragEl, dropEl, position) => {
|
|
682
|
+
this.options.parentApi.itemDropped.emit({ dragEl, dropEl, position });
|
|
683
|
+
});
|
|
591
684
|
});
|
|
592
685
|
}
|
|
593
686
|
return li;
|
|
@@ -18347,7 +18440,7 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
|
|
|
18347
18440
|
const deprecated = getPropertyFromNode(value, 'deprecated', false);
|
|
18348
18441
|
const objToPush = {
|
|
18349
18442
|
id: keyPropFromNode,
|
|
18350
|
-
|
|
18443
|
+
nodeId: keyPropFromNode,
|
|
18351
18444
|
depth,
|
|
18352
18445
|
text: valueTranslatedPropFromNode,
|
|
18353
18446
|
fullpath: fullpathPropFromNode,
|
|
@@ -19184,8 +19277,9 @@ const HierarchizedPickerComponent = class {
|
|
|
19184
19277
|
async setNodeAsSelected(id, treeToUpdate, userClick) {
|
|
19185
19278
|
// TODO Temporarily ignores disabled mode for selecting nodes if mode is tree
|
|
19186
19279
|
if (((this.isDisabled && this.optionsManager.getOptions().mode != "tree") && this.shownTree && this.setValueOnClick) ||
|
|
19187
|
-
(this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1))
|
|
19280
|
+
(this.loadedTreeJs.liElementsById[id] && this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1)) {
|
|
19188
19281
|
return;
|
|
19282
|
+
}
|
|
19189
19283
|
if (treeToUpdate.getValues().indexOf(id.toString()) != -1)
|
|
19190
19284
|
return;
|
|
19191
19285
|
this.ignoreOptionsChanges = true;
|
|
@@ -619,8 +619,9 @@ export class HierarchizedPickerComponent {
|
|
|
619
619
|
async setNodeAsSelected(id, treeToUpdate, userClick) {
|
|
620
620
|
// TODO Temporarily ignores disabled mode for selecting nodes if mode is tree
|
|
621
621
|
if (((this.isDisabled && this.optionsManager.getOptions().mode != "tree") && this.shownTree && this.setValueOnClick) ||
|
|
622
|
-
(this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1))
|
|
622
|
+
(this.loadedTreeJs.liElementsById[id] && this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1)) {
|
|
623
623
|
return;
|
|
624
|
+
}
|
|
624
625
|
if (treeToUpdate.getValues().indexOf(id.toString()) != -1)
|
|
625
626
|
return;
|
|
626
627
|
this.ignoreOptionsChanges = true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import VanillaContextMenu from 'vanilla-context-menu';
|
|
2
|
+
import { onItemDragStart, onItemDragEnd, onItemDragOver, onItemDragLeave, onItemDrop } from '../../features/tree/drag-drop';
|
|
2
3
|
function deepClone(obj) {
|
|
3
4
|
return JSON.parse(JSON.stringify(obj));
|
|
4
5
|
}
|
|
@@ -165,7 +166,8 @@ Tree.prototype.bindEvent = function (ele) {
|
|
|
165
166
|
return typeof item === 'string'
|
|
166
167
|
? item
|
|
167
168
|
: Object.assign(Object.assign({}, item), { callback: e => {
|
|
168
|
-
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId]
|
|
169
|
+
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId] && that.nodesById[e.target.nodeId].children &&
|
|
170
|
+
that.nodesById[e.target.nodeId].children.length && that.nodesById[e.target.nodeId].children.length > 0 });
|
|
169
171
|
delete targetOutput.children;
|
|
170
172
|
this.options.parentApi.onItemContextMenuItemClick(Object.assign(Object.assign({}, e), { target: targetOutput, contextMenuItem: item }));
|
|
171
173
|
} });
|
|
@@ -542,19 +544,21 @@ Tree.prototype.createLiEle = function (node, closed) {
|
|
|
542
544
|
if (this.options.parentApi.theOptions.dragAndDropEnabled) {
|
|
543
545
|
li.setAttribute('draggable', 'true');
|
|
544
546
|
li.addEventListener('dragstart', e => {
|
|
545
|
-
|
|
547
|
+
onItemDragStart(li, e);
|
|
546
548
|
});
|
|
547
549
|
li.addEventListener('dragend', e => {
|
|
548
|
-
|
|
550
|
+
onItemDragEnd(li, e);
|
|
549
551
|
});
|
|
550
552
|
li.addEventListener('dragover', e => {
|
|
551
|
-
|
|
553
|
+
onItemDragOver(li, e);
|
|
552
554
|
});
|
|
553
555
|
li.addEventListener('dragleave', e => {
|
|
554
|
-
|
|
556
|
+
onItemDragLeave(li, e);
|
|
555
557
|
});
|
|
556
558
|
li.addEventListener('drop', e => {
|
|
557
|
-
|
|
559
|
+
onItemDrop(li, e, (dragEl, dropEl, position) => {
|
|
560
|
+
this.options.parentApi.itemDropped.emit({ dragEl, dropEl, position });
|
|
561
|
+
});
|
|
558
562
|
});
|
|
559
563
|
}
|
|
560
564
|
return li;
|
|
@@ -79,7 +79,7 @@ export function fillTreeWithObject(tree, myObject, searched, options, depth = 0)
|
|
|
79
79
|
const deprecated = getPropertyFromNode(value, 'deprecated', false);
|
|
80
80
|
const objToPush = {
|
|
81
81
|
id: keyPropFromNode,
|
|
82
|
-
|
|
82
|
+
nodeId: keyPropFromNode,
|
|
83
83
|
depth,
|
|
84
84
|
text: valueTranslatedPropFromNode,
|
|
85
85
|
fullpath: fullpathPropFromNode,
|
|
@@ -41,6 +41,96 @@ var vanillaContextMenu = createCommonjsModule(function (module, exports) {
|
|
|
41
41
|
|
|
42
42
|
const VanillaContextMenu = /*@__PURE__*/getDefaultExportFromCjs(vanillaContextMenu);
|
|
43
43
|
|
|
44
|
+
let curDraggingItem = null;
|
|
45
|
+
let lastDraggedOverNodeId = null;
|
|
46
|
+
let lastDraggedOverTimeForAscendent = new Date().getTime();
|
|
47
|
+
let lastDraggedOverTimeForLevel = new Date().getTime();
|
|
48
|
+
const acceptableDelayBetweenSimilarActions = 300;
|
|
49
|
+
/**
|
|
50
|
+
* Handles the drag start event.
|
|
51
|
+
*/
|
|
52
|
+
function onItemDragStart(el, e) {
|
|
53
|
+
curDraggingItem = el;
|
|
54
|
+
el.classList.add('dragging');
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Handles the drag end event.
|
|
59
|
+
*/
|
|
60
|
+
function onItemDragEnd(el, e) {
|
|
61
|
+
el.classList.remove('dragging');
|
|
62
|
+
e.stopPropagation();
|
|
63
|
+
clearDragOverStyles(el.parentElement);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Handles the drag over event.
|
|
67
|
+
*/
|
|
68
|
+
function onItemDragOver(el, e) {
|
|
69
|
+
const now = new Date().getTime();
|
|
70
|
+
if (now - lastDraggedOverTimeForAscendent < 50 && el.dataset.nodeId !== lastDraggedOverNodeId) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
lastDraggedOverTimeForAscendent = now;
|
|
74
|
+
if (el.dataset.nodeId === lastDraggedOverNodeId) {
|
|
75
|
+
if (now - lastDraggedOverTimeForLevel < acceptableDelayBetweenSimilarActions) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
lastDraggedOverTimeForLevel = now;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
lastDraggedOverNodeId = el.dataset.nodeId;
|
|
82
|
+
}
|
|
83
|
+
clearDragOverStyles(el);
|
|
84
|
+
if (el === curDraggingItem) {
|
|
85
|
+
el.classList.remove('dragover');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const pos = getDragOverPosition(el, e);
|
|
89
|
+
el.classList.add(`dragover-${pos}`);
|
|
90
|
+
el.classList.add('dragover');
|
|
91
|
+
e.stopPropagation();
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Handles the drag leave event.
|
|
96
|
+
*/
|
|
97
|
+
function onItemDragLeave(el, e) {
|
|
98
|
+
clearDragOverStyles(el);
|
|
99
|
+
el.classList.remove('dragover');
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Handles the drop event.
|
|
104
|
+
*/
|
|
105
|
+
function onItemDrop(el, e, dropCallback) {
|
|
106
|
+
clearDragOverStyles(el);
|
|
107
|
+
el.classList.remove('dragover');
|
|
108
|
+
e.stopPropagation();
|
|
109
|
+
if (curDraggingItem) {
|
|
110
|
+
const pos = getDragOverPosition(el, e);
|
|
111
|
+
dropCallback(curDraggingItem, el, pos);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Determines the drop position based on the mouse event.
|
|
116
|
+
*/
|
|
117
|
+
function getDragOverPosition(el, e) {
|
|
118
|
+
const h = el.offsetHeight;
|
|
119
|
+
const before = h / 4;
|
|
120
|
+
const after = h - before;
|
|
121
|
+
const y = e.offsetY;
|
|
122
|
+
return y <= before ? 'before' : y >= after ? 'after' : 'over';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Clears the drag-over styles from the element.
|
|
126
|
+
*/
|
|
127
|
+
function clearDragOverStyles(el) {
|
|
128
|
+
if (!el)
|
|
129
|
+
return;
|
|
130
|
+
const prevClasses = Array.from(el.classList).filter(name => name.startsWith('dragover-'));
|
|
131
|
+
prevClasses.forEach(name => el.classList.remove(name));
|
|
132
|
+
}
|
|
133
|
+
|
|
44
134
|
function deepClone(obj) {
|
|
45
135
|
return JSON.parse(JSON.stringify(obj));
|
|
46
136
|
}
|
|
@@ -196,7 +286,8 @@ Tree.prototype.bindEvent = function (ele) {
|
|
|
196
286
|
return typeof item === 'string'
|
|
197
287
|
? item
|
|
198
288
|
: Object.assign(Object.assign({}, item), { callback: e => {
|
|
199
|
-
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId]
|
|
289
|
+
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId] && that.nodesById[e.target.nodeId].children &&
|
|
290
|
+
that.nodesById[e.target.nodeId].children.length && that.nodesById[e.target.nodeId].children.length > 0 });
|
|
200
291
|
delete targetOutput.children;
|
|
201
292
|
this.options.parentApi.onItemContextMenuItemClick(Object.assign(Object.assign({}, e), { target: targetOutput, contextMenuItem: item }));
|
|
202
293
|
} });
|
|
@@ -572,19 +663,21 @@ Tree.prototype.createLiEle = function (node, closed) {
|
|
|
572
663
|
if (this.options.parentApi.theOptions.dragAndDropEnabled) {
|
|
573
664
|
li.setAttribute('draggable', 'true');
|
|
574
665
|
li.addEventListener('dragstart', e => {
|
|
575
|
-
|
|
666
|
+
onItemDragStart(li, e);
|
|
576
667
|
});
|
|
577
668
|
li.addEventListener('dragend', e => {
|
|
578
|
-
|
|
669
|
+
onItemDragEnd(li, e);
|
|
579
670
|
});
|
|
580
671
|
li.addEventListener('dragover', e => {
|
|
581
|
-
|
|
672
|
+
onItemDragOver(li, e);
|
|
582
673
|
});
|
|
583
674
|
li.addEventListener('dragleave', e => {
|
|
584
|
-
|
|
675
|
+
onItemDragLeave(li, e);
|
|
585
676
|
});
|
|
586
677
|
li.addEventListener('drop', e => {
|
|
587
|
-
|
|
678
|
+
onItemDrop(li, e, (dragEl, dropEl, position) => {
|
|
679
|
+
this.options.parentApi.itemDropped.emit({ dragEl, dropEl, position });
|
|
680
|
+
});
|
|
588
681
|
});
|
|
589
682
|
}
|
|
590
683
|
return li;
|
|
@@ -18344,7 +18437,7 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
|
|
|
18344
18437
|
const deprecated = getPropertyFromNode(value, 'deprecated', false);
|
|
18345
18438
|
const objToPush = {
|
|
18346
18439
|
id: keyPropFromNode,
|
|
18347
|
-
|
|
18440
|
+
nodeId: keyPropFromNode,
|
|
18348
18441
|
depth,
|
|
18349
18442
|
text: valueTranslatedPropFromNode,
|
|
18350
18443
|
fullpath: fullpathPropFromNode,
|
|
@@ -19182,8 +19275,9 @@ const HierarchizedPickerComponent = class extends HTMLElement {
|
|
|
19182
19275
|
async setNodeAsSelected(id, treeToUpdate, userClick) {
|
|
19183
19276
|
// TODO Temporarily ignores disabled mode for selecting nodes if mode is tree
|
|
19184
19277
|
if (((this.isDisabled && this.optionsManager.getOptions().mode != "tree") && this.shownTree && this.setValueOnClick) ||
|
|
19185
|
-
(this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1))
|
|
19278
|
+
(this.loadedTreeJs.liElementsById[id] && this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1)) {
|
|
19186
19279
|
return;
|
|
19280
|
+
}
|
|
19187
19281
|
if (treeToUpdate.getValues().indexOf(id.toString()) != -1)
|
|
19188
19282
|
return;
|
|
19189
19283
|
this.ignoreOptionsChanges = true;
|
|
@@ -40,6 +40,96 @@ var vanillaContextMenu = createCommonjsModule(function (module, exports) {
|
|
|
40
40
|
|
|
41
41
|
const VanillaContextMenu = /*@__PURE__*/getDefaultExportFromCjs(vanillaContextMenu);
|
|
42
42
|
|
|
43
|
+
let curDraggingItem = null;
|
|
44
|
+
let lastDraggedOverNodeId = null;
|
|
45
|
+
let lastDraggedOverTimeForAscendent = new Date().getTime();
|
|
46
|
+
let lastDraggedOverTimeForLevel = new Date().getTime();
|
|
47
|
+
const acceptableDelayBetweenSimilarActions = 300;
|
|
48
|
+
/**
|
|
49
|
+
* Handles the drag start event.
|
|
50
|
+
*/
|
|
51
|
+
function onItemDragStart(el, e) {
|
|
52
|
+
curDraggingItem = el;
|
|
53
|
+
el.classList.add('dragging');
|
|
54
|
+
e.stopPropagation();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Handles the drag end event.
|
|
58
|
+
*/
|
|
59
|
+
function onItemDragEnd(el, e) {
|
|
60
|
+
el.classList.remove('dragging');
|
|
61
|
+
e.stopPropagation();
|
|
62
|
+
clearDragOverStyles(el.parentElement);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Handles the drag over event.
|
|
66
|
+
*/
|
|
67
|
+
function onItemDragOver(el, e) {
|
|
68
|
+
const now = new Date().getTime();
|
|
69
|
+
if (now - lastDraggedOverTimeForAscendent < 50 && el.dataset.nodeId !== lastDraggedOverNodeId) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
lastDraggedOverTimeForAscendent = now;
|
|
73
|
+
if (el.dataset.nodeId === lastDraggedOverNodeId) {
|
|
74
|
+
if (now - lastDraggedOverTimeForLevel < acceptableDelayBetweenSimilarActions) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
lastDraggedOverTimeForLevel = now;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
lastDraggedOverNodeId = el.dataset.nodeId;
|
|
81
|
+
}
|
|
82
|
+
clearDragOverStyles(el);
|
|
83
|
+
if (el === curDraggingItem) {
|
|
84
|
+
el.classList.remove('dragover');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const pos = getDragOverPosition(el, e);
|
|
88
|
+
el.classList.add(`dragover-${pos}`);
|
|
89
|
+
el.classList.add('dragover');
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Handles the drag leave event.
|
|
95
|
+
*/
|
|
96
|
+
function onItemDragLeave(el, e) {
|
|
97
|
+
clearDragOverStyles(el);
|
|
98
|
+
el.classList.remove('dragover');
|
|
99
|
+
e.stopPropagation();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Handles the drop event.
|
|
103
|
+
*/
|
|
104
|
+
function onItemDrop(el, e, dropCallback) {
|
|
105
|
+
clearDragOverStyles(el);
|
|
106
|
+
el.classList.remove('dragover');
|
|
107
|
+
e.stopPropagation();
|
|
108
|
+
if (curDraggingItem) {
|
|
109
|
+
const pos = getDragOverPosition(el, e);
|
|
110
|
+
dropCallback(curDraggingItem, el, pos);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Determines the drop position based on the mouse event.
|
|
115
|
+
*/
|
|
116
|
+
function getDragOverPosition(el, e) {
|
|
117
|
+
const h = el.offsetHeight;
|
|
118
|
+
const before = h / 4;
|
|
119
|
+
const after = h - before;
|
|
120
|
+
const y = e.offsetY;
|
|
121
|
+
return y <= before ? 'before' : y >= after ? 'after' : 'over';
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Clears the drag-over styles from the element.
|
|
125
|
+
*/
|
|
126
|
+
function clearDragOverStyles(el) {
|
|
127
|
+
if (!el)
|
|
128
|
+
return;
|
|
129
|
+
const prevClasses = Array.from(el.classList).filter(name => name.startsWith('dragover-'));
|
|
130
|
+
prevClasses.forEach(name => el.classList.remove(name));
|
|
131
|
+
}
|
|
132
|
+
|
|
43
133
|
function deepClone(obj) {
|
|
44
134
|
return JSON.parse(JSON.stringify(obj));
|
|
45
135
|
}
|
|
@@ -195,7 +285,8 @@ Tree.prototype.bindEvent = function (ele) {
|
|
|
195
285
|
return typeof item === 'string'
|
|
196
286
|
? item
|
|
197
287
|
: Object.assign(Object.assign({}, item), { callback: e => {
|
|
198
|
-
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId]
|
|
288
|
+
let targetOutput = Object.assign(Object.assign({}, that.nodesById[e.target.nodeId]), { hasChildren: that.nodesById[e.target.nodeId] && that.nodesById[e.target.nodeId].children &&
|
|
289
|
+
that.nodesById[e.target.nodeId].children.length && that.nodesById[e.target.nodeId].children.length > 0 });
|
|
199
290
|
delete targetOutput.children;
|
|
200
291
|
this.options.parentApi.onItemContextMenuItemClick(Object.assign(Object.assign({}, e), { target: targetOutput, contextMenuItem: item }));
|
|
201
292
|
} });
|
|
@@ -571,19 +662,21 @@ Tree.prototype.createLiEle = function (node, closed) {
|
|
|
571
662
|
if (this.options.parentApi.theOptions.dragAndDropEnabled) {
|
|
572
663
|
li.setAttribute('draggable', 'true');
|
|
573
664
|
li.addEventListener('dragstart', e => {
|
|
574
|
-
|
|
665
|
+
onItemDragStart(li, e);
|
|
575
666
|
});
|
|
576
667
|
li.addEventListener('dragend', e => {
|
|
577
|
-
|
|
668
|
+
onItemDragEnd(li, e);
|
|
578
669
|
});
|
|
579
670
|
li.addEventListener('dragover', e => {
|
|
580
|
-
|
|
671
|
+
onItemDragOver(li, e);
|
|
581
672
|
});
|
|
582
673
|
li.addEventListener('dragleave', e => {
|
|
583
|
-
|
|
674
|
+
onItemDragLeave(li, e);
|
|
584
675
|
});
|
|
585
676
|
li.addEventListener('drop', e => {
|
|
586
|
-
|
|
677
|
+
onItemDrop(li, e, (dragEl, dropEl, position) => {
|
|
678
|
+
this.options.parentApi.itemDropped.emit({ dragEl, dropEl, position });
|
|
679
|
+
});
|
|
587
680
|
});
|
|
588
681
|
}
|
|
589
682
|
return li;
|
|
@@ -18343,7 +18436,7 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
|
|
|
18343
18436
|
const deprecated = getPropertyFromNode(value, 'deprecated', false);
|
|
18344
18437
|
const objToPush = {
|
|
18345
18438
|
id: keyPropFromNode,
|
|
18346
|
-
|
|
18439
|
+
nodeId: keyPropFromNode,
|
|
18347
18440
|
depth,
|
|
18348
18441
|
text: valueTranslatedPropFromNode,
|
|
18349
18442
|
fullpath: fullpathPropFromNode,
|
|
@@ -19180,8 +19273,9 @@ const HierarchizedPickerComponent = class {
|
|
|
19180
19273
|
async setNodeAsSelected(id, treeToUpdate, userClick) {
|
|
19181
19274
|
// TODO Temporarily ignores disabled mode for selecting nodes if mode is tree
|
|
19182
19275
|
if (((this.isDisabled && this.optionsManager.getOptions().mode != "tree") && this.shownTree && this.setValueOnClick) ||
|
|
19183
|
-
(this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1))
|
|
19276
|
+
(this.loadedTreeJs.liElementsById[id] && this.loadedTreeJs.liElementsById[id].classList.value && this.loadedTreeJs.liElementsById[id].classList.value.indexOf('readonly_node') != -1)) {
|
|
19184
19277
|
return;
|
|
19278
|
+
}
|
|
19185
19279
|
if (treeToUpdate.getValues().indexOf(id.toString()) != -1)
|
|
19186
19280
|
return;
|
|
19187
19281
|
this.ignoreOptionsChanges = true;
|