mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 16:21:57 -05:00
State keys naming refactor.
This commit is contained in:
parent
7abfaf639e
commit
7b7fd7680f
30 changed files with 207 additions and 207 deletions
|
@ -115,7 +115,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [item (get-in state [:workspace :history :by-version version])
|
||||
page (get-in state [:pages-by-id (:page item)])
|
||||
page (get-in state [:pages (:page item)])
|
||||
page (assoc page
|
||||
:history true
|
||||
:data (:data item))]
|
||||
|
@ -133,7 +133,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(-> state
|
||||
(update-in [:pages-by-id id] dissoc :history)
|
||||
(update-in [:pages id] dissoc :history)
|
||||
(assoc-in [:workspace :history :selected] nil)))
|
||||
|
||||
rs/WatchEvent
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
(reduce (fn [state item]
|
||||
(let [id (:id item)
|
||||
item (assoc item :type :own)]
|
||||
(assoc-in state [:icon-colls-by-id id] item)))
|
||||
(assoc-in state [:icon-collections id] item)))
|
||||
state
|
||||
items)))
|
||||
|
||||
|
@ -90,7 +90,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [{:keys [id] :as item} (assoc item :type :own)]
|
||||
(update state :icon-colls-by-id assoc id item)))
|
||||
(update state :icon-collections assoc id item)))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
|
@ -124,7 +124,7 @@
|
|||
(defrecord CollectionUpdated [item]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:icon-colls-by-id (:id item)] merge item)))
|
||||
(update-in state [:icon-collections (:id item)] merge item)))
|
||||
|
||||
(defn collection-updated
|
||||
[item]
|
||||
|
@ -135,7 +135,7 @@
|
|||
(defrecord UpdateCollection [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [item (get-in state [:icon-colls-by-id id])]
|
||||
(let [item (get-in state [:icon-collections id])]
|
||||
(->> (rp/req :update/icon-collection item)
|
||||
(rx/map :payload)
|
||||
(rx/map collection-updated)))))
|
||||
|
@ -149,7 +149,7 @@
|
|||
(defrecord RenameCollection [id name]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:icon-colls-by-id id :name] name))
|
||||
(assoc-in state [:icon-collections id :name] name))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
|
@ -164,7 +164,7 @@
|
|||
(defrecord DeleteCollection [id]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update state :icon-colls-by-id dissoc id))
|
||||
(update state :icon-collections dissoc id))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
|
@ -182,7 +182,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [{:keys [id] :as item} (assoc item :type :icon)]
|
||||
(update state :icons-by-id assoc id item))))
|
||||
(update state :icons assoc id item))))
|
||||
|
||||
(defn icon-created
|
||||
[item]
|
||||
|
@ -250,7 +250,7 @@
|
|||
(defrecord IconUpdated [id data]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:icons-by-id id] data)))
|
||||
(assoc-in state [:icons id] data)))
|
||||
|
||||
(defn icon-updated
|
||||
[{:keys [id] :as data}]
|
||||
|
@ -262,7 +262,7 @@
|
|||
(defrecord UpdateIcon [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
(let [icon (get-in state [:icons-by-id id])]
|
||||
(let [icon (get-in state [:icons id])]
|
||||
(->> (rp/req :update/icon icon)
|
||||
(rx/map :payload)
|
||||
(rx/map icon-updated)))))
|
||||
|
@ -279,7 +279,7 @@
|
|||
(-apply-update [_ state]
|
||||
(reduce (fn [state {:keys [id] :as icon}]
|
||||
(let [icon (assoc icon :type :icon)]
|
||||
(assoc-in state [:icons-by-id id] icon)))
|
||||
(assoc-in state [:icons id] icon)))
|
||||
state
|
||||
items)))
|
||||
|
||||
|
@ -308,7 +308,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(-> state
|
||||
(update :icons-by-id dissoc id)
|
||||
(update :icons dissoc id)
|
||||
(update-in [:dashboard :icons :selected] disj id)))
|
||||
|
||||
rs/WatchEvent
|
||||
|
@ -357,7 +357,7 @@
|
|||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
(let [selected (get-in state [:dashboard :icons :selected])
|
||||
selected (map #(get-in state [:icons-by-id %]) selected)]
|
||||
selected (map #(get-in state [:icons %]) selected)]
|
||||
(->> (rx/from-coll selected)
|
||||
(rx/map #(dissoc % :id))
|
||||
(rx/map #(assoc % :collection id))
|
||||
|
@ -377,7 +377,7 @@
|
|||
(-apply-update [_ state]
|
||||
(let [selected (get-in state [:dashboard :icons :selected])]
|
||||
(reduce (fn [state icon]
|
||||
(assoc-in state [:icons-by-id icon :collection] id))
|
||||
(assoc-in state [:icons icon :collection] id))
|
||||
state
|
||||
selected)))
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
(reduce (fn [state item]
|
||||
(let [id (:id item)
|
||||
item (assoc item :type :own)]
|
||||
(assoc-in state [:image-colls-by-id id] item)))
|
||||
(assoc-in state [:image-collections id] item)))
|
||||
state
|
||||
items)))
|
||||
|
||||
|
@ -90,7 +90,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [{:keys [id] :as item} (assoc item :type :own)]
|
||||
(update state :image-colls-by-id assoc id item)))
|
||||
(update state :image-collections assoc id item)))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
|
@ -124,7 +124,7 @@
|
|||
(defrecord CollectionUpdated [item]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:image-colls-by-id (:id item)] merge item)))
|
||||
(update-in state [:image-collections (:id item)] merge item)))
|
||||
|
||||
(defn collection-updated
|
||||
[item]
|
||||
|
@ -135,7 +135,7 @@
|
|||
(defrecord UpdateCollection [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [item (get-in state [:image-colls-by-id id])]
|
||||
(let [item (get-in state [:image-collections id])]
|
||||
(->> (rp/req :update/image-collection item)
|
||||
(rx/map :payload)
|
||||
(rx/map collection-updated)))))
|
||||
|
@ -149,7 +149,7 @@
|
|||
(defrecord RenameCollection [id name]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:image-colls-by-id id :name] name))
|
||||
(assoc-in state [:image-collections id :name] name))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
|
@ -164,7 +164,7 @@
|
|||
(defrecord DeleteCollection [id]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update state :image-colls-by-id dissoc id))
|
||||
(update state :image-collections dissoc id))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
|
@ -181,7 +181,7 @@
|
|||
(defrecord ImageCreated [item]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update state :images-by-id assoc (:id item) item)))
|
||||
(update state :images assoc (:id item) item)))
|
||||
|
||||
(defn image-created
|
||||
[item]
|
||||
|
@ -237,7 +237,7 @@
|
|||
(defrecord ImageUpdated [id data]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:images-by-id id] data)))
|
||||
(assoc-in state [:images id] data)))
|
||||
|
||||
(defn image-updated
|
||||
[{:keys [id] :as data}]
|
||||
|
@ -249,7 +249,7 @@
|
|||
(defrecord UpdateImage [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
(let [image (get-in state [:images-by-id id])]
|
||||
(let [image (get-in state [:images id])]
|
||||
(->> (rp/req :update/image image)
|
||||
(rx/map :payload)
|
||||
(rx/map image-updated)))))
|
||||
|
@ -265,7 +265,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(reduce (fn [state {:keys [id] :as image}]
|
||||
(assoc-in state [:images-by-id id] image))
|
||||
(assoc-in state [:images id] image))
|
||||
state
|
||||
items)))
|
||||
|
||||
|
@ -296,7 +296,7 @@
|
|||
(defrecord FetchImage [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
(let [existing (get-in state [:images-by-id id])]
|
||||
(let [existing (get-in state [:images id])]
|
||||
(if existing
|
||||
(rx/empty)
|
||||
(->> (rp/req :fetch/image {:id id})
|
||||
|
@ -316,7 +316,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [id (:id image)]
|
||||
(update state :images-by-id assoc id image))))
|
||||
(update state :images assoc id image))))
|
||||
|
||||
(defn image-fetched
|
||||
[image]
|
||||
|
@ -329,7 +329,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(-> state
|
||||
(update :images-by-id dissoc id)
|
||||
(update :images dissoc id)
|
||||
(update-in [:dashboard :images :selected] disj id)))
|
||||
|
||||
rs/WatchEvent
|
||||
|
@ -378,7 +378,7 @@
|
|||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
(let [selected (get-in state [:dashboard :images :selected])
|
||||
selected (map #(get-in state [:images-by-id %]) selected)]
|
||||
selected (map #(get-in state [:images %]) selected)]
|
||||
(->> (rx/from-coll selected)
|
||||
(rx/map #(dissoc % :id))
|
||||
(rx/map #(assoc % :collection id))
|
||||
|
@ -398,7 +398,7 @@
|
|||
(-apply-update [_ state]
|
||||
(let [selected (get-in state [:dashboard :images :selected])]
|
||||
(reduce (fn [state image]
|
||||
(assoc-in state [:images-by-id image :collection] id))
|
||||
(assoc-in state [:images image :collection] id))
|
||||
state
|
||||
selected)))
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
|
||||
(defn dissoc-page-shapes
|
||||
[state id]
|
||||
(let [shapes (get-in state [:shapes-by-id])]
|
||||
(assoc state :shapes-by-id (reduce-kv (fn [acc k v]
|
||||
(let [shapes (get-in state [:shapes])]
|
||||
(assoc state :shapes (reduce-kv (fn [acc k v]
|
||||
(if (= (:page v) id)
|
||||
(dissoc acc k)
|
||||
acc))
|
||||
|
@ -39,12 +39,12 @@
|
|||
"Return a packed version of page object ready
|
||||
for send to remore storage service."
|
||||
[state id]
|
||||
(let [page (get-in state [:pages-by-id id])
|
||||
(let [page (get-in state [:pages id])
|
||||
xf (filter #(= (:page (second %)) id))
|
||||
shapes (into {} xf (:shapes-by-id state))]
|
||||
shapes (into {} xf (:shapes state))]
|
||||
(-> page
|
||||
(assoc-in [:data :shapes] (into [] (:shapes page)))
|
||||
(assoc-in [:data :shapes-by-id] shapes)
|
||||
(assoc-in [:data :shapes] shapes)
|
||||
(update-in [:data] dissoc :items)
|
||||
(dissoc :shapes))))
|
||||
|
||||
|
@ -54,18 +54,18 @@
|
|||
[state page]
|
||||
(let [data (:data page)
|
||||
shapes (:shapes data)
|
||||
shapes-by-id (:shapes-by-id data)
|
||||
shapes-by-id (:shapes data)
|
||||
page (-> (dissoc page :data)
|
||||
(assoc :shapes shapes))]
|
||||
(-> state
|
||||
(update :shapes-by-id merge shapes-by-id)
|
||||
(update :pages-by-id assoc (:id page) page))))
|
||||
(update :shapes merge shapes-by-id)
|
||||
(update :pages assoc (:id page) page))))
|
||||
|
||||
(defn purge-page
|
||||
"Remove page and all related stuff from the state."
|
||||
[state id]
|
||||
(-> state
|
||||
(update :pages-by-id dissoc id)
|
||||
(update :pages dissoc id)
|
||||
(update :pagedata-by-id dissoc id)
|
||||
(dissoc-page-shapes id)))
|
||||
|
||||
|
@ -134,7 +134,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [this state]
|
||||
(-> state
|
||||
(assoc-in [:pages-by-id (:id page) :version] (:version page))
|
||||
(assoc-in [:pages (:id page) :version] (:version page))
|
||||
(assoc-page page))))
|
||||
|
||||
(defn- page-synced?
|
||||
|
@ -159,7 +159,7 @@
|
|||
(defrecord UpdatePage [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [this state s]
|
||||
(let [page (get-in state [:pages-by-id id])]
|
||||
(let [page (get-in state [:pages id])]
|
||||
(if (:history page)
|
||||
(rx/empty)
|
||||
(rx/of (sync-page id))))))
|
||||
|
@ -204,12 +204,12 @@
|
|||
(when width {:width width})
|
||||
(when height {:height height})
|
||||
(when name {:name name})))]
|
||||
(update-in state [:pages-by-id id] updater)))
|
||||
(update-in state [:pages id] updater)))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [this state s]
|
||||
(letfn [(on-success [{page :payload}]
|
||||
#(assoc-in % [:pages-by-id id :version] (:version page)))]
|
||||
#(assoc-in % [:pages id :version] (:version page)))]
|
||||
(->> (rp/req :update/page-metadata (into {} this))
|
||||
(rx/map on-success)))))
|
||||
|
||||
|
@ -233,7 +233,7 @@
|
|||
(defrecord UpdatePageOptions [id options]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [this state s]
|
||||
(let [page (get-in state [:pages-by-id id])
|
||||
(let [page (get-in state [:pages id])
|
||||
page (assoc page :options options)]
|
||||
(rx/of (map->UpdatePageMetadata page)))))
|
||||
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
to the state map."
|
||||
[state proj]
|
||||
(let [id (:id proj)]
|
||||
(update-in state [:projects-by-id id] merge proj)))
|
||||
(update-in state [:projects id] merge proj)))
|
||||
|
||||
(defn dissoc-project
|
||||
"A reduce function for dissoc the project
|
||||
from the state map."
|
||||
[state id]
|
||||
(update-in state [:projects-by-id] dissoc id))
|
||||
(update-in state [:projects] dissoc id))
|
||||
|
||||
;; --- Initialize
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [shape (get-in state [:shapes-by-id id])]
|
||||
(let [shape (get-in state [:shapes id])]
|
||||
(impl/dissoc-shape state shape)))))
|
||||
|
||||
(defn update-shape
|
||||
|
@ -51,7 +51,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id id] merge shape))))
|
||||
(update-in state [:shapes id] merge shape))))
|
||||
|
||||
;; --- Shape Transformations
|
||||
|
||||
|
@ -62,8 +62,8 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(update-in state [:shapes-by-id sid] geom/move delta)))))
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(update-in state [:shapes sid] geom/move delta)))))
|
||||
|
||||
(declare align-point)
|
||||
|
||||
|
@ -76,7 +76,7 @@
|
|||
(reify
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id id])
|
||||
(let [shape (get-in state [:shapes id])
|
||||
shape (geom/outer-rect state shape)
|
||||
point (gpt/point (:x shape) (:y shape))
|
||||
point (gpt/add point canvas-coords)]
|
||||
|
@ -90,10 +90,10 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [shape (get-in state [:shapes-by-id sid])
|
||||
(let [shape (get-in state [:shapes sid])
|
||||
props (select-keys opts [:x1 :y1 :x2 :y2])
|
||||
props' (select-keys shape [:x1 :y1 :x2 :y2])]
|
||||
(update-in state [:shapes-by-id sid] geom/setup
|
||||
(update-in state [:shapes sid] geom/setup
|
||||
(merge props' props))))))
|
||||
|
||||
(defn update-rotation
|
||||
|
@ -105,7 +105,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid]
|
||||
(update-in state [:shapes sid]
|
||||
geom/rotate rotation))))
|
||||
|
||||
(defn update-size
|
||||
|
@ -118,7 +118,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid] geom/resize-dim opts))))
|
||||
(update-in state [:shapes sid] geom/resize-dim opts))))
|
||||
|
||||
(defn update-vertex-position
|
||||
[id {:keys [vid delta]}]
|
||||
|
@ -126,14 +126,14 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id id] geom/move-vertex vid delta))))
|
||||
(update-in state [:shapes id] geom/move-vertex vid delta))))
|
||||
|
||||
(defn initial-vertext-align
|
||||
[id vid]
|
||||
(reify
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id id])
|
||||
(let [shape (get-in state [:shapes id])
|
||||
point (geom/get-vertex-point shape vid)
|
||||
point (gpt/add point canvas-coords)]
|
||||
(->> (align-point point)
|
||||
|
@ -146,7 +146,7 @@
|
|||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid] geom/absolute-move opts))))
|
||||
(update-in state [:shapes sid] geom/absolute-move opts))))
|
||||
|
||||
(defn update-text
|
||||
[sid {:keys [content]}]
|
||||
|
@ -155,7 +155,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :content] content))))
|
||||
(assoc-in state [:shapes sid :content] content))))
|
||||
|
||||
(defn update-fill-attrs
|
||||
[sid {:keys [color opacity] :as opts}]
|
||||
|
@ -163,7 +163,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid]
|
||||
(update-in state [:shapes sid]
|
||||
merge
|
||||
(when color {:fill color})
|
||||
(when opacity {:fill-opacity opacity})))))
|
||||
|
@ -175,7 +175,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid :font]
|
||||
(update-in state [:shapes sid :font]
|
||||
merge
|
||||
(when line-height {:line-height line-height})
|
||||
(when letter-spacing {:letter-spacing letter-spacing})
|
||||
|
@ -191,7 +191,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid]
|
||||
(update-in state [:shapes sid]
|
||||
merge
|
||||
(when type {:stroke-type type})
|
||||
(when width {:stroke-width width})
|
||||
|
@ -204,7 +204,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid]
|
||||
(update-in state [:shapes sid]
|
||||
merge
|
||||
(when rx {:rx rx})
|
||||
(when ry {:ry ry})))))
|
||||
|
@ -221,11 +221,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [[width height] (-> (get-in state [:shapes-by-id sid])
|
||||
(let [[width height] (-> (get-in state [:shapes sid])
|
||||
(geom/size)
|
||||
(keep [:width :height]))
|
||||
proportion (/ width height)]
|
||||
(update-in state [:shapes-by-id sid] assoc
|
||||
(update-in state [:shapes sid] assoc
|
||||
:proportion proportion
|
||||
:proportion-lock true)))))
|
||||
|
||||
|
@ -236,7 +236,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id sid] assoc
|
||||
(update-in state [:shapes sid] assoc
|
||||
:proportion-lock false))))
|
||||
|
||||
;; --- Group Collapsing
|
||||
|
@ -248,7 +248,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id id] assoc :collapsed true))))
|
||||
(update-in state [:shapes id] assoc :collapsed true))))
|
||||
|
||||
(defn uncollapse-shape
|
||||
[id]
|
||||
|
@ -257,7 +257,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id id] assoc :collapsed false))))
|
||||
(update-in state [:shapes id] assoc :collapsed false))))
|
||||
|
||||
;; --- Shape Visibility
|
||||
|
||||
|
@ -267,11 +267,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :hidden] true))
|
||||
(assoc-in state [:shapes sid :hidden] true))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(if-not (= (:type shape) :group)
|
||||
(rx/empty)
|
||||
(rx/from-coll
|
||||
|
@ -283,11 +283,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :hidden] false))
|
||||
(assoc-in state [:shapes sid :hidden] false))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(if-not (= (:type shape) :group)
|
||||
(rx/empty)
|
||||
(rx/from-coll
|
||||
|
@ -299,11 +299,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :blocked] true))
|
||||
(assoc-in state [:shapes sid :blocked] true))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(if-not (= (:type shape) :group)
|
||||
(rx/empty)
|
||||
(rx/from-coll
|
||||
|
@ -315,11 +315,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :blocked] false))
|
||||
(assoc-in state [:shapes sid :blocked] false))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(if-not (= (:type shape) :group)
|
||||
(rx/empty)
|
||||
(rx/from-coll
|
||||
|
@ -331,11 +331,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :locked] true))
|
||||
(assoc-in state [:shapes sid :locked] true))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(if-not (= (:type shape) :group)
|
||||
(rx/empty)
|
||||
(rx/from-coll
|
||||
|
@ -347,11 +347,11 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:shapes-by-id sid :locked] false))
|
||||
(assoc-in state [:shapes sid :locked] false))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(let [shape (get-in state [:shapes sid])]
|
||||
(if-not (= (:type shape) :group)
|
||||
(rx/empty)
|
||||
(rx/from-coll
|
||||
|
@ -376,7 +376,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [page (get-in state [:workspace :page])
|
||||
id (first (get-in state [:pages-by-id page :shapes]))]
|
||||
id (first (get-in state [:pages page :shapes]))]
|
||||
(assoc-in state [:workspace :selected] #{id})))))
|
||||
|
||||
(defn select-shape
|
||||
|
@ -414,7 +414,7 @@
|
|||
(let [id (or (:id interaction)
|
||||
(uuid/random))
|
||||
data (assoc interaction :id id)]
|
||||
(assoc-in state [:shapes-by-id shape :interactions id] data))))
|
||||
(assoc-in state [:shapes shape :interactions id] data))))
|
||||
|
||||
(defn update-interaction
|
||||
[shape interaction]
|
||||
|
@ -426,7 +426,7 @@
|
|||
udp/IPageUpdate
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id shape :interactions] dissoc id)))
|
||||
(update-in state [:shapes shape :interactions] dissoc id)))
|
||||
|
||||
(defn delete-interaction
|
||||
[shape id]
|
||||
|
@ -438,7 +438,7 @@
|
|||
(defrecord UpdatePath [id index delta]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:shapes-by-id id :points index] gpt/add delta)))
|
||||
(update-in state [:shapes id :points index] gpt/add delta)))
|
||||
|
||||
(defn update-path
|
||||
"Update a concrete point in the path shape."
|
||||
|
@ -449,7 +449,7 @@
|
|||
(defrecord InitialPathPointAlign [id index]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [shape (get-in state [:shapes-by-id id])
|
||||
(let [shape (get-in state [:shapes id])
|
||||
point (get-in shape [:points index])
|
||||
point (gpt/add point canvas-coords)]
|
||||
(->> (align-point point)
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
(let [sid (uuid/random)
|
||||
shape (merge shape {:id sid :page page})]
|
||||
(as-> state $
|
||||
(update-in $ [:pages-by-id page :shapes] #(into [] (cons sid %)))
|
||||
(assoc-in $ [:shapes-by-id sid] shape))))
|
||||
(update-in $ [:pages page :shapes] #(into [] (cons sid %)))
|
||||
(assoc-in $ [:shapes sid] shape))))
|
||||
|
||||
(defn duplicate-shapes'
|
||||
([state shapes page]
|
||||
|
@ -30,12 +30,12 @@
|
|||
shape (assoc shape :id id :page page :items [])
|
||||
state (if (nil? group)
|
||||
(as-> state $
|
||||
(update-in $ [:pages-by-id page :shapes] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes-by-id id] shape))
|
||||
(update-in $ [:pages page :shapes] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes id] shape))
|
||||
(as-> state $
|
||||
(update-in $ [:shapes-by-id group :items] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes-by-id id] shape)))]
|
||||
(->> (map #(get-in state [:shapes-by-id %]) items)
|
||||
(update-in $ [:shapes group :items] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes id] shape)))]
|
||||
(->> (map #(get-in state [:shapes %]) items)
|
||||
(reduce #(duplicate-shape %1 %2 page id) state)))
|
||||
(let [id (uuid/random)
|
||||
shape (-> (dissoc shape :group)
|
||||
|
@ -43,11 +43,11 @@
|
|||
(merge (when group {:group group})))]
|
||||
(if (nil? group)
|
||||
(as-> state $
|
||||
(update-in $ [:pages-by-id page :shapes] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes-by-id id] shape))
|
||||
(update-in $ [:pages page :shapes] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes id] shape))
|
||||
(as-> state $
|
||||
(update-in $ [:shapes-by-id group :items] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes-by-id id] shape))))))]
|
||||
(update-in $ [:shapes group :items] #(into [] (cons id %)))
|
||||
(assoc-in $ [:shapes id] shape))))))]
|
||||
|
||||
(reduce #(duplicate-shape %1 %2 page group) state shapes))))
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
|||
(all-same-group? [coll]
|
||||
(let [group (:group (first coll))]
|
||||
(every? #(= group (:group %)) coll)))]
|
||||
(let [shapes (reverse (mapv #(get-in state [:shapes-by-id %]) shapes))]
|
||||
(let [shapes (reverse (mapv #(get-in state [:shapes %]) shapes))]
|
||||
(cond
|
||||
(all-toplevel? shapes)
|
||||
(let [page (or page (:page (first shapes)))]
|
||||
|
@ -82,28 +82,28 @@
|
|||
data structure of shapes from the state."
|
||||
[state {:keys [id type] :as shape}]
|
||||
(if (= :group type)
|
||||
(let [items (map #(get-in state [:shapes-by-id %]) (:items shape))]
|
||||
(let [items (map #(get-in state [:shapes %]) (:items shape))]
|
||||
(as-> state $
|
||||
(update-in $ [:shapes-by-id] dissoc id)
|
||||
(update-in $ [:shapes] dissoc id)
|
||||
(reduce dissoc-from-index $ items)))
|
||||
(update-in state [:shapes-by-id] dissoc id)))
|
||||
(update-in state [:shapes] dissoc id)))
|
||||
|
||||
(defn dissoc-from-page
|
||||
"Given a shape, try to remove its reference from the
|
||||
corresponding page."
|
||||
[state {:keys [id page] :as shape}]
|
||||
(as-> (get-in state [:pages-by-id page :shapes]) $
|
||||
(as-> (get-in state [:pages page :shapes]) $
|
||||
(into [] (remove #(= % id) $))
|
||||
(assoc-in state [:pages-by-id page :shapes] $)))
|
||||
(assoc-in state [:pages page :shapes] $)))
|
||||
|
||||
(defn dissoc-from-group
|
||||
"Given a shape, try to remove its reference from the
|
||||
corresponding group (only if it belongs to one group)."
|
||||
[state {:keys [id group] :as shape}]
|
||||
(if-let [group' (get-in state [:shapes-by-id group])]
|
||||
(if-let [group' (get-in state [:shapes group])]
|
||||
(as-> (:items group') $
|
||||
(into [] (remove #(= % id) $))
|
||||
(assoc-in state [:shapes-by-id group :items] $))
|
||||
(assoc-in state [:shapes group :items] $))
|
||||
state))
|
||||
|
||||
(declare dissoc-shape)
|
||||
|
@ -116,7 +116,7 @@
|
|||
all empty parent groups of recently removed
|
||||
shape."
|
||||
[state {:keys [group] :as shape}]
|
||||
(if-let [group' (get-in state [:shapes-by-id group])]
|
||||
(if-let [group' (get-in state [:shapes group])]
|
||||
(if (empty? (:items group'))
|
||||
(dissoc-shape state group')
|
||||
state)
|
||||
|
@ -141,13 +141,13 @@
|
|||
(defn drop-relative
|
||||
[state loc sid]
|
||||
{:pre [(not (nil? sid))]}
|
||||
(let [shape (get-in state [:shapes-by-id (first sid)])
|
||||
(let [shape (get-in state [:shapes (first sid)])
|
||||
{:keys [page group]} shape
|
||||
sid (:id shape)
|
||||
|
||||
shapes (if group
|
||||
(get-in state [:shapes-by-id group :items])
|
||||
(get-in state [:pages-by-id page :shapes]))
|
||||
(get-in state [:shapes group :items])
|
||||
(get-in state [:pages page :shapes]))
|
||||
|
||||
index (case loc
|
||||
:first 0
|
||||
|
@ -160,19 +160,19 @@
|
|||
(dissoc-from-group shape))
|
||||
|
||||
shapes (if group
|
||||
(get-in state [:shapes-by-id group :items])
|
||||
(get-in state [:pages-by-id page :shapes]))
|
||||
(get-in state [:shapes group :items])
|
||||
(get-in state [:pages page :shapes]))
|
||||
|
||||
shapes (drop-at-index index shapes sid)]
|
||||
|
||||
(if group
|
||||
(as-> state $
|
||||
(assoc-in $ [:shapes-by-id group :items] shapes)
|
||||
(update-in $ [:shapes-by-id sid] assoc :group group)
|
||||
(assoc-in $ [:shapes group :items] shapes)
|
||||
(update-in $ [:shapes sid] assoc :group group)
|
||||
(clear-empty-groups $ shape))
|
||||
(as-> state $
|
||||
(assoc-in $ [:pages-by-id page :shapes] shapes)
|
||||
(update-in $ [:shapes-by-id sid] dissoc :group)
|
||||
(assoc-in $ [:pages page :shapes] shapes)
|
||||
(update-in $ [:shapes sid] dissoc :group)
|
||||
(clear-empty-groups $ shape)))))
|
||||
|
||||
(defn drop-aside
|
||||
|
@ -180,16 +180,16 @@
|
|||
{:pre [(not= tid sid)
|
||||
(not (nil? tid))
|
||||
(not (nil? sid))]}
|
||||
(let [{:keys [page group]} (get-in state [:shapes-by-id tid])
|
||||
source (get-in state [:shapes-by-id sid])
|
||||
(let [{:keys [page group]} (get-in state [:shapes tid])
|
||||
source (get-in state [:shapes sid])
|
||||
|
||||
state (-> state
|
||||
(dissoc-from-page source)
|
||||
(dissoc-from-group source))
|
||||
|
||||
shapes (if group
|
||||
(get-in state [:shapes-by-id group :items])
|
||||
(get-in state [:pages-by-id page :shapes]))
|
||||
(get-in state [:shapes group :items])
|
||||
(get-in state [:pages page :shapes]))
|
||||
|
||||
index (case loc
|
||||
:after (inc (index-of shapes tid))
|
||||
|
@ -198,12 +198,12 @@
|
|||
shapes (drop-at-index index shapes sid)]
|
||||
(if group
|
||||
(as-> state $
|
||||
(assoc-in $ [:shapes-by-id group :items] shapes)
|
||||
(update-in $ [:shapes-by-id sid] assoc :group group)
|
||||
(assoc-in $ [:shapes group :items] shapes)
|
||||
(update-in $ [:shapes sid] assoc :group group)
|
||||
(clear-empty-groups $ source))
|
||||
(as-> state $
|
||||
(assoc-in $ [:pages-by-id page :shapes] shapes)
|
||||
(update-in $ [:shapes-by-id sid] dissoc :group)
|
||||
(assoc-in $ [:pages page :shapes] shapes)
|
||||
(update-in $ [:shapes sid] dissoc :group)
|
||||
(clear-empty-groups $ source)))))
|
||||
|
||||
(def drop-after #(drop-aside %1 :after %2 %3))
|
||||
|
@ -212,15 +212,15 @@
|
|||
(defn drop-inside
|
||||
[state tid sid]
|
||||
{:pre [(not= tid sid)]}
|
||||
(let [source (get-in state [:shapes-by-id sid])
|
||||
(let [source (get-in state [:shapes sid])
|
||||
state (-> state
|
||||
(dissoc-from-page source)
|
||||
(dissoc-from-group source))
|
||||
shapes (get-in state [:shapes-by-id tid :items])]
|
||||
shapes (get-in state [:shapes tid :items])]
|
||||
(if (seq shapes)
|
||||
(as-> state $
|
||||
(assoc-in $ [:shapes-by-id tid :items] (conj shapes sid))
|
||||
(update-in $ [:shapes-by-id sid] assoc :group tid))
|
||||
(assoc-in $ [:shapes tid :items] (conj shapes sid))
|
||||
(update-in $ [:shapes sid] assoc :group tid))
|
||||
state)))
|
||||
|
||||
(defn drop-shape
|
||||
|
@ -262,12 +262,12 @@
|
|||
|
||||
(defn match-by-selrect
|
||||
[state page selrect]
|
||||
(let [xf (comp (map #(get-in state [:shapes-by-id %]))
|
||||
(let [xf (comp (map #(get-in state [:shapes %]))
|
||||
(remove :hidden)
|
||||
(remove :blocked)
|
||||
(map geom/outer-rect))
|
||||
match (partial try-match-shape xf selrect)
|
||||
shapes (get-in state [:pages-by-id page :shapes])]
|
||||
shapes (get-in state [:pages page :shapes])]
|
||||
(reduce match #{} (sequence xf shapes))))
|
||||
|
||||
(defn group-shapes
|
||||
|
@ -282,37 +282,37 @@
|
|||
(move-shapes-to-new-group [state page shapes new-group]
|
||||
(reduce (fn [state {:keys [id group] :as shape}]
|
||||
(-> state
|
||||
(update-in [:shapes-by-id group :items] #(remove (set [id]) %))
|
||||
(update-in [:pages-by-id page :shapes] #(remove (set [id]) %))
|
||||
(update-in [:shapes group :items] #(remove (set [id]) %))
|
||||
(update-in [:pages page :shapes] #(remove (set [id]) %))
|
||||
(clear-empty-groups shape)
|
||||
(assoc-in [:shapes-by-id id :group] new-group)
|
||||
(assoc-in [:shapes id :group] new-group)
|
||||
))
|
||||
state
|
||||
shapes))
|
||||
|
||||
(update-shapes-on-page [state page shapes group]
|
||||
(as-> (get-in state [:pages-by-id page :shapes]) $
|
||||
(as-> (get-in state [:pages page :shapes]) $
|
||||
(replace-first-item (set shapes) $ group)
|
||||
(remove (set shapes) $)
|
||||
(into [] $)
|
||||
(assoc-in state [:pages-by-id page :shapes] $)))
|
||||
(assoc-in state [:pages page :shapes] $)))
|
||||
|
||||
(update-shapes-on-group [state parent-group shapes group]
|
||||
(as-> (get-in state [:shapes-by-id parent-group :items]) $
|
||||
(as-> (get-in state [:shapes parent-group :items]) $
|
||||
(replace-first-item (set shapes) $ group)
|
||||
(remove (set shapes) $)
|
||||
(into [] $)
|
||||
(assoc-in state [:shapes-by-id parent-group :items] $)))
|
||||
(assoc-in state [:shapes parent-group :items] $)))
|
||||
|
||||
(update-shapes-on-index [state shapes group]
|
||||
(reduce (fn [state {:keys [id] :as shape}]
|
||||
(as-> shape $
|
||||
(assoc $ :group group)
|
||||
(assoc-in state [:shapes-by-id id] $)))
|
||||
(assoc-in state [:shapes id] $)))
|
||||
state
|
||||
shapes))]
|
||||
(let [sid (uuid/random)
|
||||
shapes' (map #(get-in state [:shapes-by-id %]) shapes)
|
||||
shapes' (map #(get-in state [:shapes %]) shapes)
|
||||
distinct-groups (distinct (map :group shapes'))
|
||||
parent-group (cond
|
||||
(not= 1 (count distinct-groups)) :multi
|
||||
|
@ -329,48 +329,48 @@
|
|||
(= :multi parent-group)
|
||||
(-> $
|
||||
(move-shapes-to-new-group page shapes' sid)
|
||||
(update-in [:pages-by-id page :shapes] #(into [] (cons sid %))))
|
||||
(update-in [:pages page :shapes] #(into [] (cons sid %))))
|
||||
(= :page parent-group)
|
||||
(update-shapes-on-page $ page shapes sid)
|
||||
:else
|
||||
(update-shapes-on-group $ parent-group shapes sid))
|
||||
(update $ :shapes-by-id assoc sid group)
|
||||
(update $ :shapes assoc sid group)
|
||||
(cond
|
||||
(= :multi parent-group) $
|
||||
(= :page parent-group) $
|
||||
:else (assoc-in $ [:shapes-by-id sid :group] parent-group))
|
||||
:else (assoc-in $ [:shapes sid :group] parent-group))
|
||||
(update $ :workspace assoc :selected #{sid})))))
|
||||
|
||||
(defn degroup-shapes
|
||||
[state shapes page]
|
||||
(letfn [(empty-group [state page-id group-id]
|
||||
(let [group (get-in state [:shapes-by-id group-id])
|
||||
(let [group (get-in state [:shapes group-id])
|
||||
parent-id (:group group)
|
||||
position (if (nil? parent-id)
|
||||
(index-of (get-in state [:pages-by-id page-id :shapes]) group-id)
|
||||
(index-of (get-in state [:shapes-by-id parent-id :items]) group-id))
|
||||
(index-of (get-in state [:pages page-id :shapes]) group-id)
|
||||
(index-of (get-in state [:shapes parent-id :items]) group-id))
|
||||
reduce-func (fn [state item]
|
||||
(if (nil? parent-id)
|
||||
(-> state
|
||||
(update-in [:pages-by-id page-id :shapes] #(drop-at-index position % item))
|
||||
(update-in [:shapes-by-id item] dissoc :group))
|
||||
(update-in [:pages page-id :shapes] #(drop-at-index position % item))
|
||||
(update-in [:shapes item] dissoc :group))
|
||||
(-> state
|
||||
(update-in [:shapes-by-id parent-id :items] #(drop-at-index position % item))
|
||||
(assoc-in [:shapes-by-id item :group] parent-id))))]
|
||||
(update-in [:shapes parent-id :items] #(drop-at-index position % item))
|
||||
(assoc-in [:shapes item :group] parent-id))))]
|
||||
|
||||
(as-> state $
|
||||
(reduce reduce-func $ (reverse (:items group)))
|
||||
(if (nil? parent-id)
|
||||
(update-in $ [:pages-by-id page-id :shapes] #(into [] (remove #{group-id} %)))
|
||||
(update-in $ [:shapes-by-id parent-id :items] #(into [] (remove #{group-id} %))))
|
||||
(update-in $ [:shapes-by-id] dissoc group-id))))
|
||||
(update-in $ [:pages page-id :shapes] #(into [] (remove #{group-id} %)))
|
||||
(update-in $ [:shapes parent-id :items] #(into [] (remove #{group-id} %))))
|
||||
(update-in $ [:shapes] dissoc group-id))))
|
||||
|
||||
(empty-groups [state page-id groups-ids]
|
||||
(reduce (fn [state group-id]
|
||||
(empty-group state page-id group-id))
|
||||
state
|
||||
groups-ids))]
|
||||
(let [shapes' (map #(get-in state [:shapes-by-id %]) shapes)
|
||||
(let [shapes' (map #(get-in state [:shapes %]) shapes)
|
||||
groups (filter #(= (:type %) :group) shapes')
|
||||
groups-ids (map :id groups)
|
||||
groups-items (remove (set groups-ids) (mapcat :items groups))]
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
rs/WatchEvent
|
||||
(-apply-watch [_ state stream]
|
||||
(let [initialized? (get-in state [:undo id])
|
||||
page-loaded? (get-in state [:pages-by-id id])]
|
||||
page-loaded? (get-in state [:pages id])]
|
||||
(cond
|
||||
(and page-loaded? initialized?)
|
||||
(rx/empty)
|
||||
|
@ -93,7 +93,7 @@
|
|||
(if (>= selected (dec (count stack)))
|
||||
state
|
||||
(let [pointer (inc selected)
|
||||
page (get-in state [:pages-by-id page-id])
|
||||
page (get-in state [:pages page-id])
|
||||
data (nth stack pointer)
|
||||
packed (assoc page :data data)]
|
||||
|
||||
|
@ -127,7 +127,7 @@
|
|||
state
|
||||
(let [pointer (dec selected)
|
||||
data (nth stack pointer)
|
||||
page (get-in state [:pages-by-id page-id])
|
||||
page (get-in state [:pages page-id])
|
||||
packed (assoc page :data data)]
|
||||
|
||||
;; (println "Redo: pointer=" pointer)
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [page-id page
|
||||
page (get-in state [:pages-by-id page-id])]
|
||||
page (get-in state [:pages page-id])]
|
||||
|
||||
;; Activate loaded if page is not fetched.
|
||||
(when-not page (reset! st/loader true))
|
||||
|
@ -81,7 +81,7 @@
|
|||
rs/EffectEvent
|
||||
(-apply-effect [_ state]
|
||||
;; Optimistic prefetch of projects if them are not already fetched
|
||||
(when-not (seq (:projects-by-id state))
|
||||
(when-not (seq (:projects state))
|
||||
(rs/emit! (dp/fetch-projects)))))
|
||||
|
||||
(defn initialize
|
||||
|
@ -208,7 +208,7 @@
|
|||
(defrecord InitializeAlignmentIndex [id]
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [page (get-in state [:pages-by-id id])
|
||||
(let [page (get-in state [:pages id])
|
||||
opts (:options page)
|
||||
message {:cmd :grid/init
|
||||
:width c/viewport-width
|
||||
|
|
|
@ -39,12 +39,12 @@
|
|||
:path (path-shape s)
|
||||
:circle (circle-shape s)
|
||||
:image (let [image-id (:image s)
|
||||
image (get-in @*state* [:images-by-id image-id])]
|
||||
image (get-in @*state* [:images image-id])]
|
||||
(image-shape (assoc s :image image)))))
|
||||
|
||||
(mx/defc shape
|
||||
[sid]
|
||||
(shape* (get-in @*state* [:shapes-by-id sid])))
|
||||
(shape* (get-in @*state* [:shapes sid])))
|
||||
|
||||
(mx/defc page-svg
|
||||
[{:keys [width height] :as page}]
|
||||
|
@ -60,5 +60,5 @@
|
|||
|
||||
(defn render-page
|
||||
[id]
|
||||
(let [page (get-in @st/state [:pages-by-id id])]
|
||||
(let [page (get-in @st/state [:pages id])]
|
||||
(mx/render-static-html (page-svg page))))
|
||||
|
|
|
@ -513,7 +513,7 @@
|
|||
(defn- inner-rect-group
|
||||
[state {:keys [id group rotation dx dy] :as shape}]
|
||||
(let [shapes (->> (:items shape)
|
||||
(map #(get-in state [:shapes-by-id %]))
|
||||
(map #(get-in state [:shapes %]))
|
||||
(map #(inner-rect state %)))
|
||||
x (apply min (map :x shapes))
|
||||
y (apply min (map :y shapes))
|
||||
|
@ -545,13 +545,13 @@
|
|||
:group (outer-rect-group state shape)
|
||||
(outer-rect-generic state shape))]
|
||||
(if (:group shape)
|
||||
(let [group (get-in state [:shapes-by-id (:group shape)])]
|
||||
(let [group (get-in state [:shapes (:group shape)])]
|
||||
(apply-parent-deltas state shape (:group group)))
|
||||
shape))))
|
||||
|
||||
(defn- apply-parent-deltas
|
||||
[state {:keys [x y] :as shape} id]
|
||||
(if-let [group (get-in state [:shapes-by-id id])]
|
||||
(if-let [group (get-in state [:shapes id])]
|
||||
(let [props {:x (+ x (:dx group 0))
|
||||
:y (+ y (:dy group 0))}]
|
||||
(apply-parent-deltas state (merge shape props) (:group group)))
|
||||
|
@ -559,7 +559,7 @@
|
|||
|
||||
(defn- outer-rect-generic
|
||||
[state {:keys [x1 y1 x2 y2 group] :as shape}]
|
||||
(let [group (get-in state [:shapes-by-id group])
|
||||
(let [group (get-in state [:shapes group])
|
||||
props {:x (+ x1 (:dx group 0))
|
||||
:y (+ y1 (:dy group 0))
|
||||
:width (- x2 x1)
|
||||
|
@ -569,7 +569,7 @@
|
|||
|
||||
(defn- outer-rect-circle
|
||||
[state {:keys [cx cy rx ry group] :as shape}]
|
||||
(let [group (get-in state [:shapes-by-id group])
|
||||
(let [group (get-in state [:shapes group])
|
||||
props {:x (+ (- cx rx) (:dx group 0))
|
||||
:y (+ (- cy ry) (:dy group 0))
|
||||
:width (* rx 2)
|
||||
|
@ -579,7 +579,7 @@
|
|||
|
||||
(defn- outer-rect-path
|
||||
[state {:keys [points group] :as shape}]
|
||||
(let [group (get-in state [:shapes-by-id group])
|
||||
(let [group (get-in state [:shapes group])
|
||||
minx (apply min (map :x points))
|
||||
miny (apply min (map :y points))
|
||||
maxx (apply max (map :x points))
|
||||
|
@ -596,7 +596,7 @@
|
|||
(defn- outer-rect-group
|
||||
[state {:keys [id group rotation dx dy] :as shape}]
|
||||
(let [shapes (->> (:items shape)
|
||||
(map #(get-in state [:shapes-by-id %]))
|
||||
(map #(get-in state [:shapes %]))
|
||||
(map #(outer-rect state %)))
|
||||
x (apply min (map :x shapes))
|
||||
y (apply min (map :y shapes))
|
||||
|
@ -754,7 +754,7 @@
|
|||
|
||||
(defn- transformation-matrix-group
|
||||
[state {:keys [dx dy rotation items] :or {rotation 0} :as shape}]
|
||||
(let [shapes-by-id (get state :shapes-by-id)
|
||||
(let [shapes-by-id (get state :shapes)
|
||||
shapes (map #(get shapes-by-id %) items)
|
||||
{:keys [x y width height]} (outer-rect-coll shapes)
|
||||
center-x (+ x (/ width 2))
|
||||
|
@ -784,7 +784,7 @@
|
|||
(resolve-parent @st/state shape))
|
||||
([state {:keys [group] :as shape}]
|
||||
(if group
|
||||
(resolve-parent state (get-in state [:shapes-by-id group]))
|
||||
(resolve-parent state (get-in state [:shapes group]))
|
||||
shape)))
|
||||
|
||||
(defn contained-in?
|
||||
|
@ -827,7 +827,7 @@
|
|||
(defn parent-satisfies?
|
||||
"Resolve the first parent that satisfies a condition."
|
||||
[{:keys [group] :as shape} pred]
|
||||
(let [shapes-by-id (:shapes-by-id @st/state)]
|
||||
(let [shapes-by-id (:shapes @st/state)]
|
||||
(if group
|
||||
(loop [parent (get shapes-by-id group)]
|
||||
(cond
|
||||
|
|
|
@ -33,14 +33,14 @@
|
|||
:undo {}
|
||||
:profile nil
|
||||
:workspace nil
|
||||
:image-colls-by-id nil
|
||||
:images-by-id nil
|
||||
:icon-colls-by-id nil
|
||||
:icons-by-id nil
|
||||
:shapes-by-id nil
|
||||
:image-collections nil
|
||||
:color-collections colors/collections
|
||||
:projects-by-id nil
|
||||
:pages-by-id nil})
|
||||
:icon-collections nil
|
||||
:images nil
|
||||
:icons nil
|
||||
:shapes nil
|
||||
:projects nil
|
||||
:pages nil})
|
||||
|
||||
(defn init
|
||||
"Initialize the state materialization."
|
||||
|
|
|
@ -56,11 +56,11 @@
|
|||
(l/derive st/state)))
|
||||
|
||||
(def ^:private collections-ref
|
||||
(-> (l/key :icon-colls-by-id)
|
||||
(-> (l/key :icon-collections)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def ^:private icons-ref
|
||||
(-> (l/key :icons-by-id)
|
||||
(-> (l/key :icons)
|
||||
(l/derive st/state)))
|
||||
|
||||
;; (defn- focus-collection
|
||||
|
|
|
@ -52,11 +52,11 @@
|
|||
(l/derive st/state)))
|
||||
|
||||
(def ^:private collections-ref
|
||||
(-> (l/key :image-colls-by-id)
|
||||
(-> (l/key :image-collections)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def ^:private images-ref
|
||||
(-> (l/key :images-by-id)
|
||||
(-> (l/key :images)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def ^:private uploading?-ref
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
;; --- Refs
|
||||
|
||||
(def projects-map-ref
|
||||
(-> (l/key :projects-by-id)
|
||||
(-> (l/key :projects)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def dashboard-ref
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
(defn- focus-shape
|
||||
[id]
|
||||
(-> (l/in [:shapes-by-id id])
|
||||
(-> (l/in [:shapes id])
|
||||
(l/derive st/state)))
|
||||
|
||||
(defn render-component
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
(defn image-ref
|
||||
[id]
|
||||
(-> (l/in [:images-by-id id])
|
||||
(-> (l/in [:images id])
|
||||
(l/derive st/state)))
|
||||
|
||||
;; --- Image Component
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
(defn- focus-selected-shapes
|
||||
[state]
|
||||
(let [selected (get-in state [:workspace :selected])]
|
||||
(mapv #(get-in state [:shapes-by-id %]) selected)))
|
||||
(mapv #(get-in state [:shapes %]) selected)))
|
||||
|
||||
(def ^:private selected-shapes-ref
|
||||
(-> (l/lens focus-selected-shapes)
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
(def project-ref
|
||||
(letfn [(getter [state]
|
||||
(let [project (get-in state [:workspace :project])]
|
||||
(get-in state [:projects-by-id project])))]
|
||||
(get-in state [:projects project])))]
|
||||
(-> (l/lens getter)
|
||||
(l/derive st/state))))
|
||||
|
||||
(def page-ref
|
||||
(letfn [(getter [state]
|
||||
(let [page (get-in state [:workspace :page])]
|
||||
(get-in state [:pages-by-id page])))]
|
||||
(get-in state [:pages page])))]
|
||||
(-> (l/lens getter)
|
||||
(l/derive st/state))))
|
||||
|
||||
|
@ -52,7 +52,7 @@
|
|||
(l/derive $ workspace-ref)))
|
||||
|
||||
(def shapes-by-id-ref
|
||||
(as-> (l/key :shapes-by-id) $
|
||||
(as-> (l/key :shapes) $
|
||||
(l/derive $ st/state)))
|
||||
|
||||
(def zoom-ref
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
(defn- focus-shape
|
||||
[id]
|
||||
(-> (l/in [:shapes-by-id id])
|
||||
(-> (l/in [:shapes id])
|
||||
(l/derive st/state)))
|
||||
|
||||
(defn- colorpicker-render
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
(defn- resolve-pages
|
||||
[state]
|
||||
(let [project (get-in state [:workspace :project])]
|
||||
(->> (vals (:pages-by-id state))
|
||||
(->> (vals (:pages state))
|
||||
(filter #(= project (:project %)))
|
||||
(sort-by :created-at))))
|
||||
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
(l/derive st/state)))
|
||||
|
||||
(def ^:private collections-ref
|
||||
(-> (l/key :image-colls-by-id)
|
||||
(-> (l/key :image-collections)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def ^:private images-ref
|
||||
(-> (l/key :images-by-id)
|
||||
(-> (l/key :images)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def ^:private uploading?-ref
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
(defn- focus-page
|
||||
[id]
|
||||
(-> (l/in [:pages-by-id id])
|
||||
(-> (l/in [:pages id])
|
||||
(l/derive st/state)))
|
||||
|
||||
(defn- select-shape
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
(letfn [(getter [state]
|
||||
(let [selected (get-in state [:workspace :selected])]
|
||||
(when (= 1 (count selected))
|
||||
(get-in state [:shapes-by-id (first selected)]))))]
|
||||
(get-in state [:shapes (first selected)]))))]
|
||||
(-> (l/lens getter)
|
||||
(l/derive st/state))))
|
||||
|
||||
|
|
|
@ -141,8 +141,8 @@
|
|||
|
||||
(defn- collect-shapes
|
||||
[state page]
|
||||
(let [shapes-by-id (:shapes-by-id state)
|
||||
shapes (get-in state [:pages-by-id page :shapes])]
|
||||
(let [shapes-by-id (:shapes state)
|
||||
shapes (get-in state [:pages page :shapes])]
|
||||
(letfn [(resolve-shape [acc id]
|
||||
(let [shape (get shapes-by-id id)]
|
||||
(if (= (:type shape) :group)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
(defn- resolve-pages
|
||||
[state]
|
||||
(let [project (get-in state [:workspace :project])]
|
||||
(->> (vals (:pages-by-id state))
|
||||
(->> (vals (:pages state))
|
||||
(filter #(= project (:project %)))
|
||||
(sort-by :created-at))))
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
:pages nil
|
||||
:page nil
|
||||
:flags #{:sitemap}
|
||||
:shapes-by-id {}
|
||||
:pages-by-id {}})
|
||||
:shapes {}
|
||||
:pages {}})
|
||||
|
||||
(defn ^:export init
|
||||
[]
|
||||
|
|
|
@ -36,12 +36,12 @@
|
|||
[state page]
|
||||
(let [data (:data page)
|
||||
shapes (:shapes data)
|
||||
shapes-by-id (:shapes-by-id data)
|
||||
shapes-by-id (:shapes data)
|
||||
page (-> page
|
||||
(dissoc page :data)
|
||||
(assoc :shapes shapes))]
|
||||
(-> state
|
||||
(update :shapes-by-id merge shapes-by-id)
|
||||
(update :shapes merge shapes-by-id)
|
||||
(update :pages conj page))))
|
||||
|
||||
(defrecord DataLoaded [data]
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
(defn- run-opacity-interaction
|
||||
[{:keys [element opacity easing delay
|
||||
duration animation direction]}]
|
||||
(let [shape (get-in @st/state [:shapes-by-id element])
|
||||
(let [shape (get-in @st/state [:shapes element])
|
||||
dom (dom/get-element (str "shape-" element))]
|
||||
(if (= direction :reverse)
|
||||
(animate* dom {:fillOpacity (:fill-opacity shape "1")
|
||||
|
@ -115,7 +115,7 @@
|
|||
;; (defn- run-size-interaction
|
||||
;; [{:keys [element resize-width resize-height
|
||||
;; easing delay duration] :as opts}]
|
||||
;; (let [shape (get-in @st/state [:shapes-by-id element])
|
||||
;; (let [shape (get-in @st/state [:shapes element])
|
||||
;; tf (geom/transformation-matrix
|
||||
;; (geom/resize shape (gpt/point resize-width resize-height)))]
|
||||
;; (animate :targets [(str "#shape-" element)]
|
||||
|
@ -176,7 +176,7 @@
|
|||
|
||||
(defn- run-size-interaction
|
||||
[{:keys [element] :as opts}]
|
||||
(let [shape (get-in @st/state [:shapes-by-id element])]
|
||||
(let [shape (get-in @st/state [:shapes element])]
|
||||
(case (:type shape)
|
||||
:icon (run-size-interaction-icon shape opts)
|
||||
:rect (run-size-interaction-rect shape opts))))
|
||||
|
@ -191,7 +191,7 @@
|
|||
|
||||
(defn- run-color-interaction
|
||||
[{:keys [element fill-color stroke-color direction easing delay duration]}]
|
||||
(let [shape (get-in @st/state [:shapes-by-id element])
|
||||
(let [shape (get-in @st/state [:shapes element])
|
||||
dom (dom/get-element (str "shape-" element))]
|
||||
(if (= direction :reverse)
|
||||
(animate* dom {:easing (translate-ease easing)
|
||||
|
@ -207,7 +207,7 @@
|
|||
|
||||
(defn- run-rotate-interaction
|
||||
[{:keys [element rotation direction easing delay duration] :as opts}]
|
||||
(let [shape (get-in @st/state [:shapes-by-id element])
|
||||
(let [shape (get-in @st/state [:shapes element])
|
||||
dom (dom/get-element (str "shape-" element))
|
||||
mtx1 (geom/transformation-matrix (update shape :rotation + rotation))
|
||||
mtx2 (geom/transformation-matrix shape)]
|
||||
|
|
|
@ -76,5 +76,5 @@
|
|||
|
||||
(mx/defc shape
|
||||
[sid]
|
||||
(let [item (get-in @st/state [:shapes-by-id sid])]
|
||||
(let [item (get-in @st/state [:shapes sid])]
|
||||
(interactions-wrapper item shape*)))
|
||||
|
|
Loading…
Add table
Reference in a new issue