@consent-manager/core
Advanced tools
Comparing version 0.0.1-next.7 to 0.0.1-next.8
# @consent-manager/core | ||
## 0.0.1-next.8 | ||
### Patch Changes | ||
- Allow multiple instances of WrapperComponents | ||
## 0.0.1-next.7 | ||
@@ -4,0 +10,0 @@ |
@@ -196,28 +196,9 @@ 'use strict'; | ||
function useWrapperComponents(config, decisions) { | ||
var Wrapper = React.useMemo(function () { | ||
return function (_ref) { | ||
var children = _ref.children; | ||
return config.integrations.filter(function (i) { | ||
return decisions[i.id] === true; | ||
}).filter(function (i) { | ||
return Boolean(i.WrapperComponent); | ||
}).reverse().reduce(function (children, _ref2) { | ||
var WrapperComponent = _ref2.WrapperComponent; | ||
return React__default.createElement(WrapperComponent, null, children); | ||
}, children); | ||
}; | ||
}, [config.integrations, decisions]); | ||
return Wrapper; | ||
} | ||
var IntegrationWrapperComponents = function IntegrationWrapperComponents(_ref) { | ||
var config = _ref.config, | ||
children = _ref.children; | ||
var IntegrationWrapperComponents = function IntegrationWrapperComponents(_ref3) { | ||
var config = _ref3.config, | ||
children = _ref3.children; | ||
var _useDecisions = useDecisions(), | ||
decisions = _useDecisions[0]; | ||
var Wrapper = useWrapperComponents(config, decisions); // Check if component was mounted for SSR | ||
var _useState = React.useState(false), | ||
@@ -230,3 +211,20 @@ isMounted = _useState[0], | ||
}, [setIsMounted]); | ||
return React__default.createElement(React__default.Fragment, null, children, isMounted && React__default.createElement(Wrapper, null, null)); | ||
var wrapperComponents = React.useMemo(function () { | ||
if (!isMounted) { | ||
return null; | ||
} | ||
return config.integrations.filter(function (i) { | ||
return decisions[i.id] === true; | ||
}).filter(function (i) { | ||
return Boolean(i.WrapperComponent); | ||
}).map(function (_ref2) { | ||
var WrapperComponent = _ref2.WrapperComponent, | ||
id = _ref2.id; | ||
return React__default.createElement(WrapperComponent, { | ||
key: id | ||
}); | ||
}); | ||
}, [config, decisions, isMounted]); | ||
return React__default.createElement(React__default.Fragment, null, children, wrapperComponents); | ||
}; | ||
@@ -233,0 +231,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),r=e(require("react-use/esm/useSet")),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=d().decisions,t=n.useState(e),r=t[0],o=t[1],a=f()[1];n.useEffect((function(){r!==e&&o((function(){return e}))}),[e,r,o,a]);var u=n.useCallback((function(e){var n="function"==typeof e?e(r):e;a((function(e){return i({},e,{decisions:n})}))}),[r,a]);return[r,u]}var p=function(e){var r,o,i=e.children,a=(r=e.config,o=m()[0],n.useMemo((function(){return function(e){var n=e.children;return r.integrations.filter((function(e){return!0===o[e.id]})).filter((function(e){return Boolean(e.WrapperComponent)})).reverse().reduce((function(e,n){return t.createElement(n.WrapperComponent,null,e)}),n)}}),[r.integrations,o])),u=n.useState(!1),l=u[0],c=u[1];return n.useEffect((function(){return c(!0)}),[c]),t.createElement(t.Fragment,null,i,l&&t.createElement(a,null,null))},g=function(e){var r=e.integrationId,o=e.fallbackUrl,i=a(e,["integrationId","fallbackUrl"]),u=b(r),l=h(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 v(){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 b(e){return s().find((function(n){return n.id===e}))}var y=function(e){var o=e.integrations,i=e.onSubmit,a=r(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"))};function h(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 E(){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?g:r,config:n,store:e.store}},t.createElement(p,{config:n},e.children))},exports.ConsentManagerForm=function(e){var r=e.formComponent,o=a(e,["formComponent"]),i=v(),u=i[0],l=i[1],f=n.useContext(c).config.integrations,s=r||y,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,["id","children"]),i=h(n)[0],u=E();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,["color"]);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=h,exports.useEnabledIntegrations=v,exports.useFallbackComponent=E,exports.useIntegration=b,exports.useIntegrations=s,exports.usePageViewEventTrigger=function(e){var t=h(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";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),r=e(require("react-use/esm/useSet")),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=d().decisions,t=n.useState(e),r=t[0],o=t[1],a=f()[1];n.useEffect((function(){r!==e&&o((function(){return e}))}),[e,r,o,a]);var u=n.useCallback((function(e){var n="function"==typeof e?e(r):e;a((function(e){return i({},e,{decisions:n})}))}),[r,a]);return[r,u]}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=function(e){var r=e.integrationId,o=e.fallbackUrl,i=a(e,["integrationId","fallbackUrl"]),u=b(r),l=h(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 v(){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 b(e){return s().find((function(n){return n.id===e}))}var y=function(e){var o=e.integrations,i=e.onSubmit,a=r(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"))};function h(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 E(){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?g:r,config:n,store:e.store}},t.createElement(p,{config:n},e.children))},exports.ConsentManagerForm=function(e){var r=e.formComponent,o=a(e,["formComponent"]),i=v(),u=i[0],l=i[1],f=n.useContext(c).config.integrations,s=r||y,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,["id","children"]),i=h(n)[0],u=E();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,["color"]);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=h,exports.useEnabledIntegrations=v,exports.useFallbackComponent=E,exports.useIntegration=b,exports.useIntegrations=s,exports.usePageViewEventTrigger=function(e){var t=h(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 |
@@ -189,28 +189,9 @@ import React, { useContext, createContext, useState, useEffect, useCallback, useMemo } from 'react'; | ||
function useWrapperComponents(config, decisions) { | ||
var Wrapper = useMemo(function () { | ||
return function (_ref) { | ||
var children = _ref.children; | ||
return config.integrations.filter(function (i) { | ||
return decisions[i.id] === true; | ||
}).filter(function (i) { | ||
return Boolean(i.WrapperComponent); | ||
}).reverse().reduce(function (children, _ref2) { | ||
var WrapperComponent = _ref2.WrapperComponent; | ||
return React.createElement(WrapperComponent, null, children); | ||
}, children); | ||
}; | ||
}, [config.integrations, decisions]); | ||
return Wrapper; | ||
} | ||
var IntegrationWrapperComponents = function IntegrationWrapperComponents(_ref) { | ||
var config = _ref.config, | ||
children = _ref.children; | ||
var IntegrationWrapperComponents = function IntegrationWrapperComponents(_ref3) { | ||
var config = _ref3.config, | ||
children = _ref3.children; | ||
var _useDecisions = useDecisions(), | ||
decisions = _useDecisions[0]; | ||
var Wrapper = useWrapperComponents(config, decisions); // Check if component was mounted for SSR | ||
var _useState = useState(false), | ||
@@ -223,3 +204,20 @@ isMounted = _useState[0], | ||
}, [setIsMounted]); | ||
return React.createElement(React.Fragment, null, children, isMounted && React.createElement(Wrapper, null, null)); | ||
var wrapperComponents = useMemo(function () { | ||
if (!isMounted) { | ||
return null; | ||
} | ||
return config.integrations.filter(function (i) { | ||
return decisions[i.id] === true; | ||
}).filter(function (i) { | ||
return Boolean(i.WrapperComponent); | ||
}).map(function (_ref2) { | ||
var WrapperComponent = _ref2.WrapperComponent, | ||
id = _ref2.id; | ||
return React.createElement(WrapperComponent, { | ||
key: id | ||
}); | ||
}); | ||
}, [config, decisions, isMounted]); | ||
return React.createElement(React.Fragment, null, children, wrapperComponents); | ||
}; | ||
@@ -226,0 +224,0 @@ |
{ | ||
"name": "@consent-manager/core", | ||
"version": "0.0.1-next.7", | ||
"version": "0.0.1-next.8", | ||
"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.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122428
22
1020