@twobirds/microcomponents 0.0.82 → 0.0.84

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 (268) hide show
  1. package/assets/documentation/MC.md +0 -1
  2. package/assets/test/test.html +1 -1
  3. package/dist/MC.d.ts +11 -10
  4. package/dist/MC.d.ts.map +1 -1
  5. package/dist/MC.js +137 -200
  6. package/dist/MC.min.js +157 -296
  7. package/dist/MC.ts +202 -337
  8. package/dist/elements.d.ts +1 -1
  9. package/dist/elements.d.ts.map +1 -1
  10. package/dist/elements.js +26 -6
  11. package/dist/elements.min.js +1 -1
  12. package/dist/elements.ts +50 -7
  13. package/dist/formValues.js +2 -2
  14. package/dist/formValues.min.js +1 -1
  15. package/dist/formValues.ts +3 -3
  16. package/dist/microcomponents.d.ts +0 -1
  17. package/dist/microcomponents.d.ts.map +1 -1
  18. package/dist/microcomponents.js +0 -1
  19. package/dist/microcomponents.min.js +1 -1
  20. package/dist/microcomponents.ts +1 -1
  21. package/dist/observables.d.ts.map +1 -1
  22. package/dist/observables.js +52 -57
  23. package/dist/observables.min.js +1 -1
  24. package/dist/observables.ts +68 -73
  25. package/package.json +6 -5
  26. package/public/MC.d.ts +11 -10
  27. package/public/MC.d.ts.map +1 -1
  28. package/public/MC.js +137 -200
  29. package/public/MC.js.map +1 -1
  30. package/public/MC.min.js +157 -296
  31. package/public/MC.ts +202 -337
  32. package/public/documentation/MC.md +0 -1
  33. package/public/elements.d.ts +1 -1
  34. package/public/elements.d.ts.map +1 -1
  35. package/public/elements.js +26 -6
  36. package/public/elements.js.map +1 -1
  37. package/public/elements.min.js +1 -1
  38. package/public/elements.ts +50 -7
  39. package/public/formValues.js +2 -2
  40. package/public/formValues.js.map +1 -1
  41. package/public/formValues.min.js +1 -1
  42. package/public/formValues.ts +3 -3
  43. package/public/microcomponents.d.ts +0 -1
  44. package/public/microcomponents.d.ts.map +1 -1
  45. package/public/microcomponents.js +0 -1
  46. package/public/microcomponents.js.map +1 -1
  47. package/public/microcomponents.min.js +1 -1
  48. package/public/microcomponents.ts +1 -1
  49. package/public/observables.d.ts.map +1 -1
  50. package/public/observables.js +52 -57
  51. package/public/observables.js.map +1 -1
  52. package/public/observables.min.js +1 -1
  53. package/public/observables.ts +68 -73
  54. package/public/{test/selectors.ts → selectors._ts} +2 -367
  55. package/public/src/MC.d.ts +37 -0
  56. package/public/src/MC.d.ts.map +1 -0
  57. package/public/src/MC.js +316 -0
  58. package/public/src/MC.js.map +1 -0
  59. package/public/src/MC.ts +202 -337
  60. package/public/src/elements.d.ts +5 -0
  61. package/public/src/elements.d.ts.map +1 -0
  62. package/public/src/elements.js +68 -0
  63. package/public/src/elements.js.map +1 -0
  64. package/public/src/elements.ts +50 -7
  65. package/public/src/formValues.d.ts +3 -0
  66. package/public/src/formValues.d.ts.map +1 -0
  67. package/public/src/formValues.js +162 -0
  68. package/public/src/formValues.js.map +1 -0
  69. package/public/src/formValues.ts +3 -3
  70. package/public/src/helpers.d.ts +14 -0
  71. package/public/src/helpers.d.ts.map +1 -0
  72. package/public/src/helpers.js +113 -0
  73. package/public/src/microcomponents.d.ts +6 -0
  74. package/public/src/microcomponents.d.ts.map +1 -0
  75. package/public/src/microcomponents.js +7 -0
  76. package/public/src/microcomponents.js.map +1 -0
  77. package/public/src/microcomponents.ts +1 -1
  78. package/public/src/observables.d.ts +11 -0
  79. package/public/src/observables.d.ts.map +1 -0
  80. package/public/src/observables.js +244 -0
  81. package/public/src/observables.js.map +1 -0
  82. package/public/src/observables.ts +68 -73
  83. package/public/{selectors.ts → src/selectors._ts} +2 -367
  84. package/public/src/test/grandparent.css +11 -0
  85. package/public/src/test/test/child.d.ts +2 -0
  86. package/public/src/test/test/child.d.ts.map +1 -0
  87. package/public/src/test/test/child.js +15 -0
  88. package/public/src/test/test/child.js.map +1 -0
  89. package/public/src/test/test/child.ts +21 -0
  90. package/public/src/test/test/grandchild.d.ts +2 -0
  91. package/public/src/test/test/grandchild.d.ts.map +1 -0
  92. package/public/src/test/test/grandchild.js +15 -0
  93. package/public/src/test/test/grandchild.js.map +1 -0
  94. package/public/src/test/test/grandchild.ts +21 -0
  95. package/public/src/test/test/grandparent.d.ts +2 -0
  96. package/public/src/test/test/grandparent.d.ts.map +1 -0
  97. package/public/src/test/test/grandparent.js +1 -0
  98. package/public/src/test/test/grandparent.js.map +1 -0
  99. package/public/src/test/test/grandparent.ts +29 -0
  100. package/public/src/test/test/greatgrandchild.d.ts +2 -0
  101. package/public/src/test/test/greatgrandchild.d.ts.map +1 -0
  102. package/public/src/test/test/greatgrandchild.js +29 -0
  103. package/public/src/test/test/greatgrandchild.js.map +1 -0
  104. package/public/src/test/test/greatgrandchild.ts +42 -0
  105. package/public/src/test/test/parent.d.ts +2 -0
  106. package/public/src/test/test/parent.d.ts.map +1 -0
  107. package/public/src/test/test/parent.js +15 -0
  108. package/public/src/test/test/parent.js.map +1 -0
  109. package/public/src/test/test/parent.ts +21 -0
  110. package/public/src/test/test/testform.d.ts +2 -0
  111. package/public/src/test/test/testform.d.ts.map +1 -0
  112. package/public/src/test/test/testform.js +1 -0
  113. package/public/src/test/test/testform.js.map +1 -0
  114. package/public/src/test/test/testform.ts +153 -0
  115. package/public/src/test/test/testfunction.d.ts +3 -0
  116. package/public/src/test/test/testfunction.d.ts.map +1 -0
  117. package/public/src/test/test/testfunction.js +7 -0
  118. package/public/src/test/test/testfunction.js.map +1 -0
  119. package/public/src/test/test/testfunction.ts +12 -0
  120. package/public/src/test/test/testmc.d.ts +3 -0
  121. package/public/src/test/test/testmc.d.ts.map +1 -0
  122. package/public/src/test/test/testmc.js +10 -0
  123. package/public/src/test/test/testmc.js.map +1 -0
  124. package/public/src/test/test/testmc.ts +16 -0
  125. package/public/src/test/test/testsimpleclass.d.ts +3 -0
  126. package/public/src/test/test/testsimpleclass.d.ts.map +1 -0
  127. package/public/src/test/test/testsimpleclass.js +9 -0
  128. package/public/src/test/test/testsimpleclass.js.map +1 -0
  129. package/public/src/test/test/testsimpleclass.ts +15 -0
  130. package/public/src/test/test.d.ts +2 -0
  131. package/public/src/test/test.d.ts.map +1 -0
  132. package/public/src/test/test.js +80 -0
  133. package/public/src/test/test.js.map +1 -0
  134. package/public/src/test/test.ts +188 -0
  135. package/public/src/test/testform.css +47 -0
  136. package/public/src/test/testform.html +56 -0
  137. package/public/src/test/testform.json +27 -0
  138. package/public/test/MC.d.ts +11 -10
  139. package/public/test/MC.d.ts.map +1 -1
  140. package/public/test/MC.js +137 -200
  141. package/public/test/MC.min.js +377 -0
  142. package/public/test/MC.ts +202 -337
  143. package/public/test/elements.d.ts +1 -1
  144. package/public/test/elements.d.ts.map +1 -1
  145. package/public/test/elements.js +26 -6
  146. package/public/test/elements.min.js +1 -0
  147. package/public/test/elements.ts +50 -7
  148. package/public/test/formValues.js +2 -2
  149. package/public/test/formValues.min.js +1 -0
  150. package/public/test/formValues.ts +3 -3
  151. package/public/test/grandparent.css +1 -3
  152. package/public/test/microcomponents.d.ts +0 -1
  153. package/public/test/microcomponents.d.ts.map +1 -1
  154. package/public/test/microcomponents.js +0 -1
  155. package/public/test/microcomponents.min.js +1 -1
  156. package/public/test/microcomponents.ts +1 -1
  157. package/public/test/observables.d.ts.map +1 -1
  158. package/public/test/observables.js +52 -57
  159. package/public/test/observables.min.js +1 -0
  160. package/public/test/observables.ts +68 -73
  161. package/public/test/test/child.ts +21 -0
  162. package/public/test/test/grandchild.ts +21 -0
  163. package/public/test/test/grandparent.d.ts.map +1 -1
  164. package/public/test/test/grandparent.js +1 -1
  165. package/public/test/test/grandparent.js.map +1 -1
  166. package/public/test/test/grandparent.ts +29 -0
  167. package/public/test/test/greatgrandchild.ts +42 -0
  168. package/public/test/test/parent.ts +21 -0
  169. package/public/test/test/testform.js +1 -1
  170. package/public/test/test/testform.js.map +1 -1
  171. package/public/test/test/testform.ts +153 -0
  172. package/public/test/test/testfunction.d.ts +3 -0
  173. package/public/test/test/testfunction.d.ts.map +1 -0
  174. package/public/test/test/testfunction.js +7 -0
  175. package/public/test/test/testfunction.js.map +1 -0
  176. package/public/test/test/testfunction.ts +12 -0
  177. package/public/test/test/testmc.d.ts +2 -5
  178. package/public/test/test/testmc.d.ts.map +1 -1
  179. package/public/test/test/testmc.js +4 -4
  180. package/public/test/test/testmc.js.map +1 -1
  181. package/public/test/test/testmc.ts +16 -0
  182. package/public/test/test/testsimpleclass.d.ts +3 -0
  183. package/public/test/test/testsimpleclass.d.ts.map +1 -0
  184. package/public/test/test/testsimpleclass.js +9 -0
  185. package/public/test/test/testsimpleclass.js.map +1 -0
  186. package/public/test/test/testsimpleclass.ts +15 -0
  187. package/public/test/test.html +1 -1
  188. package/public/test/test.js +5 -6
  189. package/public/test/test.js.map +1 -1
  190. package/public/test/test.ts +188 -0
  191. package/public/test/testform.css +47 -0
  192. package/public/test/testform.html +56 -0
  193. package/public/test/testform.json +3 -3
  194. package/public/typedoc/assets/navigation.js +1 -1
  195. package/public/typedoc/assets/search.js +1 -1
  196. package/public/typedoc/classes/MC.DC.html +6 -4
  197. package/public/typedoc/classes/MC.MC.html +3 -4
  198. package/public/typedoc/classes/MC.McBase.html +2 -2
  199. package/public/typedoc/functions/MC.autoload.html +1 -1
  200. package/public/typedoc/functions/MC.off.html +1 -0
  201. package/public/typedoc/functions/MC.on.html +1 -0
  202. package/public/typedoc/functions/MC.one.html +1 -0
  203. package/public/typedoc/functions/elements.defineCE.html +1 -1
  204. package/public/typedoc/functions/elements.getCE.html +1 -1
  205. package/public/typedoc/functions/formValues.formValues.html +1 -1
  206. package/public/typedoc/functions/observables.observe.html +1 -1
  207. package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
  208. package/public/typedoc/modules/MC.html +7 -6
  209. package/public/typedoc/modules/elements.html +1 -1
  210. package/public/typedoc/modules/formValues.html +1 -1
  211. package/public/typedoc/modules/observables.html +1 -1
  212. package/public/typedoc/types/observables.Observable.html +1 -1
  213. package/src/MC.ts +202 -337
  214. package/src/elements.ts +50 -7
  215. package/src/formValues.ts +3 -3
  216. package/src/microcomponents.ts +1 -1
  217. package/src/observables.ts +68 -73
  218. package/{dist/selectors.ts → src/selectors._ts} +2 -367
  219. package/src/test/test/grandparent.ts +12 -4
  220. package/src/test/test/testform.ts +13 -11
  221. package/src/test/test/testfunction.ts +12 -0
  222. package/src/test/test/testmc.ts +13 -9
  223. package/src/test/test/testsimpleclass.ts +15 -0
  224. package/src/test/test.ts +8 -20
  225. package/tasks.md +36 -0
  226. package/tsconfig.json +2 -2
  227. package/typedoc.json +1 -1
  228. package/webpack.config.js +2 -2
  229. package/dist/McEvent.d.ts +0 -15
  230. package/dist/McEvent.d.ts.map +0 -1
  231. package/dist/McEvent.js +0 -71
  232. package/dist/selectors.d.ts +0 -108
  233. package/dist/selectors.d.ts.map +0 -1
  234. package/dist/selectors.js +0 -971
  235. package/dist/selectors.min.js +0 -1
  236. package/public/McEvent.d.ts +0 -15
  237. package/public/McEvent.d.ts.map +0 -1
  238. package/public/McEvent.js +0 -71
  239. package/public/McEvent.js.map +0 -1
  240. package/public/selectors.d.ts +0 -108
  241. package/public/selectors.d.ts.map +0 -1
  242. package/public/selectors.js +0 -971
  243. package/public/selectors.js.map +0 -1
  244. package/public/selectors.min.js +0 -1
  245. package/public/src/selectors.ts +0 -1634
  246. package/public/test/MC.js.map +0 -1
  247. package/public/test/McEvent.d.ts +0 -15
  248. package/public/test/McEvent.d.ts.map +0 -1
  249. package/public/test/McEvent.js +0 -71
  250. package/public/test/McEvent.js.map +0 -1
  251. package/public/test/McEvent.ts +0 -96
  252. package/public/test/elements.js.map +0 -1
  253. package/public/test/formValues.js.map +0 -1
  254. package/public/test/microcomponents.js.map +0 -1
  255. package/public/test/observables.js.map +0 -1
  256. package/public/test/selectors.d.ts +0 -108
  257. package/public/test/selectors.d.ts.map +0 -1
  258. package/public/test/selectors.js +0 -971
  259. package/public/test/selectors.js.map +0 -1
  260. package/public/typedoc/classes/MC.McEvent.html +0 -9
  261. package/public/typedoc/functions/MC.addListener.html +0 -1
  262. package/public/typedoc/functions/MC.removeListener.html +0 -1
  263. package/src/McEvent.ts +0 -96
  264. package/src/selectors.ts +0 -1634
  265. /package/{dist/McEvent.ts → public/McEvent._ts} +0 -0
  266. /package/public/{McEvent.ts → src/McEvent._ts} +0 -0
  267. /package/public/{test → src}/helpers.js.map +0 -0
  268. /package/{public/src/McEvent.ts → src/McEvent._ts} +0 -0
@@ -0,0 +1,15 @@
1
+ import { DC, defineCE, getCE } from '../../microcomponents.js';
2
+ import { Child } from './child.js';
3
+ defineCE('test-parent', class Parent extends DC {
4
+ constructor(target) {
5
+ super(target);
6
+ }
7
+ onConnected() {
8
+ let that = this;
9
+ for (let x = 0; x < 5; x++) {
10
+ that.target.append(new Child());
11
+ }
12
+ }
13
+ });
14
+ export const Parent = getCE('test-parent');
15
+ //# sourceMappingURL=parent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parent.js","sourceRoot":"","sources":["../../../src/test/test/parent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,QAAQ,CACP,aAAa,EAEb,MAAM,MAAO,SAAQ,EAAE;IACtB,YAAY,MAAmB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IACf,CAAC;IAED,WAAW;QACV,IAAI,IAAI,GAAG,IAAI,CAAC;QAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAM,EAAE,CAAC,CAAC;QAClC,CAAC;IACF,CAAC;CACD,CACD,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { DC, defineCE, getCE } from '../../microcomponents.js';
2
+ import { Child } from './child.js';
3
+ defineCE(
4
+ 'test-parent',
5
+
6
+ class Parent extends DC {
7
+ constructor(target: HTMLElement) {
8
+ super(target);
9
+ }
10
+
11
+ onConnected() {
12
+ let that = this;
13
+
14
+ for (let x = 0; x < 5; x++) {
15
+ that.target.append(new Child!());
16
+ }
17
+ }
18
+ }
19
+ );
20
+
21
+ export const Parent = getCE('test-parent');
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=testform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testform.d.ts","sourceRoot":"","sources":["../../../src/test/test/testform.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");function t(e,t){let n=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const a=e?._mc;!t&&a?n=n.concat(Object.values(e._mc)):t&&a&&a[t]&&n.push(a[t])}})),n}function n(e,t,n=!0){let a=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&a.push(e._mc[t]):a=a.concat(Object.values(e._mc)),n))return a;e=e.parentNode}return a}function a(e){return e&&e instanceof HTMLElement}function l(e,t,n={}){let a=e;if(!a._mc){let t=u?.debug;u.debug=!1,a._mc=new u(e),u.debug=t,delete a._mc._mc}const l=a._mc;return t.length&&!l[t]&&(l[t]=n,e instanceof HTMLElement&&!e.getAttribute("data-mc")&&e.setAttribute("data-mc","")),n}function r(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("data-mc")&&e.removeAttribute("data-mc")}function o(e){return"_mc"+e[0].toUpperCase()+e.substring(1)}function s(e,t,n,a=!1){e.addEventListener(o(t),n,{capture:!1,once:a})}function i(e,t,n={},a="l"){const l="string"==typeof t?new CustomEvent(o(t),{detail:{data:n,bubble:a}}):t;a.length&&a.indexOf("l")>-1&&e.dispatchEvent(l),/[u|d]/.test(a)&&function(e,t){setTimeout((()=>{-1===t.detail.bubble.indexOf("l")&&(t.detail.bubble+="l"),t.detail.bubble.indexOf("u")>-1&&e.closest("[data-mc]")?.dispatchEvent(t),t.detail.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&u.trigger(e,t)}))}),0)}(e,l)}class c{_target;constructor(t,n=!1){var a;this._target=new WeakRef(t||{}),(a=this).constructor!==u&&setTimeout((()=>{a.trigger("Init")}),0),function(t){if(!e()||t.constructor===u)return;const n=t.target;if(n instanceof HTMLElement){let e=t;Object.getOwnPropertyNames(e.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof e.constructor.prototype[t])).forEach((t=>{let a=/^one/.test(t),l=t.replace(/^on[e]{0,1}/,""),r=l.toLowerCase(),o=n=>{e[t](n)};n["on"+r]?n.addEventListener(r,o):s(n,l,o,a)}))}}(this)}get target(){return this._target.deref()}}class u extends c{constructor(e,t=!1){super(e)}static add=l;static remove=r;static trigger=i;off(e,t){!function(e,t,n){e.removeEventListener(o(t),n)}(this.target,e,t)}on(e,t){s(this.target,e,t)}one(e,t){!function(e,t,n){s(e,t,n,!0)}(this.target,e,t)}trigger(e,t={},n="l"){}parent(e=""){let t=this.target;return a(t)?n(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return a(t)?n(this.target.parentNode,e,!1):[]}children(e=""){let n=this?.target;return a(n)?t([...function(e){const t=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+t+'"] [data-mc] [data-mc])';e.setAttribute("temp_id",t);const a=e.querySelectorAll(n);return e.removeAttribute("temp_id"),a}(n)],e):[]}descendants(e=""){let n=this?.target;return a(n)?t([...n.querySelectorAll("*[data-mc]")],e):[]}}function p(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var a;(a=e[n])&&a.constructor&&a.constructor===Object?t[n]=p(e[n]):t[n]=e[n]})),t}function d(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const a=d(e[t],!1);for(const e in a)n[t+"."+e]=a[e]}else n[t]=e[t]})),t?p(n):n}function b(e,t){return JSON.stringify(d(e))===JSON.stringify(d(t))}function m(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function f(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,a]of Object.entries(n))("get"in a||"set"in a)&&Object.defineProperty(t,e,a)}new Set;class h extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(e,t,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function g(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}function y(e){return null!=e&&"object"==typeof e}function v(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(n))).forEach((t=>{let a=new Set(e.getAttribute(t)?.match(n));a.forEach((e=>a.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(n))).forEach((e=>{(e.nodeValue||"").match(n).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const O=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class E extends u{data={};oldDisplay="";constructor(e){super(e),v(e).forEach((e=>this.data[e]="")),k(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g))).forEach((t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));var a;this.data.observe((a=e.getAttribute(t),l=>{let r=a;n.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),e.setAttribute(t,r)}))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{t=!0;let a=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((t=>l=>{let r=t;a.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=r})(n.nodeValue)),this.oldDisplay=e.getAttribute("style")||"",t&&!O.includes(e.constructor)&&"FIELDSET"!==e.tagName&&(e.style.display="none")}))}onData(e){let t={};Object.keys(e.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])})),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}}const w={};function x(e){let t=e.constructor.name;return w[t]||function(e){const t=e.constructor,n=t.name;let a=class extends t{#t=!0;#n=[];constructor(e){super(e),this.constructor.callbacks=[],y(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#n}set callbacks(e){this.#n=e}observe(e){return this.#n.push(e),this}bind(e){if(y(this.valueOf())){!function(e){var t;(t=e,[t].concat([...t.querySelectorAll("*")]).filter((e=>!!v(e).length)).filter((e=>"STYLE"!==e?.tagName)).reverse()).forEach((e=>{e?._mc?._placeholders||u.add(e,"_placeholders",new E(e))}))}(e);const t=[e,...e.querySelectorAll("[data-mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let n=d(e);t.forEach((e=>{e&&i(e,"data",n)}))};this.#n.push(n),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(e){let t=y(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==e&&(this.#t=e),this.#n.forEach((e=>{e(t)})),this}};return w[n]=a,a}(e)}const k=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let n=e[t],a=new(x(n))(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(y(a.valueOf())){let e=structuredClone(Object.assign({},a));setTimeout(m((function(){b(structuredClone(Object.assign({},a)),e)||a.notify()}),0),0)}return a},set(e){if(typeof e==typeof a.valueOf())if(y(a.valueOf())&&a.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},a));void 0===a?.constructor?.prototype?.observe&&(a=new(x(e))(structuredClone(Object.assign({},e))),f(e,a),a.seal()),Object.assign(a,e),setTimeout(m((function(){b(structuredClone(Object.assign({},a)),t)||a.notify()}),0),0)}else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(x(e))(e),a.callbacks=n,a.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof a.valueOf(),a,"- CANNOT BECOME:",typeof e)}}),e[t]=n}})),e);class A{constructor(e){}}class C extends A{#a;constructor(e){super(e),this.#a=e}get val(){return new FormData(this.#a.form).get(this.#a.name)}set val(e){[...this.#a.form.querySelectorAll(`input[type="radio"][name="${this.#a.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class j extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.checked}set val(e){this.#a.checked=e}}class S extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class _ extends A{#a;#l=!1;constructor(e){super(e),this.#a=e,this.#l=e.multiple}get val(){const e=[];return[...this.#a.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#l?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class N extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value||""}set val(e){this.#a.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let a=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");g(t.prototype.constructor)&&t.prototype instanceof c?customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(a,class extends h{instance;constructor(e){super();const n=g(t)?new t(this,e):t;u.add(this,a,n)}static get observedAttributes(){return n}})):customElements.define(e,t)}("test-testform",class extends u{data;constructor(e){super(e);let t=this.target.attachShadow({mode:"open"});t.innerHTML=`<style>${this.css}</style>${this.template}`,function(e,t,n){let a=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let a=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":a=new C(e);break;case"checkbox":a=new j(e);break;default:a=new S(e)}break;case"select":a=new _(e);break;case"textarea":a=new N(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}a&&(u.add(e,t,a),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val!==e&&(a.val=e)}}))}})),n})(n);e[t]=Object.assign({},a),k(e,t),f(a,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{e[t].notify()}))}))}(this,"data",t),this.data.bind(t),fetch("./testform.json").then((e=>e.json())).then((e=>{this.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" />&nbsp;<strong>2wB:&nbsp;</strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects&nbsp;<strong>2wB:&nbsp;</strong>&nbsp;<span>"{singleSelect}"</span>&nbsp;<span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons&nbsp;<strong>2wB:&nbsp;</strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testform.js","sourceRoot":"","sources":["../../../src/test/test/testform.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EACH,EAAE,EACF,QAAQ,EAER,UAAU,EAEb,MAAM,0BAA0B,CAAC;AAElC,QAAQ,CACP,eAAe,EAEf,MAAM,QAAS,SAAQ,EAAE;IACxB,IAAI,CAAU;IAEd,YAAY,MAAmB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,MAAM,GAAI,IAAW,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAChE,MAAM,CAAC,SAAS,GAAG,UAAU,IAAI,CAAC,GAAG,WAAW,IAAI,CAAC,QAAQ,EAAE,CAAC;QAEhE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAEhC,IAAI,CAAC,IAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAG9B,KAAK,CAAC,iBAAiB,CAAC;aACnB,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;aACxB,IAAI,CAAE,IAAI,CAAC,EAAE;YACV,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC,CAAC;IAEjB,CAAC;IAED,IAAI,QAAQ;QACX,OAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuEN,CAAC;IACZ,CAAC;IAED,IAAI,GAAG;QACN,OAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuCL,CAAC;IACZ,CAAC;CACD,CACD,CAAC"}
@@ -0,0 +1,153 @@
1
+ 'use strict';
2
+ import {
3
+ DC,
4
+ defineCE,
5
+ Observable,
6
+ formValues,
7
+ LooseObject
8
+ } from '../../microcomponents.js';
9
+
10
+ defineCE(
11
+ 'test-testform',
12
+
13
+ class TestForm extends DC {
14
+ data: unknown;
15
+
16
+ constructor(target: HTMLElement) {
17
+ super(target);
18
+
19
+ let shadow = (this as DC).target.attachShadow({ mode: 'open' });
20
+ shadow.innerHTML = `<style>${this.css}</style>${this.template}`;
21
+
22
+ formValues(this, 'data', shadow); // create this.data formdata observable
23
+
24
+ (this.data as Observable).bind(shadow); // 1 way bind formdata to the form DOM
25
+
26
+ // load and display data
27
+ fetch('./testform.json')
28
+ .then( res => res.json())
29
+ .then( data => {
30
+ this.data = data;
31
+ });
32
+
33
+ }
34
+
35
+ get template() {
36
+ return /*html*/ `
37
+ <form>
38
+ <!-- sample form to start with -->
39
+ <fieldset>
40
+ <legend>Inputs</legend>
41
+ <label>text</label><input type="text" name="textInput" value="Hallo" />&nbsp;<strong>2wB:&nbsp;</strong>{textInput}<br />
42
+ <label>color</label><input type="color" name="colorInput" value="#000000" /><br />
43
+ <label>date</label><input type="date" name="dateInput" value="" /><br />
44
+ <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />
45
+ <label>email</label><input type="email" name="email" value="" /><br />
46
+ <label>file</label><input type="file" name="fileInput" value="" /><br />
47
+ <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />
48
+ <label>month</label><input type="month" name="month" value="" /><br />
49
+ <label>number</label><input type="number" name="number" value="" /><br />
50
+ <label>password</label><input type="password" name="passInput" value="" /><br />
51
+ <label>range</label><input type="range" name="rangeInput" value="" /><br />
52
+ <label>search</label><input type="search" name="searchInput" value="" /><br />
53
+ <label>tel</label><input type="tel" name="telInput" value="" /><br />
54
+ <label>time</label><input type="time" name="timeInput" value="" /><br />
55
+ <label>url</label><input type="url" name="urlInput" value="" /><br />
56
+ <label>week</label><input type="week" name="weekInput" value="" /><br />
57
+ </fieldset>
58
+
59
+ <fieldset>
60
+ <legend>Selects&nbsp;<strong>2wB:&nbsp;</strong>&nbsp;<span>"{singleSelect}"</span>&nbsp;<span>[{multiSelect}]</span></legend>
61
+
62
+ <label>singleSelect</label>
63
+ <select name="singleSelect">
64
+ <option disabled selected value> -- select -- </option>
65
+ <option value="1">Option 1</option>
66
+ <option value="2">Option 2</option>
67
+ <option value="3">Option 3</option>
68
+ <option value="4">Option 4</option>
69
+ </select><br />
70
+
71
+ <label>multiSelect</label>
72
+ <select name="multiSelect" multiple="multiple" type="select-multiple">
73
+ <option value="1">Option 1</option>
74
+ <option value="2" selected=true>Option 2</option>
75
+ <option value="3">Option 3</option>
76
+ <option value="4" selected=true>Option 4</option>
77
+ </select>
78
+
79
+ </fieldset>
80
+
81
+ <fieldset>
82
+ <legend>Radiobuttons&nbsp;<strong>2wB:&nbsp;</strong><span>"{myRadio}"</span></legend>
83
+
84
+ <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />
85
+ <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />
86
+ <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />
87
+
88
+ </fieldset>
89
+
90
+ <fieldset>
91
+ <legend>Checkboxes</legend>
92
+ <label>cb1</label><input type="checkbox" name="cb1"><br />
93
+ <label>cb2</label><input type="checkbox" name="cb2"><br />
94
+ <label>cb3</label><input type="checkbox" name="cb3"><br />
95
+ <label>cb4</label><input type="checkbox" name="cb4"><br />
96
+ <label>cb5</label><input type="checkbox" name="cb5"><br />
97
+
98
+ </fieldset>
99
+
100
+ <fieldset>
101
+ <legend>TextArea</legend>
102
+ <label>textArea</label>
103
+ <textarea name="textArea">abc</textarea>
104
+ </fieldset>
105
+
106
+ </form>
107
+ `;
108
+ }
109
+
110
+ get css() {
111
+ return /*css*/ `
112
+ legend {
113
+ display: inherit;
114
+ margin: inherit;
115
+ vertical-align: inherit;
116
+ font-weight: bold;
117
+ }
118
+
119
+ label {
120
+ display: inline-block;
121
+ margin-top: 1em;
122
+ margin-left: 5px;
123
+ vertical-align: top;
124
+ min-width:10em;
125
+ text-align: right;
126
+ }
127
+
128
+ form input,
129
+ form select,
130
+ form textarea {
131
+ display: inline-block;
132
+ margin-left: 5px;
133
+ margin-top: 1.1em;
134
+ }
135
+
136
+ input[type="radio"],
137
+ input[type="checkbox"] {
138
+ margin-top: 1.3em;
139
+ }
140
+
141
+ body > form {
142
+ display: block;
143
+ }
144
+
145
+ form fieldset {
146
+ border: 1px solid #aaaaaa;
147
+ border-radius: 3px;
148
+ margin: 0.5em 0;
149
+ }
150
+ `;
151
+ }
152
+ }
153
+ );
@@ -0,0 +1,3 @@
1
+ declare const _default: CustomElementConstructor | undefined;
2
+ export default _default;
3
+ //# sourceMappingURL=testfunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testfunction.d.ts","sourceRoot":"","sources":["../../../src/test/test/testfunction.ts"],"names":[],"mappings":";AAWA,wBAA4C"}
@@ -0,0 +1,7 @@
1
+ import { defineCE, getCE } from '../../microcomponents.js';
2
+ console.log('testfunction.ts');
3
+ defineCE('test-testfunction', function testfunction(a, b) {
4
+ return a + b;
5
+ });
6
+ export default getCE('test-testfunction');
7
+ //# sourceMappingURL=testfunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testfunction.js","sourceRoot":"","sources":["../../../src/test/test/testfunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,CAAC,GAAG,CAAE,iBAAiB,CAAE,CAAC;AAEjC,QAAQ,CACJ,mBAAmB,EACnB,SAAS,YAAY,CAAE,CAAS,EAAE,CAAQ;IACtC,OAAO,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC,CACJ,CAAC;AAEF,eAAe,KAAK,CAAE,mBAAmB,CAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { defineCE, getCE } from '../../microcomponents.js';
2
+
3
+ console.log( 'testfunction.ts' );
4
+
5
+ defineCE(
6
+ 'test-testfunction',
7
+ function testfunction( a: number, b:number ){
8
+ return a + b;
9
+ }
10
+ );
11
+
12
+ export default getCE( 'test-testfunction' );
@@ -0,0 +1,3 @@
1
+ declare const _default: CustomElementConstructor | undefined;
2
+ export default _default;
3
+ //# sourceMappingURL=testmc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testmc.d.ts","sourceRoot":"","sources":["../../../src/test/test/testmc.ts"],"names":[],"mappings":";AAeA,wBAAsC"}
@@ -0,0 +1,10 @@
1
+ import { defineCE, getCE, DC } from '../../microcomponents.js';
2
+ defineCE('test-testmc', class TestMc extends DC {
3
+ constructor(target) {
4
+ super(target);
5
+ }
6
+ oneInit() {
7
+ }
8
+ });
9
+ export default getCE('test-testmc');
10
+ //# sourceMappingURL=testmc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testmc.js","sourceRoot":"","sources":["../../../src/test/test/testmc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE/D,QAAQ,CACJ,aAAa,EACb,MAAM,MAAO,SAAQ,EAAE;IACnB,YAAY,MAAmB;QAC3B,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,OAAO;IAEP,CAAC;CACJ,CACJ,CAAC;AAEF,eAAe,KAAK,CAAE,aAAa,CAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { defineCE, getCE, DC } from '../../microcomponents.js';
2
+
3
+ defineCE(
4
+ 'test-testmc',
5
+ class TestMc extends DC {
6
+ constructor(target: HTMLElement) {
7
+ super(target);
8
+ }
9
+
10
+ oneInit() {
11
+ // console.log('testmc connected to DOM');
12
+ }
13
+ }
14
+ );
15
+
16
+ export default getCE( 'test-testmc' );
@@ -0,0 +1,3 @@
1
+ declare const _default: CustomElementConstructor | undefined;
2
+ export default _default;
3
+ //# sourceMappingURL=testsimpleclass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testsimpleclass.d.ts","sourceRoot":"","sources":["../../../src/test/test/testsimpleclass.ts"],"names":[],"mappings":";AAcA,wBAA+C"}
@@ -0,0 +1,9 @@
1
+ import { defineCE, getCE } from '../../microcomponents.js';
2
+ defineCE('test-testsimpleclass', class TestSimpleClass {
3
+ constructor(target) {
4
+ }
5
+ oneInit() {
6
+ }
7
+ });
8
+ export default getCE('test-testsimpleclass');
9
+ //# sourceMappingURL=testsimpleclass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testsimpleclass.js","sourceRoot":"","sources":["../../../src/test/test/testsimpleclass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAM,MAAM,0BAA0B,CAAC;AAE/D,QAAQ,CACJ,sBAAsB,EACtB,MAAM,eAAe;IACjB,YAAY,MAAmB;IAC/B,CAAC;IAED,OAAO;IAEP,CAAC;CACJ,CACJ,CAAC;AAEF,eAAe,KAAK,CAAE,sBAAsB,CAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { defineCE, getCE, DC } from '../../microcomponents.js';
2
+
3
+ defineCE(
4
+ 'test-testsimpleclass',
5
+ class TestSimpleClass {
6
+ constructor(target: HTMLElement) {
7
+ }
8
+
9
+ oneInit() {
10
+ // console.log('testmc connected to DOM');
11
+ }
12
+ }
13
+ );
14
+
15
+ export default getCE( 'test-testsimpleclass' );
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/test/test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,80 @@
1
+ import { DC, defineCE, getCE, observe, } from '../microcomponents.js';
2
+ class Translator extends DC {
3
+ #translations = {};
4
+ Language = 'en';
5
+ Translation = {};
6
+ constructor(target, translations, translationTargetObject) {
7
+ super(target);
8
+ let that = this;
9
+ that.Language = 'en';
10
+ that.Translation = {};
11
+ observe(that);
12
+ that.#translations = translations;
13
+ that.Language.observe((lang) => {
14
+ if (that.#translations.hasOwnProperty(lang)) {
15
+ that.Translation = { lang: that.#translations[lang] };
16
+ }
17
+ });
18
+ that.Translation.bind(translationTargetObject);
19
+ that.target.setAttribute('language', 'en');
20
+ that.Language.notify();
21
+ }
22
+ onAttributeChanged(ev) {
23
+ let detail = ev.detail || {};
24
+ if (!detail.newValue)
25
+ return;
26
+ switch (detail.name) {
27
+ case 'language':
28
+ this.Language = detail.newValue;
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ defineCE('my-tag', class MyTag extends DC {
34
+ #template = '<button>{lang.click} {counter}</button>';
35
+ #languages = {
36
+ en: {
37
+ click: 'click me',
38
+ },
39
+ de: {
40
+ click: 'klick mich',
41
+ },
42
+ };
43
+ Dom = {};
44
+ constructor(target) {
45
+ super(target);
46
+ let that = this;
47
+ target.innerHTML = this.#template;
48
+ DC.add(target, 'translator', new Translator(target, that.#languages, target));
49
+ }
50
+ oneInit(ev) {
51
+ let that = this;
52
+ that.Dom = { counter: 0 };
53
+ observe(that);
54
+ that.Dom.bind(that.target);
55
+ }
56
+ onClick(ev) {
57
+ const that = this, c = that.Dom.counter++;
58
+ ev.detail.data.stopPropagation();
59
+ that.target.classList.remove('clicked');
60
+ that.target.classList.add(that.Dom.counter > 9 ? 'overClicked' : 'clicked');
61
+ }
62
+ }, ['language']);
63
+ let MyTag = getCE('my-tag'), fragment = new DocumentFragment();
64
+ let start = new Date().getTime(), max = 1000;
65
+ for (let x = 0; x < max; x++) {
66
+ fragment.append(new MyTag());
67
+ }
68
+ let end = new Date().getTime();
69
+ document.body.appendChild(fragment);
70
+ setTimeout(() => {
71
+ console.log('%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.', 'font-weight: bold; color: black;', 'font-weight: normal;', max, max * 3, 'font-weight: bold; color: blue;', end - start);
72
+ let element = document.querySelector('my-tag');
73
+ console.log("\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s", 'font-weight: bold;', 'font-weight: normal;', element, 'font-weight: bold;', '\n\nLook up code in the debugger: test.js\n');
74
+ let form = document.querySelector('test-testform');
75
+ let formInstance = form._mc.TestTestform;
76
+ window.form = formInstance;
77
+ console.log("\n\n%cAttached a global variable 'form':%c \n\n %O %c %s %c %s %c %s", 'font-weight: bold;', 'font-weight: normal;', formInstance, 'font-weight: bold;', '\n\nYou can use it to change input values, e.g. \n\n', 'font-weight: normal;', ' form.data.textInput="other value"', 'font-weight: bold;', '\n\nChanges will be reflected in the form contents, same as vice versa.\n');
78
+ DC.trigger(element, 'doSomething');
79
+ }, 1000);
80
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,EAAE,EACF,QAAQ,EACR,KAAK,EACL,OAAO,GAEP,MAAM,uBAAuB,CAAC;AAE/B,MAAM,UAAW,SAAQ,EAAE;IAC1B,aAAa,GAAgB,EAAE,CAAC;IAEhC,QAAQ,GAAY,IAAI,CAAC;IACzB,WAAW,GAA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,
7
+ Observable,
8
+ } from '../microcomponents.js';
9
+
10
+ class Translator extends DC {
11
+ #translations: LooseObject = {};
12
+
13
+ Language: unknown = 'en';
14
+ Translation: unknown = {};
15
+
16
+ constructor(
17
+ target: HTMLElement | ShadowRoot | DocumentFragment,
18
+ translations: LooseObject,
19
+ translationTargetObject: HTMLElement
20
+ ) {
21
+ super(target as HTMLElement);
22
+ let that = this; // minifier help
23
+
24
+ // state
25
+ that.Language = 'en';
26
+ that.Translation = {};
27
+
28
+ observe(that);
29
+
30
+ // setup
31
+ that.#translations = translations;
32
+
33
+ // on language change switch translation object
34
+ (that.Language as Observable).observe((lang) => {
35
+ if (that.#translations.hasOwnProperty(lang)) {
36
+ that.Translation = { lang: that.#translations[lang] }; // set translation
37
+ }
38
+ });
39
+
40
+ (that.Translation as Observable).bind(translationTargetObject);
41
+
42
+ that.target.setAttribute('language', 'en');
43
+
44
+ (that.Language as Observable).notify();
45
+ }
46
+
47
+ onAttributeChanged(ev: CustomEvent) {
48
+ let detail = ev.detail || {};
49
+ if (!detail.newValue) return;
50
+ switch (detail.name) {
51
+ case 'language':
52
+ this.Language = detail.newValue;
53
+ break;
54
+ }
55
+ }
56
+ }
57
+
58
+ defineCE(
59
+ // equivalent to custom element registry .define()
60
+ 'my-tag',
61
+ class MyTag extends DC {
62
+ #template: string = '<button>{lang.click} {counter}</button>';
63
+
64
+ #languages = {
65
+ en: {
66
+ click: 'click me',
67
+ },
68
+ de: {
69
+ click: 'klick mich',
70
+ },
71
+ };
72
+
73
+ Dom: LooseObject = {};
74
+
75
+ constructor(target: HTMLElement) {
76
+ super(target);
77
+
78
+ let that = this; // minifier help
79
+
80
+ // render
81
+ target.innerHTML = this.#template;
82
+
83
+ // add translator
84
+ DC.add(
85
+ target,
86
+ 'translator',
87
+ new Translator(target, that.#languages, target)
88
+ );
89
+ }
90
+
91
+ oneInit(ev: CustomEvent) {
92
+ let that = this;
93
+
94
+ // state
95
+ that.Dom = { counter: 0 };
96
+
97
+ // state: convert all props defined so far into observables
98
+ observe(that);
99
+
100
+ // bind Dom to target
101
+ (that.Dom as Observable).bind(that.target);
102
+ }
103
+
104
+ onClick(ev: CustomEvent) {
105
+ const that = this,
106
+ c = that.Dom.counter++;
107
+ (ev.detail.data as PointerEvent).stopPropagation();
108
+ (that.target as HTMLElement).classList.remove('clicked');
109
+ (that.target as HTMLElement).classList.add(
110
+ that.Dom.counter > 9 ? 'overClicked' : 'clicked'
111
+ );
112
+ }
113
+ },
114
+ ['language']
115
+ );
116
+
117
+ let MyTag: CustomElementConstructor = getCE('my-tag')!,
118
+ fragment = new DocumentFragment();
119
+
120
+ /*
121
+ stress test
122
+ */
123
+
124
+ let start = new Date().getTime(),
125
+ max = 1000;
126
+
127
+ // create 1000 elements
128
+ for (let x = 0; x < max; x++) {
129
+ fragment.append(new MyTag());
130
+ }
131
+
132
+ let end = new Date().getTime();
133
+
134
+ // and put them into the DOM
135
+ document.body.appendChild(fragment);
136
+
137
+ //document.querySelectorAll('my-tag').forEach((e) => e.remove());
138
+
139
+ /*
140
+ console test
141
+ */
142
+
143
+ setTimeout(() => {
144
+ // console.clear();
145
+
146
+ console.log(
147
+ '%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.',
148
+ 'font-weight: bold; color: black;',
149
+ 'font-weight: normal;',
150
+ max,
151
+ max * 3,
152
+ 'font-weight: bold; color: blue;',
153
+ end - start
154
+ );
155
+
156
+ //document.body.appendChild(new MyTag());
157
+
158
+ let element = document.querySelector('my-tag');
159
+
160
+ console.log(
161
+ "\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
162
+ 'font-weight: bold;',
163
+ 'font-weight: normal;',
164
+ element,
165
+ 'font-weight: bold;',
166
+ '\n\nLook up code in the debugger: test.js\n'
167
+ );
168
+
169
+ let form = ( document.querySelector('test-testform') as any);
170
+ let formInstance = form._mc.TestTestform;
171
+
172
+ (window as any).form = formInstance;
173
+ console.log(
174
+ "\n\n%cAttached a global variable 'form':%c \n\n %O %c %s %c %s %c %s",
175
+ 'font-weight: bold;',
176
+ 'font-weight: normal;',
177
+ formInstance,
178
+ 'font-weight: bold;',
179
+ '\n\nYou can use it to change input values, e.g. \n\n',
180
+ 'font-weight: normal;',
181
+ ' form.data.textInput="other value"',
182
+ 'font-weight: bold;',
183
+ '\n\nChanges will be reflected in the form contents, same as vice versa.\n'
184
+ );
185
+
186
+ // will trigger the event on all micro components contained in <my-tag>
187
+ DC.trigger(element, 'doSomething');
188
+ }, 1000);