@twobirds/microcomponents 0.0.10 → 0.0.14

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 (73) hide show
  1. package/README.md +27 -47
  2. package/assets/documentation/ajaxian-1.png +0 -0
  3. package/assets/documentation/ajaxian-2.png +0 -0
  4. package/assets/documentation/ajaxian-3.png +0 -0
  5. package/assets/documentation/history.md +436 -0
  6. package/assets/documentation/how_tos.md +0 -0
  7. package/assets/documentation/introduction.md +0 -0
  8. package/{microcomponents_magic.md → assets/documentation/magic.md} +1 -1
  9. package/assets/documentation/rnd0023-1.jpg +0 -0
  10. package/assets/documentation/rnd0023-2.jpg +0 -0
  11. package/assets/documentation/rnd0023-3.jpg +0 -0
  12. package/assets/documentation/tB_react.md +369 -0
  13. package/assets/test.html +11 -0
  14. package/dist/microcomponents.d.ts +15 -231
  15. package/dist/microcomponents.d.ts.map +1 -1
  16. package/dist/microcomponents.es3.d.ts +5 -0
  17. package/dist/microcomponents.es3.d.ts.map +1 -1
  18. package/dist/microcomponents.js +143 -334
  19. package/dist/microcomponents.min.js +32 -29
  20. package/dist/microcomponents.ts +209 -395
  21. package/package.json +3 -4
  22. package/public/{docs/assets → assets}/highlight.css +29 -22
  23. package/public/assets/search.js +1 -0
  24. package/public/{docs/classes → classes}/microcomponents.MC.html +78 -241
  25. package/public/{docs/classes → classes}/microcomponents_es3.MC.html +12 -12
  26. package/public/documentation/ajaxian-1.png +0 -0
  27. package/public/documentation/ajaxian-2.png +0 -0
  28. package/public/documentation/ajaxian-3.png +0 -0
  29. package/public/documentation/functional_requirements.md +8 -0
  30. package/public/documentation/history.md +436 -0
  31. package/public/documentation/how_tos.md +0 -0
  32. package/public/documentation/introduction.md +0 -0
  33. package/public/documentation/magic.md +87 -0
  34. package/public/documentation/proposal_draft.md +37 -0
  35. package/public/documentation/rnd0023-1.jpg +0 -0
  36. package/public/documentation/rnd0023-2.jpg +0 -0
  37. package/public/documentation/rnd0023-3.jpg +0 -0
  38. package/public/documentation/tB_react.md +369 -0
  39. package/public/documentation/usage.md +142 -0
  40. package/public/documentation/why.md +25 -0
  41. package/public/{docs/functions → functions}/microcomponents_es3.__isEmpty.html +1 -1
  42. package/public/index.html +101 -11
  43. package/public/microcomponents.js +176 -0
  44. package/public/{docs/modules → modules}/microcomponents.html +2 -7
  45. package/public/test.html +11 -0
  46. package/public/test.js +216 -0
  47. package/src/microcomponents.ts +209 -395
  48. package/src/test.js +247 -0
  49. package/typedoc.json +1 -1
  50. package/assets/index.html +0 -11
  51. package/jsdoc.conf.json +0 -19
  52. package/public/docs/assets/search.js +0 -1
  53. package/public/docs/index.html +0 -97
  54. package/public/docs/interfaces/microcomponents.HTMLElementMc.html +0 -3605
  55. package/public/jsdoc/es3/files.html +0 -216
  56. package/public/jsdoc/es3/index.html +0 -210
  57. package/public/jsdoc/es3/symbols/_global_.html +0 -368
  58. package/public/jsdoc/es3/symbols/src/build_microcomponents.es3.js.html +0 -104
  59. package/public/jsdoc/es5+/files.html +0 -218
  60. package/public/jsdoc/es5+/index.html +0 -218
  61. package/public/jsdoc/es5+/symbols/MC.html +0 -621
  62. package/public/jsdoc/es5+/symbols/_global_.html +0 -720
  63. package/public/jsdoc/es5+/symbols/microcomponents.MC.html +0 -323
  64. package/public/jsdoc/es5+/symbols/src/build_microcomponents.js.html +0 -375
  65. /package/{microcomponents_functional_requirements.md → assets/documentation/functional_requirements.md} +0 -0
  66. /package/{MicroComponentProposal_draft.md → assets/documentation/proposal_draft.md} +0 -0
  67. /package/{microcomponents_usage.md → assets/documentation/usage.md} +0 -0
  68. /package/{microcomponents_why.md → assets/documentation/why.md} +0 -0
  69. /package/public/{docs/.nojekyll → .nojekyll} +0 -0
  70. /package/public/{docs/assets → assets}/main.js +0 -0
  71. /package/public/{docs/assets → assets}/style.css +0 -0
  72. /package/public/{docs/modules → modules}/microcomponents_es3.html +0 -0
  73. /package/public/{docs/modules.html → modules.html} +0 -0
