Skip to content

Commit

Permalink
sync tags registry fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sashafirsov committed May 4, 2024
1 parent 4118459 commit a3b714e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
<xsl:template match="*[name()='template']"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
<xsl:template match="*"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
<xsl:template match="*[name()='svg']|*[name()='math']"><xsl:apply-templates mode="sanitize" select="."/></xsl:template>
<xsl:template mode="sanitize" match="*[count(text())=1 and count(*)=0]"><xsl:copy><xsl:apply-templates mode="sanitize" select="@*"/><xsl:value-of select="text()"/></xsl:copy></xsl:template>
<xsl:template mode="sanitize" match="xhtml:*[count(text())=1 and count(*)=0]"><xsl:element name="{local-name()}"><xsl:apply-templates mode="sanitize" select="@*"/><xsl:value-of select="text()"/></xsl:element></xsl:template>
<xsl:template mode="sanitize" match="*[count(text())=1 and count(*)=0]"><xsl:copy><xsl:apply-templates mode="sanitize" select="@*"/><xsl:value-of select="text()"></xsl:value-of></xsl:copy></xsl:template>
<xsl:template mode="sanitize" match="xhtml:*[count(text())=1 and count(*)=0]"><xsl:element name="{local-name()}"><xsl:apply-templates mode="sanitize" select="@*"/><xsl:value-of select="text()"></xsl:value-of></xsl:element></xsl:template>
<xsl:template mode="sanitize" match="*|@*"><xsl:copy><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:copy></xsl:template>
<xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
<xsl:template mode="sanitize" match="text()"><dce-text><xsl:copy/></dce-text></xsl:template>
Expand Down Expand Up @@ -206,8 +206,7 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
<xsl:choose>
<xsl:when test="//attr">{//attr}</xsl:when>
<xsl:otherwise>{def}</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="."/></xsl:template>
</xsl:choose><xsl:value-of select="."></xsl:value-of></xsl:template>
<xsl:template mode="payload" match="attributes"></xsl:template>
<xsl:template match="/">
<xsl:apply-templates mode="payload" select="/datadom/attributes"/>
Expand Down Expand Up @@ -693,12 +692,17 @@ CustomElement extends HTMLElement

get dce(){ return dce }
}
const registerTag = tag =>
{
if( window.customElements.get(tag) !== DceElement )
window.customElements.define( tag, DceElement);
};
if(tag)
window.customElements.define( tag, DceElement);
registerTag(tag);
else
{ const t = tagName;
this.setAttribute('tag', t );
window.customElements.define( t, DceElement);
registerTag(t);
const el = document.createElement(t);
this.getAttributeNames().forEach(a=>el.setAttribute(a,this.getAttribute(a)));
el.append(...[...this.childNodes].filter( e => e.localName!=='style') );
Expand Down
9 changes: 6 additions & 3 deletions src/http-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class HttpRequestElement extends HTMLElement

async fetch()
{
if( !this.closest('custom-element') )
if( !this.closest('body') )
return;
const url = attr(this, 'url') || '';
if( !url )
Expand Down Expand Up @@ -61,8 +61,11 @@ export class HttpRequestElement extends HTMLElement

slice.response = r;
update();
slice.data = await response.json();
update();
if( r.headers['content-type']?.includes('json'))
try
{ slice.data = await response.json();
update();
}catch(_e){}
}

attributeChangedCallback(name, oldValue, newValue)
Expand Down

0 comments on commit a3b714e

Please sign in to comment.