Skip to content

Add Clipboard interface, readText, writeText #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
19 changes: 19 additions & 0 deletions src/Web/Clipboard/Clipboard.js
Original file line number Diff line number Diff line change
@@ -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);
};
};
}
25 changes: 25 additions & 0 deletions src/Web/Clipboard/Clipboard.purs
Original file line number Diff line number Diff line change
@@ -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)