mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
🐛 Fix issue when exporting libraries when merging libraries
This commit is contained in:
parent
65bb795199
commit
979828ffe3
2 changed files with 51 additions and 93 deletions
|
@ -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 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 issue when exporting libraries when merging libraries [Taiga #8758](https://tree.taiga.io/project/penpot/issue/8758)
|
||||
|
||||
## 2.1.5
|
||||
|
||||
|
|
|
@ -202,108 +202,61 @@
|
|||
|
||||
(defn make-local-external-references
|
||||
[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]
|
||||
(->> content
|
||||
(ct/transform-nodes
|
||||
#(cond-> %
|
||||
(not= file-id (:fill-color-ref-file %))
|
||||
(assoc :fill-color-ref-file file-id)
|
||||
(fn [node]
|
||||
(-> node
|
||||
(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 %))
|
||||
(assoc :typography-ref-file file-id)))))
|
||||
|
||||
detach-shape
|
||||
change-shape
|
||||
(fn [shape]
|
||||
(cond-> shape
|
||||
(not= file-id (:fill-color-ref-file shape))
|
||||
(assoc :fill-color-ref-file file-id)
|
||||
(-> shape
|
||||
(d/update-when :fills #(mapv change-fill %))
|
||||
(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))
|
||||
(assoc :stroke-color-ref-file file-id)
|
||||
(cond-> (= :text (:type shape))
|
||||
(update :content change-text))))
|
||||
|
||||
(not= file-id (:component-file shape))
|
||||
(assoc :component-file file-id)
|
||||
|
||||
(= :text (:type shape))
|
||||
(update :content detach-text)))
|
||||
|
||||
detach-objects
|
||||
change-objects
|
||||
(fn [objects]
|
||||
(->> objects
|
||||
(d/mapm #(detach-shape %2))))
|
||||
(d/mapm #(change-shape %2))))
|
||||
|
||||
detach-pages
|
||||
change-pages
|
||||
(fn [pages-index]
|
||||
(->> pages-index
|
||||
(d/mapm
|
||||
(fn [_ data]
|
||||
(-> data
|
||||
(update :objects detach-objects))))))]
|
||||
(update :objects change-objects))))))]
|
||||
(-> file
|
||||
(update-in [:data :pages-index] detach-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)))))
|
||||
(update-in [:data :pages-index] change-pages))))
|
||||
|
||||
(defn merge-assets [target-file assets-files]
|
||||
(let [external-refs (collect-external-references target-file)
|
||||
|
||||
merge-file-assets
|
||||
(let [merge-file-assets
|
||||
(fn [target file]
|
||||
(let [colors (-> (get-in file [:data :colors])
|
||||
(select-keys (get external-refs (:id file))))
|
||||
typographies (-> (get-in file [:data :typographies])
|
||||
(select-keys (get external-refs (:id 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))))]
|
||||
(let [colors (get-in file [:data :colors])
|
||||
typographies (get-in file [:data :typographies])
|
||||
media (get-in file [:data :media])
|
||||
components (ctkl/components (:data file))]
|
||||
(cond-> target
|
||||
(d/not-empty? colors)
|
||||
(update-in [:data :colors] merge colors)
|
||||
|
@ -323,16 +276,20 @@
|
|||
(defn process-export
|
||||
[file-id export-type files]
|
||||
|
||||
(case export-type
|
||||
:all files
|
||||
:merge (let [file-list (-> files (d/without-keys [file-id]) vals)]
|
||||
(-> (select-keys files [file-id])
|
||||
(update file-id merge-assets file-list)
|
||||
(update file-id make-local-external-references file-id)
|
||||
(update file-id dissoc :libraries)))
|
||||
:detach (-> (select-keys files [file-id])
|
||||
(update file-id ctf/detach-external-references file-id)
|
||||
(update file-id dissoc :libraries))))
|
||||
(let [result
|
||||
(case export-type
|
||||
:all files
|
||||
:merge (let [file-list (-> files (d/without-keys [file-id]) vals)]
|
||||
(-> (select-keys files [file-id])
|
||||
(update file-id merge-assets file-list)
|
||||
(update file-id make-local-external-references file-id)
|
||||
(update file-id dissoc :libraries)))
|
||||
:detach (-> (select-keys files [file-id])
|
||||
(update file-id ctf/detach-external-references file-id)
|
||||
(update file-id dissoc :libraries)))]
|
||||
|
||||
;;(.log js/console (clj->js result))
|
||||
result))
|
||||
|
||||
(defn collect-files
|
||||
[file-id export-type features]
|
||||
|
|
Loading…
Add table
Reference in a new issue