@epa-wg/custom-element 0.0.15 → 0.0.17
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 +14 -5
- package/custom-element.d.ts +31 -0
- package/custom-element.js +7 -3
- package/demo/a.html +2 -13
- package/demo/parameters.html +1 -1
- package/demo/z.html +5 -14
- package/package.json +5 -4
- package/web-types.json +70 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# custom-element
|
|
2
2
|
`Declarative Custom Element` (DCE) is a part of pure `Declarative Web Application` stack. A proof of concept as a part of
|
|
3
3
|
[WCCG in Declarative custom elements](https://github.com/w3c/webcomponents-cg/issues/32#issuecomment-1321037301) and [Declarative Web Application](https://github.com/EPA-WG/dwa#readme)
|
|
4
|
-
discussion. The functionality of DCE and its data access does not require programming using JavaScript.
|
|
4
|
+
discussion. **NO-JS** The functionality of DCE and its data access does not require programming using JavaScript.
|
|
5
5
|
|
|
6
6
|
It allows to define custom HTML tag with template filled from slots, attributes and data `slice` as of now from
|
|
7
7
|
[local-storage][local-storage-demo], [http-request][http-request-demo], [location][location-demo].
|
|
@@ -133,10 +133,19 @@ constructor creates XML with
|
|
|
133
133
|
|
|
134
134
|
DOM content is replaced with results of instance XML transformation by declaration XSLT.
|
|
135
135
|
|
|
136
|
+
# `tag` attribute
|
|
137
|
+
allows to define the Custom Element tag registered by `window.customElements.define()`.
|
|
138
|
+
|
|
139
|
+
If omitted, the tag is auto-generated and the content is rendered inline.
|
|
140
|
+
```html
|
|
141
|
+
<custom-element> my tag is {tag} </custom-element>
|
|
142
|
+
```
|
|
143
|
+
See [demo](https://unpkg.com/@epa-wg/custom-element@0.0/demo/external-template.html) for `tag` attribute use.
|
|
144
|
+
|
|
136
145
|
# `src` attribute
|
|
137
146
|
allows to refer either external template or template within external library by `#id` hash in URL.
|
|
138
147
|
|
|
139
|
-
See [demo](demo/external-template.html) with various samples.
|
|
148
|
+
See [demo](https://unpkg.com/@epa-wg/custom-element@0.0/demo/external-template.html) with various samples.
|
|
140
149
|
|
|
141
150
|
## types of template
|
|
142
151
|
* HTML with DCE syntax ( slots, data slices, xslt operators, etc. )
|
|
@@ -308,9 +317,9 @@ within template
|
|
|
308
317
|
[github-image]: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg
|
|
309
318
|
[npm-image]: https://img.shields.io/npm/v/@epa-wg/custom-element.svg
|
|
310
319
|
[npm-url]: https://npmjs.org/package/@epa-wg/custom-element
|
|
311
|
-
[coverage-image]: https://unpkg.com/@epa-wg/custom-element-test@0.0.
|
|
312
|
-
[coverage-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.
|
|
313
|
-
[storybook-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.
|
|
320
|
+
[coverage-image]: https://unpkg.com/@epa-wg/custom-element-test@0.0.17/coverage/coverage.svg
|
|
321
|
+
[coverage-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.17/coverage/lcov-report/index.html
|
|
322
|
+
[storybook-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.17/storybook-static/index.html?path=/story/welcome--introduction
|
|
314
323
|
[sandbox-url]: https://stackblitz.com/github/EPA-WG/custom-element?file=index.html
|
|
315
324
|
[webcomponents-url]: https://www.webcomponents.org/element/@epa-wg/custom-element
|
|
316
325
|
[webcomponents-img]: https://img.shields.io/badge/webcomponents.org-published-blue.svg
|
package/custom-element.d.ts
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
export function log(x: any): void;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @summary Declarative Custom Element as W3C proposal PoC with native(XSLT) based templating
|
|
5
|
+
* ```html
|
|
6
|
+
* <custom-element tag="my-element">
|
|
7
|
+
* <template>
|
|
8
|
+
* <xsl:param name="p1" >default_P1</xsl:param>
|
|
9
|
+
* <style>
|
|
10
|
+
* color:green;
|
|
11
|
+
* b{ color: blue;}
|
|
12
|
+
* input:checked+b{ color: darkblue; text-shadow: 0 0 4px springgreen;}
|
|
13
|
+
* </style>
|
|
14
|
+
* <label>
|
|
15
|
+
* green
|
|
16
|
+
* <input type="checkbox" value="Glowing Blue" checked/><b>blue</b>
|
|
17
|
+
* </label>
|
|
18
|
+
* p1:{$p1}
|
|
19
|
+
* </template>
|
|
20
|
+
* </custom-element>
|
|
21
|
+
* <my-element p1="abc"></my-element>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @extends HTMLElement
|
|
25
|
+
* @tag custom-element
|
|
26
|
+
* @tag-name custom-element
|
|
27
|
+
* @attr {boolean} hidden - hides DCE definition to prevent visual appearance of content. Wrap the payload into template tag to prevent applying the inline CSS in global scope.
|
|
28
|
+
* @attr {string} tag - HTML tag for Custom Element. Used for window.customElements.define(). If not set, would be generated and DCE instance rendered inline.
|
|
29
|
+
* @attr {string} src - full, relative, or hash URL to DCE template.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
2
32
|
export class CustomElement extends HTMLElement {
|
|
33
|
+
static observedAttributes : string[];
|
|
3
34
|
}
|
|
4
35
|
export default CustomElement;
|
package/custom-element.js
CHANGED
|
@@ -386,6 +386,7 @@ export function assureUID(n,attr)
|
|
|
386
386
|
export class
|
|
387
387
|
CustomElement extends HTMLElement
|
|
388
388
|
{
|
|
389
|
+
static observedAttributes = ['src','tag','hidden'];
|
|
389
390
|
async connectedCallback()
|
|
390
391
|
{
|
|
391
392
|
const templateRoots = await loadTemplateRoots( attr( this, 'src' ), this )
|
|
@@ -409,8 +410,10 @@ CustomElement extends HTMLElement
|
|
|
409
410
|
class DceElement extends HTMLElement
|
|
410
411
|
{
|
|
411
412
|
static get observedAttributes()
|
|
412
|
-
{
|
|
413
|
-
|
|
413
|
+
{ return templateDocs.reduce( (ret,t) =>
|
|
414
|
+
{ if( t.params ) ret.push( ...t.params.map(e=>attr(e,'name')) );
|
|
415
|
+
return ret;
|
|
416
|
+
}, [] );
|
|
414
417
|
}
|
|
415
418
|
connectedCallback()
|
|
416
419
|
{ if( this.firstElementChild?.tagName === 'TEMPLATE' )
|
|
@@ -519,10 +522,11 @@ CustomElement extends HTMLElement
|
|
|
519
522
|
window.customElements.define( tag, DceElement);
|
|
520
523
|
else
|
|
521
524
|
{ const t = tagName;
|
|
525
|
+
this.setAttribute('tag', t );
|
|
522
526
|
window.customElements.define( t, DceElement);
|
|
523
527
|
const el = document.createElement(t);
|
|
524
528
|
this.getAttributeNames().forEach(a=>el.setAttribute(a,this.getAttribute(a)));
|
|
525
|
-
el.append(...[...this.childNodes].filter(e=>e.localName!=='style'))
|
|
529
|
+
el.append(...[...this.childNodes].filter( e => e.localName!=='style') );
|
|
526
530
|
this.append(el);
|
|
527
531
|
}
|
|
528
532
|
}
|
package/demo/a.html
CHANGED
|
@@ -20,19 +20,8 @@
|
|
|
20
20
|
</style>
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
<local-storage key="basket" slice="basket"></local-storage>
|
|
26
|
-
<html:table>
|
|
27
|
-
<xsl:for-each select="//slice/basket/@*">
|
|
28
|
-
<html:tr>
|
|
29
|
-
<html:th> {name()} </html:th>
|
|
30
|
-
<html:td> {.} </html:td>
|
|
31
|
-
</html:tr>
|
|
32
|
-
</xsl:for-each>
|
|
33
|
-
</html:table>
|
|
34
|
-
count:<xsl:value-of select="count(//slice/basket/@*)"/>
|
|
35
|
-
</custom-element>
|
|
23
|
+
<custom-element> my tag is {tag} </custom-element>
|
|
24
|
+
<my-element></my-element>
|
|
36
25
|
|
|
37
26
|
</body>
|
|
38
27
|
</html>
|
package/demo/parameters.html
CHANGED
|
@@ -32,7 +32,7 @@ params needed to declare DCE attributes and track the attributes changes. It als
|
|
|
32
32
|
<xsl:param name="p3" select="//p3 ?? 'def_P3' " ></xsl:param>
|
|
33
33
|
p1:{$p1} <br/> p2: {$p2} <br/> p3: {$p3}
|
|
34
34
|
</custom-element>
|
|
35
|
-
<dce-link id="dce1"></dce-link>
|
|
35
|
+
<dce-link id="dce1" ></dce-link>
|
|
36
36
|
<section>
|
|
37
37
|
<dce-link id="dce2" p1="123" p2="override ignored as select is defined"></dce-link> <br/>
|
|
38
38
|
<div><input id="i1" value="p1" /> <button onclick="dce2.setAttribute('p1',i1.value)"> set p1</button> </div>
|
package/demo/z.html
CHANGED
|
@@ -39,21 +39,12 @@
|
|
|
39
39
|
</head>
|
|
40
40
|
<body>
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
<
|
|
44
|
-
<xsl:param name="p1" select="//p1 ?? 'def_p1' " ></xsl:param>
|
|
45
|
-
<xsl:param name="p2" select="'always_p2'" ></xsl:param>
|
|
46
|
-
<xsl:param name="p3" >default_P3</xsl:param>
|
|
47
|
-
p1:{$p1} <br/> p2: {$p2} <br/> p3: {$p3}
|
|
42
|
+
<custom-element src="html-template.xhtml#embedded-xsl">
|
|
43
|
+
<template>whole XSLT is embedded into HTML body</template>
|
|
48
44
|
</custom-element>
|
|
49
|
-
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
<div><input id="i2" value="p2" /> <button onclick="dce2.setAttribute('p2',i2.value)"> set p2</button> </div>
|
|
53
|
-
<div><input id="i3" value="p3" /> <button onclick="dce2.setAttribute('p3',i3.value)"> set p3</button> </div>
|
|
54
|
-
</section>
|
|
55
|
-
<dce-link id="dce2" p1="123" p2="override ignored as select is defined"></dce-link> |
|
|
56
|
-
<dce-link id="dce3" p1="123" p3="qwe"></dce-link> |
|
|
45
|
+
<!--<custom-element src="html-template.html#none">-->
|
|
46
|
+
<!-- <template><i>element with id=none is missing in template</i></template>-->
|
|
47
|
+
<!--</custom-element>-->
|
|
57
48
|
|
|
58
49
|
</body>
|
|
59
50
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epa-wg/custom-element",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
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",
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"*"
|
|
14
14
|
],
|
|
15
|
-
"type": "module",
|
|
16
|
-
"types": "./custom-element.d.ts",
|
|
17
15
|
"scripts": {
|
|
18
16
|
"dev:help": "echo \"needed for sandbox demo\"",
|
|
19
17
|
"dev": "bash bin/stackblitz.sh",
|
|
@@ -21,6 +19,8 @@
|
|
|
21
19
|
"test": "echo \"test would reside in https://github.com/EPA-WG/custom-element-test\" && exit 0",
|
|
22
20
|
"typings": "npx -p typescript tsc custom-element.js --declaration --allowJs --emitDeclarationOnly "
|
|
23
21
|
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"types": "./custom-element.d.ts",
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
26
26
|
"url": "git+https://github.com/EPA-WG/custom-element.git"
|
|
@@ -45,5 +45,6 @@
|
|
|
45
45
|
"funding": {
|
|
46
46
|
"type": "patreon",
|
|
47
47
|
"url": "https://www.patreon.com/sashafirsov"
|
|
48
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"web-types": "./web-types.json"
|
|
49
50
|
}
|
package/web-types.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/web-types",
|
|
3
|
+
"name": "@epa-wg/custom-element",
|
|
4
|
+
"version": "0.0.17",
|
|
5
|
+
"js-types-syntax": "typescript",
|
|
6
|
+
"description-markup": "markdown",
|
|
7
|
+
"contributions": {
|
|
8
|
+
"html": {
|
|
9
|
+
"elements": [
|
|
10
|
+
{
|
|
11
|
+
"name": "custom-element",
|
|
12
|
+
"description": "Declarative Custom Element as W3C proposal PoC with native(XSLT) based templating",
|
|
13
|
+
"doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#custom-element",
|
|
14
|
+
"attributes": [
|
|
15
|
+
{
|
|
16
|
+
"name": "hidden",
|
|
17
|
+
"description": "hides DCE definition to prevent visual appearance of content. Wrap the payload into template tag to prevent applying the inline CSS in global scope.",
|
|
18
|
+
"required": false,
|
|
19
|
+
"doc-url": "https://developer.mozilla.org/en-US/docs/web/html/global_attributes/hidden",
|
|
20
|
+
"value": {
|
|
21
|
+
"type": "boolean"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "tag",
|
|
26
|
+
"description": "HTML tag for Custom Element. Used for window.customElements.define(). If not set, would be generated and DCE instance rendered inline. ",
|
|
27
|
+
"default": "",
|
|
28
|
+
"required": false,
|
|
29
|
+
"doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#tag-attribute",
|
|
30
|
+
"value": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "src",
|
|
36
|
+
"description": "full, relative, or hash URL to DCE template.",
|
|
37
|
+
"default": "",
|
|
38
|
+
"required": false,
|
|
39
|
+
"doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#src-attribute",
|
|
40
|
+
"value": {
|
|
41
|
+
"type": "URL"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"slots": [],
|
|
46
|
+
"js": {
|
|
47
|
+
"events": [
|
|
48
|
+
{
|
|
49
|
+
"name": "value:changed",
|
|
50
|
+
"description": "Emitted when data changes. Can be used for state serialization in hydration flow"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"properties": [
|
|
54
|
+
{
|
|
55
|
+
"name": "value",
|
|
56
|
+
"type": "string",
|
|
57
|
+
"default": "",
|
|
58
|
+
"description": "DCE state. Can be used for state serialization in hydration flow. Format TBD, most likely encoded XML string"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"css": {
|
|
63
|
+
"properties": [
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|