mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 23:46:10 +02:00
✨ Change to penpot file format and fixes
This commit is contained in:
parent
84a7ab8568
commit
7b4603e33e
7 changed files with 77 additions and 51 deletions
|
@ -161,15 +161,15 @@
|
||||||
(->> (uw/ask-many!
|
(->> (uw/ask-many!
|
||||||
{:cmd :export-file
|
{:cmd :export-file
|
||||||
:team-id current-team-id
|
:team-id current-team-id
|
||||||
:files files})
|
:files (->> files (mapv :id))})
|
||||||
(rx/subs
|
(rx/subs
|
||||||
(fn [{:keys [type data] :as msg}]
|
(fn [msg]
|
||||||
(case type
|
(case (:type msg)
|
||||||
:progress
|
:progress
|
||||||
(prn "[Progress]" data)
|
(prn "[Progress]" (:data msg))
|
||||||
|
|
||||||
:finish
|
:finish
|
||||||
(dom/save-as data "export" "application/zip" "Export package (*.zip)"))))))]
|
(dom/trigger-download-uri (:filename msg) (:mtype msg) (:uri msg)))))))]
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
(let [on-file-selected (use-import-file project-id on-finish-import)]
|
(let [on-file-selected (use-import-file project-id on-finish-import)]
|
||||||
[:form.import-file
|
[:form.import-file
|
||||||
[:& file-uploader {:accept "application/zip"
|
[:& file-uploader {:accept ".penpot"
|
||||||
:multi true
|
:multi true
|
||||||
:ref external-ref
|
:ref external-ref
|
||||||
:on-selected on-file-selected}]]))
|
:on-selected on-file-selected}]]))
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
(defn set-styles [attrs shape]
|
(defn set-styles [attrs shape]
|
||||||
(let [custom-attrs (-> (usa/extract-style-attrs shape)
|
(let [custom-attrs (-> (usa/extract-style-attrs shape)
|
||||||
(obj/without ["transform"]))
|
(obj/without ["transform"]))
|
||||||
|
|
||||||
|
attrs (or attrs {})
|
||||||
attrs (cond-> attrs
|
attrs (cond-> attrs
|
||||||
(string? (:style attrs)) usvg/clean-attrs)
|
(string? (:style attrs)) usvg/clean-attrs)
|
||||||
style (obj/merge! (clj->js (:style attrs {}))
|
style (obj/merge! (clj->js (:style attrs {}))
|
||||||
|
|
|
@ -292,6 +292,7 @@
|
||||||
"image/svg+xml" "svg"
|
"image/svg+xml" "svg"
|
||||||
"image/webp" "webp"
|
"image/webp" "webp"
|
||||||
"application/zip" "zip"
|
"application/zip" "zip"
|
||||||
|
"application/penpot" "penpot"
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(defn set-attribute [^js node ^string attr value]
|
(defn set-attribute [^js node ^string attr value]
|
||||||
|
@ -346,11 +347,15 @@
|
||||||
:types [{:description description
|
:types [{:description description
|
||||||
:accept { mtype [(str "." extension)]}}]}]
|
:accept { mtype [(str "." extension)]}}]}]
|
||||||
|
|
||||||
(p/let [file-system (.showSaveFilePicker globals/window (clj->js opts))
|
(-> (p/let [file-system (.showSaveFilePicker globals/window (clj->js opts))
|
||||||
writable (.createWritable file-system)
|
writable (.createWritable file-system)
|
||||||
response (js/fetch uri)
|
response (js/fetch uri)
|
||||||
blob (.blob response)
|
blob (.blob response)
|
||||||
_ (.write writable blob)]
|
_ (.write writable blob)]
|
||||||
(.close writable)))
|
(.close writable))
|
||||||
|
(p/catch
|
||||||
|
#(when-not (and (= (type %) js/DOMException)
|
||||||
|
(= (.-name %) "AbortError"))
|
||||||
|
(trigger-download-uri filename mtype uri)))))
|
||||||
|
|
||||||
(trigger-download-uri filename mtype uri)))
|
(trigger-download-uri filename mtype uri)))
|
||||||
|
|
|
@ -592,8 +592,9 @@
|
||||||
(assoc :grids grids))))
|
(assoc :grids grids))))
|
||||||
|
|
||||||
(defn has-image?
|
(defn has-image?
|
||||||
[type node]
|
[node]
|
||||||
(let [pattern-image
|
(let [type (get-type node)
|
||||||
|
pattern-image
|
||||||
(-> node
|
(-> node
|
||||||
(find-node :defs)
|
(find-node :defs)
|
||||||
(find-node :pattern)
|
(find-node :pattern)
|
||||||
|
|
|
@ -57,14 +57,12 @@
|
||||||
[{:keys [id file-id markup] :as page}]
|
[{:keys [id file-id markup] :as page}]
|
||||||
[(str file-id "/" id ".svg") markup])
|
[(str file-id "/" id ".svg") markup])
|
||||||
|
|
||||||
(defmethod impl/handler :export-file
|
|
||||||
[{:keys [team-id project-id files] :as message}]
|
|
||||||
|
|
||||||
(let [files-ids (->> files (mapv :id))
|
(defn export-file
|
||||||
|
[team-id file-id]
|
||||||
|
|
||||||
files-stream
|
(let [files-stream
|
||||||
(->> (rx/from files-ids)
|
(->> (rp/query :file {:id file-id})
|
||||||
(rx/merge-map #(rp/query :file {:id %}))
|
|
||||||
(rx/reduce #(assoc %1 (:id %2) %2) {})
|
(rx/reduce #(assoc %1 (:id %2) %2) {})
|
||||||
(rx/share))
|
(rx/share))
|
||||||
|
|
||||||
|
@ -87,11 +85,30 @@
|
||||||
|
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(->> render-stream
|
(->> render-stream
|
||||||
(rx/map #(hash-map :type :progress
|
(rx/map #(hash-map
|
||||||
|
:type :progress
|
||||||
|
:file file-id
|
||||||
:data (str "Render " (:file-name %) " - " (:name %)))))
|
:data (str "Render " (:file-name %) " - " (:name %)))))
|
||||||
(->> (rx/merge pages-stream
|
|
||||||
manifest-stream)
|
(->> (rx/merge manifest-stream pages-stream)
|
||||||
(rx/reduce conj [])
|
(rx/reduce conj [])
|
||||||
(rx/flat-map uz/compress-files)
|
(rx/with-latest-from files-stream)
|
||||||
(rx/map #(hash-map :type :finish
|
(rx/flat-map (fn [[data files]]
|
||||||
:data (dom/create-uri %)))))))
|
(->> (uz/compress-files data)
|
||||||
|
(rx/map #(vector (get files file-id) %)))))))))
|
||||||
|
|
||||||
|
(defmethod impl/handler :export-file
|
||||||
|
[{:keys [team-id project-id files] :as message}]
|
||||||
|
|
||||||
|
(->> (rx/from files)
|
||||||
|
(rx/mapcat #(export-file team-id %))
|
||||||
|
(rx/map
|
||||||
|
(fn [value]
|
||||||
|
(if (contains? value :type)
|
||||||
|
value
|
||||||
|
(let [[file export-blob] value]
|
||||||
|
{:type :finish
|
||||||
|
:filename (:name file)
|
||||||
|
:mtype "application/penpot"
|
||||||
|
:description "Penpot export (*.penpot)"
|
||||||
|
:uri (dom/create-uri export-blob)}))))))
|
||||||
|
|
|
@ -118,7 +118,7 @@
|
||||||
(defn resolve-images
|
(defn resolve-images
|
||||||
[file-id node]
|
[file-id node]
|
||||||
(if (and (not (cip/close? node))
|
(if (and (not (cip/close? node))
|
||||||
(cip/has-image? type node))
|
(cip/has-image? node))
|
||||||
(let [name (cip/get-image-name node)
|
(let [name (cip/get-image-name node)
|
||||||
data-uri (cip/get-image-data node)]
|
data-uri (cip/get-image-data node)]
|
||||||
(->> (upload-media-files file-id name data-uri)
|
(->> (upload-media-files file-id name data-uri)
|
||||||
|
@ -162,25 +162,26 @@
|
||||||
pages (->> (:pages file-desc)
|
pages (->> (:pages file-desc)
|
||||||
(mapv #(vector % (get-in index [(keyword %) :name]))))]
|
(mapv #(vector % (get-in index [(keyword %) :name]))))]
|
||||||
(->> (rx/from pages)
|
(->> (rx/from pages)
|
||||||
(rx/flat-map #(process-page file-id zip %))
|
(rx/mapcat #(process-page file-id zip %))
|
||||||
(merge-reduce import-page file)
|
(merge-reduce import-page file)
|
||||||
(rx/flat-map send-changes)
|
(rx/flat-map send-changes)
|
||||||
(rx/ignore))))
|
(rx/ignore))))
|
||||||
|
|
||||||
|
(defn process-package
|
||||||
|
[project-id zip-file]
|
||||||
|
(->> (uz/get-file zip-file "manifest.json")
|
||||||
|
(rx/flat-map (comp :files json/decode :content))
|
||||||
|
(rx/flat-map
|
||||||
|
(fn [[file-id file-desc]]
|
||||||
|
(->> (create-file project-id (:name file-desc))
|
||||||
|
(rx/flat-map #(process-file % file-id file-desc zip-file)))))))
|
||||||
|
|
||||||
(defmethod impl/handler :import-file
|
(defmethod impl/handler :import-file
|
||||||
[{:keys [project-id files]}]
|
[{:keys [project-id files]}]
|
||||||
|
|
||||||
(let [zip-str (->> (rx/from files)
|
(->> (rx/from files)
|
||||||
(rx/flat-map uz/load-from-url)
|
(rx/flat-map uz/load-from-url)
|
||||||
(rx/share))]
|
(rx/flat-map (partial process-package project-id))
|
||||||
|
(rx/catch
|
||||||
(->> zip-str
|
(fn [err]
|
||||||
(rx/flat-map #(uz/get-file % "manifest.json"))
|
(.error js/console "ERROR" err (clj->js (.-data err)))))))
|
||||||
(rx/flat-map (comp :files json/decode :content))
|
|
||||||
(rx/with-latest-from zip-str)
|
|
||||||
(rx/flat-map
|
|
||||||
(fn [[[file-id file-desc] zip]]
|
|
||||||
(->> (create-file project-id (:name file-desc))
|
|
||||||
(rx/flat-map #(process-file % file-id file-desc zip))
|
|
||||||
(rx/catch (fn [err]
|
|
||||||
(.error js/console "ERROR" err (clj->js (.-data err)))))))))))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue