mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 23:06:10 +02:00
✨ Make clipboard api more generic.
This commit is contained in:
parent
7e7c0dad7f
commit
a0b70b7bbd
2 changed files with 8 additions and 8 deletions
|
@ -2072,7 +2072,9 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [selected (get-in state [:workspace-local :selected])
|
(let [selected (get-in state [:workspace-local :selected])
|
||||||
cdata (prepare-selected state 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/catch on-copy-error)
|
||||||
(rx/ignore)))))))
|
(rx/ignore)))))))
|
||||||
|
|
||||||
|
@ -2160,12 +2162,13 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(->> (rx/from (wapi/read-from-clipboard))
|
(->> (rx/from (wapi/read-from-clipboard))
|
||||||
|
(rx/map t/decode)
|
||||||
(rx/filter #(= :copied-shapes (:type %)))
|
(rx/filter #(= :copied-shapes (:type %)))
|
||||||
(rx/pr-log "pasting:")
|
(rx/pr-log "pasting:")
|
||||||
(rx/map :data)
|
(rx/map :data)
|
||||||
(rx/map paste-impl)
|
(rx/map paste-impl)
|
||||||
(rx/catch (fn [err]
|
(rx/catch (fn [err]
|
||||||
(js/console.error "Clipboard blocked:" err)
|
(js/console.error "Clipboard error:" err)
|
||||||
(rx/empty)))))))
|
(rx/empty)))))))
|
||||||
|
|
||||||
(defn select-pasted-objs
|
(defn select-pasted-objs
|
||||||
|
|
|
@ -69,18 +69,15 @@
|
||||||
|
|
||||||
(defn write-to-clipboard
|
(defn write-to-clipboard
|
||||||
[data]
|
[data]
|
||||||
|
(assert (string? data) "`data` should be string")
|
||||||
(let [cboard (unchecked-get js/navigator "clipboard")]
|
(let [cboard (unchecked-get js/navigator "clipboard")]
|
||||||
(.writeText cboard (uxbox.util.transit/encode data))))
|
(.writeText cboard data)))
|
||||||
|
|
||||||
(defn- read-from-clipboard
|
(defn- read-from-clipboard
|
||||||
[]
|
[]
|
||||||
(let [cboard (unchecked-get js/navigator "clipboard")]
|
(let [cboard (unchecked-get js/navigator "clipboard")]
|
||||||
(-> (.readText cboard)
|
(-> (.readText cboard)
|
||||||
(p/then (fn [data]
|
(p/then identity))))
|
||||||
(try
|
|
||||||
(t/decode data)
|
|
||||||
(catch :default e
|
|
||||||
nil)))))))
|
|
||||||
|
|
||||||
(defn request-fullscreen
|
(defn request-fullscreen
|
||||||
[el]
|
[el]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue