@micromag/core 0.3.707 → 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 +21 -10
- package/package.json +2 -2
package/es/contexts.js
CHANGED
|
@@ -321,6 +321,7 @@ var ConsentProvider = function ConsentProvider(_ref) {
|
|
|
321
321
|
initialConsented = _ref.consented,
|
|
322
322
|
expiration = _ref.expiration,
|
|
323
323
|
children = _ref.children;
|
|
324
|
+
// Has consented or not to cookies
|
|
324
325
|
var cookieConsented = JSCookie.get('has_consented') === 'true';
|
|
325
326
|
var _useState = useState(initialConsented || cookieConsented),
|
|
326
327
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -331,6 +332,8 @@ var ConsentProvider = function ConsentProvider(_ref) {
|
|
|
331
332
|
setConsented(initialConsented);
|
|
332
333
|
}
|
|
333
334
|
}, [initialConsented, setConsented]);
|
|
335
|
+
|
|
336
|
+
// The consent state itself
|
|
334
337
|
var baseConsent = useMemo(function () {
|
|
335
338
|
return (providedConsent || consentStates || []).map(function (item) {
|
|
336
339
|
if (isString(item)) {
|
|
@@ -349,40 +352,48 @@ var ConsentProvider = function ConsentProvider(_ref) {
|
|
|
349
352
|
});
|
|
350
353
|
});
|
|
351
354
|
}, [providedConsent]);
|
|
352
|
-
var _useState3 = useState(
|
|
355
|
+
var _useState3 = useState(null),
|
|
353
356
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
354
357
|
consent = _useState4[0],
|
|
355
358
|
setConsentState = _useState4[1];
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
}, [baseConsent, setConsentState]);
|
|
361
|
-
var setConsent = useCallback(function (values) {
|
|
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
362
|
var hasConsented = values !== null && typeof values !== 'undefined';
|
|
363
363
|
JSCookie.set('has_consented', hasConsented, {
|
|
364
364
|
secure: true,
|
|
365
365
|
expires: expiration
|
|
366
366
|
});
|
|
367
367
|
setConsented(hasConsented);
|
|
368
|
-
(values || []).
|
|
368
|
+
var tagManagerConsent = (values || []).reduce(function (acc, it) {
|
|
369
369
|
if (it.value === true) {
|
|
370
370
|
JSCookie.set(it.id, 'granted', {
|
|
371
371
|
secure: true,
|
|
372
372
|
expires: expiration
|
|
373
373
|
});
|
|
374
|
+
acc[it.id] = 'granted';
|
|
374
375
|
} else if (it.value === false) {
|
|
375
376
|
JSCookie.set(it.id, 'denied', {
|
|
376
377
|
secure: true,
|
|
377
378
|
expires: expiration
|
|
378
379
|
});
|
|
380
|
+
acc[it.id] = 'denied';
|
|
379
381
|
} else {
|
|
380
382
|
JSCookie.remove(it.id);
|
|
383
|
+
acc[it.id] = 'denied';
|
|
381
384
|
}
|
|
382
|
-
|
|
385
|
+
return acc;
|
|
386
|
+
}, {});
|
|
387
|
+
if (typeof gtag === 'function') {
|
|
388
|
+
gtag('consent', initial === true ? 'default' : 'update', tagManagerConsent);
|
|
389
|
+
}
|
|
383
390
|
setConsentState(values);
|
|
384
|
-
return values;
|
|
385
391
|
}, [setConsentState, expiration]);
|
|
392
|
+
useEffect(function () {
|
|
393
|
+
if (baseConsent !== null && baseConsent.length > 0) {
|
|
394
|
+
setConsent(baseConsent);
|
|
395
|
+
}
|
|
396
|
+
}, [baseConsent, setConsent]);
|
|
386
397
|
var value = useMemo(function () {
|
|
387
398
|
return {
|
|
388
399
|
consent: consent,
|
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
|
}
|