@twobirds/microcomponents 0.1.16 → 0.1.19
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/dist/MC.ts +345 -346
- package/dist/elements.ts +80 -96
- package/dist/formValues.ts +165 -171
- package/dist/helpers.ts +100 -100
- package/dist/observables.ts +295 -325
- package/package.json +4 -3
- package/dist/MC.d.ts +0 -39
- package/dist/MC.d.ts.map +0 -1
- package/dist/MC.js +0 -302
- package/dist/MC.min.js +0 -345
- package/dist/elements.d.ts +0 -5
- package/dist/elements.d.ts.map +0 -1
- package/dist/elements.js +0 -67
- package/dist/elements.min.js +0 -1
- package/dist/formValues.d.ts +0 -3
- package/dist/formValues.d.ts.map +0 -1
- package/dist/formValues.js +0 -159
- package/dist/formValues.min.js +0 -1
- package/dist/helpers.d.ts +0 -14
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js +0 -111
- package/dist/microcomponents.d.ts +0 -6
- package/dist/microcomponents.d.ts.map +0 -1
- package/dist/microcomponents.js +0 -6
- package/dist/microcomponents.min.js +0 -1
- package/dist/observables.d.ts +0 -11
- package/dist/observables.d.ts.map +0 -1
- package/dist/observables.js +0 -234
- package/dist/observables.min.js +0 -1
package/dist/helpers.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
export function isNativeObject(value) {
|
|
3
|
-
return value && value['constructor'] && value.constructor === Object;
|
|
4
|
-
}
|
|
5
|
-
export function sortObject(o) {
|
|
6
|
-
let result = {}, keys = [...Object.keys(o)].sort();
|
|
7
|
-
keys.forEach((key) => {
|
|
8
|
-
if (isNativeObject(o[key])) {
|
|
9
|
-
result[key] = sortObject(o[key]);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
result[key] = o[key];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
export function flattenObject(o, doSort = true) {
|
|
18
|
-
let result = {};
|
|
19
|
-
[...Object.getOwnPropertyNames(o)].forEach((propName) => {
|
|
20
|
-
if (o[propName] instanceof Object) {
|
|
21
|
-
const temp = flattenObject(o[propName], false);
|
|
22
|
-
result[propName] = {};
|
|
23
|
-
for (const j in temp) {
|
|
24
|
-
result[propName + '.' + j] = temp[j];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
result[propName] = o[propName];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return doSort ? sortObject(result) : result;
|
|
32
|
-
}
|
|
33
|
-
export function deepEqual(o1, o2) {
|
|
34
|
-
return JSON.stringify(flattenObject(o1)) === JSON.stringify(flattenObject(o2));
|
|
35
|
-
}
|
|
36
|
-
export function nameSpace(ns, obj = {}) {
|
|
37
|
-
let nsa = ns.constructor === String ? ns.split('.') : ns;
|
|
38
|
-
if (!obj || !nsa[0] || !obj[nsa[0]]) {
|
|
39
|
-
console.warn('ns', nsa[0], 'not in', obj);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (obj[nsa[0]].constructor === Object && nsa.length > 1) {
|
|
43
|
-
return nameSpace(nsa.splice(1), obj[nsa[0]]);
|
|
44
|
-
}
|
|
45
|
-
return obj[nsa[0]];
|
|
46
|
-
}
|
|
47
|
-
export function parse(what, parseThis) {
|
|
48
|
-
var args = Array.from(arguments);
|
|
49
|
-
if (args.length > 2) {
|
|
50
|
-
while (args.length > 1) {
|
|
51
|
-
args[0] = parse(args[0], args[1]);
|
|
52
|
-
args.splice(1, 1);
|
|
53
|
-
}
|
|
54
|
-
return args[0];
|
|
55
|
-
}
|
|
56
|
-
if (typeof what === 'string') {
|
|
57
|
-
what.match(/\{[^\{\}]*\}/g)?.forEach(function (pPropname) {
|
|
58
|
-
var propname = pPropname.substring(1, pPropname.length - 1), value = nameSpace(propname, parseThis);
|
|
59
|
-
if (typeof value !== 'undefined') {
|
|
60
|
-
what = what.replace(pPropname, value);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else if (isNativeObject(what)) {
|
|
65
|
-
switch (what.constructor) {
|
|
66
|
-
case Object:
|
|
67
|
-
Object.keys(what).forEach(function (pKey) {
|
|
68
|
-
if (what.hasOwnProperty(pKey)) {
|
|
69
|
-
what[pKey] = parse(what[pKey], parseThis);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
break;
|
|
73
|
-
case Array:
|
|
74
|
-
what.forEach(function (pValue, pKey, original) {
|
|
75
|
-
original[pKey] = parse(what[pKey], parseThis);
|
|
76
|
-
});
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return what;
|
|
81
|
-
}
|
|
82
|
-
export function kebabToPascal(str) {
|
|
83
|
-
return str
|
|
84
|
-
.split('-')
|
|
85
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
86
|
-
.join('');
|
|
87
|
-
}
|
|
88
|
-
export function debounce(func, milliseconds) {
|
|
89
|
-
let timeout;
|
|
90
|
-
return () => {
|
|
91
|
-
clearTimeout(timeout);
|
|
92
|
-
timeout = setTimeout(function () {
|
|
93
|
-
func(...arguments);
|
|
94
|
-
}, milliseconds);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
export function htmlToElements(html) {
|
|
98
|
-
let template = document.createElement('template');
|
|
99
|
-
html = html.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi, '<$1$2></$1>');
|
|
100
|
-
template.innerHTML = html;
|
|
101
|
-
template.content.normalize();
|
|
102
|
-
return Array.from(template.content.childNodes);
|
|
103
|
-
}
|
|
104
|
-
export function copyGettersSetters(source, target) {
|
|
105
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
106
|
-
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
107
|
-
if ('get' in descriptor || 'set' in descriptor) {
|
|
108
|
-
Object.defineProperty(target, key, descriptor);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
package/dist/microcomponents.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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)},e={};function n(t){return t&&t.constructor&&t.constructor===Object}function r(t){let e={};return[...Object.keys(t)].sort().forEach((s=>{n(t[s])?e[s]=r(t[s]):e[s]=t[s]})),e}function s(t,e=!0){let n={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]instanceof Object){const r=s(t[e],!1);n[e]={};for(const t in r)n[e+"."+t]=r[t]}else n[e]=t[e]})),e?r(n):n}function a(t,e){return JSON.stringify(s(t))===JSON.stringify(s(e))}function c(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?c(n.splice(1),e[n[0]]):e[n[0]];console.warn("ns",n[0],"not in",e)}function o(t,e){var r=Array.from(arguments);if(r.length>2){for(;r.length>1;)r[0]=o(r[0],r[1]),r.splice(1,1);return r[0]}if("string"==typeof t)t.match(/\{[^\{\}]*\}/g)?.forEach((function(n){var r=c(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]=o(t[n],e))}));break;case Array:t.forEach((function(n,r,s){s[r]=o(t[r],e)}))}return t}function l(t){return t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function i(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.d(e,{DC:()=>w,MC:()=>O,Oc:()=>E,E_:()=>N,IT:()=>d,sg:()=>i,bD:()=>a,c2:()=>x,YO:()=>s,Rc:()=>U,tn:()=>D,qS:()=>u,nz:()=>n,TK:()=>l,k5:()=>c,lB:()=>R,AU:()=>p,on:()=>g,xH:()=>b,qg:()=>o,mf:()=>r,hZ:()=>v});const f=new Function("try {return this===window;}catch(e){ return false;}");function h(t){return t&&t instanceof HTMLElement}function m(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function p(t,e,n){t.removeEventListener(m(e),n)}function g(t,e,n,r=!1){return t.addEventListener(m(e),n,{capture:!1,once:r}),n}function b(t,e,n){return g(t,e,n,!0),n}class y{stopped=!1;constructor(){}stop(){this.stopped=!0}}function v(t,e,n={},r="l",s){const a=/^_mc/.test(e)?e:m(e),c=s||new y,o=new CustomEvent(a,{detail:{data:n,control:c},bubbles:!1});c.stopped||/l/.test(r)&&(t.dispatchEvent(o),o.stopImmediatePropagation(),c.stopped)||/[ud]/.test(r)&&(-1===r.indexOf("l")&&(r+="l"),setTimeout((()=>{if(r.indexOf("u")>-1){let e=t.parentElement?.closest("[data-mc]");e&&e?._mc.trigger(a,n,r,c)}if(r.indexOf("d")>-1){let e=t._mc.children();e&&e.forEach((t=>t.trigger(a,n,r)))}}),0))}class E{_target;constructor(t){var e;this._target=new WeakRef(t||{}),function(t){if(!f()||t.constructor===w)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),s=t.replace(/^on[e]{0,1}/,""),a=s.toLowerCase();if("on"+a in e){let r=e=>{n[t](e)};e.addEventListener(a,r)}else g(e,s,(e=>{n[t](e)}),r)}))}}(this),e=this,setTimeout((()=>{e.constructor!==w&&e.trigger("Init")}),0)}get target(){return this._target.deref()}}class O extends E{constructor(t){super(t)}}class w extends E{constructor(t){super(t)}static add(t,e,n={}){return function(t,e,n={}){let r=t;r._mc||(r._mc=new w(t));const s=r._mc;return e.length&&!s[e]&&(s[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}(t,e,n)}static remove(t,e){!function(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")}(t,e)}off(t,e){p(this.target,t,e)}on(t,e){return g(this.target,t,e)}one(t,e){return b(this.target,t,e)}trigger(t,e={},n="l",r){v(this.target,t,e,n,r)}ancestors(){let t=this?.target,e=[];if(!h(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return h(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return h(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(!h(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}const A=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=>{try{w.add(e,n.name,new n(e))}catch(t){if(!n.create)throw`Class ${n.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`;{let t=n.create(e);t.setAttribute("data-mc",e.getAttribute("data-mc")),e.replaceWith(t),e=t}}const r=e.getAttribute("data-mc").split(" ").filter((e=>e!==t&&""!==e)).join(" ").trim();e.setAttribute("data-mc",r)}))}}function k(t){if(A.has(t))return;A.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=>{A.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 j(){[...document.querySelectorAll(":not(:defined)")].filter((t=>!!t&&!customElements.get(t.tagName.toLowerCase())&&!A.has(t.tagName.toLowerCase()))).forEach((t=>{k(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);A.has(t)||e?e&&C(t)():k(t)}))}))}let _=!1,S=null;function N(t=!0){return t?(_=t,S=new MutationObserver(j),setTimeout((()=>{S.observe(document.body,{childList:!0,subtree:!0}),j()}),5),window.autoload=window.autoload||N,_):(S?.disconnect(),S=null,_)}N.state=A;class T 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 x(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=l(t);L(e.prototype.constructor)&&e.prototype instanceof E?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends T{instance;constructor(t){super();const n=L(e)?new e(this,t):e;w.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function D(t){return customElements.get(t)}function M(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 P=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class H extends w{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),s=>{let a=r;n.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((n=>{e=!0;let r=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>s=>{let a=e;r.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!P.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 V(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=[],M(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(M(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||w.add(t,"_placeholders",new H(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),n=function(t){let n=s(t);e.forEach((t=>{t&&v(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=M(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#e&&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(V(n))(n),s=i((function(){r.notify()}),0);Object.defineProperty(t,e,{enumerable:!0,get(){if(M(r.valueOf())){let t=structuredClone(Object.assign({},r));setTimeout((function(){let e=structuredClone(Object.assign({},r));console.log("compare",t,"to",e,"with",r.callbacks,"isChanged:",!a(e,t)),a(e,t)||s()}),0)}return r},set(t){if(typeof t==typeof r.valueOf())if(M(r.valueOf())&&r.valueOf()instanceof Array==0)void 0===r?.constructor?.prototype?.observe&&(r=new(V(t))(structuredClone(Object.assign({},t))),d(t,r)),Object.assign(r,t),r.notify();else{let e=r.valueOf(),n=r.callbacks;t!==e&&(r=new(V(t))(t),r.callbacks=n,s())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof t)}}),t[e]=n}})),t);class ${constructor(t){}}class F extends ${#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 ${#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.checked}set val(t){this.#r.checked=t}}class z extends ${#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value}set val(t){this.#r.value=t}}class B extends ${#r;#s=!1;constructor(t){super(t),this.#r=t,this.#s=t.multiple}get val(){const t=[];return[...this.#r.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.#r.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class G extends ${#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value||""}set val(t){this.#r.value=t}}const J=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 F(t);break;case"checkbox":r=new Z(t);break;default:r=new z(t)}break;case"select":r=new B(t);break;case"textarea":r=new G(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}r&&(w.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 U(t,e,n){let r=J(n);t[e]=Object.assign({},r),R(t,e),d(r,t[e]),Object.seal(t[e]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{t[e].notify()}))}))}var Y=e.DC,K=e.MC,W=e.Oc,Q=e.E_,X=e.IT,tt=e.sg,et=e.bD,nt=e.c2,rt=e.YO,st=e.Rc,at=e.tn,ct=e.qS,ot=e.nz,lt=e.TK,it=e.k5,ut=e.lB,dt=e.AU,ft=e.on,ht=e.xH,mt=e.qg,pt=e.mf,gt=e.hZ;export{Y as DC,K as MC,W as McBase,Q as autoload,X as copyGettersSetters,tt as debounce,et as deepEqual,nt as defineCE,rt as flattenObject,st as formValues,at as getCE,ct as htmlToElements,ot as isNativeObject,lt as kebabToPascal,it as nameSpace,ut as observe,dt as off,ft as on,ht as one,mt as parse,pt as sortObject,gt as trigger};
|
package/dist/observables.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { LooseObject } from './helpers.js';
|
|
2
|
-
type Callback = (value: any) => void;
|
|
3
|
-
export type Observable = {
|
|
4
|
-
observe: (cb: Callback) => void;
|
|
5
|
-
notify: () => void;
|
|
6
|
-
bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
|
|
7
|
-
callbacks: Array<Function>;
|
|
8
|
-
};
|
|
9
|
-
export declare const observe: (target: LooseObject, propertyName?: string) => LooseObject;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=observables.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["../src/observables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAA0D,MAAM,cAAc,CAAC;AAQnG,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AA2JrC,MAAM,MAAM,UAAU,GAAG;IACrB,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,GAAG,UAAU,KAAK,IAAI,CAAC;IACpE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC9B,CAAC;AA8GF,eAAO,MAAM,OAAO,WAAY,WAAW,iBAAiB,MAAM,KAAG,WAuFpE,CAAC"}
|
package/dist/observables.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
import { debounce, deepEqual, flattenObject, copyGettersSetters } from './helpers.js';
|
|
3
|
-
import { DC, trigger } from './MC.js';
|
|
4
|
-
function isObservableObject(value) {
|
|
5
|
-
return value != null && typeof value === 'object';
|
|
6
|
-
}
|
|
7
|
-
function getPlaceholders(target) {
|
|
8
|
-
let placeholders = new Set(), regEx = /\{[^\{\}]*\}/g;
|
|
9
|
-
(target.getAttributeNames ? target.getAttributeNames() : [])
|
|
10
|
-
.filter((attr) => target.getAttribute(attr)?.match(regEx))
|
|
11
|
-
.forEach((attr) => {
|
|
12
|
-
let placeholders = new Set(target.getAttribute(attr)?.match(regEx));
|
|
13
|
-
placeholders.forEach((placeholder) => placeholders.add(placeholder.replace(/[\{\}]/g, '')));
|
|
14
|
-
});
|
|
15
|
-
[...target.childNodes]
|
|
16
|
-
.filter((childNode) => {
|
|
17
|
-
return (childNode.nodeType === 3 && (childNode.nodeValue || '').match(regEx));
|
|
18
|
-
})
|
|
19
|
-
.forEach((childNode) => {
|
|
20
|
-
(childNode.nodeValue || '').match(regEx).forEach((placeholder) => {
|
|
21
|
-
placeholders.add(placeholder.replace(/[\{\}]/g, ''));
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
return [...placeholders].map((placeholder) => placeholder.replace(/[\{\}]/g, ''));
|
|
25
|
-
}
|
|
26
|
-
const inputs = [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement];
|
|
27
|
-
class Placeholders extends DC {
|
|
28
|
-
data = {};
|
|
29
|
-
oldDisplay = '';
|
|
30
|
-
constructor(target) {
|
|
31
|
-
super(target);
|
|
32
|
-
getPlaceholders(target).forEach((property) => (this.data[property] = ''));
|
|
33
|
-
observe(this);
|
|
34
|
-
this.#attachCallbacks();
|
|
35
|
-
}
|
|
36
|
-
#attachCallbacks() {
|
|
37
|
-
let target = this.target, hide = false;
|
|
38
|
-
(target.getAttributeNames ? target.getAttributeNames() : [])
|
|
39
|
-
.filter((attr) => target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g))
|
|
40
|
-
.forEach((attr) => {
|
|
41
|
-
let placeholders = new Set(target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g));
|
|
42
|
-
this.data.observe(((template) => (data) => {
|
|
43
|
-
let result = template;
|
|
44
|
-
placeholders.forEach((placeholder) => {
|
|
45
|
-
result = result.replace(placeholder, data[placeholder.replace(/[\{\}]/g, '')]);
|
|
46
|
-
});
|
|
47
|
-
target.setAttribute(attr, result);
|
|
48
|
-
})(target.getAttribute(attr)));
|
|
49
|
-
});
|
|
50
|
-
[...target.childNodes]
|
|
51
|
-
.filter((childNode) => {
|
|
52
|
-
return (childNode.nodeType === 3 &&
|
|
53
|
-
(childNode.nodeValue || '').match(/\{[^\{\}]*\}/g));
|
|
54
|
-
})
|
|
55
|
-
.forEach((childNode) => {
|
|
56
|
-
hide = true;
|
|
57
|
-
let placeholders = new Set(childNode.nodeValue.match(/\{[^\{\}]*\}/g));
|
|
58
|
-
this.data.observe(((template) => (data) => {
|
|
59
|
-
let result = template;
|
|
60
|
-
placeholders.forEach((placeholder) => {
|
|
61
|
-
result = result.replace(placeholder, data[placeholder.replace(/[\{\}]/g, '')]);
|
|
62
|
-
});
|
|
63
|
-
if (this.oldDisplay) {
|
|
64
|
-
target.style = this.oldDisplay;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
target.removeAttribute('style');
|
|
68
|
-
}
|
|
69
|
-
delete this.oldDisplay;
|
|
70
|
-
childNode.nodeValue = result;
|
|
71
|
-
})(childNode.nodeValue));
|
|
72
|
-
this.oldDisplay = target.getAttribute('style') || '';
|
|
73
|
-
if (hide &&
|
|
74
|
-
!inputs.includes(target.constructor) &&
|
|
75
|
-
target.tagName !== 'FIELDSET') {
|
|
76
|
-
target.style.display = 'none';
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
onData(ev) {
|
|
81
|
-
let data = {};
|
|
82
|
-
Object.keys(ev.detail.data).forEach((key) => {
|
|
83
|
-
if (this.data.hasOwnProperty(key))
|
|
84
|
-
data[key] = ev.detail.data[key];
|
|
85
|
-
});
|
|
86
|
-
if (JSON.stringify(data) !== JSON.stringify(this.data))
|
|
87
|
-
Object.assign(this.data, data);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function getPlaceholderElements(target) {
|
|
91
|
-
let elements = [target]
|
|
92
|
-
.concat([...target.querySelectorAll('*')])
|
|
93
|
-
.filter((e) => !!getPlaceholders(e).length)
|
|
94
|
-
.filter((e) => e?.tagName !== 'STYLE')
|
|
95
|
-
.reverse();
|
|
96
|
-
return elements;
|
|
97
|
-
}
|
|
98
|
-
function makePlaceholders(element) {
|
|
99
|
-
getPlaceholderElements(element).forEach((e) => {
|
|
100
|
-
if (e?._mc?._placeholders)
|
|
101
|
-
return;
|
|
102
|
-
DC.add(e, '_placeholders', new Placeholders(e));
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
const classRepo = {};
|
|
106
|
-
function makeObservable(val) {
|
|
107
|
-
const Constructor = val.constructor, ConstructorName = Constructor.name;
|
|
108
|
-
let ObservableClass = class extends Constructor {
|
|
109
|
-
#notify = true;
|
|
110
|
-
#callbacks = [];
|
|
111
|
-
constructor(val) {
|
|
112
|
-
super(val);
|
|
113
|
-
this.constructor.callbacks = [];
|
|
114
|
-
if (isObservableObject(val)) {
|
|
115
|
-
Object.getOwnPropertyNames(val).forEach((key) => {
|
|
116
|
-
this[key] = val[key];
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
get callbacks() {
|
|
121
|
-
return this.#callbacks;
|
|
122
|
-
}
|
|
123
|
-
set callbacks(callbacks) {
|
|
124
|
-
this.#callbacks = callbacks;
|
|
125
|
-
}
|
|
126
|
-
observe(callback) {
|
|
127
|
-
this.#callbacks.push(callback);
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
bind(target) {
|
|
131
|
-
const iso = isObservableObject(this.valueOf());
|
|
132
|
-
if (iso) {
|
|
133
|
-
makePlaceholders(target);
|
|
134
|
-
const placeholders = [
|
|
135
|
-
target,
|
|
136
|
-
...target.querySelectorAll('[data-mc]'),
|
|
137
|
-
].filter((e) => !!e?._mc?._placeholders);
|
|
138
|
-
const func = function callback(data) {
|
|
139
|
-
let flattenedData = flattenObject(data);
|
|
140
|
-
placeholders.forEach((node) => {
|
|
141
|
-
if (!node)
|
|
142
|
-
return;
|
|
143
|
-
trigger(node, 'data', flattenedData);
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
this.#callbacks.push(func);
|
|
147
|
-
this.notify();
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
console.warn('IGNORED - cannot bind a non-Object to the dom, IS:', typeof this.valueOf(), this);
|
|
151
|
-
}
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
notify(notify) {
|
|
155
|
-
let data = isObservableObject(this.valueOf()) && this.valueOf() instanceof Array === false
|
|
156
|
-
? structuredClone(Object.assign({}, this))
|
|
157
|
-
: this.valueOf();
|
|
158
|
-
if (notify !== undefined) {
|
|
159
|
-
this.#notify = notify;
|
|
160
|
-
}
|
|
161
|
-
if (this.#notify) {
|
|
162
|
-
this.#callbacks.forEach((f) => {
|
|
163
|
-
f(data);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
classRepo[ConstructorName] = ObservableClass;
|
|
170
|
-
return ObservableClass;
|
|
171
|
-
}
|
|
172
|
-
function getConstructor(val) {
|
|
173
|
-
let key = val.constructor.name;
|
|
174
|
-
return classRepo[key] || makeObservable(val);
|
|
175
|
-
}
|
|
176
|
-
export const observe = (target, propertyName) => {
|
|
177
|
-
let keys = !propertyName ? [...Object.getOwnPropertyNames(target)] : [propertyName];
|
|
178
|
-
keys.forEach((key) => {
|
|
179
|
-
if (target.hasOwnProperty(key) &&
|
|
180
|
-
typeof target[key] !== 'function' &&
|
|
181
|
-
!target?.[key]?.constructor?.prototype?.observe) {
|
|
182
|
-
if (key[0] === '_' || target?.[key] === undefined)
|
|
183
|
-
return target;
|
|
184
|
-
let val = target[key];
|
|
185
|
-
let o = new (getConstructor(val))(val);
|
|
186
|
-
let debouncedNotify = debounce(function debouncedNotify() {
|
|
187
|
-
o.notify();
|
|
188
|
-
}, 0);
|
|
189
|
-
Object.defineProperty(target, key, {
|
|
190
|
-
enumerable: true,
|
|
191
|
-
get() {
|
|
192
|
-
if (isObservableObject(o.valueOf())) {
|
|
193
|
-
let check = structuredClone(Object.assign({}, o));
|
|
194
|
-
setTimeout(function checkChanges() {
|
|
195
|
-
let state = structuredClone(Object.assign({}, o));
|
|
196
|
-
console.log('compare', check, 'to', state, 'with', o.callbacks, 'isChanged:', !deepEqual(state, check));
|
|
197
|
-
if (!deepEqual(state, check)) {
|
|
198
|
-
debouncedNotify();
|
|
199
|
-
}
|
|
200
|
-
}, 0);
|
|
201
|
-
}
|
|
202
|
-
return o;
|
|
203
|
-
},
|
|
204
|
-
set(val) {
|
|
205
|
-
if (typeof val === typeof o.valueOf()) {
|
|
206
|
-
let iso = isObservableObject(o.valueOf()) &&
|
|
207
|
-
o.valueOf() instanceof Array === false;
|
|
208
|
-
if (iso) {
|
|
209
|
-
if (o?.constructor?.prototype?.observe === undefined) {
|
|
210
|
-
o = new (getConstructor(val))(structuredClone(Object.assign({}, val)));
|
|
211
|
-
copyGettersSetters(val, o);
|
|
212
|
-
}
|
|
213
|
-
Object.assign(o, val);
|
|
214
|
-
o.notify();
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
let old = o.valueOf(), callbacks = o.callbacks;
|
|
218
|
-
if (val !== old) {
|
|
219
|
-
o = new (getConstructor(val))(val);
|
|
220
|
-
o.callbacks = callbacks;
|
|
221
|
-
debouncedNotify();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
console.warn('IGNORED - cannot change observable types, IS:', typeof o.valueOf(), o, '- CANNOT BECOME:', typeof val);
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
target[key] = val;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
return target;
|
|
234
|
-
};
|
package/dist/observables.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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)},e={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var c;(c=t[n])&&c.constructor&&c.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let c={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]instanceof Object){const r=n(t[e],!1);c[e]={};for(const t in r)c[e+"."+t]=r[t]}else c[e]=t[e]})),e?r(c):c}function c(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}t.d(e,{l:()=>O});const o=new Function("try {return this===window;}catch(e){ return false;}");function a(t){return t&&t instanceof HTMLElement}function s(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function i(t,e,r,n=!1){return t.addEventListener(s(e),r,{capture:!1,once:n}),r}class l{stopped=!1;constructor(){}stop(){this.stopped=!0}}function u(t,e,r={},n="l",c){const o=/^_mc/.test(e)?e:s(e),a=c||new l,i=new CustomEvent(o,{detail:{data:r,control:a},bubbles:!1});a.stopped||/l/.test(n)&&(t.dispatchEvent(i),i.stopImmediatePropagation(),a.stopped)||/[ud]/.test(n)&&(-1===n.indexOf("l")&&(n+="l"),setTimeout((()=>{if(n.indexOf("u")>-1){let e=t.parentElement?.closest("[data-mc]");e&&e?._mc.trigger(o,r,n,a)}if(n.indexOf("d")>-1){let e=t._mc.children();e&&e.forEach((t=>t.trigger(o,r,n)))}}),0))}class f{_target;constructor(t){var e;this._target=new WeakRef(t||{}),function(t){if(!o()||t.constructor===h)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),c=t.replace(/^on[e]{0,1}/,""),o=c.toLowerCase();if("on"+o in e){let n=e=>{r[t](e)};e.addEventListener(o,n)}else i(e,c,(e=>{r[t](e)}),n)}))}}(this),e=this,setTimeout((()=>{e.constructor!==h&&e.trigger("Init")}),0)}get target(){return this._target.deref()}}class h extends f{constructor(t){super(t)}static add(t,e,r={}){return function(t,e,r={}){let n=t;n._mc||(n._mc=new h(t));const c=n._mc;return e.length&&!c[e]&&(c[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}(t,e,r)}static remove(t,e){!function(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")}(t,e)}off(t,e){!function(t,e,r){t.removeEventListener(s(e),r)}(this.target,t,e)}on(t,e){return i(this.target,t,e)}one(t,e){return function(t,e,r){return i(t,e,r,!0),r}(this.target,t,e)}trigger(t,e={},r="l",n){u(this.target,t,e,r,n)}ancestors(){let t=this?.target,e=[];if(!a(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return a(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return a(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(!a(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}function d(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 m=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class g extends h{data={};oldDisplay="";constructor(t){super(t),p(t).forEach((t=>this.data[t]="")),O(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),c=>{let o=n;r.forEach((t=>{o=o.replace(t,c[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,o)}))})),[...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=>c=>{let o=e;n.forEach((t=>{o=o.replace(t,c[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=o})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!m.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 b={};function y(t){let e=t.constructor.name;return b[e]||function(t){const e=t.constructor,r=e.name;let c=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],d(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(d(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||h.add(t,"_placeholders",new g(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&&u(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=d(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#e&&this.#r.forEach((t=>{t(e)})),this}};return b[r]=c,c}(t)}const O=(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(y(r))(r),o=function(){let t;return()=>{clearTimeout(t),t=setTimeout((function(){!function(){n.notify()}(...arguments)}),0)}}();Object.defineProperty(t,e,{enumerable:!0,get(){if(d(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout((function(){let e=structuredClone(Object.assign({},n));console.log("compare",t,"to",e,"with",n.callbacks,"isChanged:",!c(e,t)),c(e,t)||o()}),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(d(n.valueOf())&&n.valueOf()instanceof Array==0)void 0===n?.constructor?.prototype?.observe&&(n=new(y(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)),Object.assign(n,t),n.notify();else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(y(t))(t),n.callbacks=r,o())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof t)}}),t[e]=r}})),t);var v=e.l;export{v as observe};
|