mirror of
https://github.com/penpot/penpot.git
synced 2025-07-31 22:08:31 +02:00
Merge pull request #3840 from penpot/hiru-bugfix-components-1
Several related bugfixes
This commit is contained in:
commit
a29291e6f2
5 changed files with 42 additions and 25 deletions
|
@ -770,6 +770,16 @@
|
||||||
(check-shape parent-id [parent-id])
|
(check-shape parent-id [parent-id])
|
||||||
shapes))))
|
shapes))))
|
||||||
|
|
||||||
|
(defmethod components-changed :add-obj
|
||||||
|
[file-data {:keys [parent-id page-id _component-id] :as change}]
|
||||||
|
(when page-id
|
||||||
|
(let [page (ctpl/get-page file-data page-id)
|
||||||
|
parents (map (partial ctn/get-shape page)
|
||||||
|
(cons parent-id (cfh/get-parent-ids (:objects page) parent-id)))
|
||||||
|
xform (comp (filter :main-instance)
|
||||||
|
(map :component-id))]
|
||||||
|
(into #{} xform parents))))
|
||||||
|
|
||||||
(defmethod components-changed :del-obj
|
(defmethod components-changed :del-obj
|
||||||
[file-data {:keys [id page-id _component-id] :as change}]
|
[file-data {:keys [id page-id _component-id] :as change}]
|
||||||
(when page-id
|
(when page-id
|
||||||
|
|
|
@ -345,13 +345,10 @@
|
||||||
force-id
|
force-id
|
||||||
keep-ids?)
|
keep-ids?)
|
||||||
|
|
||||||
;; If frame-id points to a shape inside the component, remap it to the
|
;; Fix empty parent-id and remap all grid cells to the new ids.
|
||||||
;; corresponding new frame shape. If not, set it to the destination frame.
|
|
||||||
;; Also fix empty parent-id.
|
|
||||||
remap-ids
|
remap-ids
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(as-> shape $
|
(as-> shape $
|
||||||
(update $ :frame-id #(get @ids-map % frame-id))
|
|
||||||
(update $ :parent-id #(or % (:frame-id $)))
|
(update $ :parent-id #(or % (:frame-id $)))
|
||||||
(cond-> $
|
(cond-> $
|
||||||
(ctl/grid-layout? shape)
|
(ctl/grid-layout? shape)
|
||||||
|
|
|
@ -354,21 +354,21 @@
|
||||||
the order of the children of each parent."
|
the order of the children of each parent."
|
||||||
|
|
||||||
([object parent-id objects]
|
([object parent-id objects]
|
||||||
(clone-object object parent-id objects (fn [object _] object) (fn [object _] object) nil false true))
|
(clone-object object parent-id objects (fn [object _] object) (fn [object _] object) nil false nil))
|
||||||
|
|
||||||
([object parent-id objects update-new-object]
|
([object parent-id objects update-new-object]
|
||||||
(clone-object object parent-id objects update-new-object (fn [object _] object) nil false true))
|
(clone-object object parent-id objects update-new-object (fn [object _] object) nil false nil))
|
||||||
|
|
||||||
([object parent-id objects update-new-object update-original-object]
|
([object parent-id objects update-new-object update-original-object]
|
||||||
(clone-object object parent-id objects update-new-object update-original-object nil false true))
|
(clone-object object parent-id objects update-new-object update-original-object nil false nil))
|
||||||
|
|
||||||
([object parent-id objects update-new-object update-original-object force-id]
|
([object parent-id objects update-new-object update-original-object force-id]
|
||||||
(clone-object object parent-id objects update-new-object update-original-object force-id false true))
|
(clone-object object parent-id objects update-new-object update-original-object force-id false nil))
|
||||||
|
|
||||||
([object parent-id objects update-new-object update-original-object force-id keep-ids?]
|
([object parent-id objects update-new-object update-original-object force-id keep-ids?]
|
||||||
(clone-object object parent-id objects update-new-object update-original-object force-id keep-ids? true))
|
(clone-object object parent-id objects update-new-object update-original-object force-id keep-ids? nil))
|
||||||
|
|
||||||
([object parent-id objects update-new-object update-original-object force-id keep-ids? calc-frame?]
|
([object parent-id objects update-new-object update-original-object force-id keep-ids? frame-id]
|
||||||
(let [new-id (cond
|
(let [new-id (cond
|
||||||
(some? force-id) force-id
|
(some? force-id) force-id
|
||||||
keep-ids? (:id object)
|
keep-ids? (:id object)
|
||||||
|
@ -378,14 +378,14 @@
|
||||||
;; or the parent's frame-id otherwise. Only for the first cloned shapes. In recursive calls
|
;; or the parent's frame-id otherwise. Only for the first cloned shapes. In recursive calls
|
||||||
;; this is not needed.
|
;; this is not needed.
|
||||||
frame-id (cond
|
frame-id (cond
|
||||||
(and calc-frame? (cfh/frame-shape? objects parent-id))
|
(and (nil? frame-id) (cfh/frame-shape? objects parent-id))
|
||||||
parent-id
|
parent-id
|
||||||
|
|
||||||
calc-frame?
|
(nil? frame-id)
|
||||||
(dm/get-in objects [parent-id :frame-id])
|
(dm/get-in objects [parent-id :frame-id])
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(:frame-id object))]
|
frame-id)]
|
||||||
|
|
||||||
(loop [child-ids (seq (:shapes object))
|
(loop [child-ids (seq (:shapes object))
|
||||||
new-direct-children []
|
new-direct-children []
|
||||||
|
@ -412,12 +412,15 @@
|
||||||
|
|
||||||
[new-object new-objects updated-objects])
|
[new-object new-objects updated-objects])
|
||||||
|
|
||||||
(let [child-id (first child-ids)
|
(let [child-id (first child-ids)
|
||||||
child (get objects child-id)
|
child (get objects child-id)
|
||||||
_ (dm/assert! (some? child))
|
_ (dm/assert! (some? child))
|
||||||
|
frame-id-child (if (cfh/frame-shape? object)
|
||||||
|
new-id
|
||||||
|
(:frame-id object))
|
||||||
|
|
||||||
[new-child new-child-objects updated-child-objects]
|
[new-child new-child-objects updated-child-objects]
|
||||||
(clone-object child new-id objects update-new-object update-original-object nil keep-ids? false)]
|
(clone-object child new-id objects update-new-object update-original-object nil keep-ids? frame-id-child)]
|
||||||
|
|
||||||
(recur
|
(recur
|
||||||
(next child-ids)
|
(next child-ids)
|
||||||
|
|
|
@ -904,7 +904,7 @@
|
||||||
root-main
|
root-main
|
||||||
root-instance)]
|
root-instance)]
|
||||||
(cond-> new-shape
|
(cond-> new-shape
|
||||||
:always
|
(= (:id original-shape) (:id component-shape))
|
||||||
(assoc :frame-id (if (= (:type parent-shape) :frame)
|
(assoc :frame-id (if (= (:type parent-shape) :frame)
|
||||||
(:id parent-shape)
|
(:id parent-shape)
|
||||||
(:frame-id parent-shape)))
|
(:frame-id parent-shape)))
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.record :as cr]
|
[app.common.record :as cr]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
|
[app.common.types.container :as ctn]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
[app.common.types.page :as ctp]
|
[app.common.types.page :as ctp]
|
||||||
[app.common.types.shape.interactions :as ctsi]
|
[app.common.types.shape.interactions :as ctsi]
|
||||||
|
@ -428,14 +429,18 @@
|
||||||
bool? (cfh/bool-shape? obj)
|
bool? (cfh/bool-shape? obj)
|
||||||
new-id (ids-map (:id obj))
|
new-id (ids-map (:id obj))
|
||||||
parent-id (or parent-id frame-id)
|
parent-id (or parent-id frame-id)
|
||||||
|
parent (get objects parent-id)
|
||||||
name (:name obj)
|
name (:name obj)
|
||||||
|
|
||||||
is-component-root? (or (:saved-component-root obj)
|
is-component-root? (or (:saved-component-root obj)
|
||||||
;; Backward compatibility
|
;; Backward compatibility
|
||||||
(:saved-component-root? obj)
|
(:saved-component-root? obj)
|
||||||
(ctk/instance-root? obj))
|
(ctk/instance-root? obj))
|
||||||
duplicating-component? (or duplicating-component? (ctk/instance-head? obj))
|
duplicating-component? (or duplicating-component? (ctk/instance-head? obj))
|
||||||
is-component-main? (ctk/main-instance? obj)
|
is-component-main? (ctk/main-instance? obj)
|
||||||
|
into-component? (and duplicating-component?
|
||||||
|
(ctn/in-any-component? objects parent))
|
||||||
|
|
||||||
regenerate-component
|
regenerate-component
|
||||||
(fn [changes shape]
|
(fn [changes shape]
|
||||||
(let [components-v2 (dm/get-in library-data [:options :components-v2])
|
(let [components-v2 (dm/get-in library-data [:options :components-v2])
|
||||||
|
@ -453,8 +458,10 @@
|
||||||
:main-instance
|
:main-instance
|
||||||
:use-for-thumbnail)
|
:use-for-thumbnail)
|
||||||
|
|
||||||
(cond->
|
(cond-> into-component?
|
||||||
(or frame? group? bool?)
|
(dissoc :component-root))
|
||||||
|
|
||||||
|
(cond-> (or frame? group? bool?)
|
||||||
(assoc :shapes []))
|
(assoc :shapes []))
|
||||||
|
|
||||||
(gsh/move delta)
|
(gsh/move delta)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue