mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 01:06:37 +02:00
♻️ Refactor common.page.helpers namespace.
This commit is contained in:
parent
24724e3340
commit
a1da4d4233
55 changed files with 1235 additions and 1348 deletions
|
@ -7,7 +7,6 @@
|
|||
[app.common.uuid :as uuid]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
|
@ -55,26 +54,22 @@
|
|||
|
||||
(defn resolve-instance
|
||||
[state root-inst-id]
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
shapes-inst (cph/get-object-with-children
|
||||
root-inst-id
|
||||
(:objects page))]
|
||||
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
shapes-inst (cph/get-children-with-self (:objects page)
|
||||
root-inst-id)]
|
||||
;; Validate that the instance tree is well constructed
|
||||
(t/is (is-instance-root (first shapes-inst)))
|
||||
(is-instance-root (first shapes-inst))
|
||||
(run! is-instance-child (rest shapes-inst))
|
||||
|
||||
shapes-inst))
|
||||
|
||||
(defn resolve-noninstance
|
||||
[state root-inst-id]
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
shapes-inst (cph/get-object-with-children
|
||||
root-inst-id
|
||||
(:objects page))]
|
||||
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
shapes-inst (cph/get-children-with-self (:objects page)
|
||||
root-inst-id)]
|
||||
;; Validate that the tree is not an instance
|
||||
(run! is-noninstance shapes-inst)
|
||||
|
||||
|
@ -82,31 +77,23 @@
|
|||
|
||||
(defn resolve-instance-and-main
|
||||
[state root-inst-id]
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
|
||||
file (dwlh/get-local-file state)
|
||||
component (cph/get-component
|
||||
(:component-id root-inst)
|
||||
(:id file)
|
||||
file
|
||||
nil)
|
||||
libs (dwlh/get-libraries state)
|
||||
component (cph/get-component libs (:component-id root-inst))
|
||||
|
||||
shapes-inst (cph/get-object-with-children
|
||||
root-inst-id
|
||||
(:objects page))
|
||||
shapes-main (cph/get-object-with-children
|
||||
(:shape-ref root-inst)
|
||||
(:objects component))
|
||||
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
|
||||
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||
|
||||
unique-refs (into #{} (map :shape-ref shapes-inst))
|
||||
unique-refs (into #{} (map :shape-ref) shapes-inst)
|
||||
|
||||
main-exists? (fn [shape]
|
||||
(t/is (some #(= (:id %) (:shape-ref shape))
|
||||
shapes-main)))]
|
||||
main-exists? (fn [shape]
|
||||
(t/is (some #(= (:id %) (:shape-ref shape))
|
||||
shapes-main)))]
|
||||
|
||||
;; Validate that the instance tree is well constructed
|
||||
(t/is (is-instance-root (first shapes-inst)))
|
||||
(is-instance-root (first shapes-inst))
|
||||
(run! is-instance-child (rest shapes-inst))
|
||||
(run! is-noninstance shapes-main)
|
||||
(t/is (= (count shapes-inst)
|
||||
|
@ -118,20 +105,11 @@
|
|||
|
||||
(defn resolve-component
|
||||
[state component-id]
|
||||
(let [page (thp/current-page state)
|
||||
|
||||
file (dwlh/get-local-file state)
|
||||
component (cph/get-component
|
||||
component-id
|
||||
(:id file)
|
||||
file
|
||||
nil)
|
||||
|
||||
root-main (cph/get-component-root
|
||||
component)
|
||||
shapes-main (cph/get-object-with-children
|
||||
(:id root-main)
|
||||
(:objects component))]
|
||||
(let [page (thp/current-page state)
|
||||
libs (dwlh/get-libraries state)
|
||||
component (cph/get-component libs component-id)
|
||||
root-main (cph/get-component-root component)
|
||||
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
|
||||
|
||||
;; Validate that the component tree is well constructed
|
||||
(run! is-noninstance shapes-main)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue