mirror of
https://github.com/penpot/penpot.git
synced 2025-03-16 01:31:22 -05:00
🐛 Fix selection handlers reactivity.
This commit is contained in:
parent
5a820b4f9e
commit
f0230c346c
3 changed files with 23 additions and 44 deletions
|
@ -565,7 +565,6 @@
|
|||
;; --- Outer Rect
|
||||
|
||||
(declare selection-rect-generic)
|
||||
(declare selection-rect-group)
|
||||
|
||||
(defn rotation-matrix
|
||||
"Generate a rotation matrix from shape."
|
||||
|
@ -590,25 +589,15 @@
|
|||
([shape]
|
||||
(selection-rect @st/state shape))
|
||||
([state shape]
|
||||
(let [{:keys [displacement resize]} (:modifiers shape)]
|
||||
(let [modifier (:modifier-mtx shape)]
|
||||
(-> (shape->rect-shape shape)
|
||||
(assoc :type :rect :id (:id shape))
|
||||
(transform (or resize (gmt/matrix)))
|
||||
(transform (or displacement (gmt/matrix)))
|
||||
(transform (or modifier (gmt/matrix)))
|
||||
(rotate-shape)
|
||||
(size)))))
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
(defn resolve-parent
|
||||
"Recursively resolve the real shape parent."
|
||||
([shape]
|
||||
(resolve-parent @st/state shape))
|
||||
([state {:keys [group] :as shape}]
|
||||
(if group
|
||||
(resolve-parent state (get-in state [:shapes group]))
|
||||
shape)))
|
||||
|
||||
(defn contained-in?
|
||||
"Check if a shape is contained in the
|
||||
provided selection rect."
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
[uxbox.main.store :as st]
|
||||
[uxbox.main.ui.shapes.attrs :as attrs]
|
||||
[uxbox.main.ui.shapes.common :as common]
|
||||
[uxbox.util.data :refer [classnames normalize-props]]))
|
||||
[uxbox.util.data :refer [classnames normalize-props]]
|
||||
[uxbox.util.geom.matrix :as gmt]))
|
||||
|
||||
;; --- Path Component
|
||||
|
||||
|
@ -22,8 +23,7 @@
|
|||
|
||||
(mf/defc path-component
|
||||
[{:keys [shape] :as props}]
|
||||
(let [modifiers (mf/deref (refs/selected-modifiers (:id shape)))
|
||||
selected (mf/deref refs/selected-shapes)
|
||||
(let [selected (mf/deref refs/selected-shapes)
|
||||
selected? (contains? selected (:id shape))]
|
||||
(letfn [(on-mouse-down [event]
|
||||
(common/on-mouse-down event shape selected))
|
||||
|
@ -35,7 +35,6 @@
|
|||
:on-double-click on-double-click
|
||||
:on-mouse-down on-mouse-down}
|
||||
[:& path-shape {:shape shape
|
||||
:modifiers modifiers
|
||||
:background? true}]])))
|
||||
|
||||
;; --- Path Shape
|
||||
|
@ -62,12 +61,13 @@
|
|||
(recur buffer (inc index)))))))
|
||||
|
||||
(mf/defc path-shape
|
||||
[{:keys [shape modifiers background?] :as props}]
|
||||
(let [{:keys [resize displacement]} modifiers
|
||||
shape (cond-> shape
|
||||
displacement (geom/transform displacement)
|
||||
resize (geom/transform resize))
|
||||
moving? (boolean displacement)
|
||||
[{:keys [shape background?] :as props}]
|
||||
(let [modifier-mtx (:modifier-mtx shape)
|
||||
shape (cond
|
||||
(gmt/matrix? modifier-mtx) (geom/transform shape modifier-mtx)
|
||||
:else shape)
|
||||
|
||||
moving? (boolean modifier-mtx)
|
||||
|
||||
pdata (render-path shape)
|
||||
props {:id (str (:id shape))
|
||||
|
|
|
@ -190,9 +190,8 @@
|
|||
:style {:cursor "pointer"}}])])))
|
||||
|
||||
(mf/defc multiple-selection-handlers
|
||||
[{:keys [shapes modifiers zoom] :as props}]
|
||||
[{:keys [shapes zoom] :as props}]
|
||||
(let [shape (->> shapes
|
||||
(map #(assoc % :modifiers (get modifiers (:id %))))
|
||||
(map #(geom/selection-rect %))
|
||||
(geom/shapes->rect-shape)
|
||||
(geom/selection-rect))
|
||||
|
@ -202,18 +201,9 @@
|
|||
:zoom zoom
|
||||
:on-click on-click}]))
|
||||
|
||||
(mf/defc single-selection-handlers
|
||||
[{:keys [shape zoom modifiers] :as props}]
|
||||
(let [on-click #(do (dom/stop-propagation %2)
|
||||
(start-resize %1 #{(:id shape)} shape))
|
||||
shape (-> (assoc shape :modifiers modifiers)
|
||||
(geom/selection-rect))]
|
||||
[:& controls {:shape shape :zoom zoom :on-click on-click}]))
|
||||
|
||||
(mf/defc text-edition-selection-handlers
|
||||
[{:keys [shape modifiers zoom] :as props}]
|
||||
(let [{:keys [x1 y1 width height] :as shape} (-> (assoc shape :modifiers modifiers)
|
||||
(geom/selection-rect))]
|
||||
[{:keys [shape zoom] :as props}]
|
||||
(let [{:keys [x1 y1 width height] :as shape} (geom/selection-rect shape)]
|
||||
[:g.controls
|
||||
[:rect.main {:x x1 :y y1
|
||||
:width width
|
||||
|
@ -224,6 +214,13 @@
|
|||
:stroke-opacity "0.5"
|
||||
:fill "transparent"}}]]))
|
||||
|
||||
(mf/defc single-selection-handlers
|
||||
[{:keys [shape zoom] :as props}]
|
||||
(let [on-click #(do (dom/stop-propagation %2)
|
||||
(start-resize %1 #{(:id shape)} shape))
|
||||
shape (geom/selection-rect shape)]
|
||||
[:& controls {:shape shape :zoom zoom :on-click on-click}]))
|
||||
|
||||
(def ^:private shapes-map-iref
|
||||
(-> (l/key :shapes)
|
||||
(l/derive st/state)))
|
||||
|
@ -233,34 +230,27 @@
|
|||
(let [shapes-map (mf/deref shapes-map-iref)
|
||||
shapes (map #(get shapes-map %) (:selected wst))
|
||||
edition? (:edition wst)
|
||||
modifiers (:modifiers wst)
|
||||
zoom (:zoom wst 1)
|
||||
num (count shapes)
|
||||
{:keys [id type] :as shape} (first shapes)]
|
||||
|
||||
|
||||
(cond
|
||||
(zero? num)
|
||||
nil
|
||||
|
||||
(> num 1)
|
||||
[:& multiple-selection-handlers {:shapes shapes
|
||||
:modifiers modifiers
|
||||
:zoom zoom}]
|
||||
|
||||
(and (= type :text)
|
||||
(= edition? (:id shape)))
|
||||
[:& text-edition-selection-handlers {:shape shape
|
||||
:modifiers (get modifiers id)
|
||||
:zoom zoom}]
|
||||
(and (= type :path)
|
||||
(= edition? (:id shape)))
|
||||
[:& path-edition-selection-handlers {:shape shape
|
||||
:zoom zoom
|
||||
:modifiers (get modifiers id)}]
|
||||
|
||||
:zoom zoom}]
|
||||
|
||||
:else
|
||||
[:& single-selection-handlers {:shape shape
|
||||
:modifiers (get modifiers id)
|
||||
:zoom zoom}])))
|
||||
|
|
Loading…
Add table
Reference in a new issue