mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 01:58:29 +02:00
🐛 Added upload svg with images method
This commit is contained in:
parent
9c626d22c7
commit
66076f1332
3 changed files with 41 additions and 0 deletions
|
@ -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)))))
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue