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

Commit

Permalink
Merge pull request #2 from jadefish/cross-browser-support
Browse files Browse the repository at this point in the history
Cross browser support
  • Loading branch information
jadefish authored Feb 20, 2020
2 parents 5699281 + 8b2e722 commit 95fc622
Show file tree
Hide file tree
Showing 31 changed files with 10,494 additions and 126 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
clipboard_presenter_plugin (0.0.1)
clipboard_presenter_plugin (0.1.0)

GEM
remote: https://rubygems.org/
Expand All @@ -12,7 +12,7 @@ PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.16)
bundler (~> 1.17.3)
clipboard_presenter_plugin!
rake (~> 10.0)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2019 Nick Miller
Copyright (c) 2019 Nick Miller

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
81 changes: 78 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
# 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 an element: `clipboard cut: :some_field`

## Usage

Include the clipboard_presenter_plugin either globally via the `plugins`
configuration setting

```ruby
# config/initializers/presenters.rb
Voom::Presenters::Settings.configure do |config|
config.presenters.plugins << :clipboard
# Now `clipboard` is available in every POM!
end
```

or on a per-POM basis via the `plugin` method.

```ruby
# presenters/foos/view.pom
Voom::Presenters.define(:view, namespace: :foos) do
plugin :clipboard

# ...
end
```

Then, use one of the clipboard actions in an event handler.

```ruby
text_field id: :my_secret_token do
value current_user.super_secret_token
end

button icon: :file_copy do
tooltip 'Copy token'

event :click do
clipboard copy: :my_secret_token
snackbar 'Copied token to clipboard!'
end
end
```

## Browser support

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 95fc622

Please sign in to comment.