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/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
- } from "./chunk-XIHO7M77.js";
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
- useConsentTexts
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.13",
4
- "description": "Biblioteca de consentimento de cookies (LGPD) para React client-side, com contexto, banner e modal personalizáveis usando MUI.",
5
- "keywords": [
6
- "lgpd",
7
- "cookie",
8
- "consent",
9
- "react",
10
- "client-side",
11
- "spa",
12
- "material-ui",
13
- "mui",
14
- "typescript",
15
- "js-cookie",
16
- "consentimento",
17
- "privacidade",
18
- "acessibilidade"
19
- ],
20
- "publishConfig": {
21
- "access": "public"
22
- },
23
- "author": {
24
- "name": "Luciano Édipo",
25
- "email": "luciano.psilva@anpd.gov.br",
26
- "url": "https://github.com/lucianoedipo"
27
- },
28
- "license": "MIT",
29
- "type": "module",
30
- "main": "dist/index.cjs",
31
- "module": "dist/index.mjs",
32
- "types": "dist/index.d.ts",
33
- "exports": {
34
- ".": {
35
- "types": "./dist/index.d.ts",
36
- "import": "./dist/index.js",
37
- "require": "./dist/index.cjs"
38
- },
39
- "./package.json": "./package.json"
40
- },
41
- "sideEffects": false,
42
- "files": [
43
- "dist",
44
- "README.md",
45
- "LICENSE",
46
- "COMPLIANCE.md"
47
- ],
48
- "engines": {
49
- "node": ">=18.18"
50
- },
51
- "packageManager": "pnpm@9.0.0",
52
- "scripts": {
53
- "clean": "rimraf dist",
54
- "build": "cross-env NODE_ENV=production tsup src/index.ts --format esm,cjs --dts --clean",
55
- "dev": "cross-env NODE_ENV=development tsup src/index.ts --format esm,cjs --dts --watch",
56
- "lint": "eslint . --ext .ts,.tsx",
57
- "format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
58
- "type-check": "tsc --noEmit",
59
- "prepublishOnly": "npm run build"
60
- },
61
- "repository": {
62
- "type": "git",
63
- "url": "git+https://github.com/lucianoedipo/react-lgpd-consent.git"
64
- },
65
- "bugs": {
66
- "url": "https://github.com/lucianoedipo/react-lgpd-consent/issues"
67
- },
68
- "homepage": "https://github.com/lucianoedipo/react-lgpd-consent#readme",
69
- "peerDependencies": {
70
- "@mui/material": "^7.0.0 || ^6.0.0 || ^5.15.0",
71
- "@mui/icons-material": "^7.0.0 || ^6.0.0 || ^5.15.0",
72
- "react": "^18.2.0 || ^19.0.0",
73
- "react-dom": "^18.2.0 || ^19.0.0"
74
- },
75
- "peerDependenciesMeta": {
76
- "@mui/icons-material": {
77
- "optional": true
78
- }
79
- },
80
- "dependencies": {
81
- "js-cookie": "^3.0.5"
82
- },
83
- "devDependencies": {
84
- "@types/js-cookie": "^3.0.6",
85
- "@types/react": "^19.1.9",
86
- "@types/react-dom": "^19.1.7",
87
- "@mui/material": "^7.3.1",
88
- "@mui/icons-material": "^7.3.1",
89
- "react": "^19.1.1",
90
- "react-dom": "^19.1.1",
91
- "cross-env": "^10.0.0",
92
- "eslint": "^9.33.0",
93
- "eslint-config-prettier": "^10.1.8",
94
- "eslint-plugin-react-hooks": "^5.2.0",
95
- "prettier": "^3.6.2",
96
- "rimraf": "^6.0.1",
97
- "tsup": "^8.5.0",
98
- "typescript": "^5.9.2"
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
+ }