0
Fork 0
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:
Florian Schroedl 2024-07-24 14:49:39 +02:00
parent 310033fd75
commit 5e911d814c

View file

@ -260,30 +260,31 @@
(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 :action #(st/emit! (dt/delete-token (:id token)))}
(with-actions context-data)) {:title "Duplicate Token"
default-actions [{:title "Delete Token" :action #(st/emit! (dt/duplicate-token (:id token)))}
:action #(st/emit! (dt/delete-token (:id token)))} {:title "Edit Token"
{:title "Duplicate Token" :action (fn [event]
:action #(st/emit! (dt/duplicate-token (:id token)))} (let [{:keys [key fields]} modal
{:title "Edit Token" token (dt/get-token-data-from-token-id (:id token))]
:action (fn [event] (st/emit! dt/hide-token-context-menu)
(let [{:keys [key fields]} modal (dom/stop-propagation event)
token (dt/get-token-data-from-token-id (:id token))] (modal/show! key {:x (.-clientX ^js event)
(st/emit! dt/hide-token-context-menu) :y (.-clientY ^js event)
(dom/stop-propagation event) :position :right
(modal/show! key {:x (.-clientX ^js event) :fields fields
:y (.-clientY ^js event) :token token})))}]))
:position :right
:fields fields (defn selection-actions [{:keys [type token] :as context-data}]
:token token})))}]] (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}]])]]))