Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copy-component

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-component - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

11

CopyComponent.js

@@ -1,8 +0,2 @@

const copyText = async (elements) => {
// Copy to the clipboard
const doc = document.createDocumentFragment();
const element = document.createElement("div");
doc.appendChild(element);
elements.forEach((el) => element.appendChild(el.cloneNode(true)));
const copyText = async (element) => {
if ("clipboard" in navigator) {

@@ -92,3 +86,4 @@ try {

try {
await copyText(slottedElements);
// cant support multiple elements due to formatting problems with the other slots
await copyText(slottedElements[0]);
this.dispatchEvent(

@@ -95,0 +90,0 @@ new CustomEvent("copy", {

{
"name": "copy-component",
"version": "0.2.0",
"version": "0.3.0",
"description": "A vanilla custom element that adds the capability to wrap html so it the inner text can be added to the users clipboard",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -13,2 +13,3 @@ # copy-component

- Browser support: Modern, requires support for Web Component APIs (v1).
- Limitation: In order to ensure that formatting can be copied this component requires you to [wrap your copyable content in a single element)[#limitations].

@@ -48,2 +49,30 @@ [Live Demos](https://griffa.dev/demos/copy-component/)

## Limitations
In order to preserve the formatting of copied content you must wrap your content you want to copy in single parent dom node i.e.
```html
<copy-component>
<div>
<p>Stuff to copy</p>
<br />
<p>Copy me too!</p>
</div>
<button slot="button">Copy me!</button>
</copy-component>
```
NOT
```html
<copy-component>
<p>Stuff to copy</p>
<br />
<p>Copy me too!</p>
<button slot="button">Copy me!</button>
</copy-component>
```
This is because due to how shadow dom works, it is not possible to get the formatted inner text of a single slot without also getting the text of the other slots (e.g. the button slot).
## Programmatic API

@@ -50,0 +79,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc