mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 12:06:38 +02:00
✨ Fix dashboard thumbnails for nested frames
This commit is contained in:
parent
566dde21a5
commit
ca326ac231
5 changed files with 50 additions and 17 deletions
|
@ -9,6 +9,7 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.pages.migrations :as pmg]
|
[app.common.pages.migrations :as pmg]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
@ -289,7 +290,7 @@
|
||||||
frame (-> page :objects cph/get-frames)]
|
frame (-> page :objects cph/get-frames)]
|
||||||
(assoc frame :page-id (:id page)))))
|
(assoc frame :page-id (:id page)))))
|
||||||
|
|
||||||
;; function responsible to filter objects data strucuture of
|
;; function responsible to filter objects data structure of
|
||||||
;; all unneded shapes if a concrete frame is provided. If no
|
;; all unneded shapes if a concrete frame is provided. If no
|
||||||
;; frame, the objects is returned untouched.
|
;; frame, the objects is returned untouched.
|
||||||
(filter-objects [objects frame-id]
|
(filter-objects [objects frame-id]
|
||||||
|
@ -307,10 +308,24 @@
|
||||||
object-id (str page-id frame-id)
|
object-id (str page-id frame-id)
|
||||||
frame (if-let [thumb (get thumbnails object-id)]
|
frame (if-let [thumb (get thumbnails object-id)]
|
||||||
(assoc frame :thumbnail thumb :shapes [])
|
(assoc frame :thumbnail thumb :shapes [])
|
||||||
(dissoc frame :thumbnail))]
|
(dissoc frame :thumbnail))
|
||||||
|
|
||||||
|
children-ids
|
||||||
|
(cph/get-children-ids objects frame-id)
|
||||||
|
|
||||||
|
bounds
|
||||||
|
(when (:show-content frame)
|
||||||
|
(gsh/selection-rect (->> children-ids (map (d/getf objects)))))
|
||||||
|
|
||||||
|
frame
|
||||||
|
(cond-> frame
|
||||||
|
(some? bounds)
|
||||||
|
(assoc :children-bounds bounds))]
|
||||||
|
|
||||||
(if (:thumbnail frame)
|
(if (:thumbnail frame)
|
||||||
(recur (-> (assoc objects frame-id frame)
|
(recur (-> objects
|
||||||
(d/without-keys (cph/get-children-ids objects frame-id)))
|
(assoc frame-id frame)
|
||||||
|
(d/without-keys children-ids))
|
||||||
(rest frames))
|
(rest frames))
|
||||||
(recur (assoc objects frame-id frame)
|
(recur (assoc objects frame-id frame)
|
||||||
(rest frames))))
|
(rest frames))))
|
||||||
|
|
|
@ -172,6 +172,7 @@
|
||||||
(dm/export gtr/merge-modifiers)
|
(dm/export gtr/merge-modifiers)
|
||||||
(dm/export gtr/transform-shape)
|
(dm/export gtr/transform-shape)
|
||||||
(dm/export gtr/transform-selrect)
|
(dm/export gtr/transform-selrect)
|
||||||
|
(dm/export gtr/transform-selrect-matrix)
|
||||||
(dm/export gtr/transform-bounds)
|
(dm/export gtr/transform-bounds)
|
||||||
(dm/export gtr/modifiers->transform)
|
(dm/export gtr/modifiers->transform)
|
||||||
(dm/export gtr/empty-modifiers?)
|
(dm/export gtr/empty-modifiers?)
|
||||||
|
|
|
@ -645,6 +645,13 @@
|
||||||
(transform-bounds center modifiers)
|
(transform-bounds center modifiers)
|
||||||
(gpr/points->selrect))))
|
(gpr/points->selrect))))
|
||||||
|
|
||||||
|
(defn transform-selrect-matrix
|
||||||
|
[selrect mtx]
|
||||||
|
(-> selrect
|
||||||
|
(gpr/rect->points)
|
||||||
|
(gco/transform-points mtx)
|
||||||
|
(gpr/points->selrect)))
|
||||||
|
|
||||||
(defn selection-rect
|
(defn selection-rect
|
||||||
"Returns a rect that contains all the shapes and is aware of the
|
"Returns a rect that contains all the shapes and is aware of the
|
||||||
rotation of each shape. Mainly used for multiple selection."
|
rotation of each shape. Mainly used for multiple selection."
|
||||||
|
|
|
@ -61,8 +61,12 @@
|
||||||
|
|
||||||
(defn- calculate-dimensions
|
(defn- calculate-dimensions
|
||||||
[objects]
|
[objects]
|
||||||
(let [shapes (cph/get-immediate-children objects)
|
(let [rect
|
||||||
rect (gsh/selection-rect shapes)]
|
(->> (cph/get-immediate-children objects)
|
||||||
|
(map #(if (some? (:children-bounds %))
|
||||||
|
(:children-bounds %)
|
||||||
|
(:selrect %)))
|
||||||
|
(gsh/join-selrects))]
|
||||||
(-> rect
|
(-> rect
|
||||||
(update :x mth/finite 0)
|
(update :x mth/finite 0)
|
||||||
(update :y mth/finite 0)
|
(update :y mth/finite 0)
|
||||||
|
@ -77,9 +81,12 @@
|
||||||
frame-shape (frame/frame-shape shape-wrapper)]
|
frame-shape (frame/frame-shape shape-wrapper)]
|
||||||
(mf/fnc frame-wrapper
|
(mf/fnc frame-wrapper
|
||||||
[{:keys [shape] :as props}]
|
[{:keys [shape] :as props}]
|
||||||
|
|
||||||
(let [childs (mapv #(get objects %) (:shapes shape))
|
(let [childs (mapv #(get objects %) (:shapes shape))
|
||||||
shape (gsh/transform-shape shape)]
|
shape (gsh/transform-shape shape)]
|
||||||
[:& frame-shape {:shape shape :childs childs}]))))
|
(if (some? (:thumbnail shape))
|
||||||
|
[:& frame/frame-thumbnail {:shape shape :bounds (:children-bounds shape)}]
|
||||||
|
[:& frame-shape {:shape shape :childs childs}])))))
|
||||||
|
|
||||||
(defn group-wrapper-factory
|
(defn group-wrapper-factory
|
||||||
[objects]
|
[objects]
|
||||||
|
@ -251,7 +258,7 @@
|
||||||
(cond
|
(cond
|
||||||
(and frame? thumbnails? (some? (:thumbnail item)))
|
(and frame? thumbnails? (some? (:thumbnail item)))
|
||||||
[:> shape-container {:shape item}
|
[:> shape-container {:shape item}
|
||||||
[:& frame/frame-thumbnail {:shape item}]]
|
[:& frame/frame-thumbnail {:shape item :bounds (:children-bounds item)}]]
|
||||||
|
|
||||||
frame?
|
frame?
|
||||||
[:> shape-container {:shape item}
|
[:> shape-container {:shape item}
|
||||||
|
@ -271,9 +278,11 @@
|
||||||
(let [frame-id (:id frame)
|
(let [frame-id (:id frame)
|
||||||
include-metadata? (mf/use-ctx export/include-metadata-ctx)
|
include-metadata? (mf/use-ctx export/include-metadata-ctx)
|
||||||
|
|
||||||
|
bounds (or (:children-bounds frame) (:selrect frame))
|
||||||
|
|
||||||
modifier
|
modifier
|
||||||
(mf/with-memo [(:x frame) (:y frame)]
|
(mf/with-memo [(:x bounds) (:y bounds)]
|
||||||
(-> (gpt/point (:x frame) (:y frame))
|
(-> (gpt/point (:x bounds) (:y bounds))
|
||||||
(gpt/negate)
|
(gpt/negate)
|
||||||
(gmt/translate-matrix)))
|
(gmt/translate-matrix)))
|
||||||
|
|
||||||
|
@ -292,9 +301,9 @@
|
||||||
(mf/with-memo [objects]
|
(mf/with-memo [objects]
|
||||||
(frame-wrapper-factory objects))
|
(frame-wrapper-factory objects))
|
||||||
|
|
||||||
width (* (:width frame) zoom)
|
width (* (:width bounds) zoom)
|
||||||
height (* (:height frame) zoom)
|
height (* (:height bounds) zoom)
|
||||||
vbox (format-viewbox {:width (:width frame 0) :height (:height frame 0)})]
|
vbox (format-viewbox {:width (:width bounds 0) :height (:height bounds 0)})]
|
||||||
|
|
||||||
[:svg {:view-box vbox
|
[:svg {:view-box vbox
|
||||||
:width (ust/format-precision width viewbox-decimal-precision)
|
:width (ust/format-precision width viewbox-decimal-precision)
|
||||||
|
@ -310,7 +319,7 @@
|
||||||
;; Render the frame thumbnail
|
;; Render the frame thumbnail
|
||||||
(let [frame (gsh/transform-shape frame)]
|
(let [frame (gsh/transform-shape frame)]
|
||||||
[:> shape-container {:shape frame}
|
[:> shape-container {:shape frame}
|
||||||
[:& frame/frame-thumbnail {:shape frame}]]))]))
|
[:& frame/frame-thumbnail {:shape frame :bounds (assoc bounds :x 0 :y 0)}]]))]))
|
||||||
|
|
||||||
|
|
||||||
;; Component for rendering a thumbnail of a single componenent. Mainly
|
;; Component for rendering a thumbnail of a single componenent. Mainly
|
||||||
|
|
|
@ -77,14 +77,15 @@
|
||||||
|
|
||||||
(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?]}]
|
[base-node {:keys [id type masked-group?] :as shape}]
|
||||||
(let [shape-node (dom/query base-node (str "#shape-" id))
|
(let [shape-node (if (= (.-id base-node) (dm/str "shape-" id))
|
||||||
|
base-node
|
||||||
|
(dom/query base-node (dm/str "#shape-" id)))
|
||||||
|
|
||||||
frame? (= :frame type)
|
frame? (= :frame type)
|
||||||
group? (= :group type)
|
group? (= :group type)
|
||||||
text? (= :text type)
|
text? (= :text type)
|
||||||
mask? (and group? masked-group?)]
|
mask? (and group? masked-group?)]
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
frame?
|
frame?
|
||||||
[shape-node
|
[shape-node
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue