mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 11:38:24 -05:00
🐛 Fix problems with mask elements modifiers when moving child
This commit is contained in:
parent
24f45fafbf
commit
0d96b5b798
1 changed files with 45 additions and 21 deletions
|
@ -11,6 +11,7 @@
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.hooks :as hooks]
|
[app.main.ui.hooks :as hooks]
|
||||||
|
@ -30,14 +31,14 @@
|
||||||
|
|
||||||
(defn get-nodes
|
(defn get-nodes
|
||||||
"Retrieve the DOM nodes to apply the matrix transformation"
|
"Retrieve the DOM nodes to apply the matrix transformation"
|
||||||
[base-node {:keys [id type masked-group?] :as shape}]
|
[base-node {:keys [id parent-id] :as shape}]
|
||||||
(when (some? base-node)
|
(when (some? base-node)
|
||||||
(let [shape-node (get-shape-node base-node id)
|
(let [shape-node (get-shape-node base-node id)
|
||||||
|
parent-node (get-shape-node base-node parent-id)
|
||||||
frame? (= :frame type)
|
frame? (cph/frame-shape? shape)
|
||||||
group? (= :group type)
|
group? (cph/group-shape? shape)
|
||||||
text? (= :text type)
|
text? (cph/text-shape? shape)
|
||||||
mask? (and group? masked-group?)]
|
masking-child? (:masking-child? (meta shape))]
|
||||||
(cond
|
(cond
|
||||||
frame?
|
frame?
|
||||||
[shape-node
|
[shape-node
|
||||||
|
@ -48,9 +49,10 @@
|
||||||
|
|
||||||
;; For groups we don't want to transform the whole group but only
|
;; For groups we don't want to transform the whole group but only
|
||||||
;; its filters/masks
|
;; its filters/masks
|
||||||
mask?
|
masking-child?
|
||||||
[(dom/query shape-node ".mask-clip-path")
|
[shape-node
|
||||||
(dom/query shape-node ".mask-shape")]
|
(dom/query parent-node ".mask-clip-path")
|
||||||
|
(dom/query parent-node ".mask-shape")]
|
||||||
|
|
||||||
group?
|
group?
|
||||||
(let [shape-defs (dom/query shape-node "defs")]
|
(let [shape-defs (dom/query shape-node "defs")]
|
||||||
|
@ -74,10 +76,12 @@
|
||||||
(-> (dom/get-attribute node "data-old-width") d/parse-double)
|
(-> (dom/get-attribute node "data-old-width") d/parse-double)
|
||||||
(-> (dom/get-attribute node "data-old-height") d/parse-double))
|
(-> (dom/get-attribute node "data-old-height") d/parse-double))
|
||||||
(gsh/transform-selrect modifiers))]
|
(gsh/transform-selrect modifiers))]
|
||||||
(dom/set-attribute! node "x" x)
|
|
||||||
(dom/set-attribute! node "y" y)
|
(when (and (some? x) (some? y) (some? width) (some? height))
|
||||||
(dom/set-attribute! node "width" width)
|
(dom/set-attribute! node "x" x)
|
||||||
(dom/set-attribute! node "height" height)))
|
(dom/set-attribute! node "y" y)
|
||||||
|
(dom/set-attribute! node "width" width)
|
||||||
|
(dom/set-attribute! node "height" height))))
|
||||||
|
|
||||||
(defn start-transform!
|
(defn start-transform!
|
||||||
[base-node shapes]
|
[base-node shapes]
|
||||||
|
@ -169,6 +173,11 @@
|
||||||
(or (= (dom/get-tag-name node) "mask")
|
(or (= (dom/get-tag-name node) "mask")
|
||||||
(= (dom/get-tag-name node) "filter"))
|
(= (dom/get-tag-name node) "filter"))
|
||||||
(do
|
(do
|
||||||
|
(dom/set-attribute! node "x" (dom/get-attribute node "data-old-x"))
|
||||||
|
(dom/set-attribute! node "y" (dom/get-attribute node "data-old-y"))
|
||||||
|
(dom/set-attribute! node "width" (dom/get-attribute node "data-old-width"))
|
||||||
|
(dom/set-attribute! node "height" (dom/get-attribute node "data-old-height"))
|
||||||
|
|
||||||
(dom/remove-attribute! node "data-old-x")
|
(dom/remove-attribute! node "data-old-x")
|
||||||
(dom/remove-attribute! node "data-old-y")
|
(dom/remove-attribute! node "data-old-y")
|
||||||
(dom/remove-attribute! node "data-old-width")
|
(dom/remove-attribute! node "data-old-width")
|
||||||
|
@ -190,6 +199,18 @@
|
||||||
(-> modifiers
|
(-> modifiers
|
||||||
(ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape')))))
|
(ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape')))))
|
||||||
|
|
||||||
|
(defn add-masking-child?
|
||||||
|
"Adds to the object the information about if the current shape is a masking child. We use the metadata
|
||||||
|
to not adding new parameters to the object."
|
||||||
|
[objects]
|
||||||
|
(fn [{:keys [id parent-id] :as shape}]
|
||||||
|
(let [parent (get objects parent-id)
|
||||||
|
masking-child? (and (cph/mask-shape? parent) (= id (first (:shapes parent))))]
|
||||||
|
|
||||||
|
(cond-> shape
|
||||||
|
masking-child?
|
||||||
|
(with-meta {:masking-child? true})))))
|
||||||
|
|
||||||
(defn use-dynamic-modifiers
|
(defn use-dynamic-modifiers
|
||||||
[objects node modifiers]
|
[objects node modifiers]
|
||||||
|
|
||||||
|
@ -198,11 +219,15 @@
|
||||||
(mf/deps modifiers)
|
(mf/deps modifiers)
|
||||||
(fn []
|
(fn []
|
||||||
(when (some? modifiers)
|
(when (some? modifiers)
|
||||||
(d/mapm (fn [id {modifiers :modifiers}]
|
(d/mapm (fn [id {current-modifiers :modifiers}]
|
||||||
(let [shape (get objects id)
|
(let [shape (get objects id)
|
||||||
adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? modifiers)))
|
adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? current-modifiers)))
|
||||||
modifiers (cond-> modifiers adapt-text? (adapt-text-modifiers shape))]
|
|
||||||
(ctm/modifiers->transform modifiers)))
|
current-modifiers
|
||||||
|
(cond-> current-modifiers
|
||||||
|
adapt-text?
|
||||||
|
(adapt-text-modifiers shape))]
|
||||||
|
(ctm/modifiers->transform current-modifiers)))
|
||||||
modifiers))))
|
modifiers))))
|
||||||
|
|
||||||
add-children (mf/use-memo (mf/deps modifiers) #(ctm/added-children-frames modifiers))
|
add-children (mf/use-memo (mf/deps modifiers) #(ctm/added-children-frames modifiers))
|
||||||
|
@ -215,7 +240,7 @@
|
||||||
(fn []
|
(fn []
|
||||||
(->> (keys transforms)
|
(->> (keys transforms)
|
||||||
(filter #(some? (get transforms %)))
|
(filter #(some? (get transforms %)))
|
||||||
(mapv (d/getf objects)))))
|
(mapv (comp (add-masking-child? objects) (d/getf objects))))))
|
||||||
|
|
||||||
prev-shapes (mf/use-var nil)
|
prev-shapes (mf/use-var nil)
|
||||||
prev-modifiers (mf/use-var nil)
|
prev-modifiers (mf/use-var nil)
|
||||||
|
@ -252,7 +277,6 @@
|
||||||
(mf/use-layout-effect
|
(mf/use-layout-effect
|
||||||
(mf/deps transforms)
|
(mf/deps transforms)
|
||||||
(fn []
|
(fn []
|
||||||
|
|
||||||
(let [curr-shapes-set (into #{} (map :id) shapes)
|
(let [curr-shapes-set (into #{} (map :id) shapes)
|
||||||
prev-shapes-set (into #{} (map :id) @prev-shapes)
|
prev-shapes-set (into #{} (map :id) @prev-shapes)
|
||||||
|
|
||||||
|
@ -266,7 +290,7 @@
|
||||||
(update-transform! node shapes transforms modifiers))
|
(update-transform! node shapes transforms modifiers))
|
||||||
|
|
||||||
(when (d/not-empty? removed-shapes)
|
(when (d/not-empty? removed-shapes)
|
||||||
(remove-transform! node @prev-shapes)))
|
(remove-transform! node removed-shapes)))
|
||||||
|
|
||||||
(reset! prev-modifiers modifiers)
|
(reset! prev-modifiers modifiers)
|
||||||
(reset! prev-transforms transforms)
|
(reset! prev-transforms transforms)
|
||||||
|
|
Loading…
Add table
Reference in a new issue