@twobirds/microcomponents 0.0.67 → 0.0.69
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.
- package/.vscode/settings.json +1 -1
- package/README.md +5 -5
- package/assets/documentation/formvalues.md +46 -0
- package/assets/test/MicroComponents.svg +15 -0
- package/assets/test/test.html +6 -6
- package/dist/microcomponents.d.ts +0 -1
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.min.js +1 -0
- package/dist/microcomponents.ts +1 -1
- package/package.json +6 -5
- package/public/MC.d.ts +36 -0
- package/public/MC.d.ts.map +1 -0
- package/public/MC.ts +605 -0
- package/public/McEvent.d.ts +15 -0
- package/public/McEvent.d.ts.map +1 -0
- package/public/McEvent.ts +96 -0
- package/public/documentation/formvalues.md +46 -0
- package/public/elements.d.ts +5 -0
- package/public/elements.d.ts.map +1 -0
- package/public/elements.ts +76 -0
- package/public/formValues.d.ts +3 -0
- package/public/formValues.d.ts.map +1 -0
- package/public/formValues.ts +233 -0
- package/public/helpers.d.ts +14 -0
- package/public/helpers.d.ts.map +1 -0
- package/public/helpers.ts +149 -0
- package/public/microcomponents.d.ts +7 -0
- package/public/microcomponents.d.ts.map +1 -0
- package/public/microcomponents.es3.d.ts +2 -0
- package/public/microcomponents.es3.d.ts.map +1 -0
- package/public/microcomponents.js +0 -1
- package/public/microcomponents.js.map +1 -1
- package/public/microcomponents.min.js +1 -0
- package/public/microcomponents.ts +8 -0
- package/public/observables.d.ts +10 -0
- package/public/observables.d.ts.map +1 -0
- package/public/observables.ts +401 -0
- package/public/selectors.d.ts +108 -0
- package/public/selectors.d.ts.map +1 -0
- package/public/selectors.ts +1634 -0
- package/public/src/microcomponents.ts +1 -1
- package/public/test/MC.d.ts +36 -0
- package/public/test/MC.d.ts.map +1 -0
- package/public/test/MC.js +378 -0
- package/public/test/MC.js.map +1 -0
- package/public/test/MC.ts +605 -0
- package/public/test/McEvent.d.ts +15 -0
- package/public/test/McEvent.d.ts.map +1 -0
- package/public/test/McEvent.js +71 -0
- package/public/test/McEvent.js.map +1 -0
- package/public/test/McEvent.ts +96 -0
- package/public/test/MicroComponents.svg +15 -0
- package/public/test/elements.d.ts +5 -0
- package/public/test/elements.d.ts.map +1 -0
- package/public/test/elements.js +48 -0
- package/public/test/elements.js.map +1 -0
- package/public/test/elements.ts +76 -0
- package/public/test/formValues.d.ts +3 -0
- package/public/test/formValues.d.ts.map +1 -0
- package/public/test/formValues.js +168 -0
- package/public/test/formValues.js.map +1 -0
- package/public/test/formValues.ts +233 -0
- package/public/test/helpers.d.ts +14 -0
- package/public/test/helpers.d.ts.map +1 -0
- package/public/test/helpers.js +113 -0
- package/public/test/helpers.js.map +1 -0
- package/public/test/helpers.ts +149 -0
- package/public/test/microcomponents.d.ts +7 -0
- package/public/test/microcomponents.d.ts.map +1 -0
- package/public/test/microcomponents.es3.d.ts +2 -0
- package/public/test/microcomponents.es3.d.ts.map +1 -0
- package/public/test/microcomponents.es3.js +303 -0
- package/public/test/microcomponents.es3.js.map +1 -0
- package/public/test/microcomponents.js +8 -0
- package/public/test/microcomponents.js.map +1 -0
- package/public/test/microcomponents.min.js +1 -0
- package/public/test/microcomponents.ts +8 -0
- package/public/test/observables.d.ts +10 -0
- package/public/test/observables.d.ts.map +1 -0
- package/public/test/observables.js +250 -0
- package/public/test/observables.js.map +1 -0
- package/public/test/observables.ts +401 -0
- package/public/test/selectors.d.ts +108 -0
- package/public/test/selectors.d.ts.map +1 -0
- package/public/test/selectors.js +971 -0
- package/public/test/selectors.js.map +1 -0
- package/public/test/selectors.ts +1634 -0
- package/public/test/test/child.d.ts +2 -0
- package/public/test/test/child.d.ts.map +1 -0
- package/public/test/{child.js → test/child.js} +1 -1
- package/public/test/test/child.js.map +1 -0
- package/public/test/test/grandchild.d.ts +2 -0
- package/public/test/test/grandchild.d.ts.map +1 -0
- package/public/test/{grandchild.js → test/grandchild.js} +1 -1
- package/public/test/test/grandchild.js.map +1 -0
- package/public/test/test/grandparent.d.ts +2 -0
- package/public/test/test/grandparent.d.ts.map +1 -0
- package/public/test/test/grandparent.js.map +1 -0
- package/public/test/test/greatgrandchild.d.ts +2 -0
- package/public/test/test/greatgrandchild.d.ts.map +1 -0
- package/public/test/{greatgrandchild.js → test/greatgrandchild.js} +1 -1
- package/public/test/test/greatgrandchild.js.map +1 -0
- package/public/test/test/parent.d.ts +2 -0
- package/public/test/test/parent.d.ts.map +1 -0
- package/public/test/{parent.js → test/parent.js} +1 -1
- package/public/test/test/parent.js.map +1 -0
- package/public/test/test/testform.d.ts +2 -0
- package/public/test/test/testform.d.ts.map +1 -0
- package/public/test/test/testform.js.map +1 -0
- package/public/test/test/testmc.d.ts +6 -0
- package/public/test/test/testmc.d.ts.map +1 -0
- package/public/test/{testmc.js → test/testmc.js} +1 -1
- package/public/test/test/testmc.js.map +1 -0
- package/public/test/test.d.ts +2 -0
- package/public/test/test.d.ts.map +1 -0
- package/public/test/test.html +6 -6
- package/public/test/test.ts +193 -0
- package/public/typedoc/classes/MC.DC.html +2 -2
- package/public/typedoc/classes/MC.MC.html +2 -2
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/classes/MC.McEvent.html +2 -2
- package/public/typedoc/functions/MC.addListener.html +1 -1
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.removeListener.html +1 -1
- package/public/typedoc/functions/elements.defineCE.html +1 -1
- package/public/typedoc/functions/elements.getCE.html +1 -1
- package/public/typedoc/functions/formValues.formValues.html +1 -1
- package/public/typedoc/functions/observables.observe.html +1 -1
- package/public/typedoc/functions/selectors._d.html +1 -1
- package/public/typedoc/functions/selectors._t.html +1 -1
- package/public/typedoc/index.html +5 -5
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/interfaces/selectors.DSelector.html +2 -2
- package/public/typedoc/interfaces/selectors.TSelector.html +2 -2
- package/public/typedoc/modules/MC.html +1 -1
- package/public/typedoc/modules/elements.html +1 -1
- package/public/typedoc/modules/formValues.html +1 -1
- package/public/typedoc/modules/observables.html +1 -1
- package/public/typedoc/modules/selectors.html +1 -1
- package/public/typedoc/types/observables.Observable.html +1 -1
- package/public/typedoc/types/selectors.selection.html +1 -1
- package/public/typedoc/types/selectors.singleSelector.html +1 -1
- package/src/microcomponents.ts +1 -1
- package/src/test/{child.ts → test/child.ts} +1 -1
- package/src/test/{grandchild.ts → test/grandchild.ts} +1 -1
- package/src/test/{grandparent.ts → test/grandparent.ts} +1 -1
- package/src/test/{greatgrandchild.ts → test/greatgrandchild.ts} +1 -1
- package/src/test/{parent.ts → test/parent.ts} +1 -1
- package/src/test/{testform.ts → test/testform.ts} +1 -1
- package/src/test/{testmc.ts → test/testmc.ts} +1 -1
- package/tsconfig.json +2 -2
- package/webpack.config.js +5 -5
- package/dist/microcomponents.js +0 -1
- package/public/test/child.js.map +0 -1
- package/public/test/grandchild.js.map +0 -1
- package/public/test/grandparent.js.map +0 -1
- package/public/test/greatgrandchild.js.map +0 -1
- package/public/test/parent.js.map +0 -1
- package/public/test/testform.js.map +0 -1
- package/public/test/testmc.js.map +0 -1
- /package/public/test/{grandparent.js → test/grandparent.js} +0 -0
- /package/public/test/{testform.js → test/testform.js} +0 -0
- /package/public/{test.js → test/test.js} +0 -0
- /package/public/{test.js.map → test/test.js.map} +0 -0
package/.vscode/settings.json
CHANGED
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ On the other hand, its **minimalistic** stance enables you to use the resulting
|
|
|
24
24
|
|
|
25
25
|
## Status
|
|
26
26
|
|
|
27
|
-
**WIP**. Should be done soon. In [manual testing](https://twobirds.gitlab.io/microcomponents/test/), also working a lot on the documentation.
|
|
27
|
+
**WIP**. Should be done soon. In [manual testing](https://twobirds.gitlab.io/microcomponents/test/test.html), also working a lot on the documentation.
|
|
28
28
|
|
|
29
29
|
## General
|
|
30
30
|
|
|
@@ -34,14 +34,14 @@ On the other hand, its **minimalistic** stance enables you to use the resulting
|
|
|
34
34
|
This repository exports 5 independent functionalities:
|
|
35
35
|
|
|
36
36
|
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.
|
|
37
|
-
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).
|
|
38
|
-
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.
|
|
39
|
-
4. (
|
|
37
|
+
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). [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/public/test/test.ts?ref_type=heads), use debugger console to [see it at work here](https://twobirds.gitlab.io/microcomponents/test/test.html).
|
|
38
|
+
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. [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/public/test/test.ts?ref_type=heads), use debugger console to [see it at work here](https://twobirds.gitlab.io/microcomponents/test/test.html).
|
|
39
|
+
4. **[Formvalues](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/formvalues.md?ref_type=heads)** gives you **2-way binding** between a HTML form and an observable object. Uses (3). [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads), use debugger console to [see it at work here](https://twobirds.gitlab.io/microcomponents/test/test.html).
|
|
40
40
|
5. (wip) **Selectors** provide chainable jQuery like selectors for both the DOM and micro components.
|
|
41
41
|
|
|
42
42
|
Also there is a bundle file that contains all of the above.
|
|
43
43
|
|
|
44
|
-
Check the [typedoc API reference](https://twobirds.gitlab.io/microcomponents/typedoc/) if you want to drill into the source code.
|
|
44
|
+
Check the [typedoc API reference](https://twobirds.gitlab.io/microcomponents/typedoc/index.html) if you want to drill into the source code.
|
|
45
45
|
|
|
46
46
|
To see what can be done, go to [additional concepts](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/magic.md?ref_type=heads) which shows what it already has been used for.
|
|
47
47
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Form Values Module Documentation
|
|
2
|
+
|
|
3
|
+
This module provides a way to bind form input elements (text, radio, checkbox, select, textarea) to a JavaScript object, enabling two-way data binding and change observation.
|
|
4
|
+
|
|
5
|
+
## Key Components
|
|
6
|
+
|
|
7
|
+
### InputBase (Abstract Class)
|
|
8
|
+
- Base class for all input handlers
|
|
9
|
+
- Defines `val` getter/setter interface
|
|
10
|
+
|
|
11
|
+
### Input Handlers
|
|
12
|
+
- **RadioHandler**: Manages radio button groups
|
|
13
|
+
- **CheckboxHandler**: Handles checkbox state
|
|
14
|
+
- **InputHandler**: For standard text inputs
|
|
15
|
+
- **SelectHandler**: Manages select dropdowns (single/multi-select)
|
|
16
|
+
- **TextAreaHandler**: For textarea elements
|
|
17
|
+
|
|
18
|
+
### getInputHandlers
|
|
19
|
+
- Scans DOM for form elements
|
|
20
|
+
- Returns object with name-to-handler mappings
|
|
21
|
+
- Automatically creates appropriate handler type
|
|
22
|
+
|
|
23
|
+
### formValues Function
|
|
24
|
+
Binds form elements to a target object:
|
|
25
|
+
```ts
|
|
26
|
+
formValues(targetObject: LooseObject, propertyName: string, dom: HTMLElement | ShadowRoot)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Example code in constructor
|
|
30
|
+
```ts
|
|
31
|
+
constructor(target: HTMLElement) {
|
|
32
|
+
super(target);
|
|
33
|
+
|
|
34
|
+
const that = this;
|
|
35
|
+
|
|
36
|
+
delete that._mc; // not needed
|
|
37
|
+
|
|
38
|
+
let shadow = (that as DC).target.attachShadow({ mode: 'open' });
|
|
39
|
+
shadow.innerHTML = `<style>${that.css}</style>${that.template}`;
|
|
40
|
+
|
|
41
|
+
formValues(that, 'data', shadow); // create this.data formdata observable
|
|
42
|
+
|
|
43
|
+
(that.data as Observable).bind(shadow); // 1 way bind formdata to the form DOM
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
Full example [here](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
|
2
|
+
<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
|
|
3
|
+
<title>test</title>
|
|
4
|
+
<rect fill="transparent" x="0" y="0" width="200" height="200" fill-opacity="1"/>
|
|
5
|
+
<g style="fill:transparent">
|
|
6
|
+
<title>first bird</title>
|
|
7
|
+
<path fill="#18829c" d="
|
|
8
|
+
m15,160
|
|
9
|
+
a30,75 45 1 0 160,-150
|
|
10
|
+
a20,50 225 1 1 -110,100
|
|
11
|
+
a12,25 45 1 1 60,-50
|
|
12
|
+
a20,50 225 1 0 -110,100
|
|
13
|
+
" />
|
|
14
|
+
</g>
|
|
15
|
+
</svg>
|
package/assets/test/test.html
CHANGED
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
rel="icon"
|
|
9
9
|
type="image/svg+xml"
|
|
10
10
|
sizes="any"
|
|
11
|
-
href="MicroComponents.svg"
|
|
11
|
+
href="./MicroComponents.svg"
|
|
12
12
|
/>
|
|
13
|
-
<link href="
|
|
14
|
-
<link href="
|
|
15
|
-
<script src="
|
|
13
|
+
<link href="my-tag.css" rel="stylesheet" />
|
|
14
|
+
<link href="grandparent.css" rel="stylesheet" />
|
|
15
|
+
<script src="microcomponents.min.js"></script>
|
|
16
16
|
<script>
|
|
17
17
|
Object.assign(window, microcomponents); // make system global, for debugging
|
|
18
18
|
autoload(true); // automVatically load web components that are undefined
|
|
19
19
|
</script>
|
|
20
|
-
<script type="module" src="
|
|
20
|
+
<script type="module" src="test.js"></script>
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
|
+
<h2>Open the debugger, check console...</h2>
|
|
23
24
|
<test-grandparent></test-grandparent>
|
|
24
25
|
<test-testform _mc="test-testmc"></test-testform>
|
|
25
|
-
Open the debugger, read console, then:<br />
|
|
26
26
|
</body>
|
|
27
27
|
</html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +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.microcomponents=t():e.microcomponents=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={};function r(e){return e&&e.constructor&&e.constructor===Object}function n(e){let t={};return[...Object.keys(e)].sort().forEach((o=>{r(e[o])?t[o]=n(e[o]):t[o]=e[o]})),t}function o(e,t=!0){let r={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const n=o(e[t],!1);for(const e in n)r[t+"."+e]=n[e]}else r[t]=e[t]})),t?n(r):r}function c(e,t){return JSON.stringify(o(e))===JSON.stringify(o(t))}function s(e,t={}){let r=e.constructor===String?e.split("."):e;if(t&&r[0]&&t[r[0]])return t[r[0]].constructor===Object&&r.length>1?s(r.splice(1),t[r[0]]):t[r[0]];console.warn("ns",r[0],"not in",t)}function a(e,t){var n=Array.from(arguments);if(n.length>2){for(;n.length>1;)n[0]=a(n[0],n[1]),n.splice(1,1);return n[0]}if("string"==typeof e)e.match(/\{[^\{\}]*\}/g)?.forEach((function(r){var n=s(r.substring(1,r.length-1),t);void 0!==n&&(e=e.replace(r,n))}));else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=a(e[r],t))}));break;case Array:e.forEach((function(r,n,o){o[n]=a(e[n],t)}))}return e}function i(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function l(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function u(e){let t=document.createElement("template");return e=e.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),t.innerHTML=e,t.content.normalize(),Array.from(t.content.childNodes)}function d(e,t){const r=Object.getOwnPropertyDescriptors(e);for(const[e,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(t,e,n)}e.r(t),e.d(t,{DC:()=>k,MC:()=>C,McBase:()=>S,McEvent:()=>p,addListener:()=>E,autoload:()=>D,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>c,defineCE:()=>q,flattenObject:()=>o,formValues:()=>K,getCE:()=>$,htmlToElements:()=>u,isNativeObject:()=>r,kebabToPascal:()=>i,nameSpace:()=>s,observe:()=>J,parse:()=>a,removeListener:()=>v,sortObject:()=>n});var f=new Function("try {return this===window;}catch(e){ return false;}");let m=new Set;f()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>m.add(e)));class p{#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 b=new Function("try {return this===window;}catch(e){ return false;}");let g=new Set;function h(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 y(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 O(e){return e&&e instanceof HTMLElement}function E(e,t,r,n=!1,o=!1){let c={once:!1};n&&(c.capture=n),o&&(c.once=o),e.addEventListener(t,r,c)}function v(e,t,r){e.removeEventListener(t,r)}function w(e,t,r={}){let n=e;if(!n._mc){let t=k?.debug;k.debug=!1,n._mc=new k(e),k.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 A(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 j(e,t,r={},n="l"){let o=e?._mc;if(!o)return;let c=t instanceof p?new p(t.type,t.data,"l"):new p(t,r,"l"),s="string"!=typeof t?t:new p(t,r,n);[...Object.values(o)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(c)})),/[ud]/.test(s.bubble)&&_(e,s)}function _(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let r=y(e,"",!0)?.[0].target;r&&k.trigger(r,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&k.trigger(e,t)}))}),0)}b()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>g.add(e)));class S{#n;constructor(e,t=!1){var r;this.#n=new WeakRef(e||{}),(r=this).constructor!==k&&setTimeout((()=>{r.trigger("Init")}),0),function(e){if(!b()||e.constructor===k)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),c=n.replace(/^on[e]{0,1}/,""),s=c.toLowerCase();o&&Object.defineProperty(e,"on"+c,{configurable:!0,enumerable:!1,writable:!0,value:e=>{r.constructor.prototype[n].bind(r)(e)}}),g.has("on"+s)&&E(t,s,(e=>{r.trigger(c,e)}),!1,o)}))}}(this)}get target(){return this.#n.deref()}}class C extends S{_mc={};constructor(e){super(e)}static trigger=j;trigger(e,t={},r="l"){let n=this;if(n.constructor===C||n.constructor===k){let o=e instanceof p?new p(e.type,e.data,"l"):new p(e,t,"l"),c="string"!=typeof e?e:new p(e,t,r);return[...Object.getOwnPropertyNames(n)].forEach((e=>{n[e]?.trigger&&"function"==typeof n[e]?.trigger&&n[e]?.trigger(o)})),void(/[ud]/.test(c.bubble)&&_(n.target,c))}if(n instanceof C||n instanceof k){const n=this,o="string"!=typeof e?e:new p(e,t,r),c="on"+o.type[0].toUpperCase()+o.type.slice(1);if(o.bubble.indexOf("l")>-1&&(o.immediateStopped||"function"!=typeof n[c]||(n[c](o),n.hasOwnProperty(c)&&delete n[c])),o.stopped||"l"===o.bubble)return n;/[ud]/.test(o.bubble)&&_(n.target,o)}}}class k extends S{_mc={};constructor(e,t=!1){super(e)}static add=w;static remove=A;static trigger=j;trigger(e,t={},r){C.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return O(t)?y(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return O(t)?y(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!O(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const o=h([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),o}descendants(e=""){let t=this?.target;return O(t)?h([...t.querySelectorAll("*[_mc]")],e):[]}}const T=new Map,N=new Map;function L(e){const t="./"+e.split("-").join("/")+".js",r=document.createElement("script");return r.setAttribute("src",t),r.setAttribute("blocking","render"),r.async=!0,r.setAttribute("type","module"),r.setAttribute("name",e),r.setAttribute("loading",""),E(r,"load",(e=>{r.removeAttribute("loading"),r.setAttribute("loaded","")})),E(r,"error",(e=>{console.error("could not load Custom Element code from",t)})),r}function M(){[...document.querySelectorAll(":not(:defined)")].filter((e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!T.has(e.tagName.toLowerCase()))).forEach((e=>{const t=e.tagName.toLowerCase(),r=(t.split("-").join("/"),L(t));E(r,"load",(()=>{T.set(t,customElements.get(e.tagName.toLowerCase()))})),T.set(t,"loading"),document.head.append(r)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((e=>!!e)).forEach((e=>{const t=e.getAttribute("_mc")?.split(" ").filter((e=>!!e))||[],r=t.filter((e=>!N.has(e)));r?.forEach((e=>{const t=L(e);E(t,"load",(()=>{return t=document.head.querySelector(`script[name="${e}"]`),void setTimeout((function(){const e=t.getAttribute("src"),r=t.getAttribute("name"),n=document.createElement("script");n.async=!0,n.setAttribute("type","module");const o=`\n\n\t\t\timport _ from "${e}";\n\t\t\timport {DC} from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${r}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${r}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${r}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${r}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;n.innerHTML=o,document.body.append(n)}),0);var t})),N.set(e,"loading"),document.head.append(t)}));const n=t.filter((e=>N.has(e)&&!N.get(e).length));n?.forEach((t=>{setTimeout((()=>{k.add(e,t,new(D.state.MCs.get(t))(e)),e.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),e.setAttribute("_mc")}),5)}))}))}let x=!1,P=null;function D(e=!0){return e?(x=e,P=new MutationObserver(M),setTimeout((()=>{P.observe(document.body,{childList:!0,subtree:!0}),M()}),5),x):(P?.disconnect(),P=null,x)}D.state={CEs:T,MCs:N};class H extends HTMLElement{constructor(){super()}connectedCallback(){k.trigger(this,"Connected")}disconnectedCallback(){k.trigger(this,"Disconnected")}adoptedCallback(){k.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){k.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function q(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=i(e);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);k.add(this,n,r)}static get observedAttributes(){return r}}))}function $(e){return customElements.get(e)}function I(e){return null!=e&&"object"==typeof e}function V(e){let t=new Set,r=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(r))).forEach((n=>{new Set(e.getAttribute(n)?.match(r)).forEach((e=>t.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(r))).forEach((e=>{(e.nodeValue||"").match(r).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const F=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class G extends k{data={};oldDisplay="";constructor(e){super(e);let t=this;V(e).forEach((e=>t.data[e]="")),J(t),t.#o(),delete t._mc}#o(){let e=this,t=e.target,r=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((r=>{let n=new Set(t.getAttribute(r)?.match(/\{[^\{\}]*\}/g));var o;e.data.observe((o=t.getAttribute(r),e=>{let c=o;n.forEach((t=>{c=c.replace(t,e[t.replace(/[\{\}]/g,"")])})),t.setAttribute(r,c)}))})),[...t.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{r=!0;let o=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));var c;e.data.observe((c=n.nodeValue,r=>{let s=c;o.forEach((e=>{s=s.replace(e,r[e.replace(/[\{\}]/g,"")])})),Object.keys(r).some((e=>!!r[e]))&&(e.oldDisplay?t.style=e.oldDisplay:t.removeAttribute("style"),delete e.oldDisplay),n.nodeValue=s})),e.oldDisplay=t.getAttribute("style)")||"",r&&!F.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,r={};Object.keys(e.data).forEach((n=>{t.data.hasOwnProperty(n)&&(r[n]=e.data[n])})),JSON.stringify(r)!==JSON.stringify(t.data)&&Object.assign(t.data,r)}}const J=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return e;let r,n=e[t];if(!n.prototype)switch(typeof n){case"string":r=String;break;case"number":r=Number;break;case"boolean":r=Boolean;break;case"object":r=n instanceof Array?Array:Object;break;default:return}let s=class extends r{#c=!0;constructor(e){super(e),this.constructor.callbacks=[],I(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this;if(I(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!V(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||k.add(e,"_placeholders",new G(e))}))}(e);const r=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let t=o(e);r.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.constructor.callbacks.push(n),t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf(),t);return this}notify(e){let t=this,r=I(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#c=e),t.constructor.callbacks.forEach((e=>{e(r)})),t}},a=new s(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(I(a.valueOf())){let e=structuredClone(Object.assign({},a));setTimeout(l((function(){c(structuredClone(Object.assign({},a)),e)||a.notify()}),0),0)}return a},set(e){if(typeof e==typeof a.valueOf())if(I(a.valueOf())&&a.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},a));a instanceof s==0&&(a=new s(structuredClone(Object.assign({},e))),d(e,a),a.seal()),Object.assign(a,e),setTimeout(l((function(){c(structuredClone(Object.assign({},a)),t)||a.notify()}),0),0)}else{let t=a.valueOf(),r=a.constructor.callbacks;a=new s(e),a.constructor.callbacks=r,e!==t&&a.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof a.valueOf(),a,"- CANNOT BECOME:",typeof e)}}),e[t]=n})),e);class R{constructor(e){}}class B extends R{#s;constructor(e){super(e),this.#s=e}get val(){return new FormData(this.#s.form).get(this.#s.name)}set val(e){[...this.#s.form.querySelectorAll(`input[type="radio"][name="${this.#s.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class Z extends R{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.checked}set val(e){this.#s.checked=e}}class z extends R{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value}set val(e){this.#s.value=e}}class U extends R{#s;#a=!1;constructor(e){super(e),this.#s=e,this.#a=e.multiple}get val(){const e=[];return[...this.#s.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#a?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#s.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class W extends R{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value||""}set val(e){this.#s.value=e}}const Y=e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],r={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let n=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":n=new B(e);break;case"checkbox":n=new Z(e);break;default:n=new z(e)}break;case"select":n=new U(e);break;case"textarea":n=new W(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}n&&(k.add(e,t,n),Object.defineProperty(r,t,{enumerable:!0,configurable:!0,get:()=>n.val,set:e=>{n.val!==e&&(n.val=e)}}))}})),r};function K(e,t,r){let n=Y(r);e[t]=Object.assign({},n),J(e,t),d(n,e[t]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{E(r,"keyup",(r=>{e[t].notify()})),E(r,"change",(r=>{e[t].notify()})),E(r,"select",(r=>{e[t].notify()}))}))}return t})()));
|
package/dist/microcomponents.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twobirds/microcomponents",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.69",
|
|
4
4
|
"description": "Micro Components Organization Class",
|
|
5
5
|
"main": "./dist/microcomponents.ts",
|
|
6
6
|
"types": "./dist/microcomponents.d.ts",
|
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"typedoc": "typedoc",
|
|
10
10
|
"webpack": "webpack",
|
|
11
|
-
"clean": "rm -rf build/*; rm -rf dist/*; rm
|
|
12
|
-
"prep": "cp
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"clean": "rm -rf build/*; rm -rf dist/*; rm -rf public/*;",
|
|
12
|
+
"prep": "cp src/* build || true; mkdir public || true;",
|
|
13
|
+
"copyToDist1": "cp -R assets/* public || true; cp dist/*.js public; cp -R build/* public; cp build/* public/test; cp dist/microcomponents.min.js public; cp public/microcomponents.min.js public/test; mv public/test.* public/test;",
|
|
14
|
+
"copyToDist2": "mkdir public/src || true; cp -R src/*.ts public/src || true; cp -R assets/* public || true; cp -R build/*.ts* dist; cp *.svg dist; cp *.svg public/fiddle; cp dist/MicroComponents.svg public; cp public/MicroComponents.svg public/test; npm run typedoc;",
|
|
15
|
+
"build": "npm run clean; npm run prep; tsc; npm run webpack; npm run copyToDist1; npm run copyToDist2;"
|
|
15
16
|
},
|
|
16
17
|
"author": "",
|
|
17
18
|
"license": "ISC",
|
package/public/MC.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LooseObject } from './helpers.js';
|
|
2
|
+
import { McEvent } from './McEvent.js';
|
|
3
|
+
export interface HTMLMcElement extends HTMLElement {
|
|
4
|
+
_mc: LooseObject;
|
|
5
|
+
}
|
|
6
|
+
declare function addListener(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject | null, capture?: boolean, once?: boolean): void;
|
|
7
|
+
declare function removeListener(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject | null): void;
|
|
8
|
+
declare function trigger(target: HTMLElement, ev: McEvent | string, data?: any, bubble?: string): void;
|
|
9
|
+
declare class McBase {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(target?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}, debug?: boolean);
|
|
14
|
+
get target(): any;
|
|
15
|
+
}
|
|
16
|
+
declare class MC extends McBase {
|
|
17
|
+
_mc?: LooseObject;
|
|
18
|
+
constructor(target?: any);
|
|
19
|
+
static trigger: typeof trigger;
|
|
20
|
+
trigger(ev: McEvent | string, data?: any, bubble?: string): this | undefined;
|
|
21
|
+
}
|
|
22
|
+
declare class DC extends McBase {
|
|
23
|
+
_mc?: LooseObject;
|
|
24
|
+
constructor(target: HTMLElement, debug?: boolean);
|
|
25
|
+
static add: Function;
|
|
26
|
+
static remove: Function;
|
|
27
|
+
static trigger: Function;
|
|
28
|
+
trigger(ev: McEvent | string, data?: any, bubble?: string): void;
|
|
29
|
+
parent(search?: string): any[];
|
|
30
|
+
ancestors(search?: string): any[];
|
|
31
|
+
children(search?: string): any[];
|
|
32
|
+
descendants(search?: string): any[];
|
|
33
|
+
}
|
|
34
|
+
export declare function autoload(enable?: boolean): boolean;
|
|
35
|
+
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
36
|
+
//# sourceMappingURL=MC.d.ts.map
|
|
@@ -0,0 +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;AA6KD,wBAAgB,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAgBxD;AAID,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC"}
|