@epa-wg/custom-element-dist 0.0.1

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 (284) hide show
  1. package/.editorconfig +11 -0
  2. package/.gitignore +26 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/compiler.xml +6 -0
  5. package/.idea/custom-element-dist.iml +13 -0
  6. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  7. package/.idea/misc.xml +6 -0
  8. package/.idea/modules.xml +8 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/.storybook/main.ts +21 -0
  11. package/.storybook/preview.ts +17 -0
  12. package/.vscode/settings.json +24 -0
  13. package/LICENSE +201 -0
  14. package/README.md +32 -0
  15. package/bin/build.sh +8 -0
  16. package/bin/clean.sh +5 -0
  17. package/bin/postinstall.sh +17 -0
  18. package/bin/start.sh +2 -0
  19. package/coverage/base.css +224 -0
  20. package/coverage/block-navigation.js +87 -0
  21. package/coverage/coverage-final.json +16 -0
  22. package/coverage/favicon.png +0 -0
  23. package/coverage/index.html +161 -0
  24. package/coverage/prettify.css +1 -0
  25. package/coverage/prettify.js +2 -0
  26. package/coverage/sort-arrow-sprite.png +0 -0
  27. package/coverage/sorter.js +196 -0
  28. package/coverage/src/coverage.svg +10 -0
  29. package/coverage/src/custom-element/coverage.svg +10 -0
  30. package/coverage/src/custom-element/custom-element.js/coverage.svg +10 -0
  31. package/coverage/src/custom-element/custom-element.js.html +2149 -0
  32. package/coverage/src/custom-element/http-request.js/coverage.svg +10 -0
  33. package/coverage/src/custom-element/http-request.js.html +352 -0
  34. package/coverage/src/custom-element/index.html +161 -0
  35. package/coverage/src/custom-element/local-storage.js/coverage.svg +10 -0
  36. package/coverage/src/custom-element/local-storage.js.html +346 -0
  37. package/coverage/src/custom-element/location-element.js/coverage.svg +10 -0
  38. package/coverage/src/custom-element/location-element.js.html +343 -0
  39. package/coverage/src/index.html +116 -0
  40. package/coverage/src/mocks/coverage.svg +10 -0
  41. package/coverage/src/mocks/handlers.ts/coverage.svg +10 -0
  42. package/coverage/src/mocks/handlers.ts.html +172 -0
  43. package/coverage/src/mocks/index.html +116 -0
  44. package/coverage/src/stories/attributes.stories.ts/coverage.svg +10 -0
  45. package/coverage/src/stories/attributes.stories.ts.html +481 -0
  46. package/coverage/src/stories/coverage.svg +10 -0
  47. package/coverage/src/stories/css.stories.ts/coverage.svg +10 -0
  48. package/coverage/src/stories/css.stories.ts.html +397 -0
  49. package/coverage/src/stories/dom-merge.stories.ts/coverage.svg +10 -0
  50. package/coverage/src/stories/dom-merge.stories.ts.html +424 -0
  51. package/coverage/src/stories/external-template.stories.ts/coverage.svg +10 -0
  52. package/coverage/src/stories/external-template.stories.ts.html +820 -0
  53. package/coverage/src/stories/http-request.stories.ts/coverage.svg +10 -0
  54. package/coverage/src/stories/http-request.stories.ts.html +817 -0
  55. package/coverage/src/stories/index.html +236 -0
  56. package/coverage/src/stories/local-storage.stories.ts/coverage.svg +10 -0
  57. package/coverage/src/stories/local-storage.stories.ts.html +1249 -0
  58. package/coverage/src/stories/location-element.stories.ts/coverage.svg +10 -0
  59. package/coverage/src/stories/location-element.stories.ts.html +484 -0
  60. package/coverage/src/stories/renderPlay.ts/coverage.svg +10 -0
  61. package/coverage/src/stories/renderPlay.ts.html +151 -0
  62. package/coverage/src/stories/slice-events.stories.ts/coverage.svg +10 -0
  63. package/coverage/src/stories/slice-events.stories.ts.html +436 -0
  64. package/coverage/src/sum.ts/coverage.svg +10 -0
  65. package/coverage/src/sum.ts.html +94 -0
  66. package/dist/confused.svg +37 -0
  67. package/dist/custom-element-B4v-KaIh.cjs +53 -0
  68. package/dist/custom-element-_g0GTup2.js +436 -0
  69. package/dist/custom-element-bundle.cjs +1 -0
  70. package/dist/custom-element-bundle.js +31 -0
  71. package/dist/embed-1.html +3 -0
  72. package/dist/html-template.html +126 -0
  73. package/dist/html-template.xhtml +45 -0
  74. package/dist/html-template.xml +45 -0
  75. package/dist/http-request-BOvP4KTl.js +56 -0
  76. package/dist/http-request-DPrY7mGh.cjs +1 -0
  77. package/dist/local-storage-Boafngui.cjs +1 -0
  78. package/dist/local-storage-BqDEu2kF.js +59 -0
  79. package/dist/location-element-2m0gWq_d.cjs +1 -0
  80. package/dist/location-element-nA_wsqBt.js +49 -0
  81. package/dist/mockServiceWorker.js +284 -0
  82. package/dist/tree.xsl +33 -0
  83. package/dist/vite.svg +1 -0
  84. package/index.html +17 -0
  85. package/package.json +97 -0
  86. package/public/confused.svg +37 -0
  87. package/public/embed-1.html +3 -0
  88. package/public/html-template.html +126 -0
  89. package/public/html-template.xhtml +45 -0
  90. package/public/html-template.xml +45 -0
  91. package/public/mockServiceWorker.js +284 -0
  92. package/public/tree.xsl +33 -0
  93. package/public/vite.svg +1 -0
  94. package/src/assets/lit.svg +1 -0
  95. package/src/custom-element/custom-element.d.ts +36 -0
  96. package/src/custom-element/custom-element.js +688 -0
  97. package/src/custom-element/demo/a.html +63 -0
  98. package/src/custom-element/demo/confused.svg +37 -0
  99. package/src/custom-element/demo/data-slices.html +184 -0
  100. package/src/custom-element/demo/dce-social-preview.png +0 -0
  101. package/src/custom-element/demo/demo.css +22 -0
  102. package/src/custom-element/demo/dom-merge.html +123 -0
  103. package/src/custom-element/demo/embed-1.html +3 -0
  104. package/src/custom-element/demo/external-template.html +179 -0
  105. package/src/custom-element/demo/hex-grid-dce.html +183 -0
  106. package/src/custom-element/demo/hex-grid-transform.png +0 -0
  107. package/src/custom-element/demo/hex-grid.html +66 -0
  108. package/src/custom-element/demo/html-template.html +126 -0
  109. package/src/custom-element/demo/html-template.xhtml +45 -0
  110. package/src/custom-element/demo/html-template.xml +45 -0
  111. package/src/custom-element/demo/http-request.html +143 -0
  112. package/src/custom-element/demo/local-storage.html +218 -0
  113. package/src/custom-element/demo/location-element.html +155 -0
  114. package/src/custom-element/demo/logo.png +0 -0
  115. package/src/custom-element/demo/parameters.html +70 -0
  116. package/src/custom-element/demo/s.xml +14 -0
  117. package/src/custom-element/demo/s.xslt +76 -0
  118. package/src/custom-element/demo/scoped-css.html +169 -0
  119. package/src/custom-element/demo/ss.html +57 -0
  120. package/src/custom-element/demo/table.xml +25 -0
  121. package/src/custom-element/demo/table.xsl +293 -0
  122. package/src/custom-element/demo/template.xsl +46 -0
  123. package/src/custom-element/demo/tree.xml +25 -0
  124. package/src/custom-element/demo/tree.xsl +33 -0
  125. package/src/custom-element/demo/wc-square.svg +1 -0
  126. package/src/custom-element/demo/xhtml-template.xhtml +45 -0
  127. package/src/custom-element/demo/z.html +62 -0
  128. package/src/custom-element/demo/z.xml +60 -0
  129. package/src/custom-element/http-request.js +89 -0
  130. package/src/custom-element/ide/IDE.md +31 -0
  131. package/src/custom-element/ide/customData-dce.json +112 -0
  132. package/src/custom-element/ide/customData-xsl.json +1018 -0
  133. package/src/custom-element/ide/web-types-dce.json +111 -0
  134. package/src/custom-element/ide/web-types-xsl.json +867 -0
  135. package/src/custom-element/index.html +168 -0
  136. package/src/custom-element/index.js +7 -0
  137. package/src/custom-element/local-storage.js +87 -0
  138. package/src/custom-element/location-element.js +87 -0
  139. package/src/custom-element.test.ts +10 -0
  140. package/src/index.css +38 -0
  141. package/src/mocks/handlers.ts +29 -0
  142. package/src/mocks/pokemons.mock.ts +13 -0
  143. package/src/stories/Configure.mdx +364 -0
  144. package/src/stories/assets/accessibility.png +0 -0
  145. package/src/stories/assets/accessibility.svg +5 -0
  146. package/src/stories/assets/addon-library.png +0 -0
  147. package/src/stories/assets/assets.png +0 -0
  148. package/src/stories/assets/avif-test-image.avif +0 -0
  149. package/src/stories/assets/context.png +0 -0
  150. package/src/stories/assets/discord.svg +15 -0
  151. package/src/stories/assets/docs.png +0 -0
  152. package/src/stories/assets/figma-plugin.png +0 -0
  153. package/src/stories/assets/github.svg +3 -0
  154. package/src/stories/assets/share.png +0 -0
  155. package/src/stories/assets/styling.png +0 -0
  156. package/src/stories/assets/testing.png +0 -0
  157. package/src/stories/assets/theming.png +0 -0
  158. package/src/stories/assets/tutorials.svg +12 -0
  159. package/src/stories/assets/youtube.svg +4 -0
  160. package/src/stories/attributes.stories.ts +132 -0
  161. package/src/stories/attributes.test.ts +14 -0
  162. package/src/stories/css.stories.ts +104 -0
  163. package/src/stories/css.test.ts +12 -0
  164. package/src/stories/dom-merge.stories.ts +113 -0
  165. package/src/stories/dom-merge.test.ts +12 -0
  166. package/src/stories/external-template.stories.ts +245 -0
  167. package/src/stories/external-template.test.ts +12 -0
  168. package/src/stories/http-request.stories.ts +244 -0
  169. package/src/stories/http-request.test.ts +29 -0
  170. package/src/stories/local-storage.stories.ts +388 -0
  171. package/src/stories/local-storage.test.ts +12 -0
  172. package/src/stories/location-element.stories.ts +133 -0
  173. package/src/stories/location-element.test.ts +14 -0
  174. package/src/stories/renderPlay.ts +22 -0
  175. package/src/stories/slice-events.stories.ts +117 -0
  176. package/src/stories/slice-events.test.ts +12 -0
  177. package/src/sum.test.ts +6 -0
  178. package/src/sum.ts +4 -0
  179. package/src/vite-env.d.ts +1 -0
  180. package/storybook-static/assets/Color-RQJUDNI5-C4yZhNbM.js +1 -0
  181. package/storybook-static/assets/Configure-C7d36rng.js +173 -0
  182. package/storybook-static/assets/DocsRenderer-K4EAMTCU-BLMupvSb.js +2 -0
  183. package/storybook-static/assets/WithTooltip-Y7J54OF7-BAQSPSFk.js +1 -0
  184. package/storybook-static/assets/accessibility-W_h2acOZ.png +0 -0
  185. package/storybook-static/assets/addon-library-BWUCAmyN.png +0 -0
  186. package/storybook-static/assets/attributes.stories-ZB0RTY1d.js +151 -0
  187. package/storybook-static/assets/context-C0qIqeS4.png +0 -0
  188. package/storybook-static/assets/css.stories-CLSX-Xxd.js +86 -0
  189. package/storybook-static/assets/custom-element-BLZZ00dz.js +53 -0
  190. package/storybook-static/assets/docs---vsFbMi.png +0 -0
  191. package/storybook-static/assets/dom-merge.stories-CgHZUABU.js +138 -0
  192. package/storybook-static/assets/entry-preview-CQqNFx4W.js +8 -0
  193. package/storybook-static/assets/entry-preview-docs-CWgqLfd3.js +2 -0
  194. package/storybook-static/assets/external-template.stories-DtSLMxvg.js +316 -0
  195. package/storybook-static/assets/figma-plugin-CH2hELiO.png +0 -0
  196. package/storybook-static/assets/formatter-B5HCVTEV-tKeEfJA9.js +58 -0
  197. package/storybook-static/assets/http-request.stories-CUzlXO89.js +300 -0
  198. package/storybook-static/assets/iframe-gCvlWuoC.js +2 -0
  199. package/storybook-static/assets/index-CBQwM6ST.js +508 -0
  200. package/storybook-static/assets/index-CDavW7r9.js +193 -0
  201. package/storybook-static/assets/index-CQA5dlr6.js +13 -0
  202. package/storybook-static/assets/index-Cc7K62zD.js +3 -0
  203. package/storybook-static/assets/index-DgaNIR0t.js +1 -0
  204. package/storybook-static/assets/index-Dkj0J1ds.js +1 -0
  205. package/storybook-static/assets/index-DnEJ_bKa.js +1 -0
  206. package/storybook-static/assets/index-DrFu-skq.js +6 -0
  207. package/storybook-static/assets/lit-element-B4_0akdT.js +19 -0
  208. package/storybook-static/assets/local-storage.stories-BkO6djDz.js +415 -0
  209. package/storybook-static/assets/location-element.stories-DCIOUd0D.js +108 -0
  210. package/storybook-static/assets/preview-B4GcaC1c.js +1 -0
  211. package/storybook-static/assets/preview-B63p-W8V.js +20 -0
  212. package/storybook-static/assets/preview-BAz7FMXc.js +396 -0
  213. package/storybook-static/assets/preview-BDY5ThwJ.js +1 -0
  214. package/storybook-static/assets/preview-C6t8KBFr.js +1 -0
  215. package/storybook-static/assets/preview-CYD85dwb.js +7 -0
  216. package/storybook-static/assets/preview-CkgAD_DE.js +2 -0
  217. package/storybook-static/assets/preview-D8LadFCz.js +48 -0
  218. package/storybook-static/assets/preview-DNpCpRPf.js +1 -0
  219. package/storybook-static/assets/preview-PxUn-cIn.js +1 -0
  220. package/storybook-static/assets/share-DGA-UcQf.png +0 -0
  221. package/storybook-static/assets/slice-events.stories-DXKjXI37.js +115 -0
  222. package/storybook-static/assets/styling-Bk6zjRzU.png +0 -0
  223. package/storybook-static/assets/syntaxhighlighter-JOJW2KGS-C04pIVD3.js +1 -0
  224. package/storybook-static/assets/testing-cbzR9l9r.png +0 -0
  225. package/storybook-static/assets/theming-D6WJLNoW.png +0 -0
  226. package/storybook-static/assets/tiny-invariant-BxWVcicq.js +1 -0
  227. package/storybook-static/confused.svg +37 -0
  228. package/storybook-static/embed-1.html +3 -0
  229. package/storybook-static/favicon.svg +7 -0
  230. package/storybook-static/html-template.html +126 -0
  231. package/storybook-static/html-template.xhtml +45 -0
  232. package/storybook-static/html-template.xml +45 -0
  233. package/storybook-static/iframe.html +492 -0
  234. package/storybook-static/index.html +163 -0
  235. package/storybook-static/index.json +1 -0
  236. package/storybook-static/mockServiceWorker.js +284 -0
  237. package/storybook-static/project.json +1 -0
  238. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js +327 -0
  239. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js.LEGAL.txt +40 -0
  240. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +3 -0
  241. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
  242. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +12 -0
  243. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
  244. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +60 -0
  245. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +18 -0
  246. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +3 -0
  247. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
  248. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +3 -0
  249. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
  250. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +3 -0
  251. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
  252. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +3 -0
  253. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
  254. package/storybook-static/sb-addons/interactions-10/manager-bundle.js +33 -0
  255. package/storybook-static/sb-addons/interactions-10/manager-bundle.js.LEGAL.txt +0 -0
  256. package/storybook-static/sb-addons/links-1/manager-bundle.js +3 -0
  257. package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
  258. package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +3 -0
  259. package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
  260. package/storybook-static/sb-common-assets/fonts.css +31 -0
  261. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  262. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  263. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  264. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  265. package/storybook-static/sb-manager/WithTooltip-Y7J54OF7-CEHQ77YF.js +1 -0
  266. package/storybook-static/sb-manager/chunk-E3WK6ZOZ.js +234 -0
  267. package/storybook-static/sb-manager/chunk-E6ABNH5R.js +183 -0
  268. package/storybook-static/sb-manager/chunk-FEE35O7J.js +9 -0
  269. package/storybook-static/sb-manager/chunk-S4VOIVUE.js +347 -0
  270. package/storybook-static/sb-manager/chunk-XCO5HRLK.js +6 -0
  271. package/storybook-static/sb-manager/chunk-XP3HGWTR.js +1 -0
  272. package/storybook-static/sb-manager/formatter-B5HCVTEV-7DCBOGO6.js +58 -0
  273. package/storybook-static/sb-manager/globals-module-info.js +1 -0
  274. package/storybook-static/sb-manager/globals-runtime.js +1 -0
  275. package/storybook-static/sb-manager/globals.js +1 -0
  276. package/storybook-static/sb-manager/index.js +1 -0
  277. package/storybook-static/sb-manager/runtime.js +1 -0
  278. package/storybook-static/sb-manager/syntaxhighlighter-JOJW2KGS-VF6EEVPI.js +1 -0
  279. package/storybook-static/sb-preview/globals.js +1 -0
  280. package/storybook-static/sb-preview/runtime.js +139 -0
  281. package/storybook-static/tree.xsl +33 -0
  282. package/storybook-static/vite.svg +1 -0
  283. package/tsconfig.json +25 -0
  284. package/vite.config.js +55 -0
@@ -0,0 +1,104 @@
1
+ import type {StoryObj} from "@storybook/web-components";
2
+ import {within, expect} from "@storybook/test";
3
+
4
+ import '../custom-element/custom-element.js';
5
+
6
+ type CssProps = { title: string; tag: string; style: string; slot: string; payload: string };
7
+ const defs = {title: '', tag: '', style: '', slot: '', payload: ''};
8
+
9
+ type Story = StoryObj<CssProps>;
10
+
11
+ function render(args: CssProps) {
12
+ const {title, tag, style, slot, payload} = { ...defs, ...args };
13
+ return `
14
+ <fieldset>
15
+ <legend>${ title }</legend>
16
+ <custom-element ${ tag ? `tag="${tag}"` : ''} >
17
+ <template>
18
+ <style>
19
+ ${ style }
20
+ </style>
21
+ <u><slot>${ slot }</slot></u>
22
+ </template>
23
+ </custom-element>
24
+ ${ payload }
25
+ </fieldset>
26
+ `;
27
+ }
28
+
29
+ const meta = { title: 'Css', render };
30
+
31
+ export default meta;
32
+
33
+ const GREEN = `<b style="color:green">green</b>`
34
+ const RED = `<i style="color:red">red</i>`
35
+
36
+ export const StyleDoesNotLeak: Story =
37
+ { args:
38
+ { title: `The default color should stay on this label, the message inside should be ${GREEN}`
39
+ , style: `color:green`
40
+ , slot: 'text has to be green'
41
+ , payload: '<u>no tags</u>'
42
+ }
43
+ , play: async ({canvasElement}) =>
44
+ { const canvas = within(canvasElement);
45
+ const el = await canvas.findByText('text has to be green');
46
+ const st = getComputedStyle(el);
47
+ const color = st.getPropertyValue('color');
48
+ // @ts-ignore
49
+ expect(color).to.equal('rgb(0, 128, 0)')
50
+ },
51
+ };
52
+
53
+ export const StyleIn2Instances: Story =
54
+ { args:
55
+ { title: `The default color should apply ${GREEN} in all instances`
56
+ , style: `color:green`
57
+ , slot: 'text has to be green'
58
+ , tag: 'dce-2'
59
+ , payload: `<u>2 instances:</u> <dce-2 id="dce21"></dce-2> * <dce-2 id="dce22"></dce-2>`
60
+ }
61
+ , play: async ({canvasElement}) =>
62
+ {
63
+ await within(canvasElement).findByText('2 instances:');
64
+ const color = ( css:string )=>
65
+ { const el = canvasElement.querySelector(css);
66
+ const st = getComputedStyle( el! );
67
+ return st.getPropertyValue('color');
68
+ };
69
+ expect( color('legend' ) ).to.not.equal(color('b'));
70
+ expect( color('legend' ) ).to.not.equal(color('b'));
71
+ expect( color('#dce21 u') ).to .equal(color('b'));
72
+ expect( color('#dce22 u') ).to .equal(color('b'));
73
+ },
74
+ };
75
+
76
+ // noinspection CssInvalidPseudoSelector
77
+ export const OverrideInPayload: Story =
78
+ { args:
79
+ { title: `${GREEN} in instance style can be overridden in payload as ${RED} in 1st instance`
80
+ , style: `color:green`
81
+ , slot: 'is green'
82
+ , tag: 'dce-3'
83
+ , payload: ` <u>should be</u> ${RED}:<dce-3 id="dce32">
84
+ <template>
85
+ <style> color:red; </style>
86
+ <u>red</u>
87
+ </template>
88
+ </dce-3> <br/>
89
+ should be ${GREEN}: <dce-3 id="dce31">green</dce-3> `
90
+ }
91
+ , play: async ({canvasElement}) =>
92
+ {
93
+ await within(canvasElement).findByText('should be');
94
+
95
+ const color = ( css:string )=>
96
+ { const el = canvasElement.querySelector(css);
97
+ const st = getComputedStyle( el! );
98
+ return st.getPropertyValue('color');
99
+ };
100
+ expect( color('legend' ) ).to.not.equal(color('b'));
101
+ expect( color('#dce31 u') ).to .equal(color('b'));
102
+ expect( color('#dce32 u') ).to .equal(color('i'));
103
+ },
104
+ };
@@ -0,0 +1,12 @@
1
+ import {describe} from 'vitest';
2
+
3
+ import '../custom-element/custom-element.js';
4
+ import meta from "./css.stories.ts";
5
+
6
+ import * as Stories from "./css.stories.ts";
7
+ import {playStories} from './renderPlay';
8
+
9
+ describe('Css', () =>
10
+ {
11
+ playStories( Stories, meta );
12
+ });
@@ -0,0 +1,113 @@
1
+ // noinspection DuplicatedCode
2
+
3
+ import type { StoryObj } from '@storybook/web-components';
4
+ import {expect, getByTestId, within, userEvent} from '@storybook/test';
5
+
6
+ import '../custom-element/custom-element.js';
7
+
8
+ type TProps = { title: string; body:string};
9
+
10
+ type Story = StoryObj<TProps>;
11
+ function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); }
12
+
13
+ function render(args: TProps)
14
+ {
15
+ const {title, body} = args;
16
+ return `
17
+ <fieldset>
18
+ <legend>${ title }</legend>
19
+ ${ body }
20
+ </fieldset>
21
+ `;
22
+ }
23
+ const meta =
24
+ { title: 'dom-merge'
25
+ , render
26
+ };
27
+
28
+ export default meta;
29
+
30
+ export const CharsCountInTextarea:Story =
31
+ { args : {title: 'Chars count in textarea', body:`
32
+ <p>Counter update happens on change event(focus change). The update should not interfere with the input</p>
33
+ <custom-element>
34
+ <form>
35
+ <label>
36
+ <textarea slice="text-container" data-testid="textarea-id">Hello world!</textarea>
37
+ <span> Chars count:
38
+ <code data-testid="counter-id">{string-length(//slice/text-container/text())}</code>
39
+ </span>
40
+ </label>
41
+ <br/><input placeholder="after textarea input, click here " data-testid="refocus-id" />
42
+ </form>
43
+ </custom-element>
44
+ `}
45
+ , play: async ({canvasElement}) =>
46
+ {
47
+ const titleText = CharsCountInTextarea.args!.title as string;
48
+ const canvas = within(canvasElement);
49
+ await canvas.findByText(titleText);
50
+ await sleep(100);
51
+ expect(await canvas.findByTestId('textarea-id')).toBeInTheDocument();
52
+ const textarea = canvas.getByTestId('textarea-id');
53
+ textarea.value ='';
54
+ textarea.focus();
55
+ await userEvent.keyboard(titleText);
56
+ expect(textarea.value).toEqual(titleText);
57
+ expect(textarea.value.length).toEqual(titleText.length);
58
+ debugger;
59
+ canvas.getByTestId('refocus-id').focus();
60
+ await sleep(10);
61
+ expect(canvas.getByTestId('counter-id').textContent).toEqual(''+titleText?.length,'counter of symbols');
62
+ },
63
+ };
64
+
65
+ export const WordCountOnType:Story =
66
+ { args : {title: 'Word count in HTML input field', body:`
67
+ <p>Counter update happens on keyup event. The update should not interfere with the input</p>
68
+ <custom-element>
69
+ <form>
70
+ <label>
71
+ <input type="text" value="{//txt ?? 'Type time update'}" slice="txt" slice-event="init input" data-testid="input-id">
72
+
73
+ <span> Character count:
74
+ <code data-testid="chars-id"
75
+ >{
76
+ string-length(//slice/txt)
77
+ }</code>
78
+ </span>
79
+ <span> Word count:
80
+ <code data-testid="words-id"
81
+ >{
82
+ string-length(normalize-space(//slice/txt)) -
83
+ string-length(translate(normalize-space(//slice/txt), ' ', '')) + 1
84
+ }</code>
85
+ <!-- The expression first normalizes the string by removing leading and trailing whitespace and
86
+ collapsing internal whitespace into a single space. It then subtracts the length of the string
87
+ with all spaces removed from the length of the original string,
88
+ and adds 1 to account for the last word.
89
+ -->
90
+ </span>
91
+
92
+ </label>
93
+ <p><b>txt</b> slice:</p> <blockquote> {//slice/txt} </blockquote>
94
+ </form>
95
+ </custom-element>
96
+ `}
97
+ , play: async ({canvasElement}) =>
98
+ {
99
+ const titleText = WordCountOnType.args!.title as string;
100
+ const canvas = within(canvasElement);
101
+ await canvas.findByText(titleText);
102
+ const input = await canvas.findByTestId('input-id');
103
+ input.value = '';
104
+ input.focus();
105
+ expect(input).toBeInTheDocument();
106
+ await userEvent.keyboard(titleText);
107
+ await sleep(10);
108
+ expect(input.value).toEqual(titleText);
109
+ expect(canvas.getByTestId('chars-id').textContent.trim()).toEqual(''+titleText.length, 'counter of symbols');
110
+ expect(titleText.split(' ').length).toEqual(6, 'counter of words in text sample');
111
+ expect(canvas.getByTestId('words-id').textContent.trim()).toEqual('6', 'counter of words in render');
112
+ },
113
+ };
@@ -0,0 +1,12 @@
1
+ import {describe, it} from 'vitest';
2
+
3
+ import '../custom-element/custom-element.js';
4
+ import meta from "./dom-merge.stories.ts";
5
+
6
+ import * as Stories from "./dom-merge.stories.ts";
7
+ import {playStories} from './renderPlay';
8
+
9
+ describe('dom-merge', () => {
10
+ localStorage.clear();
11
+ playStories( Stories, meta );
12
+ });
@@ -0,0 +1,245 @@
1
+ // noinspection DuplicatedCode
2
+
3
+ import type { StoryObj } from '@storybook/web-components';
4
+ import {expect, getByTestId, within} from '@storybook/test';
5
+
6
+ import '../custom-element/custom-element.js';
7
+
8
+ type TProps = { title: string; body:string};
9
+
10
+ type Story = StoryObj<TProps>;
11
+ function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); }
12
+
13
+ function render(args: TProps)
14
+ {
15
+ const {title, body} = args;
16
+ return `
17
+ <fieldset>
18
+ <legend>${ title }</legend>
19
+ ${ body }
20
+ </fieldset>
21
+ `;
22
+ }
23
+ const meta =
24
+ { title: 'external-templates'
25
+ , render
26
+ };
27
+
28
+ export default meta;
29
+
30
+ export const TemplateInPage:Story =
31
+ { args : {title: 'Template in page DOM', body:`
32
+ <template id="template1">
33
+ <slot>Hello</slot> World!
34
+ </template>
35
+
36
+ <custom-element tag="dce-internal" src="#template1"></custom-element>
37
+ <!-- no need for loading fallback as the template exists -->
38
+
39
+ <dce-internal data-testid="slot-override">👋</dce-internal>
40
+ <dce-internal data-testid="slot-default"></dce-internal>
41
+ `}
42
+ , play: async ({canvasElement}) =>
43
+ {
44
+ const canvas = within(canvasElement);
45
+ await canvas.findByText(TemplateInPage.args!.title as string);
46
+ const val = (prop)=> canvas.getByTestId(prop).textContent.trim();
47
+
48
+ expect(val('slot-override')).toEqual('👋 World!');
49
+ expect(val('slot-default' )).toEqual('Hello World!');
50
+ },
51
+ };
52
+
53
+ export const NoTag:Story =
54
+ { args : {title: 'no tag, template in same DOM', body:`
55
+ <template id="template2">
56
+ 🏗️ construction
57
+ </template>
58
+
59
+ <custom-element src="#template2"></custom-element>
60
+ <custom-element src="#template2"></custom-element>`}
61
+ , play: async ({canvasElement}) =>
62
+ {
63
+ const canvas = within(canvasElement);
64
+ await canvas.findByText(NoTag.args!.title as string);
65
+
66
+ expect(canvasElement.querySelectorAll('custom-element')[0].textContent.trim()).toEqual('🏗️ construction');
67
+ expect(canvasElement.querySelectorAll('custom-element')[1].textContent.trim()).toEqual('🏗️ construction');
68
+ },
69
+ };
70
+
71
+ export const ExternalSvg:Story =
72
+ { args : {title: 'External SVG as template', body:`
73
+ <custom-element tag="dce-external" src="/confused.svg">
74
+ <template><i>loading from SVG ...</i></template>
75
+ </custom-element>
76
+ <dce-external></dce-external>
77
+ <custom-element src="confused.svg">
78
+ <i>inline DCE loading from SVG ...</i>
79
+ </custom-element>
80
+ <custom-element src="no.svg">
81
+ <i>fallback for missing image</i>
82
+ </custom-element>
83
+ `}
84
+ , play: async ({canvasElement}) =>
85
+ {
86
+ const canvas = within(canvasElement);
87
+ await canvas.findByText(ExternalSvg.args!.title as string);
88
+ expect(canvasElement.querySelector('[src="confused.svg"]').innerHTML).to.include('loading from SVG ...');
89
+ await sleep(100);
90
+ expect(canvasElement.querySelector('dce-external').innerHTML).to.include('<svg');
91
+ expect(canvasElement.querySelector('[src="no.svg"]').innerHTML).to.include('Vitest Browser Tester');
92
+ // "fallback for missing image" is not shown in test as test does not return 404, see test on 404 instead
93
+ },
94
+ };
95
+
96
+ export const ExternalXsltFile:Story =
97
+ { args : {title: 'External XSLT file', body:`
98
+ <custom-element tag="dce-external-4" src="/tree.xsl">
99
+ <template><i>loading from XSLT ...</i></template>
100
+ </custom-element>
101
+ <dce-external-4 title="DCE with external XSLT template" data-fruit="🍌">Hi</dce-external-4>
102
+ <hr/>
103
+ <custom-element src="/tree.xsl" data-smile="👼" data-basket="🍒">
104
+ <i>inline DCE loading from XSLT ...</i>
105
+ </custom-element>
106
+ `}
107
+ , play: async ({canvasElement}) =>
108
+ {
109
+ const canvas = within(canvasElement);
110
+ await canvas.findByText(ExternalXsltFile.args!.title as string);
111
+ expect(canvasElement.querySelector('dce-external-4').innerHTML).to.include('Hi');
112
+ expect(canvasElement.querySelector('[data-smile="👼"]').innerHTML).to.include('loading from XSLT ...');
113
+ await sleep(100);
114
+ expect(canvas.getByTestId('data-fruit').innerHTML).to.include('🍌');
115
+ expect(canvas.getByTestId('data-smile').innerHTML).to.include('👼');
116
+ },
117
+ };
118
+
119
+ export const ExternalHtmlFile:Story =
120
+ { args : {title: 'external HTML template', body:`
121
+ <custom-element tag="dce-external-5" src="/html-template.html">
122
+ <template><i>loading from HTML file ...</i></template>
123
+ </custom-element>
124
+ <dce-external-5 title="DCE with external XSLT template" data-fruit="🍌">Hi</dce-external-5>
125
+ `}
126
+ , play: async ({canvasElement}) =>
127
+ {
128
+ const canvas = within(canvasElement);
129
+ await canvas.findByText(ExternalHtmlFile.args!.title as string);
130
+ await canvas.findByText('👋');
131
+ const t5 = canvasElement.querySelector('dce-external-5').innerHTML;
132
+ expect(t5).to.include('👋');
133
+ expect(t5).to.include('👌');
134
+ expect(t5).to.include('<svg');
135
+ expect(t5).to.include('<math');
136
+ },
137
+ };
138
+
139
+ export const ExternalHtmlFileInline:Story =
140
+ { args : {title: 'external HTML template', body:`
141
+ <custom-element src="/html-template.html" data-smile="👼" data-basket="🍒">
142
+ <i>inline DCE loading from HTML file ...</i>
143
+ </custom-element>
144
+ `}
145
+ , play: async ({canvasElement}) =>
146
+ {
147
+ const canvas = within(canvasElement);
148
+ await canvas.findByText(ExternalHtmlFileInline.args!.title as string);
149
+ await canvas.findByText('👋');
150
+ const t5 = canvasElement.innerHTML;
151
+ expect(t5).to.include('👋');
152
+ expect(t5).to.include('👌');
153
+ expect(t5).to.include('<svg');
154
+ expect(t5).to.include('<math');
155
+ },
156
+ };
157
+
158
+ export const HtmlWithinHtmlFile:Story =
159
+ { args : {title: 'external HTML template - html by id', body:`
160
+ <custom-element src="/html-template.html#wave">
161
+ <template><i>loading HTML from templates file ...</i></template>
162
+ </custom-element>
163
+ `}
164
+ , play: async ({canvasElement}) =>
165
+ {
166
+ const canvas = within(canvasElement);
167
+ await canvas.findByText(HtmlWithinHtmlFile.args!.title as string);
168
+ expect(await canvas.findByText('👋')).toBeInTheDocument();
169
+ },
170
+ };
171
+
172
+ export const SvgWithinHtmlFile:Story =
173
+ { args : {title: 'external HTML template - SVG by id', body:`
174
+ <custom-element src="/html-template.html#dwc-logo">
175
+ <template><i>loading SVG from templates file ...</i></template>
176
+ </custom-element>
177
+ `}
178
+ , play: async ({canvasElement}) =>
179
+ {
180
+ const canvas = within(canvasElement);
181
+ await canvas.findByText(SvgWithinHtmlFile.args!.title as string);
182
+ expect(await canvas.findByTestId('svg-test')).toBeInTheDocument();
183
+ },
184
+ };
185
+
186
+ export const MathMLWithinHtmlFile:Story =
187
+ { args : {title: 'external HTML template - MathML by id', body:`
188
+ <custom-element src="/html-template.html#sophomores-dream">
189
+ <template><i>loading MathML from HTML file ...</i></template>
190
+ </custom-element>
191
+ `}
192
+ , play: async ({canvasElement}) =>
193
+ {
194
+ const canvas = within(canvasElement);
195
+ await canvas.findByText(MathMLWithinHtmlFile.args!.title as string);
196
+ const ml = await canvas.findByTestId('ml-test');
197
+ debugger;
198
+ expect(ml.firstElementChild.localName).toEqual('mrow');
199
+ },
200
+ };
201
+
202
+ export const ByIdWithinXsltFile:Story =
203
+ { args : {title: 'external XHTML template - xsl by id', body:`
204
+ <custom-element src="/html-template.xhtml#embedded-xsl">
205
+ <template>whole XSLT is embedded into HTML body</template>
206
+ </custom-element>
207
+ `}
208
+ , play: async ({canvasElement}) =>
209
+ {
210
+ const canvas = within(canvasElement);
211
+ await canvas.findByText(ByIdWithinXsltFile.args!.title as string);
212
+ const ml = await canvas.findByTestId('src');
213
+ expect(ml.textContent).to.include('/html-template.xhtml#embedded-xsl');
214
+ },
215
+ };
216
+ export const MissingIdWithinXsltFile:Story =
217
+ { args : {title: 'external HTML template - missing id', body:`
218
+ <custom-element src="/html-template.html#none">
219
+ <template><i data-testid="no-id">element with id=none is missing in template</i></template>
220
+ </custom-element>
221
+ `}
222
+ , play: async ({canvasElement}) =>
223
+ {
224
+ const canvas = within(canvasElement);
225
+ await canvas.findByText(MissingIdWithinXsltFile.args!.title as string);
226
+ await sleep(100);
227
+ const ml = await canvas.findByTestId('no-id');
228
+ expect(ml.textContent).to.include('element with id=none is missing in template');
229
+ },
230
+ };
231
+ export const EmbeddingInAnotherFile:Story =
232
+ { args : {title: 'external file with embedding of another external DCE', body:`
233
+ <custom-element src="/embed-1.html">
234
+ loading from embed-1.html ...
235
+ </custom-element>
236
+ `}
237
+ , play: async ({canvasElement}) =>
238
+ {
239
+ const canvas = within(canvasElement);
240
+ await canvas.findByText(EmbeddingInAnotherFile.args!.title as string);
241
+ await sleep(100);
242
+ expect(await canvas.findByTestId('wave')).toBeInTheDocument();
243
+ expect(canvas.getByTestId('wave').innerHTML).toEqual('🖖');
244
+ },
245
+ };
@@ -0,0 +1,12 @@
1
+ import {describe, it} from 'vitest';
2
+
3
+ import '../custom-element/custom-element.js';
4
+ import meta from "./external-template.stories.ts";
5
+
6
+ import * as Stories from "./external-template.stories.ts";
7
+ import {playStories} from './renderPlay';
8
+
9
+ describe('external-template', () => {
10
+ localStorage.clear();
11
+ playStories( Stories, meta );
12
+ });