mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 00:31:40 +02:00
✨ Import/Export framework first version
This commit is contained in:
parent
d7eec3b92b
commit
bf5f845789
12 changed files with 413 additions and 7 deletions
23
frontend/src/app/libs/file_builder.cljs
Normal file
23
frontend/src/app/libs/file_builder.cljs
Normal file
|
@ -0,0 +1,23 @@
|
|||
;; 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.libs.file-builder
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.file-builder :as fb]))
|
||||
|
||||
(deftype File [^:mutable file]
|
||||
Object
|
||||
(addPage [self name]
|
||||
(set! file (fb/add-page file name))
|
||||
(str (:current-page-id file))))
|
||||
|
||||
|
||||
(defn create-file-export [^string name]
|
||||
(File. (fb/create-file name)))
|
||||
|
||||
(defn exports []
|
||||
#js { :createFile create-file-export })
|
28
frontend/src/app/libs/render.cljs
Normal file
28
frontend/src/app/libs/render.cljs
Normal file
|
@ -0,0 +1,28 @@
|
|||
;; 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.libs.render
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.render :as r]
|
||||
[beicon.core :as rx]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn render-page-export
|
||||
[file ^string page-id]
|
||||
|
||||
;; Better to expose the api as a promise to be consumed from JS
|
||||
(let [page-id (uuid/uuid page-id)
|
||||
file-data (.-file file)
|
||||
data (get-in file-data [:data :pages-index page-id])]
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(->> (r/render-page data)
|
||||
(rx/take 1)
|
||||
(rx/subs resolve reject))) )))
|
||||
|
||||
(defn exports []
|
||||
#js {:renderPage render-page-export})
|
Loading…
Add table
Add a link
Reference in a new issue