@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
@@ -1,367 +1,176 @@
1
1
  'use strict';
2
- /**
3
- * @module microcomponenents
4
- */
5
- /**
6
- * A static flag to enable or disable debugging mode.
7
- * @name debug
8
- * @memberOf MC
9
- * @static
10
- * @type {boolean} A static flag to enable or disable debugging mode.
11
- */
12
- /**
13
- * Retrieves all top-level microcomponents from a target HTMLElement.
14
- * @name siblings
15
- * @memberOf MC
16
- * @static
17
- * @function
18
- * @param {HTMLElement} target - The target DOM element.
19
- * @param {string} [search] - The key of the specific microcomponent to find.
20
- * @returns {Array<any>} An array of microcomponents or an empty array if none found.
21
- * @example
22
- * const siblings = MC.siblings(
23
- * &nbsp;document.getElementById('myElement'),
24
- * &nbsp;'myComponent'
25
- * );
26
- */
27
- /**
28
- * Adds a top level microcomponent to a target DOM node.
29
- * @name add
30
- * @memberOf MC
31
- * @static
32
- * @function
33
- * @param {HTMLElement} target - The target DOM element.
34
- * @param {string} key - The key to identify the microcomponent.
35
- * @param {any} [element={}] - The microcomponent to add.
36
- * @returns {any} The added microcomponent.
37
- * @example
38
- * const component = MC.add(
39
- * &nbsp;document.getElementById('myElement'),
40
- * &nbsp;'myComponent',
41
- * &nbsp;{}
42
- * );
43
- */
44
- /**
45
- * Removes a top level microcomponent from the target DOM node.
46
- * @name remove
47
- * @memberOf MC
48
- * @static
49
- * @function
50
- * @param {HTMLElement} target - The target DOM element.
51
- * @param {string} key - The key identifying the microcomponent.
52
- * @example
53
- * MC.remove(
54
- * &nbsp;document.getElementById('myElement'),
55
- * &nbsp;'myComponent'
56
- * );
57
- */
58
- /**
59
- * Manages microcomponents (MCs) attached to DOM elements, allowing for the
60
- * addition, removal, and traversal of microcomponents across siblings, parents,
61
- * children, and descendants.
62
- *
63
- * This class provides an API for interacting with microcomponents on DOM elements.
64
- * Public microcomponents are stored on the `_mc` attribute of the DOM element, while
65
- * private microcomponents are managed internally.
66
- *
67
- * @example
68
- * ```javascript
69
- *
70
- * // create the micro component class
71
- * class MyMC extends MC{
72
- *
73
- * &nbsp;constructor( target ){
74
- * &nbsp;&nbsp;super( target );
75
- * &nbsp;&nbsp;this.target = target;
76
- * &nbsp;}
77
- * }
78
- *
79
- * const element = document.querySelector('div')
80
- *
81
- * // Add the top level microcomponent to the target element
82
- * let mcc = MC.add(
83
- * &nbsp;element,
84
- * &nbsp;'myMC',
85
- * &nbsp;new MyMC( element )
86
- * );
87
- *
88
- * // Add an inner (private) microcomponent to mcc
89
- * let mcc.add(
90
- * &nbsp;'myInnerMC',
91
- * &nbsp;new MyMC( element )
92
- * );
93
- *
94
- * console.log( element._mc );
95
- * // { 'myMC': { target: (element) } }
96
- *
97
- * console.log( element._mc.myMC );
98
- * // { target: (element) }
99
- *
100
- * console.log( mcc.siblings() );
101
- * // [ { target: (element) } ]
102
- *
103
- * ```
104
- * @class
105
- * @name MC
106
- */
107
- class MC {
108
- target;
109
- privateMCs = {};
110
- _mc = {};
111
- static debug = false;
112
- /**
113
- * Constructs an MC instance with a target DOM element.
114
- * @constructor
115
- * @param {HTMLElement | { [key: string]: any }} - The target DOM element or any object.
116
- */
117
- constructor(target = undefined) {
118
- /**
119
- * target is a DOM element or a parent MC
120
- * @type {object}
121
- * @public
122
- */
123
- this.target = target;
124
- /**
125
- * The collection of private microcomponents.
126
- * @private
127
- * @type {Object.<string, any>}
128
- */
129
- this.privateMCs = {};
130
- if (MC.debug) {
131
- /**
132
- * exposes private microcomponents in debug mode.
133
- * @public
134
- * @type {Object.<string, any>}
135
- */
136
- this._mc = this.privateMCs;
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;
137
36
  }
37
+ node = node.parentNode;
138
38
  }
139
- static siblings(target, search) {
140
- let t = target;
141
- if (!t?._mc)
142
- return [];
143
- let mc = t._mc;
144
- return search ? mc[search] ? [mc[search]] : [] : [...Object.entries(t._mc)];
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 = {};
145
51
  }
146
- static add(target, key, element = {}) {
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 = '') {
147
62
  const mc = target;
148
63
  if (!mc._mc) {
149
- mc._mc = new 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);
150
78
  }
151
- if (key && !mc._mc[key]) {
152
- mc._mc[key] = element;
153
- if (target) {
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) {
154
85
  target.setAttribute('_mc', '');
155
86
  }
156
87
  }
157
88
  return element;
158
89
  }
90
+ // remove a micro component from the DOM
159
91
  static remove(target, key) {
160
- if (!key || typeof key !== 'string' || !target || !(target instanceof HTMLElement))
161
- return;
162
- const mc = target;
163
- if (mc._mc && mc._mc[key]) {
164
- delete mc._mc[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];
165
98
  }
166
- if (!Object.keys(mc._mc).length && target.hasAttribute('_mc')) {
99
+ // remove the _mc attribute if the DOM collection is empty
100
+ if (!Object.keys(_mc).length && target instanceof HTMLElement && target.hasAttribute('_mc')) {
167
101
  target.removeAttribute('_mc');
168
102
  }
103
+ return;
169
104
  }
170
- /**
171
- * returns top level microcomponents from a list of HTMLElements.
172
- * @name getMicroComponents
173
- * @instance
174
- * @function
175
- * @private
176
- * @param {Array<any>} elements - The elements to search for microcomponents.
177
- * @param {string} [search] - The key of the specific microcomponent.
178
- * @returns {Array<any>} An array of microcomponents.
179
- */
180
- getMicroComponents(elements, search) {
181
- let mcValues = [];
182
- elements.forEach(e => {
183
- if (e) {
184
- if (e instanceof HTMLElement) {
185
- if (!search && e._mc) {
186
- mcValues = mcValues.concat(Object.values(e._mc));
187
- }
188
- else if (search && e._mc && e._mc[search]) {
189
- mcValues.push(e._mc[search]);
190
- }
191
- }
192
- else if (e instanceof MC) {
193
- if (!search) {
194
- mcValues = mcValues.concat(Object.values(this.privateMCs));
195
- }
196
- else if (search && this.privateMCs[search]) {
197
- mcValues.push(e._mc[search]);
198
- }
199
- }
200
- }
201
- });
202
- return mcValues;
203
- }
204
- /**
205
- * returns ancestor MCs
206
- * @name traverseNodes
207
- * @instance
208
- * @function
209
- * @private
210
- * @param {Node | null} node - The starting DOM node.
211
- * @param {string} [search] - The key of the specific microcomponent.
212
- * @param {boolean} [firstonly=true] - If true, returns the first match only.
213
- * @returns {Array<any>} An array of matching microcomponents.
214
- */
215
- traverseNodes(node, search, firstonly = true) {
216
- let mcValues = [];
217
- while (node) {
218
- if (node._mc) {
219
- if (!search) {
220
- mcValues = mcValues.concat(Object.values(node._mc));
221
- }
222
- else if (search && node._mc[search]) {
223
- mcValues.push(node._mc[search]);
224
- }
225
- if (firstonly)
226
- return mcValues;
227
- }
228
- node = node.parentNode;
229
- }
230
- return mcValues;
231
- }
232
- /**
233
- * returns true if the element is an instance of HTMLElement.
234
- * @instance
235
- * @function
236
- * @name isDOM
237
- * @private
238
- * @type {Function}
239
- * @param {any} element - The element to check.
240
- * @returns {boolean}
241
- */
242
- isDOM(element) {
243
- return element && element instanceof HTMLElement;
244
- }
245
- /**
246
- * adds a microcomponent to the private collection.
247
- * @name add
248
- * @instance
249
- * @function
250
- * @param {string} [key] - The key to identify the microcomponent.
251
- * @param {any} [element={}] - The microcomponent to add.
252
- * @returns {any} The added microcomponent.
253
- * @example
254
- * const privateComp = this.add('privateComponent', {});
255
- */
256
- add(key, element = {}) {
257
- if (key) {
258
- this.privateMCs[key] = element;
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);
259
114
  }
115
+ // add the new micro component to the private collection anyway
116
+ this.#_mc[key] = element;
260
117
  return element;
261
118
  }
262
- /**
263
- * removes a microcomponent from the private collection.
264
- * @name remove
265
- * @instance
266
- * @function
267
- * @param {string} [key] - The key to identify the microcomponent.
268
- * @example
269
- * this.remove('privateComponent');
270
- */
271
- remove(key) {
272
- if (key in this.privateMCs) {
273
- delete this.privateMCs[key];
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);
274
128
  }
129
+ // remove the new micro component from the private collection anyway
130
+ delete _mc?.[key];
275
131
  }
276
- /**
277
- * removes a microcomponent from the private collection.
278
- * @name siblings
279
- * @instance
280
- * @function
281
- * @param {string} [search] - The key of the specific microcomponent.
282
- * @returns {Array<any>} An array of matching sibling microcomponents.
283
- * @example
284
- * const siblings = this.siblings('siblingComponent');
285
- */
286
- siblings(search) {
287
- if (this.target) {
288
- if (this.target instanceof HTMLElement === true) {
289
- return this.getMicroComponents([this.target], search);
290
- }
291
- else {
292
- const result = this.privateMCs[search || ''];
293
- return search && result ? [result] : Object.entries(this.privateMCs);
294
- }
295
- }
296
- return [];
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)];
297
141
  }
298
- /**
299
- * retrieves the first ancestor DOM node with a matching microcomponent.
300
- * @name parent
301
- * @instance
302
- * @function
303
- * @param {string} [search] - The key of the specific microcomponent.
304
- * @returns {Array<any>} An array with the matching microcomponent.
305
- * @example
306
- * const parent = mcInstance.parent('parentComponent');
307
- */
308
- /**
309
- */
310
- parent(search) {
311
- if (!this.isDOM(this.target))
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))
312
148
  return [];
313
- return this.traverseNodes(this.target.parentNode, search, true);
149
+ return traverseNodes(this.#target.parentNode, search, true);
314
150
  }
315
- /**
316
- * retrieves the first ancestor DOM node with a matching microcomponent.
317
- * @name parents
318
- * @instance
319
- * @function
320
- * @param {string} [search] - The key of the specific microcomponent.
321
- * @returns {Array<any>} An array of matching ancestor microcomponents.
322
- * @example
323
- * const parents = mcInstance.parents('ancestorComponent');
324
- */
325
- parents(search) {
326
- if (!this.isDOM(this.target))
151
+ // all anchestor DOM nodes, beginning with the closest, all public MCs
152
+ parents(search = '') {
153
+ if (!isDOM(this.#target))
327
154
  return [];
328
- return this.traverseNodes(this.target.parentNode, search, false);
155
+ return traverseNodes(this.#target.parentNode, search, false);
329
156
  }
330
- /**
331
- * retrieves nearest child _mc DOM nodes, gets their matching microcomponents, and stops there.
332
- * @name children
333
- * @instance
334
- * @function
335
- * @param {string} [search] - The key of the specific microcomponent.
336
- * @returns {Array<any>} An array of matching child microcomponents.
337
- * @example
338
- * const children = mcInstance.children('childComponent');
339
- */
340
- children(search) {
341
- if (!this.isDOM(this.target))
157
+ // nearest child DOM nodes, all puclic MCs
158
+ children(search = '') {
159
+ if (!isDOM(this.#target))
342
160
  return [];
343
- const id = crypto.randomUUID();
344
- this.target.setAttribute('temp-id', id);
345
- const myDomElements = this.target.querySelectorAll(`*[_mc]:not([temp-id="${id}"] [_mc] [_mc])`);
346
- const mcValues = this.getMicroComponents(Array.from(myDomElements), search);
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');
347
167
  return mcValues;
348
168
  }
349
- /**
350
- * retrieves all decendant _mc DOM nodes and gets their matching microcomponents.
351
- * @name children
352
- * @instance
353
- * @function
354
- * @param {string} [search] - The key of the specific microcomponent.
355
- * @returns {Array<any>} An array of matching descendant microcomponents.
356
- * @example
357
- * const descendants = mcInstance.descendants('descendantComponent');
358
- */
359
- descendants(search) {
360
- if (!this.isDOM(this.target))
169
+ // all descendant DOM nodes, all puclic MCs
170
+ descendants(search = '') {
171
+ if (!isDOM(this.#target))
361
172
  return [];
362
- const myDomElements = this.target.querySelectorAll('*[_mc]');
363
- const mcValues = this.getMicroComponents(Array.from(myDomElements), search);
364
- return mcValues;
173
+ const myDomElements = this.#target.querySelectorAll('*[_mc]');
174
+ return getMicroComponents([...myDomElements], search);
365
175
  }
366
176
  }
367
- export { MC };
@@ -1,35 +1,38 @@
1
- 'use strict';class MC{target;privateMCs={};_mc={};static debug=false;constructor(target=undefined){this.target=target;this.privateMCs={};if(MC.debug){this._mc=this.privateMCs;}}
2
- static siblings(target,search){let t=target;if(!t?._mc)
3
- return[];let mc=t._mc;return search?mc[search]?[mc[search]]:[]:[...Object.entries(t._mc)];}
4
- static add(target,key,element={}){const mc=target;if(!mc._mc){mc._mc=new MC();}
5
- if(key&&!mc._mc[key]){mc._mc[key]=element;if(target){target.setAttribute('_mc','');}}
6
- return element;}
7
- static remove(target,key){if(!key||typeof key!=='string'||!target||!(target instanceof HTMLElement))
8
- return;const mc=target;if(mc._mc&&mc._mc[key]){delete mc._mc[key];}
9
- if(!Object.keys(mc._mc).length&&target.hasAttribute('_mc')){target.removeAttribute('_mc');}}
10
- getMicroComponents(elements,search){let mcValues=[];elements.forEach(e=>{if(e){if(e instanceof HTMLElement){if(!search&&e._mc){mcValues=mcValues.concat(Object.values(e._mc));}
11
- else if(search&&e._mc&&e._mc[search]){mcValues.push(e._mc[search]);}}
12
- else if(e instanceof MC){if(!search){mcValues=mcValues.concat(Object.values(this.privateMCs));}
13
- else if(search&&this.privateMCs[search]){mcValues.push(e._mc[search]);}}}});return mcValues;}
14
- traverseNodes(node,search,firstonly=true){let mcValues=[];while(node){if(node._mc){if(!search){mcValues=mcValues.concat(Object.values(node._mc));}
1
+ 'use strict';function getMicroComponents(elements,search){let mcValues=[];elements.forEach(e=>{if(e){if(e instanceof HTMLElement){const _mc=e?._mc;if(!search&&_mc){mcValues=mcValues.concat(Object.values(e._mc));}
2
+ else if(search&&_mc&&_mc[search]){mcValues.push(_mc[search]);}}}});return mcValues;}
3
+ function traverseNodes(node,search,firstonly=true){let mcValues=[];while(node){if(node._mc){if(!search){mcValues=mcValues.concat(Object.values(node._mc));}
15
4
  else if(search&&node._mc[search]){mcValues.push(node._mc[search]);}
16
5
  if(firstonly)
17
6
  return mcValues;}
18
7
  node=node.parentNode;}
19
8
  return mcValues;}
20
- isDOM(element){return element&&element instanceof HTMLElement;}
21
- add(key,element={}){if(key){this.privateMCs[key]=element;}
9
+ function isDOM(element){return element&&element instanceof HTMLElement;}
10
+ export class MC{#target={};#_mc={};static debug=false;constructor(target){this.#target=target;this.#_mc={};}
11
+ get _mc(){if(!MC.debug)
12
+ return undefined;return this.#_mc;}
13
+ get target(){return this.#target;}
14
+ static siblings(target,search=''){const mc=target;if(!mc._mc){return[];}
15
+ const _mc=mc._mc;if(search.length){return _mc?.[search]||[];}
16
+ return[...Object.values(_mc)];}
17
+ static add(target,key,element={}){let node=target;if(!node._mc){node._mc=new MC(target);}
18
+ const _mc=node._mc;if(key.length&&!_mc[key]){_mc[key]=element;if(target instanceof HTMLElement){target.setAttribute('_mc','');}}
22
19
  return element;}
23
- remove(key){if(key in this.privateMCs){delete this.privateMCs[key];}}
24
- siblings(search){if(this.target){if(this.target instanceof HTMLElement===true){return this.getMicroComponents([this.target],search);}
25
- else{const result=this.privateMCs[search||''];return search&&result?[result]:Object.entries(this.privateMCs);}}
26
- return[];}
27
- parent(search){if(!this.isDOM(this.target))
28
- return[];return this.traverseNodes(this.target.parentNode,search,true);}
29
- parents(search){if(!this.isDOM(this.target))
30
- return[];return this.traverseNodes(this.target.parentNode,search,false);}
31
- children(search){if(!this.isDOM(this.target))
32
- return[];const id=crypto.randomUUID();this.target.setAttribute('temp-id',id);const myDomElements=this.target.querySelectorAll(`*[_mc]:not([temp-id="${id}"][_mc][_mc])`);const mcValues=this.getMicroComponents(Array.from(myDomElements),search);return mcValues;}
33
- descendants(search){if(!this.isDOM(this.target))
34
- return[];const myDomElements=this.target.querySelectorAll('*[_mc]');const mcValues=this.getMicroComponents(Array.from(myDomElements),search);return mcValues;}}
35
- export{MC};
20
+ static remove(target,key){if(!key)
21
+ return;const _mc=target?._mc||{};if(_mc&&_mc[key]){delete _mc[key];}
22
+ if(!Object.keys(_mc).length&&target instanceof HTMLElement&&target.hasAttribute('_mc')){target.removeAttribute('_mc');}
23
+ return;}
24
+ add(key,element,target){if(this.#_mc[key])
25
+ return;if(target){MC.add(target,key,element);}
26
+ this.#_mc[key]=element;return element;}
27
+ remove(key,target){const _mc=this.#_mc;const t=target;if(target){MC.remove(t,key);}
28
+ delete _mc?.[key];}
29
+ siblings(search=''){const _mc=this.#_mc;if(!_mc)
30
+ return[];const result=_mc[search||''];return search&&result?[result]:[...Object.values(_mc)];}
31
+ parent(search=''){if(!isDOM(this.#target))
32
+ return[];return traverseNodes(this.#target.parentNode,search,true);}
33
+ parents(search=''){if(!isDOM(this.#target))
34
+ return[];return traverseNodes(this.#target.parentNode,search,false);}
35
+ children(search=''){if(!isDOM(this.#target))
36
+ return[];const id=Math.random().toString().replace('.','');const selector='[_mc]:not([temp_id="'+id+'"] [_mc] [_mc])';this.#target.setAttribute('temp_id',id);const myDomElements=this.#target.querySelectorAll(selector);const mcValues=getMicroComponents([...myDomElements],search);this.#target.removeAttribute('temp-id');return mcValues;}
37
+ descendants(search=''){if(!isDOM(this.#target))
38
+ return[];const myDomElements=this.#target.querySelectorAll('*[_mc]');return getMicroComponents([...myDomElements],search);}}