mirror of
https://github.com/penpot/penpot.git
synced 2025-05-06 19:05:53 +02:00
🐛 Fix vertical positioning.
This commit is contained in:
parent
65c9c46a22
commit
1dfc604cf0
4 changed files with 39 additions and 171 deletions
|
@ -165,115 +165,6 @@
|
||||||
res (cp/process-changes data [chg])]
|
res (cp/process-changes data [chg])]
|
||||||
(t/is (= 0 (count (:objects res))))))
|
(t/is (= 0 (count (:objects res))))))
|
||||||
|
|
||||||
(t/deftest process-change-mod-obj-abs-order
|
|
||||||
(let [id1 (uuid/next)
|
|
||||||
id2 (uuid/next)
|
|
||||||
id3 (uuid/next)
|
|
||||||
data (-> cp/default-page-data
|
|
||||||
(assoc-in [:objects uuid/zero :shapes] [id1 id2 id3]))]
|
|
||||||
|
|
||||||
(t/testing "abs order 1"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :abs-order
|
|
||||||
:id id3
|
|
||||||
:index 0}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id3 id1 id2] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
|
|
||||||
(t/testing "abs order 2"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :abs-order
|
|
||||||
:id id1
|
|
||||||
:index 100}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id2 id3 id1] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
|
|
||||||
(t/testing "abs order 3"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :abs-order
|
|
||||||
:id id3
|
|
||||||
:index 1}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id1 id3 id2] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
(t/deftest process-change-mod-obj-rel-order
|
|
||||||
(let [id1 (uuid/next)
|
|
||||||
id2 (uuid/next)
|
|
||||||
id3 (uuid/next)
|
|
||||||
data (-> cp/default-page-data
|
|
||||||
(assoc-in [:objects uuid/zero :shapes] [id1 id2 id3]))]
|
|
||||||
|
|
||||||
(t/testing "rel order 1"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :rel-order
|
|
||||||
:id id3
|
|
||||||
:loc :down}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id1 id3 id2] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
|
|
||||||
|
|
||||||
(t/testing "rel order 2"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :rel-order
|
|
||||||
:id id1
|
|
||||||
:loc :top}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id2 id3 id1] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
|
|
||||||
(t/testing "rel order 3"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :rel-order
|
|
||||||
:id id2
|
|
||||||
:loc :up}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id1 id3 id2] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
|
|
||||||
(t/testing "rel order 4"
|
|
||||||
(let [chg {:type :mod-obj
|
|
||||||
:id uuid/zero
|
|
||||||
:operations [{:type :rel-order
|
|
||||||
:id id3
|
|
||||||
:loc :bottom}]}
|
|
||||||
res (cp/process-changes data [chg])]
|
|
||||||
|
|
||||||
;; (clojure.pprint/pprint data)
|
|
||||||
;; (clojure.pprint/pprint res)
|
|
||||||
|
|
||||||
(t/is (= [id3 id1 id2] (get-in res [:objects uuid/zero :shapes])))))
|
|
||||||
))
|
|
||||||
|
|
||||||
(t/deftest process-change-move-objects
|
(t/deftest process-change-move-objects
|
||||||
(let [frame-a-id (uuid/custom 1)
|
(let [frame-a-id (uuid/custom 1)
|
||||||
frame-b-id (uuid/custom 2)
|
frame-b-id (uuid/custom 2)
|
||||||
|
|
|
@ -158,19 +158,12 @@
|
||||||
(s/def ::attr keyword?)
|
(s/def ::attr keyword?)
|
||||||
(s/def ::val any?)
|
(s/def ::val any?)
|
||||||
(s/def ::frame-id uuid?)
|
(s/def ::frame-id uuid?)
|
||||||
(s/def ::loc #{:top :bottom :up :down})
|
|
||||||
|
|
||||||
(defmulti operation-spec-impl :type)
|
(defmulti operation-spec-impl :type)
|
||||||
|
|
||||||
(defmethod operation-spec-impl :set [_]
|
(defmethod operation-spec-impl :set [_]
|
||||||
(s/keys :req-un [::attr ::val]))
|
(s/keys :req-un [::attr ::val]))
|
||||||
|
|
||||||
(defmethod operation-spec-impl :abs-order [_]
|
|
||||||
(s/keys :req-un [::id ::index]))
|
|
||||||
|
|
||||||
(defmethod operation-spec-impl :rel-order [_]
|
|
||||||
(s/keys :req-un [::id ::loc]))
|
|
||||||
|
|
||||||
(s/def ::operation (s/multi-spec operation-spec-impl :type))
|
(s/def ::operation (s/multi-spec operation-spec-impl :type))
|
||||||
(s/def ::operations (s/coll-of ::operation))
|
(s/def ::operations (s/coll-of ::operation))
|
||||||
|
|
||||||
|
@ -465,7 +458,6 @@
|
||||||
(reduce remove-from-old-parent $ shapes)
|
(reduce remove-from-old-parent $ shapes)
|
||||||
(reduce update-frame-ids $ (get-in $ [:objects parent-id :shapes]))))))
|
(reduce update-frame-ids $ (get-in $ [:objects parent-id :shapes]))))))
|
||||||
|
|
||||||
|
|
||||||
(defmethod process-operation :set
|
(defmethod process-operation :set
|
||||||
[shape op]
|
[shape op]
|
||||||
(let [attr (:attr op)
|
(let [attr (:attr op)
|
||||||
|
@ -474,32 +466,6 @@
|
||||||
(dissoc shape attr)
|
(dissoc shape attr)
|
||||||
(assoc shape attr val))))
|
(assoc shape attr val))))
|
||||||
|
|
||||||
(defmethod process-operation :abs-order
|
|
||||||
[obj {:keys [id index]}]
|
|
||||||
(assert (vector? (:shapes obj)) ":shapes should be a vector")
|
|
||||||
(update obj :shapes (fn [items]
|
|
||||||
(let [[b a] (->> (remove #(= % id) items)
|
|
||||||
(split-at index))]
|
|
||||||
(vec (concat b [id] a))))))
|
|
||||||
|
|
||||||
|
|
||||||
(defmethod process-operation :rel-order
|
|
||||||
[obj {:keys [id loc] :as change}]
|
|
||||||
(assert (vector? (:shapes obj)) ":shapes should be a vector")
|
|
||||||
(let [shapes (:shapes obj)
|
|
||||||
cindex (d/index-of shapes id)
|
|
||||||
nindex (case loc
|
|
||||||
:top (- (count shapes) 1)
|
|
||||||
:down (max 0 (- cindex 1))
|
|
||||||
:up (min (- (count shapes) 1) (inc cindex))
|
|
||||||
:bottom 0)]
|
|
||||||
(update obj :shapes
|
|
||||||
(fn [shapes]
|
|
||||||
(let [[fst snd] (->> (remove #(= % id) shapes)
|
|
||||||
(split-at nindex))]
|
|
||||||
(d/concat [] fst [id] snd))))))
|
|
||||||
|
|
||||||
|
|
||||||
(defmethod process-operation :default
|
(defmethod process-operation :default
|
||||||
[shape op]
|
[shape op]
|
||||||
(ex/raise :type :operation-not-implemented
|
(ex/raise :type :operation-not-implemented
|
||||||
|
|
|
@ -750,21 +750,31 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
selected (seq (get-in state [:workspace-local :selected]))
|
selected (get-in state [:workspace-local :selected])
|
||||||
|
|
||||||
rchanges (mapv (fn [id]
|
rchanges (mapv (fn [id]
|
||||||
(let [frame-id (get-in objects [id :frame-id])]
|
(let [obj (get objects id)
|
||||||
{:type :mod-obj
|
parent (get objects (:parent-id obj))
|
||||||
:id frame-id
|
shapes (:shapes parent)
|
||||||
:operations [{:type :rel-order :id id :loc loc}]}))
|
cindex (d/index-of shapes id)
|
||||||
|
nindex (case loc
|
||||||
|
:top (count shapes)
|
||||||
|
:down (max 0 (- cindex 1))
|
||||||
|
:up (min (count shapes) (+ (inc cindex) 1))
|
||||||
|
:bottom 0)]
|
||||||
|
{:type :mov-objects
|
||||||
|
:parent-id (:parent-id obj)
|
||||||
|
:frame-id (:frame-id obj)
|
||||||
|
:index nindex
|
||||||
|
:shapes [id]}))
|
||||||
selected)
|
selected)
|
||||||
|
|
||||||
uchanges (mapv (fn [id]
|
uchanges (mapv (fn [id]
|
||||||
(let [frame-id (get-in objects [id :frame-id])
|
(let [obj (get objects id)]
|
||||||
shapes (get-in objects [frame-id :shapes])
|
{:type :mov-objects
|
||||||
cindex (d/index-of shapes id)]
|
:parent-id (:parent-id obj)
|
||||||
{:type :mod-obj
|
:frame-id (:frame-id obj)
|
||||||
:id frame-id
|
:shapes [id]
|
||||||
:operations [{:type :abs-order :id id :index cindex}]}))
|
:index (cph/position-on-parent id objects)}))
|
||||||
selected)]
|
selected)]
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))
|
||||||
|
|
||||||
|
|
|
@ -82,18 +82,19 @@
|
||||||
(d/concat
|
(d/concat
|
||||||
(mapv #(array-map :type :set :attr % :val (get mb %)) added)
|
(mapv #(array-map :type :set :attr % :val (get mb %)) added)
|
||||||
(mapv #(array-map :type :set :attr % :val nil) removed)
|
(mapv #(array-map :type :set :attr % :val nil) removed)
|
||||||
(loop [k (first both)
|
(loop [items (seq both)
|
||||||
r (rest both)
|
result []]
|
||||||
rs []]
|
(if items
|
||||||
(if k
|
(let [k (first items)
|
||||||
(let [vma (get ma k)
|
vma (get ma k)
|
||||||
vmb (get mb k)]
|
vmb (get mb k)]
|
||||||
(if (= vma vmb)
|
(if (= vma vmb)
|
||||||
(recur (first r) (rest r) rs)
|
(recur (next items) result)
|
||||||
(recur (first r) (rest r) (conj rs {:type :set
|
(recur (next items)
|
||||||
|
(conj result {:type :set
|
||||||
:attr k
|
:attr k
|
||||||
:val vmb}))))
|
:val vmb}))))
|
||||||
rs)))))
|
result)))))
|
||||||
|
|
||||||
(defn- generate-changes
|
(defn- generate-changes
|
||||||
[prev curr]
|
[prev curr]
|
||||||
|
|
Loading…
Add table
Reference in a new issue