@epa-wg/custom-element 0.0.32 → 0.0.33

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
@@ -47,7 +47,7 @@ This project is a POC( Proof of Concept ) targeting to become a base for native
47
47
 
48
48
  # use
49
49
 
50
- Use the [bootstrap project](https://github.com/EPA-WG/custom-element-bootstrap) with all pre-configured or
50
+ [//]: # (Use the [bootstrap project](https://github.com/EPA-WG/custom-element-bootstrap) with all pre-configured or)
51
51
  ## install
52
52
  use via CDN
53
53
  ```html
@@ -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]: https://unpkg.com/@epa-wg/custom-element@0.0.32/demo/hex-grid-transform.png
344
+ [hex-grid-image]: https://unpkg.com/@epa-wg/custom-element@0.0.33/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.32/coverage/src/custom-element/coverage.svg
352
- [coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.32/coverage/src/custom-element/index.html
353
- [storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.32/storybook-static/index.html?path=/story/welcome--introduction
351
+ [coverage-image]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.33/coverage/src/custom-element/coverage.svg
352
+ [coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.33/coverage/src/custom-element/index.html
353
+ [storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.33/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.32",
119
+ "version": "0.0.33",
120
120
  "js-types-syntax": "typescript",
121
121
  "description-markup": "markdown",
122
122
  "contributions": {
@@ -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 cloneAs(sourceNode: HTMLElement, tag:string): HTMLElement;
4
+ export function mix(objTo: any, objFrom:any): any;
5
+ export function mergeAttr(fromEl: HTMLElement, toEL:HTMLElement): void;
6
+
3
7
  export function xml2dom(xmlString:string): Document;
4
8
  export function xmlString(doc:Node|Document): string;
5
9
  export function obj2node(o:any, tag:string, doc:Document): HTMLElement;
package/custom-element.js CHANGED
@@ -5,7 +5,7 @@ const XSL_NS_URL = 'http://www.w3.org/1999/XSL/Transform'
5
5
 
6
6
  // const log = x => console.debug( new XMLSerializer().serializeToString( x ) );
7
7
 
8
- const attr = (el, attr)=> el.getAttribute?.(attr)
8
+ const attr = (el, attr)=> el?.getAttribute?.(attr)
9
9
  , isText = e => e.nodeType === 3
10
10
  , isString = s => typeof s === 'string'
11
11
  , isNode = e => e && typeof e.nodeType === 'number'
@@ -294,6 +294,16 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
294
294
  fr.append(r)
295
295
  }
296
296
 
297
+ [...fr.querySelectorAll('[test]')].forEach( n=>{
298
+ const t = attr(n,'test')
299
+ , r = t.replace(/hasBoolAttribute\((.*?)\)/g,
300
+ (match, p1, p2,p3,p4)=>
301
+ { const a = p1.substring(1);
302
+ return `(not($${a} = \'false\') and ($${a} = '' or $${a} = '${a}' or $${a} = 'true' ))`
303
+ });
304
+ t!== r && n.setAttribute('test',r);
305
+ });
306
+
297
307
  [...fr.querySelectorAll('dce-root>attribute')].forEach( a=>
298
308
  {
299
309
  keepAttributes(a,'namespace,name,select');
@@ -317,10 +327,15 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
317
327
  if( select?.length>1 )
318
328
  { p.removeAttribute('select');
319
329
  const c = $( xslDom, 'template[match="ignore"]>choose').cloneNode(true);
320
- // todo multiple ?? operators
321
330
  emptyNode(c.firstElementChild).append( createText(c,'{'+select[0]+'}'));
322
- emptyNode(c.lastElementChild ).append( createText(c,'{'+select[1]+'}'));
323
- c.firstElementChild.setAttribute('test','string-length('+select[0]+')');
331
+ c.firstElementChild.setAttribute('test',select[0]);
332
+ for( let i=1; i<select.length-1; i++)
333
+ { const when = c.firstElementChild.cloneNode(true);
334
+ emptyNode(when).append( createText(c,'{'+select[i]+'}'));
335
+ when.setAttribute('test',select[i]);
336
+ c.insertBefore(when, c.lastElementChild);
337
+ }
338
+ emptyNode(c.lastElementChild ).append( createText(c,'{'+select[select.length-1]+'}'));
324
339
  p.append(c);
325
340
  val = c.cloneNode(true);
326
341
  }else
@@ -329,8 +344,12 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
329
344
  a.append(val);
330
345
  a.removeAttribute('select');
331
346
  }else
332
- { keepAttributes( p, 'name' );
347
+ {
348
+ keepAttributes( p, 'name' );
333
349
  p.setAttribute('select','/datadom/attributes/'+name)
350
+
351
+ if( !hardcodedAttributes[name] )
352
+ a.remove();
334
353
  }
335
354
  });
336
355
  [...fr.querySelectorAll('[value]')].filter(el=>el.getAttribute('value').match( /\{(.*)\?\?(.*)\}/g )).forEach(el=>
@@ -460,12 +479,15 @@ event2slice( x, sliceNames, ev, dce )
460
479
  const v = notChecked? '' : el.value ?? attr( el, 'value' );
461
480
  cleanSliceValue();
462
481
  if( v === null || v === undefined )
482
+ {
463
483
  [...s.childNodes].filter(n=>n.localName!=='event').map(n=>n.remove());
484
+ s.removeAttribute('value');
485
+ }
464
486
  else
465
- if( isString(v) )
466
- s.append( createText( d, v) );
467
- else
468
- s.append( obj2node(v,'value',s.ownerDocument) )
487
+ { const ve = isString(v) ? createText( d, v) : obj2node(v,'value',s.ownerDocument);
488
+ s.append( ve );
489
+ s.setAttribute('value',v);
490
+ }
469
491
  }
470
492
  return s
471
493
  })
@@ -513,11 +535,24 @@ const loadTemplateRoots = async ( src, dce )=>
513
535
  export function mergeAttr( from, to )
514
536
  { for( let a of from.attributes)
515
537
  try
516
- { a.namespaceURI? to.setAttributeNS( a.namespaceURI, a.name, a.value ) : to.setAttribute( a.name, a.value )
538
+ { const name = a.name;
539
+ if( a.namespaceURI )
540
+ { if( !to.hasAttributeNS(a.namespaceURI, name) || to.getAttributeNS(a.namespaceURI, name) !== a.value )
541
+ to.setAttributeNS( a.namespaceURI, name, a.value )
542
+ }else
543
+ { if( !to.hasAttribute(name) || to.getAttribute(name) !== a.value )
544
+ to.setAttribute( a.name, a.value )
545
+ }
517
546
  if( a.name === 'value')
518
547
  to.value = a.value
519
548
  }catch(e)
520
549
  { console.warn('attribute assignment error',e?.message || e); }
550
+ const ea = to.dceExportedAttributes
551
+ , aa = to.getAttribute('dce-exported-attributes')
552
+ , em = aa ? new Set( aa.split(' ') ) : null;
553
+ for( let a of to.getAttributeNames() )
554
+ if( !from.hasAttribute(a) && !ea?.has(a) && !em?.has(a) )
555
+ to.removeAttribute(a)
521
556
  }
522
557
  export function assureUnique(n, id=0)
523
558
  {
@@ -681,11 +716,13 @@ CustomElement extends HTMLElement
681
716
  .map(splitSliceNames).flat();
682
717
 
683
718
  const { declaredAttributes, hardcodedAttributes, exposedAttributes } = templateDocs[0];
719
+ const dceExportedAttributes = new Set([...Object.keys(hardcodedAttributes), ...Object.keys(exposedAttributes)]);
684
720
 
685
721
  class DceElement extends HTMLElement
686
722
  {
687
723
  static get observedAttributes(){ return declaredAttributes; }
688
724
  #inTransform = 0;
725
+ get dceExportedAttributes(){ return dceExportedAttributes; }
689
726
  connectedCallback()
690
727
  { let payload = sanitizeBlankText(this.childNodes);
691
728
  if( this.firstElementChild?.tagName === 'TEMPLATE' )
@@ -719,8 +756,9 @@ CustomElement extends HTMLElement
719
756
  this.innerHTML='';
720
757
  const attrsRoot = injectData( x, 'attributes' , this.attributes, e => createXmlNode( e.nodeName, e.value ) )
721
758
  , inAttrs = a=> this.hasAttribute(a) || [...attrsRoot.children].find(e=>e.localName === a);
759
+ mergeAttr( this, attrsRoot );
722
760
  Object.keys(hardcodedAttributes).map(a=> inAttrs(a) || attrsRoot.append(createXmlNode(a,hardcodedAttributes[a])) );
723
- declaredAttributes.map(a=> inAttrs(a) || attrsRoot.append(createXmlNode(a)) );
761
+ Object.keys(exposedAttributes).map(a=> inAttrs(a) || attrsRoot.append(createXmlNode(a)) );
724
762
 
725
763
  injectData( x, 'dataset', Object.keys( this.dataset ), k => createXmlNode( k, this.dataset[ k ] ) );
726
764
  const sliceRoot = injectData( x, 'slice', sliceNames, k => createXmlNode( k, '' ) )
@@ -753,34 +791,42 @@ CustomElement extends HTMLElement
753
791
  const transform = this.transform = ()=>
754
792
  { if(this.#inTransform){ debugger }
755
793
  this.#inTransform = 1;
756
-
757
- const ff = xp.map( (p,i) =>
758
- { const f = p.transformToFragment(x.ownerDocument, document)
759
- if( !f )
760
- console.error( "XSLT transformation error. xsl:\n", xmlString(templateDocs[i]), '\nxml:\n', xmlString(x) );
761
- return f
762
- });
763
- ff.map( f =>
764
- { if( !f )
765
- return;
766
- assureUnique(f);
767
- merge( this, f.childNodes )
768
- })
769
-
770
- Object.entries(hardcodedAttributes).map(( [a,v] )=>
771
- { if( !this.hasAttribute(a) && v !== attr(this,a) )
772
- { this.setAttribute( a, v );
773
- this.#applyAttribute( a, v );
774
- }
775
- });
776
-
777
- Object.keys(exposedAttributes).map( a =>
778
- { let v = attr(this.firstElementChild,a);
779
- if( v !== attr(this,a) )
780
- { this.setAttribute( a, v );
781
- this.#applyAttribute( a, v );
782
- }
783
- });
794
+ const renderModel = ()=>
795
+ {
796
+ const ff = xp.map( (p,i) =>
797
+ { const f = p.transformToFragment(x.ownerDocument, document)
798
+ if( !f )
799
+ console.error( "XSLT transformation error. xsl:\n", xmlString(templateDocs[i]), '\nxml:\n', xmlString(x) );
800
+ return f
801
+ });
802
+ ff.map( f =>
803
+ { if( !f )
804
+ return;
805
+ assureUnique(f);
806
+ merge( this, f.childNodes )
807
+ })
808
+ let attrChangedCount = 0;
809
+ Object.entries(hardcodedAttributes).map(( [a,v] )=>
810
+ { if( !this.hasAttribute(a) && v !== attr(this,a) )
811
+ { this.setAttribute( a, v );
812
+ this.#applyAttribute( a, v );
813
+ attrChangedCount++;
814
+ }
815
+ });
816
+
817
+ Object.keys(exposedAttributes).map( a =>
818
+ { let v = attr(this.firstElementChild,a);
819
+ if( v !== attr(this,a) )
820
+ { this.setAttribute( a, v );
821
+ this.#applyAttribute( a, v );
822
+ attrChangedCount++;
823
+ }
824
+ });
825
+ return attrChangedCount;
826
+ };
827
+ if( renderModel() )
828
+ if( renderModel() )
829
+ console.warn("model update should not be the result of transform more than once");
784
830
 
785
831
  function getSliceTarget(el)
786
832
  { let r = el;
@@ -868,13 +914,15 @@ CustomElement extends HTMLElement
868
914
  #applyAttribute(name, newValue)
869
915
  { if( 'value' === name )
870
916
  this.value = newValue;
917
+ const attrs = this.xml.querySelector('attributes');
871
918
  let a = this.xml.querySelector(`attributes>${name}`);
872
919
  if( a )
873
920
  emptyNode(a).append( createText(a,newValue) );
874
921
  else
875
922
  { a = create( name, newValue, this.xml );
876
- this.xml.querySelector('attributes').append( a );
923
+ attrs.append( a );
877
924
  }
925
+ this.#inTransform || attrs.setAttribute(name,newValue);
878
926
 
879
927
  this.dispatchEvent(new CustomEvent('change', { bubbles: true,detail: { [name]: newValue }}))
880
928
  }
@@ -22,14 +22,30 @@
22
22
  <nav>
23
23
  <a href="../index.html"><h3><code>custom-element</code> demo</h3></a>
24
24
  </nav>
25
- <html-demo-element legend="param as attributes definition" description="
26
- params needed to declare DCE attributes and track the attributes changes. It also be used by IDE and validation.
27
- ">
25
+ <main>
26
+ <p><code>attribute</code> is used for DCE attributes declaration and track the attributes changes. It also be used by IDE and validation.</p>
27
+ <p>The attribute can be changed by component itself and used as output to the container.
28
+ Usual case is when <code>value</code> attribute is updated from inside.</p>
29
+ <p>Initial value of attribute is available on the <code>attributes</code> node attribute as in <code>/datadom/attributes/@attr1</code></p>
30
+ <p>The current, i.e. including the changes by component itself, attribute value is a child node of <code>attributes</code> as in <code>/datadom/attributes/attr1</code>.</p>
31
+ <p>To define the attribute which is modified from within, the 3 parts are usually used as in <code>//s[//s/event] ?? //attributes/@v ?? 'def' </code>
32
+ <ol>
33
+ <li><code>//s[//s/event]</code> the slice <code>s</code> with event gives the slice value which was modified by user event like input</li>
34
+ <li><code>//attributes/@v</code> the attribute passed by container</li>
35
+ <li><code>'def' </code> the default value which used when no user input or attribute set by container</li>
36
+ </ol>
37
+ </p>
38
+ </main>
39
+ <html-demo-element legend="attributes definition" >
40
+ <p slot="description">
41
+ <code>attribute</code> is used for DCE attributes declaration and track the attributes changes. It also be used by IDE and validation.
42
+
43
+ </p>
28
44
  <template>
29
45
  <custom-element tag="dce-link" hidden>
30
46
  <attribute name="p1" >default_P1 </attribute>
31
47
  <attribute name="p2" select="'always_p2'" ></attribute>
32
- <attribute name="p3" select="//p3 ?? 'def_P3' " ></attribute>
48
+ <attribute name="p3" select="//attributes/@p3 ?? 'def_P3' " ></attribute>
33
49
  p1:{$p1} <br/> p2: {$p2} <br/> p3: {$p3}
34
50
  </custom-element>
35
51
  <dce-link id="dce1" ></dce-link>
@@ -44,13 +60,15 @@ params needed to declare DCE attributes and track the attributes changes. It als
44
60
  </template>
45
61
  </html-demo-element>
46
62
 
47
- <html-demo-element legend="attribute from slice" description="
48
- when slice value points to attribute, it would be populated on slice change
49
- ">
63
+ <html-demo-element legend="attribute from slice">
64
+ <p slot="description">
65
+ When slice value points to attribute, it would be populated on slice change.<br/>
50
66
  Type in the input field to see the variable $title change. <br/>
51
67
  Hover the mouse to see the title attribute text popup.<br/>
52
68
  Inspect DCE node in dev tools to see `title` attribute updated while typing.
53
69
 
70
+ </p>
71
+
54
72
  <template>
55
73
  <custom-element>
56
74
  <template>
@@ -62,6 +80,52 @@ when slice value points to attribute, it would be populated on slice change
62
80
  </template>
63
81
  </html-demo-element>
64
82
 
83
+
84
+ <html-demo-element legend="V attribute matches input value" description="
85
+ Type in the input field and observe in DevTools the V attribute changed.
86
+ ">
87
+ <template>
88
+ <custom-element tag="x-input" >
89
+ <template>
90
+ <attribute name="is-changed" select="count(//s/event) &gt; 0"></attribute>
91
+ <attribute name="v" select="//s[//s/event] ?? //attributes/@v ?? 'def' "></attribute>
92
+ /datadom/attributes/v='{/datadom/attributes/v}'<br/>
93
+ same as v='{v}'<br/>
94
+ same as $v='{$v}'<br/>
95
+ //attributes/@v='{//attributes/@v}'<br/>
96
+ //s='{//s}'<br/>
97
+ is-changed ={ is-changed }<br/>
98
+ <input slice="s" slice-event="input" value="{//attributes/v}"/>
99
+ </template>
100
+ </custom-element>
101
+ <x-input></x-input>
102
+ <x-input v="V1"></x-input>
103
+ </template>
104
+ </html-demo-element>
105
+
106
+ <html-demo-element legend="attribute defaults, from container, and from slice" description="
107
+ Type in the input field and observe in DevTools the V attribute changed.
108
+ ">
109
+ <template>
110
+ <custom-element tag="attr-demo">
111
+ <template>
112
+ <variable name="has-input" select="count(//s/*) &gt; 0"></variable>
113
+ <attribute name="v" select="//s[//s/event] ?? //attributes/@v ?? 'def' "></attribute>
114
+ //attributes/v='{//attributes/v}'<br/>
115
+ //attributes/@v='{//attributes/@v}'<br/>
116
+ $v='{$v}'<br/>
117
+ //s='{//s}'<br/>
118
+ A='{//s[//s/event] | //attributes/v[not(//s/event)]}'<br/>
119
+ has-input ={ $has-input }<br/>
120
+ <input slice="s" slice-event="input" />
121
+ </template>
122
+ </custom-element>
123
+
124
+ <attr-demo></attr-demo>
125
+ <attr-demo v="From Container"></attr-demo>
126
+ </template>
127
+ </html-demo-element>
128
+
65
129
  <details>
66
130
  <summary>Attributes processing</summary>
67
131
  To be available in template, <code>custom-element</code> attributes should be
package/demo/s.xml CHANGED
@@ -1,12 +1,75 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <datadom>
3
- <payload xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"/>
4
- <attributes>
5
- <id>dce1</id>
6
- <p1>default_P1</p1>
7
- <p2>always_p2</p2>
8
- <p3></p3>
3
+ <payload xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml">
4
+ <div xmlns="http://www.w3.org/1999/xhtml" slot="leading" data-dce-id="4">
5
+ <cem-icon image="history_edu" class="input-focused" data-dce-id="5">
6
+ <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"
7
+ xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1">
8
+ <span xmlns="" class="icon material-icons" data-dce-id="5">history_edu</span>
9
+ </dce-root>
10
+ </cem-icon>
11
+ <cem-icon image="edit" class="input-unfocused" data-dce-id="6">
12
+ <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"
13
+ xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1">
14
+ <span xmlns="" class="icon material-icons" data-dce-id="5">edit</span>
15
+ </dce-root>
16
+ </cem-icon>
17
+ </div>
18
+ <div xmlns="http://www.w3.org/1999/xhtml" slot="trailing" data-dce-id="7">
19
+ <label class="eye-contailer" for="visible-cb" data-dce-id="8">
20
+ <cem-icon image="visibility" class="visible-ico" tabindex="0" data-dce-id="9">
21
+ <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"
22
+ xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1">
23
+ <span xmlns="" class="icon material-icons" data-dce-id="5">visibility</span>
24
+ </dce-root>
25
+ </cem-icon>
26
+ <cem-icon image="visibility_off" class="invisible-ico" tabindex="0" data-dce-id="10">
27
+ <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"
28
+ xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1">
29
+ <span xmlns="" class="icon material-icons" data-dce-id="5">visibility_off</span>
30
+ </dce-root>
31
+ </cem-icon>
32
+ </label>
33
+ <cem-icon image="close" class="clear" tabindex="0" slice="password" slice-event="click" slice-value="''"
34
+ data-dce-id="11">
35
+ <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"
36
+ xmlns:dce="urn:schemas-epa-wg:dce" data-dce-id="1">
37
+ <span xmlns="" class="icon material-icons" data-dce-id="5">close</span>
38
+ </dce-root>
39
+ </cem-icon>
40
+ <dce-text data-dce-id="12">️
41
+ </dce-text>
42
+ </div>
43
+ </payload>
44
+ <attributes xmlns="" label="password sample" value="secret word" slice="password" data-dce-id="3" type="">
45
+ <xmlns/>
46
+ <label>password sample</label>
47
+ <value>secret word</value>
48
+ <slice>password</slice>
49
+ <data-dce-id>3</data-dce-id>
50
+ <type></type>
9
51
  </attributes>
10
- <dataset/>
11
- <slice/>
52
+ <dataset>
53
+ <dceId>3</dceId>
54
+ </dataset>
55
+ <slice>
56
+ <selected/>
57
+ <password image="close" class="clear" tabindex="0" slice="password" slice-event="click" slice-value="''"
58
+ data-dce-id="11">
59
+ <event isTrusted="true" sliceProcessed="1" pointerId="1" width="1" height="1" pressure="0" tiltX="0"
60
+ tiltY="0" azimuthAngle="0" altitudeAngle="1.5707963267948966" tangentialPressure="0" twist="0"
61
+ pointerType="mouse" isPrimary="false" persistentDeviceId="0" screenX="345" screenY="682"
62
+ clientX="345" clientY="595" ctrlKey="false" shiftKey="false" altKey="false" metaKey="false"
63
+ button="0" buttons="0" pageX="345" pageY="4354" x="345" y="595" offsetX="14" offsetY="15"
64
+ movementX="0" movementY="0" layerX="248" layerY="27" detail="1" which="1" type="click" eventPhase="3"
65
+ bubbles="true" cancelable="true" defaultPrevented="false" composed="true"
66
+ timeStamp="1974517.2999999523" returnValue="true" cancelBubble="false" NONE="0" CAPTURING_PHASE="1"
67
+ AT_TARGET="2" BUBBLING_PHASE="3">
68
+ <relatedTarget/>
69
+ <fromElement/>
70
+ <toElement/>
71
+ <sourceCapabilities firesTouchEvents="false"/>
72
+ </event>
73
+ </password>
74
+ </slice>
12
75
  </datadom>
package/demo/s.xslt CHANGED
@@ -1,4 +1,3 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
1
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"
3
2
  xmlns:dce="urn:schemas-epa-wg:dce" xmlns:exsl="http://exslt.org/common" version="1.0"
4
3
  exclude-result-prefixes="exsl">
@@ -14,54 +13,79 @@
14
13
  <xsl:value-of select="."/>
15
14
  </xsl:template>
16
15
  <xsl:template mode="payload" match="attributes">
17
- <xsl:param name="p1" select="/datadom/attributes/p1">default_P1</xsl:param>
18
- <xsl:param name="p2" select="'always_p2'"/>
19
- <xsl:param name="p3">
16
+ <xsl:param name="v">
20
17
  <xsl:choose>
21
- <xsl:when test="string-length(//p3)>0 ">RRRR
22
- <xsl:value-of select="count(//p3)"/>
23
- +<xsl:value-of select="//p3 "/>=
18
+ <xsl:when test="//s[//s/event] ">
19
+ <xsl:value-of select="//s[//s/event] "/>
24
20
  </xsl:when>
25
- <xsl:otherwise>OOO
26
- <xsl:value-of select=" 'def_P3' "/>
21
+ <xsl:when test=" //attributes/@v ">
22
+ <xsl:value-of select=" //attributes/@v "/>
23
+ </xsl:when>
24
+ <xsl:otherwise>
25
+ <xsl:value-of select=" 'def' "/>
27
26
  </xsl:otherwise>
28
27
  </xsl:choose>
29
28
  </xsl:param>
30
29
  <dce-root xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" data-dce-id="1">
31
- <xsl:attribute name="p1">default_P1</xsl:attribute>
32
- <xsl:attribute name="p2">
33
- <xsl:value-of select="'always_p2'"/>
34
- </xsl:attribute>
35
- <xsl:attribute name="p3">
30
+ <xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="has-input"
31
+ select="count(//s/*) &gt; 0"/>
32
+ <xsl:attribute name="v">
36
33
  <xsl:choose>
37
- <xsl:when test="//p3 ">
38
- <xsl:value-of select="//p3 "/>
34
+ <xsl:when test="//s[//s/event] ">
35
+ <xsl:value-of select="//s[//s/event] "/>
36
+ </xsl:when>
37
+ <xsl:when test=" //attributes/@v ">
38
+ <xsl:value-of select=" //attributes/@v "/>
39
39
  </xsl:when>
40
40
  <xsl:otherwise>
41
- <xsl:value-of select=" 'def_P3' "/>
41
+ <xsl:value-of select=" 'def' "/>
42
42
  </xsl:otherwise>
43
43
  </xsl:choose>
44
44
  </xsl:attribute>
45
45
  <dce-text xmlns="" data-dce-id="2">
46
- p1:
46
+
47
+ //attributes/v='<xsl:value-of select="//attributes/v"/>'
47
48
  </dce-text>
48
- <code xmlns="" data-testid="p1" data-dce-id="3">
49
- <xsl:value-of select="$p1"/>
50
- </code>
51
- <br xmlns="" data-dce-id="4"/>
52
- <dce-text xmlns="" data-dce-id="5">
53
- p2:
49
+ <br xmlns="" data-dce-id="3"/>
50
+ <dce-text xmlns="" data-dce-id="4">
51
+ //attributes/@v='<xsl:value-of select="//attributes/@v"/>'
52
+ </dce-text>
53
+ <br xmlns="" data-dce-id="5"/>
54
+ <dce-text xmlns="" data-dce-id="6">
55
+ $v='<xsl:value-of select="$v"/>'
54
56
  </dce-text>
55
- <code xmlns="" data-testid="p2" data-dce-id="6">
56
- <xsl:value-of select="$p2"/>
57
- </code>
58
57
  <br xmlns="" data-dce-id="7"/>
59
58
  <dce-text xmlns="" data-dce-id="8">
60
- p3:
59
+ //s='<xsl:value-of select="//s"/>'
60
+ </dce-text>
61
+ <br xmlns="" data-dce-id="9"/>
62
+ <dce-text xmlns="" data-dce-id="10">
63
+ A='<xsl:value-of select="//s[//s/event] | //attributes/v[not(//s/event)]"/>'
64
+ </dce-text>
65
+ <br xmlns="" data-dce-id="11"/>
66
+ <dce-text xmlns="" data-dce-id="12">
67
+ has-input =<xsl:value-of select=" $has-input "/>
68
+ </dce-text>
69
+ <br xmlns="" data-dce-id="13"/>
70
+ <xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="in-value">
71
+ <xsl:choose>
72
+ <xsl:when test="//s/event">
73
+ <xsl:value-of select="//s">
74
+ </xsl:value-of>
75
+ </xsl:when>
76
+ <xsl:when test="//attributes/@v">
77
+ <xsl:value-of select="//attributes/@v">
78
+ </xsl:value-of>
79
+ </xsl:when>
80
+ <xsl:otherwise>def</xsl:otherwise>
81
+ </xsl:choose>
82
+ </xsl:variable>
83
+ <xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="xx"
84
+ select="//s[//s/event] ?? //attributes/@v ?? 'def' "/>
85
+ <input xmlns="" slice="s" slice-event="input" value="{$in-value}" data-dce-id="14"/>
86
+ <dce-text xmlns="" data-dce-id="15">$in-value:<xsl:value-of select="$in-value"/> | $xx:<xsl:value-of
87
+ select="$xx"/>
61
88
  </dce-text>
62
- <code xmlns="" data-testid="p3" data-dce-id="9">
63
- <xsl:value-of select="$p3"/>
64
- </code>
65
89
  </dce-root>
66
90
  </xsl:template>
67
91
  <xsl:template match="/">
package/demo/ss.html CHANGED
@@ -1,5 +1,14 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <dce-root data-dce-id="1" value="123"
3
- xmlns="http://www.w3.org/1999/xhtml" xmlns:dce="urn:schemas-epa-wg:dce" xmlns:xhtml="http://www.w3.org/1999/xhtml"><label data-dce-id="2">
4
- <dce-text data-dce-id="3"/>
5
- <input data-dce-id="4" slice="selected" slice-event="input" value="123"/></label></dce-root>
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"><label data-dce-id="2" xmlns=""><input data-dce-id="3"
4
+ slice="disabled-slice"
5
+ type="checkbox"
6
+ value="disabled"/>
7
+ <dce-text data-dce-id="4">disabled</dce-text>
8
+ </label>
9
+ <cem-input data-dce-id="6" value="123"/>
10
+ <button data-dce-id="7">Next</button>
11
+
12
+
13
+ </p></form>
14
+ </dce-root>
@@ -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.32",
4
+ "version": "0.0.33",
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.32",
4
+ "version": "0.0.33",
5
5
  "js-types-syntax": "typescript",
6
6
  "description-markup": "markdown",
7
7
  "contributions": {
package/index.html CHANGED
@@ -51,7 +51,7 @@
51
51
  <a href="./demo/module-url.html" >importmap </a> <br/>
52
52
  <a href="./demo/hex-grid.html" >hex grid lib </a> |
53
53
  <a href="./demo/scoped-css.html" >scoped CSS </a> |
54
- <a href="./demo/parameters.html" >attributes </a> |
54
+ <a href="./demo/attributes.html" >attributes </a> |
55
55
  <a href="./demo/data-slices.html" >data slices/events </a> |
56
56
  <a href="./demo/form.html" >Form validation </a> |
57
57
  <a href="./demo/dom-merge.html" >DOM merge on dynamic update </a><br/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epa-wg/custom-element",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
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",