mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 00:58:26 -05:00
✨ Handoff handling nested frames
This commit is contained in:
parent
1bde183c50
commit
e638475a67
4 changed files with 43 additions and 28 deletions
|
@ -277,18 +277,33 @@
|
||||||
(gpt/negate)
|
(gpt/negate)
|
||||||
(gmt/translate-matrix)))
|
(gmt/translate-matrix)))
|
||||||
|
|
||||||
|
children-ids
|
||||||
|
(cph/get-children-ids objects frame-id)
|
||||||
|
|
||||||
objects
|
objects
|
||||||
(mf/with-memo [frame-id objects modifier]
|
(mf/with-memo [frame-id objects modifier]
|
||||||
(let [update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)]
|
(let [update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)]
|
||||||
(->> (cph/get-children-ids objects frame-id)
|
(->> children-ids
|
||||||
(into [frame-id])
|
(into [frame-id])
|
||||||
(reduce update-fn objects))))
|
(reduce update-fn objects))))
|
||||||
|
|
||||||
frame
|
frame
|
||||||
(mf/with-memo [modifier]
|
(mf/with-memo [modifier]
|
||||||
(assoc-in frame [:modifiers :displacement] modifier))
|
(-> frame
|
||||||
|
(assoc-in [:modifiers :displacement] modifier)
|
||||||
|
(gsh/transform-shape)))
|
||||||
|
|
||||||
wrapper
|
bounds
|
||||||
|
(if (:show-content frame)
|
||||||
|
(gsh/selection-rect (concat [frame] (->> children-ids (map (d/getf objects)))))
|
||||||
|
(-> frame :points gsh/points->rect))
|
||||||
|
|
||||||
|
frame
|
||||||
|
(cond-> frame
|
||||||
|
(and (some? bounds) (nil? (:children-bounds bounds)))
|
||||||
|
(assoc :children-bounds bounds))
|
||||||
|
|
||||||
|
frame-wrapper
|
||||||
(mf/with-memo [objects]
|
(mf/with-memo [objects]
|
||||||
(frame-wrapper-factory objects))
|
(frame-wrapper-factory objects))
|
||||||
|
|
||||||
|
@ -296,6 +311,7 @@
|
||||||
height (* (:height bounds) zoom)
|
height (* (:height bounds) zoom)
|
||||||
vbox (format-viewbox {:width (:width bounds 0) :height (:height bounds 0)})]
|
vbox (format-viewbox {:width (:width bounds 0) :height (:height bounds 0)})]
|
||||||
|
|
||||||
|
[:& (mf/provider muc/render-thumbnails) {:value show-thumbnails?}
|
||||||
[:svg {:view-box vbox
|
[:svg {:view-box vbox
|
||||||
:width (ust/format-precision width viewbox-decimal-precision)
|
:width (ust/format-precision width viewbox-decimal-precision)
|
||||||
:height (ust/format-precision height viewbox-decimal-precision)
|
:height (ust/format-precision height viewbox-decimal-precision)
|
||||||
|
@ -304,13 +320,9 @@
|
||||||
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
||||||
:xmlns:penpot (when include-metadata? "https://penpot.app/xmlns")
|
:xmlns:penpot (when include-metadata? "https://penpot.app/xmlns")
|
||||||
:fill "none"}
|
:fill "none"}
|
||||||
(if (or (not show-thumbnails?) (nil? (:thumbnail frame)))
|
|
||||||
[:& wrapper {:shape frame :view-box vbox}]
|
|
||||||
|
|
||||||
;; Render the frame thumbnail
|
|
||||||
(let [frame (gsh/transform-shape frame)]
|
|
||||||
[:> shape-container {:shape frame}
|
[:> shape-container {:shape frame}
|
||||||
[:& frame/frame-thumbnail {:shape frame :bounds (assoc bounds :x 0 :y 0)}]]))]))
|
[:& frame-wrapper {:shape frame :view-box vbox}]]]]))
|
||||||
|
|
||||||
|
|
||||||
;; Component for rendering a thumbnail of a single componenent. Mainly
|
;; Component for rendering a thumbnail of a single componenent. Mainly
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
(ns app.main.ui.shapes.shape
|
(ns app.main.ui.shapes.shape
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.pages.helpers :as cph]
|
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.ui.context :as muc]
|
[app.main.ui.context :as muc]
|
||||||
[app.main.ui.shapes.attrs :as attrs]
|
[app.main.ui.shapes.attrs :as attrs]
|
||||||
|
|
|
@ -30,24 +30,26 @@
|
||||||
(declare shape-container-factory)
|
(declare shape-container-factory)
|
||||||
|
|
||||||
(defn handle-hover-shape
|
(defn handle-hover-shape
|
||||||
[{:keys [type id]} hover?]
|
[shape hover?]
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(when-not (#{:group :frame} type)
|
(when-not (or (cph/group-shape? shape)
|
||||||
|
(cph/root-frame? shape))
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(st/emit! (dv/hover-shape id hover?)))))
|
(st/emit! (dv/hover-shape (:id shape) hover?)))))
|
||||||
|
|
||||||
(defn select-shape [{:keys [type id]}]
|
(defn select-shape [shape]
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(when-not (#{:group :frame} type)
|
(when-not (or (cph/group-shape? shape)
|
||||||
|
(cph/root-frame? shape))
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(cond
|
(cond
|
||||||
(.-shiftKey ^js event)
|
(.-shiftKey ^js event)
|
||||||
(st/emit! (dv/toggle-selection id))
|
(st/emit! (dv/toggle-selection (:id shape)))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(st/emit! (dv/select-shape id))))))
|
(st/emit! (dv/select-shape (:id shape)))))))
|
||||||
|
|
||||||
(defn shape-wrapper-factory
|
(defn shape-wrapper-factory
|
||||||
[component]
|
[component]
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
(ns app.main.ui.viewer.thumbnails
|
(ns app.main.ui.viewer.thumbnails
|
||||||
(:require
|
(:require
|
||||||
[app.common.pages.helpers :as cph]
|
|
||||||
[app.common.geom.shapes :as gsh]
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.pages.helpers :as cph]
|
||||||
[app.main.data.viewer :as dv]
|
[app.main.data.viewer :as dv]
|
||||||
[app.main.render :as render]
|
[app.main.render :as render]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -85,7 +85,8 @@
|
||||||
[:div.thumbnail-preview
|
[:div.thumbnail-preview
|
||||||
{:class (dom/classnames :selected selected?)}
|
{:class (dom/classnames :selected selected?)}
|
||||||
[:& render/frame-svg {:frame (-> frame
|
[:& render/frame-svg {:frame (-> frame
|
||||||
(assoc :thumbnail (get thumbnail-data (dm/str page-id (:id frame)))))
|
(assoc :thumbnail (get thumbnail-data (dm/str page-id (:id frame))))
|
||||||
|
(assoc :children-bounds children-bounds))
|
||||||
:objects objects
|
:objects objects
|
||||||
:show-thumbnails? true}]]
|
:show-thumbnails? true}]]
|
||||||
[:div.thumbnail-info
|
[:div.thumbnail-info
|
||||||
|
|
Loading…
Add table
Reference in a new issue