diff --git a/CHANGES.md b/CHANGES.md index b300b83bc1..0264dbe4c0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -57,6 +57,7 @@ is a number of cores) - Fix problem with multiple color changes [Taiga #9631](https://tree.taiga.io/project/penpot/issue/9631) - Fix problem in plugins with zoomIntoView [Plugins #189](https://github.com/penpot/penpot-plugins/issues/189) - Fix problem in plugins with renaming components [Taiga #10060](https://tree.taiga.io/project/penpot/issue/10060) +- Added upload svg with images method [#5489](https://github.com/penpot/penpot/issues/5489) ## 2.4.3 diff --git a/frontend/src/app/main/data/workspace/media.cljs b/frontend/src/app/main/data/workspace/media.cljs index dfebb5ab6a..3a6be86c25 100644 --- a/frontend/src/app/main/data/workspace/media.cljs +++ b/frontend/src/app/main/data/workspace/media.cljs @@ -476,3 +476,24 @@ (rx/take 1) (rx/map #(svg/add-svg-shapes id % position {:ignore-selection? true :change-selection? false})))))) +(defn create-svg-shape-with-images + [file-id id name svg-string position on-success on-error] + (ptk/reify ::create-svg-shape-with-images + ptk/WatchEvent + (watch [_ _ _] + (->> (svg->clj [name svg-string]) + (rx/take 1) + (rx/mapcat + (fn [svg-data] + (->> (svg/upload-images svg-data file-id) + (rx/map #(assoc svg-data :image-data %))))) + (rx/map + (fn [svg-data] + (svg/add-svg-shapes + id + svg-data + position + {:ignore-selection? true + :change-selection? false}))) + (rx/tap on-success) + (rx/catch on-error))))) diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index e0cc93c362..9ce731f18b 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -346,6 +346,25 @@ (st/emit! (dwm/create-svg-shape id "svg" svg-string (gpt/point 0 0))) (shape/shape-proxy plugin-id file-id page-id id)))) + :createShapeFromSvgWithImages + (fn [svg-string] + (js/Promise. + (fn [resolve reject] + (cond + (or (not (string? svg-string)) (empty? svg-string)) + (do + (u/display-not-valid :createShapeFromSvg "Svg not valid") + (reject "Svg not valid")) + + :else + (let [id (uuid/next) + file-id (:current-file-id @st/state) + page-id (:current-page-id @st/state)] + (st/emit! (dwm/create-svg-shape-with-images + file-id id "svg" svg-string (gpt/point 0 0) + #(resolve (shape/shape-proxy plugin-id file-id page-id id)) + reject))))))) + :createBoolean (fn [bool-type shapes] (let [bool-type (keyword bool-type)]