0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 00:01:51 -05:00

Merge pull request #1078 from penpot/enhancement/shape-to-path

Double click won't make a shape a path until you change a node
This commit is contained in:
Andrey Antukh 2021-07-08 16:38:27 +02:00 committed by GitHub
commit 3a64efd136
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 111 additions and 86 deletions

View file

@ -14,6 +14,7 @@
- Preserve components if possible, when pasted into a different file [Taiga #1063](https://tree.taiga.io/project/penpot/issue/1063). - Preserve components if possible, when pasted into a different file [Taiga #1063](https://tree.taiga.io/project/penpot/issue/1063).
- Add the ability to offload file data to a cheaper storage when file becomes inactive. - Add the ability to offload file data to a cheaper storage when file becomes inactive.
- Import/Export Penpot files from dashboard. - Import/Export Penpot files from dashboard.
- Double click won't make a shape a path until you change a node [Taiga #]
### :bug: Bugs fixed ### :bug: Bugs fixed

View file

@ -1046,14 +1046,11 @@
:text :text
(rx/of (dwc/start-edition-mode id)) (rx/of (dwc/start-edition-mode id))
:path
(rx/of (dwc/start-edition-mode id)
(dwdp/start-path-edit id))
:group :group
(rx/of (dwc/select-shapes (into (d/ordered-set) [(last shapes)]))) (rx/of (dwc/select-shapes (into (d/ordered-set) [(last shapes)])))
(rx/empty)))))))) (rx/of (dwc/start-edition-mode id)
(dwdp/start-path-edit id)))))))))
;; --- Change Page Order (D&D Ordering) ;; --- Change Page Order (D&D Ordering)
@ -1825,7 +1822,6 @@
(d/export dwt/update-dimensions) (d/export dwt/update-dimensions)
(d/export dwt/flip-horizontal-selected) (d/export dwt/flip-horizontal-selected)
(d/export dwt/flip-vertical-selected) (d/export dwt/flip-vertical-selected)
(d/export dwt/selected-to-path)
;; Persistence ;; Persistence

View file

