mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 23:31:21 -05:00
🐛 When creating a frame moves the top-level shapes inside
This commit is contained in:
parent
9ae9da8256
commit
3f887f20e9
3 changed files with 45 additions and 20 deletions
|
@ -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]
|
||||
|
|
|
@ -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}))))))
|
||||
|
|
|
@ -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))))))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue