0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

Make canvas behave like shapes on the data layer.

This commit is contained in:
Andrey Antukh 2019-08-24 15:58:20 +02:00
parent afae00f660
commit f99134c70b
2 changed files with 11 additions and 23 deletions

View file

@ -58,20 +58,20 @@
{:id (mk-uuid "page" i)
:user (mk-uuid "user" ui)
:project (mk-uuid "project" pi)
:data {:canvas [{:id (mk-uuid "canvas" i 1)
:data {:shapes [{:id (mk-uuid "canvas" i 1)
:name "Canvas 1"
:type :canvas
:x1 200
:y1 200
:x2 1224
:y2 968}
{:id (mk-uuid "canvas" i 2)
:name "Canvas 2"
:type :canvas
:x1 1324
:y1 200
:x2 2348
:y2 968}]
:shapes []
:shapes-map {}}
:y2 968}]}
:metadata {:width 1024
:height 768
:layout "tablet"}

View file

@ -80,39 +80,27 @@
"Return a packed version of page object ready
for send to remore storage service."
[state id]
(letfn [(get-shape [id]
(get-in state [:shapes id]))
(pack-shapes [ids]
(reduce #(assoc %1 %2 (get-shape %2)) {} ids))
(pack-canvas [ids]
(mapv #(get-in state [:canvas %]) ids))]
(letfn [(pack-shapes [ids]
(mapv #(get-in state [:shapes %]) ids))]
(let [page (get-in state [:pages id])
data {:canvas (pack-canvas (:canvas page))
:shapes (vec (:shapes page))
:shapes-map (pack-shapes (:shapes page))}]
data {:shapes (pack-shapes (:shapes page))}]
(-> page
(assoc :data data)
(dissoc :shapes :canvas)))))
(dissoc :shapes)))))
(defn unpack-page
"Unpacks packed page object and assocs it to the
provided state."
[state {:keys [id data] :as page}]
(let [shapes (:shapes data)
shapes-map (:shapes-map data)
canvas-data (:canvas data [])
canvas (mapv :id canvas-data)
canvas-map (index-by-id canvas-data)
(let [shapes-data (:shapes data [])
shapes (mapv :id shapes-data)
shapes-map (index-by-id shapes-data)
page (-> page
(dissoc :data)
(assoc :canvas canvas)
(assoc :shapes shapes))]
(-> state
(update :shapes merge shapes-map)
(update :canvas merge canvas-map)
(update :pages assoc id page))))
(defn purge-page