@twobirds/microcomponents 0.0.10 → 0.0.12

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 (46) hide show
  1. package/README.md +2 -4
  2. package/assets/test.html +11 -0
  3. package/dist/microcomponents.d.ts +15 -231
  4. package/dist/microcomponents.d.ts.map +1 -1
  5. package/dist/microcomponents.es3.d.ts +5 -0
  6. package/dist/microcomponents.es3.d.ts.map +1 -1
  7. package/dist/microcomponents.js +143 -334
  8. package/dist/microcomponents.min.js +32 -29
  9. package/dist/microcomponents.ts +209 -395
  10. package/dist/test.d.ts +36 -0
  11. package/dist/test.d.ts.map +1 -0
  12. package/dist/test.js +214 -0
  13. package/package.json +3 -4
  14. package/public/{docs/assets → assets}/highlight.css +29 -22
  15. package/public/assets/search.js +1 -0
  16. package/public/{docs/classes → classes}/microcomponents.MC.html +78 -241
  17. package/public/{docs/classes → classes}/microcomponents_es3.MC.html +12 -12
  18. package/public/{docs/functions → functions}/microcomponents_es3.__isEmpty.html +1 -1
  19. package/public/index.html +101 -11
  20. package/public/microcomponents.js +176 -0
  21. package/public/{docs/modules → modules}/microcomponents.html +2 -7
  22. package/public/test.html +11 -0
  23. package/public/test.js +214 -0
  24. package/src/microcomponents.ts +209 -395
  25. package/src/test.js +245 -0
  26. package/typedoc.json +1 -1
  27. package/assets/index.html +0 -11
  28. package/jsdoc.conf.json +0 -19
  29. package/public/docs/assets/search.js +0 -1
  30. package/public/docs/index.html +0 -97
  31. package/public/docs/interfaces/microcomponents.HTMLElementMc.html +0 -3605
  32. package/public/jsdoc/es3/files.html +0 -216
  33. package/public/jsdoc/es3/index.html +0 -210
  34. package/public/jsdoc/es3/symbols/_global_.html +0 -368
  35. package/public/jsdoc/es3/symbols/src/build_microcomponents.es3.js.html +0 -104
  36. package/public/jsdoc/es5+/files.html +0 -218
  37. package/public/jsdoc/es5+/index.html +0 -218
  38. package/public/jsdoc/es5+/symbols/MC.html +0 -621
  39. package/public/jsdoc/es5+/symbols/_global_.html +0 -720
  40. package/public/jsdoc/es5+/symbols/microcomponents.MC.html +0 -323
  41. package/public/jsdoc/es5+/symbols/src/build_microcomponents.js.html +0 -375
  42. /package/public/{docs/.nojekyll → .nojekyll} +0 -0
  43. /package/public/{docs/assets → assets}/main.js +0 -0
  44. /package/public/{docs/assets → assets}/style.css +0 -0
  45. /package/public/{docs/modules → modules}/microcomponents_es3.html +0 -0
  46. /package/public/{docs/modules.html → modules.html} +0 -0
package/src/test.js ADDED
@@ -0,0 +1,245 @@
1
+ function getMicroComponents(elements, search) {
2
+ let mcValues = [];
3
+ elements.forEach((e) => {
4
+ if (e) {
5
+ if (e instanceof HTMLElement) {
6
+ const _mc = e?._mc;
7
+ if (!search && _mc) {
8
+ mcValues = mcValues.concat(Object.values(e._mc));
9
+ } else if (search && _mc && _mc[search]) {
10
+ mcValues.push(_mc[search]);
11
+ }
12
+ }
13
+ }
14
+ });
15
+ return mcValues;
16
+ }
17
+ function traverseNodes(node, search, firstonly = true) {
18
+ let mcValues = [];
19
+ while (node) {
20
+ if (node._mc) {
21
+ if (!search) {
22
+ mcValues = mcValues.concat(Object.values(node._mc));
23
+ } else if (search && node._mc[search]) {
24
+ mcValues.push(node._mc[search]);
25
+ }
26
+ if (firstonly) return mcValues;
27
+ }
28
+ node = node.parentNode;
29
+ }
30
+ return mcValues;
31
+ }
32
+ function isDOM(element) {
33
+ return element && element instanceof HTMLElement;
34
+ }
35
+ class MC {
36
+ #target = {};
37
+ #_mc = {};
38
+ static debug = false;
39
+ constructor(target) {
40
+ this.#target = target;
41
+ this.#_mc = {};
42
+ }
43
+ get _mc() {
44
+ if (!MC.debug) return undefined;
45
+ return this.#_mc;
46
+ }
47
+ get target() {
48
+ return this.#target;
49
+ }
50
+ static siblings(target, search = "") {
51
+ const mc = target;
52
+ if (!mc._mc) {
53
+ return [];
54
+ }
55
+ const _mc = mc._mc;
56
+ if (search.length) {
57
+ return _mc?.[search] || [];
58
+ }
59
+ return [...Object.values(_mc)];
60
+ }
61
+ static add(target, key, element = {}) {
62
+ let node = target;
63
+ if (!node._mc) {
64
+ node._mc = new MC(target);
65
+ }
66
+ const _mc = node._mc;
67
+ if (key.length && !_mc[key]) {
68
+ _mc[key] = element;
69
+ if (target instanceof HTMLElement) {
70
+ target.setAttribute("_mc", "");
71
+ }
72
+ }
73
+ return element;
74
+ }
75
+ static remove(target, key) {
76
+ if (!key) return;
77
+ const _mc = target?._mc || {};
78
+ if (_mc && _mc[key]) {
79
+ delete _mc[key];
80
+ }
81
+ if (
82
+ !Object.keys(_mc).length &&
83
+ target instanceof HTMLElement &&
84
+ target.hasAttribute("_mc")
85
+ ) {
86
+ target.removeAttribute("_mc");
87
+ }
88
+ return;
89
+ }
90
+ add(key, element, target) {
91
+ if (this.#_mc[key]) return;
92
+ if (target) {
93
+ MC.add(target, key, element);
94
+ }
95
+ this.#_mc[key] = element;
96
+ return element;
97
+ }
98
+ remove(key, target) {
99
+ const _mc = this.#_mc;
100
+ const t = target;
101
+ if (target) {
102
+ MC.remove(t, key);
103
+ }
104
+ delete _mc?.[key];
105
+ }
106
+ siblings(search = "") {
107
+ const _mc = this.#_mc;
108
+ if (!_mc) return [];
109
+ const result = _mc[search || ""];
110
+ return search && result ? [result] : [...Object.values(_mc)];
111
+ }
112
+ parent(search = "") {
113
+ if (!isDOM(this.#target)) return [];
114
+ return traverseNodes(this.#target.parentNode, search, true);
115
+ }
116
+ parents(search = "") {
117
+ if (!isDOM(this.#target)) return [];
118
+ return traverseNodes(this.#target.parentNode, search, false);
119
+ }
120
+ children(search = "") {
121
+ if (!isDOM(this.#target)) return [];
122
+ const id = Math.random().toString().replace(".", "");
123
+ const selector = '[_mc]:not([temp_id="' + id + '"] [_mc] [_mc])';
124
+ this.#target.setAttribute("temp_id", id);
125
+ const myDomElements = this.#target.querySelectorAll(selector);
126
+ const mcValues = getMicroComponents([...myDomElements], search);
127
+ this.#target.removeAttribute("temp-id");
128
+ return mcValues;
129
+ }
130
+ descendants(search = "") {
131
+ if (!isDOM(this.#target)) return [];
132
+ const myDomElements = this.#target.querySelectorAll("*[_mc]");
133
+ return getMicroComponents([...myDomElements], search);
134
+ }
135
+ }
136
+
137
+ // create test page
138
+ document.body.innerHTML = `<div class="level_1"><span><div class="level_2"><span><div class="level_3"><span><div class="level_4"><span><div class="level_5"></div></span></div></span></div></span></div></span></div>`;
139
+
140
+ let elements = [...document.querySelectorAll("div")].reverse();
141
+ elements.forEach((e) => (e.innerHTML = e.innerHTML.repeat(5)));
142
+
143
+ document.body.innerHTML = document.body.innerHTML.repeat(5);
144
+ document.body.innerHTML =
145
+ document.body.innerHTML +
146
+ "<span>F12 opens the debugger, console has some manual tests...</span>";
147
+
148
+ // create an inner micro component class
149
+ class MyInnerMC extends MC {
150
+ constructor(target) {
151
+ super(target);
152
+ }
153
+
154
+ doSomething() {
155
+ console.log(this, " myInnerMC something done");
156
+ console.log(this.siblings());
157
+ }
158
+ }
159
+
160
+ // create a custom micro component class
161
+ class MyMC extends MC {
162
+ #myInner;
163
+
164
+ constructor(target) {
165
+ super(target);
166
+
167
+ //add a micro component
168
+ this.add("myInnerMC", new MyInnerMC(target));
169
+
170
+ // add a private MC
171
+ this.#myInner = new MyInnerMC(target);
172
+ }
173
+
174
+ doSomething() {
175
+ console.log(this, "myMC something done");
176
+ this.#myInner.doSomething();
177
+ }
178
+ }
179
+
180
+ console.time("MC creation time");
181
+ // get some element from the DOM
182
+ const element = document.querySelector("div");
183
+
184
+ // Add the custom micro component instance to the target element
185
+ let topLevelMC = MC.add(element, "myFirstMC", new MyMC(element));
186
+
187
+ // Add the custom micro component instance to every div
188
+ document.querySelectorAll("div").forEach((e) => {
189
+ MC.add(e, "myPublicMC1", new MyMC(e));
190
+ MC.add(e, "myPublicMC2", new MyMC(e));
191
+ });
192
+
193
+ console.timeEnd("MC creation time");
194
+
195
+ let c = document.querySelectorAll("[_mc]");
196
+ console.info(
197
+ "number of DOM nodes:",
198
+ document.querySelectorAll("*").length,
199
+ "\nnumber of DOM nodes containing micro components:",
200
+ c.length,
201
+ "\nnumber of top level micro components:",
202
+ c.length * 2 + 1, // TODO write reducer
203
+ "\nnumber of top level & inner micro components:",
204
+ c.length * 3 + 2 // TODO write reducer
205
+ );
206
+
207
+ console.log("ROOT element", element);
208
+ console.log("-> ._mc", element._mc);
209
+ console.log("-> _mc.myMC", element._mc.myMC);
210
+ console.log(
211
+ "-> _mc.myFirstMC._mc (MC.debug = false)",
212
+ element._mc.myFirstMC._mc
213
+ );
214
+ MC.debug = true;
215
+ console.log(
216
+ "-> _mc.myFirstMC._mc (MC.debug = true)",
217
+ element._mc.myFirstMC._mc
218
+ );
219
+ MC.debug = false;
220
+
221
+ /*
222
+ test selectors
223
+ */
224
+
225
+ let sc = c[2]._mc.myPublicMC1; // 3rd level DIV micro component
226
+ console.info("sc", sc);
227
+
228
+ console.log("number of sc parents (expect 5)", sc.parents());
229
+ console.log("number of sc parent (expect 2)", sc.parent());
230
+ console.log(
231
+ "sc PUBLIC siblings (expect 2)",
232
+ sc.target.className,
233
+ Object.keys(sc.target._mc),
234
+ sc.target._mc
235
+ );
236
+ console.log("sc PRIVATE siblings (MC.debug = false, expect undefined)", sc._mc);
237
+ MC.debug = true;
238
+ console.log(
239
+ "sc PRIVATE siblings (MC.debug = true, expect 1)",
240
+ Object.keys(sc._mc).length,
241
+ sc._mc
242
+ );
243
+ MC.debug = false;
244
+ console.log("number of sc children (expect 10)", sc.children());
245
+ console.log("number of sc descendants (expect 60)", sc.descendants());
package/typedoc.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "entryPoints": ["src/microcomponents.ts","src/microcomponents.es3.js"],
3
- "out": "./public/docs/",
3
+ "out": "./public/",
4
4
  "readme": "README.md",
5
5
  "name": "Micro Components",
6
6
  "tsconfig": "./tsconfig.json"
package/assets/index.html DELETED
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Micro Components</title>
7
- </head>
8
- <body>
9
- <a href="http://twobirds.gitlab.io/microcomponents/docs/modules.html" target="_blank">API</a>
10
- </body>
11
- </html>
package/jsdoc.conf.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "source": {
3
- "include": ["src/microcomponents.js"],
4
- "includePattern": ".+\\.js(doc|x)?$",
5
- "excludePattern": "(^|\\/|\\\\)_"
6
- },
7
- "opts": {
8
- "destination": "./public/jsdoc/es5+",
9
- "recurse": false,
10
- "template": "default"
11
- },
12
- "plugins": [
13
- "plugins/markdown"
14
- ],
15
- "templates": {
16
- "cleverLinks": true,
17
- "monospaceLinks": true
18
- }
19
- }
@@ -1 +0,0 @@
1
- window.searchData = JSON.parse("{\"kinds\":{\"2\":\"Module\",\"64\":\"Function\",\"128\":\"Class\",\"256\":\"Interface\",\"512\":\"Constructor\",\"1024\":\"Property\",\"2048\":\"Method\",\"65536\":\"Type literal\"},\"rows\":[{\"kind\":2,\"name\":\"microcomponents\",\"url\":\"modules/microcomponents.html\",\"classes\":\"tsd-kind-module\"},{\"kind\":256,\"name\":\"HTMLElementMc\",\"url\":\"interfaces/microcomponents.HTMLElementMc.html\",\"classes\":\"tsd-kind-interface tsd-parent-kind-module\",\"parent\":\"microcomponents\"},{\"kind\":1024,\"name\":\"_mc\",\"url\":\"interfaces/microcomponents.HTMLElementMc.html#_mc\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"microcomponents.HTMLElementMc\"},{\"kind\":128,\"name\":\"MC\",\"url\":\"classes/microcomponents.MC.html\",\"classes\":\"tsd-kind-class tsd-parent-kind-module\",\"parent\":\"microcomponents\"},{\"kind\":1024,\"name\":\"debug\",\"url\":\"classes/microcomponents.MC.html#debug\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"siblings\",\"url\":\"classes/microcomponents.MC.html#siblings-2\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"add\",\"url\":\"classes/microcomponents.MC.html#add-2\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"remove\",\"url\":\"classes/microcomponents.MC.html#remove-2\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/microcomponents.MC.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":1024,\"name\":\"target\",\"url\":\"classes/microcomponents.MC.html#target\",\"classes\":\"tsd-kind-property tsd-parent-kind-class tsd-is-private\",\"parent\":\"microcomponents.MC\"},{\"kind\":1024,\"name\":\"privateMCs\",\"url\":\"classes/microcomponents.MC.html#privateMCs\",\"classes\":\"tsd-kind-property tsd-parent-kind-class tsd-is-private\",\"parent\":\"microcomponents.MC\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"classes/microcomponents.MC.html#privateMCs.__type-1\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-property\",\"parent\":\"microcomponents.MC.privateMCs\"},{\"kind\":1024,\"name\":\"_mc\",\"url\":\"classes/microcomponents.MC.html#_mc\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"classes/microcomponents.MC.html#_mc.__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-property\",\"parent\":\"microcomponents.MC._mc\"},{\"kind\":2048,\"name\":\"getMicroComponents\",\"url\":\"classes/microcomponents.MC.html#getMicroComponents\",\"classes\":\"tsd-kind-method tsd-parent-kind-class tsd-is-private\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"traverseNodes\",\"url\":\"classes/microcomponents.MC.html#traverseNodes\",\"classes\":\"tsd-kind-method tsd-parent-kind-class tsd-is-private\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"isDOM\",\"url\":\"classes/microcomponents.MC.html#isDOM\",\"classes\":\"tsd-kind-method tsd-parent-kind-class tsd-is-private\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"add\",\"url\":\"classes/microcomponents.MC.html#add\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"remove\",\"url\":\"classes/microcomponents.MC.html#remove\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"siblings\",\"url\":\"classes/microcomponents.MC.html#siblings\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"parent\",\"url\":\"classes/microcomponents.MC.html#parent\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"parents\",\"url\":\"classes/microcomponents.MC.html#parents\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"children\",\"url\":\"classes/microcomponents.MC.html#children\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2048,\"name\":\"descendants\",\"url\":\"classes/microcomponents.MC.html#descendants\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.MC\"},{\"kind\":2,\"name\":\"microcomponents.es3\",\"url\":\"modules/microcomponents_es3.html\",\"classes\":\"tsd-kind-module\"},{\"kind\":64,\"name\":\"__isEmpty\",\"url\":\"functions/microcomponents_es3.__isEmpty.html\",\"classes\":\"tsd-kind-function tsd-parent-kind-module\",\"parent\":\"microcomponents.es3\"},{\"kind\":128,\"name\":\"MC\",\"url\":\"classes/microcomponents_es3.MC.html\",\"classes\":\"tsd-kind-class tsd-parent-kind-module\",\"parent\":\"microcomponents.es3\"},{\"kind\":2048,\"name\":\"add\",\"url\":\"classes/microcomponents_es3.MC.html#add\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":2048,\"name\":\"remove\",\"url\":\"classes/microcomponents_es3.MC.html#remove\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/microcomponents_es3.MC.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":1024,\"name\":\"_target\",\"url\":\"classes/microcomponents_es3.MC.html#_target\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":2048,\"name\":\"siblings\",\"url\":\"classes/microcomponents_es3.MC.html#siblings\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":2048,\"name\":\"parent\",\"url\":\"classes/microcomponents_es3.MC.html#parent\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":2048,\"name\":\"parents\",\"url\":\"classes/microcomponents_es3.MC.html#parents\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":2048,\"name\":\"children\",\"url\":\"classes/microcomponents_es3.MC.html#children\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"},{\"kind\":2048,\"name\":\"descendants\",\"url\":\"classes/microcomponents_es3.MC.html#descendants\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"microcomponents.es3.MC\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,32.055]],[\"comment/0\",[]],[\"name/1\",[1,32.055]],[\"comment/1\",[]],[\"name/2\",[2,26.946]],[\"comment/2\",[]],[\"name/3\",[3,26.946]],[\"comment/3\",[]],[\"name/4\",[4,32.055]],[\"comment/4\",[]],[\"name/5\",[5,23.582]],[\"comment/5\",[]],[\"name/6\",[6,23.582]],[\"comment/6\",[]],[\"name/7\",[7,23.582]],[\"comment/7\",[]],[\"name/8\",[8,26.946]],[\"comment/8\",[]],[\"name/9\",[9,32.055]],[\"comment/9\",[]],[\"name/10\",[10,32.055]],[\"comment/10\",[]],[\"name/11\",[11,26.946]],[\"comment/11\",[]],[\"name/12\",[2,26.946]],[\"comment/12\",[]],[\"name/13\",[11,26.946]],[\"comment/13\",[]],[\"name/14\",[12,32.055]],[\"comment/14\",[]],[\"name/15\",[13,32.055]],[\"comment/15\",[]],[\"name/16\",[14,32.055]],[\"comment/16\",[]],[\"name/17\",[6,23.582]],[\"comment/17\",[]],[\"name/18\",[7,23.582]],[\"comment/18\",[]],[\"name/19\",[5,23.582]],[\"comment/19\",[]],[\"name/20\",[15,26.946]],[\"comment/20\",[]],[\"name/21\",[16,26.946]],[\"comment/21\",[]],[\"name/22\",[17,26.946]],[\"comment/22\",[]],[\"name/23\",[18,26.946]],[\"comment/23\",[]],[\"name/24\",[19,32.055]],[\"comment/24\",[]],[\"name/25\",[20,32.055]],[\"comment/25\",[]],[\"name/26\",[3,26.946]],[\"comment/26\",[]],[\"name/27\",[6,23.582]],[\"comment/27\",[]],[\"name/28\",[7,23.582]],[\"comment/28\",[]],[\"name/29\",[8,26.946]],[\"comment/29\",[]],[\"name/30\",[21,32.055]],[\"comment/30\",[]],[\"name/31\",[5,23.582]],[\"comment/31\",[]],[\"name/32\",[15,26.946]],[\"comment/32\",[]],[\"name/33\",[16,26.946]],[\"comment/33\",[]],[\"name/34\",[17,26.946]],[\"comment/34\",[]],[\"name/35\",[18,26.946]],[\"comment/35\",[]]],\"invertedIndex\":[[\"__isempty\",{\"_index\":20,\"name\":{\"25\":{}},\"comment\":{}}],[\"__type\",{\"_index\":11,\"name\":{\"11\":{},\"13\":{}},\"comment\":{}}],[\"_mc\",{\"_index\":2,\"name\":{\"2\":{},\"12\":{}},\"comment\":{}}],[\"_target\",{\"_index\":21,\"name\":{\"30\":{}},\"comment\":{}}],[\"add\",{\"_index\":6,\"name\":{\"6\":{},\"17\":{},\"27\":{}},\"comment\":{}}],[\"children\",{\"_index\":17,\"name\":{\"22\":{},\"34\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":8,\"name\":{\"8\":{},\"29\":{}},\"comment\":{}}],[\"debug\",{\"_index\":4,\"name\":{\"4\":{}},\"comment\":{}}],[\"descendants\",{\"_index\":18,\"name\":{\"23\":{},\"35\":{}},\"comment\":{}}],[\"getmicrocomponents\",{\"_index\":12,\"name\":{\"14\":{}},\"comment\":{}}],[\"htmlelementmc\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"isdom\",{\"_index\":14,\"name\":{\"16\":{}},\"comment\":{}}],[\"mc\",{\"_index\":3,\"name\":{\"3\":{},\"26\":{}},\"comment\":{}}],[\"microcomponents\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"microcomponents.es3\",{\"_index\":19,\"name\":{\"24\":{}},\"comment\":{}}],[\"parent\",{\"_index\":15,\"name\":{\"20\":{},\"32\":{}},\"comment\":{}}],[\"parents\",{\"_index\":16,\"name\":{\"21\":{},\"33\":{}},\"comment\":{}}],[\"privatemcs\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"remove\",{\"_index\":7,\"name\":{\"7\":{},\"18\":{},\"28\":{}},\"comment\":{}}],[\"siblings\",{\"_index\":5,\"name\":{\"5\":{},\"19\":{},\"31\":{}},\"comment\":{}}],[\"target\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"traversenodes\",{\"_index\":13,\"name\":{\"15\":{}},\"comment\":{}}]],\"pipeline\":[]}}");
@@ -1,97 +0,0 @@
1
- <!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Micro Components</title><meta name="description" content="Documentation for Micro Components"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
2
- <div class="tsd-toolbar-contents container">
3
- <div class="table-cell" id="tsd-search" data-base=".">
4
- <div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
5
- <div class="field">
6
- <div id="tsd-toolbar-links"></div></div>
7
- <ul class="results">
8
- <li class="state loading">Preparing search index...</li>
9
- <li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">Micro Components</a></div>
10
- <div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
11
- <div class="container container-main">
12
- <div class="col-8 col-content">
13
- <div class="tsd-page-title">
14
- <h2>Micro Components</h2></div>
15
- <div class="tsd-panel tsd-typography">
16
- <a href="#micro-components" id="micro-components" style="color: inherit; text-decoration: none;">
17
- <h2>MICRO COMPONENTS</h2>
18
- </a>
19
- <p><img src="https://gitlab.com/twoBirds/microcomponents/-/raw/main/MicroComponents.svg" alt="Micro Components Logo"></p>
20
-
21
- <a href="#status" id="status" style="color: inherit; text-decoration: none;">
22
- <h2>Status</h2>
23
- </a>
24
- <p>WIP. Should be tested and done soon.</p>
25
-
26
- <a href="#general" id="general" style="color: inherit; text-decoration: none;">
27
- <h2>General</h2>
28
- </a>
29
- <p>This code aims at improving Javascript modularity. It does not describe a specific Micro Component itself but rather describes they way they are <strong>organized</strong>.</p>
30
- <p>Using micro components enforces <strong>DRY, KISS and SOLID</strong> principles in Javascript programming. Read this <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/main/MicroComponentProposal_draft.md?ref_type=heads">RFC</a> for the shortest info, and <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_why.md?ref_type=heads">click here to see why you may want to use it</a>.</p>
31
- <p>This is a low-level approach. It consists of a single class with 3 static methods and 5 selector methods, and weights in at ~2 kB. Also there is an ES3 version to help e.g. <a href="https://en.wikipedia.org/wiki/Hybrid_Broadcast_Broadband_TV">hbbtv</a> modular JS coding, or any other device that relies on ES3. The latter is WIP, backporting is currently last on my list.</p>
32
- <p>For a short usage description goto <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_usage.md?ref_type=heads">Micro Component Usage</a>.</p>
33
- <p>Check the <a href="http://twobirds.gitlab.io/microcomponents/docs/modules.html">typedoc API reference</a> if you want to drill into the source code.</p>
34
- <p>Or read the more detailed <a href="http://twobirds.gitlab.io/microcomponents/jsdoc/es5+/index.html">jsdoc API documentation</a> which contains <strong>examples</strong>.</p>
35
- <p>To see what can be done, go to <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_magic.md?ref_type=heads">additional concepts</a> which shows what it already has been used for.</p>
36
-
37
- <a href="#functional-requirements" id="functional-requirements" style="color: inherit; text-decoration: none;">
38
- <h2>Functional Requirements</h2>
39
- </a>
40
- <ul>
41
- <li>I want to <strong>enrich a standard HTMLElement instance with encapsuled and modular javascript</strong>, without having to resort to web components or big frameworks.</li>
42
- <li>I want to have an <strong>interface</strong> into this functionality that I can both tight and loosely couple.</li>
43
- <li>I want to <strong>import and use Micro Components in any framework</strong> that allows for direct DOM access.</li>
44
- <li>I want <strong>a single location</strong> in an HTMLElement instance where all this functionality is <strong>stored and sufficiently organized</strong>.</li>
45
- <li>I want to be able to use <strong>selectors</strong> to find those instances in the DOM.</li>
46
- <li>All this must stricly follow <strong>web standards</strong>.</li>
47
- </ul>
48
-
49
- <a href="#simple-usage" id="simple-usage" style="color: inherit; text-decoration: none;">
50
- <h2>Simple Usage:</h2>
51
- </a>
52
- <p><strong>Micro Components</strong> can be added to to a DOM element like this:</p>
53
- <p>before:</p>
54
- <pre><code class="language-HTML"><span class="hl-0">&lt;</span><span class="hl-1">button</span><span class="hl-0">&gt;&lt;/</span><span class="hl-1">button</span><span class="hl-0">&gt;</span>
55
- </code></pre>
56
- <p>code: (assume &quot;Button&quot; is some class in a library)</p>
57
- <pre><code class="language-javascript"><span class="hl-2">// create the micro component class</span><br/><span class="hl-3">class</span><span class="hl-4"> </span><span class="hl-5">MyMC</span><span class="hl-4"> </span><span class="hl-3">extends</span><span class="hl-4"> </span><span class="hl-5">MC</span><span class="hl-4">{</span><br/><br/><span class="hl-4"> </span><span class="hl-3">constructor</span><span class="hl-4">( </span><span class="hl-6">target</span><span class="hl-4"> ){</span><br/><span class="hl-4"> </span><span class="hl-3">super</span><span class="hl-4">( </span><span class="hl-6">target</span><span class="hl-4"> );</span><br/><span class="hl-4"> </span><span class="hl-3">this</span><span class="hl-4">.</span><span class="hl-6">target</span><span class="hl-4"> = </span><span class="hl-6">target</span><span class="hl-4">;</span><br/><span class="hl-4"> }</span><br/><span class="hl-4">}</span><br/><br/><span class="hl-3">const</span><span class="hl-4"> </span><span class="hl-7">element</span><span class="hl-4"> = </span><span class="hl-6">document</span><span class="hl-4">.</span><span class="hl-8">querySelector</span><span class="hl-4">(</span><span class="hl-9">&#39;div&#39;</span><span class="hl-4">)</span><br/><br/><span class="hl-2">// Add the top level microcomponent to the target element</span><br/><span class="hl-3">let</span><span class="hl-4"> </span><span class="hl-6">mcc</span><span class="hl-4"> = </span><span class="hl-7">MC</span><span class="hl-4">.</span><span class="hl-8">add</span><span class="hl-4">(</span><br/><span class="hl-4"> </span><span class="hl-6">element</span><span class="hl-4">,</span><br/><span class="hl-4"> </span><span class="hl-9">&#39;myMC&#39;</span><span class="hl-4">,</span><br/><span class="hl-4"> </span><span class="hl-3">new</span><span class="hl-4"> </span><span class="hl-8">MyMC</span><span class="hl-4">( </span><span class="hl-6">element</span><span class="hl-4"> )</span><br/><span class="hl-4">);</span><br/><br/><span class="hl-2">// Add an inner (private) microcomponent to mcc</span><br/><span class="hl-3">let</span><span class="hl-4"> </span><span class="hl-6">mcc</span><span class="hl-4">.add(</span><br/><span class="hl-4"> </span><span class="hl-9">&#39;myInnerMC&#39;</span><span class="hl-4">,</span><br/><span class="hl-4"> </span><span class="hl-3">new</span><span class="hl-4"> </span><span class="hl-8">MyMC</span><span class="hl-4">( </span><span class="hl-6">element</span><span class="hl-4"> )</span><br/><span class="hl-4">);</span><br/><br/><span class="hl-6">console</span><span class="hl-4">.</span><span class="hl-8">log</span><span class="hl-4">( </span><span class="hl-6">element</span><span class="hl-4">.</span><span class="hl-6">_mc</span><span class="hl-4"> );</span><br/><span class="hl-2">// { &#39;myMC&#39;: { target: (element) } }</span><br/><br/><span class="hl-6">console</span><span class="hl-4">.</span><span class="hl-8">log</span><span class="hl-4">( </span><span class="hl-6">element</span><span class="hl-4">.</span><span class="hl-6">_mc</span><span class="hl-4">.</span><span class="hl-6">myMC</span><span class="hl-4"> );</span><br/><span class="hl-2">// { target: (element) }</span><br/><br/><span class="hl-6">console</span><span class="hl-4">.</span><span class="hl-8">log</span><span class="hl-4">( </span><span class="hl-6">mcc</span><span class="hl-4">.</span><span class="hl-8">siblings</span><span class="hl-4">() );</span><br/><span class="hl-2">// [ { target: (element) } ]</span>
58
- </code></pre>
59
- <p>after:</p>
60
- <pre><code class="language-HTML"><span class="hl-0">&lt;</span><span class="hl-1">button</span><span class="hl-4"> </span><span class="hl-10">_mc</span><span class="hl-0">&gt;&lt;/</span><span class="hl-1">button</span><span class="hl-0">&gt;</span>
61
- </code></pre>
62
- <p>_mc indicates that this HTML element contains at least one micro component. This is needed for the <strong>selectors</strong>.</p>
63
- <p>I decided to extract this functionality from the <a href="https://www.npmjs.com/package/twobirds-core">twoBirds framework</a>, since it is framework agnostic, and relies solely on the standard DOM and native javascript or typescript, and is a useful tool in itself. Also this will be a dependency in twoBirds then.</p>
64
-
65
- <a href="#contact" id="contact" style="color: inherit; text-decoration: none;">
66
- <h2>Contact</h2>
67
- </a>
68
- <p>Feel free to contact me for any questions or inquiries:</p>
69
- <p>email <a href="mailto:fthuerigen@gmail.com?subject=Micro%20Components">Frank Thürigen</a> or <a href="skype:frank.thuerigen">Skype</a></p>
70
- <p>And yes, you can <a href="https://gofund.me/076c614c">fund this</a>.</p>
71
- </div></div>
72
- <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
73
- <div class="tsd-navigation settings">
74
- <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
75
- <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)"></path></svg> Settings</h3></summary>
76
- <div class="tsd-accordion-details">
77
- <div class="tsd-filter-visibility">
78
- <h4 class="uppercase">Member Visibility</h4><form>
79
- <ul id="tsd-filter-options">
80
- <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li>
81
- <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li>
82
- <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li>
83
- <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div>
84
- <div class="tsd-theme-toggle">
85
- <h4 class="uppercase">Theme</h4><select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div>
86
- <nav class="tsd-navigation primary">
87
- <details class="tsd-index-accordion" open><summary class="tsd-accordion-summary">
88
- <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)"></path></svg> Modules</h3></summary>
89
- <div class="tsd-accordion-details">
90
- <ul>
91
- <li class="current selected"><a href="modules.html">Micro <wbr/>Components</a>
92
- <ul>
93
- <li class="tsd-kind-module"><a href="modules/microcomponents.html">microcomponents</a></li>
94
- <li class="tsd-kind-module"><a href="modules/microcomponents_es3.html">microcomponents.es3</a></li></ul></li></ul></div></details></nav></div></div>
95
- <div class="container tsd-generator">
96
- <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
97
- <div class="overlay"></div><script src="assets/main.js"></script></body></html>