@superrb/react-addons 4.0.0-8 → 4.0.0

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.
package/config.js CHANGED
@@ -1,14 +1,14 @@
1
- import { EVAL, INLINE, SELF, NONE } from 'csp-header';
1
+ import { EVAL, INLINE, SELF, NONE, DATA, BLOB } from 'csp-header';
2
2
  export const cspConfig = () => ({
3
3
  'default-src': [SELF],
4
4
  'connect-src': [SELF],
5
- 'script-src': [SELF, INLINE, EVAL, 'netlify-run.netlify.app'],
5
+ 'script-src': [SELF, INLINE, EVAL],
6
6
  'style-src': [SELF, INLINE],
7
- 'img-src': [SELF, 'blob:', 'data:'],
8
- 'font-src': [SELF, 'data:'],
7
+ 'img-src': [SELF, BLOB, DATA],
8
+ 'font-src': [SELF, DATA],
9
9
  'object-src': [NONE],
10
- 'media-src': [SELF, 'blob:', 'data:'],
11
- 'frame-src': [SELF, 'app.netlify.com'],
10
+ 'media-src': [SELF, BLOB, DATA],
11
+ 'frame-src': [SELF],
12
12
  'frame-ancestors': [SELF],
13
13
  'base-uri': [SELF],
14
14
  'form-action': [SELF],
@@ -21,3 +21,447 @@ export const recaptchaCspConfig = () => ({
21
21
  ],
22
22
  'frame-src': ['https://www.google.com/recaptcha/'],
23
23
  });
24
+ export const googleTagManagerCspConfig = () => ({
25
+ 'connect-src': [
26
+ 'www.googletagmanager.com',
27
+ 'www.google.com',
28
+ 'analytics.google.com',
29
+ 'https://analytics.google.com',
30
+ 'https://*.google-analytics.com',
31
+ 'https://*.analytics.google.com',
32
+ 'https://*.googletagmanager.com',
33
+ 'https://pagead2.googlesyndication.com',
34
+ 'https://www.googleadservices.com',
35
+ 'https://googleads.g.doubleclick.net',
36
+ 'https://google.com',
37
+ 'https://stats.g.doubleclick.net',
38
+ 'https://www.google.com',
39
+ 'https://www.google.ad',
40
+ 'https://www.google.ae',
41
+ 'https://www.google.com.af',
42
+ 'https://www.google.com.ag',
43
+ 'https://www.google.al',
44
+ 'https://www.google.am',
45
+ 'https://www.google.co.ao',
46
+ 'https://www.google.com.ar',
47
+ 'https://www.google.as',
48
+ 'https://www.google.at',
49
+ 'https://www.google.com.au',
50
+ 'https://www.google.az',
51
+ 'https://www.google.ba',
52
+ 'https://www.google.com.bd',
53
+ 'https://www.google.be',
54
+ 'https://www.google.bf',
55
+ 'https://www.google.bg',
56
+ 'https://www.google.com.bh',
57
+ 'https://www.google.bi',
58
+ 'https://www.google.bj',
59
+ 'https://www.google.com.bn',
60
+ 'https://www.google.com.bo',
61
+ 'https://www.google.com.br',
62
+ 'https://www.google.bs',
63
+ 'https://www.google.bt',
64
+ 'https://www.google.co.bw',
65
+ 'https://www.google.by',
66
+ 'https://www.google.com.bz',
67
+ 'https://www.google.ca',
68
+ 'https://www.google.cd',
69
+ 'https://www.google.cf',
70
+ 'https://www.google.cg',
71
+ 'https://www.google.ch',
72
+ 'https://www.google.ci',
73
+ 'https://www.google.co.ck',
74
+ 'https://www.google.cl',
75
+ 'https://www.google.cm',
76
+ 'https://www.google.cn',
77
+ 'https://www.google.com.co',
78
+ 'https://www.google.co.cr',
79
+ 'https://www.google.com.cu',
80
+ 'https://www.google.cv',
81
+ 'https://www.google.com.cy',
82
+ 'https://www.google.cz',
83
+ 'https://www.google.de',
84
+ 'https://www.google.dj',
85
+ 'https://www.google.dk',
86
+ 'https://www.google.dm',
87
+ 'https://www.google.com.do',
88
+ 'https://www.google.dz',
89
+ 'https://www.google.com.ec',
90
+ 'https://www.google.ee',
91
+ 'https://www.google.com.eg',
92
+ 'https://www.google.es',
93
+ 'https://www.google.com.et',
94
+ 'https://www.google.fi',
95
+ 'https://www.google.com.fj',
96
+ 'https://www.google.fm',
97
+ 'https://www.google.fr',
98
+ 'https://www.google.ga',
99
+ 'https://www.google.ge',
100
+ 'https://www.google.gg',
101
+ 'https://www.google.com.gh',
102
+ 'https://www.google.com.gi',
103
+ 'https://www.google.gl',
104
+ 'https://www.google.gm',
105
+ 'https://www.google.gr',
106
+ 'https://www.google.com.gt',
107
+ 'https://www.google.gy',
108
+ 'https://www.google.com.hk',
109
+ 'https://www.google.hn',
110
+ 'https://www.google.hr',
111
+ 'https://www.google.ht',
112
+ 'https://www.google.hu',
113
+ 'https://www.google.co.id',
114
+ 'https://www.google.ie',
115
+ 'https://www.google.co.il',
116
+ 'https://www.google.im',
117
+ 'https://www.google.co.in',
118
+ 'https://www.google.iq',
119
+ 'https://www.google.is',
120
+ 'https://www.google.it',
121
+ 'https://www.google.je',
122
+ 'https://www.google.com.jm',
123
+ 'https://www.google.jo',
124
+ 'https://www.google.co.jp',
125
+ 'https://www.google.co.ke',
126
+ 'https://www.google.com.kh',
127
+ 'https://www.google.ki',
128
+ 'https://www.google.kg',
129
+ 'https://www.google.co.kr',
130
+ 'https://www.google.com.kw',
131
+ 'https://www.google.kz',
132
+ 'https://www.google.la',
133
+ 'https://www.google.com.lb',
134
+ 'https://www.google.li',
135
+ 'https://www.google.lk',
136
+ 'https://www.google.co.ls',
137
+ 'https://www.google.lt',
138
+ 'https://www.google.lu',
139
+ 'https://www.google.lv',
140
+ 'https://www.google.com.ly',
141
+ 'https://www.google.co.ma',
142
+ 'https://www.google.md',
143
+ 'https://www.google.me',
144
+ 'https://www.google.mg',
145
+ 'https://www.google.mk',
146
+ 'https://www.google.ml',
147
+ 'https://www.google.com.mm',
148
+ 'https://www.google.mn',
149
+ 'https://www.google.com.mt',
150
+ 'https://www.google.mu',
151
+ 'https://www.google.mv',
152
+ 'https://www.google.mw',
153
+ 'https://www.google.com.mx',
154
+ 'https://www.google.com.my',
155
+ 'https://www.google.co.mz',
156
+ 'https://www.google.com.na',
157
+ 'https://www.google.com.ng',
158
+ 'https://www.google.com.ni',
159
+ 'https://www.google.ne',
160
+ 'https://www.google.nl',
161
+ 'https://www.google.no',
162
+ 'https://www.google.com.np',
163
+ 'https://www.google.nr',
164
+ 'https://www.google.nu',
165
+ 'https://www.google.co.nz',
166
+ 'https://www.google.com.om',
167
+ 'https://www.google.com.pa',
168
+ 'https://www.google.com.pe',
169
+ 'https://www.google.com.pg',
170
+ 'https://www.google.com.ph',
171
+ 'https://www.google.com.pk',
172
+ 'https://www.google.pl',
173
+ 'https://www.google.pn',
174
+ 'https://www.google.com.pr',
175
+ 'https://www.google.ps',
176
+ 'https://www.google.pt',
177
+ 'https://www.google.com.py',
178
+ 'https://www.google.com.qa',
179
+ 'https://www.google.ro',
180
+ 'https://www.google.ru',
181
+ 'https://www.google.rw',
182
+ 'https://www.google.com.sa',
183
+ 'https://www.google.com.sb',
184
+ 'https://www.google.sc',
185
+ 'https://www.google.se',
186
+ 'https://www.google.com.sg',
187
+ 'https://www.google.sh',
188
+ 'https://www.google.si',
189
+ 'https://www.google.sk',
190
+ 'https://www.google.com.sl',
191
+ 'https://www.google.sn',
192
+ 'https://www.google.so',
193
+ 'https://www.google.sm',
194
+ 'https://www.google.sr',
195
+ 'https://www.google.st',
196
+ 'https://www.google.com.sv',
197
+ 'https://www.google.td',
198
+ 'https://www.google.tg',
199
+ 'https://www.google.co.th',
200
+ 'https://www.google.com.tj',
201
+ 'https://www.google.tl',
202
+ 'https://www.google.tm',
203
+ 'https://www.google.tn',
204
+ 'https://www.google.to',
205
+ 'https://www.google.com.tr',
206
+ 'https://www.google.tt',
207
+ 'https://www.google.com.tw',
208
+ 'https://www.google.co.tz',
209
+ 'https://www.google.com.ua',
210
+ 'https://www.google.co.ug',
211
+ 'https://www.google.co.uk',
212
+ 'https://www.google.com.uy',
213
+ 'https://www.google.co.uz',
214
+ 'https://www.google.com.vc',
215
+ 'https://www.google.co.ve',
216
+ 'https://www.google.co.vi',
217
+ 'https://www.google.com.vn',
218
+ 'https://www.google.vu',
219
+ 'https://www.google.ws',
220
+ 'https://www.google.rs',
221
+ 'https://www.google.co.za',
222
+ 'https://www.google.co.zm',
223
+ 'https://www.google.co.zw',
224
+ 'https://www.google.cat',
225
+ ],
226
+ 'script-src': [
227
+ 'https://www.googletagmanager.com',
228
+ 'https://googletagmanager.com',
229
+ 'https://tagmanager.google.com',
230
+ 'https://*.googletagmanager.com',
231
+ 'https://www.googleadservices.com',
232
+ 'https://www.google.com',
233
+ 'https://pagead2.googlesyndication.com',
234
+ 'https://googleads.g.doubleclick.net',
235
+ ],
236
+ 'frame-src': ['https://www.googletagmanager.com'],
237
+ 'img-src': [
238
+ 'www.googletagmanager.com',
239
+ 'https://googletagmanager.com',
240
+ 'https://ssl.gstatic.com',
241
+ 'https://www.gstatic.com',
242
+ 'https://*.google-analytics.com',
243
+ 'https://*.googletagmanager.com',
244
+ 'https://www.googletagmanager.com',
245
+ 'https://googleads.g.doubleclick.net',
246
+ 'https://www.google.com',
247
+ 'https://pagead2.googlesyndication.com',
248
+ 'https://www.googleadservices.com',
249
+ 'https://google.com',
250
+ 'https://www.google.com',
251
+ 'https://www.google.ad',
252
+ 'https://www.google.ae',
253
+ 'https://www.google.com.af',
254
+ 'https://www.google.com.ag',
255
+ 'https://www.google.al',
256
+ 'https://www.google.am',
257
+ 'https://www.google.co.ao',
258
+ 'https://www.google.com.ar',
259
+ 'https://www.google.as',
260
+ 'https://www.google.at',
261
+ 'https://www.google.com.au',
262
+ 'https://www.google.az',
263
+ 'https://www.google.ba',
264
+ 'https://www.google.com.bd',
265
+ 'https://www.google.be',
266
+ 'https://www.google.bf',
267
+ 'https://www.google.bg',
268
+ 'https://www.google.com.bh',
269
+ 'https://www.google.bi',
270
+ 'https://www.google.bj',
271
+ 'https://www.google.com.bn',
272
+ 'https://www.google.com.bo',
273
+ 'https://www.google.com.br',
274
+ 'https://www.google.bs',
275
+ 'https://www.google.bt',
276
+ 'https://www.google.co.bw',
277
+ 'https://www.google.by',
278
+ 'https://www.google.com.bz',
279
+ 'https://www.google.ca',
280
+ 'https://www.google.cd',
281
+ 'https://www.google.cf',
282
+ 'https://www.google.cg',
283
+ 'https://www.google.ch',
284
+ 'https://www.google.ci',
285
+ 'https://www.google.co.ck',
286
+ 'https://www.google.cl',
287
+ 'https://www.google.cm',
288
+ 'https://www.google.cn',
289
+ 'https://www.google.com.co',
290
+ 'https://www.google.co.cr',
291
+ 'https://www.google.com.cu',
292
+ 'https://www.google.cv',
293
+ 'https://www.google.com.cy',
294
+ 'https://www.google.cz',
295
+ 'https://www.google.de',
296
+ 'https://www.google.dj',
297
+ 'https://www.google.dk',
298
+ 'https://www.google.dm',
299
+ 'https://www.google.com.do',
300
+ 'https://www.google.dz',
301
+ 'https://www.google.com.ec',
302
+ 'https://www.google.ee',
303
+ 'https://www.google.com.eg',
304
+ 'https://www.google.es',
305
+ 'https://www.google.com.et',
306
+ 'https://www.google.fi',
307
+ 'https://www.google.com.fj',
308
+ 'https://www.google.fm',
309
+ 'https://www.google.fr',
310
+ 'https://www.google.ga',
311
+ 'https://www.google.ge',
312
+ 'https://www.google.gg',
313
+ 'https://www.google.com.gh',
314
+ 'https://www.google.com.gi',
315
+ 'https://www.google.gl',
316
+ 'https://www.google.gm',
317
+ 'https://www.google.gr',
318
+ 'https://www.google.com.gt',
319
+ 'https://www.google.gy',
320
+ 'https://www.google.com.hk',
321
+ 'https://www.google.hn',
322
+ 'https://www.google.hr',
323
+ 'https://www.google.ht',
324
+ 'https://www.google.hu',
325
+ 'https://www.google.co.id',
326
+ 'https://www.google.ie',
327
+ 'https://www.google.co.il',
328
+ 'https://www.google.im',
329
+ 'https://www.google.co.in',
330
+ 'https://www.google.iq',
331
+ 'https://www.google.is',
332
+ 'https://www.google.it',
333
+ 'https://www.google.je',
334
+ 'https://www.google.com.jm',
335
+ 'https://www.google.jo',
336
+ 'https://www.google.co.jp',
337
+ 'https://www.google.co.ke',
338
+ 'https://www.google.com.kh',
339
+ 'https://www.google.ki',
340
+ 'https://www.google.kg',
341
+ 'https://www.google.co.kr',
342
+ 'https://www.google.com.kw',
343
+ 'https://www.google.kz',
344
+ 'https://www.google.la',
345
+ 'https://www.google.com.lb',
346
+ 'https://www.google.li',
347
+ 'https://www.google.lk',
348
+ 'https://www.google.co.ls',
349
+ 'https://www.google.lt',
350
+ 'https://www.google.lu',
351
+ 'https://www.google.lv',
352
+ 'https://www.google.com.ly',
353
+ 'https://www.google.co.ma',
354
+ 'https://www.google.md',
355
+ 'https://www.google.me',
356
+ 'https://www.google.mg',
357
+ 'https://www.google.mk',
358
+ 'https://www.google.ml',
359
+ 'https://www.google.com.mm',
360
+ 'https://www.google.mn',
361
+ 'https://www.google.com.mt',
362
+ 'https://www.google.mu',
363
+ 'https://www.google.mv',
364
+ 'https://www.google.mw',
365
+ 'https://www.google.com.mx',
366
+ 'https://www.google.com.my',
367
+ 'https://www.google.co.mz',
368
+ 'https://www.google.com.na',
369
+ 'https://www.google.com.ng',
370
+ 'https://www.google.com.ni',
371
+ 'https://www.google.ne',
372
+ 'https://www.google.nl',
373
+ 'https://www.google.no',
374
+ 'https://www.google.com.np',
375
+ 'https://www.google.nr',
376
+ 'https://www.google.nu',
377
+ 'https://www.google.co.nz',
378
+ 'https://www.google.com.om',
379
+ 'https://www.google.com.pa',
380
+ 'https://www.google.com.pe',
381
+ 'https://www.google.com.pg',
382
+ 'https://www.google.com.ph',
383
+ 'https://www.google.com.pk',
384
+ 'https://www.google.pl',
385
+ 'https://www.google.pn',
386
+ 'https://www.google.com.pr',
387
+ 'https://www.google.ps',
388
+ 'https://www.google.pt',
389
+ 'https://www.google.com.py',
390
+ 'https://www.google.com.qa',
391
+ 'https://www.google.ro',
392
+ 'https://www.google.ru',
393
+ 'https://www.google.rw',
394
+ 'https://www.google.com.sa',
395
+ 'https://www.google.com.sb',
396
+ 'https://www.google.sc',
397
+ 'https://www.google.se',
398
+ 'https://www.google.com.sg',
399
+ 'https://www.google.sh',
400
+ 'https://www.google.si',
401
+ 'https://www.google.sk',
402
+ 'https://www.google.com.sl',
403
+ 'https://www.google.sn',
404
+ 'https://www.google.so',
405
+ 'https://www.google.sm',
406
+ 'https://www.google.sr',
407
+ 'https://www.google.st',
408
+ 'https://www.google.com.sv',
409
+ 'https://www.google.td',
410
+ 'https://www.google.tg',
411
+ 'https://www.google.co.th',
412
+ 'https://www.google.com.tj',
413
+ 'https://www.google.tl',
414
+ 'https://www.google.tm',
415
+ 'https://www.google.tn',
416
+ 'https://www.google.to',
417
+ 'https://www.google.com.tr',
418
+ 'https://www.google.tt',
419
+ 'https://www.google.com.tw',
420
+ 'https://www.google.co.tz',
421
+ 'https://www.google.com.ua',
422
+ 'https://www.google.co.ug',
423
+ 'https://www.google.co.uk',
424
+ 'https://www.google.com.uy',
425
+ 'https://www.google.co.uz',
426
+ 'https://www.google.com.vc',
427
+ 'https://www.google.co.ve',
428
+ 'https://www.google.co.vi',
429
+ 'https://www.google.com.vn',
430
+ 'https://www.google.vu',
431
+ 'https://www.google.ws',
432
+ 'https://www.google.rs',
433
+ 'https://www.google.co.za',
434
+ 'https://www.google.co.zm',
435
+ 'https://www.google.co.zw',
436
+ 'https://www.google.cat',
437
+ ],
438
+ 'style-src': [
439
+ 'https://googletagmanager.com',
440
+ 'https://tagmanager.google.com',
441
+ 'https://fonts.googleapis.com',
442
+ ],
443
+ 'font-src': ['https://fonts.gstatic.com'],
444
+ });
445
+ export const facebookPixelCspConfig = () => ({
446
+ 'script-src': ['https://connect.facebook.net'],
447
+ 'img-src': ['https://www.facebook.com'],
448
+ 'connect-src': ['https://www.facebook.com'],
449
+ });
450
+ export const typekitCspConfig = () => ({
451
+ 'script-src': ['use.typekit.net'],
452
+ 'style-src': ['use.typekit.net'],
453
+ 'font-src': ['use.typekit.net'],
454
+ 'img-src': ['p.typekit.net'],
455
+ 'connect-src': ['performance.typekit.net'],
456
+ });
457
+ export const cloudflareCspConfig = () => ({
458
+ 'script-src': [
459
+ SELF,
460
+ INLINE,
461
+ 'ajax.cloudflare.com',
462
+ 'static.cloudflareinsights.com',
463
+ 'https://challenges.cloudflare.com',
464
+ ],
465
+ 'connect-src': ['cloudflareinsights.com'],
466
+ 'frame-src': ['https://challenges.cloudflare.com'],
467
+ });
@@ -23,22 +23,31 @@ export default function useDraggableScroll(ref, { className, ...opts }) {
23
23
  ref.current?.classList[fn](`${className}--draggable`);
24
24
  }, [ref, className]);
25
25
  const onDragStart = () => {
26
+ if (!isInViewport) {
27
+ return;
28
+ }
26
29
  setDragging(true);
27
30
  ref.current?.classList.add(`${className}--dragging`);
28
31
  };
29
32
  const onDragMove = () => {
33
+ if (!isInViewport) {
34
+ return;
35
+ }
30
36
  if (timer.current && dragging) {
31
37
  clearTimeout(timer.current);
32
38
  }
33
39
  };
34
40
  const onDragEnd = () => {
41
+ if (!isInViewport) {
42
+ return;
43
+ }
35
44
  setDragging(false);
36
45
  timer.current = setTimeout(() => {
37
46
  ref.current?.classList.remove(`${className}--dragging`);
38
47
  }, 100);
39
48
  };
40
- useEventListener('mousemove', onDragMove, undefined, undefined, isInViewport && shouldScroll);
41
- useEventListener('mouseup', onDragEnd, undefined, undefined, isInViewport && shouldScroll);
49
+ useEventListener('mousemove', onDragMove);
50
+ useEventListener('mouseup', onDragEnd);
42
51
  useEffect(() => {
43
52
  if (!shouldScroll) {
44
53
  setModifiedEvents({
@@ -1 +1 @@
1
- {"version":3,"file":"use-escape.d.ts","sourceRoot":"","sources":["../src/hooks/use-escape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGjC,QAAA,MAAM,SAAS,GACb,KAAK,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,UAAU,MAAM,IAAI,EACpB;;CAEC,SAiBF,CAAA;AAED,eAAe,SAAS,CAAA"}
1
+ {"version":3,"file":"use-escape.d.ts","sourceRoot":"","sources":["../src/hooks/use-escape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,OAAO,CAAA;AAGzC,QAAA,MAAM,SAAS,GACb,KAAK,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,UAAU,MAAM,IAAI,EACpB;;CAEC,SAqBF,CAAA;AAED,eAAe,SAAS,CAAA"}
@@ -1,13 +1,16 @@
1
- import { useEventListener } from '../hooks';
1
+ import { useRef } from 'react';
2
+ import useEventListener from './use-event-listener';
2
3
  const useEscape = (ref, callback, opts = {
3
- requireFocus: true
4
+ requireFocus: true,
4
5
  }) => {
6
+ const documentRef = useRef(typeof document !== 'undefined' ? document : null);
5
7
  useEventListener('keydown', (event) => {
6
- if ((opts.requireFocus == false || ref.current?.contains(document.activeElement)) &&
8
+ if ((opts.requireFocus == false ||
9
+ ref.current?.contains(document.activeElement)) &&
7
10
  event.key === 'Escape') {
8
11
  event.preventDefault();
9
12
  callback();
10
13
  }
11
- }, {}, typeof document !== 'undefined' ? document : undefined, ref.current !== undefined && typeof document !== 'undefined');
14
+ }, undefined, documentRef);
12
15
  };
13
16
  export default useEscape;
@@ -1,7 +1,6 @@
1
- type Target = Document | Window | Element;
2
- type EventMap<T extends Target> = T extends Window ? WindowEventHandlersEventMap & GlobalEventHandlersEventMap : T extends Document ? DocumentEventMap : GlobalEventHandlersEventMap;
3
- type EventName<T extends Target> = keyof EventMap<T>;
4
- type EventListener<T extends Target, E extends EventName<T>> = (event: EventMap<T>[E]) => void | boolean;
5
- export default function useEventListener<T extends Target, E extends EventName<T>>(eventName: E, handler: EventListener<T, E>, options?: boolean | AddEventListenerOptions, element?: T | null, flag?: boolean): void;
6
- export {};
1
+ import type { RefObject } from 'react';
2
+ export default function useEventListener<K extends keyof MediaQueryListEventMap>(eventName: K, handler: (event: MediaQueryListEventMap[K]) => void, options?: boolean | AddEventListenerOptions, element?: RefObject<MediaQueryList>, flag?: boolean): void;
3
+ export default function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, options?: boolean | AddEventListenerOptions, element?: undefined, flag?: boolean): void;
4
+ export default function useEventListener<K extends keyof HTMLElementEventMap & keyof SVGElementEventMap, T extends Element = K extends keyof HTMLElementEventMap ? HTMLDivElement : SVGElement>(eventName: K, handler: ((event: HTMLElementEventMap[K]) => void) | ((event: SVGElementEventMap[K]) => void), options?: boolean | AddEventListenerOptions, element?: RefObject<T>, flag?: boolean): void;
5
+ export default function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, options?: boolean | AddEventListenerOptions, element?: RefObject<Document>, flag?: boolean): void;
7
6
  //# sourceMappingURL=use-event-listener.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-event-listener.d.ts","sourceRoot":"","sources":["../src/hooks/use-event-listener.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzC,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,GAC9C,2BAA2B,GAAG,2BAA2B,GACzD,CAAC,SAAS,QAAQ,GAChB,gBAAgB,GAChB,2BAA2B,CAAA;AAEjC,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEpD,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,CAC7D,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAClB,IAAI,GAAG,OAAO,CAAA;AAGnB,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAEtB,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,GAAE,OAAO,GAAG,uBAA4B,EAC/C,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,EAClB,IAAI,GAAE,OAAc,QAmDrB"}
1
+ {"version":3,"file":"use-event-listener.d.ts","sourceRoot":"","sources":["../src/hooks/use-event-listener.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS,MAAM,sBAAsB,EAEtC,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,IAAI,EACnD,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,EAC3C,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,EACnC,IAAI,CAAC,EAAE,OAAO,GACb,IAAI,CAAA;AAGP,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,CAAC,SAAS,MAAM,cAAc,EACrE,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,EAC3C,OAAO,CAAC,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,OAAO,GACb,IAAI,CAAA;AAGP,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS,MAAM,mBAAmB,GAAG,MAAM,kBAAkB,EAC9D,CAAC,SAAS,OAAO,GAAG,CAAC,SAAS,MAAM,mBAAmB,GACnD,cAAc,GACd,UAAU,EAEd,SAAS,EAAE,CAAC,EACZ,OAAO,EACH,CAAC,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,GACzC,CAAC,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,EAC3C,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EACtB,IAAI,CAAC,EAAE,OAAO,GACb,IAAI,CAAA;AAGP,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,CAAC,SAAS,MAAM,gBAAgB,EACvE,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC7C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,EAC3C,OAAO,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,EAC7B,IAAI,CAAC,EAAE,OAAO,GACb,IAAI,CAAA"}
@@ -1,37 +1,28 @@
1
1
  import { useEffect, useRef } from 'react';
2
- // Hook
3
- export default function useEventListener(eventName, handler, options = {}, element, flag = true) {
2
+ import { useIsomorphicLayoutEffect } from 'usehooks-ts';
3
+ export default function useEventListener(eventName, handler, options, element, flag = true) {
4
4
  // Create a ref that stores handler
5
- const savedHandler = useRef(null);
6
- const elementRef = useRef(null);
7
- useEffect(() => {
8
- elementRef.current = element || window;
9
- }, [element]);
10
- // Update ref.current value if handler changes.
11
- // This allows our effect below to always get latest handler ...
12
- // ... without us needing to pass it in effect deps array ...
13
- // ... and potentially cause effect to re-run every render.
14
- useEffect(() => {
5
+ const savedHandler = useRef(handler);
6
+ useIsomorphicLayoutEffect(() => {
15
7
  savedHandler.current = handler;
16
8
  }, [handler]);
17
9
  useEffect(() => {
18
- // Make sure element supports addEventListener
19
- // On
20
- const isSupported = elementRef.current && elementRef.current.addEventListener;
21
- if (!isSupported)
10
+ const targetElement = element?.current ?? window;
11
+ if (!(targetElement && targetElement.addEventListener))
22
12
  return;
23
13
  // Create event listener that calls handler function stored in ref
24
- const eventListener = (event) => savedHandler.current?.(event);
14
+ const listener = (event) => {
15
+ savedHandler.current(event);
16
+ };
25
17
  if (flag) {
26
- // Add event listener
27
- elementRef.current?.addEventListener(eventName, eventListener, options);
18
+ targetElement.addEventListener(eventName, listener, options);
28
19
  }
29
20
  else {
30
- elementRef.current?.removeEventListener(eventName, eventListener);
21
+ targetElement.removeEventListener(eventName, listener, options);
31
22
  }
32
23
  // Remove event listener on cleanup
33
24
  return () => {
34
- elementRef.current?.removeEventListener(eventName, eventListener);
25
+ targetElement.removeEventListener(eventName, listener, options);
35
26
  };
36
- }, [eventName, handler, options, element, flag]);
27
+ }, [eventName, element, options, flag]);
37
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-hide-on-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-hide-on-scroll.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,YAAY,GAAE,OAAe,GAC5B,OAAO,CA+DT"}
1
+ {"version":3,"file":"use-hide-on-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-hide-on-scroll.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,YAAY,GAAE,OAAe,GAC5B,OAAO,CA2CT"}
@@ -1,5 +1,5 @@
1
- import { useEventListener } from '../hooks';
2
1
  import { useCallback, useEffect, useState } from 'react';
2
+ import useEventListener from './use-event-listener';
3
3
  export default function useHideOnScroll(hiddenOnLoad = false) {
4
4
  const [hidden, setHidden] = useState(hiddenOnLoad);
5
5
  const handleScroll = useCallback(() => {
@@ -26,9 +26,9 @@ export default function useHideOnScroll(hiddenOnLoad = false) {
26
26
  useEffect(() => {
27
27
  handleScroll();
28
28
  }, []);
29
- useEventListener('scroll', handleScroll, { passive: true }, typeof window !== 'undefined' ? window : undefined);
30
- useEventListener('resize', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
31
- useEventListener('popstate', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
32
- useEventListener('pageshow', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
29
+ useEventListener('scroll', handleScroll, { passive: true });
30
+ useEventListener('resize', handleLoad, { passive: true });
31
+ useEventListener('popstate', handleLoad, { passive: true });
32
+ useEventListener('pageshow', handleLoad, { passive: true });
33
33
  return hidden;
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-parallax.d.ts","sourceRoot":"","sources":["../src/hooks/use-parallax.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,GAAE,OAAc,QA4BrB"}
1
+ {"version":3,"file":"use-parallax.d.ts","sourceRoot":"","sources":["../src/hooks/use-parallax.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,GAAE,OAAc,QA0BrB"}
@@ -3,6 +3,9 @@ import { useCallback } from 'react';
3
3
  export default function useParallax(items, flag = true) {
4
4
  const isMotionAllowed = useMotionAllowed();
5
5
  const onScroll = useCallback((event) => {
6
+ if (!flag || !isMotionAllowed) {
7
+ return;
8
+ }
6
9
  items.forEach((item, index) => {
7
10
  if (!item) {
8
11
  return;
@@ -12,6 +15,6 @@ export default function useParallax(items, flag = true) {
12
15
  item.style.transform = `translate3d(0, ${(box.top / window.innerHeight) * 100 * (1 + index / 500)}%, 0)`;
13
16
  });
14
17
  });
15
- }, [items]);
16
- useEventListener('scroll', onScroll, { passive: true }, undefined, flag && isMotionAllowed);
18
+ }, [items, flag, isMotionAllowed]);
19
+ useEventListener('scroll', onScroll, { passive: true });
17
20
  }