mirror of
https://github.com/penpot/penpot.git
synced 2026-08-29 16:18:48 +00:00
wip
This commit is contained in:
parent
9c40563e27
commit
47962cef52
@ -42,7 +42,7 @@
|
||||
[clojure.set :as set]))
|
||||
|
||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||
(log/set-level! :warn)
|
||||
(log/set-level! :trace)
|
||||
|
||||
;; Add uuids here to filter logs to only show specific shapes or containers (and all shapes
|
||||
;; contained in them).
|
||||
@ -1192,7 +1192,9 @@
|
||||
|
||||
(defn- compare-children
|
||||
[changes shape-inst children-inst children-main container-inst container-main file libraries only-inst-cb only-main-cb both-cb swapped-cb moved-cb inverse? reset?]
|
||||
(shape-log :trace (:id shape-inst) container-inst :msg "Compare children")
|
||||
(shape-log :trace (:id shape-inst) container-inst :msg "Compare children"
|
||||
:children-inst (map :id children-inst)
|
||||
:children-main (map :id children-main))
|
||||
(loop [children-inst (seq (or children-inst []))
|
||||
children-main (seq (or children-main []))
|
||||
changes changes]
|
||||
|
||||
@ -539,3 +539,67 @@
|
||||
;; A position-only change in the main component must not propagate to copies
|
||||
;; and therefore must produce no redo-changes.
|
||||
(t/is (empty? (:redo-changes sync-changes)))))
|
||||
|
||||
(t/deftest test-sync-reorder-main-children-via-mod-obj
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-child :main-nested-root :main-nested-child)
|
||||
(thc/make-component :nested-comp :main-nested-root)
|
||||
(tho/add-frame :main-top-root)
|
||||
(thc/instantiate-component :nested-comp :nested-instance :parent-label :main-top-root)
|
||||
(ths/add-sample-shape :top-group {:type :group :parent-label :main-top-root})
|
||||
(thc/make-component :top-comp :main-top-root)
|
||||
(thc/instantiate-component :top-comp :top-copy))
|
||||
page (thf/current-page file)
|
||||
main-root (ths/get-shape file :main-top-root)
|
||||
copy-root (ths/get-shape file :top-copy)
|
||||
main-order (:shapes main-root)
|
||||
copy-order (:shapes copy-root)
|
||||
|
||||
;; ==== Action
|
||||
changes {:redo-changes [{:type :mod-obj
|
||||
:page-id (:id page)
|
||||
:id (:id main-root)
|
||||
:operations [{:type :set
|
||||
:attr :shapes
|
||||
:val (vec (reverse main-order))}]}]
|
||||
:undo-changes []}
|
||||
file' (thf/apply-changes file changes)]
|
||||
|
||||
;; ==== Check
|
||||
;; The copy children must be reordered to keep the component referential integrity.
|
||||
(t/is (= (vec (reverse main-order))
|
||||
(get-in file' [:data :pages-index (:id page) :objects (:id main-root) :shapes])))
|
||||
(t/is (= (vec (reverse copy-order))
|
||||
(get-in file' [:data :pages-index (:id page) :objects (:id copy-root) :shapes])))))
|
||||
|
||||
(t/deftest test-sync-reorder-main-children-via-reorder-children
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-child :main-nested-root :main-nested-child)
|
||||
(thc/make-component :nested-comp :main-nested-root)
|
||||
(tho/add-frame :main-top-root)
|
||||
(thc/instantiate-component :nested-comp :nested-instance :parent-label :main-top-root)
|
||||
(ths/add-sample-shape :top-group {:type :group :parent-label :main-top-root})
|
||||
(thc/make-component :top-comp :main-top-root)
|
||||
(thc/instantiate-component :top-comp :top-copy))
|
||||
page (thf/current-page file)
|
||||
main-root (ths/get-shape file :main-top-root)
|
||||
copy-root (ths/get-shape file :top-copy)
|
||||
main-order (:shapes main-root)
|
||||
copy-order (:shapes copy-root)
|
||||
|
||||
;; ==== Action
|
||||
changes {:redo-changes [{:type :reorder-children
|
||||
:page-id (:id page)
|
||||
:parent-id (:id main-root)
|
||||
:shapes (vec (reverse main-order))}]
|
||||
:undo-changes []}
|
||||
file' (thf/apply-changes file changes)]
|
||||
|
||||
;; ==== Check
|
||||
;; The copy children must be reordered to keep the component referential integrity.
|
||||
(t/is (= (vec (reverse main-order))
|
||||
(get-in file' [:data :pages-index (:id page) :objects (:id main-root) :shapes])))
|
||||
(t/is (= (vec (reverse copy-order))
|
||||
(get-in file' [:data :pages-index (:id page) :objects (:id copy-root) :shapes])))))
|
||||
|
||||
@ -63,7 +63,7 @@
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||
(log/set-level! :warn)
|
||||
(log/set-level! :trace)
|
||||
|
||||
(defn- debug-pretty-file
|
||||
[file-id state]
|
||||
@ -1459,6 +1459,12 @@
|
||||
(into #{}
|
||||
(mapcat (partial ch/components-changed old-data))
|
||||
changes))]
|
||||
(log/trace :hint "processing changes"
|
||||
:js/rchanges (log-changes
|
||||
changes
|
||||
old-data))
|
||||
(log/trace :hint "changed components"
|
||||
:components (str changed-components))
|
||||
(cond
|
||||
(empty? changed-components)
|
||||
(rx/empty)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user