mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -05:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
e241273a1e
29 changed files with 321 additions and 281 deletions
|
@ -39,6 +39,7 @@
|
|||
- Fix visual problem with group invite [Taiga #1290](https://tree.taiga.io/project/penpot/issue/1290)
|
||||
- Fix issues with promote owner panel [Taiga #763](https://tree.taiga.io/project/penpot/issue/763)
|
||||
- Allow use library colors when defining gradients [Taiga #1614](https://tree.taiga.io/project/penpot/issue/1614)
|
||||
- Fix group selrect not updating after alignment [#895](https://github.com/penpot/penpot/issues/895)
|
||||
|
||||
### :arrow_up: Deps updates
|
||||
|
||||
|
|
|
@ -125,8 +125,7 @@
|
|||
["/assets" {:middleware [[middleware/format-response-body]
|
||||
[middleware/errors errors/handle]
|
||||
[middleware/cookies]
|
||||
(:middleware session)
|
||||
middleware/activity-logger]}
|
||||
(:middleware session)]}
|
||||
["/by-id/:id" {:get (:objects-handler assets)}]
|
||||
["/by-file-media-id/:id" {:get (:file-objects-handler assets)}]
|
||||
["/by-file-media-id/:id/thumbnail" {:get (:file-thumbnails-handler assets)}]]
|
||||
|
@ -152,8 +151,7 @@
|
|||
["/auth/oauth/:provider" {:post (:handler oauth)}]
|
||||
["/auth/oauth/:provider/callback" {:get (:callback-handler oauth)}]
|
||||
|
||||
["/rpc" {:middleware [(:middleware session)
|
||||
middleware/activity-logger]}
|
||||
["/rpc" {:middleware [(:middleware session)]}
|
||||
["/query/:type" {:get (:query-handler rpc)
|
||||
:post (:query-handler rpc)}]
|
||||
["/mutation/:type" {:post (:mutation-handler rpc)}]]]]))
|
||||
|
|
|
@ -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)]
|
||||
|
||||
|
@ -572,11 +573,11 @@
|
|||
(ptk/reify ::zoom-to-selected-shape
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [selected (get-in state [:workspace-local :selected])]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(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))]
|
||||
|
@ -622,7 +623,7 @@
|
|||
(ptk/reify ::update-selected-shapes
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [selected (get-in state [:workspace-local :selected])]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(rx/from (map #(update-shape % attrs) selected))))))
|
||||
|
||||
;; --- Shape Movement (using keyboard shorcuts)
|
||||
|
@ -660,7 +661,7 @@
|
|||
(ptk/reify ::delete-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [selected (get-in state [:workspace-local :selected])]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(rx/of (dwc/delete-shapes selected)
|
||||
(dws/deselect-all))))))
|
||||
|
||||
|
@ -675,8 +676,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
rchanges (mapv (fn [id]
|
||||
(let [obj (get objects id)
|
||||
parent (get objects (:parent-id obj))
|
||||
|
@ -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)
|
||||
|
@ -987,7 +988,7 @@
|
|||
(ptk/reify ::relocate-selected-shapes
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [selected (get-in state [:workspace-local :selected])]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(rx/of (relocate-shapes selected parent-id to-index))))))
|
||||
|
||||
|
||||
|
@ -996,11 +997,11 @@
|
|||
(ptk/reify ::start-editing-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [selected (get-in state [:workspace-local :selected])]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(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,8 +1047,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
moved (if (= 1 (count selected))
|
||||
(align-object-to-frame objects (first selected) axis)
|
||||
(align-objects-list objects selected axis))
|
||||
|
@ -1077,8 +1078,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
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)
|
||||
|
@ -1231,7 +1232,7 @@
|
|||
(let [mdata (cond-> params
|
||||
(some? shape)
|
||||
(assoc :selected
|
||||
(get-in state [:workspace-local :selected])))]
|
||||
(wsh/lookup-selected state)))]
|
||||
(assoc-in state [:workspace-local :context-menu] mdata)))))
|
||||
|
||||
(defn show-shape-context-menu
|
||||
|
@ -1241,7 +1242,7 @@
|
|||
(ptk/reify ::show-shape-context-menu
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [selected (get-in state [:workspace-local :selected])]
|
||||
(let [selected (wsh/lookup-selected state)]
|
||||
(rx/concat
|
||||
(when-not (selected (:id shape))
|
||||
(rx/of (dws/select-shape (:id shape))))
|
||||
|
@ -1311,8 +1312,8 @@
|
|||
(ptk/reify ::copy-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [objects (dwc/lookup-page-objects state)
|
||||
selected (->> (get-in state [:workspace-local :selected])
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
selected (->> (wsh/lookup-selected state)
|
||||
(cp/clean-loops objects))
|
||||
pdata (reduce (partial collect-object-ids objects) {} selected)
|
||||
initial {:type :copied-shapes
|
||||
|
@ -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)
|
||||
|
@ -1411,9 +1412,8 @@
|
|||
(js/console.error "Clipboard error:" err))))))
|
||||
|
||||
(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)]
|
||||
(let [selected (wsh/lookup-selected state)
|
||||
objects (wsh/lookup-page-objects state)]
|
||||
(and (and (= 1 (count selected))
|
||||
(= :frame (get-in objects [(first selected) :type]))))))
|
||||
|
||||
|
@ -1450,10 +1450,10 @@
|
|||
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])
|
||||
page-selected (wsh/lookup-selected state)
|
||||
wrapper (gsh/selection-rect selected-objs)
|
||||
orig-pos (gpt/point (:x1 wrapper) (:y1 wrapper))]
|
||||
(cond
|
||||
|
@ -1518,7 +1518,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 +1574,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
|
||||
|
@ -1634,7 +1634,7 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [initial-pos @ms/mouse-position
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
selected (wsh/lookup-selected state)
|
||||
stopper (rx/filter ms/mouse-up? stream)]
|
||||
(when (= 1 (count selected))
|
||||
(rx/concat
|
||||
|
@ -1649,8 +1649,8 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected-shape-id (-> state (get-in [:workspace-local :selected]) first)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected-shape-id (-> state wsh/lookup-selected first)
|
||||
selected-shape (get objects selected-shape-id)
|
||||
selected-shape-frame-id (:frame-id selected-shape)
|
||||
start-frame (get objects selected-shape-frame-id)
|
||||
|
@ -1672,10 +1672,10 @@
|
|||
(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]))
|
||||
shape-id (-> state wsh/lookup-selected first)
|
||||
shape (get objects shape-id)]
|
||||
|
||||
(when-not (= position initial-pos)
|
||||
|
@ -1699,7 +1699,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)
|
||||
|
@ -191,7 +191,7 @@
|
|||
(ptk/reify ::picker-for-selected-shape
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [ids (get-in state [:workspace-local :selected])
|
||||
(let [ids (wsh/lookup-selected state)
|
||||
stop? (rx/filter (ptk/type? ::stop-picker) stream)
|
||||
|
||||
update-events
|
||||
|
@ -227,7 +227,7 @@
|
|||
(ptk/reify ::start-gradient
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (first (get-in state [:workspace-local :selected]))]
|
||||
(let [id (-> state wsh/lookup-selected first)]
|
||||
(-> state
|
||||
(assoc-in [:workspace-local :current-gradient] gradient)
|
||||
(assoc-in [:workspace-local :current-gradient :shape-id] id))))))
|
||||
|
|
|
@ -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]
|
||||
|
@ -27,35 +28,12 @@
|
|||
(s/def ::shape-attrs ::cp/shape-attrs)
|
||||
(s/def ::set-of-string (s/every string? :kind set?))
|
||||
(s/def ::ordered-set-of-uuid (s/every uuid? :kind d/ordered-set?))
|
||||
;; --- Protocols
|
||||
|
||||
(declare setup-selection-index)
|
||||
(declare update-indices)
|
||||
(declare reset-undo)
|
||||
(declare append-undo)
|
||||
|
||||
|
||||
;; --- 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 +176,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 +187,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 +197,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,14 +278,14 @@
|
|||
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
|
||||
(retrieve-used-names)
|
||||
(generate-unique-name (:name attrs)))
|
||||
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
selected (wsh/lookup-selected state)
|
||||
|
||||
[rchanges uchanges] (add-shape-changes
|
||||
page-id
|
||||
|
@ -329,7 +307,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 +339,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 +457,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,8 +102,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
selected (cp/clean-loops objects selected)
|
||||
shapes (shapes-for-grouping objects selected)]
|
||||
(when-not (empty? shapes)
|
||||
|
@ -115,8 +116,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
group-id (first selected)
|
||||
group (get objects group-id)]
|
||||
(when (and (= 1 (count selected))
|
||||
|
@ -130,8 +131,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
selected (cp/clean-loops objects selected)
|
||||
shapes (shapes-for-grouping objects selected)]
|
||||
(when-not (empty? shapes)
|
||||
|
@ -185,8 +186,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])]
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)]
|
||||
(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,8 +238,8 @@
|
|||
(watch [_ state stream]
|
||||
(let [file-id (:current-file-id state)
|
||||
page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
selected (cp/clean-loops objects selected)]
|
||||
(let [[group rchanges uchanges]
|
||||
(dwlh/generate-add-component selected objects page-id file-id)]
|
||||
|
@ -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]
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
(ns app.main.data.workspace.notifications
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.uri :as u]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.spec :as us]
|
||||
[app.common.uri :as u]
|
||||
[app.config :as cf]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.persistence :as dwp]
|
||||
[app.main.repo :as rp]
|
||||
|
@ -217,7 +217,7 @@
|
|||
(let [changes-by-pages (group-by :page-id changes)
|
||||
process-page-changes
|
||||
(fn [[page-id changes]]
|
||||
(dwc/update-indices page-id changes))]
|
||||
(dch/update-indices page-id changes))]
|
||||
|
||||
(rx/merge
|
||||
(rx/of (dwp/shapes-changes-persisted file-id msg))
|
||||
|
|
|
@ -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,9 +119,9 @@
|
|||
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] #{})
|
||||
wsh/lookup-selected
|
||||
(conj id))]
|
||||
(-> state
|
||||
(assoc-in [:workspace-local :selected]
|
||||
|
@ -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,9 +146,9 @@
|
|||
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])
|
||||
(->> (wsh/lookup-selected state)
|
||||
(map #(get objects %)))
|
||||
|
||||
frame-ids
|
||||
|
@ -205,8 +206,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state)
|
||||
selected (wsh/lookup-selected state)
|
||||
initial-set (if preserve?
|
||||
selected
|
||||
lks/empty-linked-set)
|
||||
|
@ -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,9 +380,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
selected (wsh/lookup-selected state)
|
||||
delta (gpt/point 0 0)
|
||||
unames (dwc/retrieve-used-names objects)
|
||||
|
||||
|
|
34
frontend/src/app/main/data/workspace/state_helpers.cljs
Normal file
34
frontend/src/app/main/data/workspace/state_helpers.cljs
Normal file
|
@ -0,0 +1,34 @@
|
|||
;; 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]))
|
||||
|
||||
(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])))
|
||||
|
||||
(defn lookup-selected
|
||||
[state]
|
||||
(let [selected (get-in state [:workspace-local :selected])
|
||||
objects (lookup-page-objects state)
|
||||
is-present? (fn [id] (contains? objects id))]
|
||||
(into (d/ordered-set)
|
||||
(filter is-present?)
|
||||
selected)))
|
|
@ -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,9 +417,9 @@
|
|||
(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])
|
||||
selected (wsh/lookup-selected state)
|
||||
|
||||
[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
|
||||
x (- x vb-x (/ vb-width 2))
|
||||
|
|
|
@ -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,8 +206,8 @@
|
|||
(ptk/reify ::start-edit-if-selected
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [objects (dwc/lookup-page-objects state)
|
||||
selected (->> state :workspace-local :selected (map #(get objects %)))]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
selected (->> state wsh/lookup-selected (mapv #(get objects %)))]
|
||||
(cond-> state
|
||||
(and (= 1 (count selected))
|
||||
(= (-> selected first :type) :text))
|
||||
|
|
|
@ -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 %)))
|
||||
|
@ -209,7 +210,7 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [initial (deref ms/mouse-position)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
selected (wsh/lookup-selected state)
|
||||
stopper (rx/filter ms/mouse-up? stream)]
|
||||
(->> ms/mouse-position
|
||||
(rx/take-until stopper)
|
||||
|
@ -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,8 +283,8 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dwc/lookup-page-objects state page-id)
|
||||
ids (if (nil? ids) (get-in state [:workspace-local :selected]) ids)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
ids (if (nil? ids) (wsh/lookup-selected state) ids)
|
||||
shapes (mapv #(get objects %) ids)
|
||||
stopper (rx/filter ms/mouse-up? stream)
|
||||
layout (get state :workspace-layout)
|
||||
|
@ -363,7 +364,7 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(if (= same-event (get-in state [:workspace-local :current-move-selected]))
|
||||
(let [selected (get-in state [:workspace-local :selected])
|
||||
(let [selected (wsh/lookup-selected state)
|
||||
move-events (->> stream
|
||||
(rx/filter (ptk/type? ::move-selected))
|
||||
(rx/filter #(= direction (deref %))))
|
||||
|
@ -399,7 +400,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]
|
||||
|
@ -451,7 +452,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])))]
|
||||
|
@ -465,7 +466,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)
|
||||
|
@ -488,7 +489,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]
|
||||
|
@ -512,7 +513,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))))))
|
||||
|
||||
|
@ -520,8 +521,8 @@
|
|||
(ptk/reify ::flip-horizontal-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [objects (dwc/lookup-page-objects state)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
selected (wsh/lookup-selected state)
|
||||
shapes (map #(get objects %) selected)
|
||||
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
||||
origin (gpt/point (:x selrect) (+ (:y selrect) (/ (:height selrect) 2)))]
|
||||
|
@ -537,8 +538,8 @@
|
|||
(ptk/reify ::flip-vertical-selected
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [objects (dwc/lookup-page-objects state)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
selected (wsh/lookup-selected state)
|
||||
shapes (map #(get objects %) selected)
|
||||
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
||||
origin (gpt/point (+ (:x selrect) (/ (:width selrect) 2)) (:y selrect))]
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
(ns app.main.refs
|
||||
"A collection of derived refs."
|
||||
(:require
|
||||
[beicon.core :as rx]
|
||||
[okulary.core :as l]
|
||||
[app.common.data :as d]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.constants :as c]
|
||||
[app.main.store :as st]))
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.store :as st]
|
||||
[beicon.core :as rx]
|
||||
[okulary.core :as l]))
|
||||
|
||||
;; ---- Global refs
|
||||
|
||||
|
@ -74,7 +75,7 @@
|
|||
(l/derived :workspace-drawing st/state))
|
||||
|
||||
(def selected-shapes
|
||||
(l/derived :selected workspace-local))
|
||||
(l/derived wsh/lookup-selected st/state))
|
||||
|
||||
(defn make-selected-ref
|
||||
[id]
|
||||
|
@ -88,7 +89,6 @@
|
|||
:edition
|
||||
:edit-path
|
||||
:tooltip
|
||||
:selected
|
||||
:panning
|
||||
:picking-color?
|
||||
:transform
|
||||
|
@ -214,30 +214,28 @@
|
|||
workspace-page-objects =))
|
||||
|
||||
(def selected-data
|
||||
(l/derived #(let [selected (get-in % [:workspace-local :selected])
|
||||
page-id (:current-page-id %)
|
||||
objects (get-in % [:workspace-data :pages-index page-id :objects])]
|
||||
(l/derived #(let [selected (wsh/lookup-selected %)
|
||||
objects (wsh/lookup-page-objects %)]
|
||||
(hash-map :selected selected
|
||||
:page-id page-id
|
||||
:objects objects))
|
||||
st/state =))
|
||||
|
||||
(defn is-child-selected?
|
||||
[id]
|
||||
(letfn [(selector [{:keys [selected page-id objects]}]
|
||||
(letfn [(selector [{:keys [selected objects]}]
|
||||
(let [children (cp/get-children id objects)]
|
||||
(some #(contains? selected %) children)))]
|
||||
(l/derived selector selected-data =)))
|
||||
|
||||
(def selected-objects
|
||||
(letfn [(selector [{:keys [selected page-id objects]}]
|
||||
(letfn [(selector [{:keys [selected objects]}]
|
||||
(->> selected
|
||||
(map #(get objects %))
|
||||
(filterv (comp not nil?))))]
|
||||
(l/derived selector selected-data =)))
|
||||
|
||||
(def selected-shapes-with-children
|
||||
(letfn [(selector [{:keys [selected page-id objects]}]
|
||||
(letfn [(selector [{:keys [selected objects]}]
|
||||
(let [children (->> selected
|
||||
(mapcat #(cp/get-children % objects))
|
||||
(filterv (comp not nil?)))]
|
||||
|
@ -245,7 +243,7 @@
|
|||
(l/derived selector selected-data =)))
|
||||
|
||||
(def selected-objects-with-children
|
||||
(letfn [(selector [{:keys [selected page-id objects]}]
|
||||
(letfn [(selector [{:keys [selected objects]}]
|
||||
(let [children (->> selected
|
||||
(mapcat #(cp/get-children % objects))
|
||||
(filterv (comp not nil?)))
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
[app.common.geom.shapes :as geom]
|
||||
[app.main.ui.context :as muc]
|
||||
[app.main.ui.shapes.attrs :as attrs]
|
||||
[app.main.ui.shapes.text.embed :as ste]
|
||||
[app.main.ui.shapes.text.styles :as sts]
|
||||
[app.util.color :as uc]
|
||||
[app.util.object :as obj]
|
||||
|
@ -30,15 +29,12 @@
|
|||
{::mf/wrap-props false}
|
||||
[props]
|
||||
(let [node (obj/get props "node")
|
||||
embed? (obj/get props "embed-fonts?")
|
||||
children (obj/get props "children")
|
||||
shape (obj/get props "shape")
|
||||
style (sts/generate-root-styles shape node)]
|
||||
[:div.root.rich-text
|
||||
{:style style
|
||||
:xmlns "http://www.w3.org/1999/xhtml"}
|
||||
(when embed?
|
||||
[:& ste/embed-fontfaces-style {:node node}])
|
||||
children]))
|
||||
|
||||
(mf/defc render-paragraph-set
|
||||
|
@ -94,7 +90,6 @@
|
|||
[props ref]
|
||||
(let [{:keys [id x y width height content] :as shape} (obj/get props "shape")
|
||||
grow-type (obj/get props "grow-type") ;; This is only needed in workspace
|
||||
embed-fonts? (mf/use-ctx muc/embed-ctx)
|
||||
;; We add 8px to add a padding for the exporter
|
||||
;; width (+ width 8)
|
||||
]
|
||||
|
@ -109,5 +104,4 @@
|
|||
:ref ref}
|
||||
[:& render-node {:index 0
|
||||
:shape shape
|
||||
:node content
|
||||
:embed-fonts? embed-fonts?}]]))
|
||||
:node content}]]))
|
||||
|
|
|
@ -62,12 +62,14 @@
|
|||
"Given a font and the variant-id, retrieves the style CSS for it."
|
||||
[{:keys [id backend family variants] :as font} font-variant-id]
|
||||
(if (= :google backend)
|
||||
(->> (http/send! {:method :get
|
||||
:mode :no-cors
|
||||
:uri (fonts/gfont-url family [{:id font-variant-id}])
|
||||
:response-type :text})
|
||||
(rx/map :body)
|
||||
(http/as-promise))
|
||||
(let [uri (fonts/gfont-url family [{:id font-variant-id}])]
|
||||
(->> (http/send! {:method :get
|
||||
:mode :cors
|
||||
:omit-default-headers true
|
||||
:uri uri
|
||||
:response-type :text})
|
||||
(rx/map :body)
|
||||
(http/as-promise)))
|
||||
(let [{:keys [name weight style suffix] :as variant} (d/seek #(= (:id %) font-variant-id) variants)
|
||||
result (str/fmt font-face-template {:family family
|
||||
:style style
|
||||
|
@ -89,7 +91,7 @@
|
|||
(with-cache {:key uris :max-age (dt/duration {:hours 4})}
|
||||
(->> (rx/from (seq uris))
|
||||
(rx/mapcat (fn [uri]
|
||||
(->> (http/send! {:method :get :uri uri :response-type :blob})
|
||||
(->> (http/send! {:method :get :uri uri :response-type :blob :omit-default-headers true})
|
||||
(rx/map :body)
|
||||
(rx/mapcat wapi/read-file-as-data-url)
|
||||
(rx/map #(vector uri %)))))
|
||||
|
@ -124,9 +126,10 @@
|
|||
|
||||
(mf/defc embed-fontfaces-style
|
||||
{::mf/wrap-props false
|
||||
::mf/wrap [mf/memo]}
|
||||
::mf/wrap [#(mf/memo' % (mf/check-props ["shapes"]))]}
|
||||
[props]
|
||||
(let [node (obj/get props "node")
|
||||
(let [shapes (obj/get props "shapes")
|
||||
node {:children (->> shapes (map :content))}
|
||||
fonts (-> node get-node-fonts memoize)
|
||||
style (mf/use-state nil)]
|
||||
|
||||
|
|
|
@ -7,37 +7,55 @@
|
|||
(ns app.main.ui.viewer.shapes
|
||||
"The main container for a frame in viewer mode"
|
||||
(:require
|
||||
[rumext.alpha :as mf]
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as geom]
|
||||
[app.common.pages :as cp]
|
||||
[app.main.data.viewer :as dv]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.shapes.filters :as filters]
|
||||
[app.main.ui.shapes.circle :as circle]
|
||||
[app.main.ui.shapes.filters :as filters]
|
||||
[app.main.ui.shapes.frame :as frame]
|
||||
[app.main.ui.shapes.group :as group]
|
||||
[app.main.ui.shapes.svg-raw :as svg-raw]
|
||||
[app.main.ui.shapes.image :as image]
|
||||
[app.main.ui.shapes.path :as path]
|
||||
[app.main.ui.shapes.rect :as rect]
|
||||
[app.main.ui.shapes.shape :refer [shape-container]]
|
||||
[app.main.ui.shapes.svg-raw :as svg-raw]
|
||||
[app.main.ui.shapes.text :as text]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.object :as obj]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as geom]
|
||||
[app.main.ui.shapes.shape :refer [shape-container]]))
|
||||
[rumext.alpha :as mf]))
|
||||
|
||||
(defn on-mouse-down
|
||||
[event {:keys [interactions] :as shape}]
|
||||
[event interactions]
|
||||
(let [interaction (first (filter #(= (:event-type %) :click) interactions))]
|
||||
(case (:action-type interaction)
|
||||
:navigate
|
||||
(let [frame-id (:destination interaction)]
|
||||
(dom/stop-propagation event)
|
||||
(st/emit! (dv/go-to-frame frame-id)))
|
||||
|
||||
nil)))
|
||||
|
||||
(mf/defc interaction
|
||||
[{:keys [shape interactions show-interactions?]}]
|
||||
(let [{:keys [x y width height]} (:selrect shape)
|
||||
frame? (= :frame (:type shape))]
|
||||
(when-not (empty? interactions)
|
||||
[:rect {:x (- x 1)
|
||||
:y (- y 1)
|
||||
:width (+ width 2)
|
||||
:height (+ height 2)
|
||||
:fill "#31EFB8"
|
||||
:stroke "#31EFB8"
|
||||
:stroke-width (if show-interactions? 1 0)
|
||||
:fill-opacity (if show-interactions? 0.2 0)
|
||||
:style {:pointer-events (when frame? "none")}
|
||||
:transform (geom/transform-matrix shape)}])))
|
||||
|
||||
(defn generic-wrapper-factory
|
||||
"Wrap some svg shape and add interaction controls"
|
||||
[component show-interactions?]
|
||||
|
@ -45,35 +63,37 @@
|
|||
{::mf/wrap-props false}
|
||||
[props]
|
||||
(let [shape (unchecked-get props "shape")
|
||||
objects (unchecked-get props "objects")
|
||||
{:keys [x y width height]} (:selrect shape)
|
||||
frame? (= :frame (:type shape))
|
||||
|
||||
childs (unchecked-get props "childs")
|
||||
frame (unchecked-get props "frame")
|
||||
|
||||
interactions (->> (:interactions shape)
|
||||
(filter #(contains? objects (:destination %))))
|
||||
|
||||
on-mouse-down (mf/use-callback
|
||||
(mf/deps shape)
|
||||
#(on-mouse-down % shape))
|
||||
(mf/deps interactions)
|
||||
(fn [event]
|
||||
(on-mouse-down event interactions)))
|
||||
|
||||
svg-element? (and (= :svg-raw (:type shape))
|
||||
(not= :svg (get-in shape [:content :tag])))]
|
||||
|
||||
(if-not svg-element?
|
||||
[:> shape-container {:shape shape
|
||||
:on-mouse-down on-mouse-down
|
||||
:cursor (when (seq (:interactions shape)) "pointer")}
|
||||
:cursor (when-not (empty? interactions) "pointer")
|
||||
:on-mouse-down on-mouse-down}
|
||||
|
||||
[:& component {:shape shape
|
||||
:frame frame
|
||||
:childs childs
|
||||
:is-child-selected? true}]
|
||||
(when (:interactions shape)
|
||||
[:rect {:x (- x 1)
|
||||
:y (- y 1)
|
||||
:width (+ width 2)
|
||||
:height (+ height 2)
|
||||
:fill "#31EFB8"
|
||||
:stroke "#31EFB8"
|
||||
:stroke-width (if show-interactions? 1 0)
|
||||
:fill-opacity (if show-interactions? 0.2 0)}])]
|
||||
|
||||
[:& interaction {:shape shape
|
||||
:interactions interactions
|
||||
:show-interactions? show-interactions?}]]
|
||||
|
||||
;; Don't wrap svg elements inside a <g> otherwise some can break
|
||||
[:& component {:shape shape
|
||||
|
@ -127,6 +147,7 @@
|
|||
props (obj/merge! #js {} props
|
||||
#js {:shape shape
|
||||
:childs childs
|
||||
:objects objects
|
||||
:show-interactions? show-interactions?})]
|
||||
[:> frame-wrapper props]))))
|
||||
|
||||
|
@ -141,6 +162,7 @@
|
|||
childs (mapv #(get objects %) (:shapes shape))
|
||||
props (obj/merge! #js {} props
|
||||
#js {:childs childs
|
||||
:objects objects
|
||||
:show-interactions? show-interactions?})]
|
||||
[:> group-wrapper props]))))
|
||||
|
||||
|
@ -155,6 +177,7 @@
|
|||
childs (mapv #(get objects %) (:shapes shape))
|
||||
props (obj/merge! #js {} props
|
||||
#js {:childs childs
|
||||
:objects objects
|
||||
:show-interactions? show-interactions?})]
|
||||
[:> svg-raw-wrapper props]))))
|
||||
|
||||
|
@ -179,7 +202,8 @@
|
|||
(when (and shape (not (:hidden shape)))
|
||||
(let [shape (-> (geom/transform-shape shape)
|
||||
(geom/translate-to-frame frame))
|
||||
opts #js {:shape shape}]
|
||||
opts #js {:shape shape
|
||||
:objects objects}]
|
||||
(case (:type shape)
|
||||
:frame [:g.empty]
|
||||
:text [:> text-wrapper opts]
|
||||
|
@ -187,8 +211,8 @@
|
|||
:path [:> path-wrapper opts]
|
||||
:image [:> image-wrapper opts]
|
||||
:circle [:> circle-wrapper opts]
|
||||
:group [:> group-container {:shape shape :frame frame}]
|
||||
:svg-raw [:> svg-raw-container {:shape shape :frame frame}])))))))
|
||||
:group [:> group-container {:shape shape :frame frame :objects objects}]
|
||||
:svg-raw [:> svg-raw-container {:shape shape :frame frame :objects objects}])))))))
|
||||
|
||||
(mf/defc frame-svg
|
||||
{::mf/wrap [mf/memo]}
|
||||
|
|
|
@ -60,8 +60,10 @@
|
|||
(mf/defc workspace-content
|
||||
{::mf/wrap-props false}
|
||||
[props]
|
||||
(let [local (mf/deref refs/viewport-data)
|
||||
{:keys [zoom vbox vport options-mode selected]} local
|
||||
(let [selected (mf/deref refs/selected-shapes)
|
||||
local (mf/deref refs/viewport-data)
|
||||
|
||||
{:keys [zoom vbox vport options-mode]} local
|
||||
file (obj/get props "file")
|
||||
layout (obj/get props "layout")]
|
||||
[:*
|
||||
|
@ -80,6 +82,7 @@
|
|||
|
||||
[:& viewport {:file file
|
||||
:local local
|
||||
:selected selected
|
||||
:layout layout}]]]
|
||||
|
||||
[:& left-toolbar {:layout layout}]
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
(ns app.main.ui.workspace.colorpalette
|
||||
(:require
|
||||
[app.common.math :as mth]
|
||||
[app.main.data.workspace.colors :as mdc]
|
||||
[app.main.data.workspace :as udw]
|
||||
[app.main.data.workspace.colors :as mdc]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.components.color-bullet :as cb]
|
||||
|
@ -16,11 +17,9 @@
|
|||
[app.main.ui.context :as ctx]
|
||||
[app.main.ui.icons :as i]
|
||||
[app.util.color :as uc]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [t]]
|
||||
[app.util.i18n :refer [tr]]
|
||||
[app.util.keyboard :as kbd]
|
||||
[app.util.object :as obj]
|
||||
[beicon.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
[goog.events :as events]
|
||||
[okulary.core :as l]
|
||||
|
@ -50,7 +49,7 @@
|
|||
[{:keys [color size local?]}]
|
||||
(let [select-color
|
||||
(fn [event]
|
||||
(let [ids (get-in @st/state [:workspace-local :selected])]
|
||||
(let [ids (wsh/lookup-selected @st/state)]
|
||||
(if (kbd/shift? event)
|
||||
(st/emit! (mdc/change-stroke ids (merge uc/empty-color color)))
|
||||
(st/emit! (mdc/change-fill ids (merge uc/empty-color color))))))]
|
||||
|
@ -74,8 +73,6 @@
|
|||
close-fn #(st/emit! (udw/toggle-layout-flags :colorpalette))
|
||||
container (mf/use-ref nil)
|
||||
|
||||
locale (mf/deref i18n/locale)
|
||||
|
||||
on-left-arrow-click
|
||||
(mf/use-callback
|
||||
(mf/deps max-offset visible)
|
||||
|
@ -143,7 +140,7 @@
|
|||
[:li.palette-library
|
||||
{:on-click #(st/emit! (mdc/change-palette-selected :file))}
|
||||
(when (= selected :file) i/tick)
|
||||
[:div.library-name (str (t locale "workspace.libraries.colors.file-library")
|
||||
[:div.library-name (str (tr "workspace.libraries.colors.file-library")
|
||||
(str/format " (%s)" (count file-colors)))]
|
||||
[:div.color-sample
|
||||
(for [[idx color] (map-indexed vector (take 7 (vals file-colors))) ]
|
||||
|
@ -153,7 +150,7 @@
|
|||
[:li.palette-library
|
||||
{:on-click #(st/emit! (mdc/change-palette-selected :recent))}
|
||||
(when (= selected :recent) i/tick)
|
||||
[:div.library-name (str (t locale "workspace.libraries.colors.recent-colors")
|
||||
[:div.library-name (str (tr "workspace.libraries.colors.recent-colors")
|
||||
(str/format " (%s)" (count recent-colors)))]
|
||||
[:div.color-sample
|
||||
(for [[idx color] (map-indexed vector (take 7 (reverse recent-colors))) ]
|
||||
|
@ -165,12 +162,12 @@
|
|||
[:li
|
||||
{:on-click #(st/emit! (mdc/change-palette-size :big))}
|
||||
(when (= size :big) i/tick)
|
||||
(t locale "workspace.libraries.colors.big-thumbnails")]
|
||||
(tr "workspace.libraries.colors.big-thumbnails")]
|
||||
|
||||
[:li
|
||||
{:on-click #(st/emit! (mdc/change-palette-size :small))}
|
||||
(when (= size :small) i/tick)
|
||||
(t locale "workspace.libraries.colors.small-thumbnails")]]]
|
||||
(tr "workspace.libraries.colors.small-thumbnails")]]]
|
||||
|
||||
[:div.color-palette-actions
|
||||
{:on-click #(swap! state assoc :show-menu true)}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
[app.main.ui.context :as muc]
|
||||
[app.main.ui.shapes.frame :as frame]
|
||||
[app.main.ui.shapes.shape :refer [shape-container]]
|
||||
[app.main.ui.shapes.text.embed :as ste]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.keyboard :as kbd]
|
||||
[app.util.timers :as ts]
|
||||
|
@ -76,14 +77,22 @@
|
|||
(let [shape (unchecked-get props "shape")
|
||||
objects (unchecked-get props "objects")
|
||||
edition (mf/deref refs/selected-edition)
|
||||
embed-fonts? (mf/use-ctx muc/embed-ctx)
|
||||
|
||||
shape (gsh/transform-shape shape)
|
||||
children (mapv #(get objects %) (:shapes shape))
|
||||
text-childs (->> objects
|
||||
vals
|
||||
(filterv #(and (= :text (:type %))
|
||||
(= (:id shape) (:frame-id %)))))
|
||||
|
||||
ds-modifier (get-in shape [:modifiers :displacement])]
|
||||
|
||||
(when (and shape (not (:hidden shape)))
|
||||
[:g.frame-wrapper {:display (when (:hidden shape) "none")}
|
||||
[:> shape-container {:shape shape}
|
||||
(when embed-fonts?
|
||||
[:& ste/embed-fontfaces-style {:shapes text-childs}])
|
||||
[:& frame-shape
|
||||
{:shape shape
|
||||
:childs children}]]])))))
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.exports :as exports]
|
||||
[app.main.refs :as refs]
|
||||
|
@ -514,7 +515,7 @@
|
|||
|
||||
apply-color
|
||||
(fn [color-id event]
|
||||
(let [ids (get-in @st/state [:workspace-local :selected])]
|
||||
(let [ids (wsh/lookup-selected @st/state)]
|
||||
(if (kbd/shift? event)
|
||||
(st/emit! (dc/change-stroke ids color))
|
||||
(st/emit! (dc/change-fill ids color)))))
|
||||
|
@ -713,7 +714,7 @@
|
|||
|
||||
apply-typography
|
||||
(fn [typography event]
|
||||
(let [ids (get-in @st/state [:workspace-local :selected])
|
||||
(let [ids (wsh/lookup-selected @st/state)
|
||||
attrs (merge
|
||||
{:typography-ref-file file-id
|
||||
:typography-ref-id (:id typography)}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
;; --- Viewport
|
||||
|
||||
(mf/defc viewport
|
||||
[{:keys [local layout file] :as props}]
|
||||
[{:keys [local selected layout file] :as props}]
|
||||
(let [;; When adding data from workspace-local revisit `app.main.ui.workspace` to check
|
||||
;; that the new parameter is sent
|
||||
{:keys [edit-path
|
||||
|
@ -44,7 +44,6 @@
|
|||
options-mode
|
||||
panning
|
||||
picking-color?
|
||||
selected
|
||||
selrect
|
||||
show-distances?
|
||||
tooltip
|
||||
|
@ -53,7 +52,6 @@
|
|||
vport
|
||||
zoom]} local
|
||||
|
||||
|
||||
;; CONTEXT
|
||||
page-id (mf/use-ctx ctx/current-page-id)
|
||||
|
||||
|
|
|
@ -181,19 +181,22 @@
|
|||
draw-interaction-to (:draw-interaction-to local)
|
||||
draw-interaction-to-frame (:draw-interaction-to-frame local)
|
||||
first-selected (first selected-shapes)]
|
||||
[:*
|
||||
|
||||
[:g.interactions
|
||||
[:g.non-selected
|
||||
(for [shape active-shapes]
|
||||
(let [interaction (get-click-interaction shape)
|
||||
dest-shape (get objects (:destination interaction))
|
||||
selected? (contains? selected (:id shape))]
|
||||
(when-not selected?
|
||||
(when-not (or selected? (not dest-shape))
|
||||
[:& interaction-path {:key (:id shape)
|
||||
:orig-shape shape
|
||||
:dest-shape dest-shape
|
||||
:selected selected
|
||||
:selected? false
|
||||
:zoom zoom}])))
|
||||
:zoom zoom}])))]
|
||||
|
||||
[:g.selected
|
||||
(if (and draw-interaction-to first-selected)
|
||||
[:& interaction-path {:key "interactive"
|
||||
:orig-shape first-selected
|
||||
|
@ -216,5 +219,5 @@
|
|||
[:& interaction-handle {:key (:id shape)
|
||||
:shape shape
|
||||
:selected selected
|
||||
:zoom zoom}])))))]))
|
||||
:zoom zoom}])))))]]))
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
(mf/deps img-ref)
|
||||
(fn []
|
||||
(let [img-node (mf/ref-val img-ref)
|
||||
svg-node #_(mf/ref-val svg-ref) (dom/get-element "render")
|
||||
svg-node (dom/get-element "render")
|
||||
xml (-> (js/XMLSerializer.)
|
||||
(.serializeToString svg-node)
|
||||
js/encodeURIComponent
|
||||
|
@ -157,21 +157,19 @@
|
|||
#(rx/dispose! sub))))
|
||||
|
||||
(mf/use-effect
|
||||
#_(mf/deps svg-ref)
|
||||
(fn []
|
||||
(let [config #js {:attributes true
|
||||
:childList true
|
||||
:subtree true
|
||||
:characterData true}
|
||||
svg-node #_(mf/ref-val svg-ref) (dom/get-element "render")
|
||||
svg-node (dom/get-element "render")
|
||||
observer (js/MutationObserver. handle-svg-change)
|
||||
]
|
||||
(.observe observer svg-node config)
|
||||
(handle-svg-change)
|
||||
|
||||
;; Disconnect on unmount
|
||||
#(.disconnect observer)
|
||||
)))
|
||||
#(.disconnect observer))))
|
||||
|
||||
[:*
|
||||
[:div.pixel-overlay
|
||||
|
@ -191,17 +189,4 @@
|
|||
:height (:height vport 0)
|
||||
:style {:position "absolute"
|
||||
:width "100%"
|
||||
:height "100%"}}]
|
||||
|
||||
#_[:& (mf/provider muc/embed-ctx) {:value true}
|
||||
[:svg.viewport
|
||||
{:ref svg-ref
|
||||
:preserveAspectRatio "xMidYMid meet"
|
||||
:width (:width vport 0)
|
||||
:height (:height vport 0)
|
||||
:view-box (format-viewbox vbox)
|
||||
:style {:position "absolute"
|
||||
:width "100%"
|
||||
:height "100%"
|
||||
:background-color (get options :background "#E8E9EA")}}
|
||||
[:& overlay-frames]]]]]]))
|
||||
:height "100%"}}]]]]))
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
{"x-frontend-version" (:full @cfg/version)})
|
||||
|
||||
(defn fetch
|
||||
[{:keys [method uri query headers body timeout mode]
|
||||
[{:keys [method uri query headers body timeout mode omit-default-headers]
|
||||
:or {timeout 10000 mode :cors headers {}}}]
|
||||
(rx/Observable.create
|
||||
(fn [subscriber]
|
||||
|
@ -67,9 +67,15 @@
|
|||
uri (cond-> uri
|
||||
(string? uri) (u/uri)
|
||||
(some? query) (assoc :query query))
|
||||
headers (->> (d/merge headers default-headers)
|
||||
(-update-headers body))
|
||||
|
||||
headers (cond-> headers
|
||||
(not omit-default-headers)
|
||||
(d/merge default-headers))
|
||||
|
||||
headers (-update-headers body headers)
|
||||
|
||||
body (-get-body-data body)
|
||||
|
||||
params #js {:method (translate-method method)
|
||||
:headers (clj->js headers)
|
||||
:body body
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
(ns app.test-components-basic
|
||||
(:require [cljs.test :as t :include-macros true]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[clojure.stacktrace :as stk]
|
||||
[beicon.core :as rx]
|
||||
[linked.core :as lks]
|
||||
[app.test-helpers.events :as the]
|
||||
[app.test-helpers.pages :as thp]
|
||||
[app.test-helpers.libraries :as thl]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.data :as d]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]))
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.test-helpers.events :as the]
|
||||
[app.test-helpers.libraries :as thl]
|
||||
[app.test-helpers.pages :as thp]
|
||||
[beicon.core :as rx]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[clojure.stacktrace :as stk]
|
||||
[linked.core :as lks]))
|
||||
|
||||
(t/use-fixtures :each
|
||||
{:before thp/reset-idmap!})
|
||||
|
@ -307,8 +309,8 @@
|
|||
(gpt/point 100 100)))
|
||||
(rx/do
|
||||
(fn [new-state]
|
||||
(let [new-instance-id (-> (get-in new-state
|
||||
[:workspace-local :selected])
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance2 shape2]
|
||||
|
|
Loading…
Add table
Reference in a new issue