0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-18 02:32:13 -05:00

Add delete with content option

This commit is contained in:
alonso.torres 2024-01-03 14:40:40 +01:00
parent 3ae1a97bc9
commit 6068ddc0ff
7 changed files with 58 additions and 21 deletions

View file

@ -923,8 +923,8 @@
parent
(cond-> parent
move-content?
(-> (remove-cell-areas prop (dec from-track))
(remove-cell-areas-after prop (- to-track 2))))
(-> (remove-cell-areas prop from-index)
(remove-cell-areas-after prop to-index)))
parent
(reorder-grid-tracks parent tracks-props from-index to-index)]

View file

@ -24,7 +24,7 @@
[app.main.data.workspace.grid-layout.editor :as dwge]
[app.main.data.workspace.modifiers :as dwm]
[app.main.data.workspace.selection :as dwse]
[app.main.data.workspace.shapes :as dws]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]
[beicon.v2.core :as rx]
@ -170,18 +170,18 @@
group-index (cfh/get-index-replacement selected objects)]
(rx/of
(dwse/select-shapes ordered-ids)
(dws/create-artboard-from-selection new-shape-id parent-id group-index (:name (first selected-shapes)))
(dwsh/create-artboard-from-selection new-shape-id parent-id group-index (:name (first selected-shapes)))
(cl/remove-all-fills [new-shape-id] {:color clr/black :opacity 1})
(create-layout-from-id new-shape-id type false)
(dch/update-shapes [new-shape-id] #(assoc % :layout-item-h-sizing :auto :layout-item-v-sizing :auto))
(dch/update-shapes selected #(assoc % :layout-item-h-sizing :fix :layout-item-v-sizing :fix))
(dws/delete-shapes page-id selected)
(dwsh/delete-shapes page-id selected)
(ptk/data-event :layout/update [new-shape-id])
(dwu/commit-undo-transaction undo-id)))
;; Create Layout from selection
(rx/of
(dws/create-artboard-from-selection new-shape-id)
(dwsh/create-artboard-from-selection new-shape-id)
(cl/remove-all-fills [new-shape-id] {:color clr/black :opacity 1})
(create-layout-from-id new-shape-id type false)
(dch/update-shapes [new-shape-id] #(assoc % :layout-item-h-sizing :auto :layout-item-v-sizing :auto))
@ -269,23 +269,38 @@
(dwu/commit-undo-transaction undo-id)))))))
(defn remove-layout-track
[ids type index]
[ids type index & {:keys [with-shapes?] :or {with-shapes? false}}]
(assert (#{:row :column} type))
(ptk/reify ::remove-layout-track
ptk/WatchEvent
(watch [_ _ _]
(watch [_ state _]
(let [undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(dch/update-shapes
ids
(fn [shape objects]
(case type
:row (ctl/remove-grid-row shape index objects)
:column (ctl/remove-grid-column shape index objects)))
{:with-objects? true})
(ptk/data-event :layout/update ids)
(dwu/commit-undo-transaction undo-id))))))
(let [objects (wsh/lookup-page-objects state)
shapes-to-delete
(when with-shapes?
(->> ids
(mapcat
(fn [id]
(let [shape (get objects id)]
(if (= type :column)
(ctl/shapes-by-column shape index)
(ctl/shapes-by-row shape index)))))
(into #{})))]
(rx/of (dwu/start-undo-transaction undo-id)
(if shapes-to-delete
(dwsh/delete-shapes shapes-to-delete)
(rx/empty))
(dch/update-shapes
ids
(fn [shape objects]
(case type
:row (ctl/remove-grid-row shape index objects)
:column (ctl/remove-grid-column shape index objects)))
{:with-objects? true})
(ptk/data-event :layout/update ids)
(dwu/commit-undo-transaction undo-id)))))))
(defn duplicate-layout-track
[ids type index]

View file

@ -58,6 +58,7 @@
@include titleTipography;
text-align: center;
width: $s-200;
color: $df-secondary;
}
}
.more-info-btn {

View file

@ -548,20 +548,28 @@
(mf/use-callback
(mf/deps grid-id type index)
(fn []
(st/emit! (dwsl/duplicate-layout-track [grid-id] type index))))]
(st/emit! (dwsl/duplicate-layout-track [grid-id] type index))))
do-delete-track-shapes
(mf/use-callback
(mf/deps grid-id type index)
(fn []
(st/emit! (dwsl/remove-layout-track [grid-id] type index {:with-shapes? true}))))]
(if (= type :column)
[:*
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.column.duplicate") :on-click do-duplicate-track}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.column.add-before") :on-click do-add-track-before}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.column.add-after") :on-click do-add-track-after}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.column.delete") :on-click do-delete-track}]]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.column.delete") :on-click do-delete-track}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.column.delete-shapes") :on-click do-delete-track-shapes}]]
[:*
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.row.duplicate") :on-click do-duplicate-track}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.row.add-before") :on-click do-add-track-before}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.row.add-after") :on-click do-add-track-after}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.row.delete") :on-click do-delete-track}]])))
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.row.delete") :on-click do-delete-track}]
[:& menu-entry {:title (tr "workspace.context-menu.grid-track.row.delete-shapes") :on-click do-delete-track-shapes}]])))
(mf/defc grid-cells-context-menu
[{:keys [mdata] :as props}]

View file

@ -95,6 +95,7 @@
}
.history-entry-summary-text {
margin: 0 $s-8;
color: $df-primary;
}
.history-entry-summary-button {
opacity: $op-0;

View file

@ -5070,6 +5070,9 @@ msgstr "Add 1 column to the right"
msgid "workspace.context-menu.grid-track.column.delete"
msgstr "Delete column"
msgid "workspace.context-menu.grid-track.column.delete-shapes"
msgstr "Delete column and shapes"
msgid "workspace.context-menu.grid-track.row.duplicate"
msgstr "Duplicate row"
@ -5082,6 +5085,9 @@ msgstr "Add 1 row bellow"
msgid "workspace.context-menu.grid-track.row.delete"
msgstr "Delete row"
msgid "workspace.context-menu.grid-track.row.delete-shapes"
msgstr "Delete row and shapes"
msgid "workspace.context-menu.grid-cells.merge"
msgstr "Merge cells"

View file

@ -5159,6 +5159,9 @@ msgstr "Añadir 1 columna a la derecha"
msgid "workspace.context-menu.grid-track.column.delete"
msgstr "Borrar columna"
msgid "workspace.context-menu.grid-track.column.delete-shapes"
msgstr "Borrar columna con el contenido"
msgid "workspace.context-menu.grid-track.row.duplicate"
msgstr "Duplicar fila"
@ -5171,6 +5174,9 @@ msgstr "Añadir 1 fila debajo"
msgid "workspace.context-menu.grid-track.row.delete"
msgstr "Borrar fila"
msgid "workspace.context-menu.grid-track.row.delete-shapes"
msgstr "Borrar fila con el contenido"
msgid "workspace.context-menu.grid-cells.merge"
msgstr "Fusionar celdas"