0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

♻️ Fix some comments

This commit is contained in:
Andrés Moya 2020-09-16 16:08:58 +02:00
parent 63c9e80ed4
commit e2dec81699
5 changed files with 34 additions and 53 deletions

View file

@ -182,13 +182,6 @@
(assoc m key (apply f found args))
m)))
(defn assoc-in-when
[m key-seq v]
(let [found (get-in m key-seq sentinel)]
(if-not (identical? sentinel found)
(assoc-in m key-seq v)
m)))
(defn assoc-when
[m key v]
(let [found (get m key sentinel)]

View file

@ -362,14 +362,17 @@
(defmethod change-spec :del-media [_]
(s/keys :req-un [::id]))
(s/def :internal.changes.add-component/shapes
(s/coll-of ::shape))
(defmethod change-spec :add-component [_]
(s/keys :req-un [::id ::name ::new-shapes]))
(s/keys :req-un [::id ::name :internal.changes.add-component/shapes]))
(defmethod change-spec :del-component [_]
(s/keys :req-un [::id]))
(defmethod change-spec :update-component [_]
(s/keys :req-un [::id ::name ::shapes]))
(s/keys :req-un [::id ::name :internal.changes.add-component/shapes]))
(s/def ::change (s/multi-spec change-spec :type))
(s/def ::changes (s/coll-of ::change))
@ -773,11 +776,11 @@
(update data :media dissoc id))
(defmethod process-change :add-component
[data {:keys [id name new-shapes]}]
[data {:keys [id name shapes]}]
(assoc-in data [:components id]
{:id id
:name name
:objects (d/index-by :id new-shapes)}))
:objects (d/index-by :id shapes)}))
(defmethod process-change :del-component
[data {:keys [id]}]

View file

@ -43,6 +43,7 @@
(defn get-children
"Retrieve all children ids recursively for a given object"
[id objects]
;; TODO: find why does this sometimes come as a list instead of vector
(let [shapes (vec (get-in objects [id :shapes]))]
(if shapes
(d/concat shapes (mapcat #(get-children % objects) shapes))
@ -58,21 +59,6 @@
[id objects]
(map #(get objects %) (concat [id] (get-children id objects))))
(defn walk-children
"Go through an object and all the children tree, and apply a
function to each one. Return the list of changed objects."
[id f objects]
(let [obj (get objects id)]
(if (nil? (:shapes obj))
[(apply f obj)]
(loop [children (map #(get objects %) (:shapes obj))
updated-children []]
(if (empty? children)
updated-children
(let [child (first children)]
(recur (rest children)
(concat [(apply f child)] updated-children))))))))
(defn is-shape-grouped
"Checks if a shape is inside a group"
[shape-id objects]
@ -175,10 +161,10 @@
Returns the cloned object, the list of all new objects (including
the cloned one), and possibly a list of original objects modified."
([object parent-id objects xf-new-object]
(clone-object object parent-id objects xf-new-object identity))
([object parent-id objects update-new-object]
(clone-object object parent-id objects update-new-object identity))
([object parent-id objects xf-new-object xf-original-object]
([object parent-id objects update-new-object update-original-object]
(let [new-id (uuid/next)]
(loop [child-ids (seq (:shapes object))
new-direct-children []
@ -194,11 +180,11 @@
(some? (:shapes object))
(assoc :shapes (map :id new-direct-children)))
new-object (xf-new-object new-object object)
new-object (update-new-object new-object object)
new-objects (concat [new-object] new-children)
updated-object (xf-original-object object new-object)
updated-object (update-original-object object new-object)
updated-objects (if (= object updated-object)
updated-children
@ -210,7 +196,7 @@
child (get objects child-id)
[new-child new-child-objects updated-child-objects]
(clone-object child new-id objects xf-new-object xf-original-object)]
(clone-object child new-id objects update-new-object update-original-object)]
(recur
(next child-ids)

View file

@ -138,7 +138,7 @@
{:type :add-component
:id (:id new-shape)
:name (:name new-shape)
:new-shapes new-shapes})
:shapes new-shapes})
rchanges (into rchanges
(map (fn [updated-shape]
@ -184,18 +184,18 @@
from parent and frame. Update the original shapes to have links
to the new ones."
[shape parent-id objects]
(let [xf-new-shape (fn [new-shape original-shape]
(assoc new-shape :frame-id nil))
(let [update-new-shape (fn [new-shape original-shape]
(assoc new-shape :frame-id nil))
xf-original-shape (fn [original-shape new-shape]
(cond-> original-shape
true
(assoc :shape-ref (:id new-shape))
update-original-shape (fn [original-shape new-shape]
(cond-> original-shape
true
(assoc :shape-ref (:id new-shape))
(nil? (:parent-id new-shape))
(assoc :component-id (:id new-shape))))]
(nil? (:parent-id new-shape))
(assoc :component-id (:id new-shape))))]
(cph/clone-object shape parent-id objects xf-new-shape xf-original-shape)))
(cph/clone-object shape parent-id objects update-new-shape update-original-shape)))
(defn delete-component
[{:keys [id] :as params}]
@ -211,7 +211,7 @@
uchanges [{:type :add-component
:id id
:name (:name component)
:new-shapes (:objects component)}]]
:shapes (vals (:objects component))}]]
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))
@ -241,7 +241,7 @@
all-frames (cph/select-frames objects)
xf-new-shape
update-new-shape
(fn [new-shape original-shape]
(let [new-name
(dwc/generate-unique-name @unames (:name new-shape))]
@ -269,7 +269,7 @@
(cph/clone-object component-shape
nil
(get component :objects)
xf-new-shape)
update-new-shape)
rchanges (map (fn [obj]
{:type :add-obj
@ -396,16 +396,16 @@
;; Clone again the original shape and its children, maintaing
;; the ids of the cloned shapes. If the original shape has some
;; new child shapes, the cloned ones will have new generated ids.
xf-new-shape (fn [new-shape original-shape]
(cond-> new-shape
true
(assoc :frame-id nil)
update-new-shape (fn [new-shape original-shape]
(cond-> new-shape
true
(assoc :frame-id nil)
(some? (:shape-ref original-shape))
(assoc :id (:shape-ref original-shape))))
(some? (:shape-ref original-shape))
(assoc :id (:shape-ref original-shape))))
[new-shape new-shapes _]
(cph/clone-object root-shape nil objects xf-new-shape)
(cph/clone-object root-shape nil objects update-new-shape)
rchanges [{:type :update-component
:id component-id

View file

@ -157,7 +157,6 @@
:xmlns "http://www.w3.org/2000/svg"}
[:& wrapper {:shape frame :view-box vbox}]]))
;; TODO: unify with frame-svg?
(mf/defc component-svg
{::mf/wrap [mf/memo]}
[{:keys [objects group zoom] :or {zoom 1} :as props}]