0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 08:29:42 -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) {:id (mk-uuid "page" i)
:user (mk-uuid "user" ui) :user (mk-uuid "user" ui)
:project (mk-uuid "project" pi) :project (mk-uuid "project" pi)
:data {:canvas [{:id (mk-uuid "canvas" i 1) :data {:shapes [{:id (mk-uuid "canvas" i 1)
:name "Canvas 1" :name "Canvas 1"
:type :canvas
:x1 200 :x1 200
:y1 200 :y1 200
:x2 1224 :x2 1224
:y2 968} :y2 968}
{:id (mk-uuid "canvas" i 2) {:id (mk-uuid "canvas" i 2)
:name "Canvas 2" :name "Canvas 2"
:type :canvas
:x1 1324 :x1 1324
:y1 200 :y1 200
:x2 2348 :x2 2348
:y2 968}] :y2 968}]}
:shapes []
:shapes-map {}}
:metadata {:width 1024 :metadata {:width 1024
:height 768 :height 768
:layout "tablet"} :layout "tablet"}

View file

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