react-lgpd-consent 0.1.12 → 0.2.0
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/README.md +124 -34
- package/dist/{PreferencesModal-IFKCHTF2.js → PreferencesModal-QQOOLRDY.js} +1 -1
- package/dist/{chunk-V54LZT2Q.js → chunk-JTPCDTOQ.js} +173 -57
- package/dist/index.cjs +361 -85
- package/dist/index.d.cts +158 -7
- package/dist/index.d.ts +158 -7
- package/dist/index.js +150 -3
- package/package.json +105 -100
package/README.md
CHANGED
|
@@ -2,38 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/react-lgpd-consent)
|
|
4
4
|
[](https://github.com/lucianoedipo/react-lgpd-consent/blob/main/LICENSE)
|
|
5
|
-
[](https://## 🔧 API Completa
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> **📖 Documentação Detalhada**: [API v0.2.0](./docs/API-v0.2.0.md) | [API v0.1.x (Legacy)](./docs/API-0.1.x.md)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```tsx
|
|
12
|
-
import { FloatingPreferencesButton } from 'react-lgpd-consent'
|
|
13
|
-
|
|
14
|
-
function App() {
|
|
15
|
-
return (
|
|
16
|
-
<ConsentProvider>
|
|
17
|
-
<MeuApp />
|
|
18
|
-
<CookieBanner />
|
|
19
|
-
|
|
20
|
-
{/* Botão flutuante opcional */}
|
|
21
|
-
<FloatingPreferencesButton
|
|
22
|
-
position="bottom-right"
|
|
23
|
-
hideWhenConsented={false}
|
|
24
|
-
tooltip="Configurar Cookies"
|
|
25
|
-
/>
|
|
26
|
-
</ConsentProvider>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Posições Disponíveis
|
|
32
|
-
|
|
33
|
-
- `bottom-left` | `bottom-right` (padrão)
|
|
34
|
-
- `top-left` | `top-right`
|
|
35
|
-
|
|
36
|
-
## 🔧 API Completahttps://img.shields.io/badge/TypeScript-Ready-blue?style=for-the-badge&logo=typescript)](https://www.typescriptlang.org/)
|
|
9
|
+
### Components.typescriptlang.org/)
|
|
37
10
|
|
|
38
11
|
[](https://reactjs.org/)
|
|
39
12
|
[](https://mui.com/)
|
|
@@ -44,17 +17,19 @@ Solução moderna, acessível e personalizável para gerenciar consentimento de
|
|
|
44
17
|
|
|
45
18
|
## ✨ Características Principais
|
|
46
19
|
|
|
47
|
-
- 🇧🇷 **Conformidade LGPD**:
|
|
48
|
-
-
|
|
20
|
+
- 🇧🇷 **Conformidade LGPD + ANPD**: 6 categorias baseadas no Guia Orientativo da ANPD
|
|
21
|
+
- 🍪 **Categorias Extensíveis**: Sistema dinâmico para categorias customizadas
|
|
22
|
+
- 🚀 **Integrações Nativas**: Google Analytics, Tag Manager, UserWay automatizados
|
|
23
|
+
- ⚡ **Client-Side First**: Arquitetura otimizada para SPA com zero-flash
|
|
49
24
|
- 🎨 **Material-UI Integration**: Componentes prontos e customizáveis com MUI
|
|
50
25
|
- ♿ **Acessibilidade**: Navegação por teclado e leitores de tela nativamente suportados
|
|
51
26
|
- 🌐 **Internacionalização**: Textos totalmente customizáveis (padrão pt-BR)
|
|
52
27
|
- 🚀 **TypeScript**: API completamente tipada para melhor DX
|
|
53
28
|
- 📦 **Zero Config**: Funciona out-of-the-box com configurações sensatas
|
|
54
|
-
- 🎯 **Granular Control**: Controle individual de categorias
|
|
29
|
+
- 🎯 **Granular Control**: Controle individual de 6+ categorias de cookies
|
|
55
30
|
- 🚫 **Banner Bloqueante**: Modo opcional para exigir interação antes de continuar
|
|
56
31
|
- 🎨 **Sistema de Temas**: Temas customizáveis para integração visual perfeita
|
|
57
|
-
- ⚡ **Carregamento
|
|
32
|
+
- ⚡ **Carregamento Automático**: Scripts só executam após consentimento explícito
|
|
58
33
|
- 🔌 **Modal Automático**: Modal de preferências incluído automaticamente com lazy loading
|
|
59
34
|
- 🎛️ **Botão Flutuante**: Componente opcional para acesso fácil às preferências
|
|
60
35
|
|
|
@@ -74,6 +49,95 @@ pnpm add react-lgpd-consent
|
|
|
74
49
|
npm install @mui/material js-cookie
|
|
75
50
|
```
|
|
76
51
|
|
|
52
|
+
## 🆕 Novidades v0.2.0 - Adequação ANPD Completa
|
|
53
|
+
|
|
54
|
+
### 🍪 Categorias Baseadas no Guia da ANPD
|
|
55
|
+
|
|
56
|
+
A biblioteca agora inclui **6 categorias** baseadas no Guia Orientativo da ANPD:
|
|
57
|
+
|
|
58
|
+
- **`necessary`**: Cookies essenciais (sempre ativos)
|
|
59
|
+
- **`analytics`**: Análise e estatísticas de uso
|
|
60
|
+
- **`functional`**: Funcionalidades extras (preferências, idioma)
|
|
61
|
+
- **`marketing`**: Publicidade e marketing direcionado
|
|
62
|
+
- **`social`**: Integração com redes sociais
|
|
63
|
+
- **`personalization`**: Personalização de conteúdo
|
|
64
|
+
|
|
65
|
+
### 🔧 Categorias Customizadas
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
const customCategories = [
|
|
69
|
+
{
|
|
70
|
+
id: 'governo',
|
|
71
|
+
name: 'Integração Governo',
|
|
72
|
+
description: 'Cookies para integração com sistemas governamentais.',
|
|
73
|
+
essential: false,
|
|
74
|
+
cookies: ['gov_session', 'cpf_hash']
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'acessibilidade',
|
|
78
|
+
name: 'Acessibilidade',
|
|
79
|
+
description: 'Ferramentas para melhorar acessibilidade.',
|
|
80
|
+
essential: false,
|
|
81
|
+
cookies: ['userway_*', 'voice_*']
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
<ConsentProvider customCategories={customCategories}>
|
|
86
|
+
{/* Sua aplicação */}
|
|
87
|
+
</ConsentProvider>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 🚀 Integrações Automáticas
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import {
|
|
94
|
+
ConsentScriptLoader,
|
|
95
|
+
createGoogleAnalyticsIntegration,
|
|
96
|
+
createUserWayIntegration,
|
|
97
|
+
} from 'react-lgpd-consent'
|
|
98
|
+
|
|
99
|
+
const integrations = [
|
|
100
|
+
createGoogleAnalyticsIntegration({
|
|
101
|
+
measurementId: 'GA_MEASUREMENT_ID',
|
|
102
|
+
}),
|
|
103
|
+
createUserWayIntegration({
|
|
104
|
+
accountId: 'USERWAY_ACCOUNT_ID',
|
|
105
|
+
}),
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
function App() {
|
|
109
|
+
return (
|
|
110
|
+
<ConsentProvider>
|
|
111
|
+
{/* Scripts carregam automaticamente quando categoria é aceita */}
|
|
112
|
+
<ConsentScriptLoader integrations={integrations} />
|
|
113
|
+
|
|
114
|
+
<CookieBanner policyLinkUrl="/privacy-policy" />
|
|
115
|
+
</ConsentProvider>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 📝 Textos ANPD Expandidos
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
<ConsentProvider
|
|
124
|
+
texts={{
|
|
125
|
+
bannerMessage: 'Utilizamos cookies para melhorar sua experiência.',
|
|
126
|
+
// Textos ANPD opcionais
|
|
127
|
+
controllerInfo: 'Controlado por Empresa LTDA (CNPJ: 00.000.000/0001-00)',
|
|
128
|
+
dataTypes: 'Coletamos dados de navegação, preferências e interações.',
|
|
129
|
+
thirdPartySharing: 'Compartilhamos com: Google Analytics, Facebook Pixel',
|
|
130
|
+
userRights: 'Você tem direito a acesso, correção e exclusão dos dados.',
|
|
131
|
+
contactInfo: 'Contato DPO: dpo@empresa.com.br | (11) 9999-9999',
|
|
132
|
+
retentionPeriod: 'Dados armazenados por até 12 meses.',
|
|
133
|
+
lawfulBasis: 'Base legal: consentimento do titular dos dados.',
|
|
134
|
+
transferCountries: 'Dados podem ser transferidos para: EUA, Irlanda.',
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{/* Os textos são exibidos condicionalmente apenas se definidos */}
|
|
138
|
+
</ConsentProvider>
|
|
139
|
+
```
|
|
140
|
+
|
|
77
141
|
## � Exemplo Completo
|
|
78
142
|
|
|
79
143
|
```tsx
|
|
@@ -478,6 +542,32 @@ Este projeto está licenciado sob a Licença MIT - veja o arquivo [LICENSE](LICE
|
|
|
478
542
|
- 🐛 [Issues](https://github.com/lucianoedipo/react-lgpd-consent/issues)
|
|
479
543
|
- 💬 [Discussões](https://github.com/lucianoedipo/react-lgpd-consent/discussions)
|
|
480
544
|
|
|
545
|
+
## 🔮 Roadmap
|
|
546
|
+
|
|
547
|
+
### v0.2.1 - Compliance Avançado (Próxima Release)
|
|
548
|
+
|
|
549
|
+
**Baseado em feedback de uso real em projetos governamentais:**
|
|
550
|
+
|
|
551
|
+
- 📋 **Sistema de Logs de Auditoria**: Rastreamento completo para prestação de contas
|
|
552
|
+
- 📜 **Templates Setoriais**: Textos pré-configurados (governo, saúde, educação)
|
|
553
|
+
- 🎨 **Presets Visuais**: Identidade visual por setor (acessibilidade WCAG AAA)
|
|
554
|
+
- 📊 **Dashboard para DPOs**: Relatórios automáticos de compliance
|
|
555
|
+
- 🔌 **Mais Integrações**: Microsoft Clarity, Hotjar, Intercom, LinkedIn
|
|
556
|
+
|
|
557
|
+
### v0.3.0 - Multi-Regulamentação
|
|
558
|
+
|
|
559
|
+
- 🌍 **Suporte GDPR/CCPA**: Detecção automática por geolocalização
|
|
560
|
+
- 🏗️ **Sistema de Plugins**: Extensões de terceiros
|
|
561
|
+
- 🎭 **Temas Avançados**: Design system tokens
|
|
562
|
+
|
|
563
|
+
### v0.4.0 - Enterprise
|
|
564
|
+
|
|
565
|
+
- 📈 **Analytics Avançadas**: Dashboards completos
|
|
566
|
+
- 🔄 **Sync Multi-Domínio**: Consentimento compartilhado
|
|
567
|
+
- 🛡️ **Segurança Empresarial**: Criptografia, audit logs remotos
|
|
568
|
+
|
|
569
|
+
[📋 Ver plano detalhado v0.2.1](./docs/v0.2.1-PLAN.md)
|
|
570
|
+
|
|
481
571
|
---
|
|
482
572
|
|
|
483
573
|
<div align="center">
|
|
@@ -11,7 +11,7 @@ import Typography2 from "@mui/material/Typography";
|
|
|
11
11
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
12
12
|
|
|
13
13
|
// src/context/ConsentContext.tsx
|
|
14
|
-
import * as
|
|
14
|
+
import * as React2 from "react";
|
|
15
15
|
import { ThemeProvider } from "@mui/material/styles";
|
|
16
16
|
|
|
17
17
|
// src/utils/cookieUtils.ts
|
|
@@ -117,18 +117,98 @@ var defaultConsentTheme = createTheme({
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
// src/context/CategoriesContext.tsx
|
|
121
|
+
import * as React from "react";
|
|
122
|
+
import { jsx } from "react/jsx-runtime";
|
|
123
|
+
var CategoriesCtx = React.createContext([]);
|
|
124
|
+
function CategoriesProvider({
|
|
125
|
+
categories,
|
|
126
|
+
children
|
|
127
|
+
}) {
|
|
128
|
+
const value = React.useMemo(() => categories || [], [categories]);
|
|
129
|
+
return /* @__PURE__ */ jsx(CategoriesCtx.Provider, { value, children });
|
|
130
|
+
}
|
|
131
|
+
function useCustomCategories() {
|
|
132
|
+
return React.useContext(CategoriesCtx);
|
|
133
|
+
}
|
|
134
|
+
function useAllCategories() {
|
|
135
|
+
const customCategories = useCustomCategories();
|
|
136
|
+
return React.useMemo(() => {
|
|
137
|
+
const defaultCategories = [
|
|
138
|
+
{
|
|
139
|
+
id: "necessary",
|
|
140
|
+
name: "Cookies Necess\xE1rios",
|
|
141
|
+
description: "Essenciais para o funcionamento b\xE1sico do site. Incluem cookies de sess\xE3o, autentica\xE7\xE3o e seguran\xE7a.",
|
|
142
|
+
essential: true,
|
|
143
|
+
cookies: ["PHPSESSID", "JSESSIONID", "cookieConsent", "csrf_token"]
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: "analytics",
|
|
147
|
+
name: "Analytics e Estat\xEDsticas",
|
|
148
|
+
description: "Permitem medir audi\xEAncia e desempenho, gerando estat\xEDsticas an\xF4nimas de uso.",
|
|
149
|
+
essential: false,
|
|
150
|
+
cookies: ["_ga", "_ga_*", "_gid", "_gat", "gtag"]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: "functional",
|
|
154
|
+
name: "Cookies Funcionais",
|
|
155
|
+
description: "Melhoram a experi\xEAncia do usu\xE1rio, lembrando prefer\xEAncias e configura\xE7\xF5es.",
|
|
156
|
+
essential: false,
|
|
157
|
+
cookies: ["language", "theme", "timezone", "preferences"]
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: "marketing",
|
|
161
|
+
name: "Marketing e Publicidade",
|
|
162
|
+
description: "Utilizados para publicidade direcionada e medi\xE7\xE3o de campanhas publicit\xE1rias.",
|
|
163
|
+
essential: false,
|
|
164
|
+
cookies: ["_fbp", "fr", "tr", "ads_*", "doubleclick"]
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: "social",
|
|
168
|
+
name: "Redes Sociais",
|
|
169
|
+
description: "Permitem compartilhamento e integra\xE7\xE3o com redes sociais como Facebook, YouTube, etc.",
|
|
170
|
+
essential: false,
|
|
171
|
+
cookies: ["__Secure-*", "sb", "datr", "c_user", "social_*"]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: "personalization",
|
|
175
|
+
name: "Personaliza\xE7\xE3o",
|
|
176
|
+
description: "Adaptam o conte\xFAdo e interface \xE0s prefer\xEAncias individuais do usu\xE1rio.",
|
|
177
|
+
essential: false,
|
|
178
|
+
cookies: ["personalization_*", "content_*", "layout_*"]
|
|
179
|
+
}
|
|
180
|
+
];
|
|
181
|
+
return [...defaultCategories, ...customCategories];
|
|
182
|
+
}, [customCategories]);
|
|
183
|
+
}
|
|
184
|
+
|
|
120
185
|
// src/context/ConsentContext.tsx
|
|
121
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
122
|
-
var PreferencesModal =
|
|
123
|
-
() => import("./PreferencesModal-
|
|
186
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
187
|
+
var PreferencesModal = React2.lazy(
|
|
188
|
+
() => import("./PreferencesModal-QQOOLRDY.js").then((m) => ({
|
|
124
189
|
default: m.PreferencesModal
|
|
125
190
|
}))
|
|
126
191
|
);
|
|
127
192
|
var DEFAULT_PREFERENCES = {
|
|
193
|
+
necessary: true,
|
|
194
|
+
// Sempre ativo (essencial)
|
|
128
195
|
analytics: false,
|
|
129
|
-
|
|
196
|
+
functional: false,
|
|
197
|
+
marketing: false,
|
|
198
|
+
social: false,
|
|
199
|
+
personalization: false
|
|
130
200
|
};
|
|
201
|
+
function createInitialPreferences(customCategories) {
|
|
202
|
+
const prefs = { ...DEFAULT_PREFERENCES };
|
|
203
|
+
if (customCategories) {
|
|
204
|
+
customCategories.forEach((category) => {
|
|
205
|
+
prefs[category.id] = category.essential === true;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return prefs;
|
|
209
|
+
}
|
|
131
210
|
var DEFAULT_TEXTS = {
|
|
211
|
+
// Textos básicos
|
|
132
212
|
bannerMessage: "Utilizamos cookies para melhorar sua experi\xEAncia.",
|
|
133
213
|
acceptAll: "Aceitar todos",
|
|
134
214
|
declineAll: "Recusar",
|
|
@@ -137,22 +217,53 @@ var DEFAULT_TEXTS = {
|
|
|
137
217
|
modalTitle: "Prefer\xEAncias de Cookies",
|
|
138
218
|
modalIntro: "Ajuste as categorias de cookies. Cookies necess\xE1rios s\xE3o sempre utilizados para funcionalidades b\xE1sicas.",
|
|
139
219
|
save: "Salvar prefer\xEAncias",
|
|
140
|
-
necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)"
|
|
220
|
+
necessaryAlwaysOn: "Cookies necess\xE1rios (sempre ativos)",
|
|
221
|
+
// Textos ANPD expandidos (opcionais)
|
|
222
|
+
controllerInfo: void 0,
|
|
223
|
+
// Exibido se definido
|
|
224
|
+
dataTypes: void 0,
|
|
225
|
+
// Exibido se definido
|
|
226
|
+
thirdPartySharing: void 0,
|
|
227
|
+
// Exibido se definido
|
|
228
|
+
userRights: void 0,
|
|
229
|
+
// Exibido se definido
|
|
230
|
+
contactInfo: void 0,
|
|
231
|
+
// Exibido se definido
|
|
232
|
+
retentionPeriod: void 0,
|
|
233
|
+
// Exibido se definido
|
|
234
|
+
lawfulBasis: void 0,
|
|
235
|
+
// Exibido se definido
|
|
236
|
+
transferCountries: void 0
|
|
237
|
+
// Exibido se definido
|
|
141
238
|
};
|
|
142
239
|
function reducer(state, action) {
|
|
143
240
|
switch (action.type) {
|
|
144
|
-
case "ACCEPT_ALL":
|
|
241
|
+
case "ACCEPT_ALL": {
|
|
242
|
+
const prefs = createInitialPreferences(action.customCategories);
|
|
243
|
+
Object.keys(prefs).forEach((key) => {
|
|
244
|
+
prefs[key] = true;
|
|
245
|
+
});
|
|
145
246
|
return {
|
|
146
247
|
consented: true,
|
|
147
|
-
preferences:
|
|
248
|
+
preferences: prefs,
|
|
148
249
|
isModalOpen: false
|
|
149
250
|
};
|
|
150
|
-
|
|
251
|
+
}
|
|
252
|
+
case "REJECT_ALL": {
|
|
253
|
+
const prefs = createInitialPreferences(action.customCategories);
|
|
254
|
+
if (action.customCategories) {
|
|
255
|
+
action.customCategories.forEach((category) => {
|
|
256
|
+
if (category.essential) {
|
|
257
|
+
prefs[category.id] = true;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
151
261
|
return {
|
|
152
262
|
consented: true,
|
|
153
|
-
preferences:
|
|
263
|
+
preferences: prefs,
|
|
154
264
|
isModalOpen: false
|
|
155
265
|
};
|
|
266
|
+
}
|
|
156
267
|
case "SET_CATEGORY":
|
|
157
268
|
return {
|
|
158
269
|
...state,
|
|
@@ -173,26 +284,29 @@ function reducer(state, action) {
|
|
|
173
284
|
case "CLOSE_MODAL":
|
|
174
285
|
return { ...state, isModalOpen: false, consented: true };
|
|
175
286
|
// houve interação
|
|
176
|
-
case "RESET":
|
|
287
|
+
case "RESET": {
|
|
177
288
|
return {
|
|
178
289
|
consented: false,
|
|
179
|
-
preferences:
|
|
290
|
+
preferences: createInitialPreferences(action.customCategories),
|
|
180
291
|
isModalOpen: false
|
|
181
292
|
};
|
|
293
|
+
}
|
|
182
294
|
case "HYDRATE":
|
|
183
295
|
return { ...action.state };
|
|
184
296
|
default:
|
|
185
297
|
return state;
|
|
186
298
|
}
|
|
187
299
|
}
|
|
188
|
-
var StateCtx =
|
|
189
|
-
var ActionsCtx =
|
|
190
|
-
var TextsCtx =
|
|
191
|
-
var HydrationCtx =
|
|
300
|
+
var StateCtx = React2.createContext(null);
|
|
301
|
+
var ActionsCtx = React2.createContext(null);
|
|
302
|
+
var TextsCtx = React2.createContext(DEFAULT_TEXTS);
|
|
303
|
+
var HydrationCtx = React2.createContext(false);
|
|
192
304
|
function ConsentProvider({
|
|
193
305
|
initialState,
|
|
194
306
|
texts: textsProp,
|
|
195
307
|
theme,
|
|
308
|
+
customCategories,
|
|
309
|
+
scriptIntegrations,
|
|
196
310
|
PreferencesModalComponent,
|
|
197
311
|
preferencesModalProps = {},
|
|
198
312
|
disableAutomaticModal = false,
|
|
@@ -202,30 +316,30 @@ function ConsentProvider({
|
|
|
202
316
|
cookie: cookieOpts,
|
|
203
317
|
children
|
|
204
318
|
}) {
|
|
205
|
-
const texts =
|
|
319
|
+
const texts = React2.useMemo(
|
|
206
320
|
() => ({ ...DEFAULT_TEXTS, ...textsProp ?? {} }),
|
|
207
321
|
[textsProp]
|
|
208
322
|
);
|
|
209
|
-
const cookie =
|
|
323
|
+
const cookie = React2.useMemo(
|
|
210
324
|
() => ({ ...DEFAULT_COOKIE_OPTS, ...cookieOpts ?? {} }),
|
|
211
325
|
[cookieOpts]
|
|
212
326
|
);
|
|
213
|
-
const appliedTheme =
|
|
327
|
+
const appliedTheme = React2.useMemo(
|
|
214
328
|
() => theme || defaultConsentTheme,
|
|
215
329
|
[theme]
|
|
216
330
|
);
|
|
217
|
-
const boot =
|
|
331
|
+
const boot = React2.useMemo(() => {
|
|
218
332
|
if (initialState) return { ...initialState, isModalOpen: false };
|
|
219
333
|
return {
|
|
220
334
|
consented: false,
|
|
221
|
-
preferences:
|
|
335
|
+
preferences: createInitialPreferences(customCategories),
|
|
222
336
|
isModalOpen: false
|
|
223
337
|
};
|
|
224
|
-
}, [initialState]);
|
|
225
|
-
const [state, dispatch] =
|
|
226
|
-
const [isHydrated, setIsHydrated] =
|
|
227
|
-
|
|
228
|
-
if (
|
|
338
|
+
}, [initialState, customCategories]);
|
|
339
|
+
const [state, dispatch] = React2.useReducer(reducer, boot);
|
|
340
|
+
const [isHydrated, setIsHydrated] = React2.useState(false);
|
|
341
|
+
React2.useEffect(() => {
|
|
342
|
+
if (!initialState) {
|
|
229
343
|
const saved = readConsentCookie(cookie.name);
|
|
230
344
|
if (saved?.consented) {
|
|
231
345
|
console.log("\u{1F680} Immediate hydration: Cookie found", saved);
|
|
@@ -234,33 +348,33 @@ function ConsentProvider({
|
|
|
234
348
|
}
|
|
235
349
|
setIsHydrated(true);
|
|
236
350
|
}, [cookie.name, initialState]);
|
|
237
|
-
|
|
351
|
+
React2.useEffect(() => {
|
|
238
352
|
if (state.consented) writeConsentCookie(state, cookie);
|
|
239
353
|
}, [state, cookie]);
|
|
240
|
-
const prevConsented =
|
|
241
|
-
|
|
354
|
+
const prevConsented = React2.useRef(state.consented);
|
|
355
|
+
React2.useEffect(() => {
|
|
242
356
|
if (!prevConsented.current && state.consented && onConsentGiven) {
|
|
243
357
|
setTimeout(() => onConsentGiven(state), 150);
|
|
244
358
|
}
|
|
245
359
|
prevConsented.current = state.consented;
|
|
246
360
|
}, [state, onConsentGiven]);
|
|
247
|
-
const prevPrefs =
|
|
248
|
-
|
|
361
|
+
const prevPrefs = React2.useRef(state.preferences);
|
|
362
|
+
React2.useEffect(() => {
|
|
249
363
|
if (state.consented && onPreferencesSaved && prevPrefs.current !== state.preferences) {
|
|
250
364
|
setTimeout(() => onPreferencesSaved(state.preferences), 150);
|
|
251
365
|
prevPrefs.current = state.preferences;
|
|
252
366
|
}
|
|
253
367
|
}, [state, onPreferencesSaved]);
|
|
254
|
-
const api =
|
|
255
|
-
const acceptAll = () => dispatch({ type: "ACCEPT_ALL" });
|
|
256
|
-
const rejectAll = () => dispatch({ type: "REJECT_ALL" });
|
|
368
|
+
const api = React2.useMemo(() => {
|
|
369
|
+
const acceptAll = () => dispatch({ type: "ACCEPT_ALL", customCategories });
|
|
370
|
+
const rejectAll = () => dispatch({ type: "REJECT_ALL", customCategories });
|
|
257
371
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
258
372
|
const setPreferences = (preferences) => dispatch({ type: "SET_PREFERENCES", preferences });
|
|
259
373
|
const openPreferences = () => dispatch({ type: "OPEN_MODAL" });
|
|
260
374
|
const closePreferences = () => dispatch({ type: "CLOSE_MODAL" });
|
|
261
375
|
const resetConsent = () => {
|
|
262
376
|
removeConsentCookie(cookie);
|
|
263
|
-
dispatch({ type: "RESET" });
|
|
377
|
+
dispatch({ type: "RESET", customCategories });
|
|
264
378
|
};
|
|
265
379
|
return {
|
|
266
380
|
consented: !!state.consented,
|
|
@@ -274,30 +388,30 @@ function ConsentProvider({
|
|
|
274
388
|
closePreferences,
|
|
275
389
|
resetConsent
|
|
276
390
|
};
|
|
277
|
-
}, [state, cookie]);
|
|
278
|
-
return /* @__PURE__ */
|
|
391
|
+
}, [state, cookie, customCategories]);
|
|
392
|
+
return /* @__PURE__ */ jsx2(ThemeProvider, { theme: appliedTheme, children: /* @__PURE__ */ jsx2(StateCtx.Provider, { value: state, children: /* @__PURE__ */ jsx2(ActionsCtx.Provider, { value: api, children: /* @__PURE__ */ jsx2(TextsCtx.Provider, { value: texts, children: /* @__PURE__ */ jsx2(HydrationCtx.Provider, { value: isHydrated, children: /* @__PURE__ */ jsxs(CategoriesProvider, { categories: customCategories, children: [
|
|
279
393
|
children,
|
|
280
|
-
!disableAutomaticModal && /* @__PURE__ */
|
|
281
|
-
] }) }) }) }) });
|
|
394
|
+
!disableAutomaticModal && /* @__PURE__ */ jsx2(React2.Suspense, { fallback: null, children: PreferencesModalComponent ? /* @__PURE__ */ jsx2(PreferencesModalComponent, { ...preferencesModalProps }) : /* @__PURE__ */ jsx2(PreferencesModal, { hideBranding }) })
|
|
395
|
+
] }) }) }) }) }) });
|
|
282
396
|
}
|
|
283
397
|
function useConsentStateInternal() {
|
|
284
|
-
const ctx =
|
|
398
|
+
const ctx = React2.useContext(StateCtx);
|
|
285
399
|
if (!ctx)
|
|
286
400
|
throw new Error("useConsentState must be used within ConsentProvider");
|
|
287
401
|
return ctx;
|
|
288
402
|
}
|
|
289
403
|
function useConsentActionsInternal() {
|
|
290
|
-
const ctx =
|
|
404
|
+
const ctx = React2.useContext(ActionsCtx);
|
|
291
405
|
if (!ctx)
|
|
292
406
|
throw new Error("useConsentActions must be used within ConsentProvider");
|
|
293
407
|
return ctx;
|
|
294
408
|
}
|
|
295
409
|
function useConsentTextsInternal() {
|
|
296
|
-
const ctx =
|
|
410
|
+
const ctx = React2.useContext(TextsCtx);
|
|
297
411
|
return ctx;
|
|
298
412
|
}
|
|
299
413
|
function useConsentHydrationInternal() {
|
|
300
|
-
return
|
|
414
|
+
return React2.useContext(HydrationCtx);
|
|
301
415
|
}
|
|
302
416
|
|
|
303
417
|
// src/hooks/useConsent.ts
|
|
@@ -327,7 +441,7 @@ function useConsentHydration() {
|
|
|
327
441
|
// src/components/Branding.tsx
|
|
328
442
|
import Link from "@mui/material/Link";
|
|
329
443
|
import Typography from "@mui/material/Typography";
|
|
330
|
-
import { jsx as
|
|
444
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
331
445
|
var brandingStyles = {
|
|
332
446
|
banner: {
|
|
333
447
|
fontSize: "0.65rem",
|
|
@@ -365,7 +479,7 @@ function Branding({ variant, hidden = false }) {
|
|
|
365
479
|
children: [
|
|
366
480
|
"fornecido por",
|
|
367
481
|
" ",
|
|
368
|
-
/* @__PURE__ */
|
|
482
|
+
/* @__PURE__ */ jsx3(
|
|
369
483
|
Link,
|
|
370
484
|
{
|
|
371
485
|
href: "https://www.ledipo.eti.br",
|
|
@@ -384,7 +498,7 @@ function Branding({ variant, hidden = false }) {
|
|
|
384
498
|
}
|
|
385
499
|
|
|
386
500
|
// src/components/PreferencesModal.tsx
|
|
387
|
-
import { jsx as
|
|
501
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
388
502
|
function PreferencesModal2({
|
|
389
503
|
DialogProps: DialogProps2,
|
|
390
504
|
hideBranding = false
|
|
@@ -413,14 +527,14 @@ function PreferencesModal2({
|
|
|
413
527
|
onClose: handleCancel,
|
|
414
528
|
...DialogProps2,
|
|
415
529
|
children: [
|
|
416
|
-
/* @__PURE__ */
|
|
530
|
+
/* @__PURE__ */ jsx4(DialogTitle, { id: "cookie-pref-title", children: texts.modalTitle }),
|
|
417
531
|
/* @__PURE__ */ jsxs3(DialogContent, { dividers: true, children: [
|
|
418
|
-
/* @__PURE__ */
|
|
532
|
+
/* @__PURE__ */ jsx4(Typography2, { variant: "body2", sx: { mb: 2 }, children: texts.modalIntro }),
|
|
419
533
|
/* @__PURE__ */ jsxs3(FormGroup, { children: [
|
|
420
|
-
/* @__PURE__ */
|
|
534
|
+
/* @__PURE__ */ jsx4(
|
|
421
535
|
FormControlLabel,
|
|
422
536
|
{
|
|
423
|
-
control: /* @__PURE__ */
|
|
537
|
+
control: /* @__PURE__ */ jsx4(
|
|
424
538
|
Switch,
|
|
425
539
|
{
|
|
426
540
|
checked: tempPreferences.analytics,
|
|
@@ -433,10 +547,10 @@ function PreferencesModal2({
|
|
|
433
547
|
label: "Cookies Anal\xEDticos (medem uso do site)"
|
|
434
548
|
}
|
|
435
549
|
),
|
|
436
|
-
/* @__PURE__ */
|
|
550
|
+
/* @__PURE__ */ jsx4(
|
|
437
551
|
FormControlLabel,
|
|
438
552
|
{
|
|
439
|
-
control: /* @__PURE__ */
|
|
553
|
+
control: /* @__PURE__ */ jsx4(
|
|
440
554
|
Switch,
|
|
441
555
|
{
|
|
442
556
|
checked: tempPreferences.marketing,
|
|
@@ -449,19 +563,19 @@ function PreferencesModal2({
|
|
|
449
563
|
label: "Cookies de Marketing/Publicidade"
|
|
450
564
|
}
|
|
451
565
|
),
|
|
452
|
-
/* @__PURE__ */
|
|
566
|
+
/* @__PURE__ */ jsx4(
|
|
453
567
|
FormControlLabel,
|
|
454
568
|
{
|
|
455
|
-
control: /* @__PURE__ */
|
|
569
|
+
control: /* @__PURE__ */ jsx4(Switch, { checked: true, disabled: true }),
|
|
456
570
|
label: texts.necessaryAlwaysOn
|
|
457
571
|
}
|
|
458
572
|
)
|
|
459
573
|
] })
|
|
460
574
|
] }),
|
|
461
|
-
!hideBranding && /* @__PURE__ */
|
|
575
|
+
!hideBranding && /* @__PURE__ */ jsx4(Branding, { variant: "modal" }),
|
|
462
576
|
/* @__PURE__ */ jsxs3(DialogActions, { children: [
|
|
463
|
-
/* @__PURE__ */
|
|
464
|
-
/* @__PURE__ */
|
|
577
|
+
/* @__PURE__ */ jsx4(Button, { variant: "outlined", onClick: handleCancel, children: "Cancelar" }),
|
|
578
|
+
/* @__PURE__ */ jsx4(Button, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
465
579
|
] })
|
|
466
580
|
]
|
|
467
581
|
}
|
|
@@ -470,6 +584,8 @@ function PreferencesModal2({
|
|
|
470
584
|
|
|
471
585
|
export {
|
|
472
586
|
defaultConsentTheme,
|
|
587
|
+
useCustomCategories,
|
|
588
|
+
useAllCategories,
|
|
473
589
|
Branding,
|
|
474
590
|
PreferencesModal2 as PreferencesModal,
|
|
475
591
|
ConsentProvider,
|