"function"==typeof t,d={get:(t,e)=>a.hasOwnProperty(e)?((t,e,{get:n,value:s})=>n||!f(s)?t.then((t=>t[e])):(...n)=>t.then((t=>t[e](...n))))(t,e,a[e]):((t,e)=>f(e)?e.bind(t):e)(t,t[e])};customElements.define("list-m",class extends HTMLElement{constructor(){super()}connectedCallback(){this.style.display="block",async function(t){const e=t.getAttribute("source");if(!e)return;const n=await async function(t){const e=document.getElementById(t);if(e)try{const t=JSON.parse(e.textContent);return console.log("data",t),t}catch(t){return!1}else try{return await((t,...e)=>new Proxy(fetch(t,...e),d))(t).json()}catch(t){return!1}}(e);if(!n)return;t.data=n}(this)}set data(t){const e=this.getAttribute("template");try{r(e)}catch(t){}this.innerHTML=this.createList(e,t)}createList(t,e){return e.map((e=>`\n <${t}\n ${function(t){return Object.entries(t).map((([t,e])=>`t-${t}="${e}"`))}(e).join("\n")}\n >${t}>\n `)).join("\n")}});
diff --git a/src/index.js b/src/index.js
index 53fdd1e..1f9af61 100644
--- a/src/index.js
+++ b/src/index.js
@@ -40,9 +40,22 @@ async function init(that) {
that.data = data
}
async function getSourceContent(source) {
- try {
- return await fetch(source).json()
- } catch (e) {
- return false
+ const el = document.getElementById(source)
+ if (el) {
+ try {
+ const data = JSON.parse(el.textContent)
+ console.log('data', data)
+ return data
+ } catch (e) {
+ return false
+ }
+
+ } else {
+ try {
+ return await fetch(source).json()
+ } catch (e) {
+ return false
+ }
}
+
}
\ No newline at end of file
diff --git a/test/index.html b/test/index.html
index 2fd1932..76d3754 100644
--- a/test/index.html
+++ b/test/index.html
@@ -15,6 +15,18 @@
+
list-m Tests
@@ -35,5 +47,9 @@
list-m Tests
template="info-m"
source="./data.txt"
>
+