react-lgpd-consent 0.1.13 → 0.2.1
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/README.md +641 -0
- package/dist/{PreferencesModal-2V2W3262.js → PreferencesModal-4WHKT67T.js} +1 -1
- package/dist/{chunk-XIHO7M77.js → chunk-QCERRRSC.js} +253 -87
- package/dist/index.cjs +442 -116
- package/dist/index.d.cts +195 -14
- package/dist/index.d.ts +195 -14
- package/dist/index.js +150 -3
- package/package.json +105 -100
package/dist/index.js
CHANGED
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
ConsentProvider,
|
|
4
4
|
PreferencesModal,
|
|
5
5
|
defaultConsentTheme,
|
|
6
|
+
useAllCategories,
|
|
6
7
|
useConsent,
|
|
7
8
|
useConsentHydration,
|
|
8
|
-
useConsentTexts
|
|
9
|
-
|
|
9
|
+
useConsentTexts,
|
|
10
|
+
useCustomCategories
|
|
11
|
+
} from "./chunk-QCERRRSC.js";
|
|
10
12
|
|
|
11
13
|
// src/components/CookieBanner.tsx
|
|
12
14
|
import Button from "@mui/material/Button";
|
|
@@ -216,15 +218,160 @@ function loadScript(id, src, category = null, attrs = {}) {
|
|
|
216
218
|
checkConsent();
|
|
217
219
|
});
|
|
218
220
|
}
|
|
221
|
+
|
|
222
|
+
// src/utils/ConsentScriptLoader.tsx
|
|
223
|
+
import * as React from "react";
|
|
224
|
+
function ConsentScriptLoader({
|
|
225
|
+
integrations,
|
|
226
|
+
reloadOnChange = false
|
|
227
|
+
}) {
|
|
228
|
+
const { preferences, consented } = useConsent();
|
|
229
|
+
const loadedScripts = React.useRef(/* @__PURE__ */ new Set());
|
|
230
|
+
React.useEffect(() => {
|
|
231
|
+
if (!consented) return;
|
|
232
|
+
integrations.forEach(async (integration) => {
|
|
233
|
+
const shouldLoad = preferences[integration.category];
|
|
234
|
+
const alreadyLoaded = loadedScripts.current.has(integration.id);
|
|
235
|
+
if (shouldLoad && (!alreadyLoaded || reloadOnChange)) {
|
|
236
|
+
try {
|
|
237
|
+
await loadScript(
|
|
238
|
+
integration.id,
|
|
239
|
+
integration.src,
|
|
240
|
+
integration.category,
|
|
241
|
+
// Categoria dinâmica
|
|
242
|
+
integration.attrs
|
|
243
|
+
);
|
|
244
|
+
if (integration.init) {
|
|
245
|
+
integration.init();
|
|
246
|
+
}
|
|
247
|
+
loadedScripts.current.add(integration.id);
|
|
248
|
+
console.log(
|
|
249
|
+
`\u2705 Script loaded: ${integration.id} (${integration.category})`
|
|
250
|
+
);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error(`\u274C Failed to load script: ${integration.id}`, error);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}, [preferences, consented, integrations, reloadOnChange]);
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
function useConsentScriptLoader() {
|
|
260
|
+
const { preferences, consented } = useConsent();
|
|
261
|
+
return React.useCallback(
|
|
262
|
+
async (integration) => {
|
|
263
|
+
if (!consented) {
|
|
264
|
+
console.warn(
|
|
265
|
+
`\u26A0\uFE0F Cannot load script ${integration.id}: No consent given`
|
|
266
|
+
);
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const shouldLoad = preferences[integration.category];
|
|
270
|
+
if (!shouldLoad) {
|
|
271
|
+
console.warn(
|
|
272
|
+
`\u26A0\uFE0F Cannot load script ${integration.id}: Category '${integration.category}' not consented`
|
|
273
|
+
);
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
await loadScript(
|
|
278
|
+
integration.id,
|
|
279
|
+
integration.src,
|
|
280
|
+
integration.category,
|
|
281
|
+
// Categoria dinâmica
|
|
282
|
+
integration.attrs
|
|
283
|
+
);
|
|
284
|
+
if (integration.init) {
|
|
285
|
+
integration.init();
|
|
286
|
+
}
|
|
287
|
+
console.log(
|
|
288
|
+
`\u2705 Script loaded: ${integration.id} (${integration.category})`
|
|
289
|
+
);
|
|
290
|
+
return true;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
console.error(`\u274C Failed to load script: ${integration.id}`, error);
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
[preferences, consented]
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/utils/scriptIntegrations.ts
|
|
301
|
+
function createGoogleAnalyticsIntegration(config) {
|
|
302
|
+
return {
|
|
303
|
+
id: "google-analytics",
|
|
304
|
+
category: "analytics",
|
|
305
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${config.measurementId}`,
|
|
306
|
+
init: () => {
|
|
307
|
+
if (typeof window !== "undefined") {
|
|
308
|
+
let gtag2 = function(...args) {
|
|
309
|
+
window.dataLayer.push(arguments);
|
|
310
|
+
};
|
|
311
|
+
var gtag = gtag2;
|
|
312
|
+
window.dataLayer = window.dataLayer || [];
|
|
313
|
+
window.gtag = gtag2;
|
|
314
|
+
gtag2("js", /* @__PURE__ */ new Date());
|
|
315
|
+
gtag2("config", config.measurementId, config.config || {});
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
attrs: { async: "true" }
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function createGoogleTagManagerIntegration(config) {
|
|
322
|
+
return {
|
|
323
|
+
id: "google-tag-manager",
|
|
324
|
+
category: "analytics",
|
|
325
|
+
src: `https://www.googletagmanager.com/gtm.js?id=${config.containerId}`,
|
|
326
|
+
init: () => {
|
|
327
|
+
if (typeof window !== "undefined") {
|
|
328
|
+
const dataLayerName = config.dataLayerName || "dataLayer";
|
|
329
|
+
window[dataLayerName] = window[dataLayerName] || [];
|
|
330
|
+
window[dataLayerName].push({
|
|
331
|
+
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
332
|
+
event: "gtm.js"
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function createUserWayIntegration(config) {
|
|
339
|
+
return {
|
|
340
|
+
id: "userway",
|
|
341
|
+
category: "marketing",
|
|
342
|
+
// ou poderia ser uma categoria 'accessibility'
|
|
343
|
+
src: `https://cdn.userway.org/widget.js`,
|
|
344
|
+
init: () => {
|
|
345
|
+
if (typeof window !== "undefined") {
|
|
346
|
+
window.UserWayWidgetApp = window.UserWayWidgetApp || {};
|
|
347
|
+
window.UserWayWidgetApp.accountId = config.accountId;
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
attrs: { "data-account": config.accountId }
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
var COMMON_INTEGRATIONS = {
|
|
354
|
+
googleAnalytics: createGoogleAnalyticsIntegration,
|
|
355
|
+
googleTagManager: createGoogleTagManagerIntegration,
|
|
356
|
+
userway: createUserWayIntegration
|
|
357
|
+
};
|
|
219
358
|
export {
|
|
359
|
+
COMMON_INTEGRATIONS,
|
|
220
360
|
ConsentGate,
|
|
221
361
|
ConsentProvider,
|
|
362
|
+
ConsentScriptLoader,
|
|
222
363
|
CookieBanner,
|
|
223
364
|
FloatingPreferencesButton,
|
|
224
365
|
PreferencesModal,
|
|
366
|
+
createGoogleAnalyticsIntegration,
|
|
367
|
+
createGoogleTagManagerIntegration,
|
|
368
|
+
createUserWayIntegration,
|
|
225
369
|
defaultConsentTheme,
|
|
226
370
|
loadScript,
|
|
371
|
+
useAllCategories,
|
|
227
372
|
useConsent,
|
|
228
373
|
useConsentHydration,
|
|
229
|
-
|
|
374
|
+
useConsentScriptLoader,
|
|
375
|
+
useConsentTexts,
|
|
376
|
+
useCustomCategories
|
|
230
377
|
};
|
package/package.json
CHANGED
|
@@ -1,100 +1,105 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-lgpd-consent",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Biblioteca de consentimento
|
|
5
|
-
"keywords": [
|
|
6
|
-
"lgpd",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"@mui/icons-material":
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
"react
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "react-lgpd-consent",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Biblioteca completa de consentimento LGPD com 6 categorias ANPD, integrações nativas e sistema extensível para React.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lgpd",
|
|
7
|
+
"anpd",
|
|
8
|
+
"cookie",
|
|
9
|
+
"consent",
|
|
10
|
+
"react",
|
|
11
|
+
"client-side",
|
|
12
|
+
"spa",
|
|
13
|
+
"material-ui",
|
|
14
|
+
"mui",
|
|
15
|
+
"typescript",
|
|
16
|
+
"js-cookie",
|
|
17
|
+
"consentimento",
|
|
18
|
+
"privacidade",
|
|
19
|
+
"acessibilidade",
|
|
20
|
+
"google-analytics",
|
|
21
|
+
"tag-manager",
|
|
22
|
+
"userway",
|
|
23
|
+
"categorias-extensiveis"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Luciano Édipo",
|
|
30
|
+
"email": "luciano.psilva@anpd.gov.br",
|
|
31
|
+
"url": "https://github.com/lucianoedipo"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"type": "module",
|
|
35
|
+
"main": "dist/index.cjs",
|
|
36
|
+
"module": "dist/index.mjs",
|
|
37
|
+
"types": "dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.js",
|
|
42
|
+
"require": "./dist/index.cjs"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"README.md",
|
|
50
|
+
"LICENSE",
|
|
51
|
+
"COMPLIANCE.md"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18.18"
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "pnpm@9.0.0",
|
|
57
|
+
"scripts": {
|
|
58
|
+
"clean": "rimraf dist",
|
|
59
|
+
"build": "cross-env NODE_ENV=production tsup src/index.ts --format esm,cjs --dts --clean",
|
|
60
|
+
"dev": "cross-env NODE_ENV=development tsup src/index.ts --format esm,cjs --dts --watch",
|
|
61
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
62
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
63
|
+
"type-check": "tsc --noEmit",
|
|
64
|
+
"prepublishOnly": "npm run build"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/lucianoedipo/react-lgpd-consent.git"
|
|
69
|
+
},
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/lucianoedipo/react-lgpd-consent/issues"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://github.com/lucianoedipo/react-lgpd-consent#readme",
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@mui/material": "^7.0.0 || ^6.0.0 || ^5.15.0",
|
|
76
|
+
"@mui/icons-material": "^7.0.0 || ^6.0.0 || ^5.15.0",
|
|
77
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
78
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"@mui/icons-material": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"js-cookie": "^3.0.5"
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@types/js-cookie": "^3.0.6",
|
|
90
|
+
"@types/react": "^19.1.9",
|
|
91
|
+
"@types/react-dom": "^19.1.7",
|
|
92
|
+
"@mui/material": "^7.3.1",
|
|
93
|
+
"@mui/icons-material": "^7.3.1",
|
|
94
|
+
"react": "^19.1.1",
|
|
95
|
+
"react-dom": "^19.1.1",
|
|
96
|
+
"cross-env": "^10.0.0",
|
|
97
|
+
"eslint": "^9.33.0",
|
|
98
|
+
"eslint-config-prettier": "^10.1.8",
|
|
99
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
100
|
+
"prettier": "^3.6.2",
|
|
101
|
+
"rimraf": "^6.0.1",
|
|
102
|
+
"tsup": "^8.5.0",
|
|
103
|
+
"typescript": "^5.9.2"
|
|
104
|
+
}
|
|
105
|
+
}
|