🐛 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

@ -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"))}])))