mirror of
https://github.com/penpot/penpot.git
synced 2026-05-01 14:18:07 +00:00
🐛 Fix restoring component inside flex
This commit is contained in:
parent
f4be117219
commit
c0c8390a7d
@ -375,7 +375,7 @@
|
||||
(rx/filter (ptk/type? ::workspace-initialized))
|
||||
(rx/observe-on :async)
|
||||
(rx/take 1)
|
||||
(rx/map #(dwl/go-to-local-component :id component-id))))
|
||||
(rx/map #(dwl/go-to-local-component :id component-id :update-layout? (:update-layout rparams)))))
|
||||
|
||||
(when (:board-id rparams)
|
||||
(->> stream
|
||||
|
||||
@ -527,14 +527,17 @@
|
||||
(ptk/reify ::restore-component
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
page (dsh/lookup-page state page-id)
|
||||
objects (:objects page)
|
||||
(let [current-file-id (:current-file-id state)
|
||||
local? (= current-file-id library-id)
|
||||
|
||||
ldata (dsh/lookup-file-data state library-id)
|
||||
ldata (dsh/lookup-file-data state library-id)
|
||||
component (get-in ldata [:components component-id])
|
||||
comp-page-id (:main-instance-page component)
|
||||
comp-page (dsh/get-page ldata comp-page-id)
|
||||
objects (:objects comp-page)
|
||||
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(cll/generate-restore-component ldata component-id library-id page objects))
|
||||
(cll/generate-restore-component ldata component-id library-id comp-page objects))
|
||||
|
||||
page-id
|
||||
(->> changes :redo-changes (keep :page-id) first)
|
||||
@ -543,7 +546,8 @@
|
||||
(->> changes :redo-changes (keep :frame-id))]
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(ptk/data-event :layout/update {:page-id page-id :ids frames}))))))
|
||||
(when local?
|
||||
(ptk/data-event :layout/update {:page-id page-id :ids frames})))))))
|
||||
|
||||
|
||||
(defn restore-components
|
||||
@ -671,7 +675,7 @@
|
||||
(dch/commit-changes changes)))))))
|
||||
|
||||
(defn go-to-component-file
|
||||
[file-id component]
|
||||
[file-id component update-layout?]
|
||||
|
||||
(assert (uuid? file-id) "expected an uuid for `file-id`")
|
||||
(assert (ctk/check-component component) "expected a valid component")
|
||||
@ -682,24 +686,34 @@
|
||||
(let [params (-> (rt/get-params state)
|
||||
(assoc :file-id file-id)
|
||||
(assoc :page-id (:main-instance-page component))
|
||||
(assoc :component-id (:id component)))]
|
||||
(assoc :component-id (:id component))
|
||||
(assoc :update-layout update-layout?))]
|
||||
(rx/of (rt/nav :workspace params ::rt/new-window true))))))
|
||||
|
||||
(defn go-to-local-component
|
||||
;; id is the id of the component to go
|
||||
;; additional-ids are ids of additional components on the same page
|
||||
;; that will be selected and zoomed along the main one
|
||||
[& {:keys [id additional-ids] :as options}]
|
||||
;; update-layout? indicates if it should send a :layout/update event
|
||||
;; for the parents of the component
|
||||
[& {:keys [id additional-ids update-layout?] :as options}]
|
||||
(ptk/reify ::go-to-local-component
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [current-page-id (:current-page-id state)
|
||||
data (dsh/lookup-file-data state)
|
||||
objects (dsh/lookup-page-objects state current-page-id)
|
||||
|
||||
|
||||
select-and-zoom
|
||||
(fn [ids]
|
||||
(rx/of (dws/select-shapes ids)
|
||||
dwz/zoom-to-selected-shape))
|
||||
(let [parent-ids (when update-layout?
|
||||
(map #(-> (get objects %) :parent-id) ids))]
|
||||
(rx/of
|
||||
(dws/select-shapes ids)
|
||||
dwz/zoom-to-selected-shape
|
||||
(when update-layout?
|
||||
(ptk/data-event :layout/update {:ids parent-ids})))))
|
||||
|
||||
redirect-to-page
|
||||
(fn [page-id ids]
|
||||
|
||||
@ -451,26 +451,28 @@
|
||||
|
||||
;; When the show-remote is after a restore, the component may still be deleted
|
||||
do-show-remote-component
|
||||
#(when-let [comp (find-component shape true)]
|
||||
(st/emit! (dwl/go-to-component-file library-id comp)))
|
||||
(fn [update-layout?]
|
||||
(when-let [comp (find-component shape true)]
|
||||
(st/emit! (dwl/go-to-component-file library-id comp update-layout?))))
|
||||
|
||||
do-show-component
|
||||
(fn []
|
||||
(fn [_ update-layout?]
|
||||
(st/emit! dw/hide-context-menu)
|
||||
(if local-component?
|
||||
(do-show-local-component)
|
||||
(do-show-remote-component)))
|
||||
(do-show-remote-component update-layout?)))
|
||||
|
||||
do-restore-component
|
||||
#(let [;; Extract a map of component-id -> component-file in order to avoid duplicates
|
||||
comps-to-restore (reduce (fn [id-file-map {:keys [component-id component-file]}]
|
||||
(assoc id-file-map component-id component-file))
|
||||
{}
|
||||
restorable-copies)]
|
||||
(fn []
|
||||
(let [;; Extract a map of component-id -> component-file in order to avoid duplicates
|
||||
comps-to-restore (reduce (fn [id-file-map {:keys [component-id component-file]}]
|
||||
(assoc id-file-map component-id component-file))
|
||||
{}
|
||||
restorable-copies)]
|
||||
|
||||
(st/emit! (dwl/restore-components comps-to-restore))
|
||||
(when (= 1 (count comps-to-restore))
|
||||
(ts/schedule 1000 do-show-component)))
|
||||
(st/emit! (dwl/restore-components comps-to-restore))
|
||||
(when (= 1 (count comps-to-restore))
|
||||
(ts/schedule 1000 #(do-show-component nil true)))))
|
||||
|
||||
menu-entries [(when (and (or (not multi) same-variant?) main-instance?)
|
||||
{:title (tr "workspace.shape.menu.show-in-assets")
|
||||
|
||||
@ -87,7 +87,7 @@
|
||||
(dom/stop-propagation event)
|
||||
(if is-local
|
||||
(st/emit! (dwl/go-to-local-component :id component-id))
|
||||
(st/emit! (dwl/go-to-component-file file-id component)))))
|
||||
(st/emit! (dwl/go-to-component-file file-id component false)))))
|
||||
|
||||
on-drop
|
||||
(mf/use-fn
|
||||
@ -537,7 +537,7 @@
|
||||
(if is-local
|
||||
(st/emit! (dwl/go-to-local-component :id current-component-id))
|
||||
(let [component (d/seek #(= (:id %) current-component-id) components)]
|
||||
(st/emit! (dwl/go-to-component-file file-id component))))))
|
||||
(st/emit! (dwl/go-to-component-file file-id component false))))))
|
||||
|
||||
on-asset-click
|
||||
(mf/use-fn (mf/deps groups on-asset-click) (partial on-asset-click groups))
|
||||
|
||||
@ -433,7 +433,8 @@
|
||||
(st/emit! (dwl/go-to-local-component {:id (first ids)
|
||||
:additional-ids (rest ids)}))
|
||||
(st/emit! (dwl/go-to-component-file (:component-file shape)
|
||||
(first duplicated-comps))))))
|
||||
(first duplicated-comps)
|
||||
false)))))
|
||||
|
||||
select-malformed-comps
|
||||
(mf/use-fn
|
||||
@ -442,7 +443,7 @@
|
||||
(let [ids (map :id malformed-comps)]
|
||||
(if (= current-file-id (:component-file shape))
|
||||
(st/emit! (dwl/go-to-local-component :id (first ids) :additional-ids (rest ids)))
|
||||
(st/emit! (dwl/go-to-component-file (:component-file shape) (first malformed-comps)))))))
|
||||
(st/emit! (dwl/go-to-component-file (:component-file shape) (first malformed-comps) false))))))
|
||||
|
||||
switch-component
|
||||
(mf/use-fn
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user