mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-17 21:33:16 +08:00
2ff327e742
* Implement cells bin * Temporarily keep cells source * Send complete bin entries from session to clients when a cell gets removed * Polish styles * Hydrate bin entries on section deletion as well
39 lines
808 B
JavaScript
39 lines
808 B
JavaScript
import { getAttributeOrThrow } from "../lib/attribute";
|
|
|
|
/**
|
|
* A hook adding click handler that copies text from the target
|
|
* element to clipboard.
|
|
*
|
|
* Configuration:
|
|
*
|
|
* * `data-target-id` - HTML id of the element whose `innerText` is copied
|
|
*/
|
|
const ClipCopy = {
|
|
mounted() {
|
|
this.props = getProps(this);
|
|
|
|
this.el.addEventListener("click", (event) => {
|
|
const target = document.getElementById(this.props.targetId);
|
|
|
|
if (target) {
|
|
const text = target.innerText;
|
|
|
|
if ("clipboard" in navigator) {
|
|
navigator.clipboard.writeText(text);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
updated() {
|
|
this.props = getProps(this);
|
|
},
|
|
};
|
|
|
|
function getProps(hook) {
|
|
return {
|
|
targetId: getAttributeOrThrow(hook.el, "data-target-id"),
|
|
};
|
|
}
|
|
|
|
export default ClipCopy;
|