mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 17:00:36 -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.logging :as l]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
|
@ -386,7 +387,6 @@
|
|||
(def ^:dynamic *options* nil)
|
||||
|
||||
;; --- EXPORT WRITER
|
||||
|
||||
(defn- embed-file-assets
|
||||
[data cfg file-id]
|
||||
(letfn [(walk-map-form [form state]
|
||||
|
@ -498,13 +498,17 @@
|
|||
:hint "unable to retrieve files for export")))
|
||||
|
||||
(defmethod write-section :v1/files
|
||||
[{:keys [::output ::embed-assets?] :as cfg}]
|
||||
[{:keys [::output ::embed-assets? ::include-libraries?] :as cfg}]
|
||||
|
||||
;; Initialize SIDS with empty vector
|
||||
(vswap! *state* assoc :sids [])
|
||||
|
||||
(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?
|
||||
(update :data embed-file-assets cfg file-id))
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
[app.common.files.features :as ffeat]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logging :as l]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.text :as ct]
|
||||
[app.common.types.color :as ctc]
|
||||
[app.common.types.colors-list :as ctcl]
|
||||
[app.common.types.component :as ctk]
|
||||
|
@ -981,7 +983,7 @@
|
|||
(report-error :missing-component-root
|
||||
(str/format "Referenced shape %s not found in near component" (:shape-ref shape))
|
||||
shape file page))))
|
||||
|
||||
|
||||
(defn validate-component-not-ref
|
||||
"Validate that this shape does not reference other one."
|
||||
[shape file page report-error]
|
||||
|
@ -1072,7 +1074,7 @@
|
|||
|
||||
(defn validate-shape
|
||||
"Validate referential integrity and semantic coherence of a shape and all its children.
|
||||
|
||||
|
||||
The context is the situation of the parent in respect to components:
|
||||
:not-component
|
||||
:main-top
|
||||
|
@ -1156,3 +1158,61 @@
|
|||
(validate-shape-not-component shape file page libraries report-error))))))
|
||||
|
||||
@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.text :as ct]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.config :as cfg]
|
||||
[app.main.render :as r]
|
||||
[app.main.repo :as rp]
|
||||
|
@ -170,63 +171,6 @@
|
|||
(let [libraries-ids (->> file-libraries (map :id) (filterv #(not= (:id file) %)))]
|
||||
(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
|
||||
[file file-id]
|
||||
(let [detach-text
|
||||
|
@ -359,7 +303,7 @@
|
|||
(update file-id make-local-external-references file-id)
|
||||
(update file-id dissoc :libraries)))
|
||||
: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))))
|
||||
|
||||
(defn collect-files
|
||||
|
|
Loading…
Reference in a new issue