diff --git a/common/app/common/pages/helpers.cljc b/common/app/common/pages/helpers.cljc index b0cc1b468..53787ac47 100644 --- a/common/app/common/pages/helpers.cljc +++ b/common/app/common/pages/helpers.cljc @@ -175,21 +175,11 @@ ([objects {:keys [include-frames?] :or {include-frames? false}}] (let [lookup #(get objects %) root (lookup uuid/zero) - childs (:shapes root)] - (loop [id (first childs) - ids (rest childs) - res []] - (if (nil? id) - res - (let [obj (lookup id) - typ (:type obj)] - (recur (first ids) - (rest ids) - (if (= :frame typ) - (if include-frames? - (d/concat res [obj] (map lookup (:shapes obj))) - (d/concat res (map lookup (:shapes obj)))) - (conj res obj))))))))) + childs (:shapes root) + shapes (->> childs + (mapv lookup))] + (cond->> shapes + include-frames? (filterv #(not= :frame (:type %))))))) (defn select-frames [objects] diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 278255c52..45ab3be45 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -538,8 +538,6 @@ unames (retrieve-used-names objects) name (generate-unique-name unames (:name shape)) - - frame-id (if (= :frame (:type attrs)) uuid/zero (or (:frame-id attrs) @@ -568,3 +566,31 @@ (when (= :text (:type attrs)) (->> (rx/of (start-edition-mode id)) (rx/observe-on :async)))))))) + +(defn move-shapes-into-frame [frame-id shapes] + (ptk/reify ::move-shapes-into-frame + ptk/WatchEvent + (watch [_ state stream] + (let [page-id (:current-page-id state) + objects (lookup-page-objects state page-id) + to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false}) + (mapv :id) + (d/enumerate) + (filterv (comp shapes second))) + + rchanges [{:type :mov-objects + :parent-id frame-id + :frame-id frame-id + :page-id page-id + :index 0 + :shapes (mapv second to-move-shapes)}] + + uchanges (->> to-move-shapes + (mapv (fn [[index shape-id]] + {:type :mov-objects + :parent-id uuid/zero + :frame-id uuid/zero + :page-id page-id + :index index + :shapes [shape-id]})))] + (rx/of (commit-changes rchanges uchanges {:commit-local? true})))))) diff --git a/frontend/src/app/main/data/workspace/drawing/common.cljs b/frontend/src/app/main/data/workspace/drawing/common.cljs index c5a19c32c..fef13e245 100644 --- a/frontend/src/app/main/data/workspace/drawing/common.cljs +++ b/frontend/src/app/main/data/workspace/drawing/common.cljs @@ -15,7 +15,8 @@ [app.common.geom.shapes :as gsh] [app.main.data.workspace.common :as dwc] [app.main.data.workspace.selection :as dws] - [app.main.streams :as ms])) + [app.main.streams :as ms] + [app.main.worker :as uw])) (def clear-drawing (ptk/reify ::clear-drawing @@ -31,7 +32,8 @@ (rx/concat (rx/of clear-drawing) (when (:initialized? shape) - (let [shape-click-width (case (:type shape) + (let [page-id (:current-page-id state) + shape-click-width (case (:type shape) :text 3 20) shape-click-height (case (:type shape) @@ -59,4 +61,11 @@ (rx/empty)) (rx/of (dws/deselect-all) - (dwc/add-shape shape)))))))))) + (dwc/add-shape shape)) + + (if (= :frame (:type shape)) + (->> (uw/ask! {:cmd :selection/query + :page-id page-id + :rect (:selrect shape)}) + (rx/map #(dwc/move-shapes-into-frame (:id shape) %))) + (rx/empty))))))))))