0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 15:51:37 -05:00

Merge pull request #3961 from penpot/alotor-bugfix

Bugfixes
This commit is contained in:
Aitor Moreno 2024-01-03 17:20:27 +01:00 committed by GitHub
commit 95868416ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 133 additions and 45 deletions

View file

@ -622,7 +622,7 @@
(defn remove-cell-areas (defn remove-cell-areas
"Remove the areas in the given `index` before and after the index" "Remove the areas in the given `index` before and after the index"
[parent prop index] [parent prop index]
(let [prop-span (if (= prop :column) :row-span :column-span) (let [prop-span (if (= prop :column) :column-span :row-span)
cells (if (= prop :column) (cells-by-column parent index) (cells-by-row parent index))] cells (if (= prop :column) (cells-by-column parent index) (cells-by-row parent index))]
(->> cells (->> cells
(filter #(> (get % prop-span) 1)) (filter #(> (get % prop-span) 1))
@ -654,7 +654,7 @@
"Remove the areas in the given `index` but only after the index." "Remove the areas in the given `index` but only after the index."
[parent prop index] [parent prop index]
(let [prop-span (if (= prop :column) :column-span :row-span) (let [prop-span (if (= prop :column) :column-span :row-span)
cells (if (= type :column) (cells-by-column parent index) (cells-by-row parent index))] cells (if (= prop :column) (cells-by-column parent index) (cells-by-row parent index))]
(->> cells (->> cells
(filter #(> (get % prop-span) 1)) (filter #(> (get % prop-span) 1))
(reduce (reduce
@ -923,8 +923,8 @@
parent parent
(cond-> parent (cond-> parent
move-content? move-content?
(-> (remove-cell-areas prop (dec from-track)) (-> (remove-cell-areas prop from-index)
(remove-cell-areas prop (dec to-track)))) (remove-cell-areas-after prop to-index)))
parent parent
(reorder-grid-tracks parent tracks-props from-index to-index)] (reorder-grid-tracks parent tracks-props from-index to-index)]
@ -1376,24 +1376,43 @@
(cells-by-row parent index true)) (cells-by-row parent index true))
([parent index check-span?] ([parent index check-span?]
(->> (:layout-grid-cells parent) (->> (:layout-grid-cells parent)
(filter (fn [[_ {:keys [row row-span]}]] (vals)
(if check-span? (filter
(and (>= (inc index) row) (fn [{:keys [row row-span]}]
(< (inc index) (+ row row-span))) (if check-span?
(= (inc index) row)))) (and (>= (inc index) row)
(map second)))) (< (inc index) (+ row row-span)))
(= (inc index) row)))))))
(defn cells-by-column (defn cells-by-column
([parent index] ([parent index]
(cells-by-column parent index true)) (cells-by-column parent index true))
([parent index check-span?] ([parent index check-span?]
(->> (:layout-grid-cells parent) (->> (:layout-grid-cells parent)
(filter (fn [[_ {:keys [column column-span]}]] (vals)
(if check-span? (filter
(and (>= (inc index) column) (fn [{:keys [column column-span] :as cell}]
(< (inc index) (+ column column-span))) (if check-span?
(= (inc index) column)))) (and (>= (inc index) column)
(map second)))) (< (inc index) (+ column column-span)))
(= (inc index) column)))))))
(defn cells-in-area
[parent first-row last-row first-column last-column]
(->> (:layout-grid-cells parent)
(vals)
(filter
(fn [{:keys [row column row-span column-span] :as cell}]
(and
(or (<= row first-row (+ row row-span -1))
(<= row last-row (+ row row-span -1))
(<= first-row row last-row)
(<= first-row (+ row row-span -1) last-row))
(or (<= column first-column (+ column column-span -1))
(<= column last-column (+ column column-span -1))
(<= first-column column last-column)
(<= first-column (+ column column-span -1) last-column)))))))
(defn shapes-by-row (defn shapes-by-row
([parent index] ([parent index]

View file

@ -6,6 +6,7 @@
(ns app.main.data.workspace.grid-layout.editor (ns app.main.data.workspace.grid-layout.editor
(:require (:require
[app.common.data.macros :as dm]
[app.common.geom.rect :as grc] [app.common.geom.rect :as grc]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
@ -25,14 +26,34 @@
(conj hover-set cell-id) (conj hover-set cell-id)
(disj hover-set cell-id)))))))) (disj hover-set cell-id))))))))
(defn select-grid-cell (defn add-to-selection
[grid-id cell-id add?] ([grid-id cell-id]
(ptk/reify ::select-grid-cell (add-to-selection grid-id cell-id false))
([grid-id cell-id shift?]
(ptk/reify ::add-to-selection
ptk/UpdateEvent
(update [_ state]
(if shift?
(let [objects (wsh/lookup-page-objects state)
grid (get objects grid-id)
selected (or (dm/get-in state [:workspace-grid-edition grid-id :selected]) #{})
selected (into selected [cell-id])
cells (->> selected (map #(dm/get-in grid [:layout-grid-cells %])))
{:keys [first-row last-row first-column last-column]} (ctl/cells-coordinates cells)
new-selected
(into #{}
(map :id)
(ctl/cells-in-area grid first-row last-row first-column last-column))]
(assoc-in state [:workspace-grid-edition grid-id :selected] new-selected))
(update-in state [:workspace-grid-edition grid-id :selected] (fnil conj #{}) cell-id))))))
(defn set-selection
[grid-id cell-id]
(ptk/reify ::set-selection
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(if add? (assoc-in state [:workspace-grid-edition grid-id :selected] #{cell-id}))))
(update-in state [:workspace-grid-edition grid-id :selected] (fnil conj #{}) cell-id)
(assoc-in state [:workspace-grid-edition grid-id :selected] #{cell-id})))))
(defn remove-selection (defn remove-selection
[grid-id cell-id] [grid-id cell-id]

View file

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

View file

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

View file

@ -548,26 +548,35 @@
(mf/use-callback (mf/use-callback
(mf/deps grid-id type index) (mf/deps grid-id type index)
(fn [] (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) (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.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-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.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.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-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.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 (mf/defc grid-cells-context-menu
[{:keys [mdata] :as props}] [{:keys [mdata] :as props}]
(let [{:keys [grid cells]} mdata (let [{:keys [grid cells]} mdata
single? (= (count cells) 1) single? (= (count cells) 1)
can-merge? can-merge?
(mf/use-memo (mf/use-memo
(mf/deps cells) (mf/deps cells)
@ -595,7 +604,8 @@
:on-click do-merge-cells}]) :on-click do-merge-cells}])
[:& menu-entry {:title (tr "workspace.context-menu.grid-cells.create-board") [:& menu-entry {:title (tr "workspace.context-menu.grid-cells.create-board")
:on-click do-create-board}]])) :on-click do-create-board
:disabled (and (not single?) (not can-merge?))}]]))
(mf/defc context-menu (mf/defc context-menu

View file

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

View file

@ -337,10 +337,19 @@
(mf/use-callback (mf/use-callback
(mf/deps (:id shape) (:id cell) selected?) (mf/deps (:id shape) (:id cell) selected?)
(fn [event] (fn [event]
(when (or (dom/left-mouse? event) (not selected?)) (when (dom/left-mouse? event)
(if (and (kbd/shift? event) selected?) (cond
(and selected? (or (kbd/mod? event) (kbd/shift? event)))
(st/emit! (dwge/remove-selection (:id shape) (:id cell))) (st/emit! (dwge/remove-selection (:id shape) (:id cell)))
(st/emit! (dwge/select-grid-cell (:id shape) (:id cell) (kbd/shift? event)))))))
(and (not selected?) (kbd/mod? event))
(st/emit! (dwge/add-to-selection (:id shape) (:id cell)))
(and (not selected?) (kbd/shift? event))
(st/emit! (dwge/add-to-selection (:id shape) (:id cell) true))
:else
(st/emit! (dwge/set-selection (:id shape) (:id cell)))))))
handle-context-menu handle-context-menu
(mf/use-callback (mf/use-callback

View file

@ -5070,6 +5070,9 @@ msgstr "Add 1 column to the right"
msgid "workspace.context-menu.grid-track.column.delete" msgid "workspace.context-menu.grid-track.column.delete"
msgstr "Delete column" 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" msgid "workspace.context-menu.grid-track.row.duplicate"
msgstr "Duplicate row" msgstr "Duplicate row"
@ -5082,6 +5085,9 @@ msgstr "Add 1 row bellow"
msgid "workspace.context-menu.grid-track.row.delete" msgid "workspace.context-menu.grid-track.row.delete"
msgstr "Delete row" msgstr "Delete row"
msgid "workspace.context-menu.grid-track.row.delete-shapes"
msgstr "Delete row and shapes"
msgid "workspace.context-menu.grid-cells.merge" msgid "workspace.context-menu.grid-cells.merge"
msgstr "Merge cells" 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" msgid "workspace.context-menu.grid-track.column.delete"
msgstr "Borrar columna" 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" msgid "workspace.context-menu.grid-track.row.duplicate"
msgstr "Duplicar fila" msgstr "Duplicar fila"
@ -5171,6 +5174,9 @@ msgstr "Añadir 1 fila debajo"
msgid "workspace.context-menu.grid-track.row.delete" msgid "workspace.context-menu.grid-track.row.delete"
msgstr "Borrar fila" 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" msgid "workspace.context-menu.grid-cells.merge"
msgstr "Fusionar celdas" msgstr "Fusionar celdas"