@twobirds/microcomponents 0.1.1 → 0.1.3

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 (343) hide show
  1. package/dist/MC.d.ts +0 -1
  2. package/dist/MC.js +6 -5
  3. package/dist/MC.min.js +39 -56
  4. package/dist/MC.ts +6 -4
  5. package/dist/elements.d.ts +0 -1
  6. package/dist/elements.js +0 -1
  7. package/dist/elements.min.js +1 -1
  8. package/dist/formValues.d.ts +0 -1
  9. package/dist/formValues.js +0 -1
  10. package/dist/formValues.min.js +1 -1
  11. package/dist/helpers.d.ts +0 -1
  12. package/dist/helpers.js +0 -1
  13. package/dist/microcomponents.d.ts +0 -1
  14. package/dist/microcomponents.js +0 -1
  15. package/dist/microcomponents.min.js +1 -1
  16. package/dist/observables.d.ts +0 -1
  17. package/dist/observables.js +0 -1
  18. package/dist/observables.min.js +1 -1
  19. package/package.json +10 -2
  20. package/.gitlab-ci.yml +0 -18
  21. package/.vscode/settings.json +0 -3
  22. package/MicroComponents.svg +0 -15
  23. package/assets/documentation/MC.md +0 -547
  24. package/assets/documentation/MicroComponents.svg +0 -15
  25. package/assets/documentation/ajaxian-1.png +0 -0
  26. package/assets/documentation/ajaxian-2.png +0 -0
  27. package/assets/documentation/ajaxian-3.png +0 -0
  28. package/assets/documentation/elements.md +0 -277
  29. package/assets/documentation/formvalues.md +0 -25
  30. package/assets/documentation/functional_requirements.md +0 -8
  31. package/assets/documentation/history.md +0 -436
  32. package/assets/documentation/klemmstein.png +0 -0
  33. package/assets/documentation/magic.md +0 -29
  34. package/assets/documentation/observables.md +0 -187
  35. package/assets/documentation/rnd0023-1.jpg +0 -0
  36. package/assets/documentation/rnd0023-2.jpg +0 -0
  37. package/assets/documentation/rnd0023-3.jpg +0 -0
  38. package/assets/documentation/tB_react.md +0 -207
  39. package/assets/documentation/usage.md +0 -142
  40. package/assets/documentation/why.md +0 -25
  41. package/assets/fiddle/MicroComponents.svg +0 -15
  42. package/assets/fiddle/fiddle.css +0 -0
  43. package/assets/fiddle/fiddle.js +0 -0
  44. package/assets/fiddle/index.html +0 -0
  45. package/assets/test/MicroComponents.svg +0 -15
  46. package/assets/test/grandparent.css +0 -16
  47. package/assets/test/myButton.css +0 -19
  48. package/assets/test/style.css +0 -8
  49. package/assets/test/test.html +0 -29
  50. package/assets/test/testform.json +0 -27
  51. package/dist/MC.d.ts.map +0 -1
  52. package/dist/elements.d.ts.map +0 -1
  53. package/dist/formValues.d.ts.map +0 -1
  54. package/dist/helpers.d.ts.map +0 -1
  55. package/dist/microcomponents.d.ts.map +0 -1
  56. package/dist/observables.d.ts.map +0 -1
  57. package/public/.nojekyll +0 -1
  58. package/public/MC.d.ts +0 -39
  59. package/public/MC.d.ts.map +0 -1
  60. package/public/MC.js +0 -287
  61. package/public/MC.js.map +0 -1
  62. package/public/MC.min.js +0 -348
  63. package/public/MC.ts +0 -431
  64. package/public/MicroComponents.svg +0 -15
  65. package/public/documentation/MC.md +0 -547
  66. package/public/documentation/MicroComponents.svg +0 -15
  67. package/public/documentation/ajaxian-1.png +0 -0
  68. package/public/documentation/ajaxian-2.png +0 -0
  69. package/public/documentation/ajaxian-3.png +0 -0
  70. package/public/documentation/elements.md +0 -277
  71. package/public/documentation/formvalues.md +0 -25
  72. package/public/documentation/functional_requirements.md +0 -8
  73. package/public/documentation/history.md +0 -436
  74. package/public/documentation/klemmstein.png +0 -0
  75. package/public/documentation/magic.md +0 -29
  76. package/public/documentation/observables.md +0 -187
  77. package/public/documentation/rnd0023-1.jpg +0 -0
  78. package/public/documentation/rnd0023-2.jpg +0 -0
  79. package/public/documentation/rnd0023-3.jpg +0 -0
  80. package/public/documentation/tB_react.md +0 -207
  81. package/public/documentation/usage.md +0 -142
  82. package/public/documentation/why.md +0 -25
  83. package/public/elements.d.ts +0 -5
  84. package/public/elements.d.ts.map +0 -1
  85. package/public/elements.js +0 -68
  86. package/public/elements.js.map +0 -1
  87. package/public/elements.min.js +0 -1
  88. package/public/elements.ts +0 -119
  89. package/public/fiddle/MicroComponents.svg +0 -15
  90. package/public/fiddle/fiddle.css +0 -0
  91. package/public/fiddle/fiddle.js +0 -0
  92. package/public/fiddle/index.html +0 -0
  93. package/public/formValues.d.ts +0 -3
  94. package/public/formValues.d.ts.map +0 -1
  95. package/public/formValues.js +0 -162
  96. package/public/formValues.js.map +0 -1
  97. package/public/formValues.min.js +0 -1
  98. package/public/formValues.ts +0 -225
  99. package/public/helpers.d.ts +0 -14
  100. package/public/helpers.d.ts.map +0 -1
  101. package/public/helpers.js +0 -113
  102. package/public/helpers.js.map +0 -1
  103. package/public/helpers.ts +0 -149
  104. package/public/microcomponents.d.ts +0 -6
  105. package/public/microcomponents.d.ts.map +0 -1
  106. package/public/microcomponents.js +0 -7
  107. package/public/microcomponents.js.map +0 -1
  108. package/public/microcomponents.min.js +0 -1
  109. package/public/microcomponents.ts +0 -8
  110. package/public/observables.d.ts +0 -11
  111. package/public/observables.d.ts.map +0 -1
  112. package/public/observables.js +0 -244
  113. package/public/observables.js.map +0 -1
  114. package/public/observables.min.js +0 -1
  115. package/public/observables.ts +0 -416
  116. package/public/selectors._ts +0 -1269
  117. package/public/src/MC.d.ts +0 -39
  118. package/public/src/MC.d.ts.map +0 -1
  119. package/public/src/MC.js +0 -287
  120. package/public/src/MC.js.map +0 -1
  121. package/public/src/MC.ts +0 -431
  122. package/public/src/elements.d.ts +0 -5
  123. package/public/src/elements.d.ts.map +0 -1
  124. package/public/src/elements.js +0 -68
  125. package/public/src/elements.js.map +0 -1
  126. package/public/src/elements.ts +0 -119
  127. package/public/src/formValues.d.ts +0 -3
  128. package/public/src/formValues.d.ts.map +0 -1
  129. package/public/src/formValues.js +0 -162
  130. package/public/src/formValues.js.map +0 -1
  131. package/public/src/formValues.ts +0 -225
  132. package/public/src/helpers.d.ts +0 -14
  133. package/public/src/helpers.d.ts.map +0 -1
  134. package/public/src/helpers.js +0 -113
  135. package/public/src/helpers.js.map +0 -1
  136. package/public/src/helpers.ts +0 -149
  137. package/public/src/microcomponents.d.ts +0 -6
  138. package/public/src/microcomponents.d.ts.map +0 -1
  139. package/public/src/microcomponents.js +0 -7
  140. package/public/src/microcomponents.js.map +0 -1
  141. package/public/src/microcomponents.ts +0 -8
  142. package/public/src/observables.d.ts +0 -11
  143. package/public/src/observables.d.ts.map +0 -1
  144. package/public/src/observables.js +0 -244
  145. package/public/src/observables.js.map +0 -1
  146. package/public/src/observables.ts +0 -416
  147. package/public/src/selectors._ts +0 -1269
  148. package/public/src/test/grandparent.css +0 -14
  149. package/public/src/test/test/child.d.ts +0 -2
  150. package/public/src/test/test/child.d.ts.map +0 -1
  151. package/public/src/test/test/child.js +0 -26
  152. package/public/src/test/test/child.js.map +0 -1
  153. package/public/src/test/test/child.ts +0 -36
  154. package/public/src/test/test/grandchild.d.ts +0 -2
  155. package/public/src/test/test/grandchild.d.ts.map +0 -1
  156. package/public/src/test/test/grandchild.js +0 -22
  157. package/public/src/test/test/grandchild.js.map +0 -1
  158. package/public/src/test/test/grandchild.ts +0 -31
  159. package/public/src/test/test/grandparent.d.ts +0 -2
  160. package/public/src/test/test/grandparent.d.ts.map +0 -1
  161. package/public/src/test/test/grandparent.js +0 -1
  162. package/public/src/test/test/grandparent.js.map +0 -1
  163. package/public/src/test/test/grandparent.ts +0 -43
  164. package/public/src/test/test/greatgrandchild.d.ts +0 -2
  165. package/public/src/test/test/greatgrandchild.d.ts.map +0 -1
  166. package/public/src/test/test/greatgrandchild.js +0 -36
  167. package/public/src/test/test/greatgrandchild.js.map +0 -1
  168. package/public/src/test/test/greatgrandchild.ts +0 -51
  169. package/public/src/test/test/parent.d.ts +0 -2
  170. package/public/src/test/test/parent.d.ts.map +0 -1
  171. package/public/src/test/test/parent.js +0 -25
  172. package/public/src/test/test/parent.js.map +0 -1
  173. package/public/src/test/test/parent.ts +0 -35
  174. package/public/src/test/test/testform.d.ts +0 -2
  175. package/public/src/test/test/testform.d.ts.map +0 -1
  176. package/public/src/test/test/testform.js +0 -1
  177. package/public/src/test/test/testform.js.map +0 -1
  178. package/public/src/test/test/testform.ts +0 -153
  179. package/public/src/test/test/testfunction.d.ts +0 -3
  180. package/public/src/test/test/testfunction.d.ts.map +0 -1
  181. package/public/src/test/test/testfunction.js +0 -7
  182. package/public/src/test/test/testfunction.js.map +0 -1
  183. package/public/src/test/test/testfunction.ts +0 -12
  184. package/public/src/test/test/testmc.d.ts +0 -3
  185. package/public/src/test/test/testmc.d.ts.map +0 -1
  186. package/public/src/test/test/testmc.js +0 -10
  187. package/public/src/test/test/testmc.js.map +0 -1
  188. package/public/src/test/test/testmc.ts +0 -16
  189. package/public/src/test/test/testsimpleclass.d.ts +0 -3
  190. package/public/src/test/test/testsimpleclass.d.ts.map +0 -1
  191. package/public/src/test/test/testsimpleclass.js +0 -9
  192. package/public/src/test/test/testsimpleclass.js.map +0 -1
  193. package/public/src/test/test/testsimpleclass.ts +0 -15
  194. package/public/src/test/test.d.ts +0 -2
  195. package/public/src/test/test.d.ts.map +0 -1
  196. package/public/src/test/test.js +0 -72
  197. package/public/src/test/test.js.map +0 -1
  198. package/public/src/test/test.ts +0 -176
  199. package/public/src/test/testform.css +0 -47
  200. package/public/src/test/testform.html +0 -56
  201. package/public/src/test/testform.json +0 -27
  202. package/public/test/MC.d.ts +0 -39
  203. package/public/test/MC.d.ts.map +0 -1
  204. package/public/test/MC.js +0 -287
  205. package/public/test/MC.min.js +0 -348
  206. package/public/test/MC.ts +0 -431
  207. package/public/test/MicroComponents.svg +0 -15
  208. package/public/test/elements.d.ts +0 -5
  209. package/public/test/elements.d.ts.map +0 -1
  210. package/public/test/elements.js +0 -68
  211. package/public/test/elements.min.js +0 -1
  212. package/public/test/elements.ts +0 -119
  213. package/public/test/formValues.d.ts +0 -3
  214. package/public/test/formValues.d.ts.map +0 -1
  215. package/public/test/formValues.js +0 -162
  216. package/public/test/formValues.min.js +0 -1
  217. package/public/test/formValues.ts +0 -225
  218. package/public/test/grandparent.css +0 -14
  219. package/public/test/helpers.d.ts +0 -14
  220. package/public/test/helpers.d.ts.map +0 -1
  221. package/public/test/helpers.js +0 -113
  222. package/public/test/helpers.ts +0 -149
  223. package/public/test/microcomponents.d.ts +0 -6
  224. package/public/test/microcomponents.d.ts.map +0 -1
  225. package/public/test/microcomponents.js +0 -7
  226. package/public/test/microcomponents.min.js +0 -1
  227. package/public/test/microcomponents.ts +0 -8
  228. package/public/test/myButton.css +0 -19
  229. package/public/test/observables.d.ts +0 -11
  230. package/public/test/observables.d.ts.map +0 -1
  231. package/public/test/observables.js +0 -244
  232. package/public/test/observables.min.js +0 -1
  233. package/public/test/observables.ts +0 -416
  234. package/public/test/style.css +0 -8
  235. package/public/test/test/child.d.ts +0 -2
  236. package/public/test/test/child.d.ts.map +0 -1
  237. package/public/test/test/child.js +0 -26
  238. package/public/test/test/child.js.map +0 -1
  239. package/public/test/test/child.ts +0 -36
  240. package/public/test/test/grandchild.d.ts +0 -2
  241. package/public/test/test/grandchild.d.ts.map +0 -1
  242. package/public/test/test/grandchild.js +0 -22
  243. package/public/test/test/grandchild.js.map +0 -1
  244. package/public/test/test/grandchild.ts +0 -31
  245. package/public/test/test/grandparent.d.ts +0 -2
  246. package/public/test/test/grandparent.d.ts.map +0 -1
  247. package/public/test/test/grandparent.js +0 -1
  248. package/public/test/test/grandparent.js.map +0 -1
  249. package/public/test/test/grandparent.ts +0 -43
  250. package/public/test/test/greatgrandchild.d.ts +0 -2
  251. package/public/test/test/greatgrandchild.d.ts.map +0 -1
  252. package/public/test/test/greatgrandchild.js +0 -36
  253. package/public/test/test/greatgrandchild.js.map +0 -1
  254. package/public/test/test/greatgrandchild.ts +0 -51
  255. package/public/test/test/parent.d.ts +0 -2
  256. package/public/test/test/parent.d.ts.map +0 -1
  257. package/public/test/test/parent.js +0 -25
  258. package/public/test/test/parent.js.map +0 -1
  259. package/public/test/test/parent.ts +0 -35
  260. package/public/test/test/testform.d.ts +0 -2
  261. package/public/test/test/testform.d.ts.map +0 -1
  262. package/public/test/test/testform.js +0 -1
  263. package/public/test/test/testform.js.map +0 -1
  264. package/public/test/test/testform.ts +0 -153
  265. package/public/test/test/testfunction.d.ts +0 -3
  266. package/public/test/test/testfunction.d.ts.map +0 -1
  267. package/public/test/test/testfunction.js +0 -7
  268. package/public/test/test/testfunction.js.map +0 -1
  269. package/public/test/test/testfunction.ts +0 -12
  270. package/public/test/test/testmc.d.ts +0 -3
  271. package/public/test/test/testmc.d.ts.map +0 -1
  272. package/public/test/test/testmc.js +0 -10
  273. package/public/test/test/testmc.js.map +0 -1
  274. package/public/test/test/testmc.ts +0 -16
  275. package/public/test/test/testsimpleclass.d.ts +0 -3
  276. package/public/test/test/testsimpleclass.d.ts.map +0 -1
  277. package/public/test/test/testsimpleclass.js +0 -9
  278. package/public/test/test/testsimpleclass.js.map +0 -1
  279. package/public/test/test/testsimpleclass.ts +0 -15
  280. package/public/test/test.d.ts +0 -2
  281. package/public/test/test.d.ts.map +0 -1
  282. package/public/test/test.html +0 -29
  283. package/public/test/test.js +0 -72
  284. package/public/test/test.js.map +0 -1
  285. package/public/test/test.ts +0 -176
  286. package/public/test/testform.css +0 -47
  287. package/public/test/testform.html +0 -56
  288. package/public/test/testform.json +0 -27
  289. package/public/typedoc/.nojekyll +0 -1
  290. package/public/typedoc/assets/highlight.css +0 -106
  291. package/public/typedoc/assets/icons.js +0 -18
  292. package/public/typedoc/assets/icons.svg +0 -1
  293. package/public/typedoc/assets/main.js +0 -60
  294. package/public/typedoc/assets/navigation.js +0 -1
  295. package/public/typedoc/assets/search.js +0 -1
  296. package/public/typedoc/assets/style.css +0 -1493
  297. package/public/typedoc/classes/MC.DC.html +0 -13
  298. package/public/typedoc/classes/MC.MC.html +0 -3
  299. package/public/typedoc/classes/MC.McBase.html +0 -3
  300. package/public/typedoc/functions/MC.autoload.html +0 -1
  301. package/public/typedoc/functions/MC.off.html +0 -1
  302. package/public/typedoc/functions/MC.on.html +0 -1
  303. package/public/typedoc/functions/MC.one.html +0 -1
  304. package/public/typedoc/functions/MC.trigger.html +0 -1
  305. package/public/typedoc/functions/elements.defineCE.html +0 -1
  306. package/public/typedoc/functions/elements.getCE.html +0 -1
  307. package/public/typedoc/functions/formValues.formValues.html +0 -1
  308. package/public/typedoc/functions/observables.observe.html +0 -1
  309. package/public/typedoc/hierarchy.html +0 -1
  310. package/public/typedoc/index.html +0 -122
  311. package/public/typedoc/interfaces/MC.HTMLMcElement.html +0 -758
  312. package/public/typedoc/media/MicroComponents.svg +0 -15
  313. package/public/typedoc/modules/MC.html +0 -10
  314. package/public/typedoc/modules/elements.html +0 -3
  315. package/public/typedoc/modules/formValues.html +0 -2
  316. package/public/typedoc/modules/observables.html +0 -3
  317. package/public/typedoc/modules.html +0 -5
  318. package/public/typedoc/types/observables.Observable.html +0 -1
  319. package/src/MC.ts +0 -431
  320. package/src/elements.ts +0 -119
  321. package/src/formValues.ts +0 -225
  322. package/src/helpers.ts +0 -149
  323. package/src/microcomponents.ts +0 -8
  324. package/src/observables.ts +0 -416
  325. package/src/selectors._ts +0 -1269
  326. package/src/test/grandparent.css +0 -14
  327. package/src/test/test/child.ts +0 -36
  328. package/src/test/test/grandchild.ts +0 -31
  329. package/src/test/test/grandparent.ts +0 -43
  330. package/src/test/test/greatgrandchild.ts +0 -51
  331. package/src/test/test/parent.ts +0 -35
  332. package/src/test/test/testform.ts +0 -153
  333. package/src/test/test/testfunction.ts +0 -12
  334. package/src/test/test/testmc.ts +0 -16
  335. package/src/test/test/testsimpleclass.ts +0 -15
  336. package/src/test/test.ts +0 -176
  337. package/src/test/testform.css +0 -47
  338. package/src/test/testform.html +0 -56
  339. package/src/test/testform.json +0 -27
  340. package/tasks.md +0 -36
  341. package/tsconfig.json +0 -107
  342. package/typedoc.json +0 -7
  343. package/webpack.config.js +0 -346
