From db3dfeffba53dd1cfd253b3056a0567d56222084 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Thu, 15 Jun 2023 01:32:03 +0530 Subject: [PATCH] Bug fix --- components/dist/copy.js | 2 +- components/dist/copy.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/dist/copy.js b/components/dist/copy.js index a7d48a9..1b735d8 100644 --- a/components/dist/copy.js +++ b/components/dist/copy.js @@ -109,7 +109,7 @@ customElements.define('sm-copy', } attributeChangedCallback(name, oldValue, newValue) { if (name === 'value') { - if (this.copyContent.querySelector('slot').assignedNodes().length === 0) + if (this.copyContent.querySelector('slot').assignedNodes() && this.copyContent.querySelector('slot').assignedNodes().length === 0) this.copyContent.textContent = newValue; } } diff --git a/components/dist/copy.min.js b/components/dist/copy.min.js index 5d7e9ec..b69e8f3 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){"value"===t&&0===this.copyContent.querySelector("slot").assignedNodes().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){"value"===t&&this.copyContent.querySelector("slot").assignedNodes()&&0===this.copyContent.querySelector("slot").assignedNodes().length&&(this.copyContent.textContent=o)}disconnectedCallback(){this.copyButton.removeEventListener("click",this.copy)}}); \ No newline at end of file