mirror of
https://github.com/penpot/penpot.git
synced 2025-05-07 00:05:53 +02:00
Add more safer shapes packing mechanism.
This commit is contained in:
parent
12b9868f45
commit
aba35dee61
3 changed files with 26 additions and 6 deletions
|
@ -76,15 +76,36 @@
|
||||||
|
|
||||||
;; --- Helpers
|
;; --- Helpers
|
||||||
|
|
||||||
|
;; TODO: make sure remove all :tmp-* related attrs from shape
|
||||||
|
|
||||||
|
(defn pack-page-shapes
|
||||||
|
"Create a hash-map of shapes indexed by their id that belongs
|
||||||
|
to the provided page."
|
||||||
|
[state page]
|
||||||
|
(let [lookup-shape-xf (map #(get-in state [:shapes %]))]
|
||||||
|
(reduce (fn reducer [acc {:keys [id type items] :as shape}]
|
||||||
|
(let [shape (assoc shape :page (:id page))]
|
||||||
|
(cond
|
||||||
|
(= type :group)
|
||||||
|
(reduce reducer
|
||||||
|
(assoc acc id shape)
|
||||||
|
(sequence lookup-shape-xf items))
|
||||||
|
|
||||||
|
(uuid? id)
|
||||||
|
(assoc acc id shape)
|
||||||
|
|
||||||
|
:else acc)))
|
||||||
|
{}
|
||||||
|
(sequence lookup-shape-xf (:shapes page)))))
|
||||||
|
|
||||||
(defn pack-page
|
(defn pack-page
|
||||||
"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]
|
||||||
(let [page (get-in state [:pages id])
|
(let [page (get-in state [:pages id])
|
||||||
xf (filter #(= (:page (second %)) id))
|
shapes (pack-page-shapes state page)]
|
||||||
shapes (into {} xf (:shapes state))]
|
|
||||||
(-> page
|
(-> page
|
||||||
(assoc-in [:data :shapes] (into [] (:shapes page)))
|
(assoc-in [:data :shapes] (vec (:shapes page)))
|
||||||
(assoc-in [:data :shapes-map] shapes)
|
(assoc-in [:data :shapes-map] shapes)
|
||||||
(dissoc :shapes))))
|
(dissoc :shapes))))
|
||||||
|
|
||||||
|
@ -303,7 +324,6 @@
|
||||||
|
|
||||||
(defn update-page
|
(defn update-page
|
||||||
[id data]
|
[id data]
|
||||||
(println "update-page" data)
|
|
||||||
{:pre [(uuid? id) (us/valid? ::page-entity data)]}
|
{:pre [(uuid? id) (us/valid? ::page-entity data)]}
|
||||||
(UpdatePage. id data))
|
(UpdatePage. id data))
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
(shape-wrapper shape)))
|
(shape-wrapper shape)))
|
||||||
|
|
||||||
(mx/defc page-svg
|
(mx/defc page-svg
|
||||||
[{:keys [metadata] :as page}]
|
[{:keys [id metadata] :as page}]
|
||||||
(let [{:keys [width height]} metadata]
|
(let [{:keys [width height]} metadata]
|
||||||
[:svg {:width width
|
[:svg {:width width
|
||||||
:height height
|
:height height
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
[]
|
[]
|
||||||
(letfn [(on-move [shape delta]
|
(letfn [(on-move [shape delta]
|
||||||
(st/emit! (uds/apply-temporal-displacement shape delta)))
|
(st/emit! (uds/apply-temporal-displacement shape delta)))
|
||||||
(on-stop [{:keys [id] :as shape}]
|
(on-stop [shape]
|
||||||
(st/emit! (uds/apply-displacement shape)))
|
(st/emit! (uds/apply-displacement shape)))
|
||||||
(on-start [shape]
|
(on-start [shape]
|
||||||
(let [stoper (->> streams/events
|
(let [stoper (->> streams/events
|
||||||
|
|
Loading…
Add table
Reference in a new issue