mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -05:00
🐛 Fix embed assets in unpublish and export
This commit is contained in:
parent
d99f4f62ea
commit
29d0499725
4 changed files with 24 additions and 60 deletions
|
@ -54,6 +54,7 @@
|
||||||
- Fix 'Detach instance' shortcut is not working [Taiga #8102](https://tree.taiga.io/project/penpot/issue/8102)
|
- Fix 'Detach instance' shortcut is not working [Taiga #8102](https://tree.taiga.io/project/penpot/issue/8102)
|
||||||
- Fix import file message does not detect 0 as error [Taiga #6824](https://tree.taiga.io/project/penpot/issue/6824)
|
- Fix import file message does not detect 0 as error [Taiga #6824](https://tree.taiga.io/project/penpot/issue/6824)
|
||||||
- Image Color Library is not persisted when exporting/importing in .zip [Taiga #8131](https://tree.taiga.io/project/penpot/issue/8131)
|
- Image Color Library is not persisted when exporting/importing in .zip [Taiga #8131](https://tree.taiga.io/project/penpot/issue/8131)
|
||||||
|
- Fix export files including libraries [Taiga #8266](https://tree.taiga.io/project/penpot/issue/8266)
|
||||||
|
|
||||||
## 2.0.3
|
## 2.0.3
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
[app.common.files.migrations :as fmg]
|
[app.common.files.migrations :as fmg]
|
||||||
[app.common.files.validate :as fval]
|
[app.common.files.validate :as fval]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
|
[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]
|
||||||
|
@ -331,54 +332,12 @@
|
||||||
|
|
||||||
(defn embed-assets
|
(defn embed-assets
|
||||||
[cfg data file-id]
|
[cfg data file-id]
|
||||||
(letfn [(walk-map-form [form state]
|
(let [library-ids (get-libraries cfg [file-id])]
|
||||||
(cond
|
(reduce (fn [data library-id]
|
||||||
(uuid? (:fill-color-ref-file form))
|
(let [library (get-file cfg library-id)]
|
||||||
(do
|
(ctf/absorb-assets data (:data library))))
|
||||||
(vswap! state conj [(:fill-color-ref-file form) :colors (:fill-color-ref-id form)])
|
data
|
||||||
(assoc form :fill-color-ref-file file-id))
|
library-ids)))
|
||||||
|
|
||||||
(uuid? (:stroke-color-ref-file form))
|
|
||||||
(do
|
|
||||||
(vswap! state conj [(:stroke-color-ref-file form) :colors (:stroke-color-ref-id form)])
|
|
||||||
(assoc form :stroke-color-ref-file file-id))
|
|
||||||
|
|
||||||
(uuid? (:typography-ref-file form))
|
|
||||||
(do
|
|
||||||
(vswap! state conj [(:typography-ref-file form) :typographies (:typography-ref-id form)])
|
|
||||||
(assoc form :typography-ref-file file-id))
|
|
||||||
|
|
||||||
(uuid? (:component-file form))
|
|
||||||
(do
|
|
||||||
(vswap! state conj [(:component-file form) :components (:component-id form)])
|
|
||||||
(assoc form :component-file file-id))
|
|
||||||
|
|
||||||
:else
|
|
||||||
form))
|
|
||||||
|
|
||||||
(process-group-of-assets [data [lib-id items]]
|
|
||||||
;; NOTE: there is a possibility that shape refers to an
|
|
||||||
;; non-existant file because the file was removed. In this
|
|
||||||
;; case we just ignore the asset.
|
|
||||||
(if-let [lib (get-file cfg lib-id)]
|
|
||||||
(reduce (partial process-asset lib) data items)
|
|
||||||
data))
|
|
||||||
|
|
||||||
(process-asset [lib data [bucket asset-id]]
|
|
||||||
(let [asset (get-in lib [:data bucket asset-id])
|
|
||||||
;; Add a special case for colors that need to have
|
|
||||||
;; correctly set the :file-id prop (pending of the
|
|
||||||
;; refactor that will remove it).
|
|
||||||
asset (cond-> asset
|
|
||||||
(= bucket :colors) (assoc :file-id file-id))]
|
|
||||||
(update data bucket assoc asset-id asset)))]
|
|
||||||
|
|
||||||
(let [assets (volatile! [])]
|
|
||||||
(walk/postwalk #(cond-> % (map? %) (walk-map-form assets)) data)
|
|
||||||
(->> (deref assets)
|
|
||||||
(filter #(as-> (first %) $ (and (uuid? $) (not= $ file-id))))
|
|
||||||
(d/group-by first rest)
|
|
||||||
(reduce (partial process-group-of-assets) data)))))
|
|
||||||
|
|
||||||
(defn- fix-version
|
(defn- fix-version
|
||||||
[file]
|
[file]
|
||||||
|
|
|
@ -130,7 +130,6 @@
|
||||||
(.writeLong output (long data))
|
(.writeLong output (long data))
|
||||||
(swap! *position* + 8))
|
(swap! *position* + 8))
|
||||||
|
|
||||||
|
|
||||||
(defn read-long!
|
(defn read-long!
|
||||||
[^DataInputStream input]
|
[^DataInputStream input]
|
||||||
(let [v (.readLong input)]
|
(let [v (.readLong input)]
|
||||||
|
|
|
@ -633,19 +633,24 @@
|
||||||
"Find all assets of a library that are used in the file, and
|
"Find all assets of a library that are used in the file, and
|
||||||
move them to the file local library."
|
move them to the file local library."
|
||||||
[file-data library-data]
|
[file-data library-data]
|
||||||
(let [used-components (find-asset-type-usages file-data library-data :component)
|
(let [used-components (find-asset-type-usages file-data library-data :component)
|
||||||
used-colors (find-asset-type-usages file-data library-data :color)
|
file-data (cond-> file-data
|
||||||
used-typographies (find-asset-type-usages file-data library-data :typography)]
|
(d/not-empty? used-components)
|
||||||
|
(absorb-components used-components library-data))
|
||||||
|
;; Note that absorbed components may also be using colors
|
||||||
|
;; and typographies. This is the reason of doing this first
|
||||||
|
;; and accumulating file data for the next ones.
|
||||||
|
|
||||||
(cond-> file-data
|
used-colors (find-asset-type-usages file-data library-data :color)
|
||||||
(d/not-empty? used-components)
|
file-data (cond-> file-data
|
||||||
(absorb-components used-components library-data)
|
(d/not-empty? used-colors)
|
||||||
|
(absorb-colors used-colors))
|
||||||
|
|
||||||
(d/not-empty? used-colors)
|
used-typographies (find-asset-type-usages file-data library-data :typography)
|
||||||
(absorb-colors used-colors)
|
file-data (cond-> file-data
|
||||||
|
(d/not-empty? used-typographies)
|
||||||
(d/not-empty? used-typographies)
|
(absorb-typographies used-typographies))]
|
||||||
(absorb-typographies used-typographies))))
|
file-data))
|
||||||
|
|
||||||
;; Debug helpers
|
;; Debug helpers
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue