@micromag/core 0.3.706 → 0.3.708
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/es/contexts.js +52 -21
- package/package.json +2 -2
package/es/contexts.js
CHANGED
|
@@ -307,14 +307,33 @@ var useConsent = function useConsent() {
|
|
|
307
307
|
};
|
|
308
308
|
var propTypes$i = {
|
|
309
309
|
children: PropTypes.node.isRequired,
|
|
310
|
-
consent: PropTypes$1.consent
|
|
310
|
+
consent: PropTypes$1.consent,
|
|
311
|
+
consented: PropTypes.bool,
|
|
312
|
+
expiration: PropTypes.number
|
|
311
313
|
};
|
|
312
314
|
var defaultProps$i = {
|
|
313
|
-
consent: ['functionality_storage', 'analytics_storage', 'ad_storage', 'ad_personalization', 'ad_user_data']
|
|
315
|
+
consent: ['functionality_storage', 'analytics_storage', 'ad_storage', 'ad_personalization', 'ad_user_data'],
|
|
316
|
+
consented: false,
|
|
317
|
+
expiration: 182 // Default expiration in days
|
|
314
318
|
};
|
|
315
319
|
var ConsentProvider = function ConsentProvider(_ref) {
|
|
316
320
|
var providedConsent = _ref.consent,
|
|
321
|
+
initialConsented = _ref.consented,
|
|
322
|
+
expiration = _ref.expiration,
|
|
317
323
|
children = _ref.children;
|
|
324
|
+
// Has consented or not to cookies
|
|
325
|
+
var cookieConsented = JSCookie.get('has_consented') === 'true';
|
|
326
|
+
var _useState = useState(initialConsented || cookieConsented),
|
|
327
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
328
|
+
consented = _useState2[0],
|
|
329
|
+
setConsented = _useState2[1];
|
|
330
|
+
useEffect(function () {
|
|
331
|
+
if (initialConsented) {
|
|
332
|
+
setConsented(initialConsented);
|
|
333
|
+
}
|
|
334
|
+
}, [initialConsented, setConsented]);
|
|
335
|
+
|
|
336
|
+
// The consent state itself
|
|
318
337
|
var baseConsent = useMemo(function () {
|
|
319
338
|
return (providedConsent || consentStates || []).map(function (item) {
|
|
320
339
|
if (isString(item)) {
|
|
@@ -333,43 +352,55 @@ var ConsentProvider = function ConsentProvider(_ref) {
|
|
|
333
352
|
});
|
|
334
353
|
});
|
|
335
354
|
}, [providedConsent]);
|
|
336
|
-
var
|
|
337
|
-
|
|
338
|
-
consent =
|
|
339
|
-
setConsentState =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
var setConsent = useCallback(function (values) {
|
|
346
|
-
JSCookie.set('show_consent', values === null || values === undefined, {
|
|
355
|
+
var _useState3 = useState(null),
|
|
356
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
357
|
+
consent = _useState4[0],
|
|
358
|
+
setConsentState = _useState4[1];
|
|
359
|
+
var setConsent = useCallback(function () {
|
|
360
|
+
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
361
|
+
var initial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
362
|
+
var hasConsented = values !== null && typeof values !== 'undefined';
|
|
363
|
+
JSCookie.set('has_consented', hasConsented, {
|
|
347
364
|
secure: true,
|
|
348
|
-
expires:
|
|
365
|
+
expires: expiration
|
|
349
366
|
});
|
|
350
|
-
(
|
|
367
|
+
setConsented(hasConsented);
|
|
368
|
+
var tagManagerConsent = (values || []).reduce(function (acc, it) {
|
|
351
369
|
if (it.value === true) {
|
|
352
370
|
JSCookie.set(it.id, 'granted', {
|
|
353
371
|
secure: true,
|
|
354
|
-
expires:
|
|
372
|
+
expires: expiration
|
|
355
373
|
});
|
|
374
|
+
acc[it.id] = 'granted';
|
|
356
375
|
} else if (it.value === false) {
|
|
357
376
|
JSCookie.set(it.id, 'denied', {
|
|
358
377
|
secure: true,
|
|
359
|
-
expires:
|
|
378
|
+
expires: expiration
|
|
360
379
|
});
|
|
380
|
+
acc[it.id] = 'denied';
|
|
361
381
|
} else {
|
|
362
382
|
JSCookie.remove(it.id);
|
|
383
|
+
acc[it.id] = 'denied';
|
|
363
384
|
}
|
|
364
|
-
|
|
385
|
+
return acc;
|
|
386
|
+
}, {});
|
|
387
|
+
if (typeof gtag === 'function') {
|
|
388
|
+
gtag('consent', initial === true ? 'default' : 'update', tagManagerConsent);
|
|
389
|
+
}
|
|
365
390
|
setConsentState(values);
|
|
366
|
-
}, [setConsentState]);
|
|
391
|
+
}, [setConsentState, expiration]);
|
|
392
|
+
useEffect(function () {
|
|
393
|
+
if (baseConsent !== null && baseConsent.length > 0) {
|
|
394
|
+
setConsent(baseConsent);
|
|
395
|
+
}
|
|
396
|
+
}, [baseConsent, setConsent]);
|
|
367
397
|
var value = useMemo(function () {
|
|
368
398
|
return {
|
|
369
399
|
consent: consent,
|
|
370
|
-
setConsent: setConsent
|
|
400
|
+
setConsent: setConsent,
|
|
401
|
+
consented: consented
|
|
371
402
|
};
|
|
372
|
-
}, [consent, setConsent]);
|
|
403
|
+
}, [consent, setConsent, consented]);
|
|
373
404
|
return /*#__PURE__*/React.createElement(ConsentContext.Provider, {
|
|
374
405
|
value: value
|
|
375
406
|
}, children);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.708",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -145,5 +145,5 @@
|
|
|
145
145
|
"access": "public",
|
|
146
146
|
"registry": "https://registry.npmjs.org/"
|
|
147
147
|
},
|
|
148
|
-
"gitHead": "
|
|
148
|
+
"gitHead": "417c809c241afc40f85d6147ed4beffc9131e204"
|
|
149
149
|
}
|