🎉 Restore page preview on dashboard.

This commit is contained in:
Andrey Antukh 2020-03-25 18:02:03 +01:00
parent 48d7ea4be4
commit 1404057a60

View file

@ -9,6 +9,7 @@
(:require (:require
[cljsjs.react.dom.server] [cljsjs.react.dom.server]
[rumext.alpha :as mf] [rumext.alpha :as mf]
[uxbox.util.uuid :as uuid]
[uxbox.util.math :as mth] [uxbox.util.math :as mth]
[uxbox.main.geom :as geom] [uxbox.main.geom :as geom]
[uxbox.main.ui.shapes.frame :as frame] [uxbox.main.ui.shapes.frame :as frame]
@ -29,13 +30,18 @@
(defn- calculate-dimensions (defn- calculate-dimensions
[data] [data]
(let [shapes (vals (:shapes-by-id data)) (let [shapes (vals (:objects data))
shape (geom/shapes->rect-shape shapes) shape (geom/shapes->rect-shape shapes)
width (+ (:x shape) (:width shape) 100) width (+ (:x shape) (:width shape) 100)
height (+ (:y shape) (:height shape) 100)] height (+ (:y shape) (:height shape) 100)]
{: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)}))
(mf/defc frame-wrapper
[{:keys [shape objects] :as props}]
(let [childs (mapv #(get objects %) (:shapes shape))]
[:& frame/frame-shape {:shape shape :childs childs}]))
(mf/defc shape-wrapper (mf/defc shape-wrapper
[{:keys [shape] :as props}] [{:keys [shape] :as props}]
(when (and shape (not (:hidden shape))) (when (and shape (not (:hidden shape)))
@ -51,20 +57,23 @@
(mf/defc page-svg (mf/defc page-svg
[{:keys [data] :as props}] [{:keys [data] :as props}]
(let [shapes-by-id (:shapes-by-id data) (let [objects (:objects data)
shapes (map #(get shapes-by-id %) (:shapes data [])) root (get objects uuid/zero)
frame (map #(get shapes-by-id %) (:frame data [])) shapes (->> (:shapes root)
(map #(get objects %)))
dim (calculate-dimensions data)] dim (calculate-dimensions data)]
[: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"
:xmlns "http://www.w3.org/2000/svg"} :xmlns "http://www.w3.org/2000/svg"}
[:& background] [:& background]
[:* (for [item (reverse shapes)]
(for [item frame] (if (= (:type item) :frame)
[:& shape-wrapper {:shape item :key (:id item)}]) [:& frame-wrapper {:shape item
(for [item shapes] :key (:id item)
[:& shape-wrapper {:shape item :key (:id item)}])]])) :objects objects}]
[:& shape-wrapper {:shape item
:key (:id item)}]))]))
;; (defn- render-html ;; (defn- render-html
;; [component] ;; [component]