mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
🐛 Fix export file with components as basic objects
This commit is contained in:
parent
026510c204
commit
88390432f5
3 changed files with 71 additions and 63 deletions
|
@ -15,6 +15,7 @@
|
||||||
[app.common.fressian :as fres]
|
[app.common.fressian :as fres]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
[app.common.types.file :as ctf]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
@ -386,7 +387,6 @@
|
||||||
(def ^:dynamic *options* nil)
|
(def ^:dynamic *options* nil)
|
||||||
|
|
||||||
;; --- EXPORT WRITER
|
;; --- EXPORT WRITER
|
||||||
|
|
||||||
(defn- embed-file-assets
|
(defn- embed-file-assets
|
||||||
[data cfg file-id]
|
[data cfg file-id]
|
||||||
(letfn [(walk-map-form [form state]
|
(letfn [(walk-map-form [form state]
|
||||||
|
@ -498,13 +498,17 @@
|
||||||
:hint "unable to retrieve files for export")))
|
:hint "unable to retrieve files for export")))
|
||||||
|
|
||||||
(defmethod write-section :v1/files
|
(defmethod write-section :v1/files
|
||||||
[{:keys [::output ::embed-assets?] :as cfg}]
|
[{:keys [::output ::embed-assets? ::include-libraries?] :as cfg}]
|
||||||
|
|
||||||
;; Initialize SIDS with empty vector
|
;; Initialize SIDS with empty vector
|
||||||
(vswap! *state* assoc :sids [])
|
(vswap! *state* assoc :sids [])
|
||||||
|
|
||||||
(doseq [file-id (-> *state* deref :files)]
|
(doseq [file-id (-> *state* deref :files)]
|
||||||
(let [file (cond-> (get-file cfg file-id)
|
(let [detach? (and (not embed-assets?) (not include-libraries?))
|
||||||
|
file (cond-> (get-file cfg file-id)
|
||||||
|
detach?
|
||||||
|
(-> (ctf/detach-external-references file-id)
|
||||||
|
(dissoc :libraries))
|
||||||
embed-assets?
|
embed-assets?
|
||||||
(update :data embed-file-assets cfg file-id))
|
(update :data embed-file-assets cfg file-id))
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,10 @@
|
||||||
[app.common.files.features :as ffeat]
|
[app.common.files.features :as ffeat]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[app.common.text :as ct]
|
||||||
[app.common.types.color :as ctc]
|
[app.common.types.color :as ctc]
|
||||||
[app.common.types.colors-list :as ctcl]
|
[app.common.types.colors-list :as ctcl]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
|
@ -1156,3 +1158,61 @@
|
||||||
(validate-shape-not-component shape file page libraries report-error))))))
|
(validate-shape-not-component shape file page libraries report-error))))))
|
||||||
|
|
||||||
@errors))
|
@errors))
|
||||||
|
|
||||||
|
;; Export
|
||||||
|
|
||||||
|
(defn- get-component-ref-file
|
||||||
|
[objects shape]
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(contains? shape :component-file)
|
||||||
|
(get shape :component-file)
|
||||||
|
|
||||||
|
(contains? shape :shape-ref)
|
||||||
|
(recur objects (get objects (:parent-id shape)))
|
||||||
|
|
||||||
|
:else
|
||||||
|
nil))
|
||||||
|
|
||||||
|
(defn detach-external-references
|
||||||
|
[file file-id]
|
||||||
|
(let [detach-text
|
||||||
|
(fn [content]
|
||||||
|
(->> content
|
||||||
|
(ct/transform-nodes
|
||||||
|
#(cond-> %
|
||||||
|
(not= file-id (:fill-color-ref-file %))
|
||||||
|
(dissoc :fill-color-ref-id :fill-color-ref-file)
|
||||||
|
|
||||||
|
(not= file-id (:typography-ref-file %))
|
||||||
|
(dissoc :typography-ref-id :typography-ref-file)))))
|
||||||
|
|
||||||
|
detach-shape
|
||||||
|
(fn [objects shape]
|
||||||
|
(l/debug :hint "detach-shape"
|
||||||
|
:file-id file-id
|
||||||
|
:component-ref-file (get-component-ref-file objects shape)
|
||||||
|
::l/sync? true)
|
||||||
|
(cond-> shape
|
||||||
|
(not= file-id (:fill-color-ref-file shape))
|
||||||
|
(dissoc :fill-color-ref-id :fill-color-ref-file)
|
||||||
|
|
||||||
|
(not= file-id (:stroke-color-ref-file shape))
|
||||||
|
(dissoc :stroke-color-ref-id :stroke-color-ref-file)
|
||||||
|
|
||||||
|
(not= file-id (get-component-ref-file objects shape))
|
||||||
|
(dissoc :component-id :component-file :shape-ref :component-root)
|
||||||
|
|
||||||
|
(= :text (:type shape))
|
||||||
|
(update :content detach-text)))
|
||||||
|
|
||||||
|
detach-objects
|
||||||
|
(fn [objects]
|
||||||
|
(update-vals objects #(detach-shape objects %)))
|
||||||
|
|
||||||
|
detach-pages
|
||||||
|
(fn [pages-index]
|
||||||
|
(update-vals pages-index #(update % :objects detach-objects)))]
|
||||||
|
|
||||||
|
(-> file
|
||||||
|
(update-in [:data :pages-index] detach-pages))))
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
[app.common.media :as cm]
|
[app.common.media :as cm]
|
||||||
[app.common.text :as ct]
|
[app.common.text :as ct]
|
||||||
[app.common.types.components-list :as ctkl]
|
[app.common.types.components-list :as ctkl]
|
||||||
|
[app.common.types.file :as ctf]
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.main.render :as r]
|
[app.main.render :as r]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
|
@ -170,63 +171,6 @@
|
||||||
(let [libraries-ids (->> file-libraries (map :id) (filterv #(not= (:id file) %)))]
|
(let [libraries-ids (->> file-libraries (map :id) (filterv #(not= (:id file) %)))]
|
||||||
(assoc file :libraries libraries-ids)))))))
|
(assoc file :libraries libraries-ids)))))))
|
||||||
|
|
||||||
(defn get-component-ref-file
|
|
||||||
[objects shape]
|
|
||||||
|
|
||||||
(cond
|
|
||||||
(contains? shape :component-file)
|
|
||||||
(get shape :component-file)
|
|
||||||
|
|
||||||
(contains? shape :shape-ref)
|
|
||||||
(recur objects (get objects (:parent-id shape)))
|
|
||||||
|
|
||||||
:else
|
|
||||||
nil))
|
|
||||||
|
|
||||||
(defn detach-external-references
|
|
||||||
[file file-id]
|
|
||||||
(let [detach-text
|
|
||||||
(fn [content]
|
|
||||||
(->> content
|
|
||||||
(ct/transform-nodes
|
|
||||||
#(cond-> %
|
|
||||||
(not= file-id (:fill-color-ref-file %))
|
|
||||||
(dissoc :fill-color-ref-id :fill-color-ref-file)
|
|
||||||
|
|
||||||
(not= file-id (:typography-ref-file %))
|
|
||||||
(dissoc :typography-ref-id :typography-ref-file)))))
|
|
||||||
|
|
||||||
detach-shape
|
|
||||||
(fn [objects shape]
|
|
||||||
(cond-> shape
|
|
||||||
(not= file-id (:fill-color-ref-file shape))
|
|
||||||
(dissoc :fill-color-ref-id :fill-color-ref-file)
|
|
||||||
|
|
||||||
(not= file-id (:stroke-color-ref-file shape))
|
|
||||||
(dissoc :stroke-color-ref-id :stroke-color-ref-file)
|
|
||||||
|
|
||||||
(not= file-id (get-component-ref-file objects shape))
|
|
||||||
(dissoc :component-id :component-file :shape-ref :component-root)
|
|
||||||
|
|
||||||
(= :text (:type shape))
|
|
||||||
(update :content detach-text)))
|
|
||||||
|
|
||||||
detach-objects
|
|
||||||
(fn [objects]
|
|
||||||
(->> objects
|
|
||||||
(d/mapm #(detach-shape objects %2))))
|
|
||||||
|
|
||||||
detach-pages
|
|
||||||
(fn [pages-index]
|
|
||||||
(->> pages-index
|
|
||||||
(d/mapm
|
|
||||||
(fn [_ data]
|
|
||||||
(-> data
|
|
||||||
(update :objects detach-objects))))))]
|
|
||||||
|
|
||||||
(-> file
|
|
||||||
(update-in [:data :pages-index] detach-pages))))
|
|
||||||
|
|
||||||
(defn make-local-external-references
|
(defn make-local-external-references
|
||||||
[file file-id]
|
[file file-id]
|
||||||
(let [detach-text
|
(let [detach-text
|
||||||
|
@ -359,7 +303,7 @@
|
||||||
(update file-id make-local-external-references file-id)
|
(update file-id make-local-external-references file-id)
|
||||||
(update file-id dissoc :libraries)))
|
(update file-id dissoc :libraries)))
|
||||||
:detach (-> (select-keys files [file-id])
|
:detach (-> (select-keys files [file-id])
|
||||||
(update file-id detach-external-references file-id)
|
(update file-id ctf/detach-external-references file-id)
|
||||||
(update file-id dissoc :libraries))))
|
(update file-id dissoc :libraries))))
|
||||||
|
|
||||||
(defn collect-files
|
(defn collect-files
|
||||||
|
|
Loading…
Add table
Reference in a new issue