@epa-wg/custom-element-dist 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/.gitignore +8 -0
- package/README.md +4 -4
- package/coverage/coverage-final.json +13 -11
- package/coverage/index.html +30 -30
- package/coverage/src/custom-element/coverage.svg +1 -1
- package/coverage/src/custom-element/custom-element.js/coverage.svg +1 -1
- package/coverage/src/custom-element/custom-element.js.html +603 -420
- package/coverage/src/custom-element/http-request.js.html +10 -10
- package/coverage/src/custom-element/index.html +18 -18
- package/coverage/src/custom-element/local-storage.js.html +2 -2
- package/coverage/src/custom-element/location-element.js.html +1 -1
- package/coverage/src/index.html +1 -1
- package/coverage/src/mocks/handlers.ts.html +1 -1
- package/coverage/src/mocks/index.html +1 -1
- package/coverage/src/stories/{css.stories.ts → attributes.test.stories.ts}/coverage.svg +1 -1
- package/coverage/src/stories/{attributes.stories.ts.html → attributes.test.stories.ts.html} +113 -83
- package/coverage/src/stories/coverage.svg +1 -1
- package/coverage/src/stories/css.test.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/{css.stories.ts.html → css.test.stories.ts.html} +122 -65
- package/coverage/src/stories/dom-merge.test.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/{dom-merge.stories.ts.html → dom-merge.test.stories.ts.html} +118 -70
- package/coverage/src/stories/external-template.test.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/{external-template.stories.ts.html → external-template.test.stories.ts.html} +180 -150
- package/coverage/src/stories/form.test.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/form.test.stories.ts.html +655 -0
- package/coverage/src/stories/http-request.stories.ts.html +7 -7
- package/coverage/src/stories/index.html +118 -88
- package/coverage/src/stories/{dom-merge.stories.ts → local-storage.test.stories.ts}/coverage.svg +1 -1
- package/coverage/src/stories/{local-storage.stories.ts.html → local-storage.test.stories.ts.html} +475 -439
- package/coverage/src/stories/{external-template.stories.ts → location-element.test.stories.ts}/coverage.svg +1 -1
- package/coverage/src/stories/{location-element.stories.ts.html → location-element.test.stories.ts.html} +134 -98
- package/coverage/src/stories/slice-events.test.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/slice-events.test.stories.ts.html +685 -0
- package/coverage/src/stories/slots.test.stories.ts/coverage.svg +10 -0
- package/coverage/src/stories/slots.test.stories.ts.html +736 -0
- package/coverage/src/stories/{renderPlay.ts.html → testStoryBook.ts.html} +44 -26
- package/coverage/src/sum.ts.html +1 -1
- package/dist/custom-element-BISbI4SU.js +463 -0
- package/dist/custom-element-N-sWiqGK.cjs +53 -0
- package/dist/custom-element-bundle.cjs +1 -1
- package/dist/custom-element-bundle.js +2 -2
- package/dist/mockServiceWorker.js +1 -1
- package/package.json +4 -4
- package/public/mockServiceWorker.js +1 -1
- package/src/custom-element/custom-element.d.ts +4 -0
- package/src/custom-element/custom-element.js +103 -42
- package/src/custom-element/demo/a.html +38 -41
- package/src/custom-element/demo/b.html +13 -0
- package/src/custom-element/demo/data-slices.html +32 -0
- package/src/custom-element/demo/form.html +240 -0
- package/src/custom-element/demo/s.xml +11 -14
- package/src/custom-element/demo/s.xslt +22 -38
- package/src/custom-element/demo/s1.xslt +60 -0
- package/src/custom-element/ide/customData-dce.json +14 -1
- package/src/custom-element/ide/web-types-dce.json +6 -1
- package/src/custom-element/ide/web-types-xsl.json +1 -1
- package/src/custom-element/index.html +1 -0
- package/src/custom-element.test.ts +24 -8
- package/src/stories/{attributes.stories.ts → attributes.test.stories.ts} +19 -9
- package/src/stories/{css.stories.ts → css.test.stories.ts} +28 -9
- package/src/stories/{dom-merge.stories.ts → dom-merge.test.stories.ts} +19 -3
- package/src/stories/{external-template.stories.ts → external-template.test.stories.ts} +13 -3
- package/src/stories/form.test.stories.ts +190 -0
- package/src/stories/http-request.stories.ts +6 -6
- package/src/stories/http-request.test.ts +0 -9
- package/src/stories/{local-storage.stories.ts → local-storage.test.stories.ts} +24 -12
- package/src/stories/{location-element.stories.ts → location-element.test.stories.ts} +21 -9
- package/src/stories/{slice-events.stories.ts → slice-events.test.stories.ts} +88 -5
- package/src/stories/slots.test.stories.ts +217 -0
- package/src/stories/testStoryBook.ts +28 -0
- package/storybook-static/assets/{Color-RQJUDNI5-C4yZhNbM.js → Color-PRSJMWNM-BD_Ds9NW.js} +1 -1
- package/storybook-static/assets/{Configure-C7d36rng.js → Configure-70I_VApa.js} +1 -1
- package/storybook-static/assets/DocsRenderer-K4EAMTCU-9dn0-HCP.js +2 -0
- package/storybook-static/assets/WithTooltip-KJL26V4Q-C6g5GOU9.js +1 -0
- package/storybook-static/assets/{attributes.stories-ZB0RTY1d.js → attributes.test.stories-BEOraI4E.js} +22 -21
- package/storybook-static/assets/css.test.stories-D9WaxrEv.js +96 -0
- package/storybook-static/assets/custom-element-BV8-hRQS.js +219 -0
- package/storybook-static/assets/{dom-merge.stories-CgHZUABU.js → dom-merge.test.stories-BhbNeum_.js} +5 -6
- package/storybook-static/assets/{entry-preview-CQqNFx4W.js → entry-preview-DrgzXgwT.js} +1 -1
- package/storybook-static/assets/{entry-preview-docs-CWgqLfd3.js → entry-preview-docs-Bxv0qQWs.js} +1 -1
- package/storybook-static/assets/{external-template.stories-DtSLMxvg.js → external-template.test.stories-Bpr_wxBo.js} +23 -24
- package/storybook-static/assets/form.test.stories-3tURbEdv.js +250 -0
- package/storybook-static/assets/{formatter-B5HCVTEV-tKeEfJA9.js → formatter-2WMMO6ZP-6IvBq34u.js} +5 -5
- package/storybook-static/assets/http-request.stories-8K_qSs8C.js +300 -0
- package/storybook-static/assets/iframe-zdt9kuj6.js +2 -0
- package/storybook-static/assets/index-B3oZkK3F.js +1 -0
- package/storybook-static/assets/index-C30JwJMK.js +548 -0
- package/storybook-static/assets/index-CVRyq5ci.js +27 -0
- package/storybook-static/assets/index-DXimoRZY.js +1 -0
- package/storybook-static/assets/{index-DnEJ_bKa.js → index-DhXZyjEd.js} +1 -1
- package/storybook-static/assets/index-DuIEV_9C.js +13 -0
- package/storybook-static/assets/{lit-element-B4_0akdT.js → lit-element-CenEXOuS.js} +2 -2
- package/storybook-static/assets/{local-storage.stories-BkO6djDz.js → local-storage.test.stories-CtisAQBB.js} +28 -24
- package/storybook-static/assets/{location-element.stories-DCIOUd0D.js → location-element.test.stories-5O_t_m4Y.js} +11 -11
- package/storybook-static/assets/preview-4Up_z4Em.js +7 -0
- package/storybook-static/assets/preview-BKCN0mOr.js +1 -0
- package/storybook-static/assets/{preview-CkgAD_DE.js → preview-D0eCfQft.js} +2 -2
- package/storybook-static/assets/preview-DRnyIGXK.js +48 -0
- package/storybook-static/assets/preview-FpHGYA1q.js +1 -0
- package/storybook-static/assets/{preview-PxUn-cIn.js → preview-TCN6m6T-.js} +1 -1
- package/storybook-static/assets/slice-events.test.stories-BSXCLIA5.js +231 -0
- package/storybook-static/assets/slots.test.stories-B1vqfHmN.js +214 -0
- package/storybook-static/assets/syntaxhighlighter-BP7B2CQK-DpPBKyTO.js +1 -0
- package/storybook-static/iframe.html +153 -10
- package/storybook-static/index.html +1 -1
- package/storybook-static/index.json +1 -1
- package/storybook-static/mockServiceWorker.js +1 -1
- package/storybook-static/project.json +1 -1
- package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js +35 -29
- package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js.LEGAL.txt +1 -1
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +5 -5
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +35 -35
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/interactions-10/manager-bundle.js +18 -16
- package/storybook-static/sb-addons/links-1/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +1 -1
- package/storybook-static/sb-manager/WithTooltip-KJL26V4Q-5LS5AN27.js +1 -0
- package/storybook-static/sb-manager/{chunk-S4VOIVUE.js → chunk-B3YDJJJH.js} +9 -9
- package/storybook-static/sb-manager/{chunk-FEE35O7J.js → chunk-BLWCBWKL.js} +3 -3
- package/storybook-static/sb-manager/{chunk-XCO5HRLK.js → chunk-GUVK2GTO.js} +3 -3
- package/storybook-static/sb-manager/chunk-LFRML3ZV.js +186 -0
- package/storybook-static/sb-manager/chunk-MC7RAF2B.js +274 -0
- package/storybook-static/sb-manager/{chunk-XP3HGWTR.js → chunk-ZR5JZWHI.js} +1 -1
- package/storybook-static/sb-manager/{formatter-B5HCVTEV-7DCBOGO6.js → formatter-2WMMO6ZP-JI7RHVTW.js} +1 -1
- package/storybook-static/sb-manager/globals-module-info.js +1 -1
- package/storybook-static/sb-manager/globals-runtime.js +1 -1
- package/storybook-static/sb-manager/index.js +1 -1
- package/storybook-static/sb-manager/runtime.js +1 -1
- package/storybook-static/sb-manager/{syntaxhighlighter-JOJW2KGS-VF6EEVPI.js → syntaxhighlighter-BP7B2CQK-WOJYHKQR.js} +1 -1
- package/storybook-static/sb-preview/runtime.js +28 -11
- package/tsconfig.json +31 -21
- package/vite.config.js +5 -5
- package/yarn.lock +10242 -0
- package/.vscode/settings.json +0 -24
- package/coverage/src/stories/local-storage.stories.ts/coverage.svg +0 -10
- package/coverage/src/stories/location-element.stories.ts/coverage.svg +0 -10
- package/coverage/src/stories/renderPlay.ts/coverage.svg +0 -10
- package/coverage/src/stories/slice-events.stories.ts/coverage.svg +0 -10
- package/coverage/src/stories/slice-events.stories.ts.html +0 -436
- package/dist/custom-element-B4v-KaIh.cjs +0 -53
- package/dist/custom-element-_g0GTup2.js +0 -436
- package/src/stories/attributes.test.ts +0 -14
- package/src/stories/css.test.ts +0 -12
- package/src/stories/dom-merge.test.ts +0 -12
- package/src/stories/external-template.test.ts +0 -12
- package/src/stories/local-storage.test.ts +0 -12
- package/src/stories/location-element.test.ts +0 -14
- package/src/stories/renderPlay.ts +0 -22
- package/src/stories/slice-events.test.ts +0 -12
- package/storybook-static/assets/DocsRenderer-K4EAMTCU-BLMupvSb.js +0 -2
- package/storybook-static/assets/WithTooltip-Y7J54OF7-BAQSPSFk.js +0 -1
- package/storybook-static/assets/css.stories-CLSX-Xxd.js +0 -86
- package/storybook-static/assets/custom-element-BLZZ00dz.js +0 -53
- package/storybook-static/assets/http-request.stories-CUzlXO89.js +0 -300
- package/storybook-static/assets/iframe-gCvlWuoC.js +0 -2
- package/storybook-static/assets/index-CBQwM6ST.js +0 -508
- package/storybook-static/assets/index-CDavW7r9.js +0 -193
- package/storybook-static/assets/index-CQA5dlr6.js +0 -13
- package/storybook-static/assets/index-DgaNIR0t.js +0 -1
- package/storybook-static/assets/index-Dkj0J1ds.js +0 -1
- package/storybook-static/assets/preview-C6t8KBFr.js +0 -1
- package/storybook-static/assets/preview-CYD85dwb.js +0 -7
- package/storybook-static/assets/preview-D8LadFCz.js +0 -48
- package/storybook-static/assets/preview-DNpCpRPf.js +0 -1
- package/storybook-static/assets/slice-events.stories-DXKjXI37.js +0 -115
- package/storybook-static/assets/syntaxhighlighter-JOJW2KGS-C04pIVD3.js +0 -1
- package/storybook-static/sb-manager/WithTooltip-Y7J54OF7-CEHQ77YF.js +0 -1
- package/storybook-static/sb-manager/chunk-E3WK6ZOZ.js +0 -234
- package/storybook-static/sb-manager/chunk-E6ABNH5R.js +0 -183
- /package/coverage/src/stories/{attributes.stories.ts → testStoryBook.ts}/coverage.svg +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";const B="http://www.w3.org/1999/XSL/Transform",q="http://www.w3.org/1999/xhtml",de="http://exslt.org/common",x=(e,l)=>e.getAttribute?.(l),K=e=>e.nodeType===3,pe=e=>typeof e=="string",fe=e=>e&&typeof e.nodeType=="number",N=(e,l="",t=document)=>(s=>(l&&s.append(S(t.ownerDocument||t,l)),s))((t.ownerDocument||t).createElement(e)),S=(e,l)=>(e.ownerDocument||e).createTextNode(l),Z=e=>{for(;e.firstChild;)e.firstChild.remove();return e},H=e=>(e.getAttributeNames().map(l=>e.removeAttribute(l)),Z(e)),he=e=>(e?.setAttribute("xmlns:xsl",B),e),xe=e=>(e?.setAttribute("xmlns:xhtml",q),he(e)),Q=(e,l)=>{const t=e.ownerDocument.createElementNS(e.namespaceURI,l);for(let s of e.attributes)t.setAttribute(s.name,s.value);for(;e.firstChild;)t.append(e.firstChild);return t};function $(e){return new DOMParser().parseFromString(e,"application/xml")}function M(e){return new XMLSerializer().serializeToString(e)}function U(e,l,t,s){const n=h=>e.ownerDocument.createElement(h),c=((h,p,m)=>(p.append(m=n(h)),m))(l,e);return[...t].forEach(h=>c.append(s(h))),c}function ye(e){return e.slot||(e.setAttribute||(e=N("span",e.textContent.replaceAll(`
|
|
2
|
+
`,""))),e.setAttribute("slot","")),e}function C(e,l,t){const s=typeof e;if(s==="string")return N(l,e,t);if(s==="number")return N(l,""+e,t);if(e instanceof Array){const i=N("array","",t);return e.map(c=>i.append(C(c,l,t))),i}if(e instanceof FormData){const i=N("form-data","",t);for(const c of e)i.append(C(c[1],c[0],t));return i}const n=N(l,"",t);for(let i in e)fe(e[i])||typeof e[i]=="function"||e[i]instanceof Window||(typeof e[i]!="object"?n.setAttribute(i,e[i]):n.append(C(e[i],i,t)));return n}function W(e){if(D(e,"*",l=>[...l.childNodes].filter(t=>t.nodeType===3&&t.parentNode.localName!=="style"&&t.data).forEach(t=>{const s=t.data,n=s.matchAll(/{([^}]*)}/g);if(n){let i=0,c=p=>S(t,p),h=[];if([...n].forEach(p=>{p.index>i&&h.push(c(p.input.substring(i,p.index)));const m=e.querySelector("value-of").cloneNode();m.setAttribute("select",p[1]),h.push(m),i=p.index+p[0].length}),i<s.length&&h.push(c(s.substring(i,s.length))),h.length){for(let p of h)l.insertBefore(p,t);l.removeChild(t)}}})),"all"in e){let l=1;for(let t of e.all)t.setAttribute&&!t.tagName.startsWith("xsl:")&&t.setAttribute("data-dce-id",""+l++)}return e}function ee(e,l="xsl:stylesheet"){if(e.tagName===l||e.documentElement?.tagName===l)return W(e);const t=$(`<xsl:stylesheet version="1.0" xmlns:xsl="${B}" xmlns:xhtml="${q}" xmlns:exsl="${de}" exclude-result-prefixes="exsl" >
|
|
3
|
+
<xsl:output method="xml" />
|
|
4
|
+
<xsl:template match="/"><dce-root xmlns="${q}"><xsl:apply-templates select="*"/></dce-root></xsl:template>
|
|
5
|
+
<xsl:template match="*[name()='template']"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
|
|
6
|
+
<xsl:template match="*"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
|
|
7
|
+
<xsl:template match="*[name()='svg']|*[name()='math']"><xsl:apply-templates mode="sanitize" select="."/></xsl:template>
|
|
8
|
+
<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>
|
|
9
|
+
<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>
|
|
10
|
+
<xsl:template mode="sanitize" match="*|@*"><xsl:copy><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:copy></xsl:template>
|
|
11
|
+
<xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
|
|
12
|
+
<xsl:template mode="sanitize" match="text()"><dce-text><xsl:copy/></dce-text></xsl:template>
|
|
13
|
+
<xsl:template mode="sanitize" match="xsl:value-of|*[name()='slot']"><dce-text><xsl:copy><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:copy></dce-text></xsl:template>
|
|
14
|
+
<xsl:template mode="sanitize" match="xhtml:*"><xsl:element name="{local-name()}"><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:element></xsl:template>
|
|
15
|
+
</xsl:stylesheet>`),s=new XSLTProcessor,n=(a=>{D(a,"script",v=>v.remove());const o=a.content??a.firstElementChild?.content??a.body??a;oe.forEach(v=>D(o,v,b=>ce(b,o)));const E=a.firstElementChild?.content||a.content,g=v=>{const b=$("<xhtml/>"),P=b.importNode(v,!0);return b.replaceChild(P,b.documentElement),xe(P)};if(E){const v=N("div");return[...E.childNodes].map(b=>v.append(b.cloneNode(!0))),g(v)}return g(a.documentElement||a.body||a)})(e),i=$(`<xsl:stylesheet version="1.0"
|
|
16
|
+
xmlns:xsl="${B}"
|
|
17
|
+
xmlns:xhtml="${q}"
|
|
18
|
+
xmlns:dce="urn:schemas-epa-wg:dce"
|
|
19
|
+
xmlns:exsl="http://exslt.org/common"
|
|
20
|
+
exclude-result-prefixes="exsl"
|
|
21
|
+
>
|
|
22
|
+
<xsl:template match="ignore">
|
|
23
|
+
<xsl:choose>
|
|
24
|
+
<xsl:when test="//attr">{//attr}</xsl:when>
|
|
25
|
+
<xsl:otherwise>{def}</xsl:otherwise>
|
|
26
|
+
</xsl:choose><xsl:value-of select="."></xsl:value-of></xsl:template>
|
|
27
|
+
<xsl:template mode="payload" match="attributes"></xsl:template>
|
|
28
|
+
<xsl:template match="/">
|
|
29
|
+
<xsl:apply-templates mode="payload" select="/datadom/attributes"/>
|
|
30
|
+
</xsl:template>
|
|
31
|
+
<xsl:template name="slot" >
|
|
32
|
+
<xsl:param name="slotname" />
|
|
33
|
+
<xsl:param name="defaultvalue" />
|
|
34
|
+
<xsl:choose>
|
|
35
|
+
<xsl:when test="//payload/*[@slot=$slotname]">
|
|
36
|
+
<xsl:copy-of select="//payload/*[@slot=$slotname]"/>
|
|
37
|
+
</xsl:when>
|
|
38
|
+
<xsl:otherwise>
|
|
39
|
+
<xsl:copy-of select="$defaultvalue"/>
|
|
40
|
+
</xsl:otherwise>
|
|
41
|
+
</xsl:choose>
|
|
42
|
+
</xsl:template>
|
|
43
|
+
<xsl:variable name="js-injected-body">
|
|
44
|
+
<xsl:call-template name="slot" >
|
|
45
|
+
<xsl:with-param name="slotname" select="''"/>
|
|
46
|
+
<xsl:with-param name="defaultvalue"/>
|
|
47
|
+
</xsl:call-template>
|
|
48
|
+
</xsl:variable>
|
|
49
|
+
</xsl:stylesheet>`);s.importStylesheet(t);const c=s.transformToFragment(n,document),h=(a,o)=>a.querySelector(o),p=h(i,'template[mode="payload"]');if(!c)return console.error("transformation error",{xml:n.outerHTML,xsl:M(t)});const m=[];[...c.querySelectorAll("dce-root>attribute")].forEach(a=>{const o=Q(a,"xsl:param"),E=x(a,"name");p.append(o);let g=x(o,"select")?.split("??");g||(g=["//"+E,`'${o.textContent}'`],H(o),o.setAttribute("name",E));let v;if(g?.length>1){o.removeAttribute("select");const b=h(i,'template[match="ignore"]>choose').cloneNode(!0);H(b.firstElementChild).append(S(b,"{"+g[0]+"}")),H(b.lastElementChild).append(S(b,"{"+g[1]+"}")),b.firstElementChild.setAttribute("test",g[0]),o.append(b),v=b.cloneNode(!0)}else v=Q(a,"xsl:value-of");v.removeAttribute("name"),a.append(v),a.removeAttribute("select"),m.push(o)}),[...c.querySelectorAll("[value]")].filter(a=>a.getAttribute("value").match(/\{(.*)\?\?(.*)\}/g)).forEach(a=>{const o=x(a,"value");o&&a.setAttribute("value",re(o))});for(const a of c.childNodes)p.append(i.importNode(a,!0));[...p.querySelectorAll("template")].forEach(a=>p.ownerDocument.documentElement.append(a));const R=h(i,'call-template[name="slot"]'),d=a=>{const o=R.cloneNode(!0),E=x(a,"name");E&&o.firstElementChild.setAttribute("select",`'${E}'`);for(let g of a.childNodes)o.lastElementChild.append(g);return o};D(p,"slot",a=>a.parentNode.replaceChild(d(a),a));const u=W(i);return u.params=m,u}async function te(e){return await new Promise((t,s)=>{const n=new XMLHttpRequest;n.open("GET",e),n.responseType="document",n.onload=()=>{n.readyState===n.DONE&&n.status===200&&t(n.responseXML||N("div",n.responseText)),s(n.statusText)},n.addEventListener("error",i=>s(i)),n.send()})}function se(e,l,t=!1){if(e===l)return!0;if(typeof e!="object"||e===null||typeof l!="object"||l===null||Object.keys(e).length!==Object.keys(l).length)return t;for(let s in e)if(!(s in l)||!se(e[s],l[s]))return t;return!0}const le=e=>e.split("|").map(l=>l.trim()).filter(l=>l),ne=(e,l)=>le(l).map(t=>{let s=e.ownerDocument,n=i=>(e.append(i),i);if(t.includes("/")){const i=[],c=s.evaluate(t,e);for(let h;h=c.iterateNext();)i.push(h);return i}return[...e.childNodes].find(i=>i.localName===t)||n(N(t,"",s))}).flat();function Y(e,l,t,s){if(!t.sliceProcessed)return t.sliceProcessed=1,ne(e,l??"").map(n=>{const i=e.ownerDocument,c=t.sliceEventSource,h=t.sliceElement,p=()=>[...n.childNodes].filter(m=>m.nodeType===3||m.localName==="value"||m.localName==="form-data").map(m=>m.remove());if(c.getAttributeNames().map(m=>n.setAttribute(m,x(c,m))),[...n.childNodes].filter(m=>m.localName==="event").map(m=>m.remove()),"validationMessage"in c&&n.setAttribute("validation-message",c.validationMessage),t.type==="init"&&p(),n.append(C(t,"event",i)),h.hasAttribute("slice-value")){c.value===void 0?n.removeAttribute("value"):n.setAttribute("value",c.value);const m=L(x(h,"slice-value"),n);p(),n.append(S(i,m))}else{if("elements"in c)return p(),n.append(C(new FormData(c),"value",n.ownerDocument)),n;const m=c.value??x(h,"value");p(),m==null?[...n.childNodes].filter(w=>w.localName!=="event").map(w=>w.remove()):pe(m)?n.append(S(i,m)):n.append(C(m,"value",n.ownerDocument))}return n})}function D(e,l,t){e.querySelectorAll&&[...e.querySelectorAll(l)].forEach(t)}const be=async(e,l)=>{if(!e||!e.trim())return[l];if(e.startsWith("#"))return(t=>{if(!t)return[];const s=t.querySelectorAll(e);if(s.length)return[...s];const n=t.getRootNode();return n===t?[]:getByHashId(n)})(l.parentElement);try{const t=await te(e),s=new URL(e,location).hash;if(s){const n=t.querySelectorAll(s);return n.length?[...n]:[l]}return[t]}catch{return[l]}};function ae(e,l){for(let t of e.attributes)t.namespaceURI?l.setAttributeNS(t.namespaceURI,t.name,t.value):l.setAttribute(t.name,t.value),t.name==="value"&&(l.value=t.value)}function G(e,l=0){const t={};for(const s of e.childNodes){const n=x(s,"data-dce-id")||s.dceId||0;if(!t[n])n?t[n]=1:(t[n]=s.dceId=++l,s.setAttribute&&s.setAttribute("data-dce-id",s.dceId));else{const i=s.dceId=n+"-"+t[n]++;s.setAttribute&&s.setAttribute("data-dce-id",i)}s.childNodes.length&&G(s)}}function J(e,l){if(!l.length)return Z(e);const t={};for(let s of e.childNodes)t[s.dceId],K(s)?(s.data.trim(),t[s.dceId||0]=s):t[x(s,"data-dce-id")||0]=s;for(let s of[...l]){const n=x(s,"data-dce-id")||s.dceId,i=t[n];i?(K(s)?i.nodeValue!==s.nodeValue&&(i.nodeValue=s.nodeValue):(ae(s,i),(i.childNodes.length||s.childNodes.length)&&J(i,s.childNodes)),delete t[n]):e.append(s)}for(let s of Object.values(t))s.remove()}function ie(e,l){return e.hasAttribute(l)||e.setAttribute(l,crypto.randomUUID()),e.getAttribute(l)}const re=e=>[...e?.matchAll(/([^{}]*)(\{)([^}]+)}([^{}]*)/g)].map(t=>`${t[1]}{${V(t[3])}}${t[4]}`).join(""),V=e=>{if(!e.trim())return e;const l=e.split("??"),t=l.shift(),s=V(l.join("??"));return l.length?`concat( ${t} , substring( ${s} , (1+string-length( ${s} )) * string-length( ${t} ) ) )`:e},L=(e,l)=>{const t=e.split("??");if(t.length>1)return L(t[0],l)||L(t[1],l);e=V(e);const s=l.ownerDocument.evaluate(e,l);switch(s.resultType){case XPathResult.NUMBER_TYPE:return s.numberValue;case XPathResult.STRING_TYPE:return s.stringValue;case XPathResult.BOOLEAN_TYPE:return s.booleanValue}let n="";for(let i;i=s.iterateNext();)n+=i.textContent;return n},oe="stylesheet,transform,import,include,strip-space,preserve-space,output,key,decimal-format,namespace-alias,template,value-of,copy-of,number,apply-templates,apply-imports,for-each,sort,if,choose,when,otherwise,attribute-set,call-template,with-param,variable,param,text,processing-instruction,element,attribute,comment,copy,message,fallback".split(","),ce=(e,l)=>{const t=N("xsl:"+e.localName);for(let s of e.attributes)t.setAttribute(s.name,s.value);for(;e.firstChild;)t.append(e.firstChild);if(e.parentElement)e.parentElement.replaceChild(t,e);else{const s=e.parentElement||l,n=[...s.childNodes];n.forEach((i,c)=>{i===e&&(n[c]=t)}),s.replaceChildren(...n)}};class me extends HTMLElement{static observedAttributes=["src","tag","hidden"];async connectedCallback(){const l=await be(x(this,"src"),this),t=x(this,"tag"),s=t||"dce-"+crypto.randomUUID();for(const d of l)D(d.templateNode||d.content||d,"style",u=>{const a=u.closest("slot"),o=a?`slot[name="${a.name}"]`:"";u.innerHTML=`${s} ${o}{${u.innerHTML}}`,this.append(u)});const n=l.map(d=>ee(d)),i=n.map((d,u)=>(u=new XSLTProcessor,u.importStylesheet(d),u));Object.defineProperty(this,"xsltString",{get:()=>n.map(d=>M(d)).join(`
|
|
50
|
+
`)});const c=this,h=[...this.templateNode.querySelectorAll("[slice]")],p=h.map(d=>x(d,"slice")).filter(d=>!d.includes("/")).filter((d,u,a)=>a.indexOf(d)===u).map(le).flat(),m=n.reduce((d,u)=>(u.params&&d.push(...u.params),d),[]);class w extends HTMLElement{static get observedAttributes(){return m.map(u=>x(u,"name"))}#e=0;connectedCallback(){let u=this.childNodes;if(this.firstElementChild?.tagName==="TEMPLATE"){this.firstElementChild!==this.lastElementChild&&console.error("payload should have TEMPLATE as only child",this.outerHTML);const f=this.firstElementChild;f.remove(),u=f.content.childNodes;for(const r of[...f.content.childNodes])if(r.localName==="style"){const y=ie(this,"data-dce-style");r.innerHTML=`${s}[data-dce-style="${y}"]{${r.innerHTML}}`,f.insertAdjacentElement("beforebegin",r)}else r.nodeType===1?f.insertAdjacentElement("beforebegin",r):r.nodeType===3&&f.insertAdjacentText("beforebegin",r.data)}const a=$("<datadom/>").documentElement,o=(f,r="")=>(y=>(r&&y.append(S(a,r)),y))(a.ownerDocument.createElement(f));U(a,"payload",u,ye),this.innerHTML="";const E=U(a,"attributes",this.attributes,f=>o(f.nodeName,f.value));U(a,"dataset",Object.keys(this.dataset),f=>o(f,this.dataset[f]));const g=U(a,"slice",p,f=>o(f,"")),v=f=>L(f,g);this.xml=a;const b=[],P=()=>{const f={};for(let r;r=b.pop();){const y=x(r.sliceElement,"slice");f[y]||(Y(g,y,r),f[y]=r)}Object.keys(f).length!==0&&X()};let k;this.onSlice=f=>{b.push(f),k||(k=setTimeout(()=>{P(),k=0},1))};const X=this.transform=()=>{if(this.#e)debugger;this.#e=1,i.map((r,y)=>{const I=r.transformToFragment(a.ownerDocument,document);return I||console.error(`XSLT transformation error. xsl:
|
|
51
|
+
`,M(n[y]),`
|
|
52
|
+
xml:
|
|
53
|
+
`,M(a)),I}).map(r=>{r&&(G(r),J(this,r.childNodes))}),w.observedAttributes.map(r=>{let y=x(this.firstElementChild,r);y!==x(this,r)&&(this.setAttribute(r,y),this.#t(r,y))}),D(this,"[slice],[slice-event]",r=>{if(!r.dceInitialized){r.dceInitialized=1;let y=x(r,"slice-event");x(r,"custom-validity")&&(y+=" change submit"),[...new Set((y||"change").split(" "))].forEach(I=>(r.localName==="slice"?r.parentElement:r).addEventListener(I,A=>{A.sliceElement=r,A.sliceEventSource=A.currentTarget||A.target;const ue=Y(g,x(A.sliceElement,"slice"),A);D(this,"[custom-validity]",z=>{if(!z.setCustomValidity)return;const F=x(z,"custom-validity");try{const j=F&&L(F,E);z.setCustomValidity(j===!0?"":j===!1?"invalid":j)}catch(j){console.error(j,"xPath",F)}});const O=x(r,"custom-validity"),T=O&&L(O,E),_=T===!0?"":T;if(O){if(r.setCustomValidity?r.setCustomValidity(_):r.validationMessage=_,ue.map(z=>z.setAttribute("validation-message",_)),A.type==="submit")return T===!0?void 0:(setTimeout(X,1),!!T===T?(T||A.preventDefault(),T):T?(A.preventDefault(),!1):void 0);setTimeout(X,1)}this.onSlice(A)})),(!y||y.includes("init"))&&(r.hasAttribute("slice-value")||r.hasAttribute("value")||r.value?this.onSlice({type:"init",target:r,sliceElement:r,sliceEventSource:r}):r.value=v(x(r,"slice")))}}),this.#e=0};X(),P()}#t(u,a){let o=this.xml.querySelector(`attributes>${u}`);o?H(o).append(S(o,a)):(o=N(u,a,this.xml),this.xml.querySelector("attributes").append(o))}attributeChangedCallback(u,a,o){!this.xml||this.#e||(this.#t(u,o),this.transform())}get dce(){return c}}const R=d=>{window.customElements.get(d)!==w&&window.customElements.define(d,w)};if(t)R(t);else{const d=s;this.setAttribute("tag",d),R(d);const u=document.createElement(d);this.getAttributeNames().forEach(a=>u.setAttribute(a,this.getAttribute(a))),u.append(...[...this.childNodes].filter(a=>a.localName!=="style")),this.append(u)}}get templateNode(){return this.firstElementChild?.tagName==="TEMPLATE"?this.firstElementChild.content:this}get dce(){return this}get xslt(){return $(this.xsltString)}}window.customElements.define("custom-element",me);exports.CustomElement=me;exports.assureSlices=ne;exports.assureUID=ie;exports.assureUnique=G;exports.createXsltFromDom=ee;exports.deepEqual=se;exports.evalCurly=re;exports.event2slice=Y;exports.merge=J;exports.mergeAttr=ae;exports.obj2node=C;exports.tagUid=W;exports.toXsl=ce;exports.xPath=L;exports.xPathDefaults=V;exports.xhrTemplate=te;exports.xml2dom=$;exports.xmlString=M;exports.xslTags=oe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./custom-element-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./custom-element-N-sWiqGK.cjs"),l=require("./http-request-DPrY7mGh.cjs"),t=require("./local-storage-Boafngui.cjs"),a=require("./location-element-2m0gWq_d.cjs");exports.CustomElement=e.CustomElement;exports.assureSlices=e.assureSlices;exports.assureUID=e.assureUID;exports.assureUnique=e.assureUnique;exports.createXsltFromDom=e.createXsltFromDom;exports.deepEqual=e.deepEqual;exports.default=e.CustomElement;exports.evalCurly=e.evalCurly;exports.event2slice=e.event2slice;exports.merge=e.merge;exports.mergeAttr=e.mergeAttr;exports.obj2node=e.obj2node;exports.tagUid=e.tagUid;exports.toXsl=e.toXsl;exports.xPath=e.xPath;exports.xPathDefaults=e.xPathDefaults;exports.xhrTemplate=e.xhrTemplate;exports.xml2dom=e.xml2dom;exports.xmlString=e.xmlString;exports.xslTags=e.xslTags;exports.HttpRequestElement=l.HttpRequestElement;exports.LocalStorageElement=t.LocalStorageElement;exports.localStorageSetItem=t.localStorageSetItem;exports.LocationElement=a.LocationElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as e } from "./custom-element-
|
|
2
|
-
import { e as o, i as r, g as l, c as m, d as x, j as n, f as p, h as u, m as f, o as g, t as i, p as c, l as d, k as E, b as S, x as h, a as L, n as q } from "./custom-element-
|
|
1
|
+
import { C as e } from "./custom-element-BISbI4SU.js";
|
|
2
|
+
import { e as o, i as r, g as l, c as m, d as x, j as n, f as p, h as u, m as f, o as g, t as i, p as c, l as d, k as E, b as S, x as h, a as L, n as q } from "./custom-element-BISbI4SU.js";
|
|
3
3
|
import { H as D } from "./http-request-BOvP4KTl.js";
|
|
4
4
|
import { L as b, l as j } from "./local-storage-BqDEu2kF.js";
|
|
5
5
|
import { L as H } from "./location-element-nA_wsqBt.js";
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const PACKAGE_VERSION = '2.
|
|
11
|
+
const PACKAGE_VERSION = '2.3.1'
|
|
12
12
|
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
|
|
13
13
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
14
14
|
const activeClientIds = new Set()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epa-wg/custom-element-dist",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"test:watch": "vitest --inspect-brk --no-file-parallelism --browser.headless=false --test-timeout=0",
|
|
15
15
|
"test:storybook": "test-storybook",
|
|
16
16
|
"sb": "yarn storybook",
|
|
17
|
-
"t": "vitest --no-file-parallelism --watch=false src/stories/
|
|
17
|
+
"t": "vitest --no-file-parallelism --watch --browser.headless=false src/stories/attributes.test.stories.ts"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@epa-wg/custom-element": "0.0.
|
|
20
|
+
"@epa-wg/custom-element": "0.0.23"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@chromatic-com/storybook": "^1.3.3",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"playwright": "^1.43.1",
|
|
40
40
|
"storybook": "^8.0.10",
|
|
41
41
|
"typescript": "^5.2.2",
|
|
42
|
-
"vite": "^5.
|
|
42
|
+
"vite": "^5.3.1",
|
|
43
43
|
"vitest": "^1.6.0",
|
|
44
44
|
"webdriverio": "^8.36.1"
|
|
45
45
|
},
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const PACKAGE_VERSION = '2.
|
|
11
|
+
const PACKAGE_VERSION = '2.3.1'
|
|
12
12
|
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
|
|
13
13
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
14
14
|
const activeClientIds = new Set()
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export function log(x: any): void;
|
|
2
2
|
export function deepEqual(a: any, b:any): boolean|0;
|
|
3
|
+
export function xml2dom(xmlString:string): Document;
|
|
4
|
+
export function xmlString(doc:Node|Document): string;
|
|
5
|
+
export function obj2node(o:any, tag:string, doc:Document): HTMLElement;
|
|
6
|
+
export function tagUid(node:HTMLElement): HTMLElement;
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* @summary Declarative Custom Element as W3C proposal PoC with native(XSLT) based templating
|
|
@@ -13,7 +13,6 @@ const attr = (el, attr)=> el.getAttribute?.(attr)
|
|
|
13
13
|
, createText = ( d, t) => (d.ownerDocument || d ).createTextNode( t )
|
|
14
14
|
, removeChildren = n => { while(n.firstChild) n.firstChild.remove(); return n; }
|
|
15
15
|
, emptyNode = n => { n.getAttributeNames().map( a => n.removeAttribute(a) ); return removeChildren(n); }
|
|
16
|
-
, createNS = ( ns, tag, t = '' ) => ( e => ((e.innerText = t||''),e) )(document.createElementNS( ns, tag ))
|
|
17
16
|
, xslNs = x => ( x?.setAttribute('xmlns:xsl', XSL_NS_URL ), x )
|
|
18
17
|
, xslHtmlNs = x => ( x?.setAttribute('xmlns:xhtml', HTML_NS_URL ), xslNs(x) )
|
|
19
18
|
, cloneAs = (p,tag) =>
|
|
@@ -23,7 +22,7 @@ const attr = (el, attr)=> el.getAttribute?.(attr)
|
|
|
23
22
|
while( p.firstChild )
|
|
24
23
|
px.append(p.firstChild);
|
|
25
24
|
return px;
|
|
26
|
-
}
|
|
25
|
+
};
|
|
27
26
|
|
|
28
27
|
function
|
|
29
28
|
ASSERT(x)
|
|
@@ -66,17 +65,22 @@ assureSlot( e )
|
|
|
66
65
|
export function
|
|
67
66
|
obj2node( o, tag, doc )
|
|
68
67
|
{ const t = typeof o;
|
|
69
|
-
if( t === 'function'){debugger}
|
|
70
68
|
if( t === 'string' )
|
|
71
69
|
return create(tag,o,doc);
|
|
72
70
|
if( t === 'number' )
|
|
73
71
|
return create(tag,''+o,doc);
|
|
74
72
|
|
|
75
73
|
if( o instanceof Array )
|
|
76
|
-
{ const ret = create('array');
|
|
74
|
+
{ const ret = create('array','',doc);
|
|
77
75
|
o.map( ae => ret.append( obj2node(ae,tag,doc)) );
|
|
78
76
|
return ret
|
|
79
77
|
}
|
|
78
|
+
if( o instanceof FormData )
|
|
79
|
+
{ const ret = create('form-data','',doc);
|
|
80
|
+
for( const p of o )
|
|
81
|
+
ret.append( obj2node(p[1],p[0],doc) );
|
|
82
|
+
return ret
|
|
83
|
+
}
|
|
80
84
|
const ret = create(tag,'',doc);
|
|
81
85
|
for( let k in o )
|
|
82
86
|
if( isNode(o[k]) || typeof o[k] ==='function' || o[k] instanceof Window )
|
|
@@ -91,13 +95,14 @@ obj2node( o, tag, doc )
|
|
|
91
95
|
export function
|
|
92
96
|
tagUid( node )
|
|
93
97
|
{ // {} to xsl:value-of
|
|
94
|
-
forEach$(node,'*',d => [...d.childNodes]
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
forEach$(node,'*',d => [...d.childNodes]
|
|
99
|
+
.filter( e => e.nodeType === 3 && e.parentNode.localName !== 'style' && e.data )
|
|
100
|
+
.forEach( e=>
|
|
101
|
+
{ const s = e.data,
|
|
102
|
+
m = s.matchAll( /{([^}]*)}/g );
|
|
98
103
|
if(m)
|
|
99
104
|
{ let l = 0
|
|
100
|
-
, txt = t => createText(e,t
|
|
105
|
+
, txt = t => createText(e,t)
|
|
101
106
|
, tt = [];
|
|
102
107
|
[...m].forEach(t=>
|
|
103
108
|
{ if( t.index > l )
|
|
@@ -107,8 +112,8 @@ tagUid( node )
|
|
|
107
112
|
tt.push(v);
|
|
108
113
|
l = t.index+t[0].length;
|
|
109
114
|
})
|
|
110
|
-
if( l <
|
|
111
|
-
tt.push( txt(
|
|
115
|
+
if( l < s.length)
|
|
116
|
+
tt.push( txt( s.substring(l,s.length) ));
|
|
112
117
|
if( tt.length )
|
|
113
118
|
{ for( let t of tt )
|
|
114
119
|
d.insertBefore(t,e);
|
|
@@ -250,7 +255,7 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
|
|
|
250
255
|
const slotCall = $(xslDom,'call-template[name="slot"]')
|
|
251
256
|
, slot2xsl = s =>
|
|
252
257
|
{ const v = slotCall.cloneNode(true)
|
|
253
|
-
, name = attr(s,'name')
|
|
258
|
+
, name = attr(s,'name');
|
|
254
259
|
name && v.firstElementChild.setAttribute('select',`'${ name }'`)
|
|
255
260
|
for( let c of s.childNodes)
|
|
256
261
|
v.lastElementChild.append(c)
|
|
@@ -297,16 +302,20 @@ deepEqual(a, b, O=false)
|
|
|
297
302
|
return O
|
|
298
303
|
return true;
|
|
299
304
|
}
|
|
305
|
+
const splitSliceNames = v => v.split('|').map( s=>s.trim() ).filter(s=>s);
|
|
306
|
+
|
|
300
307
|
export const
|
|
301
308
|
assureSlices = ( root, names) =>
|
|
302
|
-
names
|
|
303
|
-
{
|
|
304
|
-
|
|
309
|
+
splitSliceNames(names).map( xp =>
|
|
310
|
+
{ let d = root.ownerDocument
|
|
311
|
+
, append = n=> (root.append(n),n);
|
|
312
|
+
if(xp.includes('/'))
|
|
313
|
+
{ const ret = [], r = d.evaluate( xp, root );
|
|
305
314
|
for( let n; n = r.iterateNext(); )
|
|
306
315
|
ret.push( n )
|
|
307
316
|
return ret
|
|
308
317
|
}
|
|
309
|
-
return [...root.childNodes].find(n=>n.localName === xp) || create(xp);
|
|
318
|
+
return [...root.childNodes].find(n=>n.localName === xp) || append( create(xp,'',d) );
|
|
310
319
|
}).flat();
|
|
311
320
|
|
|
312
321
|
/**
|
|
@@ -319,19 +328,24 @@ assureSlices = ( root, names) =>
|
|
|
319
328
|
export function
|
|
320
329
|
event2slice( x, sliceNames, ev, dce )
|
|
321
330
|
{
|
|
331
|
+
if( ev.sliceProcessed )
|
|
332
|
+
return
|
|
333
|
+
ev.sliceProcessed = 1;
|
|
322
334
|
// evaluate slices[]
|
|
323
335
|
// inject @attributes
|
|
324
336
|
// inject event
|
|
325
337
|
// evaluate slice-value
|
|
326
338
|
// slice[i] = slice-value
|
|
327
|
-
assureSlices(x,sliceNames).map( s =>
|
|
339
|
+
return assureSlices( x, sliceNames ?? '' ).map( s =>
|
|
328
340
|
{
|
|
329
341
|
const d = x.ownerDocument
|
|
330
342
|
, el = ev.sliceEventSource
|
|
331
343
|
, sel = ev.sliceElement
|
|
332
|
-
, cleanSliceValue = ()=>[...s.childNodes].filter(n=>n.nodeType===3 || n.localName==='value').map(n=>n.remove());
|
|
344
|
+
, cleanSliceValue = ()=>[...s.childNodes].filter(n=>n.nodeType===3 || n.localName==='value' || n.localName==='form-data').map(n=>n.remove());
|
|
333
345
|
el.getAttributeNames().map( a => s.setAttribute( a, attr(el,a) ) );
|
|
334
346
|
[...s.childNodes].filter(n=>n.localName==='event').map(n=>n.remove());
|
|
347
|
+
if( 'validationMessage' in el )
|
|
348
|
+
s.setAttribute('validation-message', el.validationMessage);
|
|
335
349
|
ev.type==='init' && cleanSliceValue();
|
|
336
350
|
s.append( obj2node( ev, 'event', d ) );
|
|
337
351
|
if( sel.hasAttribute('slice-value') )
|
|
@@ -343,7 +357,12 @@ event2slice( x, sliceNames, ev, dce )
|
|
|
343
357
|
cleanSliceValue();
|
|
344
358
|
s.append( createText( d, v ) );
|
|
345
359
|
}else
|
|
346
|
-
{
|
|
360
|
+
{ if( 'elements' in el )
|
|
361
|
+
{ cleanSliceValue();
|
|
362
|
+
s.append( obj2node(new FormData(el),'value', s.ownerDocument) )
|
|
363
|
+
return s
|
|
364
|
+
}
|
|
365
|
+
const v = el.value ?? attr( sel, 'value' ) ;
|
|
347
366
|
cleanSliceValue();
|
|
348
367
|
if( v === null || v === undefined )
|
|
349
368
|
[...s.childNodes].filter(n=>n.localName!=='event').map(n=>n.remove());
|
|
@@ -353,6 +372,7 @@ event2slice( x, sliceNames, ev, dce )
|
|
|
353
372
|
else
|
|
354
373
|
s.append( obj2node(v,'value',s.ownerDocument) )
|
|
355
374
|
}
|
|
375
|
+
return s
|
|
356
376
|
})
|
|
357
377
|
}
|
|
358
378
|
|
|
@@ -360,7 +380,6 @@ function forEach$( el, css, cb){
|
|
|
360
380
|
if( el.querySelectorAll )
|
|
361
381
|
[...el.querySelectorAll(css)].forEach(cb)
|
|
362
382
|
}
|
|
363
|
-
const getByHashId = ( n, id )=> ( p => n===p? null: (p && ( p.querySelector(id) || getByHashId(p,id) ) ))( n.getRootNode() )
|
|
364
383
|
const loadTemplateRoots = async ( src, dce )=>
|
|
365
384
|
{
|
|
366
385
|
if( !src || !src.trim() )
|
|
@@ -388,12 +407,7 @@ const loadTemplateRoots = async ( src, dce )=>
|
|
|
388
407
|
}catch (error){ return [dce]}
|
|
389
408
|
}
|
|
390
409
|
export function mergeAttr( from, to )
|
|
391
|
-
{
|
|
392
|
-
{
|
|
393
|
-
if( !isText(to) ){ debugger }
|
|
394
|
-
return
|
|
395
|
-
}
|
|
396
|
-
for( let a of from.attributes)
|
|
410
|
+
{ for( let a of from.attributes)
|
|
397
411
|
{ a.namespaceURI? to.setAttributeNS( a.namespaceURI, a.name, a.value ) : to.setAttribute( a.name, a.value )
|
|
398
412
|
if( a.name === 'value')
|
|
399
413
|
to.value = a.value
|
|
@@ -472,12 +486,18 @@ export const xPathDefaults = x=>
|
|
|
472
486
|
// return xx.length ? `${a}|(${xPathDefaults(xx.join('??'))})[not(${a})]`: a
|
|
473
487
|
}
|
|
474
488
|
export const xPath = (x,root)=>
|
|
475
|
-
{
|
|
489
|
+
{
|
|
490
|
+
const xx = x.split('??');
|
|
491
|
+
if( xx.length > 1 )
|
|
492
|
+
return xPath(xx[0], root) || xPath(xx[1], root);
|
|
493
|
+
|
|
494
|
+
x = xPathDefaults(x);
|
|
476
495
|
|
|
477
496
|
const it = root.ownerDocument.evaluate(x, root);
|
|
478
497
|
switch( it.resultType )
|
|
479
498
|
{ case XPathResult.NUMBER_TYPE: return it.numberValue;
|
|
480
499
|
case XPathResult.STRING_TYPE: return it.stringValue;
|
|
500
|
+
case XPathResult.BOOLEAN_TYPE: return it.booleanValue;
|
|
481
501
|
}
|
|
482
502
|
|
|
483
503
|
let ret = '';
|
|
@@ -529,7 +549,10 @@ CustomElement extends HTMLElement
|
|
|
529
549
|
|
|
530
550
|
const dce = this
|
|
531
551
|
, sliceNodes = [...this.templateNode.querySelectorAll('[slice]')]
|
|
532
|
-
, sliceNames = sliceNodes.map(e=>attr(e,'slice'))
|
|
552
|
+
, sliceNames = sliceNodes.map(e=>attr(e,'slice'))
|
|
553
|
+
.filter(n=>!n.includes('/'))
|
|
554
|
+
.filter((v, i, a)=>a.indexOf(v) === i)
|
|
555
|
+
.map(splitSliceNames).flat()
|
|
533
556
|
, declaredAttributes = templateDocs.reduce( (ret,t) => { if( t.params ) ret.push( ...t.params ); return ret; }, [] );
|
|
534
557
|
|
|
535
558
|
class DceElement extends HTMLElement
|
|
@@ -540,6 +563,8 @@ CustomElement extends HTMLElement
|
|
|
540
563
|
{ let payload = this.childNodes;
|
|
541
564
|
if( this.firstElementChild?.tagName === 'TEMPLATE' )
|
|
542
565
|
{
|
|
566
|
+
if( this.firstElementChild !== this.lastElementChild )
|
|
567
|
+
{ console.error('payload should have TEMPLATE as only child', this.outerHTML ) }
|
|
543
568
|
const t = this.firstElementChild;
|
|
544
569
|
t.remove();
|
|
545
570
|
payload = t.content.childNodes;
|
|
@@ -563,7 +588,7 @@ CustomElement extends HTMLElement
|
|
|
563
588
|
})(x.ownerDocument.createElement( tag ))
|
|
564
589
|
injectData( x, 'payload' , payload , assureSlot );
|
|
565
590
|
this.innerHTML='';
|
|
566
|
-
injectData( x, 'attributes' , this.attributes, e => createXmlNode( e.nodeName, e.value ) );
|
|
591
|
+
const attrsRoot = injectData( x, 'attributes' , this.attributes, e => createXmlNode( e.nodeName, e.value ) );
|
|
567
592
|
injectData( x, 'dataset', Object.keys( this.dataset ), k => createXmlNode( k, this.dataset[ k ] ) );
|
|
568
593
|
const sliceRoot = injectData( x, 'slice', sliceNames, k => createXmlNode( k, '' ) )
|
|
569
594
|
, sliceXPath = x => xPath(x, sliceRoot);
|
|
@@ -585,14 +610,12 @@ CustomElement extends HTMLElement
|
|
|
585
610
|
let timeoutID;
|
|
586
611
|
|
|
587
612
|
this.onSlice = ev=>
|
|
588
|
-
{
|
|
589
|
-
ev.sliceEventSource = ev.currentTarget || ev.target;
|
|
590
|
-
sliceEvents.push(ev);
|
|
613
|
+
{ sliceEvents.push(ev);
|
|
591
614
|
if( !timeoutID )
|
|
592
615
|
timeoutID = setTimeout(()=>
|
|
593
616
|
{ applySlices();
|
|
594
617
|
timeoutID =0;
|
|
595
|
-
},
|
|
618
|
+
},1);
|
|
596
619
|
};
|
|
597
620
|
const transform = this.transform = ()=>
|
|
598
621
|
{ if(this.#inTransform){ debugger }
|
|
@@ -619,20 +642,58 @@ CustomElement extends HTMLElement
|
|
|
619
642
|
}
|
|
620
643
|
})
|
|
621
644
|
|
|
622
|
-
forEach$( this,'[slice]', el =>
|
|
645
|
+
forEach$( this,'[slice],[slice-event]', el =>
|
|
623
646
|
{ if( !el.dceInitialized )
|
|
624
647
|
{ el.dceInitialized = 1;
|
|
625
|
-
|
|
626
|
-
(
|
|
627
|
-
|
|
648
|
+
let evs = attr(el,'slice-event');
|
|
649
|
+
if( attr(el,'custom-validity') )
|
|
650
|
+
evs += ' change submit';
|
|
651
|
+
|
|
652
|
+
[...new Set((evs || 'change') .split(' '))]
|
|
628
653
|
.forEach( t=> (el.localName==='slice'? el.parentElement : el)
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
654
|
+
.addEventListener( t, ev=>
|
|
655
|
+
{ ev.sliceElement = el;
|
|
656
|
+
ev.sliceEventSource = ev.currentTarget || ev.target;
|
|
657
|
+
const slices = event2slice( sliceRoot, attr( ev.sliceElement, 'slice'), ev, this );
|
|
658
|
+
|
|
659
|
+
forEach$(this,'[custom-validity]',el =>
|
|
660
|
+
{ if( !el.setCustomValidity )
|
|
661
|
+
return;
|
|
662
|
+
const x = attr( el, 'custom-validity' );
|
|
663
|
+
try
|
|
664
|
+
{ const v = x && xPath( x, attrsRoot );
|
|
665
|
+
el.setCustomValidity( v === true? '': v === false ? 'invalid' : v );
|
|
666
|
+
}catch(err)
|
|
667
|
+
{ console.error(err, 'xPath', x) }
|
|
668
|
+
})
|
|
669
|
+
const x = attr(el,'custom-validity')
|
|
670
|
+
, v = x && xPath( x, attrsRoot )
|
|
671
|
+
, msg = v === true? '' : v;
|
|
672
|
+
|
|
673
|
+
if( x )
|
|
674
|
+
{ el.setCustomValidity ? el.setCustomValidity( msg ) : ( el.validationMessage = msg );
|
|
675
|
+
slices.map( s => s.setAttribute('validation-message', msg ) );
|
|
676
|
+
if( ev.type === 'submit' )
|
|
677
|
+
{ if( v === true )
|
|
678
|
+
return;
|
|
679
|
+
setTimeout(transform,1)
|
|
680
|
+
if( !!v === v )
|
|
681
|
+
{ v || ev.preventDefault();
|
|
682
|
+
return v;
|
|
683
|
+
}
|
|
684
|
+
if( v )
|
|
685
|
+
{ ev.preventDefault();
|
|
686
|
+
return !1
|
|
687
|
+
}
|
|
688
|
+
return ;
|
|
689
|
+
}else
|
|
690
|
+
setTimeout(transform,1)
|
|
691
|
+
}
|
|
692
|
+
this.onSlice(ev);
|
|
693
|
+
} ));
|
|
633
694
|
if( !evs || evs.includes('init') )
|
|
634
695
|
{ if( el.hasAttribute('slice-value') || el.hasAttribute('value') || el.value )
|
|
635
|
-
this.onSlice({type:'init', target: el, sliceElement:el })
|
|
696
|
+
this.onSlice({type:'init', target: el, sliceElement:el, sliceEventSource:el })
|
|
636
697
|
else
|
|
637
698
|
el.value = sliceXPath( attr(el,'slice') )
|
|
638
699
|
}
|
|
@@ -1,63 +1,60 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
|
3
|
-
xmlns:html="http://www.w3.org/1999/xhtml">
|
|
2
|
+
<html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
4
3
|
<head>
|
|
5
4
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
6
|
-
<title>
|
|
5
|
+
<title>Data slices - Declarative Custom Element implementation demo</title>
|
|
7
6
|
<link rel="icon" href="./wc-square.svg"/>
|
|
7
|
+
|
|
8
8
|
<script type="module" src="../http-request.js"></script>
|
|
9
|
-
<script type="module" src="../local-storage.js"></script>
|
|
10
9
|
<script type="module" src="../custom-element.js"></script>
|
|
11
|
-
|
|
12
10
|
<style>
|
|
13
11
|
@import "./demo.css";
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
table {
|
|
20
|
-
min-width: 16rem;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
td {
|
|
24
|
-
border-bottom: 1px solid silver;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
tfoot td {
|
|
28
|
-
border-bottom: none;
|
|
13
|
+
label {
|
|
14
|
+
display: flex;
|
|
29
15
|
}
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
label:has(input[type="text"],input[type="password"],input:not([type]) ) {
|
|
18
|
+
flex-direction: column;
|
|
33
19
|
}
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
font-weight: bolder;
|
|
38
|
-
font-family: sans-serif;
|
|
21
|
+
nav {
|
|
22
|
+
max-width: 32em;
|
|
39
23
|
}
|
|
40
24
|
</style>
|
|
25
|
+
<!-- https://github.com/mdn/learning-area/blob/main/html/forms/form-validation/custom-error-message.html
|
|
26
|
+
todo: apply setCustomValidity( warningStr )
|
|
27
|
+
-->
|
|
28
|
+
|
|
41
29
|
</head>
|
|
42
30
|
<body>
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
<fieldset>
|
|
33
|
+
<legend><b style="color:green">green</b> in instance style can be overridden in payload as <i
|
|
34
|
+
style="color:red">red</i> in 1st instance
|
|
35
|
+
</legend>
|
|
36
|
+
<custom-element tag="dce-3">
|
|
37
|
+
<template>
|
|
38
|
+
<u>
|
|
39
|
+
<slot>is green</slot>
|
|
40
|
+
</u>
|
|
52
41
|
</template>
|
|
42
|
+
<style>dce-3 {
|
|
43
|
+
color: green
|
|
44
|
+
}</style>
|
|
53
45
|
</custom-element>
|
|
54
|
-
<
|
|
55
|
-
<dce-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
</
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
<u>should be</u> <i style="color:red">red</i>:
|
|
47
|
+
<dce-3 id="dce32">
|
|
48
|
+
<template>
|
|
49
|
+
<style> color:red; </style>
|
|
50
|
+
<u>red</u>
|
|
51
|
+
</template>
|
|
52
|
+
</dce-3> <br/>
|
|
53
|
+
should be GREEN:
|
|
54
|
+
<dce-3 id="dce31">green</dce-3>
|
|
55
|
+
</fieldset>
|
|
56
|
+
|
|
57
|
+
<script type="module" src="https://unpkg.com/html-demo-element@1/html-demo-element.js"></script>
|
|
58
|
+
|
|
62
59
|
</body>
|
|
63
60
|
</html>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<dce-root data-dce-id="1" xmlns="http://www.w3.org/1999/xhtml" xmlns:dce="urn:schemas-epa-wg:dce"
|
|
3
|
+
xmlns:xhtml="http://www.w3.org/1999/xhtml"><u data-dce-id="2" xmlns="">
|
|
4
|
+
<dce-text data-dce-id="3">
|
|
5
|
+
<xhtml:span xmlns:xsl="http://www.w3.org/1999/XSL/Transform" slot=""/>
|
|
6
|
+
<xhtml:style xmlns:xsl="http://www.w3.org/1999/XSL/Transform" slot="" title="ABC">
|
|
7
|
+
dce-3[data-dce-style="54f96d52-ce70-435d-83c4-b421357d9a17"]{ color:red; }
|
|
8
|
+
</xhtml:style>
|
|
9
|
+
<xhtml:span xmlns:xsl="http://www.w3.org/1999/XSL/Transform" slot=""/>
|
|
10
|
+
<xhtml:u xmlns:xsl="http://www.w3.org/1999/XSL/Transform" slot="">red</xhtml:u>
|
|
11
|
+
<xhtml:span xmlns:xsl="http://www.w3.org/1999/XSL/Transform" slot=""/>
|
|
12
|
+
</dce-text>
|
|
13
|
+
</u></dce-root>
|
|
@@ -178,6 +178,38 @@
|
|
|
178
178
|
</template>
|
|
179
179
|
</html-demo-element>
|
|
180
180
|
|
|
181
|
+
|
|
182
|
+
<html-demo-element legend="10. multiple slices by same field"
|
|
183
|
+
description="same element value sets s1 and s2 slice">
|
|
184
|
+
<template>
|
|
185
|
+
<custom-element>
|
|
186
|
+
<template>
|
|
187
|
+
<input slice="s1|s2"
|
|
188
|
+
slice-event="input"
|
|
189
|
+
data-testid="f1"
|
|
190
|
+
/><br/>
|
|
191
|
+
Type to update s1 and s2 slices <br/>
|
|
192
|
+
slice <code>s1: {//slice/s1}</code><br/>
|
|
193
|
+
slice <code>s2: {//slice/s2}</code><br/>
|
|
194
|
+
</template>
|
|
195
|
+
</custom-element>
|
|
196
|
+
</template>
|
|
197
|
+
</html-demo-element>
|
|
198
|
+
|
|
199
|
+
<html-demo-element legend="11. slices and attribute"
|
|
200
|
+
description="initial attribute value should be smile as emoji and :) on blur from input it should be updated from value">
|
|
201
|
+
<template>
|
|
202
|
+
<custom-element>
|
|
203
|
+
<template>
|
|
204
|
+
<attribute name="emotion">😃</attribute>
|
|
205
|
+
<input slice="/datadom/attributes/emotion | s1"/>
|
|
206
|
+
Type and unfocus to update emotion attribute: {emotion}
|
|
207
|
+
and slice: {//slice/s1}
|
|
208
|
+
</template>
|
|
209
|
+
</custom-element>
|
|
210
|
+
</template>
|
|
211
|
+
</html-demo-element>
|
|
212
|
+
|
|
181
213
|
<script type="module" src="https://unpkg.com/html-demo-element@1/html-demo-element.js"></script>
|
|
182
214
|
|
|
183
215
|
</body>
|