package/public/index.html CHANGED
@@ -1,11 +1,101 @@
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>
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
+ <p><strong>This code aims at improving Javascript modularity and encapsulation</strong>.</p>
21
+ <p>Importing a custom MC in your client side code:</p>
22
+ <pre><code class="language-javascript"><span class="hl-0">import</span><span class="hl-1"> </span><span class="hl-2">MyButton</span><span class="hl-1"> </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&#39;@mySampleLib/Button&#39;</span><span class="hl-1">;</span>
23
+ </code></pre>
24
+ <p>... is equivalent to:</p>
25
+ <pre><code class="language-javascript"><span class="hl-2">npm</span><span class="hl-1"> </span><span class="hl-2">i</span><span class="hl-1"> @</span><span class="hl-2">mySampleLib</span><span class="hl-1">/</span><span class="hl-2">Button</span><span class="hl-1">;</span>
26
+ </code></pre>
27
+ <p>... on the server side.</p>
28
+ <p>Imagine your micro components to be organized like a &quot;node_modules&quot; directory that is attached to a DOM node.</p>
29
+ <p><strong>On the client side</strong> MCs reside inside DOM nodes in a &quot;_mc&quot; property, or inside each other recursively. Usually they provide a direct interface to their inner code.</p>
30
+ <p><strong>On the server side</strong> MCs can be used to organize your code, too.</p>
31
+
32
+ <a href="#status" id="status" style="color: inherit; text-decoration: none;">
33
+ <h2>Status</h2>
34
+ </a>
35
+ <p>WIP. Micro components should be done soon, as in days.</p>
36
+
37
+ <a href="#disclaimer" id="disclaimer" style="color: inherit; text-decoration: none;">
38
+ <h2>Disclaimer</h2>
39
+ </a>
40
+ <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. Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.</p>
41
+ <p>This is a massive undertaking. MCs are just the foundation of what I do. <strong>I am about to dump</strong> <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_magic.md?ref_type=heads#things-i-already-did-with-this-in-my-own-framework-twobirds-or-in-apps-that-i-developed-with-it">20+ years of javascript programming</a> <strong>into open source libraries</strong>, so feel free to <a href="https://gofund.me/076c614c">fund this</a>. The better this is funded, the faster it will be done. Given enough resources, I will start a crowdfunded company that will develop a new ecosystem for javascript/typescript programming.</p>
42
+ <p>By <strong>&quot;Open Source&quot;</strong> I mean <strong>really free and open</strong>, as <strong>you get all my inner source code with it</strong>. Once you understand the Micro Component principle, you are back in command of your software, no matter what MC functionality you import in your system. Since <strong>Micro Components</strong> are encapsuled, off-shoring and near-shoring is no problem, and reusability is guaranteed. Your external coders do not need to access your code repository or your toolchain. They only need to understand MCs.</p>
43
+ <p><strong>Established frameworks</strong>, as opposed to MCs, <strong>provide a documented interface to a hidden layer of closed source inner functionality</strong>. MCs can be used to <strong>add an interface to components you developed using other frameworks</strong>. So you can still use your existing code, and MCs in it. But you will want to migrate it ASAP, since MCs work with any FW.</p>
44
+
45
+ <a href="#general" id="general" style="color: inherit; text-decoration: none;">
46
+ <h2>General</h2>
47
+ </a>
48
+ <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>
49
+ <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>
50
+ <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>
51
+ <p>Check the <a href="http://twobirds.gitlab.io/microcomponents/classes/microcomponents.MC.html">typedoc API reference</a> if you want to drill into the source code.</p>
52
+ <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>
53
+
54
+ <a href="#simple-usage" id="simple-usage" style="color: inherit; text-decoration: none;">
55
+ <h2>Simple Usage:</h2>
56
+ </a>
57
+ <p><strong>Micro Components</strong> can be added to to a DOM element like this:</p>
58
+ <p>before:</p>
59
+ <pre><code class="language-HTML"><span class="hl-4">&lt;</span><span class="hl-5">div</span><span class="hl-4">&gt;&lt;/</span><span class="hl-5">div</span><span class="hl-4">&gt;</span>
60
+ </code></pre>
61
+ <p>code:</p>
62
+ <pre><code class="language-typescript"><span class="hl-6">// create an inner micro component class</span><br/><span class="hl-7">class</span><span class="hl-1"> </span><span class="hl-8">MyInnerMC</span><span class="hl-1"> </span><span class="hl-7">extends</span><span class="hl-1"> </span><span class="hl-8">MC</span><span class="hl-1">{</span><br/><br/><span class="hl-1"> </span><span class="hl-7">constructor</span><span class="hl-1">( </span><span class="hl-2">target</span><span class="hl-1"> ){</span><br/><span class="hl-1"> </span><span class="hl-7">super</span><span class="hl-1">( </span><span class="hl-2">target</span><span class="hl-1"> );</span><br/><span class="hl-1"> }</span><br/><br/><span class="hl-1"> </span><span class="hl-9">doSomething</span><span class="hl-1">(){</span><br/><span class="hl-1"> </span><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-9">log</span><span class="hl-1">( </span><span class="hl-7">this</span><span class="hl-1">, </span><span class="hl-3">&#39;something done&#39;</span><span class="hl-1"> )</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-6">// create a custom micro component class</span><br/><span class="hl-7">class</span><span class="hl-1"> </span><span class="hl-8">MyMC</span><span class="hl-1"> </span><span class="hl-7">extends</span><span class="hl-1"> </span><span class="hl-8">MC</span><span class="hl-1">{</span><br/><br/><span class="hl-1"> </span><span class="hl-7">private</span><span class="hl-1"> </span><span class="hl-2">myInner</span><span class="hl-1">: </span><span class="hl-8">MyInnerMC</span><span class="hl-1">;</span><br/><br/><span class="hl-1"> </span><span class="hl-7">constructor</span><span class="hl-1">( </span><span class="hl-2">target</span><span class="hl-1"> ){</span><br/><span class="hl-1"> </span><span class="hl-7">super</span><span class="hl-1">( </span><span class="hl-2">target</span><span class="hl-1"> );</span><br/><span class="hl-1"> </span><span class="hl-7">this</span><span class="hl-1">.</span><span class="hl-2">target</span><span class="hl-1"> = </span><span class="hl-2">target</span><span class="hl-1">;</span><br/><br/><span class="hl-1"> </span><span class="hl-6">//add a private inner micro component</span><br/><span class="hl-1"> </span><span class="hl-7">this</span><span class="hl-1">.</span><span class="hl-2">myInner</span><span class="hl-1"> = </span><span class="hl-7">new</span><span class="hl-1"> </span><span class="hl-9">MyInnerMC</span><span class="hl-1">( </span><span class="hl-2">target</span><span class="hl-1"> );</span><br/><br/><span class="hl-1"> </span><span class="hl-6">//add a public micro component</span><br/><span class="hl-1"> </span><span class="hl-7">this</span><span class="hl-1">.</span><span class="hl-9">add</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-3">&#39;myPublicInnerMC&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-7">new</span><span class="hl-1"> </span><span class="hl-9">MyInnerMC</span><span class="hl-1">( </span><span class="hl-2">target</span><span class="hl-1"> )</span><br/><span class="hl-1"> );</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-6">// get some element from the DOM</span><br/><span class="hl-7">const</span><span class="hl-1"> </span><span class="hl-10">element</span><span class="hl-1"> = </span><span class="hl-2">document</span><span class="hl-1">.</span><span class="hl-9">querySelector</span><span class="hl-1">(</span><span class="hl-3">&#39;div&#39;</span><span class="hl-1">)</span><br/><br/><span class="hl-6">// Add the custom micro component instance to the target element</span><br/><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-2">topLevelMC</span><span class="hl-1"> = </span><span class="hl-10">MC</span><span class="hl-1">.</span><span class="hl-9">add</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">element</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-3">&#39;myMC&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-7">new</span><span class="hl-1"> </span><span class="hl-9">MyMC</span><span class="hl-1">( </span><span class="hl-2">element</span><span class="hl-1"> )</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-9">log</span><span class="hl-1">( </span><span class="hl-2">element</span><span class="hl-1">.</span><span class="hl-2">_mc</span><span class="hl-1"> );</span><br/><span class="hl-6">// { &#39;myMC&#39;: { target: (element), _mc: { myPublicInnerMC: {...} } } }</span><br/><br/><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-9">log</span><span class="hl-1">( </span><span class="hl-2">element</span><span class="hl-1">.</span><span class="hl-2">_mc</span><span class="hl-1">.</span><span class="hl-2">myMC</span><span class="hl-1"> );</span><br/><span class="hl-6">// { target: (element), _mc: { myPublicInnerMC: {...} } }</span><br/><br/><span class="hl-2">console</span><span class="hl-1">.</span><span class="hl-9">log</span><span class="hl-1">( </span><span class="hl-2">topLevelMC</span><span class="hl-1">.</span><span class="hl-9">siblings</span><span class="hl-1">() );</span><br/><span class="hl-6">// [ { target: (element), _mc: { myPublicInnerMC: {...} } } ]</span>
63
+ </code></pre>
64
+ <p>after:</p>
65
+ <pre><code class="language-HTML"><span class="hl-4">&lt;</span><span class="hl-5">div</span><span class="hl-1"> </span><span class="hl-11">_mc</span><span class="hl-4">&gt;&lt;/</span><span class="hl-5">button</span><span class="hl-4">&gt;</span>
66
+ </code></pre>
67
+ <p>_mc indicates that this HTML element contains at least one micro component. This is needed for the <strong>selectors</strong>.</p>
68
+
69
+ <a href="#contact" id="contact" style="color: inherit; text-decoration: none;">
70
+ <h2>Contact</h2>
71
+ </a>
72
+ <p>Feel free to contact me for any questions or inquiries:</p>
73
+ <p>email <a href="mailto:fthuerigen@gmail.com?subject=Micro%20Components">Frank Thürigen</a> or <a href="skype:frank.thuerigen">Skype</a></p>
74
+ <p>And yes, you can <a href="https://gofund.me/076c614c">fund this</a>.</p>
75
+ </div></div>
76
+ <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
77
+ <div class="tsd-navigation settings">
78
+ <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
79
+ <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>
80
+ <div class="tsd-accordion-details">
81
+ <div class="tsd-filter-visibility">
82
+ <h4 class="uppercase">Member Visibility</h4><form>
83
+ <ul id="tsd-filter-options">
84
+ <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>
85
+ <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>
86
+ <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>
87
+ <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>
88
+ <div class="tsd-theme-toggle">
89
+ <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>
90
+ <nav class="tsd-navigation primary">
91
+ <details class="tsd-index-accordion" open><summary class="tsd-accordion-summary">
92
+ <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>
93
+ <div class="tsd-accordion-details">
94
+ <ul>
95
+ <li class="current selected"><a href="modules.html">Micro <wbr/>Components</a>
96
+ <ul>
97
+ <li class="tsd-kind-module"><a href="modules/microcomponents.html">microcomponents</a></li>
98
+ <li class="tsd-kind-module"><a href="modules/microcomponents_es3.html">microcomponents.es3</a></li></ul></li></ul></div></details></nav></div></div>
99
+ <div class="container tsd-generator">
100
+ <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
101
+ <div class="overlay"></div><script src="assets/main.js"></script></body></html>
@@ -0,0 +1,176 @@
1
+ 'use strict';
2
+ /*
3
+ helper methods
4
+ */
5
+ // get all microcomponents from a list of HTMLElements
6
+ function getMicroComponents(elements, search) {
7
+ let mcValues = [];
8
+ elements.forEach(e => {
9
+ if (e) {
10
+ if (e instanceof HTMLElement) {
11
+ const _mc = e?._mc;
12
+ if (!search && _mc) {
13
+ mcValues = mcValues.concat(Object.values(e._mc));
14
+ }
15
+ else if (search && _mc && _mc[search]) {
16
+ mcValues.push(_mc[search]);
17
+ }
18
+ }
19
+ }
20
+ });
21
+ return mcValues;
22
+ }
23
+ // get all ancestor DOM nodes up to the document
24
+ function traverseNodes(node, search, firstonly = true) {
25
+ let mcValues = [];
26
+ while (node) {
27
+ if (node._mc) {
28
+ if (!search) {
29
+ mcValues = mcValues.concat(Object.values(node._mc));
30
+ }
31
+ else if (search && node._mc[search]) {
32
+ mcValues.push(node._mc[search]);
33
+ }
34
+ if (firstonly)
35
+ return mcValues;
36
+ }
37
+ node = node.parentNode;
38
+ }
39
+ return mcValues;
40
+ }
41
+ function isDOM(element) {
42
+ return element && element instanceof HTMLElement;
43
+ }
44
+ export class MC {
45
+ #target = {};
46
+ #_mc = {};
47
+ static debug = false;
48
+ constructor(target) {
49
+ this.#target = target;
50
+ this.#_mc = {};
51
+ }
52
+ get _mc() {
53
+ if (!MC.debug)
54
+ return undefined;
55
+ return this.#_mc;
56
+ }
57
+ get target() {
58
+ return this.#target;
59
+ }
60
+ // return all top-level micro components from an HTMLElement, or the searched one
61
+ static siblings(target, search = '') {
62
+ const mc = target;
63
+ if (!mc._mc) {
64
+ return [];
65
+ }
66
+ const _mc = mc._mc;
67
+ if (search.length) {
68
+ return _mc?.[search] || [];
69
+ }
70
+ return [...Object.values(_mc)];
71
+ }
72
+ // add a microcomponent to a target DOM node
73
+ static add(target, key, element = {}) {
74
+ let node = target;
75
+ // create the _mc property if necessary
76
+ if (!node._mc) {
77
+ node._mc = new MC(target);
78
+ }
79
+ const _mc = node._mc;
80
+ // add the element with the given property key to the _mc property
81
+ if (key.length && !_mc[key]) {
82
+ _mc[key] = element;
83
+ // add attribute if HTMLElement
84
+ if (target instanceof HTMLElement) {
85
+ target.setAttribute('_mc', '');
86
+ }
87
+ }
88
+ return element;
89
+ }
90
+ // remove a micro component from the DOM
91
+ static remove(target, key) {
92
+ if (!key)
93
+ return; // silent fail
94
+ const _mc = target?._mc || {};
95
+ // delete the property from the HTMLElement _mc collection
96
+ if (_mc && _mc[key]) {
97
+ delete _mc[key];
98
+ }
99
+ // remove the _mc attribute if the DOM collection is empty
100
+ if (!Object.keys(_mc).length && target instanceof HTMLElement && target.hasAttribute('_mc')) {
101
+ target.removeAttribute('_mc');
102
+ }
103
+ return;
104
+ }
105
+ // add a microcomponent to the collection
106
+ add(key, element, target) {
107
+ if (this.#_mc[key])
108
+ return;
109
+ // if target parameter exists ( a DOM node )
110
+ // you want a top level (public) MC
111
+ if (target) {
112
+ // ... add the new micro component to the DOM node _mc
113
+ MC.add(target, key, element);
114
+ }
115
+ // add the new micro component to the private collection anyway
116
+ this.#_mc[key] = element;
117
+ return element;
118
+ }
119
+ // remove a micro component from the collection
120
+ remove(key, target) {
121
+ const _mc = this.#_mc;
122
+ const t = target;
123
+ // if target parameter exists ( a DOM node )
124
+ // you want to remove a top level (public) MC
125
+ if (target) {
126
+ // ... remove the new micro component from the DOM node _mc
127
+ MC.remove(t, key);
128
+ }
129
+ // remove the new micro component from the private collection anyway
130
+ delete _mc?.[key];
131
+ }
132
+ // return all micro components from the collection, or the searched one
133
+ // in a top level DOM MC, this refers to the inner collection always
134
+ // use MC.siblings() to get the public MCs
135
+ siblings(search = '') {
136
+ const _mc = this.#_mc;
137
+ if (!_mc)
138
+ return [];
139
+ const result = _mc[search || ''];
140
+ return search && result ? [result] : [...Object.values(_mc)];
141
+ }
142
+ /*
143
+ the following selectors will only work for the DOM top level MCs and return [] otherwise
144
+ */
145
+ // first anchestor DOM node, all public MCs
146
+ parent(search = '') {
147
+ if (!isDOM(this.#target))
148
+ return [];
149
+ return traverseNodes(this.#target.parentNode, search, true);
150
+ }
151
+ // all anchestor DOM nodes, beginning with the closest, all public MCs
152
+ parents(search = '') {
153
+ if (!isDOM(this.#target))
154
+ return [];
155
+ return traverseNodes(this.#target.parentNode, search, false);
156
+ }
157
+ // nearest child DOM nodes, all puclic MCs
158
+ children(search = '') {
159
+ if (!isDOM(this.#target))
160
+ return [];
161
+ const id = Math.random().toString().replace('.', '');
162
+ const selector = '[_mc]:not([temp_id="' + id + '"] [_mc] [_mc])'; // HOTFIX: minifier or tsc compiler error, dont use backtick string, cuts out blanks
163
+ this.#target.setAttribute('temp_id', id);
164
+ const myDomElements = this.#target.querySelectorAll(selector);
165
+ const mcValues = getMicroComponents([...myDomElements], search);
166
+ this.#target.removeAttribute('temp-id');
167
+ return mcValues;
168
+ }
169
+ // all descendant DOM nodes, all puclic MCs
170
+ descendants(search = '') {
171
+ if (!isDOM(this.#target))
172
+ return [];
173
+ const myDomElements = this.#target.querySelectorAll('*[_mc]');
174
+ return getMicroComponents([...myDomElements], search);
175
+ }
176
+ }
@@ -16,7 +16,7 @@
16
16
  <li><a href="microcomponents.html">microcomponents</a></li></ul>
17
17
  <h1>Module microcomponents</h1></div><aside class="tsd-sources">
18
18
  <ul>
19
- <li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/cb1aec4/src/microcomponents.ts#L1">src/microcomponents.ts:1</a></li></ul></aside>
19
+ <li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/f72dc84/src/microcomponents.ts#L1">microcomponents.ts:1</a></li></ul></aside>
20
20
  <section class="tsd-panel-group">
21
21
  <section class="tsd-panel tsd-typography"></section></section>
22
22
  <section class="tsd-panel-group tsd-index-group">
@@ -25,10 +25,6 @@
25
25
  <section class="tsd-index-section">
26
26
  <h3 class="tsd-index-heading">Classes</h3>
27
27
  <div class="tsd-index-list"><a href="../classes/microcomponents.MC.html" class="tsd-index-link tsd-kind-class tsd-parent-kind-module"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-class)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-128-path"></rect><path d="M11.898 16.1201C11.098 16.1201 10.466 15.8961 10.002 15.4481C9.53803 15.0001 9.30603 14.3841 9.30603 13.6001V9.64012C9.30603 8.85612 9.53803 8.24012 10.002 7.79212C10.466 7.34412 11.098 7.12012 11.898 7.12012C12.682 7.12012 13.306 7.34812 13.77 7.80412C14.234 8.25212 14.466 8.86412 14.466 9.64012H13.386C13.386 9.14412 13.254 8.76412 12.99 8.50012C12.734 8.22812 12.37 8.09212 11.898 8.09212C11.426 8.09212 11.054 8.22412 10.782 8.48812C10.518 8.75212 10.386 9.13212 10.386 9.62812V13.6001C10.386 14.0961 10.518 14.4801 10.782 14.7521C11.054 15.0161 11.426 15.1481 11.898 15.1481C12.37 15.1481 12.734 15.0161 12.99 14.7521C13.254 14.4801 13.386 14.0961 13.386 13.6001H14.466C14.466 14.3761 14.234 14.9921 13.77 15.4481C13.306 15.8961 12.682 16.1201 11.898 16.1201Z" fill="var(--color-text)" id="icon-128-text"></path></svg><span>MC</span></a>
28
- </div></section>
29
- <section class="tsd-index-section">
30
- <h3 class="tsd-index-heading">Interfaces</h3>
31
- <div class="tsd-index-list"><a href="../interfaces/microcomponents.HTMLElementMc.html" class="tsd-index-link tsd-kind-interface tsd-parent-kind-module"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-256-path"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)" id="icon-256-text"></path></svg><span>HTMLElement<wbr/>Mc</span></a>
32
28
  </div></section></section></section></div>
33
29
  <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
34
30
  <div class="tsd-navigation settings">
@@ -55,8 +51,7 @@
55
51
  <li class="tsd-kind-module"><a href="microcomponents_es3.html">microcomponents.es3</a></li></ul></li></ul></div></details></nav>
56
52
  <nav class="tsd-navigation secondary menu-sticky">
57
53
  <ul>
58
- <li class="tsd-kind-class tsd-parent-kind-module"><a href="../classes/microcomponents.MC.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg>MC</a></li>
59
- <li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/microcomponents.HTMLElementMc.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-256-path"></use><use href="#icon-256-text"></use></svg>HTMLElement<wbr/>Mc</a></li></ul></nav></div></div>
54
+ <li class="tsd-kind-class tsd-parent-kind-module"><a href="../classes/microcomponents.MC.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg>MC</a></li></ul></nav></div></div>
60
55
  <div class="container tsd-generator">
61
56
  <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
62
57
  <div class="overlay"></div><script src="../assets/main.js"></script></body></html>
@@ -0,0 +1,11 @@
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 Manual Test</title>
7
+ </head>
8
+ <body>
9
+ <script type="module" src="./test.js"></script>
10
+ </body>
11
+ </html>
package/public/test.js ADDED
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ function getMicroComponents(elements, search) {
3
+ let mcValues = [];
4
+ elements.forEach((e) => {
5
+ if (e) {
6
+ if (e instanceof HTMLElement) {
7
+ const _mc = e?._mc;
8
+ if (!search && _mc) {
9
+ mcValues = mcValues.concat(Object.values(e._mc));
10
+ }
11
+ else if (search && _mc && _mc[search]) {
12
+ mcValues.push(_mc[search]);
13
+ }
14
+ }
15
+ }
16
+ });
17
+ return mcValues;
18
+ }
19
+ function traverseNodes(node, search, firstonly = true) {
20
+ let mcValues = [];
21
+ while (node) {
22
+ if (node._mc) {
23
+ if (!search) {
24
+ mcValues = mcValues.concat(Object.values(node._mc));
25
+ }
26
+ else if (search && node._mc[search]) {
27
+ mcValues.push(node._mc[search]);
28
+ }
29
+ if (firstonly)
30
+ return mcValues;
31
+ }
32
+ node = node.parentNode;
33
+ }
34
+ return mcValues;
35
+ }
36
+ function isDOM(element) {
37
+ return element && element instanceof HTMLElement;
38
+ }
39
+ class MC {
40
+ #target = {};
41
+ #_mc = {};
42
+ static debug = false;
43
+ constructor(target) {
44
+ this.#target = target;
45
+ this.#_mc = {};
46
+ }
47
+ get _mc() {
48
+ if (!MC.debug)
49
+ return undefined;
50
+ return this.#_mc;
51
+ }
52
+ get target() {
53
+ return this.#target;
54
+ }
55
+ static siblings(target, search = "") {
56
+ const mc = target;
57
+ if (!mc._mc) {
58
+ return [];
59
+ }
60
+ const _mc = mc._mc;
61
+ if (search.length) {
62
+ return _mc?.[search] || [];
63
+ }
64
+ return [...Object.values(_mc)];
65
+ }
66
+ static add(target, key, element = {}) {
67
+ let node = target;
68
+ if (!node._mc) {
69
+ node._mc = new MC(target);
70
+ }
71
+ const _mc = node._mc;
72
+ if (key.length && !_mc[key]) {
73
+ _mc[key] = element;
74
+ if (target instanceof HTMLElement) {
75
+ target.setAttribute("_mc", "");
76
+ }
77
+ }
78
+ return element;
79
+ }
80
+ static remove(target, key) {
81
+ if (!key)
82
+ return;
83
+ const _mc = target?._mc || {};
84
+ if (_mc && _mc[key]) {
85
+ delete _mc[key];
86
+ }
87
+ if (!Object.keys(_mc).length &&
88
+ target instanceof HTMLElement &&
89
+ target.hasAttribute("_mc")) {
90
+ target.removeAttribute("_mc");
91
+ }
92
+ return;
93
+ }
94
+ add(key, element, target) {
95
+ if (this.#_mc[key])
96
+ return;
97
+ if (target) {
98
+ MC.add(target, key, element);
99
+ }
100
+ this.#_mc[key] = element;
101
+ return element;
102
+ }
103
+ remove(key, target) {
104
+ const _mc = this.#_mc;
105
+ const t = target;
106
+ if (target) {
107
+ MC.remove(t, key);
108
+ }
109
+ delete _mc?.[key];
110
+ }
111
+ siblings(search = "") {
112
+ const _mc = this.#_mc;
113
+ if (!_mc)
114
+ return [];
115
+ const result = _mc[search || ""];
116
+ return search && result ? [result] : [...Object.values(_mc)];
117
+ }
118
+ parent(search = "") {
119
+ if (!isDOM(this.#target))
120
+ return [];
121
+ return traverseNodes(this.#target.parentNode, search, true);
122
+ }
123
+ parents(search = "") {
124
+ if (!isDOM(this.#target))
125
+ return [];
126
+ return traverseNodes(this.#target.parentNode, search, false);
127
+ }
128
+ children(search = "") {
129
+ if (!isDOM(this.#target))
130
+ return [];
131
+ const id = Math.random().toString().replace(".", "");
132
+ const selector = '[_mc]:not([temp_id="' + id + '"] [_mc] [_mc])';
133
+ this.#target.setAttribute("temp_id", id);
134
+ const myDomElements = this.#target.querySelectorAll(selector);
135
+ const mcValues = getMicroComponents([...myDomElements], search);
136
+ this.#target.removeAttribute("temp-id");
137
+ return mcValues;
138
+ }
139
+ descendants(search = "") {
140
+ if (!isDOM(this.#target))
141
+ return [];
142
+ const myDomElements = this.#target.querySelectorAll("*[_mc]");
143
+ return getMicroComponents([...myDomElements], search);
144
+ }
145
+ }
146
+ // create test page if necessary, otherwise test what is present
147
+ if (window.location.hostname.indexOf("gitlab") > -1) {
148
+ 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><div class="level_5"></div><div class="level_5"></div><div class="level_5"></div><div class="level_5"></div></span></div></span></div></span></div></span></div>`;
149
+ let elements = [...document.querySelectorAll("div")].reverse();
150
+ elements.forEach((e) => (e.innerHTML = e.innerHTML.repeat(5)));
151
+ document.body.innerHTML = document.body.innerHTML.repeat(5);
152
+ document.body.innerHTML =
153
+ document.body.innerHTML +
154
+ "<span>F12 opens the debugger, console has some manual tests...</span>";
155
+ }
156
+ // create an inner micro component class
157
+ class MyInnerMC extends MC {
158
+ constructor(target) {
159
+ super(target);
160
+ }
161
+ doSomething() {
162
+ console.log(this, " myInnerMC something done");
163
+ console.log(this.siblings());
164
+ }
165
+ }
166
+ // create a custom micro component class
167
+ class MyMC extends MC {
168
+ #myInner;
169
+ constructor(target) {
170
+ super(target);
171
+ //add a micro component
172
+ this.add("myInnerMC", new MyInnerMC(target));
173
+ // add a private MC
174
+ this.#myInner = new MyInnerMC(target);
175
+ }
176
+ doSomething() {
177
+ console.log(this, "myMC something done");
178
+ this.#myInner.doSomething();
179
+ }
180
+ }
181
+ console.time("MC creation time");
182
+ // get some element from the DOM
183
+ const domElement = document.querySelector("div");
184
+ // Add the custom micro component instance to the target element
185
+ MC.add(domElement, "myFirstMC", new MyMC(domElement));
186
+ // Add the custom micro component instance to every div
187
+ document.querySelectorAll("div").forEach((e) => {
188
+ MC.add(e, "myPublicMC1", new MyMC(e));
189
+ MC.add(e, "myPublicMC2", new MyMC(e));
190
+ });
191
+ console.timeEnd("MC creation time");
192
+ let c = document.querySelectorAll("[_mc]");
193
+ console.info("number of DOM nodes:", document.querySelectorAll("*").length, "\nnumber of DOM nodes containing micro components:", c.length, "\nnumber of top level micro components:", c.length * 2 + 1, // TODO write reducer
194
+ "\nnumber of top level & inner micro components:", c.length * 6 + 2 // TODO write reducer
195
+ );
196
+ console.warn("domElement = first DIV element:", domElement);
197
+ console.log("domElement\n ._mc", domElement._mc);
198
+ console.log("domElement\n ._mc\n .myFirstMC", domElement._mc.myFirstMC);
199
+ console.log("domElement\n ._mc\n .myFirstMC\n ._mc (MC.debug = false)", domElement._mc.myFirstMC._mc);
200
+ MC.debug = true;
201
+ console.log("domElement\n ._mc\n .myFirstMC\n ._mc (MC.debug = true)", domElement._mc.myFirstMC._mc);
202
+ MC.debug = false;
203
+ /*
204
+ test selectors
205
+ */
206
+ let sc = c[2]._mc.myPublicMC1; // 3rd level DIV micro component
207
+ console.warn("sc = some div in the middle of the tree, level 3 of 5", sc);
208
+ console.log("number of sc parents (expect 5)", sc.parents());
209
+ console.log("number of sc parent (expect 2)", sc.parent());
210
+ console.log("sc PUBLIC siblings (expect 2)", sc.target.className, Object.keys(sc.target._mc), sc.target._mc);
211
+ console.log("sc PRIVATE siblings (MC.debug = false, expect undefined)", sc._mc);
212
+ MC.debug = true;
213
+ console.log("sc PRIVATE siblings (MC.debug = true, expect 1)", Object.keys(sc._mc).length, sc._mc);
214
+ MC.debug = false;
215
+ console.log("number of sc children (expect 10)", sc.children());
216
+ console.log("number of sc descendants (expect 260)", sc.descendants());