mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
Show attribute actions only when something is selected
This commit is contained in:
parent
310033fd75
commit
5e911d814c
1 changed files with 30 additions and 28 deletions
|
@ -260,12 +260,9 @@
|
||||||
(generic-attribute-actions #{:x} "X" context-data)
|
(generic-attribute-actions #{:x} "X" context-data)
|
||||||
(generic-attribute-actions #{:y} "Y" context-data)))}))
|
(generic-attribute-actions #{:y} "Y" context-data)))}))
|
||||||
|
|
||||||
(defn generate-menu-entries [{:keys [type token] :as context-data}]
|
(defn default-actions [{:keys [token]}]
|
||||||
(let [{:keys [modal]} (get wtc/token-types (:type token))
|
(let [{:keys [modal]} (get wtc/token-types token)]
|
||||||
with-actions (get shape-attribute-actions-map (or type (:type token)))
|
[{:title "Delete Token"
|
||||||
attribute-actions (when with-actions
|
|
||||||
(with-actions context-data))
|
|
||||||
default-actions [{:title "Delete Token"
|
|
||||||
:action #(st/emit! (dt/delete-token (:id token)))}
|
:action #(st/emit! (dt/delete-token (:id token)))}
|
||||||
{:title "Duplicate Token"
|
{:title "Duplicate Token"
|
||||||
:action #(st/emit! (dt/duplicate-token (:id token)))}
|
:action #(st/emit! (dt/duplicate-token (:id token)))}
|
||||||
|
@ -279,11 +276,15 @@
|
||||||
:y (.-clientY ^js event)
|
:y (.-clientY ^js event)
|
||||||
:position :right
|
:position :right
|
||||||
:fields fields
|
:fields fields
|
||||||
:token token})))}]]
|
:token token})))}]))
|
||||||
|
|
||||||
|
(defn selection-actions [{:keys [type token] :as context-data}]
|
||||||
|
(let [with-actions (get shape-attribute-actions-map (or type (:type token)))
|
||||||
|
attribute-actions (with-actions context-data)]
|
||||||
(concat
|
(concat
|
||||||
attribute-actions
|
attribute-actions
|
||||||
(when attribute-actions [:separator])
|
[:separator]
|
||||||
default-actions)))
|
(default-actions context-data))))
|
||||||
|
|
||||||
;; Components ------------------------------------------------------------------
|
;; Components ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -340,8 +341,10 @@
|
||||||
children]])]))
|
children]])]))
|
||||||
|
|
||||||
(mf/defc context-menu-tree
|
(mf/defc context-menu-tree
|
||||||
[context-data]
|
[{:keys [selected-shapes] :as context-data}]
|
||||||
(let [entries (generate-menu-entries context-data)]
|
(let [entries (if (seq selected-shapes)
|
||||||
|
(selection-actions context-data)
|
||||||
|
(default-actions context-data))]
|
||||||
(for [[index {:keys [title action selected? submenu] :as entry}] (d/enumerate entries)]
|
(for [[index {:keys [title action selected? submenu] :as entry}] (d/enumerate entries)]
|
||||||
[:* {:key (str title " " index)}
|
[:* {:key (str title " " index)}
|
||||||
(cond
|
(cond
|
||||||
|
@ -382,7 +385,6 @@
|
||||||
:ref dropdown-ref
|
:ref dropdown-ref
|
||||||
:style {:top top :left left}
|
:style {:top top :left left}
|
||||||
:on-context-menu prevent-default}
|
:on-context-menu prevent-default}
|
||||||
(when (= :token (:type mdata))
|
|
||||||
[:ul {:class (stl/css :context-list)}
|
[:ul {:class (stl/css :context-list)}
|
||||||
[:& context-menu-tree {:token token
|
[:& context-menu-tree {:token token
|
||||||
:selected-shapes selected-shapes}]])]]))
|
:selected-shapes selected-shapes}]]]]))
|
||||||
|
|
Loading…
Reference in a new issue