mirror of
https://github.com/penpot/penpot.git
synced 2025-03-28 15:41:25 -05:00
✨ Add items to grid cells
This commit is contained in:
parent
fde0bcfd3e
commit
ca7f17efd1
5 changed files with 55 additions and 21 deletions
|
@ -1281,6 +1281,21 @@
|
|||
(let [cells+index (d/enumerate cells)]
|
||||
(d/seek #(in-cell? (second %) row column) cells+index)))
|
||||
|
||||
(defn free-cell-shapes
|
||||
"Removes the shape-ids from the cells previously assigned."
|
||||
[parent shape-ids]
|
||||
(let [shape-ids (set shape-ids)]
|
||||
(letfn [(free-cells
|
||||
[cells]
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(if (some shape-ids (:shapes v))
|
||||
(assoc-in m [k :shapes] [])
|
||||
m))
|
||||
cells
|
||||
cells))]
|
||||
(update parent :layout-grid-cells free-cells))))
|
||||
|
||||
(defn push-into-cell
|
||||
"Push the shapes into the row/column cell and moves the rest"
|
||||
[parent shape-ids row column]
|
||||
|
@ -1295,16 +1310,17 @@
|
|||
;; Move shift the `shapes` attribute between cells
|
||||
(->> (range start-index (inc to-index))
|
||||
(map vector shape-ids)
|
||||
(reduce (fn [[parent cells] [shape-id idx]]
|
||||
;; If the shape to put in a cell is the same that is already in the cell we do nothing
|
||||
(if (= shape-id (get-in parent [:layout-grid-cells (get-in cells [idx :id]) :shapes 0]))
|
||||
[parent cells]
|
||||
(let [[parent cells] (free-cell-push parent cells idx)]
|
||||
[(update-in parent [:layout-grid-cells (get-in cells [idx :id])]
|
||||
assoc :position :manual
|
||||
:shapes [shape-id])
|
||||
cells])))
|
||||
[parent cells])
|
||||
(reduce
|
||||
(fn [[parent cells] [shape-id idx]]
|
||||
;; If the shape to put in a cell is the same that is already in the cell we do nothing
|
||||
(if (= shape-id (get-in parent [:layout-grid-cells (get-in cells [idx :id]) :shapes 0]))
|
||||
[parent cells]
|
||||
(let [[parent cells] (free-cell-push parent cells idx)]
|
||||
[(update-in parent [:layout-grid-cells (get-in cells [idx :id])]
|
||||
assoc :position :manual
|
||||
:shapes [shape-id])
|
||||
cells])))
|
||||
[parent cells])
|
||||
(first)))
|
||||
parent)))
|
||||
|
||||
|
|
|
@ -112,7 +112,6 @@
|
|||
(dwu/commit-undo-transaction undo-id)))
|
||||
|
||||
(catch :default cause
|
||||
(js/console.log (.-stack cause))
|
||||
(rx/throw {:type :svg-parser
|
||||
:data cause})))))))
|
||||
|
||||
|
|
|
@ -831,7 +831,7 @@
|
|||
:ignore-constraints false
|
||||
:ignore-snap-pixel true}))))))
|
||||
|
||||
(defn- move-shapes-to-frame
|
||||
(defn move-shapes-to-frame
|
||||
[ids frame-id drop-index [row column :as cell]]
|
||||
(ptk/reify ::move-shapes-to-frame
|
||||
ptk/WatchEvent
|
||||
|
@ -923,24 +923,32 @@
|
|||
changes
|
||||
(-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects)
|
||||
|
||||
;; Remove layout-item properties when moving a shape outside a layout
|
||||
(cond-> (not (ctl/any-layout? objects frame-id))
|
||||
(pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data))
|
||||
|
||||
;; Remove the swap slots if it is moving to a different component
|
||||
(pcb/update-shapes child-heads
|
||||
(fn [shape]
|
||||
(cond-> shape
|
||||
(not= component-main-frame (ctn/find-component-main objects shape false))
|
||||
(ctk/remove-swap-slot))))
|
||||
(pcb/update-shapes
|
||||
child-heads
|
||||
(fn [shape]
|
||||
(cond-> shape
|
||||
(not= component-main-frame (ctn/find-component-main objects shape false))
|
||||
(ctk/remove-swap-slot))))
|
||||
|
||||
;; Remove component-root property when moving a shape inside a component
|
||||
(cond-> (ctn/get-instance-root objects frame)
|
||||
(pcb/update-shapes moving-shapes-children-ids #(dissoc % :component-root)))
|
||||
|
||||
;; Add component-root property when moving a component outside a component
|
||||
(cond-> (not (ctn/get-instance-root objects frame))
|
||||
(pcb/update-shapes child-heads #(assoc % :component-root true)))
|
||||
|
||||
(pcb/update-shapes moving-shapes-ids #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true)))
|
||||
(pcb/update-shapes shape-ids-to-detach ctk/detach-shape)
|
||||
(pcb/change-parent frame-id moving-shapes drop-index)
|
||||
|
||||
;; Change the grid cell in a grid layout
|
||||
(cond-> (ctl/grid-layout? objects frame-id)
|
||||
(-> (pcb/update-shapes
|
||||
[frame-id]
|
||||
|
@ -948,7 +956,8 @@
|
|||
(-> frame
|
||||
;; Assign the cell when pushing into a specific grid cell
|
||||
(cond-> (some? cell)
|
||||
(-> (ctl/push-into-cell moving-shapes-ids row column)
|
||||
(-> (ctl/free-cell-shapes moving-shapes-ids)
|
||||
(ctl/push-into-cell moving-shapes-ids row column)
|
||||
(ctl/assign-cells objects)))
|
||||
(ctl/assign-cell-positions objects)))
|
||||
{:with-objects? true})
|
||||
|
|
|
@ -127,7 +127,6 @@
|
|||
state
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
_ (prn "??" (->> ids (map #(get objects %)) (map :name)))
|
||||
srect (->> ids
|
||||
(map #(get objects %))
|
||||
(gsh/shapes->rect))]
|
||||
|
|
|
@ -10,9 +10,13 @@
|
|||
[app.common.record :as crc]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.utils :as utils :refer [get-data get-state]]))
|
||||
[app.plugins.utils :as utils :refer [get-data get-state]]
|
||||
[app.util.object :as obj]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(defn- make-tracks
|
||||
[tracks]
|
||||
|
@ -72,7 +76,14 @@
|
|||
(remove
|
||||
[self]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsl/remove-layout #{id})))))
|
||||
(st/emit! (dwsl/remove-layout #{id}))))
|
||||
|
||||
(appendChild
|
||||
[self child row column]
|
||||
(let [parent-id (get-data self :id)
|
||||
child-id (uuid/uuid (obj/get child "id"))]
|
||||
(st/emit! (dwt/move-shapes-to-frame #{child-id} parent-id nil [row column])
|
||||
(ptk/data-event :layout/update {:ids [parent-id]})))))
|
||||
|
||||
(defn grid-layout-proxy
|
||||
[data]
|
||||
|
|
Loading…
Add table
Reference in a new issue