mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
♻️ Refactor common.page.helpers namespace.
This commit is contained in:
committed by
Andrés Moya
parent
24724e3340
commit
a1da4d4233
@@ -197,13 +197,10 @@
|
||||
"Renamed component"))
|
||||
(rx/do
|
||||
(fn [new-state]
|
||||
(let [file (dwlh/get-local-file new-state)
|
||||
component (cph/get-component
|
||||
(:component-id instance1)
|
||||
(:component-file instance1)
|
||||
file
|
||||
{})]
|
||||
|
||||
(let [libs (dwlh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
(t/is (= (:name component)
|
||||
"Renamed component")))))
|
||||
|
||||
@@ -274,13 +271,10 @@
|
||||
new-state
|
||||
(:id instance1))
|
||||
|
||||
file (dwlh/get-local-file new-state)
|
||||
component (cph/get-component
|
||||
(:component-id instance1)
|
||||
(:component-file instance1)
|
||||
file
|
||||
{})]
|
||||
|
||||
libs (dwlh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
(t/is (nil? component)))))
|
||||
|
||||
(rx/subs done #(throw %))))))
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
[app.common.colors :as clr]
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace.changes :as dwc]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
([state label type] (sample-shape state type {}))
|
||||
([state label type props]
|
||||
(let [page (current-page state)
|
||||
frame (cph/get-top-frame (:objects page))
|
||||
frame (cph/get-frame (:objects page))
|
||||
shape (-> (cp/make-minimal-shape type)
|
||||
(gsh/setup {:x 0 :y 0 :width 1 :height 1})
|
||||
(merge props))]
|
||||
|
||||
Reference in New Issue
Block a user