0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

🎉 Render dashbaord thumbnails on webworker.

This commit is contained in:
Andrey Antukh 2020-05-05 19:48:51 +02:00 committed by Alonso Torres
parent f2274d8617
commit adfa117dc0
7 changed files with 41 additions and 35 deletions

View file

@ -124,15 +124,16 @@
(defmethod load-font :google
[{:keys [id family variants ::on-loaded] :as font}]
(js/console.log "[debug:fonts]: loading google font" id)
(let [base (str "https://fonts.googleapis.com/css?family=" family)
variants (str/join "," (map :id variants))
uri (str base ":" variants "&display=block")
node (create-link-node uri)]
(.addEventListener node "load" (fn [event] (when (fn? on-loaded)
(on-loaded id))))
(.append (.-head js/document) node)
nil))
(when (exists? js/window)
(js/console.log "[debug:fonts]: loading google font" id)
(let [base (str "https://fonts.googleapis.com/css?family=" family)
variants (str/join "," (map :id variants))
uri (str base ":" variants "&display=block")
node (create-link-node uri)]
(.addEventListener node "load" (fn [event] (when (fn? on-loaded)
(on-loaded id))))
(.append (.-head js/document) node)
nil)))
(defmethod load-font :default
[{:keys [backend] :as font}]

View file

@ -27,7 +27,6 @@
[uxbox.main.ui.profile.recovery-request :refer [profile-recovery-request-page]]
[uxbox.main.ui.profile.register :refer [profile-register-page]]
[uxbox.main.ui.settings :as settings]
[uxbox.main.ui.shapes]
[uxbox.main.ui.viewer :refer [viewer-page]]
[uxbox.main.ui.workspace :as workspace]
[uxbox.util.i18n :refer [tr]]

View file

@ -1,15 +1,17 @@
(ns uxbox.main.ui.dashboard.grid
(:require
[cuerdas.core :as str]
[beicon.core :as rx]
[rumext.alpha :as mf]
[uxbox.builtins.icons :as i]
[uxbox.main.data.dashboard :as dsh]
[uxbox.main.store :as st]
[uxbox.main.exports :as exports]
[uxbox.main.ui.modal :as modal]
[uxbox.main.ui.keyboard :as kbd]
[uxbox.main.ui.confirm :refer [confirm-dialog]]
[uxbox.main.ui.components.context-menu :refer [context-menu]]
[uxbox.main.worker :as wrk]
[uxbox.main.fonts :as fonts]
[uxbox.util.dom :as dom]
[uxbox.util.i18n :as i18n :refer [t tr]]
[uxbox.util.router :as rt]
@ -19,12 +21,19 @@
;; --- Grid Item Thumbnail
(mf/defc grid-item-thumbnail
{::mf/wrap [#(mf/deferred % ts/schedule-on-idle)]}
{::mf/wrap [mf/memo]}
[{:keys [file] :as props}]
[:div.grid-item-th
[:& exports/page-svg {:data (:data file)
:width "290"
:height "150"}]])
(let [container (mf/use-ref)]
(mf/use-effect
(mf/deps file)
(fn []
(-> (wrk/ask! {:cmd :thumbnails/generate
:data (:data file)})
(rx/subscribe (fn [{:keys [svg fonts]}]
(run! fonts/ensure-loaded! fonts)
(let [node (mf/ref-val container)]
(set! (.-innerHTML node) svg)))))))
[:div.grid-item-th {:ref container}]))
;; --- Grid Item

View file

@ -117,8 +117,8 @@
(mf/defc text-shape
{::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")
shape (unchecked-get props "selected?")
(let [shape (unchecked-get props "shape")
selected? (unchecked-get props "selected?")
{:keys [id x y width height rotation content]} shape]
[:foreignObject {:x x
:y y

View file

@ -7,14 +7,16 @@
(ns uxbox.util.http
"A http client with rx streams interface."
(:refer-clojure :exclude [get])
(:require [beicon.core :as rx]
[goog.events :as events]
[clojure.string :as str])
(:import [goog.net ErrorCode EventType]
[goog.net.XhrIo ResponseType]
[goog.net XhrIo]
[goog.Uri QueryData]
[goog Uri]))
(:require
[beicon.core :as rx]
[goog.events :as events]
[clojure.string :as str])
(:import
[goog.net ErrorCode EventType]
[goog.net.XhrIo ResponseType]
[goog.net XhrIo]
[goog.Uri QueryData]
[goog Uri]))
(defn translate-method
[method]

View file

@ -18,6 +18,7 @@
[uxbox.common.uuid :as uuid]
[uxbox.worker.impl :as impl]
[uxbox.worker.selection]
[uxbox.worker.thumbnails]
[uxbox.util.transit :as t]
[uxbox.util.worker :as w]))

View file

@ -13,22 +13,16 @@
[cljs.spec.alpha :as s]
[uxbox.common.exceptions :as ex]
[uxbox.common.spec :as us]
[uxbox.main.fonts :as fonts]
[uxbox.main.exports :as exports]
[uxbox.worker.impl :as impl]
["react-dom/server" :as rds]))
(mf/defc foobar
[{:keys [name]}]
[:span name])
(defmethod impl/handler :echo
[message]
{:result (rds/renderToString (mf/element foobar {:name "foobar"}))})
(defmethod impl/handler :thumbnails/generate
[{:keys [data] :as message}]
(let [elem (mf/element exports/page-svg #js {:data data
:width "290"
:height "150"})]
(rds/renderToStaticMarkup elem)))
{:svg (rds/renderToStaticMarkup elem)
:fonts @fonts/loaded}))