@twobirds/microcomponents 0.0.21 → 0.0.23

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 (118) hide show
  1. package/.gitlab-ci.yml +1 -0
  2. package/README.md +31 -12
  3. package/assets/documentation/MicroComponents.md +228 -0
  4. package/assets/my-tag.css +4 -0
  5. package/assets/test.html +5 -1
  6. package/dist/MC.d.ts +32 -0
  7. package/dist/MC.d.ts.map +1 -0
  8. package/dist/MC.min.js +414 -0
  9. package/dist/MC.ts +350 -0
  10. package/dist/McEvent.d.ts +15 -0
  11. package/dist/McEvent.d.ts.map +1 -0
  12. package/dist/McEvent.ts +96 -0
  13. package/dist/autoloader.d.ts +2 -0
  14. package/dist/autoloader.d.ts.map +1 -0
  15. package/dist/autoloader.ts +98 -0
  16. package/dist/customElements.d.ts +5 -0
  17. package/dist/customElements.d.ts.map +1 -0
  18. package/dist/customElements.min.js +1 -0
  19. package/dist/customElements.ts +67 -0
  20. package/dist/customObservables.d.ts +3 -0
  21. package/dist/customObservables.d.ts.map +1 -0
  22. package/dist/customObservables.min.js +1 -0
  23. package/dist/customObservables.ts +340 -0
  24. package/dist/customSelectors.d.ts +108 -0
  25. package/dist/customSelectors.d.ts.map +1 -0
  26. package/dist/customSelectors.min.js +1 -0
  27. package/dist/customSelectors.ts +1634 -0
  28. package/dist/formValues.d.ts +4 -0
  29. package/dist/formValues.d.ts.map +1 -0
  30. package/dist/formValues.ts +275 -0
  31. package/dist/formvValues.min.js +1 -0
  32. package/dist/helpers.d.ts +11 -0
  33. package/dist/helpers.d.ts.map +1 -0
  34. package/dist/helpers.ts +173 -0
  35. package/dist/microcomponents.d.ts +7 -25
  36. package/dist/microcomponents.d.ts.map +1 -1
  37. package/dist/microcomponents.es3.d.ts +1 -20
  38. package/dist/microcomponents.es3.d.ts.map +1 -1
  39. package/dist/microcomponents.min.js +1 -38
  40. package/dist/microcomponents.ts +8 -216
  41. package/dist/test.d.ts +2 -0
  42. package/dist/test.d.ts.map +1 -0
  43. package/package.json +11 -7
  44. package/public/MC.js +273 -0
  45. package/public/MC.min.js +414 -0
  46. package/public/MCbundle.js +8 -0
  47. package/public/MCbundle.min.js +1 -0
  48. package/public/McEvent.js +74 -0
  49. package/public/MicroComponents.svg +15 -0
  50. package/public/assets/search.js +1 -1
  51. package/public/autoloader.js +57 -0
  52. package/public/classes/MC.DC.html +247 -0
  53. package/public/classes/MC.MC.html +150 -0
  54. package/public/classes/MC.McBase.html +123 -0
  55. package/public/classes/MCbundle.McEvent.html +184 -0
  56. package/public/customElements.js +48 -0
  57. package/public/customElements.min.js +1 -0
  58. package/public/customObservables.js +255 -0
  59. package/public/customObservables.min.js +1 -0
  60. package/public/customSelectors.js +1088 -0
  61. package/public/customSelectors.min.js +1 -0
  62. package/public/documentation/MicroComponents.md +228 -0
  63. package/public/formValues.js +211 -0
  64. package/public/formvValues.min.js +1 -0
  65. package/public/functions/MC.addListener.html +73 -0
  66. package/public/functions/MC.removeListener.html +69 -0
  67. package/public/functions/MCbundle._d.html +85 -0
  68. package/public/functions/MCbundle._t.html +85 -0
  69. package/public/functions/MCbundle.debounce.html +85 -0
  70. package/public/functions/MCbundle.deepEqual.html +85 -0
  71. package/public/functions/MCbundle.defineCE.html +98 -0
  72. package/public/functions/MCbundle.formValues.html +89 -0
  73. package/public/functions/MCbundle.getCE.html +83 -0
  74. package/public/functions/MCbundle.htmlToElements.html +83 -0
  75. package/public/functions/MCbundle.isObject.html +83 -0
  76. package/public/functions/MCbundle.kebabToPascal.html +83 -0
  77. package/public/functions/MCbundle.makeCO.html +85 -0
  78. package/public/functions/MCbundle.nameSpace.html +89 -0
  79. package/public/functions/MCbundle.parse.html +85 -0
  80. package/public/helpers.js +128 -0
  81. package/public/index.html +22 -13
  82. package/public/interfaces/MC.HTMLMcElement.html +3605 -0
  83. package/public/interfaces/MCbundle.DSelector.html +1010 -0
  84. package/public/interfaces/MCbundle.LooseObject.html +80 -0
  85. package/public/interfaces/MCbundle.TSelector.html +709 -0
  86. package/public/microcomponents.es3.js +348 -0
  87. package/public/microcomponents.js +8 -176
  88. package/public/microcomponents.min.js +1 -0
  89. package/public/modules/MC.html +84 -0
  90. package/public/modules/MCbundle.html +133 -0
  91. package/public/modules.html +4 -4
  92. package/public/my-tag.css +4 -0
  93. package/public/test.html +5 -1
  94. package/public/test.js +100 -202
  95. package/public/types/MCbundle.selection.html +74 -0
  96. package/public/types/MCbundle.singleSelector.html +74 -0
  97. package/src/MC.ts +350 -0
  98. package/src/McEvent.ts +96 -0
  99. package/src/autoloader.ts +98 -0
  100. package/src/customElements.ts +67 -0
  101. package/src/customObservables.ts +340 -0
  102. package/src/customSelectors.ts +1634 -0
  103. package/src/formValues.ts +275 -0
  104. package/src/helpers.ts +173 -0
  105. package/src/microcomponents.es3.js +353 -82
  106. package/src/microcomponents.ts +8 -216
  107. package/src/test.js +137 -218
  108. package/tsconfig.json +2 -2
  109. package/typedoc.json +1 -1
  110. package/webpack.config.js +233 -0
  111. package/dist/microcomponents.es3.js +0 -96
  112. package/dist/microcomponents.es3.min.js +0 -15
  113. package/dist/microcomponents.js +0 -176
  114. package/public/classes/microcomponents.MC.html +0 -313
  115. package/public/classes/microcomponents_es3.MC.html +0 -336
  116. package/public/functions/microcomponents_es3.__isEmpty.html +0 -60
  117. package/public/modules/microcomponents.html +0 -57
  118. package/public/modules/microcomponents_es3.html +0 -60
