From 161197b0bb4e840d6b41a76a857659db1eb2c123 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Wed, 13 Jul 2022 15:19:43 +0100 Subject: [PATCH 1/2] Add `Clipboard` interface, `readText`, `writeText` --- bower.json | 3 ++- src/Web/Clipboard/Clipboard.js | 19 +++++++++++++++++++ src/Web/Clipboard/Clipboard.purs | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/Web/Clipboard/Clipboard.js create mode 100644 src/Web/Clipboard/Clipboard.purs diff --git a/bower.json b/bower.json index 98b20f9..74b041c 100644 --- a/bower.json +++ b/bower.json @@ -15,6 +15,7 @@ "package.json" ], "dependencies": { - "purescript-web-html": "^4.0.0" + "purescript-web-html": "^4.0.0", + "purescript-web-promise": "purescript-web/purescript-web-promise#^3.0.0" } } diff --git a/src/Web/Clipboard/Clipboard.js b/src/Web/Clipboard/Clipboard.js new file mode 100644 index 0000000..1808ff6 --- /dev/null +++ b/src/Web/Clipboard/Clipboard.js @@ -0,0 +1,19 @@ +export function clipboard(navigator) { + return function () { + return navigator.clipboard; + }; +} + +export function readText(clipboard) { + return function () { + return clipboard.readText(); + }; +} + +export function writeText(text) { + return function (clipboard) { + return function () { + return clipboard.writeText(text); + }; + }; +} diff --git a/src/Web/Clipboard/Clipboard.purs b/src/Web/Clipboard/Clipboard.purs new file mode 100644 index 0000000..87081da --- /dev/null +++ b/src/Web/Clipboard/Clipboard.purs @@ -0,0 +1,25 @@ +module Web.Clipboard where + +import Prelude + +import Data.Maybe (Maybe) +import Effect (Effect) +import Unsafe.Coerce (unsafeCoerce) +import Web.Event.Internal.Types (EventTarget) +import Web.HTML (Navigator) +import Web.Internal.FFI (unsafeReadProtoTagged) +import Web.Promise (Promise) + +foreign import clipboard :: Navigator -> Effect Clipboard + +foreign import data Clipboard :: Type + +toEventTarget :: Clipboard -> EventTarget +toEventTarget = unsafeCoerce + +fromEventTarget :: EventTarget -> Maybe Clipboard +fromEventTarget = unsafeReadProtoTagged "Clipboard" + +foreign import readText :: Clipboard -> Effect (Promise String) + +foreign import writeText :: String -> Clipboard -> Effect (Promise Unit) From 7686ad151bac463f3566c7262e7c3cdec2267522 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 14 Jul 2022 14:39:08 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e751ca..951b704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,17 @@ Bugfixes: Other improvements: +## [v4.1.0](https://github.com/purescript-web/purescript-web-clipboard/releases/tag/v4.1.0) - 2022-07-14 + +Breaking changes: + +New features: +- Added partial `Clipboard` interface implementation with `readText` and `writeText` operations (#11 by @garyb) + +Bugfixes: + +Other improvements: + ## [v4.0.0](https://github.com/purescript-web/purescript-web-clipboard/releases/tag/v4.0.0) - 2022-04-27 Breaking changes: