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