mirror of
https://github.com/penpot/penpot.git
synced 2025-05-09 23:06:43 +02:00
✨ Add nesting constraints for components
This commit is contained in:
parent
3c07416c48
commit
a78eb226e2
9 changed files with 277 additions and 131 deletions
|
@ -170,7 +170,7 @@
|
|||
(dwl/add-component)
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-add-component-from-component
|
||||
(t/deftest test-add-component-from-component-instance
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
|
@ -178,30 +178,27 @@
|
|||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
[(thp/id :shape1)])
|
||||
(thp/instantiate-component :instance1 (thp/id :component1)))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
;; Expected shape tree:
|
||||
;;
|
||||
;; [Page]
|
||||
;; Root Frame
|
||||
;; Rect 1
|
||||
;; Rect 1
|
||||
;; Rect 1
|
||||
;;
|
||||
;; [Rect 1]
|
||||
;; page1 / Rect 1
|
||||
;;
|
||||
;; [Rect 1]
|
||||
;; page1 / Rect 1
|
||||
;;
|
||||
;; Expected shape tree:
|
||||
;;
|
||||
;; [Page: Page]
|
||||
;; Root Frame
|
||||
;; Rect 1 #
|
||||
;; Rect 1
|
||||
;; Rect 1 #
|
||||
;; Rect 1* @--> Rect 1
|
||||
;; Rect 1 ---> Rect 1
|
||||
;;
|
||||
(let [[[instance1 shape1]
|
||||
[c-instance1 c-shape1]
|
||||
component1]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(thp/id :main1)
|
||||
(thp/id :instance1)
|
||||
true)
|
||||
|
||||
[[instance2 instance1' shape1']
|
||||
|
@ -225,6 +222,56 @@
|
|||
(t/is (= (:name c-instance1') "Rect 1"))
|
||||
(t/is (= (:name c-instance2) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/select-shape (thp/id :instance1))
|
||||
(dwl/add-component)
|
||||
:the/end))))
|
||||
|
||||
|
||||
(t/deftest test-add-component-from-component-main
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
;; Expected shape tree:
|
||||
;;
|
||||
;; [Page]
|
||||
;; Root Frame
|
||||
;; Rect 1
|
||||
;; Rect 1
|
||||
;;
|
||||
;; [Rect 1]
|
||||
;; page1 / Rect 1
|
||||
;;
|
||||
(let [file (wsh/get-local-file new-state)
|
||||
components (ctkl/components file)
|
||||
page (thp/current-page new-state)
|
||||
shape1 (thp/get-shape new-state :shape1)
|
||||
parent1 (ctn/get-shape page (:parent-id shape1))
|
||||
main1 (thp/get-shape state :main1)
|
||||
[[instance1 shape1]
|
||||
[c-instance1 c-shape1]
|
||||
component1]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id main1))]
|
||||
;; Creating a component from a main doesn't generate a new component
|
||||
(t/is (= (count components) 1))
|
||||
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name instance1) "Rect 1"))
|
||||
(t/is (= (:name component1) "Rect 1"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-instance1) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/select-shape (thp/id :main1))
|
||||
|
@ -580,7 +627,62 @@
|
|||
(dwl/detach-component (:id instance1))
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-add-nested-component
|
||||
|
||||
|
||||
(t/deftest test-add-nested-component-instance
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)])
|
||||
(thp/instantiate-component :instance1 (thp/id :component1)))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
;; Expected shape tree:
|
||||
;;
|
||||
;; [Page]
|
||||
;; Root Frame
|
||||
;; Rect 1
|
||||
;; Rect 1
|
||||
;; Board
|
||||
;; Rect 1
|
||||
;; Rect 1
|
||||
;;
|
||||
;; [Rect 1]
|
||||
;; page1 / Rect 1
|
||||
;;
|
||||
;; [Board]
|
||||
;; page1 / Board
|
||||
;;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id instance1))]
|
||||
|
||||
(t/is (= (:name group) "Board"))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (= (:name component) "Board"))
|
||||
(t/is (= (:name c-group) "Board"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/select-shape (thp/id :instance1))
|
||||
(dwsh/create-artboard-from-selection)
|
||||
(dwl/add-component)
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-add-nested-component-main
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
|
@ -594,34 +696,36 @@
|
|||
;;
|
||||
;; [Page]
|
||||
;; Root Frame
|
||||
;; Group
|
||||
;; Board
|
||||
;; Rect 1
|
||||
;; Rect 1
|
||||
;;
|
||||
;; [Rect 1]
|
||||
;; page1 / Rect 1
|
||||
;;
|
||||
;; [Group]
|
||||
;; page1 / Group
|
||||
;;
|
||||
(let [page (thp/current-page new-state)
|
||||
(let [file (wsh/get-local-file new-state)
|
||||
components (ctkl/components file)
|
||||
page (thp/current-page new-state)
|
||||
|
||||
shape1 (thp/get-shape new-state :shape1)
|
||||
parent1 (ctn/get-shape page (:parent-id shape1))
|
||||
|
||||
[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
[[group shape1]
|
||||
[c-group c-shape1]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id parent1))]
|
||||
(:parent-id shape1))]
|
||||
|
||||
(t/is (= (:name group) "Board"))
|
||||
;; Creating a component from something containing a main doesn't generate a new component
|
||||
(t/is (= (count components) 1))
|
||||
|
||||
(t/is (= (:name group) "Rect 1"))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (= (:name component) "Board"))
|
||||
(t/is (= (:name c-group) "Board"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 1")))))]
|
||||
(t/is (= (:name component) "Rect 1"))
|
||||
(t/is (= (:name c-group) "Rect 1"))
|
||||
(t/is (= (:name c-shape1) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue