react-lgpd-consent 0.2.1 → 0.2.3
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/COMPLIANCE.md +231 -87
- package/README.md +118 -20
- package/dist/{PreferencesModal-4WHKT67T.js → PreferencesModal-UMNANMVX.js} +1 -1
- package/dist/{chunk-QCERRRSC.js → chunk-E763JXNL.js} +307 -121
- package/dist/index.cjs +315 -116
- package/dist/index.d.cts +236 -24
- package/dist/index.d.ts +236 -24
- package/dist/index.js +9 -3
- package/package.json +1 -1
|
@@ -8,10 +8,238 @@ import FormControlLabel from "@mui/material/FormControlLabel";
|
|
|
8
8
|
import FormGroup from "@mui/material/FormGroup";
|
|
9
9
|
import Switch from "@mui/material/Switch";
|
|
10
10
|
import Typography2 from "@mui/material/Typography";
|
|
11
|
-
import { useEffect as
|
|
11
|
+
import { useEffect as useEffect4, useState as useState2 } from "react";
|
|
12
12
|
|
|
13
|
-
// src/context/
|
|
13
|
+
// src/context/CategoriesContext.tsx
|
|
14
14
|
import * as React2 from "react";
|
|
15
|
+
|
|
16
|
+
// src/utils/developerGuidance.ts
|
|
17
|
+
import * as React from "react";
|
|
18
|
+
var DEFAULT_PROJECT_CATEGORIES = {
|
|
19
|
+
enabledCategories: ["analytics"],
|
|
20
|
+
// Só analytics além de necessary
|
|
21
|
+
customCategories: []
|
|
22
|
+
};
|
|
23
|
+
function analyzeDeveloperConfiguration(config) {
|
|
24
|
+
const guidance = {
|
|
25
|
+
warnings: [],
|
|
26
|
+
suggestions: [],
|
|
27
|
+
activeCategoriesInfo: [],
|
|
28
|
+
usingDefaults: !config
|
|
29
|
+
};
|
|
30
|
+
const finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
31
|
+
if (!config) {
|
|
32
|
+
guidance.warnings.push(
|
|
33
|
+
'LGPD-CONSENT: Nenhuma configura\xE7\xE3o de categorias especificada. Usando padr\xE3o: necessary + analytics. Para produ\xE7\xE3o, recomenda-se especificar explicitamente as categorias via prop "categories".'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
guidance.activeCategoriesInfo.push({
|
|
37
|
+
id: "necessary",
|
|
38
|
+
name: "Cookies Necess\xE1rios",
|
|
39
|
+
description: "Essenciais para funcionamento b\xE1sico do site",
|
|
40
|
+
essential: true,
|
|
41
|
+
uiRequired: false
|
|
42
|
+
// Não precisa de toggle (sempre ativo)
|
|
43
|
+
});
|
|
44
|
+
const enabledCategories = finalConfig.enabledCategories || [];
|
|
45
|
+
const categoryNames = {
|
|
46
|
+
analytics: {
|
|
47
|
+
name: "Cookies Anal\xEDticos",
|
|
48
|
+
description: "Medem uso e performance do site"
|
|
49
|
+
},
|
|
50
|
+
functional: {
|
|
51
|
+
name: "Cookies Funcionais",
|
|
52
|
+
description: "Melhoram experi\xEAncia e funcionalidades"
|
|
53
|
+
},
|
|
54
|
+
marketing: {
|
|
55
|
+
name: "Cookies de Marketing",
|
|
56
|
+
description: "Publicidade direcionada e campanhas"
|
|
57
|
+
},
|
|
58
|
+
social: {
|
|
59
|
+
name: "Cookies de Redes Sociais",
|
|
60
|
+
description: "Integra\xE7\xE3o com plataformas sociais"
|
|
61
|
+
},
|
|
62
|
+
personalization: {
|
|
63
|
+
name: "Cookies de Personaliza\xE7\xE3o",
|
|
64
|
+
description: "Adaptam conte\xFAdo \xE0s prefer\xEAncias do usu\xE1rio"
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
enabledCategories.forEach((categoryId) => {
|
|
68
|
+
const categoryInfo = categoryNames[categoryId];
|
|
69
|
+
if (categoryInfo) {
|
|
70
|
+
guidance.activeCategoriesInfo.push({
|
|
71
|
+
id: categoryId,
|
|
72
|
+
name: categoryInfo.name,
|
|
73
|
+
description: categoryInfo.description,
|
|
74
|
+
essential: false,
|
|
75
|
+
uiRequired: true
|
|
76
|
+
// Precisa de toggle na UI
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const customCategories = finalConfig.customCategories || [];
|
|
81
|
+
customCategories.forEach((category) => {
|
|
82
|
+
guidance.activeCategoriesInfo.push({
|
|
83
|
+
id: category.id,
|
|
84
|
+
name: category.name,
|
|
85
|
+
description: category.description,
|
|
86
|
+
essential: category.essential === true,
|
|
87
|
+
uiRequired: category.essential !== true
|
|
88
|
+
// Apenas não-essenciais precisam toggle
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
const totalToggleable = guidance.activeCategoriesInfo.filter(
|
|
92
|
+
(c) => c.uiRequired
|
|
93
|
+
).length;
|
|
94
|
+
if (totalToggleable === 0) {
|
|
95
|
+
guidance.suggestions.push(
|
|
96
|
+
'Apenas cookies necess\xE1rios est\xE3o configurados. Para compliance completo LGPD, considere adicionar categorias como "analytics" ou "functional" conforme uso real.'
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (totalToggleable > 5) {
|
|
100
|
+
guidance.warnings.push(
|
|
101
|
+
`${totalToggleable} categorias opcionais detectadas. UI com muitas op\xE7\xF5es pode ' +
|
|
102
|
+
'prejudicar experi\xEAncia do usu\xE1rio. Considere agrupar categorias similares.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const poorDescriptions = customCategories.filter(
|
|
106
|
+
(c) => !c.description || c.description.length < 10
|
|
107
|
+
);
|
|
108
|
+
if (poorDescriptions.length > 0) {
|
|
109
|
+
guidance.warnings.push(
|
|
110
|
+
`Categorias customizadas com descri\xE7\xF5es inadequadas: ${poorDescriptions.map((c) => c.id).join(", ")}. Descri\xE7\xF5es claras s\xE3o obrigat\xF3rias para compliance LGPD.`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return guidance;
|
|
114
|
+
}
|
|
115
|
+
function logDeveloperGuidance(guidance) {
|
|
116
|
+
try {
|
|
117
|
+
const isProduction = (
|
|
118
|
+
// 1. NODE_ENV de bundlers (Vite, webpack, etc.)
|
|
119
|
+
typeof globalThis.process !== "undefined" && globalThis.process.env?.NODE_ENV === "production" || // 2. Vite/bundler env vars (apenas em ESM)
|
|
120
|
+
typeof globalThis !== "undefined" && typeof globalThis.import !== "undefined" && globalThis.import.meta?.env?.PROD === true || // 3. Flag customizada para desabilitar logs
|
|
121
|
+
typeof globalThis !== "undefined" && globalThis.__LGPD_PRODUCTION__ || // 4. Flag de desenvolvimento desabilitada
|
|
122
|
+
typeof window !== "undefined" && window.__LGPD_DISABLE_GUIDANCE__
|
|
123
|
+
);
|
|
124
|
+
if (isProduction) return;
|
|
125
|
+
const PREFIX = "[\u{1F36A} LGPD-CONSENT]";
|
|
126
|
+
if (guidance.warnings.length > 0) {
|
|
127
|
+
console.group(`${PREFIX} \u26A0\uFE0F Avisos de Configura\xE7\xE3o`);
|
|
128
|
+
guidance.warnings.forEach(
|
|
129
|
+
(warning) => console.warn(`${PREFIX} ${warning}`)
|
|
130
|
+
);
|
|
131
|
+
console.groupEnd();
|
|
132
|
+
}
|
|
133
|
+
if (guidance.suggestions.length > 0) {
|
|
134
|
+
console.group(`${PREFIX} \u{1F4A1} Sugest\xF5es`);
|
|
135
|
+
guidance.suggestions.forEach(
|
|
136
|
+
(suggestion) => console.info(`${PREFIX} ${suggestion}`)
|
|
137
|
+
);
|
|
138
|
+
console.groupEnd();
|
|
139
|
+
}
|
|
140
|
+
if (guidance.usingDefaults) {
|
|
141
|
+
console.info(
|
|
142
|
+
`${PREFIX} \u{1F4CB} Usando configura\xE7\xE3o padr\xE3o. Para personalizar, use a prop "categories" no ConsentProvider.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
console.group(`${PREFIX} \u{1F527} Categorias Ativas (para UI customizada)`);
|
|
146
|
+
console.table(
|
|
147
|
+
guidance.activeCategoriesInfo.map((cat) => ({
|
|
148
|
+
ID: cat.id,
|
|
149
|
+
Nome: cat.name,
|
|
150
|
+
"Toggle UI?": cat.uiRequired ? "\u2705 SIM" : "\u274C N\xC3O (sempre ativo)",
|
|
151
|
+
"Essencial?": cat.essential ? "\u{1F512} SIM" : "\u2699\uFE0F N\xC3O"
|
|
152
|
+
}))
|
|
153
|
+
);
|
|
154
|
+
console.info(
|
|
155
|
+
`${PREFIX} \u2139\uFE0F Use estes dados para criar componentes customizados adequados.`
|
|
156
|
+
);
|
|
157
|
+
console.groupEnd();
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
160
|
+
console.warn(
|
|
161
|
+
"[\u{1F36A} LGPD-CONSENT] Sistema de orienta\xE7\xF5es encontrou erro:",
|
|
162
|
+
error
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function useDeveloperGuidance(config) {
|
|
168
|
+
const guidance = analyzeDeveloperConfiguration(config);
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
logDeveloperGuidance(guidance);
|
|
171
|
+
}, [JSON.stringify(config)]);
|
|
172
|
+
return guidance;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/context/CategoriesContext.tsx
|
|
176
|
+
import { jsx } from "react/jsx-runtime";
|
|
177
|
+
var CategoriesContext = React2.createContext(
|
|
178
|
+
null
|
|
179
|
+
);
|
|
180
|
+
var CategoriesCtx = React2.createContext([]);
|
|
181
|
+
function CategoriesProvider({
|
|
182
|
+
children,
|
|
183
|
+
categories,
|
|
184
|
+
// LEGACY: prop antiga (apenas customCategories)
|
|
185
|
+
config
|
|
186
|
+
// NOVO: configuração completa
|
|
187
|
+
}) {
|
|
188
|
+
const contextValue = React2.useMemo(() => {
|
|
189
|
+
let finalConfig;
|
|
190
|
+
if (categories && !config) {
|
|
191
|
+
finalConfig = {
|
|
192
|
+
enabledCategories: DEFAULT_PROJECT_CATEGORIES.enabledCategories,
|
|
193
|
+
customCategories: categories
|
|
194
|
+
};
|
|
195
|
+
} else {
|
|
196
|
+
finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
197
|
+
}
|
|
198
|
+
const guidance = analyzeDeveloperConfiguration(
|
|
199
|
+
config || (categories ? { customCategories: categories } : void 0)
|
|
200
|
+
);
|
|
201
|
+
const toggleableCategories = guidance.activeCategoriesInfo.filter(
|
|
202
|
+
(cat) => cat.uiRequired
|
|
203
|
+
);
|
|
204
|
+
return {
|
|
205
|
+
config: finalConfig,
|
|
206
|
+
guidance,
|
|
207
|
+
toggleableCategories,
|
|
208
|
+
allCategories: guidance.activeCategoriesInfo,
|
|
209
|
+
legacyCategories: categories || []
|
|
210
|
+
};
|
|
211
|
+
}, [config, categories]);
|
|
212
|
+
React2.useEffect(() => {
|
|
213
|
+
logDeveloperGuidance(contextValue.guidance);
|
|
214
|
+
}, [contextValue.guidance]);
|
|
215
|
+
return /* @__PURE__ */ jsx(CategoriesContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(CategoriesCtx.Provider, { value: contextValue.legacyCategories, children }) });
|
|
216
|
+
}
|
|
217
|
+
function useCategories() {
|
|
218
|
+
const context = React2.useContext(CategoriesContext);
|
|
219
|
+
if (!context) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
"useCategories deve ser usado dentro de CategoriesProvider. Certifique-se de que o ConsentProvider est\xE1 envolvendo seu componente."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
return context;
|
|
225
|
+
}
|
|
226
|
+
function useCategoryStatus(categoryId) {
|
|
227
|
+
const { allCategories } = useCategories();
|
|
228
|
+
const category = allCategories.find((cat) => cat.id === categoryId);
|
|
229
|
+
return {
|
|
230
|
+
isActive: !!category,
|
|
231
|
+
isEssential: category?.essential || false,
|
|
232
|
+
needsToggle: category?.uiRequired || false,
|
|
233
|
+
name: category?.name,
|
|
234
|
+
description: category?.description
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function useCustomCategories() {
|
|
238
|
+
return React2.useContext(CategoriesCtx);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/context/ConsentContext.tsx
|
|
242
|
+
import * as React3 from "react";
|
|
15
243
|
import { ThemeProvider } from "@mui/material/styles";
|
|
16
244
|
|
|
17
245
|
// src/utils/cookieUtils.ts
|
|
@@ -158,75 +386,10 @@ var defaultConsentTheme = createTheme({
|
|
|
158
386
|
}
|
|
159
387
|
});
|
|
160
388
|
|
|
161
|
-
// src/context/CategoriesContext.tsx
|
|
162
|
-
import * as React from "react";
|
|
163
|
-
import { jsx } from "react/jsx-runtime";
|
|
164
|
-
var CategoriesCtx = React.createContext([]);
|
|
165
|
-
function CategoriesProvider({
|
|
166
|
-
categories,
|
|
167
|
-
children
|
|
168
|
-
}) {
|
|
169
|
-
const value = React.useMemo(() => categories || [], [categories]);
|
|
170
|
-
return /* @__PURE__ */ jsx(CategoriesCtx.Provider, { value, children });
|
|
171
|
-
}
|
|
172
|
-
function useCustomCategories() {
|
|
173
|
-
return React.useContext(CategoriesCtx);
|
|
174
|
-
}
|
|
175
|
-
function useAllCategories() {
|
|
176
|
-
const customCategories = useCustomCategories();
|
|
177
|
-
return React.useMemo(() => {
|
|
178
|
-
const defaultCategories = [
|
|
179
|
-
{
|
|
180
|
-
id: "necessary",
|
|
181
|
-
name: "Cookies Necess\xE1rios",
|
|
182
|
-
description: "Essenciais para o funcionamento b\xE1sico do site. Incluem cookies de sess\xE3o, autentica\xE7\xE3o e seguran\xE7a.",
|
|
183
|
-
essential: true,
|
|
184
|
-
cookies: ["PHPSESSID", "JSESSIONID", "cookieConsent", "csrf_token"]
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
id: "analytics",
|
|
188
|
-
name: "Analytics e Estat\xEDsticas",
|
|
189
|
-
description: "Permitem medir audi\xEAncia e desempenho, gerando estat\xEDsticas an\xF4nimas de uso.",
|
|
190
|
-
essential: false,
|
|
191
|
-
cookies: ["_ga", "_ga_*", "_gid", "_gat", "gtag"]
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
id: "functional",
|
|
195
|
-
name: "Cookies Funcionais",
|
|
196
|
-
description: "Melhoram a experi\xEAncia do usu\xE1rio, lembrando prefer\xEAncias e configura\xE7\xF5es.",
|
|
197
|
-
essential: false,
|
|
198
|
-
cookies: ["language", "theme", "timezone", "preferences"]
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
id: "marketing",
|
|
202
|
-
name: "Marketing e Publicidade",
|
|
203
|
-
description: "Utilizados para publicidade direcionada e medi\xE7\xE3o de campanhas publicit\xE1rias.",
|
|
204
|
-
essential: false,
|
|
205
|
-
cookies: ["_fbp", "fr", "tr", "ads_*", "doubleclick"]
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
id: "social",
|
|
209
|
-
name: "Redes Sociais",
|
|
210
|
-
description: "Permitem compartilhamento e integra\xE7\xE3o com redes sociais como Facebook, YouTube, etc.",
|
|
211
|
-
essential: false,
|
|
212
|
-
cookies: ["__Secure-*", "sb", "datr", "c_user", "social_*"]
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
id: "personalization",
|
|
216
|
-
name: "Personaliza\xE7\xE3o",
|
|
217
|
-
description: "Adaptam o conte\xFAdo e interface \xE0s prefer\xEAncias individuais do usu\xE1rio.",
|
|
218
|
-
essential: false,
|
|
219
|
-
cookies: ["personalization_*", "content_*", "layout_*"]
|
|
220
|
-
}
|
|
221
|
-
];
|
|
222
|
-
return [...defaultCategories, ...customCategories];
|
|
223
|
-
}, [customCategories]);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
389
|
// src/context/ConsentContext.tsx
|
|
227
390
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
228
|
-
var PreferencesModal =
|
|
229
|
-
() => import("./PreferencesModal-
|
|
391
|
+
var PreferencesModal = React3.lazy(
|
|
392
|
+
() => import("./PreferencesModal-UMNANMVX.js").then((m) => ({
|
|
230
393
|
default: m.PreferencesModal
|
|
231
394
|
}))
|
|
232
395
|
);
|
|
@@ -346,15 +509,18 @@ function reducer(state, action) {
|
|
|
346
509
|
return state;
|
|
347
510
|
}
|
|
348
511
|
}
|
|
349
|
-
var StateCtx =
|
|
350
|
-
var ActionsCtx =
|
|
351
|
-
var TextsCtx =
|
|
352
|
-
var HydrationCtx =
|
|
512
|
+
var StateCtx = React3.createContext(null);
|
|
513
|
+
var ActionsCtx = React3.createContext(null);
|
|
514
|
+
var TextsCtx = React3.createContext(DEFAULT_TEXTS);
|
|
515
|
+
var HydrationCtx = React3.createContext(false);
|
|
353
516
|
function ConsentProvider({
|
|
354
517
|
initialState,
|
|
518
|
+
categories,
|
|
519
|
+
// NOVO: configuração completa de categorias
|
|
355
520
|
texts: textsProp,
|
|
356
521
|
theme,
|
|
357
522
|
customCategories,
|
|
523
|
+
// LEGACY: compatibilidade
|
|
358
524
|
scriptIntegrations,
|
|
359
525
|
PreferencesModalComponent,
|
|
360
526
|
preferencesModalProps = {},
|
|
@@ -365,19 +531,31 @@ function ConsentProvider({
|
|
|
365
531
|
cookie: cookieOpts,
|
|
366
532
|
children
|
|
367
533
|
}) {
|
|
368
|
-
const texts =
|
|
534
|
+
const texts = React3.useMemo(
|
|
369
535
|
() => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }),
|
|
370
536
|
[textsProp]
|
|
371
537
|
);
|
|
372
|
-
const cookie =
|
|
538
|
+
const cookie = React3.useMemo(
|
|
373
539
|
() => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
|
|
374
540
|
[cookieOpts]
|
|
375
541
|
);
|
|
376
|
-
const appliedTheme =
|
|
542
|
+
const appliedTheme = React3.useMemo(
|
|
377
543
|
() => theme || defaultConsentTheme,
|
|
378
544
|
[theme]
|
|
379
545
|
);
|
|
380
|
-
const
|
|
546
|
+
const finalCategoriesConfig = React3.useMemo(() => {
|
|
547
|
+
if (categories) return categories;
|
|
548
|
+
if (customCategories) {
|
|
549
|
+
return {
|
|
550
|
+
enabledCategories: ["analytics"],
|
|
551
|
+
// padrão quando usando API antiga
|
|
552
|
+
customCategories
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
return void 0;
|
|
556
|
+
}, [categories, customCategories]);
|
|
557
|
+
useDeveloperGuidance(finalCategoriesConfig);
|
|
558
|
+
const boot = React3.useMemo(() => {
|
|
381
559
|
if (initialState) return { ...initialState, isModalOpen: false };
|
|
382
560
|
return createFullConsentState(
|
|
383
561
|
false,
|
|
@@ -386,9 +564,9 @@ function ConsentProvider({
|
|
|
386
564
|
false
|
|
387
565
|
);
|
|
388
566
|
}, [initialState, customCategories]);
|
|
389
|
-
const [state, dispatch] =
|
|
390
|
-
const [isHydrated, setIsHydrated] =
|
|
391
|
-
|
|
567
|
+
const [state, dispatch] = React3.useReducer(reducer, boot);
|
|
568
|
+
const [isHydrated, setIsHydrated] = React3.useState(false);
|
|
569
|
+
React3.useEffect(() => {
|
|
392
570
|
if (!initialState) {
|
|
393
571
|
const saved = readConsentCookie(cookie.name);
|
|
394
572
|
if (saved?.consented) {
|
|
@@ -398,24 +576,24 @@ function ConsentProvider({
|
|
|
398
576
|
}
|
|
399
577
|
setIsHydrated(true);
|
|
400
578
|
}, [cookie.name, initialState]);
|
|
401
|
-
|
|
579
|
+
React3.useEffect(() => {
|
|
402
580
|
if (state.consented) writeConsentCookie(state, state.source, cookie);
|
|
403
581
|
}, [state, cookie]);
|
|
404
|
-
const prevConsented =
|
|
405
|
-
|
|
582
|
+
const prevConsented = React3.useRef(state.consented);
|
|
583
|
+
React3.useEffect(() => {
|
|
406
584
|
if (!prevConsented.current && state.consented && onConsentGiven) {
|
|
407
585
|
setTimeout(() => onConsentGiven(state), 150);
|
|
408
586
|
}
|
|
409
587
|
prevConsented.current = state.consented;
|
|
410
588
|
}, [state, onConsentGiven]);
|
|
411
|
-
const prevPrefs =
|
|
412
|
-
|
|
589
|
+
const prevPrefs = React3.useRef(state.preferences);
|
|
590
|
+
React3.useEffect(() => {
|
|
413
591
|
if (state.consented && onPreferencesSaved && prevPrefs.current !== state.preferences) {
|
|
414
592
|
setTimeout(() => onPreferencesSaved(state.preferences), 150);
|
|
415
593
|
prevPrefs.current = state.preferences;
|
|
416
594
|
}
|
|
417
595
|
}, [state, onPreferencesSaved]);
|
|
418
|
-
const api =
|
|
596
|
+
const api = React3.useMemo(() => {
|
|
419
597
|
const acceptAll = () => dispatch({ type: "ACCEPT_ALL", customCategories });
|
|
420
598
|
const rejectAll = () => dispatch({ type: "REJECT_ALL", customCategories });
|
|
421
599
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
@@ -439,29 +617,36 @@ function ConsentProvider({
|
|
|
439
617
|
resetConsent
|
|
440
618
|
};
|
|
441
619
|
}, [state, cookie, customCategories]);
|
|
442
|
-
return /* @__PURE__ */ jsx2(ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ jsx2(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx2(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ jsx2(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ jsx2(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ jsxs(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
620
|
+
return /* @__PURE__ */ jsx2(ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ jsx2(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx2(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ jsx2(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ jsx2(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ jsxs(
|
|
621
|
+
CategoriesProvider,
|
|
622
|
+
{
|
|
623
|
+
config: finalCategoriesConfig,
|
|
624
|
+
categories: customCategories,
|
|
625
|
+
children: [
|
|
626
|
+
children,
|
|
627
|
+
!disableAutomaticModal && /* @__PURE__ */ jsx2(React3.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ jsx2(PreferencesModalComponent, { ...preferencesModalProps }) : /* @__PURE__ */ jsx2(PreferencesModal, { hideBranding }) })
|
|
628
|
+
]
|
|
629
|
+
}
|
|
630
|
+
) }) }) }) }) });
|
|
446
631
|
}
|
|
447
632
|
function useConsentStateInternal() {
|
|
448
|
-
const ctx =
|
|
633
|
+
const ctx = React3.useContext(StateCtx);
|
|
449
634
|
if (!ctx)
|
|
450
635
|
throw new Error("useConsentState must be used within ConsentProvider");
|
|
451
636
|
return ctx;
|
|
452
637
|
}
|
|
453
638
|
function useConsentActionsInternal() {
|
|
454
|
-
const ctx =
|
|
639
|
+
const ctx = React3.useContext(ActionsCtx);
|
|
455
640
|
if (!ctx)
|
|
456
641
|
throw new Error("useConsentActions must be used within ConsentProvider");
|
|
457
642
|
return ctx;
|
|
458
643
|
}
|
|
459
644
|
function useConsentTextsInternal() {
|
|
460
|
-
const ctx =
|
|
645
|
+
const ctx = React3.useContext(TextsCtx);
|
|
461
646
|
return ctx;
|
|
462
647
|
}
|
|
463
648
|
function useConsentHydrationInternal() {
|
|
464
|
-
return
|
|
649
|
+
return React3.useContext(HydrationCtx);
|
|
465
650
|
}
|
|
466
651
|
|
|
467
652
|
// src/hooks/useConsent.ts
|
|
@@ -555,12 +740,25 @@ function PreferencesModal2({
|
|
|
555
740
|
}) {
|
|
556
741
|
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
557
742
|
const texts = useConsentTexts();
|
|
558
|
-
const
|
|
559
|
-
|
|
743
|
+
const { toggleableCategories } = useCategories();
|
|
744
|
+
const [tempPreferences, setTempPreferences] = useState2(
|
|
745
|
+
() => {
|
|
746
|
+
const initialPrefs = { necessary: true };
|
|
747
|
+
toggleableCategories.forEach((category) => {
|
|
748
|
+
initialPrefs[category.id] = preferences[category.id] ?? false;
|
|
749
|
+
});
|
|
750
|
+
return initialPrefs;
|
|
751
|
+
}
|
|
752
|
+
);
|
|
753
|
+
useEffect4(() => {
|
|
560
754
|
if (isModalOpen) {
|
|
561
|
-
|
|
755
|
+
const syncedPrefs = { necessary: true };
|
|
756
|
+
toggleableCategories.forEach((category) => {
|
|
757
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
758
|
+
});
|
|
759
|
+
setTempPreferences(syncedPrefs);
|
|
562
760
|
}
|
|
563
|
-
}, [isModalOpen, preferences]);
|
|
761
|
+
}, [isModalOpen, preferences, toggleableCategories]);
|
|
564
762
|
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
565
763
|
const handleSave = () => {
|
|
566
764
|
setPreferences(tempPreferences);
|
|
@@ -581,38 +779,23 @@ function PreferencesModal2({
|
|
|
581
779
|
/* @__PURE__ */ jsxs3(DialogContent, { dividers: true, children: [
|
|
582
780
|
/* @__PURE__ */ jsx4(Typography2, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
583
781
|
/* @__PURE__ */ jsxs3(FormGroup, { children: [
|
|
584
|
-
/* @__PURE__ */ jsx4(
|
|
585
|
-
FormControlLabel,
|
|
586
|
-
{
|
|
587
|
-
control: /* @__PURE__ */ jsx4(
|
|
588
|
-
Switch,
|
|
589
|
-
{
|
|
590
|
-
checked: tempPreferences.analytics,
|
|
591
|
-
onChange: (e) => setTempPreferences((prev) => ({
|
|
592
|
-
...prev,
|
|
593
|
-
analytics: e.target.checked
|
|
594
|
-
}))
|
|
595
|
-
}
|
|
596
|
-
),
|
|
597
|
-
label: "Cookies Anal\xEDticos (medem uso do site)"
|
|
598
|
-
}
|
|
599
|
-
),
|
|
600
|
-
/* @__PURE__ */ jsx4(
|
|
782
|
+
toggleableCategories.map((category) => /* @__PURE__ */ jsx4(
|
|
601
783
|
FormControlLabel,
|
|
602
784
|
{
|
|
603
785
|
control: /* @__PURE__ */ jsx4(
|
|
604
786
|
Switch,
|
|
605
787
|
{
|
|
606
|
-
checked: tempPreferences.
|
|
788
|
+
checked: tempPreferences[category.id] ?? false,
|
|
607
789
|
onChange: (e) => setTempPreferences((prev) => ({
|
|
608
790
|
...prev,
|
|
609
|
-
|
|
791
|
+
[category.id]: e.target.checked
|
|
610
792
|
}))
|
|
611
793
|
}
|
|
612
794
|
),
|
|
613
|
-
label:
|
|
614
|
-
}
|
|
615
|
-
|
|
795
|
+
label: `${category.name} - ${category.description}`
|
|
796
|
+
},
|
|
797
|
+
category.id
|
|
798
|
+
)),
|
|
616
799
|
/* @__PURE__ */ jsx4(
|
|
617
800
|
FormControlLabel,
|
|
618
801
|
{
|
|
@@ -634,8 +817,11 @@ function PreferencesModal2({
|
|
|
634
817
|
|
|
635
818
|
export {
|
|
636
819
|
defaultConsentTheme,
|
|
820
|
+
DEFAULT_PROJECT_CATEGORIES,
|
|
821
|
+
analyzeDeveloperConfiguration,
|
|
822
|
+
useCategories,
|
|
823
|
+
useCategoryStatus,
|
|
637
824
|
useCustomCategories,
|
|
638
|
-
useAllCategories,
|
|
639
825
|
Branding,
|
|
640
826
|
PreferencesModal2 as PreferencesModal,
|
|
641
827
|
ConsentProvider,
|