From 51791ea6d8451a16eb46fb11768e4dc7bf72678e Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 26 Apr 2021 19:52:51 +0200 Subject: [PATCH] tree: dragging: add placeholder and display a thin ghost at new index --- src/client/ui/ui-tree.js | 13 +++++++++++-- src/scss/ui/tree.scss | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/client/ui/ui-tree.js b/src/client/ui/ui-tree.js index d4b7df4e..942ae41f 100644 --- a/src/client/ui/ui-tree.js +++ b/src/client/ui/ui-tree.js @@ -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' + }, })) }) diff --git a/src/scss/ui/tree.scss b/src/scss/ui/tree.scss index 88e6ccf3..71dcb91d 100644 --- a/src/scss/ui/tree.scss +++ b/src/scss/ui/tree.scss @@ -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 {