mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 12:26:42 +02:00
✨ Adds path new-point edition
This commit is contained in:
parent
f7712f2b40
commit
e2cf3a5a98
6 changed files with 74 additions and 44 deletions
|
@ -22,6 +22,7 @@
|
|||
(d/export edition/start-move-handler)
|
||||
(d/export edition/start-move-path-point)
|
||||
(d/export edition/start-path-edit)
|
||||
(d/export edition/create-node-at-position)
|
||||
|
||||
;; Selection
|
||||
(d/export selection/handle-selection)
|
||||
|
|
|
@ -234,3 +234,15 @@
|
|||
(update [_ state]
|
||||
(let [id (get-in state [:workspace-local :edition])]
|
||||
(update state :workspace-local dissoc :edit-path id)))))
|
||||
|
||||
(defn create-node-at-position
|
||||
[{:keys [from-p to-p t]}]
|
||||
(ptk/reify ::create-node-at-position
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (st/get-path-id state)]
|
||||
(update-in state (st/get-path state :content) ugp/split-segments #{from-p to-p} t)))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(rx/of (changes/save-path-content)))))
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
[rumext.alpha :as mf])
|
||||
(:import goog.events.EventType))
|
||||
|
||||
(mf/defc path-point [{:keys [position zoom edit-mode hover? selected? preview? start-path? last-p?]}]
|
||||
(mf/defc path-point [{:keys [position zoom edit-mode hover? selected? preview? start-path? last-p? new-point?]}]
|
||||
(let [{:keys [x y]} position
|
||||
|
||||
on-enter
|
||||
|
@ -40,6 +40,9 @@
|
|||
(dom/stop-propagation event)
|
||||
(dom/prevent-default event)
|
||||
|
||||
(when (and new-point? (some? (meta position)))
|
||||
(st/emit! (drp/create-node-at-position (meta position))))
|
||||
|
||||
(let [shift? (kbd/shift? event)]
|
||||
(cond
|
||||
(= edit-mode :move)
|
||||
|
@ -190,6 +193,8 @@
|
|||
last-p (->> content last ugp/command->point)
|
||||
handlers (ugp/content->handlers content)
|
||||
|
||||
start-p? (not (some? last-point))
|
||||
|
||||
[snap-selected snap-points]
|
||||
(cond
|
||||
(some? drag-handler) [#{drag-handler} points]
|
||||
|
@ -199,7 +204,9 @@
|
|||
[(->> selected-points (map base->point) (into #{}))
|
||||
(->> points (remove selected-points) (into #{}))])
|
||||
|
||||
show-snap? (and snap-toggled (or (some? drag-handler) (some? preview) (some? moving-handler) moving-nodes))
|
||||
show-snap? (and snap-toggled
|
||||
(empty? hover-points)
|
||||
(or (some? drag-handler) (some? preview) (some? moving-handler) moving-nodes))
|
||||
|
||||
handle-double-click-outside
|
||||
(fn [event]
|
||||
|
@ -213,6 +220,13 @@
|
|||
#(doseq [key keys]
|
||||
(events/unlistenByKey key)))))
|
||||
|
||||
(hooks/use-stream
|
||||
ms/mouse-position
|
||||
(mf/deps shape zoom)
|
||||
(fn [position]
|
||||
(when-let [point (gshp/path-closest-point shape position)]
|
||||
(reset! hover-point (when (< (gpt/distance position point) (/ 10 zoom)) point)))))
|
||||
|
||||
[:g.path-editor {:ref editor-ref}
|
||||
(when (and preview (not drag-handler))
|
||||
[:& path-preview {:command preview
|
||||
|
@ -228,13 +242,15 @@
|
|||
(when @hover-point
|
||||
[:g.hover-point
|
||||
[:& path-point {:position @hover-point
|
||||
:edit-mode edit-mode
|
||||
:new-point? true
|
||||
:start-path? start-p?
|
||||
:zoom zoom}]])
|
||||
|
||||
(for [position points]
|
||||
(let [point-selected? (contains? selected-points (get point->base position))
|
||||
point-hover? (contains? hover-points (get point->base position))
|
||||
last-p? (= last-point (get point->base position))
|
||||
start-p? (not (some? last-point))]
|
||||
last-p? (= last-point (get point->base position))]
|
||||
|
||||
[:g.path-node
|
||||
[:g.point-handlers {:pointer-events (when (= edit-mode :draw) "none")}
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
drawing-path? (or (and edition (= :draw (get-in edit-path [edition :edit-mode])))
|
||||
(and (some? drawing-obj) (= :path (:type drawing-obj))))
|
||||
text-editing? (and edition (= :text (get-in objects [edition :type])))
|
||||
path-editing? (and edition (= :path (get-in objects [edition :type])))
|
||||
|
||||
on-click (actions/on-click hover selected edition drawing-path? drawing-tool)
|
||||
on-context-menu (actions/on-context-menu hover)
|
||||
|
@ -132,11 +133,12 @@
|
|||
show-snap-distance? (and (contains? layout :dynamic-alignment) (= transform :move) (not (empty? selected)))
|
||||
show-snap-points? (and (contains? layout :dynamic-alignment) (or drawing-obj transform))
|
||||
show-selrect? (and selrect (empty? drawing))
|
||||
show-measures? (and (not transform) (not path-editing?) show-distances?)
|
||||
]
|
||||
|
||||
(hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?)
|
||||
(hooks/setup-viewport-size viewport-ref)
|
||||
(hooks/setup-cursor cursor alt? panning drawing-tool drawing-path?)
|
||||
(hooks/setup-cursor cursor alt? panning drawing-tool drawing-path? path-editing?)
|
||||
(hooks/setup-resize layout viewport-ref)
|
||||
(hooks/setup-keyboard alt? ctrl?)
|
||||
(hooks/setup-hover-shapes page-id move-stream selected objects transform selected ctrl? hover hover-ids)
|
||||
|
@ -224,7 +226,7 @@
|
|||
:disable-handlers (or drawing-tool edition)
|
||||
:on-move-selected on-move-selected}])
|
||||
|
||||
(when (and (not transform) show-distances?)
|
||||
(when show-measures?
|
||||
[:& msr/measurement
|
||||
{:bounds vbox
|
||||
:selected-shapes selected-shapes
|
||||
|
|
|
@ -58,23 +58,23 @@
|
|||
;; We schedule the event so it fires after `initialize-page` event
|
||||
(timers/schedule #(st/emit! (dw/initialize-viewport size)))))))
|
||||
|
||||
(defn setup-cursor [cursor alt? panning drawing-tool drawing-path?]
|
||||
(defn setup-cursor [cursor alt? panning drawing-tool drawing-path? path-editing?]
|
||||
(mf/use-effect
|
||||
(mf/deps @cursor @alt? panning drawing-tool drawing-path?)
|
||||
(mf/deps @cursor @alt? panning drawing-tool drawing-path? path-editing?)
|
||||
(fn []
|
||||
(let [new-cursor
|
||||
(cond
|
||||
panning (utils/get-cursor :hand)
|
||||
(= drawing-tool :comments) (utils/get-cursor :comments)
|
||||
(= drawing-tool :frame) (utils/get-cursor :create-artboard)
|
||||
(= drawing-tool :rect) (utils/get-cursor :create-rectangle)
|
||||
(= drawing-tool :circle) (utils/get-cursor :create-ellipse)
|
||||
panning (utils/get-cursor :hand)
|
||||
(= drawing-tool :comments) (utils/get-cursor :comments)
|
||||
(= drawing-tool :frame) (utils/get-cursor :create-artboard)
|
||||
(= drawing-tool :rect) (utils/get-cursor :create-rectangle)
|
||||
(= drawing-tool :circle) (utils/get-cursor :create-ellipse)
|
||||
(or (= drawing-tool :path)
|
||||
drawing-path?) (utils/get-cursor :pen)
|
||||
(= drawing-tool :curve) (utils/get-cursor :pencil)
|
||||
drawing-tool (utils/get-cursor :create-shape)
|
||||
@alt? (utils/get-cursor :duplicate)
|
||||
:else (utils/get-cursor :pointer-inner))]
|
||||
drawing-path?) (utils/get-cursor :pen)
|
||||
(= drawing-tool :curve) (utils/get-cursor :pencil)
|
||||
drawing-tool (utils/get-cursor :create-shape)
|
||||
(and @alt? (not path-editing?)) (utils/get-cursor :duplicate)
|
||||
:else (utils/get-cursor :pointer-inner))]
|
||||
|
||||
(when (not= @cursor new-cursor)
|
||||
(reset! cursor new-cursor))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue