From 69c27ca24dd833b133882b61a1a506d7ed765a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 1 Apr 2020 17:16:40 +0200 Subject: [PATCH] :sparkles: Put new objects at the top --- common/uxbox/common/pages.cljc | 8 +-- frontend/src/uxbox/main/data/workspace.cljs | 51 ------------------- frontend/src/uxbox/main/ui/shapes/frame.cljs | 2 +- .../main/ui/workspace/sidebar/layers.cljs | 4 +- .../src/uxbox/main/ui/workspace/viewport.cljs | 2 +- 5 files changed, 8 insertions(+), 59 deletions(-) diff --git a/common/uxbox/common/pages.cljc b/common/uxbox/common/pages.cljc index d244cf2bd..bab18595e 100644 --- a/common/uxbox/common/pages.cljc +++ b/common/uxbox/common/pages.cljc @@ -247,10 +247,10 @@ (let [shapes (:shapes obj) cindex (d/index-of shapes id) nindex (case loc - :top 0 - :down (min (- (count shapes) 1) (inc cindex)) - :up (max 0 (- cindex 1)) - :bottom (- (count shapes) 1))] + :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) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index aae9035b7..5b1a5e1ab 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -1374,57 +1374,6 @@ ;; --- Shape Vertical Ordering -(declare impl-order-shape) - -;; TODO -(defn order-selected-shapes - [loc] - (us/verify ::direction loc) - (ptk/reify ::move-selected-layer - IBatchedChange - ptk/UpdateEvent - (update [_ state] - (let [id (first (get-in state [:workspace-local :selected])) - type (get-in state [:workspace-data :objects id :type])] - ;; NOTE: multiple selection ordering not supported - (if (and id (not= type :frame)) - (impl-order-shape state id loc) - state))))) - -(defn impl-order-shape - [state sid opt] - (let [shapes (get-in state [:workspace-data :shapes]) - index (case opt - :top 0 - :down (min (- (count shapes) 1) (inc (d/index-of shapes sid))) - :up (max 0 (- (d/index-of shapes sid) 1)) - :bottom (- (count shapes) 1))] - (update-in state [:workspace-data :shapes] - (fn [items] - (let [[fst snd] (->> (remove #(= % sid) items) - (split-at index))] - (into [] (concat fst [sid] snd))))))) - -(defn impl-vertical-order - [state id loc] - (let [page-id (::page-id state) - objects (get-in state [:workspace-data page-id :objects]) - - frame-id (get-in objects [id :frame-id]) - shapes (get-in objects [frame-id :shapes]) - - cindex (d/index-of shapes id) - nindex (case loc - :top 0 - :down (min (- (count shapes) 1) (inc cindex)) - :up (max 0 (- cindex 1)) - :bottom (- (count shapes) 1))] - (update-in state [:workspace-data page-id :objects frame-id :shapes] - (fn [shapes] - (let [[fst snd] (->> (remove #(= % id) shapes) - (split-at nindex))] - (d/concat [] fst [id] snd)))))) - (defn vertical-order-selected [loc] (us/verify ::loc loc) diff --git a/frontend/src/uxbox/main/ui/shapes/frame.cljs b/frontend/src/uxbox/main/ui/shapes/frame.cljs index d645b150a..dc00173c2 100644 --- a/frontend/src/uxbox/main/ui/shapes/frame.cljs +++ b/frontend/src/uxbox/main/ui/shapes/frame.cljs @@ -143,7 +143,7 @@ translate #(translate-to-frame % ds-modifier (gpt/point (- x) (- y)))] [:svg {:x x :y y :width width :height height} [:> "rect" props] - (for [item (reverse childs)] + (for [item childs] [:& shape-wrapper {:shape (translate item) :key (:id item)}])])) (defn- translate-to-frame diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/layers.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/layers.cljs index eee20a131..95c2a6c2a 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/layers.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/layers.cljs @@ -250,7 +250,7 @@ i/arrow-slide]] (when-not collapsed? [:ul - (for [[index id] (d/enumerate (:shapes item))] + (for [[index id] (d/enumerate (reverse (:shapes item)))] (let [item (get objects id)] (if (= (:type item) :frame) [:& layer-frame-item @@ -273,7 +273,7 @@ objects (:objects data) root (get objects uuid/zero)] [:ul.element-list - (for [[index id] (d/enumerate (:shapes root))] + (for [[index id] (d/enumerate (reverse (:shapes root)))] (let [item (get objects id)] (if (= (:type item) :frame) [:& layer-frame-item diff --git a/frontend/src/uxbox/main/ui/workspace/viewport.cljs b/frontend/src/uxbox/main/ui/workspace/viewport.cljs index 5e98983dd..e3bcc7f30 100644 --- a/frontend/src/uxbox/main/ui/workspace/viewport.cljs +++ b/frontend/src/uxbox/main/ui/workspace/viewport.cljs @@ -126,7 +126,7 @@ shapes (->> (:shapes root) (map #(get objects %)))] [:g.shapes - (for [item (reverse shapes)] + (for [item shapes] (if (= (:type item) :frame) [:& frame-wrapper {:shape item :key (:id item)