@epa-wg/custom-element 0.0.22 → 0.0.24
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 +3 -3
- package/bin/xslDtd2Ide.mjs +1 -1
- package/custom-element.js +9 -1
- package/demo/form.html +92 -46
- package/demo/s.xml +9 -17
- package/ide/web-types-dce.json +1 -1
- package/ide/web-types-xsl.json +1 -1
- package/package.json +1 -1
- package/custom-element1-1.js +0 -763
- package/custom-element1.js +0 -763
package/README.md
CHANGED
|
@@ -348,9 +348,9 @@ within template
|
|
|
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.
|
|
352
|
-
[coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.
|
|
353
|
-
[storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.
|
|
351
|
+
[coverage-image]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.24/coverage/src/custom-element/coverage.svg
|
|
352
|
+
[coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.24/coverage/src/custom-element/index.html
|
|
353
|
+
[storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.24/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
|
package/bin/xslDtd2Ide.mjs
CHANGED
|
@@ -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.
|
|
119
|
+
"version": "0.0.24",
|
|
120
120
|
"js-types-syntax": "typescript",
|
|
121
121
|
"description-markup": "markdown",
|
|
122
122
|
"contributions": {
|
package/custom-element.js
CHANGED
|
@@ -434,6 +434,14 @@ export function assureUnique(n, id=0)
|
|
|
434
434
|
e.childNodes.length && assureUnique(e)
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
|
+
export function appendByDceId(parent,e,k)
|
|
438
|
+
{
|
|
439
|
+
k = 1*k;
|
|
440
|
+
for( let n of parent.childNodes )
|
|
441
|
+
if( (n.dceId ?? n.getAttribute('data-dce-id')*1) > k )
|
|
442
|
+
return parent.insertBefore(e,n);
|
|
443
|
+
parent.append(e)
|
|
444
|
+
}
|
|
437
445
|
export function merge( parent, fromArr )
|
|
438
446
|
{
|
|
439
447
|
if(!fromArr.length)
|
|
@@ -461,7 +469,7 @@ export function merge( parent, fromArr )
|
|
|
461
469
|
}
|
|
462
470
|
delete id2old[ k ]
|
|
463
471
|
}else
|
|
464
|
-
parent
|
|
472
|
+
appendByDceId(parent,e,k)
|
|
465
473
|
}
|
|
466
474
|
for( let v of Object.values(id2old) )
|
|
467
475
|
v.remove();
|
package/demo/form.html
CHANGED
|
@@ -9,9 +9,18 @@
|
|
|
9
9
|
<script type="module" src="../custom-element.js"></script>
|
|
10
10
|
<style>
|
|
11
11
|
@import "./demo.css";
|
|
12
|
-
|
|
13
|
-
label
|
|
14
|
-
|
|
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
|
+
}
|
|
15
24
|
</style>
|
|
16
25
|
<!-- https://github.com/mdn/learning-area/blob/main/html/forms/form-validation/custom-error-message.html
|
|
17
26
|
todo: apply setCustomValidity( warningStr )
|
|
@@ -22,36 +31,74 @@
|
|
|
22
31
|
|
|
23
32
|
<nav>
|
|
24
33
|
<a href="../index.html"><h3><code>custom-element</code> demo</h3></a>
|
|
25
|
-
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
|
|
34
|
+
|
|
35
|
+
<p> <b>formData</b><br/>
|
|
36
|
+
The values of named form fields are populated into the <b>slice</b> as <b>form-data</b> on <var>change</var>
|
|
37
|
+
or <var>submit</var> event. The field values can be used in form validation via <var>custom-validity</var>
|
|
38
|
+
attribute
|
|
39
|
+
and in condition to enabling the form parts
|
|
40
|
+
<a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData">formData MDN</a>
|
|
41
|
+
</p>
|
|
42
|
+
<details>
|
|
43
|
+
<summary>slice to form-data mapping</summary>
|
|
44
|
+
<html-demo-element>
|
|
45
|
+
<template>
|
|
46
|
+
<datadom hidden>
|
|
47
|
+
<slice>
|
|
48
|
+
<signin-form>
|
|
49
|
+
<form-data>
|
|
50
|
+
<username>QWE</username>
|
|
51
|
+
<password>ASD</password>
|
|
52
|
+
</form-data>
|
|
53
|
+
</signin-form>
|
|
54
|
+
</slice>
|
|
55
|
+
</datadom>
|
|
56
|
+
</template>
|
|
57
|
+
</html-demo-element>
|
|
58
|
+
</details>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
<p> <b> custom-validity attribute </b><br/>
|
|
62
|
+
applied on the form itself or on the form field.<br/>
|
|
63
|
+
The value is an XPath over DCE <var>datadom</var>. When evaluated as <u>boolean</u>, it would enable(true) or
|
|
64
|
+
disable(false)
|
|
65
|
+
the form submission, acting as form validation mechanism.<br>
|
|
66
|
+
Alternatively, the value can be evaluated as a <u>string</u> which would be treated as an error and can be used
|
|
67
|
+
as
|
|
68
|
+
validation error message set as <var>@validation-message</var> attribute on the form slice.
|
|
69
|
+
Look for <var>email-form/@validation-message</var> example on the page.<br/>
|
|
70
|
+
</p>
|
|
71
|
+
<p> When <var>custom-validity</var> attribute is set on the field, its XPath evaluated value is propagated to
|
|
72
|
+
<a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage">
|
|
73
|
+
validationMessage property</a>. Which would be shown via browser system popup as the field validation error.
|
|
74
|
+
</p>
|
|
75
|
+
<p> <var>@validation-message</var> is set either by <var>custom-validity</var> attribute or by browser as system message.
|
|
76
|
+
By default, it is shown as popup on the field validation. But also is available for template as a string via
|
|
77
|
+
form field attribute. Like in <var>email-form/@validation-message</var>.
|
|
78
|
+
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
<a href="https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation">Form Validation MDN</a>
|
|
36
82
|
</nav>
|
|
37
83
|
|
|
38
84
|
<html-demo-element legend="1. Simple validation"
|
|
39
85
|
description="custom-validity boolean value prevents submission, username length switches Next to 'Sign In' button ">
|
|
40
86
|
<ol>
|
|
41
|
-
<li> Click Next, observe the warning
|
|
42
|
-
<li> Fill input with 10+ characters
|
|
43
|
-
<li> Click Next, the password and "Sign In" button should appear
|
|
87
|
+
<li> Click Next, observe the warning</li>
|
|
88
|
+
<li> Fill input with 10+ characters</li>
|
|
89
|
+
<li> Click Next, the password and "Sign In" button should appear</li>
|
|
44
90
|
</ol>
|
|
45
91
|
<template>
|
|
46
92
|
<custom-element>
|
|
47
93
|
<template>
|
|
48
|
-
<form
|
|
49
|
-
|
|
94
|
+
<form slice="signin-form"
|
|
95
|
+
custom-validity="
|
|
50
96
|
string-length(/datadom/slice/signin-form/form-data/username) > 10
|
|
51
97
|
and string-length(//form-data/password) > 3 "
|
|
52
|
-
|
|
98
|
+
>
|
|
53
99
|
<label> Email
|
|
54
|
-
<input name="username" autocomplete="username" placeholder="Email, phone, or username"
|
|
100
|
+
<input name="username" autocomplete="username" placeholder="Email, phone, or username"
|
|
101
|
+
required="">
|
|
55
102
|
</label>
|
|
56
103
|
<variable name="showpassword" select="string-length(//form-data/username) > 10 "></variable>
|
|
57
104
|
<if test="not($showpassword)">
|
|
@@ -69,20 +116,20 @@
|
|
|
69
116
|
</html-demo-element>
|
|
70
117
|
|
|
71
118
|
<html-demo-element legend="2. Form life cycle demo"
|
|
72
|
-
description="form-data in the form slice is the source of truth"
|
|
119
|
+
description="form-data in the form slice is the source of truth">
|
|
73
120
|
|
|
74
121
|
<template>
|
|
75
122
|
<custom-element>
|
|
76
123
|
<template>
|
|
77
|
-
<form
|
|
78
|
-
|
|
124
|
+
<form slice="signin-form"
|
|
125
|
+
custom-validity="
|
|
79
126
|
string-length(/datadom/slice/signin-form/form-data/username) > 9
|
|
80
127
|
and ( ( //confirm-by = 'sms' )
|
|
81
128
|
or ( //confirm-by = 'email' )
|
|
82
129
|
or ( //confirm-by = 'password' and string-length(//form-data/password) > 3 )
|
|
83
130
|
)
|
|
84
131
|
"
|
|
85
|
-
|
|
132
|
+
>
|
|
86
133
|
<!-- form validity should be based on form-data -->
|
|
87
134
|
<variable name="warn">
|
|
88
135
|
<if test="string-length(//username-slice) < 9 ">
|
|
@@ -96,22 +143,22 @@
|
|
|
96
143
|
</variable>
|
|
97
144
|
<label> Enter your email, phone, or user name
|
|
98
145
|
<input name="username" autocomplete="username"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
146
|
+
placeholder="Email, phone, or username"
|
|
147
|
+
custom-validity="( string-length(//username-slice) > 9 ) ?? 'should be 10+ symbols'"
|
|
148
|
+
slice-event="input"
|
|
149
|
+
slice="username-slice"
|
|
150
|
+
required
|
|
104
151
|
/>
|
|
105
152
|
</label>
|
|
106
153
|
<var> {$warn} </var>
|
|
107
154
|
<fieldset>
|
|
108
155
|
<legend>Confirm by</legend>
|
|
109
|
-
<label><input type="radio" name="confirm-by" value="email"
|
|
110
|
-
<label><input type="radio" name="confirm-by" value="sms"
|
|
111
|
-
<label><input type="radio" name="confirm-by" value="password"
|
|
156
|
+
<label><input type="radio" name="confirm-by" value="email"/> email </label>
|
|
157
|
+
<label><input type="radio" name="confirm-by" value="sms"/> text to phone </label>
|
|
158
|
+
<label><input type="radio" name="confirm-by" value="password"/> password </label>
|
|
112
159
|
<if test="/datadom/slice/signin-form/form-data/confirm-by = 'password'">
|
|
113
160
|
<label>Enter password: <input type="password" NAME="password"
|
|
114
|
-
|
|
161
|
+
custom-validity="( string-length(//form-data/password) > 3 ) ?? 'password is too short'"
|
|
115
162
|
/></label>
|
|
116
163
|
</if>
|
|
117
164
|
<if test="not(//confirm-by)">
|
|
@@ -136,8 +183,8 @@
|
|
|
136
183
|
<ol>
|
|
137
184
|
<li> type in input field</li>
|
|
138
185
|
<li> delete input field content</li>
|
|
139
|
-
<li> observe the warning in string
|
|
140
|
-
<li> Click Next observe the system warning in
|
|
186
|
+
<li> observe the warning in string after input</li>
|
|
187
|
+
<li> Click Next observe the system warning in dropdown over input</li>
|
|
141
188
|
</ol>
|
|
142
189
|
<template>
|
|
143
190
|
<custom-element>
|
|
@@ -150,7 +197,6 @@
|
|
|
150
197
|
<var>{//username/@validation-message}</var>
|
|
151
198
|
</if>
|
|
152
199
|
<button>Next</button>
|
|
153
|
-
<p>{//email-form/@validation-message}</p>
|
|
154
200
|
</form>
|
|
155
201
|
</template>
|
|
156
202
|
</custom-element>
|
|
@@ -160,27 +206,27 @@
|
|
|
160
206
|
<html-demo-element legend="4. form validity message"
|
|
161
207
|
description="@validation-message propagated into form slice and ">
|
|
162
208
|
<ol>
|
|
163
|
-
<li> type up to 3 chars in input field
|
|
164
|
-
<li> observe the slice value change
|
|
165
|
-
<li> click next
|
|
166
|
-
<li> observe the warning bellow the button
|
|
209
|
+
<li> type up to 3 chars in input field</li>
|
|
210
|
+
<li> observe the slice value change</li>
|
|
211
|
+
<li> click next</li>
|
|
212
|
+
<li> observe the warning bellow the button</li>
|
|
167
213
|
</ol>
|
|
168
214
|
<template>
|
|
169
215
|
<custom-element>
|
|
170
216
|
<template>
|
|
171
217
|
<form slice="email-form"
|
|
172
|
-
|
|
218
|
+
custom-validity=" string-length(//slice/username) > 3 ??
|
|
173
219
|
concat('should be more than 3 characters, now is ',string-length(//slice/username) ) "
|
|
174
|
-
|
|
220
|
+
>
|
|
175
221
|
<label> Email
|
|
176
|
-
<input name="email" slice="username" slice-event="input" placeholder="non-empty" required
|
|
222
|
+
<input name="email" slice="username" slice-event="input" placeholder="non-empty" required/>
|
|
177
223
|
</label>
|
|
178
224
|
<if test="//username/@validation-message">
|
|
179
225
|
<var>{//username/@validation-message}</var>
|
|
180
226
|
</if>
|
|
181
227
|
<button>Next</button>
|
|
182
|
-
<p>//email-form/@validation-message:
|
|
183
|
-
<p>//slice/username:
|
|
228
|
+
<p>//email-form/@validation-message: {//email-form/@validation-message} </p>
|
|
229
|
+
<p>//slice/username: {//slice/username} </p>
|
|
184
230
|
</form>
|
|
185
231
|
</template>
|
|
186
232
|
</custom-element>
|
package/demo/s.xml
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<datadom
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
</
|
|
11
|
-
<attributes>
|
|
12
|
-
<id>dce32</id>
|
|
13
|
-
<data-dce-style>54f96d52-ce70-435d-83c4-b421357d9a17</data-dce-style>
|
|
14
|
-
</attributes>
|
|
15
|
-
<dataset>
|
|
16
|
-
<dceStyle>54f96d52-ce70-435d-83c4-b421357d9a17</dceStyle>
|
|
17
|
-
</dataset>
|
|
18
|
-
<slice/>
|
|
2
|
+
<datadom>
|
|
3
|
+
<slice>
|
|
4
|
+
<signin-form>
|
|
5
|
+
<form-data>
|
|
6
|
+
<username>QWE</username>
|
|
7
|
+
<password>ASD</password>
|
|
8
|
+
</form-data>
|
|
9
|
+
</signin-form>
|
|
10
|
+
</slice>
|
|
19
11
|
</datadom>
|
package/ide/web-types-dce.json
CHANGED
package/ide/web-types-xsl.json
CHANGED
package/package.json
CHANGED