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

Don't stop SVG import when an image cannot be imported

This commit is contained in:
alonso.torres 2022-03-21 22:58:37 +01:00
parent 6008dc12d3
commit f2d1a4190a
4 changed files with 88 additions and 47 deletions

View file

@ -37,6 +37,7 @@
- Add the ability to specify the attr for retrieve the email on OIDC integration [#1460](https://github.com/penpot/penpot/issues/1460) - Add the ability to specify the attr for retrieve the email on OIDC integration [#1460](https://github.com/penpot/penpot/issues/1460)
- Allow registration with invitation token when registration is disabled - Allow registration with invitation token when registration is disabled
- Add the ability to disable standard, password login [Taiga #2999](https://tree.taiga.io/project/penpot/us/2999) - Add the ability to disable standard, password login [Taiga #2999](https://tree.taiga.io/project/penpot/us/2999)
- Don't stop SVG import when an image cannot be imported [#1531](https://github.com/penpot/penpot/issues/1531)
### :bug: Bugs fixed ### :bug: Bugs fixed

View file

@ -70,6 +70,8 @@
:else (str tag)))) :else (str tag))))
(defn setup-fill [shape] (defn setup-fill [shape]
(if (some? (:fills shape))
shape
(cond-> shape (cond-> shape
;; Color present as attribute ;; Color present as attribute
(uc/color? (str/trim (get-in shape [:svg-attrs :fill]))) (uc/color? (str/trim (get-in shape [:svg-attrs :fill])))
@ -93,7 +95,7 @@
(get-in shape [:svg-attrs :style :fill-opacity]) (get-in shape [:svg-attrs :style :fill-opacity])
(-> (update-in [:svg-attrs :style] dissoc :fill-opacity) (-> (update-in [:svg-attrs :style] dissoc :fill-opacity)
(assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :fill-opacity]) (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :fill-opacity])
(d/parse-double)))))) (d/parse-double)))))))
(defn setup-stroke [shape] (defn setup-stroke [shape]
(let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap]) (let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap])
@ -337,6 +339,8 @@
(update :y - (:y origin))) (update :y - (:y origin)))
rect-metadata (calculate-rect-metadata rect-data transform)] rect-metadata (calculate-rect-metadata rect-data transform)]
(when (some? image-data)
(-> {:id (uuid/next) (-> {:id (uuid/next)
:type :image :type :image
:name name :name name
@ -348,7 +352,7 @@
(merge rect-metadata) (merge rect-metadata)
(assoc :svg-viewbox (select-keys rect [:x :y :width :height])) (assoc :svg-viewbox (select-keys rect [:x :y :width :height]))
(assoc :svg-attrs (dissoc attrs :x :y :width :height :xlink:href))))) (assoc :svg-attrs (dissoc attrs :x :y :width :height :xlink:href))))))
(defn parse-svg-element [frame-id svg-data element-data unames] (defn parse-svg-element [frame-id svg-data element-data unames]
(let [{:keys [tag attrs]} element-data (let [{:keys [tag attrs]} element-data
@ -389,9 +393,9 @@
:polygon (create-path-shape name frame-id svg-data (-> element-data usvg/polygon->path)) :polygon (create-path-shape name frame-id svg-data (-> element-data usvg/polygon->path))
:line (create-path-shape name frame-id svg-data (-> element-data usvg/line->path)) :line (create-path-shape name frame-id svg-data (-> element-data usvg/line->path))
:image (create-image-shape name frame-id svg-data element-data) :image (create-image-shape name frame-id svg-data element-data)
#_other (create-raw-svg name frame-id svg-data element-data))) #_other (create-raw-svg name frame-id svg-data element-data)))]
(when (some? shape)
shape (assoc shape :fills []) (let [shape (assoc shape :fills [])
shape (assoc shape :strokes []) shape (assoc shape :strokes [])
shape (when (some? shape) shape (when (some? shape)
@ -403,7 +407,7 @@
children (cond->> (:content element-data) children (cond->> (:content element-data)
(or (= tag :g) (= tag :svg)) (or (= tag :g) (= tag :svg))
(mapv #(usvg/inherit-attributes attrs %)))] (mapv #(usvg/inherit-attributes attrs %)))]
[shape children])))) [shape children]))))))
(defn add-svg-child-changes [page-id objects selected frame-id parent-id svg-data [unames changes] [index data]] (defn add-svg-child-changes [page-id objects selected frame-id parent-id svg-data [unames changes] [index data]]
(let [[shape children] (parse-svg-element frame-id svg-data data unames)] (let [[shape children] (parse-svg-element frame-id svg-data data unames)]
@ -448,6 +452,9 @@
(->> (rp/mutation! (if (contains? uri-data :content) (->> (rp/mutation! (if (contains? uri-data :content)
:upload-file-media-object :upload-file-media-object
:create-file-media-object-from-url) uri-data) :create-file-media-object-from-url) uri-data)
;; When the image uploaded fail we skip the shape
;; returning `nil` will afterward not create the shape.
(rx/catch #(rx/of nil))
(rx/map #(vector (:url uri-data) %))))) (rx/map #(vector (:url uri-data) %)))))
(rx/reduce (fn [acc [url image]] (assoc acc url image)) {}) (rx/reduce (fn [acc [url image]] (assoc acc url image)) {})
(rx/map #(create-svg-shapes (assoc svg-data :image-data %) position)))))) (rx/map #(create-svg-shapes (assoc svg-data :image-data %) position))))))

View file

@ -180,6 +180,11 @@
(obj/set! "fill" (obj/get svg-styles "fill")) (obj/set! "fill" (obj/get svg-styles "fill"))
(obj/set! "fillOpacity" (obj/get svg-styles "fillOpacity"))) (obj/set! "fillOpacity" (obj/get svg-styles "fillOpacity")))
(obj/contains? svg-attrs "fill")
(-> styles
(obj/set! "fill" (obj/get svg-attrs "fill"))
(obj/set! "fillOpacity" (obj/get svg-attrs "fillOpacity")))
;; If contains svg-attrs the origin is svg. If it's not svg origin ;; If contains svg-attrs the origin is svg. If it's not svg origin
;; we setup the default fill as transparent (instead of black) ;; we setup the default fill as transparent (instead of black)
(and (contains? shape :svg-attrs) (and (contains? shape :svg-attrs)
@ -187,8 +192,11 @@
(empty? (:fills shape))) (empty? (:fills shape)))
styles styles
(d/not-empty? (:fills shape))
(add-fill styles (d/without-nils (get-in shape [:fills 0])) render-id 0)
:else :else
(add-fill styles (d/without-nils (get-in shape [:fills 0])) render-id 0))] styles)]
(-> props (-> props
(obj/merge! svg-attrs) (obj/merge! svg-attrs)

View file

@ -328,7 +328,13 @@
props (cond-> props props (cond-> props
(d/not-empty? (:shadow shape)) (d/not-empty? (:shadow shape))
(obj/set! "filter" (dm/fmt "url(#filter_%)" render-id)))] (obj/set! "filter" (dm/fmt "url(#filter_%)" render-id)))
svg-defs (:svg-defs shape {})
svg-attrs (:svg-attrs shape {})
[svg-attrs svg-styles]
(attrs/extract-svg-attrs render-id svg-defs svg-attrs)]
(cond (cond
url-fill? url-fill?
@ -339,6 +345,25 @@
(obj/without ["fill" "fillOpacity"])))] (obj/without ["fill" "fillOpacity"])))]
(obj/set! props "fill" (dm/fmt "url(#fill-0-%)" render-id))) (obj/set! props "fill" (dm/fmt "url(#fill-0-%)" render-id)))
(obj/contains? svg-styles "fill")
(let [style
(-> (obj/get props "style")
(obj/clone)
(obj/set! "fill" (obj/get svg-styles "fill"))
(obj/set! "fillOpacity" (obj/get svg-styles "fillOpacity")))]
(-> props
(obj/set! "style" style)))
(obj/contains? svg-attrs "fill")
(let [style
(-> (obj/get props "style")
(obj/clone)
(obj/set! "fill" (obj/get svg-attrs "fill"))
(obj/set! "fillOpacity" (obj/get svg-attrs "fillOpacity")))]
(-> props
(obj/set! "style" style)))
(d/not-empty? (:fills shape)) (d/not-empty? (:fills shape))
(let [fill-props (let [fill-props
(attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0) (attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0)