@twobirds/microcomponents 0.0.84 → 0.0.86
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/README.md +22 -6
- package/assets/documentation/MC.md +60 -81
- package/assets/documentation/elements.md +6 -9
- package/assets/documentation/observables.md +97 -11
- package/assets/test/{my-tag.css → myButton.css} +4 -4
- package/assets/test/test.html +1 -1
- package/dist/MC.d.ts +6 -9
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.js +40 -73
- package/dist/MC.min.js +40 -73
- package/dist/MC.ts +67 -114
- package/dist/elements.min.js +1 -1
- package/dist/formValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.min.js +1 -1
- package/package.json +2 -2
- package/public/MC.d.ts +6 -9
- package/public/MC.d.ts.map +1 -1
- package/public/MC.js +40 -73
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +40 -73
- package/public/MC.ts +67 -114
- package/public/documentation/MC.md +60 -81
- package/public/documentation/elements.md +6 -9
- package/public/documentation/observables.md +97 -11
- package/public/elements.min.js +1 -1
- package/public/formValues.min.js +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/observables.min.js +1 -1
- package/public/src/MC.d.ts +6 -9
- package/public/src/MC.d.ts.map +1 -1
- package/public/src/MC.js +40 -73
- package/public/src/MC.js.map +1 -1
- package/public/src/MC.ts +67 -114
- package/public/src/test/test/grandparent.js +1 -1
- package/public/src/test/test/testform.js +1 -1
- package/public/src/test/test.js +23 -31
- package/public/src/test/test.js.map +1 -1
- package/public/src/test/test.ts +61 -72
- package/public/test/MC.d.ts +6 -9
- package/public/test/MC.d.ts.map +1 -1
- package/public/test/MC.js +40 -73
- package/public/test/MC.min.js +40 -73
- package/public/test/MC.ts +67 -114
- package/public/test/elements.min.js +1 -1
- package/public/test/formValues.min.js +1 -1
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/{my-tag.css → myButton.css} +4 -4
- package/public/test/observables.min.js +1 -1
- package/public/test/test/grandparent.js +1 -1
- package/public/test/test/testform.js +1 -1
- package/public/test/test.html +1 -1
- package/public/test/test.js +23 -31
- package/public/test/test.js.map +1 -1
- package/public/test/test.ts +61 -72
- package/public/typedoc/assets/navigation.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +3 -4
- package/public/typedoc/classes/MC.MC.html +2 -4
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.off.html +1 -1
- package/public/typedoc/functions/MC.on.html +1 -1
- package/public/typedoc/functions/MC.one.html +1 -1
- package/public/typedoc/functions/MC.trigger.html +1 -0
- 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/index.html +21 -10
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +3 -3
- 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/types/observables.Observable.html +1 -1
- package/src/MC.ts +67 -114
- package/src/test/test.ts +61 -72
|
@@ -53,7 +53,7 @@ export type Observable = {
|
|
|
53
53
|
**Methods**
|
|
54
54
|
|
|
55
55
|
- `observe(cb: Callback)`
|
|
56
|
-
Registers a callback to be notified of changes.
|
|
56
|
+
- Registers a callback to be notified of changes.
|
|
57
57
|
|
|
58
58
|
- `notify( enable?: boolean)`
|
|
59
59
|
- Enables / Disables notifications.
|
|
@@ -62,10 +62,12 @@ export type Observable = {
|
|
|
62
62
|
- Otherwise calls all registered callbacks with the current data.
|
|
63
63
|
|
|
64
64
|
- `bind(target: HTMLElement | DocumentFragment | ShadowRoot)`
|
|
65
|
-
Binds the observable to a DOM element, replacing placeholders with data values.
|
|
65
|
+
- Binds the observable to a DOM element, replacing placeholders with data values.
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
##
|
|
68
|
+
## Examples
|
|
69
|
+
|
|
70
|
+
### How to use observables in native JS Code
|
|
69
71
|
|
|
70
72
|
HTML:
|
|
71
73
|
```html
|
|
@@ -79,23 +81,107 @@ JavaScript:
|
|
|
79
81
|
```javascript
|
|
80
82
|
import { observe } from './observables.js';
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
// define an object
|
|
85
|
+
const address = {
|
|
86
|
+
data: {
|
|
87
|
+
name: 'John',
|
|
88
|
+
age: 30,
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
otherData: {
|
|
92
|
+
whatever: true
|
|
93
|
+
}
|
|
94
|
+
|
|
85
95
|
};
|
|
86
96
|
|
|
87
|
-
|
|
97
|
+
// make all properties of the object observable
|
|
98
|
+
observe(address);
|
|
99
|
+
|
|
100
|
+
// OR: make one property of the object observable
|
|
101
|
+
observe(address, 'data');
|
|
88
102
|
|
|
103
|
+
// connect the observable to DOM structure placeholders
|
|
89
104
|
const element = document.getElementById('user-card');
|
|
90
|
-
data.bind(element);
|
|
105
|
+
address.data.bind(element);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
When `address.data.name` or `address.data.age` changes, or you reassign `address.data` completely, the DOM updates automatically.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### How to use observables in Micro Components
|
|
113
|
+
|
|
114
|
+
HTML:
|
|
115
|
+
```html
|
|
116
|
+
<div id="user-card">
|
|
117
|
+
<p>Hello, {name}</p>
|
|
118
|
+
<p>Age: {age}</p>
|
|
119
|
+
</div>
|
|
91
120
|
```
|
|
92
121
|
|
|
93
|
-
|
|
122
|
+
Micro Components are instances of classes. So you can store the class in the CustomElementRegistry:
|
|
123
|
+
|
|
124
|
+
JavaScript: (**define** the micro component)
|
|
125
|
+
`./user/card/data.js`
|
|
126
|
+
```javascript
|
|
127
|
+
import {
|
|
128
|
+
DC,
|
|
129
|
+
defineCE,
|
|
130
|
+
getCE,
|
|
131
|
+
Observable,
|
|
132
|
+
observe
|
|
133
|
+
} from './microcomponents.js';
|
|
134
|
+
|
|
135
|
+
// define the micro component
|
|
136
|
+
defineCE(
|
|
137
|
+
'user-card-data',
|
|
138
|
+
|
|
139
|
+
class UserCardData extends DC {
|
|
140
|
+
data: unknown;
|
|
141
|
+
|
|
142
|
+
constructor(target: HTMLElement, data?: { name: string = '', age: number = 0 }) {
|
|
143
|
+
super(target);
|
|
144
|
+
|
|
145
|
+
this.data = data;
|
|
146
|
+
|
|
147
|
+
// create this.data observable
|
|
148
|
+
observe(this);
|
|
149
|
+
|
|
150
|
+
// 1 way bind formdata to the form DOM
|
|
151
|
+
(this.data as Observable).bind(target);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
export default getCE('user-card-data');
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
JavaScript: (**use** the micro component)
|
|
161
|
+
```javascript
|
|
162
|
+
import {
|
|
163
|
+
getCE,
|
|
164
|
+
} from './microcomponents.js';
|
|
165
|
+
|
|
166
|
+
const element = document.getElementById('user-card');
|
|
167
|
+
const Dc = getCE('user-card-data');
|
|
168
|
+
const dc = new Dc( element, { name: 'Sarah', age: 33 } );
|
|
169
|
+
|
|
170
|
+
// add the micro component to the DOM element
|
|
171
|
+
DC.add(
|
|
172
|
+
element,
|
|
173
|
+
'userCardData',
|
|
174
|
+
dc
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// change data
|
|
178
|
+
element._mc.userCardData.data = { name: 'John', age: 27 };
|
|
179
|
+
```
|
|
94
180
|
|
|
95
181
|
---
|
|
96
182
|
|
|
97
|
-
##
|
|
183
|
+
## Hints
|
|
98
184
|
|
|
185
|
+
- Native values (strings, numbers, booleans) can be made observable.
|
|
99
186
|
- Only objects can be bound to the DOM.
|
|
100
|
-
- Native values (strings, numbers, booleans) are wrapped in observable proxies.
|
|
101
187
|
- Changes to observable properties trigger updates in bound DOM elements.
|
package/public/elements.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.elements=e():t.elements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{defineCE:()=>
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.elements=e():t.elements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{defineCE:()=>m,getCE:()=>f});const n=new Function("try {return this===window;}catch(e){ return false;}");function r(t){return t&&t instanceof HTMLElement}function o(t,e,n={}){let r=t;r._mc||(r._mc=new l(t));const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}function c(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function s(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function a(t,e,n,r=!1){t.addEventListener(s(e),n,{capture:!1,once:r})}class i{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==l&&e.trigger("Init")}),0),function(t){if(!n()||t.constructor===l)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase();if("on"+c in e){let r=e=>{n[t](e)};e.addEventListener(c,r)}else a(e,o,(e=>{n[t](e)}),r)}))}}(this)}get target(){return this._target.deref()}}class l extends i{constructor(t,e=!1){super(t)}static add=o;static remove=c;off(t,e){!function(t,e,n){t.removeEventListener(s(e),n)}(this.target,t,e)}on(t,e){a(this.target,t,e)}one(t,e){!function(t,e,n){a(t,e,n,!0)}(this.target,t,e)}trigger(t,e={},n="l"){!function(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(s(e),{detail:{data:n,bubble:r}}):e;r.length&&r.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(r)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,o)}(this.target,t,e,n)}parent(){let t=this.target;return r(t)&&t.closest("[data-mc]")?._mc||null}ancestors(){let t=this?.target,e=[];if(!r(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}children(){let t=this?.target;return r(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),r.length?r:null}(t):null}descendants(){const t=this?.target;if(!r(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}new Set;class u extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function d(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function m(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");d(e.prototype.constructor)&&e.prototype instanceof i?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends u{instance;constructor(t){super();const n=d(e)?new e(this,t):e;l.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function f(t){return customElements.get(t)}return e})()));
|
package/public/formValues.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.formValues=e():t.formValues=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.formValues=e():t.formValues=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var s;(s=t[n])&&s.constructor&&s.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let s={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=n(t[e],!1);for(const t in r)s[e+"."+t]=r[t]}else s[e]=t[e]})),e?r(s):s}function s(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function a(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}function c(t,e){const r=Object.getOwnPropertyDescriptors(t);for(const[t,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(e,t,n)}t.r(e),t.d(e,{formValues:()=>T});const o=new Function("try {return this===window;}catch(e){ return false;}");function l(t){return t&&t instanceof HTMLElement}function i(t,e,r={}){let n=t;n._mc||(n._mc=new m(t));const s=n._mc;return e.length&&!s[e]&&(s[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function u(t,e){if(!e)return;const r=t?._mc||{};r&&r[e]&&delete r[e],!Object.keys(r).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function f(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function d(t,e,r,n=!1){t.addEventListener(f(e),r,{capture:!1,once:n})}function h(t,e,r={},n="l"){const s="string"==typeof e?new CustomEvent(f(e),{detail:{data:r,bubble:n}}):e;n.length&&n.indexOf("l")>-1&&t.dispatchEvent(s),/[u|d]/.test(n)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,s)}class b{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==m&&e.trigger("Init")}),0),function(t){if(!o()||t.constructor===m)return;const e=t.target;if(e instanceof HTMLElement){let r=t;Object.getOwnPropertyNames(r.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof r.constructor.prototype[t])).forEach((t=>{let n=/^one/.test(t),s=t.replace(/^on[e]{0,1}/,""),a=s.toLowerCase();if("on"+a in e){let n=e=>{r[t](e)};e.addEventListener(a,n)}else d(e,s,(e=>{r[t](e)}),n)}))}}(this)}get target(){return this._target.deref()}}class m extends b{constructor(t,e=!1){super(t)}static add=i;static remove=u;off(t,e){!function(t,e,r){t.removeEventListener(f(e),r)}(this.target,t,e)}on(t,e){d(this.target,t,e)}one(t,e){!function(t,e,r){d(t,e,r,!0)}(this.target,t,e)}trigger(t,e={},r="l"){h(this.target,t,e,r)}parent(){let t=this.target;return l(t)&&t.closest("[data-mc]")?._mc||null}ancestors(){let t=this?.target,e=[];if(!l(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}children(){let t=this?.target;return l(t)?function(t){const e=Math.random().toString().replace(".",""),r='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const n=[...t.querySelectorAll(r)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),n.length?n:null}(t):null}descendants(){const t=this?.target;if(!l(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}function p(t){return null!=t&&"object"==typeof t}function g(t){let e=new Set,r=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(r))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(r));n.forEach((t=>n.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(r))).forEach((t=>{(t.nodeValue||"").match(r).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}new Set;const y=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class v extends m{data={};oldDisplay="";constructor(t){super(t),g(t).forEach((t=>this.data[t]="")),w(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var n;this.data.observe((n=t.getAttribute(e),s=>{let a=n;r.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,a)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{e=!0;let n=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>s=>{let a=e;n.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=a})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!y.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((r=>{this.data.hasOwnProperty(r)&&(e[r]=t.detail.data[r])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const O={};function E(t){let e=t.constructor.name;return O[e]||function(t){const e=t.constructor,r=e.name;let s=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],p(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#r}set callbacks(t){this.#r=t}observe(t){return this.#r.push(t),this}bind(t){if(p(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!g(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||m.add(t,"_placeholders",new v(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),r=function(t){let r=n(t);e.forEach((t=>{t&&h(t,"data",r)}))};this.#r.push(r),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=p(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#r.forEach((t=>{t(e)})),this}};return O[r]=s,s}(t)}const w=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let r=t[e],n=new(E(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(p(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(a((function(){s(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(p(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(E(t))(structuredClone(Object.assign({},t))),c(t,n),n.seal()),Object.assign(n,t),setTimeout(a((function(){s(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(E(t))(t),n.callbacks=r,n.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof t)}}),t[e]=r}})),t);class A{constructor(t){}}class j extends A{#n;constructor(t){super(t),this.#n=t}get val(){return new FormData(this.#n.form).get(this.#n.name)}set val(t){[...this.#n.form.querySelectorAll(`input[type="radio"][name="${this.#n.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class S extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.checked}set val(t){this.#n.checked=t}}class _ extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value}set val(t){this.#n.value=t}}class k extends A{#n;#s=!1;constructor(t){super(t),this.#n=t,this.#s=t.multiple}get val(){const t=[];return[...this.#n.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#s?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#n.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class x extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value||""}set val(t){this.#n.value=t}}const N=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],r={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let n=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":n=new j(t);break;case"checkbox":n=new S(t);break;default:n=new _(t)}break;case"select":n=new k(t);break;case"textarea":n=new x(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}n&&(m.add(t,e,n),Object.defineProperty(r,e,{enumerable:!0,configurable:!0,get:()=>n.val,set:t=>{n.val!==t&&(n.val=t)}}))}})),r};function T(t,e,r){let n=N(r);t[e]=Object.assign({},n),w(t,e),c(n,t[e]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{r.addEventListener("input",(r=>{t[e].notify()}))}))}return e})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.microcomponents=e():t.microcomponents=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t){return t&&t.constructor&&t.constructor===Object}function r(t){let e={};return[...Object.keys(t)].sort().forEach((o=>{n(t[o])?e[o]=r(t[o]):e[o]=t[o]})),e}function o(t,e=!0){let n={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=o(t[e],!1);for(const t in r)n[e+"."+t]=r[t]}else n[e]=t[e]})),e?r(n):n}function c(t,e){return JSON.stringify(o(t))===JSON.stringify(o(e))}function s(t,e={}){let n=t.constructor===String?t.split("."):t;if(e&&n[0]&&e[n[0]])return e[n[0]].constructor===Object&&n.length>1?s(n.splice(1),e[n[0]]):e[n[0]];console.warn("ns",n[0],"not in",e)}function a(t,e){var r=Array.from(arguments);if(r.length>2){for(;r.length>1;)r[0]=a(r[0],r[1]),r.splice(1,1);return r[0]}if("string"==typeof t)t.match(/\{[^\{\}]*\}/g)?.forEach((function(n){var r=s(n.substring(1,n.length-1),e);void 0!==r&&(t=t.replace(n,r))}));else if(n(t))switch(t.constructor){case Object:Object.keys(t).forEach((function(n){t.hasOwnProperty(n)&&(t[n]=a(t[n],e))}));break;case Array:t.forEach((function(n,r,o){o[r]=a(t[r],e)}))}return t}function i(t){return t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function l(t,e){let n;return()=>{clearTimeout(n),n=setTimeout((function(){t(...arguments)}),e)}}function u(t){let e=document.createElement("template");return t=t.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),e.innerHTML=t,e.content.normalize(),Array.from(e.content.childNodes)}function d(t,e){const n=Object.getOwnPropertyDescriptors(t);for(const[t,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(e,t,r)}t.r(e),t.d(e,{DC:()=>C,MC:()=>j,McBase:()=>A,autoload:()=>x,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>c,defineCE:()=>D,flattenObject:()=>o,formValues:()=>K,getCE:()=>q,htmlToElements:()=>u,isNativeObject:()=>n,kebabToPascal:()=>i,nameSpace:()=>s,observe:()=>G,off:()=>v,on:()=>E,one:()=>O,parse:()=>a,sortObject:()=>r,trigger:()=>w});var f=new Function("try {return this===window;}catch(e){ return false;}");function h(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function m(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function p(t){return t&&t instanceof HTMLElement}function b(t,e,n={}){let r=t;if(!r._mc){let e=C?.debug;C.debug=!1,r._mc=new C(t),C.debug=e,delete r._mc._mc}const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function g(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function y(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function v(t,e,n){t.removeEventListener(y(e),n)}function E(t,e,n,r=!1){t.addEventListener(y(e),n,{capture:!1,once:r})}function O(t,e,n){E(t,e,n,!0)}function w(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(y(e),{detail:{data:n,bubble:r}}):e;r.length&&r.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(r)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&C.trigger(t,e)}))}),0)}(t,o)}class A{_target;constructor(t,e=!1){var n;this._target=new WeakRef(t||{}),(n=this).constructor!==C&&setTimeout((()=>{n.trigger("Init")}),0),function(t){if(!f()||t.constructor===C)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase(),s=e=>{n[t](e)};e["on"+c]?e.addEventListener(c,s):E(e,o,s,r)}))}}(this)}get target(){return this._target.deref()}}class j extends A{constructor(t){super(t)}static trigger=w;trigger(t,e={},n="l"){}}class C extends A{constructor(t,e=!1){super(t)}static add=b;static remove=g;static trigger=w;off(t,e){v(this.target,t,e)}on(t,e){E(this.target,t,e)}one(t,e){O(this.target,t,e)}trigger(t,e={},n="l"){}parent(t=""){let e=this.target;return p(e)?m(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return p(e)?m(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;return p(e)?h([...function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=t.querySelectorAll(n);return t.removeAttribute("temp_id"),r}(e)],t):[]}descendants(t=""){let e=this?.target;return p(e)?h([...e.querySelectorAll("*[data-mc]")],t):[]}}const S=new Set;function k(t){return()=>{const e=Array.from(document.querySelectorAll(`[data-mc*="${t}"]`)).filter((t=>t instanceof HTMLElement));if(0===e.length)return;const n=customElements.get(t);e.forEach((e=>{C.add(e,n.name,new n(e));const r=e.getAttribute("data-mc").split(" ").filter((e=>e!==t&&""!==e)).join(" ").trim();e.setAttribute("data-mc",r)}))}}function _(t){if(S.has(t))return;S.add(t);const e="./"+t.split("-").join("/")+".js",n=document.createElement("script");n.setAttribute("src",e),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("data-name",t),n.setAttribute("loading",""),customElements.whenDefined(t).then(k(t)),n.addEventListener("load",(e=>{S.delete(t),document.head.querySelector(`script[data-name="${t}"]`)?.remove()})),n.addEventListener("error",(t=>{console.error("could not load DC code from",e)})),document.head.append(n)}function N(){[...document.querySelectorAll(":not(:defined)")].filter((t=>!!t&&!customElements.get(t.tagName.toLowerCase())&&!S.has(t.tagName.toLowerCase()))).forEach((t=>{_(t.tagName.toLowerCase())})),[...document.querySelectorAll('[data-mc]:not([data-mc=""]')].filter((t=>!!t)).forEach((t=>{const e=t.getAttribute("data-mc")?.split(" ").filter((t=>""!==t));e?.forEach((t=>{const e=customElements.get(t);S.has(t)||e?e&&k(t)():_(t)}))}))}let T=!1,L=null;function x(t=!0){return t?(T=t,L=new MutationObserver(N),setTimeout((()=>{L.observe(document.body,{childList:!0,subtree:!0}),N()}),5),window.autoload=window.autoload||x,T):(L?.disconnect(),L=null,T)}x.state=S;class M extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function P(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function D(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=i(t);P(e.prototype.constructor)&&e.prototype instanceof A?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends M{instance;constructor(t){super();const n=P(e)?new e(this,t):e;C.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function q(t){return customElements.get(t)}function H(t){return null!=t&&"object"==typeof t}function V(t){let e=new Set,n=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(n))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(n));r.forEach((t=>r.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(n))).forEach((t=>{(t.nodeValue||"").match(n).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}const I=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class $ extends C{data={};oldDisplay="";constructor(t){super(t),V(t).forEach((t=>this.data[t]="")),G(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var r;this.data.observe((r=t.getAttribute(e),o=>{let c=r;n.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,c)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{e=!0;let r=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>o=>{let c=e;r.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=c})(n.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!I.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(e[n]=t.detail.data[n])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const R={};function F(t){let e=t.constructor.name;return R[e]||function(t){const e=t.constructor,n=e.name;let r=class extends e{#e=!0;#n=[];constructor(t){super(t),this.constructor.callbacks=[],H(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#n}set callbacks(t){this.#n=t}observe(t){return this.#n.push(t),this}bind(t){if(H(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!V(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||C.add(t,"_placeholders",new $(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),n=function(t){let n=o(t);e.forEach((t=>{t&&w(t,"data",n)}))};this.#n.push(n),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=H(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#n.forEach((t=>{t(e)})),this}};return R[n]=r,r}(t)}const G=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let n=t[e],r=new(F(n))(n);Object.defineProperty(t,e,{enumerable:!0,get(){if(H(r.valueOf())){let t=structuredClone(Object.assign({},r));setTimeout(l((function(){c(structuredClone(Object.assign({},r)),t)||r.notify()}),0),0)}return r},set(t){if(typeof t==typeof r.valueOf())if(H(r.valueOf())&&r.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},r));void 0===r?.constructor?.prototype?.observe&&(r=new(F(t))(structuredClone(Object.assign({},t))),d(t,r),r.seal()),Object.assign(r,t),setTimeout(l((function(){c(structuredClone(Object.assign({},r)),e)||r.notify()}),0),0)}else{let e=r.valueOf(),n=r.callbacks;t!==e&&(r=new(F(t))(t),r.callbacks=n,r.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof t)}}),t[e]=n}})),t);class J{constructor(t){}}class Z extends J{#r;constructor(t){super(t),this.#r=t}get val(){return new FormData(this.#r.form).get(this.#r.name)}set val(t){[...this.#r.form.querySelectorAll(`input[type="radio"][name="${this.#r.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class z extends J{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.checked}set val(t){this.#r.checked=t}}class B extends J{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value}set val(t){this.#r.value=t}}class U extends J{#r;#o=!1;constructor(t){super(t),this.#r=t,this.#o=t.multiple}get val(){const t=[];return[...this.#r.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#o?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#r.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class W extends J{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value||""}set val(t){this.#r.value=t}}const Y=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],n={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let r=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":r=new Z(t);break;case"checkbox":r=new z(t);break;default:r=new B(t)}break;case"select":r=new U(t);break;case"textarea":r=new W(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}r&&(C.add(t,e,r),Object.defineProperty(n,e,{enumerable:!0,configurable:!0,get:()=>r.val,set:t=>{r.val!==t&&(r.val=t)}}))}})),n};function K(t,e,n){let r=Y(n);t[e]=Object.assign({},r),G(t,e),d(r,t[e]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{t[e].notify()}))}))}return e})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.microcomponents=e():t.microcomponents=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t){return t&&t.constructor&&t.constructor===Object}function r(t){let e={};return[...Object.keys(t)].sort().forEach((o=>{n(t[o])?e[o]=r(t[o]):e[o]=t[o]})),e}function o(t,e=!0){let n={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=o(t[e],!1);for(const t in r)n[e+"."+t]=r[t]}else n[e]=t[e]})),e?r(n):n}function c(t,e){return JSON.stringify(o(t))===JSON.stringify(o(e))}function s(t,e={}){let n=t.constructor===String?t.split("."):t;if(e&&n[0]&&e[n[0]])return e[n[0]].constructor===Object&&n.length>1?s(n.splice(1),e[n[0]]):e[n[0]];console.warn("ns",n[0],"not in",e)}function a(t,e){var r=Array.from(arguments);if(r.length>2){for(;r.length>1;)r[0]=a(r[0],r[1]),r.splice(1,1);return r[0]}if("string"==typeof t)t.match(/\{[^\{\}]*\}/g)?.forEach((function(n){var r=s(n.substring(1,n.length-1),e);void 0!==r&&(t=t.replace(n,r))}));else if(n(t))switch(t.constructor){case Object:Object.keys(t).forEach((function(n){t.hasOwnProperty(n)&&(t[n]=a(t[n],e))}));break;case Array:t.forEach((function(n,r,o){o[r]=a(t[r],e)}))}return t}function i(t){return t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function l(t,e){let n;return()=>{clearTimeout(n),n=setTimeout((function(){t(...arguments)}),e)}}function u(t){let e=document.createElement("template");return t=t.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),e.innerHTML=t,e.content.normalize(),Array.from(e.content.childNodes)}function d(t,e){const n=Object.getOwnPropertyDescriptors(t);for(const[t,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(e,t,r)}t.r(e),t.d(e,{DC:()=>A,MC:()=>w,McBase:()=>O,autoload:()=>T,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>c,defineCE:()=>M,flattenObject:()=>o,formValues:()=>W,getCE:()=>P,htmlToElements:()=>u,isNativeObject:()=>n,kebabToPascal:()=>i,nameSpace:()=>s,observe:()=>R,off:()=>g,on:()=>y,one:()=>v,parse:()=>a,sortObject:()=>r,trigger:()=>E});const f=new Function("try {return this===window;}catch(e){ return false;}");function m(t){return t&&t instanceof HTMLElement}function h(t,e,n={}){let r=t;r._mc||(r._mc=new A(t));const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}function p(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function b(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function g(t,e,n){t.removeEventListener(b(e),n)}function y(t,e,n,r=!1){t.addEventListener(b(e),n,{capture:!1,once:r})}function v(t,e,n){y(t,e,n,!0)}function E(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(b(e),{detail:{data:n,bubble:r}}):e;r.length&&r.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(r)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,o)}class O{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==A&&e.trigger("Init")}),0),function(t){if(!f()||t.constructor===A)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase();if("on"+c in e){let r=e=>{n[t](e)};e.addEventListener(c,r)}else y(e,o,(e=>{n[t](e)}),r)}))}}(this)}get target(){return this._target.deref()}}class w extends O{constructor(t){super(t)}}class A extends O{constructor(t,e=!1){super(t)}static add=h;static remove=p;off(t,e){g(this.target,t,e)}on(t,e){y(this.target,t,e)}one(t,e){v(this.target,t,e)}trigger(t,e={},n="l"){E(this.target,t,e,n)}parent(){let t=this.target;return m(t)&&t.closest("[data-mc]")?._mc||null}ancestors(){let t=this?.target,e=[];if(!m(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}children(){let t=this?.target;return m(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),r.length?r:null}(t):null}descendants(){const t=this?.target;if(!m(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}const j=new Set;function C(t){return()=>{const e=Array.from(document.querySelectorAll(`[data-mc*="${t}"]`)).filter((t=>t instanceof HTMLElement));if(0===e.length)return;const n=customElements.get(t);e.forEach((e=>{A.add(e,n.name,new n(e));const r=e.getAttribute("data-mc").split(" ").filter((e=>e!==t&&""!==e)).join(" ").trim();e.setAttribute("data-mc",r)}))}}function S(t){if(j.has(t))return;j.add(t);const e="./"+t.split("-").join("/")+".js",n=document.createElement("script");n.setAttribute("src",e),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("data-name",t),n.setAttribute("loading",""),customElements.whenDefined(t).then(C(t)),n.addEventListener("load",(e=>{j.delete(t),document.head.querySelector(`script[data-name="${t}"]`)?.remove()})),n.addEventListener("error",(t=>{console.error("could not load DC code from",e)})),document.head.append(n)}function k(){[...document.querySelectorAll(":not(:defined)")].filter((t=>!!t&&!customElements.get(t.tagName.toLowerCase())&&!j.has(t.tagName.toLowerCase()))).forEach((t=>{S(t.tagName.toLowerCase())})),[...document.querySelectorAll('[data-mc]:not([data-mc=""]')].filter((t=>!!t)).forEach((t=>{const e=t.getAttribute("data-mc")?.split(" ").filter((t=>""!==t));e?.forEach((t=>{const e=customElements.get(t);j.has(t)||e?e&&C(t)():S(t)}))}))}let _=!1,N=null;function T(t=!0){return t?(_=t,N=new MutationObserver(k),setTimeout((()=>{N.observe(document.body,{childList:!0,subtree:!0}),k()}),5),window.autoload=window.autoload||T,_):(N?.disconnect(),N=null,_)}T.state=j;class x extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function L(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function M(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=i(t);L(e.prototype.constructor)&&e.prototype instanceof O?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends x{instance;constructor(t){super();const n=L(e)?new e(this,t):e;A.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function P(t){return customElements.get(t)}function D(t){return null!=t&&"object"==typeof t}function q(t){let e=new Set,n=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(n))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(n));r.forEach((t=>r.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(n))).forEach((t=>{(t.nodeValue||"").match(n).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}const H=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class V extends A{data={};oldDisplay="";constructor(t){super(t),q(t).forEach((t=>this.data[t]="")),R(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var r;this.data.observe((r=t.getAttribute(e),o=>{let c=r;n.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,c)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{e=!0;let r=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>o=>{let c=e;r.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=c})(n.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!H.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(e[n]=t.detail.data[n])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const I={};function $(t){let e=t.constructor.name;return I[e]||function(t){const e=t.constructor,n=e.name;let r=class extends e{#e=!0;#n=[];constructor(t){super(t),this.constructor.callbacks=[],D(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#n}set callbacks(t){this.#n=t}observe(t){return this.#n.push(t),this}bind(t){if(D(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!q(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||A.add(t,"_placeholders",new V(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),n=function(t){let n=o(t);e.forEach((t=>{t&&E(t,"data",n)}))};this.#n.push(n),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=D(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#n.forEach((t=>{t(e)})),this}};return I[n]=r,r}(t)}const R=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let n=t[e],r=new($(n))(n);Object.defineProperty(t,e,{enumerable:!0,get(){if(D(r.valueOf())){let t=structuredClone(Object.assign({},r));setTimeout(l((function(){c(structuredClone(Object.assign({},r)),t)||r.notify()}),0),0)}return r},set(t){if(typeof t==typeof r.valueOf())if(D(r.valueOf())&&r.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},r));void 0===r?.constructor?.prototype?.observe&&(r=new($(t))(structuredClone(Object.assign({},t))),d(t,r),r.seal()),Object.assign(r,t),setTimeout(l((function(){c(structuredClone(Object.assign({},r)),e)||r.notify()}),0),0)}else{let e=r.valueOf(),n=r.callbacks;t!==e&&(r=new($(t))(t),r.callbacks=n,r.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof t)}}),t[e]=n}})),t);class F{constructor(t){}}class G extends F{#r;constructor(t){super(t),this.#r=t}get val(){return new FormData(this.#r.form).get(this.#r.name)}set val(t){[...this.#r.form.querySelectorAll(`input[type="radio"][name="${this.#r.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class J extends F{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.checked}set val(t){this.#r.checked=t}}class Z extends F{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value}set val(t){this.#r.value=t}}class z extends F{#r;#o=!1;constructor(t){super(t),this.#r=t,this.#o=t.multiple}get val(){const t=[];return[...this.#r.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#o?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#r.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class B extends F{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value||""}set val(t){this.#r.value=t}}const U=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],n={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let r=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":r=new G(t);break;case"checkbox":r=new J(t);break;default:r=new Z(t)}break;case"select":r=new z(t);break;case"textarea":r=new B(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}r&&(A.add(t,e,r),Object.defineProperty(n,e,{enumerable:!0,configurable:!0,get:()=>r.val,set:t=>{r.val!==t&&(r.val=t)}}))}})),n};function W(t,e,n){let r=U(n);t[e]=Object.assign({},r),R(t,e),d(r,t[e]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{t[e].notify()}))}))}return e})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.observables=e():t.observables=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var o;(o=t[n])&&o.constructor&&o.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let o={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=n(t[e],!1);for(const t in r)o[e+"."+t]=r[t]}else o[e]=t[e]})),e?r(o):o}function o(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function c(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}t.r(e),t.d(e,{observe:()=>
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.observables=e():t.observables=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var o;(o=t[n])&&o.constructor&&o.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let o={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=n(t[e],!1);for(const t in r)o[e+"."+t]=r[t]}else o[e]=t[e]})),e?r(o):o}function o(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function c(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}t.r(e),t.d(e,{observe:()=>E});const a=new Function("try {return this===window;}catch(e){ return false;}");function s(t){return t&&t instanceof HTMLElement}function i(t,e,r={}){let n=t;n._mc||(n._mc=new b(t));const o=n._mc;return e.length&&!o[e]&&(o[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function l(t,e){if(!e)return;const r=t?._mc||{};r&&r[e]&&delete r[e],!Object.keys(r).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function u(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function f(t,e,r,n=!1){t.addEventListener(u(e),r,{capture:!1,once:n})}function d(t,e,r={},n="l"){const o="string"==typeof e?new CustomEvent(u(e),{detail:{data:r,bubble:n}}):e;n.length&&n.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(n)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,o)}class h{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==b&&e.trigger("Init")}),0),function(t){if(!a()||t.constructor===b)return;const e=t.target;if(e instanceof HTMLElement){let r=t;Object.getOwnPropertyNames(r.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof r.constructor.prototype[t])).forEach((t=>{let n=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase();if("on"+c in e){let n=e=>{r[t](e)};e.addEventListener(c,n)}else f(e,o,(e=>{r[t](e)}),n)}))}}(this)}get target(){return this._target.deref()}}class b extends h{constructor(t,e=!1){super(t)}static add=i;static remove=l;off(t,e){!function(t,e,r){t.removeEventListener(u(e),r)}(this.target,t,e)}on(t,e){f(this.target,t,e)}one(t,e){!function(t,e,r){f(t,e,r,!0)}(this.target,t,e)}trigger(t,e={},r="l"){d(this.target,t,e,r)}parent(){let t=this.target;return s(t)&&t.closest("[data-mc]")?._mc||null}ancestors(){let t=this?.target,e=[];if(!s(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}children(){let t=this?.target;return s(t)?function(t){const e=Math.random().toString().replace(".",""),r='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const n=[...t.querySelectorAll(r)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),n.length?n:null}(t):null}descendants(){const t=this?.target;if(!s(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}function m(t){return null!=t&&"object"==typeof t}function p(t){let e=new Set,r=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(r))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(r));n.forEach((t=>n.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(r))).forEach((t=>{(t.nodeValue||"").match(r).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}new Set;const g=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class y extends b{data={};oldDisplay="";constructor(t){super(t),p(t).forEach((t=>this.data[t]="")),E(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var n;this.data.observe((n=t.getAttribute(e),o=>{let c=n;r.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,c)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{e=!0;let n=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>o=>{let c=e;n.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=c})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!g.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((r=>{this.data.hasOwnProperty(r)&&(e[r]=t.detail.data[r])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const O={};function v(t){let e=t.constructor.name;return O[e]||function(t){const e=t.constructor,r=e.name;let o=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],m(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#r}set callbacks(t){this.#r=t}observe(t){return this.#r.push(t),this}bind(t){if(m(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!p(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||b.add(t,"_placeholders",new y(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),r=function(t){let r=n(t);e.forEach((t=>{t&&d(t,"data",r)}))};this.#r.push(r),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=m(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#r.forEach((t=>{t(e)})),this}};return O[r]=o,o}(t)}const E=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let r=t[e],n=new(v(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(m(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(c((function(){o(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(m(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(v(t))(structuredClone(Object.assign({},t))),function(t,e){const r=Object.getOwnPropertyDescriptors(t);for(const[t,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(e,t,n)}(t,n),n.seal()),Object.assign(n,t),setTimeout(c((function(){o(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(v(t))(t),n.callbacks=r,n.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof t)}}),t[e]=r}})),t);return e})()));
|
package/public/src/MC.d.ts
CHANGED
|
@@ -10,27 +10,24 @@ declare class McBase {
|
|
|
10
10
|
private _target;
|
|
11
11
|
constructor(target?: {
|
|
12
12
|
[key: string]: any;
|
|
13
|
-
}
|
|
13
|
+
});
|
|
14
14
|
get target(): any;
|
|
15
15
|
}
|
|
16
16
|
declare class MC extends McBase {
|
|
17
17
|
constructor(target?: any);
|
|
18
|
-
static trigger: typeof trigger;
|
|
19
|
-
trigger(ev: string, data?: any, bubble?: string): void;
|
|
20
18
|
}
|
|
21
19
|
declare class DC extends McBase {
|
|
22
20
|
constructor(target: HTMLElement, debug?: boolean);
|
|
23
21
|
static add: Function;
|
|
24
22
|
static remove: Function;
|
|
25
|
-
static trigger: Function;
|
|
26
23
|
off(eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
27
24
|
on(eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
28
25
|
one(eventName: string, handler: EventListenerOrEventListenerObject): void;
|
|
29
|
-
trigger(
|
|
30
|
-
parent(
|
|
31
|
-
ancestors(
|
|
32
|
-
children(
|
|
33
|
-
descendants(
|
|
26
|
+
trigger(eventName: string, data?: any, bubble?: string): void;
|
|
27
|
+
parent(): DC | null;
|
|
28
|
+
ancestors(): DC[] | null;
|
|
29
|
+
children(): DC[] | null;
|
|
30
|
+
descendants(): DC[] | null;
|
|
34
31
|
}
|
|
35
32
|
declare function autoload(enable?: boolean): boolean;
|
|
36
33
|
export { McBase, MC, DC, autoload, on, one, off, trigger };
|
package/public/src/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;AAiB3C,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAiB3C,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AAmED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,QAE1F;AAED,iBAAS,EAAE,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,EAAE,IAAI,GAAE,OAAe,QAEhH;AAED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,QAE1F;AAGD,iBAAS,OAAO,CACf,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,WAAW,GAAG,MAAM,EAC3B,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAepB;AA+ED,cAAM,MAAM;IACX,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAU3C,IAAI,MAAM,IAAI,GAAG,CAEhB;CAED;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,CAAC,EAAE,GAAG;CAGxB;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IAGjC,GAAG,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAInE,EAAE,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAIlE,GAAG,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAInE,OAAO,CAAE,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;IAKhE,MAAM,IAAI,EAAE,GAAG,IAAI;IAOnB,SAAS,IAAI,EAAE,EAAE,GAAG,IAAI;IAgBxB,QAAQ,IAAI,EAAE,EAAE,GAAG,IAAI;IAMvB,WAAW,IAAI,EAAE,EAAE,GAAG,IAAI;CAS1B;AAiHD,iBAAS,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAmBjD;AAID,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC"}
|
package/public/src/MC.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
const isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
|
|
3
3
|
function getNativeEventNames(domNode) {
|
|
4
4
|
let nativeEventNames = [];
|
|
5
5
|
if (isBrowser()) {
|
|
@@ -9,51 +9,13 @@ function getNativeEventNames(domNode) {
|
|
|
9
9
|
}
|
|
10
10
|
return nativeEventNames;
|
|
11
11
|
}
|
|
12
|
-
function getMicroComponents(elements, search) {
|
|
13
|
-
let mcValues = [];
|
|
14
|
-
elements.forEach((e) => {
|
|
15
|
-
if (e) {
|
|
16
|
-
if (e instanceof HTMLElement) {
|
|
17
|
-
const _mc = e?._mc;
|
|
18
|
-
if (!search && _mc) {
|
|
19
|
-
mcValues = mcValues.concat(Object.values(e._mc));
|
|
20
|
-
}
|
|
21
|
-
else if (search && _mc && _mc[search]) {
|
|
22
|
-
mcValues.push(_mc[search]);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return mcValues;
|
|
28
|
-
}
|
|
29
|
-
function traverseNodes(node, search, firstonly = true) {
|
|
30
|
-
let mcValues = [];
|
|
31
|
-
while (node) {
|
|
32
|
-
if (node._mc) {
|
|
33
|
-
if (!search) {
|
|
34
|
-
mcValues = mcValues.concat(Object.values(node._mc));
|
|
35
|
-
}
|
|
36
|
-
else if (search && node._mc[search]) {
|
|
37
|
-
mcValues.push(node._mc[search]);
|
|
38
|
-
}
|
|
39
|
-
if (firstonly)
|
|
40
|
-
return mcValues;
|
|
41
|
-
}
|
|
42
|
-
node = node.parentNode;
|
|
43
|
-
}
|
|
44
|
-
return mcValues;
|
|
45
|
-
}
|
|
46
12
|
function isDOM(element) {
|
|
47
13
|
return element && element instanceof HTMLElement;
|
|
48
14
|
}
|
|
49
15
|
function add(target, key, element = {}) {
|
|
50
16
|
let node = target;
|
|
51
17
|
if (!node._mc) {
|
|
52
|
-
let debug = DC?.debug;
|
|
53
|
-
DC.debug = false;
|
|
54
18
|
node._mc = new DC(target);
|
|
55
|
-
DC.debug = debug;
|
|
56
|
-
delete node._mc._mc;
|
|
57
19
|
}
|
|
58
20
|
const _mc = node._mc;
|
|
59
21
|
if (key.length && !_mc[key]) {
|
|
@@ -62,7 +24,7 @@ function add(target, key, element = {}) {
|
|
|
62
24
|
target.setAttribute('data-mc', '');
|
|
63
25
|
}
|
|
64
26
|
}
|
|
65
|
-
return
|
|
27
|
+
return node;
|
|
66
28
|
}
|
|
67
29
|
function remove(target, key) {
|
|
68
30
|
if (!key)
|
|
@@ -79,9 +41,9 @@ function remove(target, key) {
|
|
|
79
41
|
return;
|
|
80
42
|
}
|
|
81
43
|
function init(element) {
|
|
82
|
-
if (element.constructor === DC)
|
|
83
|
-
return;
|
|
84
44
|
setTimeout(() => {
|
|
45
|
+
if (element.constructor === DC)
|
|
46
|
+
return;
|
|
85
47
|
element.trigger('Init');
|
|
86
48
|
}, 0);
|
|
87
49
|
}
|
|
@@ -122,7 +84,7 @@ function bubbleEvent(domNode, ev) {
|
|
|
122
84
|
.map((c) => c?.target));
|
|
123
85
|
targets.forEach((target) => {
|
|
124
86
|
if (target)
|
|
125
|
-
|
|
87
|
+
target._mc.trigger(target, ev);
|
|
126
88
|
});
|
|
127
89
|
}
|
|
128
90
|
}, 0);
|
|
@@ -138,13 +100,16 @@ function autoAttachListeners(element) {
|
|
|
138
100
|
typeof that.constructor.prototype[key] === 'function')
|
|
139
101
|
.forEach((key) => {
|
|
140
102
|
let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), nativeEventName = withoutOnOne.toLowerCase();
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
103
|
+
if (('on' + nativeEventName) in target) {
|
|
104
|
+
let listener = (ev) => {
|
|
105
|
+
that[key](ev);
|
|
106
|
+
};
|
|
145
107
|
target.addEventListener(nativeEventName, listener);
|
|
146
108
|
}
|
|
147
109
|
else {
|
|
110
|
+
let listener = (ev) => {
|
|
111
|
+
that[key](ev);
|
|
112
|
+
};
|
|
148
113
|
on(target, withoutOnOne, listener, once);
|
|
149
114
|
}
|
|
150
115
|
});
|
|
@@ -154,13 +119,15 @@ function getMcChildNodes(domNode) {
|
|
|
154
119
|
const id = Math.random().toString().replace('.', '');
|
|
155
120
|
const selector = '[data-mc]:not([temp_id="' + id + '"] [data-mc] [data-mc])';
|
|
156
121
|
domNode.setAttribute('temp_id', id);
|
|
157
|
-
const
|
|
122
|
+
const mcArray = [...domNode.querySelectorAll(selector)]
|
|
123
|
+
.filter((e) => !!e._mc)
|
|
124
|
+
.map(e => e._mc);
|
|
158
125
|
domNode.removeAttribute('temp_id');
|
|
159
|
-
return
|
|
126
|
+
return mcArray.length ? mcArray : null;
|
|
160
127
|
}
|
|
161
128
|
class McBase {
|
|
162
129
|
_target;
|
|
163
|
-
constructor(target
|
|
130
|
+
constructor(target) {
|
|
164
131
|
let element = this;
|
|
165
132
|
this._target = new WeakRef(target || {});
|
|
166
133
|
init(element);
|
|
@@ -174,9 +141,6 @@ class MC extends McBase {
|
|
|
174
141
|
constructor(target) {
|
|
175
142
|
super(target);
|
|
176
143
|
}
|
|
177
|
-
static trigger = trigger;
|
|
178
|
-
trigger(ev, data = {}, bubble = 'l') {
|
|
179
|
-
}
|
|
180
144
|
}
|
|
181
145
|
class DC extends McBase {
|
|
182
146
|
constructor(target, debug = false) {
|
|
@@ -184,7 +148,6 @@ class DC extends McBase {
|
|
|
184
148
|
}
|
|
185
149
|
static add = add;
|
|
186
150
|
static remove = remove;
|
|
187
|
-
static trigger = trigger;
|
|
188
151
|
off(eventName, handler) {
|
|
189
152
|
off(this.target, eventName, handler);
|
|
190
153
|
}
|
|
@@ -194,36 +157,40 @@ class DC extends McBase {
|
|
|
194
157
|
one(eventName, handler) {
|
|
195
158
|
one(this.target, eventName, handler);
|
|
196
159
|
}
|
|
197
|
-
trigger(
|
|
198
|
-
|
|
199
|
-
}
|
|
160
|
+
trigger(eventName, data = {}, bubble = 'l') {
|
|
161
|
+
trigger(this.target, eventName, data, bubble);
|
|
200
162
|
}
|
|
201
|
-
parent(
|
|
163
|
+
parent() {
|
|
202
164
|
let target = this.target;
|
|
203
165
|
if (!isDOM(target))
|
|
204
|
-
return
|
|
205
|
-
return
|
|
166
|
+
return null;
|
|
167
|
+
return target.closest('[data-mc]')?._mc || null;
|
|
206
168
|
}
|
|
207
|
-
ancestors(
|
|
208
|
-
let
|
|
209
|
-
if (!isDOM(
|
|
169
|
+
ancestors() {
|
|
170
|
+
let currentNode = this?.target, result = [];
|
|
171
|
+
if (!isDOM(currentNode))
|
|
210
172
|
return [];
|
|
211
|
-
|
|
173
|
+
while (currentNode = (currentNode.closest('[data-mc]'))) {
|
|
174
|
+
if (currentNode?._mc) {
|
|
175
|
+
result.push(currentNode?._mc);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return result.length ? result : null;
|
|
212
179
|
}
|
|
213
|
-
children(
|
|
180
|
+
children() {
|
|
214
181
|
let target = this?.target;
|
|
215
182
|
if (!isDOM(target))
|
|
216
|
-
return
|
|
217
|
-
|
|
218
|
-
const mcValues = getMicroComponents([...myDomElements], search);
|
|
219
|
-
return mcValues;
|
|
183
|
+
return null;
|
|
184
|
+
return getMcChildNodes(target);
|
|
220
185
|
}
|
|
221
|
-
descendants(
|
|
222
|
-
|
|
186
|
+
descendants() {
|
|
187
|
+
const target = this?.target;
|
|
223
188
|
if (!isDOM(target))
|
|
224
189
|
return [];
|
|
225
|
-
const
|
|
226
|
-
|
|
190
|
+
const mcArray = [...target.querySelectorAll('[data-mc]')]
|
|
191
|
+
.filter((e) => !!e._mc)
|
|
192
|
+
.map(e => e._mc);
|
|
193
|
+
return mcArray.length ? mcArray : null;
|
|
227
194
|
}
|
|
228
195
|
}
|
|
229
196
|
const loadingDCs = new Set();
|