react-lgpd-consent 0.2.1 → 0.2.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/COMPLIANCE.md +231 -87
- package/README.md +118 -20
- package/dist/{PreferencesModal-4WHKT67T.js → PreferencesModal-UL552BFP.js} +1 -1
- package/dist/{chunk-QCERRRSC.js → chunk-JAX63PBG.js} +276 -121
- package/dist/index.cjs +283 -116
- package/dist/index.d.cts +68 -7
- package/dist/index.d.ts +68 -7
- package/dist/index.js +9 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -186,74 +186,212 @@ var init_theme = __esm({
|
|
|
186
186
|
}
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
+
// src/utils/developerGuidance.ts
|
|
190
|
+
function analyzeDeveloperConfiguration(config) {
|
|
191
|
+
const guidance = {
|
|
192
|
+
warnings: [],
|
|
193
|
+
suggestions: [],
|
|
194
|
+
activeCategoriesInfo: [],
|
|
195
|
+
usingDefaults: !config
|
|
196
|
+
};
|
|
197
|
+
const finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
198
|
+
if (!config) {
|
|
199
|
+
guidance.warnings.push(
|
|
200
|
+
'LGPD-CONSENT: Nenhuma configura\xE7\xE3o de categorias especificada. Usando padr\xE3o: necessary + analytics. Para produ\xE7\xE3o, recomenda-se especificar explicitamente as categorias via prop "categories".'
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
guidance.activeCategoriesInfo.push({
|
|
204
|
+
id: "necessary",
|
|
205
|
+
name: "Cookies Necess\xE1rios",
|
|
206
|
+
description: "Essenciais para funcionamento b\xE1sico do site",
|
|
207
|
+
essential: true,
|
|
208
|
+
uiRequired: false
|
|
209
|
+
// Não precisa de toggle (sempre ativo)
|
|
210
|
+
});
|
|
211
|
+
const enabledCategories = finalConfig.enabledCategories || [];
|
|
212
|
+
const categoryNames = {
|
|
213
|
+
analytics: {
|
|
214
|
+
name: "Cookies Anal\xEDticos",
|
|
215
|
+
description: "Medem uso e performance do site"
|
|
216
|
+
},
|
|
217
|
+
functional: {
|
|
218
|
+
name: "Cookies Funcionais",
|
|
219
|
+
description: "Melhoram experi\xEAncia e funcionalidades"
|
|
220
|
+
},
|
|
221
|
+
marketing: {
|
|
222
|
+
name: "Cookies de Marketing",
|
|
223
|
+
description: "Publicidade direcionada e campanhas"
|
|
224
|
+
},
|
|
225
|
+
social: {
|
|
226
|
+
name: "Cookies de Redes Sociais",
|
|
227
|
+
description: "Integra\xE7\xE3o com plataformas sociais"
|
|
228
|
+
},
|
|
229
|
+
personalization: {
|
|
230
|
+
name: "Cookies de Personaliza\xE7\xE3o",
|
|
231
|
+
description: "Adaptam conte\xFAdo \xE0s prefer\xEAncias do usu\xE1rio"
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
enabledCategories.forEach((categoryId) => {
|
|
235
|
+
const categoryInfo = categoryNames[categoryId];
|
|
236
|
+
if (categoryInfo) {
|
|
237
|
+
guidance.activeCategoriesInfo.push({
|
|
238
|
+
id: categoryId,
|
|
239
|
+
name: categoryInfo.name,
|
|
240
|
+
description: categoryInfo.description,
|
|
241
|
+
essential: false,
|
|
242
|
+
uiRequired: true
|
|
243
|
+
// Precisa de toggle na UI
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
const customCategories = finalConfig.customCategories || [];
|
|
248
|
+
customCategories.forEach((category) => {
|
|
249
|
+
guidance.activeCategoriesInfo.push({
|
|
250
|
+
id: category.id,
|
|
251
|
+
name: category.name,
|
|
252
|
+
description: category.description,
|
|
253
|
+
essential: category.essential === true,
|
|
254
|
+
uiRequired: category.essential !== true
|
|
255
|
+
// Apenas não-essenciais precisam toggle
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
const totalToggleable = guidance.activeCategoriesInfo.filter(
|
|
259
|
+
(c) => c.uiRequired
|
|
260
|
+
).length;
|
|
261
|
+
if (totalToggleable === 0) {
|
|
262
|
+
guidance.suggestions.push(
|
|
263
|
+
'Apenas cookies necess\xE1rios est\xE3o configurados. Para compliance completo LGPD, considere adicionar categorias como "analytics" ou "functional" conforme uso real.'
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
if (totalToggleable > 5) {
|
|
267
|
+
guidance.warnings.push(
|
|
268
|
+
`${totalToggleable} categorias opcionais detectadas. UI com muitas op\xE7\xF5es pode ' +
|
|
269
|
+
'prejudicar experi\xEAncia do usu\xE1rio. Considere agrupar categorias similares.`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
const poorDescriptions = customCategories.filter(
|
|
273
|
+
(c) => !c.description || c.description.length < 10
|
|
274
|
+
);
|
|
275
|
+
if (poorDescriptions.length > 0) {
|
|
276
|
+
guidance.warnings.push(
|
|
277
|
+
`Categorias customizadas com descri\xE7\xF5es inadequadas: ${poorDescriptions.map((c) => c.id).join(", ")}. Descri\xE7\xF5es claras s\xE3o obrigat\xF3rias para compliance LGPD.`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return guidance;
|
|
281
|
+
}
|
|
282
|
+
function logDeveloperGuidance(guidance) {
|
|
283
|
+
const isProduction = typeof globalThis !== "undefined" && globalThis.__LGPD_PRODUCTION__ || typeof window !== "undefined" && !window.__LGPD_DEV__;
|
|
284
|
+
if (isProduction) return;
|
|
285
|
+
if (guidance.warnings.length > 0) {
|
|
286
|
+
console.group("\u{1F7E8} LGPD-CONSENT: Avisos de Configura\xE7\xE3o");
|
|
287
|
+
guidance.warnings.forEach((warning) => console.warn(warning));
|
|
288
|
+
console.groupEnd();
|
|
289
|
+
}
|
|
290
|
+
if (guidance.suggestions.length > 0) {
|
|
291
|
+
console.group("\u{1F4A1} LGPD-CONSENT: Sugest\xF5es");
|
|
292
|
+
guidance.suggestions.forEach((suggestion) => console.info(suggestion));
|
|
293
|
+
console.groupEnd();
|
|
294
|
+
}
|
|
295
|
+
if (guidance.usingDefaults) {
|
|
296
|
+
console.info(
|
|
297
|
+
'\u{1F4CB} LGPD-CONSENT: Usando configura\xE7\xE3o padr\xE3o. Para personalizar, use a prop "categories" no ConsentProvider.'
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
console.group("\u{1F527} LGPD-CONSENT: Categorias Ativas (para UI customizada)");
|
|
301
|
+
console.table(
|
|
302
|
+
guidance.activeCategoriesInfo.map((cat) => ({
|
|
303
|
+
ID: cat.id,
|
|
304
|
+
Nome: cat.name,
|
|
305
|
+
"Toggle UI?": cat.uiRequired ? "\u2705 SIM" : "\u274C N\xC3O (sempre ativo)",
|
|
306
|
+
"Essencial?": cat.essential ? "\u{1F512} SIM" : "\u2699\uFE0F N\xC3O"
|
|
307
|
+
}))
|
|
308
|
+
);
|
|
309
|
+
console.groupEnd();
|
|
310
|
+
}
|
|
311
|
+
var React, DEFAULT_PROJECT_CATEGORIES;
|
|
312
|
+
var init_developerGuidance = __esm({
|
|
313
|
+
"src/utils/developerGuidance.ts"() {
|
|
314
|
+
"use strict";
|
|
315
|
+
React = __toESM(require("react"), 1);
|
|
316
|
+
DEFAULT_PROJECT_CATEGORIES = {
|
|
317
|
+
enabledCategories: ["analytics"],
|
|
318
|
+
// Só analytics além de necessary
|
|
319
|
+
customCategories: []
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
189
324
|
// src/context/CategoriesContext.tsx
|
|
190
325
|
function CategoriesProvider({
|
|
326
|
+
children,
|
|
191
327
|
categories,
|
|
192
|
-
|
|
328
|
+
// LEGACY: prop antiga (apenas customCategories)
|
|
329
|
+
config
|
|
330
|
+
// NOVO: configuração completa
|
|
193
331
|
}) {
|
|
194
|
-
const
|
|
195
|
-
|
|
332
|
+
const contextValue = React2.useMemo(() => {
|
|
333
|
+
let finalConfig;
|
|
334
|
+
if (categories && !config) {
|
|
335
|
+
finalConfig = {
|
|
336
|
+
enabledCategories: DEFAULT_PROJECT_CATEGORIES.enabledCategories,
|
|
337
|
+
customCategories: categories
|
|
338
|
+
};
|
|
339
|
+
} else {
|
|
340
|
+
finalConfig = config || DEFAULT_PROJECT_CATEGORIES;
|
|
341
|
+
}
|
|
342
|
+
const guidance = analyzeDeveloperConfiguration(
|
|
343
|
+
config || (categories ? { customCategories: categories } : void 0)
|
|
344
|
+
);
|
|
345
|
+
const toggleableCategories = guidance.activeCategoriesInfo.filter(
|
|
346
|
+
(cat) => cat.uiRequired
|
|
347
|
+
);
|
|
348
|
+
return {
|
|
349
|
+
config: finalConfig,
|
|
350
|
+
guidance,
|
|
351
|
+
toggleableCategories,
|
|
352
|
+
allCategories: guidance.activeCategoriesInfo,
|
|
353
|
+
legacyCategories: categories || []
|
|
354
|
+
};
|
|
355
|
+
}, [config, categories]);
|
|
356
|
+
React2.useEffect(() => {
|
|
357
|
+
logDeveloperGuidance(contextValue.guidance);
|
|
358
|
+
}, [contextValue.guidance]);
|
|
359
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CategoriesContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CategoriesCtx.Provider, { value: contextValue.legacyCategories, children }) });
|
|
196
360
|
}
|
|
197
|
-
function
|
|
198
|
-
|
|
361
|
+
function useCategories() {
|
|
362
|
+
const context = React2.useContext(CategoriesContext);
|
|
363
|
+
if (!context) {
|
|
364
|
+
throw new Error(
|
|
365
|
+
"useCategories deve ser usado dentro de CategoriesProvider. Certifique-se de que o ConsentProvider est\xE1 envolvendo seu componente."
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
return context;
|
|
199
369
|
}
|
|
200
|
-
function
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
name: "Analytics e Estat\xEDsticas",
|
|
214
|
-
description: "Permitem medir audi\xEAncia e desempenho, gerando estat\xEDsticas an\xF4nimas de uso.",
|
|
215
|
-
essential: false,
|
|
216
|
-
cookies: ["_ga", "_ga_*", "_gid", "_gat", "gtag"]
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
id: "functional",
|
|
220
|
-
name: "Cookies Funcionais",
|
|
221
|
-
description: "Melhoram a experi\xEAncia do usu\xE1rio, lembrando prefer\xEAncias e configura\xE7\xF5es.",
|
|
222
|
-
essential: false,
|
|
223
|
-
cookies: ["language", "theme", "timezone", "preferences"]
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
id: "marketing",
|
|
227
|
-
name: "Marketing e Publicidade",
|
|
228
|
-
description: "Utilizados para publicidade direcionada e medi\xE7\xE3o de campanhas publicit\xE1rias.",
|
|
229
|
-
essential: false,
|
|
230
|
-
cookies: ["_fbp", "fr", "tr", "ads_*", "doubleclick"]
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
id: "social",
|
|
234
|
-
name: "Redes Sociais",
|
|
235
|
-
description: "Permitem compartilhamento e integra\xE7\xE3o com redes sociais como Facebook, YouTube, etc.",
|
|
236
|
-
essential: false,
|
|
237
|
-
cookies: ["__Secure-*", "sb", "datr", "c_user", "social_*"]
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
id: "personalization",
|
|
241
|
-
name: "Personaliza\xE7\xE3o",
|
|
242
|
-
description: "Adaptam o conte\xFAdo e interface \xE0s prefer\xEAncias individuais do usu\xE1rio.",
|
|
243
|
-
essential: false,
|
|
244
|
-
cookies: ["personalization_*", "content_*", "layout_*"]
|
|
245
|
-
}
|
|
246
|
-
];
|
|
247
|
-
return [...defaultCategories, ...customCategories];
|
|
248
|
-
}, [customCategories]);
|
|
370
|
+
function useCategoryStatus(categoryId) {
|
|
371
|
+
const { allCategories } = useCategories();
|
|
372
|
+
const category = allCategories.find((cat) => cat.id === categoryId);
|
|
373
|
+
return {
|
|
374
|
+
isActive: !!category,
|
|
375
|
+
isEssential: category?.essential || false,
|
|
376
|
+
needsToggle: category?.uiRequired || false,
|
|
377
|
+
name: category?.name,
|
|
378
|
+
description: category?.description
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function useCustomCategories() {
|
|
382
|
+
return React2.useContext(CategoriesCtx);
|
|
249
383
|
}
|
|
250
|
-
var
|
|
384
|
+
var React2, import_jsx_runtime, CategoriesContext, CategoriesCtx;
|
|
251
385
|
var init_CategoriesContext = __esm({
|
|
252
386
|
"src/context/CategoriesContext.tsx"() {
|
|
253
387
|
"use strict";
|
|
254
|
-
|
|
388
|
+
React2 = __toESM(require("react"), 1);
|
|
389
|
+
init_developerGuidance();
|
|
255
390
|
import_jsx_runtime = require("react/jsx-runtime");
|
|
256
|
-
|
|
391
|
+
CategoriesContext = React2.createContext(
|
|
392
|
+
null
|
|
393
|
+
);
|
|
394
|
+
CategoriesCtx = React2.createContext([]);
|
|
257
395
|
}
|
|
258
396
|
});
|
|
259
397
|
|
|
@@ -333,12 +471,25 @@ function PreferencesModal({
|
|
|
333
471
|
}) {
|
|
334
472
|
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
335
473
|
const texts = useConsentTexts();
|
|
336
|
-
const
|
|
474
|
+
const { toggleableCategories } = useCategories();
|
|
475
|
+
const [tempPreferences, setTempPreferences] = (0, import_react.useState)(
|
|
476
|
+
() => {
|
|
477
|
+
const initialPrefs = { necessary: true };
|
|
478
|
+
toggleableCategories.forEach((category) => {
|
|
479
|
+
initialPrefs[category.id] = preferences[category.id] ?? false;
|
|
480
|
+
});
|
|
481
|
+
return initialPrefs;
|
|
482
|
+
}
|
|
483
|
+
);
|
|
337
484
|
(0, import_react.useEffect)(() => {
|
|
338
485
|
if (isModalOpen) {
|
|
339
|
-
|
|
486
|
+
const syncedPrefs = { necessary: true };
|
|
487
|
+
toggleableCategories.forEach((category) => {
|
|
488
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
489
|
+
});
|
|
490
|
+
setTempPreferences(syncedPrefs);
|
|
340
491
|
}
|
|
341
|
-
}, [isModalOpen, preferences]);
|
|
492
|
+
}, [isModalOpen, preferences, toggleableCategories]);
|
|
342
493
|
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
343
494
|
const handleSave = () => {
|
|
344
495
|
setPreferences(tempPreferences);
|
|
@@ -359,38 +510,23 @@ function PreferencesModal({
|
|
|
359
510
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_DialogContent.default, { dividers: true, children: [
|
|
360
511
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_Typography2.default, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
361
512
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_FormGroup.default, { children: [
|
|
362
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
363
|
-
import_FormControlLabel.default,
|
|
364
|
-
{
|
|
365
|
-
control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
366
|
-
import_Switch.default,
|
|
367
|
-
{
|
|
368
|
-
checked: tempPreferences.analytics,
|
|
369
|
-
onChange: (e) => setTempPreferences((prev) => ({
|
|
370
|
-
...prev,
|
|
371
|
-
analytics: e.target.checked
|
|
372
|
-
}))
|
|
373
|
-
}
|
|
374
|
-
),
|
|
375
|
-
label: "Cookies Anal\xEDticos (medem uso do site)"
|
|
376
|
-
}
|
|
377
|
-
),
|
|
378
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
513
|
+
toggleableCategories.map((category) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
379
514
|
import_FormControlLabel.default,
|
|
380
515
|
{
|
|
381
516
|
control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
382
517
|
import_Switch.default,
|
|
383
518
|
{
|
|
384
|
-
checked: tempPreferences.
|
|
519
|
+
checked: tempPreferences[category.id] ?? false,
|
|
385
520
|
onChange: (e) => setTempPreferences((prev) => ({
|
|
386
521
|
...prev,
|
|
387
|
-
|
|
522
|
+
[category.id]: e.target.checked
|
|
388
523
|
}))
|
|
389
524
|
}
|
|
390
525
|
),
|
|
391
|
-
label:
|
|
392
|
-
}
|
|
393
|
-
|
|
526
|
+
label: `${category.name} - ${category.description}`
|
|
527
|
+
},
|
|
528
|
+
category.id
|
|
529
|
+
)),
|
|
394
530
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
395
531
|
import_FormControlLabel.default,
|
|
396
532
|
{
|
|
@@ -423,6 +559,7 @@ var init_PreferencesModal = __esm({
|
|
|
423
559
|
import_Switch = __toESM(require("@mui/material/Switch"), 1);
|
|
424
560
|
import_Typography2 = __toESM(require("@mui/material/Typography"), 1);
|
|
425
561
|
import_react = require("react");
|
|
562
|
+
init_CategoriesContext();
|
|
426
563
|
init_useConsent();
|
|
427
564
|
init_Branding();
|
|
428
565
|
import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -515,9 +652,12 @@ function reducer(state, action) {
|
|
|
515
652
|
}
|
|
516
653
|
function ConsentProvider({
|
|
517
654
|
initialState,
|
|
655
|
+
categories,
|
|
656
|
+
// NOVO: configuração completa de categorias
|
|
518
657
|
texts: textsProp,
|
|
519
658
|
theme,
|
|
520
659
|
customCategories,
|
|
660
|
+
// LEGACY: compatibilidade
|
|
521
661
|
scriptIntegrations,
|
|
522
662
|
PreferencesModalComponent,
|
|
523
663
|
preferencesModalProps = {},
|
|
@@ -528,19 +668,30 @@ function ConsentProvider({
|
|
|
528
668
|
cookie: cookieOpts,
|
|
529
669
|
children
|
|
530
670
|
}) {
|
|
531
|
-
const texts =
|
|
671
|
+
const texts = React3.useMemo(
|
|
532
672
|
() => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }),
|
|
533
673
|
[textsProp]
|
|
534
674
|
);
|
|
535
|
-
const cookie =
|
|
675
|
+
const cookie = React3.useMemo(
|
|
536
676
|
() => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
|
|
537
677
|
[cookieOpts]
|
|
538
678
|
);
|
|
539
|
-
const appliedTheme =
|
|
679
|
+
const appliedTheme = React3.useMemo(
|
|
540
680
|
() => theme || defaultConsentTheme,
|
|
541
681
|
[theme]
|
|
542
682
|
);
|
|
543
|
-
const
|
|
683
|
+
const finalCategoriesConfig = React3.useMemo(() => {
|
|
684
|
+
if (categories) return categories;
|
|
685
|
+
if (customCategories) {
|
|
686
|
+
return {
|
|
687
|
+
enabledCategories: ["analytics"],
|
|
688
|
+
// padrão quando usando API antiga
|
|
689
|
+
customCategories
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
return void 0;
|
|
693
|
+
}, [categories, customCategories]);
|
|
694
|
+
const boot = React3.useMemo(() => {
|
|
544
695
|
if (initialState) return { ...initialState, isModalOpen: false };
|
|
545
696
|
return createFullConsentState(
|
|
546
697
|
false,
|
|
@@ -549,9 +700,9 @@ function ConsentProvider({
|
|
|
549
700
|
false
|
|
550
701
|
);
|
|
551
702
|
}, [initialState, customCategories]);
|
|
552
|
-
const [state, dispatch] =
|
|
553
|
-
const [isHydrated, setIsHydrated] =
|
|
554
|
-
|
|
703
|
+
const [state, dispatch] = React3.useReducer(reducer, boot);
|
|
704
|
+
const [isHydrated, setIsHydrated] = React3.useState(false);
|
|
705
|
+
React3.useEffect(() => {
|
|
555
706
|
if (!initialState) {
|
|
556
707
|
const saved = readConsentCookie(cookie.name);
|
|
557
708
|
if (saved?.consented) {
|
|
@@ -561,24 +712,24 @@ function ConsentProvider({
|
|
|
561
712
|
}
|
|
562
713
|
setIsHydrated(true);
|
|
563
714
|
}, [cookie.name, initialState]);
|
|
564
|
-
|
|
715
|
+
React3.useEffect(() => {
|
|
565
716
|
if (state.consented) writeConsentCookie(state, state.source, cookie);
|
|
566
717
|
}, [state, cookie]);
|
|
567
|
-
const prevConsented =
|
|
568
|
-
|
|
718
|
+
const prevConsented = React3.useRef(state.consented);
|
|
719
|
+
React3.useEffect(() => {
|
|
569
720
|
if (!prevConsented.current && state.consented && onConsentGiven) {
|
|
570
721
|
setTimeout(() => onConsentGiven(state), 150);
|
|
571
722
|
}
|
|
572
723
|
prevConsented.current = state.consented;
|
|
573
724
|
}, [state, onConsentGiven]);
|
|
574
|
-
const prevPrefs =
|
|
575
|
-
|
|
725
|
+
const prevPrefs = React3.useRef(state.preferences);
|
|
726
|
+
React3.useEffect(() => {
|
|
576
727
|
if (state.consented && onPreferencesSaved && prevPrefs.current !== state.preferences) {
|
|
577
728
|
setTimeout(() => onPreferencesSaved(state.preferences), 150);
|
|
578
729
|
prevPrefs.current = state.preferences;
|
|
579
730
|
}
|
|
580
731
|
}, [state, onPreferencesSaved]);
|
|
581
|
-
const api =
|
|
732
|
+
const api = React3.useMemo(() => {
|
|
582
733
|
const acceptAll = () => dispatch({ type: "ACCEPT_ALL", customCategories });
|
|
583
734
|
const rejectAll = () => dispatch({ type: "REJECT_ALL", customCategories });
|
|
584
735
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
@@ -602,41 +753,48 @@ function ConsentProvider({
|
|
|
602
753
|
resetConsent
|
|
603
754
|
};
|
|
604
755
|
}, [state, cookie, customCategories]);
|
|
605
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_styles2.ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StateCtx.Provider, { value: state, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
756
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_styles2.ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StateCtx.Provider, { value: state, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
757
|
+
CategoriesProvider,
|
|
758
|
+
{
|
|
759
|
+
config: finalCategoriesConfig,
|
|
760
|
+
categories: customCategories,
|
|
761
|
+
children: [
|
|
762
|
+
children,
|
|
763
|
+
!disableAutomaticModal && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(React3.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PreferencesModalComponent, { ...preferencesModalProps }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PreferencesModal2, { hideBranding }) })
|
|
764
|
+
]
|
|
765
|
+
}
|
|
766
|
+
) }) }) }) }) });
|
|
609
767
|
}
|
|
610
768
|
function useConsentStateInternal() {
|
|
611
|
-
const ctx =
|
|
769
|
+
const ctx = React3.useContext(StateCtx);
|
|
612
770
|
if (!ctx)
|
|
613
771
|
throw new Error("useConsentState must be used within ConsentProvider");
|
|
614
772
|
return ctx;
|
|
615
773
|
}
|
|
616
774
|
function useConsentActionsInternal() {
|
|
617
|
-
const ctx =
|
|
775
|
+
const ctx = React3.useContext(ActionsCtx);
|
|
618
776
|
if (!ctx)
|
|
619
777
|
throw new Error("useConsentActions must be used within ConsentProvider");
|
|
620
778
|
return ctx;
|
|
621
779
|
}
|
|
622
780
|
function useConsentTextsInternal() {
|
|
623
|
-
const ctx =
|
|
781
|
+
const ctx = React3.useContext(TextsCtx);
|
|
624
782
|
return ctx;
|
|
625
783
|
}
|
|
626
784
|
function useConsentHydrationInternal() {
|
|
627
|
-
return
|
|
785
|
+
return React3.useContext(HydrationCtx);
|
|
628
786
|
}
|
|
629
|
-
var
|
|
787
|
+
var React3, import_styles2, import_jsx_runtime4, PreferencesModal2, DEFAULT_PREFERENCES, DEFAULT_TEXTS, StateCtx, ActionsCtx, TextsCtx, HydrationCtx;
|
|
630
788
|
var init_ConsentContext = __esm({
|
|
631
789
|
"src/context/ConsentContext.tsx"() {
|
|
632
790
|
"use strict";
|
|
633
|
-
|
|
791
|
+
React3 = __toESM(require("react"), 1);
|
|
634
792
|
import_styles2 = require("@mui/material/styles");
|
|
635
793
|
init_cookieUtils();
|
|
636
794
|
init_theme();
|
|
637
795
|
init_CategoriesContext();
|
|
638
796
|
import_jsx_runtime4 = require("react/jsx-runtime");
|
|
639
|
-
PreferencesModal2 =
|
|
797
|
+
PreferencesModal2 = React3.lazy(
|
|
640
798
|
() => Promise.resolve().then(() => (init_PreferencesModal(), PreferencesModal_exports)).then((m) => ({
|
|
641
799
|
default: m.PreferencesModal
|
|
642
800
|
}))
|
|
@@ -674,10 +832,10 @@ var init_ConsentContext = __esm({
|
|
|
674
832
|
transferCountries: void 0
|
|
675
833
|
// Exibido se definido
|
|
676
834
|
};
|
|
677
|
-
StateCtx =
|
|
678
|
-
ActionsCtx =
|
|
679
|
-
TextsCtx =
|
|
680
|
-
HydrationCtx =
|
|
835
|
+
StateCtx = React3.createContext(null);
|
|
836
|
+
ActionsCtx = React3.createContext(null);
|
|
837
|
+
TextsCtx = React3.createContext(DEFAULT_TEXTS);
|
|
838
|
+
HydrationCtx = React3.createContext(false);
|
|
681
839
|
}
|
|
682
840
|
});
|
|
683
841
|
|
|
@@ -719,14 +877,17 @@ __export(index_exports, {
|
|
|
719
877
|
ConsentProvider: () => ConsentProvider,
|
|
720
878
|
ConsentScriptLoader: () => ConsentScriptLoader,
|
|
721
879
|
CookieBanner: () => CookieBanner,
|
|
880
|
+
DEFAULT_PROJECT_CATEGORIES: () => DEFAULT_PROJECT_CATEGORIES,
|
|
722
881
|
FloatingPreferencesButton: () => FloatingPreferencesButton,
|
|
723
882
|
PreferencesModal: () => PreferencesModal,
|
|
883
|
+
analyzeDeveloperConfiguration: () => analyzeDeveloperConfiguration,
|
|
724
884
|
createGoogleAnalyticsIntegration: () => createGoogleAnalyticsIntegration,
|
|
725
885
|
createGoogleTagManagerIntegration: () => createGoogleTagManagerIntegration,
|
|
726
886
|
createUserWayIntegration: () => createUserWayIntegration,
|
|
727
887
|
defaultConsentTheme: () => defaultConsentTheme,
|
|
728
888
|
loadScript: () => loadScript,
|
|
729
|
-
|
|
889
|
+
useCategories: () => useCategories,
|
|
890
|
+
useCategoryStatus: () => useCategoryStatus,
|
|
730
891
|
useConsent: () => useConsent,
|
|
731
892
|
useConsentHydration: () => useConsentHydration,
|
|
732
893
|
useConsentScriptLoader: () => useConsentScriptLoader,
|
|
@@ -960,15 +1121,15 @@ function loadScript(id, src, category = null, attrs = {}) {
|
|
|
960
1121
|
init_theme();
|
|
961
1122
|
|
|
962
1123
|
// src/utils/ConsentScriptLoader.tsx
|
|
963
|
-
var
|
|
1124
|
+
var React4 = __toESM(require("react"), 1);
|
|
964
1125
|
init_useConsent();
|
|
965
1126
|
function ConsentScriptLoader({
|
|
966
1127
|
integrations,
|
|
967
1128
|
reloadOnChange = false
|
|
968
1129
|
}) {
|
|
969
1130
|
const { preferences, consented } = useConsent();
|
|
970
|
-
const loadedScripts =
|
|
971
|
-
|
|
1131
|
+
const loadedScripts = React4.useRef(/* @__PURE__ */ new Set());
|
|
1132
|
+
React4.useEffect(() => {
|
|
972
1133
|
if (!consented) return;
|
|
973
1134
|
integrations.forEach(async (integration) => {
|
|
974
1135
|
const shouldLoad = preferences[integration.category];
|
|
@@ -999,7 +1160,7 @@ function ConsentScriptLoader({
|
|
|
999
1160
|
}
|
|
1000
1161
|
function useConsentScriptLoader() {
|
|
1001
1162
|
const { preferences, consented } = useConsent();
|
|
1002
|
-
return
|
|
1163
|
+
return React4.useCallback(
|
|
1003
1164
|
async (integration) => {
|
|
1004
1165
|
if (!consented) {
|
|
1005
1166
|
console.warn(
|
|
@@ -1096,6 +1257,9 @@ var COMMON_INTEGRATIONS = {
|
|
|
1096
1257
|
googleTagManager: createGoogleTagManagerIntegration,
|
|
1097
1258
|
userway: createUserWayIntegration
|
|
1098
1259
|
};
|
|
1260
|
+
|
|
1261
|
+
// src/index.ts
|
|
1262
|
+
init_developerGuidance();
|
|
1099
1263
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1100
1264
|
0 && (module.exports = {
|
|
1101
1265
|
COMMON_INTEGRATIONS,
|
|
@@ -1103,14 +1267,17 @@ var COMMON_INTEGRATIONS = {
|
|
|
1103
1267
|
ConsentProvider,
|
|
1104
1268
|
ConsentScriptLoader,
|
|
1105
1269
|
CookieBanner,
|
|
1270
|
+
DEFAULT_PROJECT_CATEGORIES,
|
|
1106
1271
|
FloatingPreferencesButton,
|
|
1107
1272
|
PreferencesModal,
|
|
1273
|
+
analyzeDeveloperConfiguration,
|
|
1108
1274
|
createGoogleAnalyticsIntegration,
|
|
1109
1275
|
createGoogleTagManagerIntegration,
|
|
1110
1276
|
createUserWayIntegration,
|
|
1111
1277
|
defaultConsentTheme,
|
|
1112
1278
|
loadScript,
|
|
1113
|
-
|
|
1279
|
+
useCategories,
|
|
1280
|
+
useCategoryStatus,
|
|
1114
1281
|
useConsent,
|
|
1115
1282
|
useConsentHydration,
|
|
1116
1283
|
useConsentScriptLoader,
|