mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 18:18:24 -05:00
🐛 Fix detach when top copy is dangling and nested copy is not
This commit is contained in:
parent
e1b85c8fe6
commit
933f4410d2
4 changed files with 96 additions and 10 deletions
|
@ -305,7 +305,12 @@
|
||||||
(and (some? (ctk/get-swap-slot ref-shape))
|
(and (some? (ctk/get-swap-slot ref-shape))
|
||||||
(nil? (ctk/get-swap-slot shape))
|
(nil? (ctk/get-swap-slot shape))
|
||||||
(not= (:id shape) shape-id))
|
(not= (:id shape) shape-id))
|
||||||
(pcb/update-shapes [(:id shape)] #(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape))))))]
|
(pcb/update-shapes [(:id shape)] #(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape)))
|
||||||
|
|
||||||
|
;; If we can't get the ref-shape (e.g. it's in an external library not linked),
|
||||||
|
;: we can't do a suitable advance. So it's better to detach the shape
|
||||||
|
(nil? ref-shape)
|
||||||
|
(pcb/update-shapes [(:id shape)] ctk/detach-shape))))]
|
||||||
|
|
||||||
(reduce skip-near changes children)))
|
(reduce skip-near changes children)))
|
||||||
|
|
||||||
|
|
|
@ -738,16 +738,20 @@
|
||||||
(:component-id shape) "@"
|
(:component-id shape) "@"
|
||||||
:else "-")
|
:else "-")
|
||||||
|
|
||||||
(when (and (:component-file shape) component-file)
|
(when (:component-file shape)
|
||||||
(str/format "<%s> "
|
(str/format "<%s> "
|
||||||
|
(if component-file
|
||||||
(if (= (:id component-file) (:id file))
|
(if (= (:id component-file) (:id file))
|
||||||
"local"
|
"local"
|
||||||
(:name component-file))))
|
(:name component-file))
|
||||||
|
(if show-ids
|
||||||
|
(str/format "¿%s?" (:component-file shape))
|
||||||
|
"?"))))
|
||||||
|
|
||||||
(or (:name component-shape)
|
(or (:name component-shape)
|
||||||
(str/format "?%s"
|
(if show-ids
|
||||||
(when show-ids
|
(str/format "¿%s?" (:shape-ref shape))
|
||||||
(str " " (:shape-ref shape)))))
|
"?"))
|
||||||
|
|
||||||
(when (and show-ids component-shape)
|
(when (and show-ids component-shape)
|
||||||
(str/format " %s" (:id component-shape)))
|
(str/format " %s" (:id component-shape)))
|
||||||
|
|
|
@ -180,6 +180,7 @@
|
||||||
[:main-instance {:optional true} :boolean]
|
[:main-instance {:optional true} :boolean]
|
||||||
[:remote-synced {:optional true} :boolean]
|
[:remote-synced {:optional true} :boolean]
|
||||||
[:shape-ref {:optional true} ::sm/uuid]
|
[:shape-ref {:optional true} ::sm/uuid]
|
||||||
|
[:touched {:optional true} [:maybe [:set :keyword]]]
|
||||||
[:blocked {:optional true} :boolean]
|
[:blocked {:optional true} :boolean]
|
||||||
[:collapsed {:optional true} :boolean]
|
[:collapsed {:optional true} :boolean]
|
||||||
[:locked {:optional true} :boolean]
|
[:locked {:optional true} :boolean]
|
||||||
|
@ -215,8 +216,7 @@
|
||||||
[:grow-type {:optional true}
|
[:grow-type {:optional true}
|
||||||
[::sm/one-of grow-types]]
|
[::sm/one-of grow-types]]
|
||||||
[:applied-tokens {:optional true} ::cto/applied-tokens]
|
[:applied-tokens {:optional true} ::cto/applied-tokens]
|
||||||
[:plugin-data {:optional true} ::ctpg/plugin-data]
|
[:plugin-data {:optional true} ::ctpg/plugin-data]])
|
||||||
[:touched {:optional true} [:maybe [:set :keyword]]]])
|
|
||||||
|
|
||||||
(def schema:group-attrs
|
(def schema:group-attrs
|
||||||
[:map {:title "GroupAttrs"}
|
[:map {:title "GroupAttrs"}
|
||||||
|
|
|
@ -103,6 +103,83 @@
|
||||||
(t/is (= (:shape-ref copy-nested-ellipse) (thi/id :nested-ellipse)))
|
(t/is (= (:shape-ref copy-nested-ellipse) (thi/id :nested-ellipse)))
|
||||||
(t/is (nil? (ctk/get-swap-slot copy-nested-ellipse)))))
|
(t/is (nil? (ctk/get-swap-slot copy-nested-ellipse)))))
|
||||||
|
|
||||||
|
(t/deftest test-advance-in-library
|
||||||
|
(let [;; ==== Setup
|
||||||
|
library (setup-file)
|
||||||
|
file (-> (thf/sample-file :file2)
|
||||||
|
(thc/instantiate-component :c-big-board
|
||||||
|
:copy-big-board
|
||||||
|
:library library
|
||||||
|
:children-labels [:copy-h-board-with-ellipse
|
||||||
|
:copy-nested-h-ellipse
|
||||||
|
:copy-nested-ellipse]))
|
||||||
|
page (thf/current-page file)
|
||||||
|
|
||||||
|
;; ==== Action
|
||||||
|
changes (cll/generate-detach-instance (-> (pcb/empty-changes nil)
|
||||||
|
(pcb/with-page page)
|
||||||
|
(pcb/with-objects (:objects page)))
|
||||||
|
page
|
||||||
|
{(:id file) file
|
||||||
|
(:id library) library}
|
||||||
|
(thi/id :copy-big-board))
|
||||||
|
file' (thf/apply-changes file changes)
|
||||||
|
|
||||||
|
;; ==== Get
|
||||||
|
copy-h-board-with-ellipse (ths/get-shape file' :copy-h-board-with-ellipse)
|
||||||
|
copy-nested-h-ellipse (ths/get-shape file' :copy-nested-h-ellipse)
|
||||||
|
copy-nested-ellipse (ths/get-shape file' :copy-nested-ellipse)]
|
||||||
|
|
||||||
|
;; ==== Check
|
||||||
|
|
||||||
|
;; It should the same as above, but in an external library.
|
||||||
|
(thf/dump-file file)
|
||||||
|
(t/is (ctk/instance-root? copy-h-board-with-ellipse))
|
||||||
|
(t/is (= (:shape-ref copy-h-board-with-ellipse) (thi/id :board-with-ellipse)))
|
||||||
|
(t/is (nil? (ctk/get-swap-slot copy-h-board-with-ellipse)))
|
||||||
|
|
||||||
|
(t/is (ctk/instance-head? copy-nested-h-ellipse))
|
||||||
|
(t/is (= (:shape-ref copy-nested-h-ellipse) (thi/id :nested-h-ellipse)))
|
||||||
|
(t/is (nil? (ctk/get-swap-slot copy-nested-h-ellipse)))
|
||||||
|
|
||||||
|
(t/is (not (ctk/instance-head? copy-nested-ellipse)))
|
||||||
|
(t/is (= (:shape-ref copy-nested-ellipse) (thi/id :nested-ellipse)))
|
||||||
|
(t/is (nil? (ctk/get-swap-slot copy-nested-ellipse)))))
|
||||||
|
|
||||||
|
(t/deftest test-advance-in-broken-library
|
||||||
|
(let [;; ==== Setup
|
||||||
|
library (setup-file)
|
||||||
|
file (-> (thf/sample-file :file2)
|
||||||
|
(thc/instantiate-component :c-big-board
|
||||||
|
:copy-big-board
|
||||||
|
:library library
|
||||||
|
:children-labels [:copy-h-board-with-ellipse
|
||||||
|
:copy-nested-h-ellipse
|
||||||
|
:copy-nested-ellipse]))
|
||||||
|
page (thf/current-page file)
|
||||||
|
|
||||||
|
;; ==== Action
|
||||||
|
changes (cll/generate-detach-instance (-> (pcb/empty-changes nil)
|
||||||
|
(pcb/with-page page)
|
||||||
|
(pcb/with-objects (:objects page)))
|
||||||
|
page
|
||||||
|
{(:id file) file}
|
||||||
|
(thi/id :copy-big-board))
|
||||||
|
file' (thf/apply-changes file changes)
|
||||||
|
|
||||||
|
;; ==== Get
|
||||||
|
copy-h-board-with-ellipse (ths/get-shape file' :copy-h-board-with-ellipse)
|
||||||
|
copy-nested-h-ellipse (ths/get-shape file' :copy-nested-h-ellipse)
|
||||||
|
copy-nested-ellipse (ths/get-shape file' :copy-nested-ellipse)]
|
||||||
|
|
||||||
|
;; ==== Check
|
||||||
|
|
||||||
|
;; If the main component cannot be found, because it's in a library that is
|
||||||
|
;; not available, the nested copies should be detached too.
|
||||||
|
(t/is (not (ctk/in-component-copy? copy-h-board-with-ellipse)))
|
||||||
|
(t/is (not (ctk/in-component-copy? copy-nested-h-ellipse)))
|
||||||
|
(t/is (not (ctk/in-component-copy? copy-nested-ellipse)))))
|
||||||
|
|
||||||
(t/deftest test-dont-advance-when-swapped-copy
|
(t/deftest test-dont-advance-when-swapped-copy
|
||||||
(let [;; ==== Setup
|
(let [;; ==== Setup
|
||||||
file (-> (setup-file)
|
file (-> (setup-file)
|
||||||
|
|
Loading…
Add table
Reference in a new issue