@epa-wg/custom-element 0.0.26 → 0.0.28

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/README.md CHANGED
@@ -341,16 +341,16 @@ within template
341
341
  [css-demo-url]: https://unpkg.com/@epa-wg/custom-element@0.0/demo/scoped-css.html
342
342
  [slice-demo-url]: https://unpkg.com/@epa-wg/custom-element@0.0/demo/data-slices.html
343
343
  [hex-grid-url]: https://unpkg.com/@epa-wg/custom-element@0.0/demo/hex-grid.html
344
- [hex-grid-image]: demo/hex-grid-transform.png
344
+ [hex-grid-image]: https://unpkg.com/@epa-wg/custom-element@0.0.28/demo/hex-grid-transform.png
345
345
  [local-storage-demo]: https://unpkg.com/@epa-wg/custom-element@0.0/demo/local-storage.html
346
346
  [http-request-demo]: https://unpkg.com/@epa-wg/custom-element@0.0/demo/http-request.html
347
347
  [location-demo]: https://unpkg.com/@epa-wg/custom-element@0.0/demo/location.html
348
348
  [github-image]: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg
349
349
  [npm-image]: https://img.shields.io/npm/v/@epa-wg/custom-element.svg
350
350
  [npm-url]: https://npmjs.org/package/@epa-wg/custom-element
351
- [coverage-image]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.26/coverage/src/custom-element/coverage.svg
352
- [coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.26/coverage/src/custom-element/index.html
353
- [storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.26/storybook-static/index.html?path=/story/welcome--introduction
351
+ [coverage-image]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.28/coverage/src/custom-element/coverage.svg
352
+ [coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.28/coverage/src/custom-element/index.html
353
+ [storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.28/storybook-static/index.html?path=/story/welcome--introduction
354
354
  [sandbox-url]: https://stackblitz.com/github/EPA-WG/custom-element?file=index.html
355
355
  [webcomponents-url]: https://www.webcomponents.org/element/@epa-wg/custom-element
356
356
  [webcomponents-img]: https://img.shields.io/badge/webcomponents.org-published-blue.svg
@@ -116,7 +116,7 @@ writeFileSync( '.././ide/customData-xsl.json', JSON.stringify( vsCode, undefined
116
116
  const intelliJ = {
117
117
  "$schema": "http://json.schemastore.org/web-types",
118
118
  "name": "@epa-wg/custom-element",
119
- "version": "0.0.26",
119
+ "version": "0.0.28",
120
120
  "js-types-syntax": "typescript",
121
121
  "description-markup": "markdown",
122
122
  "contributions": {
package/custom-element.js CHANGED
@@ -47,6 +47,7 @@ xml2dom( xmlString )
47
47
  }
48
48
  export function
49
49
  xmlString(doc){ return new XMLSerializer().serializeToString( doc ) }
50
+ function x(doc) { return xmlString(doc) }
50
51
 
51
52
  function
52
53
  injectData( root, sectionName, arr, cb )
@@ -71,6 +72,12 @@ assureSlot( e )
71
72
  }
72
73
  return e;
73
74
  }
75
+ function
76
+ keepAttributes(e, aNames)
77
+ { e.getAttributeNames().forEach( n=> aNames.includes(n) || e.removeAttribute(n) ); }
78
+
79
+ export const
80
+ sanitizeBlankText = payload=> [...payload].filter(e=>!(e.nodeType===3 && e.data.trim() ==='' ));
74
81
 
75
82
  export function
76
83
  obj2node( o, tag, doc )
@@ -145,22 +152,72 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
145
152
  if( templateNode.tagName === S || templateNode.documentElement?.tagName === S )
146
153
  return tagUid(templateNode)
147
154
  const sanitizeXsl = xml2dom(`<xsl:stylesheet version="1.0" xmlns:xsl="${ XSL_NS_URL }" xmlns:xhtml="${ HTML_NS_URL }" xmlns:exsl="${EXSL_NS_URL}" exclude-result-prefixes="exsl" >
148
- <xsl:output method="xml" />
149
- <xsl:template match="/"><dce-root xmlns="${ HTML_NS_URL }"><xsl:apply-templates select="*"/></dce-root></xsl:template>
150
- <xsl:template match="*[name()='template']"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
151
- <xsl:template match="*"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
152
- <xsl:template match="*[name()='svg']|*[name()='math']"><xsl:apply-templates mode="sanitize" select="."/></xsl:template>
153
- <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>
154
- <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>
155
- <xsl:template mode="sanitize" match="*|@*"><xsl:copy><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:copy></xsl:template>
156
- <xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
157
- <xsl:template mode="sanitize" match="text()"><dce-text><xsl:copy/></dce-text></xsl:template>
158
- <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>
159
- <xsl:template mode="sanitize" match="xhtml:*"><xsl:element name="{local-name()}"><xsl:apply-templates mode="sanitize" select="*|@*|text()"/></xsl:element></xsl:template>
160
- </xsl:stylesheet>`)
155
+ <xsl:output method="xml"/>
156
+ <xsl:template match="/"><dce-root xmlns="${ HTML_NS_URL }"><xsl:apply-templates select="*" /></dce-root></xsl:template>
157
+ <xsl:template match="*[name()='template']">
158
+ <xsl:apply-templates mode="sanitize" select="*|text()"/>
159
+ </xsl:template>
160
+ <xsl:template match="*">
161
+ <xsl:apply-templates mode="sanitize" select="*|text()"/>
162
+ </xsl:template>
163
+ <xsl:template match="*[name()='svg']|*[name()='math']">
164
+ <xsl:apply-templates mode="sanitize" select="."/>
165
+ </xsl:template>
166
+ <xsl:template mode="sanitize" match="*[count(text())=1 and count(*)=0]">
167
+ <xsl:copy>
168
+ <xsl:apply-templates mode="sanitize" select="@*"/>
169
+ <xsl:value-of select="text()"></xsl:value-of>
170
+ </xsl:copy>
171
+ </xsl:template>
172
+ <xsl:template mode="sanitize" match="xhtml:*[count(text())=1 and count(*)=0]">
173
+ <xsl:element name="{local-name()}">
174
+ <xsl:apply-templates mode="sanitize" select="@*"/>
175
+ <xsl:value-of select="text()"></xsl:value-of>
176
+ </xsl:element>
177
+ </xsl:template>
178
+ <xsl:template mode="sanitize" match="*|@*">
179
+ <xsl:copy>
180
+ <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
181
+ </xsl:copy>
182
+ </xsl:template>
183
+ <xsl:template mode="sanitize" match="text()[normalize-space(.) = '']"/>
184
+ <xsl:template mode="sanitize" match="text()">
185
+ <dce-text>
186
+ <xsl:copy/>
187
+ </dce-text>
188
+ </xsl:template>
189
+ <xsl:template mode="sanitize" match="xsl:value-of|*[name()='slot']">
190
+ <xsl:copy>
191
+ <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
192
+ </xsl:copy>
193
+ </xsl:template>
194
+ <xsl:template mode="sanitize" match="xhtml:*">
195
+ <xsl:element name="{local-name()}">
196
+ <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
197
+ </xsl:element>
198
+ </xsl:template>
199
+ <xsl:template mode="sanitize" match="xhtml:input">
200
+ <xsl:element name="{local-name()}">
201
+ <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
202
+ </xsl:element>
203
+ <xsl:for-each select="*">
204
+ <xsl:copy>
205
+ <xsl:attribute name="for" >^</xsl:attribute>
206
+ <xsl:apply-templates mode="sanitize" select="*|@*|text()"/>
207
+ </xsl:copy>
208
+ </xsl:for-each>
209
+ </xsl:template>
210
+ </xsl:stylesheet>`)
161
211
  const sanitizeProcessor = new XSLTProcessor()
162
212
  , tc = (n =>
163
213
  {
214
+ forEach$(n,'custom-element', ce=>{
215
+ if( 'template' === ce.firstElementChild.localName )
216
+ {
217
+ [...ce.firstElementChild.content.childNodes].forEach(n=>ce.append(n));
218
+ ce.firstElementChild.remove();
219
+ }
220
+ })
164
221
  forEach$(n,'script', s=> s.remove() );
165
222
  const xslRoot = n.content ?? n.firstElementChild?.content ?? n.body ?? n;
166
223
  xslTags.forEach( tag => forEach$( xslRoot, tag, el=>toXsl(el,xslRoot) ) );
@@ -223,12 +280,19 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
223
280
  , payload = $( xslDom, 'template[mode="payload"]');
224
281
  if( !fr )
225
282
  return console.error("transformation error",{ xml:tc.outerHTML, xsl: xmlString( sanitizeXsl ) });
283
+ if( 'dce-root'!==fr.firstElementChild.localName )
284
+ { const r = fr.ownerDocument.createElement('dce-root');
285
+ [...fr.childNodes].forEach(n=>r.append(n));
286
+ fr.append(r)
287
+ }
226
288
  const params = [];
227
289
  [...fr.querySelectorAll('dce-root>attribute')].forEach( a=>
228
290
  {
291
+ keepAttributes(a,'namespace,name,select');
229
292
  const p = cloneAs(a,'xsl:param')
230
293
  , name = attr(a,'name');
231
294
  payload.append(p);
295
+ keepAttributes(p,'select,name');
232
296
  let select = attr(p,'select')?.split('??')
233
297
  if( !select)
234
298
  { select = ['//'+name, `'${p.textContent}'`];
@@ -236,8 +300,8 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
236
300
  p.setAttribute('name',name);
237
301
  }
238
302
  let val;
239
- if( select?.length>1 ){
240
- p.removeAttribute('select');
303
+ if( select?.length>1 )
304
+ { p.removeAttribute('select');
241
305
  const c = $( xslDom, 'template[match="ignore"]>choose').cloneNode(true);
242
306
  emptyNode(c.firstElementChild).append( createText(c,'{'+select[0]+'}'));
243
307
  emptyNode(c.lastElementChild ).append( createText(c,'{'+select[1]+'}'));
@@ -270,7 +334,7 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
270
334
  for( let c of s.childNodes)
271
335
  v.lastElementChild.append(c)
272
336
  return v
273
- }
337
+ };
274
338
 
275
339
  forEach$( payload,'slot', s => s.parentNode.replaceChild( slot2xsl(s), s ) )
276
340
 
@@ -419,7 +483,8 @@ const loadTemplateRoots = async ( src, dce )=>
419
483
  if( hash )
420
484
  { const ret = dom.querySelectorAll('#'+hash);
421
485
  if( ret.length )
422
- return [...ret]
486
+ return [...ret];
487
+ console.error('template not found',src+'#'+hash);
423
488
  return [dce]
424
489
  }
425
490
  return [dom]
@@ -562,6 +627,8 @@ CustomElement extends HTMLElement
562
627
  static observedAttributes = ['src','tag','hidden'];
563
628
  async connectedCallback()
564
629
  {
630
+ if(this.firstElementChild && this.firstElementChild.localName !== 'template')
631
+ console.warn('custom-element used without template wrapping content\n', this.outerHTML);
565
632
  const templateRoots = await loadTemplateRoots( attr( this, 'src' ), this )
566
633
  , tag = attr( this, 'tag' )
567
634
  , tagName = tag ? tag : 'dce-'+crypto.randomUUID();
@@ -574,7 +641,13 @@ CustomElement extends HTMLElement
574
641
  this.append(s);
575
642
  })
576
643
  const templateDocs = templateRoots.map( n => createXsltFromDom( n ) )
577
- , xp = templateDocs.map( (td, p) =>{ p = new XSLTProcessor(); p.importStylesheet( td ); return p })
644
+ , xp = templateDocs.map( (td, p) =>
645
+ { p = new XSLTProcessor();
646
+ try{ p.importStylesheet( td ) }
647
+ catch( e )
648
+ { console.error(e, xmlString(td)) }
649
+ return p
650
+ })
578
651
 
579
652
  Object.defineProperty( this, "xsltString", { get: ()=>templateDocs.map( td => xmlString(td) ).join('\n') });
580
653
 
@@ -591,16 +664,16 @@ CustomElement extends HTMLElement
591
664
  static get observedAttributes(){ return declaredAttributes.map( a=>attr(a,'name')); }
592
665
  #inTransform = 0;
593
666
  connectedCallback()
594
- { let payload = this.childNodes;
667
+ { let payload = sanitizeBlankText(this.childNodes);
595
668
  if( this.firstElementChild?.tagName === 'TEMPLATE' )
596
669
  {
597
670
  if( this.firstElementChild !== this.lastElementChild )
598
671
  { console.error('payload should have TEMPLATE as only child', this.outerHTML ) }
599
672
  const t = this.firstElementChild;
600
673
  t.remove();
601
- payload = t.content.childNodes;
674
+ payload = sanitizeBlankText(t.content.childNodes);
602
675
 
603
- for( const n of [...t.content.childNodes] )
676
+ for( const n of payload )
604
677
  if( n.localName === 'style' ){
605
678
  const id = assureUID(this,'data-dce-style')
606
679
  n.innerHTML= `${tagName}[data-dce-style="${id}"]{${n.innerHTML}}`;
@@ -675,18 +748,39 @@ CustomElement extends HTMLElement
675
748
  }
676
749
  })
677
750
 
751
+ function getSliceTarget(el)
752
+ { let r = el;
753
+ if( el.localName === 'slice')
754
+ { const ref= attr(el,'for');
755
+ if( !ref )
756
+ r = el.parentElement;
757
+ if( '^' === ref )
758
+ { do r = r.previousElementSibling;
759
+ while( r.localName === 'slice' )
760
+ } else
761
+ r = this.querySelector(ref)
762
+
763
+ if( !r )
764
+ return console.warn(`can not find selector in "slice for=${ref}" `, el.outerHTML);
765
+ attr(el,'slice') || el.setAttribute('slice', attr(el,'name'))
766
+ }
767
+ return r;
768
+ }
678
769
  forEach$( this,'[slice],[slice-event]', el =>
679
- { if( !el.dceInitialized )
770
+ { let evs = attr(el,'slice-event');
771
+ const sVal = el.hasAttribute('slice-value') || el.hasAttribute('value') || el.value;
772
+ const tgt = getSliceTarget(el);
773
+ if( !el.dceInitialized )
680
774
  { el.dceInitialized = 1;
681
- let evs = attr(el,'slice-event');
682
- if( el.hasAttribute('custom-validity') )
775
+ if( tgt.hasAttribute('custom-validity') )
683
776
  evs += ' change submit';
684
777
 
685
778
  [...new Set((evs || 'change') .split(' '))]
686
- .forEach( t=> (el.localName==='slice'? el.parentElement : el)
687
- .addEventListener( t, ev=>
779
+ .forEach( t=>
780
+ tgt.addEventListener( t, ev=>
688
781
  { ev.sliceElement = el;
689
782
  ev.sliceEventSource = ev.currentTarget || ev.target;
783
+ ev.sliceProcessed = 0;
690
784
  const slices = event2slice( sliceRoot, attr( ev.sliceElement, 'slice'), ev, this );
691
785
 
692
786
  forEach$(this,'[custom-validity]',el =>
@@ -699,7 +793,7 @@ CustomElement extends HTMLElement
699
793
  }catch(err)
700
794
  { console.error(err, 'xPath', x) }
701
795
  })
702
- const x = attr(el,'custom-validity')
796
+ const x = attr(tgt,'custom-validity')
703
797
  , v = x && xPath( x, attrsRoot )
704
798
  , msg = v === true? '' : v;
705
799
 
@@ -725,8 +819,8 @@ CustomElement extends HTMLElement
725
819
  this.onSlice(ev);
726
820
  } ));
727
821
  if( !evs || evs.includes('init') )
728
- { if( el.hasAttribute('slice-value') || el.hasAttribute('value') || el.value )
729
- this.onSlice({type:'init', target: el, sliceElement:el, sliceEventSource:el })
822
+ { if( sVal )
823
+ this.onSlice({type:'init', target: tgt, sliceElement:el, sliceEventSource:tgt })
730
824
  else
731
825
  el.value = sliceXPath( attr(el,'slice') )
732
826
  }
package/demo/demo.css CHANGED
@@ -4,13 +4,12 @@ html
4
4
  }
5
5
  body,nav{ display: flex; flex-wrap: wrap; align-content: stretch; gap: 1rem; }
6
6
  body>*{flex: auto;}
7
- nav{ flex-direction: column;}
8
- custom-element+*,
9
- custom-element+*+*,
10
- custom-element:not([tag]),
11
- dce-link,dce-1-slot,dce-2-slot,dce-3-slot,dce-4-slot,dce-2-slots,greet-element,pokemon-tile,
12
- dce-1,dce-2,dce-3,dce-4,dce-internal,dce-hash
13
- { box-shadow: 0 0 0.5rem lime; padding: 1rem; display: inline-block; flex:1; }
7
+ nav
8
+ { flex-direction: column;
9
+ dce-root{ box-shadow:none; padding: 0;}
10
+ }
11
+
12
+ html-demo-element *:has(>dce-root){ box-shadow: 0 0 0.5rem lime; padding: 1rem; flex:1; display: block; }
14
13
  script{ display:none !important; }
15
14
  dd{ padding: 1rem;}
16
15
  p{ margin: 0;}
@@ -141,13 +141,13 @@
141
141
  <html-demo-element legend="6. HTML, SVG by ID within external file" description="Should render 👋, svg, formula">
142
142
  <a href="html-template.html">html-template.html</a>
143
143
  <template>
144
- <custom-element src="html-template.html#wave">
144
+ <custom-element src="./html-template.html#wave">
145
145
  <template><i>loading HTML from templates file ...</i></template>
146
146
  </custom-element>
147
- <custom-element src="html-template.html#dwc-logo">
147
+ <custom-element src="./html-template.html#dwc-logo">
148
148
  <template><i>loading SVG from templates file ...</i></template>
149
149
  </custom-element>
150
- <custom-element src="html-template.html#sophomores-dream">
150
+ <custom-element src="./html-template.html#sophomores-dream">
151
151
  <template><i>loading MathML from HTML file ...</i></template>
152
152
  </custom-element>
153
153
  </template>
@@ -4,8 +4,16 @@
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
5
  <title>DOM merge - Declarative Custom Element implementation demo</title>
6
6
  <link rel="icon" href="./wc-square.svg"/>
7
-
7
+ <script type="importmap">
8
+ {
9
+ "imports": {
10
+ "@epa-wg/custom-element/": "../",
11
+ "@epa-wg/custom-element-dist/": "../"
12
+ }
13
+ }
14
+ </script>
8
15
  <script type="module" src="../http-request.js"></script>
16
+ <script type="module" src="../location-element.js"></script>
9
17
  <script type="module" src="../custom-element.js"></script>
10
18
  <style>
11
19
  @import "./demo.css";
@@ -40,16 +48,20 @@
40
48
  <html-demo-element legend="1. NPM package version picker"
41
49
  description="defaults, last version should be preselected">
42
50
  <template>
43
- <custom-element tag="npm-version" src="./npm-versions.html#npm-version"></custom-element>
44
- <npm-version package-name="@epa-wg/custom-element-dist"></npm-version>
51
+ <custom-element src="./npm-versions.html#npm-version"
52
+ package-name="@epa-wg/custom-element-dist"></custom-element>
45
53
  </template>
46
54
  </html-demo-element>
47
55
 
48
56
  <html-demo-element legend="2. preselected NPM package version picker"
49
- description="version 22 should be selected">
57
+ description="version 22 should be selected and date shown">
50
58
  <template>
51
59
  <custom-element tag="custom-element-version" src="./npm-versions.html#npm-version"></custom-element>
52
- <custom-element-version current-version="0.0.22" package-name="@epa-wg/custom-element"></custom-element-version>
60
+ <custom-element-version
61
+ package-name="@epa-wg/custom-element"
62
+ current-version="0.0.22"
63
+ show-date="true"
64
+ ></custom-element-version>
53
65
  </template>
54
66
  </html-demo-element>
55
67
 
@@ -90,11 +102,12 @@
90
102
 
91
103
  <html-demo-element legend="5. control version in URL"
92
104
  description="">
93
- 1. <button onclick="window.location.hash = `#@epa-wg/custom-element-dist@0.0.26/storybook-static/index.html`">set in page URL</button>
94
- (can be skipped when run from unpkg.com)<br/>
105
+ 1. <button onclick="window.location.hash = `#@epa-wg/custom-element-dist@0.0.25/storybook-static/index.html`">set in page URL to version 0.0.25</button><br/>
95
106
  2. switch the package version in select and observe the URL change.
96
107
  <template>
97
- <custom-element src="./npm-versions.html#npm-version-to-url" package-name="custom-element-dist" current-version="0.0.26"></custom-element>
108
+ <custom-element src="@epa-wg/custom-element-dist/demo/npm-versions.html#npm-version-to-url"
109
+ package-name="@epa-wg/custom-element-dist"
110
+ ></custom-element>
98
111
  </template>
99
112
  </html-demo-element>
100
113
 
@@ -4,6 +4,7 @@
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
5
  <title>npm-version template</title>
6
6
  <link rel="icon" href="./wc-square.svg"/>
7
+
7
8
  </head>
8
9
  <body>
9
10
 
@@ -11,28 +12,29 @@
11
12
  <a href="./npm-versions-demo.html">docs</a>
12
13
  <template id="npm-version">
13
14
  <attribute name="package-name"></attribute>
14
- <attribute name="current-version"></attribute>
15
+ <attribute name="current-version" aria-description="version to select"></attribute>
16
+ <attribute name="show-date" aria-description="set to 'true' to append the date to the version"></attribute>
15
17
  <attribute name="value" select="//selected-version"></attribute>
16
-
17
18
  <http-request
18
- url="https://registry.npmjs.org/@epa-wg/custom-element-dist"
19
+ url="https://registry.npmjs.org/{$package-name}"
19
20
  method="GET"
20
21
  header-accept="application/json"
21
22
  slice="versions-ajax"></http-request>
22
23
 
23
- <label><slot name="label">{$package-name} version:</slot>
24
+ <label>
25
+ <slot name="label"><var>{$package-name}</var> version:</slot>
24
26
  <xhtml:select slice="selected-version" autocomplete="off" name="version">
25
27
  <for-each select="//versions/*">
26
28
  <option value="{./@version}">
27
29
  <variable name="item-version">{./@version}</variable>
28
- { $item-version } - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}
30
+ { $item-version }<if test="$show-date = 'true' "> - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}</if>
29
31
  </option>
30
32
  </for-each>
31
33
  <for-each select="//versions/*">
32
34
  <if test="./@version = $current-version">
33
35
  <option selected value="{./@version}">
34
36
  <variable name="item-version">{./@version}</variable>
35
- { $item-version } - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}
37
+ { $item-version }<if test="$show-date = 'true' "> - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}</if>
36
38
  </option>
37
39
  </if>
38
40
  </for-each>
@@ -41,25 +43,52 @@
41
43
  </template>
42
44
 
43
45
  <template id="npm-version-to-url">
44
- <variable name="url" select="//window-location/value/@href"></variable>
45
- <variable name="current-version" >0{
46
- substring-before(substring-after(substring($url, string-length(substring-before($url, '/')) - string-length(substring-before(substring-before($url, '/'), '@0')) + 2), '@0'), '/')
47
- }</variable>
48
- <location-element slice="window-location" live>
49
- <if test=" not(//selected-version = $current-version ) and not(//selected-version = '') ">
50
- <attribute name="src">{ concat( substring-before($url, $current-version),
51
- //selected-version,
52
- substring-after($url, $current-version) ) }</attribute>
53
- <attribute name="method">location.href</attribute>
54
- </if>
55
- </location-element>
56
- <http-request
57
- url="https://registry.npmjs.org/@epa-wg/custom-element-dist"
58
- method="GET"
59
- header-accept="application/json"
60
- slice="versions-ajax" ></http-request>
46
+ <attribute name="package-name"></attribute>
47
+ <attribute name="value" select="//selected-version"></attribute>
48
+ <variable name="url" select="//window-location/value/@href"></variable>
49
+
50
+ <variable name="url-version">0{
51
+ substring-before(substring-after(substring($url, string-length(substring-before($url, '/')) -
52
+ string-length(substring-before(substring-before($url, '/'), '@0')) + 2), '@0'), '/')
53
+ }</variable>
61
54
 
62
- <custom-element src="#npm-version" slice="selected-version"></custom-element>
63
- </template>
55
+ <location-element slice="window-location" live>
56
+ <if test="//selected-version">
57
+ <if test=" not(//url-version = //selected-version ) ">
58
+ <attribute name="src">{ concat( substring-before($url, $url-version),
59
+ //selected-version,
60
+ substring-after($url, $url-version) ) }
61
+ </attribute>
62
+ <attribute name="method">location.href</attribute>
63
+ </if>
64
+ </if>
65
+ </location-element>
66
+
67
+ <http-request
68
+ url="https://registry.npmjs.org/{$package-name}"
69
+ method="GET"
70
+ header-accept="application/json"
71
+ slice="versions-ajax"></http-request>
72
+
73
+ <label>
74
+ <slot name="label">{$package-name} version:</slot>
75
+ <xhtml:select slice="selected-version" autocomplete="off" name="version">
76
+ <for-each select="//versions/*">
77
+ <option value="{./@version}">
78
+ <variable name="item-version">{./@version}</variable>
79
+ { $item-version } - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}
80
+ </option>
81
+ </for-each>
82
+ <for-each select="//versions/*">
83
+ <if test="./@version = $url-version">
84
+ <option selected value="{./@version}">
85
+ <variable name="item-version">{./@version}</variable>
86
+ { $item-version } - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}
87
+ </option>
88
+ </if>
89
+ </for-each>
90
+ </xhtml:select>
91
+ </label>
92
+ </template>
64
93
  </body>
65
94
  </html>
package/demo/s.xml CHANGED
@@ -1,28 +1,18 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <datadom>
3
3
  <payload xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml">
4
- <span xmlns="http://www.w3.org/1999/xhtml" slot=""></span>
5
- <npm-version xmlns="http://www.w3.org/1999/xhtml" slice="selected-version" package-name="@epa-wg/custom-element"
6
- slot=""></npm-version>
7
- <span xmlns="http://www.w3.org/1999/xhtml" slot=""></span>
8
- <p xmlns="http://www.w3.org/1999/xhtml" slot="">
9
- <code>selected-version</code>
10
- slice: {//selected-version}
11
- </p>
12
- <span xmlns="http://www.w3.org/1999/xhtml" slot=""></span>
4
+ <a xmlns="http://www.w3.org/1999/xhtml" href="#" data-dce-id="4" slot="">link 1</a>
5
+ <a xmlns="http://www.w3.org/1999/xhtml" href="#" data-dce-id="5" slot="">link 2</a>
6
+ <a xmlns="http://www.w3.org/1999/xhtml" href="#" data-dce-id="6" slot="">link 3</a>
13
7
  </payload>
14
8
  <attributes>
15
- <tag>dce-bbc8e8b4-575f-40d3-9880-2f1d56d85d80</tag>
9
+ <xmlns/>
10
+ <justify>end</justify>
11
+ <data-dce-id>2</data-dce-id>
12
+ <direction>row</direction>
16
13
  </attributes>
17
- <dataset/>
18
- <slice>
19
- <selected-version xmlns="" slice="selected-version" package-name="@epa-wg/custom-element" data-dce-id="2"
20
- current-version="" value="0.0.21">
21
- <event isTrusted="false" sliceProcessed="1" type="change" eventPhase="2" bubbles="true" cancelable="false"
22
- defaultPrevented="false" composed="false" timeStamp="2225577.4000000954" returnValue="true"
23
- cancelBubble="false" NONE="0" CAPTURING_PHASE="1" AT_TARGET="2" BUBBLING_PHASE="3">
24
- <detail package-name="@epa-wg/custom-element"/>
25
- </event>
26
- </selected-version>
27
- </slice>
14
+ <dataset>
15
+ <dceId>2</dceId>
16
+ </dataset>
17
+ <slice/>
28
18
  </datadom>
package/demo/s.xslt CHANGED
@@ -1,78 +1,20 @@
1
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"
2
- xmlns:dce="urn:schemas-epa-wg:dce" xmlns:exsl="http://exslt.org/common" version="1.0"
3
- exclude-result-prefixes="exsl">
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dce="urn:schemas-epa-wg:dce" xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl">
4
3
  <xsl:template match="ignore">
5
4
  <xsl:choose>
6
- <xsl:when test="//attr">
7
- <xsl:value-of select="//attr"/>
8
- </xsl:when>
9
- <xsl:otherwise>
10
- <xsl:value-of select="def"/>
11
- </xsl:otherwise>
12
- </xsl:choose>
13
- <xsl:value-of select="."/>
14
- </xsl:template>
15
- <xsl:template mode="payload" match="attributes">
16
- <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" data-dce-id="1">
17
- <xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="methods">
18
- <a xmlns="" href="https://developer.mozilla.org/en-US/docs/Web/API/Location/href" data-dce-id="2">
19
- location.href
20
- </a>
21
- <a xmlns="" href="https://developer.mozilla.org/en-US/docs/Web/API/Location/hash" data-dce-id="3">
22
- location.hash
23
- </a>
24
- <a xmlns="" href="https://developer.mozilla.org/en-US/docs/Web/API/Location/assign" data-dce-id="4">
25
- location.assign
26
- </a>
27
- </xsl:variable>
28
- <fieldset xmlns="" data-dce-id="5">
29
- <legend data-dce-id="6">
30
- <b data-dce-id="7">set-by</b>
31
- </legend>
32
- <xsl:for-each xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="$methods">
33
- <p data-dce-id="8">
34
- <label data-dce-id="9">
35
- <input type="radio" name="method" value="{.}" data-dce-id="10"/>
36
- <dce-text data-dce-id="11">
37
- <xsl:value-of select="."/>
38
- </dce-text>
39
- </label>
40
- <a class="infolink" href="https://developer.mozilla.org/en-US/docs/Web/API/Location/assign"
41
- data-dce-id="12">mdn
42
- </a>
43
- </p>
44
- </xsl:for-each>
45
- <label data-dce-id="13">
46
- <input type="radio" name="method" value="location.href" data-dce-id="14"/>
47
- <dce-text data-dce-id="15">location.href</dce-text>
48
- </label>
49
- <label data-dce-id="16">
50
- <input type="radio" name="method" value="location" data-dce-id="17"/>
51
- <dce-text data-dce-id="18">location</dce-text>
52
- </label>
53
- <label data-dce-id="19">
54
- <input type="radio" name="method" value="location.replace" data-dce-id="20"/>
55
- <dce-text data-dce-id="21">location.replace</dce-text>
56
- </label>
57
- <label data-dce-id="22">
58
- <input type="radio" name="method" value="location.assign" data-dce-id="23"/>
59
- <dce-text data-dce-id="24">location.assign</dce-text>
60
- </label>
61
- <label data-dce-id="25">
62
- <input type="radio" name="method" value="location.hash" data-dce-id="26"/>
63
- <dce-text data-dce-id="27">location.hash</dce-text>
64
- </label>
65
- <label data-dce-id="28">
66
- <input type="radio" name="method" value="history.pushState" data-dce-id="29"/>
67
- <dce-text data-dce-id="30">history.pushState</dce-text>
68
- </label>
69
- <label data-dce-id="31">
70
- <input type="radio" name="method" value="history.replaceState" data-dce-id="32"/>
71
- <dce-text data-dce-id="33">history.replaceState</dce-text>
72
- </label>
73
- </fieldset>
74
- </dce-root>
75
- </xsl:template>
5
+ <xsl:when test="//attr"><xsl:value-of select="//attr"/></xsl:when>
6
+ <xsl:otherwise><xsl:value-of select="def"/></xsl:otherwise>
7
+ </xsl:choose><xsl:value-of select="."/></xsl:template>
8
+ <xsl:template mode="payload" match="attributes"><xsl:param name="direction"><xsl:choose>
9
+ <xsl:when test="//direction"><xsl:value-of select="//direction"/></xsl:when>
10
+ <xsl:otherwise><xsl:value-of select="'row'"/></xsl:otherwise>
11
+ </xsl:choose></xsl:param><dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" data-dce-id="1"><xsl:attribute name="direction"><xsl:choose>
12
+ <xsl:when test="//direction"><xsl:value-of select="//direction"/></xsl:when>
13
+ <xsl:otherwise><xsl:value-of select="'row'"/></xsl:otherwise>
14
+ </xsl:choose></xsl:attribute><xsl:call-template name="slot">
15
+ <xsl:with-param name="slotname" select="''"/>
16
+ <xsl:with-param name="defaultvalue"/>
17
+ </xsl:call-template></dce-root></xsl:template>
76
18
  <xsl:template match="/">
77
19
  <xsl:apply-templates mode="payload" select="/datadom/attributes"/>
78
20
  </xsl:template>
@@ -81,7 +23,7 @@
81
23
  <xsl:param name="defaultvalue"/>
82
24
  <xsl:choose>
83
25
  <xsl:when test="//payload/*[@slot=$slotname]">
84
- <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
26
+ <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
85
27
  </xsl:when>
86
28
  <xsl:otherwise>
87
29
  <xsl:copy-of select="$defaultvalue"/>
package/demo/ss.html CHANGED
@@ -1,57 +1,24 @@
1
- <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1"><http-request xmlns="" url="/reflect" slice="page" data-dce-id="2"></http-request><p xmlns="" data-dce-id="3">Pokemon Count: 6</p>
2
- <ul xmlns="" data-dce-id="6">
3
- <var data-testid="request-section" data-dce-id="7"><dce-text data-dce-id="8">request</dce-text></var><div data-dce-id="9">
4
- <var data-dce-id="10">@url</var><dce-text data-dce-id="11">
5
- =
6
- </dce-text><code data-testid="attr-url" data-dce-id="12">/reflect</code>
7
- </div>
8
- <div data-dce-id="9-1">
9
- <var data-dce-id="10">@data-dce-id</var><dce-text data-dce-id="11">
10
- =
11
- </dce-text><code data-testid="attr-data-dce-id" data-dce-id="12">2</code>
12
- </div>
13
- </ul>
14
- <ul xmlns="" data-dce-id="6-1">
15
- <var data-testid="request-section" data-dce-id="7"><dce-text data-dce-id="8">response</dce-text></var><div data-dce-id="9">
16
- <var data-dce-id="10">@ok</var><dce-text data-dce-id="11">
17
- =
18
- </dce-text><code data-testid="attr-ok" data-dce-id="12">true</code>
19
- </div>
20
- <div data-dce-id="9-1">
21
- <var data-dce-id="10">@status</var><dce-text data-dce-id="11">
22
- =
23
- </dce-text><code data-testid="attr-status" data-dce-id="12">200</code>
24
- </div>
25
- <div data-dce-id="9-2">
26
- <var data-dce-id="10">@statusText</var><dce-text data-dce-id="11">
27
- =
28
- </dce-text><code data-testid="attr-statusText" data-dce-id="12">OK</code>
29
- </div>
30
- <div data-dce-id="9-3">
31
- <var data-dce-id="10">@type</var><dce-text data-dce-id="11">
32
- =
33
- </dce-text><code data-testid="attr-type" data-dce-id="12">basic</code>
34
- </div>
35
- <div data-dce-id="9-4">
36
- <var data-dce-id="10">@url</var><dce-text data-dce-id="11">
37
- =
38
- </dce-text><code data-testid="attr-url" data-dce-id="12">http://localhost:5173/reflect</code>
39
- </div>
40
- <div data-dce-id="9-5">
41
- <var data-dce-id="10">@redirected</var><dce-text data-dce-id="11">
42
- =
43
- </dce-text><code data-testid="attr-redirected" data-dce-id="12">false</code>
44
- </div>
45
- </ul><button xmlns="" data-dce-id="5">bulbasaur</button><button xmlns="" data-dce-id="5-1">ivysaur</button><button xmlns="" data-dce-id="5-2">venusaur</button><button xmlns="" data-dce-id="5-3">charmander</button><button xmlns="" data-dce-id="5-4">charmeleon</button><button xmlns="" data-dce-id="5-5">charizard</button>
46
- <ul xmlns="" data-dce-id="6-2">
47
- <var data-testid="request-section" data-dce-id="7"><dce-text data-dce-id="8">data</dce-text></var><div data-dce-id="9">
48
- <var data-dce-id="10">@count</var><dce-text data-dce-id="11">
49
- =
50
- </dce-text><code data-testid="attr-count" data-dce-id="12">1279</code>
51
- </div>
52
- <div data-dce-id="9-1">
53
- <var data-dce-id="10">@next</var><dce-text data-dce-id="11">
54
- =
55
- </dce-text><code data-testid="attr-next" data-dce-id="12">https://pokeapi.co/api/v2/pokemon?offset=6&amp;limit=6</code>
56
- </div>
57
- </ul></dce-root>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <dce-root data-dce-id="1" label="Number" name="" placeholder="Enter the numeric value" type="text" value=""
3
+ xmlns="http://www.w3.org/1999/xhtml" xmlns:dce="urn:schemas-epa-wg:dce"
4
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"><pre data-dce-id="2" xmlns=""> //focused
5
+ //suggest
6
+ //selected
7
+ $selected-value </pre>
8
+ <label data-dce-id="3">
9
+ <dce-text data-dce-id="4">Number</dce-text>
10
+ <input data-dce-id="5" name="" placeholder="Enter the numeric value" type="text" value="">
11
+ <slice data-dce-id="6" name="focused" slice-event="focus" slice-value="1"/>
12
+ <slice data-dce-id="7" name="selected" slice-event="input"/>
13
+ </input></label>
14
+ <fieldset data-dce-id="8" form="cem-autocomplete-form" xmlns=""><label data-dce-id="9" value="one"><input
15
+ data-dce-id="10" name="cem-autocomplete" slice="suggest" slice-event="input" type="radio" value="one"/>
16
+ <dce-text data-dce-id="11">One</dce-text>
17
+ </label><label data-dce-id="9" value="two"><input data-dce-id="10" name="cem-autocomplete" slice="suggest" slice-event="input"
18
+ type="radio" value="two"/>
19
+ <dce-text data-dce-id="11">Two</dce-text>
20
+ </label><label data-dce-id="9" value="three"><input data-dce-id="10" name="cem-autocomplete" slice="suggest"
21
+ slice-event="input" type="radio" value="three"/>
22
+ <dce-text data-dce-id="11">Three</dce-text>
23
+ </label></fieldset>
24
+ </dce-root>
@@ -0,0 +1,7 @@
1
+ # transformation lifecycle
2
+
3
+ # embedded CE rendering
4
+
5
+ * render outer CE
6
+ * render inner CE
7
+ *
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/web-types",
3
3
  "name": "@epa-wg/custom-element",
4
- "version": "0.0.26",
4
+ "version": "0.0.28",
5
5
  "js-types-syntax": "typescript",
6
6
  "description-markup": "markdown",
7
7
  "contributions": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/web-types",
3
3
  "name": "@epa-wg/custom-element",
4
- "version": "0.0.26",
4
+ "version": "0.0.28",
5
5
  "js-types-syntax": "typescript",
6
6
  "description-markup": "markdown",
7
7
  "contributions": {
package/index.html CHANGED
@@ -4,7 +4,17 @@
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
5
  <title>custom-element Declarative Custom Element implementation demo</title>
6
6
  <link rel="icon" href="demo/wc-square.svg" />
7
- <script type="module" src="custom-element.js"></script>
7
+ <script type="importmap">
8
+ {
9
+ "imports": {
10
+ "@epa-wg/custom-element/": "./",
11
+ "@epa-wg/custom-element-dist/": "./"
12
+ }
13
+ }
14
+ </script>
15
+ <script type="module" src="./http-request.js"></script>
16
+ <script type="module" src="./location-element.js"></script>
17
+ <script type="module" src="./custom-element.js"></script>
8
18
  <style>
9
19
  @import "demo/demo.css";
10
20
  </style>
@@ -18,6 +28,12 @@
18
28
  | <a href="https://stackblitz.com/github/EPA-WG/custom-element?file=index.html">Sandbox</a>
19
29
  | <a href="https://chrome.google.com/webstore/detail/epa-wgcustom-element/hiofgpmmkdembdogjpagmbbbmefefhbl"
20
30
  >Chrome devtools plugin</a>
31
+ | <custom-element src="@epa-wg/custom-element/demo/npm-versions.html#npm-version-to-url"
32
+ slice="selected" package-name="@epa-wg/custom-element">
33
+ <i slot="label">version:</i>
34
+ </custom-element>
35
+
36
+
21
37
  </div>
22
38
  <p>
23
39
  This <em>Declarative Custom Element</em> allows to define<br/>
@@ -38,7 +54,8 @@
38
54
  <a href="./demo/parameters.html" >attributes </a> |
39
55
  <a href="./demo/data-slices.html" >data slices/events </a> |
40
56
  <a href="./demo/form.html" >Form validation </a> |
41
- <a href="./demo/dom-merge.html" >DOM merge on dynamic update </a>
57
+ <a href="./demo/dom-merge.html" >DOM merge on dynamic update </a><br/>
58
+ <a href="./demo/npm-versions-demo.html">npm version </a>
42
59
  </section>
43
60
  </nav>
44
61
  <html-demo-element legend="1. simple payload"
package/local-storage.js CHANGED
@@ -21,29 +21,34 @@ const string2value = (type, v) =>
21
21
 
22
22
  let originalSetItem,originalRemoveItem,originalClear;
23
23
 
24
+ export function localStorage_setItem( key, value )
25
+ { originalSetItem.call(localStorage, key, value);
26
+ window.dispatchEvent( new CustomEvent('local-storage',{detail:{key,value}}) );
27
+ }
28
+ export function localStorage_removeItem( key )
29
+ { originalRemoveItem.call(localStorage, key);
30
+ window.dispatchEvent( new CustomEvent('local-storage',{detail:{key}}) );
31
+ }
32
+
33
+ export function localStorage_clear()
34
+ { originalClear.call(localStorage);
35
+ window.dispatchEvent( new CustomEvent('local-storage',{detail:{}}) );
36
+ }
37
+
24
38
  function ensureTrackLocalStorage()
25
39
  { if( originalSetItem )
26
40
  return;
27
41
  originalSetItem = localStorage.setItem;
28
- localStorage.setItem = function( key, value, ...rest )
29
- { originalSetItem.apply(this, [ key, value, ...rest ]);
30
- window.dispatchEvent( new CustomEvent('local-storage',{detail:{key,value}}) );
31
- };
42
+ localStorage.setItem = localStorage_setItem;
32
43
  originalRemoveItem = localStorage.removeItem;
33
- localStorage.removeItem = function( key, ...rest )
34
- { originalRemoveItem.apply(this, [ key, ...rest ]);
35
- window.dispatchEvent( new CustomEvent('local-storage',{detail:{key}}) );
36
- };
44
+ localStorage.removeItem = localStorage_removeItem;
37
45
  originalClear = localStorage.clear;
38
- localStorage.clear = function( ...rest )
39
- { originalClear.apply(this, [ ...rest ]);
40
- window.dispatchEvent( new CustomEvent('local-storage',{detail:{}}) );
41
- };
46
+ localStorage.clear = localStorage_clear;
42
47
  }
48
+ ensureTrackLocalStorage();
43
49
 
44
50
  export function localStorageSetItem(key, value)
45
- { localStorage.setItem(key, value);
46
- window.dispatchEvent( new CustomEvent('local-storage',{detail:{key,value}}) );
51
+ { localStorage_setItem(key, value);
47
52
  }
48
53
  export class LocalStorageElement extends HTMLElement
49
54
  {
package/module-url.js CHANGED
@@ -10,9 +10,10 @@ export class ModuleUrl extends HTMLElement
10
10
 
11
11
  sliceInit()
12
12
  { let path = attr(this,'src');
13
+
13
14
  try
14
15
  { const url = '.' === path.charAt(0)
15
- ? new URL(path, this.closest('[base]')?.getAttribute('base') ).href
16
+ ? new URL(path, this.closest('[base]')?.getAttribute('base') || location.href).href
16
17
  : import.meta.resolve(path);
17
18
  this.setAttribute('value',this.value = url );
18
19
  }catch( er )
@@ -30,4 +31,4 @@ export class ModuleUrl extends HTMLElement
30
31
  }
31
32
 
32
33
  window.customElements.define( 'module-url', ModuleUrl );
33
- export default ModuleUrl;
34
+ export default ModuleUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epa-wg/custom-element",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "Declarative Custom Element as W3C proposal PoC with native(XSLT) based templating",
5
5
  "browser": "custom-element.js",
6
6
  "module": "custom-element.js",
package/demo/a.html DELETED
@@ -1,60 +0,0 @@
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
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
- <title>Data slices - Declarative Custom Element implementation demo</title>
6
- <link rel="icon" href="./wc-square.svg"/>
7
-
8
- <script type="module" src="../http-request.js"></script>
9
- <script type="module" src="../custom-element.js"></script>
10
- <style>
11
- @import "./demo.css";
12
-
13
- label {
14
- display: flex;
15
- }
16
-
17
- label:has(input[type="text"],input[type="password"],input:not([type]) ) {
18
- flex-direction: column;
19
- }
20
-
21
- nav {
22
- max-width: 32em;
23
- }
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
-
29
- </head>
30
- <body>
31
-
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>
41
- </template>
42
- <style>dce-3 {
43
- color: green
44
- }</style>
45
- </custom-element>
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
-
59
- </body>
60
- </html>
package/demo/b.html DELETED
@@ -1,13 +0,0 @@
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>
Binary file
Binary file
package/demo/s1.xslt DELETED
@@ -1,60 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"
3
- xmlns:dce="urn:schemas-epa-wg:dce" xmlns:exsl="http://exslt.org/common" version="1.0"
4
- exclude-result-prefixes="exsl">
5
- <xsl:template match="ignore">
6
- <xsl:choose>
7
- <xsl:when test="//attr">
8
- <xsl:value-of select="//attr"/>
9
- </xsl:when>
10
- <xsl:otherwise>
11
- <xsl:value-of select="def"/>
12
- </xsl:otherwise>
13
- </xsl:choose>
14
- <xsl:value-of select="."/>
15
- </xsl:template>
16
- <xsl:template mode="payload" match="attributes">
17
- <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" data-dce-id="1">
18
- <u xmlns="" data-dce-id="2">
19
- <dce-text data-dce-id="3">
20
- <xsl:call-template name="slot">
21
- <xsl:with-param name="slotname" select="''"/>
22
- <xsl:with-param name="defaultvalue">
23
- <dce-text xmlns="" data-dce-id="4">is green</dce-text>
24
- </xsl:with-param>
25
- </xsl:call-template>
26
- </dce-text>
27
- </u>
28
- </dce-root>
29
- </xsl:template>
30
- <xsl:template match="/">
31
- <xsl:apply-templates mode="payload" select="/datadom/attributes"/>
32
- </xsl:template>
33
-
34
- <xsl:template match="@*|node()" mode="copy-html">
35
- <xsl:copy><xsl:apply-templates select="@*|node()" mode="copy-html"/></xsl:copy>
36
- </xsl:template>
37
- <xsl:template match="node()[starts-with(name(),'xhtml:')]" mode="copy-html">
38
- <xsl:element name="{local-name()}"><xsl:apply-templates select="@*|node()" mode="copy-html"/></xsl:element>
39
- </xsl:template>
40
-
41
-
42
- <xsl:template name="slot">
43
- <xsl:param name="slotname"/>
44
- <xsl:param name="defaultvalue"/>
45
- <xsl:choose>
46
- <xsl:when test="//payload/*[@slot=$slotname]">
47
- <xsl:apply-templates mode="copy-html" select="//payload/*[@slot=$slotname]"/>
48
- </xsl:when>
49
- <xsl:otherwise>
50
- <xsl:apply-templates mode="copy-html" select="$defaultvalue"/>
51
- </xsl:otherwise>
52
- </xsl:choose>
53
- </xsl:template>
54
- <xsl:variable name="js-injected-body">
55
- <xsl:call-template name="slot">
56
- <xsl:with-param name="slotname" select="''"/>
57
- <xsl:with-param name="defaultvalue"/>
58
- </xsl:call-template>
59
- </xsl:variable>
60
- </xsl:stylesheet>
package/demo/z.html DELETED
@@ -1,62 +0,0 @@
1
- <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"
2
- xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1">
3
- <location-element xmlns="" slice="window-url" live="" data-dce-id="2"></location-element>
4
- <table xmlns="" data-dce-id="3">
5
- <tbody data-dce-id="0-1">
6
- <tr data-dce-id="4">
7
- <th data-dce-id="5"><h3 data-dce-id="6"> URL properties </h3></th>
8
- <td data-dce-id="7">9</td>
9
- </tr>
10
- <tr data-dce-id="10">
11
- <th data-dce-id="11">href</th>
12
- <td data-dce-id="12">http://localhost:63342/custom-element/demo/a.html?_ijt=dmv0p4go000q47lg48i5im92f7&amp;_ij_reload=RELOAD_ON_SAVE</td>
13
- </tr>
14
- <tr data-dce-id="10-1">
15
- <th data-dce-id="11">origin</th>
16
- <td data-dce-id="12">http://localhost:63342</td>
17
- </tr>
18
- <tr data-dce-id="10-2">
19
- <th data-dce-id="11">protocol</th>
20
- <td data-dce-id="12">http:</td>
21
- </tr>
22
- <tr data-dce-id="10-3">
23
- <th data-dce-id="11">host</th>
24
- <td data-dce-id="12">localhost:63342</td>
25
- </tr>
26
- <tr data-dce-id="10-4">
27
- <th data-dce-id="11">hostname</th>
28
- <td data-dce-id="12">localhost</td>
29
- </tr>
30
- <tr data-dce-id="10-5">
31
- <th data-dce-id="11">port</th>
32
- <td data-dce-id="12">63342</td>
33
- </tr>
34
- <tr data-dce-id="10-6">
35
- <th data-dce-id="11">pathname</th>
36
- <td data-dce-id="12">/custom-element/demo/a.html</td>
37
- </tr>
38
- <tr data-dce-id="10-7">
39
- <th data-dce-id="11">search</th>
40
- <td data-dce-id="12">?_ijt=dmv0p4go000q47lg48i5im92f7&amp;_ij_reload=RELOAD_ON_SAVE</td>
41
- </tr>
42
- <tr data-dce-id="10-8">
43
- <th data-dce-id="11">hash</th>
44
- <td data-dce-id="12"></td>
45
- </tr>
46
- </tbody>
47
- </table>
48
- <h3 data-dce-id="9"> URL parameters </h3>
49
- <table xmlns="" data-dce-id="8">
50
-
51
- <tbody data-dce-id="0-1">
52
- <tr data-dce-id="10">
53
- <th data-dce-id="11">_ijt</th>
54
- <td data-dce-id="12">dmv0p4go000q47lg48i5im92f7</td>
55
- </tr>
56
- <tr data-dce-id="10-1">
57
- <th data-dce-id="11">_ij_reload</th>
58
- <td data-dce-id="12">RELOAD_ON_SAVE</td>
59
- </tr>
60
- </tbody>
61
- </table>
62
- </dce-root>
package/demo/z.js DELETED
@@ -1,9 +0,0 @@
1
- import circle from "circle";
2
- import circle2 from "lib-root/circle.js";
3
- console.log(circle())
4
- try{
5
-
6
- console.log(import.meta.resolve('lib-root/a.js'))
7
- }catch( err ){
8
- console.error(err.message)
9
- }
package/demo/z.xml DELETED
@@ -1,60 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <dce-root data-dce-id="1" xmlns:dce="urn:schemas-epa-wg:dce" xmlns:xhtml="http://www.w3.org/1999/xhtml">
3
- <location-element slice="window-url" data-dce-id="2"/>
4
- <table data-dce-id="3">
5
- <tr data-dce-id="4">
6
- <th data-dce-id="5">
7
- <u data-dce-id="6">URL properties</u>
8
- </th>
9
- </tr>
10
- <tr data-dce-id="7">
11
- <th data-dce-id="8">href</th>
12
- <td data-dce-id="9">http://localhost:63342/custom-element/demo/a.html?_ijt=qca6trk5kne6eo4s4tomq4egmm&amp;_ij_reload=RELOAD_ON_SAVE</td>
13
- </tr>
14
- <tr data-dce-id="7">
15
- <th data-dce-id="8">origin</th>
16
- <td data-dce-id="9">http://localhost:63342</td>
17
- </tr>
18
- <tr data-dce-id="7">
19
- <th data-dce-id="8">protocol</th>
20
- <td data-dce-id="9">http:</td>
21
- </tr>
22
- <tr data-dce-id="7">
23
- <th data-dce-id="8">host</th>
24
- <td data-dce-id="9">localhost:63342</td>
25
- </tr>
26
- <tr data-dce-id="7">
27
- <th data-dce-id="8">hostname</th>
28
- <td data-dce-id="9">localhost</td>
29
- </tr>
30
- <tr data-dce-id="7">
31
- <th data-dce-id="8">port</th>
32
- <td data-dce-id="9">63342</td>
33
- </tr>
34
- <tr data-dce-id="7">
35
- <th data-dce-id="8">pathname</th>
36
- <td data-dce-id="9">/custom-element/demo/a.html</td>
37
- </tr>
38
- <tr data-dce-id="7">
39
- <th data-dce-id="8">search</th>
40
- <td data-dce-id="9">?_ijt=qca6trk5kne6eo4s4tomq4egmm&amp;_ij_reload=RELOAD_ON_SAVE</td>
41
- </tr>
42
- <tr data-dce-id="7">
43
- <th data-dce-id="8">hash</th>
44
- <td data-dce-id="9"/>
45
- </tr>
46
- <tr data-dce-id="10">
47
- <th data-dce-id="11">
48
- <u data-dce-id="12">URL parameters</u>
49
- </th>
50
- </tr>
51
- <tr data-dce-id="13">
52
- <th data-dce-id="14">_ijt</th>
53
- <td data-dce-id="15">qca6trk5kne6eo4s4tomq4egmm</td>
54
- </tr>
55
- <tr data-dce-id="13">
56
- <th data-dce-id="14">_ij_reload</th>
57
- <td data-dce-id="15">RELOAD_ON_SAVE</td>
58
- </tr>
59
- </table>
60
- </dce-root>
package/request.html DELETED
@@ -1,53 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
- <title>custom-element Declarative Custom Element implementation demo</title>
6
- <script type="module" src="custom-element.js"></script>
7
- <style>
8
- body,nav{ display: flex; flex-wrap: wrap; align-content: stretch; gap: 1rem; }
9
- nav{ flex-direction: column;}
10
- dce-link,dce-1-slot,dce-2-slot,dce-3-slot,dce-4-slot,dce-2-slots,greet-element,pokemon-tile
11
- { box-shadow: 0 0 0.5rem lime; padding: 1rem; display: inline-block;}
12
- dd{ padding: 1rem;}
13
- p{ margin: 0;}
14
- </style>
15
- </head>
16
- <body>
17
-
18
- <html-demo-element legend="1. simple payload"
19
- description="payload is ignored as in DCE definition there is no default slot">
20
- <template>
21
- <custom-element tag="poke-image-request" hidden>
22
- <img src="https://unpkg.com/pokeapi-sprites@2.0.2/sprites/pokemon/other/dream-world/{//poke-id}.svg"/>
23
- </custom-element>
24
- <poke-image-request poke-id="1"></poke-image-request>
25
-
26
- <custom-element tag="poke-list-request" hidden>
27
- <a href="https://pokeapi.co/api/v2/pokemon?offset={//offset}&limit=10">list json</a>
28
- </custom-element>
29
-
30
- <custom-element tag="poke-list-page" hidden>
31
- <a href="https://pokeapi.co/api/v2/pokemon?offset={//offset}&limit=10">list json</a>
32
- <http-request-json
33
- target="poke-list"
34
- src="https://pokeapi.co/api/v2/pokemon?offset={//offset}&limit=10"
35
- ></http-request-json>
36
- <ol>
37
- <for-each select="">
38
-
39
- </for-each>
40
- </ol>
41
- </custom-element>
42
- <poke-list-page>
43
- <poke-list-request offset="0"></poke-list-request>
44
- </poke-list-page>
45
-
46
- </template>
47
- </html-demo-element>
48
-
49
-
50
- <script type="module" src="https://unpkg.com/html-demo-element@1.0/html-demo-element.js"></script>
51
-
52
- </body>
53
- </html>