@twobirds/microcomponents 0.1.1 → 0.1.2

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 (324) hide show
  1. package/dist/MC.min.js +33 -52
  2. package/dist/elements.min.js +1 -1
  3. package/dist/formValues.min.js +1 -1
  4. package/dist/microcomponents.min.js +1 -1
  5. package/dist/observables.min.js +1 -1
  6. package/package.json +11 -2
  7. package/.gitlab-ci.yml +0 -18
  8. package/.vscode/settings.json +0 -3
  9. package/MicroComponents.svg +0 -15
  10. package/assets/documentation/MC.md +0 -547
  11. package/assets/documentation/MicroComponents.svg +0 -15
  12. package/assets/documentation/ajaxian-1.png +0 -0
  13. package/assets/documentation/ajaxian-2.png +0 -0
  14. package/assets/documentation/ajaxian-3.png +0 -0
  15. package/assets/documentation/elements.md +0 -277
  16. package/assets/documentation/formvalues.md +0 -25
  17. package/assets/documentation/functional_requirements.md +0 -8
  18. package/assets/documentation/history.md +0 -436
  19. package/assets/documentation/klemmstein.png +0 -0
  20. package/assets/documentation/magic.md +0 -29
  21. package/assets/documentation/observables.md +0 -187
  22. package/assets/documentation/rnd0023-1.jpg +0 -0
  23. package/assets/documentation/rnd0023-2.jpg +0 -0
  24. package/assets/documentation/rnd0023-3.jpg +0 -0
  25. package/assets/documentation/tB_react.md +0 -207
  26. package/assets/documentation/usage.md +0 -142
  27. package/assets/documentation/why.md +0 -25
  28. package/assets/fiddle/MicroComponents.svg +0 -15
  29. package/assets/fiddle/fiddle.css +0 -0
  30. package/assets/fiddle/fiddle.js +0 -0
  31. package/assets/fiddle/index.html +0 -0
  32. package/assets/test/MicroComponents.svg +0 -15
  33. package/assets/test/grandparent.css +0 -16
  34. package/assets/test/myButton.css +0 -19
  35. package/assets/test/style.css +0 -8
  36. package/assets/test/test.html +0 -29
  37. package/assets/test/testform.json +0 -27
  38. package/public/.nojekyll +0 -1
  39. package/public/MC.d.ts +0 -39
  40. package/public/MC.d.ts.map +0 -1
  41. package/public/MC.js +0 -287
  42. package/public/MC.js.map +0 -1
  43. package/public/MC.min.js +0 -348
  44. package/public/MC.ts +0 -431
  45. package/public/MicroComponents.svg +0 -15
  46. package/public/documentation/MC.md +0 -547
  47. package/public/documentation/MicroComponents.svg +0 -15
  48. package/public/documentation/ajaxian-1.png +0 -0
  49. package/public/documentation/ajaxian-2.png +0 -0
  50. package/public/documentation/ajaxian-3.png +0 -0
  51. package/public/documentation/elements.md +0 -277
  52. package/public/documentation/formvalues.md +0 -25
  53. package/public/documentation/functional_requirements.md +0 -8
  54. package/public/documentation/history.md +0 -436
  55. package/public/documentation/klemmstein.png +0 -0
  56. package/public/documentation/magic.md +0 -29
  57. package/public/documentation/observables.md +0 -187
  58. package/public/documentation/rnd0023-1.jpg +0 -0
  59. package/public/documentation/rnd0023-2.jpg +0 -0
  60. package/public/documentation/rnd0023-3.jpg +0 -0
  61. package/public/documentation/tB_react.md +0 -207
  62. package/public/documentation/usage.md +0 -142
  63. package/public/documentation/why.md +0 -25
  64. package/public/elements.d.ts +0 -5
  65. package/public/elements.d.ts.map +0 -1
  66. package/public/elements.js +0 -68
  67. package/public/elements.js.map +0 -1
  68. package/public/elements.min.js +0 -1
  69. package/public/elements.ts +0 -119
  70. package/public/fiddle/MicroComponents.svg +0 -15
  71. package/public/fiddle/fiddle.css +0 -0
  72. package/public/fiddle/fiddle.js +0 -0
  73. package/public/fiddle/index.html +0 -0
  74. package/public/formValues.d.ts +0 -3
  75. package/public/formValues.d.ts.map +0 -1
  76. package/public/formValues.js +0 -162
  77. package/public/formValues.js.map +0 -1
  78. package/public/formValues.min.js +0 -1
  79. package/public/formValues.ts +0 -225
  80. package/public/helpers.d.ts +0 -14
  81. package/public/helpers.d.ts.map +0 -1
  82. package/public/helpers.js +0 -113
  83. package/public/helpers.js.map +0 -1
  84. package/public/helpers.ts +0 -149
  85. package/public/microcomponents.d.ts +0 -6
  86. package/public/microcomponents.d.ts.map +0 -1
  87. package/public/microcomponents.js +0 -7
  88. package/public/microcomponents.js.map +0 -1
  89. package/public/microcomponents.min.js +0 -1
  90. package/public/microcomponents.ts +0 -8
  91. package/public/observables.d.ts +0 -11
  92. package/public/observables.d.ts.map +0 -1
  93. package/public/observables.js +0 -244
  94. package/public/observables.js.map +0 -1
  95. package/public/observables.min.js +0 -1
  96. package/public/observables.ts +0 -416
  97. package/public/selectors._ts +0 -1269
  98. package/public/src/MC.d.ts +0 -39
  99. package/public/src/MC.d.ts.map +0 -1
  100. package/public/src/MC.js +0 -287
  101. package/public/src/MC.js.map +0 -1
  102. package/public/src/MC.ts +0 -431
  103. package/public/src/elements.d.ts +0 -5
  104. package/public/src/elements.d.ts.map +0 -1
  105. package/public/src/elements.js +0 -68
  106. package/public/src/elements.js.map +0 -1
  107. package/public/src/elements.ts +0 -119
  108. package/public/src/formValues.d.ts +0 -3
  109. package/public/src/formValues.d.ts.map +0 -1
  110. package/public/src/formValues.js +0 -162
  111. package/public/src/formValues.js.map +0 -1
  112. package/public/src/formValues.ts +0 -225
  113. package/public/src/helpers.d.ts +0 -14
  114. package/public/src/helpers.d.ts.map +0 -1
  115. package/public/src/helpers.js +0 -113
  116. package/public/src/helpers.js.map +0 -1
  117. package/public/src/helpers.ts +0 -149
  118. package/public/src/microcomponents.d.ts +0 -6
  119. package/public/src/microcomponents.d.ts.map +0 -1
  120. package/public/src/microcomponents.js +0 -7
  121. package/public/src/microcomponents.js.map +0 -1
  122. package/public/src/microcomponents.ts +0 -8
  123. package/public/src/observables.d.ts +0 -11
  124. package/public/src/observables.d.ts.map +0 -1
  125. package/public/src/observables.js +0 -244
  126. package/public/src/observables.js.map +0 -1
  127. package/public/src/observables.ts +0 -416
  128. package/public/src/selectors._ts +0 -1269
  129. package/public/src/test/grandparent.css +0 -14
  130. package/public/src/test/test/child.d.ts +0 -2
  131. package/public/src/test/test/child.d.ts.map +0 -1
  132. package/public/src/test/test/child.js +0 -26
  133. package/public/src/test/test/child.js.map +0 -1
  134. package/public/src/test/test/child.ts +0 -36
  135. package/public/src/test/test/grandchild.d.ts +0 -2
  136. package/public/src/test/test/grandchild.d.ts.map +0 -1
  137. package/public/src/test/test/grandchild.js +0 -22
  138. package/public/src/test/test/grandchild.js.map +0 -1
  139. package/public/src/test/test/grandchild.ts +0 -31
  140. package/public/src/test/test/grandparent.d.ts +0 -2
  141. package/public/src/test/test/grandparent.d.ts.map +0 -1
  142. package/public/src/test/test/grandparent.js +0 -1
  143. package/public/src/test/test/grandparent.js.map +0 -1
  144. package/public/src/test/test/grandparent.ts +0 -43
  145. package/public/src/test/test/greatgrandchild.d.ts +0 -2
  146. package/public/src/test/test/greatgrandchild.d.ts.map +0 -1
  147. package/public/src/test/test/greatgrandchild.js +0 -36
  148. package/public/src/test/test/greatgrandchild.js.map +0 -1
  149. package/public/src/test/test/greatgrandchild.ts +0 -51
  150. package/public/src/test/test/parent.d.ts +0 -2
  151. package/public/src/test/test/parent.d.ts.map +0 -1
  152. package/public/src/test/test/parent.js +0 -25
  153. package/public/src/test/test/parent.js.map +0 -1
  154. package/public/src/test/test/parent.ts +0 -35
  155. package/public/src/test/test/testform.d.ts +0 -2
  156. package/public/src/test/test/testform.d.ts.map +0 -1
  157. package/public/src/test/test/testform.js +0 -1
  158. package/public/src/test/test/testform.js.map +0 -1
  159. package/public/src/test/test/testform.ts +0 -153
  160. package/public/src/test/test/testfunction.d.ts +0 -3
  161. package/public/src/test/test/testfunction.d.ts.map +0 -1
  162. package/public/src/test/test/testfunction.js +0 -7
  163. package/public/src/test/test/testfunction.js.map +0 -1
  164. package/public/src/test/test/testfunction.ts +0 -12
  165. package/public/src/test/test/testmc.d.ts +0 -3
  166. package/public/src/test/test/testmc.d.ts.map +0 -1
  167. package/public/src/test/test/testmc.js +0 -10
  168. package/public/src/test/test/testmc.js.map +0 -1
  169. package/public/src/test/test/testmc.ts +0 -16
  170. package/public/src/test/test/testsimpleclass.d.ts +0 -3
  171. package/public/src/test/test/testsimpleclass.d.ts.map +0 -1
  172. package/public/src/test/test/testsimpleclass.js +0 -9
  173. package/public/src/test/test/testsimpleclass.js.map +0 -1
  174. package/public/src/test/test/testsimpleclass.ts +0 -15
  175. package/public/src/test/test.d.ts +0 -2
  176. package/public/src/test/test.d.ts.map +0 -1
  177. package/public/src/test/test.js +0 -72
  178. package/public/src/test/test.js.map +0 -1
  179. package/public/src/test/test.ts +0 -176
  180. package/public/src/test/testform.css +0 -47
  181. package/public/src/test/testform.html +0 -56
  182. package/public/src/test/testform.json +0 -27
  183. package/public/test/MC.d.ts +0 -39
  184. package/public/test/MC.d.ts.map +0 -1
  185. package/public/test/MC.js +0 -287
  186. package/public/test/MC.min.js +0 -348
  187. package/public/test/MC.ts +0 -431
  188. package/public/test/MicroComponents.svg +0 -15
  189. package/public/test/elements.d.ts +0 -5
  190. package/public/test/elements.d.ts.map +0 -1
  191. package/public/test/elements.js +0 -68
  192. package/public/test/elements.min.js +0 -1
  193. package/public/test/elements.ts +0 -119
  194. package/public/test/formValues.d.ts +0 -3
  195. package/public/test/formValues.d.ts.map +0 -1
  196. package/public/test/formValues.js +0 -162
  197. package/public/test/formValues.min.js +0 -1
  198. package/public/test/formValues.ts +0 -225
  199. package/public/test/grandparent.css +0 -14
  200. package/public/test/helpers.d.ts +0 -14
  201. package/public/test/helpers.d.ts.map +0 -1
  202. package/public/test/helpers.js +0 -113
  203. package/public/test/helpers.ts +0 -149
  204. package/public/test/microcomponents.d.ts +0 -6
  205. package/public/test/microcomponents.d.ts.map +0 -1
  206. package/public/test/microcomponents.js +0 -7
  207. package/public/test/microcomponents.min.js +0 -1
  208. package/public/test/microcomponents.ts +0 -8
  209. package/public/test/myButton.css +0 -19
  210. package/public/test/observables.d.ts +0 -11
  211. package/public/test/observables.d.ts.map +0 -1
  212. package/public/test/observables.js +0 -244
  213. package/public/test/observables.min.js +0 -1
  214. package/public/test/observables.ts +0 -416
  215. package/public/test/style.css +0 -8
  216. package/public/test/test/child.d.ts +0 -2
  217. package/public/test/test/child.d.ts.map +0 -1
  218. package/public/test/test/child.js +0 -26
  219. package/public/test/test/child.js.map +0 -1
  220. package/public/test/test/child.ts +0 -36
  221. package/public/test/test/grandchild.d.ts +0 -2
  222. package/public/test/test/grandchild.d.ts.map +0 -1
  223. package/public/test/test/grandchild.js +0 -22
  224. package/public/test/test/grandchild.js.map +0 -1
  225. package/public/test/test/grandchild.ts +0 -31
  226. package/public/test/test/grandparent.d.ts +0 -2
  227. package/public/test/test/grandparent.d.ts.map +0 -1
  228. package/public/test/test/grandparent.js +0 -1
  229. package/public/test/test/grandparent.js.map +0 -1
  230. package/public/test/test/grandparent.ts +0 -43
  231. package/public/test/test/greatgrandchild.d.ts +0 -2
  232. package/public/test/test/greatgrandchild.d.ts.map +0 -1
  233. package/public/test/test/greatgrandchild.js +0 -36
  234. package/public/test/test/greatgrandchild.js.map +0 -1
  235. package/public/test/test/greatgrandchild.ts +0 -51
  236. package/public/test/test/parent.d.ts +0 -2
  237. package/public/test/test/parent.d.ts.map +0 -1
  238. package/public/test/test/parent.js +0 -25
  239. package/public/test/test/parent.js.map +0 -1
  240. package/public/test/test/parent.ts +0 -35
  241. package/public/test/test/testform.d.ts +0 -2
  242. package/public/test/test/testform.d.ts.map +0 -1
  243. package/public/test/test/testform.js +0 -1
  244. package/public/test/test/testform.js.map +0 -1
  245. package/public/test/test/testform.ts +0 -153
  246. package/public/test/test/testfunction.d.ts +0 -3
  247. package/public/test/test/testfunction.d.ts.map +0 -1
  248. package/public/test/test/testfunction.js +0 -7
  249. package/public/test/test/testfunction.js.map +0 -1
  250. package/public/test/test/testfunction.ts +0 -12
  251. package/public/test/test/testmc.d.ts +0 -3
  252. package/public/test/test/testmc.d.ts.map +0 -1
  253. package/public/test/test/testmc.js +0 -10
  254. package/public/test/test/testmc.js.map +0 -1
  255. package/public/test/test/testmc.ts +0 -16
  256. package/public/test/test/testsimpleclass.d.ts +0 -3
  257. package/public/test/test/testsimpleclass.d.ts.map +0 -1
  258. package/public/test/test/testsimpleclass.js +0 -9
  259. package/public/test/test/testsimpleclass.js.map +0 -1
  260. package/public/test/test/testsimpleclass.ts +0 -15
  261. package/public/test/test.d.ts +0 -2
  262. package/public/test/test.d.ts.map +0 -1
  263. package/public/test/test.html +0 -29
  264. package/public/test/test.js +0 -72
  265. package/public/test/test.js.map +0 -1
  266. package/public/test/test.ts +0 -176
  267. package/public/test/testform.css +0 -47
  268. package/public/test/testform.html +0 -56
  269. package/public/test/testform.json +0 -27
  270. package/public/typedoc/.nojekyll +0 -1
  271. package/public/typedoc/assets/highlight.css +0 -106
  272. package/public/typedoc/assets/icons.js +0 -18
  273. package/public/typedoc/assets/icons.svg +0 -1
  274. package/public/typedoc/assets/main.js +0 -60
  275. package/public/typedoc/assets/navigation.js +0 -1
  276. package/public/typedoc/assets/search.js +0 -1
  277. package/public/typedoc/assets/style.css +0 -1493
  278. package/public/typedoc/classes/MC.DC.html +0 -13
  279. package/public/typedoc/classes/MC.MC.html +0 -3
  280. package/public/typedoc/classes/MC.McBase.html +0 -3
  281. package/public/typedoc/functions/MC.autoload.html +0 -1
  282. package/public/typedoc/functions/MC.off.html +0 -1
  283. package/public/typedoc/functions/MC.on.html +0 -1
  284. package/public/typedoc/functions/MC.one.html +0 -1
  285. package/public/typedoc/functions/MC.trigger.html +0 -1
  286. package/public/typedoc/functions/elements.defineCE.html +0 -1
  287. package/public/typedoc/functions/elements.getCE.html +0 -1
  288. package/public/typedoc/functions/formValues.formValues.html +0 -1
  289. package/public/typedoc/functions/observables.observe.html +0 -1
  290. package/public/typedoc/hierarchy.html +0 -1
  291. package/public/typedoc/index.html +0 -122
  292. package/public/typedoc/interfaces/MC.HTMLMcElement.html +0 -758
  293. package/public/typedoc/media/MicroComponents.svg +0 -15
  294. package/public/typedoc/modules/MC.html +0 -10
  295. package/public/typedoc/modules/elements.html +0 -3
  296. package/public/typedoc/modules/formValues.html +0 -2
  297. package/public/typedoc/modules/observables.html +0 -3
  298. package/public/typedoc/modules.html +0 -5
  299. package/public/typedoc/types/observables.Observable.html +0 -1
  300. package/src/MC.ts +0 -431
  301. package/src/elements.ts +0 -119
  302. package/src/formValues.ts +0 -225
  303. package/src/helpers.ts +0 -149
  304. package/src/microcomponents.ts +0 -8
  305. package/src/observables.ts +0 -416
  306. package/src/selectors._ts +0 -1269
  307. package/src/test/grandparent.css +0 -14
  308. package/src/test/test/child.ts +0 -36
  309. package/src/test/test/grandchild.ts +0 -31
  310. package/src/test/test/grandparent.ts +0 -43
  311. package/src/test/test/greatgrandchild.ts +0 -51
  312. package/src/test/test/parent.ts +0 -35
  313. package/src/test/test/testform.ts +0 -153
  314. package/src/test/test/testfunction.ts +0 -12
  315. package/src/test/test/testmc.ts +0 -16
  316. package/src/test/test/testsimpleclass.ts +0 -15
  317. package/src/test/test.ts +0 -176
  318. package/src/test/testform.css +0 -47
  319. package/src/test/testform.html +0 -56
  320. package/src/test/testform.json +0 -27
  321. package/tasks.md +0 -36
  322. package/tsconfig.json +0 -107
  323. package/typedoc.json +0 -7
  324. package/webpack.config.js +0 -346
@@ -1,207 +0,0 @@
1
- # Discussing React Prop Drilling with ChatGPT
2
-
3
- This is an interesting read where I wanted ChatGPT to come up with a Micro Component solution for a React problem.
4
-
5
- To be honest, I knew MCs can solve it. But I wanted to know what ChatGPT can make of it. Spoiler: it got remarkably close on the first try. The second try was spot on.
6
-
7
- Please mind I have a trained session with a backlog. So you wont get the same answers.
8
-
9
- ***( Cut outs and comments are in parentheses...)***
10
-
11
- ## Start Session
12
-
13
- Me:
14
- **Do you remember our chat regarding Micro Components vs. existing frameworks?**
15
-
16
- ChatGPT:
17
-
18
- Yes, I remember our discussion! We talked about your approach to microcomponents as distinct from established frameworks, with a focus on smaller, modular, data-driven components that are stored in a hash attached to DOM elements (specifically in a _tb property in twoBirds or _mc for microcomponents). Your system emphasizes manual wiring, observability, and ease of interaction across components, making it different from React, Vue, or other component libraries that depend heavily on virtual DOMs, JSX, or hooks.
19
-
20
- Your components follow principles of separation of concerns and DRY by keeping interactions modular but flexible, and they use observables to trigger functions in other components, which can be linked in chains. Your approach allows a component-based design that integrates deeply into the DOM without the overhead of larger frameworks. And while existing frameworks typically follow a top-down data flow, your system allows bi-directional, observable properties that automatically update the DOM when data changes.
21
-
22
- Would you like to revisit any specific aspect, or compare further?
23
-
24
-
25
- ## React
26
-
27
- Me:
28
- **There was something about React specifically?**
29
-
30
-
31
- ChatGPT:
32
-
33
- (...)
34
-
35
- ### Manual Wiring vs. React’s Context and Hooks:
36
- React uses Context and hooks (like useState and useEffect) to manage data flow and lifecycle.
37
-
38
- Your approach leans on manual wiring for connecting data across microcomponents, avoiding the abstraction of hooks and allowing direct, observable-driven updates. This can make the flow of data more transparent and easier to trace in complex applications, whereas hooks can sometimes add complexity or obscurity when trying to understand data dependencies.
39
-
40
- ### Component Reusability and Scaling:
41
- Both React and Micro Components support component-based architecture.
42
-
43
- However, Micro Components allows multiple microcomponents on a single DOM element, and each microcomponent is responsible for specific tasks, making scaling in large applications more modular and straightforward. React encourages separation at the component level, whereas Micro Components does so at the microcomponent level, with direct chaining possible between components.
44
-
45
- (...)
46
-
47
- Each of these aspects underlines Micro Components’ focus on minimalism, modularity, and developer control. These are different from React's abstraction and tooling-heavy approach, making your framework potentially more transparent and lightweight for specific use cases.
48
-
49
- Would you like to dive into any of these differences in more detail?
50
-
51
-
52
- ## Prop Drilling
53
-
54
- Me:
55
- **In general there was a problem regarding carrying properties from a component close to the root of the document to a component that is much deeper into the DOM tree, do you remember that?**
56
-
57
- ChatGPT:
58
-
59
- Yes, I remember!
60
-
61
- We discussed the challenges in carrying properties or state from a root-level component down to deeply nested components. In React, this kind of deep property sharing can become cumbersome and often requires additional tools or patterns, such as:
62
-
63
- ### Prop Drilling:
64
- React requires passing data through each level of components in the tree via props, a process known as prop drilling. This can lead to complex and hard-to-manage code, especially when the data isn’t relevant to every component in the chain.
65
-
66
- (...)
67
-
68
- In contrast, your Micro Components microcomponents have an alternative approach that makes it easier to pass properties throughout the DOM tree:
69
-
70
- ### Direct Microcomponent Selectors:
71
- Micro Components includes selector methods (like .parents() and .descendants()) that allow components to access any microcomponent within the tree without explicit data passing. This capability enables deeply nested components to retrieve properties from higher-level components directly, bypassing the need to route data through intermediary components.
72
-
73
- (...)
74
-
75
- ### Manual Wiring for Control:
76
-
77
- **Because Micro Components rely on manual wiring, you can set up specific connections between components as needed.** This gives you fine-grained control over where and how data flows through the app without involving a top-level state or intermediary components, making it more scalable for larger apps without the need for a Context API or state library.
78
-
79
- (...)
80
-
81
- This structure offers a highly flexible, context-free solution for deep property sharing, making it an efficient alternative to prop drilling or global state libraries in many scenarios. Would you like more details on how Micro Components selectors work with observables to achieve this?
82
-
83
-
84
- ## Generate Code
85
-
86
- Me:
87
- **Can you give an example of 2 react components that interact with each other using micro components? Give me the code of both components, using microomponents to exchange data**
88
-
89
- ***( it took some further hinting, but in the end ChatGPT came up with this: )***
90
-
91
-
92
- ChatGPT:
93
-
94
- Here's the updated code:
95
- Parent Micro Component
96
-
97
- This component will receive a target DOM node and set a value that propagates down to its descendants:
98
-
99
- ```javascript
100
- import { MC } from '@twobirds/microcomponents';
101
-
102
- // Parent Micro Component
103
- class ParentMC extends MC {
104
- constructor(targetNode) {
105
- super(targetNode); // Receive and pass the target DOM node to the MC constructor
106
- }
107
-
108
- set value(newValue) {
109
- // Send value to all descendants named "targetMC"
110
- this.descendants("targetMC").forEach(descendant => descendant.data = newValue);
111
- }
112
- }
113
- ```
114
-
115
- Child Micro Component
116
-
117
- This component has a data setter that updates the internal React state in each child:
118
-
119
- ```javascript
120
- import { MC } from '@twobirds/microcomponents';
121
-
122
- // Child Micro Component
123
- class ChildMC extends MC {
124
- constructor(targetNode, setReactState) {
125
- super(targetNode); // Receive the target DOM node to be managed by MC
126
- this.setReactState = setReactState;
127
- }
128
-
129
- set data(newValue) {
130
- this.setReactState(newValue); // Update React state when data is set
131
- }
132
- }
133
- ```
134
-
135
- React Components Using Micro Components
136
-
137
- The following React setup attaches ParentMC and ChildMC to their respective DOM elements, using the parent DOM node to instantiate the micro components.
138
- Parent Component
139
-
140
- The parent component attaches an instance of ParentMC to the DOM node and sets its value based on inputValue.
141
-
142
- ```javascript
143
-
144
- import React, { useState, useRef, useEffect } from 'react';
145
- import { MC } from '@twobirds/microcomponents';
146
- import { ParentMC } from '@myCompany/ParentMC';
147
-
148
- const ParentComponent = () => {
149
- const [inputValue, setInputValue] = useState("");
150
- const parentRef = useRef(null);
151
- const parentMC = new ParentMC( parentRef );
152
- const sender = MC.add(parentRef.current, 'parentMC', parentMC);
153
-
154
- useEffect(() => {
155
- // Update value in ParentMC whenever inputValue changes
156
- parentMC.value = inputValue;
157
- }, [inputValue]);
158
-
159
- return (
160
- <div ref={parentRef}>
161
- <input
162
- type="text"
163
- value={inputValue}
164
- onChange={(e) => setInputValue( e.target.value )}
165
- placeholder="Type to send data to children"
166
- />
167
- <ChildComponent />
168
- </div>
169
- );
170
- };
171
- ```
172
-
173
- Child Component
174
-
175
- The child component attaches an instance of ChildMC, which updates its state whenever data is set.
176
-
177
- ```javascript
178
- import React, { useState, useRef } from 'react';
179
- import { MC } from '@twobirds/microcomponents';
180
- import { ChildMC } from '@myCompany/ChildMC';
181
-
182
-
183
- const ChildComponent = () => {
184
- const [childData, setChildData] = useState("");
185
- const childRef = useRef(null);
186
- const childMC = new ChildMC( childRef, setChildData );
187
- const receiver = MC.add(childRef.current, 'childMC', childMC);
188
-
189
- return (
190
- <div ref={childRef}>
191
- <h3>Received Data:</h3>
192
- <p>childData</p>
193
- </div>
194
- );
195
- };
196
- ```
197
-
198
- ***( ... I cannot tell about the react part, but the micro coomponent code is spot on. Like WLAN on the DOM :-) )***
199
-
200
-
201
- **ChatGPT can produce errors. Check the information.**
202
-
203
- ## ... yes I do :-)
204
-
205
- ***( ... but it was right on the money in the end. I love AI, albeit with a healthy grain of sceptic salt. )***
206
-
207
- ***( ... and I asked about MCs and Angular likewise, and it directly pointed me to a NG module problem that can also be solved. It even came up with sample code. )***
@@ -1,142 +0,0 @@
1
- # Micro Component Management
2
-
3
- This system allows you to attach, manage, and interact with micro components.
4
-
5
- **Micro Components** can literally be anything you can put into an object as a property.
6
-
7
- Also it has selectors to find micro components in the DOM. It consists of a single class `MC`.
8
-
9
- ## Summary of MC() Methods
10
-
11
- - **Static Methods:**
12
- - `MC.add( target, key, element)`: Attach a top level micro component to an HTMLElement.
13
- - `MC.remove( target, key )`: Detach a top level micro component from an HTMLElement.
14
- - `MC.siblings( target )`: get top level micro components from an HTMLElement.
15
-
16
- - **Instance Methods:**
17
- - `add( key, element )`: Attach a private Micro Component to a Micro Component.
18
- - `remove( key )`: Detach a private Micro Component from a Micro Component.
19
- - `siblings(search?)`: Retrieve sibling micro components.
20
- - `parent(search?)`: Get parent top level micro components.
21
- - `parents(search?)`: Get all ancestor top level micro components.
22
- - `children(search?)`: Retrieve child top level micro components.
23
- - `descendants(search?)`: Get all descendant top level micro components.
24
-
25
- **Micro Components** will most likely be **class instances** that expose inner methods **or an observable collection** for data driven workflows, e.g. business process logic.
26
-
27
- ## Typical Workflow
28
-
29
- 1. **Attach micro components** to elements using `MC.add()`.
30
- 2. **Access** micro components by their property key or navigating through DOM (e.g., `siblings()`, `parents()`, `children()`, etc.) **and use their inner functionality**.
31
- 3. **Manipulate** micro components by adding or removing them as needed or change their properties/call their methods.
32
-
33
-
34
- ## Hints
35
-
36
- - **All static methods handle top level Micro Components. These are PUBLIC, that is they are visible in the DOM elements _mc property and usually have an interface.**
37
-
38
- - **All MC instance methods handle inner Micro Components. These are PRIVATE, that is they are not visible in the DOM elements _mc property.**
39
-
40
- - **Micro Components can recursively contain Micro Components. Just like npm and the node_modules directory.**
41
-
42
-
43
- ## Attaching a top level Micro Component to a DOM element
44
-
45
- To attach a micro component to an HTML element, use the `MC.add()` static function.
46
-
47
- ### Example Usage:
48
- ```javascript
49
- const myElement = document.getElementById('myDiv');
50
-
51
- // Attach a micro component (most often a class instance, here a simple object for simplicity) with a specific key
52
- MC.add( myElement, 'myComponent', { name: 'Mike' } );
53
- ```
54
-
55
- - After you added a micro component using this function, the HTMLElement will contain a property `_mc` which is a MC() class instance that offers some methods.
56
- - Also the HTMLElement then has an attribute _mc which will indicate that at least one micro component is attached to this dom element.
57
-
58
- ## Removing a top level Micro Component from a DOM element
59
-
60
- Micro components can be removed using the `MC.remove()` static method.
61
-
62
- ### Removing a Micro component:
63
- ```javascript
64
- MC.remove( myDomElement, 'myComponent');
65
- ```
66
-
67
- **When all micro components are removed** (the _mc object has no more properties), the `_mc` **attribute is also removed** from the HTML element. The `_mc` **property persists**.
68
-
69
-
70
- ## Retrieve all top level Micro Components from a DOM element
71
-
72
- The `MC.siblings()` method retrieves all top level micro components attached to the same DOM element.
73
-
74
- ### Example:
75
- ```javascript
76
- const target = document.querySelector( 'div' );
77
- const siblings = MC.siblings( target );
78
- console.log(siblings); // Logs an array of top level sibling micro components
79
- ```
80
-
81
- To retrieve a specific micro component by its key:
82
- ```javascript
83
- const target = document.querySelector( 'div' );
84
- const siblings = MC.siblings( target, 'myOtherComponent' );
85
- console.log(siblings); // Logs an array containing a top level sibling micro component, if its key matches the search string
86
- ```
87
-
88
-
89
- ## Retrieving Sibling Micro components
90
-
91
- The `.siblings()` method retrieves all micro components attached to the same DOM element.
92
-
93
- ### Example:
94
- ```javascript
95
- const siblings = myElement._mc.siblings();
96
- console.log(siblings); // Logs an array of sibling micro components
97
- ```
98
-
99
- To retrieve a specific micro component by its key:
100
- ```javascript
101
- const specificSibling = myElement._mc.siblings('anotherComponent');
102
- ```
103
-
104
-
105
- - **The following methods hop over HTMLElements that contain no micro component.**
106
-
107
-
108
- ## 4. Navigating Parent and Ancestor Micro components
109
-
110
- The `_mc.parent()` and `_mc.parents()` methods allow you to retrieve micro components attached to parent elements.
111
-
112
- ### Example:
113
- ```javascript
114
- const parentMc = myElement._mc.parent();
115
- console.log(parentMc); // Logs micro components closest nachestor that has microcomponents
116
-
117
- const allAncestorsMc = myElement._mc.parents();
118
- console.log(allAncestorsMc); // Logs all ancestor micro components up to document
119
- ```
120
-
121
- To retrieve a specific micro component attached to the parent or ancestors:
122
- ```javascript
123
- const specificAncestorMc = myElement._mc.parents('myComponent');
124
- ```
125
-
126
- ## 5. Retrieving Child and Descendant Micro components
127
-
128
- The `_mc.children()` and `_mc.descendants()` methods retrieve micro components attached to child elements or any descendants.
129
-
130
- ### Example:
131
- ```javascript
132
- const childMicro components = myElement._mc.children();
133
- console.log(childMicro components); // Logs an array of nearest child micro components
134
-
135
- const descendantMicro components = myElement._mc.descendants();
136
- console.log(descendantMicro components); // Logs micro components attached to all descendants
137
- ```
138
-
139
- To search for a specific micro component by key:
140
- ```javascript
141
- const specificMc = myElement._mc.<someComponent>;
142
- ```
@@ -1,25 +0,0 @@
1
-
2
- ## Why would I give this a try?
3
-
4
- It is lightweight, proven and can yield positive results immediatly.
5
-
6
-
7
- ### **As the CTO**:
8
-
9
- - **Reusability**: this works with every Javascript framework that allows for DOM access, and it will work as long as the DOM exists in browsers. That is, forever.
10
- - **Scalability**: scales perfectly by design.
11
- - **Interoperability**: where many teams in different projects should share specific business or UI logic, you want to have something that works in any JS framework you use.
12
-
13
- ### **As a Project Manager**:
14
-
15
- - **Separation of Concerns**: since this is a modular approach you can **split UI logic from Business logic** and let diffent teams work on each.
16
- - using this, you can **work with external developers without the need to give them access to your projects code repository**.
17
- - you will find out that this allows your project to **become independent from the "tools hell"**. You tend to use **DIY** modules where you had tools before.
18
-
19
- ### **As a Javascript Developer**:
20
-
21
- - The learning curve to use this is more than shallow. 1 hour should be enough.
22
- - This is based on **plain Javascript/Typescript, HTML and CSS**. There is no abstraction layer.
23
- - From the very start **it is fun to work with**. You are back in control of your code without bigger frameworks, but you are able to interact with them.
24
- - You can **work for any customer right away**. **No training on their system required**, just fulfill their micro component requirements.
25
- - Over time, you can **build your own framework or functional libraries** from scratch.
@@ -1,5 +0,0 @@
1
- export declare function defineCE(tagName: string, DefinitionClass: {
2
- new (...args: any[]): any;
3
- } | Function, observedAttributes?: string[]): void;
4
- export declare function getCE(tagName: string): CustomElementConstructor | undefined;
5
- //# sourceMappingURL=elements.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAoDA,wBAAgB,QAAQ,CACvB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,GAAG,QAAQ,EACzD,kBAAkB,GAAE,MAAM,EAAO,QA2DjC;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAE3E"}
@@ -1,68 +0,0 @@
1
- 'use strict';
2
- import { DC, McBase } from './MC.js';
3
- import { kebabToPascal } from './helpers.js';
4
- class CeBaseClass extends HTMLElement {
5
- constructor() {
6
- super();
7
- }
8
- connectedCallback() {
9
- this.dispatchEvent(new CustomEvent('_mcConnected'));
10
- }
11
- connectedMoveCallback() {
12
- this.dispatchEvent(new CustomEvent('_mcConnectedMove'));
13
- }
14
- disconnectedCallback() {
15
- this.dispatchEvent(new CustomEvent('_mcDisconnected'));
16
- }
17
- adoptedCallback() {
18
- this.dispatchEvent(new CustomEvent('_mcAdopted'));
19
- }
20
- attributeChangedCallback(name, oldValue, newValue) {
21
- this.dispatchEvent(new CustomEvent('_mcAttributeChanged', { detail: { name, oldValue, newValue } }));
22
- }
23
- formResetCallback() {
24
- this.dispatchEvent(new CustomEvent('_mcFormReset'));
25
- }
26
- }
27
- function createNamedClass(name, ClassBody) {
28
- return Object.defineProperty(ClassBody, 'name', { value: name });
29
- }
30
- function isClass(func) {
31
- return typeof func === 'function'
32
- && /^class\s/.test(Function.prototype.toString.call(func));
33
- }
34
- export function defineCE(tagName, DefinitionClass, observedAttributes = []) {
35
- if (customElements.get(tagName)) {
36
- console.warn(`IGNORED: Custom element "${tagName}" is already defined!`);
37
- return;
38
- }
39
- if (!tagName.includes('-')) {
40
- throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');
41
- }
42
- let name = kebabToPascal(tagName);
43
- if (!isClass(DefinitionClass.prototype.constructor)) {
44
- customElements.define(tagName, DefinitionClass);
45
- return;
46
- }
47
- if (!(DefinitionClass.prototype instanceof McBase)) {
48
- customElements.define(tagName, DefinitionClass);
49
- return;
50
- }
51
- customElements.define(tagName, createNamedClass(name, class extends CeBaseClass {
52
- instance;
53
- constructor(data) {
54
- super();
55
- const instance = isClass(DefinitionClass)
56
- ? new DefinitionClass(this, data)
57
- : DefinitionClass;
58
- DC.add(this, name, instance);
59
- }
60
- static get observedAttributes() {
61
- return observedAttributes;
62
- }
63
- }));
64
- }
65
- export function getCE(tagName) {
66
- return customElements.get(tagName);
67
- }
68
- //# sourceMappingURL=elements.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"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"}
@@ -1 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.elements=e():t.elements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{defineCE:()=>d,getCE:()=>m});const n=new Function("try {return this===window;}catch(e){ return false;}");function r(t){return t&&t instanceof HTMLElement}function o(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function c(t,e,n,r=!1){return t.addEventListener(o(e),n,{capture:!1,once:r}),n}class s{stopped=!1;constructor(){}stop(){this.stopped=!0}}class i{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==a&&e.trigger("Init")}),0),function(t){if(!n()||t.constructor===a)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),s=o.toLowerCase();if("on"+s in e){let r=e=>{n[t](e)};e.addEventListener(s,r)}else c(e,o,(e=>{n[t](e)}),r)}))}}(this)}get target(){return this._target.deref()}}class a extends i{constructor(t){super(t)}static add(t,e,n={}){return function(t,e,n={}){let r=t;r._mc||(r._mc=new a(t));const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}(t,e,n)}static remove(t,e){!function(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}(t,e)}off(t,e){!function(t,e,n){t.removeEventListener(o(e),n)}(this.target,t,e)}on(t,e){return c(this.target,t,e)}one(t,e){return function(t,e,n){return c(t,e,n,!0),n}(this.target,t,e)}trigger(t,e={},n="l",r){!function(t,e,n={},r="l",c){const i=/^_mc/.test(e)?e:o(e),a=c||new s,u=new CustomEvent(i,{detail:{data:n,control:a},bubbles:!1});a.stopped||(t.dispatchEvent(u),u.stopImmediatePropagation(),a.stopped||/[ud]/.test(r)&&(-1===r.indexOf("l")&&(r+="l"),setTimeout((()=>{if(r.indexOf("u")>-1){let e=t.parentElement?.closest("[data-mc]");e&&e?._mc.trigger(i,n,r,a)}if(r.indexOf("d")>-1){let e=t._mc.children();e&&e.forEach((t=>t.trigger(i,n,r)))}}),0)))}(this.target,t,e,n,r)}ancestors(){let t=this?.target,e=[];if(!r(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return r(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return r(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),r.length?r:null}(t):null}descendants(){const t=this?.target;if(!r(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}new Set;class u 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(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function l(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function d(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");l(e.prototype.constructor)&&e.prototype instanceof i?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends u{instance;constructor(t){super();const n=l(e)?new e(this,t):e;a.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function m(t){return customElements.get(t)}return e})()));
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- import { DC, McBase } from './MC.js';
4
- import { kebabToPascal } from './helpers.js';
5
-
6
- class CeBaseClass extends HTMLElement {
7
- constructor() {
8
- super();
9
- }
10
-
11
- connectedCallback() {
12
- this.dispatchEvent( new CustomEvent('_mcConnected') );
13
- }
14
-
15
- connectedMoveCallback() {
16
- this.dispatchEvent( new CustomEvent('_mcConnectedMove') );
17
- }
18
-
19
- disconnectedCallback() {
20
- this.dispatchEvent( new CustomEvent('_mcDisconnected') );
21
- }
22
-
23
- adoptedCallback() {
24
- this.dispatchEvent( new CustomEvent('_mcAdopted') );
25
- }
26
-
27
- attributeChangedCallback(name: string, oldValue: any, newValue: any) {
28
- this.dispatchEvent(
29
- new CustomEvent(
30
- '_mcAttributeChanged',
31
- { detail: { name, oldValue, newValue } }
32
- )
33
- );
34
- }
35
-
36
- formResetCallback(){
37
- this.dispatchEvent( new CustomEvent('_mcFormReset') );
38
- }
39
- }
40
-
41
- function createNamedClass(
42
- name: string,
43
- ClassBody: { new (...args: any[]): any }
44
- ) {
45
- return Object.defineProperty(ClassBody, 'name', { value: name });
46
- }
47
-
48
- function isClass(func: any) {
49
- return typeof func === 'function'
50
- && /^class\s/.test(Function.prototype.toString.call(func));
51
- }
52
-
53
- export function defineCE(
54
- tagName: string,
55
- DefinitionClass: { new (...args: any[]): any } | Function,
56
- observedAttributes: string[] = []
57
- ) {
58
- if (customElements.get(tagName)) {
59
- console.warn(`IGNORED: Custom element "${tagName}" is already defined!`);
60
- return;
61
- }
62
-
63
- if (!tagName.includes('-')) {
64
- throw new Error(
65
- 'createCustomElement: tagName must contain at least one hyphen ("-").'
66
- );
67
- }
68
-
69
- let name = kebabToPascal(tagName);
70
-
71
- // not a class, but a function
72
- if ( !isClass( DefinitionClass.prototype.constructor ) ){
73
- customElements.define(
74
- tagName,
75
- // @ts-ignore
76
- DefinitionClass
77
- );
78
- return;
79
- }
80
-
81
- // a class, but not a MC
82
- if ( !( DefinitionClass.prototype instanceof McBase ) ){
83
- customElements.define(
84
- tagName,
85
- // @ts-ignore
86
- DefinitionClass
87
- );
88
- return;
89
- }
90
-
91
- // a MC
92
- customElements.define(
93
- tagName,
94
- createNamedClass(
95
- name,
96
- class extends CeBaseClass {
97
- instance: any;
98
-
99
- constructor(data?: any) {
100
- super();
101
- // @ts-ignore
102
- const instance = isClass( DefinitionClass )
103
- // @ts-ignore
104
- ? new DefinitionClass(this, data)
105
- : DefinitionClass;
106
- DC.add(this, name, instance);
107
- }
108
-
109
- static get observedAttributes() {
110
- return observedAttributes;
111
- }
112
- }
113
- )
114
- );
115
- }
116
-
117
- export function getCE(tagName: string): CustomElementConstructor | undefined {
118
- return customElements.get(tagName);
119
- }
@@ -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>
File without changes
File without changes
File without changes
@@ -1,3 +0,0 @@
1
- import { LooseObject } from './helpers.js';
2
- export declare function formValues(targetObject: LooseObject, propertyName: string, dom: HTMLElement | ShadowRoot): void;
3
- //# sourceMappingURL=formValues.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../src/formValues.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AA0M/D,wBAAgB,UAAU,CACzB,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,WAAW,GAAG,UAAU,QAgB7B"}