Create frames in reverse order of other shapes.

This commit is contained in:
Andrey Antukh 2020-11-25 11:48:52 +01:00 committed by Hirunatan
parent f314efdfdc
commit 81e909b961

View File

@ -735,28 +735,38 @@
(defmethod process-change :add-obj (defmethod process-change :add-obj
[data {:keys [id obj page-id component-id frame-id parent-id [data {:keys [id obj page-id component-id frame-id parent-id
index ignore-touched] :as change}] index ignore-touched] :as change}]
(let [update-fn (fn [data] (letfn [(update-fn [data]
(let [parent-id (or parent-id frame-id) (let [parent-id (or parent-id frame-id)
objects (:objects data)] objects (:objects data)]
(let [obj (assoc obj (let [obj (assoc obj
:frame-id frame-id :frame-id frame-id
:parent-id parent-id :parent-id parent-id
:id id)] :id id)]
(-> data (if (and (contains? objects parent-id)
(update :objects assoc id obj) (contains? objects frame-id))
(update-in [:objects parent-id :shapes] (-> data
(fn [shapes] (update :objects assoc id obj)
(let [shapes (or shapes [])] (update-in [:objects parent-id :shapes]
(cond (fn [shapes]
(some #{id} shapes) shapes (let [shapes (or shapes [])]
(nil? index) (conj shapes id) (cond
:else (cph/insert-at-index shapes index [id]))))) (some #{id} shapes)
(cond-> shapes
(and (:shape-ref (get-in data [:objects parent-id]))
(nil? index)
(if (= :frame (:type obj))
(d/concat [id] shapes)
(conj shapes id))
:else
(cph/insert-at-index shapes index [id])))))
(cond-> (and (:shape-ref (get-in data [:objects parent-id]))
(not= parent-id frame-id) (not= parent-id frame-id)
(not ignore-touched)) (not ignore-touched))
(update-in [:objects parent-id :touched] (update-in [:objects parent-id :touched]
cph/set-touched-group :shapes-group))))))] cph/set-touched-group :shapes-group)))
data))))]
(if page-id (if page-id
(d/update-in-when data [:pages-index page-id] update-fn) (d/update-in-when data [:pages-index page-id] update-fn)
(d/update-in-when data [:components component-id] update-fn)))) (d/update-in-when data [:components component-id] update-fn))))