@consent-manager/core
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -238,6 +238,7 @@ 'use strict'; | ||
var _excluded = ["integrationId", "fallbackUrl"]; | ||
var FallbackComponent = function FallbackComponent(_ref) { | ||
var integrationId = _ref.integrationId, | ||
fallbackUrl = _ref.fallbackUrl, | ||
props = _objectWithoutPropertiesLoose(_ref, ["integrationId", "fallbackUrl"]); | ||
props = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
@@ -377,5 +378,6 @@ var integration = useIntegration(integrationId); | ||
var _excluded$1 = ["formComponent"]; | ||
var ConsentManagerForm = function ConsentManagerForm(_ref) { | ||
var formComponent = _ref.formComponent, | ||
props = _objectWithoutPropertiesLoose(_ref, ["formComponent"]); | ||
props = _objectWithoutPropertiesLoose(_ref, _excluded$1); | ||
@@ -404,2 +406,3 @@ var _useEnabledIntegratio = useEnabledIntegrations(), | ||
var _excluded$2 = ["color"]; | ||
function getForegroundColor(bgHex) { | ||
@@ -412,3 +415,3 @@ return wcagContrast.hex(bgHex, '#000') >= 7 ? '#000' : '#fff'; | ||
color = _ref$color === void 0 ? 'currentColor' : _ref$color, | ||
props = _objectWithoutPropertiesLoose(_ref, ["color"]); | ||
props = _objectWithoutPropertiesLoose(_ref, _excluded$2); | ||
@@ -429,2 +432,3 @@ return React__default.createElement("svg", Object.assign({ | ||
var _excluded$3 = ["id", "children"]; | ||
var ConsentManager = function ConsentManager(_ref) { | ||
@@ -478,3 +482,3 @@ var children = _ref.children, | ||
children = _ref2.children, | ||
props = _objectWithoutPropertiesLoose(_ref2, ["id", "children"]); | ||
props = _objectWithoutPropertiesLoose(_ref2, _excluded$3); | ||
@@ -481,0 +485,0 @@ var _useDecision = useDecision(id), |
@@ -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=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.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"))};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 C(){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=C();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.useDecisions=m,exports.useEnabledIntegrations=v,exports.useFallbackComponent=C,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";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(){}}; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -231,6 +231,7 @@ import React, { useContext, createContext, useState, useEffect, useCallback, useMemo } from 'react'; | ||
var _excluded = ["integrationId", "fallbackUrl"]; | ||
var FallbackComponent = function FallbackComponent(_ref) { | ||
var integrationId = _ref.integrationId, | ||
fallbackUrl = _ref.fallbackUrl, | ||
props = _objectWithoutPropertiesLoose(_ref, ["integrationId", "fallbackUrl"]); | ||
props = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
@@ -370,5 +371,6 @@ var integration = useIntegration(integrationId); | ||
var _excluded$1 = ["formComponent"]; | ||
var ConsentManagerForm = function ConsentManagerForm(_ref) { | ||
var formComponent = _ref.formComponent, | ||
props = _objectWithoutPropertiesLoose(_ref, ["formComponent"]); | ||
props = _objectWithoutPropertiesLoose(_ref, _excluded$1); | ||
@@ -397,2 +399,3 @@ var _useEnabledIntegratio = useEnabledIntegrations(), | ||
var _excluded$2 = ["color"]; | ||
function getForegroundColor(bgHex) { | ||
@@ -405,3 +408,3 @@ return hex(bgHex, '#000') >= 7 ? '#000' : '#fff'; | ||
color = _ref$color === void 0 ? 'currentColor' : _ref$color, | ||
props = _objectWithoutPropertiesLoose(_ref, ["color"]); | ||
props = _objectWithoutPropertiesLoose(_ref, _excluded$2); | ||
@@ -422,2 +425,3 @@ return React.createElement("svg", Object.assign({ | ||
var _excluded$3 = ["id", "children"]; | ||
var ConsentManager = function ConsentManager(_ref) { | ||
@@ -471,3 +475,3 @@ var children = _ref.children, | ||
children = _ref2.children, | ||
props = _objectWithoutPropertiesLoose(_ref2, ["id", "children"]); | ||
props = _objectWithoutPropertiesLoose(_ref2, _excluded$3); | ||
@@ -474,0 +478,0 @@ var _useDecision = useDecision(id), |
@@ -15,2 +15,3 @@ import React, { Dispatch, SetStateAction } from 'react'; | ||
id: IntegrationId; | ||
children: React.ReactNode; | ||
} | ||
@@ -17,0 +18,0 @@ export declare const PrivacyShield: React.FC<PrivacyShieldProps>; |
{ | ||
"name": "@consent-manager/core", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"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
125852
1044