mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 12:59:12 -05:00
♻️ Fix some comments
This commit is contained in:
parent
63c9e80ed4
commit
e2dec81699
5 changed files with 34 additions and 53 deletions
|
@ -182,13 +182,6 @@
|
||||||
(assoc m key (apply f found args))
|
(assoc m key (apply f found args))
|
||||||
m)))
|
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
|
(defn assoc-when
|
||||||
[m key v]
|
[m key v]
|
||||||
(let [found (get m key sentinel)]
|
(let [found (get m key sentinel)]
|
||||||
|
|
|
@ -362,14 +362,17 @@
|
||||||
(defmethod change-spec :del-media [_]
|
(defmethod change-spec :del-media [_]
|
||||||
(s/keys :req-un [::id]))
|
(s/keys :req-un [::id]))
|
||||||
|
|
||||||
|
(s/def :internal.changes.add-component/shapes
|
||||||
|
(s/coll-of ::shape))
|
||||||
|
|
||||||
(defmethod change-spec :add-component [_]
|
(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 [_]
|
(defmethod change-spec :del-component [_]
|
||||||
(s/keys :req-un [::id]))
|
(s/keys :req-un [::id]))
|
||||||
|
|
||||||
(defmethod change-spec :update-component [_]
|
(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 ::change (s/multi-spec change-spec :type))
|
||||||
(s/def ::changes (s/coll-of ::change))
|
(s/def ::changes (s/coll-of ::change))
|
||||||
|
@ -773,11 +776,11 @@
|
||||||
(update data :media dissoc id))
|
(update data :media dissoc id))
|
||||||
|
|
||||||
(defmethod process-change :add-component
|
(defmethod process-change :add-component
|
||||||
[data {:keys [id name new-shapes]}]
|
[data {:keys [id name shapes]}]
|
||||||
(assoc-in data [:components id]
|
(assoc-in data [:components id]
|
||||||
{:id id
|
{:id id
|
||||||
:name name
|
:name name
|
||||||
:objects (d/index-by :id new-shapes)}))
|
:objects (d/index-by :id shapes)}))
|
||||||
|
|
||||||
(defmethod process-change :del-component
|
(defmethod process-change :del-component
|
||||||
[data {:keys [id]}]
|
[data {:keys [id]}]
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
(defn get-children
|
(defn get-children
|
||||||
"Retrieve all children ids recursively for a given object"
|
"Retrieve all children ids recursively for a given object"
|
||||||
[id objects]
|
[id objects]
|
||||||
|
;; TODO: find why does this sometimes come as a list instead of vector
|
||||||
(let [shapes (vec (get-in objects [id :shapes]))]
|
(let [shapes (vec (get-in objects [id :shapes]))]
|
||||||
(if shapes
|
(if shapes
|
||||||
(d/concat shapes (mapcat #(get-children % objects) shapes))
|
(d/concat shapes (mapcat #(get-children % objects) shapes))
|
||||||
|
@ -58,21 +59,6 @@
|
||||||
[id objects]
|
[id objects]
|
||||||
(map #(get objects %) (concat [id] (get-children 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
|
(defn is-shape-grouped
|
||||||
"Checks if a shape is inside a group"
|
"Checks if a shape is inside a group"
|
||||||
[shape-id objects]
|
[shape-id objects]
|
||||||
|
@ -175,10 +161,10 @@
|
||||||
Returns the cloned object, the list of all new objects (including
|
Returns the cloned object, the list of all new objects (including
|
||||||
the cloned one), and possibly a list of original objects modified."
|
the cloned one), and possibly a list of original objects modified."
|
||||||
|
|
||||||
([object parent-id objects xf-new-object]
|
([object parent-id objects update-new-object]
|
||||||
(clone-object object parent-id objects xf-new-object identity))
|
(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)]
|
(let [new-id (uuid/next)]
|
||||||
(loop [child-ids (seq (:shapes object))
|
(loop [child-ids (seq (:shapes object))
|
||||||
new-direct-children []
|
new-direct-children []
|
||||||
|
@ -194,11 +180,11 @@
|
||||||
(some? (:shapes object))
|
(some? (:shapes object))
|
||||||
(assoc :shapes (map :id new-direct-children)))
|
(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)
|
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-objects (if (= object updated-object)
|
||||||
updated-children
|
updated-children
|
||||||
|
@ -210,7 +196,7 @@
|
||||||
child (get objects child-id)
|
child (get objects child-id)
|
||||||
|
|
||||||
[new-child new-child-objects updated-child-objects]
|
[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
|
(recur
|
||||||
(next child-ids)
|
(next child-ids)
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
{:type :add-component
|
{:type :add-component
|
||||||
:id (:id new-shape)
|
:id (:id new-shape)
|
||||||
:name (:name new-shape)
|
:name (:name new-shape)
|
||||||
:new-shapes new-shapes})
|
:shapes new-shapes})
|
||||||
|
|
||||||
rchanges (into rchanges
|
rchanges (into rchanges
|
||||||
(map (fn [updated-shape]
|
(map (fn [updated-shape]
|
||||||
|
@ -184,18 +184,18 @@
|
||||||
from parent and frame. Update the original shapes to have links
|
from parent and frame. Update the original shapes to have links
|
||||||
to the new ones."
|
to the new ones."
|
||||||
[shape parent-id objects]
|
[shape parent-id objects]
|
||||||
(let [xf-new-shape (fn [new-shape original-shape]
|
(let [update-new-shape (fn [new-shape original-shape]
|
||||||
(assoc new-shape :frame-id nil))
|
(assoc new-shape :frame-id nil))
|
||||||
|
|
||||||
xf-original-shape (fn [original-shape new-shape]
|
update-original-shape (fn [original-shape new-shape]
|
||||||
(cond-> original-shape
|
(cond-> original-shape
|
||||||
true
|
true
|
||||||
(assoc :shape-ref (:id new-shape))
|
(assoc :shape-ref (:id new-shape))
|
||||||
|
|
||||||
(nil? (:parent-id new-shape))
|
(nil? (:parent-id new-shape))
|
||||||
(assoc :component-id (: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
|
(defn delete-component
|
||||||
[{:keys [id] :as params}]
|
[{:keys [id] :as params}]
|
||||||
|
@ -211,7 +211,7 @@
|
||||||
uchanges [{:type :add-component
|
uchanges [{:type :add-component
|
||||||
:id id
|
:id id
|
||||||
:name (:name component)
|
:name (:name component)
|
||||||
:new-shapes (:objects component)}]]
|
:shapes (vals (:objects component))}]]
|
||||||
|
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@
|
||||||
|
|
||||||
all-frames (cph/select-frames objects)
|
all-frames (cph/select-frames objects)
|
||||||
|
|
||||||
xf-new-shape
|
update-new-shape
|
||||||
(fn [new-shape original-shape]
|
(fn [new-shape original-shape]
|
||||||
(let [new-name
|
(let [new-name
|
||||||
(dwc/generate-unique-name @unames (:name new-shape))]
|
(dwc/generate-unique-name @unames (:name new-shape))]
|
||||||
|
@ -269,7 +269,7 @@
|
||||||
(cph/clone-object component-shape
|
(cph/clone-object component-shape
|
||||||
nil
|
nil
|
||||||
(get component :objects)
|
(get component :objects)
|
||||||
xf-new-shape)
|
update-new-shape)
|
||||||
|
|
||||||
rchanges (map (fn [obj]
|
rchanges (map (fn [obj]
|
||||||
{:type :add-obj
|
{:type :add-obj
|
||||||
|
@ -396,16 +396,16 @@
|
||||||
;; Clone again the original shape and its children, maintaing
|
;; Clone again the original shape and its children, maintaing
|
||||||
;; the ids of the cloned shapes. If the original shape has some
|
;; the ids of the cloned shapes. If the original shape has some
|
||||||
;; new child shapes, the cloned ones will have new generated ids.
|
;; new child shapes, the cloned ones will have new generated ids.
|
||||||
xf-new-shape (fn [new-shape original-shape]
|
update-new-shape (fn [new-shape original-shape]
|
||||||
(cond-> new-shape
|
(cond-> new-shape
|
||||||
true
|
true
|
||||||
(assoc :frame-id nil)
|
(assoc :frame-id nil)
|
||||||
|
|
||||||
(some? (:shape-ref original-shape))
|
(some? (:shape-ref original-shape))
|
||||||
(assoc :id (:shape-ref original-shape))))
|
(assoc :id (:shape-ref original-shape))))
|
||||||
|
|
||||||
[new-shape new-shapes _]
|
[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
|
rchanges [{:type :update-component
|
||||||
:id component-id
|
:id component-id
|
||||||
|
|
|
@ -157,7 +157,6 @@
|
||||||
:xmlns "http://www.w3.org/2000/svg"}
|
:xmlns "http://www.w3.org/2000/svg"}
|
||||||
[:& wrapper {:shape frame :view-box vbox}]]))
|
[:& wrapper {:shape frame :view-box vbox}]]))
|
||||||
|
|
||||||
;; TODO: unify with frame-svg?
|
|
||||||
(mf/defc component-svg
|
(mf/defc component-svg
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [objects group zoom] :or {zoom 1} :as props}]
|
[{:keys [objects group zoom] :or {zoom 1} :as props}]
|
||||||
|
|
Loading…
Add table
Reference in a new issue