mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
🐛 Fix error streen when uploading wrong SVG
This commit is contained in:
parent
7b72906096
commit
6962e15b6d
4 changed files with 103 additions and 93 deletions
|
@ -16,6 +16,7 @@
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
- Fix problem with rules position on changing pages [Taiga #4847](https://tree.taiga.io/project/penpot/issue/4847)
|
- 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
|
### :arrow_up: Deps updates
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,9 @@
|
||||||
height (get-in data [:attrs :height] 100)
|
height (get-in data [:attrs :height] 100)
|
||||||
viewbox (get-in data [:attrs :viewBox] (str "0 0 " width " " height))
|
viewbox (get-in data [:attrs :viewBox] (str "0 0 " width " " height))
|
||||||
[x y width height] (->> (str/split viewbox #"\s+")
|
[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 :x x)
|
||||||
(assert-valid-num :y y)
|
(assert-valid-num :y y)
|
||||||
(assert-valid-pos-num :width width)
|
(assert-valid-pos-num :width width)
|
||||||
|
@ -483,7 +485,6 @@
|
||||||
|
|
||||||
(defn create-svg-shapes
|
(defn create-svg-shapes
|
||||||
[svg-data {:keys [x y]} objects frame-id parent-id selected center?]
|
[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)
|
(let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
|
||||||
x (mth/round
|
x (mth/round
|
||||||
(if center?
|
(if center?
|
||||||
|
@ -544,18 +545,14 @@
|
||||||
(d/enumerate (->> (:content svg-data)
|
(d/enumerate (->> (:content svg-data)
|
||||||
(mapv #(usvg/inherit-attributes root-attrs %)))))]
|
(mapv #(usvg/inherit-attributes root-attrs %)))))]
|
||||||
|
|
||||||
[new-shape new-children])
|
[new-shape new-children]))
|
||||||
|
|
||||||
(catch :default e
|
|
||||||
(.error js/console "Error SVG" e)
|
|
||||||
(rx/throw {:type :svg-parser
|
|
||||||
:data e}))))
|
|
||||||
|
|
||||||
(defn add-svg-shapes
|
(defn add-svg-shapes
|
||||||
[svg-data position]
|
[svg-data position]
|
||||||
(ptk/reify ::add-svg-shapes
|
(ptk/reify ::add-svg-shapes
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
|
(try
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame-id (ctst/top-nested-frame objects position)
|
frame-id (ctst/top-nested-frame objects position)
|
||||||
|
@ -565,8 +562,9 @@
|
||||||
selected-frame? (and (= 1 (count selected))
|
selected-frame? (and (= 1 (count selected))
|
||||||
(= :frame (get-in objects [(first selected) :type])))
|
(= :frame (get-in objects [(first selected) :type])))
|
||||||
|
|
||||||
parent-id (if
|
parent-id
|
||||||
(or selected-frame? (empty? selected)) frame-id
|
(if (or selected-frame? (empty? selected))
|
||||||
|
frame-id
|
||||||
(:parent-id base))
|
(:parent-id base))
|
||||||
|
|
||||||
[new-shape new-children]
|
[new-shape new-children]
|
||||||
|
@ -596,4 +594,9 @@
|
||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes)
|
||||||
(dws/select-shapes (d/ordered-set (:id new-shape)))
|
(dws/select-shapes (d/ordered-set (:id new-shape)))
|
||||||
(ptk/data-event :layout/update [(: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}))))))
|
||||||
|
|
|
@ -46,7 +46,9 @@
|
||||||
(defonce state
|
(defonce state
|
||||||
(ptk/store {:resolve ptk/resolve
|
(ptk/store {:resolve ptk/resolve
|
||||||
:on-event on-event
|
: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
|
(defonce stream
|
||||||
(ptk/input-stream state))
|
(ptk/input-stream state))
|
||||||
|
|
|
@ -820,6 +820,10 @@
|
||||||
(defn line->path [{:keys [attrs] :as node}]
|
(defn line->path [{:keys [attrs] :as node}]
|
||||||
(let [tag :path
|
(let [tag :path
|
||||||
{:keys [x1 y1 x2 y2]} attrs
|
{:keys [x1 y1 x2 y2]} attrs
|
||||||
|
x1 (or x1 0)
|
||||||
|
y1 (or y1 0)
|
||||||
|
x2 (or x2 0)
|
||||||
|
y2 (or y2 0)
|
||||||
attrs (-> attrs
|
attrs (-> attrs
|
||||||
(dissoc :x1 :x2 :y1 :y2)
|
(dissoc :x1 :x2 :y1 :y2)
|
||||||
(assoc :d (str "M" x1 "," y1 " L" x2 "," y2)))]
|
(assoc :d (str "M" x1 "," y1 " L" x2 "," y2)))]
|
||||||
|
|
Loading…
Reference in a new issue