react-lgpd-consent 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +481 -0
- package/README.md +646 -79
- package/dist/{PreferencesModal-XCTM6WJN.js → PreferencesModal-J27W5XAJ.js} +1 -1
- package/dist/{chunk-R3IKVZBC.js → chunk-VFAOBR3X.js} +392 -82
- package/dist/index.cjs +437 -105
- package/dist/index.d.cts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +11 -3
- package/package.json +5 -4
|
@@ -202,11 +202,186 @@ function useCategoryStatus(categoryId) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// src/context/ConsentContext.tsx
|
|
205
|
-
import * as
|
|
206
|
-
|
|
205
|
+
import * as React5 from "react";
|
|
206
|
+
|
|
207
|
+
// src/utils/SafeThemeProvider.tsx
|
|
208
|
+
import * as React3 from "react";
|
|
209
|
+
import { ThemeProvider, createTheme } from "@mui/material/styles";
|
|
210
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
211
|
+
var createSafeTheme = (userTheme) => {
|
|
212
|
+
const baseTheme = createTheme({
|
|
213
|
+
palette: {
|
|
214
|
+
primary: {
|
|
215
|
+
main: "#1976d2",
|
|
216
|
+
dark: "#1565c0",
|
|
217
|
+
light: "#42a5f5",
|
|
218
|
+
contrastText: "#ffffff"
|
|
219
|
+
},
|
|
220
|
+
secondary: {
|
|
221
|
+
main: "#dc004e",
|
|
222
|
+
dark: "#9a0036",
|
|
223
|
+
light: "#e33371",
|
|
224
|
+
contrastText: "#ffffff"
|
|
225
|
+
},
|
|
226
|
+
background: {
|
|
227
|
+
default: "#fafafa",
|
|
228
|
+
paper: "#ffffff"
|
|
229
|
+
},
|
|
230
|
+
text: {
|
|
231
|
+
primary: "#333333",
|
|
232
|
+
secondary: "#666666"
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
transitions: {
|
|
236
|
+
duration: {
|
|
237
|
+
shortest: 150,
|
|
238
|
+
shorter: 200,
|
|
239
|
+
short: 250,
|
|
240
|
+
standard: 300,
|
|
241
|
+
complex: 375,
|
|
242
|
+
enteringScreen: 225,
|
|
243
|
+
leavingScreen: 195
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
if (!userTheme) {
|
|
248
|
+
return baseTheme;
|
|
249
|
+
}
|
|
250
|
+
return createTheme({
|
|
251
|
+
...baseTheme,
|
|
252
|
+
...userTheme,
|
|
253
|
+
palette: {
|
|
254
|
+
...baseTheme.palette,
|
|
255
|
+
...userTheme.palette,
|
|
256
|
+
primary: {
|
|
257
|
+
...baseTheme.palette.primary,
|
|
258
|
+
...userTheme.palette?.primary
|
|
259
|
+
},
|
|
260
|
+
secondary: {
|
|
261
|
+
...baseTheme.palette.secondary,
|
|
262
|
+
...userTheme.palette?.secondary
|
|
263
|
+
},
|
|
264
|
+
background: {
|
|
265
|
+
...baseTheme.palette.background,
|
|
266
|
+
...userTheme.palette?.background
|
|
267
|
+
},
|
|
268
|
+
text: {
|
|
269
|
+
...baseTheme.palette.text,
|
|
270
|
+
...userTheme.palette?.text
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
transitions: {
|
|
274
|
+
...baseTheme.transitions,
|
|
275
|
+
...userTheme.transitions,
|
|
276
|
+
duration: {
|
|
277
|
+
...baseTheme.transitions.duration,
|
|
278
|
+
...userTheme.transitions?.duration
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
function SafeThemeProvider({
|
|
284
|
+
theme,
|
|
285
|
+
children
|
|
286
|
+
}) {
|
|
287
|
+
const safeTheme = React3.useMemo(() => createSafeTheme(theme), [theme]);
|
|
288
|
+
return /* @__PURE__ */ jsx2(ThemeProvider, { theme: safeTheme, children });
|
|
289
|
+
}
|
|
207
290
|
|
|
208
291
|
// src/utils/cookieUtils.ts
|
|
209
292
|
import Cookies from "js-cookie";
|
|
293
|
+
|
|
294
|
+
// src/utils/logger.ts
|
|
295
|
+
var IS_DEVELOPMENT = typeof window !== "undefined" && window.__REACT_DEVTOOLS_GLOBAL_HOOK__ || typeof globalThis !== "undefined" && globalThis.process?.env?.NODE_ENV === "development";
|
|
296
|
+
var LOG_PREFIX = "[react-lgpd-consent]";
|
|
297
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
298
|
+
LogLevel2[LogLevel2["ERROR"] = 0] = "ERROR";
|
|
299
|
+
LogLevel2[LogLevel2["WARN"] = 1] = "WARN";
|
|
300
|
+
LogLevel2[LogLevel2["INFO"] = 2] = "INFO";
|
|
301
|
+
LogLevel2[LogLevel2["DEBUG"] = 3] = "DEBUG";
|
|
302
|
+
return LogLevel2;
|
|
303
|
+
})(LogLevel || {});
|
|
304
|
+
var ConsentLogger = class {
|
|
305
|
+
constructor() {
|
|
306
|
+
this.enabled = IS_DEVELOPMENT;
|
|
307
|
+
this.level = 2 /* INFO */;
|
|
308
|
+
}
|
|
309
|
+
setEnabled(enabled) {
|
|
310
|
+
this.enabled = enabled;
|
|
311
|
+
}
|
|
312
|
+
setLevel(level) {
|
|
313
|
+
this.level = level;
|
|
314
|
+
}
|
|
315
|
+
error(...args) {
|
|
316
|
+
if (this.enabled && this.level >= 0 /* ERROR */) {
|
|
317
|
+
console.error(LOG_PREFIX, "[ERROR]", ...args);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
warn(...args) {
|
|
321
|
+
if (this.enabled && this.level >= 1 /* WARN */) {
|
|
322
|
+
console.warn(LOG_PREFIX, "[WARN]", ...args);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
info(...args) {
|
|
326
|
+
if (this.enabled && this.level >= 2 /* INFO */) {
|
|
327
|
+
console.info(LOG_PREFIX, "[INFO]", ...args);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
debug(...args) {
|
|
331
|
+
if (this.enabled && this.level >= 3 /* DEBUG */) {
|
|
332
|
+
console.debug(LOG_PREFIX, "[DEBUG]", ...args);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// Logs específicos para troubleshooting
|
|
336
|
+
themeCompatibility(themeInfo) {
|
|
337
|
+
this.debug("Theme compatibility check:", {
|
|
338
|
+
hasTheme: !!themeInfo,
|
|
339
|
+
hasPalette: !!themeInfo?.palette,
|
|
340
|
+
hasPrimary: !!themeInfo?.palette?.primary,
|
|
341
|
+
hasTransitions: !!themeInfo?.transitions,
|
|
342
|
+
hasDuration: !!themeInfo?.transitions?.duration
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
consentState(action, state) {
|
|
346
|
+
this.debug(`Consent state change [${action}]:`, {
|
|
347
|
+
consented: state.consented,
|
|
348
|
+
isModalOpen: state.isModalOpen,
|
|
349
|
+
preferencesCount: Object.keys(state.preferences || {}).length
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
cookieOperation(operation, cookieName, data) {
|
|
353
|
+
this.debug(`Cookie ${operation}:`, {
|
|
354
|
+
name: cookieName,
|
|
355
|
+
hasData: !!data,
|
|
356
|
+
dataSize: data ? JSON.stringify(data).length : 0
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
componentRender(componentName, props) {
|
|
360
|
+
this.debug(`Component render [${componentName}]:`, {
|
|
361
|
+
hasProps: !!props,
|
|
362
|
+
propsKeys: props ? Object.keys(props) : []
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
scriptIntegration(scriptName, action, success) {
|
|
366
|
+
this.info(
|
|
367
|
+
`Script ${action} [${scriptName}]:`,
|
|
368
|
+
success ? "SUCCESS" : "FAILED"
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
apiUsage(method, params) {
|
|
372
|
+
this.debug(`API call [${method}]:`, params);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
var logger = new ConsentLogger();
|
|
376
|
+
function setDebugLogging(enabled, level = 2 /* INFO */) {
|
|
377
|
+
logger.setEnabled(enabled);
|
|
378
|
+
logger.setLevel(level);
|
|
379
|
+
logger.info(
|
|
380
|
+
`Debug logging ${enabled ? "enabled" : "disabled"} with level ${LogLevel[level]}`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/utils/cookieUtils.ts
|
|
210
385
|
var DEFAULT_COOKIE_OPTS = {
|
|
211
386
|
name: "cookieConsent",
|
|
212
387
|
maxAgeDays: 365,
|
|
@@ -216,22 +391,32 @@ var DEFAULT_COOKIE_OPTS = {
|
|
|
216
391
|
};
|
|
217
392
|
var COOKIE_SCHEMA_VERSION = "1.0";
|
|
218
393
|
function readConsentCookie(name = DEFAULT_COOKIE_OPTS.name) {
|
|
219
|
-
|
|
394
|
+
logger.debug("Reading consent cookie", { name });
|
|
395
|
+
if (typeof document === "undefined") {
|
|
396
|
+
logger.debug("Cookie read skipped: server-side environment");
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
220
399
|
const raw = Cookies.get(name);
|
|
221
|
-
if (!raw)
|
|
400
|
+
if (!raw) {
|
|
401
|
+
logger.debug("No consent cookie found");
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
222
404
|
try {
|
|
223
405
|
const data = JSON.parse(raw);
|
|
406
|
+
logger.cookieOperation("read", name, data);
|
|
224
407
|
if (!data.version) {
|
|
408
|
+
logger.debug("Migrating legacy cookie format");
|
|
225
409
|
return migrateLegacyCookie(data);
|
|
226
410
|
}
|
|
227
411
|
if (data.version !== COOKIE_SCHEMA_VERSION) {
|
|
228
|
-
|
|
229
|
-
`
|
|
412
|
+
logger.warn(
|
|
413
|
+
`Cookie version mismatch: ${data.version} != ${COOKIE_SCHEMA_VERSION}`
|
|
230
414
|
);
|
|
231
415
|
return null;
|
|
232
416
|
}
|
|
233
417
|
return data;
|
|
234
|
-
} catch {
|
|
418
|
+
} catch (error) {
|
|
419
|
+
logger.error("Error parsing consent cookie", error);
|
|
235
420
|
return null;
|
|
236
421
|
}
|
|
237
422
|
}
|
|
@@ -255,7 +440,10 @@ function migrateLegacyCookie(legacyData) {
|
|
|
255
440
|
}
|
|
256
441
|
}
|
|
257
442
|
function writeConsentCookie(state, config, opts, source = "banner") {
|
|
258
|
-
if (typeof document === "undefined")
|
|
443
|
+
if (typeof document === "undefined") {
|
|
444
|
+
logger.debug("Cookie write skipped: server-side environment");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
259
447
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
260
448
|
const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
|
|
261
449
|
const cookieData = {
|
|
@@ -269,17 +457,28 @@ function writeConsentCookie(state, config, opts, source = "banner") {
|
|
|
269
457
|
projectConfig: config
|
|
270
458
|
// isModalOpen NÃO é persistido (campo de UI apenas)
|
|
271
459
|
};
|
|
460
|
+
logger.cookieOperation("write", o.name, cookieData);
|
|
272
461
|
Cookies.set(o.name, JSON.stringify(cookieData), {
|
|
273
462
|
expires: o.maxAgeDays,
|
|
274
463
|
sameSite: o.sameSite,
|
|
275
464
|
secure: o.secure,
|
|
276
465
|
path: o.path
|
|
277
466
|
});
|
|
467
|
+
logger.info("Consent cookie saved", {
|
|
468
|
+
consented: cookieData.consented,
|
|
469
|
+
source: cookieData.source,
|
|
470
|
+
preferencesCount: Object.keys(cookieData.preferences).length
|
|
471
|
+
});
|
|
278
472
|
}
|
|
279
473
|
function removeConsentCookie(opts) {
|
|
280
|
-
if (typeof document === "undefined")
|
|
474
|
+
if (typeof document === "undefined") {
|
|
475
|
+
logger.debug("Cookie removal skipped: server-side environment");
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
281
478
|
const o = { ...DEFAULT_COOKIE_OPTS, ...opts };
|
|
479
|
+
logger.cookieOperation("delete", o.name);
|
|
282
480
|
Cookies.remove(o.name, { path: o.path });
|
|
481
|
+
logger.info("Consent cookie removed");
|
|
283
482
|
}
|
|
284
483
|
|
|
285
484
|
// src/utils/categoryUtils.ts
|
|
@@ -311,8 +510,8 @@ function validateProjectPreferences(preferences, config) {
|
|
|
311
510
|
}
|
|
312
511
|
|
|
313
512
|
// src/utils/theme.ts
|
|
314
|
-
import { createTheme } from "@mui/material/styles";
|
|
315
|
-
var defaultConsentTheme =
|
|
513
|
+
import { createTheme as createTheme2 } from "@mui/material/styles";
|
|
514
|
+
var defaultConsentTheme = createTheme2({
|
|
316
515
|
palette: {
|
|
317
516
|
primary: {
|
|
318
517
|
main: "#1976d2",
|
|
@@ -379,17 +578,17 @@ var defaultConsentTheme = createTheme({
|
|
|
379
578
|
});
|
|
380
579
|
|
|
381
580
|
// src/context/DesignContext.tsx
|
|
382
|
-
import * as
|
|
383
|
-
import { jsx as
|
|
384
|
-
var DesignContext =
|
|
581
|
+
import * as React4 from "react";
|
|
582
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
583
|
+
var DesignContext = React4.createContext(void 0);
|
|
385
584
|
function DesignProvider({
|
|
386
585
|
tokens,
|
|
387
586
|
children
|
|
388
587
|
}) {
|
|
389
|
-
return /* @__PURE__ */
|
|
588
|
+
return /* @__PURE__ */ jsx3(DesignContext.Provider, { value: tokens, children });
|
|
390
589
|
}
|
|
391
590
|
function useDesignTokens() {
|
|
392
|
-
return
|
|
591
|
+
return React4.useContext(DesignContext);
|
|
393
592
|
}
|
|
394
593
|
|
|
395
594
|
// src/components/CookieBanner.tsx
|
|
@@ -404,7 +603,7 @@ import Link2 from "@mui/material/Link";
|
|
|
404
603
|
// src/components/Branding.tsx
|
|
405
604
|
import Link from "@mui/material/Link";
|
|
406
605
|
import Typography from "@mui/material/Typography";
|
|
407
|
-
import { jsx as
|
|
606
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
408
607
|
var brandingStyles = {
|
|
409
608
|
banner: {
|
|
410
609
|
fontSize: "0.65rem",
|
|
@@ -432,6 +631,7 @@ var linkStyles = {
|
|
|
432
631
|
}
|
|
433
632
|
};
|
|
434
633
|
function Branding({ variant, hidden = false }) {
|
|
634
|
+
const texts = useConsentTexts();
|
|
435
635
|
if (hidden) return null;
|
|
436
636
|
return /* @__PURE__ */ jsxs(
|
|
437
637
|
Typography,
|
|
@@ -442,9 +642,9 @@ function Branding({ variant, hidden = false }) {
|
|
|
442
642
|
color: theme.palette.text.secondary
|
|
443
643
|
}),
|
|
444
644
|
children: [
|
|
445
|
-
"fornecido por",
|
|
645
|
+
texts.brandingPoweredBy || "fornecido por",
|
|
446
646
|
" ",
|
|
447
|
-
/* @__PURE__ */
|
|
647
|
+
/* @__PURE__ */ jsx4(
|
|
448
648
|
Link,
|
|
449
649
|
{
|
|
450
650
|
href: "https://www.ledipo.eti.br",
|
|
@@ -463,7 +663,7 @@ function Branding({ variant, hidden = false }) {
|
|
|
463
663
|
}
|
|
464
664
|
|
|
465
665
|
// src/components/CookieBanner.tsx
|
|
466
|
-
import { Fragment, jsx as
|
|
666
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
467
667
|
function CookieBanner({
|
|
468
668
|
policyLinkUrl,
|
|
469
669
|
debug,
|
|
@@ -477,6 +677,13 @@ function CookieBanner({
|
|
|
477
677
|
const isHydrated = useConsentHydration();
|
|
478
678
|
const designTokens = useDesignTokens();
|
|
479
679
|
const open = debug ? true : isHydrated && !consented;
|
|
680
|
+
logger.componentRender("CookieBanner", {
|
|
681
|
+
open,
|
|
682
|
+
consented,
|
|
683
|
+
isHydrated,
|
|
684
|
+
blocking,
|
|
685
|
+
hideBranding
|
|
686
|
+
});
|
|
480
687
|
if (!open) return null;
|
|
481
688
|
const bannerStyle = {
|
|
482
689
|
p: designTokens?.spacing?.padding?.banner ?? 2,
|
|
@@ -487,7 +694,7 @@ function CookieBanner({
|
|
|
487
694
|
borderRadius: designTokens?.spacing?.borderRadius?.banner,
|
|
488
695
|
fontFamily: designTokens?.typography?.fontFamily
|
|
489
696
|
};
|
|
490
|
-
const bannerContent = /* @__PURE__ */
|
|
697
|
+
const bannerContent = /* @__PURE__ */ jsx5(Paper, { elevation: 3, sx: bannerStyle, ...PaperProps, children: /* @__PURE__ */ jsxs2(Stack, { spacing: 1, children: [
|
|
491
698
|
/* @__PURE__ */ jsxs2(
|
|
492
699
|
Typography2,
|
|
493
700
|
{
|
|
@@ -496,7 +703,7 @@ function CookieBanner({
|
|
|
496
703
|
children: [
|
|
497
704
|
texts.bannerMessage,
|
|
498
705
|
" ",
|
|
499
|
-
policyLinkUrl && /* @__PURE__ */
|
|
706
|
+
policyLinkUrl && /* @__PURE__ */ jsx5(
|
|
500
707
|
Link2,
|
|
501
708
|
{
|
|
502
709
|
href: policyLinkUrl,
|
|
@@ -517,29 +724,38 @@ function CookieBanner({
|
|
|
517
724
|
spacing: 1,
|
|
518
725
|
justifyContent: "flex-end",
|
|
519
726
|
children: [
|
|
520
|
-
/* @__PURE__ */
|
|
727
|
+
/* @__PURE__ */ jsx5(
|
|
521
728
|
Button,
|
|
522
729
|
{
|
|
523
730
|
variant: "outlined",
|
|
524
|
-
onClick:
|
|
731
|
+
onClick: () => {
|
|
732
|
+
logger.apiUsage("rejectAll", { source: "banner" });
|
|
733
|
+
rejectAll();
|
|
734
|
+
},
|
|
525
735
|
sx: { color: designTokens?.colors?.secondary },
|
|
526
736
|
children: texts.declineAll
|
|
527
737
|
}
|
|
528
738
|
),
|
|
529
|
-
/* @__PURE__ */
|
|
739
|
+
/* @__PURE__ */ jsx5(
|
|
530
740
|
Button,
|
|
531
741
|
{
|
|
532
742
|
variant: "contained",
|
|
533
|
-
onClick:
|
|
743
|
+
onClick: () => {
|
|
744
|
+
logger.apiUsage("acceptAll", { source: "banner" });
|
|
745
|
+
acceptAll();
|
|
746
|
+
},
|
|
534
747
|
sx: { backgroundColor: designTokens?.colors?.primary },
|
|
535
748
|
children: texts.acceptAll
|
|
536
749
|
}
|
|
537
750
|
),
|
|
538
|
-
/* @__PURE__ */
|
|
751
|
+
/* @__PURE__ */ jsx5(
|
|
539
752
|
Button,
|
|
540
753
|
{
|
|
541
754
|
variant: "text",
|
|
542
|
-
onClick:
|
|
755
|
+
onClick: () => {
|
|
756
|
+
logger.apiUsage("openPreferences", { source: "banner" });
|
|
757
|
+
openPreferences();
|
|
758
|
+
},
|
|
543
759
|
sx: { color: designTokens?.colors?.text },
|
|
544
760
|
children: texts.preferences
|
|
545
761
|
}
|
|
@@ -547,7 +763,7 @@ function CookieBanner({
|
|
|
547
763
|
]
|
|
548
764
|
}
|
|
549
765
|
),
|
|
550
|
-
!hideBranding && /* @__PURE__ */
|
|
766
|
+
!hideBranding && /* @__PURE__ */ jsx5(Branding, { variant: "banner" })
|
|
551
767
|
] }) });
|
|
552
768
|
const positionStyle = {
|
|
553
769
|
position: "fixed",
|
|
@@ -560,7 +776,7 @@ function CookieBanner({
|
|
|
560
776
|
};
|
|
561
777
|
if (blocking) {
|
|
562
778
|
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
563
|
-
/* @__PURE__ */
|
|
779
|
+
/* @__PURE__ */ jsx5(
|
|
564
780
|
Box,
|
|
565
781
|
{
|
|
566
782
|
sx: {
|
|
@@ -574,10 +790,10 @@ function CookieBanner({
|
|
|
574
790
|
}
|
|
575
791
|
}
|
|
576
792
|
),
|
|
577
|
-
/* @__PURE__ */
|
|
793
|
+
/* @__PURE__ */ jsx5(Box, { sx: positionStyle, children: bannerContent })
|
|
578
794
|
] });
|
|
579
795
|
}
|
|
580
|
-
return /* @__PURE__ */
|
|
796
|
+
return /* @__PURE__ */ jsx5(
|
|
581
797
|
Snackbar,
|
|
582
798
|
{
|
|
583
799
|
open,
|
|
@@ -596,21 +812,49 @@ import CookieOutlined from "@mui/icons-material/CookieOutlined";
|
|
|
596
812
|
import Fab from "@mui/material/Fab";
|
|
597
813
|
import Tooltip from "@mui/material/Tooltip";
|
|
598
814
|
import { useTheme } from "@mui/material/styles";
|
|
599
|
-
import { jsx as
|
|
815
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
816
|
+
function useThemeWithFallbacks() {
|
|
817
|
+
const theme = useTheme();
|
|
818
|
+
logger.themeCompatibility(theme);
|
|
819
|
+
return {
|
|
820
|
+
palette: {
|
|
821
|
+
primary: {
|
|
822
|
+
main: theme?.palette?.primary?.main || "#1976d2",
|
|
823
|
+
dark: theme?.palette?.primary?.dark || "#1565c0"
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
transitions: {
|
|
827
|
+
duration: {
|
|
828
|
+
shortest: theme?.transitions?.duration?.shortest || 150,
|
|
829
|
+
short: theme?.transitions?.duration?.short || 250
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
600
834
|
function FloatingPreferencesButton({
|
|
601
835
|
position = "bottom-right",
|
|
602
836
|
offset = 24,
|
|
603
|
-
icon = /* @__PURE__ */
|
|
837
|
+
icon = /* @__PURE__ */ jsx6(CookieOutlined, {}),
|
|
604
838
|
tooltip,
|
|
605
839
|
FabProps,
|
|
606
840
|
hideWhenConsented = false
|
|
607
841
|
}) {
|
|
608
842
|
const { openPreferences, consented } = useConsent();
|
|
609
|
-
const
|
|
843
|
+
const texts = useConsentTexts();
|
|
844
|
+
const safeTheme = useThemeWithFallbacks();
|
|
845
|
+
logger.componentRender("FloatingPreferencesButton", {
|
|
846
|
+
position,
|
|
847
|
+
offset,
|
|
848
|
+
hideWhenConsented,
|
|
849
|
+
consented
|
|
850
|
+
});
|
|
610
851
|
if (hideWhenConsented && consented) {
|
|
852
|
+
logger.debug(
|
|
853
|
+
"FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
|
|
854
|
+
);
|
|
611
855
|
return null;
|
|
612
856
|
}
|
|
613
|
-
const tooltipText = tooltip ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
857
|
+
const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
614
858
|
const getPosition = () => {
|
|
615
859
|
const styles = {
|
|
616
860
|
position: "fixed",
|
|
@@ -629,7 +873,7 @@ function FloatingPreferencesButton({
|
|
|
629
873
|
return { ...styles, bottom: offset, right: offset };
|
|
630
874
|
}
|
|
631
875
|
};
|
|
632
|
-
return /* @__PURE__ */
|
|
876
|
+
return /* @__PURE__ */ jsx6(Tooltip, { title: tooltipText, placement: "top", children: /* @__PURE__ */ jsx6(
|
|
633
877
|
Fab,
|
|
634
878
|
{
|
|
635
879
|
size: "medium",
|
|
@@ -637,10 +881,11 @@ function FloatingPreferencesButton({
|
|
|
637
881
|
onClick: openPreferences,
|
|
638
882
|
sx: {
|
|
639
883
|
...getPosition(),
|
|
640
|
-
backgroundColor:
|
|
884
|
+
backgroundColor: safeTheme.palette.primary.main,
|
|
641
885
|
"&:hover": {
|
|
642
|
-
backgroundColor:
|
|
643
|
-
}
|
|
886
|
+
backgroundColor: safeTheme.palette.primary.dark
|
|
887
|
+
},
|
|
888
|
+
transition: `all ${safeTheme.transitions.duration.short}ms`
|
|
644
889
|
},
|
|
645
890
|
"aria-label": tooltipText,
|
|
646
891
|
...FabProps,
|
|
@@ -650,9 +895,21 @@ function FloatingPreferencesButton({
|
|
|
650
895
|
}
|
|
651
896
|
|
|
652
897
|
// src/context/ConsentContext.tsx
|
|
653
|
-
import { jsx as
|
|
654
|
-
var
|
|
655
|
-
(
|
|
898
|
+
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
899
|
+
var log = {
|
|
900
|
+
debug: (message, data) => {
|
|
901
|
+
if (typeof window !== "undefined" && window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
902
|
+
console.debug("[react-lgpd-consent] [DEBUG]", message, data);
|
|
903
|
+
}
|
|
904
|
+
},
|
|
905
|
+
info: (message, data) => {
|
|
906
|
+
if (typeof window !== "undefined" && window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
907
|
+
console.info("[react-lgpd-consent] [INFO]", message, data);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
var PreferencesModal = React5.lazy(
|
|
912
|
+
() => import("./PreferencesModal-J27W5XAJ.js").then((m) => ({
|
|
656
913
|
default: m.PreferencesModal
|
|
657
914
|
}))
|
|
658
915
|
);
|
|
@@ -680,7 +937,15 @@ var DEFAULT_TEXTS = {
|
|
|
680
937
|
modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
|
|
681
938
|
save: "Salvar prefer\xEAncias",
|
|
682
939
|
necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)",
|
|
940
|
+
// Textos adicionais para UI customizada
|
|
941
|
+
preferencesButton: "Configurar Cookies",
|
|
942
|
+
preferencesTitle: "Gerenciar Prefer\xEAncias de Cookies",
|
|
943
|
+
preferencesDescription: "Escolha quais tipos de cookies voc\xEA permite que sejam utilizados.",
|
|
944
|
+
close: "Fechar",
|
|
945
|
+
accept: "Aceitar",
|
|
946
|
+
reject: "Rejeitar",
|
|
683
947
|
// Textos ANPD expandidos (opcionais)
|
|
948
|
+
brandingPoweredBy: "fornecido por",
|
|
684
949
|
controllerInfo: void 0,
|
|
685
950
|
// Exibido se definido
|
|
686
951
|
dataTypes: void 0,
|
|
@@ -699,10 +964,14 @@ var DEFAULT_TEXTS = {
|
|
|
699
964
|
// Exibido se definido
|
|
700
965
|
};
|
|
701
966
|
function reducer(state, action) {
|
|
967
|
+
log.debug("State transition:", {
|
|
968
|
+
action: action.type,
|
|
969
|
+
currentState: state.consented
|
|
970
|
+
});
|
|
702
971
|
switch (action.type) {
|
|
703
972
|
case "ACCEPT_ALL": {
|
|
704
973
|
const prefs = createProjectPreferences(action.config, true);
|
|
705
|
-
|
|
974
|
+
const newState = createFullConsentState(
|
|
706
975
|
true,
|
|
707
976
|
prefs,
|
|
708
977
|
"banner",
|
|
@@ -710,10 +979,14 @@ function reducer(state, action) {
|
|
|
710
979
|
false,
|
|
711
980
|
state
|
|
712
981
|
);
|
|
982
|
+
log.info("User accepted all cookies", {
|
|
983
|
+
preferences: newState.preferences
|
|
984
|
+
});
|
|
985
|
+
return newState;
|
|
713
986
|
}
|
|
714
987
|
case "REJECT_ALL": {
|
|
715
988
|
const prefs = createProjectPreferences(action.config, false);
|
|
716
|
-
|
|
989
|
+
const newState = createFullConsentState(
|
|
717
990
|
true,
|
|
718
991
|
prefs,
|
|
719
992
|
"banner",
|
|
@@ -721,8 +994,16 @@ function reducer(state, action) {
|
|
|
721
994
|
false,
|
|
722
995
|
state
|
|
723
996
|
);
|
|
997
|
+
log.info("User rejected all cookies", {
|
|
998
|
+
preferences: newState.preferences
|
|
999
|
+
});
|
|
1000
|
+
return newState;
|
|
724
1001
|
}
|
|
725
1002
|
case "SET_CATEGORY":
|
|
1003
|
+
log.debug("Category preference changed", {
|
|
1004
|
+
category: action.category,
|
|
1005
|
+
value: action.value
|
|
1006
|
+
});
|
|
726
1007
|
return {
|
|
727
1008
|
...state,
|
|
728
1009
|
preferences: {
|
|
@@ -732,6 +1013,7 @@ function reducer(state, action) {
|
|
|
732
1013
|
lastUpdate: (/* @__PURE__ */ new Date()).toISOString()
|
|
733
1014
|
};
|
|
734
1015
|
case "SET_PREFERENCES":
|
|
1016
|
+
log.info("Preferences saved", { preferences: action.preferences });
|
|
735
1017
|
return createFullConsentState(
|
|
736
1018
|
true,
|
|
737
1019
|
action.preferences,
|
|
@@ -775,10 +1057,10 @@ function reducer(state, action) {
|
|
|
775
1057
|
return state;
|
|
776
1058
|
}
|
|
777
1059
|
}
|
|
778
|
-
var StateCtx =
|
|
779
|
-
var ActionsCtx =
|
|
780
|
-
var TextsCtx =
|
|
781
|
-
var HydrationCtx =
|
|
1060
|
+
var StateCtx = React5.createContext(null);
|
|
1061
|
+
var ActionsCtx = React5.createContext(null);
|
|
1062
|
+
var TextsCtx = React5.createContext(DEFAULT_TEXTS);
|
|
1063
|
+
var HydrationCtx = React5.createContext(false);
|
|
782
1064
|
function ConsentProvider({
|
|
783
1065
|
initialState,
|
|
784
1066
|
categories,
|
|
@@ -802,24 +1084,24 @@ function ConsentProvider({
|
|
|
802
1084
|
disableDeveloperGuidance,
|
|
803
1085
|
children
|
|
804
1086
|
}) {
|
|
805
|
-
const texts =
|
|
1087
|
+
const texts = React5.useMemo(
|
|
806
1088
|
() => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }),
|
|
807
1089
|
[textsProp]
|
|
808
1090
|
);
|
|
809
|
-
const cookie =
|
|
1091
|
+
const cookie = React5.useMemo(
|
|
810
1092
|
() => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
|
|
811
1093
|
[cookieOpts]
|
|
812
1094
|
);
|
|
813
|
-
const appliedTheme =
|
|
1095
|
+
const appliedTheme = React5.useMemo(
|
|
814
1096
|
() => theme || defaultConsentTheme,
|
|
815
1097
|
[theme]
|
|
816
1098
|
);
|
|
817
|
-
const finalCategoriesConfig =
|
|
1099
|
+
const finalCategoriesConfig = React5.useMemo(() => {
|
|
818
1100
|
if (categories) return categories;
|
|
819
1101
|
return DEFAULT_PROJECT_CATEGORIES;
|
|
820
1102
|
}, [categories]);
|
|
821
1103
|
useDeveloperGuidance(finalCategoriesConfig, disableDeveloperGuidance);
|
|
822
|
-
const boot =
|
|
1104
|
+
const boot = React5.useMemo(() => {
|
|
823
1105
|
if (initialState) return { ...initialState, isModalOpen: false };
|
|
824
1106
|
return createFullConsentState(
|
|
825
1107
|
false,
|
|
@@ -829,9 +1111,9 @@ function ConsentProvider({
|
|
|
829
1111
|
false
|
|
830
1112
|
);
|
|
831
1113
|
}, [initialState, finalCategoriesConfig]);
|
|
832
|
-
const [state, dispatch] =
|
|
833
|
-
const [isHydrated, setIsHydrated] =
|
|
834
|
-
|
|
1114
|
+
const [state, dispatch] = React5.useReducer(reducer, boot);
|
|
1115
|
+
const [isHydrated, setIsHydrated] = React5.useState(false);
|
|
1116
|
+
React5.useEffect(() => {
|
|
835
1117
|
if (!initialState) {
|
|
836
1118
|
const saved = readConsentCookie(cookie.name);
|
|
837
1119
|
if (saved?.consented) {
|
|
@@ -844,18 +1126,18 @@ function ConsentProvider({
|
|
|
844
1126
|
}
|
|
845
1127
|
setIsHydrated(true);
|
|
846
1128
|
}, [cookie.name, initialState, finalCategoriesConfig]);
|
|
847
|
-
|
|
1129
|
+
React5.useEffect(() => {
|
|
848
1130
|
if (state.consented)
|
|
849
1131
|
writeConsentCookie(state, finalCategoriesConfig, cookie);
|
|
850
1132
|
}, [state, cookie, finalCategoriesConfig]);
|
|
851
|
-
const prevConsented =
|
|
852
|
-
|
|
1133
|
+
const prevConsented = React5.useRef(state.consented);
|
|
1134
|
+
React5.useEffect(() => {
|
|
853
1135
|
if (!prevConsented.current && state.consented && onConsentGiven) {
|
|
854
1136
|
setTimeout(() => onConsentGiven(state), 150);
|
|
855
1137
|
}
|
|
856
1138
|
prevConsented.current = state.consented;
|
|
857
1139
|
}, [state, onConsentGiven]);
|
|
858
|
-
const api =
|
|
1140
|
+
const api = React5.useMemo(() => {
|
|
859
1141
|
const acceptAll = () => dispatch({ type: "ACCEPT_ALL", config: finalCategoriesConfig });
|
|
860
1142
|
const rejectAll = () => dispatch({ type: "REJECT_ALL", config: finalCategoriesConfig });
|
|
861
1143
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
@@ -888,14 +1170,18 @@ function ConsentProvider({
|
|
|
888
1170
|
resetConsent
|
|
889
1171
|
};
|
|
890
1172
|
}, [state, cookie, finalCategoriesConfig, onPreferencesSaved]);
|
|
891
|
-
|
|
1173
|
+
React5.useEffect(() => {
|
|
1174
|
+
_registerGlobalOpenPreferences(api.openPreferences);
|
|
1175
|
+
return () => _unregisterGlobalOpenPreferences();
|
|
1176
|
+
}, [api.openPreferences]);
|
|
1177
|
+
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(
|
|
892
1178
|
CategoriesProvider,
|
|
893
1179
|
{
|
|
894
1180
|
config: finalCategoriesConfig,
|
|
895
1181
|
disableDeveloperGuidance,
|
|
896
1182
|
children: [
|
|
897
1183
|
children,
|
|
898
|
-
/* @__PURE__ */
|
|
1184
|
+
/* @__PURE__ */ jsx7(React5.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ jsx7(
|
|
899
1185
|
PreferencesModalComponent,
|
|
900
1186
|
{
|
|
901
1187
|
preferences: api.preferences,
|
|
@@ -905,8 +1191,8 @@ function ConsentProvider({
|
|
|
905
1191
|
texts,
|
|
906
1192
|
...preferencesModalProps
|
|
907
1193
|
}
|
|
908
|
-
) : /* @__PURE__ */
|
|
909
|
-
!state.consented && isHydrated && (CookieBannerComponent ? /* @__PURE__ */
|
|
1194
|
+
) : /* @__PURE__ */ jsx7(PreferencesModal, { hideBranding }) }),
|
|
1195
|
+
!state.consented && isHydrated && (CookieBannerComponent ? /* @__PURE__ */ jsx7(
|
|
910
1196
|
CookieBannerComponent,
|
|
911
1197
|
{
|
|
912
1198
|
consented: api.consented,
|
|
@@ -916,37 +1202,37 @@ function ConsentProvider({
|
|
|
916
1202
|
texts,
|
|
917
1203
|
...cookieBannerProps
|
|
918
1204
|
}
|
|
919
|
-
) : /* @__PURE__ */
|
|
920
|
-
state.consented && !disableFloatingPreferencesButton && (FloatingPreferencesButtonComponent ? /* @__PURE__ */
|
|
1205
|
+
) : /* @__PURE__ */ jsx7(CookieBanner, {})),
|
|
1206
|
+
state.consented && !disableFloatingPreferencesButton && (FloatingPreferencesButtonComponent ? /* @__PURE__ */ jsx7(
|
|
921
1207
|
FloatingPreferencesButtonComponent,
|
|
922
1208
|
{
|
|
923
1209
|
openPreferences: api.openPreferences,
|
|
924
1210
|
consented: api.consented,
|
|
925
1211
|
...floatingPreferencesButtonProps
|
|
926
1212
|
}
|
|
927
|
-
) : /* @__PURE__ */
|
|
1213
|
+
) : /* @__PURE__ */ jsx7(FloatingPreferencesButton, {}))
|
|
928
1214
|
]
|
|
929
1215
|
}
|
|
930
1216
|
) }) }) }) }) }) });
|
|
931
1217
|
}
|
|
932
1218
|
function useConsentStateInternal() {
|
|
933
|
-
const ctx =
|
|
1219
|
+
const ctx = React5.useContext(StateCtx);
|
|
934
1220
|
if (!ctx)
|
|
935
1221
|
throw new Error("useConsentState must be used within ConsentProvider");
|
|
936
1222
|
return ctx;
|
|
937
1223
|
}
|
|
938
1224
|
function useConsentActionsInternal() {
|
|
939
|
-
const ctx =
|
|
1225
|
+
const ctx = React5.useContext(ActionsCtx);
|
|
940
1226
|
if (!ctx)
|
|
941
1227
|
throw new Error("useConsentActions must be used within ConsentProvider");
|
|
942
1228
|
return ctx;
|
|
943
1229
|
}
|
|
944
1230
|
function useConsentTextsInternal() {
|
|
945
|
-
const ctx =
|
|
1231
|
+
const ctx = React5.useContext(TextsCtx);
|
|
946
1232
|
return ctx;
|
|
947
1233
|
}
|
|
948
1234
|
function useConsentHydrationInternal() {
|
|
949
|
-
return
|
|
1235
|
+
return React5.useContext(HydrationCtx);
|
|
950
1236
|
}
|
|
951
1237
|
|
|
952
1238
|
// src/hooks/useConsent.ts
|
|
@@ -972,9 +1258,29 @@ function useConsentTexts() {
|
|
|
972
1258
|
function useConsentHydration() {
|
|
973
1259
|
return useConsentHydrationInternal();
|
|
974
1260
|
}
|
|
1261
|
+
function useOpenPreferencesModal() {
|
|
1262
|
+
const { openPreferences } = useConsent();
|
|
1263
|
+
return openPreferences;
|
|
1264
|
+
}
|
|
1265
|
+
var globalOpenPreferences = null;
|
|
1266
|
+
function openPreferencesModal() {
|
|
1267
|
+
if (globalOpenPreferences) {
|
|
1268
|
+
globalOpenPreferences();
|
|
1269
|
+
} else {
|
|
1270
|
+
console.warn(
|
|
1271
|
+
"openPreferencesModal: ConsentProvider n\xE3o foi inicializado ou n\xE3o est\xE1 dispon\xEDvel."
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function _registerGlobalOpenPreferences(openPreferences) {
|
|
1276
|
+
globalOpenPreferences = openPreferences;
|
|
1277
|
+
}
|
|
1278
|
+
function _unregisterGlobalOpenPreferences() {
|
|
1279
|
+
globalOpenPreferences = null;
|
|
1280
|
+
}
|
|
975
1281
|
|
|
976
1282
|
// src/components/PreferencesModal.tsx
|
|
977
|
-
import { jsx as
|
|
1283
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
978
1284
|
function PreferencesModal2({
|
|
979
1285
|
DialogProps: DialogProps2,
|
|
980
1286
|
hideBranding = false
|
|
@@ -1016,14 +1322,14 @@ function PreferencesModal2({
|
|
|
1016
1322
|
onClose: handleCancel,
|
|
1017
1323
|
...DialogProps2,
|
|
1018
1324
|
children: [
|
|
1019
|
-
/* @__PURE__ */
|
|
1325
|
+
/* @__PURE__ */ jsx8(DialogTitle, { id: "cookie-pref-title", children: texts.modalTitle }),
|
|
1020
1326
|
/* @__PURE__ */ jsxs4(DialogContent, { dividers: true, children: [
|
|
1021
|
-
/* @__PURE__ */
|
|
1327
|
+
/* @__PURE__ */ jsx8(Typography3, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
1022
1328
|
/* @__PURE__ */ jsxs4(FormGroup, { children: [
|
|
1023
|
-
toggleableCategories.map((category) => /* @__PURE__ */
|
|
1329
|
+
toggleableCategories.map((category) => /* @__PURE__ */ jsx8(
|
|
1024
1330
|
FormControlLabel,
|
|
1025
1331
|
{
|
|
1026
|
-
control: /* @__PURE__ */
|
|
1332
|
+
control: /* @__PURE__ */ jsx8(
|
|
1027
1333
|
Switch,
|
|
1028
1334
|
{
|
|
1029
1335
|
checked: tempPreferences[category.id] ?? false,
|
|
@@ -1037,20 +1343,20 @@ function PreferencesModal2({
|
|
|
1037
1343
|
},
|
|
1038
1344
|
category.id
|
|
1039
1345
|
)),
|
|
1040
|
-
/* @__PURE__ */
|
|
1346
|
+
/* @__PURE__ */ jsx8(
|
|
1041
1347
|
FormControlLabel,
|
|
1042
1348
|
{
|
|
1043
|
-
control: /* @__PURE__ */
|
|
1349
|
+
control: /* @__PURE__ */ jsx8(Switch, { checked: true, disabled: true }),
|
|
1044
1350
|
label: texts.necessaryAlwaysOn
|
|
1045
1351
|
}
|
|
1046
1352
|
)
|
|
1047
1353
|
] })
|
|
1048
1354
|
] }),
|
|
1049
1355
|
/* @__PURE__ */ jsxs4(DialogActions, { children: [
|
|
1050
|
-
/* @__PURE__ */
|
|
1051
|
-
/* @__PURE__ */
|
|
1356
|
+
/* @__PURE__ */ jsx8(Button2, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
1357
|
+
/* @__PURE__ */ jsx8(Button2, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
1052
1358
|
] }),
|
|
1053
|
-
!hideBranding && /* @__PURE__ */
|
|
1359
|
+
!hideBranding && /* @__PURE__ */ jsx8(Branding, { variant: "modal" })
|
|
1054
1360
|
]
|
|
1055
1361
|
}
|
|
1056
1362
|
);
|
|
@@ -1061,10 +1367,14 @@ export {
|
|
|
1061
1367
|
analyzeDeveloperConfiguration,
|
|
1062
1368
|
useCategories,
|
|
1063
1369
|
useCategoryStatus,
|
|
1370
|
+
LogLevel,
|
|
1371
|
+
setDebugLogging,
|
|
1064
1372
|
defaultConsentTheme,
|
|
1065
1373
|
ConsentProvider,
|
|
1066
1374
|
useConsent,
|
|
1067
1375
|
useConsentTexts,
|
|
1068
1376
|
useConsentHydration,
|
|
1377
|
+
useOpenPreferencesModal,
|
|
1378
|
+
openPreferencesModal,
|
|
1069
1379
|
PreferencesModal2 as PreferencesModal
|
|
1070
1380
|
};
|