mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 17:00:36 -05:00
🐛 Disable boolean operations when selecting invalid shapes
This commit is contained in:
parent
85f8e77928
commit
5547383434
3 changed files with 48 additions and 20 deletions
|
@ -1324,10 +1324,33 @@
|
||||||
(ptk/reify ::show-context-menu
|
(ptk/reify ::show-context-menu
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [mdata (cond-> params
|
(let [selected (wsh/lookup-selected state)
|
||||||
(some? shape)
|
objects (wsh/lookup-page-objects state)
|
||||||
(assoc :selected
|
|
||||||
(wsh/lookup-selected state)))]
|
selected-with-children
|
||||||
|
(into []
|
||||||
|
(mapcat #(cp/get-object-with-children % objects))
|
||||||
|
selected)
|
||||||
|
|
||||||
|
head (get objects (first selected))
|
||||||
|
|
||||||
|
first-not-group-like?
|
||||||
|
(and (= (count selected) 1)
|
||||||
|
(not (contains? #{:group :bool} (:type head))))
|
||||||
|
|
||||||
|
has-invalid-shapes? (->> selected-with-children
|
||||||
|
(some (comp #{:frame :text} :type)))
|
||||||
|
|
||||||
|
disable-booleans? (or (empty? selected) has-invalid-shapes? first-not-group-like?)
|
||||||
|
disable-flatten? (or (empty? selected) has-invalid-shapes?)
|
||||||
|
|
||||||
|
mdata
|
||||||
|
(-> params
|
||||||
|
(assoc :disable-booleans? disable-booleans?)
|
||||||
|
(assoc :disable-flatten? disable-flatten?)
|
||||||
|
(cond-> (some? shape)
|
||||||
|
(assoc :selected selected)))]
|
||||||
|
|
||||||
(assoc-in state [:workspace-local :context-menu] mdata)))))
|
(assoc-in state [:workspace-local :context-menu] mdata)))))
|
||||||
|
|
||||||
(defn show-shape-context-menu
|
(defn show-shape-context-menu
|
||||||
|
|
|
@ -87,15 +87,15 @@
|
||||||
|
|
||||||
(mf/defc shape-context-menu
|
(mf/defc shape-context-menu
|
||||||
[{:keys [mdata] :as props}]
|
[{:keys [mdata] :as props}]
|
||||||
(let [{:keys [id] :as shape} (:shape mdata)
|
(let [{:keys [shape selected disable-booleans? disable-flatten?]} mdata
|
||||||
selected (:selected mdata)
|
{:keys [id type]} shape
|
||||||
|
|
||||||
single? (= (count selected) 1)
|
single? (= (count selected) 1)
|
||||||
multiple? (> (count selected) 1)
|
multiple? (> (count selected) 1)
|
||||||
editable-shape? (#{:group :text :path} (:type shape))
|
editable-shape? (#{:group :text :path} type)
|
||||||
|
|
||||||
is-group? (and (some? shape) (= :group (:type shape)))
|
is-group? (and (some? shape) (= :group type))
|
||||||
is-bool? (and (some? shape) (= :bool (:type shape)))
|
is-bool? (and (some? shape) (= :bool type))
|
||||||
|
|
||||||
options (mf/deref refs/workspace-page-options)
|
options (mf/deref refs/workspace-page-options)
|
||||||
flows (:flows options)
|
flows (:flows options)
|
||||||
|
@ -235,10 +235,12 @@
|
||||||
:shortcut (sc/get-tooltip :start-editing)
|
:shortcut (sc/get-tooltip :start-editing)
|
||||||
:on-click do-start-editing}])
|
:on-click do-start-editing}])
|
||||||
|
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.transform-to-path")
|
(when-not disable-flatten?
|
||||||
:on-click do-transform-to-path}]
|
[:& menu-entry {:title (tr "workspace.shape.menu.transform-to-path")
|
||||||
|
:on-click do-transform-to-path}])
|
||||||
|
|
||||||
(when (or multiple? (and single? (or is-group? is-bool?)))
|
(when (and (not disable-booleans?)
|
||||||
|
(or multiple? (and single? (or is-group? is-bool?))))
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.path")}
|
[:& menu-entry {:title (tr "workspace.shape.menu.path")}
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.union")
|
[:& menu-entry {:title (tr "workspace.shape.menu.union")
|
||||||
:shortcut (sc/get-tooltip :boolean-union)
|
:shortcut (sc/get-tooltip :boolean-union)
|
||||||
|
@ -253,7 +255,7 @@
|
||||||
:shortcut (sc/get-tooltip :boolean-exclude)
|
:shortcut (sc/get-tooltip :boolean-exclude)
|
||||||
:on-click (set-bool :exclude)}]
|
:on-click (set-bool :exclude)}]
|
||||||
|
|
||||||
(when (and single? is-bool?)
|
(when (and single? is-bool? (not disable-flatten?))
|
||||||
[:*
|
[:*
|
||||||
[:& menu-separator]
|
[:& menu-separator]
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.flatten")
|
[:& menu-entry {:title (tr "workspace.shape.menu.flatten")
|
||||||
|
|
|
@ -17,19 +17,22 @@
|
||||||
(mf/defc booleans-options
|
(mf/defc booleans-options
|
||||||
[]
|
[]
|
||||||
(let [selected (mf/deref refs/selected-objects)
|
(let [selected (mf/deref refs/selected-objects)
|
||||||
|
selected-with-children (mf/deref refs/selected-objects-with-children)
|
||||||
|
|
||||||
disabled-bool-btns
|
has-invalid-shapes? (->> selected-with-children
|
||||||
(or (empty? selected)
|
(some (comp #{:frame :text} :type)))
|
||||||
(and (<= (count selected) 1)
|
|
||||||
(not (contains? #{:group :bool} (:type (first selected))))))
|
|
||||||
|
|
||||||
disabled-flatten
|
first-not-group-like?
|
||||||
(empty? selected)
|
(and (= (count selected) 1)
|
||||||
|
(not (contains? #{:group :bool} (:type (first selected)))))
|
||||||
|
|
||||||
|
disabled-bool-btns (or (empty? selected) has-invalid-shapes? first-not-group-like?)
|
||||||
|
disabled-flatten (or (empty? selected) has-invalid-shapes?)
|
||||||
|
|
||||||
head (first selected)
|
head (first selected)
|
||||||
is-group? (and (some? head) (= :group (:type head)))
|
is-group? (and (some? head) (= :group (:type head)))
|
||||||
is-bool? (and (some? head) (= :bool (:type head)))
|
is-bool? (and (some? head) (= :bool (:type head)))
|
||||||
head-bool-type (and (some? head) (:bool-type head))
|
head-bool-type (and (some? head) is-bool? (:bool-type head))
|
||||||
|
|
||||||
set-bool
|
set-bool
|
||||||
(fn [bool-type]
|
(fn [bool-type]
|
||||||
|
|
Loading…
Reference in a new issue