mirror of
https://github.com/penpot/penpot.git
synced 2025-06-01 16:11:40 +02:00
♻️ Refactor path editor component: path-preview
This commit is contained in:
parent
3d864c4ff1
commit
93a601a1e7
1 changed files with 30 additions and 17 deletions
|
@ -191,20 +191,33 @@
|
||||||
:style {:fill "none"
|
:style {:fill "none"
|
||||||
:stroke-width 0}}]]))
|
:stroke-width 0}}]]))
|
||||||
|
|
||||||
(mf/defc path-preview [{:keys [zoom command from]}]
|
(mf/defc path-preview*
|
||||||
[:g.preview {:style {:pointer-events "none"}}
|
{::mf/private true}
|
||||||
(when (not= :move-to (:command command))
|
[{:keys [zoom segment from]}]
|
||||||
[:path {:style {:fill "none"
|
|
||||||
:stroke pc/black-color
|
(let [path
|
||||||
:stroke-width (/ handler-stroke-width zoom)
|
(when (not= :move-to (:command segment))
|
||||||
:stroke-dasharray (/ path-preview-dasharray zoom)}
|
(let [segments [{:command :move-to
|
||||||
:d (upf/format-path [{:command :move-to
|
:params from}]
|
||||||
:params {:x (:x from)
|
segments (conj segments segment)]
|
||||||
:y (:y from)}}
|
(path/content segments)))
|
||||||
command])}])
|
|
||||||
[:> path-point* {:position (:params command)
|
position
|
||||||
:is-preview true
|
(mf/with-memo [segment]
|
||||||
:zoom zoom}]])
|
;; FIXME: use a helper from common for this
|
||||||
|
(gpt/point (:params segment)))]
|
||||||
|
|
||||||
|
[:g.preview {:style {:pointer-events "none"}}
|
||||||
|
(when (some? path)
|
||||||
|
[:path {:style {:fill "none"
|
||||||
|
:stroke pc/black-color
|
||||||
|
:stroke-width (/ handler-stroke-width zoom)
|
||||||
|
:stroke-dasharray (/ path-preview-dasharray zoom)}
|
||||||
|
:d (str path)}])
|
||||||
|
|
||||||
|
[:> path-point* {:position position
|
||||||
|
:is-preview true
|
||||||
|
:zoom zoom}]]))
|
||||||
|
|
||||||
(mf/defc path-snap [{:keys [selected points zoom]}]
|
(mf/defc path-snap [{:keys [selected points zoom]}]
|
||||||
(let [ranges (mf/use-memo (mf/deps selected points) #(snap/create-ranges points selected))
|
(let [ranges (mf/use-memo (mf/deps selected points) #(snap/create-ranges points selected))
|
||||||
|
@ -322,9 +335,9 @@
|
||||||
:stroke pc/accent-color
|
:stroke pc/accent-color
|
||||||
:strokeWidth (/ 1 zoom)}}]
|
:strokeWidth (/ 1 zoom)}}]
|
||||||
(when (and preview (not drag-handler))
|
(when (and preview (not drag-handler))
|
||||||
[:& path-preview {:command preview
|
[:> path-preview* {:segment preview
|
||||||
:from last-p
|
:from last-p
|
||||||
:zoom zoom}])
|
:zoom zoom}])
|
||||||
|
|
||||||
(when (and drag-handler last-p)
|
(when (and drag-handler last-p)
|
||||||
[:g.drag-handler {:pointer-events "none"}
|
[:g.drag-handler {:pointer-events "none"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue