@twobirds/microcomponents 0.0.34 → 0.0.39

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 (120) 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/assets/my-tag.css +6 -2
  7. package/dist/MC.d.ts +3 -4
  8. package/dist/MC.d.ts.map +1 -1
  9. package/dist/MC.min.js +89 -66
  10. package/dist/MC.ts +213 -178
  11. package/dist/autoloader.ts +1 -1
  12. package/dist/{customElements.d.ts → elements.d.ts} +1 -1
  13. package/dist/elements.d.ts.map +1 -0
  14. package/dist/elements.min.js +1 -0
  15. package/dist/{customElements.ts → elements.ts} +23 -14
  16. package/dist/helpers.d.ts +6 -4
  17. package/dist/helpers.d.ts.map +1 -1
  18. package/dist/helpers.ts +95 -128
  19. package/dist/microcomponents.d.ts +3 -3
  20. package/dist/microcomponents.d.ts.map +1 -1
  21. package/dist/microcomponents.min.js +1 -1
  22. package/dist/microcomponents.ts +3 -3
  23. package/dist/{customObservables.d.ts → observables.d.ts} +3 -3
  24. package/dist/observables.d.ts.map +1 -0
  25. package/dist/observables.min.js +1 -0
  26. package/dist/observables.ts +353 -0
  27. package/dist/{customSelectors.d.ts → selectors.d.ts} +1 -1
  28. package/dist/selectors.d.ts.map +1 -0
  29. package/dist/selectors.min.js +1 -0
  30. package/dist/test.ts +135 -156
  31. package/klemmstein.png +0 -0
  32. package/package.json +52 -52
  33. package/public/MC.js +90 -67
  34. package/public/MC.js.map +1 -1
  35. package/public/MC.min.js +89 -66
  36. package/public/assets/search.js +1 -1
  37. package/public/autoloader.js +1 -1
  38. package/public/autoloader.js.map +1 -1
  39. package/public/classes/{DC.html → MC.DC.html} +60 -59
  40. package/public/classes/{MC.html → MC.MC.html} +41 -35
  41. package/public/classes/{McBase.html → MC.McBase.html} +28 -20
  42. package/public/classes/{McEvent.html → MC.McEvent.html} +48 -42
  43. package/public/documentation/{MicroComponents.md → MC.md} +17 -17
  44. package/public/documentation/comparision.md +0 -0
  45. package/public/documentation/elements.md +276 -0
  46. package/public/documentation/magic.md +10 -68
  47. package/public/{customElements.js → elements.js} +9 -10
  48. package/public/elements.js.map +1 -0
  49. package/public/elements.min.js +1 -0
  50. package/public/functions/{addListener.html → MC.addListener.html} +18 -12
  51. package/public/functions/{removeListener.html → MC.removeListener.html} +18 -12
  52. package/public/functions/elements.defineCE.html +78 -0
  53. package/public/functions/elements.getCE.html +63 -0
  54. package/public/functions/formValues.formValues.html +68 -0
  55. package/public/functions/observables.observe.html +65 -0
  56. package/public/functions/selectors._d.html +69 -0
  57. package/public/functions/selectors._t.html +69 -0
  58. package/public/helpers.js +66 -89
  59. package/public/helpers.js.map +1 -1
  60. package/public/index.html +48 -33
  61. package/public/interfaces/{HTMLMcElement.html → MC.HTMLMcElement.html} +601 -595
  62. package/public/interfaces/selectors.DSelector.html +1013 -0
  63. package/public/interfaces/selectors.TSelector.html +712 -0
  64. package/public/microcomponents.js +3 -3
  65. package/public/microcomponents.js.map +1 -1
  66. package/public/microcomponents.min.js +1 -1
  67. package/public/modules/MC.html +78 -0
  68. package/public/modules/elements.html +62 -0
  69. package/public/modules/formValues.html +60 -0
  70. package/public/modules/observables.html +65 -0
  71. package/public/modules/selectors.html +76 -0
  72. package/public/modules.html +11 -23
  73. package/public/my-tag.css +6 -2
  74. package/public/observables.js +259 -0
  75. package/public/observables.js.map +1 -0
  76. package/public/observables.min.js +1 -0
  77. package/public/{customSelectors.js → selectors.js} +1 -1
  78. package/public/selectors.js.map +1 -0
  79. package/public/selectors.min.js +1 -0
  80. package/public/src/MC.ts +413 -0
  81. package/public/src/McEvent.ts +96 -0
  82. package/public/src/autoloader.ts +98 -0
  83. package/{src/customElements.ts → public/src/elements.ts} +23 -14
  84. package/public/src/formValues.ts +275 -0
  85. package/public/src/helpers.ts +140 -0
  86. package/public/src/microcomponents.ts +8 -0
  87. package/public/src/observables.ts +353 -0
  88. package/public/src/test.ts +190 -0
  89. package/public/test.js +93 -118
  90. package/public/test.js.map +1 -1
  91. package/public/types/observables.Observable.html +91 -0
  92. package/public/types/selectors.selection.html +58 -0
  93. package/public/types/selectors.singleSelector.html +58 -0
  94. package/src/MC.ts +213 -178
  95. package/src/autoloader.ts +1 -1
  96. package/src/elements.ts +76 -0
  97. package/src/helpers.ts +95 -128
  98. package/src/microcomponents.ts +3 -3
  99. package/src/observables.ts +353 -0
  100. package/src/selectors.ts +1634 -0
  101. package/src/test.ts +135 -156
  102. package/typedoc.json +1 -1
  103. package/webpack.config.js +9 -9
  104. package/dist/customElements.d.ts.map +0 -1
  105. package/dist/customElements.min.js +0 -1
  106. package/dist/customObservables.d.ts.map +0 -1
  107. package/dist/customObservables.min.js +0 -1
  108. package/dist/customObservables.ts +0 -348
  109. package/dist/customSelectors.d.ts.map +0 -1
  110. package/dist/customSelectors.min.js +0 -1
  111. package/public/customElements.js.map +0 -1
  112. package/public/customElements.min.js +0 -1
  113. package/public/customObservables.js +0 -256
  114. package/public/customObservables.js.map +0 -1
  115. package/public/customObservables.min.js +0 -1
  116. package/public/customSelectors.js.map +0 -1
  117. package/public/customSelectors.min.js +0 -1
  118. package/src/customObservables.ts +0 -348
  119. /package/dist/{customSelectors.ts → selectors.ts} +0 -0
  120. /package/{src/customSelectors.ts → public/src/selectors.ts} +0 -0
package/dist/test.ts CHANGED
@@ -1,211 +1,190 @@
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
+ LooseObject,
5
+ MC,
6
+ DC,
7
+ McEvent,
8
+ defineCE,
9
+ getCE,
10
+ observe,
11
+ Observable,
12
+ } from './microcomponents.js';
13
+
14
+ //import { MC, DC, McEvent } from "./MC.js";
15
+ //import { defineCE, getCE } from "./elements.js";
16
+ //import { observe } from "./observables.js";
8
17
 
9
18
  //MC.debug = true;
10
19
 
11
- class Adder {
12
- constructor() {}
13
-
14
- sum(...numbers: number[]): number {
15
- return numbers.reduce((acc: number, curr: number) => acc + curr, 0);
16
- }
17
- }
20
+ class Translator extends DC {
21
+ #translations: LooseObject = {};
18
22
 
19
- class DeeplyNestedEvTarget extends MC {
20
- constructor(target: any) {
21
- super(target);
22
- }
23
+ Language: unknown = 'en';
24
+ Translation: unknown = {};
23
25
 
24
- oneInit(ev: typeof McEvent) {
25
- let logger = this.target?.target?.target?._mc?.logger;
26
- //logger?.warn("DeeplyNestedEvTarget .oneInit(ev)", ev);
27
- }
28
- }
26
+ constructor(
27
+ target: HTMLElement | ShadowRoot | DocumentFragment,
28
+ translations: LooseObject,
29
+ translationTargetObject: HTMLElement
30
+ ) {
31
+ super(target as HTMLElement);
32
+ let that = this; // minifier help
29
33
 
30
- class EvTarget extends MC {
31
- constructor(target: any) {
32
- super(target);
33
- }
34
+ // state
35
+ that.Language = 'en';
36
+ that.Translation = {};
34
37
 
35
- onCustomEvent(ev: typeof McEvent) {
36
- let logger = this.target?.target?._mc?.logger;
37
- logger?.log("onCustomEvent", ev);
38
- }
38
+ observe(that);
39
39
 
40
- oneInit(ev: typeof McEvent) {
41
- let that = this,
42
- _mc = that._mc!,
43
- logger = this.target?.target?._mc?.logger;
40
+ // setup
41
+ that.#translations = translations;
44
42
 
45
- //logger?.warn("EvTarget .oneInit(ev)", ev);
43
+ // state
44
+ (that.Language as Observable).observe((lang) => {
45
+ if (that.#translations.hasOwnProperty(lang)) {
46
+ that.Translation = { lang: that.#translations[lang] }; // set translation
47
+ }
48
+ });
46
49
 
47
- _mc.deeplyNestedEvTarget = new DeeplyNestedEvTarget( that );
48
- }
49
- }
50
+ (that.Translation as Observable).bind(translationTargetObject);
50
51
 
51
- class Logger extends DC {
52
+ this.target.setAttribute('language', 'en');
52
53
 
53
- prefix: string = "";
54
-
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;
54
+ (this.Language as Observable).notify();
67
55
  }
68
56
 
69
- log() {
70
- this.stdOut.log(this.prefix, this.target.constructor.name, ...arguments);
57
+ oneInit() {
58
+ //(this.Language as Observable).notify(); // trigger translation
71
59
  }
72
60
 
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);
61
+ onAttributeChanged(ev: McEvent) {
62
+ if (!ev.data.newValue) return;
63
+
64
+ let that = this;
65
+
66
+ switch (ev.data.name) {
67
+ case 'language':
68
+ that.Language = ev.data.newValue;
69
+ break;
70
+ }
78
71
  }
79
72
  }
80
73
 
81
74
  defineCE(
82
75
  // equivalent to custom element registry .define()
83
- "my-tag",
76
+ 'my-tag',
84
77
  class MyTag extends DC {
78
+ #template: string = '<button>{lang.click} {counter}</button>';
85
79
 
86
- In: string = "";
80
+ #languages = {
81
+ en: {
82
+ click: 'click me',
83
+ },
84
+ de: {
85
+ click: 'klick mich',
86
+ },
87
+ };
87
88
 
88
- Counter: number = 0;
89
+ Dom: LooseObject = {};
89
90
 
90
- constructor(target: HTMLElement, data: string) {
91
+ constructor(target: HTMLElement) {
91
92
  super(target);
92
93
 
93
94
  let that = this; // minifier help
94
95
 
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]"));
96
+ // hide
97
+ target.setAttribute('style', 'display:none');
103
98
 
104
99
  // render
105
- target.innerHTML = "Click Me";
106
- }
107
-
108
- /*
109
- web component specific event handlers
110
- */
111
-
112
- onConnected(ev: typeof McEvent) {
113
- //this.target._mc?.logger.info("onConnected handler", ev);
100
+ target.innerHTML = this.#template;
101
+
102
+ // add public translator
103
+ DC.add(
104
+ target,
105
+ 'translator',
106
+ new Translator(target, that.#languages, target)
107
+ );
114
108
  }
115
109
 
116
- onAttributeChanged(ev: typeof McEvent) {
117
- let logger = this.target._mc?.logger;
118
- //logger?.info("onAttributeChanged handler", ev);
119
- }
110
+ oneInit(ev: McEvent) {
111
+ let that = this;
120
112
 
121
- /*
122
- native event handlers
123
- */
124
- oneClick(ev: typeof McEvent) {
125
- let logger = this.target._mc?.logger;
113
+ // state
114
+ that.Dom = { counter: 0 };
126
115
 
127
- logger.info("oneClick handler", ev);
116
+ // state: convert all props defined so far into observables
117
+ observe(that);
128
118
 
129
- this._mc.customEventTarget.trigger("customEvent");
119
+ // bind Dom to target
120
+ (that.Dom as Observable).bind(that.target);
130
121
 
131
- this.target.setAttribute("my-attribute", "testValue");
122
+ // show
123
+ setTimeout(() => that.target.removeAttribute('style'), 100);
132
124
  }
133
125
 
134
- onClick(ev: typeof McEvent) {
135
- let logger = this.target._mc?.logger;
136
-
137
- logger?.info("onClick handler", ev);
138
-
139
- this.Counter++;
126
+ onAttributeChanged(ev: McEvent) {
127
+ //console.log(ev);
128
+ this.target._mc.translator.Language = ev.data.newValue;
140
129
  }
141
130
 
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);
131
+ onClick(ev: McEvent) {
132
+ this.Dom.counter++;
133
+ (this.target as HTMLElement).classList.add('clicked');
170
134
  }
171
135
  },
172
- ["my-attribute"]
136
+ ['language']
173
137
  );
174
138
 
175
- let MyTag: CustomElementConstructor = getCE("my-tag")!,
139
+ let MyTag: CustomElementConstructor = getCE('my-tag')!,
176
140
  fragment = new DocumentFragment();
177
141
 
178
- // stress test
179
- console.time("Instancing");
180
- // create 1000 elements
181
- for ( let x = 0; x < 1000; x ++ ){
182
- fragment.append( new MyTag("my-data") );
142
+ /*
143
+ stress test
144
+ */
145
+
146
+ let start = new Date().getTime();
147
+
148
+ // create 100 elements
149
+ for (let x = 0; x < 100; x++) {
150
+ fragment.append(new MyTag());
183
151
  }
184
- document.body.appendChild( fragment );
185
152
 
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");
153
+ let end = new Date().getTime();
192
154
 
193
- document.querySelectorAll('my-tag').forEach( (e) => e.remove() );
155
+ // and put them into the DOM
156
+ document.body.appendChild(fragment);
194
157
 
195
- // and put them into thwe DOM
158
+ //document.querySelectorAll('my-tag').forEach((e) => e.remove());
196
159
 
197
- document.body.appendChild( new MyTag("my-data") );
160
+ /*
161
+ console test
162
+ */
198
163
 
199
- let element = document.querySelector("my-tag");
164
+ setTimeout(() => {
165
+ console.clear();
200
166
 
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
- );
167
+ console.log(
168
+ '%c \n\nStress Test:\n\n %cInstancing 100 web components: %c %s ms.',
169
+ 'font-weight: bold; color: black;',
170
+ 'font-weight: normal;',
171
+ 'font-weight: bold; color: blue;',
172
+ end - start
173
+ );
174
+
175
+ document.body.appendChild(new MyTag());
176
+
177
+ let element = document.querySelector('my-tag');
178
+
179
+ console.log(
180
+ "\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
181
+ 'font-weight: bold;',
182
+ 'font-weight: normal;',
183
+ element,
184
+ 'font-weight: bold;',
185
+ '\n\nLook up code in the debugger: test.js\n\n'
186
+ );
209
187
 
210
- // will trigger the event on all micro components contained in <my-tag>
211
- DC.trigger(element, "doSomething");
188
+ // will trigger the event on all micro components contained in <my-tag>
189
+ DC.trigger(element, 'doSomething');
190
+ }, 500);
package/klemmstein.png ADDED
Binary file
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
1
  {
2
- "name": "@twobirds/microcomponents",
3
- "version": "0.0.34",
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.39",
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
  }