mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 06:41:37 +02:00
🐛 Fix update main targeting remote-shape
This commit is contained in:
parent
c5315de91c
commit
c2a27bb845
2 changed files with 39 additions and 18 deletions
|
@ -620,10 +620,11 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(log/info :msg "UPDATE-COMPONENT of shape" :id (str id) :undo-group undo-group)
|
(log/info :msg "UPDATE-COMPONENT of shape" :id (str id) :undo-group undo-group)
|
||||||
(let [page-id (get state :current-page-id)
|
(let [page-id (get state :current-page-id)
|
||||||
local-file (wsh/get-local-file state)
|
local-file (wsh/get-local-file state)
|
||||||
container (cph/get-container local-file :page page-id)
|
container (cph/get-container local-file :page page-id)
|
||||||
shape (ctn/get-shape container id)]
|
shape (ctn/get-shape container id)
|
||||||
|
components-v2 (features/active-feature? state :components-v2)]
|
||||||
|
|
||||||
(when (ctk/instance-head? shape)
|
(when (ctk/instance-head? shape)
|
||||||
(let [libraries (wsh/get-libraries state)
|
(let [libraries (wsh/get-libraries state)
|
||||||
|
@ -632,7 +633,7 @@
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/set-undo-group undo-group)
|
(pcb/set-undo-group undo-group)
|
||||||
(pcb/with-container container)
|
(pcb/with-container container)
|
||||||
(dwlh/generate-sync-shape-inverse libraries container id))
|
(dwlh/generate-sync-shape-inverse libraries container id components-v2))
|
||||||
|
|
||||||
file-id (:component-file shape)
|
file-id (:component-file shape)
|
||||||
file (wsh/get-file state file-id)
|
file (wsh/get-file state file-id)
|
||||||
|
|
|
@ -525,6 +525,14 @@
|
||||||
;; is different than the one in the near component (Shape-2-2-1)
|
;; is different than the one in the near component (Shape-2-2-1)
|
||||||
;; but it's not touched.
|
;; but it's not touched.
|
||||||
|
|
||||||
|
(defn- redirect-shaperef ;;Set the :shape-ref of a shape pointing to the :id of its remote-shape
|
||||||
|
([container libraries shape]
|
||||||
|
(redirect-shaperef nil nil shape (ctf/find-remote-shape container libraries shape)))
|
||||||
|
([_ _ shape remote-shape]
|
||||||
|
(if (some? (:shape-ref shape))
|
||||||
|
(assoc shape :shape-ref (:id remote-shape))
|
||||||
|
shape)))
|
||||||
|
|
||||||
(defn generate-sync-shape-direct
|
(defn generate-sync-shape-direct
|
||||||
"Generate changes to synchronize one shape that is the root of a component
|
"Generate changes to synchronize one shape that is the root of a component
|
||||||
instance, and all its children, from the given component."
|
instance, and all its children, from the given component."
|
||||||
|
@ -532,13 +540,7 @@
|
||||||
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
|
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
|
||||||
(let [shape-inst (ctn/get-shape container shape-id)]
|
(let [shape-inst (ctn/get-shape container shape-id)]
|
||||||
(if (ctk/in-component-copy? shape-inst)
|
(if (ctk/in-component-copy? shape-inst)
|
||||||
(let [redirect-shaperef ;;Set the :shape-ref of a shape pointing to the :id of its remote-shape
|
(let [redirect-shaperef (partial redirect-shaperef container libraries)
|
||||||
(fn redirect-shaperef
|
|
||||||
([shape]
|
|
||||||
(redirect-shaperef shape (ctf/find-remote-shape container libraries shape)))
|
|
||||||
([shape remote-shape]
|
|
||||||
(assoc shape :shape-ref (:id remote-shape))))
|
|
||||||
|
|
||||||
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
||||||
component (or (ctkl/get-component library (:component-id shape-inst))
|
component (or (ctkl/get-component library (:component-id shape-inst))
|
||||||
(and reset?
|
(and reset?
|
||||||
|
@ -683,12 +685,21 @@
|
||||||
(defn generate-sync-shape-inverse
|
(defn generate-sync-shape-inverse
|
||||||
"Generate changes to update the component a shape is linked to, from
|
"Generate changes to update the component a shape is linked to, from
|
||||||
the values in the shape and all its children."
|
the values in the shape and all its children."
|
||||||
[changes libraries container shape-id]
|
[changes libraries container shape-id components-v2]
|
||||||
(log/debug :msg "Sync shape inverse" :shape (str shape-id))
|
(log/debug :msg "Sync shape inverse" :shape (str shape-id))
|
||||||
(let [shape-inst (ctn/get-shape container shape-id)
|
(let [redirect-shaperef (partial redirect-shaperef container libraries)
|
||||||
|
shape-inst (ctn/get-shape container shape-id)
|
||||||
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
||||||
component (ctkl/get-component library (:component-id shape-inst))
|
component (ctkl/get-component library (:component-id shape-inst))
|
||||||
shape-main (ctf/get-ref-shape library component shape-inst)
|
|
||||||
|
shape-main (when component
|
||||||
|
(if components-v2
|
||||||
|
(ctf/find-remote-shape container libraries shape-inst)
|
||||||
|
(ctf/get-ref-shape library component shape-inst)))
|
||||||
|
|
||||||
|
shape-inst (if components-v2
|
||||||
|
(redirect-shaperef shape-inst shape-main)
|
||||||
|
shape-inst)
|
||||||
|
|
||||||
initial-root? (:component-root shape-inst)
|
initial-root? (:component-root shape-inst)
|
||||||
|
|
||||||
|
@ -704,11 +715,13 @@
|
||||||
shape-main
|
shape-main
|
||||||
root-inst
|
root-inst
|
||||||
root-main
|
root-main
|
||||||
initial-root?)
|
initial-root?
|
||||||
|
redirect-shaperef
|
||||||
|
components-v2)
|
||||||
changes)))
|
changes)))
|
||||||
|
|
||||||
(defn- generate-sync-shape-inverse-recursive
|
(defn- generate-sync-shape-inverse-recursive
|
||||||
[changes container shape-inst component library shape-main root-inst root-main initial-root?]
|
[changes container shape-inst component library shape-main root-inst root-main initial-root? redirect-shaperef components-v2]
|
||||||
(log/trace :msg "Sync shape inverse recursive"
|
(log/trace :msg "Sync shape inverse recursive"
|
||||||
:shape (str (:name shape-inst))
|
:shape (str (:name shape-inst))
|
||||||
:component (:name component))
|
:component (:name component))
|
||||||
|
@ -750,6 +763,11 @@
|
||||||
children-main (mapv #(ctn/get-shape component-container %)
|
children-main (mapv #(ctn/get-shape component-container %)
|
||||||
(:shapes shape-main))
|
(:shapes shape-main))
|
||||||
|
|
||||||
|
children-inst (if components-v2
|
||||||
|
(map #(redirect-shaperef %) children-inst)
|
||||||
|
children-inst)
|
||||||
|
|
||||||
|
|
||||||
only-inst (fn [changes child-inst]
|
only-inst (fn [changes child-inst]
|
||||||
(add-shape-to-main changes
|
(add-shape-to-main changes
|
||||||
child-inst
|
child-inst
|
||||||
|
@ -776,7 +794,9 @@
|
||||||
child-main
|
child-main
|
||||||
root-inst
|
root-inst
|
||||||
root-main
|
root-main
|
||||||
initial-root?))
|
initial-root?
|
||||||
|
redirect-shaperef
|
||||||
|
components-v2))
|
||||||
|
|
||||||
moved (fn [changes child-inst child-main]
|
moved (fn [changes child-inst child-main]
|
||||||
(move-shape
|
(move-shape
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue