0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 15:51:37 -05:00

Make clipboard api more generic.

This commit is contained in:
Andrey Antukh 2020-04-08 16:37:32 +02:00
parent 7e7c0dad7f
commit a0b70b7bbd
2 changed files with 8 additions and 8 deletions

View file

@ -2072,7 +2072,9 @@
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])
cdata (prepare-selected state selected)]
(->> (rx/from (wapi/write-to-clipboard cdata))
(->> (t/encode cdata)
(wapi/write-to-clipboard)
(rx/from)
(rx/catch on-copy-error)
(rx/ignore)))))))
@ -2160,12 +2162,13 @@
ptk/WatchEvent
(watch [_ state stream]
(->> (rx/from (wapi/read-from-clipboard))
(rx/map t/decode)
(rx/filter #(= :copied-shapes (:type %)))
(rx/pr-log "pasting:")
(rx/map :data)
(rx/map paste-impl)
(rx/catch (fn [err]
(js/console.error "Clipboard blocked:" err)
(js/console.error "Clipboard error:" err)
(rx/empty)))))))
(defn select-pasted-objs

View file

@ -69,18 +69,15 @@
(defn write-to-clipboard
[data]
(assert (string? data) "`data` should be string")
(let [cboard (unchecked-get js/navigator "clipboard")]
(.writeText cboard (uxbox.util.transit/encode data))))
(.writeText cboard data)))
(defn- read-from-clipboard
[]
(let [cboard (unchecked-get js/navigator "clipboard")]
(-> (.readText cboard)
(p/then (fn [data]
(try
(t/decode data)
(catch :default e
nil)))))))
(p/then identity))))
(defn request-fullscreen
[el]