@twobirds/microcomponents 0.0.48 → 0.0.51

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 (130) hide show
  1. package/assets/Grandparent.css +13 -0
  2. package/assets/documentation/MC.md +380 -166
  3. package/assets/test.html +5 -1
  4. package/dist/MC.d.ts +1 -0
  5. package/dist/MC.d.ts.map +1 -1
  6. package/dist/MC.min.js +44 -0
  7. package/dist/MC.ts +65 -0
  8. package/dist/elements.min.js +1 -1
  9. package/dist/elements.ts +10 -10
  10. package/dist/formValues.d.ts +3 -2
  11. package/dist/formValues.d.ts.map +1 -1
  12. package/dist/formValues.ts +205 -203
  13. package/dist/formvValues.min.js +1 -1
  14. package/dist/helpers.d.ts +1 -0
  15. package/dist/helpers.d.ts.map +1 -1
  16. package/dist/helpers.ts +9 -0
  17. package/dist/microcomponents.min.js +1 -1
  18. package/dist/observables.d.ts +1 -1
  19. package/dist/observables.d.ts.map +1 -1
  20. package/dist/observables.min.js +1 -1
  21. package/dist/observables.ts +64 -31
  22. package/dist/selectors.min.js +1 -1
  23. package/dist/test.ts +8 -5
  24. package/package.json +1 -1
  25. package/public/assets/search.js +1 -1
  26. package/public/classes/MC.DC.html +13 -13
  27. package/public/classes/MC.MC.html +7 -7
  28. package/public/classes/MC.McBase.html +4 -4
  29. package/public/classes/MC.McEvent.html +13 -13
  30. package/public/classes/formValues.FormValues.html +86 -0
  31. package/public/functions/MC.addListener.html +2 -1
  32. package/public/functions/{formValues.formValues.html → MC.autoload.html} +18 -17
  33. package/public/functions/MC.removeListener.html +2 -1
  34. package/public/functions/elements.defineCE.html +1 -1
  35. package/public/functions/elements.getCE.html +1 -1
  36. package/public/functions/observables.observe.html +3 -3
  37. package/public/functions/selectors._d.html +1 -1
  38. package/public/functions/selectors._t.html +1 -1
  39. package/public/interfaces/MC.HTMLMcElement.html +2 -2
  40. package/public/interfaces/selectors.DSelector.html +55 -55
  41. package/public/interfaces/selectors.TSelector.html +37 -37
  42. package/public/modules/MC.html +3 -1
  43. package/public/modules/elements.html +1 -1
  44. package/public/modules/formValues.html +4 -4
  45. package/public/modules/observables.html +1 -1
  46. package/public/modules/selectors.html +1 -1
  47. package/public/types/observables.Observable.html +1 -1
  48. package/public/types/selectors.selection.html +1 -1
  49. package/public/types/selectors.singleSelector.html +1 -1
  50. package/src/MC.ts +65 -0
  51. package/src/elements.ts +10 -10
  52. package/src/formValues.ts +205 -203
  53. package/src/helpers.ts +9 -0
  54. package/src/observables.ts +64 -31
  55. package/src/test/Child.ts +21 -0
  56. package/src/test/Grandchild.ts +21 -0
  57. package/src/test/Grandparent.css +11 -0
  58. package/src/test/Grandparent.ts +21 -0
  59. package/src/test/Greatgrandchild.ts +42 -0
  60. package/src/test/Parent.ts +21 -0
  61. package/src/test/Testform.css +47 -0
  62. package/src/test/Testform.html +56 -0
  63. package/src/test/Testform.json +27 -0
  64. package/src/test/Testform.ts +159 -0
  65. package/src/test.ts +8 -5
  66. package/webpack.config.js +135 -61
  67. package/public/3d.html +0 -42
  68. package/public/MC.js +0 -271
  69. package/public/MC.js.map +0 -1
  70. package/public/MC.min.js +0 -407
  71. package/public/McEvent.js +0 -71
  72. package/public/McEvent.js.map +0 -1
  73. package/public/MicroComponents.svg +0 -15
  74. package/public/autoloader.js +0 -53
  75. package/public/autoloader.js.map +0 -1
  76. package/public/documentation/MC.md +0 -256
  77. package/public/documentation/ajaxian-1.png +0 -0
  78. package/public/documentation/ajaxian-2.png +0 -0
  79. package/public/documentation/ajaxian-3.png +0 -0
  80. package/public/documentation/comparision.md +0 -0
  81. package/public/documentation/elements.md +0 -276
  82. package/public/documentation/functional_requirements.md +0 -8
  83. package/public/documentation/history.md +0 -436
  84. package/public/documentation/how_tos.md +0 -0
  85. package/public/documentation/introduction.md +0 -0
  86. package/public/documentation/magic.md +0 -29
  87. package/public/documentation/proposal_draft.md +0 -37
  88. package/public/documentation/rnd0023-1.jpg +0 -0
  89. package/public/documentation/rnd0023-2.jpg +0 -0
  90. package/public/documentation/rnd0023-3.jpg +0 -0
  91. package/public/documentation/tB_react.md +0 -207
  92. package/public/documentation/usage.md +0 -142
  93. package/public/documentation/why.md +0 -25
  94. package/public/elements.js +0 -48
  95. package/public/elements.js.map +0 -1
  96. package/public/elements.min.js +0 -1
  97. package/public/fiddle/MicroComponents.svg +0 -15
  98. package/public/fiddle/fiddle.css +0 -0
  99. package/public/fiddle/fiddle.js +0 -0
  100. package/public/fiddle/index.html +0 -0
  101. package/public/formValues.js +0 -196
  102. package/public/formValues.js.map +0 -1
  103. package/public/formvValues.min.js +0 -1
  104. package/public/helpers.js +0 -105
  105. package/public/helpers.js.map +0 -1
  106. package/public/microcomponents.es3.js +0 -303
  107. package/public/microcomponents.es3.js.map +0 -1
  108. package/public/microcomponents.js +0 -9
  109. package/public/microcomponents.js.map +0 -1
  110. package/public/microcomponents.min.js +0 -1
  111. package/public/my-tag.css +0 -19
  112. package/public/observables.js +0 -239
  113. package/public/observables.js.map +0 -1
  114. package/public/observables.min.js +0 -1
  115. package/public/selectors.js +0 -971
  116. package/public/selectors.js.map +0 -1
  117. package/public/selectors.min.js +0 -1
  118. package/public/src/MC.ts +0 -413
  119. package/public/src/McEvent.ts +0 -96
  120. package/public/src/autoloader.ts +0 -98
  121. package/public/src/elements.ts +0 -76
  122. package/public/src/formValues.ts +0 -275
  123. package/public/src/helpers.ts +0 -140
  124. package/public/src/microcomponents.ts +0 -8
  125. package/public/src/observables.ts +0 -372
  126. package/public/src/selectors.ts +0 -1634
  127. package/public/src/test.ts +0 -174
  128. package/public/test.html +0 -23
  129. package/public/test.js +0 -79
  130. package/public/test.js.map +0 -1
@@ -2,11 +2,10 @@
2
2
 
3
3
  import {
4
4
  LooseObject,
5
- parse,
6
5
  debounce,
7
6
  deepEqual,
8
- nameSpace,
9
7
  flattenObject,
8
+ copyGettersSetters,
10
9
  } from './helpers.js';
11
10
 
12
11
  import { DC, HTMLMcElement, McEvent } from './MC.js';
@@ -79,7 +78,7 @@ class Placeholders extends DC {
79
78
  target = that.target,
80
79
  hide: boolean = false;
81
80
 
82
- // console.log('attachCallbacks', that.target);
81
+ //console.log('attachCallbacks', that.target);
83
82
 
84
83
  // scan attributes
85
84
  target
@@ -126,6 +125,7 @@ class Placeholders extends DC {
126
125
  that.data.observe(
127
126
  ((template: string) => (data: LooseObject) => {
128
127
  let result: string = template;
128
+ //console.log('text node "', template, '" callbach data:', data);
129
129
  phs.forEach((placeholder) => {
130
130
  result = result.replace(
131
131
  placeholder,
@@ -150,7 +150,11 @@ class Placeholders extends DC {
150
150
 
151
151
  // hide for now
152
152
  that.oldDisplay = target.getAttribute('style)') || '';
153
- if (hide && !inputs.includes((target as any).constructor)) {
153
+ if (
154
+ hide &&
155
+ !inputs.includes((target as any).constructor) &&
156
+ target.tagName !== 'FIELDSET'
157
+ ) {
154
158
  target.style.display = 'none';
155
159
  }
156
160
  });
@@ -162,7 +166,7 @@ class Placeholders extends DC {
162
166
  Object.keys(ev.data).forEach((key) => {
163
167
  if (that.data.hasOwnProperty(key)) data[key] = ev.data[key];
164
168
  });
165
- // console.log('onData()', ev, data, that.data);
169
+ //console.log('onData()', ev, data, that.data);
166
170
  if (JSON.stringify(data) !== JSON.stringify(that.data))
167
171
  Object.assign(that.data, data); // will trigger callbacks
168
172
  }
@@ -175,13 +179,16 @@ function getPlaceholderElements(
175
179
  target instanceof HTMLElement ? [target] : []
176
180
  )
177
181
  .concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
178
- .filter((e) => !!getPlaceholders(e as HTMLElement).length);
182
+ .filter((e) => !!getPlaceholders(e as HTMLElement).length)
183
+ .filter((e) => e.tagName !== 'STYLE');
184
+ //console.log('getPlaceholderElements', elements);
179
185
  return elements as HTMLElement[];
180
186
  }
181
187
 
182
- function makePlaceHolders(
188
+ function makePlaceholders(
183
189
  element: HTMLElement | DocumentFragment | ShadowRoot
184
190
  ): void {
191
+ //console.log('makePlaceholders', element);
185
192
  getPlaceholderElements(element).forEach((e: HTMLElement) => {
186
193
  if ((e as HTMLMcElement)?._mc?._placeholders) return;
187
194
  DC.add(e, '_placeholders', new Placeholders(e));
@@ -194,14 +201,17 @@ export type Observable = {
194
201
  bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
195
202
  };
196
203
 
197
- export const observe = (target: LooseObject, propertyName?: string) => {
204
+ export const observe = (
205
+ target: LooseObject,
206
+ propertyName?: string
207
+ ): LooseObject => {
198
208
  let keys = !propertyName
199
209
  ? [...Object.getOwnPropertyNames(target)]
200
210
  : [propertyName];
201
211
 
202
212
  keys.forEach((key) => {
203
213
  // console.log( 'co propname', key, typeof target[key], target[key] );
204
- if (key[0] === '_' || target?.[key] === undefined) return;
214
+ if (key[0] === '_' || target?.[key] === undefined) return target;
205
215
  let val: any = target[key],
206
216
  Constructor: any;
207
217
 
@@ -229,6 +239,8 @@ export const observe = (target: LooseObject, propertyName?: string) => {
229
239
  }
230
240
 
231
241
  let Observable = class extends Constructor {
242
+ #notify: boolean = true;
243
+
232
244
  constructor(val: any) {
233
245
  super(val);
234
246
  (this.constructor as LooseObject).callbacks = [];
@@ -252,16 +264,22 @@ export const observe = (target: LooseObject, propertyName?: string) => {
252
264
  //console.log('bind', iso, target);
253
265
 
254
266
  if (iso) {
255
- makePlaceHolders(target);
256
- (this.constructor as any).callbacks.push((data: LooseObject) => {
267
+ makePlaceholders(target);
268
+ const placeholders: unknown = [
269
+ ...target.querySelectorAll('[_mc]'),
270
+ ].filter((e) => !!(e as LooseObject)?._mc?._placeholders);
271
+ //console.log('placeholders:', target, placeholders);
272
+ const func = function callback(data: LooseObject) {
257
273
  // avoid bubbling for speed
258
- new DC(target as HTMLMcElement)
259
- .descendants('_placeholders')
260
- .forEach((e) => {
261
- if (!e) return;
262
- e.trigger('data', flattenObject(data));
263
- });
264
- });
274
+ let d = flattenObject(data);
275
+ //console.log('inside callback', target, d);
276
+ (placeholders as DC[]).forEach((e) => {
277
+ // console.log('trigger callback', e);
278
+ if (!e) return;
279
+ (e as any)._mc.trigger('data', d);
280
+ });
281
+ };
282
+ (that.constructor as any).callbacks.push(func);
265
283
  that.notify();
266
284
  } else {
267
285
  console.warn(
@@ -274,22 +292,34 @@ export const observe = (target: LooseObject, propertyName?: string) => {
274
292
  return this;
275
293
  }
276
294
 
277
- notify() {
295
+ notify(notify?: boolean) {
278
296
  let that = this,
279
297
  data =
280
298
  isObservableObject(that.valueOf()) &&
281
299
  that.valueOf() instanceof Array === false
282
300
  ? structuredClone(Object.assign({}, that))
283
301
  : that.valueOf();
302
+
303
+ if (notify !== undefined) {
304
+ that.#notify = notify;
305
+ // return;
306
+ }
307
+
308
+ //if (that.#notify) console.log('notify', this, data);
284
309
  (that.constructor as any).callbacks.forEach((f: Function) => {
285
- // console.log( 'callback', f, data);
310
+ // console.log(
311
+ // (this.constructor as any).callbacks,
312
+ // 'notify: exec callback',
313
+ // f,
314
+ // data
315
+ // );
286
316
  f(data);
287
317
  });
288
- return this;
318
+
319
+ return that;
289
320
  }
290
321
  };
291
322
 
292
- //(Observable.constructor as LooseObject).callbacks = [];
293
323
  let o = new Observable(val);
294
324
 
295
325
  Object.defineProperty(target, key, {
@@ -317,20 +347,21 @@ export const observe = (target: LooseObject, propertyName?: string) => {
317
347
  let iso =
318
348
  isObservableObject(o.valueOf()) &&
319
349
  o.valueOf() instanceof Array === false;
320
- //let iso = o.constructor.prototype.__proto__.constructor === Object;
321
350
  //console.log('target iso:', iso);
322
351
  if (iso) {
323
352
  let old = structuredClone(Object.assign({}, o));
324
- val = structuredClone(Object.assign({}, val));
353
+ //val = structuredClone(Object.assign({}, val));
325
354
 
326
- let hasFormHandler =
327
- (o.constructor as LooseObject)?.hasFormHandler ?? false,
328
- callbacks = (o.constructor as LooseObject).callbacks;
329
- o = new Observable(structuredClone(Object.assign({}, val)));
355
+ //let callbacks = (o.constructor as LooseObject).callbacks;
356
+ if (o instanceof Observable === false) {
357
+ o = new Observable(structuredClone(Object.assign({}, val)));
358
+ copyGettersSetters(val, o);
359
+ o.seal();
360
+ }
361
+ Object.assign(o, val);
330
362
 
331
- //console.log('after set o=', o, 'check', old);
332
- (o.constructor as LooseObject).callbacks = hasFormHandler;
333
- (o.constructor as LooseObject).callbacks = callbacks;
363
+ // console.log('after set o=', o, 'check', old);
364
+ // (o.constructor as LooseObject).callbacks = callbacks;
334
365
 
335
366
  setTimeout(
336
367
  // check for changes
@@ -369,4 +400,6 @@ export const observe = (target: LooseObject, propertyName?: string) => {
369
400
  // replace old property with proxy (observable)
370
401
  target[key] = val;
371
402
  });
403
+
404
+ return target;
372
405
  };
@@ -0,0 +1,21 @@
1
+ import { DC, defineCE, getCE } from '.././microcomponents.js';
2
+ import { TestGrandchild } from './Grandchild.js';
3
+ defineCE(
4
+ 'test-child',
5
+
6
+ class TestChild extends DC {
7
+ constructor(target: HTMLElement) {
8
+ super(target);
9
+ }
10
+
11
+ onConnected() {
12
+ let that = this;
13
+
14
+ for (let x = 0; x < 10; x++) {
15
+ that.target.append(new TestGrandchild!());
16
+ }
17
+ }
18
+ }
19
+ );
20
+
21
+ export const TestChild = getCE('test-child');
@@ -0,0 +1,21 @@
1
+ import { DC, defineCE, getCE } from '.././microcomponents.js';
2
+ import { TestGreatgrandchild } from './Greatgrandchild.js';
3
+ defineCE(
4
+ 'test-grandchild',
5
+
6
+ class TestGrandchild extends DC {
7
+ constructor(target: HTMLElement) {
8
+ super(target);
9
+ }
10
+
11
+ onConnected() {
12
+ let that = this;
13
+
14
+ for (let x = 0; x < 2; x++) {
15
+ that.target.append(new TestGreatgrandchild!());
16
+ }
17
+ }
18
+ }
19
+ );
20
+
21
+ export const TestGrandchild = getCE('test-grandchild');
@@ -0,0 +1,11 @@
1
+ test-grandparent,
2
+ test-parent,
3
+ test-child,
4
+ test-grandchild,
5
+ test-greatgrandchild {
6
+ display: inline-block;
7
+ padding: 1px;
8
+ margin: 1px;
9
+ border: 1px solid darkslategray;
10
+ border-radius: 2px;
11
+ }
@@ -0,0 +1,21 @@
1
+ import { DC, defineCE, getCE } from '.././microcomponents.js';
2
+ import { TestParent } from './Parent.js';
3
+ defineCE(
4
+ 'test-grandparent',
5
+
6
+ class TestGrandparent extends DC {
7
+ constructor(target: HTMLElement) {
8
+ super(target);
9
+ }
10
+
11
+ onConnected() {
12
+ let that = this;
13
+
14
+ for (let x = 0; x < 5; x++) {
15
+ that.target.append(new TestParent!());
16
+ }
17
+ }
18
+ }
19
+ );
20
+
21
+ export const TestGrandparent = getCE('test-grandparent');
@@ -0,0 +1,42 @@
1
+ import { DC, defineCE, getCE } from '.././microcomponents.js';
2
+
3
+ function random(min: number, max: number) {
4
+ var random = Math.floor(Math.random() * (max - min + 1) + min);
5
+ return random;
6
+ }
7
+
8
+ defineCE(
9
+ 'test-greatgrandchild',
10
+
11
+ class TestGreatgrandchild extends DC {
12
+ constructor(target: HTMLElement) {
13
+ super(target);
14
+ }
15
+
16
+ onConnected() {
17
+ let that = this;
18
+
19
+ that.updateStyle();
20
+ }
21
+
22
+ updateStyle() {
23
+ var that = this;
24
+
25
+ function randomBorderColor() {
26
+ return (
27
+ 'rgb(' +
28
+ random(0, 255) +
29
+ ',' +
30
+ random(0, 255) +
31
+ ',' +
32
+ random(0, 255) +
33
+ ')'
34
+ );
35
+ }
36
+
37
+ that.target.setAttribute('style', 'border-color:' + randomBorderColor());
38
+ }
39
+ }
40
+ );
41
+
42
+ export const TestGreatgrandchild = getCE('test-greatgrandchild');
@@ -0,0 +1,21 @@
1
+ import { DC, defineCE, getCE } from '.././microcomponents.js';
2
+ import { TestChild } from './Child.js';
3
+ defineCE(
4
+ 'test-parent',
5
+
6
+ class TestParent extends DC {
7
+ constructor(target: HTMLElement) {
8
+ super(target);
9
+ }
10
+
11
+ onConnected() {
12
+ let that = this;
13
+
14
+ for (let x = 0; x < 5; x++) {
15
+ that.target.append(new TestChild!());
16
+ }
17
+ }
18
+ }
19
+ );
20
+
21
+ export const TestParent = getCE('test-parent');
@@ -0,0 +1,47 @@
1
+ legend {
2
+ display: inherit;
3
+ margin: inherit;
4
+ vertical-align: inherit;
5
+ }
6
+
7
+ label {
8
+ display: inline;
9
+ margin-top: 5px;
10
+ margin-left: 5px;
11
+ vertical-align: top;
12
+ width: 10em;
13
+ text-align: right;
14
+ }
15
+
16
+ label::before {
17
+ content: ' ';
18
+ display: block;
19
+ }
20
+
21
+ form input,
22
+ form select,
23
+ form textarea {
24
+ margin-left: 5px;
25
+ margin-top: 0px;
26
+ display: inline;
27
+ }
28
+
29
+ form label + textarea {
30
+ display: inline-block;
31
+ margin-top: 3px;
32
+ }
33
+
34
+ form input + label {
35
+ width: inherit;
36
+ margin-top: 3px;
37
+ text-align: left;
38
+ }
39
+
40
+ body > form {
41
+ display: block;
42
+ }
43
+
44
+ form fieldset {
45
+ border: 1px solid darkslategrey;
46
+ border-radius: 3px;
47
+ }
@@ -0,0 +1,56 @@
1
+ <!-- test form -->
2
+ <fieldset>
3
+ <legend>Inputs</legend>
4
+ <label>text</label><input type="text" name="textInput" value="" />&nbsp;<strong>2wB:&nbsp;</strong>{textInput}
5
+ <label>color</label><input type="color" name="colorInput" value="" />
6
+ <label>date</label><input type="date" name="dateInput" value="" />
7
+ <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" />
8
+ <label>email</label><input type="email" name="email" value="" />
9
+ <label>file</label><input type="file" name="fileInput" value="" />
10
+ <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" />
11
+ <label>month</label><input type="month" name="month" value="" />
12
+ <label>number</label><input type="number" name="number" value="" />
13
+ <label>password</label><input type="password" name="passInput" value="" />
14
+ <label>range</label><input type="range" name="rangeInput" value="" />
15
+ <label>search</label><input type="search" name="searchInput" value="" />
16
+ <label>tel</label><input type="tel" name="telInput" value="" />
17
+ <label>time</label><input type="time" name="timeInput" value="" />
18
+ <label>url</label><input type="url" name="urlInput" value="" />
19
+ <label>week</label><input type="week" name="weekInput" value="" />
20
+ </fieldset>
21
+ <fieldset>
22
+ <legend>Selects</legend>
23
+ <label>singleSelect</label>
24
+ <select name="singleSelect">
25
+ <option disabled selected value> -- select -- </option>
26
+ <option value="1">Option 1</option>
27
+ <option value="2">Option 2</option>
28
+ <option value="3">Option 3</option>
29
+ <option value="4">Option 4</option>
30
+ </select>
31
+ <label>multiSelect</label>
32
+ <select name="multiSelect" multiple="multiple" type="select-multiple">
33
+ <option value="1">Option 1</option>
34
+ <option value="2" selected=true>Option 2</option>
35
+ <option value="3">Option 3</option>
36
+ <option value="4" selected=true>Option 4</option>
37
+ </select>
38
+ </fieldset>
39
+ <fieldset>
40
+ <legend>Radiobuttons&nbsp;<strong>2wB:&nbsp;</strong>{myRadio}</legend>
41
+ <label>radio1</label><input type="radio" name="myRadio" value="radio1">
42
+ <label>radio2</label><input type="radio" name="myRadio" value="radio2">
43
+ <label>radio3</label><input type="radio" name="myRadio" value="radio3">
44
+ </fieldset>
45
+ <fieldset>
46
+ <legend>Checkboxes</legend>
47
+ <label>cb1</label><input type="checkbox" name="cb1">
48
+ <label>cb2</label><input type="checkbox" name="cb2">
49
+ <label>cb3</label><input type="checkbox" name="cb3">
50
+ <label>cb4</label><input type="checkbox" name="cb4">
51
+ <label>cb5</label><input type="checkbox" name="cb5">
52
+ </fieldset>
53
+ <fieldset>
54
+ <legend>TextArea</legend>
55
+ <label>textArea</label><textarea name="textArea"></textarea>
56
+ </fieldset>
@@ -0,0 +1,27 @@
1
+ {
2
+ "textInput":"Hallo Welt",
3
+ "colorInput":"#eaf8f8",
4
+ "dateInput":"",
5
+ "dtlInput":"",
6
+ "email":"",
7
+ "hiddenInput":"",
8
+ "hiddenVal":"",
9
+ "month":"",
10
+ "number":"",
11
+ "passInput":"",
12
+ "rangeInput":"30",
13
+ "searchInput":"",
14
+ "telInput":"",
15
+ "timeInput":"",
16
+ "urlInput":"",
17
+ "weekInput":"",
18
+ "myRadio":"radio3",
19
+ "cb1":true,
20
+ "cb2":false,
21
+ "cb3":true,
22
+ "cb4":false,
23
+ "cb5":false,
24
+ "singleSelect":"",
25
+ "multiSelect":["2","4"],
26
+ "textArea":"This is some example\rtext..."
27
+ }
@@ -0,0 +1,159 @@
1
+ 'use strict';
2
+ import { DC, defineCE, Observable, FormValues } from '.././microcomponents.js';
3
+
4
+ defineCE(
5
+ 'test-testform',
6
+
7
+ class TestTestForm extends DC {
8
+ data: unknown;
9
+
10
+ constructor(target: HTMLElement) {
11
+ super(target);
12
+
13
+ const that = this;
14
+
15
+ delete this._mc;
16
+
17
+ let shadow = (that as DC).target.attachShadow({ mode: 'open' });
18
+ shadow.innerHTML = `<style>${this.css}</style>${this.template}`;
19
+
20
+ new FormValues(that, 'data', shadow);
21
+
22
+ (that.data as Observable).bind(shadow);
23
+ }
24
+
25
+ onConnected() {}
26
+
27
+ oneInit() {
28
+ let that = this;
29
+ }
30
+
31
+ get template() {
32
+ return /*html*/ `
33
+ <form>
34
+ <!-- sample form to start with -->
35
+ <fieldset>
36
+ <legend>Inputs</legend>
37
+ <label>text</label><input type="text" name="textInput" value="Hallo" />&nbsp;<strong>2wB:&nbsp;</strong>{textInput}
38
+ <label>color</label><input type="color" name="colorInput" value="" />
39
+ <label>date</label><input type="date" name="dateInput" value="" />
40
+ <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" />
41
+ <label>email</label><input type="email" name="email" value="" />
42
+ <label>file</label><input type="file" name="fileInput" value="" />
43
+ <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" />
44
+ <label>month</label><input type="month" name="month" value="" />
45
+ <label>number</label><input type="number" name="number" value="" />
46
+ <label>password</label><input type="password" name="passInput" value="" />
47
+ <label>range</label><input type="range" name="rangeInput" value="" />
48
+ <label>search</label><input type="search" name="searchInput" value="" />
49
+ <label>tel</label><input type="tel" name="telInput" value="" />
50
+ <label>time</label><input type="time" name="timeInput" value="" />
51
+ <label>url</label><input type="url" name="urlInput" value="" />
52
+ <label>week</label><input type="week" name="weekInput" value="" />
53
+ </fieldset>
54
+
55
+ <fieldset>
56
+ <legend>Selects</legend>
57
+
58
+ <label>singleSelect</label>
59
+ <select name="singleSelect">
60
+ <option disabled selected value> -- select -- </option>
61
+ <option value="1">Option 1</option>
62
+ <option value="2">Option 2</option>
63
+ <option value="3">Option 3</option>
64
+ <option value="4">Option 4</option>
65
+ </select>
66
+
67
+ <label>multiSelect</label>
68
+ <select name="multiSelect" multiple="multiple" type="select-multiple">
69
+ <option value="1">Option 1</option>
70
+ <option value="2" selected=true>Option 2</option>
71
+ <option value="3">Option 3</option>
72
+ <option value="4" selected=true>Option 4</option>
73
+ </select>
74
+
75
+ </fieldset>
76
+
77
+ <fieldset>
78
+ <legend>Radiobuttons&nbsp;<strong>2wB:&nbsp;</strong><span>{myRadio}</span></legend>
79
+
80
+ <label>radio1</label><input type="radio" name="myRadio" value="radio1">
81
+ <label>radio2</label><input type="radio" name="myRadio" value="radio2">
82
+ <label>radio3</label><input type="radio" name="myRadio" value="radio3">
83
+
84
+ </fieldset>
85
+
86
+ <fieldset>
87
+ <legend>Checkboxes</legend>
88
+ <label>cb1</label><input type="checkbox" name="cb1">
89
+ <label>cb2</label><input type="checkbox" name="cb2">
90
+ <label>cb3</label><input type="checkbox" name="cb3">
91
+ <label>cb4</label><input type="checkbox" name="cb4">
92
+ <label>cb5</label><input type="checkbox" name="cb5">
93
+
94
+ </fieldset>
95
+
96
+ <fieldset>
97
+ <legend>TextArea</legend>
98
+ <label>textArea</label>
99
+ <textarea name="textArea">abc</textarea>
100
+ </fieldset>
101
+
102
+ </form>
103
+ `;
104
+ }
105
+
106
+ get css() {
107
+ return /*css*/ `
108
+ legend {
109
+ display: inherit;
110
+ margin: inherit;
111
+ vertical-align: inherit;
112
+ }
113
+
114
+ label {
115
+ display: inline;
116
+ margin-top: 5px;
117
+ margin-left: 5px;
118
+ vertical-align: top;
119
+ width: 10em;
120
+ text-align: right;
121
+ }
122
+
123
+ label::before {
124
+ content: ' ';
125
+ display: block;
126
+ }
127
+
128
+ form input,
129
+ form select,
130
+ form textarea {
131
+ margin-left: 5px;
132
+ margin-top: 0px;
133
+ display: inline;
134
+ }
135
+
136
+ form label + textarea {
137
+ display: inline-block;
138
+ margin-top: 3px;
139
+ }
140
+
141
+ form input + label {
142
+ width: inherit;
143
+ margin-top: 3px;
144
+ text-align: left;
145
+ }
146
+
147
+ body > form {
148
+ display: block;
149
+ }
150
+
151
+ form fieldset {
152
+ border: 1px solid darkslategrey;
153
+ border-radius: 3px;
154
+ margin: 0.5em 0;
155
+ }
156
+ `;
157
+ }
158
+ }
159
+ );
package/src/test.ts CHANGED
@@ -127,10 +127,11 @@ let MyTag: CustomElementConstructor = getCE('my-tag')!,
127
127
  stress test
128
128
  */
129
129
 
130
- let start = new Date().getTime();
130
+ let start = new Date().getTime(),
131
+ max = 100;
131
132
 
132
- // create 100 elements
133
- for (let x = 0; x < 1000; x++) {
133
+ // create 1000 elements
134
+ for (let x = 0; x < max; x++) {
134
135
  fragment.append(new MyTag());
135
136
  }
136
137
 
@@ -149,14 +150,16 @@ setTimeout(() => {
149
150
  // console.clear();
150
151
 
151
152
  console.log(
152
- '%c \n\nStress Test:\n\n %cInstancing 1000 web components (3000 classes): %c %s ms.',
153
+ '%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.',
153
154
  'font-weight: bold; color: black;',
154
155
  'font-weight: normal;',
156
+ max,
157
+ max * 3,
155
158
  'font-weight: bold; color: blue;',
156
159
  end - start
157
160
  );
158
161
 
159
- document.body.appendChild(new MyTag());
162
+ //document.body.appendChild(new MyTag());
160
163
 
161
164
  let element = document.querySelector('my-tag');
162
165