mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -05:00
Recurse tree instead of repetition
This commit is contained in:
parent
f20313e7f8
commit
81c83f9dd4
1 changed files with 21 additions and 35 deletions
|
@ -106,15 +106,14 @@
|
||||||
[:span {:key (dm/str shortcut "-" idx)
|
[:span {:key (dm/str shortcut "-" idx)
|
||||||
:class (stl/css :shortcut-key)} sc])])
|
:class (stl/css :shortcut-key)} sc])])
|
||||||
|
|
||||||
(when (> (count children) 1)
|
(when children
|
||||||
[:span {:class (stl/css :submenu-icon)} i/arrow])
|
[:*
|
||||||
|
[:span {:class (stl/css :submenu-icon)} i/arrow]
|
||||||
(when (> (count children) 1)
|
[:ul {:class (stl/css :token-context-submenu)
|
||||||
[:ul {:class (stl/css :token-context-submenu)
|
:ref submenu-ref
|
||||||
:ref submenu-ref
|
:style {:display "none" :left 235}
|
||||||
:style {:display "none" :left 235}
|
:on-context-menu prevent-default}
|
||||||
:on-context-menu prevent-default}
|
children]])])))
|
||||||
children])])))
|
|
||||||
|
|
||||||
(mf/defc menu-separator
|
(mf/defc menu-separator
|
||||||
[]
|
[]
|
||||||
|
@ -474,34 +473,21 @@
|
||||||
(when attribute-actions [:separator])
|
(when attribute-actions [:separator])
|
||||||
default-actions)))
|
default-actions)))
|
||||||
|
|
||||||
(mf/defc token-pill-context-menu
|
(mf/defc context-menu-tree
|
||||||
[context-data]
|
[context-data]
|
||||||
(let [menu-entries (generate-menu-entries context-data)]
|
(let [entries (generate-menu-entries context-data)]
|
||||||
(for [[index {:keys [title action selected? submenu] :as entry}] (d/enumerate menu-entries)]
|
(for [[index {:keys [title action selected? submenu] :as entry}] (d/enumerate entries)]
|
||||||
[:* {:key (str title " " index)}
|
[:* {:key (str title " " index)}
|
||||||
(cond
|
(cond
|
||||||
(= :separator entry) [:& menu-separator]
|
(= :separator entry) [:& menu-separator]
|
||||||
:else
|
submenu [:& menu-entry {:title title}
|
||||||
[:& menu-entry (cond-> {:title title}
|
[:& context-menu-tree (assoc context-data :type submenu)]]
|
||||||
(not submenu) (assoc :on-click action
|
:else [:& menu-entry
|
||||||
;; TODO: Allow selected items wihtout an icon for the context menu
|
{:title title
|
||||||
:icon (mf/html [:div {:class (stl/css-case :empty-icon true
|
:on-click action
|
||||||
:hidden-icon (not selected?))}])
|
:icon (mf/html [:div {:class (stl/css-case :empty-icon true
|
||||||
:selected? selected?))
|
:hidden-icon (not selected?))}])
|
||||||
(when submenu
|
:selected? selected?}])])))
|
||||||
(let [submenu-entries (-> (assoc context-data :type submenu)
|
|
||||||
(generate-menu-entries))]
|
|
||||||
(for [[index {:keys [title action selected?] :as sub-entry}] (d/enumerate submenu-entries)]
|
|
||||||
[:* {:key (str title " " index)}
|
|
||||||
(cond
|
|
||||||
(= :separator sub-entry) [:& menu-separator]
|
|
||||||
:else
|
|
||||||
[:& menu-entry {:key index
|
|
||||||
:title title
|
|
||||||
:on-click action
|
|
||||||
:icon (mf/html [:div {:class (stl/css-case :empty-icon true
|
|
||||||
:hidden-icon (not selected?))}])
|
|
||||||
:selected? selected?}])])))])])))
|
|
||||||
|
|
||||||
(mf/defc token-context-menu
|
(mf/defc token-context-menu
|
||||||
[]
|
[]
|
||||||
|
@ -534,5 +520,5 @@
|
||||||
:on-context-menu prevent-default}
|
:on-context-menu prevent-default}
|
||||||
(when (= :token (:type mdata))
|
(when (= :token (:type mdata))
|
||||||
[:ul {:class (stl/css :context-list)}
|
[:ul {:class (stl/css :context-list)}
|
||||||
[:& token-pill-context-menu {:token token
|
[:& context-menu-tree {:token token
|
||||||
:selected-shapes selected-shapes}]])]]))
|
:selected-shapes selected-shapes}]])]]))
|
||||||
|
|
Loading…
Add table
Reference in a new issue