0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-02 04:19:08 -05:00

🐛 Fix issue when exporting libraries when merging libraries

This commit is contained in:
alonso.torres 2024-09-16 09:08:51 +02:00
parent 65bb795199
commit 979828ffe3
2 changed files with 51 additions and 93 deletions

View file

@ -82,6 +82,7 @@
- Fix problem when creating a component instance from grid layout [Github #4881](https://github.com/penpot/penpot/issues/4881) - Fix problem when creating a component instance from grid layout [Github #4881](https://github.com/penpot/penpot/issues/4881)
- Fix problem when dismissing shared library update [Taiga #8669](https://tree.taiga.io/project/penpot/issue/8669) - Fix problem when dismissing shared library update [Taiga #8669](https://tree.taiga.io/project/penpot/issue/8669)
- Fix visual problem with stroke cap menu [Taiga #8730](https://tree.taiga.io/project/penpot/issue/8730) - Fix visual problem with stroke cap menu [Taiga #8730](https://tree.taiga.io/project/penpot/issue/8730)
- Fix issue when exporting libraries when merging libraries [Taiga #8758](https://tree.taiga.io/project/penpot/issue/8758)
## 2.1.5 ## 2.1.5

View file

@ -202,108 +202,61 @@
(defn make-local-external-references (defn make-local-external-references
[file file-id] [file file-id]
(let [detach-text (let [change-fill
(fn [fill]
(cond-> fill
(not= file-id (:fill-color-ref-file fill))
(assoc :fill-color-ref-file file-id)))
change-stroke
(fn [stroke]
(cond-> stroke
(not= file-id (:stroke-color-ref-file stroke))
(assoc :stroke-color-ref-file file-id)))
change-text
(fn [content] (fn [content]
(->> content (->> content
(ct/transform-nodes (ct/transform-nodes
#(cond-> % (fn [node]
(not= file-id (:fill-color-ref-file %)) (-> node
(assoc :fill-color-ref-file file-id) (d/update-when :fills #(mapv change-fill %))
(cond-> (not= file-id (:typography-ref-file node))
(assoc :typography-ref-file file-id)))))))
(not= file-id (:typography-ref-file %)) change-shape
(assoc :typography-ref-file file-id)))))
detach-shape
(fn [shape] (fn [shape]
(cond-> shape (-> shape
(not= file-id (:fill-color-ref-file shape)) (d/update-when :fills #(mapv change-fill %))
(assoc :fill-color-ref-file file-id) (d/update-when :strokes #(mapv change-stroke %))
(cond-> (not= file-id (:component-file shape))
(assoc :component-file file-id))
(not= file-id (:stroke-color-ref-file shape)) (cond-> (= :text (:type shape))
(assoc :stroke-color-ref-file file-id) (update :content change-text))))
(not= file-id (:component-file shape)) change-objects
(assoc :component-file file-id)
(= :text (:type shape))
(update :content detach-text)))
detach-objects
(fn [objects] (fn [objects]
(->> objects (->> objects
(d/mapm #(detach-shape %2)))) (d/mapm #(change-shape %2))))
detach-pages change-pages
(fn [pages-index] (fn [pages-index]
(->> pages-index (->> pages-index
(d/mapm (d/mapm
(fn [_ data] (fn [_ data]
(-> data (-> data
(update :objects detach-objects))))))] (update :objects change-objects))))))]
(-> file (-> file
(update-in [:data :pages-index] detach-pages)))) (update-in [:data :pages-index] change-pages))))
(defn collect-external-references
[file]
(let [get-text-refs
(fn [content]
(->> content
(ct/node-seq #(or (contains? % :fill-color-ref-id)
(contains? % :typography-ref-id)))
(mapcat (fn [node]
(cond-> []
(contains? node :fill-color-ref-id)
(conj {:id (:fill-color-ref-id node)
:file-id (:fill-color-ref-file node)})
(contains? node :typography-ref-id)
(conj {:id (:typography-ref-id node)
:file-id (:typography-ref-file node)}))))
(into [])))
get-shape-refs
(fn [[_ shape]]
(cond-> []
(contains? shape :fill-color-ref-id)
(conj {:id (:fill-color-ref-id shape)
:file-id (:fill-color-ref-file shape)})
(contains? shape :stroke-color-ref-id)
(conj {:id (:stroke-color-ref-id shape)
:file-id (:stroke-color-ref-file shape)})
(contains? shape :component-id)
(conj {:id (:component-id shape)
:file-id (:component-file shape)})
(= :text (:type shape))
(into (get-text-refs (:content shape)))))]
(->> (get-in file [:data :pages-index])
(vals)
(mapcat :objects)
(mapcat get-shape-refs)
(filter (comp some? :file-id))
(filter (comp some? :id))
(group-by :file-id)
(d/mapm #(mapv :id %2)))))
(defn merge-assets [target-file assets-files] (defn merge-assets [target-file assets-files]
(let [external-refs (collect-external-references target-file) (let [merge-file-assets
merge-file-assets
(fn [target file] (fn [target file]
(let [colors (-> (get-in file [:data :colors]) (let [colors (get-in file [:data :colors])
(select-keys (get external-refs (:id file)))) typographies (get-in file [:data :typographies])
typographies (-> (get-in file [:data :typographies]) media (get-in file [:data :media])
(select-keys (get external-refs (:id file)))) components (ctkl/components (:data file))]
media (-> (get-in file [:data :media])
(select-keys (get external-refs (:id file))))
components (-> (ctkl/components (:data file))
(select-keys (get external-refs (:id file))))]
(cond-> target (cond-> target
(d/not-empty? colors) (d/not-empty? colors)
(update-in [:data :colors] merge colors) (update-in [:data :colors] merge colors)
@ -323,16 +276,20 @@
(defn process-export (defn process-export
[file-id export-type files] [file-id export-type files]
(case export-type (let [result
:all files (case export-type
:merge (let [file-list (-> files (d/without-keys [file-id]) vals)] :all files
(-> (select-keys files [file-id]) :merge (let [file-list (-> files (d/without-keys [file-id]) vals)]
(update file-id merge-assets file-list) (-> (select-keys files [file-id])
(update file-id make-local-external-references file-id) (update file-id merge-assets file-list)
(update file-id dissoc :libraries))) (update file-id make-local-external-references file-id)
:detach (-> (select-keys files [file-id]) (update file-id dissoc :libraries)))
(update file-id ctf/detach-external-references file-id) :detach (-> (select-keys files [file-id])
(update file-id dissoc :libraries)))) (update file-id ctf/detach-external-references file-id)
(update file-id dissoc :libraries)))]
;;(.log js/console (clj->js result))
result))
(defn collect-files (defn collect-files
[file-id export-type features] [file-id export-type features]