Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@consent-manager/core

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@consent-manager/core - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0-next.0

3

dist/components/IntegrationWrapperComponents.d.ts

@@ -1,5 +0,6 @@

import React from 'react';
import React, { ReactNode } from 'react';
import { ConsentManagerConfig } from '../config';
export declare const IntegrationWrapperComponents: React.FC<{
config: ConsentManagerConfig;
children: ReactNode;
}>;

@@ -13,6 +13,5 @@ 'use strict';

function _extends() {
_extends = Object.assign || function (target) {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {

@@ -24,9 +23,6 @@ if (Object.prototype.hasOwnProperty.call(source, key)) {

}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {

@@ -37,3 +33,2 @@ if (source == null) return {};

var key, i;
for (i = 0; i < sourceKeys.length; i++) {

@@ -44,6 +39,4 @@ key = sourceKeys[i];

}
return target;
}
function _unsupportedIterableToArray(o, minLen) {

@@ -57,34 +50,24 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (it) return (it = it.call(o)).next.bind(it);
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
return {
done: false,
value: o[i++]
};
};
}
it = o[Symbol.iterator]();
return it.next.bind(it);
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

@@ -106,4 +89,3 @@

var _useContext = React.useContext(ConsentManagerContext),
config = _useContext.config;
config = _useContext.config;
return config;

@@ -113,4 +95,3 @@ }

var _useContext2 = React.useContext(ConsentManagerContext),
store = _useContext2.store;
store = _useContext2.store;
return store;

@@ -120,4 +101,3 @@ }

var _useContext3 = React.useContext(ConsentManagerContext),
config = _useContext3.config;
config = _useContext3.config;
return config.integrations;

@@ -128,3 +108,2 @@ }

var _store$decisions;
var store = storage[0];

@@ -134,3 +113,2 @@ var storedDecisions = (_store$decisions = store == null ? void 0 : store.decisions) != null ? _store$decisions : {};

