mirror of
https://github.com/penpot/penpot.git
synced 2025-07-22 23:17:11 +02:00
🐛 Try to remove cases when the thumbnail could be empty
This commit is contained in:
parent
1c54e9fa4d
commit
316b3d4539
2 changed files with 39 additions and 18 deletions
|
@ -114,26 +114,37 @@
|
||||||
|
|
||||||
generate-thumbnail
|
generate-thumbnail
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(fn []
|
(fn generate-thumbnail []
|
||||||
(let [node @node-ref
|
(try
|
||||||
frame-html (dom/node->xml node)
|
(let [node @node-ref]
|
||||||
|
(if (dom/has-children? node)
|
||||||
|
;; The frame-content need to have children in order to generate the thumbnail
|
||||||
|
(let [frame-html (dom/node->xml node)
|
||||||
|
style-node (dom/query (dm/str "#frame-container-" (:id shape) " style"))
|
||||||
|
style-str (or (-> style-node dom/node->xml) "")
|
||||||
|
|
||||||
{:keys [x y width height]} @shape-bb-ref
|
{:keys [x y width height]} @shape-bb-ref
|
||||||
|
viewbox (dm/str x " " y " " width " " height)
|
||||||
|
|
||||||
style-node (dom/query (dm/str "#frame-container-" (:id shape) " style"))
|
svg-node
|
||||||
style-str (or (-> style-node dom/node->xml) "")
|
(-> (dom/make-node "http://www.w3.org/2000/svg" "svg")
|
||||||
|
(dom/set-property! "version" "1.1")
|
||||||
|
(dom/set-property! "viewBox" viewbox)
|
||||||
|
(dom/set-property! "width" width)
|
||||||
|
(dom/set-property! "height" height)
|
||||||
|
(dom/set-property! "fill" "none")
|
||||||
|
(obj/set! "innerHTML" (dm/str style-str frame-html)))
|
||||||
|
|
||||||
svg-node
|
img-src
|
||||||
(-> (dom/make-node "http://www.w3.org/2000/svg" "svg")
|
(-> svg-node dom/node->xml dom/svg->data-uri)]
|
||||||
(dom/set-property! "version" "1.1")
|
|
||||||
(dom/set-property! "viewBox" (dm/str x " " y " " width " " height))
|
|
||||||
(dom/set-property! "width" width)
|
|
||||||
(dom/set-property! "height" height)
|
|
||||||
(dom/set-property! "fill" "none")
|
|
||||||
(obj/set! "innerHTML" (dm/str style-str frame-html)))
|
|
||||||
img-src (-> svg-node dom/node->xml dom/svg->data-uri)]
|
|
||||||
|
|
||||||
(reset! image-url img-src))))
|
(reset! image-url img-src))
|
||||||
|
|
||||||
|
;; Node not yet ready, we schedule a new generation
|
||||||
|
(ts/schedule generate-thumbnail)))
|
||||||
|
|
||||||
|
(catch :default e
|
||||||
|
(.error js/console e)))))
|
||||||
|
|
||||||
on-change-frame
|
on-change-frame
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
|
|
|
@ -264,12 +264,14 @@
|
||||||
(defn append-child!
|
(defn append-child!
|
||||||
[^js el child]
|
[^js el child]
|
||||||
(when (some? el)
|
(when (some? el)
|
||||||
(.appendChild ^js el child)))
|
(.appendChild ^js el child))
|
||||||
|
el)
|
||||||
|
|
||||||
(defn remove-child!
|
(defn remove-child!
|
||||||
[^js el child]
|
[^js el child]
|
||||||
(when (some? el)
|
(when (some? el)
|
||||||
(.removeChild ^js el child)))
|
(.removeChild ^js el child))
|
||||||
|
el)
|
||||||
|
|
||||||
(defn get-first-child
|
(defn get-first-child
|
||||||
[^js el]
|
[^js el]
|
||||||
|
@ -639,3 +641,11 @@
|
||||||
|
|
||||||
{:ascent (.-fontBoundingBoxAscent measure)
|
{:ascent (.-fontBoundingBoxAscent measure)
|
||||||
:descent (.-fontBoundingBoxDescent measure)}))
|
:descent (.-fontBoundingBoxDescent measure)}))
|
||||||
|
|
||||||
|
(defn clone-node
|
||||||
|
[^js node]
|
||||||
|
(.cloneNode node))
|
||||||
|
|
||||||
|
(defn has-children?
|
||||||
|
[^js node]
|
||||||
|
(> (-> node .-children .-length) 0))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue