@@ -28,22 +28,20 @@ import Message from './Message';
2828import {
2929 BellEvent ,
3030 BellState ,
31- type BellStateType ,
31+ type BellStateValue ,
3232 MESSAGE_TIMEOUT ,
33- MesageType ,
33+ MessageType ,
3434} from './constants' ;
3535
3636const logoSvg = `<svg class="onesignal-bell-svg" xmlns="http://www.w3.org/2000/svg" width="99.7" height="99.7" viewBox="0 0 99.7 99.7"><circle class="background" cx="49.9" cy="49.9" r="49.9"/><path class="foreground" d="M50.1 66.2H27.7s-2-.2-2-2.1c0-1.9 1.7-2 1.7-2s6.7-3.2 6.7-5.5S33 52.7 33 43.3s6-16.6 13.2-16.6c0 0 1-2.4 3.9-2.4 2.8 0 3.8 2.4 3.8 2.4 7.2 0 13.2 7.2 13.2 16.6s-1 11-1 13.3c0 2.3 6.7 5.5 6.7 5.5s1.7.1 1.7 2c0 1.8-2.1 2.1-2.1 2.1H50.1zm-7.2 2.3h14.5s-1 6.3-7.2 6.3-7.3-6.3-7.3-6.3z"/><ellipse class="stroke" cx="49.9" cy="49.9" rx="37.4" ry="36.9"/></svg>` ;
3737
38- type BellState = 'uninitialized' | 'subscribed' | 'unsubscribed' | 'blocked' ;
39-
4038const DEFAULT_SIZE : BellSize = 'medium' ;
4139const DEFAULT_POSITION : BellPosition = 'bottom-right' ;
4240const DEFAULT_THEME = 'default' ;
4341
4442export default class Bell {
4543 public options : AppUserConfigNotifyButton ;
46- public state : BellStateType = BellState . _Uninitialized ;
44+ public state : BellStateValue = BellState . _Uninitialized ;
4745 public _ignoreSubscriptionState = false ;
4846 public hovering = false ;
4947 public initialized = false ;
@@ -190,7 +188,7 @@ export default class Bell {
190188 } )
191189 . then ( ( ) => {
192190 return this . message . display (
193- MesageType . _Message ,
191+ MessageType . _Message ,
194192 this . options . text [ 'message.action.resubscribed' ] ,
195193 MESSAGE_TIMEOUT ,
196194 ) ;
@@ -226,7 +224,7 @@ export default class Bell {
226224 } )
227225 . then ( ( ) => {
228226 return this . message . display (
229- MesageType . _Message ,
227+ MessageType . _Message ,
230228 this . options . text [ 'message.action.unsubscribed' ] ,
231229 MESSAGE_TIMEOUT ,
232230 ) ;
@@ -248,7 +246,7 @@ export default class Bell {
248246
249247 // If the message is a message and not a tip, don't show it (only show tips)
250248 // Messages will go away on their own
251- if ( this . message . contentType === MesageType . _Message ) {
249+ if ( this . message . contentType === MessageType . _Message ) {
252250 this . hovering = false ;
253251 return ;
254252 }
@@ -258,14 +256,14 @@ export default class Bell {
258256 if ( this . message . queued . length > 0 ) {
259257 return this . message . dequeue ( ) . then ( ( msg : any ) => {
260258 this . message . content = msg ;
261- this . message . contentType = MesageType . _Queued ;
259+ this . message . contentType = MessageType . _Queued ;
262260 resolve ( ) ;
263261 } ) ;
264262 } else {
265263 this . message . content = decodeHtmlEntities (
266264 this . message . getTipForState ( ) ,
267265 ) ;
268- this . message . contentType = MesageType . _Tip ;
266+ this . message . contentType = MessageType . _Tip ;
269267 resolve ( ) ;
270268 }
271269 } )
@@ -282,7 +280,7 @@ export default class Bell {
282280
283281 OneSignal . _emitter . on ( BellEvent . _Hovered , ( ) => {
284282 // If a message is displayed (and not a tip), don't control it. Visitors have no control over messages
285- if ( this . message . contentType === MesageType . _Message ) {
283+ if ( this . message . contentType === MessageType . _Message ) {
286284 return ;
287285 }
288286
@@ -334,7 +332,7 @@ export default class Bell {
334332
335333 const permission =
336334 await OneSignal . _context . _permissionManager . getPermissionStatus ( ) ;
337- let bellState : BellStateType ;
335+ let bellState : BellStateValue ;
338336 if ( isSubscribed . current . optedIn ) {
339337 bellState = BellState . _Subscribed ;
340338 } else if ( permission === 'denied' ) {
@@ -353,7 +351,10 @@ export default class Bell {
353351 }
354352 if ( state . to === BellState . _Subscribed ) {
355353 this . launcher . inactivate ( ) ;
356- } else if ( state . to === BellState . _Unsubscribed || BellState . _Blocked ) {
354+ } else if (
355+ state . to === BellState . _Unsubscribed ||
356+ state . to === BellState . _Blocked
357+ ) {
357358 this . launcher . activate ( ) ;
358359 }
359360 } ) ;
@@ -579,27 +580,24 @@ export default class Bell {
579580 dialogElement ?. querySelector < HTMLButtonElement > ( 'button.action' ) ;
580581 const buttonElement = this . button . element ;
581582 const pulseRing = buttonElement ?. querySelector < HTMLElement > ( '.pulse-ring' ) ;
582- const graphic = this . graphic ;
583583
584584 // Reset added styles first
585- if ( graphic ) {
586- const background = graphic . querySelector < HTMLElement > ( '.background' ) ;
587- if ( background ) {
588- background . style . cssText = '' ;
589- }
590- const foregroundElements =
591- graphic . querySelectorAll < HTMLElement > ( '.foreground' ) ;
592- for ( let i = 0 ; i < foregroundElements . length ; i ++ ) {
593- const element = foregroundElements [ i ] ;
594- if ( element ) {
595- element . style . cssText = '' ;
596- }
597- }
598- const stroke = graphic . querySelector < HTMLElement > ( '.stroke' ) ;
599- if ( stroke ) {
600- stroke . style . cssText = '' ;
585+ const background = this . graphic ?. querySelector < HTMLElement > ( '.background' ) ;
586+ if ( background ) {
587+ background . style . cssText = '' ;
588+ }
589+ const foregroundElements =
590+ this . graphic ?. querySelectorAll < HTMLElement > ( '.foreground' ) ?? [ ] ;
591+ for ( let i = 0 ; i < foregroundElements . length ; i ++ ) {
592+ const element = foregroundElements [ i ] ;
593+ if ( element ) {
594+ element . style . cssText = '' ;
601595 }
602596 }
597+ const stroke = this . graphic ?. querySelector < HTMLElement > ( '.stroke' ) ;
598+ if ( stroke ) {
599+ stroke . style . cssText = '' ;
600+ }
603601
604602 const badgeElement = this . badge . element ;
605603 if ( badgeElement ) {
@@ -617,21 +615,22 @@ export default class Bell {
617615 if ( this . options . colors ) {
618616 const colors = this . options . colors ;
619617 if ( colors [ 'circle.background' ] ) {
620- const background = graphic ?. querySelector < HTMLElement > ( '.background' ) ;
618+ const background =
619+ this . graphic ?. querySelector < HTMLElement > ( '.background' ) ;
621620 if ( background ) {
622621 background . style . cssText += `fill: ${ colors [ 'circle.background' ] } ` ;
623622 }
624623 }
625624 if ( colors [ 'circle.foreground' ] ) {
626625 const foregroundElements =
627- graphic ?. querySelectorAll < HTMLElement > ( '.foreground' ) ?? [ ] ;
626+ this . graphic ?. querySelectorAll < HTMLElement > ( '.foreground' ) ?? [ ] ;
628627 for ( let i = 0 ; i < foregroundElements . length ; i ++ ) {
629628 const element = foregroundElements [ i ] ;
630629 if ( element ) {
631630 element . style . cssText += `fill: ${ colors [ 'circle.foreground' ] } ` ;
632631 }
633632 }
634- const stroke = graphic ?. querySelector < HTMLElement > ( '.stroke' ) ;
633+ const stroke = this . graphic ?. querySelector < HTMLElement > ( '.stroke' ) ;
635634 if ( stroke ) {
636635 stroke . style . cssText += `stroke: ${ colors [ 'circle.foreground' ] } ` ;
637636 }
@@ -718,7 +717,7 @@ export default class Bell {
718717 * Updates the current state to the specified new state.
719718 * @param newState One of ['subscribed', 'unsubscribed'].
720719 */
721- setState ( newState : BellStateType , silent = false ) {
720+ setState ( newState : BellStateValue , silent = false ) {
722721 const lastState = this . state ;
723722 this . state = newState ;
724723 if ( lastState !== newState && ! silent ) {
0 commit comments