From f17309b5ad368accceae5d5f298c288a513dc4cb Mon Sep 17 00:00:00 2001 From: Evan Plaice Date: Tue, 11 May 2021 12:43:06 -0600 Subject: [PATCH] Major Bump @vanillaes/interpolate --- index.min.js | 4 ++-- package.json | 2 +- src/wc-sortable-table.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index.min.js b/index.min.js index 33eef56..0da78f7 100644 --- a/index.min.js +++ b/index.min.js @@ -1,7 +1,7 @@ -function c(h,t={}){let e=Object.keys(t),s=Object.values(t);try{return new Function(...e,`return \`${h}\`;`)(...s)}catch(i){throw new o(h,t,i)}}var o=class extends Error{constructor(t,e,s){super();this.name="TemplateError";let i=` +function o(h,t={}){let e=Object.keys(t),s=Object.values(t);try{return new Function(...e,`return \`${h}\`;`)(...s)}catch(i){throw new l(h,t,i)}}var l=class extends Error{constructor(t,e,s){super();this.name="TemplateError";let i=` ------------------ `;i+=`Template: \`${t}\``,i+=` ------------------ `,i+=`Tags: ${JSON.stringify(e,null,2)}`,i+=` ------------------ -`,i+=s,this.message=i}};var d=class extends HTMLElement{static get observedAttributes(){return["src"]}attributeChangedCallback(t,e,s){!this.__initialized||e!==s&&(this[t]=s)}get src(){return this.getAttribute("src")}set src(t){this.setAttribute("src",t),this.setSrc(t)}get value(){return this.__data}set value(t){this.setValue(t)}constructor(){super();this.__initialized=!1,this.__theme=null,this.__data=null,this.__table=null,this.__column=null,this.__headers=null,this.__selected=null}async connectedCallback(){this.__table=document.createElement("table"),this.hasAttribute("theme")?(this.__theme=document.createElement("template"),this.__theme.innerHTML=await this.getTheme(),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(this.__theme.content.cloneNode(!0)),this.shadowRoot.appendChild(this.__table)):this.appendChild(this.__table),this.hasAttribute("src")&&this.setSrc(),this.__initialized=!0}async getTheme(){let t=this.getAttribute("theme"),e=await this.fetchTheme(t);return c(e)}async fetchTheme(t){let e=await fetch(t);if(e.status!==200)throw Error(`ERR ${e.status}: ${e.statusText}`);return e.text()}async setSrc(){this.hasAttribute("src")&&(this.__data=await this.fetchSrc(this.src),this.render())}async fetchSrc(t){let e=await fetch(t);if(e.status!==200)throw Error(`ERR ${e.status}: ${e.statusText}`);return e.json()}setValue(t){this.__data=t,this.render()}sortData(t){if(this.__column===null)return t;let e=this.__column,i=this.__direction?(r,n)=>rr>n;return t.sort((r,n)=>i(r[e],n[e])?-1:1)}headerClicked(t){this.__selected=t.target.cellIndex;let e=t.target.cellIndex;this.__direction=e!==this.__column?!0:!this.__direction,this.__column=e,this.render()}styleHeaders(){let t=this.__direction?"asc":"desc",e=this.__direction?"asc":"desc";for(let s of this.__headers.children)s.cellIndex===this.__selected?s.classList.contains(e)?s.classList.remove(e):s.classList.add(t):(s.classList.contains(t)&&s.classList.remove(t),s.classList.contains(e)&&s.classList.remove(e))}render(){let t=[...this.__data],e=document.createElement("table");this.__headers=document.createElement("tr"),this.__headers.addEventListener("click",n=>this.headerClicked(n)),t.shift().forEach(n=>{let a=document.createElement("th");a.innerText=n,this.__headers.appendChild(a)}),this.styleHeaders();let i=document.createElement("thead");i.appendChild(this.__headers),e.appendChild(i),t=this.sortData(t);let r=document.createElement("tbody");t.forEach(n=>{let a=document.createElement("tr");n.forEach(_=>{let l=document.createElement("td");l.innerText=_,a.appendChild(l)}),r.appendChild(a)}),e.appendChild(r),this.__theme?(this.shadowRoot.removeChild(this.__table),this.__table=e,this.shadowRoot.appendChild(this.__table)):(this.removeChild(this.__table),this.__table=e,this.appendChild(this.__table))}};customElements.define("wc-sortable-table",d);export{d as WCSortableTable}; +`,i+=s,this.message=i}};var d=class extends HTMLElement{static get observedAttributes(){return["src"]}attributeChangedCallback(t,e,s){!this.__initialized||e!==s&&(this[t]=s)}get src(){return this.getAttribute("src")}set src(t){this.setAttribute("src",t),this.setSrc(t)}get value(){return this.__data}set value(t){this.setValue(t)}constructor(){super();this.__initialized=!1,this.__theme=null,this.__data=null,this.__table=null,this.__column=null,this.__headers=null,this.__selected=null}async connectedCallback(){this.__table=document.createElement("table"),this.hasAttribute("theme")?(this.__theme=document.createElement("template"),this.__theme.innerHTML=await this.getTheme(),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(this.__theme.content.cloneNode(!0)),this.shadowRoot.appendChild(this.__table)):this.appendChild(this.__table),this.hasAttribute("src")&&this.setSrc(),this.__initialized=!0}async getTheme(){let t=this.getAttribute("theme"),e=await this.fetchTheme(t);return o(e)}async fetchTheme(t){let e=await fetch(t);if(e.status!==200)throw Error(`ERR ${e.status}: ${e.statusText}`);return e.text()}async setSrc(){this.hasAttribute("src")&&(this.__data=await this.fetchSrc(this.src),this.render())}async fetchSrc(t){let e=await fetch(t);if(e.status!==200)throw Error(`ERR ${e.status}: ${e.statusText}`);return e.json()}setValue(t){this.__data=t,this.render()}sortData(t){if(this.__column===null)return t;let e=this.__column,i=this.__direction?(r,n)=>rr>n;return t.sort((r,n)=>i(r[e],n[e])?-1:1)}headerClicked(t){this.__selected=t.target.cellIndex;let e=t.target.cellIndex;this.__direction=e!==this.__column?!0:!this.__direction,this.__column=e,this.render()}styleHeaders(){let t=this.__direction?"asc":"desc",e=this.__direction?"asc":"desc";for(let s of this.__headers.children)s.cellIndex===this.__selected?s.classList.contains(e)?s.classList.remove(e):s.classList.add(t):(s.classList.contains(t)&&s.classList.remove(t),s.classList.contains(e)&&s.classList.remove(e))}render(){let t=[...this.__data],e=document.createElement("table");this.__headers=document.createElement("tr"),this.__headers.addEventListener("click",n=>this.headerClicked(n)),t.shift().forEach(n=>{let a=document.createElement("th");a.innerText=n,this.__headers.appendChild(a)}),this.styleHeaders();let i=document.createElement("thead");i.appendChild(this.__headers),e.appendChild(i),t=this.sortData(t);let r=document.createElement("tbody");t.forEach(n=>{let a=document.createElement("tr");n.forEach(_=>{let c=document.createElement("td");c.innerText=_,a.appendChild(c)}),r.appendChild(a)}),e.appendChild(r),this.__theme?(this.shadowRoot.removeChild(this.__table),this.__table=e,this.shadowRoot.appendChild(this.__table)):(this.removeChild(this.__table),this.__table=e,this.appendChild(this.__table))}};customElements.define("wc-sortable-table",d);export{d as WCSortableTable}; diff --git a/package.json b/package.json index 284b8b7..8be70ea 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "postversion": "git push --follow-tags" }, "devDependencies": { - "@vanillaes/interpolate": "^1.4.0", + "@vanillaes/interpolate": "^2.0.4", "esmtk": "^0.5.6" }, "standard": { diff --git a/src/wc-sortable-table.js b/src/wc-sortable-table.js index 8c9eccf..725a689 100644 --- a/src/wc-sortable-table.js +++ b/src/wc-sortable-table.js @@ -1,5 +1,5 @@ /* eslint no-undef: 0 */ -import Interpolate from '../node_modules/@vanillaes/interpolate/index.js' +import { interpolate } from '../node_modules/@vanillaes/interpolate/index.js' export class WCSortableTable extends HTMLElement { static get observedAttributes () { @@ -58,7 +58,7 @@ export class WCSortableTable extends HTMLElement { async getTheme () { const path = this.getAttribute('theme') const contents = await this.fetchTheme(path) - return Interpolate(contents) + return interpolate(contents) } async fetchTheme (src) {