🐛 Fixes problem with dashboard preview

This commit is contained in:
alonso.torres 2020-04-10 09:31:17 +02:00
parent 1978c6860b
commit 2ab803cebc
3 changed files with 45 additions and 39 deletions

View file

@ -39,36 +39,43 @@
{:width (if (mth/nan? width) 100 width) {:width (if (mth/nan? width) 100 width)
:height (if (mth/nan? height) 100 height)})) :height (if (mth/nan? height) 100 height)}))
(declare frame-shape) (declare shape-wrapper)
(declare group-shape)
(mf/defc frame-wrapper (defn frame-wrapper [objects]
[{:keys [shape objects] :as props}] (mf/fnc frame-wrapper
(let [childs (mapv #(get objects %) (:shapes shape))] [{:keys [shape] :as props}]
[:& frame-shape {:shape shape :childs childs}])) (let [childs (mapv #(get objects %) (:shapes shape))
shape-wrapper (shape-wrapper objects)
frame-shape (frame/frame-shape shape-wrapper)
shape (geom/transform-shape shape)]
[:& frame-shape {:shape shape :childs childs}])))
(mf/defc group-wrapper (defn group-wrapper [objects]
[{:keys [shape-wrapper shape objects] :as props}] (mf/fnc group-wrapper
(let [children (mapv #(get objects %) (:shapes shape))] [{:keys [shape frame] :as props}]
[:& group-shape {:shape shape :children children}])) (let [children (mapv #(get objects %) (:shapes shape))
shape-wrapper (shape-wrapper objects)
group-shape (group/group-shape shape-wrapper)]
[:& group-shape {:frame frame
:shape shape
:children children}])))
(mf/defc shape-wrapper (defn shape-wrapper [objects]
[{:keys [frame shape objects] :as props}] (mf/fnc shape-wrapper
[{:keys [frame shape] :as props}]
(when (and shape (not (:hidden shape))) (when (and shape (not (:hidden shape)))
(let [shape (geom/transform-shape frame shape)] (let [shape (geom/transform-shape frame shape)
opts #js {:shape shape :frame frame}]
(case (:type shape) (case (:type shape)
:curve [:& path/path-shape {:shape shape}] :curve [:> path/path-shape opts]
:text [:& text/text-shape {:shape shape}] :text [:> text/text-shape opts]
:icon [:& icon/icon-shape {:shape shape}] :icon [:> icon/icon-shape opts]
:rect [:& rect/rect-shape {:shape shape}] :rect [:> rect/rect-shape opts]
:path [:& path/path-shape {:shape shape}] :path [:> path/path-shape opts]
:image [:& image/image-shape {:shape shape}] :image [:> image/image-shape opts]
:circle [:& circle/circle-shape {:shape shape}] :circle [:> circle/circle-shape opts]
:group [:& group-wrapper {:shape shape :objects objects}] :group [:> (group-wrapper objects) opts]
nil)))) nil)))))
(def group-shape (group/group-shape shape-wrapper))
(def frame-shape (frame/frame-shape shape-wrapper))
(mf/defc page-svg (mf/defc page-svg
[{:keys [data] :as props}] [{:keys [data] :as props}]
@ -76,7 +83,9 @@
root (get objects uuid/zero) root (get objects uuid/zero)
shapes (->> (:shapes root) shapes (->> (:shapes root)
(map #(get objects %))) (map #(get objects %)))
dim (calculate-dimensions data)] dim (calculate-dimensions data)
frame-wrapper (frame-wrapper objects)
shape-wrapper (shape-wrapper objects)]
[:svg {:view-box (str "0 0 " (:width dim 0) " " (:height dim 0)) [:svg {:view-box (str "0 0 " (:width dim 0) " " (:height dim 0))
:version "1.1" :version "1.1"
:xmlnsXlink "http://www.w3.org/1999/xlink" :xmlnsXlink "http://www.w3.org/1999/xlink"
@ -85,9 +94,7 @@
(for [item shapes] (for [item shapes]
(if (= (:type item) :frame) (if (= (:type item) :frame)
[:& frame-wrapper {:shape item [:& frame-wrapper {:shape item
:key (:id item) :key (:id item)}]
:objects objects}]
[:& shape-wrapper {:shape item [:& shape-wrapper {:shape item
:key (:id item) :key (:id item)}]))]))
:objects objects}]))]))

View file

@ -99,15 +99,14 @@
;; User may also select the frame with single click in the label ;; User may also select the frame with single click in the label
:on-click on-double-click} :on-click on-double-click}
(:name shape)] (:name shape)]
[:& frame-shape {:shape shape [:& frame-shape {:shape (geom/transform-shape shape)
:childs childs}]]))))) :childs childs}]])))))
(defn frame-shape (defn frame-shape
[shape-wrapper] [shape-wrapper]
(mf/fnc frame-shape (mf/fnc frame-shape
[{:keys [shape childs] :as props}] [{:keys [shape childs] :as props}]
(let [shape (geom/transform-shape shape) (let [{:keys [id x y width height]} shape
{:keys [id x y width height]} shape
props (-> (attrs/extract-style-attrs shape) props (-> (attrs/extract-style-attrs shape)
(itr/obj-assign! (itr/obj-assign!

View file

@ -87,7 +87,8 @@
width (* (:width frame) zoom) width (* (:width frame) zoom)
height (* (:height frame) zoom) height (* (:height frame) zoom)
vbox (str "0 0 " (:width frame 0) " " (:height frame 0))] vbox (str "0 0 " (:width frame 0) " " (:height frame 0))
frame-wrapper (exports/frame-wrapper objects)]
[:svg {:view-box vbox [:svg {:view-box vbox
:width width :width width
@ -95,8 +96,7 @@
:version "1.1" :version "1.1"
:xmlnsXlink "http://www.w3.org/1999/xlink" :xmlnsXlink "http://www.w3.org/1999/xlink"
:xmlns "http://www.w3.org/2000/svg"} :xmlns "http://www.w3.org/2000/svg"}
[:& exports/frame-wrapper {:shape frame [:& frame-wrapper {:shape frame
:objects objects
:view-box vbox}]])) :view-box vbox}]]))
(mf/defc thumbnails-summary (mf/defc thumbnails-summary