@twobirds/microcomponents 0.0.33 → 0.0.37

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/README.md +40 -27
  2. package/assets/documentation/{MicroComponents.md → MC.md} +17 -17
  3. package/assets/documentation/comparision.md +0 -0
  4. package/assets/documentation/elements.md +276 -0
  5. package/assets/documentation/magic.md +10 -68
  6. package/dist/MC.d.ts +2 -3
  7. package/dist/MC.d.ts.map +1 -1
  8. package/dist/MC.min.js +45 -43
  9. package/dist/MC.ts +173 -175
  10. package/dist/autoloader.ts +1 -1
  11. package/dist/{customElements.d.ts → elements.d.ts} +1 -1
  12. package/dist/elements.d.ts.map +1 -0
  13. package/dist/elements.min.js +1 -0
  14. package/dist/{customElements.ts → elements.ts} +23 -14
  15. package/dist/helpers.d.ts +6 -4
  16. package/dist/helpers.d.ts.map +1 -1
  17. package/dist/helpers.ts +95 -128
  18. package/dist/microcomponents.d.ts +3 -3
  19. package/dist/microcomponents.d.ts.map +1 -1
  20. package/dist/microcomponents.min.js +1 -1
  21. package/dist/microcomponents.ts +3 -3
  22. package/dist/{customObservables.d.ts → observables.d.ts} +3 -3
  23. package/dist/observables.d.ts.map +1 -0
  24. package/dist/observables.min.js +1 -0
  25. package/dist/observables.ts +354 -0
  26. package/dist/{customSelectors.d.ts → selectors.d.ts} +1 -1
  27. package/dist/selectors.d.ts.map +1 -0
  28. package/dist/selectors.min.js +1 -0
  29. package/dist/test.ts +133 -157
  30. package/klemmstein.png +0 -0
  31. package/package.json +52 -52
  32. package/public/MC.js +46 -44
  33. package/public/MC.js.map +1 -1
  34. package/public/MC.min.js +45 -43
  35. package/public/assets/search.js +1 -1
  36. package/public/autoloader.js +1 -1
  37. package/public/autoloader.js.map +1 -1
  38. package/public/classes/{DC.html → MC.DC.html} +60 -59
  39. package/public/classes/{MC.html → MC.MC.html} +41 -35
  40. package/public/classes/{McBase.html → MC.McBase.html} +28 -20
  41. package/public/classes/{McEvent.html → MC.McEvent.html} +48 -42
  42. package/public/documentation/{MicroComponents.md → MC.md} +17 -17
  43. package/public/documentation/comparision.md +0 -0
  44. package/public/documentation/elements.md +276 -0
  45. package/public/documentation/magic.md +10 -68
  46. package/public/{customElements.js → elements.js} +9 -10
  47. package/public/elements.js.map +1 -0
  48. package/public/elements.min.js +1 -0
  49. package/public/functions/{addListener.html → MC.addListener.html} +18 -12
  50. package/public/functions/{removeListener.html → MC.removeListener.html} +18 -12
  51. package/public/functions/elements.defineCE.html +78 -0
  52. package/public/functions/elements.getCE.html +63 -0
  53. package/public/functions/formValues.formValues.html +68 -0
  54. package/public/functions/observables.observe.html +65 -0
  55. package/public/functions/selectors._d.html +69 -0
  56. package/public/functions/selectors._t.html +69 -0
  57. package/public/helpers.js +66 -89
  58. package/public/helpers.js.map +1 -1
  59. package/public/index.html +48 -33
  60. package/public/interfaces/{HTMLMcElement.html → MC.HTMLMcElement.html} +601 -595
  61. package/public/interfaces/selectors.DSelector.html +1013 -0
  62. package/public/interfaces/selectors.TSelector.html +712 -0
  63. package/public/microcomponents.js +3 -3
  64. package/public/microcomponents.js.map +1 -1
  65. package/public/microcomponents.min.js +1 -1
  66. package/public/modules/MC.html +78 -0
  67. package/public/modules/elements.html +62 -0
  68. package/public/modules/formValues.html +60 -0
  69. package/public/modules/observables.html +65 -0
  70. package/public/modules/selectors.html +76 -0
  71. package/public/modules.html +11 -23
  72. package/public/observables.js +255 -0
  73. package/public/observables.js.map +1 -0
  74. package/public/observables.min.js +1 -0
  75. package/public/{customSelectors.js → selectors.js} +1 -1
  76. package/public/selectors.js.map +1 -0
  77. package/public/selectors.min.js +1 -0
  78. package/public/src/MC.ts +376 -0
  79. package/public/src/McEvent.ts +96 -0
  80. package/public/src/autoloader.ts +98 -0
  81. package/{src/customElements.ts → public/src/elements.ts} +23 -14
  82. package/public/src/formValues.ts +275 -0
  83. package/public/src/helpers.ts +140 -0
  84. package/public/src/microcomponents.ts +8 -0
  85. package/public/src/observables.ts +354 -0
  86. package/public/src/test.ts +187 -0
  87. package/public/test.js +99 -115
  88. package/public/test.js.map +1 -1
  89. package/public/types/observables.Observable.html +91 -0
  90. package/public/types/selectors.selection.html +58 -0
  91. package/public/types/selectors.singleSelector.html +58 -0
  92. package/src/MC.ts +173 -175
  93. package/src/autoloader.ts +1 -1
  94. package/src/elements.ts +76 -0
  95. package/src/helpers.ts +95 -128
  96. package/src/microcomponents.ts +3 -3
  97. package/src/observables.ts +354 -0
  98. package/src/selectors.ts +1634 -0
  99. package/src/test.ts +133 -157
  100. package/typedoc.json +1 -1
  101. package/webpack.config.js +9 -9
  102. package/dist/customElements.d.ts.map +0 -1
  103. package/dist/customElements.min.js +0 -1
  104. package/dist/customObservables.d.ts.map +0 -1
  105. package/dist/customObservables.min.js +0 -1
  106. package/dist/customObservables.ts +0 -348
  107. package/dist/customSelectors.d.ts.map +0 -1
  108. package/dist/customSelectors.min.js +0 -1
  109. package/public/customElements.js.map +0 -1
  110. package/public/customElements.min.js +0 -1
  111. package/public/customObservables.js +0 -256
  112. package/public/customObservables.js.map +0 -1
  113. package/public/customObservables.min.js +0 -1
  114. package/public/customSelectors.js.map +0 -1
  115. package/public/customSelectors.min.js +0 -1
  116. package/src/customObservables.ts +0 -348
  117. /package/dist/{customSelectors.ts → selectors.ts} +0 -0
  118. /package/{src/customSelectors.ts → public/src/selectors.ts} +0 -0
package/dist/test.ts CHANGED
@@ -1,211 +1,187 @@
1
- "use strict";
2
-
3
- import { MC, DC, McEvent, defineCE, getCE, observe } from "./microcomponents.js";
4
-
5
- //import { MC, DC, typeof McEvent } from "./MC.js";
6
- //import { defineCE, getCE } from "./customElements.js";
7
- //import { observe } from "./customObservables.js";
1
+ 'use strict';
2
+
3
+ import {
4
+ HTMLMcElement,
5
+ LooseObject,
6
+ MC,
7
+ DC,
8
+ McEvent,
9
+ defineCE,
10
+ getCE,
11
+ observe,
12
+ Observable,
13
+ } from './microcomponents.js';
14
+
15
+ //import { MC, DC, McEvent } from "./MC.js";
16
+ //import { defineCE, getCE } from "./elements.js";
17
+ //import { observe } from "./observables.js";
8
18
 
9
19
  //MC.debug = true;
10
20
 
11
- class Adder {
12
- constructor() {}
21
+ class Translator extends DC {
22
+ #translations: LooseObject = {};
13
23
 
14
- sum(...numbers: number[]): number {
15
- return numbers.reduce((acc: number, curr: number) => acc + curr, 0);
16
- }
17
- }
24
+ Language: unknown = 'en';
25
+ Translation: unknown = {};
18
26
 
19
- class DeeplyNestedEvTarget extends MC {
20
- constructor(target: any) {
21
- super(target);
22
- }
27
+ constructor(
28
+ target: HTMLElement | ShadowRoot | DocumentFragment,
29
+ translations: LooseObject,
30
+ translationTargetObject: HTMLElement
31
+ ) {
32
+ super(target as HTMLElement);
33
+ let that = this; // minifier help
23
34
 
24
- oneInit(ev: typeof McEvent) {
25
- let logger = this.target?.target?.target?._mc?.logger;
26
- //logger?.warn("DeeplyNestedEvTarget .oneInit(ev)", ev);
27
- }
28
- }
35
+ // state
36
+ that.Language = 'en';
37
+ that.Translation = {};
29
38
 
30
- class EvTarget extends MC {
31
- constructor(target: any) {
32
- super(target);
33
- }
39
+ observe(that);
34
40
 
35
- onCustomEvent(ev: typeof McEvent) {
36
- let logger = this.target?.target?._mc?.logger;
37
- logger?.log("onCustomEvent", ev);
38
- }
41
+ // setup
42
+ that.#translations = translations;
39
43
 
40
- oneInit(ev: typeof McEvent) {
41
- let that = this,
42
- _mc = that._mc!,
43
- logger = this.target?.target?._mc?.logger;
44
+ // state
45
+ (that.Language as Observable).observe((lang) => {
46
+ if (that.#translations.hasOwnProperty(lang)) {
47
+ that.Translation = { lang: that.#translations[lang] }; // set translation
48
+ }
49
+ });
44
50
 
45
- //logger?.warn("EvTarget .oneInit(ev)", ev);
51
+ (that.Translation as Observable).bind(target);
46
52
 
47
- _mc.deeplyNestedEvTarget = new DeeplyNestedEvTarget( that );
53
+ this.target.setAttribute('language', 'en');
48
54
  }
49
- }
50
-
51
- class Logger extends DC {
52
-
53
- prefix: string = "";
54
55
 
55
- stdOut: typeof console = console;
56
-
57
- constructor(target: HTMLElement, logger: typeof console, prefix: string) {
58
- // logger must implement the console interface
59
- super(target);
60
-
61
- let that = this; // scoping and minifier help
62
-
63
- that.prefix = prefix;
64
-
65
- // instance that handles logging, depency injection
66
- that.stdOut = logger;
56
+ oneInit() {
57
+ (this.Language as Observable).notify(); // trigger translation
67
58
  }
68
59
 
69
- log() {
70
- this.stdOut.log(this.prefix, this.target.constructor.name, ...arguments);
71
- }
60
+ onAttributeChanged(ev: McEvent) {
61
+ if (!ev.data.newValue) return;
72
62
 
73
- info() {
74
- this.stdOut.info(this.prefix, this.target.constructor.name, ...arguments);
75
- }
76
- warn() {
77
- this.stdOut.warn(this.prefix, this.target.constructor.name, ...arguments);
63
+ let that = this;
64
+
65
+ switch (ev.data.name) {
66
+ case 'language':
67
+ that.Language = ev.data.newValue;
68
+ break;
69
+ }
78
70
  }
79
71
  }
80
72
 
81
73
  defineCE(
82
74
  // equivalent to custom element registry .define()
83
- "my-tag",
75
+ 'my-tag',
84
76
  class MyTag extends DC {
77
+ #template: string = '{lang.click} {counter}';
85
78
 
86
- In: string = "";
79
+ #languages = {
80
+ en: {
81
+ click: 'click me',
82
+ },
83
+ de: {
84
+ click: 'klick mich',
85
+ },
86
+ };
87
87
 
88
- Counter: number = 0;
88
+ Dom: LooseObject = {};
89
89
 
90
- constructor(target: HTMLElement, data: string) {
90
+ constructor(target: HTMLElement) {
91
91
  super(target);
92
92
 
93
93
  let that = this; // minifier help
94
94
 
95
- // state observables
96
- that.In = data;
97
- that.Counter = 0;
98
-
99
- // convert all props defined so far into custom observables
100
- observe(that);
101
-
102
- DC.add(target, "logger", new Logger(target, console, "[logger]"));
103
-
104
95
  // render
105
- target.innerHTML = "Click Me";
96
+ target.innerHTML = this.#template;
97
+
98
+ // add public translator
99
+ DC.add(
100
+ target,
101
+ 'translator',
102
+ new Translator(target, that.#languages, target)
103
+ );
106
104
  }
107
105
 
108
- /*
109
- web component specific event handlers
110
- */
106
+ oneInit(ev: McEvent) {
107
+ let that = this;
111
108
 
112
- onConnected(ev: typeof McEvent) {
113
- //this.target._mc?.logger.info("onConnected handler", ev);
114
- }
115
-
116
- onAttributeChanged(ev: typeof McEvent) {
117
- let logger = this.target._mc?.logger;
118
- //logger?.info("onAttributeChanged handler", ev);
119
- }
109
+ // state
110
+ that.Dom = { counter: 0 };
120
111
 
121
- /*
122
- native event handlers
123
- */
124
- oneClick(ev: typeof McEvent) {
125
- let logger = this.target._mc?.logger;
126
-
127
- logger.info("oneClick handler", ev);
128
-
129
- this._mc.customEventTarget.trigger("customEvent");
112
+ // state: convert all props defined so far into observables
113
+ observe(that);
130
114
 
131
- this.target.setAttribute("my-attribute", "testValue");
115
+ // bind Dom to target
116
+ (that.Dom as Observable).bind(that.target);
132
117
  }
133
118
 
134
- onClick(ev: typeof McEvent) {
135
- let logger = this.target._mc?.logger;
136
-
137
- logger?.info("onClick handler", ev);
138
-
139
- this.Counter++;
119
+ onAttributeChanged(ev: McEvent) {
120
+ //console.log(ev);
121
+ this.target._mc.translator.Language = ev.data.newValue;
140
122
  }
141
123
 
142
- /*
143
- DC custom event handlers
144
- */
145
- oneInit(ev: typeof McEvent) {
146
- let that = this,
147
- _mc = that._mc;
148
-
149
- let logger = that.target._mc.logger;
150
-
151
- //logger.warn("oneInit handler", ev);
152
-
153
- // add a private event target
154
- _mc.customEventTarget = new EvTarget(that);
155
-
156
- // add a private adder
157
- _mc.Adder = new Adder();
158
-
159
- // add callback for this.Counter changes
160
- ( that.Counter as any).observe((value: number) => {
161
- logger.log("Counter has changed to: " + value);
162
- });
163
-
164
- //logger.log("add 1,2,3 =", _mc.Adder.sum(1, 2, 3));
165
- }
166
-
167
- onDoSomething(ev: typeof McEvent) {
168
- let logger = this.target._mc?.logger;
169
- logger?.log(".onDoSomething(ev): something done...", ev);
124
+ onClick(ev: McEvent) {
125
+ this.Dom.counter++;
170
126
  }
171
127
  },
172
- ["my-attribute"]
128
+ ['language']
173
129
  );
174
130
 
175
- let MyTag: CustomElementConstructor = getCE("my-tag")!,
131
+ let MyTag: CustomElementConstructor = getCE('my-tag')!,
176
132
  fragment = new DocumentFragment();
177
133
 
178
- // stress test
179
- console.time("Instancing");
134
+ /*
135
+ stress test
136
+ */
137
+
138
+ /*
139
+ let start = new Date().getTime();
140
+
180
141
  // create 1000 elements
181
- for ( let x = 0; x < 1000; x ++ ){
182
- fragment.append( new MyTag("my-data") );
142
+ for (let x = 0; x < 1000; x++) {
143
+ let mt = new MyTag('my-data');
144
+ fragment.append(mt);
183
145
  }
184
- document.body.appendChild( fragment );
185
146
 
186
- console.log(
187
- '%c \n\nStress Test:\n\n %cInstancing 1000 classes and putting them in the DOM took (ms):',
188
- "font-weight: bold; color: black;",
189
- "color: black;"
190
- );
191
- console.timeEnd("Instancing");
147
+ let end = new Date().getTime();
192
148
 
193
- document.querySelectorAll('my-tag').forEach( (e) => e.remove() );
149
+ // and put them into the DOM
150
+ document.body.appendChild(fragment);
194
151
 
195
- // and put them into thwe DOM
152
+ document.querySelectorAll('my-tag').forEach((e) => e.remove());
153
+ */
196
154
 
197
- document.body.appendChild( new MyTag("my-data") );
155
+ /*
156
+ console test
157
+ */
198
158
 
199
- let element = document.querySelector("my-tag");
159
+ setTimeout(() => {
160
+ console.clear();
200
161
 
201
- console.log(
202
- "\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
203
- "font-weight: bold;",
204
- "font-weight: normal;",
205
- element,
206
- "font-weight: bold;",
207
- "\n\nLook up code in the debugger: test.js\n\n"
208
- );
162
+ /*
163
+ console.log(
164
+ '%c \n\nStress Test:\n\n %cInstancing 1000 web components: %c %s ms.',
165
+ 'font-weight: bold; color: black;',
166
+ 'font-weight: normal;',
167
+ 'font-weight: bold; color: blue;',
168
+ 0
169
+ );
170
+ */
171
+
172
+ document.body.appendChild(new MyTag());
173
+
174
+ let element = document.querySelector('my-tag');
175
+
176
+ console.log(
177
+ "\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
178
+ 'font-weight: bold;',
179
+ 'font-weight: normal;',
180
+ element,
181
+ 'font-weight: bold;',
182
+ '\n\nLook up code in the debugger: test.js\n\n'
183
+ );
209
184
 
210
- // will trigger the event on all micro components contained in <my-tag>
211
- DC.trigger(element, "doSomething");
185
+ // will trigger the event on all micro components contained in <my-tag>
186
+ DC.trigger(element, 'doSomething');
187
+ }, 20);
package/klemmstein.png ADDED
Binary file
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
1
  {
2
- "name": "@twobirds/microcomponents",
3
- "version": "0.0.33",
4
- "description": "Micro Components Organization Class",
5
- "main": "./dist/microcomponents.ts",
6
- "types": "./dist/microcomponents.d.ts",
7
- "sideEffects": false,
8
- "scripts": {
9
- "typedoc": "typedoc",
10
- "webpack": "webpack",
11
- "clean": "rm -rf build/*; rm -rf dist/*;",
12
- "prep": "cp -R assets/* public || true; cp src/* build || true;",
13
- "build": "npm run clean; npm run prep; tsc; npm run copyToDist; npm run webpack; cp dist/*.js public; cp dist/microcomponents.js build; cp build/*.js public; cp build/*.js.map public;",
14
- "copyToDist": "cp -R assets/* public || true; cp build/*.ts* dist; cp MicroComponents.svg dist; cp MicroComponents.svg public/fiddle; cp dist/MicroComponents.svg public; cp dist/microcomponents.js public;"
15
- },
16
- "author": "",
17
- "license": "ISC",
18
- "devDependencies": {
19
- "jsmin": "^1.0.1",
20
- "ts-loader": "^9.5.2",
21
- "typedoc": "^0.26.11",
22
- "typescript": "^5.5.4",
23
- "webpack": "^5.97.1",
24
- "webpack-cli": "^6.0.1"
25
- },
26
- "keywords": [
27
- "javascript",
28
- "library",
29
- "native",
30
- "DOM manipulation",
31
- "lightweight",
32
- "standalone",
33
- "SPA",
34
- "PWA",
35
- "ES3",
36
- "ES5",
37
- "ES6",
38
- "ES7",
39
- "ES2015",
40
- "ES2016",
41
- "client",
42
- "API"
43
- ],
44
- "repository": {
45
- "type": "git",
46
- "url": "https://gitlab.com/twoBirds/microcomponents"
47
- },
48
- "contributors": [
49
- {
50
- "name": "Frank Thürigen",
51
- "email": "fthuerigen@gmail.com"
52
- }
53
- ]
2
+ "name": "@twobirds/microcomponents",
3
+ "version": "0.0.37",
4
+ "description": "Micro Components Organization Class",
5
+ "main": "./dist/microcomponents.ts",
6
+ "types": "./dist/microcomponents.d.ts",
7
+ "sideEffects": false,
8
+ "scripts": {
9
+ "typedoc": "typedoc",
10
+ "webpack": "webpack",
11
+ "clean": "rm -rf build/*; rm -rf dist/*;",
12
+ "prep": "cp -R assets/* public || true; cp src/* build || true;",
13
+ "build": "npm run clean; npm run prep; tsc; npm run copyToDist; npm run webpack; cp dist/*.js public; cp dist/microcomponents.js build; cp build/*.js public; cp build/*.js.map public;",
14
+ "copyToDist": "mkdir public/src || true; cp src/*.ts public/src || true; cp -R assets/* public || true; cp build/*.ts* dist; cp *.svg dist; cp *.svg public/fiddle; cp dist/MicroComponents.svg public; cp dist/microcomponents.js public;"
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "devDependencies": {
19
+ "jsmin": "^1.0.1",
20
+ "ts-loader": "^9.5.2",
21
+ "typedoc": "^0.26.11",
22
+ "typescript": "^5.5.4",
23
+ "webpack": "^5.97.1",
24
+ "webpack-cli": "^6.0.1"
25
+ },
26
+ "keywords": [
27
+ "javascript",
28
+ "library",
29
+ "native",
30
+ "DOM manipulation",
31
+ "lightweight",
32
+ "standalone",
33
+ "SPA",
34
+ "PWA",
35
+ "ES3",
36
+ "ES5",
37
+ "ES6",
38
+ "ES7",
39
+ "ES2015",
40
+ "ES2016",
41
+ "client",
42
+ "API"
43
+ ],
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://gitlab.com/twoBirds/microcomponents"
47
+ },
48
+ "contributors": [
49
+ {
50
+ "name": "Frank Thürigen",
51
+ "email": "fthuerigen@gmail.com"
52
+ }
53
+ ]
54
54
  }
package/public/MC.js CHANGED
@@ -1,15 +1,17 @@
1
- "use strict";
1
+ 'use strict';
2
2
  import { McEvent } from './McEvent.js';
3
- var isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
3
+ var isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
4
4
  let nativeEventNames = new Set();
5
5
  // HTMLElement native event names
6
6
  if (isBrowser()) {
7
- Object.keys(HTMLElement.prototype).filter(key => /^on/.test(key)).forEach(eventName => nativeEventNames.add(eventName));
7
+ Object.keys(HTMLElement.prototype)
8
+ .filter((key) => /^on/.test(key))
9
+ .forEach((eventName) => nativeEventNames.add(eventName));
8
10
  }
9
11
  // get all microcomponents from a list of HTMLElements
10
12
  function getMicroComponents(elements, search) {
11
13
  let mcValues = [];
12
- elements.forEach(e => {
14
+ elements.forEach((e) => {
13
15
  if (e) {
14
16
  if (e instanceof HTMLElement) {
15
17
  const _mc = e?._mc;
@@ -91,7 +93,9 @@ function remove(target, key) {
91
93
  delete _mc[key];
92
94
  }
93
95
  // remove the _mc attribute if the DOM collection is empty
94
- if (!Object.keys(_mc).length && target instanceof HTMLElement && target.hasAttribute('_mc')) {
96
+ if (!Object.keys(_mc).length &&
97
+ target instanceof HTMLElement &&
98
+ target.hasAttribute('_mc')) {
95
99
  target.removeAttribute('_mc');
96
100
  }
97
101
  return;
@@ -109,26 +113,25 @@ function trigger(target, ev, data = {}) {
109
113
  });
110
114
  return;
111
115
  }
112
- // run the "init" lifecycle event on the completemcr structure
116
+ // run the "init" lifecycle event on the complete _mc structure
113
117
  function init(element) {
114
118
  if (element.constructor === DC)
115
119
  return;
116
120
  setTimeout(() => {
117
121
  element.trigger('Init');
118
- setTimeout(() => {
119
- let keys = Object.keys(element?._mc);
120
- if (keys.length) {
122
+ /*
123
+ let keys = Object.keys( ( element as any)?._mc );
124
+ if ( keys.length ){
121
125
  //console.log( 'inner Inits on [', mc.constructor.name, ']', keys );
122
- keys?.forEach((key) => {
123
- let mc = element?._mc?.[key];
126
+ keys?.forEach( (key: string) => {
127
+ let mc = ( element as any)?._mc?.[key];
124
128
  //console.log( key, typeof mc?.oneInit, mc );
125
- if (mc['oneInit'] && typeof mc.oneInit == 'function') {
126
- mc.oneInit(new McEvent('Init'));
129
+ if ( ( mc as any )['oneInit'] && typeof ( mc as any ).oneInit == 'function' ){
130
+ ( mc as any ).oneInit( new McEvent('Init') );
127
131
  }
128
132
  });
129
- }
130
- ;
131
- }, 0);
133
+ };
134
+ */
132
135
  }, 0);
133
136
  }
134
137
  function autoAttachListeners(element) {
@@ -137,13 +140,14 @@ function autoAttachListeners(element) {
137
140
  const target = element.target;
138
141
  if (target instanceof HTMLElement) {
139
142
  let that = element;
140
- Object
141
- .getOwnPropertyNames(that.constructor.prototype)
142
- .filter(key => /^on[A-Z]|one[A-Z]/.test(key) && typeof that.constructor.prototype[key] === 'function')
143
- .forEach(key => {
143
+ Object.getOwnPropertyNames(that.constructor.prototype)
144
+ .filter((key) => /^on[A-Z]|one[A-Z]/.test(key) &&
145
+ typeof that.constructor.prototype[key] === 'function')
146
+ .forEach((key) => {
144
147
  let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), // preserves upper/lowercase for non-native events
145
- nativeEventName = withoutOnOne.toLowerCase(), listener = (ev) => { that.trigger(withoutOnOne, ev); };
146
- ;
148
+ nativeEventName = withoutOnOne.toLowerCase(), listener = (ev) => {
149
+ that.trigger(withoutOnOne, ev);
150
+ };
147
151
  if (once) {
148
152
  // console.log( '...is only called once', that.constructor.prototype[key] );
149
153
  Object.defineProperty(element, 'on' + withoutOnOne, {
@@ -152,11 +156,12 @@ function autoAttachListeners(element) {
152
156
  writable: true,
153
157
  value: (ev) => {
154
158
  // console.log( 'onceHandler execute:', that.constructor.prototype[key] );
155
- (that.constructor.prototype[key]).bind(that)(ev);
156
- }
159
+ that.constructor.prototype[key].bind(that)(ev);
160
+ },
157
161
  });
158
162
  }
159
- if (nativeEventNames.has('on' + nativeEventName)) { // native event defined in HTMLElement
163
+ if (nativeEventNames.has('on' + nativeEventName)) {
164
+ // native event defined in HTMLElement
160
165
  // console.log('added as native listener', target, nativeEventName );
161
166
  addListener(target, nativeEventName, listener, false, once);
162
167
  }
@@ -165,7 +170,7 @@ function autoAttachListeners(element) {
165
170
  }
166
171
  class McBase {
167
172
  #target; // avoid circular reference
168
- constructor(target) {
173
+ constructor(target, debug = false) {
169
174
  let that = this, element = that;
170
175
  this.#target = new WeakRef(target || {});
171
176
  init(element); // async lifecycle event
@@ -188,7 +193,8 @@ class MC extends McBase {
188
193
  // run all triggers
189
194
  if (that.constructor === MC || that.constructor === DC) {
190
195
  [...Object.getOwnPropertyNames(that)].forEach((mc) => {
191
- if (that[mc]?.trigger && typeof that[mc]?.trigger === 'function') {
196
+ if (that[mc]?.trigger &&
197
+ typeof that[mc]?.trigger === 'function') {
192
198
  that[mc]?.trigger(ev, data, bubble);
193
199
  }
194
200
  });
@@ -196,15 +202,17 @@ class MC extends McBase {
196
202
  }
197
203
  // only this instance
198
204
  if (that instanceof MC || that instanceof DC) {
199
- const that = this, mcEvent = typeof ev !== 'string' ? ev : new McEvent(ev, data, bubble), handlerName = 'on' + mcEvent.type[0].toUpperCase() + mcEvent.type.slice(1);
200
- ;
205
+ const that = this, mcEvent = typeof ev !== 'string'
206
+ ? ev
207
+ : new McEvent(ev, data, bubble), handlerName = 'on' + mcEvent.type[0].toUpperCase() + mcEvent.type.slice(1);
201
208
  // console.log('trigger', handlerName, mcEvent, data, bubble );
202
209
  if (mcEvent.bubble.indexOf('l') > -1) {
203
- if (!mcEvent.immediateStopped
204
- && typeof that[handlerName] === 'function') {
210
+ if (!mcEvent.immediateStopped &&
211
+ typeof that[handlerName] === 'function') {
205
212
  // console.log( 'execute handler:', handlerName );
206
213
  that[handlerName](mcEvent);
207
- if (that.hasOwnProperty(handlerName)) { // it is a once handler
214
+ if (that.hasOwnProperty(handlerName)) {
215
+ // it is a once handler
208
216
  delete that[handlerName]; // remove after first execution
209
217
  }
210
218
  }
@@ -215,7 +223,9 @@ class MC extends McBase {
215
223
  }
216
224
  // at this point, either 'u' or 'd' bubbling should be indicated
217
225
  // mcEvent bubbling is asynchronous, and the order of target MC execution in case of multiple matches is not guaranteed!
218
- if (isBrowser() && /[ud]/.test(mcEvent.bubble) && that instanceof MC) {
226
+ if (isBrowser() &&
227
+ /[ud]/.test(mcEvent.bubble) &&
228
+ that instanceof MC) {
219
229
  setTimeout(() => {
220
230
  // bubbling must include 'l' for local, or else no handlers are executed'
221
231
  if (mcEvent.bubble.indexOf('l') === -1) {
@@ -223,17 +233,13 @@ class MC extends McBase {
223
233
  }
224
234
  // bubble up towards root
225
235
  if (mcEvent.bubble.indexOf('u') > -1) {
226
- that
227
- .parent()
228
- .forEach((mc) => {
236
+ that.parent().forEach((mc) => {
229
237
  mc instanceof MC ? mc.trigger(mcEvent) : null;
230
238
  });
231
239
  }
232
240
  // bubble down
233
241
  if (mcEvent.bubble.indexOf('d') > -1) {
234
- that
235
- .children()
236
- .forEach((mc) => {
242
+ that.children().forEach((mc) => {
237
243
  mc instanceof MC ? mc.trigger(mcEvent) : null;
238
244
  });
239
245
  }
@@ -242,20 +248,17 @@ class MC extends McBase {
242
248
  }
243
249
  }
244
250
  }
245
- ;
246
251
  class DC extends McBase {
247
252
  _mc = {};
248
- constructor(target) {
253
+ constructor(target, debug = false) {
249
254
  super(target);
250
255
  }
251
- static debug = false;
252
256
  static add = add;
253
257
  static remove = remove;
254
258
  static trigger = trigger;
255
259
  trigger(ev, data = {}, bubble) {
256
260
  MC.prototype.trigger.call(this, ev, data, bubble);
257
261
  }
258
- ;
259
262
  parent(search = '') {
260
263
  let target = this.target;
261
264
  if (!isDOM(target))
@@ -288,6 +291,5 @@ class DC extends McBase {
288
291
  return getMicroComponents([...myDomElements], search);
289
292
  }
290
293
  }
291
- ;
292
294
  export { addListener, removeListener, McBase, MC, DC, McEvent };
293
295
  //# sourceMappingURL=MC.js.map