♻️ Rename custom data types in drag&drop

This commit is contained in:
Andrés Moya 2021-03-15 13:30:30 +01:00 committed by Andrey Antukh
parent 374653d9f6
commit 797ba3ef9b
5 changed files with 16 additions and 16 deletions

View file

@ -100,7 +100,7 @@
on-drag-start on-drag-start
(mf/use-callback (mf/use-callback
(fn [component event] (fn [component event]
(dnd/set-data! event "app/component" {:file-id file-id (dnd/set-data! event "penpot/component" {:file-id file-id
:component component}) :component component})
(dnd/set-allowed-effect! event "move")))] (dnd/set-allowed-effect! event "move")))]

View file

@ -181,7 +181,7 @@
(st/emit! (dwc/toggle-collapse (:id item))))) (st/emit! (dwc/toggle-collapse (:id item)))))
[dprops dref] (hooks/use-sortable [dprops dref] (hooks/use-sortable
:data-type "app/layer" :data-type "penpot/layer"
:on-drop on-drop :on-drop on-drop
:on-drag on-drag :on-drag on-drag
:on-hold on-hold :on-hold on-hold

View file

@ -99,7 +99,7 @@
[dprops dref] [dprops dref]
(hooks/use-sortable (hooks/use-sortable
:data-type "app/page" :data-type "penpot/page"
:on-drop on-drop :on-drop on-drop
:data {:id id :data {:id id
:index index :index index

View file

@ -578,8 +578,8 @@
on-drag-enter on-drag-enter
(mf/use-callback (mf/use-callback
(fn [e] (fn [e]
(when (or (dnd/has-type? e "app/shape") (when (or (dnd/has-type? e "penpot/shape")
(dnd/has-type? e "app/component") (dnd/has-type? e "penpot/component")
(dnd/has-type? e "Files") (dnd/has-type? e "Files")
(dnd/has-type? e "text/uri-list") (dnd/has-type? e "text/uri-list")
(dnd/has-type? e "text/asset-id")) (dnd/has-type? e "text/asset-id"))
@ -588,8 +588,8 @@
on-drag-over on-drag-over
(mf/use-callback (mf/use-callback
(fn [e] (fn [e]
(when (or (dnd/has-type? e "app/shape") (when (or (dnd/has-type? e "penpot/shape")
(dnd/has-type? e "app/component") (dnd/has-type? e "penpot/component")
(dnd/has-type? e "Files") (dnd/has-type? e "Files")
(dnd/has-type? e "text/uri-list") (dnd/has-type? e "text/uri-list")
(dnd/has-type? e "text/asset-id")) (dnd/has-type? e "text/asset-id"))
@ -610,8 +610,8 @@
asset-name (dnd/get-data event "text/asset-name") asset-name (dnd/get-data event "text/asset-name")
asset-type (dnd/get-data event "text/asset-type")] asset-type (dnd/get-data event "text/asset-type")]
(cond (cond
(dnd/has-type? event "app/shape") (dnd/has-type? event "penpot/shape")
(let [shape (dnd/get-data event "app/shape") (let [shape (dnd/get-data event "penpot/shape")
final-x (- (:x viewport-coord) (/ (:width shape) 2)) final-x (- (:x viewport-coord) (/ (:width shape) 2))
final-y (- (:y viewport-coord) (/ (:height shape) 2))] final-y (- (:y viewport-coord) (/ (:height shape) 2))]
(st/emit! (dw/add-shape (-> shape (st/emit! (dw/add-shape (-> shape
@ -619,8 +619,8 @@
(assoc :x final-x) (assoc :x final-x)
(assoc :y final-y))))) (assoc :y final-y)))))
(dnd/has-type? event "app/component") (dnd/has-type? event "penpot/component")
(let [{:keys [component file-id]} (dnd/get-data event "app/component") (let [{:keys [component file-id]} (dnd/get-data event "penpot/component")
shape (get-in component [:objects (:id component)]) shape (get-in component [:objects (:id component)])
final-x (- (:x viewport-coord) (/ (:width shape) 2)) final-x (- (:x viewport-coord) (/ (:width shape) 2))
final-y (- (:y viewport-coord) (/ (:height shape) 2))] final-y (- (:y viewport-coord) (/ (:height shape) 2))]

View file

@ -55,11 +55,11 @@
(defn set-data! (defn set-data!
([e data] ([e data]
(set-data! e "app/data" data)) (set-data! e "penpot/data" data))
([e data-type data] ([e data-type data]
(let [dt (.-dataTransfer e)] (let [dt (.-dataTransfer e)]
(if (or (str/starts-with? data-type "application") (if (or (str/starts-with? data-type "application")
(str/starts-with? data-type "app")) (str/starts-with? data-type "penpot"))
(.setData dt data-type (t/encode data)) (.setData dt data-type (t/encode data))
(.setData dt data-type data)) (.setData dt data-type data))
e))) e)))
@ -100,10 +100,10 @@
(defn get-data (defn get-data
([e] ([e]
(get-data e "app/data")) (get-data e "penpot/data"))
([e data-type] ([e data-type]
(let [dt (.-dataTransfer e)] (let [dt (.-dataTransfer e)]
(if (or (str/starts-with? data-type "app") (if (or (str/starts-with? data-type "penpot")
(= data-type "application/json")) (= data-type "application/json"))
(t/decode (.getData dt data-type)) (t/decode (.getData dt data-type))
(.getData dt data-type))))) (.getData dt data-type)))))