@twobirds/microcomponents 0.0.20 → 0.0.22

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 (122) hide show
  1. package/.gitlab-ci.yml +1 -0
  2. package/README.md +33 -14
  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/MCbundle.d.ts +8 -0
  11. package/dist/MCbundle.d.ts.map +1 -0
  12. package/dist/MCbundle.min.js +1 -0
  13. package/dist/MCbundle.ts +8 -0
  14. package/dist/McEvent.d.ts +15 -0
  15. package/dist/McEvent.d.ts.map +1 -0
  16. package/dist/McEvent.ts +96 -0
  17. package/dist/autoloader.d.ts +2 -0
  18. package/dist/autoloader.d.ts.map +1 -0
  19. package/dist/autoloader.ts +98 -0
  20. package/dist/customElements.d.ts +5 -0
  21. package/dist/customElements.d.ts.map +1 -0
  22. package/dist/customElements.min.js +1 -0
  23. package/dist/customElements.ts +67 -0
  24. package/dist/customObservables.d.ts +3 -0
  25. package/dist/customObservables.d.ts.map +1 -0
  26. package/dist/customObservables.min.js +1 -0
  27. package/dist/customObservables.ts +340 -0
  28. package/dist/customSelectors.d.ts +108 -0
  29. package/dist/customSelectors.d.ts.map +1 -0
  30. package/dist/customSelectors.min.js +1 -0
  31. package/dist/customSelectors.ts +1634 -0
  32. package/dist/formValues.d.ts +4 -0
  33. package/dist/formValues.d.ts.map +1 -0
  34. package/dist/formValues.ts +275 -0
  35. package/dist/formvValues.min.js +1 -0
  36. package/dist/helpers.d.ts +11 -0
  37. package/dist/helpers.d.ts.map +1 -0
  38. package/dist/helpers.ts +173 -0
  39. package/dist/microcomponents.es3.d.ts +1 -20
  40. package/dist/microcomponents.es3.d.ts.map +1 -1
  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/modules/MC.html +84 -0
  88. package/public/modules/MCbundle.html +133 -0
  89. package/public/modules.html +4 -4
  90. package/public/my-tag.css +4 -0
  91. package/public/test.html +5 -1
  92. package/public/test.js +100 -202
  93. package/public/types/MCbundle.selection.html +74 -0
  94. package/public/types/MCbundle.singleSelector.html +74 -0
  95. package/src/MC.ts +350 -0
  96. package/src/MCbundle.ts +8 -0
  97. package/src/McEvent.ts +96 -0
  98. package/src/autoloader.ts +98 -0
  99. package/src/customElements.ts +67 -0
  100. package/src/customObservables.ts +340 -0
  101. package/src/customSelectors.ts +1634 -0
  102. package/src/formValues.ts +275 -0
  103. package/src/helpers.ts +173 -0
  104. package/src/microcomponents.es3.js +353 -82
  105. package/src/test.js +137 -218
  106. package/tsconfig.json +2 -2
  107. package/typedoc.json +1 -1
  108. package/webpack.config.js +233 -0
  109. package/dist/microcomponents.d.ts +0 -26
  110. package/dist/microcomponents.d.ts.map +0 -1
  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/dist/microcomponents.min.js +0 -38
  115. package/dist/microcomponents.ts +0 -216
  116. package/public/classes/microcomponents.MC.html +0 -313
  117. package/public/classes/microcomponents_es3.MC.html +0 -336
  118. package/public/functions/microcomponents_es3.__isEmpty.html +0 -60
  119. package/public/microcomponents.js +0 -176
  120. package/public/modules/microcomponents.html +0 -57
  121. package/public/modules/microcomponents_es3.html +0 -60
  122. package/src/microcomponents.ts +0 -216
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ import { isObject, parse, debounce, deepEqual } from './helpers.js';
3
+ export const makeCO = (target, propertyName) => {
4
+ let keys = !propertyName ? [...Object.getOwnPropertyNames(target)] : [propertyName];
5
+ keys.forEach((key) => {
6
+ // console.log( 'co propname', key, typeof target[key], target[key] );
7
+ if (key[0] === '_' || target?.[key] === undefined)
8
+ return;
9
+ let val = target[key], Constructor;
10
+ if (!val.prototype) {
11
+ switch (typeof val) {
12
+ case "string":
13
+ Constructor = String;
14
+ break;
15
+ case "number":
16
+ Constructor = Number;
17
+ break;
18
+ case "boolean":
19
+ Constructor = Boolean;
20
+ break;
21
+ case "object":
22
+ if (val instanceof Array) {
23
+ Constructor = Array;
24
+ }
25
+ else {
26
+ Constructor = Object;
27
+ }
28
+ break;
29
+ default:
30
+ return;
31
+ }
32
+ }
33
+ let Observable = class extends Constructor {
34
+ constructor(val) {
35
+ super(val);
36
+ this.constructor.callbacks = [];
37
+ if (isObject(val)) { // you cannot bind native values to the dom
38
+ this.constructor.bound = [];
39
+ Object.getOwnPropertyNames(val).forEach((key) => {
40
+ this[key] = val[key];
41
+ });
42
+ }
43
+ }
44
+ observe(f) {
45
+ //console.log('observe');
46
+ this.constructor.callbacks.push(f);
47
+ return this;
48
+ }
49
+ bind(target) {
50
+ const that = this, iso = isObject(that.valueOf()), bound = that.constructor.bound;
51
+ //console.log('bind', iso, target);
52
+ if (iso) {
53
+ // console.log('bind...', that.valueOf(), target );
54
+ function walk(element) {
55
+ //console.log('-walk:', element, element.childNodes );
56
+ if (!!element['nodeType'] && element.nodeType === 3) { // text node
57
+ //console.log('--type: textNode(3)');
58
+ var placeholders = Array.from(element.nodeValue && element.nodeValue.match(/\{[^\{\}]*\}/g) || []);
59
+ if (placeholders.length > 0) {
60
+ //console.log('--placeholders:', placeholders);
61
+ var f = (function (template) {
62
+ //console.log('template', template);
63
+ return function (values) {
64
+ var t, changed = false;
65
+ //console.log( 'placeholders:', placeholders, 'values:', values);
66
+ if (placeholders) {
67
+ if (iso) {
68
+ placeholders.forEach(function (placeholder) {
69
+ if (f.values[placeholder] !== values[placeholder]) {
70
+ f.values[placeholder] = values[placeholder];
71
+ changed = true;
72
+ }
73
+ });
74
+ }
75
+ else { // it is a simple value
76
+ f.values = values;
77
+ changed = true;
78
+ }
79
+ ;
80
+ }
81
+ if (changed) { // only reflow if changed
82
+ t = template;
83
+ //console.log('--template parse', t, (f as LooseObject).values );
84
+ if (iso) {
85
+ element.nodeValue = parse(t, f.values);
86
+ }
87
+ else { // it is a simple value -> replace every placeholder whatever the name wi
88
+ element.nodeValue = t.replace(/\{.*\}/g, f.values);
89
+ }
90
+ ;
91
+ }
92
+ return values;
93
+ };
94
+ })(element.nodeValue || '');
95
+ f.values = iso ? {} : undefined;
96
+ placeholders = Array.from(placeholders).map((pKey) => pKey.replace(/[\{\}]/g, '').trim());
97
+ let initial = iso ? {} : undefined;
98
+ placeholders.forEach(function (pKey) {
99
+ if (iso) {
100
+ initial[pKey] = "";
101
+ }
102
+ });
103
+ bound.push(f);
104
+ // console.log( `--bound textNode`, placeholders, f );
105
+ //(observableFunction as Function)(initial);
106
+ }
107
+ //console.log('--childNodes:', element.childNodes );
108
+ Array.from(element.childNodes)
109
+ .forEach(function (childNode) {
110
+ walk(childNode);
111
+ });
112
+ that.notify();
113
+ }
114
+ if (!!element['nodeType'] && element.nodeType === 1) { // HTML element
115
+ //console.log('--type: HTMLElement(1)');
116
+ Array.from(element.attributes)
117
+ .forEach(function (attributeNode) {
118
+ var placeholders = Array.from(attributeNode.value && attributeNode.value.match(/\{[^\{\}]*\}/g) || []);
119
+ if (placeholders.length > 0) {
120
+ //console.log( `--[${attributeNode.value}] placeholders:`, placeholders );
121
+ var f = (function (template) {
122
+ return function (values) {
123
+ var t, changed = false;
124
+ //console.log( 'placeholders:', placeholders, 'values:', values);
125
+ if (placeholders) {
126
+ placeholders.forEach(function (pKey) {
127
+ if (f.values[pKey] !== values[pKey]) {
128
+ f.values[pKey] = values[pKey];
129
+ changed = true;
130
+ }
131
+ });
132
+ }
133
+ if (changed) { // only reflow if changed
134
+ t = template;
135
+ element.nodeValue = parse(t, f.values);
136
+ }
137
+ return values;
138
+ };
139
+ })(attributeNode.value || '');
140
+ f.values = {};
141
+ placeholders = Array.from(placeholders).map((pKey) => pKey.replace(/[\{\}]/g, '').trim());
142
+ let initial = {};
143
+ placeholders.forEach(function (pKey) {
144
+ initial[pKey] = "";
145
+ });
146
+ bound.push(f);
147
+ // console.log( `--bound element attribute`, placeholders, f );
148
+ // console.log( `--bound`, observableFunction.bound );
149
+ //(observableFunction as Function)(initial);
150
+ }
151
+ });
152
+ //console.log('--childNodes:', element.childNodes );
153
+ Array.from(element.childNodes)
154
+ .forEach(function (childNode) {
155
+ walk(childNode);
156
+ });
157
+ that.notify();
158
+ }
159
+ if (!!element['nodeType'] && element.nodeType === 11) { // shadowRoot node
160
+ // console.log( element, element.childNodes );
161
+ Array.from(element.childNodes)
162
+ .forEach(function (childNode) {
163
+ walk(childNode);
164
+ });
165
+ }
166
+ }
167
+ walk(target);
168
+ if (bound.length > 0) {
169
+ that.notify();
170
+ }
171
+ }
172
+ else {
173
+ console.warn('IGNORED - cannot bind a non-Object to the dom, IS:', typeof that.valueOf());
174
+ }
175
+ return this;
176
+ }
177
+ notify() {
178
+ let that = this, data = isObject(that.valueOf()) && (that.valueOf() instanceof Array) === false
179
+ ? structuredClone(Object.assign({}, that))
180
+ : that.valueOf();
181
+ // console.log('notify', that.constructor, (that.constructor as any).callbacks.length, (that.constructor as any)?.bound?.length, data );
182
+ that.constructor.callbacks.forEach((f) => {
183
+ // console.log( 'callback', f, data);
184
+ f(data);
185
+ });
186
+ if (isObject(that.valueOf())) {
187
+ // console.log('bound', this.constructor);
188
+ that.constructor.bound.forEach((f) => {
189
+ // console.log( 'bound', f, data);
190
+ f(data);
191
+ });
192
+ }
193
+ return this;
194
+ }
195
+ };
196
+ //(Observable.constructor as LooseObject).callbacks = [];
197
+ let o = new Observable(val);
198
+ Object.defineProperty(target, key, {
199
+ enumerable: true,
200
+ get() {
201
+ if (isObject(o.valueOf())) {
202
+ let check = structuredClone(Object.assign({}, o));
203
+ setTimeout(debounce(function checkChanges() {
204
+ let state = structuredClone(Object.assign({}, o));
205
+ //console.log( 'check changes', state, check );
206
+ if (!deepEqual(state, check)) {
207
+ //console.log( '-> not equal!' );
208
+ o.notify();
209
+ }
210
+ }, 0), 0);
211
+ }
212
+ return o;
213
+ },
214
+ set(val) {
215
+ //console.log( 'SET:', isObject( val.valueOf() ), 'set:', val, 'to', isObject( o.valueOf() ), o, );
216
+ if (typeof val === typeof o.valueOf()) {
217
+ let iso = isObject(o.valueOf()) && (o.valueOf() instanceof Array) === false;
218
+ //let iso = o.constructor.prototype.__proto__.constructor === Object;
219
+ //console.log('target iso:', iso);
220
+ if (iso) {
221
+ let old = structuredClone(Object.assign({}, o));
222
+ val = structuredClone(Object.assign({}, val));
223
+ let hasFormHandler = o.constructor?.hasFormHandler ?? false, callbacks = o.constructor.callbacks, bound = o.constructor.bound;
224
+ o = new Observable(structuredClone(Object.assign({}, val)));
225
+ //console.log('after set o=', o, 'check', old);
226
+ o.constructor.callbacks = hasFormHandler;
227
+ o.constructor.callbacks = callbacks;
228
+ o.constructor.bound = bound;
229
+ setTimeout(// check for changes
230
+ debounce(function checkChanges() {
231
+ let state = structuredClone(Object.assign({}, o));
232
+ //console.log( 'check changes', state, check );
233
+ if (!deepEqual(state, old)) {
234
+ //console.log( '-> not equal!' );
235
+ o.notify();
236
+ }
237
+ }, 0), 0);
238
+ }
239
+ else { // simple native var
240
+ let old = o.valueOf(), callbacks = o.constructor.callbacks;
241
+ o = new Observable(val);
242
+ o.constructor.callbacks = callbacks;
243
+ if (val !== old) {
244
+ o.notify();
245
+ }
246
+ }
247
+ }
248
+ else {
249
+ console.warn('IGNORED - cannot change observable types, IS:', typeof o.valueOf(), '- CANNOT BECOME:', typeof val);
250
+ }
251
+ }
252
+ });
253
+ target[key] = val;
254
+ });
255
+ };
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.customObservables=t():e.customObservables=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return null!=e&&"object"==typeof e}function o(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function n(e,t){const o=Object.keys(e),c=Object.keys(t);if(o.length!==c.length)return!1;for(const c of o){const o=e[c],a=t[c],u=r(o)&&r(a);if(u&&!n(o,a)||!u&&o!==a)return!1}return!0}function c(e,t,o=null,n){let a=e.split(".");n||(n=t);let u=a.shift(),s=a.join(".");null!==o&&u.length&&void 0===t[u]&&(t[u]={});let l=t[u];return 0===s.length?null!==o?(t[u]=o,n):t[u]:r(t[u])?c(s,t[u],o,n):o?n:l[u]}function a(e,t){var o=Array.from(arguments);if(o.length){if(1===o.length)return o[1];if(o.length>2){for(;o.length>1;)o[0]=a(o[0],o[1]),o.splice(1,1);return o[0]}if("string"==typeof e){var n=e.match(/\{[^\{\}]*\}/g);n&&n.forEach((function(r){var o=c(r.substr(1,r.length-2),t);void 0!==o&&(e=e.replace(r,o))}))}else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=a(e[r],t))}));break;case Array:e.forEach((function(r,o,n){n[o]=a(e[o],t)}))}return e}console.error("no arguments give to parse")}e.r(t),e.d(t,{makeCO:()=>u});const u=(e,t)=>{(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return;let c,u=e[t];if(!u.prototype)switch(typeof u){case"string":c=String;break;case"number":c=Number;break;case"boolean":c=Boolean;break;case"object":c=u instanceof Array?Array:Object;break;default:return}let s=class extends c{constructor(e){super(e),this.constructor.callbacks=[],r(e)&&(this.constructor.bound=[],Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]})))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this,o=r(t.valueOf()),n=t.constructor.bound;if(o){function c(e){if(e.nodeType&&3===e.nodeType){var r=Array.from(e.nodeValue&&e.nodeValue.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var u=(s=e.nodeValue||"",function(t){var n,c=!1;return r&&(o?r.forEach((function(e){u.values[e]!==t[e]&&(u.values[e]=t[e],c=!0)})):(u.values=t,c=!0)),c&&(n=s,e.nodeValue=o?a(n,u.values):n.replace(/\{.*\}/g,u.values)),t});u.values=o?{}:void 0,r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let t=o?{}:void 0;r.forEach((function(e){o&&(t[e]="")})),n.push(u)}Array.from(e.childNodes).forEach((function(e){c(e)})),t.notify()}var s;e.nodeType&&1===e.nodeType&&(Array.from(e.attributes).forEach((function(t){var r=Array.from(t.value&&t.value.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var o=function(t){return function(n){var c,u=!1;return r&&r.forEach((function(e){o.values[e]!==n[e]&&(o.values[e]=n[e],u=!0)})),u&&(c=t,e.nodeValue=a(c,o.values)),n}}(t.value||"");o.values={},r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let c={};r.forEach((function(e){c[e]=""})),n.push(o)}})),Array.from(e.childNodes).forEach((function(e){c(e)})),t.notify()),e.nodeType&&11===e.nodeType&&Array.from(e.childNodes).forEach((function(e){c(e)}))}c(e),n.length>0&&t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf());return this}notify(){let e=this,t=r(e.valueOf())&&e.valueOf()instanceof Array==0?structuredClone(Object.assign({},e)):e.valueOf();return e.constructor.callbacks.forEach((e=>{e(t)})),r(e.valueOf())&&e.constructor.bound.forEach((e=>{e(t)})),this}},l=new s(u);Object.defineProperty(e,t,{enumerable:!0,get(){if(r(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(o((function(){n(structuredClone(Object.assign({},l)),e)||l.notify()}),0),0)}return l},set(e){if(typeof e==typeof l.valueOf())if(r(l.valueOf())&&l.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},l));e=structuredClone(Object.assign({},e));let r=l.constructor?.hasFormHandler??!1,c=l.constructor.callbacks,a=l.constructor.bound;l=new s(structuredClone(Object.assign({},e))),l.constructor.callbacks=r,l.constructor.callbacks=c,l.constructor.bound=a,setTimeout(o((function(){n(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),r=l.constructor.callbacks;l=new s(e),l.constructor.callbacks=r,e!==t&&l.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof l.valueOf(),"- CANNOT BECOME:",typeof e)}}),e[t]=u}))};return t})()));