mirror of
https://github.com/penpot/penpot.git
synced 2025-07-16 19:25:17 +02: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)]
|
[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 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 []
|
(defn add-node []
|
||||||
(ptk/reify ::add-node
|
(ptk/reify ::add-node
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(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)
|
(let [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 (get-in state (st/get-path state))
|
||||||
|
@ -62,23 +65,16 @@
|
||||||
content (:content shape)
|
content (:content shape)
|
||||||
|
|
||||||
|
|
||||||
cmd-changes (->> (ugp/get-segments content selected-points)
|
|
||||||
(into {}
|
|
||||||
(comp (map split-segments)
|
|
||||||
(filter (comp not nil?)))))
|
|
||||||
|
|
||||||
process-segments (fn [command]
|
new-content (->> content
|
||||||
(if (contains? cmd-changes command)
|
(filterv #(not (contains? selected-points (ugp/command->point %)))))
|
||||||
(get cmd-changes command)
|
|
||||||
[command]))
|
|
||||||
|
|
||||||
new-content (into [] (mapcat process-segments) content)
|
|
||||||
|
|
||||||
[rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)]
|
[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 []
|
(defn merge-nodes []
|
||||||
(ptk/reify ::merge-nodes))
|
(ptk/reify ::merge-nodes))
|
||||||
|
|
|
@ -59,10 +59,10 @@
|
||||||
(when (and (not= edition id) text-editing?)
|
(when (and (not= edition id) text-editing?)
|
||||||
(st/emit! dw/clear-edition-mode))
|
(st/emit! dw/clear-edition-mode))
|
||||||
|
|
||||||
(when (and (or (not edition) (not= edition id)) (not blocked) (not hidden) (not (#{:comments :path} drawing-tool)))
|
(when (and (or (not edition) (not= edition id))
|
||||||
(not= edition id))
|
|
||||||
(not blocked)
|
(not blocked)
|
||||||
(not hidden)
|
(not hidden)
|
||||||
|
(not (#{:comments :path} drawing-tool))
|
||||||
(not drawing-path?))
|
(not drawing-path?))
|
||||||
(cond
|
(cond
|
||||||
drawing-tool
|
drawing-tool
|
||||||
|
|
|
@ -675,3 +675,25 @@
|
||||||
(rest content))
|
(rest content))
|
||||||
|
|
||||||
segments)))))
|
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
Add a link
Reference in a new issue