Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Commit

Permalink
Fix functionality in Safari and Firefox
Browse files Browse the repository at this point in the history
In browsers which do not support the native asynchronous Clipboard API,
the plugin now falls back to an interaction strategy which utilizes
`document.execCommand`.

Browsers supporting the Clipboard API continue to function as expected,
sans permissions checking. This may change in the future.

* Rewrite in TypeScript
* Transpile JS with Babel
* Bundle with Webpack
* Add unit tests
* Remove paste functionality

[#1]
  • Loading branch information
jadefish committed Feb 20, 2020
1 parent 7192c1f commit ad78e5e
Show file tree
Hide file tree
Showing 29 changed files with 10,441 additions and 126 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# clipboard_presenter_plugin

A plugin for [voom/presenters](https://github.com/rx/presenters) which
provides clipboard interaction via the
[clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API).
The clipboard_presenter_plugin is a plugin for
[rx/presenters](https://github.com/rx/presenters) which provides clipboard
interaction.

## Actions

The clipboard_presenter_plugin provides the following actions:

* Copy from an element: `clipboard copy: :some_field`
* Cut from a mutable element: `clipboard cut: :another_field`
* Paste into a mutable element: `clipboard paste: :receiving_field`
* Cut from an element: `clipboard cut: :some_field`

## Usage

Expand Down Expand Up @@ -55,4 +54,27 @@ end

## Browser support

Currently, the clipboard Presenters plugin only supports Chrome. :(
The following browsers are considered officially supported:

* Chrome 42+
* Edge 12+
* Firefox 41+
* Safari 10+

## Building

0. `nvm use && npm i`
1. `npm run type-check`
2. Compile TS to JS: `npm run build` (output: `views/clipboard/build`)
3. Transpile and bundle via Babel and Webpack: `npm run bundle:dev` (output:
`dist/bundle.js`)

Or, `npm run watch` to watch `views/clipboard/src` for changes and run steps 1-3 above.

## Contributing

1. Fork it
2. Branch it
4. Fix it
4. PR it
5. Done!
2 changes: 1 addition & 1 deletion clipboard_presenter_plugin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
end
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "bundler", "~> 1.17.3"
spec.add_development_dependency "rake", "~> 10.0"
end
26 changes: 1 addition & 25 deletions demo/clipboard.pom
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,14 @@ Voom::Presenters.define(:clipboard, namespace: :plugins) do
indented_grid do
headline 'Copy'
text_field id: :copy_me do
value 'Copy that.'
value "Don't copy that floppy!"
end
button :copy, type: :raised do
event :click do
clipboard copy: :copy_me
end
end
end

indented_grid do
headline 'Cut'
text_field id: :cut_me do
value 'Prepare to get cut!'
end
button :cut, type: :raised do
event :click do
clipboard cut: :cut_me
end
end
end

indented_grid do
headline 'Paste'
text_field id: :paste_me do
value 'Do not eat paste.'
end
button :paste, type: :raised do
event :click do
clipboard paste: :paste_me
end
end
end
end

attach :code, file: __FILE__
Expand Down
2 changes: 1 addition & 1 deletion lib/voom/presenters/plugins/clipboard/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Voom
module Presenters
module Plugins
module Clipboard
VALID_ACTIONS = %i[cut copy paste].freeze
VALID_ACTIONS = %i[cut copy].freeze

class Action < DSL::Components::Actions::Base
attr_reader :action,
Expand Down
91 changes: 0 additions & 91 deletions lib/voom/presenters/plugins/clipboard/clipboard.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/voom/presenters/plugins/clipboard/clipboard_header.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<script>
<%= File.read(File.expand_path('clipboard.js', __dir__) ) %>
<%= File.read(File.expand_path('../../../../../public/bundle.js', __dir__) ) %>
</script>
2 changes: 1 addition & 1 deletion lib/voom/presenters/plugins/clipboard/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Voom
module Presenters
module Plugins
module Clipboard
VERSION = '0.0.1'.freeze
VERSION = '0.1.0'.freeze
end
end
end
Expand Down
183 changes: 183 additions & 0 deletions public/bundle.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions views/clipboard/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"presets": [
["@babel/env", {
"targets": {
"chrome": "42",
"edge": "12",
"firefox": "41",
"ie": "9",
"opera": "29",
"safari": "10"
}
}],
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties"
],
"sourceType": "unambiguous",

"env": {
"test": {
"plugins": [
["@babel/plugin-transform-runtime", {
"regenerator": true
}]
]
}
}
}
3 changes: 3 additions & 0 deletions views/clipboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/build
coverage
1 change: 1 addition & 0 deletions views/clipboard/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.16
Loading

0 comments on commit ad78e5e

Please sign in to comment.