@twobirds/microcomponents 0.0.84 → 0.0.86

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 (78) hide show
  1. package/README.md +22 -6
  2. package/assets/documentation/MC.md +60 -81
  3. package/assets/documentation/elements.md +6 -9
  4. package/assets/documentation/observables.md +97 -11
  5. package/assets/test/{my-tag.css → myButton.css} +4 -4
  6. package/assets/test/test.html +1 -1
  7. package/dist/MC.d.ts +6 -9
  8. package/dist/MC.d.ts.map +1 -1
  9. package/dist/MC.js +40 -73
  10. package/dist/MC.min.js +40 -73
  11. package/dist/MC.ts +67 -114
  12. package/dist/elements.min.js +1 -1
  13. package/dist/formValues.min.js +1 -1
  14. package/dist/microcomponents.min.js +1 -1
  15. package/dist/observables.min.js +1 -1
  16. package/package.json +2 -2
  17. package/public/MC.d.ts +6 -9
  18. package/public/MC.d.ts.map +1 -1
  19. package/public/MC.js +40 -73
  20. package/public/MC.js.map +1 -1
  21. package/public/MC.min.js +40 -73
  22. package/public/MC.ts +67 -114
  23. package/public/documentation/MC.md +60 -81
  24. package/public/documentation/elements.md +6 -9
  25. package/public/documentation/observables.md +97 -11
  26. package/public/elements.min.js +1 -1
  27. package/public/formValues.min.js +1 -1
  28. package/public/microcomponents.min.js +1 -1
  29. package/public/observables.min.js +1 -1
  30. package/public/src/MC.d.ts +6 -9
  31. package/public/src/MC.d.ts.map +1 -1
  32. package/public/src/MC.js +40 -73
  33. package/public/src/MC.js.map +1 -1
  34. package/public/src/MC.ts +67 -114
  35. package/public/src/test/test/grandparent.js +1 -1
  36. package/public/src/test/test/testform.js +1 -1
  37. package/public/src/test/test.js +23 -31
  38. package/public/src/test/test.js.map +1 -1
  39. package/public/src/test/test.ts +61 -72
  40. package/public/test/MC.d.ts +6 -9
  41. package/public/test/MC.d.ts.map +1 -1
  42. package/public/test/MC.js +40 -73
  43. package/public/test/MC.min.js +40 -73
  44. package/public/test/MC.ts +67 -114
  45. package/public/test/elements.min.js +1 -1
  46. package/public/test/formValues.min.js +1 -1
  47. package/public/test/microcomponents.min.js +1 -1
  48. package/public/test/{my-tag.css → myButton.css} +4 -4
  49. package/public/test/observables.min.js +1 -1
  50. package/public/test/test/grandparent.js +1 -1
  51. package/public/test/test/testform.js +1 -1
  52. package/public/test/test.html +1 -1
  53. package/public/test/test.js +23 -31
  54. package/public/test/test.js.map +1 -1
  55. package/public/test/test.ts +61 -72
  56. package/public/typedoc/assets/navigation.js +1 -1
  57. package/public/typedoc/assets/search.js +1 -1
  58. package/public/typedoc/classes/MC.DC.html +3 -4
  59. package/public/typedoc/classes/MC.MC.html +2 -4
  60. package/public/typedoc/classes/MC.McBase.html +2 -2
  61. package/public/typedoc/functions/MC.autoload.html +1 -1
  62. package/public/typedoc/functions/MC.off.html +1 -1
  63. package/public/typedoc/functions/MC.on.html +1 -1
  64. package/public/typedoc/functions/MC.one.html +1 -1
  65. package/public/typedoc/functions/MC.trigger.html +1 -0
  66. package/public/typedoc/functions/elements.defineCE.html +1 -1
  67. package/public/typedoc/functions/elements.getCE.html +1 -1
  68. package/public/typedoc/functions/formValues.formValues.html +1 -1
  69. package/public/typedoc/functions/observables.observe.html +1 -1
  70. package/public/typedoc/index.html +21 -10
  71. package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
  72. package/public/typedoc/modules/MC.html +3 -3
  73. package/public/typedoc/modules/elements.html +1 -1
  74. package/public/typedoc/modules/formValues.html +1 -1
  75. package/public/typedoc/modules/observables.html +1 -1
  76. package/public/typedoc/types/observables.Observable.html +1 -1
  77. package/src/MC.ts +67 -114
  78. package/src/test/test.ts +61 -72
package/src/test/test.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  getCE,
6
6
  observe,
7
7
  Observable,
8
+ HTMLMcElement,
8
9
  } from '../microcomponents.js';
9
10
 
