diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 449bc5956..23629fb39 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1324,10 +1324,33 @@ (ptk/reify ::show-context-menu ptk/UpdateEvent (update [_ state] - (let [mdata (cond-> params - (some? shape) - (assoc :selected - (wsh/lookup-selected state)))] + (let [selected (wsh/lookup-selected state) + objects (wsh/lookup-page-objects 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))))) (defn show-shape-context-menu diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 6833c4070..9cdae0466 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -87,15 +87,15 @@ (mf/defc shape-context-menu [{:keys [mdata] :as props}] - (let [{:keys [id] :as shape} (:shape mdata) - selected (:selected mdata) + (let [{:keys [shape selected disable-booleans? disable-flatten?]} mdata + {:keys [id type]} shape single? (= (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-bool? (and (some? shape) (= :bool (:type shape))) + is-group? (and (some? shape) (= :group type)) + is-bool? (and (some? shape) (= :bool type)) options (mf/deref refs/workspace-page-options) flows (:flows options) @@ -235,10 +235,12 @@ :shortcut (sc/get-tooltip :start-editing) :on-click do-start-editing}]) - [:& menu-entry {:title (tr "workspace.shape.menu.transform-to-path") - :on-click do-transform-to-path}] + (when-not disable-flatten? + [:& 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.union") :shortcut (sc/get-tooltip :boolean-union) @@ -253,7 +255,7 @@ :shortcut (sc/get-tooltip :boolean-exclude) :on-click (set-bool :exclude)}] - (when (and single? is-bool?) + (when (and single? is-bool? (not disable-flatten?)) [:* [:& menu-separator] [:& menu-entry {:title (tr "workspace.shape.menu.flatten") diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/booleans.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/booleans.cljs index 64b287417..80b2be852 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/booleans.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/booleans.cljs @@ -17,19 +17,22 @@ (mf/defc booleans-options [] (let [selected (mf/deref refs/selected-objects) + selected-with-children (mf/deref refs/selected-objects-with-children) - disabled-bool-btns - (or (empty? selected) - (and (<= (count selected) 1) - (not (contains? #{:group :bool} (:type (first selected)))))) + has-invalid-shapes? (->> selected-with-children + (some (comp #{:frame :text} :type))) - disabled-flatten - (empty? selected) + first-not-group-like? + (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) is-group? (and (some? head) (= :group (: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 (fn [bool-type]