Allow to drop shape inside frames or groups in layers panel

This commit is contained in:
Andrés Moya 2020-05-20 14:07:59 +02:00
parent 0f7b33837c
commit 6cb4822842
4 changed files with 45 additions and 27 deletions

View file

@ -85,8 +85,20 @@
(set! (.-src img) imd)
img))
(defn drop-side
[height ypos detect-center?]
(let [thold (/ height 2)
thold1 (* height 0.2)
thold2 (* height 0.8)]
(if detect-center?
(cond
(< ypos thold1) :top
(> ypos thold2) :bot
:else :center)
(if (> ypos thold) :bot :top))))
(defn use-sortable
[& {:keys [type data on-drop on-drag] :as opts}]
[& {:keys [type data on-drop on-drag detect-center?] :as opts}]
(let [ref (mf/use-ref)
state (mf/use-state {})
@ -115,8 +127,7 @@
dtrans (unchecked-get event "dataTransfer")
ypos (unchecked-get event "offsetY")
height (unchecked-get target "clientHeight")
thold (/ height 2)
side (if (> ypos thold) :bot :top)]
side (drop-side height ypos detect-center?)]
(set! (.-dropEffect dtrans) "move")
(set! (.-effectAllowed dtrans) "move")
@ -159,8 +170,7 @@
ypos (unchecked-get event "offsetY")
height (unchecked-get target "clientHeight")
thold (/ height 2)
side (if (> ypos thold) :bot :top)]
side (drop-side height ypos detect-center?)]
;; TODO: seems unnecessary
(swap! state (fn [state]