0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

🐛 Fix lost image colors in library when export/import using zip format

This commit is contained in:
Alejandro Alonso 2024-06-26 19:05:07 +02:00 committed by Alonso Torres
parent 034170afac
commit 40b43c6c5b
3 changed files with 67 additions and 13 deletions

View file

@ -53,7 +53,7 @@
- Fix can't collapse groups when searching in the assets tab [Taiga #8125](https://tree.taiga.io/project/penpot/issue/8125)
- 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)
- Image Color Library is not persisted when exporting/importing in .zip [Taiga #8131](https://tree.taiga.io/project/penpot/issue/8131)
## 2.0.3

View file

@ -93,6 +93,9 @@
(def ^:const color-keys
[:name :color :opacity :gradient :path])
(def ^:const image-color-keys
[:width :height :mtype :name :keep-aspect-ratio])
(def ^:const typography-keys
[:name :font-family :font-id :font-size :font-style :font-variant-id :font-weight
:letter-spacing :line-height :text-transform :path])
@ -102,7 +105,21 @@
(defn collect-color
[result color]
(collect-entries result color color-keys))
(let [id (str (:id color))
basic-data (select-keys color color-keys)
image-color-data (when-let [image-color (:image color)]
(->> (select-keys image-color image-color-keys)))
color-data (cond-> basic-data
(some? image-color-data)
(->
(assoc :image image-color-data)
(assoc-in [:image :id] (str (get-in color [:image :id])))))]
(-> result
(assoc id
(->> color-data
(d/deep-mapm
(fn [[k v]]
[(-> k str/camel) v])))))))
(defn collect-typography
[result typography]
@ -114,11 +131,25 @@
(defn parse-library-color
[[file-id colors]]
(let [markup
(->> (vals colors)
(reduce collect-color {})
(json/encode))]
[(str file-id "/colors.json") markup]))
(rx/merge
(let [markup
(->> (vals colors)
(reduce collect-color {})
(json/encode))]
(rx/of (vector (str file-id "/colors.json") markup)))
(->> (rx/from (vals colors))
(rx/map :image)
(rx/filter d/not-empty?)
(rx/merge-map
(fn [image-color]
(let [file-path (str/concat file-id "/colors/" (:id image-color) (cm/mtype->extension (:mtype image-color)))]
(->> (http/send!
{:uri (cfg/resolve-file-media image-color)
:response-type :blob
:method :get})
(rx/map :body)
(rx/map #(vector file-path %)))))))))
(defn parse-library-typographies
[[file-id typographies]]
@ -355,7 +386,7 @@
(rx/merge-map vals)
(rx/map #(vector (:id %) (get-in % [:data :colors])))
(rx/filter #(d/not-empty? (second %)))
(rx/map parse-library-color))
(rx/merge-map parse-library-color))
typographies-stream
(->> files-stream

View file

@ -50,7 +50,9 @@
path (case type
:manifest (str "manifest.json")
:page (str file-id "/" id ".svg")
:colors (str file-id "/colors.json")
:colors-list (str file-id "/colors.json")
:colors (let [ext (cm/mtype->extension (:mtype media))]
(str/concat file-id "/colors/" id ext))
:typographies (str file-id "/typographies.json")
:media-list (str file-id "/media.json")
:media (let [ext (cm/mtype->extension (:mtype media))]
@ -560,15 +562,36 @@
(if (:has-colors context)
(let [resolve (:resolve context)
add-color
(fn [file [id color]]
(fn [file color]
(let [color (-> color
(d/update-in-when [:gradient :type] keyword)
(assoc :id (resolve id)))]
(d/update-in-when [:image :id] resolve)
(update :id resolve))]
(fb/add-library-color file color)))]
(->> (get-file context :colors)
(->> (get-file context :colors-list)
(rx/merge-map (comp d/kebab-keys parser/string->uuid))
(rx/mapcat
(fn [[id color]]
(let [color (assoc color :id id)
color-image (:image color)
upload-image? (some? color-image)
color-image-id (:id color-image)]
(if upload-image?
(->> (get-file context :colors color-image-id color-image)
(rx/map (fn [blob]
(let [content (.slice blob 0 (.-size blob) (:mtype color-image))]
{:name (:name color-image)
:id (resolve color-image-id)
:file-id (:id file)
:content content
:is-local false})))
(rx/tap #(progress! context :upload-media (:name %)))
(rx/merge-map #(rp/cmd! :upload-file-media-object %))
(rx/map (constantly color))
(rx/catch #(do (.error js/console (str "Error uploading color-image: " (:name color-image)))
(rx/empty))))
(rx/of color)))))
(rx/reduce add-color file)))
(rx/of file)))
(defn process-library-typographies