diff --git a/frontend/src/uxbox/main/data/helpers.cljs b/frontend/src/uxbox/main/data/helpers.cljs index 9a3009aaa..b0ab21386 100644 --- a/frontend/src/uxbox/main/data/helpers.cljs +++ b/frontend/src/uxbox/main/data/helpers.cljs @@ -37,6 +37,23 @@ (:id shape)))] (some check-parenthood (vals objects)))) +(defn calculate-child-parent-map + [objects] + (let [red-fn + (fn [acc {:keys [id shapes]}] + ;; Insert every pair shape -> parent into accumulated value + (into acc (map #(vector % id) (or shapes []))))] + (reduce red-fn {} (vals objects)))) + +(defn get-all-parents + [shape-id objects] + (let [child->parent (calculate-child-parent-map objects) + rec-fn (fn [cur result] + (if-let [parent (child->parent cur)] + (recur parent (conj result parent)) + (vec (reverse result))))] + (rec-fn shape-id []))) + (defn replace-shapes "Replace inside shapes the value `to-replace-id` for the value in items keeping the same order. `to-replace-id` can be a set, a sequable or a single value. Any of these will be changed into a diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index fcc4253ae..00f2b822b 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -1502,20 +1502,21 @@ (let [page-id (::page-id state) objects (get-in state [:workspace-data page-id :objects]) groups-to-adjust (->> ids - (map #(helpers/get-parent % objects)) + (mapcat #(reverse (helpers/get-all-parents % objects))) (map #(get objects %)) (filter #(= (:type %) :group)) (map #(:id %)) distinct) update-group - (fn [group] - (let [group-objects (map #(get objects %) (:shapes group)) + (fn [state group] + (let [objects (get-in state [:workspace-data page-id :objects]) + group-objects (map #(get objects %) (:shapes group)) selrect (geom/selection-rect group-objects)] (merge group (select-keys selrect [:x :y :width :height])))) reduce-fn - #(update-in %1 [:workspace-data page-id :objects %2] update-group)] + #(update-in %1 [:workspace-data page-id :objects %2] (partial update-group %1))] (reduce reduce-fn state groups-to-adjust))) diff --git a/frontend/src/uxbox/main/ui/workspace/selection.cljs b/frontend/src/uxbox/main/ui/workspace/selection.cljs index 68b97766f..eb093f0d2 100644 --- a/frontend/src/uxbox/main/ui/workspace/selection.cljs +++ b/frontend/src/uxbox/main/ui/workspace/selection.cljs @@ -250,10 +250,15 @@ [{:keys [shapes selected zoom] :as props}] (let [shape (geom/selection-rect shapes) on-resize #(do (dom/stop-propagation %2) - (st/emit! (start-resize %1 selected shape)))] + (st/emit! (start-resize %1 selected shape))) + + on-rotate #(do (dom/stop-propagation %) + (println "ROTATE!"))] + [:& controls {:shape shape :zoom zoom - :on-resize on-resize}])) + :on-resize on-resize + :on-rotate on-rotate}])) (mf/defc single-selection-handlers [{:keys [shape zoom objects] :as props}]