@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/README.md CHANGED
@@ -21,7 +21,7 @@ Imagine your micro components to be organized like a "node_modules" directory th
21
21
  **On the server side** MCs can be used to organize your code, too.
22
22
 
23
23
  ## Status
24
- WIP. Micro components should be done soon, as in days.
24
+ WIP. Should be done soon. In [manual testing](http://twobirds.gitlab.io/microcomponents/test.html).
25
25
 
26
26
  ## Disclaimer
27
27
  I decided to extract this functionality from the [twoBirds framework](https://www.npmjs.com/package/twobirds-core), 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.
@@ -40,9 +40,7 @@ This is a low-level approach. It consists of a single class with 3 static method
40
40
 
41
41
  For a short usage description goto [Micro Component Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_usage.md?ref_type=heads).
42
42
 
43
- Check the [typedoc API reference](http://twobirds.gitlab.io/microcomponents/docs/modules.html) if you want to drill into the source code.
44
-
45
- Or read the more detailed [jsdoc API documentation](http://twobirds.gitlab.io/microcomponents/jsdoc/es5+/index.html) which contains **examples**.
43
+ Check the [typedoc API reference](http://twobirds.gitlab.io/microcomponents/classes/microcomponents.MC.html) if you want to drill into the source code.
46
44
 
47
45
  To see what can be done, go to [additional concepts](https://gitlab.com/twoBirds/microcomponents/-/blob/main/microcomponents_magic.md?ref_type=heads) which shows what it already has been used for.
48
46
 
@@ -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>
@@ -1,242 +1,26 @@
1
- /**
2
- * @module microcomponenents
3
- */
4
- /**
5
- * A static flag to enable or disable debugging mode.
6
- * @name debug
7
- * @memberOf MC
8
- * @static
9
- * @type {boolean} A static flag to enable or disable debugging mode.
10
- */
11
- /**
12
- * Retrieves all top-level microcomponents from a target HTMLElement.
13
- * @name siblings
14
- * @memberOf MC
15
- * @static
16
- * @function
17
- * @param {HTMLElement} target - The target DOM element.
18
- * @param {string} [search] - The key of the specific microcomponent to find.
19
- * @returns {Array<any>} An array of microcomponents or an empty array if none found.
20
- * @example
21
- * const siblings = MC.siblings(
22
- * &nbsp;document.getElementById('myElement'),
23
- * &nbsp;'myComponent'
24
- * );
25
- */
26
- /**
27
- * Adds a top level microcomponent to a target DOM node.
28
- * @name add
29
- * @memberOf MC
30
- * @static
31
- * @function
32
- * @param {HTMLElement} target - The target DOM element.
33
- * @param {string} key - The key to identify the microcomponent.
34
- * @param {any} [element={}] - The microcomponent to add.
35
- * @returns {any} The added microcomponent.
36
- * @example
37
- * const component = MC.add(
38
- * &nbsp;document.getElementById('myElement'),
39
- * &nbsp;'myComponent',
40
- * &nbsp;{}
41
- * );
42
- */
43
- /**
44
- * Removes a top level microcomponent from the target DOM node.
45
- * @name remove
46
- * @memberOf MC
47
- * @static
48
- * @function
49
- * @param {HTMLElement} target - The target DOM element.
50
- * @param {string} key - The key identifying the microcomponent.
51
- * @example
52
- * MC.remove(
53
- * &nbsp;document.getElementById('myElement'),
54
- * &nbsp;'myComponent'
55
- * );
56
- */
57
- /**
58
- * Manages microcomponents (MCs) attached to DOM elements, allowing for the
59
- * addition, removal, and traversal of microcomponents across siblings, parents,
60
- * children, and descendants.
61
- *
62
- * This class provides an API for interacting with microcomponents on DOM elements.
63
- * Public microcomponents are stored on the `_mc` attribute of the DOM element, while
64
- * private microcomponents are managed internally.
65
- *
66
- * @example
67
- * ```javascript
68
- *
69
- * // create the micro component class
70
- * class MyMC extends MC{
71
- *
72
- * &nbsp;constructor( target ){
73
- * &nbsp;&nbsp;super( target );
74
- * &nbsp;&nbsp;this.target = target;
75
- * &nbsp;}
76
- * }
77
- *
78
- * const element = document.querySelector('div')
79
- *
80
- * // Add the top level microcomponent to the target element
81
- * let mcc = MC.add(
82
- * &nbsp;element,
83
- * &nbsp;'myMC',
84
- * &nbsp;new MyMC( element )
85
- * );
86
- *
87
- * // Add an inner (private) microcomponent to mcc
88
- * let mcc.add(
89
- * &nbsp;'myInnerMC',
90
- * &nbsp;new MyMC( element )
91
- * );
92
- *
93
- * console.log( element._mc );
94
- * // { 'myMC': { target: (element) } }
95
- *
96
- * console.log( element._mc.myMC );
97
- * // { target: (element) }
98
- *
99
- * console.log( mcc.siblings() );
100
- * // [ { target: (element) } ]
101
- *
102
- * ```
103
- * @class
104
- * @name MC
105
- */
106
- declare class MC {
107
- private target;
108
- private privateMCs;
109
- _mc?: {
1
+ type HTMLElementMC = HTMLElement & {
2
+ _mc: {
110
3
  [key: string]: any;
111
4
  };
5
+ };
6
+ export declare class MC {
7
+ #private;
112
8
  static debug: boolean;
113
- /**
114
- * Constructs an MC instance with a target DOM element.
115
- * @constructor
116
- * @param {HTMLElement | { [key: string]: any }} - The target DOM element or any object.
117
- */
118
- constructor(target?: HTMLElement | {
9
+ constructor(target: {
119
10
  [key: string]: any;
120
- } | undefined);
121
- static siblings(target: HTMLElement, search?: string): any[];
122
- static add(target: HTMLElement, key: string, element?: any): any[];
123
- static remove(target: HTMLElement, key: string): void;
124
- /**
125
- * returns top level microcomponents from a list of HTMLElements.
126
- * @name getMicroComponents
127
- * @instance
128
- * @function
129
- * @private
130
- * @param {Array<any>} elements - The elements to search for microcomponents.
131
- * @param {string} [search] - The key of the specific microcomponent.
132
- * @returns {Array<any>} An array of microcomponents.
133
- */
134
- private getMicroComponents;
135
- /**
136
- * returns ancestor MCs
137
- * @name traverseNodes
138
- * @instance
139
- * @function
140
- * @private
141
- * @param {Node | null} node - The starting DOM node.
142
- * @param {string} [search] - The key of the specific microcomponent.
143
- * @param {boolean} [firstonly=true] - If true, returns the first match only.
144
- * @returns {Array<any>} An array of matching microcomponents.
145
- */
146
- private traverseNodes;
147
- /**
148
- * returns true if the element is an instance of HTMLElement.
149
- * @instance
150
- * @function
151
- * @name isDOM
152
- * @private
153
- * @type {Function}
154
- * @param {any} element - The element to check.
155
- * @returns {boolean}
156
- */
157
- private isDOM;
158
- /**
159
- * adds a microcomponent to the private collection.
160
- * @name add
161
- * @instance
162
- * @function
163
- * @param {string} [key] - The key to identify the microcomponent.
164
- * @param {any} [element={}] - The microcomponent to add.
165
- * @returns {any} The added microcomponent.
166
- * @example
167
- * const privateComp = this.add('privateComponent', {});
168
- */
169
- add(key?: string, element?: any): any;
170
- /**
171
- * removes a microcomponent from the private collection.
172
- * @name remove
173
- * @instance
174
- * @function
175
- * @param {string} [key] - The key to identify the microcomponent.
176
- * @example
177
- * this.remove('privateComponent');
178
- */
179
- remove(key: string): void;
180
- /**
181
- * removes a microcomponent from the private collection.
182
- * @name siblings
183
- * @instance
184
- * @function
185
- * @param {string} [search] - The key of the specific microcomponent.
186
- * @returns {Array<any>} An array of matching sibling microcomponents.
187
- * @example
188
- * const siblings = this.siblings('siblingComponent');
189
- */
11
+ });
12
+ get _mc(): undefined | any;
13
+ get target(): any;
14
+ static siblings(target: HTMLElementMC, search?: string): any[];
15
+ static add(target: HTMLElement, key: string, element?: {}): any;
16
+ static remove(target: HTMLElementMC, key: string): void;
17
+ add(key: string, element: any, target?: HTMLElement): any;
18
+ remove(key: string, target?: HTMLElement): void;
190
19
  siblings(search?: string): any[];
191
- /**
192
- * retrieves the first ancestor DOM node with a matching microcomponent.
193
- * @name parent
194
- * @instance
195
- * @function
196
- * @param {string} [search] - The key of the specific microcomponent.
197
- * @returns {Array<any>} An array with the matching microcomponent.
198
- * @example
199
- * const parent = mcInstance.parent('parentComponent');
200
- */
201
- /**
202
- */
203
20
  parent(search?: string): any[];
204
- /**
205
- * retrieves the first ancestor DOM node with a matching microcomponent.
206
- * @name parents
207
- * @instance
208
- * @function
209
- * @param {string} [search] - The key of the specific microcomponent.
210
- * @returns {Array<any>} An array of matching ancestor microcomponents.
211
- * @example
212
- * const parents = mcInstance.parents('ancestorComponent');
213
- */
214
21
  parents(search?: string): any[];
215
- /**
216
- * retrieves nearest child _mc DOM nodes, gets their matching microcomponents, and stops there.
217
- * @name children
218
- * @instance
219
- * @function
220
- * @param {string} [search] - The key of the specific microcomponent.
221
- * @returns {Array<any>} An array of matching child microcomponents.
222
- * @example
223
- * const children = mcInstance.children('childComponent');
224
- */
225
22
  children(search?: string): any[];
226
- /**
227
- * retrieves all decendant _mc DOM nodes and gets their matching microcomponents.
228
- * @name children
229
- * @instance
230
- * @function
231
- * @param {string} [search] - The key of the specific microcomponent.
232
- * @returns {Array<any>} An array of matching descendant microcomponents.
233
- * @example
234
- * const descendants = mcInstance.descendants('descendantComponent');
235
- */
236
23
  descendants(search?: string): any[];
237
24
  }
238
- export interface HTMLElementMc extends HTMLElement {
239
- _mc: MC;
240
- }
241
- export { MC };
25
+ export {};
242
26
  //# sourceMappingURL=microcomponents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,cAAM,EAAE;IAEP,OAAO,CAAC,MAAM,CAAmD;IAE9D,OAAO,CAAC,UAAU,CAA8B;IAEzC,GAAG,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAA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GAAI,GAAG,EAAE;CAOzC"}
@@ -1,6 +1,11 @@
1
1
  declare function __isEmpty(obj: any): boolean;
2
2
  declare function MC(target: any): void;
3
3
  declare class MC {
4
+ static add(target: any, key: any, element?: {}): {};
5
+ static remove(target: any, key: any): void;
6
+ static debug: boolean;
7
+ static siblings(target: any, search?: string): any;
8
+ constructor(target: any);
4
9
  constructor(target: any);
5
10
  _target: any;
6
11
  siblings(search: any): any[];
@@ -1 +1 @@
1
- {"version":3,"file":"microcomponents.es3.d.ts","sourceRoot":"","sources":["../src/microcomponents.es3.js"],"names":[],"mappings":"AAEA,8CAQC;AAED,uCAEC;;IAFD,yBAEC;IADA,aAAqB;IAqBtB,6BAcC;IAED,yBAUC;IAED,4BAUC;IAED,6BAeC;IAED,gCAcC;;;IAxFD,iEAMC;IAED,sDAMC"}
1
+ {"version":3,"file":"microcomponents.es3.d.ts","sourceRoot":"","sources":["../src/microcomponents.es3.js"],"names":[],"mappings":"AAEA,8CAQC;AAED,uCAEC;;;;;;;IAFD,yBAEC;IADA,aAAqB;IAqBtB,6BAcC;IAED,yBAUC;IAED,4BAUC;IAED,6BAeC;IAED,gCAcC;;;IAxFD,iEAMC;IAED,sDAMC"}