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
package/dist/index.cjs
CHANGED
|
@@ -50,7 +50,6 @@ function analyzeDeveloperConfiguration(config) {
|
|
|
50
50
|
description: "Essenciais para funcionamento b\xE1sico do site",
|
|
51
51
|
essential: true,
|
|
52
52
|
uiRequired: false
|
|
53
|
-
// Não precisa de toggle (sempre ativo)
|
|
54
53
|
});
|
|
55
54
|
const enabledCategories = finalConfig.enabledCategories || [];
|
|
56
55
|
const categoryNames = {
|
|
@@ -84,13 +83,10 @@ function analyzeDeveloperConfiguration(config) {
|
|
|
84
83
|
description: categoryInfo.description,
|
|
85
84
|
essential: false,
|
|
86
85
|
uiRequired: true
|
|
87
|
-
// Precisa de toggle na UI
|
|
88
86
|
});
|
|
89
87
|
}
|
|
90
88
|
});
|
|
91
|
-
const totalToggleable = guidance.activeCategoriesInfo.filter(
|
|
92
|
-
(c) => c.uiRequired
|
|
93
|
-
).length;
|
|
89
|
+
const totalToggleable = guidance.activeCategoriesInfo.filter((c) => c.uiRequired).length;
|
|
94
90
|
if (totalToggleable === 0) {
|
|
95
91
|
guidance.suggestions.push(
|
|
96
92
|
'Apenas cookies necess\xE1rios est\xE3o configurados. Para compliance completo LGPD, considere adicionar categorias como "analytics" ou "functional" conforme uso real.'
|
|
@@ -98,78 +94,66 @@ function analyzeDeveloperConfiguration(config) {
|
|
|
98
94
|
}
|
|
99
95
|
if (totalToggleable > 5) {
|
|
100
96
|
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.`
|
|
97
|
+
`${totalToggleable} categorias opcionais detectadas. UI com muitas op\xE7\xF5es pode prejudicar experi\xEAncia do usu\xE1rio. Considere agrupar categorias similares.`
|
|
103
98
|
);
|
|
104
99
|
}
|
|
105
100
|
return guidance;
|
|
106
101
|
}
|
|
107
102
|
function logDeveloperGuidance(guidance, disableGuidanceProp) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// 1. NODE_ENV de bundlers (Vite, webpack, etc.)
|
|
113
|
-
typeof globalThis.process !== "undefined" && globalThis.process.env?.NODE_ENV === "production" || // 2. Flag customizada para desabilitar logs
|
|
114
|
-
typeof globalThis !== "undefined" && globalThis.__LGPD_PRODUCTION__ === true || // 3. Flag de desenvolvimento desabilitada via window global (legado)
|
|
115
|
-
typeof window !== "undefined" && window.__LGPD_DISABLE_GUIDANCE__ === true
|
|
116
|
-
);
|
|
117
|
-
if (isProduction) return;
|
|
103
|
+
const nodeEnv = typeof globalThis.process !== "undefined" ? globalThis.process.env?.NODE_ENV : void 0;
|
|
104
|
+
const isProd = nodeEnv === "production" || globalThis.__LGPD_PRODUCTION__ === true && typeof globalThis !== "undefined";
|
|
105
|
+
const isDisabled = !!disableGuidanceProp || globalThis.__LGPD_DISABLE_GUIDANCE__ === true && typeof globalThis !== "undefined";
|
|
106
|
+
if (isProd || isDisabled) return;
|
|
118
107
|
const PREFIX = "[\u{1F36A} LGPD-CONSENT]";
|
|
119
108
|
if (guidance.warnings.length > 0) {
|
|
120
109
|
console.group(`${PREFIX} \u26A0\uFE0F Avisos de Configura\xE7\xE3o`);
|
|
121
|
-
guidance.warnings.forEach((
|
|
110
|
+
guidance.warnings.forEach((msg) => console.warn(`${PREFIX} ${msg}`));
|
|
122
111
|
console.groupEnd();
|
|
123
112
|
}
|
|
124
113
|
if (guidance.suggestions.length > 0) {
|
|
125
114
|
console.group(`${PREFIX} \u{1F4A1} Sugest\xF5es`);
|
|
126
|
-
guidance.suggestions.forEach(
|
|
127
|
-
(suggestion) => console.info(`${PREFIX} ${suggestion}`)
|
|
128
|
-
);
|
|
115
|
+
guidance.suggestions.forEach((msg) => console.info(`${PREFIX} ${msg}`));
|
|
129
116
|
console.groupEnd();
|
|
130
117
|
}
|
|
131
118
|
if (guidance.usingDefaults) {
|
|
132
119
|
console.warn(
|
|
133
|
-
// Changed from console.info to console.warn
|
|
134
120
|
`${PREFIX} \u{1F4CB} Usando configura\xE7\xE3o padr\xE3o. Para personalizar, use a prop "categories" no ConsentProvider.`
|
|
135
121
|
);
|
|
136
122
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
123
|
+
const rows = guidance.activeCategoriesInfo.map((cat) => ({
|
|
124
|
+
ID: cat.id,
|
|
125
|
+
Nome: cat.name,
|
|
126
|
+
"Toggle UI?": cat.uiRequired ? "\u2705 SIM" : "\u274C N\xC3O (sempre ativo)",
|
|
127
|
+
"Essencial?": cat.essential ? "\u{1F512} SIM" : "\u2699\uFE0F N\xC3O"
|
|
128
|
+
}));
|
|
129
|
+
if (typeof console.table === "function") {
|
|
130
|
+
console.group(`${PREFIX} \u{1F527} Categorias Ativas (para UI customizada)`);
|
|
131
|
+
console.table(rows);
|
|
132
|
+
console.info(`${PREFIX} \u2139\uFE0F Use estes dados para criar componentes customizados adequados.`);
|
|
133
|
+
console.groupEnd();
|
|
134
|
+
} else {
|
|
135
|
+
console.log(`${PREFIX} \u{1F527} Categorias Ativas (para UI customizada)`, rows);
|
|
136
|
+
console.info(`${PREFIX} \u2139\uFE0F Use estes dados para criar componentes customizados adequados.`);
|
|
137
|
+
}
|
|
150
138
|
}
|
|
151
139
|
function useDeveloperGuidance(config, disableGuidanceProp) {
|
|
152
|
-
const guidance =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (disableGuidanceProp === true) {
|
|
159
|
-
return;
|
|
140
|
+
const guidance = import_react.default.useMemo(() => {
|
|
141
|
+
return analyzeDeveloperConfiguration(config);
|
|
142
|
+
}, [config]);
|
|
143
|
+
import_react.default.useEffect(() => {
|
|
144
|
+
if (!disableGuidanceProp) {
|
|
145
|
+
logDeveloperGuidance(guidance, disableGuidanceProp);
|
|
160
146
|
}
|
|
161
|
-
|
|
162
|
-
}, [guidance, stringifiedConfig, disableGuidanceProp]);
|
|
147
|
+
}, [guidance, disableGuidanceProp]);
|
|
163
148
|
return guidance;
|
|
164
149
|
}
|
|
165
|
-
var
|
|
150
|
+
var import_react, DEFAULT_PROJECT_CATEGORIES;
|
|
166
151
|
var init_developerGuidance = __esm({
|
|
167
152
|
"src/utils/developerGuidance.ts"() {
|
|
168
153
|
"use strict";
|
|
169
|
-
|
|
154
|
+
import_react = __toESM(require("react"), 1);
|
|
170
155
|
DEFAULT_PROJECT_CATEGORIES = {
|
|
171
156
|
enabledCategories: ["analytics"]
|
|
172
|
-
// Só analytics além de necessary
|
|
173
157
|
};
|
|
174
158
|
}
|
|
175
159
|
});
|
|
@@ -178,15 +162,12 @@ var init_developerGuidance = __esm({
|
|
|
178
162
|
function CategoriesProvider({
|
|
179
163
|
children,
|
|
180
164
|
config,
|
|
181
|
-
// NOVO: configuração completa
|
|
182
165
|
disableDeveloperGuidance
|
|
183
166
|
}) {
|
|
184
167
|
const contextValue = React2.useMemo(() => {
|
|
185
168
|
const finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
186
169
|
const guidance = analyzeDeveloperConfiguration(config);
|
|
187
|
-
const toggleableCategories = guidance.activeCategoriesInfo.filter(
|
|
188
|
-
(cat) => cat.uiRequired
|
|
189
|
-
);
|
|
170
|
+
const toggleableCategories = guidance.activeCategoriesInfo.filter((cat) => cat.uiRequired);
|
|
190
171
|
return {
|
|
191
172
|
config: finalConfig,
|
|
192
173
|
guidance,
|
|
@@ -226,30 +207,297 @@ var init_CategoriesContext = __esm({
|
|
|
226
207
|
React2 = __toESM(require("react"), 1);
|
|
227
208
|
init_developerGuidance();
|
|
228
209
|
import_jsx_runtime = require("react/jsx-runtime");
|
|
229
|
-
CategoriesContext = React2.createContext(
|
|
230
|
-
|
|
231
|
-
|
|
210
|
+
CategoriesContext = React2.createContext(null);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// src/utils/SafeThemeProvider.tsx
|
|
215
|
+
function SafeThemeProvider({ theme, children }) {
|
|
216
|
+
const safeTheme = React3.useMemo(() => createSafeTheme(theme), [theme]);
|
|
217
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_styles.ThemeProvider, { theme: safeTheme, children });
|
|
218
|
+
}
|
|
219
|
+
var React3, import_styles, import_jsx_runtime2, createSafeTheme;
|
|
220
|
+
var init_SafeThemeProvider = __esm({
|
|
221
|
+
"src/utils/SafeThemeProvider.tsx"() {
|
|
222
|
+
"use strict";
|
|
223
|
+
React3 = __toESM(require("react"), 1);
|
|
224
|
+
import_styles = require("@mui/material/styles");
|
|
225
|
+
import_jsx_runtime2 = require("react/jsx-runtime");
|
|
226
|
+
createSafeTheme = (userTheme) => {
|
|
227
|
+
const baseTheme = (0, import_styles.createTheme)({
|
|
228
|
+
palette: {
|
|
229
|
+
primary: {
|
|
230
|
+
main: "#1976d2",
|
|
231
|
+
dark: "#1565c0",
|
|
232
|
+
light: "#42a5f5",
|
|
233
|
+
contrastText: "#ffffff"
|
|
234
|
+
},
|
|
235
|
+
secondary: {
|
|
236
|
+
main: "#dc004e",
|
|
237
|
+
dark: "#9a0036",
|
|
238
|
+
light: "#e33371",
|
|
239
|
+
contrastText: "#ffffff"
|
|
240
|
+
},
|
|
241
|
+
background: {
|
|
242
|
+
default: "#fafafa",
|
|
243
|
+
paper: "#ffffff"
|
|
244
|
+
},
|
|
245
|
+
text: {
|
|
246
|
+
primary: "#333333",
|
|
247
|
+
secondary: "#666666"
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
transitions: {
|
|
251
|
+
duration: {
|
|
252
|
+
shortest: 150,
|
|
253
|
+
shorter: 200,
|
|
254
|
+
short: 250,
|
|
255
|
+
standard: 300,
|
|
256
|
+
complex: 375,
|
|
257
|
+
enteringScreen: 225,
|
|
258
|
+
leavingScreen: 195
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
if (!userTheme) {
|
|
263
|
+
return baseTheme;
|
|
264
|
+
}
|
|
265
|
+
return (0, import_styles.createTheme)({
|
|
266
|
+
...baseTheme,
|
|
267
|
+
...userTheme,
|
|
268
|
+
palette: {
|
|
269
|
+
...baseTheme.palette,
|
|
270
|
+
...userTheme.palette,
|
|
271
|
+
primary: {
|
|
272
|
+
...baseTheme.palette.primary,
|
|
273
|
+
...userTheme.palette?.primary
|
|
274
|
+
},
|
|
275
|
+
secondary: {
|
|
276
|
+
...baseTheme.palette.secondary,
|
|
277
|
+
...userTheme.palette?.secondary
|
|
278
|
+
},
|
|
279
|
+
background: {
|
|
280
|
+
...baseTheme.palette.background,
|
|
281
|
+
...userTheme.palette?.background
|
|
282
|
+
},
|
|
283
|
+
text: {
|
|
284
|
+
...baseTheme.palette.text,
|
|
285
|
+
...userTheme.palette?.text
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
transitions: {
|
|
289
|
+
...baseTheme.transitions,
|
|
290
|
+
...userTheme.transitions,
|
|
291
|
+
duration: {
|
|
292
|
+
...baseTheme.transitions.duration,
|
|
293
|
+
...userTheme.transitions?.duration
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// src/utils/logger.ts
|
|
302
|
+
function setDebugLogging(enabled, level = 2 /* INFO */) {
|
|
303
|
+
logger.setEnabled(enabled);
|
|
304
|
+
logger.setLevel(level);
|
|
305
|
+
logger.info(`Debug logging ${enabled ? "enabled" : "disabled"} with level ${LogLevel[level]}`);
|
|
306
|
+
}
|
|
307
|
+
var LogLevel, _ConsentLogger, ConsentLogger, logger;
|
|
308
|
+
var init_logger = __esm({
|
|
309
|
+
"src/utils/logger.ts"() {
|
|
310
|
+
"use strict";
|
|
311
|
+
LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
312
|
+
LogLevel2[LogLevel2["ERROR"] = 0] = "ERROR";
|
|
313
|
+
LogLevel2[LogLevel2["WARN"] = 1] = "WARN";
|
|
314
|
+
LogLevel2[LogLevel2["INFO"] = 2] = "INFO";
|
|
315
|
+
LogLevel2[LogLevel2["DEBUG"] = 3] = "DEBUG";
|
|
316
|
+
return LogLevel2;
|
|
317
|
+
})(LogLevel || {});
|
|
318
|
+
_ConsentLogger = class _ConsentLogger {
|
|
319
|
+
constructor() {
|
|
320
|
+
this.enabled = _ConsentLogger.IS_DEVELOPMENT;
|
|
321
|
+
this.level = 2 /* INFO */;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Habilita ou desabilita o sistema de logging.
|
|
325
|
+
* @param {boolean} enabled Se `true`, os logs serão exibidos; caso contrário, serão suprimidos.
|
|
326
|
+
*/
|
|
327
|
+
setEnabled(enabled) {
|
|
328
|
+
this.enabled = enabled;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Define o nível mínimo de severidade para os logs.
|
|
332
|
+
* Mensagens com severidade menor que o nível definido não serão exibidas.
|
|
333
|
+
* @param {LogLevel} level O nível mínimo de severidade (ex: `LogLevel.DEBUG` para ver todos os logs).
|
|
334
|
+
*/
|
|
335
|
+
setLevel(level) {
|
|
336
|
+
this.level = level;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Registra uma mensagem de erro.
|
|
340
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
341
|
+
*/
|
|
342
|
+
error(...args) {
|
|
343
|
+
if (this.enabled && this.level >= 0 /* ERROR */) {
|
|
344
|
+
console.error(_ConsentLogger.LOG_PREFIX, "[ERROR]", ...args);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Registra uma mensagem de aviso.
|
|
349
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
350
|
+
*/
|
|
351
|
+
warn(...args) {
|
|
352
|
+
if (this.enabled && this.level >= 1 /* WARN */) {
|
|
353
|
+
console.warn(_ConsentLogger.LOG_PREFIX, "[WARN]", ...args);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Registra uma mensagem informativa.
|
|
358
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
359
|
+
*/
|
|
360
|
+
info(...args) {
|
|
361
|
+
if (this.enabled && this.level >= 2 /* INFO */) {
|
|
362
|
+
console.info(_ConsentLogger.LOG_PREFIX, "[INFO]", ...args);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Registra uma mensagem de depuração.
|
|
367
|
+
* @param {...any[]} args Os argumentos a serem logados.
|
|
368
|
+
*/
|
|
369
|
+
debug(...args) {
|
|
370
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
371
|
+
console.debug(_ConsentLogger.LOG_PREFIX, "[DEBUG]", ...args);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Inicia um grupo de logs no console.
|
|
376
|
+
* @param {...any[]} args Os argumentos para o título do grupo.
|
|
377
|
+
*/
|
|
378
|
+
group(...args) {
|
|
379
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
380
|
+
console.group(_ConsentLogger.LOG_PREFIX, ...args);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Finaliza o grupo de logs mais recente no console.
|
|
385
|
+
*/
|
|
386
|
+
groupEnd() {
|
|
387
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
388
|
+
console.groupEnd();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Exibe dados tabulares no console.
|
|
393
|
+
* @param {any} tabularData Os dados a serem exibidos na tabela.
|
|
394
|
+
* @param {string[]} [properties] Um array opcional de propriedades para exibir.
|
|
395
|
+
*/
|
|
396
|
+
table(tabularData, properties) {
|
|
397
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
398
|
+
console.table(tabularData, properties);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Registra informações sobre a compatibilidade do tema Material-UI.
|
|
403
|
+
* @param {any} themeInfo Objeto com informações do tema.
|
|
404
|
+
*/
|
|
405
|
+
themeCompatibility(themeInfo) {
|
|
406
|
+
this.debug("Theme compatibility check:", {
|
|
407
|
+
hasTheme: !!themeInfo,
|
|
408
|
+
hasPalette: !!themeInfo?.palette,
|
|
409
|
+
hasPrimary: !!themeInfo?.palette?.primary,
|
|
410
|
+
hasTransitions: !!themeInfo?.transitions,
|
|
411
|
+
hasDuration: !!themeInfo?.transitions?.duration
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Registra mudanças no estado de consentimento.
|
|
416
|
+
* @param {string} action A ação que causou a mudança de estado.
|
|
417
|
+
* @param {any} state O estado atual do consentimento.
|
|
418
|
+
*/
|
|
419
|
+
consentState(action, state) {
|
|
420
|
+
this.debug(`Consent state change [${action}]:`, {
|
|
421
|
+
consented: state.consented,
|
|
422
|
+
isModalOpen: state.isModalOpen,
|
|
423
|
+
preferencesCount: Object.keys(state.preferences || {}).length
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Registra operações de cookie (leitura, escrita, remoção).
|
|
428
|
+
* @param {'read' | 'write' | 'delete'} operation O tipo de operação de cookie.
|
|
429
|
+
* @param {string} cookieName O nome do cookie.
|
|
430
|
+
* @param {any} [data] Os dados do cookie, se aplicável.
|
|
431
|
+
*/
|
|
432
|
+
cookieOperation(operation, cookieName, data) {
|
|
433
|
+
this.debug(`Cookie ${operation}:`, {
|
|
434
|
+
name: cookieName,
|
|
435
|
+
hasData: !!data,
|
|
436
|
+
dataSize: data ? JSON.stringify(data).length : 0
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Registra a renderização de um componente.
|
|
441
|
+
* @param {string} componentName O nome do componente.
|
|
442
|
+
* @param {any} [props] As propriedades do componente.
|
|
443
|
+
*/
|
|
444
|
+
componentRender(componentName, props) {
|
|
445
|
+
this.debug(`Component render [${componentName}]:`, {
|
|
446
|
+
hasProps: !!props,
|
|
447
|
+
propsKeys: props ? Object.keys(props) : []
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Registra o status de carregamento de scripts de integração.
|
|
452
|
+
* @param {string} scriptName O nome do script.
|
|
453
|
+
* @param {'load' | 'remove'} action A ação realizada (carregar ou remover).
|
|
454
|
+
* @param {boolean} success Se a operação foi bem-sucedida.
|
|
455
|
+
*/
|
|
456
|
+
scriptIntegration(scriptName, action, success) {
|
|
457
|
+
this.info(`Script ${action} [${scriptName}]:`, success ? "SUCCESS" : "FAILED");
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Registra chamadas à API interna da biblioteca.
|
|
461
|
+
* @param {string} method O nome do método da API chamado.
|
|
462
|
+
* @param {any} [params] Os parâmetros passados para o método.
|
|
463
|
+
*/
|
|
464
|
+
apiUsage(method, params) {
|
|
465
|
+
this.debug(`API call [${method}]:`, params);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
_ConsentLogger.IS_DEVELOPMENT = typeof globalThis !== "undefined" && globalThis.process?.env?.NODE_ENV === "development";
|
|
469
|
+
_ConsentLogger.LOG_PREFIX = "[react-lgpd-consent]";
|
|
470
|
+
ConsentLogger = _ConsentLogger;
|
|
471
|
+
logger = new ConsentLogger();
|
|
232
472
|
}
|
|
233
473
|
});
|
|
234
474
|
|
|
235
475
|
// src/utils/cookieUtils.ts
|
|
236
476
|
function readConsentCookie(name = DEFAULT_COOKIE_OPTS.name) {
|
|
237
|
-
|
|
477
|
+
logger.debug("Reading consent cookie", { name });
|
|
478
|
+
if (typeof document === "undefined") {
|
|
479
|
+
logger.debug("Cookie read skipped: server-side environment");
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
238
482
|
const raw = import_js_cookie.default.get(name);
|
|
239
|
-
if (!raw)
|
|
483
|
+
if (!raw) {
|
|
484
|
+
logger.debug("No consent cookie found");
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
240
487
|
try {
|
|
241
488
|
const data = JSON.parse(raw);
|
|
489
|
+
logger.cookieOperation("read", name, data);
|
|
242
490
|
if (!data.version) {
|
|
491
|
+
logger.debug("Migrating legacy cookie format");
|
|
243
492
|
return migrateLegacyCookie(data);
|
|
244
493
|
}
|
|
245
494
|
if (data.version !== COOKIE_SCHEMA_VERSION) {
|
|
246
|
-
|
|
247
|
-
`[react-lgpd-consent] Cookie version mismatch: ${data.version} != ${COOKIE_SCHEMA_VERSION}`
|
|
248
|
-
);
|
|
495
|
+
logger.warn(`Cookie version mismatch: ${data.version} != ${COOKIE_SCHEMA_VERSION}`);
|
|
249
496
|
return null;
|
|
250
497
|
}
|
|
251
498
|
return data;
|
|
252
|
-
} catch {
|
|
499
|
+
} catch (error) {
|
|
500
|
+
logger.error("Error parsing consent cookie", error);
|
|
253
501
|
return null;
|
|
254
502
|
}
|
|
255
503
|
}
|
|
@@ -261,19 +509,19 @@ function migrateLegacyCookie(legacyData) {
|
|
|
261
509
|
consented: legacyData.consented || false,
|
|
262
510
|
preferences: legacyData.preferences || { necessary: true },
|
|
263
511
|
consentDate: now,
|
|
264
|
-
// Não temos o original, usar data atual
|
|
265
512
|
lastUpdate: now,
|
|
266
513
|
source: "banner",
|
|
267
|
-
// Assumir origem banner
|
|
268
514
|
isModalOpen: false
|
|
269
|
-
// Nunca persistir estado de UI
|
|
270
515
|
};
|
|
271
516
|
} catch {
|
|
272
517
|
return null;
|
|
273
518
|
}
|
|
274
519
|
}
|
|
275
520
|
function writeConsentCookie(state, config, opts, source = "banner") {
|
|
276
|
-
if (typeof document === "undefined")
|
|
521
|
+
if (typeof document === "undefined") {
|
|
522
|
+
logger.debug("Cookie write skipped: server-side environment");
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
277
525
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
278
526
|
const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
|
|
279
527
|
const cookieData = {
|
|
@@ -281,29 +529,39 @@ function writeConsentCookie(state, config, opts, source = "banner") {
|
|
|
281
529
|
consented: state.consented,
|
|
282
530
|
preferences: state.preferences,
|
|
283
531
|
consentDate: state.consentDate || now,
|
|
284
|
-
// Preservar data original ou usar atual
|
|
285
532
|
lastUpdate: now,
|
|
286
533
|
source,
|
|
287
534
|
projectConfig: config
|
|
288
|
-
// isModalOpen NÃO é persistido (campo de UI apenas)
|
|
289
535
|
};
|
|
536
|
+
logger.cookieOperation("write", o.name, cookieData);
|
|
290
537
|
import_js_cookie.default.set(o.name, JSON.stringify(cookieData), {
|
|
291
538
|
expires: o.maxAgeDays,
|
|
292
539
|
sameSite: o.sameSite,
|
|
293
540
|
secure: o.secure,
|
|
294
541
|
path: o.path
|
|
295
542
|
});
|
|
543
|
+
logger.info("Consent cookie saved", {
|
|
544
|
+
consented: cookieData.consented,
|
|
545
|
+
source: cookieData.source,
|
|
546
|
+
preferencesCount: Object.keys(cookieData.preferences).length
|
|
547
|
+
});
|
|
296
548
|
}
|
|
297
549
|
function removeConsentCookie(opts) {
|
|
298
|
-
if (typeof document === "undefined")
|
|
550
|
+
if (typeof document === "undefined") {
|
|
551
|
+
logger.debug("Cookie removal skipped: server-side environment");
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
299
554
|
const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
|
|
555
|
+
logger.cookieOperation("delete", o.name);
|
|
300
556
|
import_js_cookie.default.remove(o.name, { path: o.path });
|
|
557
|
+
logger.info("Consent cookie removed");
|
|
301
558
|
}
|
|
302
559
|
var import_js_cookie, DEFAULT_COOKIE_OPTS, COOKIE_SCHEMA_VERSION;
|
|
303
560
|
var init_cookieUtils = __esm({
|
|
304
561
|
"src/utils/cookieUtils.ts"() {
|
|
305
562
|
"use strict";
|
|
306
563
|
import_js_cookie = __toESM(require("js-cookie"), 1);
|
|
564
|
+
init_logger();
|
|
307
565
|
DEFAULT_COOKIE_OPTS = {
|
|
308
566
|
name: "cookieConsent",
|
|
309
567
|
maxAgeDays: 365,
|
|
@@ -342,6 +600,64 @@ function validateProjectPreferences(preferences, config) {
|
|
|
342
600
|
});
|
|
343
601
|
return validPreferences;
|
|
344
602
|
}
|
|
603
|
+
function getAllProjectCategories(config) {
|
|
604
|
+
const allCategories = [
|
|
605
|
+
{
|
|
606
|
+
id: "necessary",
|
|
607
|
+
name: "Necess\xE1rios",
|
|
608
|
+
description: "Cookies essenciais para funcionamento b\xE1sico do site",
|
|
609
|
+
essential: true
|
|
610
|
+
}
|
|
611
|
+
];
|
|
612
|
+
const enabledCategories = config?.enabledCategories || [];
|
|
613
|
+
enabledCategories.forEach((category) => {
|
|
614
|
+
if (category !== "necessary") {
|
|
615
|
+
allCategories.push(getDefaultCategoryDefinition(category));
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
return allCategories;
|
|
619
|
+
}
|
|
620
|
+
function getDefaultCategoryDefinition(category) {
|
|
621
|
+
const definitions = {
|
|
622
|
+
necessary: {
|
|
623
|
+
id: "necessary",
|
|
624
|
+
name: "Necess\xE1rios",
|
|
625
|
+
description: "Cookies essenciais para funcionamento b\xE1sico do site",
|
|
626
|
+
essential: true
|
|
627
|
+
},
|
|
628
|
+
analytics: {
|
|
629
|
+
id: "analytics",
|
|
630
|
+
name: "An\xE1lise e Estat\xEDsticas",
|
|
631
|
+
description: "Cookies para an\xE1lise de uso e estat\xEDsticas do site",
|
|
632
|
+
essential: false
|
|
633
|
+
},
|
|
634
|
+
functional: {
|
|
635
|
+
id: "functional",
|
|
636
|
+
name: "Funcionalidades",
|
|
637
|
+
description: "Cookies para funcionalidades extras como prefer\xEAncias e idioma",
|
|
638
|
+
essential: false
|
|
639
|
+
},
|
|
640
|
+
marketing: {
|
|
641
|
+
id: "marketing",
|
|
642
|
+
name: "Marketing e Publicidade",
|
|
643
|
+
description: "Cookies para publicidade direcionada e marketing",
|
|
644
|
+
essential: false
|
|
645
|
+
},
|
|
646
|
+
social: {
|
|
647
|
+
id: "social",
|
|
648
|
+
name: "Redes Sociais",
|
|
649
|
+
description: "Cookies para integra\xE7\xE3o com redes sociais e compartilhamento",
|
|
650
|
+
essential: false
|
|
651
|
+
},
|
|
652
|
+
personalization: {
|
|
653
|
+
id: "personalization",
|
|
654
|
+
name: "Personaliza\xE7\xE3o",
|
|
655
|
+
description: "Cookies para personaliza\xE7\xE3o de conte\xFAdo e experi\xEAncia",
|
|
656
|
+
essential: false
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
return definitions[category];
|
|
660
|
+
}
|
|
345
661
|
var init_categoryUtils = __esm({
|
|
346
662
|
"src/utils/categoryUtils.ts"() {
|
|
347
663
|
"use strict";
|
|
@@ -349,12 +665,12 @@ var init_categoryUtils = __esm({
|
|
|
349
665
|
});
|
|
350
666
|
|
|
351
667
|
// src/utils/theme.ts
|
|
352
|
-
var
|
|
668
|
+
var import_styles2, defaultConsentTheme;
|
|
353
669
|
var init_theme = __esm({
|
|
354
670
|
"src/utils/theme.ts"() {
|
|
355
671
|
"use strict";
|
|
356
|
-
|
|
357
|
-
defaultConsentTheme = (0,
|
|
672
|
+
import_styles2 = require("@mui/material/styles");
|
|
673
|
+
defaultConsentTheme = (0, import_styles2.createTheme)({
|
|
358
674
|
palette: {
|
|
359
675
|
primary: {
|
|
360
676
|
main: "#1976d2",
|
|
@@ -427,25 +743,26 @@ function DesignProvider({
|
|
|
427
743
|
tokens,
|
|
428
744
|
children
|
|
429
745
|
}) {
|
|
430
|
-
return /* @__PURE__ */ (0,
|
|
746
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DesignContext.Provider, { value: tokens, children });
|
|
431
747
|
}
|
|
432
748
|
function useDesignTokens() {
|
|
433
|
-
return
|
|
749
|
+
return React4.useContext(DesignContext);
|
|
434
750
|
}
|
|
435
|
-
var
|
|
751
|
+
var React4, import_jsx_runtime3, DesignContext;
|
|
436
752
|
var init_DesignContext = __esm({
|
|
437
753
|
"src/context/DesignContext.tsx"() {
|
|
438
754
|
"use strict";
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
DesignContext =
|
|
755
|
+
React4 = __toESM(require("react"), 1);
|
|
756
|
+
import_jsx_runtime3 = require("react/jsx-runtime");
|
|
757
|
+
DesignContext = React4.createContext(void 0);
|
|
442
758
|
}
|
|
443
759
|
});
|
|
444
760
|
|
|
445
761
|
// src/components/Branding.tsx
|
|
446
762
|
function Branding({ variant, hidden = false }) {
|
|
763
|
+
const texts = useConsentTexts();
|
|
447
764
|
if (hidden) return null;
|
|
448
|
-
return /* @__PURE__ */ (0,
|
|
765
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
449
766
|
import_Typography.default,
|
|
450
767
|
{
|
|
451
768
|
variant: "caption",
|
|
@@ -454,9 +771,9 @@ function Branding({ variant, hidden = false }) {
|
|
|
454
771
|
color: theme.palette.text.secondary
|
|
455
772
|
}),
|
|
456
773
|
children: [
|
|
457
|
-
"fornecido por",
|
|
774
|
+
texts.brandingPoweredBy || "fornecido por",
|
|
458
775
|
" ",
|
|
459
|
-
/* @__PURE__ */ (0,
|
|
776
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
460
777
|
import_Link.default,
|
|
461
778
|
{
|
|
462
779
|
href: "https://www.ledipo.eti.br",
|
|
@@ -473,13 +790,14 @@ function Branding({ variant, hidden = false }) {
|
|
|
473
790
|
}
|
|
474
791
|
);
|
|
475
792
|
}
|
|
476
|
-
var import_Link, import_Typography,
|
|
793
|
+
var import_Link, import_Typography, import_jsx_runtime4, brandingStyles, linkStyles;
|
|
477
794
|
var init_Branding = __esm({
|
|
478
795
|
"src/components/Branding.tsx"() {
|
|
479
796
|
"use strict";
|
|
797
|
+
init_useConsent();
|
|
480
798
|
import_Link = __toESM(require("@mui/material/Link"), 1);
|
|
481
799
|
import_Typography = __toESM(require("@mui/material/Typography"), 1);
|
|
482
|
-
|
|
800
|
+
import_jsx_runtime4 = require("react/jsx-runtime");
|
|
483
801
|
brandingStyles = {
|
|
484
802
|
banner: {
|
|
485
803
|
fontSize: "0.65rem",
|
|
@@ -523,6 +841,13 @@ function CookieBanner({
|
|
|
523
841
|
const isHydrated = useConsentHydration();
|
|
524
842
|
const designTokens = useDesignTokens();
|
|
525
843
|
const open = debug ? true : isHydrated && !consented;
|
|
844
|
+
logger.componentRender("CookieBanner", {
|
|
845
|
+
open,
|
|
846
|
+
consented,
|
|
847
|
+
isHydrated,
|
|
848
|
+
blocking,
|
|
849
|
+
hideBranding
|
|
850
|
+
});
|
|
526
851
|
if (!open) return null;
|
|
527
852
|
const bannerStyle = {
|
|
528
853
|
p: designTokens?.spacing?.padding?.banner ?? 2,
|
|
@@ -533,67 +858,61 @@ function CookieBanner({
|
|
|
533
858
|
borderRadius: designTokens?.spacing?.borderRadius?.banner,
|
|
534
859
|
fontFamily: designTokens?.typography?.fontFamily
|
|
535
860
|
};
|
|
536
|
-
const bannerContent = /* @__PURE__ */ (0,
|
|
537
|
-
/* @__PURE__ */ (0,
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
)
|
|
593
|
-
]
|
|
594
|
-
}
|
|
595
|
-
),
|
|
596
|
-
!hideBranding && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Branding, { variant: "banner" })
|
|
861
|
+
const bannerContent = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_Paper.default, { elevation: 3, sx: bannerStyle, ...PaperProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_Stack.default, { spacing: 1, children: [
|
|
862
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_Typography2.default, { variant: "body2", sx: { fontSize: designTokens?.typography?.fontSize?.banner }, children: [
|
|
863
|
+
texts.bannerMessage,
|
|
864
|
+
" ",
|
|
865
|
+
policyLinkUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
866
|
+
import_Link2.default,
|
|
867
|
+
{
|
|
868
|
+
href: policyLinkUrl,
|
|
869
|
+
underline: "hover",
|
|
870
|
+
target: "_blank",
|
|
871
|
+
rel: "noopener noreferrer",
|
|
872
|
+
sx: { color: designTokens?.colors?.primary },
|
|
873
|
+
children: texts.policyLink ?? "Saiba mais"
|
|
874
|
+
}
|
|
875
|
+
)
|
|
876
|
+
] }),
|
|
877
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_Stack.default, { direction: { xs: "column", sm: "row" }, spacing: 1, justifyContent: "flex-end", children: [
|
|
878
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
879
|
+
import_Button.default,
|
|
880
|
+
{
|
|
881
|
+
variant: "outlined",
|
|
882
|
+
onClick: () => {
|
|
883
|
+
logger.apiUsage("rejectAll", { source: "banner" });
|
|
884
|
+
rejectAll();
|
|
885
|
+
},
|
|
886
|
+
sx: { color: designTokens?.colors?.secondary },
|
|
887
|
+
children: texts.declineAll
|
|
888
|
+
}
|
|
889
|
+
),
|
|
890
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
891
|
+
import_Button.default,
|
|
892
|
+
{
|
|
893
|
+
variant: "contained",
|
|
894
|
+
onClick: () => {
|
|
895
|
+
logger.apiUsage("acceptAll", { source: "banner" });
|
|
896
|
+
acceptAll();
|
|
897
|
+
},
|
|
898
|
+
sx: { backgroundColor: designTokens?.colors?.primary },
|
|
899
|
+
children: texts.acceptAll
|
|
900
|
+
}
|
|
901
|
+
),
|
|
902
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
903
|
+
import_Button.default,
|
|
904
|
+
{
|
|
905
|
+
variant: "text",
|
|
906
|
+
onClick: () => {
|
|
907
|
+
logger.apiUsage("openPreferences", { source: "banner" });
|
|
908
|
+
openPreferences();
|
|
909
|
+
},
|
|
910
|
+
sx: { color: designTokens?.colors?.text },
|
|
911
|
+
children: texts.preferences
|
|
912
|
+
}
|
|
913
|
+
)
|
|
914
|
+
] }),
|
|
915
|
+
!hideBranding && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Branding, { variant: "banner" })
|
|
597
916
|
] }) });
|
|
598
917
|
const positionStyle = {
|
|
599
918
|
position: "fixed",
|
|
@@ -605,8 +924,8 @@ function CookieBanner({
|
|
|
605
924
|
p: 2
|
|
606
925
|
};
|
|
607
926
|
if (blocking) {
|
|
608
|
-
return /* @__PURE__ */ (0,
|
|
609
|
-
/* @__PURE__ */ (0,
|
|
927
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
928
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
610
929
|
import_Box.default,
|
|
611
930
|
{
|
|
612
931
|
sx: {
|
|
@@ -620,10 +939,10 @@ function CookieBanner({
|
|
|
620
939
|
}
|
|
621
940
|
}
|
|
622
941
|
),
|
|
623
|
-
/* @__PURE__ */ (0,
|
|
942
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_Box.default, { sx: positionStyle, children: bannerContent })
|
|
624
943
|
] });
|
|
625
944
|
}
|
|
626
|
-
return /* @__PURE__ */ (0,
|
|
945
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
627
946
|
import_Snackbar.default,
|
|
628
947
|
{
|
|
629
948
|
open,
|
|
@@ -636,7 +955,7 @@ function CookieBanner({
|
|
|
636
955
|
}
|
|
637
956
|
);
|
|
638
957
|
}
|
|
639
|
-
var import_Button, import_Box, import_Paper, import_Snackbar, import_Stack, import_Typography2, import_Link2,
|
|
958
|
+
var import_Button, import_Box, import_Paper, import_Snackbar, import_Stack, import_Typography2, import_Link2, import_jsx_runtime5;
|
|
640
959
|
var init_CookieBanner = __esm({
|
|
641
960
|
"src/components/CookieBanner.tsx"() {
|
|
642
961
|
"use strict";
|
|
@@ -650,25 +969,54 @@ var init_CookieBanner = __esm({
|
|
|
650
969
|
init_useConsent();
|
|
651
970
|
init_DesignContext();
|
|
652
971
|
init_Branding();
|
|
653
|
-
|
|
972
|
+
init_logger();
|
|
973
|
+
import_jsx_runtime5 = require("react/jsx-runtime");
|
|
654
974
|
}
|
|
655
975
|
});
|
|
656
976
|
|
|
657
977
|
// src/components/FloatingPreferencesButton.tsx
|
|
978
|
+
function useThemeWithFallbacks() {
|
|
979
|
+
const theme = (0, import_styles3.useTheme)();
|
|
980
|
+
logger.themeCompatibility(theme);
|
|
981
|
+
return {
|
|
982
|
+
palette: {
|
|
983
|
+
primary: {
|
|
984
|
+
main: theme?.palette?.primary?.main || "#1976d2",
|
|
985
|
+
dark: theme?.palette?.primary?.dark || "#1565c0"
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
transitions: {
|
|
989
|
+
duration: {
|
|
990
|
+
shortest: theme?.transitions?.duration?.shortest || 150,
|
|
991
|
+
short: theme?.transitions?.duration?.short || 250
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
}
|
|
658
996
|
function FloatingPreferencesButton({
|
|
659
997
|
position = "bottom-right",
|
|
660
998
|
offset = 24,
|
|
661
|
-
icon = /* @__PURE__ */ (0,
|
|
999
|
+
icon = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_CookieOutlined.default, {}),
|
|
662
1000
|
tooltip,
|
|
663
1001
|
FabProps,
|
|
664
1002
|
hideWhenConsented = false
|
|
665
1003
|
}) {
|
|
666
1004
|
const { openPreferences, consented } = useConsent();
|
|
667
|
-
const
|
|
1005
|
+
const texts = useConsentTexts();
|
|
1006
|
+
const safeTheme = useThemeWithFallbacks();
|
|
1007
|
+
logger.componentRender("FloatingPreferencesButton", {
|
|
1008
|
+
position,
|
|
1009
|
+
offset,
|
|
1010
|
+
hideWhenConsented,
|
|
1011
|
+
consented
|
|
1012
|
+
});
|
|
668
1013
|
if (hideWhenConsented && consented) {
|
|
1014
|
+
logger.debug(
|
|
1015
|
+
"FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
|
|
1016
|
+
);
|
|
669
1017
|
return null;
|
|
670
1018
|
}
|
|
671
|
-
const tooltipText = tooltip ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
1019
|
+
const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
672
1020
|
const getPosition = () => {
|
|
673
1021
|
const styles = {
|
|
674
1022
|
position: "fixed",
|
|
@@ -687,7 +1035,7 @@ function FloatingPreferencesButton({
|
|
|
687
1035
|
return { ...styles, bottom: offset, right: offset };
|
|
688
1036
|
}
|
|
689
1037
|
};
|
|
690
|
-
return /* @__PURE__ */ (0,
|
|
1038
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_Tooltip.default, { title: tooltipText, placement: "top", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
691
1039
|
import_Fab.default,
|
|
692
1040
|
{
|
|
693
1041
|
size: "medium",
|
|
@@ -695,10 +1043,11 @@ function FloatingPreferencesButton({
|
|
|
695
1043
|
onClick: openPreferences,
|
|
696
1044
|
sx: {
|
|
697
1045
|
...getPosition(),
|
|
698
|
-
backgroundColor:
|
|
1046
|
+
backgroundColor: safeTheme.palette.primary.main,
|
|
699
1047
|
"&:hover": {
|
|
700
|
-
backgroundColor:
|
|
701
|
-
}
|
|
1048
|
+
backgroundColor: safeTheme.palette.primary.dark
|
|
1049
|
+
},
|
|
1050
|
+
transition: `all ${safeTheme.transitions.duration.short}ms`
|
|
702
1051
|
},
|
|
703
1052
|
"aria-label": tooltipText,
|
|
704
1053
|
...FabProps,
|
|
@@ -706,16 +1055,17 @@ function FloatingPreferencesButton({
|
|
|
706
1055
|
}
|
|
707
1056
|
) });
|
|
708
1057
|
}
|
|
709
|
-
var import_CookieOutlined, import_Fab, import_Tooltip,
|
|
1058
|
+
var import_CookieOutlined, import_Fab, import_Tooltip, import_styles3, import_jsx_runtime6;
|
|
710
1059
|
var init_FloatingPreferencesButton = __esm({
|
|
711
1060
|
"src/components/FloatingPreferencesButton.tsx"() {
|
|
712
1061
|
"use strict";
|
|
713
1062
|
import_CookieOutlined = __toESM(require("@mui/icons-material/CookieOutlined"), 1);
|
|
714
1063
|
import_Fab = __toESM(require("@mui/material/Fab"), 1);
|
|
715
1064
|
import_Tooltip = __toESM(require("@mui/material/Tooltip"), 1);
|
|
716
|
-
|
|
1065
|
+
import_styles3 = require("@mui/material/styles");
|
|
717
1066
|
init_useConsent();
|
|
718
|
-
|
|
1067
|
+
init_logger();
|
|
1068
|
+
import_jsx_runtime6 = require("react/jsx-runtime");
|
|
719
1069
|
}
|
|
720
1070
|
});
|
|
721
1071
|
|
|
@@ -734,30 +1084,29 @@ function createFullConsentState(consented, preferences, source, projectConfig, i
|
|
|
734
1084
|
};
|
|
735
1085
|
}
|
|
736
1086
|
function reducer(state, action) {
|
|
1087
|
+
logger.consentState(action.type, state);
|
|
737
1088
|
switch (action.type) {
|
|
738
1089
|
case "ACCEPT_ALL": {
|
|
739
1090
|
const prefs = createProjectPreferences(action.config, true);
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
false,
|
|
746
|
-
state
|
|
747
|
-
);
|
|
1091
|
+
const newState = createFullConsentState(true, prefs, "banner", action.config, false, state);
|
|
1092
|
+
logger.info("User accepted all cookies", {
|
|
1093
|
+
preferences: newState.preferences
|
|
1094
|
+
});
|
|
1095
|
+
return newState;
|
|
748
1096
|
}
|
|
749
1097
|
case "REJECT_ALL": {
|
|
750
1098
|
const prefs = createProjectPreferences(action.config, false);
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
false,
|
|
757
|
-
state
|
|
758
|
-
);
|
|
1099
|
+
const newState = createFullConsentState(true, prefs, "banner", action.config, false, state);
|
|
1100
|
+
logger.info("User rejected all cookies", {
|
|
1101
|
+
preferences: newState.preferences
|
|
1102
|
+
});
|
|
1103
|
+
return newState;
|
|
759
1104
|
}
|
|
760
1105
|
case "SET_CATEGORY":
|
|
1106
|
+
logger.debug("Category preference changed", {
|
|
1107
|
+
category: action.category,
|
|
1108
|
+
value: action.value
|
|
1109
|
+
});
|
|
761
1110
|
return {
|
|
762
1111
|
...state,
|
|
763
1112
|
preferences: {
|
|
@@ -767,25 +1116,12 @@ function reducer(state, action) {
|
|
|
767
1116
|
lastUpdate: (/* @__PURE__ */ new Date()).toISOString()
|
|
768
1117
|
};
|
|
769
1118
|
case "SET_PREFERENCES":
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
action.preferences,
|
|
773
|
-
"modal",
|
|
774
|
-
action.config,
|
|
775
|
-
false,
|
|
776
|
-
state
|
|
777
|
-
);
|
|
1119
|
+
logger.info("Preferences saved", { preferences: action.preferences });
|
|
1120
|
+
return createFullConsentState(true, action.preferences, "modal", action.config, false, state);
|
|
778
1121
|
case "OPEN_MODAL":
|
|
779
1122
|
return { ...state, isModalOpen: true };
|
|
780
1123
|
case "CLOSE_MODAL":
|
|
781
|
-
return createFullConsentState(
|
|
782
|
-
true,
|
|
783
|
-
state.preferences,
|
|
784
|
-
"modal",
|
|
785
|
-
action.config,
|
|
786
|
-
false,
|
|
787
|
-
state
|
|
788
|
-
);
|
|
1124
|
+
return createFullConsentState(true, state.preferences, "modal", action.config, false, state);
|
|
789
1125
|
case "RESET": {
|
|
790
1126
|
return createFullConsentState(
|
|
791
1127
|
false,
|
|
@@ -813,12 +1149,9 @@ function reducer(state, action) {
|
|
|
813
1149
|
function ConsentProvider({
|
|
814
1150
|
initialState,
|
|
815
1151
|
categories,
|
|
816
|
-
// Nova prop para configuração de categorias
|
|
817
1152
|
texts: textsProp,
|
|
818
1153
|
theme,
|
|
819
1154
|
designTokens,
|
|
820
|
-
scriptIntegrations,
|
|
821
|
-
// eslint-disable-line no-unused-vars
|
|
822
1155
|
PreferencesModalComponent,
|
|
823
1156
|
preferencesModalProps = {},
|
|
824
1157
|
CookieBannerComponent,
|
|
@@ -833,24 +1166,18 @@ function ConsentProvider({
|
|
|
833
1166
|
disableDeveloperGuidance,
|
|
834
1167
|
children
|
|
835
1168
|
}) {
|
|
836
|
-
const texts =
|
|
837
|
-
|
|
838
|
-
[textsProp]
|
|
839
|
-
);
|
|
840
|
-
const cookie = React4.useMemo(
|
|
1169
|
+
const texts = React5.useMemo(() => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }), [textsProp]);
|
|
1170
|
+
const cookie = React5.useMemo(
|
|
841
1171
|
() => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
|
|
842
1172
|
[cookieOpts]
|
|
843
1173
|
);
|
|
844
|
-
const appliedTheme =
|
|
845
|
-
|
|
846
|
-
[theme]
|
|
847
|
-
);
|
|
848
|
-
const finalCategoriesConfig = React4.useMemo(() => {
|
|
1174
|
+
const appliedTheme = React5.useMemo(() => theme || defaultConsentTheme, [theme]);
|
|
1175
|
+
const finalCategoriesConfig = React5.useMemo(() => {
|
|
849
1176
|
if (categories) return categories;
|
|
850
1177
|
return DEFAULT_PROJECT_CATEGORIES;
|
|
851
1178
|
}, [categories]);
|
|
852
1179
|
useDeveloperGuidance(finalCategoriesConfig, disableDeveloperGuidance);
|
|
853
|
-
const boot =
|
|
1180
|
+
const boot = React5.useMemo(() => {
|
|
854
1181
|
if (initialState) return { ...initialState, isModalOpen: false };
|
|
855
1182
|
return createFullConsentState(
|
|
856
1183
|
false,
|
|
@@ -860,9 +1187,9 @@ function ConsentProvider({
|
|
|
860
1187
|
false
|
|
861
1188
|
);
|
|
862
1189
|
}, [initialState, finalCategoriesConfig]);
|
|
863
|
-
const [state, dispatch] =
|
|
864
|
-
const [isHydrated, setIsHydrated] =
|
|
865
|
-
|
|
1190
|
+
const [state, dispatch] = React5.useReducer(reducer, boot);
|
|
1191
|
+
const [isHydrated, setIsHydrated] = React5.useState(false);
|
|
1192
|
+
React5.useEffect(() => {
|
|
866
1193
|
if (!initialState) {
|
|
867
1194
|
const saved = readConsentCookie(cookie.name);
|
|
868
1195
|
if (saved?.consented) {
|
|
@@ -875,18 +1202,17 @@ function ConsentProvider({
|
|
|
875
1202
|
}
|
|
876
1203
|
setIsHydrated(true);
|
|
877
1204
|
}, [cookie.name, initialState, finalCategoriesConfig]);
|
|
878
|
-
|
|
879
|
-
if (state.consented)
|
|
880
|
-
writeConsentCookie(state, finalCategoriesConfig, cookie);
|
|
1205
|
+
React5.useEffect(() => {
|
|
1206
|
+
if (state.consented) writeConsentCookie(state, finalCategoriesConfig, cookie);
|
|
881
1207
|
}, [state, cookie, finalCategoriesConfig]);
|
|
882
|
-
const prevConsented =
|
|
883
|
-
|
|
1208
|
+
const prevConsented = React5.useRef(state.consented);
|
|
1209
|
+
React5.useEffect(() => {
|
|
884
1210
|
if (!prevConsented.current && state.consented && onConsentGiven) {
|
|
885
1211
|
setTimeout(() => onConsentGiven(state), 150);
|
|
886
1212
|
}
|
|
887
1213
|
prevConsented.current = state.consented;
|
|
888
1214
|
}, [state, onConsentGiven]);
|
|
889
|
-
const api =
|
|
1215
|
+
const api = React5.useMemo(() => {
|
|
890
1216
|
const acceptAll = () => dispatch({ type: "ACCEPT_ALL", config: finalCategoriesConfig });
|
|
891
1217
|
const rejectAll = () => dispatch({ type: "REJECT_ALL", config: finalCategoriesConfig });
|
|
892
1218
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
@@ -919,14 +1245,18 @@ function ConsentProvider({
|
|
|
919
1245
|
resetConsent
|
|
920
1246
|
};
|
|
921
1247
|
}, [state, cookie, finalCategoriesConfig, onPreferencesSaved]);
|
|
922
|
-
|
|
1248
|
+
React5.useEffect(() => {
|
|
1249
|
+
_registerGlobalOpenPreferences(api.openPreferences);
|
|
1250
|
+
return () => _unregisterGlobalOpenPreferences();
|
|
1251
|
+
}, [api.openPreferences]);
|
|
1252
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SafeThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StateCtx.Provider, { value: state, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DesignProvider, { tokens: designTokens, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
923
1253
|
CategoriesProvider,
|
|
924
1254
|
{
|
|
925
1255
|
config: finalCategoriesConfig,
|
|
926
1256
|
disableDeveloperGuidance,
|
|
927
1257
|
children: [
|
|
928
1258
|
children,
|
|
929
|
-
/* @__PURE__ */ (0,
|
|
1259
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(React5.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
930
1260
|
PreferencesModalComponent,
|
|
931
1261
|
{
|
|
932
1262
|
preferences: api.preferences,
|
|
@@ -936,8 +1266,8 @@ function ConsentProvider({
|
|
|
936
1266
|
texts,
|
|
937
1267
|
...preferencesModalProps
|
|
938
1268
|
}
|
|
939
|
-
) : /* @__PURE__ */ (0,
|
|
940
|
-
!state.consented && isHydrated && (CookieBannerComponent ? /* @__PURE__ */ (0,
|
|
1269
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreferencesModal, { hideBranding }) }),
|
|
1270
|
+
!state.consented && isHydrated && (CookieBannerComponent ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
941
1271
|
CookieBannerComponent,
|
|
942
1272
|
{
|
|
943
1273
|
consented: api.consented,
|
|
@@ -947,54 +1277,54 @@ function ConsentProvider({
|
|
|
947
1277
|
texts,
|
|
948
1278
|
...cookieBannerProps
|
|
949
1279
|
}
|
|
950
|
-
) : /* @__PURE__ */ (0,
|
|
951
|
-
state.consented && !disableFloatingPreferencesButton && (FloatingPreferencesButtonComponent ? /* @__PURE__ */ (0,
|
|
1280
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CookieBanner, {})),
|
|
1281
|
+
state.consented && !disableFloatingPreferencesButton && (FloatingPreferencesButtonComponent ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
952
1282
|
FloatingPreferencesButtonComponent,
|
|
953
1283
|
{
|
|
954
1284
|
openPreferences: api.openPreferences,
|
|
955
1285
|
consented: api.consented,
|
|
956
1286
|
...floatingPreferencesButtonProps
|
|
957
1287
|
}
|
|
958
|
-
) : /* @__PURE__ */ (0,
|
|
1288
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FloatingPreferencesButton, {}))
|
|
959
1289
|
]
|
|
960
1290
|
}
|
|
961
1291
|
) }) }) }) }) }) });
|
|
962
1292
|
}
|
|
963
1293
|
function useConsentStateInternal() {
|
|
964
|
-
const ctx =
|
|
965
|
-
if (!ctx)
|
|
966
|
-
throw new Error("useConsentState must be used within ConsentProvider");
|
|
1294
|
+
const ctx = React5.useContext(StateCtx);
|
|
1295
|
+
if (!ctx) throw new Error("useConsentState must be used within ConsentProvider");
|
|
967
1296
|
return ctx;
|
|
968
1297
|
}
|
|
969
1298
|
function useConsentActionsInternal() {
|
|
970
|
-
const ctx =
|
|
971
|
-
if (!ctx)
|
|
972
|
-
throw new Error("useConsentActions must be used within ConsentProvider");
|
|
1299
|
+
const ctx = React5.useContext(ActionsCtx);
|
|
1300
|
+
if (!ctx) throw new Error("useConsentActions must be used within ConsentProvider");
|
|
973
1301
|
return ctx;
|
|
974
1302
|
}
|
|
975
1303
|
function useConsentTextsInternal() {
|
|
976
|
-
const ctx =
|
|
1304
|
+
const ctx = React5.useContext(TextsCtx);
|
|
977
1305
|
return ctx;
|
|
978
1306
|
}
|
|
979
1307
|
function useConsentHydrationInternal() {
|
|
980
|
-
return
|
|
1308
|
+
return React5.useContext(HydrationCtx);
|
|
981
1309
|
}
|
|
982
|
-
var
|
|
1310
|
+
var React5, import_jsx_runtime7, PreferencesModal, DEFAULT_TEXTS, StateCtx, ActionsCtx, TextsCtx, HydrationCtx, defaultTexts;
|
|
983
1311
|
var init_ConsentContext = __esm({
|
|
984
1312
|
"src/context/ConsentContext.tsx"() {
|
|
985
1313
|
"use strict";
|
|
986
|
-
|
|
987
|
-
|
|
1314
|
+
React5 = __toESM(require("react"), 1);
|
|
1315
|
+
init_SafeThemeProvider();
|
|
988
1316
|
init_cookieUtils();
|
|
989
1317
|
init_categoryUtils();
|
|
990
1318
|
init_theme();
|
|
991
1319
|
init_CategoriesContext();
|
|
992
1320
|
init_DesignContext();
|
|
993
1321
|
init_developerGuidance();
|
|
1322
|
+
init_useConsent();
|
|
1323
|
+
init_logger();
|
|
994
1324
|
init_CookieBanner();
|
|
995
1325
|
init_FloatingPreferencesButton();
|
|
996
|
-
|
|
997
|
-
PreferencesModal =
|
|
1326
|
+
import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1327
|
+
PreferencesModal = React5.lazy(
|
|
998
1328
|
() => Promise.resolve().then(() => (init_PreferencesModal(), PreferencesModal_exports)).then((m) => ({
|
|
999
1329
|
default: m.PreferencesModal
|
|
1000
1330
|
}))
|
|
@@ -1010,7 +1340,15 @@ var init_ConsentContext = __esm({
|
|
|
1010
1340
|
modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
|
|
1011
1341
|
save: "Salvar prefer\xEAncias",
|
|
1012
1342
|
necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)",
|
|
1343
|
+
// Textos adicionais para UI customizada
|
|
1344
|
+
preferencesButton: "Configurar Cookies",
|
|
1345
|
+
preferencesTitle: "Gerenciar Prefer\xEAncias de Cookies",
|
|
1346
|
+
preferencesDescription: "Escolha quais tipos de cookies voc\xEA permite que sejam utilizados.",
|
|
1347
|
+
close: "Fechar",
|
|
1348
|
+
accept: "Aceitar",
|
|
1349
|
+
reject: "Rejeitar",
|
|
1013
1350
|
// Textos ANPD expandidos (opcionais)
|
|
1351
|
+
brandingPoweredBy: "fornecido por",
|
|
1014
1352
|
controllerInfo: void 0,
|
|
1015
1353
|
// Exibido se definido
|
|
1016
1354
|
dataTypes: void 0,
|
|
@@ -1028,10 +1366,11 @@ var init_ConsentContext = __esm({
|
|
|
1028
1366
|
transferCountries: void 0
|
|
1029
1367
|
// Exibido se definido
|
|
1030
1368
|
};
|
|
1031
|
-
StateCtx =
|
|
1032
|
-
ActionsCtx =
|
|
1033
|
-
TextsCtx =
|
|
1034
|
-
HydrationCtx =
|
|
1369
|
+
StateCtx = React5.createContext(null);
|
|
1370
|
+
ActionsCtx = React5.createContext(null);
|
|
1371
|
+
TextsCtx = React5.createContext(DEFAULT_TEXTS);
|
|
1372
|
+
HydrationCtx = React5.createContext(false);
|
|
1373
|
+
defaultTexts = DEFAULT_TEXTS;
|
|
1035
1374
|
}
|
|
1036
1375
|
});
|
|
1037
1376
|
|
|
@@ -1058,10 +1397,32 @@ function useConsentTexts() {
|
|
|
1058
1397
|
function useConsentHydration() {
|
|
1059
1398
|
return useConsentHydrationInternal();
|
|
1060
1399
|
}
|
|
1400
|
+
function useOpenPreferencesModal() {
|
|
1401
|
+
const { openPreferences } = useConsent();
|
|
1402
|
+
return openPreferences;
|
|
1403
|
+
}
|
|
1404
|
+
function openPreferencesModal() {
|
|
1405
|
+
if (globalOpenPreferences) {
|
|
1406
|
+
globalOpenPreferences();
|
|
1407
|
+
} else {
|
|
1408
|
+
logger.warn(
|
|
1409
|
+
"openPreferencesModal: ConsentProvider n\xE3o foi inicializado ou n\xE3o est\xE1 dispon\xEDvel."
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
function _registerGlobalOpenPreferences(openPreferences) {
|
|
1414
|
+
globalOpenPreferences = openPreferences;
|
|
1415
|
+
}
|
|
1416
|
+
function _unregisterGlobalOpenPreferences() {
|
|
1417
|
+
globalOpenPreferences = null;
|
|
1418
|
+
}
|
|
1419
|
+
var globalOpenPreferences;
|
|
1061
1420
|
var init_useConsent = __esm({
|
|
1062
1421
|
"src/hooks/useConsent.ts"() {
|
|
1063
1422
|
"use strict";
|
|
1064
1423
|
init_ConsentContext();
|
|
1424
|
+
init_logger();
|
|
1425
|
+
globalOpenPreferences = null;
|
|
1065
1426
|
}
|
|
1066
1427
|
});
|
|
1067
1428
|
|
|
@@ -1077,16 +1438,14 @@ function PreferencesModal2({
|
|
|
1077
1438
|
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
1078
1439
|
const texts = useConsentTexts();
|
|
1079
1440
|
const { toggleableCategories } = useCategories();
|
|
1080
|
-
const [tempPreferences, setTempPreferences] = (0,
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
);
|
|
1089
|
-
(0, import_react.useEffect)(() => {
|
|
1441
|
+
const [tempPreferences, setTempPreferences] = (0, import_react2.useState)(() => {
|
|
1442
|
+
const initialPrefs = { necessary: true };
|
|
1443
|
+
toggleableCategories.forEach((category) => {
|
|
1444
|
+
initialPrefs[category.id] = preferences[category.id] ?? false;
|
|
1445
|
+
});
|
|
1446
|
+
return initialPrefs;
|
|
1447
|
+
});
|
|
1448
|
+
(0, import_react2.useEffect)(() => {
|
|
1090
1449
|
if (isModalOpen) {
|
|
1091
1450
|
const syncedPrefs = { necessary: true };
|
|
1092
1451
|
toggleableCategories.forEach((category) => {
|
|
@@ -1103,54 +1462,39 @@ function PreferencesModal2({
|
|
|
1103
1462
|
setTempPreferences(preferences);
|
|
1104
1463
|
closePreferences();
|
|
1105
1464
|
};
|
|
1106
|
-
return /* @__PURE__ */ (0,
|
|
1107
|
-
|
|
1108
|
-
{
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_Typography3.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
1117
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_FormGroup.default, { children: [
|
|
1118
|
-
toggleableCategories.map((category) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1119
|
-
import_FormControlLabel.default,
|
|
1120
|
-
{
|
|
1121
|
-
control: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1122
|
-
import_Switch.default,
|
|
1123
|
-
{
|
|
1124
|
-
checked: tempPreferences[category.id] ?? false,
|
|
1125
|
-
onChange: (e) => setTempPreferences((prev) => ({
|
|
1126
|
-
...prev,
|
|
1127
|
-
[category.id]: e.target.checked
|
|
1128
|
-
}))
|
|
1129
|
-
}
|
|
1130
|
-
),
|
|
1131
|
-
label: `${category.name} - ${category.description}`
|
|
1132
|
-
},
|
|
1133
|
-
category.id
|
|
1134
|
-
)),
|
|
1135
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1136
|
-
import_FormControlLabel.default,
|
|
1465
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_Dialog.default, { "aria-labelledby": "cookie-pref-title", open, onClose: handleCancel, ...DialogProps2, children: [
|
|
1466
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_DialogTitle.default, { id: "cookie-pref-title", children: texts.modalTitle }),
|
|
1467
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_DialogContent.default, { dividers: true, children: [
|
|
1468
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_Typography3.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
1469
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_FormGroup.default, { children: [
|
|
1470
|
+
toggleableCategories.map((category) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1471
|
+
import_FormControlLabel.default,
|
|
1472
|
+
{
|
|
1473
|
+
control: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1474
|
+
import_Switch.default,
|
|
1137
1475
|
{
|
|
1138
|
-
|
|
1139
|
-
|
|
1476
|
+
checked: tempPreferences[category.id] ?? false,
|
|
1477
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
1478
|
+
...prev,
|
|
1479
|
+
[category.id]: e.target.checked
|
|
1480
|
+
}))
|
|
1140
1481
|
}
|
|
1141
|
-
)
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1482
|
+
),
|
|
1483
|
+
label: `${category.name} - ${category.description}`
|
|
1484
|
+
},
|
|
1485
|
+
category.id
|
|
1486
|
+
)),
|
|
1487
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_FormControlLabel.default, { control: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_Switch.default, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn })
|
|
1488
|
+
] })
|
|
1489
|
+
] }),
|
|
1490
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_DialogActions.default, { children: [
|
|
1491
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_Button2.default, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
1492
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_Button2.default, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
1493
|
+
] }),
|
|
1494
|
+
!hideBranding && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Branding, { variant: "modal" })
|
|
1495
|
+
] });
|
|
1152
1496
|
}
|
|
1153
|
-
var import_Button2, import_Dialog, import_DialogActions, import_DialogContent, import_DialogTitle, import_FormControlLabel, import_FormGroup, import_Switch, import_Typography3,
|
|
1497
|
+
var import_Button2, import_Dialog, import_DialogActions, import_DialogContent, import_DialogTitle, import_FormControlLabel, import_FormGroup, import_Switch, import_Typography3, import_react2, import_jsx_runtime8;
|
|
1154
1498
|
var init_PreferencesModal = __esm({
|
|
1155
1499
|
"src/components/PreferencesModal.tsx"() {
|
|
1156
1500
|
"use strict";
|
|
@@ -1163,11 +1507,11 @@ var init_PreferencesModal = __esm({
|
|
|
1163
1507
|
import_FormGroup = __toESM(require("@mui/material/FormGroup"), 1);
|
|
1164
1508
|
import_Switch = __toESM(require("@mui/material/Switch"), 1);
|
|
1165
1509
|
import_Typography3 = __toESM(require("@mui/material/Typography"), 1);
|
|
1166
|
-
|
|
1510
|
+
import_react2 = require("react");
|
|
1167
1511
|
init_CategoriesContext();
|
|
1168
1512
|
init_useConsent();
|
|
1169
1513
|
init_Branding();
|
|
1170
|
-
|
|
1514
|
+
import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1171
1515
|
}
|
|
1172
1516
|
});
|
|
1173
1517
|
|
|
@@ -1178,20 +1522,30 @@ __export(index_exports, {
|
|
|
1178
1522
|
ConsentGate: () => ConsentGate,
|
|
1179
1523
|
ConsentProvider: () => ConsentProvider,
|
|
1180
1524
|
ConsentScriptLoader: () => ConsentScriptLoader,
|
|
1525
|
+
CookieBanner: () => CookieBanner,
|
|
1181
1526
|
DEFAULT_PROJECT_CATEGORIES: () => DEFAULT_PROJECT_CATEGORIES,
|
|
1527
|
+
FloatingPreferencesButton: () => FloatingPreferencesButton,
|
|
1528
|
+
LogLevel: () => LogLevel,
|
|
1182
1529
|
PreferencesModal: () => PreferencesModal2,
|
|
1183
1530
|
analyzeDeveloperConfiguration: () => analyzeDeveloperConfiguration,
|
|
1184
1531
|
createGoogleAnalyticsIntegration: () => createGoogleAnalyticsIntegration,
|
|
1185
1532
|
createGoogleTagManagerIntegration: () => createGoogleTagManagerIntegration,
|
|
1533
|
+
createProjectPreferences: () => createProjectPreferences,
|
|
1186
1534
|
createUserWayIntegration: () => createUserWayIntegration,
|
|
1187
1535
|
defaultConsentTheme: () => defaultConsentTheme,
|
|
1536
|
+
defaultTexts: () => defaultTexts,
|
|
1537
|
+
getAllProjectCategories: () => getAllProjectCategories,
|
|
1188
1538
|
loadScript: () => loadScript,
|
|
1539
|
+
openPreferencesModal: () => openPreferencesModal,
|
|
1540
|
+
setDebugLogging: () => setDebugLogging,
|
|
1189
1541
|
useCategories: () => useCategories,
|
|
1190
1542
|
useCategoryStatus: () => useCategoryStatus,
|
|
1191
1543
|
useConsent: () => useConsent,
|
|
1192
1544
|
useConsentHydration: () => useConsentHydration,
|
|
1193
1545
|
useConsentScriptLoader: () => useConsentScriptLoader,
|
|
1194
|
-
useConsentTexts: () => useConsentTexts
|
|
1546
|
+
useConsentTexts: () => useConsentTexts,
|
|
1547
|
+
useOpenPreferencesModal: () => useOpenPreferencesModal,
|
|
1548
|
+
validateProjectPreferences: () => validateProjectPreferences
|
|
1195
1549
|
});
|
|
1196
1550
|
module.exports = __toCommonJS(index_exports);
|
|
1197
1551
|
init_PreferencesModal();
|
|
@@ -1201,11 +1555,11 @@ init_CategoriesContext();
|
|
|
1201
1555
|
|
|
1202
1556
|
// src/utils/ConsentGate.tsx
|
|
1203
1557
|
init_useConsent();
|
|
1204
|
-
var
|
|
1558
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1205
1559
|
function ConsentGate(props) {
|
|
1206
1560
|
const { preferences } = useConsent();
|
|
1207
1561
|
if (!preferences[props.category]) return null;
|
|
1208
|
-
return /* @__PURE__ */ (0,
|
|
1562
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: props.children });
|
|
1209
1563
|
}
|
|
1210
1564
|
|
|
1211
1565
|
// src/utils/scriptLoader.ts
|
|
@@ -1249,15 +1603,16 @@ function loadScript(id, src, category = null, attrs = {}) {
|
|
|
1249
1603
|
init_theme();
|
|
1250
1604
|
|
|
1251
1605
|
// src/utils/ConsentScriptLoader.tsx
|
|
1252
|
-
var
|
|
1606
|
+
var React6 = __toESM(require("react"), 1);
|
|
1253
1607
|
init_useConsent();
|
|
1608
|
+
init_logger();
|
|
1254
1609
|
function ConsentScriptLoader({
|
|
1255
1610
|
integrations,
|
|
1256
1611
|
reloadOnChange = false
|
|
1257
1612
|
}) {
|
|
1258
1613
|
const { preferences, consented } = useConsent();
|
|
1259
|
-
const loadedScripts =
|
|
1260
|
-
|
|
1614
|
+
const loadedScripts = React6.useRef(/* @__PURE__ */ new Set());
|
|
1615
|
+
React6.useEffect(() => {
|
|
1261
1616
|
if (!consented) return;
|
|
1262
1617
|
integrations.forEach(async (integration) => {
|
|
1263
1618
|
const shouldLoad = preferences[integration.category];
|
|
@@ -1276,7 +1631,7 @@ function ConsentScriptLoader({
|
|
|
1276
1631
|
}
|
|
1277
1632
|
loadedScripts.current.add(integration.id);
|
|
1278
1633
|
} catch (error) {
|
|
1279
|
-
|
|
1634
|
+
logger.error(`\u274C Failed to load script: ${integration.id}`, error);
|
|
1280
1635
|
}
|
|
1281
1636
|
}
|
|
1282
1637
|
});
|
|
@@ -1285,17 +1640,15 @@ function ConsentScriptLoader({
|
|
|
1285
1640
|
}
|
|
1286
1641
|
function useConsentScriptLoader() {
|
|
1287
1642
|
const { preferences, consented } = useConsent();
|
|
1288
|
-
return
|
|
1643
|
+
return React6.useCallback(
|
|
1289
1644
|
async (integration) => {
|
|
1290
1645
|
if (!consented) {
|
|
1291
|
-
|
|
1292
|
-
`\u26A0\uFE0F Cannot load script ${integration.id}: No consent given`
|
|
1293
|
-
);
|
|
1646
|
+
logger.warn(`\u26A0\uFE0F Cannot load script ${integration.id}: No consent given`);
|
|
1294
1647
|
return false;
|
|
1295
1648
|
}
|
|
1296
1649
|
const shouldLoad = preferences[integration.category];
|
|
1297
1650
|
if (!shouldLoad) {
|
|
1298
|
-
|
|
1651
|
+
logger.warn(
|
|
1299
1652
|
`\u26A0\uFE0F Cannot load script ${integration.id}: Category '${integration.category}' not consented`
|
|
1300
1653
|
);
|
|
1301
1654
|
return false;
|
|
@@ -1313,7 +1666,7 @@ function useConsentScriptLoader() {
|
|
|
1313
1666
|
}
|
|
1314
1667
|
return true;
|
|
1315
1668
|
} catch (error) {
|
|
1316
|
-
|
|
1669
|
+
logger.error(`\u274C Failed to load script: ${integration.id}`, error);
|
|
1317
1670
|
return false;
|
|
1318
1671
|
}
|
|
1319
1672
|
},
|
|
@@ -1363,8 +1716,7 @@ function createUserWayIntegration(config) {
|
|
|
1363
1716
|
return {
|
|
1364
1717
|
id: "userway",
|
|
1365
1718
|
category: "functional",
|
|
1366
|
-
|
|
1367
|
-
src: `https://cdn.userway.org/widget.js`,
|
|
1719
|
+
src: "https://cdn.userway.org/widget.js",
|
|
1368
1720
|
init: () => {
|
|
1369
1721
|
if (typeof window !== "undefined") {
|
|
1370
1722
|
window.UserWayWidgetApp = window.UserWayWidgetApp || {};
|
|
@@ -1382,24 +1734,39 @@ var COMMON_INTEGRATIONS = {
|
|
|
1382
1734
|
|
|
1383
1735
|
// src/index.ts
|
|
1384
1736
|
init_developerGuidance();
|
|
1737
|
+
init_logger();
|
|
1738
|
+
init_CookieBanner();
|
|
1739
|
+
init_FloatingPreferencesButton();
|
|
1740
|
+
init_ConsentContext();
|
|
1741
|
+
init_categoryUtils();
|
|
1385
1742
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1386
1743
|
0 && (module.exports = {
|
|
1387
1744
|
COMMON_INTEGRATIONS,
|
|
1388
1745
|
ConsentGate,
|
|
1389
1746
|
ConsentProvider,
|
|
1390
1747
|
ConsentScriptLoader,
|
|
1748
|
+
CookieBanner,
|
|
1391
1749
|
DEFAULT_PROJECT_CATEGORIES,
|
|
1750
|
+
FloatingPreferencesButton,
|
|
1751
|
+
LogLevel,
|
|
1392
1752
|
PreferencesModal,
|
|
1393
1753
|
analyzeDeveloperConfiguration,
|
|
1394
1754
|
createGoogleAnalyticsIntegration,
|
|
1395
1755
|
createGoogleTagManagerIntegration,
|
|
1756
|
+
createProjectPreferences,
|
|
1396
1757
|
createUserWayIntegration,
|
|
1397
1758
|
defaultConsentTheme,
|
|
1759
|
+
defaultTexts,
|
|
1760
|
+
getAllProjectCategories,
|
|
1398
1761
|
loadScript,
|
|
1762
|
+
openPreferencesModal,
|
|
1763
|
+
setDebugLogging,
|
|
1399
1764
|
useCategories,
|
|
1400
1765
|
useCategoryStatus,
|
|
1401
1766
|
useConsent,
|
|
1402
1767
|
useConsentHydration,
|
|
1403
1768
|
useConsentScriptLoader,
|
|
1404
|
-
useConsentTexts
|
|
1769
|
+
useConsentTexts,
|
|
1770
|
+
useOpenPreferencesModal,
|
|
1771
|
+
validateProjectPreferences
|
|
1405
1772
|
});
|