mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 03:56:38 +02:00
🐛 Remove incorrect find-component function
This commit is contained in:
parent
5157928cdb
commit
0d1af260a4
4 changed files with 12 additions and 27 deletions
|
@ -117,12 +117,6 @@
|
||||||
(ctkl/update-component file-data (:id container) f)))
|
(ctkl/update-component file-data (:id container) f)))
|
||||||
|
|
||||||
;; Asset helpers
|
;; Asset helpers
|
||||||
|
|
||||||
(defn find-component
|
|
||||||
"Retrieve a component from libraries, iterating over all of them."
|
|
||||||
[libraries component-id & {:keys [include-deleted?] :or {include-deleted? false}}]
|
|
||||||
(some #(ctkl/get-component (:data %) component-id include-deleted?) (vals libraries)))
|
|
||||||
|
|
||||||
(defn find-component-file
|
(defn find-component-file
|
||||||
[file libraries component-file]
|
[file libraries component-file]
|
||||||
(if (and (some? file) (= component-file (:id file)))
|
(if (and (some? file) (= component-file (:id file)))
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
[page root-inst-id libraries]
|
[page root-inst-id libraries]
|
||||||
(let [root-inst (ctn/get-shape page root-inst-id)
|
(let [root-inst (ctn/get-shape page root-inst-id)
|
||||||
|
|
||||||
component (ctf/find-component libraries (:component-id root-inst))
|
component (ctf/get-component libraries (:component-file root-inst) (:component-id root-inst))
|
||||||
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
||||||
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
|
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||||
|
@ -94,7 +94,7 @@
|
||||||
(ctn/get-component-shape (:objects page) shape)
|
(ctn/get-component-shape (:objects page) shape)
|
||||||
|
|
||||||
component
|
component
|
||||||
(ctf/find-component libraries (:component-id component-shape))
|
(ctf/get-component libraries (:component-file component-shape) (:component-id component-shape))
|
||||||
|
|
||||||
main-shape
|
main-shape
|
||||||
(ctn/get-shape component (:shape-ref shape))]
|
(ctn/get-shape component (:shape-ref shape))]
|
||||||
|
@ -118,7 +118,7 @@
|
||||||
[page root-inst-id libraries]
|
[page root-inst-id libraries]
|
||||||
(let [root-inst (ctn/get-shape page root-inst-id)
|
(let [root-inst (ctn/get-shape page root-inst-id)
|
||||||
|
|
||||||
component (ctf/find-component libraries (:component-id root-inst))
|
component (ctf/get-component libraries (:component-file root-inst) (:component-id root-inst))
|
||||||
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
||||||
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
|
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
(ctn/get-component-shape (:objects page) shape)
|
(ctn/get-component-shape (:objects page) shape)
|
||||||
|
|
||||||
component
|
component
|
||||||
(ctf/find-component libraries (:component-id component-shape))
|
(ctf/get-component libraries (:component-file component-shape) (:component-id component-shape))
|
||||||
|
|
||||||
main-shape
|
main-shape
|
||||||
(ctn/get-shape component (:shape-ref shape))]
|
(ctn/get-shape component (:shape-ref shape))]
|
||||||
|
@ -142,15 +142,5 @@
|
||||||
|
|
||||||
[shapes-inst shapes-main component]))
|
[shapes-inst shapes-main component]))
|
||||||
|
|
||||||
(defn resolve-component
|
|
||||||
"Get the component with the given id and all its shapes."
|
|
||||||
[page component-id libraries]
|
|
||||||
(let [component (ctf/find-component libraries component-id)
|
|
||||||
root-main (ctk/get-component-root component)
|
|
||||||
shapes-main (cfh/get-children-with-self (:objects component) (:id root-main))]
|
|
||||||
|
|
||||||
;; Validate that the component tree is well constructed
|
|
||||||
(run! check-noninstance shapes-main)
|
|
||||||
|
|
||||||
[shapes-main component]))
|
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
main-instance? (:main-instance root-inst)
|
main-instance? (:main-instance root-inst)
|
||||||
|
|
||||||
libs (wsh/get-libraries state)
|
libs (wsh/get-libraries state)
|
||||||
component (ctf/find-component libs (:component-id root-inst))
|
component (ctf/get-component libs (:component-file root-inst) (:component-id root-inst))
|
||||||
library (ctf/get-component-library libs root-inst)
|
library (ctf/get-component-library libs root-inst)
|
||||||
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
||||||
|
@ -152,7 +152,7 @@
|
||||||
root-inst (ctn/get-shape page root-inst-id)
|
root-inst (ctn/get-shape page root-inst-id)
|
||||||
|
|
||||||
libs (wsh/get-libraries state)
|
libs (wsh/get-libraries state)
|
||||||
component (ctf/find-component libs (:component-id root-inst))
|
component (ctf/get-component libs (:component-file root-inst) (:component-id root-inst))
|
||||||
library (ctf/get-component-library libs root-inst)
|
library (ctf/get-component-library libs root-inst)
|
||||||
|
|
||||||
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
|
||||||
|
@ -165,9 +165,9 @@
|
||||||
|
|
||||||
(defn resolve-component
|
(defn resolve-component
|
||||||
"Get the component with the given id and all its shapes."
|
"Get the component with the given id and all its shapes."
|
||||||
[state component-id]
|
[state component-file component-id]
|
||||||
(let [libs (wsh/get-libraries state)
|
(let [libs (wsh/get-libraries state)
|
||||||
component (ctf/find-component libs component-id)
|
component (ctf/get-component libs component-file component-id)
|
||||||
library (ctf/get-component-library libs component)
|
library (ctf/get-component-library libs component)
|
||||||
shapes-main (ctf/get-component-shapes (:data library) component)]
|
shapes-main (ctf/get-component-shapes (:data library) component)]
|
||||||
|
|
||||||
|
|
|
@ -186,9 +186,9 @@
|
||||||
;; Expected shape tree:
|
;; Expected shape tree:
|
||||||
;;
|
;;
|
||||||
;; [Page: Page]
|
;; [Page: Page]
|
||||||
;; Root Frame
|
;; Root Frame
|
||||||
;; Rect 1 #
|
;; Rect 1 #
|
||||||
;; Rect 1
|
;; Rect 1
|
||||||
;; Rect 1 #
|
;; Rect 1 #
|
||||||
;; Rect 1* @--> Rect 1
|
;; Rect 1* @--> Rect 1
|
||||||
;; Rect 1 ---> Rect 1
|
;; Rect 1 ---> Rect 1
|
||||||
|
@ -362,6 +362,7 @@
|
||||||
component2]
|
component2]
|
||||||
(thl/resolve-component
|
(thl/resolve-component
|
||||||
new-state
|
new-state
|
||||||
|
(:current-file-id new-state)
|
||||||
new-component-id)]
|
new-component-id)]
|
||||||
|
|
||||||
(t/is (= (:name component2) "Rect 1")))))]
|
(t/is (= (:name component2) "Rect 1")))))]
|
||||||
|
@ -657,7 +658,7 @@
|
||||||
;;
|
;;
|
||||||
;; [Board]
|
;; [Board]
|
||||||
;; page1 / Board
|
;; page1 / Board
|
||||||
;;
|
;;
|
||||||
(let [instance1 (thp/get-shape new-state :instance1)
|
(let [instance1 (thp/get-shape new-state :instance1)
|
||||||
|
|
||||||
[[group shape1 shape2]
|
[[group shape1 shape2]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue