@epa-wg/custom-element 0.0.11 → 0.0.13

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.
Files changed (47) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +22 -7
  2. package/.idea/misc.xml +4 -5
  3. package/.vs/VSWorkspaceState.json +8 -0
  4. package/.vs/custom-element/FileContentIndex/1487e471-3751-47bc-a499-d78eda924eda.vsidx +0 -0
  5. package/.vs/custom-element/v17/.wsuo +0 -0
  6. package/.vs/slnx.sqlite +0 -0
  7. package/README.md +71 -19
  8. package/custom-element.js +241 -66
  9. package/demo/a.html +25 -11
  10. package/demo/confused.svg +36 -36
  11. package/demo/dom-merge.html +124 -0
  12. package/demo/embed-1.html +2 -2
  13. package/demo/external-template.html +9 -7
  14. package/demo/hex-grid-dce.html +183 -0
  15. package/demo/hex-grid-transform.png +0 -0
  16. package/demo/hex-grid.html +66 -0
  17. package/demo/html-template.html +125 -12
  18. package/demo/html-template.xhtml +44 -44
  19. package/demo/html-template.xml +44 -44
  20. package/demo/http-request.html +44 -57
  21. package/demo/local-storage.html +23 -18
  22. package/demo/location-element.html +59 -58
  23. package/demo/s.xml +1 -0
  24. package/demo/s.xslt +159 -0
  25. package/demo/scoped-css.html +170 -0
  26. package/demo/ss.html +32 -0
  27. package/demo/table.xml +24 -24
  28. package/demo/table.xsl +292 -292
  29. package/demo/template.xsl +45 -45
  30. package/demo/tree.xml +24 -24
  31. package/demo/tree.xsl +32 -32
  32. package/demo/xhtml-template.xhtml +44 -44
  33. package/demo/z.html +42 -0
  34. package/demo/z.xml +60 -0
  35. package/http-request.js +28 -37
  36. package/index.html +23 -19
  37. package/input-text.js +17 -0
  38. package/local-storage.js +28 -35
  39. package/location-element.js +15 -16
  40. package/package.json +1 -1
  41. package/0/a.html +0 -19
  42. package/0/a.xml +0 -10
  43. package/0/a.xsl +0 -66
  44. package/0/a1.xsl +0 -38
  45. package/0/ab.xsl +0 -23
  46. package/0/az.xml +0 -30
  47. package/0/b.html +0 -90
package/local-storage.js CHANGED
@@ -1,5 +1,4 @@
1
- const attr = (el, attr)=> el.getAttribute(attr)
2
- , string2value = (type, v) =>
1
+ const string2value = (type, v) =>
3
2
  { if( type === 'text')
4
3
  return v;
5
4
  if( type === 'json')
@@ -24,42 +23,36 @@ function ensureTrackLocalStorage()
24
23
 
25
24
  export class LocalStorageElement extends HTMLElement
26
25
  {
27
- // @attribute live - monitors localStorage change
28
- // @attribute type - `text|json`, defaults to text, other types are compatible with INPUT field
29
- constructor()
26
+ static get observedAttributes() {
27
+ return [ 'value' // populated from localStorage, if defined initially, sets the valiue in storage
28
+ , 'slice'
29
+ , 'key'
30
+ , 'type' // `text|json`, defaults to text, other types are compatible with INPUT field
31
+ , 'live' // monitors localStorage change
32
+ ];
33
+ }
34
+
35
+ async connectedCallback()
30
36
  {
31
- super();
32
- const state = {}
33
- , type = attr(this, 'type') || 'text'
34
- , listener = e=> e.detail.key === attr( this,'key' ) && propagateSlice()
35
- , propagateSlice = ()=>
36
- { for( let parent = this.parentElement; parent; parent = parent.parentElement)
37
- if( parent.onSlice )
38
- return parent.onSlice(
39
- { detail: string2value( type, localStorage.getItem( attr( this, 'key' ) ) )
40
- , target: this
41
- } );
42
- console.error(`${this.localName} used outside of custom-element`)
43
- debugger;
44
- };
45
- this.sliceInit = s =>
46
- { if( !state.listener && this.hasAttribute('live') )
47
- { state.listener = 1;
48
- window.addEventListener( 'local-storage', listener );
49
- ensureTrackLocalStorage();
50
- }
51
- propagateSlice();
52
- return s || {}
37
+ const attr = attr => this.getAttribute(attr)
38
+ , fromStorage = ()=>
39
+ { this.value = string2value( attr('type'), localStorage.getItem( attr( 'key' ) ) );
40
+ this.dispatchEvent( new Event('change') )
41
+ }
42
+ // todo apply type
43
+ if( this.hasAttribute('value'))
44
+ localStorage.setItem( attr( this, 'key' ) )
45
+ else
46
+ fromStorage()
47
+
48
+ if( this.hasAttribute('live') )
49
+ { const listener = (e => e.detail.key === attr( 'key' ) && fromStorage());
50
+ window.addEventListener( 'local-storage', listener );
51
+ ensureTrackLocalStorage();
52
+ this._destroy = ()=> window.removeEventListener('local-storage', listener );
53
53
  }
54
- this._destroy = ()=>
55
- {
56
- if( !state.listener )
57
- return;
58
- state.listener && window.removeEventListener('local-storage', listener );
59
- delete state.listener;
60
- };
61
54
  }
62
- disconnectedCallback(){ this._destroy(); }
55
+ disconnectedCallback(){ this._destroy?.(); }
63
56
  }
64
57
 
65
58
  window.customElements.define( 'local-storage', LocalStorageElement );
@@ -2,15 +2,20 @@ const attr = (el, attr)=> el.getAttribute(attr);
2
2
 
3
3
  export class LocationElement extends HTMLElement
4
4
  {
5
- // @attribute live - monitors localStorage change
6
- // @attribute src - URL to be parsed, defaults to `window.location`
5
+ static get observedAttributes()
6
+ { return [ 'value' // populated from localStorage, if defined initially, sets the valiue in storage
7
+ , 'slice'
8
+ , 'live' // monitors location change
9
+ , 'src' // URL to be parsed, defaults to `window.location`
10
+ ];
11
+ }
7
12
 
8
13
  constructor()
9
14
  {
10
15
  super();
11
16
  const state = {}
12
17
  , listener = e=> propagateSlice(e)
13
- , propagateSlice = (e)=>
18
+ , propagateSlice = ()=>
14
19
  { const urlStr = attr(this,'src')
15
20
  const url = urlStr? new URL(urlStr) : window.location
16
21
 
@@ -24,21 +29,14 @@ export class LocationElement extends HTMLElement
24
29
  { if ('string' === typeof url[k])
25
30
  detail[k] = url[k]
26
31
  }
27
- for( let parent = this.parentElement; parent; parent = parent.parentElement)
28
- { if (parent.onSlice)
29
- return parent.onSlice(
30
- { detail
31
- , target: this
32
- });
33
- }
34
- console.error(`${this.localName} used outside of custom-element`)
35
- debugger;
32
+ this.value = detail;
33
+ this.dispatchEvent( new Event('change') );
36
34
  };
37
35
  this.sliceInit = s =>
38
36
  {
39
37
  if( !state.listener && this.hasAttribute('live') )
40
38
  { state.listener = 1;
41
- window.addEventListener( 'popstate', listener );
39
+ window.addEventListener( 'popstate' , listener );
42
40
  window.addEventListener( 'hashchange', listener );
43
41
  }
44
42
  propagateSlice();
@@ -49,14 +47,15 @@ export class LocationElement extends HTMLElement
49
47
  if( !state.listener )
50
48
  return;
51
49
  if(state.listener)
52
- { window.removeEventListener('popstate', listener);
50
+ { window.removeEventListener('popstate' , listener);
53
51
  window.removeEventListener('hashchange', listener);
54
52
  }
55
53
  delete state.listener;
56
54
  };
57
- this.sliceInit()
55
+
58
56
  }
59
- disconnectedCallback(){ this._destroy(); }
57
+ connectedCallback(){ this.sliceInit() }
58
+ disconnectedCallback(){ this._destroy() }
60
59
  }
61
60
 
62
61
  window.customElements.define( 'location-element', LocationElement );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epa-wg/custom-element",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
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/0/a.html DELETED
@@ -1,19 +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
- <link rel="icon" href="demo/wc-square.svg" />
7
- <script type="module" src="../custom-element.js"></script>
8
- <style>
9
- @import "demo/demo.css";
10
- </style>
11
- </head>
12
- <body>
13
-
14
- <custom-element src="../demo/embed-1.html" hidden>
15
- loading from embed-1.html ...
16
- </custom-element>
17
-
18
- </body>
19
- </html>
package/0/a.xml DELETED
@@ -1,10 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <?xml-stylesheet type="text/xsl" href="a.xsl"?>
3
- <datadom xmlns="urn:schemas-epa-wg:dce">
4
- <payload/>
5
- <attributes>
6
- <a></a>
7
- </attributes>
8
- <dataset/>
9
- <slice/>
10
- </datadom>
package/0/a.xsl DELETED
@@ -1,66 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
2
- <xsl:output method="html"/>
3
-
4
- <xsl:template match="/">
5
- selecting <xsl:value-of select="count(//attributes)"/> attrs
6
- <xsl:for-each select="//attributes">
7
- <xsl:call-template name="attributes"/>
8
- </xsl:for-each>
9
- </xsl:template>
10
- <xsl:template name="slot">
11
- <xsl:param name="slotname"/>
12
- <xsl:param name="defaultvalue"/>
13
- <xsl:choose>
14
- <xsl:when test="//payload/*[@slot=$slotname]">
15
- <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
16
- </xsl:when>
17
- <xsl:otherwise>
18
- <xsl:copy-of select="$defaultvalue"/>
19
- </xsl:otherwise>
20
- </xsl:choose>
21
- </xsl:template>
22
- <xsl:template name="attributes">
23
-
24
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.0">
25
- <defs>
26
- <linearGradient id="d">
27
- <stop offset="0"/>
28
- <stop offset=".5"/>
29
- <stop offset=".80000001" stop-opacity=".46666667"/>
30
- <stop offset="1" stop-opacity="0"/>
31
- </linearGradient>
32
- <linearGradient id="a">
33
- <stop offset="0" stop-color="#fb0"/>
34
- <stop offset=".5" stop-color="#e29d00"/>
35
- <stop offset="1" stop-color="#fb0"/>
36
- </linearGradient>
37
- <linearGradient id="c">
38
- <stop offset="0"/>
39
- <stop offset="1" stop-opacity="0"/>
40
- </linearGradient>
41
- <linearGradient id="b">
42
- <stop offset="0" stop-color="#ffc"/>
43
- <stop offset=".5" stop-color="#fff965"/>
44
- <stop offset="1" stop-color="#fc3"/>
45
- </linearGradient>
46
- <linearGradient xlink:href="#a" id="i" x1="8.0350637" x2="42.788235" y1="32.372219" y2="32.372219" gradientUnits="userSpaceOnUse" spreadMethod="pad"/>
47
- <radialGradient xlink:href="#b" id="f" cx="17.986637" cy="16.545853" r="23.978155" fx="17.986637" fy="16.545853" gradientUnits="userSpaceOnUse"/>
48
- <radialGradient xlink:href="#c" id="e" cx="53.309223" cy="94.956306" r="63.252911" fx="53.309223" fy="94.956306" gradientTransform="matrix(1 0 0 .34935 0 61.7838)" gradientUnits="userSpaceOnUse"/>
49
- <radialGradient xlink:href="#d" id="g" cx="18.71347" cy="21.759708" r="1.8644418" fx="18.71347" fy="21.759708" gradientTransform="matrix(1 0 0 1.77778 0 -16.92422)" gradientUnits="userSpaceOnUse"/>
50
- </defs>
51
- <path fill="url(#e)" d="M116.56213 94.956306a63.252911 22.097088 0 1 1-126.5058174 0 63.252911 22.097088 0 1 1 126.5058174 0z" opacity=".53200001" transform="matrix(.3162 0 0 .33941 6.936944 8.132618)"/>
52
- <path fill="url(#f)" stroke="#fb0" stroke-width="1.43869453" d="M47.094418 23.83131a23.478155 23.478155 0 1 1-46.9563107 0 23.478155 23.478155 0 1 1 46.9563107 0z" transform="translate(4.30185 4.122792) scale(.83409)"/>
53
- <path id="h" fill="#fff" fill-opacity="1" fill-rule="nonzero" stroke="#fc0" stroke-dasharray="none" stroke-dashoffset="0" stroke-linejoin="miter" stroke-miterlimit="4" stroke-opacity="1" stroke-width="1" d="M21.682767 18.5142a3.9360437 6.9743929 0 1 1-7.872088 0 3.9360437 6.9743929 0 1 1 7.872088 0z" opacity="1" transform="matrix(1.01507 0 0 1.00354 -.0090285 .916405)"/>
54
- <path id="j" fill="url(#g)" fill-opacity="1" fill-rule="nonzero" stroke="none" stroke-dasharray="none" stroke-dashoffset="0" stroke-linejoin="miter" stroke-miterlimit="4" stroke-opacity="1" stroke-width="1" d="M20.577912 21.759708a1.8644418 3.314563 0 1 1-3.728883 0 1.8644418 3.314563 0 1 1 3.728883 0z" opacity="1" transform="translate(-.138107 .535104)"/>
55
- <use xlink:href="#h" width="48" height="48" transform="translate(12.50001 -4.4e-7)"/>
56
- <path fill="none" stroke="url(#i)" stroke-linecap="round" stroke-width="1.97319973" d="M9.0216636 35.899178c4.7689724-7.457767 10.9544424-9.489956 17.3095664-3.728884 5.404329 4.899155 11.190398 4.350365 15.470406-.656007"/>
57
- <path fill="none" stroke="#e2ac00" stroke-linecap="round" stroke-width="1.17813516" d="M15.504748 34.21319c3.012147-3.243177 6.693658.87012 6.693658.87012" opacity=".8"/>
58
- <use xlink:href="#j" width="48" height="48" transform="translate(10.78418 -5)"/>
59
- </svg></xsl:template>
60
- <xsl:variable name="slottemplate">
61
- <xsl:call-template name="slot">
62
- <xsl:with-param name="slotname" select="''"/>
63
- <xsl:with-param name="defaultvalue"/>
64
- </xsl:call-template>
65
- </xsl:variable>
66
- </xsl:stylesheet>
package/0/a1.xsl DELETED
@@ -1,38 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dce="urn:schemas-epa-wg:dce" version="1.0">
2
- <xsl:output method="html"/>
3
-
4
- <xsl:template match="/">
5
- <xsl:apply-templates select="//dce:attributes"/>
6
- </xsl:template>
7
- <xsl:template name="slot">
8
- <xsl:param name="slotname"/>
9
- <xsl:param name="defaultvalue"/>
10
- <xsl:choose>
11
- <xsl:when test="//dce:payload/*[@slot=$slotname]">
12
- <xsl:copy-of select="//dce:payload/*[@slot=$slotname]"/>
13
- </xsl:when>
14
- <xsl:otherwise>
15
- <xsl:copy-of select="$defaultvalue"/>
16
- </xsl:otherwise>
17
- </xsl:choose>
18
- </xsl:template>
19
- <xsl:template match="dce:attributes">
20
- slot1
21
- <xsl:call-template name="slot">
22
- <xsl:with-param name="slotname" select="'slot1'"/>
23
- <xsl:with-param name="defaultvalue"> 😃</xsl:with-param>
24
- </xsl:call-template>
25
- <hr/> slot2:
26
- <xsl:call-template name="slot">
27
- <xsl:with-param name="slotname" select="'slot2'"/>
28
- <xsl:with-param name="defaultvalue"> 😃</xsl:with-param>
29
- </xsl:call-template>
30
- <input xmlns="http://www.w3.org/1999/xhtml" placeholder="🐇❤️{//*[@slot='slot2']}" />
31
- </xsl:template>
32
- <xsl:variable name="slottemplate">
33
- <xsl:call-template name="slot">
34
- <xsl:with-param name="slotname" select="''"/>
35
- <xsl:with-param name="defaultvalue"/>
36
- </xsl:call-template>
37
- </xsl:variable>
38
- </xsl:stylesheet>
package/0/ab.xsl DELETED
@@ -1,23 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
- <xsl:output method="html"/>
4
-
5
- <xsl:template match="/">
6
- <xsl:apply-templates select="//attributes"/>
7
- </xsl:template>
8
- <xsl:variable name="body">
9
- <slot> Hello </slot> World!
10
- </xsl:variable>
11
- <xsl:template match="attributes">
12
- <h1>attributes</h1>
13
- <xsl:apply-templates mode="slots" select="."/>
14
- <xsl:value-of select="//*[@slot=&quot;&quot;] "/> World!
15
- </xsl:template>
16
- <xsl:template mode="slots" match="slot">
17
- <xsl:copy />
18
- </xsl:template>
19
- <xsl:template mode="slots" match="*">
20
- <xsl:copy />
21
- </xsl:template>
22
-
23
- </xsl:stylesheet>
package/0/az.xml DELETED
@@ -1,30 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
2
- <xsl:output method="html"/>
3
-
4
- <xsl:template match="/">
5
- <xsl:for-each select="//attributes">
6
- <xsl:call-template name="attributes"/>
7
- </xsl:for-each>
8
- </xsl:template>
9
- <xsl:template name="slot">
10
- <xsl:param name="slotname"/>
11
- <xsl:param name="defaultvalue"/>
12
- <xsl:choose>
13
- <xsl:when test="//payload/*[@slot=$slotname]">
14
- <xsl:copy-of select="//payload/*[@slot=$slotname]"/>
15
- </xsl:when>
16
- <xsl:otherwise>
17
- <xsl:copy-of select="$defaultvalue"/>
18
- </xsl:otherwise>
19
- </xsl:choose>
20
- </xsl:template>
21
- <xsl:template name="attributes"><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><h4>embed-1.html</h4>
22
- <custom-element tag="dce-embed-1">🖖</custom-element>
23
- <dce-embed-1>?</dce-embed-1></body></html></xsl:template>
24
- <xsl:variable name="slottemplate">
25
- <xsl:call-template name="slot">
26
- <xsl:with-param name="slotname" select="''"/>
27
- <xsl:with-param name="defaultvalue"/>
28
- </xsl:call-template>
29
- </xsl:variable>
30
- </xsl:stylesheet>
package/0/b.html DELETED
@@ -1,90 +0,0 @@
1
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
2
- <xsl:output method="html"/>
3
-
4
- <xsl:template match="/">
5
- <xsl:apply-templates select="//attributes"/>
6
- </xsl:template>
7
- <xsl:template match="attributes">
8
- <h3 xmlns="http://www.w3.org/1999/xhtml">
9
- <xsl:value-of select="title"/>
10
- </h3> <!-- title is an attribute in instance
11
- mapped into /*/attributes/title -->
12
- <xsl:if xmlns="http://www.w3.org/1999/xhtml" test="//smile"> <!-- data-smile DCE instance attribute,
13
- mapped into /*/dataset/smile
14
- used in condition -->
15
- <!-- data-smile DCE instance attribute, used as HTML -->
16
- <div>Smile as:
17
- <xsl:value-of select="//smile"/>
18
- </div>
19
- </xsl:if>
20
- <!-- image would not be visible in sandbox, see live demo -->
21
- <img xmlns="http://www.w3.org/1999/xhtml"
22
- src="https://unpkg.com/pokeapi-sprites@2.0.2/sprites/pokemon/other/dream-world/{pokemon-id}.svg"
23
- alt="{title} image"/>
24
- <!-- image-src and title are DCE instance attributes,
25
- mapped into /*/attributes/
26
- used within output attribute via curly brackets -->
27
-
28
- <!-- `slot name=xxx` replaced with elements with `slot=xxx` attribute -->
29
- <p xmlns="http://www.w3.org/1999/xhtml">
30
- <xsl:value-of select="//*[@slot=&quot;description&quot;]"/>
31
- </p>
32
- <xsl:for-each xmlns="http://www.w3.org/1999/xhtml" select="//*[@pokemon-id]">
33
- <!-- loop over payload elements with `pokemon-id` attribute -->
34
- <button>
35
- <img height="32"
36
- src="https://unpkg.com/pokeapi-sprites@2.0.2/sprites/pokemon/other/dream-world/{@pokemon-id}.svg"
37
- alt="{text()}"/>
38
- <br/>
39
- <xsl:value-of select="text()">
40
- </xsl:value-of>
41
- </button>
42
-
43
- </xsl:for-each>
44
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
45
- <xsl:output method="html"/>
46
-
47
- <xsl:template match="/">
48
- <xsl:apply-templates select="//attributes"/>
49
- </xsl:template>
50
- <xsl:template match="attributes">
51
- <h3 xmlns="http://www.w3.org/1999/xhtml">
52
- <xsl:value-of select="title"/>
53
- </h3> <!-- title is an attribute in instance
54
- mapped into /*/attributes/title -->
55
- <xsl:if xmlns="http://www.w3.org/1999/xhtml" test="//smile"> <!-- data-smile DCE instance attribute,
56
- mapped into /*/dataset/smile
57
- used in condition -->
58
- <!-- data-smile DCE instance attribute, used as HTML -->
59
- <div>Smile as:
60
- <xsl:value-of select="//smile"/>
61
- </div>
62
- </xsl:if>
63
- <!-- image would not be visible in sandbox, see live demo -->
64
- <img xmlns="http://www.w3.org/1999/xhtml"
65
- src="https://unpkg.com/pokeapi-sprites@2.0.2/sprites/pokemon/other/dream-world/{pokemon-id}.svg"
66
- alt="{title} image"/>
67
- <!-- image-src and title are DCE instance attributes,
68
- mapped into /*/attributes/
69
- used within output attribute via curly brackets -->
70
-
71
- <!-- `slot name=xxx` replaced with elements with `slot=xxx` attribute -->
72
- <p xmlns="http://www.w3.org/1999/xhtml">
73
- <xsl:value-of select="//*[@slot=&quot;description&quot;]"/>
74
- </p>
75
- <xsl:for-each xmlns="http://www.w3.org/1999/xhtml" select="//*[@pokemon-id]">
76
- <!-- loop over payload elements with `pokemon-id` attribute -->
77
- <button>
78
- <img height="32"
79
- src="https://unpkg.com/pokeapi-sprites@2.0.2/sprites/pokemon/other/dream-world/{@pokemon-id}.svg"
80
- alt="{text()}"/>
81
- <br/>
82
- <xsl:value-of select="text()">
83
- </xsl:value-of>
84
- </button>
85
-
86
- </xsl:for-each>
87
- </xsl:template>
88
- </xsl:stylesheet>
89
- </xsl:template>
90
- </xsl:stylesheet>