@twobirds/microcomponents 0.0.57 → 0.0.59

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 (111) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/README.md +6 -2
  3. package/assets/documentation/observables.md +105 -0
  4. package/assets/test.html +2 -2
  5. package/dist/MC.d.ts +1 -1
  6. package/dist/MC.d.ts.map +1 -1
  7. package/dist/MC.min.js +65 -27
  8. package/dist/MC.ts +132 -39
  9. package/dist/elements.min.js +1 -1
  10. package/dist/formValues.d.ts +1 -3
  11. package/dist/formValues.d.ts.map +1 -1
  12. package/dist/formValues.ts +23 -24
  13. package/dist/formvValues.min.js +1 -1
  14. package/dist/microcomponents.min.js +1 -1
  15. package/dist/observables.d.ts.map +1 -1
  16. package/dist/observables.min.js +1 -1
  17. package/dist/observables.ts +5 -6
  18. package/dist/selectors.min.js +1 -1
  19. package/dist/test.ts +18 -2
  20. package/package.json +3 -3
  21. package/public/MC.js +65 -27
  22. package/public/MC.js.map +1 -1
  23. package/public/MC.min.js +65 -27
  24. package/public/documentation/observables.md +105 -0
  25. package/public/elements.min.js +1 -1
  26. package/public/formValues.js +15 -17
  27. package/public/formValues.js.map +1 -1
  28. package/public/formvValues.min.js +1 -1
  29. package/public/microcomponents.min.js +1 -1
  30. package/public/observables.js +1 -2
  31. package/public/observables.js.map +1 -1
  32. package/public/observables.min.js +1 -1
  33. package/public/selectors.min.js +1 -1
  34. package/public/src/MC.ts +132 -39
  35. package/public/src/autoloader.ts +55 -55
  36. package/public/src/formValues.ts +23 -24
  37. package/public/src/observables.ts +5 -6
  38. package/public/src/test.ts +18 -2
  39. package/public/test/child.js +15 -0
  40. package/public/test/child.js.map +1 -0
  41. package/public/test/grandchild.js +15 -0
  42. package/public/test/grandchild.js.map +1 -0
  43. package/public/test/grandparent.js +15 -0
  44. package/public/test/grandparent.js.map +1 -0
  45. package/public/test/greatgrandchild.js +29 -0
  46. package/public/test/greatgrandchild.js.map +1 -0
  47. package/public/test/parent.js +15 -0
  48. package/public/test/parent.js.map +1 -0
  49. package/public/test/testform.js +141 -0
  50. package/public/test/testform.js.map +1 -0
  51. package/public/test/testmc.js +10 -0
  52. package/public/test/testmc.js.map +1 -0
  53. package/public/test.html +2 -2
  54. package/public/test.js +5 -2
  55. package/public/test.js.map +1 -1
  56. package/src/MC.ts +132 -39
  57. package/src/formValues.ts +23 -24
  58. package/src/observables.ts +5 -6
  59. package/src/test/{Child.ts → child.ts} +3 -3
  60. package/src/test/{Grandchild.ts → grandchild.ts} +3 -3
  61. package/src/test/{Grandparent.ts → grandparent.ts} +3 -3
  62. package/src/test/{Greatgrandchild.ts → greatgrandchild.ts} +1 -1
  63. package/src/test/{Parent.ts → parent.ts} +4 -4
  64. package/src/test/{Testform.ts → testform.ts} +3 -9
  65. package/src/test/testmc.ts +11 -0
  66. package/src/test.ts +18 -2
  67. package/webpack.config.js +44 -5
  68. package/dist/autoloader.d.ts +0 -2
  69. package/dist/autoloader.d.ts.map +0 -1
  70. package/dist/autoloader.ts +0 -98
  71. package/public/assets/highlight.css +0 -99
  72. package/public/assets/main.js +0 -58
  73. package/public/assets/search.js +0 -1
  74. package/public/assets/style.css +0 -1280
  75. package/public/autoloader.js +0 -53
  76. package/public/autoloader.js.map +0 -1
  77. package/public/classes/MC.DC.html +0 -228
  78. package/public/classes/MC.MC.html +0 -171
  79. package/public/classes/MC.McBase.html +0 -117
  80. package/public/classes/MC.McEvent.html +0 -187
  81. package/public/classes/formValues.FormValues.html +0 -86
  82. package/public/functions/MC.addListener.html +0 -77
  83. package/public/functions/MC.autoload.html +0 -69
  84. package/public/functions/MC.removeListener.html +0 -73
  85. package/public/functions/elements.defineCE.html +0 -78
  86. package/public/functions/elements.getCE.html +0 -63
  87. package/public/functions/observables.observe.html +0 -65
  88. package/public/functions/selectors._d.html +0 -69
  89. package/public/functions/selectors._t.html +0 -69
  90. package/public/index.html +0 -126
  91. package/public/interfaces/MC.HTMLMcElement.html +0 -3608
  92. package/public/interfaces/selectors.DSelector.html +0 -1013
  93. package/public/interfaces/selectors.TSelector.html +0 -712
  94. package/public/modules/MC.html +0 -80
  95. package/public/modules/elements.html +0 -62
  96. package/public/modules/formValues.html +0 -60
  97. package/public/modules/observables.html +0 -65
  98. package/public/modules/selectors.html +0 -76
  99. package/public/modules.html +0 -54
  100. package/public/test/Grandparent.js +0 -1
  101. package/public/test/Testform.js +0 -1
  102. package/public/types/observables.Observable.html +0 -91
  103. package/public/types/selectors.selection.html +0 -58
  104. package/public/types/selectors.singleSelector.html +0 -58
  105. package/src/autoloader.ts +0 -98
  106. /package/assets/{Grandparent.css → grandparent.css} +0 -0
  107. /package/public/{Grandparent.css → grandparent.css} +0 -0
  108. /package/src/test/{Grandparent.css → grandparent.css} +0 -0
  109. /package/src/test/{Testform.css → testform.css} +0 -0
  110. /package/src/test/{Testform.html → testform.html} +0 -0
  111. /package/src/test/{Testform.json → testform.json} +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "CodeGPT.apiKey": "Ollama"
3
+ }
package/README.md CHANGED
@@ -8,10 +8,14 @@ Using micro components enforces **DRY, KISS and SOLID** principles in Javascript
8
8
 
9
9
  ## Think **Building Blocks**
10
10
 
11
- When coding with this system, you create classes that extend either the **[MC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#mc-class-extends-mcbase)** or **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#dc-class-extends-mcbase)** superclasses provided here. These classes provide the structure you need to build your wonderland.
11
+ In general this is a **HTML / Web Standards first** system. There is almost no abstraction, especially not for templating, except state binding to the DOM.
12
+
13
+ When coding with this system, you create classes that extend either the **[MC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#mc-class-extends-mcbase)** or **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#dc-class-extends-mcbase)** superclasses provided here. These classes provide the structure you need to build your wonderland. You can attach instances of your custom code to any HTMLElement, and there can be as many as you want connected to a single HTML tag.
12
14
 
13
15
  In an almost literal sense they work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
14
16
 
17
+ Also you can easily define native JS custom elements, and since these are just another instance of DC, you can enhance them even at runtime, as they are displayed in the browser.
18
+
15
19
  This systems **modular** approach gives you full control over your software, without the need to rely on other frameworks. On the other hand, its **minimalistic** stance enables you to use the resulting functionality in any other framework, and makes the **learning curve neglectable**.
16
20
 
17
21
  ## Status
@@ -27,7 +31,7 @@ This repository exports 5 independent functionalities:
27
31
 
28
32
  1. **[Micro Components](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads)** contains the **MC** and **DC** classes you can use as super classes.
29
33
  2. **[Elements](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads)** lets you define and use your own native web components. Uses (1).
30
- 3. (wip) **Observables** add **observability** and **run time type safety** to object properties. Also they provide **1-way binding** to placeholders in your template HTML.
34
+ 3. **[Observables](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads)** add **observability** and **run time type safety** to object properties. Also they provide **1-way binding** to placeholders in your template HTML.
31
35
  4. (wip) **FormValues** gives you **2-way binding** between a HTML form and an observable object. Uses (3).
32
36
  5. (wip) **Selectors** provide chainable jQuery like selectors for both the DOM and micro components.
33
37
 
@@ -0,0 +1,105 @@
1
+ # Observables Documentation
2
+
3
+ This module provides utilities for observing and binding data to DOM elements using placeholders. It supports reactive updates when data changes.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Functions](#functions)
9
+ - [Types](#types)
10
+ - [Example Usage](#example-usage)
11
+
12
+ ---
13
+
14
+ ## Overview
15
+
16
+ The module defines an `observe` function that makes object properties observable.
17
+
18
+ You can use this function to turn a single property or all properties of an object into observables.
19
+
20
+ This functionality can be used standalone in any framework.
21
+
22
+ ## Functions
23
+
24
+ ### `observe( target: LooseObject, propertyName?: string ): LooseObject`
25
+
26
+ **Description**
27
+
28
+ Registers a distinct property or all object properties as an observable, making them reactive.
29
+
30
+ Those properties are dual use:
31
+
32
+ - **Direct Assign Native Values**:
33
+ - Directly assign native values to the property, and the observable will be notified of the change.
34
+
35
+ - **Use as an Instance of Observable**
36
+ - Use the property as an instance of the `Observable` class. This allows you to attach callbacks and react to changes. You can bind the property to DOM elements.
37
+
38
+ ## Types
39
+
40
+ ### `Observable`
41
+
42
+ **Definition**
43
+ ```typescript
44
+ export type Observable = {
45
+ observe: (cb: Callback) => void; // attach a callback to be notified of changes
46
+ notify: () => void; // mostly internal use, but can be called to trigger all callbacks
47
+ bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void; // the target DOM element to bind the observable to. {placeholder} will be replaced with the actual data value.
48
+ };
49
+ ```
50
+
51
+ **Methods**
52
+
53
+ - `observe(cb: Callback)`
54
+ Registers a callback to be notified of changes.
55
+
56
+ - `notify( enable?: boolean)`
57
+ - Enables / Disables notifications.
58
+ - By default, notifications are enabled.
59
+ - If `enable` is `false`, notifications are disabled. You need to explicitly call `notify(true)` to re-enable notifications.
60
+ - Triggers all registered callbacks with the current data.
61
+
62
+ - `bind(target: HTMLElement | DocumentFragment | ShadowRoot)`
63
+ Binds the observable to a DOM element, replacing placeholders with data values.
64
+
65
+
66
+ ## Example Usage
67
+
68
+ ```typescript
69
+ import { observe } from './src/observables';
70
+
71
+ const data = {
72
+ name: 'John',
73
+ age: 30,
74
+ };
75
+
76
+ observe(data);
77
+
78
+ const element = document.getElementById('user-card');
79
+ data.bind(element);
80
+ ```
81
+
82
+ In HTML:
83
+ ```html
84
+ <div id="user-card">
85
+ <p>Hello, {name}</p>
86
+ <p>Age: {age}</p>
87
+ </div>
88
+ ```
89
+
90
+ When `data.name` or `data.age` changes, the DOM updates automatically.
91
+
92
+ ---
93
+
94
+ ## Dependencies
95
+
96
+ - `helpers.js` - Provides utilities like `deepEqual`, `debounce`, `flattenObject`, etc.
97
+ - `MC.js` - Contains `DC`, `HTMLMcElement`, and `McEvent` for DOM manipulation and event handling.
98
+
99
+ ---
100
+
101
+ ## Notes
102
+
103
+ - Only objects can be bound to the DOM.
104
+ - Native values (strings, numbers, booleans) are wrapped in observable proxies.
105
+ - Changes to observable properties trigger updates in bound DOM elements.
package/assets/test.html CHANGED
@@ -11,7 +11,7 @@
11
11
  href="MicroComponents.svg"
12
12
  />
13
13
  <link href="./my-tag.css" rel="stylesheet" />
14
- <link href="./Grandparent.css" rel="stylesheet" />
14
+ <link href="./grandparent.css" rel="stylesheet" />
15
15
  <script src="./microcomponents.min.js"></script>
16
16
  <script>
17
17
  Object.assign(window, microcomponents); // make system global, for debugging
@@ -21,7 +21,7 @@
21
21
  </head>
22
22
  <body>
23
23
  <test-grandparent></test-grandparent>
24
- <test-testform></test-testform>
24
+ <test-testform _mc="test-testmc"></test-testform>
25
25
  Open the debugger, read console, then:<br />
26
26
  </body>
27
27
  </html>
package/dist/MC.d.ts CHANGED
@@ -31,6 +31,6 @@ declare class DC extends McBase {
31
31
  children(search?: string): any[];
32
32
  descendants(search?: string): any[];
33
33
  }
34
- export { addListener, removeListener, McBase, MC, DC, McEvent };
35
34
  export declare function autoload(enable?: boolean): boolean;
35
+ export { addListener, removeListener, McBase, MC, DC, McEvent };
36
36
  //# sourceMappingURL=MC.d.ts.map
package/dist/MC.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAevC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA8CD,iBAAS,WAAW,CACnB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAClD,OAAO,GAAE,OAAe,EACxB,IAAI,GAAE,OAAe,QAarB;AAED,iBAAS,cAAc,CACtB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAGlD;AAmDD,iBAAS,OAAO,CACf,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,OAAO,GAAG,MAAM,EACpB,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAwBpB;AAiGD,cAAM,MAAM;;gBAGC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,KAAK,GAAE,OAAe;IAWnE,IAAI,MAAM,IAAI,GAAG,CAEhB;CACD;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,CAAC,EAAE,GAAG;IAIxB,MAAM,CAAC,OAAO,iBAAW;IAEzB,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;CAmElE;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IACjC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAW;IAEnC,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAI7D,MAAM,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMlC,SAAS,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMrC,QAAQ,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAYpC,WAAW,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;CAMvC;AAED,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;AAiDhE,wBAAgB,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAgBxD"}
1
+ {"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAevC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA8CD,iBAAS,WAAW,CACnB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAClD,OAAO,GAAE,OAAe,EACxB,IAAI,GAAE,OAAe,QAarB;AAED,iBAAS,cAAc,CACtB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAGlD;AAmDD,iBAAS,OAAO,CACf,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,OAAO,GAAG,MAAM,EACpB,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAwBpB;AAiGD,cAAM,MAAM;;gBAGC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,KAAK,GAAE,OAAe;IAWnE,IAAI,MAAM,IAAI,GAAG,CAEhB;CACD;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,CAAC,EAAE,GAAG;IAIxB,MAAM,CAAC,OAAO,iBAAW;IAEzB,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;CAmElE;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IACjC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAW;IAEnC,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAI7D,MAAM,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMlC,SAAS,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMrC,QAAQ,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAYpC,WAAW,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;CAMvC;AA6ID,wBAAgB,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAgBxD;AAED,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC"}
package/dist/MC.min.js CHANGED
@@ -202,7 +202,7 @@ function add(target, key, element = {}) {
202
202
  const _mc = node._mc;
203
203
  if (key.length && !_mc[key]) {
204
204
  _mc[key] = element;
205
- if (target instanceof HTMLElement) {
205
+ if (target instanceof HTMLElement && !target.getAttribute('_mc')) {
206
206
  target.setAttribute('_mc', '');
207
207
  }
208
208
  }
@@ -400,32 +400,69 @@ class DC extends McBase {
400
400
  return MC_getMicroComponents([...myDomElements], search);
401
401
  }
402
402
  }
403
-
404
403
  let observer = null;
405
- const unresolved = new Map();
406
- function loadit() {
407
- document
408
- .querySelectorAll(':not(:defined),[_mc]:not([_mc=""])')
404
+ const unresolvedCEs = new Map();
405
+ const MCs = new Map();
406
+ function loadUndefinedMicroComponents() {
407
+ [...document.querySelectorAll(':not(:defined)')]
408
+ .filter((element) => !!element && !document.head.querySelector(`script[${element.tagName.toLowerCase()}]`))
409
409
  .forEach((el) => {
410
- const load = el.tagName.includes('-')
411
- ? [el.tagName.toLowerCase()]
412
- : el.getAttribute('_mc').trim().split(' ');
413
- load.forEach((elementName) => {
414
- let fileName = elementName.toLowerCase().split('-'), lastElement = fileName[fileName.length - 1], renameLastElement = lastElement[0].toUpperCase() + lastElement.slice(1);
415
- fileName[fileName.length - 1] = renameLastElement;
416
- fileName = fileName.join('/') + '.js';
417
- if (el.tagName.includes('-') &&
418
- !unresolved.has(el.tagName.toLowerCase())) {
419
- const se = document.createElement('script');
420
- unresolved.set(elementName, fileName);
421
- se.setAttribute('src', fileName);
422
- se.setAttribute('blocking', 'render');
423
- se.setAttribute('type', 'module');
424
- se.onload = () => {
425
- unresolved.delete(elementName);
426
- };
427
- document.head.append(se);
428
- }
410
+ const elementName = el.tagName.toLowerCase(), fileName = '/' + elementName.split('-').join('/') + '.js';
411
+ const se = document.createElement('script');
412
+ se.setAttribute('src', fileName);
413
+ se.setAttribute('blocking', 'render');
414
+ se.setAttribute('type', 'module');
415
+ se.setAttribute(elementName, '');
416
+ se.onerror = () => {
417
+ console.error('could not load Custom Element code from', fileName);
418
+ };
419
+ document.head.append(se);
420
+ });
421
+ [...document.querySelectorAll('[_mc]:not([_mc=""]')]
422
+ .filter((element) => !!element)
423
+ .forEach((el) => {
424
+ const toBeLoaded = el.getAttribute('_mc')?.split(' ').filter(m => !!m && !document.head.querySelector(`script[${m}]`));
425
+ toBeLoaded?.forEach(elementName => {
426
+ const se = document.createElement('script'), fileName = '/' + elementName.split('-').join('/') + '.js';
427
+ se.setAttribute('src', fileName);
428
+ se.setAttribute('blocking', 'render');
429
+ se.async = true;
430
+ se.setAttribute('type', 'module');
431
+ se.setAttribute(elementName, '');
432
+ se.onload = () => {
433
+ setTimeout(function () {
434
+ const se = document.createElement('script');
435
+ const importFileName = fileName;
436
+ se.async = true;
437
+ se.setAttribute('type', 'module');
438
+ const code = `
439
+ import _ from "${importFileName}";
440
+ import {DC} from "./microcomponents.js";
441
+
442
+ //console.log('use importFileName', '${importFileName}');
443
+ // console.log('use elementName', '${elementName}');
444
+
445
+ const elements = Array.from(document.querySelectorAll('[_mc*="${elementName}"]')).filter( element => element instanceof HTMLElement );
446
+
447
+ // console.log('elements', elements);
448
+ elements.forEach((element) => {
449
+ // console.log('DC, element,class', DC, element, _);
450
+ DC.add(element, _.name, new _(element));
451
+ element.setAttribute('_mc', element.getAttribute('_mc').replace('${elementName}', '').replace( /\w\w/g, ' ').trim());
452
+ });
453
+ setTimeout( () => {
454
+ // console.log('remove callback script tag', '${elementName}');
455
+ document.body.querySelector('script[${elementName}]')?.remove();
456
+ },0);
457
+ `;
458
+ se.innerHTML = code;
459
+ document.body.append(se);
460
+ }, 0);
461
+ };
462
+ se.onerror = () => {
463
+ console.error('could not load DOM Component code from', fileName);
464
+ };
465
+ document.head.append(se);
429
466
  });
430
467
  });
431
468
  }
@@ -437,14 +474,15 @@ function autoload(enable = true) {
437
474
  return autoloadEnabled;
438
475
  }
439
476
  autoloadEnabled = enable;
440
- observer = new MutationObserver(loadit);
477
+ observer = new MutationObserver(loadUndefinedMicroComponents);
441
478
  setTimeout(() => {
442
479
  observer.observe(document.body, { childList: true, subtree: true });
443
- loadit();
480
+ loadUndefinedMicroComponents();
444
481
  }, 5);
445
482
  return autoloadEnabled;
446
483
  }
447
484
 
485
+
448
486
  /******/ return __webpack_exports__;
449
487
  /******/ })()
450
488
  ;
package/dist/MC.ts CHANGED
@@ -111,7 +111,7 @@ function add(target: HTMLElement, key: string, element = {}): any {
111
111
  if (key.length && !_mc[key]) {
112
112
  _mc[key] = element;
113
113
  // add attribute if HTMLElement
114
- if (target instanceof HTMLElement) {
114
+ if (target instanceof HTMLElement && ! target.getAttribute('_mc') ) {
115
115
  target.setAttribute('_mc', '');
116
116
  }
117
117
  }
@@ -410,50 +410,140 @@ class DC extends McBase {
410
410
  }
411
411
  }
412
412
 
413
- export { addListener, removeListener, McBase, MC, DC, McEvent };
414
-
415
413
  let observer: MutationObserver | null = null;
416
- const unresolved = new Map();
417
414
 
418
- function loadit() {
419
- document
420
- .querySelectorAll(':not(:defined),[_mc]:not([_mc=""])')
415
+ /*
416
+ unresolvedCEs (code below this comment):
417
+
418
+ a repository (a hashmap) of undefined custom elements:
419
+ the name is the tagname of the micro component (like "my-custom-component")
420
+ if they are loading, the value is a script element
421
+ if they are loaded, the entry is deleted and the browser instanciates it automatically
422
+ if they cannot be loaded, the browser will throw an error
423
+
424
+ If the custom element ( defined by its tagname, like "my-custom-component") is not defined, it will be on-demand loaded:
425
+ The file name is assumed to be "/my/custom/component.js"
426
+ The file must define a custom element via the defineCE() function included in the "elements" module.
427
+ This function is a wrapper for customElementRegistry.define(), which you can also use directly in the imported code.
428
+
429
+ In general this behaves like a custom runtime import for custom elements in the browser.
430
+ The only difference is that the micro component is loaded only when needed, and not on page load.
431
+ */
432
+
433
+ const unresolvedCEs = new Map();
434
+
435
+ /*
436
+ MCs (code below this comment):
437
+ a repository (a hashmap) of micro components:
438
+ the name is the name of the micro component (like "my-mc")
439
+ if they are loading, the value is a script element
440
+ if they are loaded, the value is the micro component class itself
441
+
442
+ This is mostly used for old style progressive enhancement:
443
+ If the micro component ( defined in the HTMLElements "_mc" attribute, like "my-mc") is not defined, it will be on-demand loaded:
444
+ The file name is assumed to be "/my/mc.js"
445
+ The file needs to have a default export, and it should be a class that extends the DC class ( since it is in a HTMLElements attribute )
446
+
447
+ In general this behaves like a custom runtime import for classes in the browser.
448
+ The only difference is that the micro component is loaded only when needed, and not on page load.
449
+ */
450
+ const MCs = new Map();
451
+
452
+ function loadUndefinedMicroComponents() {
453
+
454
+ // load unresolved custom eleents
455
+ [ ...document.querySelectorAll(':not(:defined)') ] // undefined custom elements
456
+ .filter( (element) => !!element && !document.head.querySelector(`script[${element.tagName.toLowerCase()}]`) )
421
457
  .forEach((el) => {
422
- const load: string[] = el.tagName.includes('-')
423
- ? [el.tagName.toLowerCase()]
424
- : el.getAttribute('_mc')!.trim().split(' ');
425
-
426
- load.forEach((elementName) => {
427
- let fileName: any = elementName.toLowerCase().split('-'), // intentional any
428
- lastElement = fileName[fileName.length - 1],
429
- renameLastElement =
430
- lastElement[0].toUpperCase() + lastElement.slice(1);
431
- fileName[fileName.length - 1] = renameLastElement;
432
- fileName = fileName.join('/') + '.js';
433
-
434
- // autoload web components
435
- // TBD: _mc components
436
- if (
437
- el.tagName.includes('-') &&
438
- !unresolved.has(el.tagName.toLowerCase())
439
- ) {
440
- const se: HTMLScriptElement = document.createElement('script');
458
+ const elementName = el.tagName.toLowerCase(),
459
+ fileName: string = '/'+elementName.split('-').join('/')+'.js';
460
+ //console.log('load undefined custom element',el);
441
461
 
442
- unresolved.set(elementName, fileName);
462
+ const se: HTMLScriptElement = document.createElement('script');
443
463
 
444
- se.setAttribute('src', fileName);
445
- se.setAttribute('blocking', 'render');
446
- se.setAttribute('type', 'module');
447
- se.onload = () => {
448
- // console.info('loaded', s);
449
- unresolved.delete(elementName);
450
- //console.log(unresolved);
451
- };
464
+ se.setAttribute('src', fileName);
465
+ se.setAttribute('blocking', 'render');
466
+ se.setAttribute('type', 'module');
467
+ se.setAttribute( elementName, '');
468
+
469
+ se.onerror = () => {
470
+ console.error('could not load Custom Element code from', fileName);
471
+ }
472
+
473
+ //console.info('load Custom Element', elementName);
474
+ document.head.append(se);
452
475
 
453
- document.head.append(se);
476
+ // instanciation of the micro component will be handled by the browser automatically
477
+ // module code must define the micro component class and add it to the customElementRegistry
478
+ });
479
+
480
+ [ ...document.querySelectorAll('[_mc]:not([_mc=""]') ] // undefined DOM components
481
+ .filter( (element) => !!element )
482
+ .forEach((el) => {
483
+ const toBeLoaded = el.getAttribute('_mc')?.split(' ').filter( m => !!m && !document.head.querySelector(`script[${m}]`) );
484
+
485
+
486
+ //console.log('load undefined DOM components',toBeLoaded);
487
+
488
+ toBeLoaded?.forEach( elementName => {
489
+ const se: HTMLScriptElement = document.createElement('script'),
490
+ fileName: string = '/'+elementName.split('-').join('/')+'.js';
491
+
492
+ se.setAttribute('src', fileName);
493
+ se.setAttribute('blocking', 'render');
494
+ se.async = true;
495
+ se.setAttribute('type', 'module');
496
+ se.setAttribute( elementName, '');
497
+
498
+ se.onload = () => {
499
+ // console.info('loaded MC', elementName);
500
+
501
+ // create callback script tag
502
+ setTimeout( function(){
503
+ // create callback script tag
504
+ const se: HTMLScriptElement = document.createElement('script');
505
+ const importFileName = fileName;
506
+
507
+ se.async = true;
508
+ se.setAttribute( 'type', 'module');
509
+
510
+ const code = /*javascript*/`
511
+ import _ from "${importFileName}";
512
+ import {DC} from "./microcomponents.js";
513
+
514
+ //console.log('use importFileName', '${importFileName}');
515
+ // console.log('use elementName', '${elementName}');
516
+
517
+ const elements = Array.from(document.querySelectorAll('[_mc*="${elementName}"]')).filter( element => element instanceof HTMLElement );
518
+
519
+ // console.log('elements', elements);
520
+ elements.forEach((element) => {
521
+ // console.log('DC, element,class', DC, element, _);
522
+ DC.add(element, _.name, new _(element));
523
+ element.setAttribute('_mc', element.getAttribute('_mc').replace('${elementName}', '').replace( /\w\w/g, ' ').trim());
524
+ });
525
+ setTimeout( () => {
526
+ // console.log('remove callback script tag', '${elementName}');
527
+ document.body.querySelector('script[${elementName}]')?.remove();
528
+ },0);
529
+ `;
530
+
531
+ //console.log('before innerHTML');
532
+ se.innerHTML = code;
533
+ //console.log('after innerHTML');
534
+ //console.log( 'callback script tag', se, code );
535
+ document.body.append(se);
536
+ }, 0);
537
+
454
538
  }
539
+
540
+ se.onerror = () => {
541
+ console.error('could not load DOM Component code from', fileName);
542
+ }
543
+
544
+ // console.info('load DOM Micro Component', elementName);
545
+ document.head.append(se);
455
546
  });
456
- //console.log(unresolved);
457
547
  });
458
548
  }
459
549
 
@@ -467,12 +557,15 @@ export function autoload(enable: boolean = true): boolean {
467
557
  }
468
558
 
469
559
  autoloadEnabled = enable;
470
- observer = new MutationObserver(loadit);
560
+ observer = new MutationObserver(loadUndefinedMicroComponents);
471
561
 
472
562
  setTimeout(() => {
473
563
  observer!.observe(document.body, { childList: true, subtree: true });
474
- loadit();
564
+ loadUndefinedMicroComponents();
475
565
  }, 5);
476
566
 
477
567
  return autoloadEnabled;
478
568
  }
569
+
570
+ export { addListener, removeListener, McBase, MC, DC, McEvent };
571
+
@@ -1 +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.elements=t():e.elements=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},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={};e.r(t),e.d(t,{defineCE:()=>y,getCE:()=>w});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>n.add(e)));class o{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var i=new Function("try {return this===window;}catch(e){ return false;}");let c=new Set;function s(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function a(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function u(e){return e&&e instanceof HTMLElement}function l(e,t,r={}){let n=e;if(!n._mc){let t=b?.debug;b.debug=!1,n._mc=new b(e),b.debug=t,delete n._mc._mc}const o=n._mc;return t.length&&!o[t]&&(o[t]=r,e instanceof HTMLElement&&e.setAttribute("_mc","")),r}function d(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function p(e,t,r={},n="l"){let i=e?._mc;if(!i)return;let c=t instanceof o?new o(t.type,t.data,"l"):new o(t,r,"l"),s="string"!=typeof t?t:new o(t,r,n);[...Object.values(i)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(c)})),/[ud]/.test(s.bubble)&&f(e,s)}function f(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let r=a(e,"",!0)?.[0].target;r&&b.trigger(r,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&b.trigger(e,t)}))}),0)}i()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>c.add(e)));class g{#n;constructor(e,t=!1){var r;this.#n=new WeakRef(e||{}),(r=this).constructor!==b&&setTimeout((()=>{r.trigger("Init")}),0),function(e){if(!i()||e.constructor===b)return;const t=e.target;if(t instanceof HTMLElement){let r=e;Object.getOwnPropertyNames(r.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof r.constructor.prototype[e])).forEach((n=>{let o=/^one/.test(n),i=n.replace(/^on[e]{0,1}/,""),s=i.toLowerCase();o&&Object.defineProperty(e,"on"+i,{configurable:!0,enumerable:!1,writable:!0,value:e=>{r.constructor.prototype[n].bind(r)(e)}}),c.has("on"+s)&&function(e,t,r,n=!1,o=!1){let i={once:!1};n&&(i.capture=n),o&&(i.once=o),e.addEventListener(t,r,i)}(t,s,(e=>{r.trigger(i,e)}),!1,o)}))}}(this)}get target(){return this.#n.deref()}}class m extends g{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},r="l"){let n=this;if(n.constructor===m||n.constructor===b){let i=e instanceof o?new o(e.type,e.data,"l"):new o(e,t,"l"),c="string"!=typeof e?e:new o(e,t,r);return[...Object.getOwnPropertyNames(n)].forEach((e=>{n[e]?.trigger&&"function"==typeof n[e]?.trigger&&n[e]?.trigger(i)})),void(/[ud]/.test(c.bubble)&&f(n.target,c))}if(n instanceof m||n instanceof b){const n=this,i="string"!=typeof e?e:new o(e,t,r),c="on"+i.type[0].toUpperCase()+i.type.slice(1);if(i.bubble.indexOf("l")>-1&&(i.immediateStopped||"function"!=typeof n[c]||(n[c](i),n.hasOwnProperty(c)&&delete n[c])),i.stopped||"l"===i.bubble)return n;/[ud]/.test(i.bubble)&&f(n.target,i)}}}class b extends g{_mc={};constructor(e,t=!1){super(e)}static add=l;static remove=d;static trigger=p;trigger(e,t={},r){m.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return u(t)?a(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return u(t)?a(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!u(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const o=s([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),o}descendants(e=""){let t=this?.target;return u(t)?s([...t.querySelectorAll("*[_mc]")],e):[]}}new Map;class h extends HTMLElement{constructor(){super()}connectedCallback(){b.trigger(this,"Connected")}disconnectedCallback(){b.trigger(this,"Disconnected")}adoptedCallback(){b.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){b.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function y(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let n=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(n,class extends h{instance;constructor(e){super();let r=new t(this,e);b.add(this,n,r)}static get observedAttributes(){return r}}))}function w(e){return customElements.get(e)}return t})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.elements=t():e.elements=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},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={};e.r(t),e.d(t,{defineCE:()=>y,getCE:()=>w});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>n.add(e)));class o{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var i=new Function("try {return this===window;}catch(e){ return false;}");let c=new Set;function s(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function a(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function u(e){return e&&e instanceof HTMLElement}function l(e,t,r={}){let n=e;if(!n._mc){let t=b?.debug;b.debug=!1,n._mc=new b(e),b.debug=t,delete n._mc._mc}const o=n._mc;return t.length&&!o[t]&&(o[t]=r,e instanceof HTMLElement&&!e.getAttribute("_mc")&&e.setAttribute("_mc","")),r}function d(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function p(e,t,r={},n="l"){let i=e?._mc;if(!i)return;let c=t instanceof o?new o(t.type,t.data,"l"):new o(t,r,"l"),s="string"!=typeof t?t:new o(t,r,n);[...Object.values(i)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(c)})),/[ud]/.test(s.bubble)&&f(e,s)}function f(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let r=a(e,"",!0)?.[0].target;r&&b.trigger(r,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&b.trigger(e,t)}))}),0)}i()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>c.add(e)));class g{#n;constructor(e,t=!1){var r;this.#n=new WeakRef(e||{}),(r=this).constructor!==b&&setTimeout((()=>{r.trigger("Init")}),0),function(e){if(!i()||e.constructor===b)return;const t=e.target;if(t instanceof HTMLElement){let r=e;Object.getOwnPropertyNames(r.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof r.constructor.prototype[e])).forEach((n=>{let o=/^one/.test(n),i=n.replace(/^on[e]{0,1}/,""),s=i.toLowerCase();o&&Object.defineProperty(e,"on"+i,{configurable:!0,enumerable:!1,writable:!0,value:e=>{r.constructor.prototype[n].bind(r)(e)}}),c.has("on"+s)&&function(e,t,r,n=!1,o=!1){let i={once:!1};n&&(i.capture=n),o&&(i.once=o),e.addEventListener(t,r,i)}(t,s,(e=>{r.trigger(i,e)}),!1,o)}))}}(this)}get target(){return this.#n.deref()}}class m extends g{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},r="l"){let n=this;if(n.constructor===m||n.constructor===b){let i=e instanceof o?new o(e.type,e.data,"l"):new o(e,t,"l"),c="string"!=typeof e?e:new o(e,t,r);return[...Object.getOwnPropertyNames(n)].forEach((e=>{n[e]?.trigger&&"function"==typeof n[e]?.trigger&&n[e]?.trigger(i)})),void(/[ud]/.test(c.bubble)&&f(n.target,c))}if(n instanceof m||n instanceof b){const n=this,i="string"!=typeof e?e:new o(e,t,r),c="on"+i.type[0].toUpperCase()+i.type.slice(1);if(i.bubble.indexOf("l")>-1&&(i.immediateStopped||"function"!=typeof n[c]||(n[c](i),n.hasOwnProperty(c)&&delete n[c])),i.stopped||"l"===i.bubble)return n;/[ud]/.test(i.bubble)&&f(n.target,i)}}}class b extends g{_mc={};constructor(e,t=!1){super(e)}static add=l;static remove=d;static trigger=p;trigger(e,t={},r){m.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return u(t)?a(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return u(t)?a(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!u(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const o=s([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),o}descendants(e=""){let t=this?.target;return u(t)?s([...t.querySelectorAll("*[_mc]")],e):[]}}new Map,new Map;class h extends HTMLElement{constructor(){super()}connectedCallback(){b.trigger(this,"Connected")}disconnectedCallback(){b.trigger(this,"Disconnected")}adoptedCallback(){b.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){b.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function y(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let n=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(n,class extends h{instance;constructor(e){super();let r=new t(this,e);b.add(this,n,r)}static get observedAttributes(){return r}}))}function w(e){return customElements.get(e)}return t})()));
@@ -1,5 +1,3 @@
1
1
  import { LooseObject } from './helpers.js';
2
- export declare class FormValues {
3
- constructor(targetObject: LooseObject, propertyName: string, dom: HTMLElement | ShadowRoot);
4
- }
2
+ export declare function formValues(targetObject: LooseObject, propertyName: string, dom: HTMLElement | ShadowRoot): void;
5
3
  //# sourceMappingURL=formValues.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../src/formValues.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AA0M/D,qBAAa,UAAU;gBAErB,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,WAAW,GAAG,UAAU;CAyB9B"}
1
+ {"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../src/formValues.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AA0M/D,wBAAgB,UAAU,CACzB,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,WAAW,GAAG,UAAU,QAwB7B"}
@@ -202,33 +202,32 @@ const getInputHandlers = (e: HTMLElement | ShadowRoot): LooseObject => {
202
202
  return handlers;
203
203
  };
204
204
 
205
- export class FormValues {
206
- constructor(
207
- targetObject: LooseObject,
208
- propertyName: string,
209
- dom: HTMLElement | ShadowRoot
210
- ) {
211
- let handlers = getInputHandlers(dom);
205
+ export function formValues(
206
+ targetObject: LooseObject,
207
+ propertyName: string,
208
+ dom: HTMLElement | ShadowRoot
209
+ ) {
210
+ let handlers = getInputHandlers(dom);
212
211
 
213
- targetObject[propertyName] = Object.assign({}, handlers);
212
+ targetObject[propertyName] = Object.assign({}, handlers);
214
213
 
215
- observe(targetObject, propertyName);
214
+ observe(targetObject, propertyName);
216
215
 
217
- copyGettersSetters(handlers, targetObject[propertyName]);
216
+ copyGettersSetters(handlers, targetObject[propertyName]);
218
217
 
219
- [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
220
- addListener(input as inputTypes, 'keyup', (ev: Event) => {
221
- //console.log('keyup', ev);
222
- targetObject[propertyName].notify();
223
- });
224
- addListener(input as HTMLElement, 'change', (ev: Event) => {
225
- //console.log('change', ev);
226
- targetObject[propertyName].notify();
227
- });
228
- addListener(input as inputTypes, 'select', (ev: Event) => {
229
- //console.log('select', ev);
230
- targetObject[propertyName].notify();
231
- });
218
+ [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
219
+ addListener(input as inputTypes, 'keyup', (ev: Event) => {
220
+ //console.log('keyup', ev);
221
+ targetObject[propertyName].notify();
232
222
  });
233
- }
223
+ addListener(input as HTMLElement, 'change', (ev: Event) => {
224
+ //console.log('change', ev);
225
+ targetObject[propertyName].notify();
226
+ });
227
+ addListener(input as inputTypes, 'select', (ev: Event) => {
228
+ //console.log('select', ev);
229
+ targetObject[propertyName].notify();
230
+ });
231
+ });
234
232
  }
233
+