mirror of
https://github.com/penpot/penpot.git
synced 2025-05-26 01:16:11 +02:00
♻️ New namespace for state helpers
This commit is contained in:
parent
0030b9c3ac
commit
be0d1c19fa
13 changed files with 149 additions and 118 deletions
|
@ -28,6 +28,7 @@
|
||||||
[app.main.data.workspace.path :as dwdp]
|
[app.main.data.workspace.path :as dwdp]
|
||||||
[app.main.data.workspace.persistence :as dwp]
|
[app.main.data.workspace.persistence :as dwp]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.main.data.workspace.selection :as dws]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.data.workspace.svg-upload :as svg]
|
[app.main.data.workspace.svg-upload :as svg]
|
||||||
[app.main.data.workspace.transforms :as dwt]
|
[app.main.data.workspace.transforms :as dwt]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
|
@ -361,7 +362,7 @@
|
||||||
|
|
||||||
(initialize [state local]
|
(initialize [state local]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
shapes (cp/select-toplevel-shapes objects {:include-frames? true})
|
shapes (cp/select-toplevel-shapes objects {:include-frames? true})
|
||||||
srect (gsh/selection-rect shapes)
|
srect (gsh/selection-rect shapes)
|
||||||
local (assoc local :vport size :zoom 1)]
|
local (assoc local :vport size :zoom 1)]
|
||||||
|
@ -553,7 +554,7 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
shapes (cp/select-toplevel-shapes objects {:include-frames? true})
|
shapes (cp/select-toplevel-shapes objects {:include-frames? true})
|
||||||
srect (gsh/selection-rect shapes)]
|
srect (gsh/selection-rect shapes)]
|
||||||
|
|
||||||
|
@ -576,7 +577,7 @@
|
||||||
(if (empty? selected)
|
(if (empty? selected)
|
||||||
state
|
state
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
srect (->> selected
|
srect (->> selected
|
||||||
(map #(get objects %))
|
(map #(get objects %))
|
||||||
(gsh/selection-rect))]
|
(gsh/selection-rect))]
|
||||||
|
@ -675,7 +676,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
rchanges (mapv (fn [id]
|
rchanges (mapv (fn [id]
|
||||||
(let [obj (get objects id)
|
(let [obj (get objects id)
|
||||||
|
@ -882,7 +883,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
;; Ignore any shape whose parent is also intented to be moved
|
;; Ignore any shape whose parent is also intented to be moved
|
||||||
ids (cp/clean-loops objects ids)
|
ids (cp/clean-loops objects ids)
|
||||||
|
@ -1000,7 +1001,7 @@
|
||||||
(if-not (= 1 (count selected))
|
(if-not (= 1 (count selected))
|
||||||
(rx/empty)
|
(rx/empty)
|
||||||
|
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
{:keys [id type shapes]} (get objects (first selected))]
|
{:keys [id type shapes]} (get objects (first selected))]
|
||||||
|
|
||||||
(case type
|
(case type
|
||||||
|
@ -1046,7 +1047,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
moved (if (= 1 (count selected))
|
moved (if (= 1 (count selected))
|
||||||
(align-object-to-frame objects (first selected) axis)
|
(align-object-to-frame objects (first selected) axis)
|
||||||
|
@ -1077,7 +1078,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
moved (-> (map #(get objects %) selected)
|
moved (-> (map #(get objects %) selected)
|
||||||
(gal/distribute-space axis objects))
|
(gal/distribute-space axis objects))
|
||||||
|
@ -1116,7 +1117,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
|
|
||||||
bbox (-> shape :points gsh/points->selrect)
|
bbox (-> shape :points gsh/points->selrect)
|
||||||
|
@ -1311,7 +1312,7 @@
|
||||||
(ptk/reify ::copy-selected
|
(ptk/reify ::copy-selected
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
selected (->> (get-in state [:workspace-local :selected])
|
selected (->> (get-in state [:workspace-local :selected])
|
||||||
(cp/clean-loops objects))
|
(cp/clean-loops objects))
|
||||||
pdata (reduce (partial collect-object-ids objects) {} selected)
|
pdata (reduce (partial collect-object-ids objects) {} selected)
|
||||||
|
@ -1377,7 +1378,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(try
|
(try
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
paste-data (wapi/read-from-paste-event event)
|
paste-data (wapi/read-from-paste-event event)
|
||||||
image-data (wapi/extract-images paste-data)
|
image-data (wapi/extract-images paste-data)
|
||||||
text-data (wapi/extract-text paste-data)
|
text-data (wapi/extract-text paste-data)
|
||||||
|
@ -1413,7 +1414,7 @@
|
||||||
(defn selected-frame? [state]
|
(defn selected-frame? [state]
|
||||||
(let [selected (get-in state [:workspace-local :selected])
|
(let [selected (get-in state [:workspace-local :selected])
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)]
|
objects (wsh/lookup-page-objects state page-id)]
|
||||||
(and (and (= 1 (count selected))
|
(and (and (= 1 (count selected))
|
||||||
(= :frame (get-in objects [(first selected) :type]))))))
|
(= :frame (get-in objects [(first selected) :type]))))))
|
||||||
|
|
||||||
|
@ -1450,7 +1451,7 @@
|
||||||
item))
|
item))
|
||||||
|
|
||||||
(calculate-paste-position [state mouse-pos in-viewport?]
|
(calculate-paste-position [state mouse-pos in-viewport?]
|
||||||
(let [page-objects (dwc/lookup-page-objects state)
|
(let [page-objects (wsh/lookup-page-objects state)
|
||||||
selected-objs (map #(get objects %) selected)
|
selected-objs (map #(get objects %) selected)
|
||||||
has-frame? (d/seek #(= (:type %) :frame) selected-objs)
|
has-frame? (d/seek #(= (:type %) :frame) selected-objs)
|
||||||
page-selected (get-in state [:workspace-local :selected])
|
page-selected (get-in state [:workspace-local :selected])
|
||||||
|
@ -1518,7 +1519,7 @@
|
||||||
:touched))))))
|
:touched))))))
|
||||||
|
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
unames (-> (dwc/lookup-page-objects state page-id)
|
unames (-> (wsh/lookup-page-objects state page-id)
|
||||||
(dwc/retrieve-used-names))
|
(dwc/retrieve-used-names))
|
||||||
|
|
||||||
rchanges (->> (dws/prepare-duplicate-changes objects page-id unames selected delta)
|
rchanges (->> (dws/prepare-duplicate-changes objects page-id unames selected delta)
|
||||||
|
@ -1574,7 +1575,7 @@
|
||||||
width (max 8 (min (* 7 (count text)) 700))
|
width (max 8 (min (* 7 (count text)) 700))
|
||||||
height 16
|
height 16
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
frame-id (-> (dwc/lookup-page-objects state page-id)
|
frame-id (-> (wsh/lookup-page-objects state page-id)
|
||||||
(cp/frame-id-by-position @ms/mouse-position))
|
(cp/frame-id-by-position @ms/mouse-position))
|
||||||
shape (gsh/setup-selrect
|
shape (gsh/setup-selrect
|
||||||
{:id id
|
{:id id
|
||||||
|
@ -1649,7 +1650,7 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected-shape-id (-> state (get-in [:workspace-local :selected]) first)
|
selected-shape-id (-> state (get-in [:workspace-local :selected]) first)
|
||||||
selected-shape (get objects selected-shape-id)
|
selected-shape (get objects selected-shape-id)
|
||||||
selected-shape-frame-id (:frame-id selected-shape)
|
selected-shape-frame-id (:frame-id selected-shape)
|
||||||
|
@ -1672,7 +1673,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [position @ms/mouse-position
|
(let [position @ms/mouse-position
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame (dwc/get-frame-at-point objects position)
|
frame (dwc/get-frame-at-point objects position)
|
||||||
|
|
||||||
shape-id (first (get-in state [:workspace-local :selected]))
|
shape-id (first (get-in state [:workspace-local :selected]))
|
||||||
|
@ -1699,7 +1700,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (get state :current-page-id)
|
(let [page-id (get state :current-page-id)
|
||||||
options (dwc/lookup-page-options state page-id)
|
options (wsh/lookup-page-options state page-id)
|
||||||
previus-color (:background options)]
|
previus-color (:background options)]
|
||||||
(rx/of (dch/commit-changes
|
(rx/of (dch/commit-changes
|
||||||
[{:type :set-option
|
[{:type :set-option
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.modal :as md]
|
[app.main.data.modal :as md]
|
||||||
[app.main.data.workspace.common :as dwc]
|
|
||||||
[app.main.data.workspace.texts :as dwt]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
|
[app.main.data.workspace.texts :as dwt]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
|
@ -127,7 +127,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
is-text? #(= :text (:type (get objects %)))
|
is-text? #(= :text (:type (get objects %)))
|
||||||
text-ids (filter is-text? ids)
|
text-ids (filter is-text? ids)
|
||||||
|
@ -159,7 +159,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
attrs (cond-> {}
|
attrs (cond-> {}
|
||||||
(contains? color :color)
|
(contains? color :color)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.main.worker :as uw]
|
[app.main.worker :as uw]
|
||||||
|
@ -37,25 +38,8 @@
|
||||||
|
|
||||||
;; --- Helpers
|
;; --- Helpers
|
||||||
|
|
||||||
(defn lookup-page-objects
|
|
||||||
([state]
|
|
||||||
(lookup-page-objects state (:current-page-id state)))
|
|
||||||
([state page-id]
|
|
||||||
(get-in state [:workspace-data :pages-index page-id :objects])))
|
|
||||||
|
|
||||||
(defn lookup-page-options
|
|
||||||
([state]
|
|
||||||
(lookup-page-options state (:current-page-id state)))
|
|
||||||
([state page-id]
|
|
||||||
(get-in state [:workspace-data :pages-index page-id :options])))
|
|
||||||
|
|
||||||
(defn interrupt? [e] (= e :interrupt))
|
(defn interrupt? [e] (= e :interrupt))
|
||||||
|
|
||||||
(defn lookup-component-objects
|
|
||||||
([state component-id]
|
|
||||||
(get-in state [:workspace-data :components component-id :objects])))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- Selection Index Handling
|
;; --- Selection Index Handling
|
||||||
|
|
||||||
(defn initialize-indices
|
(defn initialize-indices
|
||||||
|
@ -198,7 +182,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (lookup-page-objects state page-id)]
|
objects (wsh/lookup-page-objects state page-id)]
|
||||||
(rx/of (expand-all-parents ids objects))))))
|
(rx/of (expand-all-parents ids objects))))))
|
||||||
|
|
||||||
(declare clear-edition-mode)
|
(declare clear-edition-mode)
|
||||||
|
@ -209,7 +193,7 @@
|
||||||
(ptk/reify ::start-edition-mode
|
(ptk/reify ::start-edition-mode
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [objects (lookup-page-objects state)]
|
(let [objects (wsh/lookup-page-objects state)]
|
||||||
;; Can only edit objects that exist
|
;; Can only edit objects that exist
|
||||||
(if (contains? objects id)
|
(if (contains? objects id)
|
||||||
(-> state
|
(-> state
|
||||||
|
@ -219,7 +203,7 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (lookup-page-objects state)]
|
(let [objects (wsh/lookup-page-objects state)]
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter interrupt?)
|
(rx/filter interrupt?)
|
||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
|
@ -300,7 +284,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
id (or (:id attrs) (uuid/next))
|
id (or (:id attrs) (uuid/next))
|
||||||
name (-> objects
|
name (-> objects
|
||||||
|
@ -329,7 +313,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false})
|
to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false})
|
||||||
(filterv #(= (:frame-id %) uuid/zero))
|
(filterv #(= (:frame-id %) uuid/zero))
|
||||||
(mapv :id)
|
(mapv :id)
|
||||||
|
@ -361,7 +345,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
get-empty-parents
|
get-empty-parents
|
||||||
(fn [parents]
|
(fn [parents]
|
||||||
|
@ -479,7 +463,7 @@
|
||||||
x (:x data (- vbc-x (/ width 2)))
|
x (:x data (- vbc-x (/ width 2)))
|
||||||
y (:y data (- vbc-y (/ height 2)))
|
y (:y data (- vbc-y (/ height 2)))
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
frame-id (-> (lookup-page-objects state page-id)
|
frame-id (-> (wsh/lookup-page-objects state page-id)
|
||||||
(cp/frame-id-by-position {:x frame-x :y frame-y}))
|
(cp/frame-id-by-position {:x frame-x :y frame-y}))
|
||||||
shape (-> (cp/make-minimal-shape type)
|
shape (-> (cp/make-minimal-shape type)
|
||||||
(merge data)
|
(merge data)
|
||||||
|
|
|
@ -6,17 +6,17 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.drawing.box
|
(ns app.main.data.workspace.drawing.box
|
||||||
(:require
|
(:require
|
||||||
[beicon.core :as rx]
|
|
||||||
[potok.core :as ptk]
|
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.math :as mth]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.common.uuid :as uuid]
|
||||||
|
[app.main.data.workspace.drawing.common :as common]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.snap :as snap]
|
[app.main.snap :as snap]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.main.data.workspace.drawing.common :as common]
|
[beicon.core :as rx]
|
||||||
[app.common.math :as mth]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
(defn truncate-zero [num default]
|
(defn truncate-zero [num default]
|
||||||
(if (mth/almost-zero? num) default num))
|
(if (mth/almost-zero? num) default num))
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
initial @ms/mouse-position
|
initial @ms/mouse-position
|
||||||
|
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
layout (get state :workspace-layout)
|
layout (get state :workspace-layout)
|
||||||
zoom (get-in state [:workspace-local :zoom] 1)
|
zoom (get-in state [:workspace-local :zoom] 1)
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.drawing.curve
|
(ns app.main.data.workspace.drawing.curve
|
||||||
(:require
|
(:require
|
||||||
[beicon.core :as rx]
|
|
||||||
[potok.core :as ptk]
|
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.geom.shapes.path :as gsp]
|
[app.common.geom.shapes.path :as gsp]
|
||||||
|
[app.common.pages :as cp]
|
||||||
|
[app.main.data.workspace.drawing.common :as common]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.util.path.simplify-curve :as ups]
|
[app.util.path.simplify-curve :as ups]
|
||||||
[app.main.data.workspace.drawing.common :as common]
|
[beicon.core :as rx]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[potok.core :as ptk]))
|
||||||
[app.common.pages :as cp]))
|
|
||||||
|
|
||||||
(def simplify-tolerance 0.3)
|
(def simplify-tolerance 0.3)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
content (get-in state [:workspace-drawing :object :content] [])
|
content (get-in state [:workspace-drawing :object :content] [])
|
||||||
position (get-in content [0 :params] nil)
|
position (get-in content [0 :params] nil)
|
||||||
frame-id (cp/frame-id-by-position objects position)]
|
frame-id (cp/frame-id-by-position objects position)]
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.main.data.workspace.common :as dwc]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.common :as dwc]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.main.data.workspace.selection :as dws]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
selected (cp/clean-loops objects selected)
|
selected (cp/clean-loops objects selected)
|
||||||
shapes (shapes-for-grouping objects selected)]
|
shapes (shapes-for-grouping objects selected)]
|
||||||
|
@ -115,7 +116,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
group-id (first selected)
|
group-id (first selected)
|
||||||
group (get objects group-id)]
|
group (get objects group-id)]
|
||||||
|
@ -130,7 +131,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
selected (cp/clean-loops objects selected)
|
selected (cp/clean-loops objects selected)
|
||||||
shapes (shapes-for-grouping objects selected)]
|
shapes (shapes-for-grouping objects selected)]
|
||||||
|
@ -185,7 +186,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])]
|
selected (get-in state [:workspace-local :selected])]
|
||||||
(when (= (count selected) 1)
|
(when (= (count selected) 1)
|
||||||
(let [group (get objects (first selected))
|
(let [group (get objects (first selected))
|
||||||
|
|
|
@ -7,24 +7,25 @@
|
||||||
(ns app.main.data.workspace.libraries
|
(ns app.main.data.workspace.libraries
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.spec :as us]
|
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.common.pages :as cp]
|
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as geom]
|
[app.common.geom.shapes :as geom]
|
||||||
[app.main.data.messages :as dm]
|
|
||||||
[app.main.data.workspace.common :as dwc]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
|
||||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
|
[app.common.pages :as cp]
|
||||||
|
[app.common.spec :as us]
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
|
[app.main.data.messages :as dm]
|
||||||
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.common :as dwc]
|
||||||
|
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.util.color :as color]
|
[app.util.color :as color]
|
||||||
[app.util.i18n :refer [tr]]
|
[app.util.i18n :refer [tr]]
|
||||||
|
[app.util.logging :as log]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.util.logging :as log]
|
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
@ -237,7 +238,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [file-id (:current-file-id state)
|
(let [file-id (:current-file-id state)
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
selected (cp/clean-loops objects selected)]
|
selected (cp/clean-loops objects selected)]
|
||||||
(let [[group rchanges uchanges]
|
(let [[group rchanges uchanges]
|
||||||
|
@ -343,7 +344,7 @@
|
||||||
delta (gpt/subtract position orig-pos)
|
delta (gpt/subtract position orig-pos)
|
||||||
|
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
unames (atom (dwc/retrieve-used-names objects))
|
unames (atom (dwc/retrieve-used-names objects))
|
||||||
|
|
||||||
frame-id (cp/frame-id-by-position objects (gpt/add orig-pos delta))
|
frame-id (cp/frame-id-by-position objects (gpt/add orig-pos delta))
|
||||||
|
@ -411,7 +412,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
shapes (cp/get-object-with-children id objects)
|
shapes (cp/get-object-with-children id objects)
|
||||||
|
|
||||||
rchanges (map (fn [obj]
|
rchanges (map (fn [obj]
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
[app.main.data.workspace.path.streams :as streams]
|
[app.main.data.workspace.path.streams :as streams]
|
||||||
[app.main.data.workspace.path.tools :as tools]
|
[app.main.data.workspace.path.tools :as tools]
|
||||||
[app.main.data.workspace.path.undo :as undo]
|
[app.main.data.workspace.path.undo :as undo]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.util.path.commands :as upc]
|
[app.util.path.commands :as upc]
|
||||||
[app.util.path.geom :as upg]
|
[app.util.path.geom :as upg]
|
||||||
|
@ -259,7 +260,7 @@
|
||||||
(ptk/reify ::setup-frame-path
|
(ptk/reify ::setup-frame-path
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
content (get-in state [:workspace-drawing :object :content] [])
|
content (get-in state [:workspace-drawing :object :content] [])
|
||||||
position (get-in content [0 :params] nil)
|
position (get-in content [0 :params] nil)
|
||||||
frame-id (cp/frame-id-by-position objects position)]
|
frame-id (cp/frame-id-by-position objects position)]
|
||||||
|
|
|
@ -6,10 +6,6 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.selection
|
(ns app.main.data.workspace.selection
|
||||||
(:require
|
(:require
|
||||||
[beicon.core :as rx]
|
|
||||||
[cljs.spec.alpha :as s]
|
|
||||||
[potok.core :as ptk]
|
|
||||||
[linked.set :as lks]
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as geom]
|
[app.common.geom.shapes :as geom]
|
||||||
|
@ -17,11 +13,16 @@
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.common :as dwc]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
|
||||||
[app.main.data.modal :as md]
|
[app.main.data.modal :as md]
|
||||||
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.common :as dwc]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.main.worker :as uw]))
|
[app.main.worker :as uw]
|
||||||
|
[beicon.core :as rx]
|
||||||
|
[cljs.spec.alpha :as s]
|
||||||
|
[linked.set :as lks]
|
||||||
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
(s/def ::set-of-uuid
|
(s/def ::set-of-uuid
|
||||||
(s/every uuid? :kind set?))
|
(s/every uuid? :kind set?))
|
||||||
|
@ -101,7 +102,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)]
|
objects (wsh/lookup-page-objects state page-id)]
|
||||||
(rx/of (dwc/expand-all-parents [id] objects)))))))
|
(rx/of (dwc/expand-all-parents [id] objects)))))))
|
||||||
|
|
||||||
(defn deselect-shape
|
(defn deselect-shape
|
||||||
|
@ -118,7 +119,7 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
selection (-> state
|
selection (-> state
|
||||||
(get-in [:workspace-local :selected] #{})
|
(get-in [:workspace-local :selected] #{})
|
||||||
(conj id))]
|
(conj id))]
|
||||||
|
@ -136,7 +137,7 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (dwc/lookup-page-objects state)]
|
(let [objects (wsh/lookup-page-objects state)]
|
||||||
(rx/of (dwc/expand-all-parents ids objects))))))
|
(rx/of (dwc/expand-all-parents ids objects))))))
|
||||||
|
|
||||||
(defn select-all
|
(defn select-all
|
||||||
|
@ -145,7 +146,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
new-selected (let [selected-objs
|
new-selected (let [selected-objs
|
||||||
(->> (get-in state [:workspace-local :selected])
|
(->> (get-in state [:workspace-local :selected])
|
||||||
(map #(get objects %)))
|
(map #(get objects %)))
|
||||||
|
@ -205,7 +206,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state)
|
objects (wsh/lookup-page-objects state)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
initial-set (if preserve?
|
initial-set (if preserve?
|
||||||
selected
|
selected
|
||||||
|
@ -229,7 +230,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
group (get objects group-id)
|
group (get objects group-id)
|
||||||
children (map #(get objects %) (:shapes group))
|
children (map #(get objects %) (:shapes group))
|
||||||
|
|
||||||
|
@ -379,7 +380,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
delta (gpt/point 0 0)
|
delta (gpt/point 0 0)
|
||||||
|
|
39
frontend/src/app/main/data/workspace/state_helpers.cljs
Normal file
39
frontend/src/app/main/data/workspace/state_helpers.cljs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) UXBOX Labs SL
|
||||||
|
|
||||||
|
(ns app.main.data.workspace.state-helpers
|
||||||
|
(:require
|
||||||
|
#_[app.common.data :as d]
|
||||||
|
#_[app.common.geom.proportions :as gpr]
|
||||||
|
#_[app.common.geom.shapes :as gsh]
|
||||||
|
#_[app.common.pages :as cp]
|
||||||
|
#_[app.common.spec :as us]
|
||||||
|
#_[app.common.uuid :as uuid]
|
||||||
|
#_[app.main.data.workspace.changes :as dch]
|
||||||
|
#_[app.main.data.workspace.undo :as dwu]
|
||||||
|
#_[app.main.streams :as ms]
|
||||||
|
#_[app.main.worker :as uw]
|
||||||
|
#_[app.util.logging :as log]
|
||||||
|
#_[beicon.core :as rx]
|
||||||
|
#_[cljs.spec.alpha :as s]
|
||||||
|
#_[potok.core :as ptk]))
|
||||||
|
|
||||||
|
(defn lookup-page-objects
|
||||||
|
([state]
|
||||||
|
(lookup-page-objects state (:current-page-id state)))
|
||||||
|
([state page-id]
|
||||||
|
(get-in state [:workspace-data :pages-index page-id :objects])))
|
||||||
|
|
||||||
|
(defn lookup-page-options
|
||||||
|
([state]
|
||||||
|
(lookup-page-options state (:current-page-id state)))
|
||||||
|
([state page-id]
|
||||||
|
(get-in state [:workspace-data :pages-index page-id :options])))
|
||||||
|
|
||||||
|
(defn lookup-component-objects
|
||||||
|
([state component-id]
|
||||||
|
(get-in state [:workspace-data :components component-id :objects])))
|
||||||
|
|
|
@ -9,16 +9,17 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
|
||||||
[app.common.geom.proportions :as gpr]
|
[app.common.geom.proportions :as gpr]
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.common :as dwc]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.common :as dwc]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.util.color :as uc]
|
[app.util.color :as uc]
|
||||||
[app.util.path.parser :as upp]
|
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
|
[app.util.path.parser :as upp]
|
||||||
[app.util.svg :as usvg]
|
[app.util.svg :as usvg]
|
||||||
[app.util.uri :as uu]
|
[app.util.uri :as uu]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
@ -416,7 +417,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(try
|
(try
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame-id (cp/frame-id-by-position objects position)
|
frame-id (cp/frame-id-by-position objects position)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,17 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.texts
|
(ns app.main.data.workspace.texts
|
||||||
(:require
|
(:require
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.common.attrs :as attrs]
|
[app.common.attrs :as attrs]
|
||||||
[app.common.text :as txt]
|
|
||||||
[app.common.geom.shapes :as gsh]
|
|
||||||
[app.common.pages :as cp]
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.common.math :as mth]
|
||||||
[app.main.data.workspace.transforms :as dwt]
|
[app.common.pages :as cp]
|
||||||
|
[app.common.text :as txt]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.common :as dwc]
|
||||||
|
[app.main.data.workspace.selection :as dws]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
|
[app.main.data.workspace.transforms :as dwt]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
[app.main.fonts :as fonts]
|
[app.main.fonts :as fonts]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
|
@ -23,8 +24,8 @@
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[goog.object :as gobj]
|
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
[goog.object :as gobj]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
(defn update-editor
|
(defn update-editor
|
||||||
|
@ -136,7 +137,7 @@
|
||||||
(ptk/reify ::update-root-attrs
|
(ptk/reify ::update-root-attrs
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
|
|
||||||
update-fn #(update-shape % txt/is-root-node? attrs/merge attrs)
|
update-fn #(update-shape % txt/is-root-node? attrs/merge attrs)
|
||||||
|
@ -156,7 +157,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(when-not (some? (get-in state [:workspace-editor-state id]))
|
(when-not (some? (get-in state [:workspace-editor-state id]))
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
|
|
||||||
merge-fn (fn [node attrs]
|
merge-fn (fn [node attrs]
|
||||||
|
@ -183,7 +184,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(when-not (some? (get-in state [:workspace-editor-state id]))
|
(when-not (some? (get-in state [:workspace-editor-state id]))
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
|
|
||||||
update-fn #(update-shape % txt/is-text-node? attrs/merge attrs)
|
update-fn #(update-shape % txt/is-text-node? attrs/merge attrs)
|
||||||
|
@ -205,7 +206,7 @@
|
||||||
(ptk/reify ::start-edit-if-selected
|
(ptk/reify ::start-edit-if-selected
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
selected (->> state :workspace-local :selected (map #(get objects %)))]
|
selected (->> state :workspace-local :selected (map #(get objects %)))]
|
||||||
(cond-> state
|
(cond-> state
|
||||||
(and (= 1 (count selected))
|
(and (= 1 (count selected))
|
||||||
|
|
|
@ -7,16 +7,17 @@
|
||||||
(ns app.main.data.workspace.transforms
|
(ns app.main.data.workspace.transforms
|
||||||
"Events related with shapes transformations"
|
"Events related with shapes transformations"
|
||||||
(:require
|
(:require
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.math :as mth]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.data.workspace.common :as dwc]
|
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[app.main.data.workspace.common :as dwc]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.main.data.workspace.selection :as dws]
|
||||||
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.snap :as snap]
|
[app.main.snap :as snap]
|
||||||
|
@ -140,7 +141,7 @@
|
||||||
layout (:workspace-layout state)
|
layout (:workspace-layout state)
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
zoom (get-in state [:workspace-local :zoom] 1)
|
zoom (get-in state [:workspace-local :zoom] 1)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
resizing-shapes (map #(get objects %) ids)
|
resizing-shapes (map #(get objects %) ids)
|
||||||
text-shapes-ids (->> resizing-shapes
|
text-shapes-ids (->> resizing-shapes
|
||||||
(filter #(= :text (:type %)))
|
(filter #(= :text (:type %)))
|
||||||
|
@ -242,7 +243,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [position @ms/mouse-position
|
(let [position @ms/mouse-position
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame-id (cp/frame-id-by-position objects position)
|
frame-id (cp/frame-id-by-position objects position)
|
||||||
|
|
||||||
moving-shapes (->> ids
|
moving-shapes (->> ids
|
||||||
|
@ -282,7 +283,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
ids (if (nil? ids) (get-in state [:workspace-local :selected]) ids)
|
ids (if (nil? ids) (get-in state [:workspace-local :selected]) ids)
|
||||||
shapes (mapv #(get objects %) ids)
|
shapes (mapv #(get objects %) ids)
|
||||||
stopper (rx/filter ms/mouse-up? stream)
|
stopper (rx/filter ms/mouse-up? stream)
|
||||||
|
@ -396,7 +397,7 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [modifiers (or modifiers (get-in state [:workspace-local :modifiers] {}))
|
(let [modifiers (or modifiers (get-in state [:workspace-local :modifiers] {}))
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
not-frame-id?
|
not-frame-id?
|
||||||
(fn [shape-id]
|
(fn [shape-id]
|
||||||
|
@ -448,7 +449,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
rotate-shape (fn [shape]
|
rotate-shape (fn [shape]
|
||||||
(let [delta (- rotation (:rotation shape))]
|
(let [delta (- rotation (:rotation shape))]
|
||||||
(set-rotation delta [shape])))]
|
(set-rotation delta [shape])))]
|
||||||
|
@ -462,7 +463,7 @@
|
||||||
(ptk/reify ::apply-modifiers
|
(ptk/reify ::apply-modifiers
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
children-ids (->> ids (mapcat #(cp/get-children % objects)))
|
children-ids (->> ids (mapcat #(cp/get-children % objects)))
|
||||||
ids-with-children (d/concat [] children-ids ids)]
|
ids-with-children (d/concat [] children-ids ids)]
|
||||||
(rx/of (dwu/start-undo-transaction)
|
(rx/of (dwu/start-undo-transaction)
|
||||||
|
@ -485,7 +486,7 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
update-children
|
update-children
|
||||||
(fn [objects ids modifiers]
|
(fn [objects ids modifiers]
|
||||||
|
@ -509,7 +510,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
ids (d/concat [] ids (mapcat #(cp/get-children % objects) ids))]
|
ids (d/concat [] ids (mapcat #(cp/get-children % objects) ids))]
|
||||||
(rx/of (apply-modifiers ids))))))
|
(rx/of (apply-modifiers ids))))))
|
||||||
|
|
||||||
|
@ -517,7 +518,7 @@
|
||||||
(ptk/reify ::flip-horizontal-selected
|
(ptk/reify ::flip-horizontal-selected
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
shapes (map #(get objects %) selected)
|
shapes (map #(get objects %) selected)
|
||||||
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
||||||
|
@ -534,7 +535,7 @@
|
||||||
(ptk/reify ::flip-vertical-selected
|
(ptk/reify ::flip-vertical-selected
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [objects (dwc/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
shapes (map #(get objects %) selected)
|
shapes (map #(get objects %) selected)
|
||||||
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue