mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 10:38:13 -05:00
✨ Path split segments
This commit is contained in:
parent
e81b1b8115
commit
5361e42976
3 changed files with 41 additions and 23 deletions
|
@ -42,19 +42,22 @@
|
|||
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true}))))))
|
||||
|
||||
(defn split-segments [[start end cmd]]
|
||||
(case (:command cmd)
|
||||
:line-to [cmd (ugp/split-line-to start cmd 0.5)]
|
||||
:curve-to [cmd (ugp/split-curve-to start cmd 0.5)]
|
||||
:close-path [cmd [(ugp/make-line-to (gpt/line-val start end 0.5))
|
||||
cmd]]
|
||||
nil))
|
||||
|
||||
(defn add-node []
|
||||
(ptk/reify ::add-node
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [id (st/get-path-id state)
|
||||
page-id (:current-page-id state)
|
||||
shape (get-in state (st/get-path state))
|
||||
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
|
||||
new-content (ugp/split-segments (:content shape) selected-points 0.5)
|
||||
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true}))))))
|
||||
|
||||
(defn remove-node []
|
||||
(ptk/reify ::remove-node
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [id (st/get-path-id state)
|
||||
page-id (:current-page-id state)
|
||||
shape (get-in state (st/get-path state))
|
||||
|
@ -62,23 +65,16 @@
|
|||
content (:content shape)
|
||||
|
||||
|
||||
cmd-changes (->> (ugp/get-segments content selected-points)
|
||||
(into {}
|
||||
(comp (map split-segments)
|
||||
(filter (comp not nil?)))))
|
||||
|
||||
process-segments (fn [command]
|
||||
(if (contains? cmd-changes command)
|
||||
(get cmd-changes command)
|
||||
[command]))
|
||||
|
||||
new-content (into [] (mapcat process-segments) content)
|
||||
|
||||
new-content (->> content
|
||||
(filterv #(not (contains? selected-points (ugp/command->point %)))))
|
||||
|
||||
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true}))))))
|
||||
(rx/of (dwc/commit-changes rch uch {:commit-local? true}))))
|
||||
|
||||
(defn remove-node []
|
||||
(ptk/reify ::remove-node))
|
||||
))
|
||||
|
||||
(defn merge-nodes []
|
||||
(ptk/reify ::merge-nodes))
|
||||
|
|
|
@ -59,10 +59,10 @@
|
|||
(when (and (not= edition id) text-editing?)
|
||||
(st/emit! dw/clear-edition-mode))
|
||||
|
||||
(when (and (or (not edition) (not= edition id)) (not blocked) (not hidden) (not (#{:comments :path} drawing-tool)))
|
||||
(not= edition id))
|
||||
(when (and (or (not edition) (not= edition id))
|
||||
(not blocked)
|
||||
(not hidden)
|
||||
(not (#{:comments :path} drawing-tool))
|
||||
(not drawing-path?))
|
||||
(cond
|
||||
drawing-tool
|
||||
|
|
|
@ -675,3 +675,25 @@
|
|||
(rest content))
|
||||
|
||||
segments)))))
|
||||
|
||||
(defn split-segments [content points value]
|
||||
(let [split-command
|
||||
(fn [[start end cmd]]
|
||||
(case (:command cmd)
|
||||
:line-to [cmd (split-line-to start cmd value)]
|
||||
:curve-to [cmd (split-curve-to start cmd value)]
|
||||
:close-path [cmd [(make-line-to (gpt/line-val start end value)) cmd]]
|
||||
nil))
|
||||
|
||||
cmd-changes
|
||||
(->> (get-segments content points)
|
||||
(into {} (comp (map split-command)
|
||||
(filter (comp not nil?)))))
|
||||
|
||||
process-segments
|
||||
(fn [command]
|
||||
(if (contains? cmd-changes command)
|
||||
(get cmd-changes command)
|
||||
[command]))]
|
||||
|
||||
(into [] (mapcat process-segments) content)))
|
||||
|
|
Loading…
Add table
Reference in a new issue