@twobirds/microcomponents 0.0.65 → 0.0.66

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 (117) hide show
  1. package/assets/documentation/MC.md +22 -28
  2. package/assets/documentation/elements.md +4 -2
  3. package/assets/documentation/observables.md +2 -0
  4. package/assets/test.html +1 -1
  5. package/dist/MC.d.ts.map +1 -1
  6. package/dist/MC.min.js +20 -15
  7. package/dist/MC.ts +23 -16
  8. package/dist/elements.min.js +1 -1
  9. package/dist/formvValues.min.js +1 -1
  10. package/dist/microcomponents.min.js +1 -1
  11. package/dist/observables.d.ts.map +1 -1
  12. package/dist/observables.min.js +1 -1
  13. package/dist/observables.ts +0 -3
  14. package/dist/selectors.min.js +1 -1
  15. package/package.json +4 -4
  16. package/public/MC.js +20 -15
  17. package/public/MC.js.map +1 -1
  18. package/public/MC.min.js +20 -15
  19. package/public/assets/highlight.css +99 -0
  20. package/public/assets/icons.js +18 -0
  21. package/public/assets/icons.svg +1 -0
  22. package/public/assets/main.js +60 -0
  23. package/public/assets/navigation.js +1 -0
  24. package/public/assets/search.js +1 -0
  25. package/public/assets/style.css +1493 -0
  26. package/public/classes/MC.DC.html +12 -0
  27. package/public/classes/MC.MC.html +6 -0
  28. package/public/classes/MC.McBase.html +3 -0
  29. package/public/classes/MC.McEvent.html +9 -0
  30. package/public/elements.min.js +1 -1
  31. package/public/formvValues.min.js +1 -1
  32. package/public/functions/MC.addListener.html +1 -0
  33. package/public/functions/MC.autoload.html +1 -0
  34. package/public/functions/MC.removeListener.html +1 -0
  35. package/public/functions/elements.defineCE.html +1 -0
  36. package/public/functions/elements.getCE.html +1 -0
  37. package/public/functions/formValues.formValues.html +1 -0
  38. package/public/functions/observables.observe.html +1 -0
  39. package/public/functions/selectors._d.html +1 -0
  40. package/public/functions/selectors._t.html +1 -0
  41. package/public/hierarchy.html +1 -0
  42. package/public/index.html +56 -0
  43. package/public/interfaces/MC.HTMLMcElement.html +758 -0
  44. package/public/interfaces/selectors.DSelector.html +50 -0
  45. package/public/interfaces/selectors.TSelector.html +34 -0
  46. package/public/microcomponents.min.js +1 -1
  47. package/public/modules/MC.html +9 -0
  48. package/public/modules/elements.html +3 -0
  49. package/public/modules/formValues.html +2 -0
  50. package/public/modules/observables.html +3 -0
  51. package/public/modules/selectors.html +7 -0
  52. package/public/modules.html +6 -0
  53. package/public/observables.js.map +1 -1
  54. package/public/observables.min.js +1 -1
  55. package/public/selectors.min.js +1 -1
  56. package/public/types/observables.Observable.html +1 -0
  57. package/public/types/selectors.selection.html +1 -0
  58. package/public/types/selectors.singleSelector.html +1 -0
  59. package/src/MC.ts +23 -16
  60. package/src/observables.ts +0 -3
  61. package/src/test/testmc.ts +7 -1
  62. package/assets/documentation/comparision.md +0 -0
  63. package/assets/documentation/how_tos.md +0 -0
  64. package/assets/documentation/introduction.md +0 -0
  65. package/assets/documentation/proposal_draft.md +0 -37
  66. package/public/3d.html +0 -42
  67. package/public/documentation/MC.md +0 -594
  68. package/public/documentation/ajaxian-1.png +0 -0
  69. package/public/documentation/ajaxian-2.png +0 -0
  70. package/public/documentation/ajaxian-3.png +0 -0
  71. package/public/documentation/comparision.md +0 -0
  72. package/public/documentation/elements.md +0 -276
  73. package/public/documentation/functional_requirements.md +0 -8
  74. package/public/documentation/history.md +0 -436
  75. package/public/documentation/how_tos.md +0 -0
  76. package/public/documentation/introduction.md +0 -0
  77. package/public/documentation/magic.md +0 -29
  78. package/public/documentation/observables.md +0 -105
  79. package/public/documentation/proposal_draft.md +0 -37
  80. package/public/documentation/rnd0023-1.jpg +0 -0
  81. package/public/documentation/rnd0023-2.jpg +0 -0
  82. package/public/documentation/rnd0023-3.jpg +0 -0
  83. package/public/documentation/tB_react.md +0 -207
  84. package/public/documentation/usage.md +0 -142
  85. package/public/documentation/why.md +0 -25
  86. package/public/fiddle/MicroComponents.svg +0 -15
  87. package/public/fiddle/fiddle.css +0 -0
  88. package/public/fiddle/fiddle.js +0 -0
  89. package/public/fiddle/index.html +0 -0
  90. package/public/grandparent.css +0 -13
  91. package/public/my-tag.css +0 -19
  92. package/public/src/MC.ts +0 -598
  93. package/public/src/McEvent.ts +0 -96
  94. package/public/src/autoloader.ts +0 -98
  95. package/public/src/elements.ts +0 -76
  96. package/public/src/formValues.ts +0 -233
  97. package/public/src/helpers.ts +0 -149
  98. package/public/src/microcomponents.ts +0 -8
  99. package/public/src/observables.ts +0 -404
  100. package/public/src/selectors.ts +0 -1634
  101. package/public/src/test.ts +0 -193
  102. package/public/test/child.js +0 -15
  103. package/public/test/child.js.map +0 -1
  104. package/public/test/grandchild.js +0 -15
  105. package/public/test/grandchild.js.map +0 -1
  106. package/public/test/grandparent.js +0 -1
  107. package/public/test/grandparent.js.map +0 -1
  108. package/public/test/greatgrandchild.js +0 -29
  109. package/public/test/greatgrandchild.js.map +0 -1
  110. package/public/test/parent.js +0 -15
  111. package/public/test/parent.js.map +0 -1
  112. package/public/test/testform.js +0 -1
  113. package/public/test/testform.js.map +0 -1
  114. package/public/test/testmc.js +0 -10
  115. package/public/test/testmc.js.map +0 -1
  116. package/public/test.html +0 -27
  117. /package/public/{MicroComponents.svg → media/MicroComponents.svg} +0 -0
@@ -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,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,13 +0,0 @@
1
- test-grandparent,
2
- test-parent,
3
- test-child,
4
- test-grandchild,
5
- test-greatgrandchild {
6
- display: inline-block;
7
- padding: 2px;
8
- margin: 1px;
9
- border: 1px solid darkslategray;
10
- border-radius: 2px;
11
- }
12
-
13
- /*# sourceMappingURL=GrandParent.css.map */
package/public/my-tag.css DELETED
@@ -1,19 +0,0 @@
1
- my-tag > button {
2
- border: 2px solid gray;
3
- margin: 3px;
4
- padding: 2px 5px;
5
- display: inline-block;
6
- width: 8em;
7
- }
8
-
9
- my-tag.clicked > button {
10
- border-color: blue;
11
- }
12
-
13
- my-tag.overClicked > button {
14
- border-color: orange;
15
- }
16
-
17
- my-tag > button:hover {
18
- border-color: red;
19
- }