@ -76,12 +76,13 @@
(ptk/reify ::save-path-content (ptk/reify ::save-path-content
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [content (get-in state (st/get-path state :content)) (let [content (st/get-path state :content)
content (if (and (not preserve-move-to) content (if (and (not preserve-move-to)
(= (-> content last :command) :move-to)) (= (-> content last :command) :move-to))
(into [] (take (dec (count content)) content)) (into [] (take (dec (count content)) content))
content)] content)]
(assoc-in state (st/get-path state :content) content))) (-> state
(st/set-content content))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
@ -89,7 +90,7 @@
page-id (:current-page-id state) page-id (:current-page-id state)
id (get-in state [:workspace-local :edition]) id (get-in state [:workspace-local :edition])
old-content (get-in state [:workspace-local :edit-path id :old-content]) old-content (get-in state [:workspace-local :edit-path id :old-content])
shape (get-in state (st/get-path state))] shape (st/get-path state)]
(if (and (some? old-content) (some? (:id shape))) (if (and (some? old-content) (some? (:id shape)))
(let [[rch uch] (generate-path-changes objects page-id shape old-content (:content shape))] (let [[rch uch] (generate-path-changes objects page-id shape old-content (:content shape))]
(rx/of (dch/commit-changes {:redo-changes rch (rx/of (dch/commit-changes {:redo-changes rch

View file

@ -9,6 +9,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.drawing.common :as dwdc] [app.main.data.workspace.drawing.common :as dwdc]
[app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.changes :as changes]
@ -22,6 +23,7 @@
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.path.commands :as upc] [app.util.path.commands :as upc]
[app.util.path.geom :as upg] [app.util.path.geom :as upg]
[app.util.path.shapes-to-path :as upsp]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -36,7 +38,7 @@
last-point (get-in state [:workspace-local :edit-path id :last-point]) last-point (get-in state [:workspace-local :edit-path id :last-point])
position (cond-> (gpt/point x y) position (cond-> (gpt/point x y)
fix-angle? (helpers/position-fixed-angle last-point)) fix-angle? (helpers/position-fixed-angle last-point))
shape (get-in state (st/get-path state)) shape (st/get-path state)
{:keys [last-point prev-handler]} (get-in state [:workspace-local :edit-path id]) {:keys [last-point prev-handler]} (get-in state [:workspace-local :edit-path id])
command (helpers/next-node shape position last-point prev-handler)] command (helpers/next-node shape position last-point prev-handler)]
(assoc-in state [:workspace-local :edit-path id :preview] command))))) (assoc-in state [:workspace-local :edit-path id :preview] command)))))
@ -55,7 +57,7 @@
(assoc-in [:workspace-local :edit-path id :last-point] position) (assoc-in [:workspace-local :edit-path id :last-point] position)
(update-in [:workspace-local :edit-path id] dissoc :prev-handler) (update-in [:workspace-local :edit-path id] dissoc :prev-handler)
(update-in [:workspace-local :edit-path id] dissoc :preview) (update-in [:workspace-local :edit-path id] dissoc :preview)
(update-in (st/get-path state) helpers/append-node position last-point prev-handler)) (update-in (st/get-path-location state) helpers/append-node position last-point prev-handler))
state))))) state)))))
(defn drag-handler (defn drag-handler
@ -66,7 +68,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
index (or index (count content)) index (or index (count content))
prefix (or prefix :c1) prefix (or prefix :c1)
@ -96,16 +98,16 @@
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
modifiers (get-in state [:workspace-local :edit-path id :content-modifiers]) modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
content (-> (get-in state (st/get-path state :content)) content (-> (st/get-path state :content)
(upc/apply-content-modifiers modifiers)) (upc/apply-content-modifiers modifiers))
handler (get-in state [:workspace-local :edit-path id :drag-handler])] handler (get-in state [:workspace-local :edit-path id :drag-handler])]
(-> state (-> state
(assoc-in (st/get-path state :content) content) (st/set-content content)
(update-in [:workspace-local :edit-path id] dissoc :drag-handler) (update-in [:workspace-local :edit-path id] dissoc :drag-handler)
(update-in [:workspace-local :edit-path id] dissoc :content-modifiers) (update-in [:workspace-local :edit-path id] dissoc :content-modifiers)
(assoc-in [:workspace-local :edit-path id :prev-handler] handler) (assoc-in [:workspace-local :edit-path id :prev-handler] handler)
(update-in (st/get-path state) helpers/update-selrect)))) (update-in (st/get-path-location state) helpers/update-selrect))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
@ -126,7 +128,7 @@
(->> stream (rx/filter #(or (helpers/end-path-event? %) (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %)))) (ms/mouse-up? %))))
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
snap-toggled (get-in state [:workspace-local :edit-path id :snap-toggled]) snap-toggled (get-in state [:workspace-local :edit-path id :snap-toggled])
points (upg/content->points content) points (upg/content->points content)
@ -163,7 +165,7 @@
(watch [_ state stream] (watch [_ state stream]
(let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %) (let [mouse-up (->> stream (rx/filter #(or (helpers/end-path-event? %)
(ms/mouse-up? %)))) (ms/mouse-up? %))))
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
points (upg/content->points content) points (upg/content->points content)
id (st/get-path-id state) id (st/get-path-id state)
@ -218,7 +220,7 @@
mouse-down (->> stream (rx/filter ms/mouse-down?)) mouse-down (->> stream (rx/filter ms/mouse-down?))
end-path-events (->> stream (rx/filter helpers/end-path-event?)) end-path-events (->> stream (rx/filter helpers/end-path-event?))
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
points (upg/content->points content) points (upg/content->points content)
id (st/get-path-id state) id (st/get-path-id state)
@ -316,6 +318,7 @@
edit-mode (get-in state [:workspace-local :edit-path id :edit-mode])] edit-mode (get-in state [:workspace-local :edit-path id :edit-mode])]
(if (= :draw edit-mode) (if (= :draw edit-mode)
(rx/concat (rx/concat
(rx/of (dch/update-shapes [id] upsp/convert-to-path))
(rx/of (handle-drawing-path id)) (rx/of (handle-drawing-path id))
(->> stream (->> stream
(rx/filter (ptk/type? ::common/finish-path)) (rx/filter (ptk/type? ::common/finish-path))
@ -328,7 +331,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
old-content (get-in state [:workspace-local :edit-path id :old-content]) old-content (get-in state [:workspace-local :edit-path id :old-content])
mode (get-in state [:workspace-local :edit-path id :edit-mode])] mode (get-in state [:workspace-local :edit-path id :edit-mode])]

View file

@ -21,6 +21,7 @@
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.path.commands :as upc] [app.util.path.commands :as upc]
[app.util.path.geom :as upg] [app.util.path.geom :as upg]
[app.util.path.shapes-to-path :as upsp]
[app.util.path.subpaths :as ups] [app.util.path.subpaths :as ups]
[app.util.path.tools :as upt] [app.util.path.tools :as upt]
[beicon.core :as rx] [beicon.core :as rx]
@ -31,8 +32,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [content (get-in state (st/get-path state :content)) (let [content (st/get-path state :content)
modifiers (helpers/move-handler-modifiers content index prefix false match-opposite? dx dy) modifiers (helpers/move-handler-modifiers content index prefix false match-opposite? dx dy)
[cx cy] (if (= prefix :c1) [:c1x :c1y] [:c2x :c2y]) [cx cy] (if (= prefix :c1) [:c1x :c1y] [:c2x :c2y])
point (gpt/point (+ (get-in content [index :params cx]) dx) point (gpt/point (+ (get-in content [index :params cx]) dx)
@ -50,7 +50,7 @@
id (st/get-path-id state) id (st/get-path-id state)
page-id (:current-page-id state) page-id (:current-page-id state)
shape (get-in state (st/get-path state)) shape (st/get-path state)
content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers]) content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers])
content (:content shape) content (:content shape)
@ -100,7 +100,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
modifiers-reducer (partial modify-content-point content move-modifier) modifiers-reducer (partial modify-content-point content move-modifier)
content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers] {}) content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers] {})
content-modifiers (->> points content-modifiers (->> points
@ -114,7 +114,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
delta (gpt/subtract to-point from-point) delta (gpt/subtract to-point from-point)
modifiers-reducer (partial modify-content-point content delta) modifiers-reducer (partial modify-content-point content delta)
@ -141,6 +141,7 @@
selected? (contains? selected-points position)] selected? (contains? selected-points position)]
(streams/drag-stream (streams/drag-stream
(rx/of (rx/of
(dch/update-shapes [id] upsp/convert-to-path)
(when-not selected? (selection/select-node position shift?)) (when-not selected? (selection/select-node position shift?))
(drag-selected-points @ms/mouse-position)) (drag-selected-points @ms/mouse-position))
(rx/of (selection/select-node position shift?))))))) (rx/of (selection/select-node position shift?)))))))
@ -156,7 +157,7 @@
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
points (upg/content->points content)] points (upg/content->points content)]
(rx/concat (rx/concat
@ -221,6 +222,7 @@
mov-vec (gpt/multiply (get-displacement direction) scale)] mov-vec (gpt/multiply (get-displacement direction) scale)]
(rx/concat (rx/concat
(rx/of (dch/update-shapes [id] upsp/convert-to-path))
(rx/merge (rx/merge
(->> move-events (->> move-events
(rx/take-until stopper) (rx/take-until stopper)
@ -247,7 +249,7 @@
start-delta-x (get-in modifiers [index cx] 0) start-delta-x (get-in modifiers [index cx] 0)
start-delta-y (get-in modifiers [index cy] 0) start-delta-y (get-in modifiers [index cy] 0)
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
points (upg/content->points content) points (upg/content->points content)
point (-> content (get (if (= prefix :c1) (dec index) index)) (upc/command->point)) point (-> content (get (if (= prefix :c1) (dec index) index)) (upc/command->point))
@ -260,6 +262,7 @@
(streams/drag-stream (streams/drag-stream
(rx/concat (rx/concat
(rx/of (dch/update-shapes [id] upsp/convert-to-path))
(->> (streams/move-handler-stream snap-toggled start-point point handler opposite points) (->> (streams/move-handler-stream snap-toggled start-point point handler opposite points)
(rx/take-until (->> stream (rx/filter #(or (ms/mouse-up? %) (rx/take-until (->> stream (rx/filter #(or (ms/mouse-up? %)
(streams/finish-edition? %))))) (streams/finish-edition? %)))))
@ -284,7 +287,8 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [edit-path (get-in state [:workspace-local :edit-path id]) (let [edit-path (get-in state [:workspace-local :edit-path id])
state (update-in state (st/get-path state :content) ups/close-subpaths)] content (st/get-path state :content)
state (st/set-content state (ups/close-subpaths content))]
(cond-> state (cond-> state
(or (not edit-path) (= :draw (:edit-mode edit-path))) (or (not edit-path) (= :draw (:edit-mode edit-path)))
(assoc-in [:workspace-local :edit-path id] {:edit-mode :move (assoc-in [:workspace-local :edit-path id] {:edit-mode :move
@ -313,17 +317,26 @@
(let [id (get-in state [:workspace-local :edition])] (let [id (get-in state [:workspace-local :edition])]
(update state :workspace-local dissoc :edit-path id))))) (update state :workspace-local dissoc :edit-path id)))))
(defn create-node-at-position (defn split-segments
[{:keys [from-p to-p t]}] [{:keys [from-p to-p t]}]
(ptk/reify ::create-node-at-position (ptk/reify ::split-segments
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
old-content (get-in state (st/get-path state :content))] content (st/get-path state :content)]
(-> state (-> state
(assoc-in [:workspace-local :edit-path id :old-content] old-content) (assoc-in [:workspace-local :edit-path id :old-content] content)
(update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t)))) (st/set-content (-> content (upt/split-segments #{from-p to-p} t))))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (changes/save-path-content {:preserve-move-to true}))))) (rx/of (changes/save-path-content {:preserve-move-to true})))))
(defn create-node-at-position
[event]
(ptk/reify ::create-node-at-position
ptk/WatchEvent
(watch [_ state _]
(let [id (st/get-path-id state)]
(rx/of (dch/update-shapes [id] upsp/convert-to-path)
(split-segments event))))))

View file

@ -48,7 +48,7 @@
(update [_ state] (update [_ state]
(let [selrect (get-in state [:workspace-local :selrect]) (let [selrect (get-in state [:workspace-local :selrect])
id (get-in state [:workspace-local :edition]) id (get-in state [:workspace-local :edition])
content (get-in state (st/get-path state :content)) content (st/get-path state :content)
selected-point? #(gsh/has-point-rect? selrect %) selected-point? #(gsh/has-point-rect? selrect %)
selected-points (get-in state [:workspace-local :edit-path id :selected-points]) selected-points (get-in state [:workspace-local :edit-path id :selected-points])
positions (into (if shift? selected-points #{}) positions (into (if shift? selected-points #{})

View file

@ -6,7 +6,8 @@
(ns app.main.data.workspace.path.state (ns app.main.data.workspace.path.state
(:require (:require
[app.common.data :as d])) [app.common.data :as d]
[app.util.path.shapes-to-path :as upsp]))
(defn get-path-id (defn get-path-id
"Retrieves the currently editing path id" "Retrieves the currently editing path id"
@ -14,16 +15,30 @@
(or (get-in state [:workspace-local :edition]) (or (get-in state [:workspace-local :edition])
(get-in state [:workspace-drawing :object :id]))) (get-in state [:workspace-drawing :object :id])))
(defn get-path (defn get-path-location
"Retrieves the location of the path object and additionaly can pass [state & ks]
the arguments. This location can be used in get-in, assoc-in... functions"
[state & path]
(let [edit-id (get-in state [:workspace-local :edition]) (let [edit-id (get-in state [:workspace-local :edition])
page-id (:current-page-id state)] page-id (:current-page-id state)]
(d/concat (d/concat
(if edit-id (if edit-id
[:workspace-data :pages-index page-id :objects edit-id] [:workspace-data :pages-index page-id :objects edit-id]
[:workspace-drawing :object]) [:workspace-drawing :object])
path))) ks)))
(defn get-path
"Retrieves the location of the path object and additionaly can pass
the arguments. This location can be used in get-in, assoc-in... functions"
[state & ks]
(let [path-loc (get-path-location state)
shape (-> (get-in state path-loc)
(upsp/convert-to-path))]
(if (empty? ks)
shape
(get-in shape ks))))
(defn set-content
[state content]
(let [path-loc (get-path-location state :content)]
(-> state
(assoc-in path-loc content))))

View file

@ -123,9 +123,8 @@
(defn position-stream (defn position-stream
[snap-toggled _points] [snap-toggled _points]
(let [zoom (get-in @st/state [:workspace-local :zoom] 1) (let [zoom (get-in @st/state [:workspace-local :zoom] 1)
;; ranges (snap/create-ranges points)
d-pos (/ snap/snap-path-accuracy zoom) d-pos (/ snap/snap-path-accuracy zoom)
get-content (fn [state] (get-in state (state/get-path state :content))) get-content #(state/get-path % :content)
content-stream content-stream
(-> (l/derived get-content st/state) (-> (l/derived get-content st/state)

View file

@ -11,6 +11,7 @@
[app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.changes :as changes]
[app.main.data.workspace.path.state :as st] [app.main.data.workspace.path.state :as st]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.util.path.shapes-to-path :as upsp]
[app.util.path.subpaths :as ups] [app.util.path.subpaths :as ups]
[app.util.path.tools :as upt] [app.util.path.tools :as upt]
[beicon.core :as rx] [beicon.core :as rx]
@ -27,19 +28,21 @@
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
id (st/get-path-id state) id (st/get-path-id state)
page-id (:current-page-id state) page-id (:current-page-id state)
shape (get-in state (st/get-path state)) shape (st/get-path state)
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
points (or points selected-points)] points (or points selected-points)]
(when (and (seq points) (some? shape)) (when (and (seq points) (some? shape))
(let [new-content (-> (tool-fn (:content shape) points) (let [new-content (-> (tool-fn (:content shape) points)
(ups/close-subpaths)) (ups/close-subpaths))
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]
(rx/concat
(rx/of (dch/update-shapes [id] upsp/convert-to-path))
(rx/of (dch/commit-changes {:redo-changes rch (rx/of (dch/commit-changes {:redo-changes rch
:undo-changes uch :undo-changes uch
:origin it}) :origin it})
(when (empty? new-content) (when (empty? new-content)
dwc/clear-edition-mode))))))))) dwc/clear-edition-mode))))))))))
(defn make-corner (defn make-corner
([] ([]

View file

@ -25,21 +25,22 @@
(= :app.main.data.workspace.common/redo (ptk/type event))) (= :app.main.data.workspace.common/redo (ptk/type event)))
(defn- make-entry [state] (defn- make-entry [state]
(let [id (st/get-path-id state)] (let [id (st/get-path-id state)
{:content (get-in state (st/get-path state :content)) shape (st/get-path state)]
:selrect (get-in state (st/get-path state :selrect)) {:content (:content shape)
:points (get-in state (st/get-path state :points)) :selrect (:selrect shape)
:points (:points shape)
:preview (get-in state [:workspace-local :edit-path id :preview]) :preview (get-in state [:workspace-local :edit-path id :preview])
:last-point (get-in state [:workspace-local :edit-path id :last-point]) :last-point (get-in state [:workspace-local :edit-path id :last-point])
:prev-handler (get-in state [:workspace-local :edit-path id :prev-handler])})) :prev-handler (get-in state [:workspace-local :edit-path id :prev-handler])}))
(defn- load-entry [state {:keys [content selrect points preview last-point prev-handler]}] (defn- load-entry [state {:keys [content selrect points preview last-point prev-handler]}]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)
old-content (get-in state (st/get-path state :content))] old-content (st/get-path state :content)]
(-> state (-> state
(d/assoc-in-when (st/get-path state :content) content) (d/assoc-in-when (st/get-path-location state :content) content)
(d/assoc-in-when (st/get-path state :selrect) selrect) (d/assoc-in-when (st/get-path-location state :selrect) selrect)
(d/assoc-in-when (st/get-path state :points) points) (d/assoc-in-when (st/get-path-location state :points) points)
(d/update-in-when (d/update-in-when
[:workspace-local :edit-path id] [:workspace-local :edit-path id]
assoc assoc
@ -128,7 +129,7 @@
(def path-content-ref (def path-content-ref
(letfn [(selector [state] (letfn [(selector [state]
(get-in state (st/get-path state :content)))] (st/get-path state :content))]
(l/derived selector store/state))) (l/derived selector store/state)))
(defn start-path-undo (defn start-path-undo

View file

@ -20,7 +20,6 @@
[app.main.data.workspace.undo :as dwu] [app.main.data.workspace.undo :as dwu]
[app.main.snap :as snap] [app.main.snap :as snap]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.util.path.shapes-to-path :as ups]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -666,10 +665,3 @@
(dissoc :workspace-modifiers) (dissoc :workspace-modifiers)
(update :workspace-local dissoc :modifiers :current-move-selected))))) (update :workspace-local dissoc :modifiers :current-move-selected)))))
(defn selected-to-path
[]
(ptk/reify ::selected-to-path
ptk/WatchEvent
(watch [_ state _]
(let [ids (wsh/lookup-selected state {:omit-blocked? true})]
(rx/of (dch/update-shapes ids ups/convert-to-path))))))

View file

@ -21,6 +21,7 @@
[app.util.path.commands :as upc] [app.util.path.commands :as upc]
[app.util.path.format :as upf] [app.util.path.format :as upf]
[app.util.path.geom :as upg] [app.util.path.geom :as upg]
[app.util.path.shapes-to-path :as ups]
[clojure.set :refer [map-invert]] [clojure.set :refer [map-invert]]
[goog.events :as events] [goog.events :as events]
[rumext.alpha :as mf]) [rumext.alpha :as mf])
@ -214,6 +215,13 @@
selected-points (or selected-points #{}) selected-points (or selected-points #{})
shape (cond-> shape
(not= :path (:type shape))
ups/convert-to-path
:always
hooks/use-equal-memo)
base-content (:content shape) base-content (:content shape)
base-points (mf/use-memo (mf/deps base-content) #(->> base-content upg/content->points)) base-points (mf/use-memo (mf/deps base-content) #(->> base-content upg/content->points))

View file

@ -104,7 +104,7 @@
create-comment? (= :comments drawing-tool) create-comment? (= :comments drawing-tool)
drawing-path? (or (and edition (= :draw (get-in edit-path [edition :edit-mode]))) drawing-path? (or (and edition (= :draw (get-in edit-path [edition :edit-mode])))
(and (some? drawing-obj) (= :path (:type drawing-obj)))) (and (some? drawing-obj) (= :path (:type drawing-obj))))
path-editing? (and edition (= :path (get-in objects [edition :type]))) node-editing? (and edition (not= :text (get-in objects [edition :type])))
text-editing? (and edition (= :text (get-in objects [edition :type]))) text-editing? (and edition (= :text (get-in objects [edition :type])))
on-click (actions/on-click hover selected edition drawing-path? drawing-tool) on-click (actions/on-click hover selected edition drawing-path? drawing-tool)
@ -113,7 +113,7 @@
on-drag-enter (actions/on-drag-enter) on-drag-enter (actions/on-drag-enter)
on-drag-over (actions/on-drag-over) on-drag-over (actions/on-drag-over)
on-drop (actions/on-drop file viewport-ref zoom) on-drop (actions/on-drop file viewport-ref zoom)
on-mouse-down (actions/on-mouse-down @hover selected edition drawing-tool text-editing? path-editing? drawing-path? create-comment?) on-mouse-down (actions/on-mouse-down @hover selected edition drawing-tool text-editing? node-editing? drawing-path? create-comment?)
on-mouse-up (actions/on-mouse-up disable-paste) on-mouse-up (actions/on-mouse-up disable-paste)
on-pointer-down (actions/on-pointer-down) on-pointer-down (actions/on-pointer-down)
on-pointer-enter (actions/on-pointer-enter in-viewport?) on-pointer-enter (actions/on-pointer-enter in-viewport?)
@ -144,16 +144,16 @@
(contains? layout :snap-grid)) (contains? layout :snap-grid))
(or drawing-obj transform)) (or drawing-obj transform))
show-selrect? (and selrect (empty? drawing)) show-selrect? (and selrect (empty? drawing))
show-measures? (and (not transform) (not path-editing?) show-distances?)] show-measures? (and (not transform) (not node-editing?) show-distances?)]
(hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?) (hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?)
(hooks/setup-viewport-size viewport-ref) (hooks/setup-viewport-size viewport-ref)
(hooks/setup-cursor cursor alt? panning drawing-tool drawing-path? path-editing?) (hooks/setup-cursor cursor alt? panning drawing-tool drawing-path? node-editing?)
(hooks/setup-resize layout viewport-ref) (hooks/setup-resize layout viewport-ref)
(hooks/setup-keyboard alt? ctrl?) (hooks/setup-keyboard alt? ctrl?)
(hooks/setup-hover-shapes page-id move-stream selected objects transform selected ctrl? hover hover-ids zoom) (hooks/setup-hover-shapes page-id move-stream selected objects transform selected ctrl? hover hover-ids zoom)
(hooks/setup-viewport-modifiers modifiers selected objects render-ref) (hooks/setup-viewport-modifiers modifiers selected objects render-ref)
(hooks/setup-shortcuts path-editing? drawing-path?) (hooks/setup-shortcuts node-editing? drawing-path?)
(hooks/setup-active-frames objects vbox hover active-frames) (hooks/setup-active-frames objects vbox hover active-frames)
[:div.viewport [:div.viewport

View file

@ -27,9 +27,9 @@
(:import goog.events.WheelEvent)) (:import goog.events.WheelEvent))
(defn on-mouse-down (defn on-mouse-down
[{:keys [id blocked hidden type]} selected edition drawing-tool text-editing? path-editing? drawing-path? create-comment?] [{:keys [id blocked hidden type]} selected edition drawing-tool text-editing? node-editing? drawing-path? create-comment?]
(mf/use-callback (mf/use-callback
(mf/deps id blocked hidden type selected edition drawing-tool text-editing? path-editing? drawing-path? create-comment?) (mf/deps id blocked hidden type selected edition drawing-tool text-editing? node-editing? drawing-path? create-comment?)
(fn [bevent] (fn [bevent]
(when (or (dom/class? (dom/get-target bevent) "viewport-controls") (when (or (dom/class? (dom/get-target bevent) "viewport-controls")
(dom/class? (dom/get-target bevent) "viewport-selrect")) (dom/class? (dom/get-target bevent) "viewport-selrect"))
@ -65,7 +65,7 @@
drawing-tool drawing-tool
(st/emit! (dd/start-drawing drawing-tool)) (st/emit! (dd/start-drawing drawing-tool))
path-editing? node-editing?
;; Handle path node area selection ;; Handle path node area selection
(st/emit! (dwdp/handle-selection shift?)) (st/emit! (dwdp/handle-selection shift?))
@ -158,9 +158,7 @@
{:keys [id type] :as shape} @hover {:keys [id type] :as shape} @hover
frame? (= :frame type) frame? (= :frame type)
group? (= :group type) group? (= :group type)]
text? (= :text type)
path? (= :path type)]
(st/emit! (ms/->MouseEvent :double-click ctrl? shift? alt?)) (st/emit! (ms/->MouseEvent :double-click ctrl? shift? alt?))
@ -174,12 +172,8 @@
(reset! hover-ids (into [] (rest @hover-ids))) (reset! hover-ids (into [] (rest @hover-ids)))
(st/emit! (dw/select-shape (:id selected)))) (st/emit! (dw/select-shape (:id selected))))
(and (not= id edition) (or text? path?)) (not= id edition)
(st/emit! (dw/select-shape id) (st/emit! (dw/select-shape id)
(dw/start-editing-selected))
:else
(st/emit! (dw/selected-to-path)
(dw/start-editing-selected)))))))) (dw/start-editing-selected))))))))
(defn on-context-menu (defn on-context-menu

View file

@ -364,8 +364,7 @@
:zoom zoom :zoom zoom
:color color}] :color color}]
(and (= type :path) (= edition (:id shape))
(= edition (:id shape)))
[:& path-editor {:zoom zoom [:& path-editor {:zoom zoom
:shape shape}] :shape shape}]

View file

@ -47,7 +47,7 @@
shape (-> selected first)] shape (-> selected first)]
(when (and (= (count selected) 1) (when (and (= (count selected) 1)
(= (:id shape) edition) (= (:id shape) edition)
(= :path (:type shape))) (not= :text (:type shape)))
[:div.viewport-actions [:div.viewport-actions
[:& path-actions {:shape shape}]]))) [:& path-actions {:shape shape}]])))