mirror of
https://github.com/penpot/penpot.git
synced 2025-01-26 08:29:42 -05:00
Improved shape component for proper handle shapes in groups.
This commit is contained in:
parent
84d87dcc4f
commit
42073077ee
1 changed files with 49 additions and 24 deletions
|
@ -8,7 +8,7 @@
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.state :as st]
|
[uxbox.state :as st]
|
||||||
[uxbox.xforms :as xf]
|
[uxbox.xforms :as xf]
|
||||||
[uxbox.shapes :as shapes]
|
[uxbox.shapes :as sh]
|
||||||
[uxbox.util.lens :as ul]
|
[uxbox.util.lens :as ul]
|
||||||
[uxbox.library.icons :as _icons]
|
[uxbox.library.icons :as _icons]
|
||||||
[uxbox.data.projects :as dp]
|
[uxbox.data.projects :as dp]
|
||||||
|
@ -49,35 +49,60 @@
|
||||||
;; Shape
|
;; Shape
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn shape-render
|
(declare shape)
|
||||||
[own shape selected]
|
|
||||||
(let [{:keys [id x y width height] :as shape} shape
|
(defn shape-render
|
||||||
selected? (contains? selected id)]
|
[own item selected]
|
||||||
(letfn [(on-mouse-down [event]
|
(let [{:keys [id x y width height group] :as item} item
|
||||||
(when-not (:blocked shape)
|
selected? (contains? selected id)
|
||||||
(let [local (:rum/local own)]
|
local (:rum/local own)]
|
||||||
(dom/stop-propagation event)
|
(letfn [(on-mouse-down [event]
|
||||||
(swap! local assoc :init-coords [x y])
|
(when-not (:blocked item)
|
||||||
(reset! wb/shapes-dragging? true))
|
;; (let [local (:rum/local own)]
|
||||||
(cond
|
;; (swap! local assoc :init-coords [x y])
|
||||||
(and (not selected?)
|
;; (reset! wb/shapes-dragging? true))
|
||||||
(empty? selected))
|
(cond
|
||||||
(rs/emit! (dw/select-shape id))
|
(and group (:locked (sh/resolve-parent item)))
|
||||||
|
nil
|
||||||
|
|
||||||
|
(and (not selected?) (empty? selected))
|
||||||
|
(do
|
||||||
|
(dom/stop-propagation event)
|
||||||
|
(swap! local assoc :init-coords [x y])
|
||||||
|
(reset! wb/shapes-dragging? true)
|
||||||
|
|
||||||
|
(rs/emit! (dw/select-shape id)))
|
||||||
|
|
||||||
|
(and (not selected?) (not (empty? selected)))
|
||||||
|
(do
|
||||||
|
(dom/stop-propagation event)
|
||||||
|
(swap! local assoc :init-coords [x y])
|
||||||
|
(reset! wb/shapes-dragging? true)
|
||||||
|
(if (.-ctrlKey event)
|
||||||
|
(rs/emit! (dw/select-shape id))
|
||||||
|
(rs/emit! (dw/deselect-all)
|
||||||
|
(dw/select-shape id))))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(do
|
||||||
|
(dom/stop-propagation event)
|
||||||
|
(swap! local assoc :init-coords [x y])
|
||||||
|
(reset! wb/shapes-dragging? true)))))
|
||||||
|
|
||||||
(and (not selected?)
|
|
||||||
(not (empty? selected)))
|
|
||||||
(if (.-ctrlKey event)
|
|
||||||
(rs/emit! (dw/select-shape id))
|
|
||||||
(rs/emit! (dw/deselect-all)
|
|
||||||
(dw/select-shape id))))))
|
|
||||||
(on-mouse-up [event]
|
(on-mouse-up [event]
|
||||||
(dom/stop-propagation event)
|
(cond
|
||||||
(reset! wb/shapes-dragging? false))]
|
(and group (:locked (sh/resolve-parent item)))
|
||||||
|
nil
|
||||||
|
|
||||||
|
:else
|
||||||
|
(do
|
||||||
|
(dom/stop-propagation event)
|
||||||
|
(reset! wb/shapes-dragging? false))))]
|
||||||
(html
|
(html
|
||||||
[:g.shape {:class (when selected? "selected")
|
[:g.shape {:class (when selected? "selected")
|
||||||
:on-mouse-down on-mouse-down
|
:on-mouse-down on-mouse-down
|
||||||
:on-mouse-up on-mouse-up}
|
:on-mouse-up on-mouse-up}
|
||||||
(shapes/-render shape nil)]))))
|
(sh/-render item #(shape % selected))]))))
|
||||||
|
|
||||||
(def ^:static shape
|
(def ^:static shape
|
||||||
(mx/component
|
(mx/component
|
||||||
|
|
Loading…
Add table
Reference in a new issue