@symbiotejs/symbiote 1.4.3 → 1.4.7
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 +62 -79
- package/build/symbiote.js +40 -28
- package/build/symbiote.min.js +1 -1
- package/core/BaseComponent.js +3 -6
- package/core/TypedCollection.js +12 -12
- package/core/TypedData.js +18 -6
- package/core/tpl-processors.js +2 -3
- package/package.json +2 -1
- package/utils/IDB.js +5 -3
- package/utils/dom-helpers.js +5 -15
|
@@ -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 i in e)((s=e[i])==null?void 0:s.constructor)===Object&&(e[i]=t(e[i]));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(i=>{i(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=[...n.querySelectorAll("slot")];if(t.initChildren.length&&e.length){let s={};e.forEach(i=>{let r=i.getAttribute("name");r?s[r]={slot:i,fr:document.createDocumentFragment()}:s.__default__={slot:i,fr:document.createDocumentFragment()}}),t.initChildren.forEach(i=>{var a;let r=(a=i.getAttribute)==null?void 0:a.call(i,"slot");r?(i.removeAttribute("slot"),s[r].fr.appendChild(i)):s.__default__&&s.__default__.fr.appendChild(i)}),Object.values(s).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(r=>{if(!r)return;let a=r.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:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute($))&&i.textContent.includes(T)&&i.textContent.includes(C)&&1}});for(;t=s.nextNode();)e.push(t);return e}var L=function(n,t){F(n).forEach(s=>{let i=[],r;for(;s.textContent.includes(C);)s.textContent.startsWith(T)?(r=s.textContent.indexOf(C)+2,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(T),s.splitText(r)),s=s.nextSibling;i.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 r=document.createElement("template");r.innerHTML=t,s=r.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let r of this.tplProcessors)r(s,this)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});let i=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let r=document.createElement("link");r.rel="stylesheet",r.href=this.constructor.__shadowStylesUrl,r.onload=i,this.shadowRoot.prepend(r)}else i()}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,i;if(t.startsWith(o.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(o.EXT_DATA_CTX_PRFX,"");else if(t.includes(o.NAMED_DATA_CTX_SPLTR)){let r=t.split(o.NAMED_DATA_CTX_SPLTR);s=l.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}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,i)=>{let r=_.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=_.__parseProp(s,this);return i.ctx.read(i.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),i=s[0].trim(),r=s[1].trim();if(i&&r){let a=l.getNamedCtx(i,!1);a||(a=l.registerNamedCtx(i,{})),a.add(r,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(),this.initChildren=[...this.childNodes];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 i=this.constructor.__attrDesc[t];i?this.__dataCtxInitialized?this.$[i]=s:this.init$[i]=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 i="__"+t;this[i]=this[t],Object.defineProperty(this,t,{set:r=>{this[i]=r,s?window.setTimeout(()=>{e==null||e(r)}):e==null||e(r)},get:()=>this[i]}),this[t]=this[i]}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,54 @@ 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]: any;
|
|
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:
|
|
76
|
+
add<T_2>(prop: string, val: T_2): void;
|
|
79
77
|
add$(obj: {
|
|
80
78
|
[x: string]: any;
|
|
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
|
-
|
|
90
|
+
initChildren: ChildNode[];
|
|
95
91
|
connectedOnce: boolean;
|
|
96
92
|
destroyCallback(): void;
|
|
97
93
|
disconnectedCallback(): void;
|
|
98
|
-
__disconnectTimeout
|
|
94
|
+
private __disconnectTimeout;
|
|
99
95
|
attributeChangedCallback(name: any, oldVal: any, newVal: any): void;
|
|
100
96
|
getCssData(propName: string, silentCheck?: boolean): any;
|
|
101
|
-
__cssDataCache
|
|
102
|
-
__computedStyle
|
|
97
|
+
private __cssDataCache;
|
|
98
|
+
private __computedStyle;
|
|
103
99
|
bindCssData(propName: string, external?: boolean): string;
|
|
104
100
|
dropCssDataCache(): void;
|
|
105
101
|
defineAccessor(propName: string, handler?: Function, isAsync?: boolean): void;
|
|
@@ -111,15 +107,11 @@ export class TypedData {
|
|
|
111
107
|
value: any;
|
|
112
108
|
};
|
|
113
109
|
}, ctxName?: string);
|
|
114
|
-
__typedSchema
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
__ctxId: string;
|
|
121
|
-
__schema: {};
|
|
122
|
-
__state: Data;
|
|
110
|
+
private __typedSchema;
|
|
111
|
+
private __ctxId;
|
|
112
|
+
private __schema;
|
|
113
|
+
private __data;
|
|
114
|
+
get uid(): string;
|
|
123
115
|
setValue(prop: string, value: any): void;
|
|
124
116
|
setMultipleValues(updObj: {
|
|
125
117
|
[x: string]: any;
|
|
@@ -143,28 +135,25 @@ export class TypedCollection {
|
|
|
143
135
|
handler?: (list: string[]) => void;
|
|
144
136
|
ctxName?: string;
|
|
145
137
|
});
|
|
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;
|
|
138
|
+
private __typedSchema;
|
|
139
|
+
private __ctxId;
|
|
140
|
+
private __data;
|
|
141
|
+
private __watchList;
|
|
142
|
+
private __handler;
|
|
143
|
+
private __subsMap;
|
|
144
|
+
private __observers;
|
|
145
|
+
private __items;
|
|
146
|
+
private __notifyObservers;
|
|
147
|
+
private __observeTimeout;
|
|
161
148
|
notify(): void;
|
|
162
|
-
__notifyTimeout
|
|
163
|
-
add(init:
|
|
149
|
+
private __notifyTimeout;
|
|
150
|
+
add(init: {
|
|
151
|
+
[x: string]: any;
|
|
152
|
+
}): any;
|
|
164
153
|
read(id: string): TypedData;
|
|
165
|
-
readProp(id:
|
|
166
|
-
publishProp(id:
|
|
167
|
-
remove(id:
|
|
154
|
+
readProp(id: string, propName: string): any;
|
|
155
|
+
publishProp<T>(id: string, propName: string, value: T): void;
|
|
156
|
+
remove(id: string): void;
|
|
168
157
|
clearAll(): void;
|
|
169
158
|
observe(handler: Function): void;
|
|
170
159
|
unobserve(handler: Function): void;
|
|
@@ -173,13 +162,13 @@ export class TypedCollection {
|
|
|
173
162
|
destroy(): void;
|
|
174
163
|
}
|
|
175
164
|
export class AppRouter {
|
|
176
|
-
static _print
|
|
165
|
+
private static _print;
|
|
177
166
|
static setDefaultTitle(title: string): void;
|
|
178
167
|
static setRoutingMap(map: {
|
|
179
168
|
[x: string]: {};
|
|
180
169
|
}): void;
|
|
181
|
-
static set routingEventName(arg:
|
|
182
|
-
static get routingEventName():
|
|
170
|
+
static set routingEventName(arg: string);
|
|
171
|
+
static get routingEventName(): string;
|
|
183
172
|
static readAddressBar(): {
|
|
184
173
|
route: any;
|
|
185
174
|
options: {};
|
|
@@ -201,7 +190,7 @@ export namespace AppRouter {
|
|
|
201
190
|
const defaultTitle: string;
|
|
202
191
|
const defaultRoute: string;
|
|
203
192
|
const errorRoute: string;
|
|
204
|
-
const __routingEventName:
|
|
193
|
+
const __routingEventName: string;
|
|
205
194
|
const _separator: string;
|
|
206
195
|
const appMap: any;
|
|
207
196
|
}
|
|
@@ -211,44 +200,38 @@ export class UID {
|
|
|
211
200
|
export class IDB {
|
|
212
201
|
static get readyEventName(): string;
|
|
213
202
|
static open(dbName?: string, storeName?: string): DbInstance;
|
|
203
|
+
private static _reg;
|
|
214
204
|
static clear(dbName: string): void;
|
|
215
205
|
}
|
|
216
|
-
export namespace IDB {
|
|
217
|
-
const _reg: any;
|
|
218
|
-
}
|
|
219
206
|
declare class DbInstance {
|
|
220
207
|
constructor(dbName: string, storeName: string);
|
|
221
|
-
_notifyWhenReady
|
|
222
|
-
get _updEventName()
|
|
223
|
-
_getUpdateEvent
|
|
224
|
-
|
|
225
|
-
newValue: any;
|
|
226
|
-
}>;
|
|
227
|
-
_notifySubscribers(key: any): void;
|
|
208
|
+
private _notifyWhenReady;
|
|
209
|
+
private get _updEventName();
|
|
210
|
+
private _getUpdateEvent;
|
|
211
|
+
private _notifySubscribers;
|
|
228
212
|
name: string;
|
|
229
213
|
storeName: string;
|
|
230
214
|
version: number;
|
|
231
215
|
request: IDBOpenDBRequest;
|
|
232
216
|
db: any;
|
|
233
217
|
objStore: any;
|
|
234
|
-
_subscribtionsMap
|
|
235
|
-
_updateHandler
|
|
236
|
-
_localUpdateHandler
|
|
218
|
+
private _subscribtionsMap;
|
|
219
|
+
private _updateHandler;
|
|
220
|
+
private _localUpdateHandler;
|
|
237
221
|
read(key: string): Promise<any>;
|
|
238
222
|
write(key: string, value: any, silent?: boolean): Promise<any>;
|
|
239
223
|
delete(key: string, silent?: boolean): Promise<any>;
|
|
240
224
|
getAll(): Promise<any>;
|
|
241
|
-
subscribe(key: string, callback:
|
|
225
|
+
subscribe(key: string, callback: (val: any) => void): {
|
|
242
226
|
remove: () => void;
|
|
243
227
|
};
|
|
244
228
|
stop(): void;
|
|
245
|
-
__subscribtionsMap: any;
|
|
246
229
|
}
|
|
247
|
-
export function applyStyles(el:
|
|
248
|
-
export function applyAttributes(el:
|
|
249
|
-
export function create(desc?: ElementDescriptor):
|
|
230
|
+
export function applyStyles<T extends HTMLElement>(el: T, styleMap: StyleMap): void;
|
|
231
|
+
export function applyAttributes<T extends HTMLElement>(el: T, attrMap: AttrMap): void;
|
|
232
|
+
export function create(desc?: ElementDescriptor): any;
|
|
250
233
|
export type StyleMap = {
|
|
251
|
-
[x: string]: string | number;
|
|
234
|
+
[x: string]: string | number | boolean;
|
|
252
235
|
};
|
|
253
236
|
export type AttrMap = {
|
|
254
237
|
[x: string]: string | number | boolean;
|
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) => {
|
|
@@ -151,7 +158,7 @@ function slotProcessor(fr, fnCtx) {
|
|
|
151
158
|
return;
|
|
152
159
|
}
|
|
153
160
|
let slots = [...fr.querySelectorAll("slot")];
|
|
154
|
-
if (fnCtx.
|
|
161
|
+
if (fnCtx.initChildren.length && slots.length) {
|
|
155
162
|
let slotMap = {};
|
|
156
163
|
slots.forEach((slot) => {
|
|
157
164
|
let slotName = slot.getAttribute("name");
|
|
@@ -167,7 +174,7 @@ function slotProcessor(fr, fnCtx) {
|
|
|
167
174
|
};
|
|
168
175
|
}
|
|
169
176
|
});
|
|
170
|
-
fnCtx.
|
|
177
|
+
fnCtx.initChildren.forEach((child) => {
|
|
171
178
|
var _a;
|
|
172
179
|
let slotName = (_a = child.getAttribute) == null ? void 0 : _a.call(child, "slot");
|
|
173
180
|
if (slotName) {
|
|
@@ -297,7 +304,7 @@ var tpl_processors_default = [slotProcessor, refProcessor, domSetProcessor, txtN
|
|
|
297
304
|
|
|
298
305
|
// core/BaseComponent.js
|
|
299
306
|
var autoTagsCount = 0;
|
|
300
|
-
var
|
|
307
|
+
var _BaseComponent = class extends HTMLElement {
|
|
301
308
|
initCallback() {
|
|
302
309
|
}
|
|
303
310
|
__initCallback() {
|
|
@@ -407,19 +414,19 @@ var BaseComponent = class extends HTMLElement {
|
|
|
407
414
|
};
|
|
408
415
|
}
|
|
409
416
|
sub(prop, handler) {
|
|
410
|
-
let parsed =
|
|
417
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
411
418
|
this.allSubs.add(parsed.ctx.sub(parsed.name, handler));
|
|
412
419
|
}
|
|
413
420
|
notify(prop) {
|
|
414
|
-
let parsed =
|
|
421
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
415
422
|
parsed.ctx.notify(parsed.name);
|
|
416
423
|
}
|
|
417
424
|
has(prop) {
|
|
418
|
-
let parsed =
|
|
425
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
419
426
|
return parsed.ctx.has(parsed.name);
|
|
420
427
|
}
|
|
421
428
|
add(prop, val) {
|
|
422
|
-
let parsed =
|
|
429
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
423
430
|
parsed.ctx.add(parsed.name, val, false);
|
|
424
431
|
}
|
|
425
432
|
add$(obj) {
|
|
@@ -432,12 +439,12 @@ var BaseComponent = class extends HTMLElement {
|
|
|
432
439
|
let o = Object.create(null);
|
|
433
440
|
this.__stateProxy = new Proxy(o, {
|
|
434
441
|
set: (obj, prop, val) => {
|
|
435
|
-
let parsed =
|
|
442
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
436
443
|
parsed.ctx.pub(parsed.name, val);
|
|
437
444
|
return true;
|
|
438
445
|
},
|
|
439
446
|
get: (obj, prop) => {
|
|
440
|
-
let parsed =
|
|
447
|
+
let parsed = _BaseComponent.__parseProp(prop, this);
|
|
441
448
|
return parsed.ctx.read(parsed.name);
|
|
442
449
|
}
|
|
443
450
|
});
|
|
@@ -489,7 +496,7 @@ var BaseComponent = class extends HTMLElement {
|
|
|
489
496
|
this.style.setProperty(DICT.CSS_CTX_PROP, `'${ctxNameAttrVal}'`);
|
|
490
497
|
}
|
|
491
498
|
this.__initDataCtx();
|
|
492
|
-
this.
|
|
499
|
+
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: ";
|
|
@@ -627,7 +636,10 @@ var TypedData = class {
|
|
|
627
636
|
acc[key] = typedSchema[key].value;
|
|
628
637
|
return acc;
|
|
629
638
|
}, {});
|
|
630
|
-
this.
|
|
639
|
+
this.__data = Data.registerNamedCtx(this.__ctxId, this.__schema);
|
|
640
|
+
}
|
|
641
|
+
get uid() {
|
|
642
|
+
return this.__ctxId;
|
|
631
643
|
}
|
|
632
644
|
setValue(prop, value) {
|
|
633
645
|
if (!this.__typedSchema.hasOwnProperty(prop)) {
|
|
@@ -638,7 +650,7 @@ var TypedData = class {
|
|
|
638
650
|
console.warn(MSG_TYPE + prop);
|
|
639
651
|
return;
|
|
640
652
|
}
|
|
641
|
-
this.
|
|
653
|
+
this.__data.pub(prop, value);
|
|
642
654
|
}
|
|
643
655
|
setMultipleValues(updObj) {
|
|
644
656
|
for (let prop in updObj) {
|
|
@@ -650,13 +662,13 @@ var TypedData = class {
|
|
|
650
662
|
console.warn(MSG_NAME + prop);
|
|
651
663
|
return void 0;
|
|
652
664
|
}
|
|
653
|
-
return this.
|
|
665
|
+
return this.__data.read(prop);
|
|
654
666
|
}
|
|
655
667
|
subscribe(prop, handler) {
|
|
656
|
-
return this.
|
|
668
|
+
return this.__data.sub(prop, handler);
|
|
657
669
|
}
|
|
658
670
|
remove() {
|
|
659
|
-
this.
|
|
671
|
+
this.__data.remove();
|
|
660
672
|
}
|
|
661
673
|
};
|
|
662
674
|
|
|
@@ -665,7 +677,7 @@ var TypedCollection = class {
|
|
|
665
677
|
constructor(options) {
|
|
666
678
|
this.__typedSchema = options.typedSchema;
|
|
667
679
|
this.__ctxId = options.ctxName || UID.generate();
|
|
668
|
-
this.
|
|
680
|
+
this.__data = Data.registerNamedCtx(this.__ctxId, {});
|
|
669
681
|
this.__watchList = options.watchList || [];
|
|
670
682
|
this.__handler = options.handler || null;
|
|
671
683
|
this.__subsMap = Object.create(null);
|
|
@@ -702,21 +714,21 @@ var TypedCollection = class {
|
|
|
702
714
|
for (let prop in init) {
|
|
703
715
|
item.setValue(prop, init[prop]);
|
|
704
716
|
}
|
|
705
|
-
this.
|
|
717
|
+
this.__data.add(item.uid, item);
|
|
706
718
|
this.__watchList.forEach((propName) => {
|
|
707
|
-
if (!this.__subsMap[item.
|
|
708
|
-
this.__subsMap[item.
|
|
719
|
+
if (!this.__subsMap[item.uid]) {
|
|
720
|
+
this.__subsMap[item.uid] = [];
|
|
709
721
|
}
|
|
710
|
-
this.__subsMap[item.
|
|
711
|
-
this.__notifyObservers(propName, item.
|
|
722
|
+
this.__subsMap[item.uid].push(item.subscribe(propName, () => {
|
|
723
|
+
this.__notifyObservers(propName, item.uid);
|
|
712
724
|
}));
|
|
713
725
|
});
|
|
714
|
-
this.__items.add(item.
|
|
726
|
+
this.__items.add(item.uid);
|
|
715
727
|
this.notify();
|
|
716
728
|
return item;
|
|
717
729
|
}
|
|
718
730
|
read(id) {
|
|
719
|
-
return this.
|
|
731
|
+
return this.__data.read(id);
|
|
720
732
|
}
|
|
721
733
|
readProp(id, propName) {
|
|
722
734
|
let item = this.read(id);
|
|
@@ -729,7 +741,7 @@ var TypedCollection = class {
|
|
|
729
741
|
remove(id) {
|
|
730
742
|
this.__items.delete(id);
|
|
731
743
|
this.notify();
|
|
732
|
-
this.
|
|
744
|
+
this.__data.pub(id, null);
|
|
733
745
|
delete this.__subsMap[id];
|
|
734
746
|
}
|
|
735
747
|
clearAll() {
|
|
@@ -757,7 +769,7 @@ var TypedCollection = class {
|
|
|
757
769
|
return [...this.__items];
|
|
758
770
|
}
|
|
759
771
|
destroy() {
|
|
760
|
-
this.
|
|
772
|
+
this.__data.remove();
|
|
761
773
|
this.__observers = null;
|
|
762
774
|
for (let id in this.__subsMap) {
|
|
763
775
|
this.__subsMap[id].forEach((sub) => {
|
|
@@ -1089,7 +1101,7 @@ var DbInstance = class {
|
|
|
1089
1101
|
}
|
|
1090
1102
|
stop() {
|
|
1091
1103
|
window.removeEventListener("storage", this._updateHandler);
|
|
1092
|
-
this.
|
|
1104
|
+
this._subscribtionsMap = null;
|
|
1093
1105
|
IDB.clear(this.name);
|
|
1094
1106
|
}
|
|
1095
1107
|
};
|
|
@@ -1098,7 +1110,7 @@ var IDB = class {
|
|
|
1098
1110
|
return READY_EVENT_NAME;
|
|
1099
1111
|
}
|
|
1100
1112
|
static open(dbName = DEFAULT_DB_NAME, storeName = "store") {
|
|
1101
|
-
let key =
|
|
1113
|
+
let key = dbName + "/" + storeName;
|
|
1102
1114
|
if (!this._reg[key]) {
|
|
1103
1115
|
this._reg[key] = new DbInstance(dbName, storeName);
|
|
1104
1116
|
}
|
|
@@ -1113,7 +1125,7 @@ var IDB = class {
|
|
|
1113
1125
|
}
|
|
1114
1126
|
}
|
|
1115
1127
|
};
|
|
1116
|
-
IDB
|
|
1128
|
+
__publicField(IDB, "_reg", Object.create(null));
|
|
1117
1129
|
export {
|
|
1118
1130
|
AppRouter,
|
|
1119
1131
|
BaseComponent,
|
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 T=(o,t,e)=>($(o,typeof t!="symbol"?t+"":t,e),e);function F(o){let t=e=>{var s;for(let i in e)((s=e[i])==null?void 0:s.constructor)===Object&&(e[i]=t(e[i]));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(i=>{i(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 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=[...o.querySelectorAll("slot")];if(t.initChildren.length&&e.length){let s={};e.forEach(i=>{let r=i.getAttribute("name");r?s[r]={slot:i,fr:document.createDocumentFragment()}:s.__default__={slot:i,fr:document.createDocumentFragment()}}),t.initChildren.forEach(i=>{var a;let r=(a=i.getAttribute)==null?void 0:a.call(i,"slot");r?(i.removeAttribute("slot"),s[r].fr.appendChild(i)):s.__default__&&s.__default__.fr.appendChild(i)}),Object.values(s).forEach(i=>{i.slot.parentNode.insertBefore(i.fr,i.slot),i.slot.remove()})}else t.innerHTML=""}function H(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 W(o,t){[...o.querySelectorAll(`[${l.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(l.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let a=r.split(":").map(c=>c.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(c=>c.trim()),E,p,x,S;if(h.includes(".")){E=!0;let c=h.split(".");S=()=>{p=e,c.forEach((u,j)=>{j<c.length-1?p=p[u]:x=u})},S()}for(let c of b)t.sub(c,u=>{m?(u==null?void 0:u.constructor)===Boolean?u?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,u):E?p?p[x]=u:window.setTimeout(()=>{S(),p[x]=u}):e[h]=u})}),e.removeAttribute(l.BIND_ATTR)})}var y="{{",w="}}",V="skip-text";function q(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(V))&&i.textContent.includes(y)&&i.textContent.includes(w)&&1}});for(;t=s.nextNode();)e.push(t);return e}var z=function(o,t){q(o).forEach(s=>{let i=[],r;for(;s.textContent.includes(w);)s.textContent.startsWith(y)?(r=s.textContent.indexOf(w)+2,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(y),s.splitText(r)),s=s.nextSibling;i.forEach(a=>{let h=a.textContent.replace(y,"").replace(w,"");t.sub(h,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 r=document.createElement("template");r.innerHTML=t,s=r.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let r of this.tplProcessors)r(s,this)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});let i=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let r=document.createElement("link");r.rel="stylesheet",r.href=this.constructor.__shadowStylesUrl,r.onload=i,this.shadowRoot.prepend(r)}else i()}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(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,i;if(t.startsWith(l.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(l.EXT_DATA_CTX_PRFX,"");else if(t.includes(l.NAMED_DATA_CTX_SPLTR)){let r=t.split(l.NAMED_DATA_CTX_SPLTR);s=n.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}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,i)=>{let r=d.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=d.__parseProp(s,this);return i.ctx.read(i.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),i=s[0].trim(),r=s[1].trim();if(i&&r){let a=n.getNamedCtx(i,!1);a||(a=n.registerNamedCtx(i,{})),a.add(r,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 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=`${l.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 i=this.constructor.__attrDesc[t];i?this.__dataCtxInitialized?this.$[i]=s:this.init$[i]=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 i="__"+t;this[i]=this[t],Object.defineProperty(this,t,{set:r=>{this[i]=r,s?window.setTimeout(()=>{e==null||e(r)}):e==null||e(r)},get:()=>this[i]}),this[t]=this[i]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},A=d;T(A,"template");var N="[Typed State] Wrong property name: ",G="[Typed State] Wrong property type: ",C=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||_.generate(),this.__schema=Object.keys(t).reduce((s,i)=>(s[i]=t[i].value,s),{}),this.__data=n.registerNamedCtx(this.__ctxId,this.__schema)}get uid(){return this.__ctxId}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.__data.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.__data.read(t)}subscribe(t,e){return this.__data.sub(t,e)}remove(){this.__data.remove()}};var v=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||_.generate(),this.__data=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,i)=>{this.__observeTimeout&&window.clearTimeout(this.__observeTimeout),e[s]||(e[s]=new Set),e[s].add(i),this.__observeTimeout=window.setTimeout(()=>{this.__observers.forEach(r=>{r({...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 C(this.__typedSchema);for(let s in t)e.setValue(s,t[s]);return this.__data.add(e.uid,e),this.__watchList.forEach(s=>{this.__subsMap[e.uid]||(this.__subsMap[e.uid]=[]),this.__subsMap[e.uid].push(e.subscribe(s,()=>{this.__notifyObservers(s,e.uid)}))}),this.__items.add(e.uid),this.notify(),e}read(t){return this.__data.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.__data.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 i=this.read(s);t(i)&&e.push(s)}),e}items(){return[...this.__items]}destroy(){this.__data.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 i=s.split("=");t.options[i[0]]=decodeURI(i[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 i="?"+t;for(let a in e)e[a]===!0?i+=this.separator+a:i+=this.separator+a+`=${e[a]}`;let r=s.title||this.defaultTitle||"";window.history.pushState(null,r,i),document.title=r}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,i=>{var r;s.multiPub({route:i.detail.route,options:i.detail.options,title:((r=i.detail.options)==null?void 0:r.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=i=>{this._notifyWhenReady(i)}},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 r=>{r(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((i,r)=>{s.onsuccess=a=>{var h;((h=a.target.result)==null?void 0:h._value)?i(a.target.result._value):(i(null),console.warn(`IDB: cannot read "${t}"`))},s.onerror=a=>{r(a)}})}write(t,e,s=!1){let i={_key:t,_value:e},a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(i);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 i=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(t);return new Promise((r,a)=>{i.onsuccess=h=>{e||this._notifySubscribers(t),r(h)},i.onerror=h=>{a(h)}})}getAll(){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,i)=>{e.onsuccess=r=>{let a=r.target.result;s(a.map(h=>h._value))},e.onerror=r=>{i(r)}})}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,g.clear(this.name)}},g=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]}};T(g,"_reg",Object.create(null));export{f as AppRouter,A as BaseComponent,n as Data,g as IDB,v as TypedCollection,C as TypedData,_ as UID,X as applyAttributes,M as applyStyles,O as create};
|
package/core/BaseComponent.js
CHANGED
|
@@ -87,10 +87,9 @@ export class BaseComponent extends HTMLElement {
|
|
|
87
87
|
super();
|
|
88
88
|
/** @type {Object<string, unknown>} */
|
|
89
89
|
this.init$ = Object.create(null);
|
|
90
|
-
|
|
91
90
|
/** @type {Set<(fr: DocumentFragment, fnCtx: unknown) => void>} */
|
|
92
91
|
this.tplProcessors = new Set();
|
|
93
|
-
/** @type {Object<string,
|
|
92
|
+
/** @type {Object<string, any>} */
|
|
94
93
|
this.ref = Object.create(null);
|
|
95
94
|
this.allSubs = new Set();
|
|
96
95
|
/** @type {Boolean} */
|
|
@@ -195,10 +194,7 @@ export class BaseComponent extends HTMLElement {
|
|
|
195
194
|
parsed.ctx.add(parsed.name, val, false);
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
/**
|
|
199
|
-
* @template T
|
|
200
|
-
* @param {Object<string, T>} obj
|
|
201
|
-
*/
|
|
197
|
+
/** @param {Object<string, any>} obj */
|
|
202
198
|
add$(obj) {
|
|
203
199
|
for (let prop in obj) {
|
|
204
200
|
this.add(prop, obj[prop]);
|
|
@@ -273,6 +269,7 @@ export class BaseComponent extends HTMLElement {
|
|
|
273
269
|
this.style.setProperty(DICT.CSS_CTX_PROP, `'${ctxNameAttrVal}'`);
|
|
274
270
|
}
|
|
275
271
|
this.__initDataCtx();
|
|
272
|
+
this.initChildren = [...this.childNodes];
|
|
276
273
|
for (let proc of PROCESSORS) {
|
|
277
274
|
this.addTemplateProcessor(proc);
|
|
278
275
|
}
|
package/core/TypedCollection.js
CHANGED
|
@@ -5,7 +5,7 @@ import { TypedData } from './TypedData.js';
|
|
|
5
5
|
export class TypedCollection {
|
|
6
6
|
/**
|
|
7
7
|
* @param {Object} options
|
|
8
|
-
* @param {Object<string, { type: any; value:
|
|
8
|
+
* @param {Object<string, { type: any; value: any }>} options.typedSchema
|
|
9
9
|
* @param {String[]} [options.watchList]
|
|
10
10
|
* @param {(list: string[]) => void} [options.handler]
|
|
11
11
|
* @param {String} [options.ctxName]
|
|
@@ -13,7 +13,7 @@ export class TypedCollection {
|
|
|
13
13
|
constructor(options) {
|
|
14
14
|
/**
|
|
15
15
|
* @private
|
|
16
|
-
* @type {Object<string, { type: any; value:
|
|
16
|
+
* @type {Object<string, { type: any; value: any }>}
|
|
17
17
|
*/
|
|
18
18
|
this.__typedSchema = options.typedSchema;
|
|
19
19
|
/**
|
|
@@ -25,7 +25,7 @@ export class TypedCollection {
|
|
|
25
25
|
* @private
|
|
26
26
|
* @type {Data}
|
|
27
27
|
*/
|
|
28
|
-
this.
|
|
28
|
+
this.__data = Data.registerNamedCtx(this.__ctxId, {});
|
|
29
29
|
/**
|
|
30
30
|
* @private
|
|
31
31
|
* @type {string[]}
|
|
@@ -96,18 +96,18 @@ export class TypedCollection {
|
|
|
96
96
|
for (let prop in init) {
|
|
97
97
|
item.setValue(prop, init[prop]);
|
|
98
98
|
}
|
|
99
|
-
this.
|
|
99
|
+
this.__data.add(item.uid, item);
|
|
100
100
|
this.__watchList.forEach((propName) => {
|
|
101
|
-
if (!this.__subsMap[item.
|
|
102
|
-
this.__subsMap[item.
|
|
101
|
+
if (!this.__subsMap[item.uid]) {
|
|
102
|
+
this.__subsMap[item.uid] = [];
|
|
103
103
|
}
|
|
104
|
-
this.__subsMap[item.
|
|
104
|
+
this.__subsMap[item.uid].push(
|
|
105
105
|
item.subscribe(propName, () => {
|
|
106
|
-
this.__notifyObservers(propName, item.
|
|
106
|
+
this.__notifyObservers(propName, item.uid);
|
|
107
107
|
})
|
|
108
108
|
);
|
|
109
109
|
});
|
|
110
|
-
this.__items.add(item.
|
|
110
|
+
this.__items.add(item.uid);
|
|
111
111
|
this.notify();
|
|
112
112
|
return item;
|
|
113
113
|
}
|
|
@@ -117,7 +117,7 @@ export class TypedCollection {
|
|
|
117
117
|
* @returns {TypedData}
|
|
118
118
|
*/
|
|
119
119
|
read(id) {
|
|
120
|
-
return this.
|
|
120
|
+
return this.__data.read(id);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
@@ -145,7 +145,7 @@ export class TypedCollection {
|
|
|
145
145
|
remove(id) {
|
|
146
146
|
this.__items.delete(id);
|
|
147
147
|
this.notify();
|
|
148
|
-
this.
|
|
148
|
+
this.__data.pub(id, null);
|
|
149
149
|
delete this.__subsMap[id];
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -185,7 +185,7 @@ export class TypedCollection {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
destroy() {
|
|
188
|
-
this.
|
|
188
|
+
this.__data.remove();
|
|
189
189
|
this.__observers = null;
|
|
190
190
|
for (let id in this.__subsMap) {
|
|
191
191
|
this.__subsMap[id].forEach((sub) => {
|
package/core/TypedData.js
CHANGED
|
@@ -6,17 +6,29 @@ const MSG_TYPE = '[Typed State] Wrong property type: ';
|
|
|
6
6
|
|
|
7
7
|
export class TypedData {
|
|
8
8
|
/**
|
|
9
|
-
* @param {Object<string, { type: any; value:
|
|
9
|
+
* @param {Object<string, { type: any; value: any }>} typedSchema
|
|
10
10
|
* @param {String} [ctxName]
|
|
11
11
|
*/
|
|
12
12
|
constructor(typedSchema, ctxName) {
|
|
13
|
+
/** @private */
|
|
13
14
|
this.__typedSchema = typedSchema;
|
|
15
|
+
/** @private */
|
|
14
16
|
this.__ctxId = ctxName || UID.generate();
|
|
17
|
+
/** @private */
|
|
15
18
|
this.__schema = Object.keys(typedSchema).reduce((acc, key) => {
|
|
16
19
|
acc[key] = typedSchema[key].value;
|
|
17
20
|
return acc;
|
|
18
21
|
}, {});
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @private
|
|
24
|
+
* @type {Data}
|
|
25
|
+
*/
|
|
26
|
+
this.__data = Data.registerNamedCtx(this.__ctxId, this.__schema);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @returns {String} */
|
|
30
|
+
get uid() {
|
|
31
|
+
return this.__ctxId;
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
/**
|
|
@@ -32,7 +44,7 @@ export class TypedData {
|
|
|
32
44
|
console.warn(MSG_TYPE + prop);
|
|
33
45
|
return;
|
|
34
46
|
}
|
|
35
|
-
this.
|
|
47
|
+
this.__data.pub(prop, value);
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
/** @param {Object<string, any>} updObj */
|
|
@@ -48,7 +60,7 @@ export class TypedData {
|
|
|
48
60
|
console.warn(MSG_NAME + prop);
|
|
49
61
|
return undefined;
|
|
50
62
|
}
|
|
51
|
-
return this.
|
|
63
|
+
return this.__data.read(prop);
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
/**
|
|
@@ -56,10 +68,10 @@ export class TypedData {
|
|
|
56
68
|
* @param {(newVal: any) => void} handler
|
|
57
69
|
*/
|
|
58
70
|
subscribe(prop, handler) {
|
|
59
|
-
return this.
|
|
71
|
+
return this.__data.sub(prop, handler);
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
remove() {
|
|
63
|
-
this.
|
|
75
|
+
this.__data.remove();
|
|
64
76
|
}
|
|
65
77
|
}
|
package/core/tpl-processors.js
CHANGED
|
@@ -10,9 +10,8 @@ function slotProcessor(fr, fnCtx) {
|
|
|
10
10
|
if (fnCtx.renderShadow) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
let initChildren = [...fnCtx.childNodes];
|
|
14
13
|
let slots = [...fr.querySelectorAll('slot')];
|
|
15
|
-
if (initChildren.length && slots.length) {
|
|
14
|
+
if (fnCtx.initChildren.length && slots.length) {
|
|
16
15
|
let slotMap = {};
|
|
17
16
|
slots.forEach((slot) => {
|
|
18
17
|
let slotName = slot.getAttribute('name');
|
|
@@ -28,7 +27,7 @@ function slotProcessor(fr, fnCtx) {
|
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
|
-
initChildren.forEach((/** @type {Element} */ child) => {
|
|
30
|
+
fnCtx.initChildren.forEach((/** @type {Element} */ child) => {
|
|
32
31
|
let slotName = child.getAttribute?.('slot');
|
|
33
32
|
if (slotName) {
|
|
34
33
|
child.removeAttribute('slot');
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"lint": "npm run lint:types && npm run lint:eslint && npm run lint:prettier",
|
|
11
11
|
"format": "npm run format:eslint && npm run format:prettier",
|
|
12
12
|
"types": "dts-bundle-generator --config ./dts.config.json",
|
|
13
|
+
"dts_native": "tsc -p dts-native.cfg.json",
|
|
13
14
|
"build": "node esbuild.js && npm run types"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "public"
|
|
26
27
|
},
|
|
27
|
-
"version": "1.4.
|
|
28
|
+
"version": "1.4.7",
|
|
28
29
|
"description": "Symbiote.js",
|
|
29
30
|
"author": "hello@symbiotejs.org",
|
|
30
31
|
"license": "MIT",
|
package/utils/IDB.js
CHANGED
|
@@ -190,6 +190,7 @@ class DbInstance {
|
|
|
190
190
|
*/
|
|
191
191
|
subscribe(key, callback) {
|
|
192
192
|
if (!this._subscribtionsMap[key]) {
|
|
193
|
+
/** @private */
|
|
193
194
|
this._subscribtionsMap[key] = new Set();
|
|
194
195
|
}
|
|
195
196
|
/** @type {Set} */
|
|
@@ -207,7 +208,7 @@ class DbInstance {
|
|
|
207
208
|
|
|
208
209
|
stop() {
|
|
209
210
|
window.removeEventListener('storage', this._updateHandler);
|
|
210
|
-
this.
|
|
211
|
+
this._subscribtionsMap = null;
|
|
211
212
|
IDB.clear(this.name);
|
|
212
213
|
}
|
|
213
214
|
}
|
|
@@ -231,6 +232,9 @@ export class IDB {
|
|
|
231
232
|
return this._reg[key];
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
/** @private */
|
|
236
|
+
static _reg = Object.create(null);
|
|
237
|
+
|
|
234
238
|
/** @param {String} dbName */
|
|
235
239
|
static clear(dbName) {
|
|
236
240
|
window.indexedDB.deleteDatabase(dbName);
|
|
@@ -241,5 +245,3 @@ export class IDB {
|
|
|
241
245
|
}
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
|
-
|
|
245
|
-
IDB._reg = Object.create(null);
|
package/utils/dom-helpers.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {any} StyleMap
|
|
3
|
-
* @type {Object<string, string | number>}
|
|
4
|
-
*/
|
|
1
|
+
/** @typedef {Object<string, string | number | boolean>} StyleMap */
|
|
5
2
|
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {any} AttrMap
|
|
8
|
-
* @type {Object<string, string | number | boolean>}
|
|
9
|
-
*/
|
|
3
|
+
/** @typedef {Object<string, string | number | boolean>} AttrMap */
|
|
10
4
|
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {any} PropMap
|
|
13
|
-
* @type {Object<string, any>}
|
|
14
|
-
*/
|
|
5
|
+
/** @typedef {Object<string, any>} PropMap */
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* @template {HTMLElement} T
|
|
@@ -50,15 +41,14 @@ export function applyAttributes(el, attrMap) {
|
|
|
50
41
|
}
|
|
51
42
|
|
|
52
43
|
/**
|
|
53
|
-
* @typedef {
|
|
54
|
-
* @type {{
|
|
44
|
+
* @typedef {{
|
|
55
45
|
* tag?: String;
|
|
56
46
|
* attributes?: AttrMap;
|
|
57
47
|
* styles?: StyleMap;
|
|
58
48
|
* properties?: PropMap;
|
|
59
49
|
* processors?: Function[];
|
|
60
50
|
* children?: ElementDescriptor[];
|
|
61
|
-
* }}
|
|
51
|
+
* }} ElementDescriptor
|
|
62
52
|
*/
|
|
63
53
|
|
|
64
54
|
/**
|