10
11
  class Translator extends DC {
@@ -39,83 +40,71 @@ class Translator extends DC {
39
40
 
40
41
  (that.Translation as Observable).bind(translationTargetObject);
41
42
 
42
- that.target.setAttribute('language', 'en');
43
-
44
43
  (that.Language as Observable).notify();
45
44
  }
46
45
 
47
- onAttributeChanged(ev: CustomEvent) {
48
- let detail = ev.detail || {};
49
- if (!detail.newValue) return;
50
- switch (detail.name) {
51
- case 'language':
52
- this.Language = detail.newValue;
53
- break;
54
- }
46
+ }
47
+
48
+ class MyButton extends DC {
49
+ #template: string = '{lang.click} {counter}';
50
+
51
+ #languages = {
52
+ en: {
53
+ click: 'click me',
54
+ },
55
+ de: {
56
+ click: 'klick mich',
57
+ },
58
+ };
59
+
60
+ Dom: LooseObject = {};
61
+
62
+ constructor(target: HTMLElement) {
63
+ super(target);
64
+
65
+ // render
66
+ target.innerHTML = this.#template;
67
+
68
+ // state
69
+ this.Dom = { counter: 0 };
70
+
71
+ // state: convert all props defined so far into observables
72
+ observe(this);
73
+
74
+ // add translator
75
+ DC.add(
76
+ target,
77
+ 'Translator',
78
+ new Translator(target, this.#languages, target)
79
+ );
80
+
81
+ // bind Dom to target
82
+ (this.Dom as Observable).bind(this.target);
83
+ }
84
+
85
+ onClick(ev: Event) {
86
+ // console.log('button.myButton onClick()');
87
+ const c = this.Dom.counter++;
88
+ ev.stopPropagation();
89
+ (this.target as HTMLElement).classList.remove('clicked');
90
+ (this.target as HTMLElement).classList.add( this.Dom.counter > 9 ? 'overClicked' : 'clicked' );
55
91
  }
56
92
  }
57
93
 
94
+ function makeButton(): HTMLMcElement {
95
+ const
96
+ button = document.createElement('button');
97
+ button.classList.add('myButton');
98
+ DC.add( button, 'MyButton', new MyButton(button) );
99
+ return button as unknown as HTMLMcElement;
100
+ }
101
+
58
102
  defineCE(
59
- // equivalent to custom element registry .define()
60
- 'my-tag',
61
- class MyTag extends DC {
62
- #template: string = '<button>{lang.click} {counter}</button>';
63
-
64
- #languages = {
65
- en: {
66
- click: 'click me',
67
- },
68
- de: {
69
- click: 'klick mich',
70
- },
71
- };
72
-
73
- Dom: LooseObject = {};
74
-
75
- constructor(target: HTMLElement) {
76
- super(target);
77
-
78
- let that = this; // minifier help
79
-
80
- // render
81
- target.innerHTML = this.#template;
82
-
83
- // add translator
84
- DC.add(
85
- target,
86
- 'translator',
87
- new Translator(target, that.#languages, target)
88
- );
89
- }
90
-
91
- oneInit(ev: CustomEvent) {
92
- let that = this;
93
-
94
- // state
95
- that.Dom = { counter: 0 };
96
-
97
- // state: convert all props defined so far into observables
98
- observe(that);
99
-
100
- // bind Dom to target
101
- (that.Dom as Observable).bind(that.target);
102
- }
103
-
104
- onClick(ev: CustomEvent) {
105
- const that = this,
106
- c = that.Dom.counter++;
107
- (ev.detail.data as PointerEvent).stopPropagation();
108
- (that.target as HTMLElement).classList.remove('clicked');
109
- (that.target as HTMLElement).classList.add(
110
- that.Dom.counter > 9 ? 'overClicked' : 'clicked'
111
- );
112
- }
113
- },
114
- ['language']
103
+ 'make-button',
104
+ makeButton
115
105
  );
116
106
 
117
- let MyTag: CustomElementConstructor = getCE('my-tag')!,
118
- fragment = new DocumentFragment();
107
+ let fragment = new DocumentFragment();
119
108
 
120
109
  /*
121
110
  stress test
@@ -126,7 +115,7 @@ let start = new Date().getTime(),
126
115
 
127
116
  // create 1000 elements
128
117
  for (let x = 0; x < max; x++) {
129
- fragment.append(new MyTag());
118
+ fragment.append( (getCE('make-button') as Function)());
130
119
  }
131
120
 
132
121
  let end = new Date().getTime();
@@ -148,14 +137,14 @@ setTimeout(() => {
148
137
  'font-weight: bold; color: black;',
149
138
  'font-weight: normal;',
150
139
  max,
151
- max * 3,
140
+ max * 2,
152
141
  'font-weight: bold; color: blue;',
153
142
  end - start
154
143
  );
155
144
 
156
145
  //document.body.appendChild(new MyTag());
157
146
 
158
- let element = document.querySelector('my-tag');
147
+ let element = document.querySelector('button');
159
148
 
160
149
  console.log(
161
150
  "\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
@@ -184,5 +173,5 @@ setTimeout(() => {
184
173
  );
185
174
 
186
175
  // will trigger the event on all micro components contained in <my-tag>
187
- DC.trigger(element, 'doSomething');
176
+ ( element as unknown as HTMLMcElement )._mc?.trigger('doSomething');
188
177
  }, 1000);