mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
✨ Additional changes to path editing
This commit is contained in:
parent
c7683dfd80
commit
961a7a2e03
9 changed files with 66 additions and 37 deletions
|
@ -38,7 +38,7 @@
|
||||||
([v]
|
([v]
|
||||||
(cond
|
(cond
|
||||||
(point? v)
|
(point? v)
|
||||||
v
|
(Point. (:x v) (:y v))
|
||||||
|
|
||||||
(number? v)
|
(number? v)
|
||||||
(point v v)
|
(point v v)
|
||||||
|
|
|
@ -364,7 +364,7 @@
|
||||||
(let [edition (get-in state [:workspace-local :edition])
|
(let [edition (get-in state [:workspace-local :edition])
|
||||||
drawing (get state :workspace-drawing)]
|
drawing (get state :workspace-drawing)]
|
||||||
;; Editors handle their own undo's
|
;; Editors handle their own undo's
|
||||||
(when-not (or (some? edition) (some? drawing))
|
(when-not (or (some? edition) (not-empty drawing))
|
||||||
(let [undo (:workspace-undo state)
|
(let [undo (:workspace-undo state)
|
||||||
items (:items undo)
|
items (:items undo)
|
||||||
index (or (:index undo) (dec (count items)))]
|
index (or (:index undo) (dec (count items)))]
|
||||||
|
@ -379,7 +379,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [edition (get-in state [:workspace-local :edition])
|
(let [edition (get-in state [:workspace-local :edition])
|
||||||
drawing (get state :workspace-drawing)]
|
drawing (get state :workspace-drawing)]
|
||||||
(when-not (or (some? edition) (some? drawing))
|
(when-not (or (some? edition) (not-empty drawing))
|
||||||
(let [undo (:workspace-undo state)
|
(let [undo (:workspace-undo state)
|
||||||
items (:items undo)
|
items (:items undo)
|
||||||
index (or (:index undo) (dec (count items)))]
|
index (or (:index undo) (dec (count items)))]
|
||||||
|
|
|
@ -44,25 +44,30 @@
|
||||||
:shapes [shape-id]}]]
|
:shapes [shape-id]}]]
|
||||||
[rch uch]))
|
[rch uch]))
|
||||||
|
|
||||||
(defn save-path-content []
|
(defn save-path-content
|
||||||
(ptk/reify ::save-path-content
|
([]
|
||||||
ptk/UpdateEvent
|
(save-path-content {}))
|
||||||
(update [_ state]
|
|
||||||
(let [content (get-in state (st/get-path state :content))
|
|
||||||
content (if (= (-> content last :command) :move-to)
|
|
||||||
(into [] (take (dec (count content)) content))
|
|
||||||
content)]
|
|
||||||
(assoc-in state (st/get-path state :content) content)))
|
|
||||||
|
|
||||||
ptk/WatchEvent
|
([{:keys [preserve-move-to] :or {preserve-move-to false}}]
|
||||||
(watch [_ state stream]
|
(ptk/reify ::save-path-content
|
||||||
(let [id (get-in state [:workspace-local :edition])
|
ptk/UpdateEvent
|
||||||
old-content (get-in state [:workspace-local :edit-path id :old-content])]
|
(update [_ state]
|
||||||
(if (some? old-content)
|
(let [content (get-in state (st/get-path state :content))
|
||||||
(let [shape (get-in state (st/get-path state))
|
content (if (and (not preserve-move-to)
|
||||||
page-id (:current-page-id state)
|
(= (-> content last :command) :move-to))
|
||||||
[rch uch] (generate-path-changes page-id shape old-content (:content shape))]
|
(into [] (take (dec (count content)) content))
|
||||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true})))
|
content)]
|
||||||
(rx/empty))))))
|
(assoc-in state (st/get-path state :content) content)))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [id (get-in state [:workspace-local :edition])
|
||||||
|
old-content (get-in state [:workspace-local :edit-path id :old-content])]
|
||||||
|
(if (some? old-content)
|
||||||
|
(let [shape (get-in state (st/get-path state))
|
||||||
|
page-id (:current-page-id state)
|
||||||
|
[rch uch] (generate-path-changes page-id shape old-content (:content shape))]
|
||||||
|
(rx/of (dwc/commit-changes rch uch {:commit-local? true})))
|
||||||
|
(rx/empty)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,9 @@
|
||||||
handlers (-> (upc/content->handlers content)
|
handlers (-> (upc/content->handlers content)
|
||||||
(get position))
|
(get position))
|
||||||
|
|
||||||
[idx prefix] (when (= (count handlers) 1) (first handlers))
|
[idx prefix] (when (= (count handlers) 1)
|
||||||
|
(first handlers))
|
||||||
|
|
||||||
drag-events-stream
|
drag-events-stream
|
||||||
(->> (streams/position-stream snap-toggled points)
|
(->> (streams/position-stream snap-toggled points)
|
||||||
(rx/take-until stop-stream)
|
(rx/take-until stop-stream)
|
||||||
|
|
|
@ -224,9 +224,12 @@
|
||||||
(ptk/reify ::create-node-at-position
|
(ptk/reify ::create-node-at-position
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [id (st/get-path-id state)]
|
(let [id (st/get-path-id state)
|
||||||
(update-in state (st/get-path state :content) upt/split-segments #{from-p to-p} t)))
|
old-content (get-in state (st/get-path state :content))]
|
||||||
|
(-> state
|
||||||
|
(assoc-in [:workspace-local :edit-path id :old-content] old-content)
|
||||||
|
(update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t))))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(rx/of (changes/save-path-content)))))
|
(rx/of (changes/save-path-content {:preserve-move-to true})))))
|
||||||
|
|
|
@ -87,7 +87,8 @@
|
||||||
(defn next-node
|
(defn next-node
|
||||||
"Calculates the next-node to be inserted."
|
"Calculates the next-node to be inserted."
|
||||||
[shape position prev-point prev-handler]
|
[shape position prev-point prev-handler]
|
||||||
(let [last-command (-> shape :content last :command)
|
(let [position (select-keys position [:x :y])
|
||||||
|
last-command (-> shape :content last :command)
|
||||||
add-line? (and prev-point (not prev-handler) (not= last-command :close-path))
|
add-line? (and prev-point (not prev-handler) (not= last-command :close-path))
|
||||||
add-curve? (and prev-point prev-handler (not= last-command :close-path))]
|
add-curve? (and prev-point prev-handler (not= last-command :close-path))]
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
id (get-in state [:workspace-local :edition])
|
id (get-in state [:workspace-local :edition])
|
||||||
content (get-in state (st/get-path state :content))
|
content (get-in state (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 #{})
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
[app.common.data.undo-stack :as u]
|
[app.common.data.undo-stack :as u]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.path.state :as st]
|
[app.main.data.workspace.path.state :as st]
|
||||||
|
[app.main.data.workspace.path.changes :as changes]
|
||||||
[app.main.store :as store]
|
[app.main.store :as store]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
|
@ -26,20 +27,26 @@
|
||||||
(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))
|
{:content (get-in state (st/get-path state :content))
|
||||||
|
:selrect (get-in state (st/get-path state :selrect))
|
||||||
|
:points (get-in state (st/get-path state :points))
|
||||||
: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 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))]
|
||||||
(-> state
|
(-> state
|
||||||
(d/assoc-in-when (st/get-path state :content) content)
|
(d/assoc-in-when (st/get-path state :content) content)
|
||||||
|
(d/assoc-in-when (st/get-path state :selrect) selrect)
|
||||||
|
(d/assoc-in-when (st/get-path state :points) points)
|
||||||
(d/update-in-when
|
(d/update-in-when
|
||||||
[:workspace-local :edit-path id]
|
[:workspace-local :edit-path id]
|
||||||
assoc
|
assoc
|
||||||
:preview preview
|
:preview preview
|
||||||
:last-point last-point
|
:last-point last-point
|
||||||
:prev-handler prev-handler))))
|
:prev-handler prev-handler
|
||||||
|
:old-content old-content))))
|
||||||
|
|
||||||
(defn undo []
|
(defn undo []
|
||||||
(ptk/reify ::undo
|
(ptk/reify ::undo
|
||||||
|
@ -54,7 +61,11 @@
|
||||||
(-> (load-entry entry)
|
(-> (load-entry entry)
|
||||||
(d/assoc-in-when
|
(d/assoc-in-when
|
||||||
[:workspace-local :edit-path id :undo-stack]
|
[:workspace-local :edit-path id :undo-stack]
|
||||||
undo-stack)))))))
|
undo-stack)))))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(rx/of (changes/save-path-content)))))
|
||||||
|
|
||||||
(defn redo []
|
(defn redo []
|
||||||
(ptk/reify ::redo
|
(ptk/reify ::redo
|
||||||
|
@ -68,7 +79,11 @@
|
||||||
(load-entry entry)
|
(load-entry entry)
|
||||||
(d/assoc-in-when
|
(d/assoc-in-when
|
||||||
[:workspace-local :edit-path id :undo-stack]
|
[:workspace-local :edit-path id :undo-stack]
|
||||||
undo-stack))))))
|
undo-stack))))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(rx/of (changes/save-path-content)))))
|
||||||
|
|
||||||
(defn add-undo-entry []
|
(defn add-undo-entry []
|
||||||
(ptk/reify ::add-undo-entry
|
(ptk/reify ::add-undo-entry
|
||||||
|
|
|
@ -165,9 +165,14 @@
|
||||||
(point->handlers )
|
(point->handlers )
|
||||||
(filter (fn [[ci cp]] (and (not= index ci) (not= prefix cp)) )))]
|
(filter (fn [[ci cp]] (and (not= index ci) (not= prefix cp)) )))]
|
||||||
|
|
||||||
(when (= (count handlers) 1)
|
(cond
|
||||||
(->> handlers
|
(= (count handlers) 1)
|
||||||
first))))
|
(->> handlers first)
|
||||||
|
|
||||||
|
(and (= :c1 prefix) (= (count content) index))
|
||||||
|
[(dec index) :c2]
|
||||||
|
|
||||||
|
:else nil)))
|
||||||
|
|
||||||
|
|
||||||
(defn get-commands
|
(defn get-commands
|
||||||
|
|
Loading…
Add table
Reference in a new issue