@@ -1,547 +0,0 @@
1
- ![logo](./MicroComponents.svg)
2
-
3
- # Micro Components
4
-
5
- This document details a lightweight JavaScript framework for creating and managing "microcomponents" (MCs) associated with DOM elements or other microcomponents. It allows you to define reusable components and attach them to build complex functionalities.
6
-
7
- The framework exports 2 main classes:
8
-
9
- - **MC**: Micro Component. The base component class, suitable for logic that doesn't directly interact with the DOM or for use on the server.
10
- - **DC**: DOM Component. Extends `MC` and adds DOM-specific methods (like traversal). Use this for components that need to interact with the browser's DOM.
11
-
12
- ## Table of Contents
13
-
14
- - [Usage Guidance](#usage-guidance)
15
- - [Core Concepts](#core-concepts)
16
- - [Microcomponents (MCs)](#microcomponents-mcs)
17
- - [`_mc` Property](#_mc-property)
18
- - [DOM Association & `target`](#dom-association--target)
19
- - [Event System](#event-system)
20
- - [Observables (Mention)](#observables-mention)
21
- - [DOM Traversal](#dom-traversal)
22
- - [Autoloading Concept](#autoloading-concept)
23
- - [Important Rule](#important-rule)
24
- - [Classes](#classes)
25
- - [Not Exported: `McBase` (Superclass)](#not-exported-mcbase-superclass)
26
- - [Exported: `MC` Class](#exported-mc-class)
27
- - [Exported: `DC` Class](#exported-dc-class)
28
- - [Examples](#examples)
29
- - [Typical Workflow](#typical-workflow)
30
- - [Attach Micro Components (`DC.add`)](#attach-micro-components-dcadd)
31
- - [Remove Micro Components (`DC.remove`)](#remove-micro-components-dcremove)
32
- - [Retrieve Micro Components](#retrieve-micro-components)
33
- - [Triggering Events](#triggering-events)
34
- - [Retrieving Inner Micro Components](#retrieving-inner-micro-components)
35
- - [Navigating Parent/Ancestor MCs](#navigating-parentancestor-mcs)
36
- - [Retrieving Child/Descendant MCs](#retrieving-childdescendant-mcs)
37
- - [Auto-attaching DOM Listeners](#auto-attaching-dom-listeners)
38
- - [Lifecycle Events](#lifecycle-events)
39
- - [Init](#init)
40
- - [Interfaces and Types](#interfaces-and-types)
41
- - [`LooseObject`](#looseobject)
42
- - [`McEvent`](#mcevent)
43
- - [`HTMLMcElement`](#htmlmcelement)
44
- - [Autoloading](#auto-loading)
45
-
46
- ## Usage Guidance
47
-
48
- - **If your component needs to access or manipulate the DOM** (e.g., find other components in the DOM, attach listeners directly, read element properties), **your class MUST extend `DC`**. This is client-side only.
49
- - **Otherwise** (e.g., for pure logic, state management, or server-side usage), **your class should extend `MC`**.
50
-
51
- Think **DRY** (Don't Repeat Yourself) and **SOLID** principles when designing your components.
52
-
53
- ## Core Concepts
54
-
55
- Fundamental ideas behind the framework.
56
-
57
- ### Microcomponents (MCs)
58
-
59
- Plain JavaScript objects or class instances (extending `MC` or `DC`) that encapsulate behavior and state. They can be attached to DOM elements (via `DC`) or nested within other MCs.
60
-
61
- ### `_mc` Property
62
-
63
- A special property attached to `HTMLElement` instances when using `DC.add`. It acts as an object container (`{ key: mcInstance, ... }`) holding one or more named microcomponent instances.
64
-
65
- - On HTMLElements, the presence of attached components is also marked by a `_mc` attribute for CSS selection and discovery. This attribute is added by `DC.add` and removed by `DC.remove` when the `_mc` object becomes empty.
66
-
67
- ### DOM Association & `target`
68
-
69
- Each microcomponent instance has a read-only `target` property providing a back-reference:
70
-
71
- - If the instance extends **`DC`** `.target` refers to the **DOM HTMLElement** it's attached to.
72
- - If the instance extends **`MC`** (or `DC`) and is nested within another component, `.target` refers to the **parent MC/DC instance**.
73
-
74
- This reference is managed using `WeakRef` internally by `McBase` to prevent circular references and potential memory leaks.
75
-
76
- ### Event System
77
-
78
- A CustomEvent system allows components to communicate. These event handlers bubble differently than native events.
79
-
80
- Any MC method name starting with `on` or `one` followed by an uppercase character will automatically be registered as a custom event handler in the DOM element.
81
-
82
- The names maps like this:
83
- **class method** `onHandlerMethod()` => **custom event handler** `_mcHandlerMethod`
84
-
85
-
86
- - **Triggering:**
87
-
88
- Events are dispatched using the `trigger` method:
89
- - `myDomElement._mc.trigger('handlerMethod', { ... } )` ... from outside.
90
- - `this.trigger( 'handlerMethod', data )` ...inside the current MC instance.
91
-
92
- native:
93
- - `myDomElement.dispatchEvent('_mcHandlerMethod', { detail: { ... } } )`;
94
-
95
-
96
- - **Handling:**
97
- - Components listen for events by defining methods named `onEventName` or `oneEventName` (for once-off handling).
98
- - These are automatically detected by `autoAttachListeners` internally.
99
- - Native DOM events matching this pattern on `DC` instances are also automatically bound to the target element.
100
-
101
-
102
- - **Bubbling:** Events triggered via `dcInstance.trigger` can bubble:
103
- - `'l'`: Local only (default). Handlers on the target element's/instance's MCs are executed.
104
- - `'u'`: Upwards. Event propagates to MCs on closest elements (DOM tree).
105
- - `'d'`: Downwards. Event propagates to MCs on descendant elements (DOM tree).
106
- - Any combination of the characters 'l','u', 'd' are possible (e.g., `'lu'`, `'ldu'`).
107
- - Bubbling (`u`/`d`) occurs asynchronously via `setTimeout`.
108
-
109
- ### Observables (Mention)
110
-
111
- - MCs can utilize observables (implementation not detailed here) for data-driven workflows.
112
- - `DC` components can leverage observables and potentially form values for 1-way or 2-way data binding with the DOM.
113
-
114
- ### DOM Traversal
115
-
116
- The `DC` class provides methods (`closest`, `ancestors`, `children`, `descendants`) to find related `DC` instances attached to elements elsewhere in the DOM hierarchy, skipping over elements without attached microcomponents.
117
-
118
- ### Autoloading Concept
119
-
120
- An optional feature (`autoload()`) that automatically detects specific HTML tags (e.g., `<my-component>`) or elements with an `data-mc="my-component"` attribute and attempts to dynamically load the corresponding JavaScript module (e.g., `/my/component.js`).
121
-
122
- ### Important Rule
123
-
124
- **Your own application code MUST NOT overwrite the core properties and methods provided by the `McBase`, `MC`, and `DC` classes (like `_mc`, `target`, `trigger`, `closest`, etc.). Doing so may break framework functionality.**
125
-
126
- ## Classes
127
-
128
- ### Not Exported: `McBase` (Superclass)
129
-
130
- The internal base class for `MC` and `DC`. You don't extend this directly.
131
-
132
- - **Instance Properties**:
133
- - `.target`: Read-only getter returning the containing DOM element (for DCs added via `DC.add`) or parent MC/DC instance (for nested MCs). Uses `WeakRef`.
134
- - **Constructor Behavior**:
135
- - Initializes the `.target` reference.
136
- - Calls `init(this)`: Triggers the 'Init' lifecycle event asynchronously.
137
- - Calls `autoAttachListeners(this)`: Sets up automatic event listeners based on method names (`onEventName`, `oneEventName`).
138
- - **Instance Methods**:
139
- - `.trigger(eventName, data)`: Base trigger logic used by `MC` and `DC`.
140
-
141
- ### Exported: `MC` Class
142
-
143
- Base class for non-DOM or server-side components. Extends `McBase`.
144
-
145
- - **Instance Properties**:
146
- - `.target`: (Inherited from `McBase`) Refers to the parent MC/DC instance it's nested within.
147
- - **Instance Methods**:
148
- - `.trigger(eventName, data)`: (Inherited) Triggers events locally within the instance and its nested `_mc` structure. Does not handle DOM bubbling.
149
-
150
- ### Exported: `DC` Class
151
-
152
- Class for DOM-aware components. Extends `McBase`. **Client-side only.**
153
-
154
- - **Static Methods**:
155
- - `DC.add(domElement, key, mcInstance)`: Attaches an `mcInstance` (should be a `DC` or `MC`) to a `domElement` under the specified `key`. Creates `domElement._mc` if needed and sets the `_mc` attribute.
156
- - `DC.remove(domElement, key)`: Removes the MC instance associated with `key` from `domElement._mc`. Removes the `data-mc` attribute if the collection becomes empty.
157
- - `DC.trigger(domElement, eventName, data, bubble)`: Triggers an event on all MCs attached to `domElement`. Handles DOM bubbling (`'l'`, `'u'`, `'d'`).
158
- - **Instance Properties**:
159
- - `.target`: (Inherited from `McBase`) Refers to the DOM HTMLElement this `DC` instance is attached to (via `DC.add`).
160
- - **Instance Methods**:
161
- - `.closest()`: Gets MC instances from the closest HTMLElement that has MCs attached.
162
- - `.ancestors()`: Gets MC instances from all ancestor HTMLElements with MCs attached MCs.
163
- - `.children()`: Gets MC instances from direct child HTMLElements with MCs attached.
164
- - `.descendants()`: Gets MC instances from all descendant HTMLElements with MCs attached.
165
- - `.trigger(eventName, data, bubble)`: Triggers an event on this `DC` instance. Can initiate DOM bubbling (`'l'`, `'u'`, `'d'`).
166
-
167
- ## Examples
168
-
169
- ### Typical Workflow
170
-
171
- 1. Define your component classes extending `MC` or `DC`. These contain plain data, observable state, event callbacks and optional internal MCs.
172
- 2. Attach defined top-level `DC` instances to HTMLElements using `DC.add()`.
173
- 3. Then...
174
- - Select and access other MCs using DOM traversal methods (`ancestors()`, `closest()`, `children()`, `descendants()` )
175
- - Dynamically attach event handlers (`on()`, `one()`, `off()`).
176
- - Communicate with other components via Events (`trigger()`).
177
-
178
- ### Attach Micro Components (`DC.add`)
179
-
180
- Use the static `DC.add()` method to attach a component (usually a `DC` instance) to an HTMLElement.
181
-
182
- ```javascript
183
- const myElement = document.getElementById('myDiv');
184
-
185
- // Define a public DC class
186
- class MyClass extends DC {
187
-
188
- constructor(target) {
189
- // target will be myElement
190
- super(target);
191
- console.log('Outer DC target:', this.target);
192
- }
193
-
194
- doSomething() {
195
- console.log('Outer action!');
196
- }
197
-
198
- onClick(event) {
199
- console.log('Div clicked!', event);
200
- }
201
- }
202
-
203
- // Attach the DC instance to the DOM element
204
- // The key 'MyClass' is used to access it later via myElement._mc.myComponent
205
- DC.add(myElement, 'MyClass', new MyClass(myElement));
206
-
207
- // Hint: After adding, myElement now has:
208
- // 1. A property: myElement._mc = { MyClass: <instanceOfMyClass> }
209
- // 2. An attribute: <div id="myDiv" data-mc>...</div>
210
- ```
211
-
212
- ### Remove Micro Components (DC.remove)
213
-
214
- Use the static DC.remove() method to detach a top-level component.
215
-
216
- ```javascript
217
- const myElement = document.getElementById('myDiv');
218
-
219
- DC.remove(myElement, 'myComponent');
220
-
221
- // If myElement._mc is now empty, the 'data-mc' attribute is also removed.
222
- ```
223
- Hint: I have yet to find a usage example for this... so far it simply exists as a counterpart to `DC.add()`.
224
-
225
- ### Retrieve Micro Components
226
-
227
- Access attached components via the `_mc` property of the target element or parent component.
228
-
229
- ```javascript
230
- // Get the container object for all MCs on an element
231
- const myElement = document.getElementById('myDiv');
232
- const mcContainer = myElement._mc;
233
- console.log(mcContainer); // { myComponent: instanceOfMyPublicClass, ... }
234
-
235
- // Get a specific instance by its key
236
- const specificInstance = myElement._mc?.myComponent;
237
- if (specificInstance) {
238
- specificInstance.doSomethingOuter();
239
- }
240
- ```
241
-
242
- ### Triggering Events
243
-
244
- 1. Triggering from outside onto components on an element:
245
-
246
- ```javascript
247
- const targetElement = document.getElementById('myDiv');
248
- const eventData = { message: 'Hello from outside!' };
249
-
250
- // Trigger 'customEvent' locally on MCs attached to targetElement
251
- trigger(targetElement, 'customEvent', eventData, 'l');
252
-
253
- // Trigger 'customEvent' and bubble up the DOM tree
254
- trigger(targetElement, 'customEvent', eventData, 'u');
255
-
256
- // Trigger 'customEvent' locally, bubble up, and bubble down
257
- trigger(targetElement, 'customEvent', eventData, 'lud');
258
- ```
259
-
260
- 2. Triggering from inside a component instance:
261
-
262
- ```javascript
263
- class MyTriggeringComponent extends DC {
264
- // ... constructor ...
265
-
266
- someMethod() {
267
- const eventData = { source: 'MyTriggeringComponent' };
268
-
269
- // Trigger 'internalEvent' only on this instance and its nested _mc components
270
- this.trigger('internalEvent', eventData); // Default bubble 'l'
271
-
272
- // Trigger 'downwardEvent' on components attached to descendant elements
273
- this.trigger('downwardEvent', eventData, 'd'); // Bubbles down from this component's target
274
- }
275
-
276
- // Event handler methods
277
- onCustomEvent(event) {
278
- console.log(`[${this.constructor.name}] received customEvent:`, event.data);
279
- }
280
-
281
- onInternalEvent(event) {
282
- console.log(
283
- `[${this.constructor.name}] received internalEvent:`,
284
- event.data
285
- );
286
- }
287
-
288
- onDownwardEvent(event) {
289
- console.log(
290
- `[${this.constructor.name}] ERROR: received downwardEvent`,
291
- event.data
292
- );
293
- }
294
- }
295
- ```
296
-
297
- ### Navigating closest/Ancestor MCs
298
-
299
- Use .closest() and .ancestors() (available on DC instances) to find components attached to elements higher up the DOM tree.
300
-
301
- These methods skip elements that don't have any MCs attached.
302
-
303
- ```javascript
304
- // Inside a method of a DC instance:
305
- const closestMcs = this.closest(); // Array of MC instances on the closest parent element that contains MCs
306
- console.log(closestMcs);
307
-
308
- const allAncestorMcs = this.ancestors(); // Array of all MC instances on all ancestor elements with MCs
309
- console.log(allAncestorMcs);
310
-
311
- // Find a specific component type/key among ancestors
312
- const specificAncestor = this.ancestors('someSpecificKey')?.[0];
313
-
314
- if (specificAncestor) {
315
- console.log('Found specific ancestor:', specificAncestor);
316
- }
317
- ```
318
-
319
- ### Retrieving Child/Descendant MCs
320
-
321
- Use .children() and .descendants() (available on DC instances) to find components attached to elements lower down the DOM tree.
322
-
323
- ```javascript
324
- // Inside a method of a DC instance:
325
- const childMcs = this.children(); // Array of MCs on direct child elements with MCs
326
- console.log(childMcs);
327
-
328
- const descendantMcs = this.descendants(); // Array of all MCs on all descendant elements with MCs
329
- console.log(descendantMcs);
330
-
331
- // Find specific components among descendants
332
- const specificDescendants = this.descendants('someSpecificKey');
333
- console.log(specificDescendants); // Array of matching descendant MCs
334
- ```
335
-
336
- ### Auto-attaching DOM Listeners
337
-
338
- Methods defined in your DC class starting with `on` or `one` followed by a capital letter, which also match native DOM event names (case-insensitive check), will automatically have listeners attached to the target DOM element:
339
-
340
- ```javascript
341
- class McWithHandlers extends DC {
342
- constructor(target) {
343
- super(target);
344
- }
345
-
346
- // This method name matches the native 'click' event.
347
- // A listener will be automatically added to this.target.
348
- onClick(domEvent) {
349
- console.log('Target element clicked!', domEvent);
350
- // 'this' refers to the MyClickHandler instance
351
- this.target.style.backgroundColor = 'lightblue';
352
- }
353
-
354
- // This method name matches the native 'mouseover' event.
355
- // 'one' means the listener will be removed after the first trigger.
356
- oneMouseover(domEvent) {
357
- console.log('Mouseover detected once!', domEvent);
358
- this.target.style.border = '2px solid red';
359
- }
360
-
361
- // This is a custom event handler, not a native DOM event.
362
- // It will be triggered by this.trigger('CustomAction')
363
- onCustomAction(mcEvent) {
364
- console.log('Custom action triggered!', mcEvent.data, mcEvent.bubble);
365
- }
366
- }
367
-
368
- const myDiv = document.getElementById('clickableDiv');
369
- DC.add(myDiv, 'clickHandler', new McWithHandlers(myDiv));
370
- // Now clicking or mousing over 'clickableDiv' will trigger the methods.
371
- ```
372
-
373
- ### Lifecycle Events
374
-
375
- The framework defines specific methods that are called at certain points in a component's life.
376
-
377
- #### Init
378
-
379
- Method Name: oneInit(event)
380
-
381
- Triggered: Asynchronously (setTimeout(0)) after the component instance is created (called from McBase constructor via the init helper).
382
-
383
- Execution Order:
384
-
385
- The component's oneInit is called first, then it recursively calls oneInit on any components nested within its `_mc` property.
386
-
387
- Requirement:
388
-
389
- - You must define a method named `oneInit` in your class for it to be called.
390
- - The `one` prefix implies it's intended to run once during initialization.
391
-
392
- ```javascript
393
- class MyLifecycleComponent extends DC {
394
- constructor(target) {
395
- super(target);
396
- console.log('Constructor finished');
397
- this._mc.nested = new NestedComponent(this);
398
- }
399
-
400
- oneInit(event) {
401
- // called asynchronous after the constructor finishes.
402
- console.log('MyLifecycleComponent oneInit called!', event);
403
- // Safe to access this.target or setup things that depend on the instance being fully constructed.
404
- }
405
- }
406
- ```
407
- ## Auto Loading
408
-
409
- `autoload()` provides a **progressive enhancement** strategy. It allows you to declare custom elements or special micro components in your HTML without needing to include all their JavaScript code upfront.
410
-
411
- The necessary code is fetched and executed only when these components actually appear in the DOM, potentially improving initial page load time and resource usage.
412
-
413
- ### Enabling
414
-
415
- - If you call **`autoload(true)`** (or just **`autoload()`** as true is the parameter default), it initializes a MutationObserver.
416
- This observer watches the document.body for any changes to its child elements or subtree (e.g., when new elements are added to the page).
417
-
418
- **./autoload.html**
419
- ```html
420
- <!DOCTYPE html>
421
- <html lang="en">
422
- <head>
423
- <meta charset="UTF-8" />
424
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
425
- <title>Humble Beginnings</title>
426
- <script src="./microcomponents.min.js"></script>
427
- <script>
428
- Object.assign(window, microcomponents); // make system global
429
- autoload(true); // automatically load web components that are undefined
430
- </script>
431
- </head>
432
- <body>
433
- <div _mc="test-mymc"></div> <!--- example of a auto-loading micro component --->
434
- <test-component></test-component> <!--- example of a auto-loading custom element --->
435
- </body>
436
- </html>
437
-
438
- ```
439
-
440
- **./test/mymc.ts**
441
- ```typescript
442
- 'use strict';
443
- import { DC } from '../microcomponents.js';
444
-
445
- export default class myMC extends DC {
446
- constructor(target: HTMLElement) {
447
- super(target);
448
- }
449
-
450
- oneInit() {
451
- console.log('testmc connected to DOM');
452
- }
453
- }
454
- ```
455
-
456
- **./test/component.ts**
457
- ```typescript
458
- 'use strict';
459
- import { DC, defineCE } from '.././microcomponents.js';
460
-
461
- defineCE(
462
- 'test-component',
463
-
464
- class extends DC {
465
- data: unknown;
466
-
467
- constructor(target: HTMLElement) {
468
- super(target);
469
-
470
- let shadow = (this as DC).target.attachShadow({ mode: 'open' });
471
- shadow.innerHTML = `<style>${this.css}</style>${this.template}`;
472
- }
473
-
474
- get template() {
475
- return /*html*/ `
476
- <span>Hello World</span>
477
- `;
478
- }
479
-
480
- get css() {
481
- return /*css*/ `
482
- div {
483
- background-color: cyan;
484
- }`;
485
- }
486
- }
487
- );
488
- ```
489
-
490
- **Page HTML after loading**
491
- ```HTML
492
- (...)
493
- <div _mc=""></div> <!--- _mc component definition now empty to avoid re-loading --->
494
- <test-component></test-component> <!--- the custom element is initialized now --->
495
- (...)
496
- ```
497
-
498
- ### Disabling:
499
-
500
- - If you call **`autoload(false)`**, it disconnects the observer, stopping the automatic loading feature:
501
-
502
- ```typescript
503
- autoload(false);
504
- ```
505
-
506
- ### Loading Mechanism:
507
-
508
- When enabled and changes are detected in the DOM, the a callback function is triggered. This function scans the DOM for two types of components that might not yet be defined:
509
-
510
- - **Undefined Custom Elements:** It looks for HTML elements whose tag names haven't been defined via customElements.define() (e.g., `<my-custom-tag>`).
511
-
512
- For an element like `<my-custom-tag>`, it will attempt to load a script from a path derived from the tag name, such as **`./my/custom/tag.js`**. The loaded script is expected to then define this custom element.
513
-
514
- - **Undefined Micro Components:** It looks for HTML elements that have an **`_mc`** attribute that is not empty, e.g., **`<div _mc="my-component my-other">`**.
515
-
516
- **For each component name** listed in the **`_mc`** attribute (like **`my-component`**), it will attempt to load a script from a path like **`./my/component.js`**.
517
-
518
- **These scripts are expected to `export default class {...}`** (usually extending DC from your code) that defines the behavior of this micro component.
519
-
520
- **In general:**
521
-
522
- - For each undefined component found, it dynamically creates a **`<script type="module">`** tag in the **`head`** of the document, and sets its src attribute to the appropriate path.
523
-
524
- - The src of the script is determined by converting the component name (e.g., **`my-component`**) into a path (e.g., **`./my/component.js`**).
525
-
526
- - These script tags are appended to the `<head>` of the document to initiate loading.
527
-
528
- ### Internal Callbacks and Instantiation:
529
-
530
- - **Custom Elements:**
531
- Once the script for a custom element loads and defines the element (using customElements.define()), the browser automatically handles upgrading any existing instances of that tag.
532
-
533
- - **Micro Components:**
534
- When a script for an _mc component loads successfully, a another callback is executed. This callback:
535
- - Stores the loaded component class in an internal repository to avoid unnecessary reloading.
536
- - Finds all HTMLElement in the DOM that declared this _mc component.
537
- - Instantiates the component class and adds it to the HTMLElement.
538
- - Removes the component's name from the _mc attribute to prevent re-processing.
539
-
540
- ### State Tracking:
541
-
542
- `autoload()` internally uses two Map() objects:
543
-
544
- - **`CEs`** (for Custom Elements that are currently loading)
545
- - **`MCs`** (for Micro Components), to keep track of components that are currently loading or have been loaded. This prevents attempting to load the same component multiple times.
546
-
547
- These maps are exposed for debugging purposes. You can access them via `autoload.state` which returns an object with `CEs` and `MCs` properties.
@@ -1,15 +0,0 @@
1
- <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
2
- <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
3
- <title>test</title>
4
- <rect fill="transparent" x="0" y="0" width="200" height="200" fill-opacity="1"/>
5
- <g style="fill:transparent">
6
- <title>first bird</title>
7
- <path fill="#18829c" d="
8
- m15,160
9
- a30,75 45 1 0 160,-150
10
- a20,50 225 1 1 -110,100
11
- a12,25 45 1 1 60,-50
12
- a20,50 225 1 0 -110,100
13
- " />
14
- </g>
15
- </svg>
Binary file
Binary file
Binary file