@radioactive-labs/plutonium 0.41.1 → 0.43.0
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.
- package/package.json +1 -1
- package/src/dist/css/plutonium.css +2 -2
- package/src/dist/js/plutonium.js +46 -1
- package/src/dist/js/plutonium.js.map +4 -4
- package/src/dist/js/plutonium.min.js +32 -32
- package/src/dist/js/plutonium.min.js.map +4 -4
- package/src/js/controllers/clipboard_controller.js +37 -0
- package/src/js/controllers/register_controllers.js +2 -0
- package/src/js/controllers/remote_modal_controller.js +18 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["source"]
|
|
5
|
+
|
|
6
|
+
copy(event) {
|
|
7
|
+
const text = this.sourceTarget.value || this.sourceTarget.textContent
|
|
8
|
+
const button = event.currentTarget
|
|
9
|
+
const originalText = button.textContent
|
|
10
|
+
|
|
11
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
12
|
+
button.textContent = "Copied!"
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
button.textContent = originalText
|
|
15
|
+
}, 2000)
|
|
16
|
+
}).catch((err) => {
|
|
17
|
+
// Fallback for browsers that don't support clipboard API
|
|
18
|
+
console.warn("Clipboard API failed, using fallback:", err)
|
|
19
|
+
this.fallbackCopy(text)
|
|
20
|
+
button.textContent = "Copied!"
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
button.textContent = originalText
|
|
23
|
+
}, 2000)
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fallbackCopy(text) {
|
|
28
|
+
const textarea = document.createElement("textarea")
|
|
29
|
+
textarea.value = text
|
|
30
|
+
textarea.style.position = "fixed"
|
|
31
|
+
textarea.style.opacity = "0"
|
|
32
|
+
document.body.appendChild(textarea)
|
|
33
|
+
textarea.select()
|
|
34
|
+
document.execCommand("copy")
|
|
35
|
+
document.body.removeChild(textarea)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -23,6 +23,7 @@ import KeyValueStoreController from "./key_value_store_controller.js"
|
|
|
23
23
|
import BulkActionsController from "./bulk_actions_controller.js"
|
|
24
24
|
import FilterPanelController from "./filter_panel_controller.js"
|
|
25
25
|
import TextareaAutogrowController from "./textarea_autogrow_controller.js"
|
|
26
|
+
import ClipboardController from "./clipboard_controller.js"
|
|
26
27
|
|
|
27
28
|
export default function (application) {
|
|
28
29
|
// Register controllers here
|
|
@@ -50,4 +51,5 @@ export default function (application) {
|
|
|
50
51
|
application.register("bulk-actions", BulkActionsController)
|
|
51
52
|
application.register("filter-panel", FilterPanelController)
|
|
52
53
|
application.register("textarea-autogrow", TextareaAutogrowController)
|
|
54
|
+
application.register("clipboard", ClipboardController)
|
|
53
55
|
}
|
|
@@ -3,8 +3,13 @@ import { Controller } from "@hotwired/stimulus";
|
|
|
3
3
|
// Connects to data-controller="remote-modal"
|
|
4
4
|
export default class extends Controller {
|
|
5
5
|
connect() {
|
|
6
|
-
// Store original scroll position
|
|
6
|
+
// Store original scroll position and body overflow
|
|
7
7
|
this.originalScrollPosition = window.scrollY;
|
|
8
|
+
this.originalOverflow = document.body.style.overflow;
|
|
9
|
+
this.bodyStateRestored = false;
|
|
10
|
+
|
|
11
|
+
// Lock body scroll
|
|
12
|
+
document.body.style.overflow = "hidden";
|
|
8
13
|
|
|
9
14
|
// Show the modal
|
|
10
15
|
this.element.showModal();
|
|
@@ -15,17 +20,26 @@ export default class extends Controller {
|
|
|
15
20
|
close() {
|
|
16
21
|
// Close the modal
|
|
17
22
|
this.element.close();
|
|
18
|
-
|
|
19
|
-
window.scrollTo(0, this.originalScrollPosition);
|
|
23
|
+
this.restoreBodyState();
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
disconnect() {
|
|
23
27
|
// Clean up event listener when controller is disconnected
|
|
24
28
|
this.element.removeEventListener("close", this.handleClose);
|
|
29
|
+
this.restoreBodyState();
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
handleClose() {
|
|
28
|
-
|
|
33
|
+
this.restoreBodyState();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
restoreBodyState() {
|
|
37
|
+
if (this.bodyStateRestored) return;
|
|
38
|
+
this.bodyStateRestored = true;
|
|
39
|
+
|
|
40
|
+
// Restore body overflow
|
|
41
|
+
document.body.style.overflow = this.originalOverflow || "";
|
|
42
|
+
// Restore the original scroll position
|
|
29
43
|
window.scrollTo(0, this.originalScrollPosition);
|
|
30
44
|
}
|
|
31
45
|
}
|