@@ -1,96 +0,0 @@
1
- "use strict";
2
- function __isEmpty(obj) {
3
- if (!obj)
4
- return false;
5
- for (var key in obj) {
6
- if (obj.hasOwnProperty(key) && key !== "_target") {
7
- return false;
8
- }
9
- }
10
- return true;
11
- }
12
- function MC(target) {
13
- this._target = target;
14
- }
15
- // static functions, chainable
16
- MC.add = function (domElement, key, element) {
17
- if (key && typeof key === "string" && domElement && !domElement._mc[key]) {
18
- domElement.mc[key] = element;
19
- domElement.setAttribute("_mc", "");
20
- }
21
- return this;
22
- };
23
- MC.remove = function (domElement, key) {
24
- delete domElement._mc[key];
25
- if (isEmpty(this)) {
26
- this._target.removeAttribute("_mc");
27
- }
28
- return this;
29
- };
30
- // other methods, not chainable
31
- MC.prototype.siblings = function (search) {
32
- var mcValues = [];
33
- if (this._target._mc) {
34
- for (var key in this._target._mc) {
35
- if (key !== "_target" &&
36
- this._target._mc.hasOwnProperty(key) &&
37
- (!search || key === search)) {
38
- mcValues.push(this._target._mc[key]);
39
- }
40
- }
41
- }
42
- return mcValues;
43
- };
44
- MC.prototype.parent = function (search) {
45
- var mcValues = [];
46
- var current = this._target.parentNode;
47
- while (current) {
48
- if (current._mc) {
49
- return current._mc.siblings(search);
50
- }
51
- current = current.parentNode;
52
- }
53
- return mcValues;
54
- };
55
- MC.prototype.parents = function (search) {
56
- var mcValues = [];
57
- var current = this._target.parentNode;
58
- while (current) {
59
- if (current._mc) {
60
- mcValues = mcValues.concat(current._mc.siblings(search));
61
- }
62
- current = current.parentNode;
63
- }
64
- return mcValues;
65
- };
66
- MC.prototype.children = function (search) {
67
- var mcValues = [];
68
- function traverseTree(element) {
69
- var children = element.children;
70
- for (var i = 0; i < children.length; i++) {
71
- var child = children[i];
72
- if (child._mc) {
73
- mcValues = mcValues.concat(child._mc.siblings(search));
74
- continue;
75
- }
76
- traverseTree(child);
77
- }
78
- }
79
- traverseTree(this._target);
80
- return mcValues;
81
- };
82
- MC.prototype.descendants = function (search) {
83
- var mcValues = [];
84
- function traverseTree(element) {
85
- var children = element.children;
86
- for (var i = 0; i < children.length; i++) {
87
- var child = children[i];
88
- if (child._mc) {
89
- mcValues = mcValues.concat(child._mc.siblings(search));
90
- }
91
- traverseTree(child);
92
- }
93
- }
94
- traverseTree(this._target);
95
- return mcValues;
96
- };
@@ -1,15 +0,0 @@
1
- "use strict";function __isEmpty(obj){if(!obj)return false;for(var key in obj){if(obj.hasOwnProperty(key)&&key!=="_target"){return false;}}
2
- return true;}
3
- function MC(target){this._target=target;}
4
- MC.add=function(domElement,key,element){if(key&&typeof key==="string"&&domElement&&!domElement._mc[key]){domElement.mc[key]=element;domElement.setAttribute("_mc","");}
5
- return this;};MC.remove=function(domElement,key){delete domElement._mc[key];if(isEmpty(this)){this._target.removeAttribute("_mc");}
6
- return this;};MC.prototype.siblings=function(search){var mcValues=[];if(this._target._mc){for(var key in this._target._mc){if(key!=="_target"&&this._target._mc.hasOwnProperty(key)&&(!search||key===search)){mcValues.push(this._target._mc[key]);}}}
7
- return mcValues;};MC.prototype.parent=function(search){var mcValues=[];var current=this._target.parentNode;while(current){if(current._mc){return current._mc.siblings(search);}
8
- current=current.parentNode;}
9
- return mcValues;};MC.prototype.parents=function(search){var mcValues=[];var current=this._target.parentNode;while(current){if(current._mc){mcValues=mcValues.concat(current._mc.siblings(search));}
10
- current=current.parentNode;}
11
- return mcValues;};MC.prototype.children=function(search){var mcValues=[];function traverseTree(element){var children=element.children;for(var i=0;i<children.length;i++){var child=children[i];if(child._mc){mcValues=mcValues.concat(child._mc.siblings(search));continue;}
12
- traverseTree(child);}}
13
- traverseTree(this._target);return mcValues;};MC.prototype.descendants=function(search){var mcValues=[];function traverseTree(element){var children=element.children;for(var i=0;i<children.length;i++){var child=children[i];if(child._mc){mcValues=mcValues.concat(child._mc.siblings(search));}
14
- traverseTree(child);}}
15
- traverseTree(this._target);return mcValues;};
@@ -1,176 +0,0 @@
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
- }