@symbiotejs/symbiote 1.4.3 → 1.4.4
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/build/BaseComponent.min.js +1 -1
- package/build/symbiote.d.ts +59 -84
- package/build/symbiote.js +20 -11
- package/build/symbiote.min.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
var E=Object.defineProperty;var X=(n,t,e)=>t in n?E(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var P=(n,t,e)=>(X(n,typeof t!="symbol"?t+"":t,e),e);function D(n){let t=e=>{var s;for(let r in e)((s=e[r])==null?void 0:s.constructor)===Object&&(e[r]=t(e[r]));return{...e}};return t(n)}var l=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=D(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(l.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(r=>{r(this.store[t])}))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){l.warn("publish",t);return}this.add(t,e)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(l.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete l.globalStore[this.uid]}static registerLocalCtx(t){let e=new l({schema:t});return l.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=l.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new l({name:t,schema:e}),l.globalStore[t]=s),s}static clearNamedCtx(t){delete l.globalStore[t]}static getNamedCtx(t,e=!0){return l.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};l.globalStore=Object.create(null);var o=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym"});var p="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",O=p.length-1,A=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:p.charAt(Math.random()*O);return e}};function N(n,t){if(t.renderShadow)return;let e=[...t.childNodes],s=[...n.querySelectorAll("slot")];if(e.length&&s.length){let r={};s.forEach(i=>{let a=i.getAttribute("name");a?r[a]={slot:i,fr:document.createDocumentFragment()}:r.__default__={slot:i,fr:document.createDocumentFragment()}}),e.forEach(i=>{var c;let a=(c=i.getAttribute)==null?void 0:c.call(i,"slot");a?(i.removeAttribute("slot"),r[a].fr.appendChild(i)):r.__default__&&r.__default__.fr.appendChild(i)}),Object.values(r).forEach(i=>{i.slot.parentNode.insertBefore(i.fr,i.slot),i.slot.remove()})}else t.innerHTML=""}function k(n,t){[...n.querySelectorAll(`[${o.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(o.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(o.EL_REF_ATTR)})}function M(n,t){[...n.querySelectorAll(`[${o.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(o.BIND_ATTR).split(";").forEach(i=>{if(!i)return;let a=i.split(":").map(u=>u.trim()),c=a[0],f;c.indexOf(o.ATTR_BIND_PRFX)===0&&(f=!0,c=c.replace(o.ATTR_BIND_PRFX,""));let R=a[1].split(",").map(u=>u.trim()),x,d,m,b;if(c.includes(".")){x=!0;let u=c.split(".");b=()=>{d=e,u.forEach((h,w)=>{w<u.length-1?d=d[h]:m=h})},b()}for(let u of R)t.sub(u,h=>{f?(h==null?void 0:h.constructor)===Boolean?h?e.setAttribute(c,""):e.removeAttribute(c):e.setAttribute(c,h):x?d?d[m]=h:window.setTimeout(()=>{b(),d[m]=h}):e[c]=h})}),e.removeAttribute(o.BIND_ATTR)})}var T="{{",C="}}",$="skip-text";function F(n){let t,e=[],s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode:r=>{var i;return!((i=r.parentElement)==null?void 0:i.hasAttribute($))&&r.textContent.includes(T)&&r.textContent.includes(C)&&1}});for(;t=s.nextNode();)e.push(t);return e}var L=function(n,t){F(n).forEach(s=>{let r=[],i;for(;s.textContent.includes(C);)s.textContent.startsWith(T)?(i=s.textContent.indexOf(C)+2,s.splitText(i),r.push(s)):(i=s.textContent.indexOf(T),s.splitText(i)),s=s.nextSibling;r.forEach(a=>{let c=a.textContent.replace(T,"").replace(C,"");t.sub(c,f=>{a.textContent=f})})})},S=[N,k,M,L];var y=0,_=class extends HTMLElement{initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if(t||this.constructor.template){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);this.firstChild;)this.firstChild.remove();if((t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let i=document.createElement("template");i.innerHTML=t,s=i.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let i of this.tplProcessors)i(s,this)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});let r=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let i=document.createElement("link");i.rel="stylesheet",i.href=this.constructor.__shadowStylesUrl,i.onload=r,this.shadowRoot.prepend(i)}else r()}addTemplateProcessor(t){this.tplProcessors.add(t)}constructor(){super();this.init$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=A.generate(),this.style.setProperty(o.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(o.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(o.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=l.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return l.getNamedCtx(this.ctxName,!1)||l.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,r;if(t.startsWith(o.EXT_DATA_CTX_PRFX))s=e.nodeCtx,r=t.replace(o.EXT_DATA_CTX_PRFX,"");else if(t.includes(o.NAMED_DATA_CTX_SPLTR)){let i=t.split(o.NAMED_DATA_CTX_SPLTR);s=l.getNamedCtx(i[0]),r=i[1]}else s=e.localCtx,r=t;return{ctx:s,name:r}}sub(t,e){let s=_.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=_.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=_.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=_.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,r)=>{let i=_.__parseProp(s,this);return i.ctx.pub(i.name,r),!0},get:(e,s)=>{let r=_.__parseProp(s,this);return r.ctx.read(r.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(o.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(o.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(o.NAMED_DATA_CTX_SPLTR)){let s=e.split(o.NAMED_DATA_CTX_SPLTR),r=s[0].trim(),i=s[1].trim();if(r&&i){let a=l.getNamedCtx(r,!1);a||(a=l.registerNamedCtx(r,{})),a.add(i,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(o.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(o.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx();for(let s of S)this.addTemplateProcessor(s);this.pauseRender||this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t)},100))}static reg(t,e=!1){if(t||(y++,t=`${o.AUTO_TAG_PRFX}-${y}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let r=this.constructor.__attrDesc[t];r?this.__dataCtxInitialized?this.$[r]=s:this.init$[r]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}bindCssData(t,e=!0){let s=(e?o.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let r="__"+t;this[r]=this[t],Object.defineProperty(this,t,{set:i=>{this[r]=i,s?window.setTimeout(()=>{e==null||e(i)}):e==null||e(i)},get:()=>this[r]}),this[t]=this[r]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},g=_;P(g,"template");export{g as BaseComponent};
|
package/build/symbiote.d.ts
CHANGED
|
@@ -19,12 +19,12 @@ export class Data {
|
|
|
19
19
|
store: {
|
|
20
20
|
[x: string]: any;
|
|
21
21
|
};
|
|
22
|
-
_storeIsProxy
|
|
22
|
+
private _storeIsProxy;
|
|
23
23
|
callbackMap: any;
|
|
24
24
|
read(prop: string): any;
|
|
25
25
|
has(prop: string): boolean;
|
|
26
|
-
add(prop: string, val:
|
|
27
|
-
pub(prop: string, val:
|
|
26
|
+
add(prop: string, val: unknown, rewrite?: boolean): void;
|
|
27
|
+
pub<T>(prop: string, val: T): void;
|
|
28
28
|
multiPub(updObj: {
|
|
29
29
|
[x: string]: any;
|
|
30
30
|
}): void;
|
|
@@ -39,10 +39,8 @@ export namespace Data {
|
|
|
39
39
|
const globalStore: any;
|
|
40
40
|
}
|
|
41
41
|
export class BaseComponent extends HTMLElement {
|
|
42
|
-
static
|
|
43
|
-
|
|
44
|
-
name: string;
|
|
45
|
-
};
|
|
42
|
+
static template: string;
|
|
43
|
+
private static __parseProp;
|
|
46
44
|
static reg(tagName?: string, isAlias?: boolean): void;
|
|
47
45
|
static get is(): string;
|
|
48
46
|
static bindAttributes(desc: {
|
|
@@ -50,56 +48,53 @@ export class BaseComponent extends HTMLElement {
|
|
|
50
48
|
}): void;
|
|
51
49
|
static set shadowStyles(arg: string);
|
|
52
50
|
initCallback(): void;
|
|
53
|
-
__initCallback
|
|
54
|
-
__initialized
|
|
51
|
+
private __initCallback;
|
|
52
|
+
private __initialized;
|
|
55
53
|
render(template?: string | DocumentFragment, shadow?: boolean): void;
|
|
56
|
-
addTemplateProcessor(processorFn: (fr: DocumentFragment, fnCtx:
|
|
54
|
+
addTemplateProcessor<T extends BaseComponent>(processorFn: (fr: DocumentFragment, fnCtx: T) => void): void;
|
|
57
55
|
init$: {
|
|
58
|
-
[x: string]:
|
|
56
|
+
[x: string]: unknown;
|
|
59
57
|
};
|
|
60
|
-
tplProcessors: Set<(fr: DocumentFragment, fnCtx:
|
|
58
|
+
tplProcessors: Set<(fr: DocumentFragment, fnCtx: unknown) => void>;
|
|
61
59
|
ref: {
|
|
62
|
-
[x: string]:
|
|
60
|
+
[x: string]: unknown;
|
|
63
61
|
};
|
|
64
62
|
allSubs: Set<any>;
|
|
65
63
|
pauseRender: boolean;
|
|
66
64
|
renderShadow: boolean;
|
|
67
65
|
readyToDestroy: boolean;
|
|
68
66
|
get autoCtxName(): string;
|
|
69
|
-
__autoCtxName
|
|
70
|
-
get cssCtxName():
|
|
71
|
-
get ctxName():
|
|
67
|
+
private __autoCtxName;
|
|
68
|
+
get cssCtxName(): string;
|
|
69
|
+
get ctxName(): string;
|
|
72
70
|
get localCtx(): Data;
|
|
73
|
-
__localCtx
|
|
71
|
+
private __localCtx;
|
|
74
72
|
get nodeCtx(): Data;
|
|
75
|
-
sub(prop: string, handler: (value:
|
|
73
|
+
sub<T_1>(prop: string, handler: (value: T_1) => void): void;
|
|
76
74
|
notify(prop: string): void;
|
|
77
75
|
has(prop: string): boolean;
|
|
78
|
-
add(prop: string, val:
|
|
79
|
-
add
|
|
80
|
-
[x: string]:
|
|
76
|
+
add<T_2>(prop: string, val: T_2): void;
|
|
77
|
+
add$<T_3>(obj: {
|
|
78
|
+
[x: string]: T_4;
|
|
81
79
|
}): void;
|
|
82
80
|
get $(): {
|
|
83
81
|
[x: string]: any;
|
|
84
82
|
};
|
|
85
|
-
__stateProxy
|
|
86
|
-
[x: string]: any;
|
|
87
|
-
};
|
|
83
|
+
private __stateProxy;
|
|
88
84
|
set$(kvObj: {
|
|
89
85
|
[x: string]: any;
|
|
90
86
|
}): void;
|
|
91
|
-
__initDataCtx
|
|
87
|
+
private __initDataCtx;
|
|
92
88
|
__dataCtxInitialized: boolean;
|
|
93
89
|
connectedCallback(): void;
|
|
94
|
-
__initChildren: ChildNode[];
|
|
95
90
|
connectedOnce: boolean;
|
|
96
91
|
destroyCallback(): void;
|
|
97
92
|
disconnectedCallback(): void;
|
|
98
|
-
__disconnectTimeout
|
|
93
|
+
private __disconnectTimeout;
|
|
99
94
|
attributeChangedCallback(name: any, oldVal: any, newVal: any): void;
|
|
100
95
|
getCssData(propName: string, silentCheck?: boolean): any;
|
|
101
|
-
__cssDataCache
|
|
102
|
-
__computedStyle
|
|
96
|
+
private __cssDataCache;
|
|
97
|
+
private __computedStyle;
|
|
103
98
|
bindCssData(propName: string, external?: boolean): string;
|
|
104
99
|
dropCssDataCache(): void;
|
|
105
100
|
defineAccessor(propName: string, handler?: Function, isAsync?: boolean): void;
|
|
@@ -143,28 +138,25 @@ export class TypedCollection {
|
|
|
143
138
|
handler?: (list: string[]) => void;
|
|
144
139
|
ctxName?: string;
|
|
145
140
|
});
|
|
146
|
-
__typedSchema
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
__subsMap: any;
|
|
157
|
-
__observers: Set<any>;
|
|
158
|
-
__items: Set<string>;
|
|
159
|
-
__notifyObservers: (propName: any, ctxId: any) => void;
|
|
160
|
-
__observeTimeout: number;
|
|
141
|
+
private __typedSchema;
|
|
142
|
+
private __ctxId;
|
|
143
|
+
private __state;
|
|
144
|
+
private __watchList;
|
|
145
|
+
private __handler;
|
|
146
|
+
private __subsMap;
|
|
147
|
+
private __observers;
|
|
148
|
+
private __items;
|
|
149
|
+
private __notifyObservers;
|
|
150
|
+
private __observeTimeout;
|
|
161
151
|
notify(): void;
|
|
162
|
-
__notifyTimeout
|
|
163
|
-
add(init:
|
|
152
|
+
private __notifyTimeout;
|
|
153
|
+
add(init: {
|
|
154
|
+
[x: string]: any;
|
|
155
|
+
}): any;
|
|
164
156
|
read(id: string): TypedData;
|
|
165
|
-
readProp(id:
|
|
166
|
-
publishProp(id:
|
|
167
|
-
remove(id:
|
|
157
|
+
readProp(id: string, propName: string): any;
|
|
158
|
+
publishProp<T>(id: string, propName: string, value: T): void;
|
|
159
|
+
remove(id: string): void;
|
|
168
160
|
clearAll(): void;
|
|
169
161
|
observe(handler: Function): void;
|
|
170
162
|
unobserve(handler: Function): void;
|
|
@@ -173,13 +165,13 @@ export class TypedCollection {
|
|
|
173
165
|
destroy(): void;
|
|
174
166
|
}
|
|
175
167
|
export class AppRouter {
|
|
176
|
-
static _print
|
|
168
|
+
private static _print;
|
|
177
169
|
static setDefaultTitle(title: string): void;
|
|
178
170
|
static setRoutingMap(map: {
|
|
179
171
|
[x: string]: {};
|
|
180
172
|
}): void;
|
|
181
|
-
static set routingEventName(arg:
|
|
182
|
-
static get routingEventName():
|
|
173
|
+
static set routingEventName(arg: string);
|
|
174
|
+
static get routingEventName(): string;
|
|
183
175
|
static readAddressBar(): {
|
|
184
176
|
route: any;
|
|
185
177
|
options: {};
|
|
@@ -201,7 +193,7 @@ export namespace AppRouter {
|
|
|
201
193
|
const defaultTitle: string;
|
|
202
194
|
const defaultRoute: string;
|
|
203
195
|
const errorRoute: string;
|
|
204
|
-
const __routingEventName:
|
|
196
|
+
const __routingEventName: string;
|
|
205
197
|
const _separator: string;
|
|
206
198
|
const appMap: any;
|
|
207
199
|
}
|
|
@@ -218,51 +210,34 @@ export namespace IDB {
|
|
|
218
210
|
}
|
|
219
211
|
declare class DbInstance {
|
|
220
212
|
constructor(dbName: string, storeName: string);
|
|
221
|
-
_notifyWhenReady
|
|
222
|
-
get _updEventName()
|
|
223
|
-
_getUpdateEvent
|
|
224
|
-
|
|
225
|
-
newValue: any;
|
|
226
|
-
}>;
|
|
227
|
-
_notifySubscribers(key: any): void;
|
|
213
|
+
private _notifyWhenReady;
|
|
214
|
+
private get _updEventName();
|
|
215
|
+
private _getUpdateEvent;
|
|
216
|
+
private _notifySubscribers;
|
|
228
217
|
name: string;
|
|
229
218
|
storeName: string;
|
|
230
219
|
version: number;
|
|
231
220
|
request: IDBOpenDBRequest;
|
|
232
221
|
db: any;
|
|
233
222
|
objStore: any;
|
|
234
|
-
_subscribtionsMap
|
|
235
|
-
_updateHandler
|
|
236
|
-
_localUpdateHandler
|
|
223
|
+
private _subscribtionsMap;
|
|
224
|
+
private _updateHandler;
|
|
225
|
+
private _localUpdateHandler;
|
|
237
226
|
read(key: string): Promise<any>;
|
|
238
227
|
write(key: string, value: any, silent?: boolean): Promise<any>;
|
|
239
228
|
delete(key: string, silent?: boolean): Promise<any>;
|
|
240
229
|
getAll(): Promise<any>;
|
|
241
|
-
subscribe(key: string, callback:
|
|
230
|
+
subscribe(key: string, callback: (val: any) => void): {
|
|
242
231
|
remove: () => void;
|
|
243
232
|
};
|
|
244
233
|
stop(): void;
|
|
245
234
|
__subscribtionsMap: any;
|
|
246
235
|
}
|
|
247
|
-
export function applyStyles(el:
|
|
248
|
-
export function applyAttributes(el:
|
|
249
|
-
export function create(desc?: ElementDescriptor):
|
|
250
|
-
export type StyleMap =
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
export type AttrMap = {
|
|
254
|
-
[x: string]: string | number | boolean;
|
|
255
|
-
};
|
|
256
|
-
export type PropMap = {
|
|
257
|
-
[x: string]: any;
|
|
258
|
-
};
|
|
259
|
-
export type ElementDescriptor = {
|
|
260
|
-
tag?: string;
|
|
261
|
-
attributes?: AttrMap;
|
|
262
|
-
styles?: StyleMap;
|
|
263
|
-
properties?: PropMap;
|
|
264
|
-
processors?: Function[];
|
|
265
|
-
children?: ElementDescriptor[];
|
|
266
|
-
};
|
|
236
|
+
export function applyStyles<T extends HTMLElement>(el: T, styleMap: StyleMap): void;
|
|
237
|
+
export function applyAttributes<T extends HTMLElement>(el: T, attrMap: AttrMap): void;
|
|
238
|
+
export function create(desc?: ElementDescriptor): any;
|
|
239
|
+
export type StyleMap = any;
|
|
240
|
+
export type AttrMap = any;
|
|
241
|
+
export type ElementDescriptor = any;
|
|
267
242
|
|
|
268
243
|
export {};
|
package/build/symbiote.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
|
|
1
8
|
// core/Data.js
|
|
2
9
|
function cloneObj(obj) {
|
|
3
10
|
let clone = (o) => {
|
|
@@ -150,8 +157,9 @@ function slotProcessor(fr, fnCtx) {
|
|
|
150
157
|
if (fnCtx.renderShadow) {
|
|
151
158
|
return;
|
|
152
159
|
}
|
|
160
|
+
let initChildren = [...fnCtx.childNodes];
|
|
153
161
|
let slots = [...fr.querySelectorAll("slot")];
|
|
154
|
-
if (
|
|
162
|
+
if (initChildren.length && slots.length) {
|
|
155
163
|
let slotMap = {};
|
|
156
164
|
slots.forEach((slot) => {
|
|
157
165
|
let slotName = slot.getAttribute("name");
|
|
@@ -167,7 +175,7 @@ function slotProcessor(fr, fnCtx) {
|
|
|
167
175
|
};
|
|
168
176
|
}
|
|
169
177
|
});
|
|
170
|
-
|
|
178
|
+
initChildren.forEach((child) => {
|
|
171
179
|
var _a;
|
|
172
180
|
let slotName = (_a = child.getAttribute) == null ? void 0 : _a.call(child, "slot");
|
|
173
181
|
if (slotName) {
|
|
@@ -297,7 +305,7 @@ var tpl_processors_default = [slotProcessor, refProcessor, domSetProcessor, txtN
|
|
|
297
305
|
|
|
298
306
|
// core/BaseComponent.js
|
|
299
307
|
var autoTagsCount = 0;
|
|
300
|
-
var
|
|
308
|
+
var _BaseComponent = class extends HTMLElement {
|
|
301
309
|
initCallback() {
|
|
302
310
|
}
|
|
303
311
|
__initCallback() {
|
|
@@ -407,19 +415,19 @@ var BaseComponent = class extends HTMLElement {
|
|
|
407
415
|
};
|
|
408
416
|
}
|
|
409
417
|
sub(prop, handler) {
|
|
410
|
-
let parsed =
|
|
418
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
411
419
|
this.allSubs.add(parsed.ctx.sub(parsed.name, handler));
|
|
412
420
|
}
|
|
413
421
|
notify(prop) {
|
|
414
|
-
let parsed =
|
|
422
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
415
423
|
parsed.ctx.notify(parsed.name);
|
|
416
424
|
}
|
|
417
425
|
has(prop) {
|
|
418
|
-
let parsed =
|
|
426
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
419
427
|
return parsed.ctx.has(parsed.name);
|
|
420
428
|
}
|
|
421
429
|
add(prop, val) {
|
|
422
|
-
let parsed =
|
|
430
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
423
431
|
parsed.ctx.add(parsed.name, val, false);
|
|
424
432
|
}
|
|
425
433
|
add$(obj) {
|
|
@@ -432,12 +440,12 @@ var BaseComponent = class extends HTMLElement {
|
|
|
432
440
|
let o = Object.create(null);
|
|
433
441
|
this.__stateProxy = new Proxy(o, {
|
|
434
442
|
set: (obj, prop, val) => {
|
|
435
|
-
let parsed =
|
|
443
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
436
444
|
parsed.ctx.pub(parsed.name, val);
|
|
437
445
|
return true;
|
|
438
446
|
},
|
|
439
447
|
get: (obj, prop) => {
|
|
440
|
-
let parsed =
|
|
448
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
441
449
|
return parsed.ctx.read(parsed.name);
|
|
442
450
|
}
|
|
443
451
|
});
|
|
@@ -489,7 +497,6 @@ var BaseComponent = class extends HTMLElement {
|
|
|
489
497
|
this.style.setProperty(DICT.CSS_CTX_PROP, `'${ctxNameAttrVal}'`);
|
|
490
498
|
}
|
|
491
499
|
this.__initDataCtx();
|
|
492
|
-
this.__initChildren = [...this.childNodes];
|
|
493
500
|
for (let proc of tpl_processors_default) {
|
|
494
501
|
this.addTemplateProcessor(proc);
|
|
495
502
|
}
|
|
@@ -615,6 +622,8 @@ var BaseComponent = class extends HTMLElement {
|
|
|
615
622
|
this.__shadowStylesUrl = URL.createObjectURL(styleBlob);
|
|
616
623
|
}
|
|
617
624
|
};
|
|
625
|
+
var BaseComponent = _BaseComponent;
|
|
626
|
+
__publicField(BaseComponent, "template");
|
|
618
627
|
|
|
619
628
|
// core/TypedData.js
|
|
620
629
|
var MSG_NAME = "[Typed State] Wrong property name: ";
|
|
@@ -1098,7 +1107,7 @@ var IDB = class {
|
|
|
1098
1107
|
return READY_EVENT_NAME;
|
|
1099
1108
|
}
|
|
1100
1109
|
static open(dbName = DEFAULT_DB_NAME, storeName = "store") {
|
|
1101
|
-
let key =
|
|
1110
|
+
let key = dbName + "/" + storeName;
|
|
1102
1111
|
if (!this._reg[key]) {
|
|
1103
1112
|
this._reg[key] = new DbInstance(dbName, storeName);
|
|
1104
1113
|
}
|
package/build/symbiote.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function k(o){let t=e=>{var s;for(let r in e)((s=e[r])==null?void 0:s.constructor)===Object&&(e[r]=t(e[r]));return{...e}};return t(o)}var n=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=k(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(n.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(r=>{r(this.store[t])}))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){n.warn("publish",t);return}this.add(t,e)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(n.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete n.globalStore[this.uid]}static registerLocalCtx(t){let e=new n({schema:t});return n.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=n.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new n({name:t,schema:e}),n.globalStore[t]=s),s}static clearNamedCtx(t){delete n.globalStore[t]}static getNamedCtx(t,e=!0){return n.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};n.globalStore=Object.create(null);var l=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym"});var A="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",j=A.length-1,d=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:A.charAt(Math.random()*j);return e}};function L(o,t){if(t.renderShadow)return;let e=[...o.querySelectorAll("slot")];if(t.__initChildren.length&&e.length){let s={};e.forEach(r=>{let i=r.getAttribute("name");i?s[i]={slot:r,fr:document.createDocumentFragment()}:s.__default__={slot:r,fr:document.createDocumentFragment()}}),t.__initChildren.forEach(r=>{var a;let i=(a=r.getAttribute)==null?void 0:a.call(r,"slot");i?(r.removeAttribute("slot"),s[i].fr.appendChild(r)):s.__default__&&s.__default__.fr.appendChild(r)}),Object.values(s).forEach(r=>{r.slot.parentNode.insertBefore(r.fr,r.slot),r.slot.remove()})}else t.innerHTML=""}function $(o,t){[...o.querySelectorAll(`[${l.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(l.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(l.EL_REF_ATTR)})}function F(o,t){[...o.querySelectorAll(`[${l.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(l.BIND_ATTR).split(";").forEach(i=>{if(!i)return;let a=i.split(":").map(_=>_.trim()),h=a[0],m;h.indexOf(l.ATTR_BIND_PRFX)===0&&(m=!0,h=h.replace(l.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(_=>_.trim()),S,p,C,g;if(h.includes(".")){S=!0;let _=h.split(".");g=()=>{p=e,_.forEach((c,I)=>{I<_.length-1?p=p[c]:C=c})},g()}for(let _ of b)t.sub(_,c=>{m?(c==null?void 0:c.constructor)===Boolean?c?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,c):S?p?p[C]=c:window.setTimeout(()=>{g(),p[C]=c}):e[h]=c})}),e.removeAttribute(l.BIND_ATTR)})}var T="{{",y="}}",U="skip-text";function B(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:r=>{var i;return!((i=r.parentElement)==null?void 0:i.hasAttribute(U))&&r.textContent.includes(T)&&r.textContent.includes(y)&&1}});for(;t=s.nextNode();)e.push(t);return e}var H=function(o,t){B(o).forEach(s=>{let r=[],i;for(;s.textContent.includes(y);)s.textContent.startsWith(T)?(i=s.textContent.indexOf(y)+2,s.splitText(i),r.push(s)):(i=s.textContent.indexOf(T),s.splitText(i)),s=s.nextSibling;r.forEach(a=>{let h=a.textContent.replace(T,"").replace(y,"");t.sub(h,m=>{a.textContent=m})})})},E=[L,$,F,H];var P=0,u=class extends HTMLElement{initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if(t||this.constructor.template){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);this.firstChild;)this.firstChild.remove();if((t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let i=document.createElement("template");i.innerHTML=t,s=i.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let i of this.tplProcessors)i(s,this)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});let r=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let i=document.createElement("link");i.rel="stylesheet",i.href=this.constructor.__shadowStylesUrl,i.onload=r,this.shadowRoot.prepend(i)}else r()}addTemplateProcessor(t){this.tplProcessors.add(t)}constructor(){super();this.init$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=d.generate(),this.style.setProperty(l.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(l.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(l.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=n.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return n.getNamedCtx(this.ctxName,!1)||n.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,r;if(t.startsWith(l.EXT_DATA_CTX_PRFX))s=e.nodeCtx,r=t.replace(l.EXT_DATA_CTX_PRFX,"");else if(t.includes(l.NAMED_DATA_CTX_SPLTR)){let i=t.split(l.NAMED_DATA_CTX_SPLTR);s=n.getNamedCtx(i[0]),r=i[1]}else s=e.localCtx,r=t;return{ctx:s,name:r}}sub(t,e){let s=u.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=u.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=u.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=u.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,r)=>{let i=u.__parseProp(s,this);return i.ctx.pub(i.name,r),!0},get:(e,s)=>{let r=u.__parseProp(s,this);return r.ctx.read(r.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(l.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(l.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(l.NAMED_DATA_CTX_SPLTR)){let s=e.split(l.NAMED_DATA_CTX_SPLTR),r=s[0].trim(),i=s[1].trim();if(r&&i){let a=n.getNamedCtx(r,!1);a||(a=n.registerNamedCtx(r,{})),a.add(i,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(l.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(l.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this.__initChildren=[...this.childNodes];for(let s of E)this.addTemplateProcessor(s);this.pauseRender||this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t)},100))}static reg(t,e=!1){if(t||(P++,t=`${l.AUTO_TAG_PRFX}-${P}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let r=this.constructor.__attrDesc[t];r?this.__dataCtxInitialized?this.$[r]=s:this.init$[r]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}bindCssData(t,e=!0){let s=(e?l.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let r="__"+t;this[r]=this[t],Object.defineProperty(this,t,{set:i=>{this[r]=i,s?window.setTimeout(()=>{e==null||e(i)}):e==null||e(i)},get:()=>this[r]}),this[t]=this[r]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}};var R="[Typed State] Wrong property name: ",W="[Typed State] Wrong property type: ",w=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||d.generate(),this.__schema=Object.keys(t).reduce((s,r)=>(s[r]=t[r].value,s),{}),this.__state=n.registerNamedCtx(this.__ctxId,this.__schema)}setValue(t,e){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(R+t);return}if((e==null?void 0:e.constructor)!==this.__typedSchema[t].type){console.warn(W+t);return}this.__state.pub(t,e)}setMultipleValues(t){for(let e in t)this.setValue(e,t[e])}getValue(t){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(R+t);return}return this.__state.read(t)}subscribe(t,e){return this.__state.sub(t,e)}remove(){this.__state.remove()}};var D=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||d.generate(),this.__state=n.registerNamedCtx(this.__ctxId,{}),this.__watchList=t.watchList||[],this.__handler=t.handler||null,this.__subsMap=Object.create(null),this.__observers=new Set,this.__items=new Set;let e=Object.create(null);this.__notifyObservers=(s,r)=>{this.__observeTimeout&&window.clearTimeout(this.__observeTimeout),e[s]||(e[s]=new Set),e[s].add(r),this.__observeTimeout=window.setTimeout(()=>{this.__observers.forEach(i=>{i({...e})}),e=Object.create(null)})}}notify(){this.__notifyTimeout&&window.clearTimeout(this.__notifyTimeout),this.__notifyTimeout=window.setTimeout(()=>{var t;(t=this.__handler)==null||t.call(this,[...this.__items])})}add(t){let e=new w(this.__typedSchema);for(let s in t)e.setValue(s,t[s]);return this.__state.add(e.__ctxId,e),this.__watchList.forEach(s=>{this.__subsMap[e.__ctxId]||(this.__subsMap[e.__ctxId]=[]),this.__subsMap[e.__ctxId].push(e.subscribe(s,()=>{this.__notifyObservers(s,e.__ctxId)}))}),this.__items.add(e.__ctxId),this.notify(),e}read(t){return this.__state.read(t)}readProp(t,e){return this.read(t).getValue(e)}publishProp(t,e,s){this.read(t).setValue(e,s)}remove(t){this.__items.delete(t),this.notify(),this.__state.pub(t,null),delete this.__subsMap[t]}clearAll(){this.__items.forEach(t=>{this.remove(t)})}observe(t){this.__observers.add(t)}unobserve(t){this.__observers.delete(t)}findItems(t){let e=[];return this.__items.forEach(s=>{let r=this.read(s);t(r)&&e.push(s)}),e}items(){return[...this.__items]}destroy(){this.__state.remove(),this.__observers=null;for(let t in this.__subsMap)this.__subsMap[t].forEach(e=>{e.remove()}),delete this.__subsMap[t]}};var f=class{static _print(t){console.warn(t)}static setDefaultTitle(t){this.defaultTitle=t}static setRoutingMap(t){Object.assign(this.appMap,t);for(let e in this.appMap)!this.defaultRoute&&this.appMap[e].default===!0?this.defaultRoute=e:!this.errorRoute&&this.appMap[e].error===!0&&(this.errorRoute=e)}static set routingEventName(t){this.__routingEventName=t}static get routingEventName(){return this.__routingEventName||"sym-on-route"}static readAddressBar(){let t={route:null,options:{}};return window.location.search.split(this.separator).forEach(s=>{if(s.includes("?"))t.route=s.replace("?","");else if(s.includes("=")){let r=s.split("=");t.options[r[0]]=decodeURI(r[1])}else t.options[s]=!0}),t}static notify(){let t=this.readAddressBar(),e=this.appMap[t.route];if(e&&e.title&&(document.title=e.title),t.route===null&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e&&this.errorRoute){this.applyRoute(this.errorRoute);return}else if(!e&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e){this._print(`Route "${t.route}" not found...`);return}let s=new CustomEvent(f.routingEventName,{detail:{route:t.route,options:Object.assign(e||{},t.options)}});window.dispatchEvent(s)}static reflect(t,e={}){let s=this.appMap[t];if(!s){this._print("Wrong route: "+t);return}let r="?"+t;for(let a in e)e[a]===!0?r+=this.separator+a:r+=this.separator+a+`=${e[a]}`;let i=s.title||this.defaultTitle||"";window.history.pushState(null,i,r),document.title=i}static applyRoute(t,e={}){this.reflect(t,e),this.notify()}static setSeparator(t){this._separator=t}static get separator(){return this._separator||"&"}static createRouterData(t,e){this.setRoutingMap(e);let s=n.registerNamedCtx(t,{route:null,options:null,title:null});return window.addEventListener(this.routingEventName,r=>{var i;s.multiPub({route:r.detail.route,options:r.detail.options,title:((i=r.detail.options)==null?void 0:i.title)||this.defaultTitle||""})}),f.notify(),s}};f.appMap=Object.create(null);window.onpopstate=()=>{f.notify()};function N(o,t){for(let e in t)e.includes("-")?o.style.setProperty(e,t[e]):o.style[e]=t[e]}function v(o,t){for(let e in t)t[e].constructor===Boolean?t[e]?o.setAttribute(e,""):o.removeAttribute(e):o.setAttribute(e,t[e])}function M(o={tag:"div"}){let t=document.createElement(o.tag);if(o.attributes&&v(t,o.attributes),o.styles&&N(t,o.styles),o.properties)for(let e in o.properties)t[e]=o.properties[e];return o.processors&&o.processors.forEach(e=>{e(t)}),o.children&&o.children.forEach(e=>{let s=M(e);t.appendChild(s)}),t}var X="idb-store-ready",V="symbiote-db",q="symbiote-idb-update_",O=class{_notifyWhenReady(t=null){window.dispatchEvent(new CustomEvent(X,{detail:{dbName:this.name,storeName:this.storeName,event:t}}))}get _updEventName(){return q+this.name}_getUpdateEvent(t){return new CustomEvent(this._updEventName,{detail:{key:this.name,newValue:t}})}_notifySubscribers(t){window.localStorage.removeItem(this.name),window.localStorage.setItem(this.name,t),window.dispatchEvent(this._getUpdateEvent(t))}constructor(t,e){this.name=t,this.storeName=e,this.version=1,this.request=window.indexedDB.open(this.name,this.version),this.request.onupgradeneeded=s=>{this.db=s.target.result,this.objStore=this.db.createObjectStore(e,{keyPath:"_key"}),this.objStore.transaction.oncomplete=r=>{this._notifyWhenReady(r)}},this.request.onsuccess=s=>{this.db=s.target.result,this._notifyWhenReady(s)},this.request.onerror=s=>{console.error(s)},this._subscribtionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscribtionsMap[s.newValue]&&this._subscribtionsMap[s.newValue].forEach(async i=>{i(await this.read(s.newValue))})},this._localUpdateHandler=s=>{this._updateHandler(s.detail)},window.addEventListener("storage",this._updateHandler),window.addEventListener(this._updEventName,this._localUpdateHandler)}read(t){let s=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).get(t);return new Promise((r,i)=>{s.onsuccess=a=>{var h;((h=a.target.result)==null?void 0:h._value)?r(a.target.result._value):(r(null),console.warn(`IDB: cannot read "${t}"`))},s.onerror=a=>{i(a)}})}write(t,e,s=!1){let r={_key:t,_value:e},a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(r);return new Promise((h,m)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),h(b.target.result)},a.onerror=b=>{m(b)}})}delete(t,e=!1){let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(t);return new Promise((i,a)=>{r.onsuccess=h=>{e||this._notifySubscribers(t),i(h)},r.onerror=h=>{a(h)}})}getAll(){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,r)=>{e.onsuccess=i=>{let a=i.target.result;s(a.map(h=>h._value))},e.onerror=i=>{r(i)}})}subscribe(t,e){this._subscribtionsMap[t]||(this._subscribtionsMap[t]=new Set);let s=this._subscribtionsMap[t];return s.add(e),{remove:()=>{s.delete(e),s.size||delete this._subscribtionsMap[t]}}}stop(){window.removeEventListener("storage",this._updateHandler),this.__subscribtionsMap=null,x.clear(this.name)}},x=class{static get readyEventName(){return X}static open(t=V,e="store"){let s=`${t}/${e}`;return this._reg[s]||(this._reg[s]=new O(t,e)),this._reg[s]}static clear(t){window.indexedDB.deleteDatabase(t);for(let e in this._reg)e.split("/")[0]===t&&delete this._reg[e]}};x._reg=Object.create(null);export{f as AppRouter,u as BaseComponent,n as Data,x as IDB,D as TypedCollection,w as TypedData,d as UID,v as applyAttributes,N as applyStyles,M as create};
|
|
1
|
+
var L=Object.defineProperty;var $=(o,t,e)=>t in o?L(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var E=(o,t,e)=>($(o,typeof t!="symbol"?t+"":t,e),e);function F(o){let t=e=>{var s;for(let r in e)((s=e[r])==null?void 0:s.constructor)===Object&&(e[r]=t(e[r]));return{...e}};return t(o)}var n=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=F(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(n.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(r=>{r(this.store[t])}))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){n.warn("publish",t);return}this.add(t,e)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(n.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete n.globalStore[this.uid]}static registerLocalCtx(t){let e=new n({schema:t});return n.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=n.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new n({name:t,schema:e}),n.globalStore[t]=s),s}static clearNamedCtx(t){delete n.globalStore[t]}static getNamedCtx(t,e=!0){return n.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};n.globalStore=Object.create(null);var h=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym"});var P="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",B=P.length-1,_=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:P.charAt(Math.random()*B);return e}};function U(o,t){if(t.renderShadow)return;let e=[...t.childNodes],s=[...o.querySelectorAll("slot")];if(e.length&&s.length){let r={};s.forEach(i=>{let a=i.getAttribute("name");a?r[a]={slot:i,fr:document.createDocumentFragment()}:r.__default__={slot:i,fr:document.createDocumentFragment()}}),e.forEach(i=>{var l;let a=(l=i.getAttribute)==null?void 0:l.call(i,"slot");a?(i.removeAttribute("slot"),r[a].fr.appendChild(i)):r.__default__&&r.__default__.fr.appendChild(i)}),Object.values(r).forEach(i=>{i.slot.parentNode.insertBefore(i.fr,i.slot),i.slot.remove()})}else t.innerHTML=""}function H(o,t){[...o.querySelectorAll(`[${h.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(h.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(h.EL_REF_ATTR)})}function W(o,t){[...o.querySelectorAll(`[${h.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(h.BIND_ATTR).split(";").forEach(i=>{if(!i)return;let a=i.split(":").map(u=>u.trim()),l=a[0],m;l.indexOf(h.ATTR_BIND_PRFX)===0&&(m=!0,l=l.replace(h.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(u=>u.trim()),A,p,C,g;if(l.includes(".")){A=!0;let u=l.split(".");g=()=>{p=e,u.forEach((c,j)=>{j<u.length-1?p=p[c]:C=c})},g()}for(let u of b)t.sub(u,c=>{m?(c==null?void 0:c.constructor)===Boolean?c?e.setAttribute(l,""):e.removeAttribute(l):e.setAttribute(l,c):A?p?p[C]=c:window.setTimeout(()=>{g(),p[C]=c}):e[l]=c})}),e.removeAttribute(h.BIND_ATTR)})}var T="{{",y="}}",V="skip-text";function q(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:r=>{var i;return!((i=r.parentElement)==null?void 0:i.hasAttribute(V))&&r.textContent.includes(T)&&r.textContent.includes(y)&&1}});for(;t=s.nextNode();)e.push(t);return e}var z=function(o,t){q(o).forEach(s=>{let r=[],i;for(;s.textContent.includes(y);)s.textContent.startsWith(T)?(i=s.textContent.indexOf(y)+2,s.splitText(i),r.push(s)):(i=s.textContent.indexOf(T),s.splitText(i)),s=s.nextSibling;r.forEach(a=>{let l=a.textContent.replace(T,"").replace(y,"");t.sub(l,m=>{a.textContent=m})})})},R=[U,H,W,z];var D=0,d=class extends HTMLElement{initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if(t||this.constructor.template){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);this.firstChild;)this.firstChild.remove();if((t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let i=document.createElement("template");i.innerHTML=t,s=i.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let i of this.tplProcessors)i(s,this)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});let r=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let i=document.createElement("link");i.rel="stylesheet",i.href=this.constructor.__shadowStylesUrl,i.onload=r,this.shadowRoot.prepend(i)}else r()}addTemplateProcessor(t){this.tplProcessors.add(t)}constructor(){super();this.init$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=_.generate(),this.style.setProperty(h.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(h.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(h.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=n.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return n.getNamedCtx(this.ctxName,!1)||n.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,r;if(t.startsWith(h.EXT_DATA_CTX_PRFX))s=e.nodeCtx,r=t.replace(h.EXT_DATA_CTX_PRFX,"");else if(t.includes(h.NAMED_DATA_CTX_SPLTR)){let i=t.split(h.NAMED_DATA_CTX_SPLTR);s=n.getNamedCtx(i[0]),r=i[1]}else s=e.localCtx,r=t;return{ctx:s,name:r}}sub(t,e){let s=d.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=d.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=d.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=d.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,r)=>{let i=d.__parseProp(s,this);return i.ctx.pub(i.name,r),!0},get:(e,s)=>{let r=d.__parseProp(s,this);return r.ctx.read(r.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(h.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(h.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(h.NAMED_DATA_CTX_SPLTR)){let s=e.split(h.NAMED_DATA_CTX_SPLTR),r=s[0].trim(),i=s[1].trim();if(r&&i){let a=n.getNamedCtx(r,!1);a||(a=n.registerNamedCtx(r,{})),a.add(i,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(h.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(h.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx();for(let s of R)this.addTemplateProcessor(s);this.pauseRender||this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t)},100))}static reg(t,e=!1){if(t||(D++,t=`${h.AUTO_TAG_PRFX}-${D}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let r=this.constructor.__attrDesc[t];r?this.__dataCtxInitialized?this.$[r]=s:this.init$[r]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}bindCssData(t,e=!0){let s=(e?h.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let r="__"+t;this[r]=this[t],Object.defineProperty(this,t,{set:i=>{this[r]=i,s?window.setTimeout(()=>{e==null||e(i)}):e==null||e(i)},get:()=>this[r]}),this[t]=this[r]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},S=d;E(S,"template");var N="[Typed State] Wrong property name: ",G="[Typed State] Wrong property type: ",w=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||_.generate(),this.__schema=Object.keys(t).reduce((s,r)=>(s[r]=t[r].value,s),{}),this.__state=n.registerNamedCtx(this.__ctxId,this.__schema)}setValue(t,e){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(N+t);return}if((e==null?void 0:e.constructor)!==this.__typedSchema[t].type){console.warn(G+t);return}this.__state.pub(t,e)}setMultipleValues(t){for(let e in t)this.setValue(e,t[e])}getValue(t){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(N+t);return}return this.__state.read(t)}subscribe(t,e){return this.__state.sub(t,e)}remove(){this.__state.remove()}};var v=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||_.generate(),this.__state=n.registerNamedCtx(this.__ctxId,{}),this.__watchList=t.watchList||[],this.__handler=t.handler||null,this.__subsMap=Object.create(null),this.__observers=new Set,this.__items=new Set;let e=Object.create(null);this.__notifyObservers=(s,r)=>{this.__observeTimeout&&window.clearTimeout(this.__observeTimeout),e[s]||(e[s]=new Set),e[s].add(r),this.__observeTimeout=window.setTimeout(()=>{this.__observers.forEach(i=>{i({...e})}),e=Object.create(null)})}}notify(){this.__notifyTimeout&&window.clearTimeout(this.__notifyTimeout),this.__notifyTimeout=window.setTimeout(()=>{var t;(t=this.__handler)==null||t.call(this,[...this.__items])})}add(t){let e=new w(this.__typedSchema);for(let s in t)e.setValue(s,t[s]);return this.__state.add(e.__ctxId,e),this.__watchList.forEach(s=>{this.__subsMap[e.__ctxId]||(this.__subsMap[e.__ctxId]=[]),this.__subsMap[e.__ctxId].push(e.subscribe(s,()=>{this.__notifyObservers(s,e.__ctxId)}))}),this.__items.add(e.__ctxId),this.notify(),e}read(t){return this.__state.read(t)}readProp(t,e){return this.read(t).getValue(e)}publishProp(t,e,s){this.read(t).setValue(e,s)}remove(t){this.__items.delete(t),this.notify(),this.__state.pub(t,null),delete this.__subsMap[t]}clearAll(){this.__items.forEach(t=>{this.remove(t)})}observe(t){this.__observers.add(t)}unobserve(t){this.__observers.delete(t)}findItems(t){let e=[];return this.__items.forEach(s=>{let r=this.read(s);t(r)&&e.push(s)}),e}items(){return[...this.__items]}destroy(){this.__state.remove(),this.__observers=null;for(let t in this.__subsMap)this.__subsMap[t].forEach(e=>{e.remove()}),delete this.__subsMap[t]}};var f=class{static _print(t){console.warn(t)}static setDefaultTitle(t){this.defaultTitle=t}static setRoutingMap(t){Object.assign(this.appMap,t);for(let e in this.appMap)!this.defaultRoute&&this.appMap[e].default===!0?this.defaultRoute=e:!this.errorRoute&&this.appMap[e].error===!0&&(this.errorRoute=e)}static set routingEventName(t){this.__routingEventName=t}static get routingEventName(){return this.__routingEventName||"sym-on-route"}static readAddressBar(){let t={route:null,options:{}};return window.location.search.split(this.separator).forEach(s=>{if(s.includes("?"))t.route=s.replace("?","");else if(s.includes("=")){let r=s.split("=");t.options[r[0]]=decodeURI(r[1])}else t.options[s]=!0}),t}static notify(){let t=this.readAddressBar(),e=this.appMap[t.route];if(e&&e.title&&(document.title=e.title),t.route===null&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e&&this.errorRoute){this.applyRoute(this.errorRoute);return}else if(!e&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e){this._print(`Route "${t.route}" not found...`);return}let s=new CustomEvent(f.routingEventName,{detail:{route:t.route,options:Object.assign(e||{},t.options)}});window.dispatchEvent(s)}static reflect(t,e={}){let s=this.appMap[t];if(!s){this._print("Wrong route: "+t);return}let r="?"+t;for(let a in e)e[a]===!0?r+=this.separator+a:r+=this.separator+a+`=${e[a]}`;let i=s.title||this.defaultTitle||"";window.history.pushState(null,i,r),document.title=i}static applyRoute(t,e={}){this.reflect(t,e),this.notify()}static setSeparator(t){this._separator=t}static get separator(){return this._separator||"&"}static createRouterData(t,e){this.setRoutingMap(e);let s=n.registerNamedCtx(t,{route:null,options:null,title:null});return window.addEventListener(this.routingEventName,r=>{var i;s.multiPub({route:r.detail.route,options:r.detail.options,title:((i=r.detail.options)==null?void 0:i.title)||this.defaultTitle||""})}),f.notify(),s}};f.appMap=Object.create(null);window.onpopstate=()=>{f.notify()};function M(o,t){for(let e in t)e.includes("-")?o.style.setProperty(e,t[e]):o.style[e]=t[e]}function X(o,t){for(let e in t)t[e].constructor===Boolean?t[e]?o.setAttribute(e,""):o.removeAttribute(e):o.setAttribute(e,t[e])}function O(o={tag:"div"}){let t=document.createElement(o.tag);if(o.attributes&&X(t,o.attributes),o.styles&&M(t,o.styles),o.properties)for(let e in o.properties)t[e]=o.properties[e];return o.processors&&o.processors.forEach(e=>{e(t)}),o.children&&o.children.forEach(e=>{let s=O(e);t.appendChild(s)}),t}var I="idb-store-ready",K="symbiote-db",Y="symbiote-idb-update_",k=class{_notifyWhenReady(t=null){window.dispatchEvent(new CustomEvent(I,{detail:{dbName:this.name,storeName:this.storeName,event:t}}))}get _updEventName(){return Y+this.name}_getUpdateEvent(t){return new CustomEvent(this._updEventName,{detail:{key:this.name,newValue:t}})}_notifySubscribers(t){window.localStorage.removeItem(this.name),window.localStorage.setItem(this.name,t),window.dispatchEvent(this._getUpdateEvent(t))}constructor(t,e){this.name=t,this.storeName=e,this.version=1,this.request=window.indexedDB.open(this.name,this.version),this.request.onupgradeneeded=s=>{this.db=s.target.result,this.objStore=this.db.createObjectStore(e,{keyPath:"_key"}),this.objStore.transaction.oncomplete=r=>{this._notifyWhenReady(r)}},this.request.onsuccess=s=>{this.db=s.target.result,this._notifyWhenReady(s)},this.request.onerror=s=>{console.error(s)},this._subscribtionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscribtionsMap[s.newValue]&&this._subscribtionsMap[s.newValue].forEach(async i=>{i(await this.read(s.newValue))})},this._localUpdateHandler=s=>{this._updateHandler(s.detail)},window.addEventListener("storage",this._updateHandler),window.addEventListener(this._updEventName,this._localUpdateHandler)}read(t){let s=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).get(t);return new Promise((r,i)=>{s.onsuccess=a=>{var l;((l=a.target.result)==null?void 0:l._value)?r(a.target.result._value):(r(null),console.warn(`IDB: cannot read "${t}"`))},s.onerror=a=>{i(a)}})}write(t,e,s=!1){let r={_key:t,_value:e},a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(r);return new Promise((l,m)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),l(b.target.result)},a.onerror=b=>{m(b)}})}delete(t,e=!1){let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(t);return new Promise((i,a)=>{r.onsuccess=l=>{e||this._notifySubscribers(t),i(l)},r.onerror=l=>{a(l)}})}getAll(){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,r)=>{e.onsuccess=i=>{let a=i.target.result;s(a.map(l=>l._value))},e.onerror=i=>{r(i)}})}subscribe(t,e){this._subscribtionsMap[t]||(this._subscribtionsMap[t]=new Set);let s=this._subscribtionsMap[t];return s.add(e),{remove:()=>{s.delete(e),s.size||delete this._subscribtionsMap[t]}}}stop(){window.removeEventListener("storage",this._updateHandler),this.__subscribtionsMap=null,x.clear(this.name)}},x=class{static get readyEventName(){return I}static open(t=K,e="store"){let s=t+"/"+e;return this._reg[s]||(this._reg[s]=new k(t,e)),this._reg[s]}static clear(t){window.indexedDB.deleteDatabase(t);for(let e in this._reg)e.split("/")[0]===t&&delete this._reg[e]}};x._reg=Object.create(null);export{f as AppRouter,S as BaseComponent,n as Data,x as IDB,v as TypedCollection,w as TypedData,_ as UID,X as applyAttributes,M as applyStyles,O as create};
|