1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
Object . defineProperty ( exports , "__esModule" , {
4
4
value : true
5
5
} ) ;
6
+ exports . default = void 0 ;
6
7
7
- var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
8
+ var _react = _interopRequireDefault ( require ( "react" ) ) ;
8
9
9
- var _react = require ( 'react' ) ;
10
-
11
- var _react2 = _interopRequireDefault ( _react ) ;
12
-
13
- var _propTypes = require ( 'prop-types' ) ;
10
+ var _propTypes = require ( "prop-types" ) ;
14
11
15
12
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
16
13
14
+ function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
15
+
17
16
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
18
17
19
- function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
18
+ function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
19
+
20
+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
21
+
22
+ function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
20
23
21
- function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . __proto__ = superClass ; }
24
+ function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
25
+
26
+ function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
27
+
28
+ function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
29
+
30
+ function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
22
31
23
32
var PERMISSION_GRANTED = 'granted' ;
24
33
var PERMISSION_DENIED = 'denied' ;
@@ -29,20 +38,26 @@ var seqGen = function seqGen() {
29
38
return i ++ ;
30
39
} ;
31
40
} ;
41
+
32
42
var seq = seqGen ( ) ;
33
43
34
- var Notification = function ( _React$Component ) {
44
+ var Notification =
45
+ /*#__PURE__*/
46
+ function ( _React$Component ) {
35
47
_inherits ( Notification , _React$Component ) ;
36
48
37
49
function Notification ( props ) {
38
- _classCallCheck ( this , Notification ) ;
50
+ var _this ;
39
51
40
- var _this = _possibleConstructorReturn ( this , ( Notification . __proto__ || Object . getPrototypeOf ( Notification ) ) . call ( this , props ) ) ;
52
+ _classCallCheck ( this , Notification ) ;
41
53
54
+ _this = _possibleConstructorReturn ( this , _getPrototypeOf ( Notification ) . call ( this , props ) ) ;
42
55
var supported = false ;
43
56
var granted = false ;
57
+
44
58
if ( 'Notification' in window && window . Notification ) {
45
59
supported = true ;
60
+
46
61
if ( window . Notification . permission === PERMISSION_GRANTED ) {
47
62
granted = true ;
48
63
}
@@ -51,32 +66,33 @@ var Notification = function (_React$Component) {
51
66
_this . state = {
52
67
supported : supported ,
53
68
granted : granted
54
- } ;
55
- // Do not save Notification instance in state
69
+ } ; // Do not save Notification instance in state
70
+
56
71
_this . notifications = { } ;
57
72
_this . windowFocus = true ;
58
- _this . onWindowFocus = _this . _onWindowFocus . bind ( _this ) ;
59
- _this . onWindowBlur = _this . _onWindowBlur . bind ( _this ) ;
73
+ _this . onWindowFocus = _this . _onWindowFocus . bind ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) ) ;
74
+ _this . onWindowBlur = _this . _onWindowBlur . bind ( _assertThisInitialized ( _assertThisInitialized ( _this ) ) ) ;
60
75
return _this ;
61
76
}
62
77
63
78
_createClass ( Notification , [ {
64
- key : ' _onWindowFocus' ,
79
+ key : " _onWindowFocus" ,
65
80
value : function _onWindowFocus ( ) {
66
81
this . windowFocus = true ;
67
82
}
68
83
} , {
69
- key : ' _onWindowBlur' ,
84
+ key : " _onWindowBlur" ,
70
85
value : function _onWindowBlur ( ) {
71
86
this . windowFocus = false ;
72
87
}
73
88
} , {
74
- key : ' _askPermission' ,
89
+ key : " _askPermission" ,
75
90
value : function _askPermission ( ) {
76
91
var _this2 = this ;
77
92
78
93
window . Notification . requestPermission ( function ( permission ) {
79
94
var result = permission === PERMISSION_GRANTED ;
95
+
80
96
_this2 . setState ( {
81
97
granted : result
82
98
} , function ( ) {
@@ -89,7 +105,7 @@ var Notification = function (_React$Component) {
89
105
} ) ;
90
106
}
91
107
} , {
92
- key : ' componentDidMount' ,
108
+ key : " componentDidMount" ,
93
109
value : function componentDidMount ( ) {
94
110
if ( this . props . disableActiveWindow ) {
95
111
window . addEventListener ( 'focus' , this . onWindowFocus ) ;
@@ -113,22 +129,23 @@ var Notification = function (_React$Component) {
113
129
}
114
130
}
115
131
} , {
116
- key : ' componentWillUnmount' ,
132
+ key : " componentWillUnmount" ,
117
133
value : function componentWillUnmount ( ) {
118
134
if ( this . props . disableActiveWindow ) {
119
135
window . removeEventListener ( 'focus' , this . onWindowFocus ) ;
120
136
window . removeEventListener ( 'blur' , this . onWindowBlur ) ;
121
137
}
122
138
}
123
139
} , {
124
- key : ' render' ,
140
+ key : " render" ,
125
141
value : function render ( ) {
126
142
var _this3 = this ;
127
143
128
144
var doNotShowOnActiveWindow = this . props . disableActiveWindow && this . windowFocus ;
129
- if ( ! this . props . ignore && this . props . title && this . state . supported && this . state . granted && ! doNotShowOnActiveWindow ) {
130
145
146
+ if ( ! this . props . ignore && this . props . title && this . state . supported && this . state . granted && ! doNotShowOnActiveWindow ) {
131
147
var opt = this . props . options ;
148
+
132
149
if ( typeof opt . tag !== 'string' ) {
133
150
opt . tag = 'web-notification-' + seq ( ) ;
134
151
}
@@ -139,50 +156,59 @@ var Notification = function (_React$Component) {
139
156
this . notifications [ opt . tag ] = { } ;
140
157
} else {
141
158
var n = new window . Notification ( this . props . title , opt ) ;
159
+
142
160
n . onshow = function ( e ) {
143
161
_this3 . props . onShow ( e , opt . tag ) ;
162
+
144
163
setTimeout ( function ( ) {
145
164
_this3 . close ( n ) ;
146
165
} , _this3 . props . timeout ) ;
147
166
} ;
167
+
148
168
n . onclick = function ( e ) {
149
169
_this3 . props . onClick ( e , opt . tag ) ;
150
170
} ;
171
+
151
172
n . onclose = function ( e ) {
152
173
_this3 . props . onClose ( e , opt . tag ) ;
153
174
} ;
175
+
154
176
n . onerror = function ( e ) {
155
177
_this3 . props . onError ( e , opt . tag ) ;
156
178
} ;
157
179
158
180
this . notifications [ opt . tag ] = n ;
159
181
}
160
182
}
161
- }
162
-
163
- // return null cause
183
+ } // return null cause
164
184
// Error: Invariant Violation: Notification.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object.
165
- return _react2 . default . createElement ( 'input' , { type : 'hidden' , name : 'dummy-for-react-web-notification' , style : { display : 'none' } } ) ;
185
+
186
+
187
+ return _react . default . createElement ( "input" , {
188
+ type : "hidden" ,
189
+ name : "dummy-for-react-web-notification" ,
190
+ style : {
191
+ display : 'none'
192
+ }
193
+ } ) ;
166
194
}
167
195
} , {
168
- key : ' close' ,
196
+ key : " close" ,
169
197
value : function close ( n ) {
170
198
if ( n && typeof n . close === 'function' ) {
171
199
n . close ( ) ;
172
200
}
173
- }
174
-
175
- // for debug
201
+ } // for debug
176
202
177
203
} , {
178
- key : ' _getNotificationInstance' ,
204
+ key : " _getNotificationInstance" ,
179
205
value : function _getNotificationInstance ( tag ) {
180
206
return this . notifications [ tag ] ;
181
207
}
182
208
} ] ) ;
183
209
184
210
return Notification ;
185
- } ( _react2 . default . Component ) ;
211
+ } ( _react . default . Component ) ;
186
212
187
213
Notification . propTypes = {
188
214
ignore : _propTypes . bool ,
@@ -200,7 +226,6 @@ Notification.propTypes = {
200
226
options : _propTypes . object ,
201
227
swRegistration : _propTypes . object
202
228
} ;
203
-
204
229
Notification . defaultProps = {
205
230
ignore : false ,
206
231
disableActiveWindow : false ,
@@ -216,5 +241,5 @@ Notification.defaultProps = {
216
241
options : { } ,
217
242
swRegistration : null
218
243
} ;
219
-
220
- exports . default = Notification ;
244
+ var _default = Notification ;
245
+ exports . default = _default ;
0 commit comments