rails-clipboard-helper 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0677492d465fef53bf7ac5e072f8588305f52c9fbf9ca492ea244dcc236536f
4
- data.tar.gz: 8d7083bd4bbf188e7ccdf55f8ea10745dddcea0a5817d8d00eb7573d2a180a62
3
+ metadata.gz: be719a85fc7938e8435fc85ad584ff73a52cd7ae4567bbf114333cc546304f5e
4
+ data.tar.gz: 3f8b196816b0f7769ba662b4f711320107a64fb697d240840248fe334c2a7786
5
5
  SHA512:
6
- metadata.gz: a08bc12b49178a98d48b116b08c98361d6e312eca98471d80fca5c92613ae73bf8ad7fd89178ed50de5513298c9615146234403c007b6622de9d8839487917f0
7
- data.tar.gz: ab6aa201508f6d34af7c05741e94f03051ee0a8980906e465fd726e48fb8fb478c8d2fb9d7d560bddd4b45cf19a824facd445759d7d973e1c380c1d69b1b994f
6
+ metadata.gz: 700dfa05a984dabf155a2986bf3c2506e91042eefd25c6f5b0630ed264594093d3a3f5ec20710447a8a38c3d1112f098f320f8af42aeeb88f116e4591ebc3b0d
7
+ data.tar.gz: 76d58104bccd82495e3520d53ecb120e3045cce0d8f0abb8252f1f0592625392570e589fe00a89b4dd93024a45d85d3d270284e0926ad438a6cc7c1707a30c90
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.3] - 2025-11-09
9
+
10
+ ### Fixed
11
+ - Fixed HTML entity escaping issue in onclick JavaScript
12
+ - Simplified inline JavaScript by removing IIFE wrapper and using `this` directly
13
+
14
+ ### Changed
15
+ - Changed implementation to use hidden DOM element for copied content instead of string escaping
16
+ - Improved code readability and maintainability
17
+
8
18
  ## [0.1.2] - 2025-11-09
9
19
 
10
20
  ### Changed
@@ -39,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
39
49
  - Implemented `clipboard_javascript_tag` helper method (for backward compatibility)
40
50
  - Clipboard copy functionality with automatic JavaScript loading
41
51
  - Rails Engine for automatic asset integration
52
+ [0.1.3]: https://github.com/dhq_boiler/rails-clipboard-helper/releases/tag/v0.1.3
42
53
  - Support for Sprockets, Importmap, esbuild, and webpack
43
54
  - Turbo/Hotwire and Turbolinks support
44
55
  - Customizable button text and CSS classes
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Clipboard
5
5
  module Helper
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.3"
7
7
  end
8
8
  end
9
9
  end
@@ -70,22 +70,21 @@ module Rails
70
70
 
71
71
  # Inline JavaScript for clipboard functionality
72
72
  onclick_js = <<~JS.strip.gsub("\n", ' ')
73
- (function(btn) {
74
- const target = document.getElementById('#{unique_id}');
75
- const text = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' ? target.value : target.textContent;
76
- navigator.clipboard.writeText(text).then(() => {
77
- const original = btn.innerHTML;
78
- btn.innerHTML = '#{copied_content.gsub("'", "\\\\'")}';
79
- btn.style.color = '#28a745';
80
- setTimeout(() => {
81
- btn.innerHTML = original;
82
- btn.style.color = '#0066cc';
83
- }, 2000);
84
- }).catch(err => {
85
- console.error('Failed to copy:', err);
86
- alert('Failed to copy to clipboard');
87
- });
88
- })(this);
73
+ const target = document.getElementById('#{unique_id}');
74
+ const copiedElement = document.getElementById('#{unique_id}-copied');
75
+ const text = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' ? target.value : target.textContent;
76
+ navigator.clipboard.writeText(text).then(() => {
77
+ const original = this.innerHTML;
78
+ this.innerHTML = copiedElement.innerHTML;
79
+ this.style.color = '#28a745';
80
+ setTimeout(() => {
81
+ this.innerHTML = original;
82
+ this.style.color = '#0066cc';
83
+ }, 2000);
84
+ }).catch(err => {
85
+ console.error('Failed to copy:', err);
86
+ alert('Failed to copy to clipboard');
87
+ });
89
88
  JS
90
89
 
91
90
  html = <<~HTML
@@ -101,6 +100,7 @@ module Rails
101
100
  >
102
101
  #{button_content}
103
102
  </button>
103
+ <span id="#{unique_id}-copied" style="display: none;">#{copied_content}</span>
104
104
  </div>
105
105
  HTML
106
106
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-clipboard-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhq_boiler