🐛 Fix many issues after PR review

This commit is contained in:
Andrey Antukh 2022-03-22 08:12:31 +01:00 committed by Alonso Torres
parent 2f6018c35c
commit 903a9356a9
18 changed files with 243 additions and 99 deletions

View file

@ -21,11 +21,9 @@
[app.main.ui.routes :as rt]
[app.main.worker :as worker]
[app.util.dom :as dom]
[app.util.globals :as glob]
[app.util.i18n :as i18n]
[app.util.theme :as theme]
[beicon.core :as rx]
[cuerdas.core :as str]
[debug]
[potok.core :as ptk]
[rumext.alpha :as mf]))
@ -68,19 +66,12 @@
(rx/take 1)
(rx/map #(ws/initialize)))))))
(def essential-only?
(let [href (.-href ^js glob/location)]
(str/includes? href "essential=t")))
(defn ^:export init
[]
(when-not essential-only?
(worker/init!)
(sentry/init!)
(i18n/init! cf/translations)
(theme/init! cf/themes))
(worker/init!)
(sentry/init!)
(i18n/init! cf/translations)
(theme/init! cf/themes)
(init-ui)
(st/emit! (initialize)))

View file

@ -108,7 +108,7 @@
(defn- send-export-command
[& {:keys [cmd params blob?]}]
(->> (http/send! {:method :post
:uri (u/join base-uri "export")
:uri (u/join base-uri "api/export")
:body (http/transit-data (assoc params :cmd cmd))
:credentials "include"
:response-type (if blob? :blob :text)})
@ -137,7 +137,7 @@
:wait false
:exports exports}]
(->> (http/send! {:method :post
:uri (u/join base-uri "export")
:uri (u/join base-uri "api/export")
:body (http/transit-data params)
:credentials "include"
:response-type :blob})

View file

@ -52,7 +52,9 @@
(mf/defc object-svg
{::mf/wrap [mf/memo]}
[{:keys [objects object-id zoom render-texts?] :or {zoom 1} :as props}]
[{:keys [objects object-id zoom render-texts?]
:or {zoom 1}
:as props}]
(let [object (get objects object-id)
frame-id (if (= :frame (:type object))
(:id object)
@ -70,9 +72,9 @@
objects (reduce updt-fn objects mod-ids)
object (get objects object-id)
object (cond-> object
(:hide-fill-on-export object)
(assoc :fills []))
object (cond-> object
(:hide-fill-on-export object)
(assoc :fills []))
all-children (cph/get-children objects object-id)
@ -100,8 +102,9 @@
render-texts? (and render-texts? (d/seek (comp nil? :position-data) text-shapes))]
(mf/with-effect [width height]
(dom/set-page-style {:size (str (mth/ceil width) "px "
(mth/ceil height) "px")}))
(dom/set-page-style!
{:size (str (mth/ceil width) "px "
(mth/ceil height) "px")}))
[:& (mf/provider embed/context) {:value false}
[:svg {:id "screenshot"

View file

@ -60,7 +60,8 @@
:object-id (first ids)}
exports (mapv #(merge % defaults) exports)]
(if (= 1 (count exports))
(st/emit! (de/request-simple-export {:export (first exports)}))
(let [export (first exports)]
(st/emit! (de/request-simple-export {:export export :filename (:name export)})))
(st/emit! (de/request-multiple-export {:exports exports :filename filename})))))))
;; TODO: maybe move to specific events for avoid to have this logic here?

View file

@ -0,0 +1,76 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) UXBOX Labs SL
(ns app.render
"The main entry point for UI part needed by the exporter."
(:require
[app.common.logging :as log]
[app.common.spec :as us]
[app.common.uri :as u]
[app.config :as cf]
[app.main.ui.render :as render]
[app.util.dom :as dom]
[app.util.globals :as glob]
[clojure.spec.alpha :as s]
[rumext.alpha :as mf]))
(log/initialize!)
(log/set-level! :root :warn)
(log/set-level! :app :info)
(declare reinit)
(declare ^:private render-object)
(log/info :hint "Welcome to penpot (Export)"
:version (:full @cf/version)
:public-uri (str cf/public-uri))
(defn- parse-params
[loc]
(let [href (unchecked-get loc "href")]
(some-> href u/uri :query u/query-string->map)))
(defn init-ui
[]
(when-let [params (parse-params glob/location)]
(when-let [component (case (:route params)
"render-object" (render-object params)
nil)]
(mf/mount component (dom/get-element "app")))))
(defn ^:export init
[]
(init-ui))
(defn reinit
[]
(mf/unmount (dom/get-element "app"))
(init-ui))
(defn ^:dev/after-load after-load
[]
(reinit))
(s/def ::page-id ::us/uuid)
(s/def ::file-id ::us/uuid)
(s/def ::object-id ::us/uuid)
(s/def ::render-text ::us/boolean)
(s/def ::render-object-params
(s/keys :req-un [::file-id ::page-id ::object-id]
:opt-un [::render-text]))
(defn- render-object
[params]
(let [{:keys [page-id file-id object-id render-texts]} (us/conform ::render-object-params params)]
(mf/html
[:& render/render-object
{:file-id file-id
:page-id page-id
:object-id object-id
:render-texts? (and (some? render-texts) (= render-texts "true"))}])))

View file

@ -6,13 +6,14 @@
(ns app.util.dom
(:require
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.util.globals :as globals]
[app.util.object :as obj]
[cuerdas.core :as str]
[goog.dom :as dom]
[promesa.core :as p]))
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.util.globals :as globals]
[app.util.object :as obj]
[cuerdas.core :as str]
[goog.dom :as dom]
[promesa.core :as p]))
;; --- Deprecated methods
@ -33,25 +34,25 @@
;; --- New methods
(declare get-elements-by-tag)
(defn set-html-title
[^string title]
(set! (.-title globals/document) title))
(defn set-page-style
[style]
(let [head (first (.getElementsByTagName ^js globals/document "head"))
style-str (str/join "\n"
(map (fn [[k v]]
(str (name k) ": " v ";"))
style))]
(.insertAdjacentHTML head "beforeend"
(str "<style>"
" @page {" style-str "}"
" html, body {" ; Fix issue having Chromium to add random 1px margin at the bottom
" overflow: hidden;" ; https://github.com/puppeteer/puppeteer/issues/2278#issuecomment-410381934
" font-size: 0;"
" }"
"</style>"))))
(defn set-page-style!
[styles]
(let [node (first (get-elements-by-tag globals/document "head"))
style (reduce-kv (fn [res k v]
(conj res (dm/str (str/css-selector k) ":" v ";")))
[]
styles)
style (dm/str "<style>\n"
" @page {" (str/join " " style) "}\n "
" html, body {font-size:0; margin:0; padding:0}\n "
"</style>")]
(.insertAdjacentHTML ^js node "beforeend" style)))
(defn get-element-by-class
([classname]