mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
Revert "🐛 Fix nested variant in a component doesn't keep inherited overrides (2)"
This reverts commit 7c6515aa7b.
This commit is contained in:
@@ -1992,9 +1992,6 @@
|
|||||||
;; If the values are already equal, don't copy them
|
;; If the values are already equal, don't copy them
|
||||||
(= (get previous-shape attr) (get current-shape attr))
|
(= (get previous-shape attr) (get current-shape attr))
|
||||||
|
|
||||||
;; If the value is the same as the origin, don't copy it
|
|
||||||
(= (get previous-shape attr) (get origin-ref-shape attr))
|
|
||||||
|
|
||||||
;; If both variants (origin and destiny) don't have the same value
|
;; If both variants (origin and destiny) don't have the same value
|
||||||
;; for that attribute, don't copy it.
|
;; for that attribute, don't copy it.
|
||||||
;; Exceptions: :points :selrect and :content can be different
|
;; Exceptions: :points :selrect and :content can be different
|
||||||
@@ -2010,7 +2007,10 @@
|
|||||||
(not= (get origin-ref-shape attr) (get current-shape attr)))
|
(not= (get origin-ref-shape attr) (get current-shape attr)))
|
||||||
|
|
||||||
;; The :content attr cant't be copied to elements of different type
|
;; The :content attr cant't be copied to elements of different type
|
||||||
(and (= attr :content) (not= (:type previous-shape) (:type current-shape))))
|
(and (= attr :content) (not= (:type previous-shape) (:type current-shape)))
|
||||||
|
|
||||||
|
;; If the attr is not touched, don't copy it
|
||||||
|
(not (touched attr-group)))
|
||||||
|
|
||||||
;; On texts, both text (the actual letters)
|
;; On texts, both text (the actual letters)
|
||||||
;; and attrs (bold, font, etc) are in the same attr :content.
|
;; and attrs (bold, font, etc) are in the same attr :content.
|
||||||
|
|||||||
@@ -131,7 +131,7 @@
|
|||||||
|
|
||||||
ref-shape-container (when ref-shape (:container (meta ref-shape)))
|
ref-shape-container (when ref-shape (:container (meta ref-shape)))
|
||||||
ref-shape-parents-set (when ref-shape
|
ref-shape-parents-set (when ref-shape
|
||||||
(->> (cfh/get-parents-with-self (:objects ref-shape-container) (:id ref-shape))
|
(->> (cfh/get-parents (:objects ref-shape-container) (:id ref-shape))
|
||||||
(into #{} d/xf:map-id)))]
|
(into #{} d/xf:map-id)))]
|
||||||
|
|
||||||
(if (or (nil? ref-shape) (contains? ref-shape-parents-set parent-id))
|
(if (or (nil? ref-shape) (contains? ref-shape-parents-set parent-id))
|
||||||
@@ -198,15 +198,15 @@
|
|||||||
|
|
||||||
;; The original-shape is in a copy. For the relation rules, we need the referenced
|
;; The original-shape is in a copy. For the relation rules, we need the referenced
|
||||||
;; shape on the main component
|
;; shape on the main component
|
||||||
orig-base-ref-shape (ctf/find-remote-shape container libraries original-shape {:with-context? true})
|
orig-ref-shape (ctf/find-remote-shape container libraries original-shape {:with-context? true})
|
||||||
orig-ref-objects (:objects (:container (meta orig-base-ref-shape)))
|
orig-ref-objects (:objects (:container (meta orig-ref-shape)))
|
||||||
|
|
||||||
;; Adds a :shape-path attribute to the children of the orig-ref-shape,
|
;; Adds a :shape-path attribute to the children of the orig-ref-shape,
|
||||||
;; that contains the type of its ancestors and its name
|
;; that contains the type of its ancestors and its name
|
||||||
o-ref-shapes-wp (add-unique-path
|
o-ref-shapes-wp (add-unique-path
|
||||||
(reverse (cfh/get-children-with-self orig-ref-objects (:id orig-base-ref-shape)))
|
(reverse (cfh/get-children-with-self orig-ref-objects (:id orig-ref-shape)))
|
||||||
orig-ref-objects
|
orig-ref-objects
|
||||||
(:id orig-base-ref-shape))
|
(:id orig-ref-shape))
|
||||||
|
|
||||||
;; Creates a map to quickly find a child of the orig-ref-shape by its shape-path
|
;; Creates a map to quickly find a child of the orig-ref-shape by its shape-path
|
||||||
o-ref-shapes-p-map (into {} (map (juxt :id :shape-path)) o-ref-shapes-wp)
|
o-ref-shapes-p-map (into {} (map (juxt :id :shape-path)) o-ref-shapes-wp)
|
||||||
@@ -221,7 +221,7 @@
|
|||||||
;; orig-child-touched is in a copy. Get the referenced shape on the main component
|
;; orig-child-touched is in a copy. Get the referenced shape on the main component
|
||||||
;; If there is a swap slot, we will get the referenced shape in another way
|
;; If there is a swap slot, we will get the referenced shape in another way
|
||||||
orig-ref-shape (when-not swap-slot
|
orig-ref-shape (when-not swap-slot
|
||||||
(find-shape-ref-child-of container libraries orig-child-touched (:id orig-base-ref-shape)))
|
(find-shape-ref-child-of container libraries orig-child-touched (:id orig-ref-shape)))
|
||||||
|
|
||||||
orig-ref-id (if swap-slot
|
orig-ref-id (if swap-slot
|
||||||
;; If there is a swap slot, find the referenced shape id
|
;; If there is a swap slot, find the referenced shape id
|
||||||
@@ -231,7 +231,6 @@
|
|||||||
|
|
||||||
;; Get the shape path of the referenced main
|
;; Get the shape path of the referenced main
|
||||||
shape-path (get o-ref-shapes-p-map orig-ref-id)
|
shape-path (get o-ref-shapes-p-map orig-ref-id)
|
||||||
|
|
||||||
;; Get its related shape in the children of new-shape: the one that
|
;; Get its related shape in the children of new-shape: the one that
|
||||||
;; has the same shape-path
|
;; has the same shape-path
|
||||||
related-shape-in-new (get new-shapes-map shape-path)
|
related-shape-in-new (get new-shapes-map shape-path)
|
||||||
|
|||||||
@@ -14,14 +14,13 @@
|
|||||||
|
|
||||||
(defn add-variant
|
(defn add-variant
|
||||||
[file variant-label component1-label root1-label component2-label root2-label
|
[file variant-label component1-label root1-label component2-label root2-label
|
||||||
& {:keys [variant1-params variant2-params]
|
& {:keys []}]
|
||||||
:or {variant1-params {} variant2-params {}}}]
|
|
||||||
(let [file (ths/add-sample-shape file variant-label :type :frame :is-variant-container true)
|
(let [file (ths/add-sample-shape file variant-label :type :frame :is-variant-container true)
|
||||||
variant-id (thi/id variant-label)]
|
variant-id (thi/id variant-label)]
|
||||||
|
|
||||||
(-> file
|
(-> file
|
||||||
(ths/add-sample-shape root2-label (assoc variant2-params :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value2"))
|
(ths/add-sample-shape root2-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value2")
|
||||||
(ths/add-sample-shape root1-label (assoc variant1-params :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value1"))
|
(ths/add-sample-shape root1-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value1")
|
||||||
(thc/make-component component1-label root1-label)
|
(thc/make-component component1-label root1-label)
|
||||||
(thc/update-component component1-label {:variant-id variant-id :variant-properties [{:name "Property 1" :value "Value1"}]})
|
(thc/update-component component1-label {:variant-id variant-id :variant-properties [{:name "Property 1" :value "Value1"}]})
|
||||||
(thc/make-component component2-label root2-label)
|
(thc/make-component component2-label root2-label)
|
||||||
@@ -43,8 +42,7 @@
|
|||||||
|
|
||||||
(defn add-variant-with-child
|
(defn add-variant-with-child
|
||||||
[file variant-label component1-label root1-label component2-label root2-label child1-label child2-label
|
[file variant-label component1-label root1-label component2-label root2-label child1-label child2-label
|
||||||
& {:keys [child1-params child2-params]
|
& {:keys [child1-params child2-params]}]
|
||||||
:or {child1-params {} child2-params {}}}]
|
|
||||||
(let [file (ths/add-sample-shape file variant-label :type :frame :is-variant-container true)
|
(let [file (ths/add-sample-shape file variant-label :type :frame :is-variant-container true)
|
||||||
variant-id (thi/id variant-label)]
|
variant-id (thi/id variant-label)]
|
||||||
(-> file
|
(-> file
|
||||||
|
|||||||
@@ -18,29 +18,6 @@
|
|||||||
|
|
||||||
(t/use-fixtures :each thi/test-fixture)
|
(t/use-fixtures :each thi/test-fixture)
|
||||||
|
|
||||||
|
|
||||||
(t/deftest test-basic-switch
|
|
||||||
(let [;; ==== Setup
|
|
||||||
file (-> (thf/sample-file :file1)
|
|
||||||
(thv/add-variant
|
|
||||||
:v01 :c01 :m01 :c02 :m02
|
|
||||||
{:variant1-params {:width 5}
|
|
||||||
:variant2-params {:width 15}})
|
|
||||||
|
|
||||||
(thc/instantiate-component :c01
|
|
||||||
:copy01))
|
|
||||||
copy01 (ths/get-shape file :copy01)
|
|
||||||
|
|
||||||
;; ==== Action
|
|
||||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
|
||||||
|
|
||||||
copy01' (ths/get-shape file' :copy02)]
|
|
||||||
(thf/dump-file file :keys [:width])
|
|
||||||
;; The copy had width 5 before the switch
|
|
||||||
(t/is (= (:width copy01) 5))
|
|
||||||
;; The rect has width 15 after the switch
|
|
||||||
(t/is (= (:width copy01') 15))))
|
|
||||||
|
|
||||||
(t/deftest test-simple-switch
|
(t/deftest test-simple-switch
|
||||||
(let [;; ==== Setup
|
(let [;; ==== Setup
|
||||||
file (-> (thf/sample-file :file1)
|
file (-> (thf/sample-file :file1)
|
||||||
@@ -68,40 +45,6 @@
|
|||||||
;; The rect has width 15 after the switch
|
;; The rect has width 15 after the switch
|
||||||
(t/is (= (:width rect02') 15))))
|
(t/is (= (:width rect02') 15))))
|
||||||
|
|
||||||
(t/deftest test-basic-switch-override
|
|
||||||
(let [;; ==== Setup
|
|
||||||
file (-> (thf/sample-file :file1)
|
|
||||||
(thv/add-variant
|
|
||||||
:v01 :c01 :m01 :c02 :m02
|
|
||||||
{:variant1-params {:width 5}
|
|
||||||
:variant2-params {:width 5}})
|
|
||||||
|
|
||||||
(thc/instantiate-component :c01
|
|
||||||
:copy01))
|
|
||||||
copy01 (ths/get-shape file :copy01)
|
|
||||||
|
|
||||||
;; Change width of copy
|
|
||||||
page (thf/current-page file)
|
|
||||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
|
||||||
#{(:id copy01)}
|
|
||||||
(fn [shape]
|
|
||||||
(assoc shape :width 25))
|
|
||||||
(:objects page)
|
|
||||||
{})
|
|
||||||
|
|
||||||
file (thf/apply-changes file changes)
|
|
||||||
copy01 (ths/get-shape file :copy01)
|
|
||||||
|
|
||||||
;; ==== Action
|
|
||||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
|
||||||
|
|
||||||
copy01' (ths/get-shape file' :copy02)]
|
|
||||||
(thf/dump-file file :keys [:width])
|
|
||||||
;; The copy had width 25 before the switch
|
|
||||||
(t/is (= (:width copy01) 25))
|
|
||||||
;; The override is keept: The copy still has width 25 after the switch
|
|
||||||
(t/is (= (:width copy01') 25))))
|
|
||||||
|
|
||||||
(t/deftest test-switch-with-override
|
(t/deftest test-switch-with-override
|
||||||
(let [;; ==== Setup
|
(let [;; ==== Setup
|
||||||
file (-> (thf/sample-file :file1)
|
file (-> (thf/sample-file :file1)
|
||||||
|
|||||||
Reference in New Issue
Block a user