mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 18:06:11 +02:00
✨ Fix problem when importing zip files
This commit is contained in:
parent
ea2173bd30
commit
86b4a95875
3 changed files with 33 additions and 17 deletions
|
@ -268,6 +268,7 @@
|
||||||
(when (:image current-color)
|
(when (:image current-color)
|
||||||
[:img {:src uri}])]
|
[:img {:src uri}])]
|
||||||
|
|
||||||
|
(when (some? (:image current-color))
|
||||||
[:div {:class (stl/css :checkbox-option)}
|
[:div {:class (stl/css :checkbox-option)}
|
||||||
[:label {:for "keep-aspect-ratio"
|
[:label {:for "keep-aspect-ratio"
|
||||||
:class (stl/css-case :global/checked keep-aspect-ratio?)}
|
:class (stl/css-case :global/checked keep-aspect-ratio?)}
|
||||||
|
@ -277,7 +278,7 @@
|
||||||
[:input {:type "checkbox"
|
[:input {:type "checkbox"
|
||||||
:id "keep-aspect-ratio"
|
:id "keep-aspect-ratio"
|
||||||
:checked keep-aspect-ratio?
|
:checked keep-aspect-ratio?
|
||||||
:on-change handle-change-keep-aspect-ratio}]]]
|
:on-change handle-change-keep-aspect-ratio}]]])
|
||||||
[:button
|
[:button
|
||||||
{:class (stl/css :choose-image)
|
{:class (stl/css :choose-image)
|
||||||
:title (tr "media.choose-image")
|
:title (tr "media.choose-image")
|
||||||
|
|
|
@ -347,7 +347,12 @@
|
||||||
(->> (upload-media-files context file-id name (:href image-data))
|
(->> (upload-media-files context file-id name (:href image-data))
|
||||||
(rx/catch #(do (.error js/console "Error uploading media: " name)
|
(rx/catch #(do (.error js/console "Error uploading media: " name)
|
||||||
(rx/of node)))
|
(rx/of node)))
|
||||||
(rx/map #(vector (:id image-data) %)))))
|
(rx/map (fn [data]
|
||||||
|
(let [data
|
||||||
|
(cond-> data
|
||||||
|
(some? (:keep-aspect-ratio image-data))
|
||||||
|
(assoc :keep-aspect-ratio (:keep-aspect-ratio image-data)))]
|
||||||
|
[(:id image-data) data]))))))
|
||||||
(rx/reduce (fn [acc [id data]] (assoc acc id data)) {})
|
(rx/reduce (fn [acc [id data]] (assoc acc id data)) {})
|
||||||
(rx/map
|
(rx/map
|
||||||
(fn [images]
|
(fn [images]
|
||||||
|
@ -360,7 +365,8 @@
|
||||||
(assoc-in [:attrs :penpot:media-width] (:width media))
|
(assoc-in [:attrs :penpot:media-width] (:width media))
|
||||||
(assoc-in [:attrs :penpot:media-height] (:height media))
|
(assoc-in [:attrs :penpot:media-height] (:height media))
|
||||||
(assoc-in [:attrs :penpot:media-mtype] (:mtype media))
|
(assoc-in [:attrs :penpot:media-mtype] (:mtype media))
|
||||||
|
(cond-> (some? (:keep-aspect-ratio media))
|
||||||
|
(assoc-in [:attrs :penpot:media-keep-aspect-ratio] (:keep-aspect-ratio media)))
|
||||||
(assoc-in [:attrs :penpot:fill-color] (:fill image-fill))
|
(assoc-in [:attrs :penpot:fill-color] (:fill image-fill))
|
||||||
(assoc-in [:attrs :penpot:fill-color-ref-file] (:fill-color-ref-file image-fill))
|
(assoc-in [:attrs :penpot:fill-color-ref-file] (:fill-color-ref-file image-fill))
|
||||||
(assoc-in [:attrs :penpot:fill-color-ref-id] (:fill-color-ref-id image-fill))
|
(assoc-in [:attrs :penpot:fill-color-ref-id] (:fill-color-ref-id image-fill))
|
||||||
|
|
|
@ -195,15 +195,22 @@
|
||||||
(d/deep-mapm
|
(d/deep-mapm
|
||||||
(fn [pair] (->> pair (mapv convert)))))))
|
(fn [pair] (->> pair (mapv convert)))))))
|
||||||
|
|
||||||
(def search-data-node? #{:rect :image :path :circle})
|
(def search-data-node? #{:rect :path :circle})
|
||||||
|
|
||||||
(defn get-svg-data
|
(defn get-svg-data
|
||||||
[type node]
|
[type node]
|
||||||
|
|
||||||
(let [node-attrs (add-attrs {} (:attrs node))]
|
(let [node-attrs (add-attrs {} (:attrs node))]
|
||||||
(cond
|
(cond
|
||||||
(search-data-node? type)
|
(search-data-node? type)
|
||||||
(let [data-tags #{:ellipse :rect :path :text :foreignObject :image}]
|
(let [data-tags #{:ellipse :rect :path :text :foreignObject}]
|
||||||
|
(->> node
|
||||||
|
(node-seq)
|
||||||
|
(filter #(contains? data-tags (:tag %)))
|
||||||
|
(map #(:attrs %))
|
||||||
|
(reduce add-attrs node-attrs)))
|
||||||
|
|
||||||
|
(= type :image)
|
||||||
|
(let [data-tags #{:rect :image}]
|
||||||
(->> node
|
(->> node
|
||||||
(node-seq)
|
(node-seq)
|
||||||
(filter #(contains? data-tags (:tag %)))
|
(filter #(contains? data-tags (:tag %)))
|
||||||
|
@ -523,7 +530,8 @@
|
||||||
(let [metadata {:id (get-meta node :media-id)
|
(let [metadata {:id (get-meta node :media-id)
|
||||||
:width (get-meta node :media-width)
|
:width (get-meta node :media-width)
|
||||||
:height (get-meta node :media-height)
|
:height (get-meta node :media-height)
|
||||||
:mtype (get-meta node :media-mtype)}]
|
:mtype (get-meta node :media-mtype)
|
||||||
|
:keep-aspect-ratio (get-meta node :media-keep-aspect-ratio str->bool)}]
|
||||||
(cond-> props
|
(cond-> props
|
||||||
(= type :image)
|
(= type :image)
|
||||||
(assoc :metadata metadata)
|
(assoc :metadata metadata)
|
||||||
|
@ -881,7 +889,8 @@
|
||||||
(let [id (get-in fill-node [:attrs :penpot:fill-image-id])
|
(let [id (get-in fill-node [:attrs :penpot:fill-image-id])
|
||||||
image-node (->> node (node-seq) (find-node-by-id id))]
|
image-node (->> node (node-seq) (find-node-by-id id))]
|
||||||
{:id id
|
{:id id
|
||||||
:href (get-in image-node [:attrs :href])})))
|
:href (get-in image-node [:attrs :href])
|
||||||
|
:keep-aspect-ratio (not= (get-in image-node [:attrs :preserveAspectRatio]) "none")})))
|
||||||
(filterv #(some? (:id %))))))
|
(filterv #(some? (:id %))))))
|
||||||
|
|
||||||
(defn has-fill-images?
|
(defn has-fill-images?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue