0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

🐛 Fix error streen when uploading wrong SVG

This commit is contained in:
alonso.torres 2023-03-02 16:24:23 +01:00
parent 7b72906096
commit 6962e15b6d
4 changed files with 103 additions and 93 deletions

View file

@ -16,6 +16,7 @@
### :bug: Bugs fixed
- Fix problem with rules position on changing pages [Taiga #4847](https://tree.taiga.io/project/penpot/issue/4847)
- Fix error streen when uploading wrong SVG [#2995](https://github.com/penpot/penpot/issues/2995)
### :arrow_up: Deps updates

View file

@ -62,7 +62,9 @@
height (get-in data [:attrs :height] 100)
viewbox (get-in data [:attrs :viewBox] (str "0 0 " width " " height))
[x y width height] (->> (str/split viewbox #"\s+")
(map d/parse-double))]
(map d/parse-double))
width (if (= width 0) 1 width)
height (if (= height 0) 1 height)]
[(assert-valid-num :x x)
(assert-valid-num :y y)
(assert-valid-pos-num :width width)
@ -483,7 +485,6 @@
(defn create-svg-shapes
[svg-data {:keys [x y]} objects frame-id parent-id selected center?]
(try
(let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
x (mth/round
(if center?
@ -544,18 +545,14 @@
(d/enumerate (->> (:content svg-data)
(mapv #(usvg/inherit-attributes root-attrs %)))))]
[new-shape new-children])
(catch :default e
(.error js/console "Error SVG" e)
(rx/throw {:type :svg-parser
:data e}))))
[new-shape new-children]))
(defn add-svg-shapes
[svg-data position]
(ptk/reify ::add-svg-shapes
ptk/WatchEvent
(watch [it state _]
(try
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
frame-id (ctst/top-nested-frame objects position)
@ -565,8 +562,9 @@
selected-frame? (and (= 1 (count selected))
(= :frame (get-in objects [(first selected) :type])))
parent-id (if
(or selected-frame? (empty? selected)) frame-id
parent-id
(if (or selected-frame? (empty? selected))
frame-id
(:parent-id base))
[new-shape new-children]
@ -596,4 +594,9 @@
(dch/commit-changes changes)
(dws/select-shapes (d/ordered-set (:id new-shape)))
(ptk/data-event :layout/update [(:id new-shape)])
(dwu/commit-undo-transaction undo-id))))))
(dwu/commit-undo-transaction undo-id)))
(catch :default e
(.error js/console "Error SVG" e)
(rx/throw {:type :svg-parser
:data e}))))))

View file

@ -46,7 +46,9 @@
(defonce state
(ptk/store {:resolve ptk/resolve
:on-event on-event
:on-error (fn [e] (@on-error e))}))
:on-error (fn [e]
(.log js/console "ERROR!!" e)
(@on-error e))}))
(defonce stream
(ptk/input-stream state))

View file

@ -820,6 +820,10 @@
(defn line->path [{:keys [attrs] :as node}]
(let [tag :path
{:keys [x1 y1 x2 y2]} attrs
x1 (or x1 0)
y1 (or y1 0)
x2 (or x2 0)
y2 (or y2 0)
attrs (-> attrs
(dissoc :x1 :x2 :y1 :y2)
(assoc :d (str "M" x1 "," y1 " L" x2 "," y2)))]