mirror of
https://github.com/penpot/penpot.git
synced 2025-06-18 12:31:39 +02:00
✨ Add some enhancements in create interactions
This commit is contained in:
parent
cd17eccd43
commit
4be9606341
4 changed files with 38 additions and 12 deletions
|
@ -208,7 +208,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [stopper (rx/filter (ptk/type? ::flash-interactions) stream)]
|
(let [stopper (rx/filter (ptk/type? ::flash-interactions) stream)]
|
||||||
(->> (rx/of flash-done)
|
(->> (rx/of flash-done)
|
||||||
(rx/delay 1000)
|
(rx/delay 500)
|
||||||
(rx/take-until stopper))))))
|
(rx/take-until stopper))))))
|
||||||
|
|
||||||
(def flash-done
|
(def flash-done
|
||||||
|
|
|
@ -1452,10 +1452,13 @@
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
frame (dwc/get-frame-at-point objects position)
|
frame (dwc/get-frame-at-point objects position)
|
||||||
|
|
||||||
shape-id (first (get-in state [:workspace-local :selected]))]
|
shape-id (first (get-in state [:workspace-local :selected]))
|
||||||
|
shape (get objects shape-id)]
|
||||||
|
|
||||||
(when-not (= position initial-pos)
|
(when-not (= position initial-pos)
|
||||||
(if (and frame shape-id (not= (:id frame) shape-id))
|
(if (and frame shape-id
|
||||||
|
(not= (:id frame) (:id shape))
|
||||||
|
(not= (:id frame) (:frame-id shape)))
|
||||||
(rx/of (update-shape shape-id
|
(rx/of (update-shape shape-id
|
||||||
{:interactions [{:event-type :click
|
{:interactions [{:event-type :click
|
||||||
:action-type :navigate
|
:action-type :navigate
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
(let [selected @refs/selected-shapes
|
(let [selected @refs/selected-shapes
|
||||||
selected? (contains? selected id)
|
selected? (contains? selected id)
|
||||||
drawing? @refs/selected-drawing-tool
|
drawing? @refs/selected-drawing-tool
|
||||||
options-mode @refs/options-mode
|
|
||||||
button (.-which (.-nativeEvent event))]
|
button (.-which (.-nativeEvent event))]
|
||||||
(when-not (:blocked shape)
|
(when-not (:blocked shape)
|
||||||
(cond
|
(cond
|
||||||
|
@ -37,9 +36,7 @@
|
||||||
(= type :frame)
|
(= type :frame)
|
||||||
(when selected?
|
(when selected?
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(if (= options-mode :design)
|
(st/emit! (dw/start-move-selected)))))
|
||||||
(st/emit! (dw/start-move-selected))
|
|
||||||
(st/emit! (dw/start-create-interaction))))
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
|
@ -48,9 +45,7 @@
|
||||||
(when-not (or (empty? selected) (kbd/shift? event))
|
(when-not (or (empty? selected) (kbd/shift? event))
|
||||||
(st/emit! dw/deselect-all))
|
(st/emit! dw/deselect-all))
|
||||||
(st/emit! (dw/select-shape id)))
|
(st/emit! (dw/select-shape id)))
|
||||||
(if (= options-mode :design)
|
(st/emit! (dw/start-move-selected)))))
|
||||||
(st/emit! (dw/start-move-selected))
|
|
||||||
(st/emit! (dw/start-create-interaction))))))))
|
|
||||||
|
|
||||||
(defn on-context-menu
|
(defn on-context-menu
|
||||||
[event shape]
|
[event shape]
|
||||||
|
|
|
@ -141,10 +141,34 @@
|
||||||
:stroke-width 2
|
:stroke-width 2
|
||||||
:d arrow-pdata}]])))
|
:d arrow-pdata}]])))
|
||||||
|
|
||||||
|
|
||||||
|
(mf/defc interaction-handle
|
||||||
|
[{:keys [shape selected] :as props}]
|
||||||
|
(let [shape-rect (geom/selection-rect-shape shape)
|
||||||
|
handle-x (+ (:x shape-rect) (:width shape-rect))
|
||||||
|
handle-y (+ (:y shape-rect) (/ (:height shape-rect) 2))
|
||||||
|
|
||||||
|
arrow-path ["M" (- handle-x 5) handle-y "l 8 0 l -4 -4 m 4 4 l -4 4"]
|
||||||
|
arrow-pdata (str/join " " arrow-path)]
|
||||||
|
|
||||||
|
[:g {:on-mouse-down #(on-mouse-down % shape selected)}
|
||||||
|
[:circle {:cx handle-x
|
||||||
|
:cy handle-y
|
||||||
|
:r 8
|
||||||
|
:stroke "#31EFB8"
|
||||||
|
:stroke-width 2
|
||||||
|
:fill "#FFFFFF"}]
|
||||||
|
[:path {:stroke "#31EFB8"
|
||||||
|
:fill "transparent"
|
||||||
|
:stroke-width 2
|
||||||
|
:d arrow-pdata}]]))
|
||||||
|
|
||||||
|
|
||||||
(mf/defc interactions
|
(mf/defc interactions
|
||||||
[{:keys [selected] :as props}]
|
[{:keys [selected] :as props}]
|
||||||
(let [data (mf/deref refs/workspace-data)
|
(let [data (mf/deref refs/workspace-data)
|
||||||
local (mf/deref refs/workspace-local)
|
local (mf/deref refs/workspace-local)
|
||||||
|
current-transform (:transform local)
|
||||||
objects (:objects data)
|
objects (:objects data)
|
||||||
active-shapes (filter #(first (get-click-interaction %)) (vals objects))
|
active-shapes (filter #(first (get-click-interaction %)) (vals objects))
|
||||||
selected-shapes (map #(get objects %) selected)
|
selected-shapes (map #(get objects %) selected)
|
||||||
|
@ -171,10 +195,14 @@
|
||||||
(for [shape selected-shapes]
|
(for [shape selected-shapes]
|
||||||
(let [interaction (get-click-interaction shape)
|
(let [interaction (get-click-interaction shape)
|
||||||
dest-shape (get objects (:destination interaction))]
|
dest-shape (get objects (:destination interaction))]
|
||||||
(when dest-shape
|
(if dest-shape
|
||||||
[:& interaction-path {:key (:id shape)
|
[:& interaction-path {:key (:id shape)
|
||||||
:orig-shape shape
|
:orig-shape shape
|
||||||
:dest-shape dest-shape
|
:dest-shape dest-shape
|
||||||
:selected selected
|
:selected selected
|
||||||
:selected? true}]))))]))
|
:selected? true}]
|
||||||
|
(when (not (#{:move :rotate} current-transform))
|
||||||
|
[:& interaction-handle {:key (:id shape)
|
||||||
|
:shape shape
|
||||||
|
:selected selected}])))))]))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue