react-lgpd-consent 0.3.0 → 0.3.2
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/CHANGELOG.md +468 -0
- package/README.md +92 -117
- package/dist/{PreferencesModal-XCTM6WJN.js → PreferencesModal-7RSEEVUK.js} +1 -1
- package/dist/chunk-JUZQJHQW.js +1406 -0
- package/dist/index.cjs +678 -311
- package/dist/index.d.cts +1683 -268
- package/dist/index.d.ts +1683 -268
- package/dist/index.js +29 -11
- package/package.json +17 -12
- package/COMPLIANCE.md +0 -107
- package/dist/chunk-R3IKVZBC.js +0 -1070
|
@@ -0,0 +1,1406 @@
|
|
|
1
|
+
// src/components/PreferencesModal.tsx
|
|
2
|
+
import Button2 from "@mui/material/Button";
|
|
3
|
+
import Dialog from "@mui/material/Dialog";
|
|
4
|
+
import DialogActions from "@mui/material/DialogActions";
|
|
5
|
+
import DialogContent from "@mui/material/DialogContent";
|
|
6
|
+
import DialogTitle from "@mui/material/DialogTitle";
|
|
7
|
+
import FormControlLabel from "@mui/material/FormControlLabel";
|
|
8
|
+
import FormGroup from "@mui/material/FormGroup";
|
|
9
|
+
import Switch from "@mui/material/Switch";
|
|
10
|
+
import Typography3 from "@mui/material/Typography";
|
|
11
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
12
|
+
|
|
13
|
+
// src/context/CategoriesContext.tsx
|
|
14
|
+
import * as React2 from "react";
|
|
15
|
+
|
|
16
|
+
// src/utils/developerGuidance.ts
|
|
17
|
+
import React from "react";
|
|
18
|
+
var DEFAULT_PROJECT_CATEGORIES = {
|
|
19
|
+
enabledCategories: ["analytics"]
|
|
20
|
+
};
|
|
21
|
+
function analyzeDeveloperConfiguration(config) {
|
|
22
|
+
const guidance = {
|
|
23
|
+
warnings: [],
|
|
24
|
+
suggestions: [],
|
|
25
|
+
activeCategoriesInfo: [],
|
|
26
|
+
usingDefaults: !config
|
|
27
|
+
};
|
|
28
|
+
const finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
29
|
+
if (!config) {
|
|
30
|
+
guidance.warnings.push(
|
|
31
|
+
'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".'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
guidance.activeCategoriesInfo.push({
|
|
35
|
+
id: "necessary",
|
|
36
|
+
name: "Cookies Necess\xE1rios",
|
|
37
|
+
description: "Essenciais para funcionamento b\xE1sico do site",
|
|
38
|
+
essential: true,
|
|
39
|
+
uiRequired: false
|
|
40
|
+
});
|
|
41
|
+
const enabledCategories = finalConfig.enabledCategories || [];
|
|
42
|
+
const categoryNames = {
|
|
43
|
+
analytics: {
|
|
44
|
+
name: "Cookies Anal\xEDticos",
|
|
45
|
+
description: "Medem uso e performance do site"
|
|
46
|
+
},
|
|
47
|
+
functional: {
|
|
48
|
+
name: "Cookies Funcionais",
|
|
49
|
+
description: "Melhoram experi\xEAncia e funcionalidades"
|
|
50
|
+
},
|
|
51
|
+
marketing: {
|
|
52
|
+
name: "Cookies de Marketing",
|
|
53
|
+
description: "Publicidade direcionada e campanhas"
|
|
54
|
+
},
|
|
55
|
+
social: {
|
|
56
|
+
name: "Cookies de Redes Sociais",
|
|
57
|
+
description: "Integra\xE7\xE3o com plataformas sociais"
|
|
58
|
+
},
|
|
59
|
+
personalization: {
|
|
60
|
+
name: "Cookies de Personaliza\xE7\xE3o",
|
|
61
|
+
description: "Adaptam conte\xFAdo \xE0s prefer\xEAncias do usu\xE1rio"
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
enabledCategories.forEach((categoryId) => {
|
|
65
|
+
const categoryInfo = categoryNames[categoryId];
|
|
66
|
+
if (categoryInfo) {
|
|
67
|
+
guidance.activeCategoriesInfo.push({
|
|
68
|
+
id: categoryId,
|
|
69
|
+
name: categoryInfo.name,
|
|
70
|
+
description: categoryInfo.description,
|
|
71
|
+
essential: false,
|
|
72
|
+
uiRequired: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const totalToggleable = guidance.activeCategoriesInfo.filter((c) => c.uiRequired).length;
|
|
77
|
+
if (totalToggleable === 0) {
|
|
78
|
+
guidance.suggestions.push(
|
|
79
|
+
'Apenas cookies necess\xE1rios est\xE3o configurados. Para compliance completo LGPD, considere adicionar categorias como "analytics" ou "functional" conforme uso real.'
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (totalToggleable > 5) {
|
|
83
|
+
guidance.warnings.push(
|
|
84
|
+
`${totalToggleable} categorias opcionais detectadas. UI com muitas op\xE7\xF5es pode prejudicar experi\xEAncia do usu\xE1rio. Considere agrupar categorias similares.`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return guidance;
|
|
88
|
+
}
|
|
89
|
+
function logDeveloperGuidance(guidance, disableGuidanceProp) {
|
|
90
|
+
const nodeEnv = typeof globalThis.process !== "undefined" ? globalThis.process.env?.NODE_ENV : void 0;
|
|
91
|
+
const isProd = nodeEnv === "production" || globalThis.__LGPD_PRODUCTION__ === true && typeof globalThis !== "undefined";
|
|
92
|
+
const isDisabled = !!disableGuidanceProp || globalThis.__LGPD_DISABLE_GUIDANCE__ === true && typeof globalThis !== "undefined";
|
|
93
|
+
if (isProd || isDisabled) return;
|
|
94
|
+
const PREFIX = "[\u{1F36A} LGPD-CONSENT]";
|
|
95
|
+
if (guidance.warnings.length > 0) {
|
|
96
|
+
console.group(`${PREFIX} \u26A0\uFE0F Avisos de Configura\xE7\xE3o`);
|
|
97
|
+
guidance.warnings.forEach((msg) => console.warn(`${PREFIX} ${msg}`));
|
|
98
|
+
console.groupEnd();
|
|
99
|
+
}
|
|
100
|
+
if (guidance.suggestions.length > 0) {
|
|
101
|
+
console.group(`${PREFIX} \u{1F4A1} Sugest\xF5es`);
|
|
102
|
+
guidance.suggestions.forEach((msg) => console.info(`${PREFIX} ${msg}`));
|
|
103
|
+
console.groupEnd();
|
|
104
|
+
}
|
|
105
|
+
if (guidance.usingDefaults) {
|
|
106
|
+
console.warn(
|
|
107
|
+
`${PREFIX} \u{1F4CB} Usando configura\xE7\xE3o padr\xE3o. Para personalizar, use a prop "categories" no ConsentProvider.`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const rows = guidance.activeCategoriesInfo.map((cat) => ({
|
|
111
|
+
ID: cat.id,
|
|
112
|
+
Nome: cat.name,
|
|
113
|
+
"Toggle UI?": cat.uiRequired ? "\u2705 SIM" : "\u274C N\xC3O (sempre ativo)",
|
|
114
|
+
"Essencial?": cat.essential ? "\u{1F512} SIM" : "\u2699\uFE0F N\xC3O"
|
|
115
|
+
}));
|
|
116
|
+
if (typeof console.table === "function") {
|
|
117
|
+
console.group(`${PREFIX} \u{1F527} Categorias Ativas (para UI customizada)`);
|
|
118
|
+
console.table(rows);
|
|
119
|
+
console.info(`${PREFIX} \u2139\uFE0F Use estes dados para criar componentes customizados adequados.`);
|
|
120
|
+
console.groupEnd();
|
|
121
|
+
} else {
|
|
122
|
+
console.log(`${PREFIX} \u{1F527} Categorias Ativas (para UI customizada)`, rows);
|
|
123
|
+
console.info(`${PREFIX} \u2139\uFE0F Use estes dados para criar componentes customizados adequados.`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function useDeveloperGuidance(config, disableGuidanceProp) {
|
|
127
|
+
const guidance = React.useMemo(() => {
|
|
128
|
+
return analyzeDeveloperConfiguration(config);
|
|
129
|
+
}, [config]);
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
if (!disableGuidanceProp) {
|
|
132
|
+
logDeveloperGuidance(guidance, disableGuidanceProp);
|
|
133
|
+
}
|
|
134
|
+
}, [guidance, disableGuidanceProp]);
|
|
135
|
+
return guidance;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/context/CategoriesContext.tsx
|
|
139
|
+
import { jsx } from "react/jsx-runtime";
|
|
140
|
+
var CategoriesContext = React2.createContext(null);
|
|
141
|
+
function CategoriesProvider({
|
|
142
|
+
children,
|
|
143
|
+
config,
|
|
144
|
+
disableDeveloperGuidance
|
|
145
|
+
}) {
|
|
146
|
+
const contextValue = React2.useMemo(() => {
|
|
147
|
+
const finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
148
|
+
const guidance = analyzeDeveloperConfiguration(config);
|
|
149
|
+
const toggleableCategories = guidance.activeCategoriesInfo.filter((cat) => cat.uiRequired);
|
|
150
|
+
return {
|
|
151
|
+
config: finalConfig,
|
|
152
|
+
guidance,
|
|
153
|
+
toggleableCategories,
|
|
154
|
+
allCategories: guidance.activeCategoriesInfo
|
|
155
|
+
};
|
|
156
|
+
}, [config]);
|
|
157
|
+
React2.useEffect(() => {
|
|
158
|
+
logDeveloperGuidance(contextValue.guidance, disableDeveloperGuidance);
|
|
159
|
+
}, [contextValue.guidance, disableDeveloperGuidance]);
|
|
160
|
+
return /* @__PURE__ */ jsx(CategoriesContext.Provider, { value: contextValue, children });
|
|
161
|
+
}
|
|
162
|
+
function useCategories() {
|
|
163
|
+
const context = React2.useContext(CategoriesContext);
|
|
164
|
+
if (!context) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
"useCategories deve ser usado dentro de CategoriesProvider. Certifique-se de que o ConsentProvider est\xE1 envolvendo seu componente."
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return context;
|
|
170
|
+
}
|
|
171
|
+
function useCategoryStatus(categoryId) {
|
|
172
|
+
const { allCategories } = useCategories();
|
|
173
|
+
const category = allCategories.find((cat) => cat.id === categoryId);
|
|
174
|
+
return {
|
|
175
|
+
isActive: !!category,
|
|
176
|
+
isEssential: category?.essential || false,
|
|
177
|
+
needsToggle: category?.uiRequired || false,
|
|
178
|
+
name: category?.name,
|
|
179
|
+
description: category?.description
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/context/ConsentContext.tsx
|
|
184
|
+
import * as React5 from "react";
|
|
185
|
+
|
|
186
|
+
// src/utils/SafeThemeProvider.tsx
|
|
187
|
+
import * as React3 from "react";
|
|
188
|
+
import { ThemeProvider, createTheme } from "@mui/material/styles";
|
|
189
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
190
|
+
var createSafeTheme = (userTheme) => {
|
|
191
|
+
const baseTheme = createTheme({
|
|
192
|
+
palette: {
|
|
193
|
+
primary: {
|
|
194
|
+
main: "#1976d2",
|
|
195
|
+
dark: "#1565c0",
|
|
196
|
+
light: "#42a5f5",
|
|
197
|
+
contrastText: "#ffffff"
|
|
198
|
+
},
|
|
199
|
+
secondary: {
|
|
200
|
+
main: "#dc004e",
|
|
201
|
+
dark: "#9a0036",
|
|
202
|
+
light: "#e33371",
|
|
203
|
+
contrastText: "#ffffff"
|
|
204
|
+
},
|
|
205
|
+
background: {
|
|
206
|
+
default: "#fafafa",
|
|
207
|
+
paper: "#ffffff"
|
|
208
|
+
},
|
|
209
|
+
text: {
|
|
210
|
+
primary: "#333333",
|
|
211
|
+
secondary: "#666666"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
transitions: {
|
|
215
|
+
duration: {
|
|
216
|
+
shortest: 150,
|
|
217
|
+
shorter: 200,
|
|
218
|
+
short: 250,
|
|
219
|
+
standard: 300,
|
|
220
|
+
complex: 375,
|
|
221
|
+
enteringScreen: 225,
|
|
222
|
+
leavingScreen: 195
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
if (!userTheme) {
|
|
227
|
+
return baseTheme;
|
|
228
|
+
}
|
|
229
|
+
return createTheme({
|
|
230
|
+
...baseTheme,
|
|
231
|
+
...userTheme,
|
|
232
|
+
palette: {
|
|
233
|
+
...baseTheme.palette,
|
|
234
|
+
...userTheme.palette,
|
|
235
|
+
primary: {
|
|
236
|
+
...baseTheme.palette.primary,
|
|
237
|
+
...userTheme.palette?.primary
|
|
238
|
+
},
|
|
239
|
+
secondary: {
|
|
240
|
+
...baseTheme.palette.secondary,
|
|
241
|
+
...userTheme.palette?.secondary
|
|
242
|
+
},
|
|
243
|
+
background: {
|
|
244
|
+
...baseTheme.palette.background,
|
|
245
|
+
...userTheme.palette?.background
|
|
246
|
+
},
|
|
247
|
+
text: {
|
|
248
|
+
...baseTheme.palette.text,
|
|
249
|
+
...userTheme.palette?.text
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
transitions: {
|
|
253
|
+
...baseTheme.transitions,
|
|
254
|
+
...userTheme.transitions,
|
|
255
|
+
duration: {
|
|
256
|
+
...baseTheme.transitions.duration,
|
|
257
|
+
...userTheme.transitions?.duration
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
function SafeThemeProvider({ theme, children }) {
|
|
263
|
+
const safeTheme = React3.useMemo(() => createSafeTheme(theme), [theme]);
|
|
264
|
+
return /* @__PURE__ */ jsx2(ThemeProvider, { theme: safeTheme, children });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/utils/cookieUtils.ts
|
|
268
|
+
import Cookies from "js-cookie";
|
|
269
|
+
|
|
270
|
+
// src/utils/logger.ts
|
|
271
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
272
|
+
LogLevel2[LogLevel2["ERROR"] = 0] = "ERROR";
|
|
273
|
+
LogLevel2[LogLevel2["WARN"] = 1] = "WARN";
|
|
274
|
+
LogLevel2[LogLevel2["INFO"] = 2] = "INFO";
|
|
275
|
+
LogLevel2[LogLevel2["DEBUG"] = 3] = "DEBUG";
|
|
276
|
+
return LogLevel2;
|
|
277
|
+
})(LogLevel || {});
|
|
278
|
+
var _ConsentLogger = class _ConsentLogger {
|
|
279
|
+
constructor() {
|
|
280
|
+
this.enabled = _ConsentLogger.IS_DEVELOPMENT;
|
|
281
|
+
this.level = 2 /* INFO */;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Habilita ou desabilita o sistema de logging.
|
|
285
|
+
* @param {boolean} enabled Se `true`, os logs serão exibidos; caso contrário, serão suprimidos.
|
|
286
|
+
*/
|
|
287
|
+
setEnabled(enabled) {
|
|
288
|
+
this.enabled = enabled;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Define o nível mínimo de severidade para os logs.
|
|
292
|
+
* Mensagens com severidade menor que o nível definido não serão exibidas.
|
|
293
|
+
* @param {LogLevel} level O nível mínimo de severidade (ex: `LogLevel.DEBUG` para ver todos os logs).
|
|
294
|
+
*/
|
|
295
|
+
setLevel(level) {
|
|
296
|
+
this.level = level;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Registra uma mensagem de erro.
|
|
300
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
301
|
+
*/
|
|
302
|
+
error(...args) {
|
|
303
|
+
if (this.enabled && this.level >= 0 /* ERROR */) {
|
|
304
|
+
console.error(_ConsentLogger.LOG_PREFIX, "[ERROR]", ...args);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Registra uma mensagem de aviso.
|
|
309
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
310
|
+
*/
|
|
311
|
+
warn(...args) {
|
|
312
|
+
if (this.enabled && this.level >= 1 /* WARN */) {
|
|
313
|
+
console.warn(_ConsentLogger.LOG_PREFIX, "[WARN]", ...args);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Registra uma mensagem informativa.
|
|
318
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
319
|
+
*/
|
|
320
|
+
info(...args) {
|
|
321
|
+
if (this.enabled && this.level >= 2 /* INFO */) {
|
|
322
|
+
console.info(_ConsentLogger.LOG_PREFIX, "[INFO]", ...args);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Registra uma mensagem de depuração.
|
|
327
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
328
|
+
*/
|
|
329
|
+
debug(...args) {
|
|
330
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
331
|
+
console.debug(_ConsentLogger.LOG_PREFIX, "[DEBUG]", ...args);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Inicia um grupo de logs no console.
|
|
336
|
+
* @param {...any[]} args Os argumentos para o título do grupo.
|
|
337
|
+
*/
|
|
338
|
+
group(...args) {
|
|
339
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
340
|
+
console.group(_ConsentLogger.LOG_PREFIX, ...args);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Finaliza o grupo de logs mais recente no console.
|
|
345
|
+
*/
|
|
346
|
+
groupEnd() {
|
|
347
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
348
|
+
console.groupEnd();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Exibe dados tabulares no console.
|
|
353
|
+
* @param {any} tabularData Os dados a serem exibidos na tabela.
|
|
354
|
+
* @param {string[]} [properties] Um array opcional de propriedades para exibir.
|
|
355
|
+
*/
|
|
356
|
+
table(tabularData, properties) {
|
|
357
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
358
|
+
console.table(tabularData, properties);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Registra informações sobre a compatibilidade do tema Material-UI.
|
|
363
|
+
* @param {any} themeInfo Objeto com informações do tema.
|
|
364
|
+
*/
|
|
365
|
+
themeCompatibility(themeInfo) {
|
|
366
|
+
this.debug("Theme compatibility check:", {
|
|
367
|
+
hasTheme: !!themeInfo,
|
|
368
|
+
hasPalette: !!themeInfo?.palette,
|
|
369
|
+
hasPrimary: !!themeInfo?.palette?.primary,
|
|
370
|
+
hasTransitions: !!themeInfo?.transitions,
|
|
371
|
+
hasDuration: !!themeInfo?.transitions?.duration
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Registra mudanças no estado de consentimento.
|
|
376
|
+
* @param {string} action A ação que causou a mudança de estado.
|
|
377
|
+
* @param {any} state O estado atual do consentimento.
|
|
378
|
+
*/
|
|
379
|
+
consentState(action, state) {
|
|
380
|
+
this.debug(`Consent state change [${action}]:`, {
|
|
381
|
+
consented: state.consented,
|
|
382
|
+
isModalOpen: state.isModalOpen,
|
|
383
|
+
preferencesCount: Object.keys(state.preferences || {}).length
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Registra operações de cookie (leitura, escrita, remoção).
|
|
388
|
+
* @param {'read' | 'write' | 'delete'} operation O tipo de operação de cookie.
|
|
389
|
+
* @param {string} cookieName O nome do cookie.
|
|
390
|
+
* @param {any} [data] Os dados do cookie, se aplicável.
|
|
391
|
+
*/
|
|
392
|
+
cookieOperation(operation, cookieName, data) {
|
|
393
|
+
this.debug(`Cookie ${operation}:`, {
|
|
394
|
+
name: cookieName,
|
|
395
|
+
hasData: !!data,
|
|
396
|
+
dataSize: data ? JSON.stringify(data).length : 0
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Registra a renderização de um componente.
|
|
401
|
+
* @param {string} componentName O nome do componente.
|
|
402
|
+
* @param {any} [props] As propriedades do componente.
|
|
403
|
+
*/
|
|
404
|
+
componentRender(componentName, props) {
|
|
405
|
+
this.debug(`Component render [${componentName}]:`, {
|
|
406
|
+
hasProps: !!props,
|
|
407
|
+
propsKeys: props ? Object.keys(props) : []
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Registra o status de carregamento de scripts de integração.
|
|
412
|
+
* @param {string} scriptName O nome do script.
|
|
413
|
+
* @param {'load' | 'remove'} action A ação realizada (carregar ou remover).
|
|
414
|
+
* @param {boolean} success Se a operação foi bem-sucedida.
|
|
415
|
+
*/
|
|
416
|
+
scriptIntegration(scriptName, action, success) {
|
|
417
|
+
this.info(`Script ${action} [${scriptName}]:`, success ? "SUCCESS" : "FAILED");
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Registra chamadas à API interna da biblioteca.
|
|
421
|
+
* @param {string} method O nome do método da API chamado.
|
|
422
|
+
* @param {any} [params] Os parâmetros passados para o método.
|
|
423
|
+
*/
|
|
424
|
+
apiUsage(method, params) {
|
|
425
|
+
this.debug(`API call [${method}]:`, params);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
_ConsentLogger.IS_DEVELOPMENT = typeof globalThis !== "undefined" && globalThis.process?.env?.NODE_ENV === "development";
|
|
429
|
+
_ConsentLogger.LOG_PREFIX = "[react-lgpd-consent]";
|
|
430
|
+
var ConsentLogger = _ConsentLogger;
|
|
431
|
+
var logger = new ConsentLogger();
|
|
432
|
+
function setDebugLogging(enabled, level = 2 /* INFO */) {
|
|
433
|
+
logger.setEnabled(enabled);
|
|
434
|
+
logger.setLevel(level);
|
|
435
|
+
logger.info(`Debug logging ${enabled ? "enabled" : "disabled"} with level ${LogLevel[level]}`);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/utils/cookieUtils.ts
|
|
439
|
+
var DEFAULT_COOKIE_OPTS = {
|
|
440
|
+
name: "cookieConsent",
|
|
441
|
+
maxAgeDays: 365,
|
|
442
|
+
sameSite: "Lax",
|
|
443
|
+
secure: typeof window !== "undefined" ? window.location.protocol === "https:" : false,
|
|
444
|
+
path: "/"
|
|
445
|
+
};
|
|
446
|
+
var COOKIE_SCHEMA_VERSION = "1.0";
|
|
447
|
+
function readConsentCookie(name = DEFAULT_COOKIE_OPTS.name) {
|
|
448
|
+
logger.debug("Reading consent cookie", { name });
|
|
449
|
+
if (typeof document === "undefined") {
|
|
450
|
+
logger.debug("Cookie read skipped: server-side environment");
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
const raw = Cookies.get(name);
|
|
454
|
+
if (!raw) {
|
|
455
|
+
logger.debug("No consent cookie found");
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
const data = JSON.parse(raw);
|
|
460
|
+
logger.cookieOperation("read", name, data);
|
|
461
|
+
if (!data.version) {
|
|
462
|
+
logger.debug("Migrating legacy cookie format");
|
|
463
|
+
return migrateLegacyCookie(data);
|
|
464
|
+
}
|
|
465
|
+
if (data.version !== COOKIE_SCHEMA_VERSION) {
|
|
466
|
+
logger.warn(`Cookie version mismatch: ${data.version} != ${COOKIE_SCHEMA_VERSION}`);
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
return data;
|
|
470
|
+
} catch (error) {
|
|
471
|
+
logger.error("Error parsing consent cookie", error);
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function migrateLegacyCookie(legacyData) {
|
|
476
|
+
try {
|
|
477
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
478
|
+
return {
|
|
479
|
+
version: COOKIE_SCHEMA_VERSION,
|
|
480
|
+
consented: legacyData.consented || false,
|
|
481
|
+
preferences: legacyData.preferences || { necessary: true },
|
|
482
|
+
consentDate: now,
|
|
483
|
+
lastUpdate: now,
|
|
484
|
+
source: "banner",
|
|
485
|
+
isModalOpen: false
|
|
486
|
+
};
|
|
487
|
+
} catch {
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function writeConsentCookie(state, config, opts, source = "banner") {
|
|
492
|
+
if (typeof document === "undefined") {
|
|
493
|
+
logger.debug("Cookie write skipped: server-side environment");
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
497
|
+
const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
|
|
498
|
+
const cookieData = {
|
|
499
|
+
version: COOKIE_SCHEMA_VERSION,
|
|
500
|
+
consented: state.consented,
|
|
501
|
+
preferences: state.preferences,
|
|
502
|
+
consentDate: state.consentDate || now,
|
|
503
|
+
lastUpdate: now,
|
|
504
|
+
source,
|
|
505
|
+
projectConfig: config
|
|
506
|
+
};
|
|
507
|
+
logger.cookieOperation("write", o.name, cookieData);
|
|
508
|
+
Cookies.set(o.name, JSON.stringify(cookieData), {
|
|
509
|
+
expires: o.maxAgeDays,
|
|
510
|
+
sameSite: o.sameSite,
|
|
511
|
+
secure: o.secure,
|
|
512
|
+
path: o.path
|
|
513
|
+
});
|
|
514
|
+
logger.info("Consent cookie saved", {
|
|
515
|
+
consented: cookieData.consented,
|
|
516
|
+
source: cookieData.source,
|
|
517
|
+
preferencesCount: Object.keys(cookieData.preferences).length
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function removeConsentCookie(opts) {
|
|
521
|
+
if (typeof document === "undefined") {
|
|
522
|
+
logger.debug("Cookie removal skipped: server-side environment");
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
|
|
526
|
+
logger.cookieOperation("delete", o.name);
|
|
527
|
+
Cookies.remove(o.name, { path: o.path });
|
|
528
|
+
logger.info("Consent cookie removed");
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/utils/categoryUtils.ts
|
|
532
|
+
function createProjectPreferences(config, defaultValue = false) {
|
|
533
|
+
const preferences = {
|
|
534
|
+
necessary: true
|
|
535
|
+
// Sempre presente e true (essencial)
|
|
536
|
+
};
|
|
537
|
+
const enabledCategories = config?.enabledCategories || [];
|
|
538
|
+
enabledCategories.forEach((category) => {
|
|
539
|
+
if (category !== "necessary") {
|
|
540
|
+
preferences[category] = defaultValue;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
return preferences;
|
|
544
|
+
}
|
|
545
|
+
function validateProjectPreferences(preferences, config) {
|
|
546
|
+
const validPreferences = {
|
|
547
|
+
necessary: true
|
|
548
|
+
// Sempre válida
|
|
549
|
+
};
|
|
550
|
+
const enabledCategories = config?.enabledCategories || [];
|
|
551
|
+
enabledCategories.forEach((category) => {
|
|
552
|
+
if (category !== "necessary" && preferences[category] !== void 0) {
|
|
553
|
+
validPreferences[category] = preferences[category];
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
return validPreferences;
|
|
557
|
+
}
|
|
558
|
+
function getAllProjectCategories(config) {
|
|
559
|
+
const allCategories = [
|
|
560
|
+
{
|
|
561
|
+
id: "necessary",
|
|
562
|
+
name: "Necess\xE1rios",
|
|
563
|
+
description: "Cookies essenciais para funcionamento b\xE1sico do site",
|
|
564
|
+
essential: true
|
|
565
|
+
}
|
|
566
|
+
];
|
|
567
|
+
const enabledCategories = config?.enabledCategories || [];
|
|
568
|
+
enabledCategories.forEach((category) => {
|
|
569
|
+
if (category !== "necessary") {
|
|
570
|
+
allCategories.push(getDefaultCategoryDefinition(category));
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
return allCategories;
|
|
574
|
+
}
|
|
575
|
+
function getDefaultCategoryDefinition(category) {
|
|
576
|
+
const definitions = {
|
|
577
|
+
necessary: {
|
|
578
|
+
id: "necessary",
|
|
579
|
+
name: "Necess\xE1rios",
|
|
580
|
+
description: "Cookies essenciais para funcionamento b\xE1sico do site",
|
|
581
|
+
essential: true
|
|
582
|
+
},
|
|
583
|
+
analytics: {
|
|
584
|
+
id: "analytics",
|
|
585
|
+
name: "An\xE1lise e Estat\xEDsticas",
|
|
586
|
+
description: "Cookies para an\xE1lise de uso e estat\xEDsticas do site",
|
|
587
|
+
essential: false
|
|
588
|
+
},
|
|
589
|
+
functional: {
|
|
590
|
+
id: "functional",
|
|
591
|
+
name: "Funcionalidades",
|
|
592
|
+
description: "Cookies para funcionalidades extras como prefer\xEAncias e idioma",
|
|
593
|
+
essential: false
|
|
594
|
+
},
|
|
595
|
+
marketing: {
|
|
596
|
+
id: "marketing",
|
|
597
|
+
name: "Marketing e Publicidade",
|
|
598
|
+
description: "Cookies para publicidade direcionada e marketing",
|
|
599
|
+
essential: false
|
|
600
|
+
},
|
|
601
|
+
social: {
|
|
602
|
+
id: "social",
|
|
603
|
+
name: "Redes Sociais",
|
|
604
|
+
description: "Cookies para integra\xE7\xE3o com redes sociais e compartilhamento",
|
|
605
|
+
essential: false
|
|
606
|
+
},
|
|
607
|
+
personalization: {
|
|
608
|
+
id: "personalization",
|
|
609
|
+
name: "Personaliza\xE7\xE3o",
|
|
610
|
+
description: "Cookies para personaliza\xE7\xE3o de conte\xFAdo e experi\xEAncia",
|
|
611
|
+
essential: false
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
return definitions[category];
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/utils/theme.ts
|
|
618
|
+
import { createTheme as createTheme2 } from "@mui/material/styles";
|
|
619
|
+
var defaultConsentTheme = createTheme2({
|
|
620
|
+
palette: {
|
|
621
|
+
primary: {
|
|
622
|
+
main: "#1976d2",
|
|
623
|
+
contrastText: "#ffffff"
|
|
624
|
+
},
|
|
625
|
+
secondary: {
|
|
626
|
+
main: "#dc004e",
|
|
627
|
+
contrastText: "#ffffff"
|
|
628
|
+
},
|
|
629
|
+
background: {
|
|
630
|
+
default: "#fafafa",
|
|
631
|
+
paper: "#ffffff"
|
|
632
|
+
},
|
|
633
|
+
text: {
|
|
634
|
+
primary: "#333333",
|
|
635
|
+
secondary: "#666666"
|
|
636
|
+
},
|
|
637
|
+
action: {
|
|
638
|
+
hover: "rgba(25, 118, 210, 0.04)"
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
typography: {
|
|
642
|
+
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
|
|
643
|
+
body2: {
|
|
644
|
+
fontSize: "0.875rem",
|
|
645
|
+
lineHeight: 1.43
|
|
646
|
+
},
|
|
647
|
+
button: {
|
|
648
|
+
fontWeight: 500,
|
|
649
|
+
textTransform: "none"
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
components: {
|
|
653
|
+
MuiButton: {
|
|
654
|
+
styleOverrides: {
|
|
655
|
+
root: {
|
|
656
|
+
borderRadius: 8,
|
|
657
|
+
paddingX: 16,
|
|
658
|
+
paddingY: 8
|
|
659
|
+
},
|
|
660
|
+
contained: {
|
|
661
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
662
|
+
"&:hover": {
|
|
663
|
+
boxShadow: "0 4px 8px rgba(0,0,0,0.15)"
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
MuiPaper: {
|
|
669
|
+
styleOverrides: {
|
|
670
|
+
root: {
|
|
671
|
+
borderRadius: 12
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
MuiDialog: {
|
|
676
|
+
styleOverrides: {
|
|
677
|
+
paper: {
|
|
678
|
+
borderRadius: 16
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
// src/context/DesignContext.tsx
|
|
686
|
+
import * as React4 from "react";
|
|
687
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
688
|
+
var DesignContext = React4.createContext(void 0);
|
|
689
|
+
function DesignProvider({
|
|
690
|
+
tokens,
|
|
691
|
+
children
|
|
692
|
+
}) {
|
|
693
|
+
return /* @__PURE__ */ jsx3(DesignContext.Provider, { value: tokens, children });
|
|
694
|
+
}
|
|
695
|
+
function useDesignTokens() {
|
|
696
|
+
return React4.useContext(DesignContext);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// src/components/CookieBanner.tsx
|
|
700
|
+
import Button from "@mui/material/Button";
|
|
701
|
+
import Box from "@mui/material/Box";
|
|
702
|
+
import Paper from "@mui/material/Paper";
|
|
703
|
+
import Snackbar from "@mui/material/Snackbar";
|
|
704
|
+
import Stack from "@mui/material/Stack";
|
|
705
|
+
import Typography2 from "@mui/material/Typography";
|
|
706
|
+
import Link2 from "@mui/material/Link";
|
|
707
|
+
|
|
708
|
+
// src/components/Branding.tsx
|
|
709
|
+
import Link from "@mui/material/Link";
|
|
710
|
+
import Typography from "@mui/material/Typography";
|
|
711
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
712
|
+
var brandingStyles = {
|
|
713
|
+
banner: {
|
|
714
|
+
fontSize: "0.65rem",
|
|
715
|
+
textAlign: "right",
|
|
716
|
+
mt: 1,
|
|
717
|
+
opacity: 0.7,
|
|
718
|
+
fontStyle: "italic",
|
|
719
|
+
width: "100%"
|
|
720
|
+
},
|
|
721
|
+
modal: {
|
|
722
|
+
fontSize: "0.65rem",
|
|
723
|
+
textAlign: "right",
|
|
724
|
+
px: 3,
|
|
725
|
+
pb: 1,
|
|
726
|
+
opacity: 0.7,
|
|
727
|
+
fontStyle: "italic",
|
|
728
|
+
width: "100%"
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
var linkStyles = {
|
|
732
|
+
textDecoration: "none",
|
|
733
|
+
fontWeight: 500,
|
|
734
|
+
"&:hover": {
|
|
735
|
+
textDecoration: "underline"
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
function Branding({ variant, hidden = false }) {
|
|
739
|
+
const texts = useConsentTexts();
|
|
740
|
+
if (hidden) return null;
|
|
741
|
+
return /* @__PURE__ */ jsxs(
|
|
742
|
+
Typography,
|
|
743
|
+
{
|
|
744
|
+
variant: "caption",
|
|
745
|
+
sx: (theme) => ({
|
|
746
|
+
...brandingStyles[variant],
|
|
747
|
+
color: theme.palette.text.secondary
|
|
748
|
+
}),
|
|
749
|
+
children: [
|
|
750
|
+
texts.brandingPoweredBy || "fornecido por",
|
|
751
|
+
" ",
|
|
752
|
+
/* @__PURE__ */ jsx4(
|
|
753
|
+
Link,
|
|
754
|
+
{
|
|
755
|
+
href: "https://www.ledipo.eti.br",
|
|
756
|
+
target: "_blank",
|
|
757
|
+
rel: "noopener noreferrer",
|
|
758
|
+
sx: (theme) => ({
|
|
759
|
+
...linkStyles,
|
|
760
|
+
color: theme.palette.primary.main
|
|
761
|
+
}),
|
|
762
|
+
children: "L\xC9dipO.eti.br"
|
|
763
|
+
}
|
|
764
|
+
)
|
|
765
|
+
]
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// src/components/CookieBanner.tsx
|
|
771
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
772
|
+
function CookieBanner({
|
|
773
|
+
policyLinkUrl,
|
|
774
|
+
debug,
|
|
775
|
+
blocking = true,
|
|
776
|
+
hideBranding = false,
|
|
777
|
+
SnackbarProps,
|
|
778
|
+
PaperProps
|
|
779
|
+
}) {
|
|
780
|
+
const { consented, acceptAll, rejectAll, openPreferences } = useConsent();
|
|
781
|
+
const texts = useConsentTexts();
|
|
782
|
+
const isHydrated = useConsentHydration();
|
|
783
|
+
const designTokens = useDesignTokens();
|
|
784
|
+
const open = debug ? true : isHydrated && !consented;
|
|
785
|
+
logger.componentRender("CookieBanner", {
|
|
786
|
+
open,
|
|
787
|
+
consented,
|
|
788
|
+
isHydrated,
|
|
789
|
+
blocking,
|
|
790
|
+
hideBranding
|
|
791
|
+
});
|
|
792
|
+
if (!open) return null;
|
|
793
|
+
const bannerStyle = {
|
|
794
|
+
p: designTokens?.spacing?.padding?.banner ?? 2,
|
|
795
|
+
maxWidth: 720,
|
|
796
|
+
mx: "auto",
|
|
797
|
+
backgroundColor: designTokens?.colors?.background,
|
|
798
|
+
color: designTokens?.colors?.text,
|
|
799
|
+
borderRadius: designTokens?.spacing?.borderRadius?.banner,
|
|
800
|
+
fontFamily: designTokens?.typography?.fontFamily
|
|
801
|
+
};
|
|
802
|
+
const bannerContent = /* @__PURE__ */ jsx5(Paper, { elevation: 3, sx: bannerStyle, ...PaperProps, children: /* @__PURE__ */ jsxs2(Stack, { spacing: 1, children: [
|
|
803
|
+
/* @__PURE__ */ jsxs2(Typography2, { variant: "body2", sx: { fontSize: designTokens?.typography?.fontSize?.banner }, children: [
|
|
804
|
+
texts.bannerMessage,
|
|
805
|
+
" ",
|
|
806
|
+
policyLinkUrl && /* @__PURE__ */ jsx5(
|
|
807
|
+
Link2,
|
|
808
|
+
{
|
|
809
|
+
href: policyLinkUrl,
|
|
810
|
+
underline: "hover",
|
|
811
|
+
target: "_blank",
|
|
812
|
+
rel: "noopener noreferrer",
|
|
813
|
+
sx: { color: designTokens?.colors?.primary },
|
|
814
|
+
children: texts.policyLink ?? "Saiba mais"
|
|
815
|
+
}
|
|
816
|
+
)
|
|
817
|
+
] }),
|
|
818
|
+
/* @__PURE__ */ jsxs2(Stack, { direction: { xs: "column", sm: "row" }, spacing: 1, justifyContent: "flex-end", children: [
|
|
819
|
+
/* @__PURE__ */ jsx5(
|
|
820
|
+
Button,
|
|
821
|
+
{
|
|
822
|
+
variant: "outlined",
|
|
823
|
+
onClick: () => {
|
|
824
|
+
logger.apiUsage("rejectAll", { source: "banner" });
|
|
825
|
+
rejectAll();
|
|
826
|
+
},
|
|
827
|
+
sx: { color: designTokens?.colors?.secondary },
|
|
828
|
+
children: texts.declineAll
|
|
829
|
+
}
|
|
830
|
+
),
|
|
831
|
+
/* @__PURE__ */ jsx5(
|
|
832
|
+
Button,
|
|
833
|
+
{
|
|
834
|
+
variant: "contained",
|
|
835
|
+
onClick: () => {
|
|
836
|
+
logger.apiUsage("acceptAll", { source: "banner" });
|
|
837
|
+
acceptAll();
|
|
838
|
+
},
|
|
839
|
+
sx: { backgroundColor: designTokens?.colors?.primary },
|
|
840
|
+
children: texts.acceptAll
|
|
841
|
+
}
|
|
842
|
+
),
|
|
843
|
+
/* @__PURE__ */ jsx5(
|
|
844
|
+
Button,
|
|
845
|
+
{
|
|
846
|
+
variant: "text",
|
|
847
|
+
onClick: () => {
|
|
848
|
+
logger.apiUsage("openPreferences", { source: "banner" });
|
|
849
|
+
openPreferences();
|
|
850
|
+
},
|
|
851
|
+
sx: { color: designTokens?.colors?.text },
|
|
852
|
+
children: texts.preferences
|
|
853
|
+
}
|
|
854
|
+
)
|
|
855
|
+
] }),
|
|
856
|
+
!hideBranding && /* @__PURE__ */ jsx5(Branding, { variant: "banner" })
|
|
857
|
+
] }) });
|
|
858
|
+
const positionStyle = {
|
|
859
|
+
position: "fixed",
|
|
860
|
+
zIndex: 1300,
|
|
861
|
+
...designTokens?.layout?.position === "top" ? { top: 0 } : { bottom: 0 },
|
|
862
|
+
left: 0,
|
|
863
|
+
right: 0,
|
|
864
|
+
width: designTokens?.layout?.width?.desktop ?? "100%",
|
|
865
|
+
p: 2
|
|
866
|
+
};
|
|
867
|
+
if (blocking) {
|
|
868
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
869
|
+
/* @__PURE__ */ jsx5(
|
|
870
|
+
Box,
|
|
871
|
+
{
|
|
872
|
+
sx: {
|
|
873
|
+
position: "fixed",
|
|
874
|
+
top: 0,
|
|
875
|
+
left: 0,
|
|
876
|
+
right: 0,
|
|
877
|
+
bottom: 0,
|
|
878
|
+
backgroundColor: designTokens?.layout?.backdrop ? "rgba(0, 0, 0, 0.5)" : "transparent",
|
|
879
|
+
zIndex: 1299
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
),
|
|
883
|
+
/* @__PURE__ */ jsx5(Box, { sx: positionStyle, children: bannerContent })
|
|
884
|
+
] });
|
|
885
|
+
}
|
|
886
|
+
return /* @__PURE__ */ jsx5(
|
|
887
|
+
Snackbar,
|
|
888
|
+
{
|
|
889
|
+
open,
|
|
890
|
+
anchorOrigin: {
|
|
891
|
+
vertical: designTokens?.layout?.position === "top" ? "top" : "bottom",
|
|
892
|
+
horizontal: "center"
|
|
893
|
+
},
|
|
894
|
+
...SnackbarProps,
|
|
895
|
+
children: bannerContent
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// src/components/FloatingPreferencesButton.tsx
|
|
901
|
+
import CookieOutlined from "@mui/icons-material/CookieOutlined";
|
|
902
|
+
import Fab from "@mui/material/Fab";
|
|
903
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
904
|
+
import { useTheme } from "@mui/material/styles";
|
|
905
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
906
|
+
function useThemeWithFallbacks() {
|
|
907
|
+
const theme = useTheme();
|
|
908
|
+
logger.themeCompatibility(theme);
|
|
909
|
+
return {
|
|
910
|
+
palette: {
|
|
911
|
+
primary: {
|
|
912
|
+
main: theme?.palette?.primary?.main || "#1976d2",
|
|
913
|
+
dark: theme?.palette?.primary?.dark || "#1565c0"
|
|
914
|
+
}
|
|
915
|
+
},
|
|
916
|
+
transitions: {
|
|
917
|
+
duration: {
|
|
918
|
+
shortest: theme?.transitions?.duration?.shortest || 150,
|
|
919
|
+
short: theme?.transitions?.duration?.short || 250
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
function FloatingPreferencesButton({
|
|
925
|
+
position = "bottom-right",
|
|
926
|
+
offset = 24,
|
|
927
|
+
icon = /* @__PURE__ */ jsx6(CookieOutlined, {}),
|
|
928
|
+
tooltip,
|
|
929
|
+
FabProps,
|
|
930
|
+
hideWhenConsented = false
|
|
931
|
+
}) {
|
|
932
|
+
const { openPreferences, consented } = useConsent();
|
|
933
|
+
const texts = useConsentTexts();
|
|
934
|
+
const safeTheme = useThemeWithFallbacks();
|
|
935
|
+
logger.componentRender("FloatingPreferencesButton", {
|
|
936
|
+
position,
|
|
937
|
+
offset,
|
|
938
|
+
hideWhenConsented,
|
|
939
|
+
consented
|
|
940
|
+
});
|
|
941
|
+
if (hideWhenConsented && consented) {
|
|
942
|
+
logger.debug(
|
|
943
|
+
"FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
|
|
944
|
+
);
|
|
945
|
+
return null;
|
|
946
|
+
}
|
|
947
|
+
const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
948
|
+
const getPosition = () => {
|
|
949
|
+
const styles = {
|
|
950
|
+
position: "fixed",
|
|
951
|
+
zIndex: 1200
|
|
952
|
+
};
|
|
953
|
+
switch (position) {
|
|
954
|
+
case "bottom-left":
|
|
955
|
+
return { ...styles, bottom: offset, left: offset };
|
|
956
|
+
case "bottom-right":
|
|
957
|
+
return { ...styles, bottom: offset, right: offset };
|
|
958
|
+
case "top-left":
|
|
959
|
+
return { ...styles, top: offset, left: offset };
|
|
960
|
+
case "top-right":
|
|
961
|
+
return { ...styles, top: offset, right: offset };
|
|
962
|
+
default:
|
|
963
|
+
return { ...styles, bottom: offset, right: offset };
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
return /* @__PURE__ */ jsx6(Tooltip, { title: tooltipText, placement: "top", children: /* @__PURE__ */ jsx6(
|
|
967
|
+
Fab,
|
|
968
|
+
{
|
|
969
|
+
size: "medium",
|
|
970
|
+
color: "primary",
|
|
971
|
+
onClick: openPreferences,
|
|
972
|
+
sx: {
|
|
973
|
+
...getPosition(),
|
|
974
|
+
backgroundColor: safeTheme.palette.primary.main,
|
|
975
|
+
"&:hover": {
|
|
976
|
+
backgroundColor: safeTheme.palette.primary.dark
|
|
977
|
+
},
|
|
978
|
+
transition: `all ${safeTheme.transitions.duration.short}ms`
|
|
979
|
+
},
|
|
980
|
+
"aria-label": tooltipText,
|
|
981
|
+
...FabProps,
|
|
982
|
+
children: icon
|
|
983
|
+
}
|
|
984
|
+
) });
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/context/ConsentContext.tsx
|
|
988
|
+
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
989
|
+
var PreferencesModal = React5.lazy(
|
|
990
|
+
() => import("./PreferencesModal-7RSEEVUK.js").then((m) => ({
|
|
991
|
+
default: m.PreferencesModal
|
|
992
|
+
}))
|
|
993
|
+
);
|
|
994
|
+
function createFullConsentState(consented, preferences, source, projectConfig, isModalOpen = false, existingState) {
|
|
995
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
996
|
+
return {
|
|
997
|
+
version: "1.0",
|
|
998
|
+
consented,
|
|
999
|
+
preferences,
|
|
1000
|
+
consentDate: existingState?.consentDate || now,
|
|
1001
|
+
lastUpdate: now,
|
|
1002
|
+
source,
|
|
1003
|
+
projectConfig,
|
|
1004
|
+
isModalOpen
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
var DEFAULT_TEXTS = {
|
|
1008
|
+
// Textos básicos
|
|
1009
|
+
bannerMessage: "Utilizamos cookies para melhorar sua experi\xEAncia.",
|
|
1010
|
+
acceptAll: "Aceitar todos",
|
|
1011
|
+
declineAll: "Recusar",
|
|
1012
|
+
preferences: "Prefer\xEAncias",
|
|
1013
|
+
policyLink: "Saiba mais",
|
|
1014
|
+
modalTitle: "Prefer\xEAncias de Cookies",
|
|
1015
|
+
modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
|
|
1016
|
+
save: "Salvar prefer\xEAncias",
|
|
1017
|
+
necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)",
|
|
1018
|
+
// Textos adicionais para UI customizada
|
|
1019
|
+
preferencesButton: "Configurar Cookies",
|
|
1020
|
+
preferencesTitle: "Gerenciar Prefer\xEAncias de Cookies",
|
|
1021
|
+
preferencesDescription: "Escolha quais tipos de cookies voc\xEA permite que sejam utilizados.",
|
|
1022
|
+
close: "Fechar",
|
|
1023
|
+
accept: "Aceitar",
|
|
1024
|
+
reject: "Rejeitar",
|
|
1025
|
+
// Textos ANPD expandidos (opcionais)
|
|
1026
|
+
brandingPoweredBy: "fornecido por",
|
|
1027
|
+
controllerInfo: void 0,
|
|
1028
|
+
// Exibido se definido
|
|
1029
|
+
dataTypes: void 0,
|
|
1030
|
+
// Exibido se definido
|
|
1031
|
+
thirdPartySharing: void 0,
|
|
1032
|
+
// Exibido se definido
|
|
1033
|
+
userRights: void 0,
|
|
1034
|
+
// Exibido se definido
|
|
1035
|
+
contactInfo: void 0,
|
|
1036
|
+
// Exibido se definido
|
|
1037
|
+
retentionPeriod: void 0,
|
|
1038
|
+
// Exibido se definido
|
|
1039
|
+
lawfulBasis: void 0,
|
|
1040
|
+
// Exibido se definido
|
|
1041
|
+
transferCountries: void 0
|
|
1042
|
+
// Exibido se definido
|
|
1043
|
+
};
|
|
1044
|
+
function reducer(state, action) {
|
|
1045
|
+
logger.consentState(action.type, state);
|
|
1046
|
+
switch (action.type) {
|
|
1047
|
+
case "ACCEPT_ALL": {
|
|
1048
|
+
const prefs = createProjectPreferences(action.config, true);
|
|
1049
|
+
const newState = createFullConsentState(true, prefs, "banner", action.config, false, state);
|
|
1050
|
+
logger.info("User accepted all cookies", {
|
|
1051
|
+
preferences: newState.preferences
|
|
1052
|
+
});
|
|
1053
|
+
return newState;
|
|
1054
|
+
}
|
|
1055
|
+
case "REJECT_ALL": {
|
|
1056
|
+
const prefs = createProjectPreferences(action.config, false);
|
|
1057
|
+
const newState = createFullConsentState(true, prefs, "banner", action.config, false, state);
|
|
1058
|
+
logger.info("User rejected all cookies", {
|
|
1059
|
+
preferences: newState.preferences
|
|
1060
|
+
});
|
|
1061
|
+
return newState;
|
|
1062
|
+
}
|
|
1063
|
+
case "SET_CATEGORY":
|
|
1064
|
+
logger.debug("Category preference changed", {
|
|
1065
|
+
category: action.category,
|
|
1066
|
+
value: action.value
|
|
1067
|
+
});
|
|
1068
|
+
return {
|
|
1069
|
+
...state,
|
|
1070
|
+
preferences: {
|
|
1071
|
+
...state.preferences,
|
|
1072
|
+
[action.category]: action.value
|
|
1073
|
+
},
|
|
1074
|
+
lastUpdate: (/* @__PURE__ */ new Date()).toISOString()
|
|
1075
|
+
};
|
|
1076
|
+
case "SET_PREFERENCES":
|
|
1077
|
+
logger.info("Preferences saved", { preferences: action.preferences });
|
|
1078
|
+
return createFullConsentState(true, action.preferences, "modal", action.config, false, state);
|
|
1079
|
+
case "OPEN_MODAL":
|
|
1080
|
+
return { ...state, isModalOpen: true };
|
|
1081
|
+
case "CLOSE_MODAL":
|
|
1082
|
+
return createFullConsentState(true, state.preferences, "modal", action.config, false, state);
|
|
1083
|
+
case "RESET": {
|
|
1084
|
+
return createFullConsentState(
|
|
1085
|
+
false,
|
|
1086
|
+
createProjectPreferences(action.config),
|
|
1087
|
+
"programmatic",
|
|
1088
|
+
action.config,
|
|
1089
|
+
false
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
case "HYDRATE": {
|
|
1093
|
+
const validatedPreferences = validateProjectPreferences(
|
|
1094
|
+
action.state.preferences,
|
|
1095
|
+
action.config
|
|
1096
|
+
);
|
|
1097
|
+
return {
|
|
1098
|
+
...action.state,
|
|
1099
|
+
preferences: validatedPreferences,
|
|
1100
|
+
isModalOpen: false
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
default:
|
|
1104
|
+
return state;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
var StateCtx = React5.createContext(null);
|
|
1108
|
+
var ActionsCtx = React5.createContext(null);
|
|
1109
|
+
var TextsCtx = React5.createContext(DEFAULT_TEXTS);
|
|
1110
|
+
var HydrationCtx = React5.createContext(false);
|
|
1111
|
+
function ConsentProvider({
|
|
1112
|
+
initialState,
|
|
1113
|
+
categories,
|
|
1114
|
+
texts: textsProp,
|
|
1115
|
+
theme,
|
|
1116
|
+
designTokens,
|
|
1117
|
+
PreferencesModalComponent,
|
|
1118
|
+
preferencesModalProps = {},
|
|
1119
|
+
CookieBannerComponent,
|
|
1120
|
+
cookieBannerProps = {},
|
|
1121
|
+
FloatingPreferencesButtonComponent,
|
|
1122
|
+
floatingPreferencesButtonProps = {},
|
|
1123
|
+
disableFloatingPreferencesButton = false,
|
|
1124
|
+
hideBranding = false,
|
|
1125
|
+
onConsentGiven,
|
|
1126
|
+
onPreferencesSaved,
|
|
1127
|
+
cookie: cookieOpts,
|
|
1128
|
+
disableDeveloperGuidance,
|
|
1129
|
+
children
|
|
1130
|
+
}) {
|
|
1131
|
+
const texts = React5.useMemo(() => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }), [textsProp]);
|
|
1132
|
+
const cookie = React5.useMemo(
|
|
1133
|
+
() => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
|
|
1134
|
+
[cookieOpts]
|
|
1135
|
+
);
|
|
1136
|
+
const appliedTheme = React5.useMemo(() => theme || defaultConsentTheme, [theme]);
|
|
1137
|
+
const finalCategoriesConfig = React5.useMemo(() => {
|
|
1138
|
+
if (categories) return categories;
|
|
1139
|
+
return DEFAULT_PROJECT_CATEGORIES;
|
|
1140
|
+
}, [categories]);
|
|
1141
|
+
useDeveloperGuidance(finalCategoriesConfig, disableDeveloperGuidance);
|
|
1142
|
+
const boot = React5.useMemo(() => {
|
|
1143
|
+
if (initialState) return { ...initialState, isModalOpen: false };
|
|
1144
|
+
return createFullConsentState(
|
|
1145
|
+
false,
|
|
1146
|
+
createProjectPreferences(finalCategoriesConfig),
|
|
1147
|
+
"banner",
|
|
1148
|
+
finalCategoriesConfig,
|
|
1149
|
+
false
|
|
1150
|
+
);
|
|
1151
|
+
}, [initialState, finalCategoriesConfig]);
|
|
1152
|
+
const [state, dispatch] = React5.useReducer(reducer, boot);
|
|
1153
|
+
const [isHydrated, setIsHydrated] = React5.useState(false);
|
|
1154
|
+
React5.useEffect(() => {
|
|
1155
|
+
if (!initialState) {
|
|
1156
|
+
const saved = readConsentCookie(cookie.name);
|
|
1157
|
+
if (saved?.consented) {
|
|
1158
|
+
dispatch({
|
|
1159
|
+
type: "HYDRATE",
|
|
1160
|
+
state: saved,
|
|
1161
|
+
config: finalCategoriesConfig
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
setIsHydrated(true);
|
|
1166
|
+
}, [cookie.name, initialState, finalCategoriesConfig]);
|
|
1167
|
+
React5.useEffect(() => {
|
|
1168
|
+
if (state.consented) writeConsentCookie(state, finalCategoriesConfig, cookie);
|
|
1169
|
+
}, [state, cookie, finalCategoriesConfig]);
|
|
1170
|
+
const prevConsented = React5.useRef(state.consented);
|
|
1171
|
+
React5.useEffect(() => {
|
|
1172
|
+
if (!prevConsented.current && state.consented && onConsentGiven) {
|
|
1173
|
+
setTimeout(() => onConsentGiven(state), 150);
|
|
1174
|
+
}
|
|
1175
|
+
prevConsented.current = state.consented;
|
|
1176
|
+
}, [state, onConsentGiven]);
|
|
1177
|
+
const api = React5.useMemo(() => {
|
|
1178
|
+
const acceptAll = () => dispatch({ type: "ACCEPT_ALL", config: finalCategoriesConfig });
|
|
1179
|
+
const rejectAll = () => dispatch({ type: "REJECT_ALL", config: finalCategoriesConfig });
|
|
1180
|
+
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
1181
|
+
const setPreferences = (preferences) => {
|
|
1182
|
+
dispatch({
|
|
1183
|
+
type: "SET_PREFERENCES",
|
|
1184
|
+
preferences,
|
|
1185
|
+
config: finalCategoriesConfig
|
|
1186
|
+
});
|
|
1187
|
+
if (onPreferencesSaved) {
|
|
1188
|
+
setTimeout(() => onPreferencesSaved(preferences), 150);
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
const openPreferences = () => dispatch({ type: "OPEN_MODAL" });
|
|
1192
|
+
const closePreferences = () => dispatch({ type: "CLOSE_MODAL", config: finalCategoriesConfig });
|
|
1193
|
+
const resetConsent = () => {
|
|
1194
|
+
removeConsentCookie(cookie);
|
|
1195
|
+
dispatch({ type: "RESET", config: finalCategoriesConfig });
|
|
1196
|
+
};
|
|
1197
|
+
return {
|
|
1198
|
+
consented: !!state.consented,
|
|
1199
|
+
preferences: state.preferences,
|
|
1200
|
+
isModalOpen: state.isModalOpen,
|
|
1201
|
+
acceptAll,
|
|
1202
|
+
rejectAll,
|
|
1203
|
+
setPreference,
|
|
1204
|
+
setPreferences,
|
|
1205
|
+
openPreferences,
|
|
1206
|
+
closePreferences,
|
|
1207
|
+
resetConsent
|
|
1208
|
+
};
|
|
1209
|
+
}, [state, cookie, finalCategoriesConfig, onPreferencesSaved]);
|
|
1210
|
+
React5.useEffect(() => {
|
|
1211
|
+
_registerGlobalOpenPreferences(api.openPreferences);
|
|
1212
|
+
return () => _unregisterGlobalOpenPreferences();
|
|
1213
|
+
}, [api.openPreferences]);
|
|
1214
|
+
return /* @__PURE__ */ jsx7(SafeThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ jsx7(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx7(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ jsx7(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ jsx7(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ jsx7(DesignProvider, { tokens: designTokens, children: /* @__PURE__ */ jsxs3(
|
|
1215
|
+
CategoriesProvider,
|
|
1216
|
+
{
|
|
1217
|
+
config: finalCategoriesConfig,
|
|
1218
|
+
disableDeveloperGuidance,
|
|
1219
|
+
children: [
|
|
1220
|
+
children,
|
|
1221
|
+
/* @__PURE__ */ jsx7(React5.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ jsx7(
|
|
1222
|
+
PreferencesModalComponent,
|
|
1223
|
+
{
|
|
1224
|
+
preferences: api.preferences,
|
|
1225
|
+
setPreferences: api.setPreferences,
|
|
1226
|
+
closePreferences: api.closePreferences,
|
|
1227
|
+
isModalOpen: api.isModalOpen,
|
|
1228
|
+
texts,
|
|
1229
|
+
...preferencesModalProps
|
|
1230
|
+
}
|
|
1231
|
+
) : /* @__PURE__ */ jsx7(PreferencesModal, { hideBranding }) }),
|
|
1232
|
+
!state.consented && isHydrated && (CookieBannerComponent ? /* @__PURE__ */ jsx7(
|
|
1233
|
+
CookieBannerComponent,
|
|
1234
|
+
{
|
|
1235
|
+
consented: api.consented,
|
|
1236
|
+
acceptAll: api.acceptAll,
|
|
1237
|
+
rejectAll: api.rejectAll,
|
|
1238
|
+
openPreferences: api.openPreferences,
|
|
1239
|
+
texts,
|
|
1240
|
+
...cookieBannerProps
|
|
1241
|
+
}
|
|
1242
|
+
) : /* @__PURE__ */ jsx7(CookieBanner, {})),
|
|
1243
|
+
state.consented && !disableFloatingPreferencesButton && (FloatingPreferencesButtonComponent ? /* @__PURE__ */ jsx7(
|
|
1244
|
+
FloatingPreferencesButtonComponent,
|
|
1245
|
+
{
|
|
1246
|
+
openPreferences: api.openPreferences,
|
|
1247
|
+
consented: api.consented,
|
|
1248
|
+
...floatingPreferencesButtonProps
|
|
1249
|
+
}
|
|
1250
|
+
) : /* @__PURE__ */ jsx7(FloatingPreferencesButton, {}))
|
|
1251
|
+
]
|
|
1252
|
+
}
|
|
1253
|
+
) }) }) }) }) }) });
|
|
1254
|
+
}
|
|
1255
|
+
function useConsentStateInternal() {
|
|
1256
|
+
const ctx = React5.useContext(StateCtx);
|
|
1257
|
+
if (!ctx) throw new Error("useConsentState must be used within ConsentProvider");
|
|
1258
|
+
return ctx;
|
|
1259
|
+
}
|
|
1260
|
+
function useConsentActionsInternal() {
|
|
1261
|
+
const ctx = React5.useContext(ActionsCtx);
|
|
1262
|
+
if (!ctx) throw new Error("useConsentActions must be used within ConsentProvider");
|
|
1263
|
+
return ctx;
|
|
1264
|
+
}
|
|
1265
|
+
function useConsentTextsInternal() {
|
|
1266
|
+
const ctx = React5.useContext(TextsCtx);
|
|
1267
|
+
return ctx;
|
|
1268
|
+
}
|
|
1269
|
+
function useConsentHydrationInternal() {
|
|
1270
|
+
return React5.useContext(HydrationCtx);
|
|
1271
|
+
}
|
|
1272
|
+
var defaultTexts = DEFAULT_TEXTS;
|
|
1273
|
+
|
|
1274
|
+
// src/hooks/useConsent.ts
|
|
1275
|
+
function useConsent() {
|
|
1276
|
+
const state = useConsentStateInternal();
|
|
1277
|
+
const actions = useConsentActionsInternal();
|
|
1278
|
+
return {
|
|
1279
|
+
consented: state.consented,
|
|
1280
|
+
preferences: state.preferences,
|
|
1281
|
+
isModalOpen: state.isModalOpen,
|
|
1282
|
+
acceptAll: actions.acceptAll,
|
|
1283
|
+
rejectAll: actions.rejectAll,
|
|
1284
|
+
setPreference: actions.setPreference,
|
|
1285
|
+
setPreferences: actions.setPreferences,
|
|
1286
|
+
openPreferences: actions.openPreferences,
|
|
1287
|
+
closePreferences: actions.closePreferences,
|
|
1288
|
+
resetConsent: actions.resetConsent
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
function useConsentTexts() {
|
|
1292
|
+
return useConsentTextsInternal();
|
|
1293
|
+
}
|
|
1294
|
+
function useConsentHydration() {
|
|
1295
|
+
return useConsentHydrationInternal();
|
|
1296
|
+
}
|
|
1297
|
+
function useOpenPreferencesModal() {
|
|
1298
|
+
const { openPreferences } = useConsent();
|
|
1299
|
+
return openPreferences;
|
|
1300
|
+
}
|
|
1301
|
+
var globalOpenPreferences = null;
|
|
1302
|
+
function openPreferencesModal() {
|
|
1303
|
+
if (globalOpenPreferences) {
|
|
1304
|
+
globalOpenPreferences();
|
|
1305
|
+
} else {
|
|
1306
|
+
logger.warn(
|
|
1307
|
+
"openPreferencesModal: ConsentProvider n\xE3o foi inicializado ou n\xE3o est\xE1 dispon\xEDvel."
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
function _registerGlobalOpenPreferences(openPreferences) {
|
|
1312
|
+
globalOpenPreferences = openPreferences;
|
|
1313
|
+
}
|
|
1314
|
+
function _unregisterGlobalOpenPreferences() {
|
|
1315
|
+
globalOpenPreferences = null;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
// src/components/PreferencesModal.tsx
|
|
1319
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1320
|
+
function PreferencesModal2({
|
|
1321
|
+
DialogProps: DialogProps2,
|
|
1322
|
+
hideBranding = false
|
|
1323
|
+
}) {
|
|
1324
|
+
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
1325
|
+
const texts = useConsentTexts();
|
|
1326
|
+
const { toggleableCategories } = useCategories();
|
|
1327
|
+
const [tempPreferences, setTempPreferences] = useState2(() => {
|
|
1328
|
+
const initialPrefs = { necessary: true };
|
|
1329
|
+
toggleableCategories.forEach((category) => {
|
|
1330
|
+
initialPrefs[category.id] = preferences[category.id] ?? false;
|
|
1331
|
+
});
|
|
1332
|
+
return initialPrefs;
|
|
1333
|
+
});
|
|
1334
|
+
useEffect3(() => {
|
|
1335
|
+
if (isModalOpen) {
|
|
1336
|
+
const syncedPrefs = { necessary: true };
|
|
1337
|
+
toggleableCategories.forEach((category) => {
|
|
1338
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
1339
|
+
});
|
|
1340
|
+
setTempPreferences(syncedPrefs);
|
|
1341
|
+
}
|
|
1342
|
+
}, [isModalOpen, preferences, toggleableCategories]);
|
|
1343
|
+
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
1344
|
+
const handleSave = () => {
|
|
1345
|
+
setPreferences(tempPreferences);
|
|
1346
|
+
};
|
|
1347
|
+
const handleCancel = () => {
|
|
1348
|
+
setTempPreferences(preferences);
|
|
1349
|
+
closePreferences();
|
|
1350
|
+
};
|
|
1351
|
+
return /* @__PURE__ */ jsxs4(Dialog, { "aria-labelledby": "cookie-pref-title", open, onClose: handleCancel, ...DialogProps2, children: [
|
|
1352
|
+
/* @__PURE__ */ jsx8(DialogTitle, { id: "cookie-pref-title", children: texts.modalTitle }),
|
|
1353
|
+
/* @__PURE__ */ jsxs4(DialogContent, { dividers: true, children: [
|
|
1354
|
+
/* @__PURE__ */ jsx8(Typography3, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
1355
|
+
/* @__PURE__ */ jsxs4(FormGroup, { children: [
|
|
1356
|
+
toggleableCategories.map((category) => /* @__PURE__ */ jsx8(
|
|
1357
|
+
FormControlLabel,
|
|
1358
|
+
{
|
|
1359
|
+
control: /* @__PURE__ */ jsx8(
|
|
1360
|
+
Switch,
|
|
1361
|
+
{
|
|
1362
|
+
checked: tempPreferences[category.id] ?? false,
|
|
1363
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
1364
|
+
...prev,
|
|
1365
|
+
[category.id]: e.target.checked
|
|
1366
|
+
}))
|
|
1367
|
+
}
|
|
1368
|
+
),
|
|
1369
|
+
label: `${category.name} - ${category.description}`
|
|
1370
|
+
},
|
|
1371
|
+
category.id
|
|
1372
|
+
)),
|
|
1373
|
+
/* @__PURE__ */ jsx8(FormControlLabel, { control: /* @__PURE__ */ jsx8(Switch, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn })
|
|
1374
|
+
] })
|
|
1375
|
+
] }),
|
|
1376
|
+
/* @__PURE__ */ jsxs4(DialogActions, { children: [
|
|
1377
|
+
/* @__PURE__ */ jsx8(Button2, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
1378
|
+
/* @__PURE__ */ jsx8(Button2, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
1379
|
+
] }),
|
|
1380
|
+
!hideBranding && /* @__PURE__ */ jsx8(Branding, { variant: "modal" })
|
|
1381
|
+
] });
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
export {
|
|
1385
|
+
DEFAULT_PROJECT_CATEGORIES,
|
|
1386
|
+
analyzeDeveloperConfiguration,
|
|
1387
|
+
useCategories,
|
|
1388
|
+
useCategoryStatus,
|
|
1389
|
+
LogLevel,
|
|
1390
|
+
logger,
|
|
1391
|
+
setDebugLogging,
|
|
1392
|
+
createProjectPreferences,
|
|
1393
|
+
validateProjectPreferences,
|
|
1394
|
+
getAllProjectCategories,
|
|
1395
|
+
defaultConsentTheme,
|
|
1396
|
+
CookieBanner,
|
|
1397
|
+
FloatingPreferencesButton,
|
|
1398
|
+
ConsentProvider,
|
|
1399
|
+
defaultTexts,
|
|
1400
|
+
useConsent,
|
|
1401
|
+
useConsentTexts,
|
|
1402
|
+
useConsentHydration,
|
|
1403
|
+
useOpenPreferencesModal,
|
|
1404
|
+
openPreferencesModal,
|
|
1405
|
+
PreferencesModal2 as PreferencesModal
|
|
1406
|
+
};
|