mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 02:43:01 +02:00
🎉 Simplify and fix compare children
This commit is contained in:
parent
895fb3b480
commit
c214d8b044
3 changed files with 64 additions and 58 deletions
|
@ -759,6 +759,13 @@
|
|||
redirect-shaperef
|
||||
components-v2))
|
||||
|
||||
swapped (fn [changes child-inst child-main]
|
||||
(log/trace :msg "Match slot"
|
||||
:child-inst (str (:name child-inst) " " (pretty-uuid (:id child-inst)))
|
||||
:child-main (str (:name child-main) " " (pretty-uuid (:id child-main))))
|
||||
;; For now we don't make any sync here.
|
||||
changes)
|
||||
|
||||
moved (fn [changes child-inst child-main]
|
||||
(log/trace :msg "Move"
|
||||
:child-inst (str (:name child-inst) " " (pretty-uuid (:id child-inst)))
|
||||
|
@ -777,6 +784,7 @@
|
|||
only-inst
|
||||
only-main
|
||||
both
|
||||
swapped
|
||||
moved
|
||||
false
|
||||
reset?))))
|
||||
|
@ -933,6 +941,13 @@
|
|||
redirect-shaperef
|
||||
components-v2))
|
||||
|
||||
swapped (fn [changes child-inst child-main]
|
||||
(log/trace :msg "Match slot"
|
||||
:child-inst (str (:name child-inst) " " (pretty-uuid (:id child-inst)))
|
||||
:child-main (str (:name child-main) " " (pretty-uuid (:id child-main))))
|
||||
;; For now we don't make any sync here.
|
||||
changes)
|
||||
|
||||
moved (fn [changes child-inst child-main]
|
||||
(move-shape
|
||||
changes
|
||||
|
@ -949,6 +964,7 @@
|
|||
only-inst
|
||||
only-main
|
||||
both
|
||||
swapped
|
||||
moved
|
||||
true
|
||||
true)
|
||||
|
@ -969,7 +985,7 @@
|
|||
;; ---- Operation generation helpers ----
|
||||
|
||||
(defn- compare-children
|
||||
[changes children-inst children-main only-inst-cb only-main-cb both-cb moved-cb inverse? reset?]
|
||||
[changes children-inst children-main only-inst-cb only-main-cb both-cb swapped-cb moved-cb inverse? reset?]
|
||||
(log/trace :msg "Compare children")
|
||||
(loop [children-inst (seq (or children-inst []))
|
||||
children-main (seq (or children-main []))
|
||||
|
@ -989,63 +1005,53 @@
|
|||
(reduce only-inst-cb changes children-inst)
|
||||
|
||||
:else
|
||||
(if (ctk/is-main-of? child-main child-inst)
|
||||
(if (or (ctk/is-main-of? child-main child-inst)
|
||||
(ctk/match-swap-slot? child-main child-inst))
|
||||
(recur (next children-inst)
|
||||
(next children-main)
|
||||
(both-cb changes child-inst child-main))
|
||||
(if (or (ctk/is-main-of? child-main child-inst) reset?)
|
||||
(both-cb changes child-inst child-main)
|
||||
(swapped-cb changes child-inst child-main)))
|
||||
|
||||
(if (and (ctk/match-swap-slot? child-main child-inst) (not reset?))
|
||||
(do
|
||||
(log/trace :msg "Match slot"
|
||||
:shape-inst (str (:name child-inst) " " (pretty-uuid (:id child-inst)))
|
||||
:shape-main (str (:name child-main) " " (pretty-uuid (:id child-main))))
|
||||
(recur (next children-inst)
|
||||
(let [child-inst' (d/seek #(or (ctk/is-main-of? child-main %)
|
||||
(ctk/match-swap-slot? child-main %))
|
||||
children-inst)
|
||||
child-main' (d/seek #(or (ctk/is-main-of? % child-inst)
|
||||
(ctk/match-swap-slot? % child-inst))
|
||||
children-main)]
|
||||
(cond
|
||||
(nil? child-inst')
|
||||
(recur children-inst
|
||||
(next children-main)
|
||||
changes))
|
||||
(only-main-cb changes child-main))
|
||||
|
||||
(let [child-inst' (d/seek #(ctk/is-main-of? child-main %) children-inst)
|
||||
child-main' (d/seek #(ctk/is-main-of? % child-inst) children-main)]
|
||||
(cond
|
||||
(nil? child-inst')
|
||||
(let [matching-inst (d/seek #(ctk/match-swap-slot? % child-main) children-inst)]
|
||||
(if (and (some? matching-inst) (not reset?))
|
||||
(do
|
||||
(log/trace :msg "Match slot inst"
|
||||
:shape-inst (str (:name child-inst') " " (pretty-uuid (:id child-inst')))
|
||||
:shape-main (str (:name child-main) " " (pretty-uuid (:id child-main))))
|
||||
(recur (remove #(= (:id %) (:id matching-inst)) children-inst)
|
||||
(next children-main)
|
||||
changes))
|
||||
(recur children-inst
|
||||
(next children-main)
|
||||
(only-main-cb changes child-main))))
|
||||
(nil? child-main')
|
||||
(recur (next children-inst)
|
||||
children-main
|
||||
(only-inst-cb changes child-inst))
|
||||
|
||||
(nil? child-main')
|
||||
(let [matching-main (d/seek #(ctk/match-swap-slot? child-inst %) children-main)]
|
||||
(if (and (some? matching-main) (not reset?))
|
||||
(do
|
||||
(log/trace :msg "Match slot main"
|
||||
:shape-inst (str (:name child-inst) " " (pretty-uuid (:id child-inst)))
|
||||
:shape-main (str (:name child-main') " " (pretty-uuid (:id child-main'))))
|
||||
(recur (next children-inst)
|
||||
(remove #(= (:id %) (:id matching-main)) children-inst)
|
||||
changes))
|
||||
(recur (next children-inst)
|
||||
children-main
|
||||
(only-inst-cb changes child-inst))))
|
||||
|
||||
:else
|
||||
(if inverse?
|
||||
:else
|
||||
(if inverse?
|
||||
(let [is-main? (ctk/is-main-of? child-inst child-main')]
|
||||
(recur (next children-inst)
|
||||
(remove #(= (:id %) (:id child-main')) children-main)
|
||||
(-> changes
|
||||
(both-cb child-inst child-main')
|
||||
(moved-cb child-inst child-main')))
|
||||
(cond-> changes
|
||||
is-main?
|
||||
(both-cb child-inst child-main')
|
||||
(not is-main?)
|
||||
(swapped-cb child-inst child-main')
|
||||
:always
|
||||
(moved-cb child-inst child-main'))))
|
||||
(let [is-main? (ctk/is-main-of? child-inst' child-main)]
|
||||
(recur (remove #(= (:id %) (:id child-inst')) children-inst)
|
||||
(next children-main)
|
||||
(-> changes
|
||||
(both-cb child-inst' child-main)
|
||||
(moved-cb child-inst' child-main))))))))))))
|
||||
(cond-> changes
|
||||
is-main?
|
||||
(both-cb child-inst' child-main)
|
||||
(not is-main?)
|
||||
(swapped-cb child-inst' child-main)
|
||||
:always
|
||||
(moved-cb child-inst' child-main))))))))))))
|
||||
|
||||
(defn- add-shape-to-instance
|
||||
[changes component-shape index component-page container root-instance root-main omit-touched? set-remote-synced?]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue