From 73c6e0c6d057f6f5a612f718269398e454b5bd40 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sat, 26 Aug 2023 03:55:12 +0530 Subject: [PATCH] Bug fix --- components/dist/copy.js | 3 +-- components/dist/copy.min.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/dist/copy.js b/components/dist/copy.js index 7aa4016..6cbd358 100644 --- a/components/dist/copy.js +++ b/components/dist/copy.js @@ -75,7 +75,6 @@ customElements.define('sm-copy', this.attachShadow({ mode: 'open' }).append(smCopy.content.cloneNode(true)); - this.copyContent = this.shadowRoot.querySelector('.copy-content'); this.copyButton = this.shadowRoot.querySelector('.copy-button'); @@ -113,7 +112,7 @@ customElements.define('sm-copy', if (!slot) return; const assignedNodes = slot.assignedNodes(); if (!assignedNodes || !assignedNodes.length) { - this.copyContent.textContent = newValue; + slot.textContent = newValue; } } } diff --git a/components/dist/copy.min.js b/components/dist/copy.min.js index a9ae633..5400b6b 100644 --- a/components/dist/copy.min.js +++ b/components/dist/copy.min.js @@ -1 +1 @@ -const smCopy=document.createElement("template");smCopy.innerHTML='\n\n
\n

\n \n

\n \n
\n',customElements.define("sm-copy",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCopy.content.cloneNode(!0)),this.copyContent=this.shadowRoot.querySelector(".copy-content"),this.copyButton=this.shadowRoot.querySelector(".copy-button"),this.copy=this.copy.bind(this)}static get observedAttributes(){return["value"]}set value(t){this.setAttribute("value",t)}get value(){return this.getAttribute("value")}fireEvent(){this.dispatchEvent(new CustomEvent("copy",{composed:!0,bubbles:!0,cancelable:!0}))}copy(){navigator.clipboard.writeText(this.getAttribute("value")).then(t=>this.fireEvent()).catch(t=>console.error(t))}connectedCallback(){this.copyButton.addEventListener("click",this.copy)}attributeChangedCallback(t,n,o){if("value"===t){const t=this.copyContent.querySelector("slot");if(!t)return;const n=t.assignedNodes();n&&n.length||(this.copyContent.textContent=o)}}disconnectedCallback(){this.copyButton.removeEventListener("click",this.copy)}}); \ No newline at end of file +const smCopy=document.createElement("template");smCopy.innerHTML='\n\n
\n

\n \n

\n \n
\n',customElements.define("sm-copy",class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).append(smCopy.content.cloneNode(!0)),this.copyContent=this.shadowRoot.querySelector(".copy-content"),this.copyButton=this.shadowRoot.querySelector(".copy-button"),this.copy=this.copy.bind(this)}static get observedAttributes(){return["value"]}set value(t){this.setAttribute("value",t)}get value(){return this.getAttribute("value")}fireEvent(){this.dispatchEvent(new CustomEvent("copy",{composed:!0,bubbles:!0,cancelable:!0}))}copy(){navigator.clipboard.writeText(this.getAttribute("value")).then(t=>this.fireEvent()).catch(t=>console.error(t))}connectedCallback(){this.copyButton.addEventListener("click",this.copy)}attributeChangedCallback(t,n,o){if("value"===t){const t=this.copyContent.querySelector("slot");if(!t)return;const n=t.assignedNodes();n&&n.length||(t.textContent=o)}}disconnectedCallback(){this.copyButton.removeEventListener("click",this.copy)}}); \ No newline at end of file