@aegenet/au2-base-component
Version:
Aurelia 2 - Base Component
3 lines (2 loc) • 12.4 kB
JavaScript
(function(_,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("aurelia"),require("@aurelia/i18n"),require("@aegenet/belt-anti-bounce"),require("@aurelia/router")):typeof define=="function"&&define.amd?define(["exports","aurelia","@aurelia/i18n","@aegenet/belt-anti-bounce","@aurelia/router"],o):(_=typeof globalThis<"u"?globalThis:_||self,o(_["@aegenet/au2-base-component"]={},_.aurelia,_.i18n,_.beltAntiBounce,_.router))})(this,function(_,o,$,W,X){"use strict";var ht=Object.defineProperty;var lt=(_,o,$)=>o in _?ht(_,o,{enumerable:!0,configurable:!0,writable:!0,value:$}):_[o]=$;var v=(_,o,$)=>lt(_,typeof o!="symbol"?o+"":o,$);var y;const T=o.DI.createInterface("au2.aware-component-service"),x=o.DI.createInterface("au2.store-service");var Ie=Object.create,ye=Object.defineProperty,Ce=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Z=t=>{throw TypeError(t)},M=(t,e,r)=>e in t?ye(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ne=t=>[,,,Ie(null)],Pe=["class","method","getter","setter","accessor","field","value","get","set"],ee=t=>t!==void 0&&typeof t!="function"?Z("Function expected"):t,Oe=(t,e,r,n,i)=>({kind:Pe[t],name:e,metadata:n,addInitializer:s=>r._?Z("Already initialized"):i.push(ee(s||null))}),Ae=(t,e)=>M(e,Ce("metadata"),t[3]),N=(t,e,r,n)=>{for(var i=0,s=t[e>>1],c=s&&s.length;i<c;i++)e&1?s[i].call(r):n=s[i].call(r,n);return n},j=(t,e,r,n,i,s)=>{var c,l,f,d,w=e&7,a=!!(e&8),I=!!(e&16),h=t.length+1,p=t[h-1]=[],B=t[h]||(t[h]=[]);i=i.prototype,w<5;for(var A=n.length-1;A>=0;A--)f=Oe(w,r,l={},t[3],B),f.static=a,f.private=I,d=f.access={has:C=>r in C},d.get=C=>C[r],d.set=(C,b)=>C[r]=b,c=(0,n[A])(void 0,f),l._=1,ee(c)&&p.unshift(c);return i},u=(t,e,r)=>M(t,typeof e!="symbol"?e+"":e,r),te,re,ie,S;ie=[o.bindable()],re=[o.bindable()],te=[o.bindable()];const P=class me{constructor(e,r){this._element=e,this._container=r,u(this,"$antiBounces"),u(this,"_auSlotInfo"),u(this,"_ea"),u(this,"_aware"),u(this,"_platform"),u(this,"_store"),u(this,"i18n"),u(this,"uid"),u(this,"eventName",N(S,8,this)),N(S,11,this),u(this,"_isInit"),u(this,"slots",{}),u(this,"auSlots",{}),u(this,"auSlotNames"),u(this,"slotNames",[]),u(this,"lastError"),u(this,"isBusy"),u(this,"embedData",N(S,12,this)),N(S,15,this),u(this,"changed",N(S,16,this)),N(S,19,this),this.uid=`au2-comp-${me._COUNTER++}`,this._auSlotInfo=this._container.get(o.IAuSlotsInfo),this._ea=this._container.get(o.IEventAggregator),this._aware=this._container.get(T),this._platform=this._container.get(o.IPlatform),this._store=this._container.get(x),this._container.has($.I18N,!0)?this.i18n=this._container.get($.I18N):console.debug("I18N cannot be used without right configuration.")}async attached(){try{this._refreshSlots(),this.isBusy=!0,this._aware.subscribe(this),await Promise.resolve(this._init()),this._isInit=!0}finally{this.isBusy=!1}}detaching(e,r){this._aware.unsubscribe(this)}_init(){}_deinit(){}_refreshSlots(){if(this.auSlotNames=this._auSlotInfo.projectedSlots,this.auSlots={},this.slots={},this.auSlotNames.length&&this.auSlotNames.forEach(e=>{this.auSlots[e]=!0}),this._element){const e=this._element.children?Array.from(this._element.children):[],r=[];let n;for(let i=0;i<e.length;i++)(n=e[i])&&n.slot&&(this.slots[n.slot]=n,r.push(n.slot));this.slotNames=r}}async unbinding(){this.slots={},this.slotNames=[],this.auSlots={},this.auSlotNames=[],W.disposeAntiBounces(this),this._isInit=!1,await Promise.resolve(this._deinit())}get taskQueue(){return this._platform.taskQueue}get ea(){return this._ea}};S=Ne(),j(S,5,"eventName",ie,P),j(S,5,"embedData",re,P),j(S,5,"changed",te,P),Ae(S,P),u(P,"_COUNTER",1);let ne=P;class ze{constructor(e){v(this,"$antiBounces");v(this,"_ea");v(this,"eventName");v(this,"_aware");v(this,"_store");v(this,"i18n");v(this,"_router");v(this,"_platform");v(this,"_isInit");v(this,"lastError");this._container=e,this._ea=this._container.get(o.IEventAggregator),this._platform=this._container.get(o.IPlatform),this._aware=this._container.get(T),this._store=this._container.get(x),this._container.has($.I18N,!0)?this.i18n=this._container.get($.I18N):console.debug("I18N cannot be used without the right configuration."),this._container.has(X.IRouter,!0)?this._router=this._container.get(X.IRouter):console.debug("Router cannot be used without the right configuration.")}async loading(e,r,n){this._aware.subscribe(this),await Promise.resolve(this._init(e,r,n)),this._isInit=!0}_init(e,r,n){}_deinit(e,r){}async unloading(e,r){W.disposeAntiBounces(this),this._aware.unsubscribe(this),this._isInit=!1,await Promise.resolve(this._deinit(e,r))}get taskQueue(){return this._platform.taskQueue}get ea(){return this._ea}get router(){return this._router}}var ke=Object.create,q=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ee=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),se=t=>{throw TypeError(t)},Te=(t,e,r)=>e in t?q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xe=(t,e)=>q(t,"name",{value:e,configurable:!0}),Fe=t=>[,,,ke(null)],Be=["class","method","getter","setter","accessor","field","value","get","set"],ae=t=>t!==void 0&&typeof t!="function"?se("Function expected"):t,je=(t,e,r,n,i)=>({kind:Be[t],name:e,metadata:n,addInitializer:s=>r._?se("Already initialized"):i.push(ae(s||null))}),qe=(t,e)=>Te(e,Ee("metadata"),t[3]),Qe=(t,e,r,n)=>{for(var i=0,s=t[e>>1],c=s&&s.length;i<c;i++)s[i].call(r);return n},Ue=(t,e,r,n,i,s)=>{var c,l,f,d=e&7,w=!!(e&16),a=0,I=t[a]||(t[a]=[]),h=d&&(i=i.prototype,d<5&&(d>3||!w)&&De(i,r));xe(i,r);for(var p=n.length-1;p>=0;p--)f=je(d,r,l={},t[3],I),c=(0,n[p])(i,f),l._=1,ae(c)&&(i=c);return qe(t,i),h&&q(i,r,h),w?d^4?s:h:i},oe,Q;oe=[o.inject(o.IEventAggregator)];let F=(y=class{constructor(e){this._ev=e}subscribe(e){var r;if(e.eventName&&((r=e.$controller)!=null&&r.definition)){const n=e.$controller.definition;if(n.name){const i=e.eventName.indexOf(":")!==-1?e.eventName:`${n.name}:${e.eventName}`;e.$awareToken=this._ev.subscribe(i,s=>{this.publish(e,s)})}}}publish(e,r){if(r!=null&&r.property&&y._RE_PROPERTY_CHECK.test(r.property)&&r.property in e){const n=Object.getOwnPropertyDescriptor(e,r.property);n?n.set||n.get?n.set&&(e[r.property]=r.value):n.value instanceof Function?n.value.apply(e,r.value):e[r.property]=r.value:e[r.property]instanceof Function&&e[r.property].apply(e,r.value)}}unsubscribe(e){e.$awareToken&&(e.$awareToken.dispose(),e.$awareToken=void 0)}},v(y,"_RE_PROPERTY_CHECK",/^[a-z]/i),y);Q=Fe(),F=Ue(Q,0,"AwareComponentService",oe,F),Qe(Q,1,F);let ce=F;var Ke=Object.create,U=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,He=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),_e=t=>{throw TypeError(t)},Ye=(t,e,r)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ge=(t,e)=>U(t,"name",{value:e,configurable:!0}),Je=t=>[,,,Ke(null)],Le=["class","method","getter","setter","accessor","field","value","get","set"],he=t=>t!==void 0&&typeof t!="function"?_e("Function expected"):t,Ve=(t,e,r,n,i)=>({kind:Le[t],name:e,metadata:n,addInitializer:s=>r._?_e("Already initialized"):i.push(he(s||null))}),We=(t,e)=>Ye(e,He("metadata"),t[3]),Xe=(t,e,r,n)=>{for(var i=0,s=t[e>>1],c=s&&s.length;i<c;i++)s[i].call(r);return n},Ze=(t,e,r,n,i,s)=>{var c,l,f,d=e&7,w=!!(e&16),a=0,I=t[a]||(t[a]=[]),h=d&&(i=i.prototype,d<5&&(d>3||!w)&&Re(i,r));Ge(i,r);for(var p=n.length-1;p>=0;p--)f=Ve(d,r,l={},t[3],I),c=(0,n[p])(i,f),l._=1,he(c)&&(i=c);return We(t,i),h&&U(i,r,h),w?d^4?s:h:i},le,K;le=[o.inject(o.IContainer)];class z{constructor(e){v(this,"_isInit",!1);v(this,"_store",new Map);v(this,"_tokens",[]);v(this,"_channel","au2.store-service");v(this,"_ev");this._container=e}initialize(e={}){this._isInit||(e.channel&&(this._channel=e.channel),e.eventAggregator&&(this._ev=e.eventAggregator),this._ev&&this._tokens.push(this._ev.subscribe(`${this._channel}:set`,async r=>{await this.setStore(r)}),this._ev.subscribe(`${this._channel}:get`,async r=>this.getStore(r.key)),this._ev.subscribe(`${this._channel}:del`,async r=>{await this.delStore(r.key)}),this._ev.subscribe(`${this._channel}:refresh`,async r=>{await this.refreshStore(r.key)})),this._isInit=!0)}dispose(){var e;(e=this._tokens)==null||e.forEach(r=>r.dispose()),this._tokens=[],this._isInit=!1,this._store.clear()}setStore(...e){e==null||e.forEach(r=>{this._store.set(r.key,r)})}delStore(e){this._store.delete(e)}async getStore(e){var n;const r=this._store.get(e);if(!r)throw new Error(`Unknown store was provided: ${String(e)}`);return!r.data&&r.load&&(r.data=await r.load(this._container),(n=this._ev)==null||n.publish(`${this._channel}:loaded`,{key:e,data:r.data})),r.data}async refreshStore(e){var n;const r=this._store.get(e);if(!r)throw new Error(`Unknown store was provided: ${String(e)}`);r.load&&(r.data=await r.load(this._container),(n=this._ev)==null||n.publish(`${this._channel}:loaded`,{key:e,data:r.data}))}}K=Je(),z=Ze(K,0,"StoreService",le,z),Xe(K,1,z);function Me(){return{register:t=>{t.register(o.Registration.singleton(T,ce)),t.register(o.Registration.singleton(x,z))}}}var et=Object.create,R=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,de=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),k=t=>{throw TypeError(t)},ue=(t,e,r)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ve=(t,e)=>R(t,"name",{value:e,configurable:!0}),rt=t=>[,,,et((t==null?void 0:t[de("metadata")])??null)],fe=["class","method","getter","setter","accessor","field","value","get","set"],D=t=>t!==void 0&&typeof t!="function"?k("Function expected"):t,it=(t,e,r,n,i)=>({kind:fe[t],name:e,metadata:n,addInitializer:s=>r._?k("Already initialized"):i.push(D(s||null))}),nt=(t,e)=>ue(e,de("metadata"),t[3]),E=(t,e,r,n)=>{for(var i=0,s=t[e>>1],c=s&&s.length;i<c;i++)e&1?s[i].call(r):n=s[i].call(r,n);return n},H=(t,e,r,n,i,s)=>{var c,l,f,d,w,a=e&7,I=!!(e&8),h=!!(e&16),p=a>3?t.length+1:a?I?1:2:0,B=fe[a+5],A=a>3&&(t[p-1]=[]),C=t[p]||(t[p]=[]),b=a&&(!h&&!I&&(i=i.prototype),a<5&&(a>3||!h)&&tt(a<4?i:{get[r](){return be(this,s)},set[r](g){return ge(this,s,g)}},r));a?h&&a<4&&ve(s,(a>2?"set ":a>1?"get ":"")+r):ve(i,r);for(var L=n.length-1;L>=0;L--)d=it(a,r,f={},t[3],C),a&&(d.static=I,d.private=h,w=d.access={has:h?g=>st(i,g):g=>r in g},a^3&&(w.get=h?g=>(a^1?be:at)(g,i,a^4?s:b.get):g=>g[r]),a>2&&(w.set=h?(g,V)=>ge(g,i,V,a^4?s:b.set):(g,V)=>g[r]=V)),l=(0,n[L])(a?a<4?h?s:b[B]:a>4?void 0:{get:b.get,set:b.set}:i,d),f._=1,a^4||l===void 0?D(l)&&(a>4?A.unshift(l):a?h?s=l:b[B]=l:i=l):typeof l!="object"||l===null?k("Object expected"):(D(c=l.get)&&(b.get=c),D(c=l.set)&&(b.set=c),D(c=l.init)&&A.unshift(c));return a||nt(t,i),b&&R(i,r,b),h?a^4?s:b:i},pe=(t,e,r)=>ue(t,typeof e!="symbol"?e+"":e,r),Y=(t,e,r)=>e.has(t)||k("Cannot "+r),st=(t,e)=>Object(e)!==e?k('Cannot use the "in" operator on this value'):t.has(e),be=(t,e,r)=>(Y(t,e,"read from private field"),r?r.call(t):e.get(t)),ge=(t,e,r,n)=>(Y(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),at=(t,e,r)=>(Y(t,e,"access private method"),r),we,Se,G,$e,m;$e=[o.customElement({name:"aware-component"}),o.inject(Element,o.IContainer)];class O extends(G=ne,Se=[o.bindable()],we=[o.bindable()],G){constructor(e,r){super(e,r),pe(this,"events",E(m,8,this,[])),E(m,11,this),pe(this,"next",E(m,12,this)),E(m,15,this)}async publish(){if(this.events)for(let e=0;e<this.events.length;e++)this._ea.publish(this.events[e].name,this.events[e].options);this.next&&await this.next(this)}}m=rt(G),H(m,5,"events",Se,O),H(m,5,"next",we,O),O=H(m,0,"AwareComponent",$e,O),E(m,1,O);var J=(t=>(t[t.instance=0]="instance",t[t.singleton=1]="singleton",t[t.transient=2]="transient",t[t.callback=3]="callback",t[t.array=4]="array",t[t.alias=5]="alias",t))(J||{});function ot(t){var i;const e={instance:[],singleton:[],transient:[],callback:[],array:[],alias:[]};if(t==null)return e;const r="$",n="h";for(const[s,c]of((i=t[n])==null?void 0:i.entries())||[])c[r]!=null&&e[J[c[r]]].push({[ct(s)||"unknown"]:{resolving:c.resolving??!1,current:c._state}});return e}function ct(t){return typeof t=="string"?t:t.friendlyName||t.toString()}function _t(t){return t!=="view-model"&&t!=="component"&&t!=="ref"}_.AwareComponent=O,_.AwareComponentService=ce,_.BaseComponent=ne,_.BasePage=ze,_.DIAwareComponentService=T,_.DIStoreService=x,_.ResolverStrategyMap=J,_.StoreService=z,_.debugContainer=ot,_.defaultCapture=_t,_.register=Me,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=index.umd.js.map