tree: dragging: add placeholder and display a thin ghost at new index

This commit is contained in:
bordun 2021-04-26 19:52:51 +02:00
parent 8568c72a8b
commit 51791ea6d8
2 changed files with 34 additions and 3 deletions

View file

@ -175,17 +175,26 @@ class UiTree extends UiWidget {
// sortable lists
DOM.each(this.list, 'ol', (el)=>{
let placeholder = null
this.sortables.push(new Sortable(el, {
group: {
name: 'group',
pull: (to, from)=>from.el.dataset.childrenType === to.el.dataset.childrenType || to.el.dataset.childrenType === '',
put: (to, from)=>from.el.dataset.childrenType === to.el.dataset.childrenType || to.el.dataset.childrenType === '',
},
onEnd: this.sortCallback,
onEnd: (e)=>{
e.from.removeChild(placeholder)
placeholder = null
if (e.from === e.to && e.newIndex > e.oldIndex) e.newIndex--
this.sortCallback(e)
},
setData: (dataTransfer)=>{
dataTransfer.setDragImage(this.dragDummy, 0, 0)
},
onStart: function (event) {
placeholder = event.from.insertBefore(event.clone.cloneNode(true), event.from.childNodes[event.oldIndex])
placeholder.style.display = 'block'
},
}))
})

View file

@ -35,10 +35,32 @@
position: relative;user-select: none;
> ol {
display: none;
// display: none;
display: block;
height: 0rem;
> li {
display: none;
}
}
&.expanded > ol {
display: block;
// min-height: 8rem;
opacity: 1;
height: auto;
> li {
display: list-item;
}
}
&.sortable-ghost {
height: 2rem;
margin-bottom: 6rem;
margin-top: 4rem;
color: transparent;
overflow: hidden;
display: list-item!important
}
> i {