var pending = [];
for (var _iterator = _createForOfIteratorHelperLoose(configuredIntegrations), _step; !(_step = _iterator()).done;) {

@@ -141,10 +119,7 @@ var integration = _step.value;

var storedDecision = userDecision || enabledByDefault;
if (typeof storedDecision === 'undefined') {
pending.push(integration.id);
}
decisions[integration.id] = Boolean(storedDecision);
}
return {

@@ -155,3 +130,2 @@ decisions: decisions,

}
function useCombinedIntegrationStoreDecisions() {

@@ -165,23 +139,17 @@ var storage = useStore();

}
function useDecisions() {
var _useContext = React.useContext(ConsentManagerContext),
onChangeDecision = _useContext.config.onChangeDecision;
onChangeDecision = _useContext.config.onChangeDecision;
var _useCombinedIntegrati = useCombinedIntegrationStoreDecisions(),
decisions = _useCombinedIntegrati.decisions;
decisions = _useCombinedIntegrati.decisions;
var _useState = React.useState(decisions),
decisionsState = _useState[0],
setDecisions = _useState[1];
decisionsState = _useState[0],
setDecisions = _useState[1];
var _useStore = useStore(),
setStore = _useStore[1];
setStore = _useStore[1];
React.useEffect(function () {
if (decisionsState === decisions) {
return;
} // TODO: spread old here to preserve decisions
}
// TODO: spread old here to preserve decisions
setDecisions(function () {

@@ -193,7 +161,5 @@ return decisions;

var nextDecisionState = typeof newDecisionState === 'function' ? newDecisionState(decisionsState) : newDecisionState;
if (onChangeDecision) {
onChangeDecision(decisionsState, nextDecisionState);
}
setStore(function (store) {

@@ -209,4 +175,3 @@ return _extends({}, store, {

var _useCombinedIntegrati2 = useCombinedIntegrationStoreDecisions(),
pending = _useCombinedIntegrati2.pending;
pending = _useCombinedIntegrati2.pending;
return pending != null ? pending : [];

@@ -221,11 +186,8 @@ }

var config = _ref.config,
children = _ref.children;
children = _ref.children;
var _useDecisions = useDecisions(),
decisions = _useDecisions[0];
decisions = _useDecisions[0];
var _useState = React.useState(false),
isMounted = _useState[0],
setIsMounted = _useState[1];
isMounted = _useState[0],
setIsMounted = _useState[1];
React.useEffect(function () {

@@ -238,3 +200,2 @@ return setIsMounted(true);

}
return config.integrations.filter(function (i) {

@@ -246,3 +207,3 @@ return decisions[i.id] === true;

var WrapperComponent = _ref2.WrapperComponent,
id = _ref2.id;
id = _ref2.id;
return React__default.createElement(WrapperComponent, {

@@ -259,23 +220,18 @@ key: id

var integrationId = _ref.integrationId,
fallbackUrl = _ref.fallbackUrl,
props = _objectWithoutPropertiesLoose(_ref, _excluded);
fallbackUrl = _ref.fallbackUrl,
props = _objectWithoutPropertiesLoose(_ref, _excluded);
var integration = useIntegration(integrationId);
var _useDecision = useDecision(integrationId),
setDecision = _useDecision[1];
setDecision = _useDecision[1];
var enableIntegration = React.useCallback(function () {
setDecision(true);
}, [setDecision]);
if (!integration) {
throw new Error("No integration found for \"" + integrationId + "\"");
}
var title = integration.title,
privacyPolicyUrl = integration.privacyPolicyUrl,
Icon = integration.Icon,
description = integration.description,
color = integration.color;
privacyPolicyUrl = integration.privacyPolicyUrl,
Icon = integration.Icon,
description = integration.description,
color = integration.color;
return React__default.createElement("section", Object.assign({

@@ -320,7 +276,5 @@ style: {

var integrations = useIntegrations();
var _useDecisions = useDecisions(),
decisions = _useDecisions[0],
setDecisions = _useDecisions[1];
decisions = _useDecisions[0],
setDecisions = _useDecisions[1];
var enabledIntegrations = React.useMemo(function () {

@@ -338,3 +292,2 @@ return integrations.filter(function (_ref) {

var decisions = {};
for (var _iterator = _createForOfIteratorHelperLoose(integrations), _step; !(_step = _iterator()).done;) {

@@ -345,3 +298,2 @@ var integration = _step.value;

}
setDecisions(decisions);

@@ -360,11 +312,9 @@ }, [enabledIntegrations, integrations, setDecisions]);

var integrations = _ref.integrations,
initialValues = _ref.initialValues,
onSubmit = _ref.onSubmit;
initialValues = _ref.initialValues,
onSubmit = _ref.onSubmit;
var _useSet = reactUse.useSet(new Set(initialValues.enabled)),
set = _useSet[0],
_useSet$ = _useSet[1],
toggle = _useSet$.toggle,
has = _useSet$.has;
set = _useSet[0],
_useSet$ = _useSet[1],
toggle = _useSet$.toggle,
has = _useSet$.has;
var handleChange = React.useCallback(function (e) {

@@ -385,3 +335,3 @@ var integrationId = e.target.value;

var id = _ref2.id,
title = _ref2.title;
title = _ref2.title;
return React__default.createElement("label", {

@@ -404,11 +354,8 @@ key: id

var formComponent = _ref.formComponent,
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
var _useEnabledIntegratio = useEnabledIntegrations(),
enabledIntegrations = _useEnabledIntegratio[0],
setEnabledIntegrations = _useEnabledIntegratio[1];
enabledIntegrations = _useEnabledIntegratio[0],
setEnabledIntegrations = _useEnabledIntegratio[1];
var _useConfig = useConfig(),
integrations = _useConfig.integrations;
integrations = _useConfig.integrations;
var DecisionsForm$1 = formComponent || DecisionsForm;

@@ -436,5 +383,4 @@ var handleFormSubmit = React.useCallback(function (values) {

var _ref$color = _ref.color,
color = _ref$color === void 0 ? 'currentColor' : _ref$color,
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
color = _ref$color === void 0 ? 'currentColor' : _ref$color,
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
return React__default.createElement("svg", Object.assign({

@@ -444,3 +390,2 @@ xmlns: "http://www.w3.org/2000/svg",

viewBox: "0 0 24 24",
/* Ensure SVG behaves responsive on Safari and some older browsers like IE */

@@ -458,6 +403,6 @@ height: "100%",

var children = _ref.children,
config = _ref.config,
_ref$fallbackComponen = _ref.fallbackComponent,
fallbackComponent = _ref$fallbackComponen === void 0 ? FallbackComponent : _ref$fallbackComponen,
store = _ref.store;
config = _ref.config,
_ref$fallbackComponen = _ref.fallbackComponent,
fallbackComponent = _ref$fallbackComponen === void 0 ? FallbackComponent : _ref$fallbackComponen,
store = _ref.store;
return React__default.createElement(ConsentManagerContext.Provider, {

@@ -475,7 +420,5 @@ value: {

var _decisions$id;
var _useDecisions = useDecisions(),
decisions = _useDecisions[0],
setAndStoreDecisions = _useDecisions[1];
decisions = _useDecisions[0],
setAndStoreDecisions = _useDecisions[1];
var decision = (_decisions$id = decisions[id]) != null ? _decisions$id : false;

@@ -486,3 +429,2 @@ return [decision, function (value) {

var _extends2;
return _extends({}, decisions, (_extends2 = {}, _extends2[id] = newStateValue, _extends2));

@@ -494,4 +436,3 @@ });

var _useContext = React.useContext(ConsentManagerContext),
FallbackComponent = _useContext.fallbackComponent;
FallbackComponent = _useContext.fallbackComponent;
if (!FallbackComponent) {

@@ -502,3 +443,2 @@ return function () {

}
return FallbackComponent;

@@ -508,14 +448,10 @@ }

var id = _ref2.id,
children = _ref2.children,
props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
children = _ref2.children,
props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
var _useDecision = useDecision(id),
decision = _useDecision[0];
decision = _useDecision[0];
var DefaultFallbackComponent = useFallbackComponent();
if (decision) {
return React__default.createElement(React__default.Fragment, null, children);
}
return React__default.createElement(DefaultFallbackComponent, Object.assign({

@@ -527,11 +463,8 @@ integrationId: id

var _useDecision2 = useDecision(id),
decision = _useDecision2[0];
decision = _useDecision2[0];
var _useContext2 = React.useContext(ConsentManagerContext),
config = _useContext2.config;
config = _useContext2.config;
var integration = config.integrations.find(function (i) {
return i.id === id;
});
if (!decision || !integration || typeof integration.pageViewEventHandler !== 'function') {

@@ -541,3 +474,2 @@ // eslint-disable-next-line @typescript-eslint/no-empty-function

}
return integration.pageViewEventHandler;

@@ -544,0 +476,0 @@ }

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("react"),t=(e=n)&&"object"==typeof e&&"default"in e?e.default:e,r=require("react-use"),o=require("wcag-contrast");function i(){return(i=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function a(e,n){if(null==e)return{};var t,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n.indexOf(t=i[r])>=0||(o[t]=e[t]);return o}function u(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function l(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return u(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?u(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}var c=n.createContext({fallbackComponent:function(){return null},config:{integrations:[]},store:[{decisions:{}},function(){}]});function f(){return n.useContext(c).store}function s(){return n.useContext(c).config.integrations}function d(){var e=f(),t=s();return n.useMemo((function(){return function(e,n){for(var t,r,o=n[0],i=null!=(t=null==o?void 0:o.decisions)?t:{},a={},u=[],c=l(e);!(r=c()).done;){var f=r.value,s=i[f.id],d=s||void 0===s&&f.enabledByDefault;void 0===d&&u.push(f.id),a[f.id]=Boolean(d)}return{decisions:a,pending:u}}(t,e)}),[t,e])}function m(){var e=n.useContext(c).config.onChangeDecision,t=d().decisions,r=n.useState(t),o=r[0],a=r[1],u=f()[1];n.useEffect((function(){o!==t&&a((function(){return t}))}),[t,o,a,u]);var l=n.useCallback((function(n){var t="function"==typeof n?n(o):n;e&&e(o,t),u((function(e){return i({},e,{decisions:t})}))}),[o,e,u]);return[o,l]}var p=function(e){var r=e.config,o=e.children,i=m()[0],a=n.useState(!1),u=a[0],l=a[1];n.useEffect((function(){return l(!0)}),[l]);var c=n.useMemo((function(){return u?r.integrations.filter((function(e){return!0===i[e.id]})).filter((function(e){return Boolean(e.WrapperComponent)})).map((function(e){return t.createElement(e.WrapperComponent,{key:e.id})})):null}),[r,i,u]);return t.createElement(t.Fragment,null,o,c)},g=["integrationId","fallbackUrl"],v=function(e){var r=e.integrationId,o=e.fallbackUrl,i=a(e,g),u=y(r),l=k(r)[1],c=n.useCallback((function(){l(!0)}),[l]);if(!u)throw new Error('No integration found for "'+r+'"');var f=u.title,s=u.privacyPolicyUrl,d=u.Icon,m=u.description,p=u.color;return t.createElement("section",Object.assign({style:{backgroundColor:"#ddd",padding:"1rem 2rem",border:"4px solid #222"}},i),t.createElement("h1",{style:{display:"flex",alignItems:"center"}},d&&t.createElement(d,{"aria-hidden":"true",color:p,style:{width:"2rem",marginRight:"1rem"}}),f),m&&t.createElement("p",null,m),s&&t.createElement("p",null,t.createElement("a",{href:s,target:"_blank",rel:"noreferrer"},"Privacy policy of ",f)),t.createElement("button",{onClick:function(){return c()},style:{display:"block",margin:"0 auto"}},"Enable ",u.title),o&&t.createElement("p",null,"Alternative:",t.createElement("br",null),"Visit"," ",t.createElement("a",{href:o,target:"_blank",rel:"noreferrer"},o)))};function b(){var e=s(),t=m(),r=t[0],o=t[1],i=n.useMemo((function(){return e.filter((function(e){return Boolean(r[e.id])})).map((function(e){return e.id}))}),[e,r]),a=n.useCallback((function(n){for(var t,r="function"==typeof n?n(i):n,a={},u=l(e);!(t=u()).done;){var c=t.value,f=r.includes(c.id);a[c.id]=f}o(a)}),[i,e,o]);return[i,a]}function y(e){return s().find((function(n){return n.id===e}))}var h=function(e){var o=e.integrations,i=e.onSubmit,a=r.useSet(new Set(e.initialValues.enabled)),u=a[0],l=a[1],c=l.toggle,f=l.has,s=n.useCallback((function(e){c(e.target.value)}),[c]),d=n.useCallback((function(e){e.preventDefault();var n=Array.from(u.values());i({enabled:n})}),[u,i]);return t.createElement("form",{onSubmit:d},o.map((function(e){var n=e.id,r=e.title;return t.createElement("label",{key:n},t.createElement("input",{name:"enabled",type:"checkbox",value:n,onChange:s,checked:f(n)})," ",r)})),t.createElement("button",{type:"submit"},"Submit"))},C=["formComponent"],E=["color"],x=["id","children"];function k(e){var n,t=m(),r=t[1],o=null!=(n=t[0][e])&&n;return[o,function(n){var t="function"==typeof n?n(o):n;r((function(n){var r;return i({},n,((r={})[e]=t,r))}))}]}function w(){return n.useContext(c).fallbackComponent||function(){return null}}exports.ConsentManager=function(e){var n=e.config,r=e.fallbackComponent;return t.createElement(c.Provider,{value:{fallbackComponent:void 0===r?v:r,config:n,store:e.store}},t.createElement(p,{config:n},e.children))},exports.ConsentManagerForm=function(e){var r=e.formComponent,o=a(e,C),i=b(),u=i[0],l=i[1],f=n.useContext(c).config.integrations,s=r||h,d=n.useCallback((function(e){l((function(){return e.enabled}))}),[l]);return t.createElement(s,Object.assign({integrations:f,initialValues:{enabled:u},onSubmit:d},o))},exports.PrivacyShield=function(e){var n=e.id,r=e.children,o=a(e,x),i=k(n)[0],u=w();return i?t.createElement(t.Fragment,null,r):t.createElement(u,Object.assign({integrationId:n},o))},exports.createIconComponentFromSimpleIconsSvgPath=function(e,n){return function(r){var o=r.color,i=void 0===o?"currentColor":o,u=a(r,E);return t.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:i,viewBox:"0 0 24 24",height:"100%",width:"100%"},u),t.createElement("title",null,e),t.createElement("path",{d:n}))}},exports.getForegroundColor=function(e){return o.hex(e,"#000")>=7?"#000":"#fff"},exports.useConsentFormVisible=function(){return 0!==(e=d().pending,null!=e?e:[]).length;var e},exports.useDecision=k,exports.useDecisions=m,exports.useEnabledIntegrations=b,exports.useFallbackComponent=w,exports.useIntegration=y,exports.useIntegrations=s,exports.usePageViewEventTrigger=function(e){var t=k(e)[0],r=n.useContext(c).config.integrations.find((function(n){return n.id===e}));return t&&r&&"function"==typeof r.pageViewEventHandler?r.pageViewEventHandler:function(){}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("react"),t=(e=n)&&"object"==typeof e&&"default"in e?e.default:e,r=require("react-use"),o=require("wcag-contrast");function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function a(e,n){if(null==e)return{};var t,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n.indexOf(t=i[r])>=0||(o[t]=e[t]);return o}function u(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function l(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return u(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?u(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var c=n.createContext({fallbackComponent:function(){return null},config:{integrations:[]},store:[{decisions:{}},function(){}]});function f(){return n.useContext(c).store}function s(){return n.useContext(c).config.integrations}function d(){var e=f(),t=s();return n.useMemo((function(){return function(e,n){for(var t,r,o=n[0],i=null!=(t=null==o?void 0:o.decisions)?t:{},a={},u=[],c=l(e);!(r=c()).done;){var f=r.value,s=i[f.id],d=s||void 0===s&&f.enabledByDefault;void 0===d&&u.push(f.id),a[f.id]=Boolean(d)}return{decisions:a,pending:u}}(t,e)}),[t,e])}function m(){var e=n.useContext(c).config.onChangeDecision,t=d().decisions,r=n.useState(t),o=r[0],a=r[1],u=f()[1];n.useEffect((function(){o!==t&&a((function(){return t}))}),[t,o,a,u]);var l=n.useCallback((function(n){var t="function"==typeof n?n(o):n;e&&e(o,t),u((function(e){return i({},e,{decisions:t})}))}),[o,e,u]);return[o,l]}var p=function(e){var r=e.config,o=e.children,i=m()[0],a=n.useState(!1),u=a[0],l=a[1];n.useEffect((function(){return l(!0)}),[l]);var c=n.useMemo((function(){return u?r.integrations.filter((function(e){return!0===i[e.id]})).filter((function(e){return Boolean(e.WrapperComponent)})).map((function(e){return t.createElement(e.WrapperComponent,{key:e.id})})):null}),[r,i,u]);return t.createElement(t.Fragment,null,o,c)},g=["integrationId","fallbackUrl"],v=function(e){var r=e.integrationId,o=e.fallbackUrl,i=a(e,g),u=y(r),l=k(r)[1],c=n.useCallback((function(){l(!0)}),[l]);if(!u)throw new Error('No integration found for "'+r+'"');var f=u.title,s=u.privacyPolicyUrl,d=u.Icon,m=u.description,p=u.color;return t.createElement("section",Object.assign({style:{backgroundColor:"#ddd",padding:"1rem 2rem",border:"4px solid #222"}},i),t.createElement("h1",{style:{display:"flex",alignItems:"center"}},d&&t.createElement(d,{"aria-hidden":"true",color:p,style:{width:"2rem",marginRight:"1rem"}}),f),m&&t.createElement("p",null,m),s&&t.createElement("p",null,t.createElement("a",{href:s,target:"_blank",rel:"noreferrer"},"Privacy policy of ",f)),t.createElement("button",{onClick:function(){return c()},style:{display:"block",margin:"0 auto"}},"Enable ",u.title),o&&t.createElement("p",null,"Alternative:",t.createElement("br",null),"Visit"," ",t.createElement("a",{href:o,target:"_blank",rel:"noreferrer"},o)))};function b(){var e=s(),t=m(),r=t[0],o=t[1],i=n.useMemo((function(){return e.filter((function(e){return Boolean(r[e.id])})).map((function(e){return e.id}))}),[e,r]),a=n.useCallback((function(n){for(var t,r="function"==typeof n?n(i):n,a={},u=l(e);!(t=u()).done;){var c=t.value,f=r.includes(c.id);a[c.id]=f}o(a)}),[i,e,o]);return[i,a]}function y(e){return s().find((function(n){return n.id===e}))}var h=function(e){var o=e.integrations,i=e.onSubmit,a=r.useSet(new Set(e.initialValues.enabled)),u=a[0],l=a[1],c=l.toggle,f=l.has,s=n.useCallback((function(e){c(e.target.value)}),[c]),d=n.useCallback((function(e){e.preventDefault();var n=Array.from(u.values());i({enabled:n})}),[u,i]);return t.createElement("form",{onSubmit:d},o.map((function(e){var n=e.id,r=e.title;return t.createElement("label",{key:n},t.createElement("input",{name:"enabled",type:"checkbox",value:n,onChange:s,checked:f(n)})," ",r)})),t.createElement("button",{type:"submit"},"Submit"))},C=["formComponent"],E=["color"],x=["id","children"];function k(e){var n,t=m(),r=t[1],o=null!=(n=t[0][e])&&n;return[o,function(n){var t="function"==typeof n?n(o):n;r((function(n){var r;return i({},n,((r={})[e]=t,r))}))}]}function w(){return n.useContext(c).fallbackComponent||function(){return null}}exports.ConsentManager=function(e){var n=e.config,r=e.fallbackComponent;return t.createElement(c.Provider,{value:{fallbackComponent:void 0===r?v:r,config:n,store:e.store}},t.createElement(p,{config:n},e.children))},exports.ConsentManagerForm=function(e){var r=e.formComponent,o=a(e,C),i=b(),u=i[0],l=i[1],f=n.useContext(c).config.integrations,s=r||h,d=n.useCallback((function(e){l((function(){return e.enabled}))}),[l]);return t.createElement(s,Object.assign({integrations:f,initialValues:{enabled:u},onSubmit:d},o))},exports.PrivacyShield=function(e){var n=e.id,r=e.children,o=a(e,x),i=k(n)[0],u=w();return i?t.createElement(t.Fragment,null,r):t.createElement(u,Object.assign({integrationId:n},o))},exports.createIconComponentFromSimpleIconsSvgPath=function(e,n){return function(r){var o=r.color,i=void 0===o?"currentColor":o,u=a(r,E);return t.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:i,viewBox:"0 0 24 24",height:"100%",width:"100%"},u),t.createElement("title",null,e),t.createElement("path",{d:n}))}},exports.getForegroundColor=function(e){return o.hex(e,"#000")>=7?"#000":"#fff"},exports.useConsentFormVisible=function(){return 0!==(e=d().pending,null!=e?e:[]).length;var e},exports.useDecision=k,exports.useDecisions=m,exports.useEnabledIntegrations=b,exports.useFallbackComponent=w,exports.useIntegration=y,exports.useIntegrations=s,exports.usePageViewEventTrigger=function(e){var t=k(e)[0],r=n.useContext(c).config.integrations.find((function(n){return n.id===e}));return t&&r&&"function"==typeof r.pageViewEventHandler?r.pageViewEventHandler:function(){}};
//# sourceMappingURL=core.cjs.production.min.js.map

@@ -6,6 +6,5 @@ import React, { useContext, createContext, useState, useEffect, useCallback, useMemo } from 'react';

function _extends() {
_extends = Object.assign || function (target) {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {

@@ -17,9 +16,6 @@ if (Object.prototype.hasOwnProperty.call(source, key)) {

}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {

@@ -30,3 +26,2 @@ if (source == null) return {};

var key, i;
for (i = 0; i < sourceKeys.length; i++) {

@@ -37,6 +32,4 @@ key = sourceKeys[i];

}
return target;
}
function _unsupportedIterableToArray(o, minLen) {

@@ -50,34 +43,24 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (it) return (it = it.call(o)).next.bind(it);
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
return {
done: false,
value: o[i++]
};
};
}
it = o[Symbol.iterator]();
return it.next.bind(it);
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

@@ -99,4 +82,3 @@

var _useContext = useContext(ConsentManagerContext),
config = _useContext.config;
config = _useContext.config;
return config;

@@ -106,4 +88,3 @@ }

var _useContext2 = useContext(ConsentManagerContext),
store = _useContext2.store;
store = _useContext2.store;
return store;

@@ -113,4 +94,3 @@ }

var _useContext3 = useContext(ConsentManagerContext),
config = _useContext3.config;
config = _useContext3.config;
return config.integrations;

@@ -121,3 +101,2 @@ }

var _store$decisions;
var store = storage[0];

@@ -127,3 +106,2 @@ var storedDecisions = (_store$decisions = store == null ? void 0 : store.decisions) != null ? _store$decisions : {};

var pending = [];
for (var _iterator = _createForOfIteratorHelperLoose(configuredIntegrations), _step; !(_step = _iterator()).done;) {

@@ -134,10 +112,7 @@ var integration = _step.value;

var storedDecision = userDecision || enabledByDefault;
if (typeof storedDecision === 'undefined') {
pending.push(integration.id);
}
decisions[integration.id] = Boolean(storedDecision);
}
return {

@@ -148,3 +123,2 @@ decisions: decisions,

}
function useCombinedIntegrationStoreDecisions() {

@@ -158,23 +132,17 @@ var storage = useStore();

}
function useDecisions() {
var _useContext = useContext(ConsentManagerContext),
onChangeDecision = _useContext.config.onChangeDecision;
onChangeDecision = _useContext.config.onChangeDecision;
var _useCombinedIntegrati = useCombinedIntegrationStoreDecisions(),
decisions = _useCombinedIntegrati.decisions;
decisions = _useCombinedIntegrati.decisions;
var _useState = useState(decisions),
decisionsState = _useState[0],
setDecisions = _useState[1];
decisionsState = _useState[0],
setDecisions = _useState[1];
var _useStore = useStore(),
setStore = _useStore[1];
setStore = _useStore[1];
useEffect(function () {
if (decisionsState === decisions) {
return;
} // TODO: spread old here to preserve decisions
}
// TODO: spread old here to preserve decisions
setDecisions(function () {

@@ -186,7 +154,5 @@ return decisions;

var nextDecisionState = typeof newDecisionState === 'function' ? newDecisionState(decisionsState) : newDecisionState;
if (onChangeDecision) {
onChangeDecision(decisionsState, nextDecisionState);
}
setStore(function (store) {

@@ -202,4 +168,3 @@ return _extends({}, store, {

var _useCombinedIntegrati2 = useCombinedIntegrationStoreDecisions(),
pending = _useCombinedIntegrati2.pending;
pending = _useCombinedIntegrati2.pending;
return pending != null ? pending : [];

@@ -214,11 +179,8 @@ }

var config = _ref.config,
children = _ref.children;
children = _ref.children;
var _useDecisions = useDecisions(),
decisions = _useDecisions[0];
decisions = _useDecisions[0];
var _useState = useState(false),
isMounted = _useState[0],
setIsMounted = _useState[1];
isMounted = _useState[0],
setIsMounted = _useState[1];
useEffect(function () {

@@ -231,3 +193,2 @@ return setIsMounted(true);

}
return config.integrations.filter(function (i) {

@@ -239,3 +200,3 @@ return decisions[i.id] === true;

var WrapperComponent = _ref2.WrapperComponent,
id = _ref2.id;
id = _ref2.id;
return React.createElement(WrapperComponent, {

@@ -252,23 +213,18 @@ key: id

var integrationId = _ref.integrationId,
fallbackUrl = _ref.fallbackUrl,
props = _objectWithoutPropertiesLoose(_ref, _excluded);
fallbackUrl = _ref.fallbackUrl,
props = _objectWithoutPropertiesLoose(_ref, _excluded);
var integration = useIntegration(integrationId);
var _useDecision = useDecision(integrationId),
setDecision = _useDecision[1];
setDecision = _useDecision[1];
var enableIntegration = useCallback(function () {
setDecision(true);
}, [setDecision]);
if (!integration) {
throw new Error("No integration found for \"" + integrationId + "\"");
}
var title = integration.title,
privacyPolicyUrl = integration.privacyPolicyUrl,
Icon = integration.Icon,
description = integration.description,
color = integration.color;
privacyPolicyUrl = integration.privacyPolicyUrl,
Icon = integration.Icon,
description = integration.description,
color = integration.color;
return React.createElement("section", Object.assign({

@@ -313,7 +269,5 @@ style: {

var integrations = useIntegrations();
var _useDecisions = useDecisions(),
decisions = _useDecisions[0],
setDecisions = _useDecisions[1];
decisions = _useDecisions[0],
setDecisions = _useDecisions[1];
var enabledIntegrations = useMemo(function () {

@@ -331,3 +285,2 @@ return integrations.filter(function (_ref) {

var decisions = {};
for (var _iterator = _createForOfIteratorHelperLoose(integrations), _step; !(_step = _iterator()).done;) {

@@ -338,3 +291,2 @@ var integration = _step.value;

}
setDecisions(decisions);

@@ -353,11 +305,9 @@ }, [enabledIntegrations, integrations, setDecisions]);

var integrations = _ref.integrations,
initialValues = _ref.initialValues,
onSubmit = _ref.onSubmit;
initialValues = _ref.initialValues,
onSubmit = _ref.onSubmit;
var _useSet = useSet(new Set(initialValues.enabled)),
set = _useSet[0],
_useSet$ = _useSet[1],
toggle = _useSet$.toggle,
has = _useSet$.has;
set = _useSet[0],
_useSet$ = _useSet[1],
toggle = _useSet$.toggle,
has = _useSet$.has;
var handleChange = useCallback(function (e) {

@@ -378,3 +328,3 @@ var integrationId = e.target.value;

var id = _ref2.id,
title = _ref2.title;
title = _ref2.title;
return React.createElement("label", {

@@ -397,11 +347,8 @@ key: id

var formComponent = _ref.formComponent,
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
var _useEnabledIntegratio = useEnabledIntegrations(),
enabledIntegrations = _useEnabledIntegratio[0],
setEnabledIntegrations = _useEnabledIntegratio[1];
enabledIntegrations = _useEnabledIntegratio[0],
setEnabledIntegrations = _useEnabledIntegratio[1];
var _useConfig = useConfig(),
integrations = _useConfig.integrations;
integrations = _useConfig.integrations;
var DecisionsForm$1 = formComponent || DecisionsForm;

@@ -429,5 +376,4 @@ var handleFormSubmit = useCallback(function (values) {

var _ref$color = _ref.color,
color = _ref$color === void 0 ? 'currentColor' : _ref$color,
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
color = _ref$color === void 0 ? 'currentColor' : _ref$color,
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
return React.createElement("svg", Object.assign({

@@ -437,3 +383,2 @@ xmlns: "http://www.w3.org/2000/svg",

viewBox: "0 0 24 24",
/* Ensure SVG behaves responsive on Safari and some older browsers like IE */

@@ -451,6 +396,6 @@ height: "100%",

var children = _ref.children,
config = _ref.config,
_ref$fallbackComponen = _ref.fallbackComponent,
fallbackComponent = _ref$fallbackComponen === void 0 ? FallbackComponent : _ref$fallbackComponen,
store = _ref.store;
config = _ref.config,
_ref$fallbackComponen = _ref.fallbackComponent,
fallbackComponent = _ref$fallbackComponen === void 0 ? FallbackComponent : _ref$fallbackComponen,
store = _ref.store;
return React.createElement(ConsentManagerContext.Provider, {

@@ -468,7 +413,5 @@ value: {

var _decisions$id;
var _useDecisions = useDecisions(),
decisions = _useDecisions[0],
setAndStoreDecisions = _useDecisions[1];
decisions = _useDecisions[0],
setAndStoreDecisions = _useDecisions[1];
var decision = (_decisions$id = decisions[id]) != null ? _decisions$id : false;

@@ -479,3 +422,2 @@ return [decision, function (value) {

var _extends2;
return _extends({}, decisions, (_extends2 = {}, _extends2[id] = newStateValue, _extends2));

@@ -487,4 +429,3 @@ });

var _useContext = useContext(ConsentManagerContext),
FallbackComponent = _useContext.fallbackComponent;
FallbackComponent = _useContext.fallbackComponent;
if (!FallbackComponent) {

@@ -495,3 +436,2 @@ return function () {

}
return FallbackComponent;

@@ -501,14 +441,10 @@ }

var id = _ref2.id,
children = _ref2.children,
props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
children = _ref2.children,
props = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
var _useDecision = useDecision(id),
decision = _useDecision[0];
decision = _useDecision[0];
var DefaultFallbackComponent = useFallbackComponent();
if (decision) {
return React.createElement(React.Fragment, null, children);
}
return React.createElement(DefaultFallbackComponent, Object.assign({

@@ -520,11 +456,8 @@ integrationId: id

var _useDecision2 = useDecision(id),
decision = _useDecision2[0];
decision = _useDecision2[0];
var _useContext2 = useContext(ConsentManagerContext),
config = _useContext2.config;
config = _useContext2.config;
var integration = config.integrations.find(function (i) {
return i.id === id;
});
if (!decision || !integration || typeof integration.pageViewEventHandler !== 'function') {

@@ -534,3 +467,2 @@ // eslint-disable-next-line @typescript-eslint/no-empty-function

}
return integration.pageViewEventHandler;

@@ -537,0 +469,0 @@ }

@@ -9,2 +9,3 @@ import React, { Dispatch, SetStateAction } from 'react';

store: ConsentManagerStore;
children: React.ReactNode;
}

@@ -11,0 +12,0 @@ export declare const ConsentManager: React.FC<ConsentManagerProps>;

{
"name": "@consent-manager/core",
"version": "1.0.1",
"version": "2.0.0-next.0",
"description": "Get proper consent before tracking and processing data of your visitors via consent-manager. Supports you to get your website GDPR and CCPA compliant.",

@@ -54,4 +54,4 @@ "license": "MIT",

"peerDependencies": {
"react": "^16.8.0 || ^17.0.1",
"react-dom": "^16.8.0 || ^17.0.1"
"react": "^16.8.0 || ^17.0.1 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.1 || ^18.0.0"
},

@@ -58,0 +58,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc