@epa-wg/custom-element-dist 0.0.23 → 0.0.25

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 (93) hide show
  1. package/.storybook/main.ts +21 -21
  2. package/.vscode/settings.json +24 -0
  3. package/README.md +4 -4
  4. package/coverage/coverage-final.json +7 -5
  5. package/coverage/index.html +26 -26
  6. package/coverage/src/custom-element/coverage.svg +1 -1
  7. package/coverage/src/custom-element/custom-element.js/coverage.svg +1 -1
  8. package/coverage/src/custom-element/custom-element.js.html +439 -379
  9. package/coverage/src/custom-element/http-request.js.html +12 -12
  10. package/coverage/src/custom-element/index.html +23 -23
  11. package/coverage/src/custom-element/local-storage.js.html +1 -1
  12. package/coverage/src/custom-element/location-element.js/coverage.svg +1 -1
  13. package/coverage/src/custom-element/location-element.js.html +116 -47
  14. package/coverage/src/index.html +1 -1
  15. package/coverage/src/mocks/handlers.ts.html +1 -1
  16. package/coverage/src/mocks/index.html +1 -1
  17. package/coverage/src/stories/attributes.test.stories.ts.html +1 -1
  18. package/coverage/src/stories/coverage.svg +1 -1
  19. package/coverage/src/stories/css.test.stories.ts.html +1 -1
  20. package/coverage/src/stories/dom-merge.test.stories.ts/coverage.svg +1 -1
  21. package/coverage/src/stories/dom-merge.test.stories.ts.html +238 -10
  22. package/coverage/src/stories/external-template.test.stories.ts.html +1 -1
  23. package/coverage/src/stories/form.test.stories.ts.html +1 -1
  24. package/coverage/src/stories/http-request.stories.ts.html +1 -1
  25. package/coverage/src/stories/index.html +46 -16
  26. package/coverage/src/stories/local-storage.test.stories.ts.html +1 -1
  27. package/coverage/src/stories/location-element.test.stories.ts.html +1 -1
  28. package/coverage/src/stories/set-url.test.stories.ts/coverage.svg +10 -0
  29. package/coverage/src/stories/set-url.test.stories.ts.html +427 -0
  30. package/coverage/src/stories/slice-events.test.stories.ts.html +1 -1
  31. package/coverage/src/stories/slots.test.stories.ts.html +1 -1
  32. package/coverage/src/stories/testStoryBook.ts.html +12 -12
  33. package/coverage/src/stories/version-select.test.stories.ts/coverage.svg +10 -0
  34. package/coverage/src/stories/version-select.test.stories.ts.html +313 -0
  35. package/coverage/src/sum.ts.html +1 -1
  36. package/dist/{custom-element-BISbI4SU.js → custom-element-DAe7uvIt.js} +187 -173
  37. package/dist/custom-element-DZvvhscI.cjs +53 -0
  38. package/dist/custom-element-bundle.cjs +1 -1
  39. package/dist/custom-element-bundle.js +23 -22
  40. package/dist/location-element-DRB7hCwA.cjs +1 -0
  41. package/dist/location-element-FJlONi2n.js +65 -0
  42. package/package.json +2 -2
  43. package/src/custom-element/custom-element.js +25 -5
  44. package/src/custom-element/demo/form.html +2 -3
  45. package/src/custom-element/demo/location-element.html +17 -4
  46. package/src/custom-element/demo/s.xml +31 -6
  47. package/src/custom-element/demo/s.xslt +59 -22
  48. package/src/custom-element/demo/set-url.html +141 -0
  49. package/src/custom-element/ide/customData-dce.json +56 -0
  50. package/src/custom-element/ide/web-types-dce.json +153 -110
  51. package/src/custom-element/ide/web-types-xsl.json +1 -1
  52. package/src/custom-element/index.html +1 -0
  53. package/src/custom-element/location-element.js +25 -2
  54. package/src/custom-element.test.ts +26 -26
  55. package/src/stories/dom-merge.test.stories.ts +76 -0
  56. package/src/stories/set-url.test.stories.ts +114 -0
  57. package/src/stories/version-select.test.stories.ts +76 -0
  58. package/storybook-static/assets/{Color-PRSJMWNM-BD_Ds9NW.js → Color-PRSJMWNM-CRSv4C7i.js} +1 -1
  59. package/storybook-static/assets/{Configure-70I_VApa.js → Configure-D0qG3gR9.js} +1 -1
  60. package/storybook-static/assets/{DocsRenderer-K4EAMTCU-9dn0-HCP.js → DocsRenderer-K4EAMTCU-CG_P5zRZ.js} +2 -2
  61. package/storybook-static/assets/{WithTooltip-KJL26V4Q-C6g5GOU9.js → WithTooltip-KJL26V4Q-CUqUi5E8.js} +1 -1
  62. package/storybook-static/assets/{attributes.test.stories-BEOraI4E.js → attributes.test.stories-W34tZdUt.js} +1 -1
  63. package/storybook-static/assets/{css.test.stories-D9WaxrEv.js → css.test.stories-BZFYx1TQ.js} +1 -1
  64. package/storybook-static/assets/{custom-element-BV8-hRQS.js → custom-element-DpIq8E2p.js} +79 -79
  65. package/storybook-static/assets/dom-merge.test.stories-S-7U5N3h.js +258 -0
  66. package/storybook-static/assets/{external-template.test.stories-Bpr_wxBo.js → external-template.test.stories-QIO3lAFz.js} +1 -1
  67. package/storybook-static/assets/{form.test.stories-3tURbEdv.js → form.test.stories-ClYhj9F1.js} +1 -1
  68. package/storybook-static/assets/{formatter-2WMMO6ZP-6IvBq34u.js → formatter-2WMMO6ZP-C-UiBIma.js} +1 -1
  69. package/storybook-static/assets/http-request-DNq59pnj.js +1 -0
  70. package/storybook-static/assets/{http-request.stories-8K_qSs8C.js → http-request.stories-DCqY5s2i.js} +9 -9
  71. package/storybook-static/assets/iframe-CURpvmVV.js +2 -0
  72. package/storybook-static/assets/{index-DhXZyjEd.js → index-CKw1EbdP.js} +1 -1
  73. package/storybook-static/assets/{index-B3oZkK3F.js → index-DYpTqTNu.js} +1 -1
  74. package/storybook-static/assets/{index-C30JwJMK.js → index-DsWii_Ep.js} +5 -5
  75. package/storybook-static/assets/{local-storage.test.stories-CtisAQBB.js → local-storage.test.stories-BqgYwqr-.js} +1 -1
  76. package/storybook-static/assets/location-element-hKpcXCdn.js +1 -0
  77. package/storybook-static/assets/{location-element.test.stories-5O_t_m4Y.js → location-element.test.stories-DvH1TWK4.js} +9 -9
  78. package/storybook-static/assets/{preview-D0eCfQft.js → preview-DjDbQHPa.js} +2 -2
  79. package/storybook-static/assets/set-url.test.stories-GlJOh31I.js +81 -0
  80. package/storybook-static/assets/{slice-events.test.stories-BSXCLIA5.js → slice-events.test.stories-VoNjuPCX.js} +1 -1
  81. package/storybook-static/assets/{slots.test.stories-B1vqfHmN.js → slots.test.stories-Da2j9YuO.js} +1 -1
  82. package/storybook-static/assets/{syntaxhighlighter-BP7B2CQK-DpPBKyTO.js → syntaxhighlighter-BP7B2CQK-CDpEe51g.js} +1 -1
  83. package/storybook-static/assets/version-select.test.stories-DLwf-TPB.js +60 -0
  84. package/storybook-static/iframe.html +1 -1
  85. package/storybook-static/index.json +1 -1
  86. package/storybook-static/project.json +1 -1
  87. package/.idea/.gitignore +0 -8
  88. package/dist/custom-element-N-sWiqGK.cjs +0 -53
  89. package/dist/location-element-2m0gWq_d.cjs +0 -1
  90. package/dist/location-element-nA_wsqBt.js +0 -49
  91. package/storybook-static/assets/dom-merge.test.stories-BhbNeum_.js +0 -137
  92. package/storybook-static/assets/iframe-zdt9kuj6.js +0 -2
  93. package/yarn.lock +0 -10242
@@ -0,0 +1,141 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
+ xmlns:xhtml="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <title>custom-element Declarative Custom Element implementation demo</title>
7
+ <link rel="icon" href="./wc-square.svg"/>
8
+ <script type="module" src="../location-element.js"></script>
9
+ <script type="module" src="../custom-element.js"></script>
10
+ <style>
11
+ @import "./demo.css";
12
+ input[type="text"]{ min-width: 30rem; }
13
+
14
+ .infolink {
15
+ &:before {
16
+ content: '❔';
17
+ display: inline-block;
18
+ border-radius: 1.2em;
19
+ }
20
+
21
+ &:hover:before {
22
+ background: blue;
23
+ }
24
+ }
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <nav>
29
+ <a href="../index.html"><h3><code>custom-element</code> demo</h3></a>
30
+ </nav>
31
+ <main>
32
+ <h3>How to set the page URL by location-element?</h3>
33
+ Answer: by defining following attributes:
34
+ <ol>
35
+ <li><code>method</code> to one of values provided bellow</li>
36
+ <li><code>src</code> with URL </li>
37
+ </ol>
38
+ <p> &lt;location-element&gt; is safe to be used unconditionally as long as `src` is missing or same as page URL.
39
+ Otherwise it can be injected by event driven condition as in sample <a href="#dce3">#3</a> </p>
40
+ </main>
41
+ <html-demo-element legend="1. Set the page URL by location.hash"
42
+ description="click on 'set' button and observe hash value change in url"
43
+ id="dce1">
44
+ <template>
45
+ <custom-element>
46
+ <template>
47
+ <button value="#dce1" slice="set-button" slice-event="click">#dce1</button>
48
+ <button value="#dce2" slice="set-button" slice-event="click">#dce2</button>
49
+ <location-element method="location.href" src="{//set-button/@value}"></location-element>
50
+ </template>
51
+ </custom-element>
52
+ </template>
53
+ </html-demo-element>
54
+
55
+ <html-demo-element legend="2. Set the page URL by method"
56
+ description="click on 'set' button and observe hash value change in url"
57
+ id="dce2">
58
+ <template>
59
+ <custom-element>
60
+ <template>
61
+ <style>
62
+ button{ display: block; width: 100%; }
63
+ </style>
64
+ <button value="location.href" slice="set-button" slice-event="click"> location.href </button>
65
+ <button value="location.hash" slice="set-button" slice-event="click"> location.hash </button>
66
+ <button value="location.assign" slice="set-button" slice-event="click"> location.assign </button>
67
+ <button value="location.replace" slice="set-button" slice-event="click"> location.replace </button>
68
+ <button value="history.pushState" slice="set-button" slice-event="click"> history.pushState </button>
69
+ <button value="history.replaceState" slice="set-button" slice-event="click"> history.replaceState </button>
70
+ <location-element method="{//set-button/@value}" src="#dce2"></location-element>
71
+ </template>
72
+ </custom-element>
73
+ </template>
74
+ </html-demo-element>
75
+
76
+ <html-demo-element legend="3. Set the page URL by location.href in conditionally injected location-element"
77
+ description="click on 'set' button and observe in url #dce3"
78
+ id="dce3">
79
+ <p>Has to produce URL properties</p>
80
+ <template>
81
+ <custom-element>
82
+ <template>
83
+ <button value="#dce3" slice="set-button" slice-event="click">set</button>
84
+ <if test="//set-button/@slice-event">
85
+ <location-element method="location.href" src="#dce3"></location-element>
86
+ look for <b>#dce3</b> in URL which is set by <code>location-element</code>
87
+ </if>
88
+ </template>
89
+ </custom-element>
90
+ </template>
91
+ </html-demo-element>
92
+
93
+ <html-demo-element legend="4. Set page URL methods"
94
+ description="To define the URL, fill input field or click the radio button, then 'set' button. "
95
+ id="dce4">
96
+ <template>
97
+ <custom-element>
98
+ <template>
99
+ <xsl:variable name="methods">
100
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/href"
101
+ title="./set-url.html?a=A">location.href</a>
102
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/hash"
103
+ title="#dec4">location.hash</a>
104
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/assign"
105
+ title="./set-url.html?assign=1">location.assign</a>
106
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/replace"
107
+ title="./set-url.html?replace=location">location.replace</a>
108
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/History/pushState"
109
+ title="./set-url.html?history=pushState">history.pushState</a>
110
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState"
111
+ title="./set-url.html?history=replaceState">history.replaceState</a>
112
+ </xsl:variable>
113
+ <form slice="url-form" custom-validity="'invalid'" method="post">
114
+ <fieldset>
115
+ <legend><b>set-by</b></legend>
116
+ <for-each select="exsl:node-set($methods)/*">
117
+ <p><label><input type="radio" name="method" value="{.}"/> {.} </label>
118
+ <a class="infolink" href="{@href}">mdn</a>
119
+ </p>
120
+ </for-each>
121
+ </fieldset>
122
+ <variable name="selected-method" select="//form-data/method/text()"></variable>
123
+ <variable name="selected-url"
124
+ select="exsl:node-set($methods)/*[text() = $selected-method ]/@title"></variable>
125
+
126
+ <label><input name="url" value="{//url ?? $selected-url }" type="text"/></label>
127
+ <button name="submit-btn" value="by-submit" type="submit">set</button>
128
+ <if test="//form-data/url">
129
+ <location-element method="{$selected-method}" src="{//form-data/url}"></location-element>
130
+ {$selected-method} = {//form-data/url}
131
+ </if>
132
+ </form>
133
+ </template>
134
+ </custom-element>
135
+ </template>
136
+ </html-demo-element>
137
+
138
+ <script type="module" src="https://unpkg.com/html-demo-element@1/html-demo-element.js"></script>
139
+
140
+ </body>
141
+ </html>
@@ -120,6 +120,62 @@
120
120
  "url": "https://github.com/EPA-WG/custom-element/tree/develop?tab=readme-ov-file#interactivity-via-data-slice-triggered-by-events"
121
121
  }
122
122
  ]
123
+ },
124
+ {
125
+ "name": "location-element",
126
+ "description": "get/set window URL parts or from SRC URL",
127
+ "attributes": [
128
+ {
129
+ "name": "href",
130
+ "description": "url to be parsed. When omitted window.location is used.",
131
+ "type": "string",
132
+ "references": [
133
+ {
134
+ "name": "MDN docs",
135
+ "url": "https://developer.mozilla.org/en-US/docs/Web/API/Location/href"
136
+ }
137
+ ]
138
+ },
139
+ {
140
+ "name": "live",
141
+ "description": "monitors history change, applicable only when href is omitted.",
142
+ "type": "string",
143
+ "references": [
144
+ {
145
+ "name": "docs",
146
+ "url": "https://unpkg.com/@epa-wg/custom-element@0/demo/location-element.html"
147
+ }
148
+ ]
149
+ },
150
+ {
151
+ "name": "src",
152
+ "description": "sets the window URL",
153
+ "type": "string",
154
+ "references": [
155
+ {
156
+ "name": "docs",
157
+ "url": "https://unpkg.com/@epa-wg/custom-element@0/demo/set-url.html"
158
+ }
159
+ ]
160
+ },
161
+ {
162
+ "name": "method",
163
+ "description": "when defined, changes URL by one of predefined methods.",
164
+ "type": "string",
165
+ "references": [
166
+ {
167
+ "name": "docs",
168
+ "url": "https://unpkg.com/@epa-wg/custom-element@0/demo/set-url.html"
169
+ }
170
+ ]
171
+ }
172
+ ],
173
+ "references": [
174
+ {
175
+ "name": "docs",
176
+ "url": "https://github.com/EPA-WG/custom-element"
177
+ }
178
+ ]
123
179
  }
