mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
♻️ Refactor state locality
The main purpose of this refactor is reduce a custom state from different pages and unify them under common access patterns
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.workspace.colors :as dc]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[cljs.test :as t :include-macros true]
|
||||
@@ -34,13 +35,10 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
shape1' (get-in new-state [:workspace-data
|
||||
:pages-index
|
||||
(cthi/id :page1)
|
||||
:objects
|
||||
(cthi/id :shape1)])
|
||||
fills' (:fills shape1')
|
||||
fill' (first fills')]
|
||||
objects (dsh/lookup-page-objects new-state)
|
||||
shape1' (get objects (cthi/id :shape1))
|
||||
fills' (:fills shape1')
|
||||
fill' (first fills')]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? shape1'))
|
||||
@@ -68,15 +66,11 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
shape1' (get-in new-state [:workspace-data
|
||||
:pages-index
|
||||
(cthi/id :page1)
|
||||
:objects
|
||||
(cthi/id :shape1)])
|
||||
stroke' (-> (:strokes shape1')
|
||||
first)]
|
||||
objects (dsh/lookup-page-objects new-state)
|
||||
shape1' (get objects (cthi/id :shape1))
|
||||
stroke' (first (:strokes shape1'))]
|
||||
|
||||
;; ==== Check
|
||||
;; ==== Check
|
||||
;; (println stroke')
|
||||
(t/is (some? shape1'))
|
||||
(t/is (= (:stroke-alignment stroke') :inner))
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.pages :as thp]))
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
root-inst (ctn/get-shape page root-inst-id)
|
||||
main-instance? (:main-instance root-inst)
|
||||
|
||||
libs (wsh/get-libraries state)
|
||||
libs (dsh/lookup-libraries state)
|
||||
component (ctf/get-component libs (:component-file root-inst) (:component-id root-inst))
|
||||
library (ctf/get-component-library libs root-inst)
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (ctn/get-shape page root-inst-id)
|
||||
|
||||
libs (wsh/get-libraries state)
|
||||
libs (dsh/lookup-libraries state)
|
||||
component (ctf/get-component libs (:component-file root-inst) (:component-id root-inst))
|
||||
library (ctf/get-component-library libs root-inst)
|
||||
|
||||
@@ -166,7 +166,7 @@
|
||||
(defn resolve-component
|
||||
"Get the component with the given id and all its shapes."
|
||||
[state component-file component-id]
|
||||
(let [libs (wsh/get-libraries state)
|
||||
(let [libs (dsh/lookup-libraries state)
|
||||
component (ctf/get-component libs component-file component-id)
|
||||
library (ctf/get-component-library libs component)
|
||||
shapes-main (ctf/get-component-shapes (:data library) component)]
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.layout :as layout]
|
||||
[app.main.data.workspace.state-helpers :as wsh]))
|
||||
[app.main.data.workspace.layout :as layout]))
|
||||
|
||||
;; ---- Helpers to manage pages and objects
|
||||
|
||||
@@ -33,12 +33,15 @@
|
||||
:current-page-id nil
|
||||
:workspace-layout layout/default-layout
|
||||
:workspace-global layout/default-global
|
||||
:workspace-data {:id current-file-id
|
||||
:options {:components-v2 true}
|
||||
:components {}
|
||||
:pages []
|
||||
:pages-index {}}
|
||||
:workspace-libraries {}
|
||||
|
||||
:files
|
||||
{current-file-id
|
||||
{:id current-file-id
|
||||
:data {:id current-file-id
|
||||
:options {:components-v2 true}
|
||||
:components {}
|
||||
:pages []
|
||||
:pages-index {}}}}
|
||||
:features-team #{"components/v2"}})
|
||||
|
||||
(def ^:private idmap (atom {}))
|
||||
@@ -48,8 +51,9 @@
|
||||
|
||||
(defn current-page
|
||||
[state]
|
||||
(let [page-id (:current-page-id state)]
|
||||
(get-in state [:workspace-data :pages-index page-id])))
|
||||
(let [page-id (:current-page-id state)
|
||||
file-id (:current-file-id state)]
|
||||
(get-in state [:files file-id :data :pages-index page-id])))
|
||||
|
||||
(defn id
|
||||
[label]
|
||||
@@ -65,20 +69,22 @@
|
||||
(let [page (current-page state)]
|
||||
(cfh/get-children (:objects page) (id label))))
|
||||
|
||||
(defn apply-changes
|
||||
[state changes]
|
||||
(let [file-id (:current-file-id state)]
|
||||
(update-in state [:files file-id :data] cp/process-changes changes)))
|
||||
|
||||
(defn sample-page
|
||||
([state] (sample-page state {}))
|
||||
([state {:keys [id name] :as props
|
||||
:or {id (uuid/next)
|
||||
name "page1"}}]
|
||||
|
||||
(swap! idmap assoc :page id)
|
||||
(-> state
|
||||
(assoc :current-page-id id)
|
||||
(update :workspace-data
|
||||
cp/process-changes
|
||||
[{:type :add-page
|
||||
:id id
|
||||
:name name}]))))
|
||||
(apply-changes [{:type :add-page
|
||||
:id id
|
||||
:name name}]))))
|
||||
|
||||
(defn sample-shape
|
||||
([state label type] (sample-shape state type {}))
|
||||
@@ -87,13 +93,12 @@
|
||||
frame (cfh/get-frame (:objects page))
|
||||
shape (cts/setup-shape (merge {:type type :x 0 :y 0 :width 1 :height 1} props))]
|
||||
(swap! idmap assoc label (:id shape))
|
||||
(update state :workspace-data
|
||||
cp/process-changes
|
||||
[{:type :add-obj
|
||||
:id (:id shape)
|
||||
:page-id (:id page)
|
||||
:frame-id (:id frame)
|
||||
:obj shape}]))))
|
||||
(apply-changes state
|
||||
[{:type :add-obj
|
||||
:id (:id shape)
|
||||
:page-id (:id page)
|
||||
:frame-id (:id frame)
|
||||
:obj shape}]))))
|
||||
|
||||
(defn group-shapes
|
||||
([state label ids] (group-shapes state label ids "Group"))
|
||||
@@ -106,8 +111,7 @@
|
||||
(dwg/prepare-create-group (pcb/empty-changes) nil (:objects page) (:id page) shapes prefix true)]
|
||||
|
||||
(swap! idmap assoc label (:id group))
|
||||
(update state :workspace-data
|
||||
cp/process-changes (:redo-changes changes)))))))
|
||||
(apply-changes state (:redo-changes changes)))))))
|
||||
|
||||
(defn frame-shapes
|
||||
([state label ids] (frame-shapes state label ids "Board"))
|
||||
@@ -128,13 +132,12 @@
|
||||
true)]
|
||||
|
||||
(swap! idmap assoc label (:id frame))
|
||||
(update state :workspace-data
|
||||
cp/process-changes (:redo-changes changes)))))))
|
||||
(apply-changes state (:redo-changes changes)))))))
|
||||
|
||||
(defn make-component
|
||||
[state instance-label component-label shape-ids]
|
||||
(let [page (current-page state)
|
||||
objects (wsh/lookup-page-objects state (:id page))
|
||||
objects (dsh/lookup-page-objects state (:id page))
|
||||
shapes (dwg/shapes-for-grouping objects shape-ids)
|
||||
|
||||
[group component-id changes]
|
||||
@@ -149,15 +152,14 @@
|
||||
|
||||
(swap! idmap assoc instance-label (:id group)
|
||||
component-label component-id)
|
||||
(update state :workspace-data
|
||||
cp/process-changes (:redo-changes changes))))
|
||||
(apply-changes state (:redo-changes changes))))
|
||||
|
||||
(defn instantiate-component
|
||||
([state label component-id]
|
||||
(instantiate-component state label component-id current-file-id))
|
||||
([state label component-id file-id]
|
||||
(let [page (current-page state)
|
||||
libraries (wsh/get-libraries state)
|
||||
libraries (dsh/lookup-libraries state)
|
||||
objects (:objects page)
|
||||
|
||||
changes (-> (pcb/empty-changes nil (:id page))
|
||||
@@ -173,26 +175,27 @@
|
||||
libraries)]
|
||||
|
||||
(swap! idmap assoc label (:id new-shape))
|
||||
(update state :workspace-data
|
||||
cp/process-changes (:redo-changes changes)))))
|
||||
(apply-changes state (:redo-changes changes)))))
|
||||
|
||||
(defn move-to-library
|
||||
[state label name]
|
||||
(let [library-id (uuid/next)
|
||||
data (get state :workspace-data)]
|
||||
file-id (:current-file-id state)
|
||||
data (get-in state [:files file-id :data])]
|
||||
(swap! idmap assoc label library-id)
|
||||
(-> state
|
||||
(update :workspace-libraries
|
||||
assoc library-id {:id library-id
|
||||
:name name
|
||||
:data {:id library-id
|
||||
:options (:options data)
|
||||
:pages (:pages data)
|
||||
:pages-index (:pages-index data)
|
||||
:components (:components data)}})
|
||||
(update :workspace-data
|
||||
assoc :components {} :pages [] :pages-index {}))))
|
||||
|
||||
(update :files assoc library-id
|
||||
{:id library-id
|
||||
:name name
|
||||
:data {:id library-id
|
||||
:options (:options data)
|
||||
:pages (:pages data)
|
||||
:pages-index (:pages-index data)
|
||||
:components (:components data)}})
|
||||
(update-in [:files file-id :data] assoc
|
||||
:components {}
|
||||
:pages []
|
||||
:pages-index {}))))
|
||||
|
||||
(defn simulate-copy-shape
|
||||
[selected objects libraries page file features version]
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
:workspace-global layout/default-global
|
||||
:current-file-id nil
|
||||
:current-page-id nil
|
||||
:workspace-data nil
|
||||
:workspace-libraries {}
|
||||
:features-team #{"components/v2"}})
|
||||
|
||||
(defn- on-error
|
||||
@@ -34,8 +32,7 @@
|
||||
(assoc :current-file-id (:id file)
|
||||
:current-page-id (cthf/current-page-id file)
|
||||
:permissions {:can-edit true}
|
||||
:workspace-file (dissoc file :data)
|
||||
:workspace-data (:data file)))
|
||||
:files {(:id file) file}))
|
||||
store (ptk/store {:state state :on-error on-error})]
|
||||
store))
|
||||
|
||||
@@ -64,7 +61,7 @@
|
||||
|
||||
(ptk/emit! store :the/end))))
|
||||
|
||||
(defn get-file-from-store
|
||||
[store]
|
||||
(-> (:workspace-file store)
|
||||
(assoc :data (:workspace-data store))))
|
||||
(defn get-file-from-state
|
||||
[state]
|
||||
(let [file-id (:current-file-id state)]
|
||||
(get-in state [:files file-id])))
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
blue1' (cths/get-shape file' :blue1)
|
||||
copied-blue1' (find-copied-shape blue1' page' uuid/zero)]
|
||||
@@ -155,7 +155,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b1' (cths/get-shape file' :frame-b1)
|
||||
blue1' (cths/get-shape file' :blue1)
|
||||
@@ -193,7 +193,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
yellow' (cths/get-shape file' :frame-yellow)
|
||||
blue1' (cths/get-shape file' :blue1)
|
||||
@@ -232,7 +232,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b2' (cths/get-shape file' :frame-b2)
|
||||
blue1' (cths/get-shape file' :blue1)
|
||||
@@ -272,7 +272,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
copied-blue1' (find-copied-shape blue1 page' uuid/zero)]
|
||||
|
||||
@@ -309,7 +309,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
yellow' (cths/get-shape file' :frame-yellow)
|
||||
copied-blue1' (find-copied-shape blue1 page' (:id yellow'))]
|
||||
@@ -346,7 +346,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b2' (cths/get-shape file' :frame-b2)
|
||||
copied-blue1' (find-copied-shape blue1 page' (:id b2'))]
|
||||
@@ -380,7 +380,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
copied-yellow' (find-copied-shape yellow page' uuid/zero)
|
||||
blue1' (cths/get-shape file' :blue1)
|
||||
@@ -419,7 +419,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b1' (cths/get-shape file' :frame-b1)
|
||||
copied-yellow' (find-copied-shape yellow page' (:id b1'))
|
||||
@@ -459,7 +459,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b2' (cths/get-shape file' :frame-b2)
|
||||
copied-yellow' (find-copied-shape yellow page' (:id b2'))
|
||||
@@ -500,7 +500,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
copied-yellow' (find-copied-shape yellow page' uuid/zero)
|
||||
copied-blue1' (find-copied-shape blue1 page' (:id copied-yellow'))]
|
||||
@@ -537,7 +537,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b1' (cths/get-shape file' :frame-b1)
|
||||
copied-yellow' (find-copied-shape yellow page' (:id b1'))
|
||||
@@ -575,7 +575,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b2' (cths/get-shape file' :frame-b2)
|
||||
copied-yellow' (find-copied-shape yellow page' (:id b2'))
|
||||
@@ -609,7 +609,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
blue2' (cths/get-shape file' :blue-copy-in-green-copy)
|
||||
copied-green' (find-copied-shape green page' uuid/zero)
|
||||
@@ -648,7 +648,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b1' (cths/get-shape file' :frame-b1)
|
||||
blue2' (cths/get-shape file' :blue-copy-in-green-copy)
|
||||
@@ -688,7 +688,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b2' (cths/get-shape file' :frame-b2)
|
||||
blue2' (cths/get-shape file' :blue-copy-in-green-copy)
|
||||
@@ -731,7 +731,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
copied-green' (find-copied-shape green page' uuid/zero)
|
||||
copied-blue1' (find-copied-shape blue2 page' (:id copied-green'))]
|
||||
@@ -768,7 +768,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b1' (cths/get-shape file' :frame-b1)
|
||||
copied-green' (find-copied-shape green page' (:id b1'))
|
||||
@@ -806,7 +806,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
b2' (cths/get-shape file' :frame-b2)
|
||||
copied-green' (find-copied-shape green page' (:id b2'))
|
||||
@@ -855,7 +855,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
green' (cths/get-shape file' :frame-green)
|
||||
blue1' (cths/get-shape file' :blue1)
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.test-helpers.tokens :as ctht]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.data.tokens :as dt]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.ui.workspace.tokens.changes :as wtch]
|
||||
[app.main.ui.workspace.tokens.update :as wtu]
|
||||
[cljs.test :as t :include-macros true]
|
||||
@@ -79,7 +79,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
frame1' (cths/get-shape file' :frame1)
|
||||
tokens-frame1' (:applied-tokens frame1')]
|
||||
|
||||
@@ -111,8 +111,8 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
selected (wsh/lookup-selected new-state)
|
||||
c-frame1' (wsh/lookup-shape new-state (first selected))
|
||||
selected (dsh/lookup-selected new-state)
|
||||
c-frame1' (dsh/lookup-shape new-state (first selected))
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
|
||||
;; ==== Check
|
||||
@@ -145,7 +145,7 @@
|
||||
store done events2
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
c-frame1' (cths/get-shape file' :c-frame1)
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
store done events2
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
c-frame1' (cths/get-shape file' :c-frame1)
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
|
||||
@@ -215,7 +215,7 @@
|
||||
store done events2
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
c-frame1' (cths/get-shape file' :c-frame1)
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
|
||||
@@ -256,7 +256,7 @@
|
||||
store done events2
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
c-frame1' (cths/get-shape file' :c-frame1)
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
|
||||
@@ -296,7 +296,7 @@
|
||||
store done events2
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
c-frame1' (cths/get-shape file' :c-frame1)
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
|
||||
@@ -390,7 +390,7 @@
|
||||
store done events2
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
frame1' (cths/get-shape file' :frame1)
|
||||
c-frame1' (cths/get-shape file' :c-frame1)
|
||||
tokens-frame1' (:applied-tokens c-frame1')]
|
||||
@@ -423,4 +423,4 @@
|
||||
(t/is (empty? (:touched c-frame1'))))))))]
|
||||
|
||||
(tohs/run-store-async
|
||||
store step2 events identity))))
|
||||
store step2 events identity))))
|
||||
|
||||
@@ -126,31 +126,32 @@
|
||||
(not (:component-root %))))
|
||||
(map :id))]
|
||||
(concat
|
||||
(apply concat (mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids))
|
||||
(apply concat (mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids)))))
|
||||
(apply concat
|
||||
(mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids))
|
||||
(apply concat
|
||||
(mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids)))))
|
||||
|
||||
(t/deftest main-and-first-level-copy-1
|
||||
(t/async
|
||||
done
|
||||
(t/async done
|
||||
(with-redefs [uuid/next cthi/next-uuid]
|
||||
(let [;; ==== Setup
|
||||
file (setup-file)
|
||||
store (ths/setup-store file)
|
||||
;; ==== Action
|
||||
;; ==== Action
|
||||
|
||||
|
||||
;; For each main and first level copy:
|
||||
;; - Duplicate it two times with copy-paste.
|
||||
;; For each main and first level copy:
|
||||
;; - Duplicate it two times with copy-paste.
|
||||
events
|
||||
(concat
|
||||
(duplicate-each-main-and-first-level-copy file)
|
||||
;; - Change color of Simple1
|
||||
;; - Change color of Simple1
|
||||
(set-color-bottom-shape :frame-simple-1 file {:color "#111111"}))]
|
||||
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#111111") 18)))))))))
|
||||
|
||||
(t/deftest main-and-first-level-copy-2
|
||||
@@ -176,7 +177,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#222222") 15)))))))))
|
||||
|
||||
(t/deftest main-and-first-level-copy-3
|
||||
@@ -203,7 +204,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#333333") 12)))))))))
|
||||
|
||||
|
||||
@@ -232,7 +233,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#444444") 6)))))))))
|
||||
|
||||
(t/deftest copy-nested-in-main-1
|
||||
@@ -255,7 +256,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
;; Check propagation to all copies.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#111111") 28)))))))))
|
||||
|
||||
@@ -279,7 +280,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
;; Check propagation to duplicated.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#222222") 9)))))))))
|
||||
|
||||
@@ -303,7 +304,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
;; Check that it's NOT PROPAGATED.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#333333") 2)))))))))
|
||||
|
||||
@@ -328,7 +329,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
;; Check propagation to all copies.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#111111") 20)))))))))
|
||||
|
||||
@@ -357,7 +358,7 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)]
|
||||
(let [file' (ths/get-file-from-state new-state)]
|
||||
;; Check that it's NOT PROPAGATED.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#111111") 11))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#222222") 7))
|
||||
@@ -365,8 +366,7 @@
|
||||
|
||||
|
||||
(t/deftest copy-nested-3
|
||||
(t/async
|
||||
done
|
||||
(t/async done
|
||||
(with-redefs [uuid/next cthi/next-uuid]
|
||||
(let [;; ==== Setup
|
||||
file (setup-file)
|
||||
@@ -388,9 +388,9 @@
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (-> (ths/get-file-from-store new-state)
|
||||
(let [file' (-> (ths/get-file-from-state new-state)
|
||||
(cthf/switch-to-page :page-2))]
|
||||
;; Check that it's NOT PROPAGATED.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#111111") 10))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#222222") 4))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#333333") 0)))))))))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#333333") 0)))))))))
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
|
||||
guide' (-> page'
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-store new-state)
|
||||
file' (ths/get-file-from-state new-state)
|
||||
page' (cthf/current-page file')
|
||||
group-id (->> (:objects page')
|
||||
vals
|
||||
|
||||
@@ -18,17 +18,20 @@
|
||||
|
||||
(t/deftest test-common-shape-properties
|
||||
(let [;; ==== Setup
|
||||
store
|
||||
(ths/setup-store (cthf/sample-file :file1 :page-label :page1))
|
||||
|
||||
_ (set! st/state store)
|
||||
store (ths/setup-store
|
||||
(cthf/sample-file :file1 :page-label :page1))
|
||||
|
||||
^js context (api/create-context "TEST")
|
||||
|
||||
_ (set! st/state store)
|
||||
context (api/create-context "TEST")
|
||||
|
||||
^js file (. context -currentFile)
|
||||
^js page (. context -currentPage)
|
||||
^js shape (.createRectangle context)
|
||||
|
||||
get-shape-path
|
||||
#(vector :workspace-data :pages-index (aget page "$id") :objects (aget shape "$id") %)]
|
||||
#(vector :files (aget file "$id") :data :pages-index (aget page "$id") :objects (aget shape "$id") %)]
|
||||
|
||||
(t/testing "Basic shape properites"
|
||||
(t/testing " - name"
|
||||
@@ -214,9 +217,9 @@
|
||||
(t/testing " - strokes"
|
||||
(set! (.-strokes shape) #js [#js {:strokeColor "#fabada" :strokeOpacity 1 :strokeWidth 5}])
|
||||
(t/is (= (get-in @store (get-shape-path :strokes)) [{:stroke-color "#fabada" :stroke-opacity 1 :stroke-width 5}]))
|
||||
(t/is (= (-> (. shape -strokes) (aget 0) (aget "strokeColor")) "#fabada"))
|
||||
(t/is (= (-> (. shape -strokes) (aget 0) (aget "strokeOpacity")) 1))
|
||||
(t/is (= (-> (. shape -strokes) (aget 0) (aget "strokeWidth")) 5))))
|
||||
(t/is (= (-> (. ^js shape -strokes) (aget 0) (aget "strokeColor")) "#fabada"))
|
||||
(t/is (= (-> (. ^js shape -strokes) (aget 0) (aget "strokeOpacity")) 1))
|
||||
(t/is (= (-> (. ^js shape -strokes) (aget 0) (aget "strokeWidth")) 5))))
|
||||
|
||||
(t/testing "Relative properties"
|
||||
(let [board (.createBoard context)]
|
||||
@@ -227,29 +230,28 @@
|
||||
(.appendChild board shape)
|
||||
|
||||
(t/testing " - boardX"
|
||||
(set! (.-boardX shape) 10)
|
||||
(t/is (m/close? (.-boardX shape) 10))
|
||||
(set! (.-boardX ^js shape) 10)
|
||||
(t/is (m/close? (.-boardX ^js shape) 10))
|
||||
(t/is (m/close? (.-x shape) 110))
|
||||
(t/is (m/close? (get-in @store (get-shape-path :x)) 110)))
|
||||
|
||||
(t/testing " - boardY"
|
||||
(set! (.-boardY shape) 20)
|
||||
(t/is (m/close? (.-boardY shape) 20))
|
||||
(set! (.-boardY ^js shape) 20)
|
||||
(t/is (m/close? (.-boardY ^js shape) 20))
|
||||
(t/is (m/close? (.-y shape) 220))
|
||||
(t/is (m/close? (get-in @store (get-shape-path :y)) 220)))
|
||||
|
||||
(t/testing " - parentX"
|
||||
(set! (.-parentX shape) 30)
|
||||
(t/is (m/close? (.-parentX shape) 30))
|
||||
(set! (.-parentX ^js shape) 30)
|
||||
(t/is (m/close? (.-parentX ^js shape) 30))
|
||||
(t/is (m/close? (.-x shape) 130))
|
||||
(t/is (m/close? (get-in @store (get-shape-path :x)) 130)))
|
||||
|
||||
(t/testing " - parentY"
|
||||
(set! (.-parentY shape) 40)
|
||||
(t/is (m/close? (.-parentY shape) 40))
|
||||
(set! (.-parentY ^js shape) 40)
|
||||
(t/is (m/close? (.-parentY ^js shape) 40))
|
||||
(t/is (m/close? (.-y shape) 240))
|
||||
(t/is (m/close? (get-in @store (get-shape-path :y)) 240)))))
|
||||
|
||||
(t/testing "Clone")
|
||||
(t/testing "Remove")))
|
||||
|
||||
|
||||
@@ -41,9 +41,8 @@
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
(t/is (= (get-in new-state [:workspace-data
|
||||
:recent-colors])
|
||||
[color]))))]
|
||||
(let [colors (:recent-colors new-state)]
|
||||
(t/is (= colors [color])))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns frontend-tests.tokens.helpers.state
|
||||
(:require
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
@@ -22,10 +23,11 @@
|
||||
(ptk/reify ::end+
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(->> (rx/from (-> (get-in state [:workspace-data :tokens-lib])
|
||||
(ctob/get-active-themes-set-tokens)
|
||||
(sd/resolve-tokens+)))
|
||||
(rx/mapcat #(rx/of (end)))))))
|
||||
(let [data (dsh/lookup-file-data state)]
|
||||
(->> (rx/from (-> (get data :tokens-lib)
|
||||
(ctob/get-active-themes-set-tokens)
|
||||
(sd/resolve-tokens+)))
|
||||
(rx/mapcat #(rx/of (end))))))))
|
||||
|
||||
(defn stop-on
|
||||
"Helper function to be used with async version of run-store.
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
(ctob/get-active-themes-set-tokens)
|
||||
(get name)))
|
||||
|
||||
(defn apply-token-to-shape [file shape-label token-label attributes]
|
||||
(defn apply-token-to-shape
|
||||
[file shape-label token-label attributes]
|
||||
(let [first-page-id (get-in file [:data :pages 0])
|
||||
shape-id (thi/id shape-label)
|
||||
token (get-token file token-label)
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
(t/testing "applies token to shape and updates shape attributes to resolved value"
|
||||
(t/async
|
||||
done
|
||||
(let [file (setup-file-with-tokens)
|
||||
store (ths/setup-store file)
|
||||
(let [file (setup-file-with-tokens)
|
||||
store (ths/setup-store file)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
events [(wtch/apply-token {:shape-ids [(:id rect-1)]
|
||||
:attributes #{:r1 :r2 :r3 :r4}
|
||||
@@ -55,12 +55,14 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
token (toht/get-token file' "borderRadius.md")
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token (toht/get-token file' "borderRadius.md")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
|
||||
(t/testing "shape `:applied-tokens` got updated"
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
(t/is (= (:r1 (:applied-tokens rect-1')) (:name token))))
|
||||
|
||||
(t/testing "shape radius got update to the resolved token value."
|
||||
(t/is (= (:r1 rect-1') 24))))))))))
|
||||
|
||||
@@ -82,7 +84,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token (toht/get-token file' "borderRadius.md")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/testing "shape `:applied-tokens` got updated"
|
||||
@@ -113,7 +115,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-sm (toht/get-token file' "borderRadius.sm")
|
||||
token-md (toht/get-token file' "borderRadius.md")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
@@ -145,7 +147,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-target' (toht/get-token file' "rotation.medium")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
@@ -173,7 +175,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-target' (toht/get-token file' "dimensions.sm")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/testing "shape `:applied-tokens` got updated"
|
||||
@@ -203,7 +205,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-target' (toht/get-token file' "sizing.sm")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/testing "shape `:applied-tokens` got updated"
|
||||
@@ -252,7 +254,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
rect-1' (cths/get-shape file' :rect-1)
|
||||
rect-2' (cths/get-shape file' :rect-2)
|
||||
rect-3' (cths/get-shape file' :rect-3)
|
||||
@@ -288,7 +290,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-target' (toht/get-token file' "rotation.medium")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
@@ -319,7 +321,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-target' (toht/get-token file' "stroke-width.sm")
|
||||
rect-with-stroke' (cths/get-shape file' :rect-1)
|
||||
rect-without-stroke' (cths/get-shape file' :rect-2)]
|
||||
@@ -345,7 +347,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-2' (toht/get-token file' "borderRadius.md")
|
||||
rect-1' (cths/get-shape file' :rect-1)
|
||||
rect-2' (cths/get-shape file' :rect-2)]
|
||||
@@ -375,7 +377,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
rect-with-token' (cths/get-shape file' :rect-1)
|
||||
rect-without-token' (cths/get-shape file' :rect-2)
|
||||
rect-with-other-token' (cths/get-shape file' :rect-3)]
|
||||
@@ -408,7 +410,7 @@
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
target-token (toht/get-token file' "borderRadius.sm")
|
||||
rect-with-other-token-1' (cths/get-shape file' :rect-1)
|
||||
rect-without-token' (cths/get-shape file' :rect-2)
|
||||
|
||||
Reference in New Issue
Block a user