mirror of
https://github.com/penpot/penpot.git
synced 2025-07-06 00:47:16 +02:00
🎉 Add clipboard related functions to webapi utils.
This commit is contained in:
parent
c66b483fba
commit
1195777036
1 changed files with 18 additions and 1 deletions
|
@ -7,8 +7,10 @@
|
||||||
(ns uxbox.util.webapi
|
(ns uxbox.util.webapi
|
||||||
"HTML5 web api helpers."
|
"HTML5 web api helpers."
|
||||||
(:require
|
(:require
|
||||||
|
[promesa.core :as p]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]
|
||||||
|
[uxbox.util.transit :as t]))
|
||||||
|
|
||||||
(defn read-file-as-text
|
(defn read-file-as-text
|
||||||
[file]
|
[file]
|
||||||
|
@ -65,4 +67,19 @@
|
||||||
;; (rx/create on-subscribe)))
|
;; (rx/create on-subscribe)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn write-to-clipboard
|
||||||
|
[data]
|
||||||
|
(let [cboard (unchecked-get js/navigator "clipboard")]
|
||||||
|
(.writeText cboard (uxbox.util.transit/encode 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)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue