mirror of
https://github.com/penpot/penpot.git
synced 2025-03-18 10:41:29 -05:00
🐛 Remove leaks of selrect attrs in the root shape object.
This commit is contained in:
parent
fd91a7b1f4
commit
4bdaab637c
4 changed files with 39 additions and 62 deletions
|
@ -48,11 +48,7 @@
|
|||
(update :y inc-y))))]
|
||||
(-> shape
|
||||
(update :x inc-x)
|
||||
(update :x1 inc-x)
|
||||
(update :x2 inc-x)
|
||||
(update :y inc-y)
|
||||
(update :y1 inc-y)
|
||||
(update :y2 inc-y)
|
||||
(update-in [:selrect :x] inc-x)
|
||||
(update-in [:selrect :x1] inc-x)
|
||||
(update-in [:selrect :x2] inc-x)
|
||||
|
@ -197,11 +193,10 @@
|
|||
(us/assert number? width)
|
||||
(us/assert number? height)
|
||||
(-> shape
|
||||
(assoc :width width
|
||||
:height height
|
||||
:x2 (+ (:x1 shape) width)
|
||||
:y2 (+ (:y1 shape) height))
|
||||
(update :selrect (nilf #(resize % width height)))))
|
||||
(assoc :width width :height height)
|
||||
(update :selrect (fn [shape]
|
||||
(assoc :x2 (+ (:x1 shape) width)
|
||||
:y2 (+ (:y1 shape) height))))))
|
||||
|
||||
;; --- Setup (Initialize)
|
||||
|
||||
|
@ -247,30 +242,16 @@
|
|||
(declare group->rect-shape)
|
||||
(declare rect->rect-shape)
|
||||
|
||||
;; TODO: completly remove
|
||||
|
||||
(defn shape->rect-shape
|
||||
"Coerce shape to rect like shape."
|
||||
|
||||
[{:keys [type] :as shape}]
|
||||
(case type
|
||||
(:curve :path) (path->rect-shape shape)
|
||||
(rect->rect-shape shape)))
|
||||
|
||||
(defn shapes->rect-shape
|
||||
[shapes]
|
||||
(let [shapes (mapv shape->rect-shape shapes)
|
||||
minx (transduce (map :x1) min ##Inf shapes)
|
||||
miny (transduce (map :y1) min ##Inf shapes)
|
||||
maxx (transduce (map :x2) max ##-Inf shapes)
|
||||
maxy (transduce (map :y2) max ##-Inf shapes)]
|
||||
{:x1 minx
|
||||
:y1 miny
|
||||
:x2 maxx
|
||||
:y2 maxy
|
||||
:x minx
|
||||
:y miny
|
||||
:width (- maxx minx)
|
||||
:height (- maxy miny)
|
||||
:type :rect}))
|
||||
|
||||
;; -- Points
|
||||
|
||||
(declare transform-shape-point)
|
||||
|
@ -603,10 +584,10 @@
|
|||
|
||||
(defn pad-selrec
|
||||
([selrect] (pad-selrec selrect 1))
|
||||
([selrec size]
|
||||
([selrect size]
|
||||
(let [inc #(+ % size)
|
||||
dec #(- % size)]
|
||||
(-> selrec
|
||||
(-> selrect
|
||||
(update :x dec)
|
||||
(update :y dec)
|
||||
(update :x1 dec)
|
||||
|
@ -728,10 +709,6 @@
|
|||
(-> rect-shape
|
||||
(update :x check)
|
||||
(update :y check)
|
||||
(update :x1 check)
|
||||
(update :y1 check)
|
||||
(update :x2 check)
|
||||
(update :y2 check)
|
||||
(update :width (comp to-positive check))
|
||||
(update :height (comp to-positive check)))))
|
||||
|
||||
|
|
|
@ -67,14 +67,13 @@
|
|||
(letfn [(resize-shape [{:keys [x y width height] :as shape} point lock? point-snap]
|
||||
(let [;; The new shape behaves like a resize on the bottom-right corner
|
||||
initial (gpt/point (+ x width) (+ y height))
|
||||
shape' (geom/shape->rect-shape shape)
|
||||
shapev (gpt/point (:width shape') (:height shape'))
|
||||
deltav (gpt/to-vec initial point-snap)
|
||||
scalev (gpt/divide (gpt/add shapev deltav) shapev)
|
||||
scalev (if lock?
|
||||
(let [v (max (:x scalev) (:y scalev))]
|
||||
(gpt/point v v))
|
||||
scalev)]
|
||||
shapev (gpt/point width height)
|
||||
deltav (gpt/to-vec initial point-snap)
|
||||
scalev (gpt/divide (gpt/add shapev deltav) shapev)
|
||||
scalev (if lock?
|
||||
(let [v (max (:x scalev) (:y scalev))]
|
||||
(gpt/point v v))
|
||||
scalev)]
|
||||
(-> shape
|
||||
(assoc-in [:modifiers :resize-vector] scalev)
|
||||
(assoc-in [:modifiers :resize-origin] (gpt/point x y))
|
||||
|
@ -87,45 +86,46 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [{:keys [flags]} (:workspace-local state)
|
||||
|
||||
stoper? #(or (ms/mouse-up? %) (= % :interrupt))
|
||||
stoper (rx/filter stoper? stream)
|
||||
stoper (rx/filter stoper? stream)
|
||||
initial @ms/mouse-position
|
||||
|
||||
page-id (get state :current-page-id)
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
layout (get state :workspace-layout)
|
||||
layout (get state :workspace-layout)
|
||||
|
||||
frames (->> objects
|
||||
vals
|
||||
(filter (comp #{:frame} :type))
|
||||
(remove #(= (:id %) uuid/zero) ))
|
||||
|
||||
frame-id (or (->> frames
|
||||
(filter #(geom/has-point? % initial))
|
||||
first
|
||||
:id)
|
||||
uuid/zero)
|
||||
frames (cp/select-frames objects)
|
||||
fid (or (->> frames
|
||||
(filter #(geom/has-point? % initial))
|
||||
first
|
||||
:id)
|
||||
uuid/zero)
|
||||
|
||||
shape (-> state
|
||||
(get-in [:workspace-local :drawing])
|
||||
(geom/setup {:x (:x initial) :y (:y initial) :width 1 :height 1})
|
||||
(assoc :frame-id frame-id)
|
||||
(assoc :frame-id fid)
|
||||
(assoc ::initialized? true))]
|
||||
(rx/concat
|
||||
;; Add shape to drawing state
|
||||
(rx/of #(assoc-in state [:workspace-local :drawing] shape))
|
||||
|
||||
;; Initial SNAP
|
||||
(->> (snap/closest-snap-point page-id [shape] layout initial)
|
||||
(rx/map (fn [{:keys [x y]}]
|
||||
#(-> %
|
||||
(assoc-in [:workspace-local :drawing :x] x)
|
||||
(assoc-in [:workspace-local :drawing :y] y)))))
|
||||
#(update-in % [:workspace-local :drawing] assoc :x x :y y))))
|
||||
|
||||
(->> ms/mouse-position
|
||||
(rx/with-latest vector ms/mouse-position-ctrl)
|
||||
(rx/switch-map (fn [[point :as current]]
|
||||
(->> (snap/closest-snap-point page-id [shape] layout point)
|
||||
(rx/map #(conj current %)))))
|
||||
(rx/map (fn [[pt ctrl? point-snap]] #(update-drawing % pt ctrl? point-snap)))
|
||||
(rx/switch-map
|
||||
(fn [[point :as current]]
|
||||
(->> (snap/closest-snap-point page-id [shape] layout point)
|
||||
(rx/map #(conj current %)))))
|
||||
(rx/map
|
||||
(fn [[pt ctrl? point-snap]]
|
||||
#(update-drawing % pt ctrl? point-snap)))
|
||||
|
||||
(rx/take-until stoper))
|
||||
(rx/of handle-finish-drawing)))))))
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
(defn- calculate-dimensions
|
||||
[{:keys [objects] :as data} vport]
|
||||
(let [shapes (cp/select-toplevel-shapes objects {:include-frames? true})]
|
||||
(->> (geom/shapes->rect-shape shapes)
|
||||
(->> (geom/selection-rect shapes)
|
||||
(geom/adjust-to-viewport vport)
|
||||
(geom/fix-invalid-rect-values))))
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
[objects]
|
||||
(let [shapes (->> (cp/select-toplevel-shapes objects {:include-frames? true})
|
||||
(map #(merge % (select-keys % [:x :y :width :height]))))
|
||||
bounds (geom/shapes->rect-shape shapes)
|
||||
bounds (geom/selection-rect shapes)
|
||||
bounds #js {:x (:x bounds)
|
||||
:y (:y bounds)
|
||||
:width (:width bounds)
|
||||
|
|
Loading…
Add table
Reference in a new issue