@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 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.22/coverage/src/custom-element/coverage.svg
352
- [coverage-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.22/coverage/src/custom-element/index.html
353
- [storybook-url]: https://unpkg.com/@epa-wg/custom-element-dist@0.0.22/storybook-static/index.html?path=/story/welcome--introduction
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
@@ -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.22",
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.append( e )
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
- label{ display: flex; }
13
- label:has(input[type="text"],input[type="password"],input:not([type]) ){flex-direction: column;}
14
- nav{ max-width: 32em; }
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
- <h3>Forms handling.</h3>
26
- <ul>
27
- <li> The form triggers re-render on <code>change</code> event before submit</li>
28
- <li> <code>disabled</code> form attribute is added when validation is not passed </li>
29
- <li> Form action triggered on submit changing the hash in URL </li>
30
- <li> URL hash hides the <var>signin</var> form from DOM and shown <var>signout</var> form </li>
31
- <li> signout action reverse visibility of signin and signout </li>
32
- <li> "remember" checkbox triggers <code>local-storage</code> with value set from <var>form-data/remember</var> slice </li>
33
- <li> "username" initial value taken from <code>local-storage</code> <var>usernane</var> slice </li>
34
- <li> <a href="https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation">Form Validation - MDN</a> </li>
35
- </ul>
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 </li>
42
- <li> Fill input with 10+ characters </li>
43
- <li> Click Next, the password and "Sign In" button should appear </li>
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 slice="signin-form"
49
- custom-validity="
94
+ <form slice="signin-form"
95
+ custom-validity="
50
96
  string-length(/datadom/slice/signin-form/form-data/username) &gt; 10
51
97
  and string-length(//form-data/password) &gt; 3 "
52
- >
98
+ >
53
99
  <label> Email
54
- <input name="username" autocomplete="username" placeholder="Email, phone, or username" required="">
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) &gt; 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 slice="signin-form"
78
- custom-validity="
124
+ <form slice="signin-form"
125
+ custom-validity="
79
126
  string-length(/datadom/slice/signin-form/form-data/username) &gt; 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) &gt; 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) &lt; 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
- placeholder="Email, phone, or username"
100
- custom-validity="( string-length(//username-slice) &gt; 9 ) ?? 'should be 10+ symbols'"
101
- slice-event="input"
102
- slice="username-slice"
103
- required
146
+ placeholder="Email, phone, or username"
147
+ custom-validity="( string-length(//username-slice) &gt; 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" /> email </label>
110
- <label><input type="radio" name="confirm-by" value="sms" /> text to phone </label>
111
- <label><input type="radio" name="confirm-by" value="password" /> password </label>
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
- custom-validity="( string-length(//form-data/password) &gt; 3 ) ?? 'password is too short'"
161
+ custom-validity="( string-length(//form-data/password) &gt; 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 bellow input</li>
140
- <li> Click Next observe the system warning in dropdown and in string bellow input</li>
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 </li>
164
- <li> observe the slice value change </li>
165
- <li> click next </li>
166
- <li> observe the warning bellow the button </li>
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
- custom-validity=" string-length(//slice/username) &gt; 3 ??
218
+ custom-validity=" string-length(//slice/username) &gt; 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: {//email-form/@validation-message} </p>
183
- <p>//slice/username: {//slice/username} </p>
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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"
3
- xmlns:dce="urn:schemas-epa-wg:dce">
4
- <payload>
5
- <xhtml:span slot=""></xhtml:span>
6
- <xhtml:style slot="" title="ABC">dce-3[data-dce-style="54f96d52-ce70-435d-83c4-b421357d9a17"]{ color:red; }</xhtml:style>
7
- <xhtml:span slot=""></xhtml:span>
8
- <xhtml:u slot="">red</xhtml:u>
9
- <xhtml:span slot=""></xhtml:span>
10
- </payload>
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>
@@ -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.22",
4
+ "version": "0.0.24",
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.22",
4
+ "version": "0.0.24",
5
5
  "js-types-syntax": "typescript",
6
6
  "description-markup": "markdown",
7
7
  "contributions": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epa-wg/custom-element",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
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",