mirror of
https://github.com/penpot/penpot.git
synced 2026-03-07 18:51:14 +00:00
✨ Make clipboard api more generic.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user