@epa-wg/custom-element 0.0.10 → 0.0.12
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/.gitignore +6 -2
- package/.idea/inspectionProfiles/Project_Default.xml +41 -0
- package/.idea/misc.xml +4 -5
- package/.vs/VSWorkspaceState.json +8 -0
- package/.vs/custom-element/FileContentIndex/1487e471-3751-47bc-a499-d78eda924eda.vsidx +0 -0
- package/.vs/custom-element/v17/.wsuo +0 -0
- package/.vs/slnx.sqlite +0 -0
- package/README.md +53 -19
- package/custom-element.js +335 -76
- package/demo/a.html +38 -0
- package/demo/confused.svg +37 -0
- package/demo/demo.css +3 -1
- package/demo/dom-merge.html +121 -0
- package/demo/embed-1.html +3 -0
- package/demo/external-template.html +178 -0
- package/demo/html-template.html +126 -0
- package/demo/html-template.xhtml +45 -0
- package/demo/html-template.xml +45 -0
- package/demo/http-request.html +45 -58
- package/demo/local-storage.html +24 -19
- package/demo/location-element.html +60 -59
- package/demo/s.xml +1 -0
- package/demo/s.xslt +159 -0
- package/demo/table.xml +25 -0
- package/demo/table.xsl +293 -0
- package/demo/template.xsl +46 -0
- package/demo/tree.xml +25 -0
- package/demo/tree.xsl +33 -0
- package/demo/wc-square.svg +1 -1
- package/demo/xhtml-template.xhtml +45 -0
- package/demo/z.html +42 -0
- package/demo/z.xml +60 -0
- package/http-request.js +28 -35
- package/index.html +41 -33
- package/input-text.js +17 -0
- package/local-storage.js +28 -35
- package/location-element.js +15 -16
- package/package.json +1 -1
package/.gitignore
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
|
|
5
|
+
<option name="myValues">
|
|
6
|
+
<value>
|
|
7
|
+
<list size="1">
|
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="slice" />
|
|
9
|
+
</list>
|
|
10
|
+
</value>
|
|
11
|
+
</option>
|
|
12
|
+
<option name="myCustomValuesEnabled" value="true" />
|
|
13
|
+
</inspection_tool>
|
|
14
|
+
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
|
|
15
|
+
<option name="myValues">
|
|
16
|
+
<value>
|
|
17
|
+
<list size="17">
|
|
18
|
+
<item index="0" class="java.lang.String" itemvalue="nobr" />
|
|
19
|
+
<item index="1" class="java.lang.String" itemvalue="noembed" />
|
|
20
|
+
<item index="2" class="java.lang.String" itemvalue="comment" />
|
|
21
|
+
<item index="3" class="java.lang.String" itemvalue="noscript" />
|
|
22
|
+
<item index="4" class="java.lang.String" itemvalue="embed" />
|
|
23
|
+
<item index="5" class="java.lang.String" itemvalue="script" />
|
|
24
|
+
<item index="6" class="java.lang.String" itemvalue="html-demo-element" />
|
|
25
|
+
<item index="7" class="java.lang.String" itemvalue="custom-element" />
|
|
26
|
+
<item index="8" class="java.lang.String" itemvalue="local-storage" />
|
|
27
|
+
<item index="9" class="java.lang.String" itemvalue="dce-1" />
|
|
28
|
+
<item index="10" class="java.lang.String" itemvalue="xhtml:table" />
|
|
29
|
+
<item index="11" class="java.lang.String" itemvalue="xhtml:tbody" />
|
|
30
|
+
<item index="12" class="java.lang.String" itemvalue="xhtml:tr" />
|
|
31
|
+
<item index="13" class="java.lang.String" itemvalue="xhtml:th" />
|
|
32
|
+
<item index="14" class="java.lang.String" itemvalue="xhtml:td" />
|
|
33
|
+
<item index="15" class="java.lang.String" itemvalue="xhtml:tfoot" />
|
|
34
|
+
<item index="16" class="java.lang.String" itemvalue="dce-2" />
|
|
35
|
+
</list>
|
|
36
|
+
</value>
|
|
37
|
+
</option>
|
|
38
|
+
<option name="myCustomValuesEnabled" value="true" />
|
|
39
|
+
</inspection_tool>
|
|
40
|
+
</profile>
|
|
41
|
+
</component>
|
package/.idea/misc.xml
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
</component>
|
|
1
|
+
<project version="4">
|
|
2
|
+
<component name="ProjectRootManager">
|
|
3
|
+
<output url="file://$PROJECT_DIR$/out" />
|
|
4
|
+
</component>
|
|
6
5
|
</project>
|
|
Binary file
|
|
Binary file
|
package/.vs/slnx.sqlite
ADDED
|
Binary file
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# custom-element
|
|
2
2
|
`Declarative Custom Element` is a part of pure `Declarative Web Application` stack. A proof of concept as a part of
|
|
3
|
-
[WCCG in Declarative custom elements](https://github.com/w3c/webcomponents-cg/issues/32#issuecomment-1321037301)
|
|
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
4
|
discussion. 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
|
|
@@ -32,13 +32,13 @@ yarn add @epa-wg/custom-element
|
|
|
32
32
|
## [Live demo 🔗][demo-url]
|
|
33
33
|
```html
|
|
34
34
|
<custom-element tag="pokemon-tile" hidden>
|
|
35
|
-
<h3
|
|
35
|
+
<h3>{title}</h3> <!-- title is an attribute in instance
|
|
36
36
|
mapped into /*/attributes/title -->
|
|
37
37
|
<xsl:if test="//smile"> <!-- data-smile DCE instance attribute,
|
|
38
38
|
mapped into /*/dataset/smile
|
|
39
39
|
used in condition -->
|
|
40
40
|
<!-- data-smile DCE instance attribute, used as HTML -->
|
|
41
|
-
<div>Smile as:
|
|
41
|
+
<div>Smile as: {//smile} </div>
|
|
42
42
|
</xsl:if>
|
|
43
43
|
<!-- image would not be visible in sandbox, see live demo -->
|
|
44
44
|
<img src="https://unpkg.com/pokeapi-sprites@2.0.2/sprites/pokemon/other/dream-world/{pokemon-id}.svg"
|
|
@@ -88,6 +88,10 @@ generates HTML
|
|
|
88
88
|
NOTE: attempt to register custom element with already registered tag name would fail due to w3c standard limitations.
|
|
89
89
|
The scoped custom element registry is still a proposal.
|
|
90
90
|
|
|
91
|
+
### omitting `tag` leads to template instantiation
|
|
92
|
+
Whether template is inline or given by `src` attribute, the `custom-element` would be instantiated inline if no `tag`
|
|
93
|
+
attribute is given.
|
|
94
|
+
|
|
91
95
|
### custom element instance
|
|
92
96
|
constructor creates XML with
|
|
93
97
|
* root matching the tag
|
|
@@ -98,6 +102,29 @@ constructor creates XML with
|
|
|
98
102
|
|
|
99
103
|
DOM content is replaced with results of instance XML transformation by declaration XSLT.
|
|
100
104
|
|
|
105
|
+
# `src` attribute
|
|
106
|
+
allows to refer either external template or template within external library by `#id` hash in URL.
|
|
107
|
+
|
|
108
|
+
See [demo](demo/external-template.html) with various samples.
|
|
109
|
+
|
|
110
|
+
## types of template
|
|
111
|
+
* HTML with DCE syntax ( slots, data slices, xslt operators, etc. )
|
|
112
|
+
* SVG image, MathML, etc.
|
|
113
|
+
* XSLT template. The `datadom` is the XML payload for transformation. In order to be embedded into external document,
|
|
114
|
+
this document has to have XML syntax like XHTML. Attempt of including XSLT within HTML file would break the template
|
|
115
|
+
integrity by parser.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## `#id` Local reference
|
|
119
|
+
allows to refer the template withing same document
|
|
120
|
+
|
|
121
|
+
## `url`
|
|
122
|
+
allows to use the external document as template
|
|
123
|
+
|
|
124
|
+
## `url#id`
|
|
125
|
+
allows to refer the template withing external document
|
|
126
|
+
|
|
127
|
+
|
|
101
128
|
# template syntax
|
|
102
129
|
## Attributes
|
|
103
130
|
curly braces `{}` in attributes implemented as [attribute value template](https://www.w3.org/TR/xslt20/#attribute-value-templates)
|
|
@@ -138,21 +165,28 @@ template engine.
|
|
|
138
165
|
|
|
139
166
|
# troubleshooting
|
|
140
167
|
## HTML parser is not compatible with templates
|
|
141
|
-
On many tags like `table`, or link `a` the attempt to use XSLT operations could lead to DOM order
|
|
142
|
-
in template. In such cases the `
|
|
168
|
+
On many tags like `table`, or link `a` the attempt to use XSLT operations could lead to DOM order mismatch to given
|
|
169
|
+
in template. In such cases the `xhtml:` prefix in front of troubled tag would solve the parsing.
|
|
143
170
|
|
|
144
171
|
```html
|
|
145
172
|
<custom-element tag="dce-2" hidden>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
</
|
|
154
|
-
|
|
155
|
-
|
|
173
|
+
<local-storage key="basket" slice="basket" live type="json"></local-storage>
|
|
174
|
+
<xhtml:table xmlns:xhtml="http://www.w3.org/1999/xhtml" >
|
|
175
|
+
<xhtml:tbody>
|
|
176
|
+
<xsl:for-each select="//basket/@*">
|
|
177
|
+
<xhtml:tr>
|
|
178
|
+
<xhtml:th> {name()} </xhtml:th>
|
|
179
|
+
<xhtml:td> {.} </xhtml:td>
|
|
180
|
+
</xhtml:tr>
|
|
181
|
+
</xsl:for-each>
|
|
182
|
+
</xhtml:tbody>
|
|
183
|
+
<xhtml:tfoot>
|
|
184
|
+
<xhtml:tr>
|
|
185
|
+
<xhtml:td><slot>🤔</slot></xhtml:td>
|
|
186
|
+
<xhtml:th> {sum(//slice/basket/@*)} </xhtml:th>
|
|
187
|
+
</xhtml:tr>
|
|
188
|
+
</xhtml:tfoot>
|
|
189
|
+
</xhtml:table>
|
|
156
190
|
</custom-element>
|
|
157
191
|
```
|
|
158
192
|
See [demo source](demo/local-storage.html) for detailed sample.
|
|
@@ -179,7 +213,7 @@ run transformation under debugger.
|
|
|
179
213
|
* try to add as attribute you could observe and put the value of node name or text to identify the current location in data
|
|
180
214
|
within template
|
|
181
215
|
```xml
|
|
182
|
-
<b title="{name(*)} : {text()}">xml tag name
|
|
216
|
+
<b title="{name(*)} : {text()}">xml tag name: <xsl:value-of select='name()'/></b>
|
|
183
217
|
```
|
|
184
218
|
|
|
185
219
|
[git-url]: https://github.com/EPA-WG/custom-element
|
|
@@ -191,9 +225,9 @@ within template
|
|
|
191
225
|
[github-image]: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg
|
|
192
226
|
[npm-image]: https://img.shields.io/npm/v/@epa-wg/custom-element.svg
|
|
193
227
|
[npm-url]: https://npmjs.org/package/@epa-wg/custom-element
|
|
194
|
-
[coverage-image]: https://unpkg.com/@epa-wg/custom-element-test@0.0.
|
|
195
|
-
[coverage-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.
|
|
196
|
-
[storybook-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.
|
|
228
|
+
[coverage-image]: https://unpkg.com/@epa-wg/custom-element-test@0.0.12/coverage/coverage.svg
|
|
229
|
+
[coverage-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.12/coverage/lcov-report/index.html
|
|
230
|
+
[storybook-url]: https://unpkg.com/@epa-wg/custom-element-test@0.0.12/storybook-static/index.html?path=/story/welcome--introduction
|
|
197
231
|
[sandbox-url]: https://stackblitz.com/github/EPA-WG/custom-element?file=index.html
|
|
198
232
|
[webcomponents-url]: https://www.webcomponents.org/element/@epa-wg/custom-element
|
|
199
233
|
[webcomponents-img]: https://img.shields.io/badge/webcomponents.org-published-blue.svg
|