♻️ Refactor path editor component: path-preview

This commit is contained in:
Andrey Antukh 2025-04-04 10:39:46 +02:00
parent 3d864c4ff1
commit 93a601a1e7

View file

@ -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"}