@salla.sa/twilight 2.0.289 → 2.0.291
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).salla={})}(this,(function(exports){"use strict";let notifier=function(e,t,i){return alert(e)},setNotifier=function(e){notifier=e},fire=function(e,t,i){return notifier(e,t,i)},error=function(e,t){return notifier(e,types.error,t)},info=function(e,t){return notifier(e,types.info,t)},success=function(e,t){return notifier(e,types.success,t)},sallaInitiated=function(){let e=window.location.href.match(/([\?\&]danger=)[^&]+/g);e&&e.forEach((e=>{error(decodeURI(e.replace("?danger=","").replace("&danger=","")))}))},types={error:"error",success:"success",info:"info"};var Notify={fire:fire,setNotifier:setNotifier,error:error,success:success,info:info,sallaInitiated:sallaInitiated,types:types},Logger=function(e){let t={log:function(t,i){if(!e)return;"trace"===salla.config.get("debug")&&(i="trace");let n=e.log,r=void 0===i?n:this.__dict__[i]||n,s=["%cTwilight","color: #5cd5c4;font-weight:bold; border:1px solid #5cd5c4; padding: 2px 6px; border-radius: 5px;"],a={event:"#CFF680",backend:"#7b68ee"}[i];a&&(s[0]+="%c"+i.
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).salla={})}(this,(function(exports){"use strict";let notifier=function(e,t,i){return alert(e)},setNotifier=function(e){notifier=e},fire=function(e,t,i){return notifier(e,t,i)},error=function(e,t){return notifier(e,types.error,t)},info=function(e,t){return notifier(e,types.info,t)},success=function(e,t){return notifier(e,types.success,t)},sallaInitiated=function(){let e=window.location.href.match(/([\?\&]danger=)[^&]+/g);e&&e.forEach((e=>{error(decodeURI(e.replace("?danger=","").replace("&danger=","")))}))},types={error:"error",success:"success",info:"info"};var Notify={fire:fire,setNotifier:setNotifier,error:error,success:success,info:info,sallaInitiated:sallaInitiated,types:types},Logger=function(e){let t={log:function(t,i){if(!e)return;"trace"===salla.config.get("debug")&&(i="trace");let n=e.log,r=void 0===i?n:this.__dict__[i]||n,s=["%cTwilight","color: #5cd5c4;font-weight:bold; border:1px solid #5cd5c4; padding: 2px 6px; border-radius: 5px;"],a={event:"#CFF680",backend:"#7b68ee"}[i];a&&(s[0]+="%c"+i[0].toUpperCase()+i.substring(1),s.push(`margin-left: 5px;color: ${a};font-weight:bold; border:1px solid ${a}; padding: 2px 6px; border-radius: 5px;`)),r.call(e,...s.concat(...t))},__dict__:{trace:e.trace,debug:e.debug,info:e.info,warn:e.warn,error:e.error}};return{event:function(){t.log(arguments,"event")},trace:function(){t.log(arguments,"trace")},debug:function(){t.log(arguments,"debug")},info:function(){t.log(arguments,"info")},warn:function(){t.log(arguments,"warn")},error:function(){t.log(arguments,"error")},log:function(){t.log(arguments,void 0)},backend:function(){t.log(arguments,"backend")},logs:function(e){[e].flat().forEach((e=>e&&t.log([e].flat(),"backend")))}}}(window.console);class BaseEvent{constructor(e){this.parent=e,this.events={},this.namespace="";let t=/function (.{1,})\(/.exec(this.constructor.toString());this.className=(t&&t.length>1?t[1]:"").toLowerCase()}after_init(){this.createDynamicFunctions()}createDynamicFunctions(){Object.keys(this.events).forEach((e=>{this.createDynamicEventFuns(e),this.createDynamicListenerFuns(e)}))}createDynamicEventFuns(e){if(this[e])return;let t=this;this[e]=function(...i){return t.dispatch(e,...i)}}createDynamicListenerFuns(e){let t="on"+e.charAt(0).toUpperCase()+e.slice(1);if(this[t])return;let i=this;this[t]=function(t){return i.on(e,t)}}getEventName(e){return e=this.events[e]||e,!this.namespace||e.includes("::")?e:this.namespace+this.parent.delimiter+e}dispatch(e,...t){return this.parent.dispatch(this.getEventName(e),...t)}on(e,t){this.parent.addListener(this.getEventName(e),t)}once(e,t){this.parent.once(this.getEventName(e),t)}register(e,t){this.on(e,t)}registerEventTemporary(e,t,i){i||(i=1),emitter.many(e,i,t)}}class AuthEvents extends BaseEvent{constructor(e){super(e),this.namespace="auth",this.events={login:"login",logout:"logout",codeSent:"code.sent",codeNotSent:"code.not-sent",verified:"verified",verificationFailed:"verification.failed",loggedIn:"logged.in",registered:"registered",registrationFailed:"registration.failed",loggedOut:"logged.out",failedLogout:"failed.logout",tokenFetched:"token.fetched",refreshFailed:"refresh.failed"},this.after_init()}login(e){return e?(e.type&&this.setTypeActionOnVerified(e.type),this.next_event=e.next_event||null,this.dispatch("login",...arguments)):(this.next_event=null,this.dispatch("login",...arguments))}loggedIn(e){salla.profile.info().then((e=>{salla.config.set("user",{id:e.data.id,type:"user",email:e.data.email,mobile:e.data.phone.code+e.data.phone.number,country_code:e.data.phone.country,language_code:e.data.language,currency_code:e.data.currency})})).finally((()=>this.dispatch("loggedIn",e)))}setTypeActionOnVerified(e){this.type_action_on_verified=e}getTypeActionOnVerified(){return this.type_action_on_verified||"redirect"}}class CartEvents extends BaseEvent{constructor(e){super(e),this.namespace="cart",this.events={latestFetched:"latest.fetched",latestFailed:"latest.failed",updated:"updated",itemUpdated:"item.updated",itemUpdatedFailed:"item.updated.failed",itemAdded:"item.added",itemAddedFailed:"item.added.failed",itemDeleted:"item.deleted",itemDeletedFailed:"item.deleted.failed",submitted:"submitted",submitFailed:"submit.failed",imageDeleted:"image.deleted",imageNotDeleted:"image.not.deleted",detailsFetched:"details.fetched",detailsNotFetched:"details.not.fetched",successReset:"success.reset",couponAdded:"coupon.added",couponDeleted:"coupon.deleted",couponAdditionFailed:"coupon.addition.failed",couponDeletionFailed:"coupon.deletion.failed"},this.after_init()}updated(e){return salla.cookie.set("fresh_summary",1),e&&"object"==typeof e?(e.offer&&salla.product.event.offerExisted(e.offer),salla.storage.set("cart.summary",{total:e.cart.total,sub_total:e.cart.sub_total,discount:e.cart.discount,real_shipping_cost:e.cart.real_shipping_cost,count:e.cart.count,shipping_cost:e.cart.free_shipping_bar?.has_free_shipping?0:e.cart.real_shipping_cost}),this.dispatch("updated",e.cart)):(salla.logger.info("Cart summary not an object!",e),this.dispatch("updated"))}latestFetched(e){return this.updated(e.data),this.dispatch("latestFetched",e)}itemAdded(e,t){return this.updated(e.data),this.dispatch("itemAdded",e,t)}itemDeleted(e,t){return this.updated(e.data),this.dispatch("itemDeleted",e,t)}itemUpdated(e,t){return this.updated(e.data),this.dispatch("itemUpdated",e,t)}couponAdded(e,t){return this.updated(e.data),this.dispatch("couponAdded",e,t)}couponDeleted(e,t){return this.updated(e.data),this.dispatch("couponDeleted",e,t)}}class GiftEvents extends BaseEvent{constructor(e){super(e),this.namespace="gift",this.events={buyingSucceeded:"buying.succeeded",buyingFailed:"buying.failed"},this.after_init()}}class OrderEvents extends BaseEvent{constructor(e){super(e),this.namespace="order",this.events={canceled:"canceled",notCanceled:"not.canceled",orderCreated:"order.created",orderCreationFailed:"order.creation.failed",invoiceSent:"invoice.sent",invoiceNotSent:"invoice.not.sent"},this.after_init()}}class ScopeEvents extends BaseEvent{constructor(e){super(e),this.namespace="scope",this.events={},this.after_init()}}class RatingEvents extends BaseEvent{constructor(e){super(e),this.namespace="rating",this.events={orderNotFetched:"order.not.fetched",orderFetched:"order.fetched",storeRated:"store.rated",storeFailed:"store.failed",productsRated:"products.rated",productsFailed:"products.failed",shippingRated:"shipping.rated",shippingFailed:"shipping.failed"},this.after_init()}}class CommentEvents extends BaseEvent{constructor(e){super(e),this.namespace="comment",this.events={added:"added",additionFailed:"addition.failed"},this.after_init()}}class LoyaltyEvents extends BaseEvent{constructor(e){super(e),this.namespace="loyalty",this.events={exchangeSucceeded:"exchange.succeeded",exchangeFailed:"exchange.failed"},this.after_init()}}class ProfileEvents extends BaseEvent{constructor(e){super(e),this.namespace="profile",this.events={updated:"updated",updateFailed:"update.failed",verificationCodeSent:"verification.code.sent",updateContactsFailed:"update.contacts.failed",verified:"verified",unverified:"unverified",infoFetched:"info.fetched",infoNotFetched:"info.not.fetched"},this.after_init()}}class ProductEvents extends BaseEvent{constructor(e){super(e),this.namespace="product",this.events={priceUpdated:"price.updated",priceUpdateFailed:"price.updated.failed",availabilitySubscribed:"availability.subscribed",availabilitySubscribeFailed:"availability.subscribe.failed",categoriesFetched:"categories.fetched",categoriesFailed:"categories.failed",searchFailed:"search.failed",searchResults:"search.results",offerExisted:"offer.existed",fetchOffersFailed:"fetch.offers.failed",offersFetched:"offers.fetched"},this.after_init()}}class DocumentEvents extends BaseEvent{constructor(e){super(e),this.namespace="document",this.events={click:"click",change:"change",submit:"submit",keyup:"keyup",leaving:"leaving",request:"request",requestFailed:"request.failed"},this.after_init()}onClick(e,t){this.fireCallableFuns("click",e,t)}onChange(e,t){this.fireCallableFuns("change",e,t)}onSubmit(e,t){this.fireCallableFuns("submit",e,t)}onKeyup(e,t){this.fireCallableFuns("keyup",e,t)}fireCallableFuns(e,t,i){this.on(e,(e=>{"function"!=typeof t?"function"==typeof i&&e.target.matches(t)&&i(e):t(e)}))}fireEvent(e,t,...i){return this.fireEventForElements(e,t,!1,...i)}fireEventForAll(e,t,...i){return this.fireEventForElements(e,t,!0,...i)}fireEventForElements(e,t,i,...n){if("string"==typeof e){if(i)return document.querySelectorAll(e).forEach((e=>this.fireEventForElements(e,t,!1,...n)));e=document.querySelector(e)}if(!e)return void salla.log("Failed To get element to fire event: "+t);const r=new CustomEvent(t,...n);return e.dispatchEvent(r)}}class WishlistEvents extends BaseEvent{constructor(e){super(e),this.namespace="wishlist",this.events={added:"added",removed:"removed",additionFailed:"addition.failed",removingFailed:"removing.failed"},this.after_init()}}class CurrencyEvents extends BaseEvent{constructor(e){super(e),this.namespace="currency",this.events={changed:"changed",failed:"failed",fetched:"fetched",failedToFetch:"failed.to.fetch"},this.after_init()}changed(...e){return salla.cart.api.latest().then((()=>this.dispatch("changed",...e)))}}class TwilightEvents extends BaseEvent{constructor(e){super(e),this.namespace="twilight",this.events={initiated:"initiated"},this.after_init()}}var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},eventemitter2$1={exports:{}};
|
|
2
2
|
/*!
|
|
3
3
|
* EventEmitter2
|
|
4
4
|
* https://github.com/hij1nx/EventEmitter2
|