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