124
180
  ]
125
181
  }
@@ -1,116 +1,159 @@
1
1
  {
2
- "$schema": "http://json.schemastore.org/web-types",
3
- "name": "@epa-wg/custom-element",
4
- "version": "0.0.23",
5
- "js-types-syntax": "typescript",
6
- "description-markup": "markdown",
7
- "contributions": {
8
- "html": {
9
- "attributes": [
10
- {
11
- "name": "slice",
12
- "description": "Defines the name of data slice in DCE where the data from `value` will be propagated on `change` or by `slice-event` event\n\nOn: any component with `value` and associated change event",
13
- "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/dom-merge.html"
14
- },
15
- {
16
- "name": "slice-event",
17
- "description": "Defines the event name on which `value` would be synchronized with DCE slice\n\nOn: any component with `value` and associated change event",
18
- "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/dom-merge.html"
19
- },
20
- {
21
- "name": "custom-validity",
22
- "description": "XPath expression to return either boolean or error string to be shown by browser native UI on form validation event. Unless value is true, prevents the form submission.",
23
- "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/form.html"
24
- },
25
- {
26
- "name": "slice-value",
27
- "description": "XPath expression to populate into the slice",
28
- "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/data-slices.html"
29
- }
30
- ],
31
- "elements": [
32
- {
33
- "name": "custom-element",
34
- "description": "Declarative Custom Element as W3C proposal PoC with native(XSLT) based templating",
35
- "doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#custom-element",
36
- "attributes": [
37
- {
38
- "name": "hidden",
39
- "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.",
40
- "required": false,
41
- "doc-url": "https://developer.mozilla.org/en-US/docs/web/html/global_attributes/hidden",
42
- "value": {
43
- "type": "boolean"
44
- }
45
- },
46
- {
47
- "name": "tag",
48
- "description": "HTML tag for Custom Element. Used for window.customElements.define(). If not set, would be generated and DCE instance rendered inline. ",
49
- "default": "",
50
- "required": false,
51
- "doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#tag-attribute",
52
- "value": {
53
- "type": "string"
54
- }
55
- },
56
- {
57
- "name": "src",
58
- "description": "full, relative, or hash URL to DCE template.",
59
- "default": "",
60
- "required": false,
61
- "doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#src-attribute",
62
- "value": {
63
- "type": "URL"
64
- }
65
- }
66
- ],
67
- "slots": [],
68
- "js": {
69
- "events": [
70
- {
71
- "name": "value:changed",
72
- "description": "Emitted when data changes. Can be used for state serialization in hydration flow"
73
- }
2
+ "$schema": "http://json.schemastore.org/web-types",
3
+ "name": "@epa-wg/custom-element",
4
+ "version": "0.0.25",
5
+ "js-types-syntax": "typescript",
6
+ "description-markup": "markdown",
7
+ "contributions": {
8
+ "html": {
9
+ "attributes": [
10
+ {
11
+ "name": "slice",
12
+ "description": "Defines the name of data slice in DCE where the data from `value` will be propagated on `change` or by `slice-event` event\n\nOn: any component with `value` and associated change event",
13
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/dom-merge.html"
14
+ },
15
+ {
16
+ "name": "slice-event",
17
+ "description": "Defines the event name on which `value` would be synchronized with DCE slice\n\nOn: any component with `value` and associated change event",
18
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/dom-merge.html"
19
+ },
20
+ {
21
+ "name": "custom-validity",
22
+ "description": "XPath expression to return either boolean or error string to be shown by browser native UI on form validation event. Unless value is true, prevents the form submission.",
23
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/form.html"
24
+ },
25
+ {
26
+ "name": "slice-value",
27
+ "description": "XPath expression to populate into the slice",
28
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element/demo/data-slices.html"
29
+ }
74
30
  ],
75
- "properties": [
76
- {
77
- "name": "value",
78
- "type": "string",
79
- "default": "",
80
- "description": "DCE state. Can be used for state serialization in hydration flow. Format TBD, most likely encoded XML string"
81
- }
82
- ]
83
- },
84
- "css": {
85
- "properties": [
86
- ]
87
- }
88
- },
89
- {
90
- "name": "for-each",
91
- "description": "The <xsl:for-each> element selects a set of nodes and processes each of them in the same way. It is often used to iterate through a set of nodes or to change the current node. If one or more <xsl:sort> elements appear as the children of this element, sorting occurs before processing. Otherwise, nodes are processed in document order.",
92
- "doc-url": "https://developer.mozilla.org/en-US/docs/Web/XSLT/Element/for-each",
93
- "attributes": [
94
- {
95
- "name": "select",
96
- "description": "Uses an XPath expression to select nodes to be processed.",
97
- "required": true,
98
- "doc-url": "https://developer.mozilla.org/en-US/docs/Web/XSLT/Element/for-each#select",
99
- "value": {
100
- "type": "string"
101
- }
102
- }
103
- ]
104
- },
105
- {
106
- "name": "slice",
107
- "description": "Synthetic element for defining the slice-attributed when more then one slice/event/value associated with parent element",
108
- "doc-url": "https://github.com/EPA-WG/custom-element/tree/develop?tab=readme-ov-file#interactivity-via-data-slice-triggered-by-events",
109
- "attributes": [
31
+ "elements": [
32
+ {
33
+ "name": "custom-element",
34
+ "description": "Declarative Custom Element as W3C proposal PoC with native(XSLT) based templating",
35
+ "doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#custom-element",
36
+ "attributes": [
37
+ {
38
+ "name": "hidden",
39
+ "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.",
40
+ "required": false,
41
+ "doc-url": "https://developer.mozilla.org/en-US/docs/web/html/global_attributes/hidden",
42
+ "value": {
43
+ "type": "boolean"
44
+ }
45
+ },
46
+ {
47
+ "name": "tag",
48
+ "description": "HTML tag for Custom Element. Used for window.customElements.define(). If not set, would be generated and DCE instance rendered inline. ",
49
+ "default": "",
50
+ "required": false,
51
+ "doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#tag-attribute",
52
+ "value": {
53
+ "type": "string"
54
+ }
55
+ },
56
+ {
57
+ "name": "src",
58
+ "description": "full, relative, or hash URL to DCE template.",
59
+ "default": "",
60
+ "required": false,
61
+ "doc-url": "https://github.com/EPA-WG/custom-element?tab=readme-ov-file#src-attribute",
62
+ "value": {
63
+ "type": "URL"
64
+ }
65
+ }
66
+ ],
67
+ "slots": [ ],
68
+ "js": {
69
+ "events": [
70
+ {
71
+ "name": "value:changed",
72
+ "description": "Emitted when data changes. Can be used for state serialization in hydration flow"
73
+ }
74
+ ],
75
+ "properties": [
76
+ {
77
+ "name": "value",
78
+ "type": "string",
79
+ "default": "",
80
+ "description": "DCE state. Can be used for state serialization in hydration flow. Format TBD, most likely encoded XML string"
81
+ }
82
+ ]
83
+ },
84
+ "css": {
85
+ "properties": [
86
+ ]
87
+ }
88
+ },
89
+ {
90
+ "name": "for-each",
91
+ "description": "The <xsl:for-each> element selects a set of nodes and processes each of them in the same way. It is often used to iterate through a set of nodes or to change the current node. If one or more <xsl:sort> elements appear as the children of this element, sorting occurs before processing. Otherwise, nodes are processed in document order.",
92
+ "doc-url": "https://developer.mozilla.org/en-US/docs/Web/XSLT/Element/for-each",
93
+ "attributes": [
94
+ {
95
+ "name": "select",
96
+ "description": "Uses an XPath expression to select nodes to be processed.",
97
+ "required": true,
98
+ "doc-url": "https://developer.mozilla.org/en-US/docs/Web/XSLT/Element/for-each#select",
99
+ "value": {
100
+ "type": "string"
101
+ }
102
+ }
103
+ ]
104
+ },
105
+ {
106
+ "name": "location-element",
107
+ "description": "get/set window URL parts or from SRC URL",
108
+ "doc-url": "https://github.com/EPA-WG/custom-element",
109
+ "attributes": [
110
+ {
111
+ "name": "href",
112
+ "description": "url to be parsed. When omitted window.location is used.",
113
+ "required": false,
114
+ "doc-url": "https://developer.mozilla.org/en-US/docs/Web/API/Location/href",
115
+ "value": {
116
+ "type": "string"
117
+ }
118
+ },
119
+ {
120
+ "name": "live",
121
+ "description": "monitors history change, applicable only when href is omitted.",
122
+ "required": false,
123
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element@0/demo/location-element.html",
124
+ "value": {
125
+ "type": "string"
126
+ }
127
+ },
128
+ {
129
+ "name": "src",
130
+ "description": "sets the window URL",
131
+ "required": false,
132
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element@0/demo/set-url.html",
133
+ "value": {
134
+ "type": "string"
135
+ }
136
+ },
137
+ {
138
+ "name": "method",
139
+ "description": "when defined, changes URL by one of predefined methods.",
140
+ "required": false,
141
+ "doc-url": "https://unpkg.com/@epa-wg/custom-element@0/demo/set-url.html",
142
+ "value": {
143
+ "type": "string"
144
+ }
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "name": "slice",
150
+ "description": "Synthetic element for defining the slice-attributed when more then one slice/event/value associated with parent element",
151
+ "doc-url": "https://github.com/EPA-WG/custom-element/tree/develop?tab=readme-ov-file#interactivity-via-data-slice-triggered-by-events",
152
+ "attributes": [
110
153
 
111
- ]
154
+ ]
155
+ }
156
+ ]
112
157
  }
113
- ]
114
158
  }
115
- }
116
159
  }
@@ -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.23",
4
+ "version": "0.0.25",
5
5
  "js-types-syntax": "typescript",
6
6
  "description-markup": "markdown",
7
7
  "contributions": {
@@ -30,6 +30,7 @@
30
30
  <a href="./demo/local-storage.html" >local-storage </a> |
31
31
  <a href="./demo/http-request.html" >http-request </a> |
32
32
  <a href="./demo/location-element.html" >location-element </a> |
33
+ <a href="./demo/set-url.html" >set-url </a> |
33
34
  <a href="./demo/external-template.html" >external template </a> <br/>
34
35
  <a href="./demo/hex-grid.html" >hex grid lib </a> |
35
36
  <a href="./demo/scoped-css.html" >scoped CSS </a> |
@@ -16,6 +16,15 @@ function ensureTrackLocationChange()
16
16
  }
17
17
  });
18
18
  }
19
+ const methods =
20
+ { 'location.href' : src => window.location.href = src
21
+ , 'location.hash' : src => window.location.hash = src
22
+ , 'location.assign' : src => window.location.assign( src )
23
+ , 'location.replace' : src => window.location.replace( src )
24
+ , 'history.pushState' : src => window.history.pushState( {}, "", src )
25
+ , 'history.replaceState' : src => window.history.replaceState( {}, "", src )
26
+ };
27
+
19
28
 
20
29
  export class LocationElement extends HTMLElement
21
30
  {
@@ -25,6 +34,8 @@ export class LocationElement extends HTMLElement
25
34
  , 'href' // url to be parsed. When omitted window.location is used.
26
35
  , 'type' // `text|json`, defaults to text, other types are compatible with INPUT field
27
36
  , 'live' // monitors history change, applicable only when href is omitted.
37
+ , 'src' // sets the URL
38
+ , 'method' // when defined, changes URL by one of predefined methods.
28
39
  ];
29
40
 
30
41
  constructor()
@@ -53,6 +64,17 @@ export class LocationElement extends HTMLElement
53
64
  };
54
65
  this.sliceInit = s =>
55
66
  {
67
+ if( this.hasAttribute('method') )
68
+ {
69
+ const method = this.getAttribute('method');
70
+ const src = this.getAttribute('src');
71
+ if( method && src )
72
+ if( method === 'location.hash' )
73
+ { if( src !== window.location.hash )
74
+ methods[ method ]?.( src );
75
+ }else if( window.location.href !== new URL(src, window.location).href )
76
+ methods[method]?.(src);
77
+ }
56
78
  if( !state.listener && this.hasAttribute('live') )
57
79
  { state.listener = 1;
58
80
  window.navigation?.addEventListener("navigate", listener );
@@ -74,8 +96,9 @@ export class LocationElement extends HTMLElement
74
96
  }
75
97
  attributeChangedCallback(name, oldValue, newValue)
76
98
  {
77
- if('href'!== name)
78
- return;
99
+ if('href'!== name && 'method' !== name && 'src' )
100
+ if( !['method','src','href'].includes(name) )
101
+ return;
79
102
  this.sliceInit && this.sliceInit();
80
103
  }
81
104
 
@@ -1,26 +1,26 @@
1
- import {expect, test} from 'vitest'
2
- import {deepEqual, xml2dom, xmlString, obj2node } from './custom-element/custom-element.js'
3
-
4
- test('deepEqual', () =>
5
- {
6
- expect(deepEqual(1, 1)).toBe(true);
7
- expect(deepEqual({}, null)).toBe(false);
8
- expect(deepEqual({a: 1}, {a: 1, b: 2})).toBe(false);
9
- expect(deepEqual({a: 1}, {a: 2})).toBe(false);
10
- expect(deepEqual({a: 1}, {a: 1})).toBe(true);
11
- })
12
- test('xml2dom', () =>
13
- {
14
- const dom = xml2dom('<a/>');
15
- expect(dom.documentElement.localName).to.equal('a');
16
- expect(dom.documentElement.childNodes.length).to.equal(0);
17
- const xStr = xmlString(dom);
18
- expect(xStr).to.include('<a');
19
- })
20
- test('obj2node', () =>
21
- {
22
- expect(obj2node(()=>{} , 'f',document).outerHTML).to.equal('<f></f>' );
23
- expect(obj2node(9 , 'a',document).outerHTML).to.equal('<a>9</a>' );
24
- expect(obj2node('abc' , 's',document).outerHTML).to.equal('<s>abc</s>' );
25
- expect(obj2node({a:1,b:{c:'abc'}} , 's',document).outerHTML).to.equal('<s a="1"><b c="abc"></b></s>');
26
- })
1
+ import {expect, test} from 'vitest'
2
+ import {deepEqual, xml2dom, xmlString, obj2node } from './custom-element/custom-element.js'
3
+
4
+ test('deepEqual', () =>
5
+ {
6
+ expect(deepEqual(1, 1)).toBe(true);
7
+ expect(deepEqual({}, null)).toBe(false);
8
+ expect(deepEqual({a: 1}, {a: 1, b: 2})).toBe(false);
9
+ expect(deepEqual({a: 1}, {a: 2})).toBe(false);
10
+ expect(deepEqual({a: 1}, {a: 1})).toBe(true);
11
+ })
12
+ test('xml2dom', () =>
13
+ {
14
+ const dom = xml2dom('<a/>');
15
+ expect(dom.documentElement.localName).to.equal('a');
16
+ expect(dom.documentElement.childNodes.length).to.equal(0);
17
+ const xStr = xmlString(dom);
18
+ expect(xStr).to.include('<a');
19
+ })
20
+ test('obj2node', () =>
21
+ {
22
+ expect(obj2node(()=>{} , 'f',document).outerHTML).to.equal('<f></f>' );
23
+ expect(obj2node(9 , 'a',document).outerHTML).to.equal('<a>9</a>' );
24
+ expect(obj2node('abc' , 's',document).outerHTML).to.equal('<s>abc</s>' );
25
+ expect(obj2node({a:1,b:{c:'abc'}} , 's',document).outerHTML).to.equal('<s a="1"><b c="abc"></b></s>');
26
+ })