mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 07:01:38 +02:00
🐛 Fix allow modify component copy structure under some circumstances
This commit is contained in:
parent
8363b86cfa
commit
38b72abf32
2 changed files with 66 additions and 56 deletions
|
@ -353,13 +353,14 @@
|
||||||
(ptk/reify ::create-artboard-from-selection
|
(ptk/reify ::create-artboard-from-selection
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (wsh/lookup-selected state)
|
selected (->> (wsh/lookup-selected state)
|
||||||
selected (cfh/clean-loops objects selected)
|
(cfh/clean-loops objects)
|
||||||
|
(remove #(ctn/has-any-copy-parent? objects (get objects %))))
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it page-id)
|
changes (-> (pcb/empty-changes it page-id)
|
||||||
(pcb/with-objects objects))
|
(pcb/with-objects objects))
|
||||||
|
|
||||||
[frame-shape changes]
|
[frame-shape changes]
|
||||||
(cfsh/prepare-create-artboard-from-selection changes
|
(cfsh/prepare-create-artboard-from-selection changes
|
||||||
|
|
|
@ -228,48 +228,54 @@
|
||||||
(mf/defc context-menu-group
|
(mf/defc context-menu-group
|
||||||
[{:keys [shapes]}]
|
[{:keys [shapes]}]
|
||||||
|
|
||||||
(let [multiple? (> (count shapes) 1)
|
(let [multiple? (> (count shapes) 1)
|
||||||
single? (= (count shapes) 1)
|
single? (= (count shapes) 1)
|
||||||
do-create-artboard-from-selection #(st/emit! (dwsh/create-artboard-from-selection))
|
|
||||||
|
objects (deref refs/workspace-page-objects)
|
||||||
|
any-in-copy? (some true? (map #(ctn/has-any-copy-parent? objects %) shapes))
|
||||||
|
|
||||||
;; components can't be ungrouped
|
;; components can't be ungrouped
|
||||||
has-frame? (->> shapes (d/seek #(and (cfh/frame-shape? %) (not (ctk/instance-head? %)))))
|
has-frame? (->> shapes (d/seek #(and (cfh/frame-shape? %) (not (ctk/instance-head? %)))))
|
||||||
has-group? (->> shapes (d/seek #(and (cfh/group-shape? %) (not (ctk/instance-head? %)))))
|
has-group? (->> shapes (d/seek #(and (cfh/group-shape? %) (not (ctk/instance-head? %)))))
|
||||||
has-bool? (->> shapes (d/seek cfh/bool-shape?))
|
has-bool? (->> shapes (d/seek cfh/bool-shape?))
|
||||||
has-mask? (->> shapes (d/seek :masked-group))
|
has-mask? (->> shapes (d/seek :masked-group))
|
||||||
|
|
||||||
is-group? (and single? has-group?)
|
is-group? (and single? has-group?)
|
||||||
is-bool? (and single? has-bool?)
|
is-bool? (and single? has-bool?)
|
||||||
|
|
||||||
do-create-group #(st/emit! dw/group-selected)
|
do-create-group #(st/emit! dw/group-selected)
|
||||||
do-mask-group #(st/emit! dw/mask-group)
|
do-mask-group #(st/emit! dw/mask-group)
|
||||||
do-remove-group #(st/emit! dw/ungroup-selected)
|
do-remove-group #(st/emit! dw/ungroup-selected)
|
||||||
do-unmask-group #(st/emit! dw/unmask-group)]
|
do-unmask-group #(st/emit! dw/unmask-group)
|
||||||
|
do-create-artboard-from-selection
|
||||||
|
#(st/emit! (dwsh/create-artboard-from-selection))]
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
(when (or has-bool? has-group? has-mask? has-frame?)
|
(when (not any-in-copy?)
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.ungroup")
|
[:*
|
||||||
:shortcut (sc/get-tooltip :ungroup)
|
(when (or has-bool? has-group? has-mask? has-frame?)
|
||||||
:on-click do-remove-group}])
|
[:& menu-entry {:title (tr "workspace.shape.menu.ungroup")
|
||||||
|
:shortcut (sc/get-tooltip :ungroup)
|
||||||
|
:on-click do-remove-group}])
|
||||||
|
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.group")
|
[:& menu-entry {:title (tr "workspace.shape.menu.group")
|
||||||
:shortcut (sc/get-tooltip :group)
|
:shortcut (sc/get-tooltip :group)
|
||||||
:on-click do-create-group}]
|
:on-click do-create-group}]
|
||||||
|
|
||||||
(when (or multiple? (and is-group? (not has-mask?)) is-bool?)
|
(when (or multiple? (and is-group? (not has-mask?)) is-bool?)
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.mask")
|
[:& menu-entry {:title (tr "workspace.shape.menu.mask")
|
||||||
:shortcut (sc/get-tooltip :mask)
|
:shortcut (sc/get-tooltip :mask)
|
||||||
:on-click do-mask-group}])
|
:on-click do-mask-group}])
|
||||||
|
|
||||||
(when has-mask?
|
(when has-mask?
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.unmask")
|
[:& menu-entry {:title (tr "workspace.shape.menu.unmask")
|
||||||
:shortcut (sc/get-tooltip :unmask)
|
:shortcut (sc/get-tooltip :unmask)
|
||||||
:on-click do-unmask-group}])
|
:on-click do-unmask-group}])
|
||||||
|
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.create-artboard-from-selection")
|
[:& menu-entry {:title (tr "workspace.shape.menu.create-artboard-from-selection")
|
||||||
:shortcut (sc/get-tooltip :artboard-selection)
|
:shortcut (sc/get-tooltip :artboard-selection)
|
||||||
:on-click do-create-artboard-from-selection}]
|
:on-click do-create-artboard-from-selection}]
|
||||||
[:& menu-separator]]))
|
[:& menu-separator]])]))
|
||||||
|
|
||||||
(mf/defc context-focus-mode-menu
|
(mf/defc context-focus-mode-menu
|
||||||
[{:keys []}]
|
[{:keys []}]
|
||||||
|
@ -391,7 +397,9 @@
|
||||||
(mf/defc context-menu-layout
|
(mf/defc context-menu-layout
|
||||||
{::mf/props :obj}
|
{::mf/props :obj}
|
||||||
[{:keys [shapes]}]
|
[{:keys [shapes]}]
|
||||||
(let [single? (= (count shapes) 1)
|
(let [single? (= (count shapes) 1)
|
||||||
|
objects (deref refs/workspace-page-objects)
|
||||||
|
any-in-copy? (some true? (map #(ctn/has-any-copy-parent? objects %) shapes))
|
||||||
|
|
||||||
has-flex?
|
has-flex?
|
||||||
(and single? (every? ctl/flex-layout? shapes))
|
(and single? (every? ctl/flex-layout? shapes))
|
||||||
|
@ -414,29 +422,30 @@
|
||||||
(fn [_event]
|
(fn [_event]
|
||||||
(let [ids (map :id shapes)]
|
(let [ids (map :id shapes)]
|
||||||
(st/emit! (dwsl/remove-layout ids)))))]
|
(st/emit! (dwsl/remove-layout ids)))))]
|
||||||
|
[:*
|
||||||
|
(when (not any-in-copy?)
|
||||||
|
(if (or ^boolean has-flex?
|
||||||
|
^boolean has-grid?)
|
||||||
|
[:div
|
||||||
|
[:& menu-separator]
|
||||||
|
(if has-flex?
|
||||||
|
[:& menu-entry {:title (tr "workspace.shape.menu.remove-flex")
|
||||||
|
:shortcut (sc/get-tooltip :toggle-layout-flex)
|
||||||
|
:on-click on-remove-layout}]
|
||||||
|
[:& menu-entry {:title (tr "workspace.shape.menu.remove-grid")
|
||||||
|
:shortcut (sc/get-tooltip :toggle-layout-grid)
|
||||||
|
:on-click on-remove-layout}])]
|
||||||
|
|
||||||
(if (or ^boolean has-flex?
|
[:div
|
||||||
^boolean has-grid?)
|
[:& menu-separator]
|
||||||
[:div
|
[:& menu-entry {:title (tr "workspace.shape.menu.add-flex")
|
||||||
[:& menu-separator]
|
:shortcut (sc/get-tooltip :toggle-layout-flex)
|
||||||
(if has-flex?
|
:value "flex"
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.remove-flex")
|
:on-click on-add-layout}]
|
||||||
:shortcut (sc/get-tooltip :toggle-layout-flex)
|
[:& menu-entry {:title (tr "workspace.shape.menu.add-grid")
|
||||||
:on-click on-remove-layout}]
|
:shortcut (sc/get-tooltip :toggle-layout-grid)
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.remove-grid")
|
:value "grid"
|
||||||
:shortcut (sc/get-tooltip :toggle-layout-grid)
|
:on-click on-add-layout}]]))]))
|
||||||
:on-click on-remove-layout}])]
|
|
||||||
|
|
||||||
[:div
|
|
||||||
[:& menu-separator]
|
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.add-flex")
|
|
||||||
:shortcut (sc/get-tooltip :toggle-layout-flex)
|
|
||||||
:value "flex"
|
|
||||||
:on-click on-add-layout}]
|
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.add-grid")
|
|
||||||
:shortcut (sc/get-tooltip :toggle-layout-grid)
|
|
||||||
:value "grid"
|
|
||||||
:on-click on-add-layout}]])))
|
|
||||||
|
|
||||||
(mf/defc context-menu-component
|
(mf/defc context-menu-component
|
||||||
[{:keys [shapes]}]
|
[{:keys [shapes]}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue