mirror of
https://github.com/penpot/penpot.git
synced 2025-02-09 08:38:15 -05:00
🐛 Fix problems with snap index regeneration
This commit is contained in:
parent
b2e01cd52b
commit
93d8c171be
12 changed files with 118 additions and 53 deletions
|
@ -52,7 +52,7 @@
|
||||||
(t/testing "Shape without modifiers should stay the same"
|
(t/testing "Shape without modifiers should stay the same"
|
||||||
(t/are [type]
|
(t/are [type]
|
||||||
(let [shape-before (create-test-shape type)
|
(let [shape-before (create-test-shape type)
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(= shape-before shape-after))
|
(= shape-before shape-after))
|
||||||
|
|
||||||
:rect :path))
|
:rect :path))
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
(t/are [type]
|
(t/are [type]
|
||||||
(let [modifiers {:displacement (gmt/translate-matrix (gpt/point 10 -10))}]
|
(let [modifiers {:displacement (gmt/translate-matrix (gpt/point 10 -10))}]
|
||||||
(let [shape-before (create-test-shape type {:modifiers modifiers})
|
(let [shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(t/is (not= shape-before shape-after))
|
(t/is (not= shape-before shape-after))
|
||||||
|
|
||||||
(t/is (close? (get-in shape-before [:selrect :x])
|
(t/is (close? (get-in shape-before [:selrect :x])
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
(t/are [type]
|
(t/are [type]
|
||||||
(let [modifiers {:displacement (gmt/matrix)}
|
(let [modifiers {:displacement (gmt/matrix)}
|
||||||
shape-before (create-test-shape type {:modifiers modifiers})
|
shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(t/are [prop]
|
(t/are [prop]
|
||||||
(t/is (close? (get-in shape-before [:selrect prop])
|
(t/is (close? (get-in shape-before [:selrect prop])
|
||||||
(get-in shape-after [:selrect prop])))
|
(get-in shape-after [:selrect prop])))
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
:resize-vector (gpt/point 2 2)
|
:resize-vector (gpt/point 2 2)
|
||||||
:resize-transform (gmt/matrix)}
|
:resize-transform (gmt/matrix)}
|
||||||
shape-before (create-test-shape type {:modifiers modifiers})
|
shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(t/is (not= shape-before shape-after))
|
(t/is (not= shape-before shape-after))
|
||||||
|
|
||||||
(t/is (close? (get-in shape-before [:selrect :x])
|
(t/is (close? (get-in shape-before [:selrect :x])
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
:resize-vector (gpt/point 1 1)
|
:resize-vector (gpt/point 1 1)
|
||||||
:resize-transform (gmt/matrix)}
|
:resize-transform (gmt/matrix)}
|
||||||
shape-before (create-test-shape type {:modifiers modifiers})
|
shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(t/are [prop]
|
(t/are [prop]
|
||||||
(t/is (close? (get-in shape-before [:selrect prop])
|
(t/is (close? (get-in shape-before [:selrect prop])
|
||||||
(get-in shape-after [:selrect prop])))
|
(get-in shape-after [:selrect prop])))
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
:resize-vector (gpt/point 0 0)
|
:resize-vector (gpt/point 0 0)
|
||||||
:resize-transform (gmt/matrix)}
|
:resize-transform (gmt/matrix)}
|
||||||
shape-before (create-test-shape type {:modifiers modifiers})
|
shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(t/is (> (get-in shape-before [:selrect :width])
|
(t/is (> (get-in shape-before [:selrect :width])
|
||||||
(get-in shape-after [:selrect :width])))
|
(get-in shape-after [:selrect :width])))
|
||||||
(t/is (> (get-in shape-after [:selrect :width]) 0))
|
(t/is (> (get-in shape-after [:selrect :width]) 0))
|
||||||
|
@ -144,7 +144,7 @@
|
||||||
(t/are [type]
|
(t/are [type]
|
||||||
(let [modifiers {:rotation 30}
|
(let [modifiers {:rotation 30}
|
||||||
shape-before (create-test-shape type {:modifiers modifiers})
|
shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
|
|
||||||
(t/is (not= shape-before shape-after))
|
(t/is (not= shape-before shape-after))
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@
|
||||||
(t/are [type]
|
(t/are [type]
|
||||||
(let [modifiers {:rotation 0}
|
(let [modifiers {:rotation 0}
|
||||||
shape-before (create-test-shape type {:modifiers modifiers})
|
shape-before (create-test-shape type {:modifiers modifiers})
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(t/are [prop]
|
(t/are [prop]
|
||||||
(t/is (close? (get-in shape-before [:selrect prop])
|
(t/is (close? (get-in shape-before [:selrect prop])
|
||||||
(get-in shape-after [:selrect prop])))
|
(get-in shape-after [:selrect prop])))
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
(let [modifiers {:displacement (gmt/matrix)}
|
(let [modifiers {:displacement (gmt/matrix)}
|
||||||
shape-before (-> (create-test-shape type {:modifiers modifiers})
|
shape-before (-> (create-test-shape type {:modifiers modifiers})
|
||||||
(assoc :selrect selrect))
|
(assoc :selrect selrect))
|
||||||
shape-after (gsh/transform-shape shape-before)]
|
shape-after (gsh/transform-shape shape-before {:round-coords? false})]
|
||||||
(= (:selrect shape-before) (:selrect shape-after)))
|
(= (:selrect shape-before) (:selrect shape-after)))
|
||||||
|
|
||||||
:rect {:x 0 :y 0 :width ##Inf :height ##Inf}
|
:rect {:x 0 :y 0 :width ##Inf :height ##Inf}
|
||||||
|
|
|
@ -266,7 +266,7 @@
|
||||||
(defn apply-transform
|
(defn apply-transform
|
||||||
"Given a new set of points transformed, set up the rectangle so it keeps
|
"Given a new set of points transformed, set up the rectangle so it keeps
|
||||||
its properties. We adjust de x,y,width,height and create a custom transform"
|
its properties. We adjust de x,y,width,height and create a custom transform"
|
||||||
[shape transform]
|
[shape transform round-coords?]
|
||||||
;;
|
;;
|
||||||
(let [points (-> shape :points (transform-points transform))
|
(let [points (-> shape :points (transform-points transform))
|
||||||
center (gco/center-points points)
|
center (gco/center-points points)
|
||||||
|
@ -283,6 +283,11 @@
|
||||||
center
|
center
|
||||||
(:width points-temp-dim)
|
(:width points-temp-dim)
|
||||||
(:height points-temp-dim))
|
(:height points-temp-dim))
|
||||||
|
(cond-> round-coords?
|
||||||
|
(-> (update :x #(mth/precision % 0))
|
||||||
|
(update :y #(mth/precision % 0))
|
||||||
|
(update :width #(mth/precision % 0))
|
||||||
|
(update :height #(mth/precision % 0))))
|
||||||
(update :width max 1)
|
(update :width max 1)
|
||||||
(update :height max 1))
|
(update :height max 1))
|
||||||
|
|
||||||
|
@ -297,11 +302,7 @@
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(-> shape
|
(-> shape
|
||||||
(merge rect-shape)
|
(merge rect-shape)))]
|
||||||
(update :x #(mth/precision % 0))
|
|
||||||
(update :y #(mth/precision % 0))
|
|
||||||
(update :width #(mth/precision % 0))
|
|
||||||
(update :height #(mth/precision % 0))))]
|
|
||||||
(as-> shape $
|
(as-> shape $
|
||||||
(update $ :transform #(gmt/multiply (or % (gmt/matrix)) matrix))
|
(update $ :transform #(gmt/multiply (or % (gmt/matrix)) matrix))
|
||||||
(update $ :transform-inverse #(gmt/multiply matrix-inverse (or % (gmt/matrix))))
|
(update $ :transform-inverse #(gmt/multiply matrix-inverse (or % (gmt/matrix))))
|
||||||
|
@ -347,7 +348,12 @@
|
||||||
%)))
|
%)))
|
||||||
shape))
|
shape))
|
||||||
|
|
||||||
(defn transform-shape [shape]
|
(defn transform-shape
|
||||||
|
([shape]
|
||||||
|
(transform-shape shape nil))
|
||||||
|
|
||||||
|
([shape {:keys [round-coords?]
|
||||||
|
:or {round-coords? true}}]
|
||||||
(let [shape (apply-displacement shape)
|
(let [shape (apply-displacement shape)
|
||||||
center (gco/center-shape shape)
|
center (gco/center-shape shape)
|
||||||
modifiers (:modifiers shape)]
|
modifiers (:modifiers shape)]
|
||||||
|
@ -355,10 +361,10 @@
|
||||||
(let [transform (modifiers->transform center modifiers)]
|
(let [transform (modifiers->transform center modifiers)]
|
||||||
(-> shape
|
(-> shape
|
||||||
(set-flip modifiers)
|
(set-flip modifiers)
|
||||||
(apply-transform transform)
|
(apply-transform transform round-coords?)
|
||||||
(apply-text-resize shape modifiers)
|
(apply-text-resize shape modifiers)
|
||||||
(dissoc :modifiers)))
|
(dissoc :modifiers)))
|
||||||
shape)))
|
shape))))
|
||||||
|
|
||||||
(defn update-group-viewbox
|
(defn update-group-viewbox
|
||||||
"Updates the viewbox for groups imported from SVG's"
|
"Updates the viewbox for groups imported from SVG's"
|
||||||
|
@ -407,5 +413,5 @@
|
||||||
;; need to remove the flip flags
|
;; need to remove the flip flags
|
||||||
(assoc :flip-x false)
|
(assoc :flip-x false)
|
||||||
(assoc :flip-y false)
|
(assoc :flip-y false)
|
||||||
(apply-transform (gmt/matrix)))))
|
(apply-transform (gmt/matrix) true))))
|
||||||
|
|
||||||
|
|
|
@ -461,8 +461,9 @@
|
||||||
(defn merge-modifiers
|
(defn merge-modifiers
|
||||||
[objects modifiers]
|
[objects modifiers]
|
||||||
|
|
||||||
(let [set-modifier (fn [objects [id modifiers]]
|
(let [set-modifier
|
||||||
|
(fn [objects [id modifiers]]
|
||||||
(-> objects
|
(-> objects
|
||||||
(d/update-when id assoc :modifiers modifiers)))]
|
(d/update-when id merge modifiers)))]
|
||||||
(->> modifiers
|
(->> modifiers
|
||||||
(reduce set-modifier objects))))
|
(reduce set-modifier objects))))
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.state-helpers
|
(ns app.main.data.workspace.state-helpers
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]))
|
[app.common.data :as d]
|
||||||
|
[app.common.pages :as cp]))
|
||||||
|
|
||||||
(defn lookup-page-objects
|
(defn lookup-page-objects
|
||||||
([state]
|
([state]
|
||||||
|
@ -26,8 +27,9 @@
|
||||||
|
|
||||||
(defn lookup-selected
|
(defn lookup-selected
|
||||||
[state]
|
[state]
|
||||||
(let [selected (get-in state [:workspace-local :selected])
|
(let [objects (lookup-page-objects state)
|
||||||
objects (lookup-page-objects state)
|
selected (->> (get-in state [:workspace-local :selected])
|
||||||
|
(cp/clean-loops objects))
|
||||||
is-present? (fn [id] (contains? objects id))]
|
is-present? (fn [id] (contains? objects id))]
|
||||||
(into (d/ordered-set)
|
(into (d/ordered-set)
|
||||||
(filter is-present?)
|
(filter is-present?)
|
||||||
|
|
|
@ -72,6 +72,27 @@
|
||||||
:bottom-left [ex sy])]
|
:bottom-left [ex sy])]
|
||||||
(gpt/point x y)))
|
(gpt/point x y)))
|
||||||
|
|
||||||
|
(defn- fix-init-point
|
||||||
|
"Fix the initial point so the resizes are accurate"
|
||||||
|
[initial handler shape]
|
||||||
|
(let [{:keys [x y width height]} (:selrect shape)
|
||||||
|
{:keys [rotation]} shape
|
||||||
|
rotation (or rotation 0)]
|
||||||
|
(if (= rotation 0)
|
||||||
|
(cond-> initial
|
||||||
|
(contains? #{:left :top-left :bottom-left} handler)
|
||||||
|
(assoc :x x)
|
||||||
|
|
||||||
|
(contains? #{:right :top-right :bottom-right} handler)
|
||||||
|
(assoc :x (+ x width))
|
||||||
|
|
||||||
|
(contains? #{:top :top-right :top-left} handler)
|
||||||
|
(assoc :y y)
|
||||||
|
|
||||||
|
(contains? #{:bottom :bottom-right :bottom-left} handler)
|
||||||
|
(assoc :y (+ y height)))
|
||||||
|
initial)))
|
||||||
|
|
||||||
(defn finish-transform []
|
(defn finish-transform []
|
||||||
(ptk/reify ::finish-transform
|
(ptk/reify ::finish-transform
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
@ -84,6 +105,10 @@
|
||||||
(letfn [(resize [shape initial resizing-shapes layout [point lock? point-snap]]
|
(letfn [(resize [shape initial resizing-shapes layout [point lock? point-snap]]
|
||||||
(let [{:keys [width height]} (:selrect shape)
|
(let [{:keys [width height]} (:selrect shape)
|
||||||
{:keys [rotation]} shape
|
{:keys [rotation]} shape
|
||||||
|
rotation (or rotation 0)
|
||||||
|
|
||||||
|
initial (fix-init-point initial handler shape)
|
||||||
|
|
||||||
shapev (-> (gpt/point width height))
|
shapev (-> (gpt/point width height))
|
||||||
|
|
||||||
scale-text (:scale-text layout)
|
scale-text (:scale-text layout)
|
||||||
|
@ -253,6 +278,7 @@
|
||||||
frame-id (cp/frame-id-by-position objects position)
|
frame-id (cp/frame-id-by-position objects position)
|
||||||
|
|
||||||
moving-shapes (->> ids
|
moving-shapes (->> ids
|
||||||
|
(cp/clean-loops objects)
|
||||||
(map #(get objects %))
|
(map #(get objects %))
|
||||||
(remove #(= (:frame-id %) frame-id)))
|
(remove #(= (:frame-id %) frame-id)))
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
[props]
|
[props]
|
||||||
(let [shape (obj/get props "shape")
|
(let [shape (obj/get props "shape")
|
||||||
frame (obj/get props "frame")
|
frame (obj/get props "frame")
|
||||||
shape (-> (geom/transform-shape shape)
|
shape (-> (geom/transform-shape shape {:round-coords? false})
|
||||||
(geom/translate-to-frame frame))
|
(geom/translate-to-frame frame))
|
||||||
opts #js {:shape shape
|
opts #js {:shape shape
|
||||||
:frame frame}
|
:frame frame}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.ui.workspace.viewport
|
(ns app.main.ui.workspace.viewport
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.pages :as cp]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.ui.context :as ctx]
|
[app.main.ui.context :as ctx]
|
||||||
|
@ -61,7 +62,9 @@
|
||||||
options (mf/deref refs/workspace-page-options)
|
options (mf/deref refs/workspace-page-options)
|
||||||
objects (mf/deref refs/workspace-page-objects)
|
objects (mf/deref refs/workspace-page-objects)
|
||||||
object-modifiers (mf/deref refs/workspace-modifiers)
|
object-modifiers (mf/deref refs/workspace-modifiers)
|
||||||
objects (d/deep-merge objects object-modifiers)
|
objects (mf/use-memo
|
||||||
|
(mf/deps objects object-modifiers)
|
||||||
|
#(cp/merge-modifiers objects object-modifiers))
|
||||||
|
|
||||||
;; STATE
|
;; STATE
|
||||||
alt? (mf/use-state false)
|
alt? (mf/use-state false)
|
||||||
|
@ -135,7 +138,9 @@
|
||||||
show-prototypes? (= options-mode :prototype)
|
show-prototypes? (= options-mode :prototype)
|
||||||
show-selection-handlers? (seq selected)
|
show-selection-handlers? (seq selected)
|
||||||
show-snap-distance? (and (contains? layout :dynamic-alignment) (= transform :move) (not (empty? selected)))
|
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-snap-points? (and (or (contains? layout :dynamic-alignment)
|
||||||
|
(contains? layout :snap-grid))
|
||||||
|
(or drawing-obj transform))
|
||||||
show-selrect? (and selrect (empty? drawing))
|
show-selrect? (and selrect (empty? drawing))
|
||||||
show-measures? (and (not transform) (not path-editing?) show-distances?)]
|
show-measures? (and (not transform) (not path-editing?) show-distances?)]
|
||||||
|
|
||||||
|
@ -283,6 +288,7 @@
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:selected selected
|
:selected selected
|
||||||
|
:objects objects
|
||||||
:modifiers modifiers}])
|
:modifiers modifiers}])
|
||||||
|
|
||||||
(when show-snap-distance?
|
(when show-snap-distance?
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
(mf/deps shape)
|
(mf/deps shape)
|
||||||
#(when path? (upf/format-path (:content shape))))
|
#(when path? (upf/format-path (:content shape))))
|
||||||
|
|
||||||
{:keys [id x y width height]} shape
|
{:keys [id x y width height selrect]} shape
|
||||||
|
|
||||||
outline-type (case (:type shape)
|
outline-type (case (:type shape)
|
||||||
:circle "ellipse"
|
:circle "ellipse"
|
||||||
|
@ -53,10 +53,10 @@
|
||||||
{:d path-data
|
{:d path-data
|
||||||
:transform nil}
|
:transform nil}
|
||||||
|
|
||||||
{:x x
|
{:x (:x selrect)
|
||||||
:y y
|
:y (:y selrect)
|
||||||
:width width
|
:width (:width selrect)
|
||||||
:height height})]
|
:height (:height selrect)})]
|
||||||
|
|
||||||
[:> outline-type (map->obj (merge common props))]))
|
[:> outline-type (map->obj (merge common props))]))
|
||||||
|
|
||||||
|
|
|
@ -241,8 +241,7 @@
|
||||||
disable-handlers (obj/get props "disable-handlers")
|
disable-handlers (obj/get props "disable-handlers")
|
||||||
current-transform (mf/deref refs/current-transform)
|
current-transform (mf/deref refs/current-transform)
|
||||||
|
|
||||||
selrect (-> (:selrect shape)
|
selrect (:selrect shape)
|
||||||
minimum-selrect)
|
|
||||||
transform (geom/transform-matrix shape {:no-flip true})]
|
transform (geom/transform-matrix shape {:no-flip true})]
|
||||||
|
|
||||||
(when (not (#{:move :rotate} current-transform))
|
(when (not (#{:move :rotate} current-transform))
|
||||||
|
@ -327,7 +326,7 @@
|
||||||
(mf/defc single-selection-handlers
|
(mf/defc single-selection-handlers
|
||||||
[{:keys [shape zoom color disable-handlers on-move-selected] :as props}]
|
[{:keys [shape zoom color disable-handlers on-move-selected] :as props}]
|
||||||
(let [shape-id (:id shape)
|
(let [shape-id (:id shape)
|
||||||
shape (geom/transform-shape shape)
|
shape (geom/transform-shape shape {:round-coords? false})
|
||||||
|
|
||||||
frame (mf/deref (refs/object-by-id (:frame-id shape)))
|
frame (mf/deref (refs/object-by-id (:frame-id shape)))
|
||||||
frame (when-not (= (:id frame) uuid/zero) frame)
|
frame (when-not (= (:id frame) uuid/zero) frame)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns app.main.ui.workspace.viewport.snap-points
|
(ns app.main.ui.workspace.viewport.snap-points
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.pages :as cp]
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
@ -151,15 +152,25 @@
|
||||||
|
|
||||||
(mf/defc snap-points
|
(mf/defc snap-points
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [layout zoom selected page-id drawing transform modifiers] :as props}]
|
[{:keys [layout zoom objects selected page-id drawing transform modifiers] :as props}]
|
||||||
(let [shapes (mf/deref (refs/objects-by-id selected))
|
|
||||||
filter-shapes (mf/deref refs/selected-shapes-with-children)
|
(let [;; shapes (mf/deref (refs/objects-by-id selected))
|
||||||
|
;; filter-shapes (mf/deref refs/selected-shapes-with-children)
|
||||||
|
|
||||||
|
shapes (->> selected
|
||||||
|
(map #(get objects %))
|
||||||
|
(filterv (comp not nil?)))
|
||||||
|
filter-shapes (into #{}
|
||||||
|
(mapcat #(cp/get-object-with-children % objects))
|
||||||
|
selected)
|
||||||
|
|
||||||
filter-shapes (fn [id]
|
filter-shapes (fn [id]
|
||||||
(if (= id :layout)
|
(if (= id :layout)
|
||||||
(or (not (contains? layout :display-grid))
|
(or (not (contains? layout :display-grid))
|
||||||
(not (contains? layout :snap-grid)))
|
(not (contains? layout :snap-grid)))
|
||||||
(or (filter-shapes id)
|
(or (filter-shapes id)
|
||||||
(not (contains? layout :dynamic-alignment)))))
|
(not (contains? layout :dynamic-alignment)))))
|
||||||
|
|
||||||
shapes (if drawing [drawing] shapes)]
|
shapes (if drawing [drawing] shapes)]
|
||||||
(when (or drawing transform)
|
(when (or drawing transform)
|
||||||
[:& snap-feedback {:shapes shapes
|
[:& snap-feedback {:shapes shapes
|
||||||
|
|
|
@ -88,7 +88,9 @@
|
||||||
|
|
||||||
(defn grid-snap-points
|
(defn grid-snap-points
|
||||||
"Returns the snap points for a given grid"
|
"Returns the snap points for a given grid"
|
||||||
([shape coord] (mapcat #(grid-snap-points shape % coord) (:grids shape)))
|
([shape coord]
|
||||||
|
(mapcat #(grid-snap-points shape % coord) (:grids shape)))
|
||||||
|
|
||||||
([shape {:keys [type display params] :as grid} coord]
|
([shape {:keys [type display params] :as grid} coord]
|
||||||
(when (:display grid)
|
(when (:display grid)
|
||||||
(case type
|
(case type
|
||||||
|
|
|
@ -71,13 +71,23 @@
|
||||||
(fn [frame-id shapes]
|
(fn [frame-id shapes]
|
||||||
{:x (-> (rt/make-tree) (add-coord-data frame-id shapes :x))
|
{:x (-> (rt/make-tree) (add-coord-data frame-id shapes :x))
|
||||||
:y (-> (rt/make-tree) (add-coord-data frame-id shapes :y))})]
|
:y (-> (rt/make-tree) (add-coord-data frame-id shapes :y))})]
|
||||||
|
|
||||||
(d/mapm create-index shapes-data)))
|
(d/mapm create-index shapes-data)))
|
||||||
|
|
||||||
|
;; Attributes that will change the values of their snap
|
||||||
|
(def snap-attrs [:x :y :width :height :selrect :grids])
|
||||||
|
|
||||||
(defn- update-snap-data
|
(defn- update-snap-data
|
||||||
[snap-data old-objects new-objects]
|
[snap-data old-objects new-objects]
|
||||||
|
|
||||||
(let [changed? #(not= (get old-objects %) (get new-objects %))
|
(let [changed? (fn [id]
|
||||||
|
(let [oldv (get old-objects id)
|
||||||
|
newv (get new-objects id)]
|
||||||
|
;; Check first without select-keys because is faster if they are
|
||||||
|
;; the same reference
|
||||||
|
(and (not= oldv newv)
|
||||||
|
(not= (select-keys oldv snap-attrs)
|
||||||
|
(select-keys newv snap-attrs)))))
|
||||||
|
|
||||||
is-deleted-frame? #(and (not= uuid/zero %)
|
is-deleted-frame? #(and (not= uuid/zero %)
|
||||||
(contains? old-objects %)
|
(contains? old-objects %)
|
||||||
(not (contains? new-objects %))
|
(not (contains? new-objects %))
|
||||||
|
@ -119,9 +129,9 @@
|
||||||
:y (rt/make-tree)}))]
|
:y (rt/make-tree)}))]
|
||||||
|
|
||||||
(as-> snap-data $
|
(as-> snap-data $
|
||||||
|
(reduce delete-data $ to-delete)
|
||||||
(reduce add-frames $ frames-to-add)
|
(reduce add-frames $ frames-to-add)
|
||||||
(reduce add-data $ to-add)
|
(reduce add-data $ to-add)
|
||||||
(reduce delete-data $ to-delete)
|
|
||||||
(reduce delete-frames $ frames-to-delete))))
|
(reduce delete-frames $ frames-to-delete))))
|
||||||
|
|
||||||
(defn- log-state
|
(defn- log-state
|
||||||
|
@ -160,8 +170,10 @@
|
||||||
|
|
||||||
(defmethod impl/handler :snaps/update-index
|
(defmethod impl/handler :snaps/update-index
|
||||||
[{:keys [page-id old-objects new-objects] :as message}]
|
[{:keys [page-id old-objects new-objects] :as message}]
|
||||||
;; TODO: Check the difference and update the index acordingly
|
|
||||||
(swap! state update-page page-id old-objects new-objects)
|
(swap! state update-page page-id old-objects new-objects)
|
||||||
|
|
||||||
|
;; Uncomment this to regenerate the index everytime
|
||||||
|
#_(swap! state index-page page-id new-objects)
|
||||||
;; (log-state)
|
;; (log-state)
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue