mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 16:08:34 +02: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
|
@ -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))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue