mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 09:08:31 -05:00
♻️ Rename custom data types in drag&drop
This commit is contained in:
parent
374653d9f6
commit
797ba3ef9b
5 changed files with 16 additions and 16 deletions
|
@ -100,7 +100,7 @@
|
|||
on-drag-start
|
||||
(mf/use-callback
|
||||
(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})
|
||||
(dnd/set-allowed-effect! event "move")))]
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@
|
|||
(st/emit! (dwc/toggle-collapse (:id item)))))
|
||||
|
||||
[dprops dref] (hooks/use-sortable
|
||||
:data-type "app/layer"
|
||||
:data-type "penpot/layer"
|
||||
:on-drop on-drop
|
||||
:on-drag on-drag
|
||||
:on-hold on-hold
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
|
||||
[dprops dref]
|
||||
(hooks/use-sortable
|
||||
:data-type "app/page"
|
||||
:data-type "penpot/page"
|
||||
:on-drop on-drop
|
||||
:data {:id id
|
||||
:index index
|
||||
|
|
|
@ -578,8 +578,8 @@
|
|||
on-drag-enter
|
||||
(mf/use-callback
|
||||
(fn [e]
|
||||
(when (or (dnd/has-type? e "app/shape")
|
||||
(dnd/has-type? e "app/component")
|
||||
(when (or (dnd/has-type? e "penpot/shape")
|
||||
(dnd/has-type? e "penpot/component")
|
||||
(dnd/has-type? e "Files")
|
||||
(dnd/has-type? e "text/uri-list")
|
||||
(dnd/has-type? e "text/asset-id"))
|
||||
|
@ -588,8 +588,8 @@
|
|||
on-drag-over
|
||||
(mf/use-callback
|
||||
(fn [e]
|
||||
(when (or (dnd/has-type? e "app/shape")
|
||||
(dnd/has-type? e "app/component")
|
||||
(when (or (dnd/has-type? e "penpot/shape")
|
||||
(dnd/has-type? e "penpot/component")
|
||||
(dnd/has-type? e "Files")
|
||||
(dnd/has-type? e "text/uri-list")
|
||||
(dnd/has-type? e "text/asset-id"))
|
||||
|
@ -610,8 +610,8 @@
|
|||
asset-name (dnd/get-data event "text/asset-name")
|
||||
asset-type (dnd/get-data event "text/asset-type")]
|
||||
(cond
|
||||
(dnd/has-type? event "app/shape")
|
||||
(let [shape (dnd/get-data event "app/shape")
|
||||
(dnd/has-type? event "penpot/shape")
|
||||
(let [shape (dnd/get-data event "penpot/shape")
|
||||
final-x (- (:x viewport-coord) (/ (:width shape) 2))
|
||||
final-y (- (:y viewport-coord) (/ (:height shape) 2))]
|
||||
(st/emit! (dw/add-shape (-> shape
|
||||
|
@ -619,8 +619,8 @@
|
|||
(assoc :x final-x)
|
||||
(assoc :y final-y)))))
|
||||
|
||||
(dnd/has-type? event "app/component")
|
||||
(let [{:keys [component file-id]} (dnd/get-data event "app/component")
|
||||
(dnd/has-type? event "penpot/component")
|
||||
(let [{:keys [component file-id]} (dnd/get-data event "penpot/component")
|
||||
shape (get-in component [:objects (:id component)])
|
||||
final-x (- (:x viewport-coord) (/ (:width shape) 2))
|
||||
final-y (- (:y viewport-coord) (/ (:height shape) 2))]
|
||||
|
|
|
@ -55,11 +55,11 @@
|
|||
|
||||
(defn set-data!
|
||||
([e data]
|
||||
(set-data! e "app/data" data))
|
||||
(set-data! e "penpot/data" data))
|
||||
([e data-type data]
|
||||
(let [dt (.-dataTransfer e)]
|
||||
(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 data))
|
||||
e)))
|
||||
|
@ -100,10 +100,10 @@
|
|||
|
||||
(defn get-data
|
||||
([e]
|
||||
(get-data e "app/data"))
|
||||
(get-data e "penpot/data"))
|
||||
([e data-type]
|
||||
(let [dt (.-dataTransfer e)]
|
||||
(if (or (str/starts-with? data-type "app")
|
||||
(if (or (str/starts-with? data-type "penpot")
|
||||
(= data-type "application/json"))
|
||||
(t/decode (.getData dt data-type))
|
||||
(.getData dt data-type)))))
|
||||
|
|
Loading…
Add table
Reference in a new issue