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/dist/index.d.cts
CHANGED
|
@@ -100,16 +100,100 @@ interface FloatingPreferencesButtonProps {
|
|
|
100
100
|
declare function FloatingPreferencesButton({ position, offset, icon, tooltip, FabProps, hideWhenConsented, }: Readonly<FloatingPreferencesButtonProps>): react_jsx_runtime.JSX.Element | null;
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
103
|
+
* Integrações nativas com scripts de terceiros.
|
|
104
|
+
* Facilita o carregamento automático baseado em consentimento.
|
|
105
105
|
*/
|
|
106
|
-
|
|
106
|
+
interface ScriptIntegration {
|
|
107
|
+
/** ID único da integração */
|
|
108
|
+
id: string;
|
|
109
|
+
/** Categoria de consentimento necessária */
|
|
110
|
+
category: string;
|
|
111
|
+
/** URL do script */
|
|
112
|
+
src: string;
|
|
113
|
+
/** Função de inicialização após carregamento */
|
|
114
|
+
init?: () => void;
|
|
115
|
+
/** Atributos adicionais do script */
|
|
116
|
+
attrs?: Record<string, string>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Configuração para Google Analytics 4.
|
|
120
|
+
*/
|
|
121
|
+
interface GoogleAnalyticsConfig {
|
|
122
|
+
measurementId: string;
|
|
123
|
+
config?: any;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Configuração para Google Tag Manager.
|
|
127
|
+
*/
|
|
128
|
+
interface GoogleTagManagerConfig {
|
|
129
|
+
containerId: string;
|
|
130
|
+
dataLayerName?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Configuração para UserWay (acessibilidade).
|
|
134
|
+
*/
|
|
135
|
+
interface UserWayConfig {
|
|
136
|
+
accountId: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Cria integração para Google Analytics 4.
|
|
140
|
+
*/
|
|
141
|
+
declare function createGoogleAnalyticsIntegration(config: GoogleAnalyticsConfig): ScriptIntegration;
|
|
142
|
+
/**
|
|
143
|
+
* Cria integração para Google Tag Manager.
|
|
144
|
+
*/
|
|
145
|
+
declare function createGoogleTagManagerIntegration(config: GoogleTagManagerConfig): ScriptIntegration;
|
|
146
|
+
/**
|
|
147
|
+
* Cria integração para UserWay (acessibilidade).
|
|
148
|
+
*/
|
|
149
|
+
declare function createUserWayIntegration(config: UserWayConfig): ScriptIntegration;
|
|
150
|
+
/**
|
|
151
|
+
* Integrações pré-configuradas mais comuns.
|
|
152
|
+
*/
|
|
153
|
+
declare const COMMON_INTEGRATIONS: {
|
|
154
|
+
googleAnalytics: typeof createGoogleAnalyticsIntegration;
|
|
155
|
+
googleTagManager: typeof createGoogleTagManagerIntegration;
|
|
156
|
+
userway: typeof createUserWayIntegration;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Categorias padrão de consentimento para cookies baseadas no Guia da ANPD.
|
|
161
|
+
*
|
|
162
|
+
* - necessary: Cookies essenciais (sempre ativos)
|
|
163
|
+
* - analytics: Análise e estatísticas
|
|
164
|
+
* - functional: Funcionalidades extras
|
|
165
|
+
* - marketing: Publicidade e marketing
|
|
166
|
+
* - social: Integração com redes sociais
|
|
167
|
+
* - personalization: Personalização de conteúdo
|
|
168
|
+
*/
|
|
169
|
+
type Category = 'necessary' | 'analytics' | 'functional' | 'marketing' | 'social' | 'personalization';
|
|
170
|
+
/**
|
|
171
|
+
* Definição detalhada de uma categoria de cookie.
|
|
172
|
+
*/
|
|
173
|
+
interface CategoryDefinition {
|
|
174
|
+
/** ID único da categoria */
|
|
175
|
+
id: string;
|
|
176
|
+
/** Nome amigável exibido na interface */
|
|
177
|
+
name: string;
|
|
178
|
+
/** Descrição detalhada da categoria */
|
|
179
|
+
description: string;
|
|
180
|
+
/** Se é uma categoria essencial (não pode ser desabilitada) */
|
|
181
|
+
essential?: boolean;
|
|
182
|
+
/** Scripts/cookies específicos desta categoria */
|
|
183
|
+
cookies?: string[];
|
|
184
|
+
}
|
|
107
185
|
/**
|
|
108
186
|
* Preferências de consentimento do usuário para cada categoria.
|
|
187
|
+
* Baseado nas categorias do Guia da ANPD, mas extensível.
|
|
109
188
|
*/
|
|
110
189
|
interface ConsentPreferences {
|
|
190
|
+
necessary: boolean;
|
|
111
191
|
analytics: boolean;
|
|
192
|
+
functional: boolean;
|
|
112
193
|
marketing: boolean;
|
|
194
|
+
social: boolean;
|
|
195
|
+
personalization: boolean;
|
|
196
|
+
[key: string]: boolean;
|
|
113
197
|
}
|
|
114
198
|
/**
|
|
115
199
|
* Estado geral do consentimento, incluindo se o usuário consentiu,
|
|
@@ -152,6 +236,14 @@ interface ConsentTexts {
|
|
|
152
236
|
modalIntro: string;
|
|
153
237
|
save: string;
|
|
154
238
|
necessaryAlwaysOn: string;
|
|
239
|
+
controllerInfo?: string;
|
|
240
|
+
dataTypes?: string;
|
|
241
|
+
thirdPartySharing?: string;
|
|
242
|
+
userRights?: string;
|
|
243
|
+
contactInfo?: string;
|
|
244
|
+
retentionPeriod?: string;
|
|
245
|
+
lawfulBasis?: string;
|
|
246
|
+
transferCountries?: string;
|
|
155
247
|
}
|
|
156
248
|
/**
|
|
157
249
|
* Opções para configuração do cookie de consentimento.
|
|
@@ -176,8 +268,12 @@ interface ConsentProviderProps {
|
|
|
176
268
|
initialState?: ConsentState;
|
|
177
269
|
/** Textos customizados para a interface. */
|
|
178
270
|
texts?: Partial<ConsentTexts>;
|
|
179
|
-
/** Tema customizado para os componentes MUI. */
|
|
271
|
+
/** Tema customizado para os componentes MUI. Aceita qualquer propriedade. */
|
|
180
272
|
theme?: any;
|
|
273
|
+
/** Categorias customizadas de cookies (complementa as padrão). */
|
|
274
|
+
customCategories?: CategoryDefinition[];
|
|
275
|
+
/** Integrações nativas de scripts (Google Analytics, etc.). */
|
|
276
|
+
scriptIntegrations?: ScriptIntegration[];
|
|
181
277
|
/** Componente customizado para modal de preferências. */
|
|
182
278
|
PreferencesModalComponent?: React.ComponentType<any>;
|
|
183
279
|
/** Props adicionais para o modal customizado. */
|
|
@@ -236,7 +332,7 @@ interface ConsentContextValue {
|
|
|
236
332
|
* <App />
|
|
237
333
|
* </ConsentProvider>
|
|
238
334
|
*/
|
|
239
|
-
declare function ConsentProvider({ initialState, texts: textsProp, theme, PreferencesModalComponent, preferencesModalProps, disableAutomaticModal, hideBranding, onConsentGiven, onPreferencesSaved, cookie: cookieOpts, children, }: Readonly<ConsentProviderProps>): react_jsx_runtime.JSX.Element;
|
|
335
|
+
declare function ConsentProvider({ initialState, texts: textsProp, theme, customCategories, scriptIntegrations, PreferencesModalComponent, preferencesModalProps, disableAutomaticModal, hideBranding, onConsentGiven, onPreferencesSaved, cookie: cookieOpts, children, }: Readonly<ConsentProviderProps>): react_jsx_runtime.JSX.Element;
|
|
240
336
|
|
|
241
337
|
/**
|
|
242
338
|
* Hook principal para acessar e manipular o estado de consentimento de cookies.
|
|
@@ -271,8 +367,18 @@ declare function useConsentTexts(): ConsentTexts;
|
|
|
271
367
|
*/
|
|
272
368
|
declare function useConsentHydration(): boolean;
|
|
273
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Hook para acessar as categorias customizadas.
|
|
372
|
+
* Retorna apenas as categorias customizadas (não as padrão analytics/marketing).
|
|
373
|
+
*/
|
|
374
|
+
declare function useCustomCategories(): CategoryDefinition[];
|
|
375
|
+
/**
|
|
376
|
+
* Hook para obter todas as categorias (padrão + customizadas).
|
|
377
|
+
*/
|
|
378
|
+
declare function useAllCategories(): CategoryDefinition[];
|
|
379
|
+
|
|
274
380
|
declare function ConsentGate(props: Readonly<{
|
|
275
|
-
category:
|
|
381
|
+
category: string;
|
|
276
382
|
children: React$1.ReactNode;
|
|
277
383
|
}>): react_jsx_runtime.JSX.Element | null;
|
|
278
384
|
|
|
@@ -301,4 +407,49 @@ declare function loadScript(id: string, src: string, category?: 'analytics' | 'm
|
|
|
301
407
|
*/
|
|
302
408
|
declare const defaultConsentTheme: _mui_material_styles.Theme;
|
|
303
409
|
|
|
304
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Componente que carrega scripts automaticamente baseado no consentimento.
|
|
412
|
+
* Facilita integração com ferramentas como Google Analytics, Tag Manager, etc.
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
interface ConsentScriptLoaderProps {
|
|
416
|
+
/** Lista de integrações de scripts para carregar baseado no consentimento */
|
|
417
|
+
integrations: ScriptIntegration[];
|
|
418
|
+
/** Se true, força recarregamento se consentimento mudar */
|
|
419
|
+
reloadOnChange?: boolean;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Componente para carregamento automático de scripts baseado no consentimento.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```tsx
|
|
426
|
+
* const integrations = [
|
|
427
|
+
* createGoogleAnalyticsIntegration({ measurementId: 'GA_ID' }),
|
|
428
|
+
* createUserWayIntegration({ accountId: 'USERWAY_ID' })
|
|
429
|
+
* ]
|
|
430
|
+
*
|
|
431
|
+
* <ConsentScriptLoader integrations={integrations} />
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function ConsentScriptLoader({ integrations, reloadOnChange, }: Readonly<ConsentScriptLoaderProps>): null;
|
|
435
|
+
/**
|
|
436
|
+
* Hook para carregamento manual de scripts baseado no consentimento.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```tsx
|
|
440
|
+
* function MyComponent() {
|
|
441
|
+
* const loadConsentScript = useConsentScriptLoader()
|
|
442
|
+
*
|
|
443
|
+
* React.useEffect(() => {
|
|
444
|
+
* loadConsentScript({
|
|
445
|
+
* id: 'my-script',
|
|
446
|
+
* category: 'analytics',
|
|
447
|
+
* src: 'https://example.com/script.js'
|
|
448
|
+
* })
|
|
449
|
+
* }, [])
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function useConsentScriptLoader(): (integration: ScriptIntegration) => Promise<boolean>;
|
|
454
|
+
|
|
455
|
+
export { COMMON_INTEGRATIONS, type Category, type CategoryDefinition, type ConsentCookieOptions, ConsentGate, type ConsentPreferences, ConsentProvider, ConsentScriptLoader, type ConsentState, type ConsentTexts, CookieBanner, FloatingPreferencesButton, type GoogleAnalyticsConfig, type GoogleTagManagerConfig, PreferencesModal, type ScriptIntegration, type UserWayConfig, createGoogleAnalyticsIntegration, createGoogleTagManagerIntegration, createUserWayIntegration, defaultConsentTheme, loadScript, useAllCategories, useConsent, useConsentHydration, useConsentScriptLoader, useConsentTexts, useCustomCategories };
|
package/dist/index.d.ts
CHANGED
|
@@ -100,16 +100,100 @@ interface FloatingPreferencesButtonProps {
|
|
|
100
100
|
declare function FloatingPreferencesButton({ position, offset, icon, tooltip, FabProps, hideWhenConsented, }: Readonly<FloatingPreferencesButtonProps>): react_jsx_runtime.JSX.Element | null;
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
103
|
+
* Integrações nativas com scripts de terceiros.
|
|
104
|
+
* Facilita o carregamento automático baseado em consentimento.
|
|
105
105
|
*/
|
|
106
|
-
|
|
106
|
+
interface ScriptIntegration {
|
|
107
|
+
/** ID único da integração */
|
|
108
|
+
id: string;
|
|
109
|
+
/** Categoria de consentimento necessária */
|
|
110
|
+
category: string;
|
|
111
|
+
/** URL do script */
|
|
112
|
+
src: string;
|
|
113
|
+
/** Função de inicialização após carregamento */
|
|
114
|
+
init?: () => void;
|
|
115
|
+
/** Atributos adicionais do script */
|
|
116
|
+
attrs?: Record<string, string>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Configuração para Google Analytics 4.
|
|
120
|
+
*/
|
|
121
|
+
interface GoogleAnalyticsConfig {
|
|
122
|
+
measurementId: string;
|
|
123
|
+
config?: any;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Configuração para Google Tag Manager.
|
|
127
|
+
*/
|
|
128
|
+
interface GoogleTagManagerConfig {
|
|
129
|
+
containerId: string;
|
|
130
|
+
dataLayerName?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Configuração para UserWay (acessibilidade).
|
|
134
|
+
*/
|
|
135
|
+
interface UserWayConfig {
|
|
136
|
+
accountId: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Cria integração para Google Analytics 4.
|
|
140
|
+
*/
|
|
141
|
+
declare function createGoogleAnalyticsIntegration(config: GoogleAnalyticsConfig): ScriptIntegration;
|
|
142
|
+
/**
|
|
143
|
+
* Cria integração para Google Tag Manager.
|
|
144
|
+
*/
|
|
145
|
+
declare function createGoogleTagManagerIntegration(config: GoogleTagManagerConfig): ScriptIntegration;
|
|
146
|
+
/**
|
|
147
|
+
* Cria integração para UserWay (acessibilidade).
|
|
148
|
+
*/
|
|
149
|
+
declare function createUserWayIntegration(config: UserWayConfig): ScriptIntegration;
|
|
150
|
+
/**
|
|
151
|
+
* Integrações pré-configuradas mais comuns.
|
|
152
|
+
*/
|
|
153
|
+
declare const COMMON_INTEGRATIONS: {
|
|
154
|
+
googleAnalytics: typeof createGoogleAnalyticsIntegration;
|
|
155
|
+
googleTagManager: typeof createGoogleTagManagerIntegration;
|
|
156
|
+
userway: typeof createUserWayIntegration;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Categorias padrão de consentimento para cookies baseadas no Guia da ANPD.
|
|
161
|
+
*
|
|
162
|
+
* - necessary: Cookies essenciais (sempre ativos)
|
|
163
|
+
* - analytics: Análise e estatísticas
|
|
164
|
+
* - functional: Funcionalidades extras
|
|
165
|
+
* - marketing: Publicidade e marketing
|
|
166
|
+
* - social: Integração com redes sociais
|
|
167
|
+
* - personalization: Personalização de conteúdo
|
|
168
|
+
*/
|
|
169
|
+
type Category = 'necessary' | 'analytics' | 'functional' | 'marketing' | 'social' | 'personalization';
|
|
170
|
+
/**
|
|
171
|
+
* Definição detalhada de uma categoria de cookie.
|
|
172
|
+
*/
|
|
173
|
+
interface CategoryDefinition {
|
|
174
|
+
/** ID único da categoria */
|
|
175
|
+
id: string;
|
|
176
|
+
/** Nome amigável exibido na interface */
|
|
177
|
+
name: string;
|
|
178
|
+
/** Descrição detalhada da categoria */
|
|
179
|
+
description: string;
|
|
180
|
+
/** Se é uma categoria essencial (não pode ser desabilitada) */
|
|
181
|
+
essential?: boolean;
|
|
182
|
+
/** Scripts/cookies específicos desta categoria */
|
|
183
|
+
cookies?: string[];
|
|
184
|
+
}
|
|
107
185
|
/**
|
|
108
186
|
* Preferências de consentimento do usuário para cada categoria.
|
|
187
|
+
* Baseado nas categorias do Guia da ANPD, mas extensível.
|
|
109
188
|
*/
|
|
110
189
|
interface ConsentPreferences {
|
|
190
|
+
necessary: boolean;
|
|
111
191
|
analytics: boolean;
|
|
192
|
+
functional: boolean;
|
|
112
193
|
marketing: boolean;
|
|
194
|
+
social: boolean;
|
|
195
|
+
personalization: boolean;
|
|
196
|
+
[key: string]: boolean;
|
|
113
197
|
}
|
|
114
198
|
/**
|
|
115
199
|
* Estado geral do consentimento, incluindo se o usuário consentiu,
|
|
@@ -152,6 +236,14 @@ interface ConsentTexts {
|
|
|
152
236
|
modalIntro: string;
|
|
153
237
|
save: string;
|
|
154
238
|
necessaryAlwaysOn: string;
|
|
239
|
+
controllerInfo?: string;
|
|
240
|
+
dataTypes?: string;
|
|
241
|
+
thirdPartySharing?: string;
|
|
242
|
+
userRights?: string;
|
|
243
|
+
contactInfo?: string;
|
|
244
|
+
retentionPeriod?: string;
|
|
245
|
+
lawfulBasis?: string;
|
|
246
|
+
transferCountries?: string;
|
|
155
247
|
}
|
|
156
248
|
/**
|
|
157
249
|
* Opções para configuração do cookie de consentimento.
|
|
@@ -176,8 +268,12 @@ interface ConsentProviderProps {
|
|
|
176
268
|
initialState?: ConsentState;
|
|
177
269
|
/** Textos customizados para a interface. */
|
|
178
270
|
texts?: Partial<ConsentTexts>;
|
|
179
|
-
/** Tema customizado para os componentes MUI. */
|
|
271
|
+
/** Tema customizado para os componentes MUI. Aceita qualquer propriedade. */
|
|
180
272
|
theme?: any;
|
|
273
|
+
/** Categorias customizadas de cookies (complementa as padrão). */
|
|
274
|
+
customCategories?: CategoryDefinition[];
|
|
275
|
+
/** Integrações nativas de scripts (Google Analytics, etc.). */
|
|
276
|
+
scriptIntegrations?: ScriptIntegration[];
|
|
181
277
|
/** Componente customizado para modal de preferências. */
|
|
182
278
|
PreferencesModalComponent?: React.ComponentType<any>;
|
|
183
279
|
/** Props adicionais para o modal customizado. */
|
|
@@ -236,7 +332,7 @@ interface ConsentContextValue {
|
|
|
236
332
|
* <App />
|
|
237
333
|
* </ConsentProvider>
|
|
238
334
|
*/
|
|
239
|
-
declare function ConsentProvider({ initialState, texts: textsProp, theme, PreferencesModalComponent, preferencesModalProps, disableAutomaticModal, hideBranding, onConsentGiven, onPreferencesSaved, cookie: cookieOpts, children, }: Readonly<ConsentProviderProps>): react_jsx_runtime.JSX.Element;
|
|
335
|
+
declare function ConsentProvider({ initialState, texts: textsProp, theme, customCategories, scriptIntegrations, PreferencesModalComponent, preferencesModalProps, disableAutomaticModal, hideBranding, onConsentGiven, onPreferencesSaved, cookie: cookieOpts, children, }: Readonly<ConsentProviderProps>): react_jsx_runtime.JSX.Element;
|
|
240
336
|
|
|
241
337
|
/**
|
|
242
338
|
* Hook principal para acessar e manipular o estado de consentimento de cookies.
|
|
@@ -271,8 +367,18 @@ declare function useConsentTexts(): ConsentTexts;
|
|
|
271
367
|
*/
|
|
272
368
|
declare function useConsentHydration(): boolean;
|
|
273
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Hook para acessar as categorias customizadas.
|
|
372
|
+
* Retorna apenas as categorias customizadas (não as padrão analytics/marketing).
|
|
373
|
+
*/
|
|
374
|
+
declare function useCustomCategories(): CategoryDefinition[];
|
|
375
|
+
/**
|
|
376
|
+
* Hook para obter todas as categorias (padrão + customizadas).
|
|
377
|
+
*/
|
|
378
|
+
declare function useAllCategories(): CategoryDefinition[];
|
|
379
|
+
|
|
274
380
|
declare function ConsentGate(props: Readonly<{
|
|
275
|
-
category:
|
|
381
|
+
category: string;
|
|
276
382
|
children: React$1.ReactNode;
|
|
277
383
|
}>): react_jsx_runtime.JSX.Element | null;
|
|
278
384
|
|
|
@@ -301,4 +407,49 @@ declare function loadScript(id: string, src: string, category?: 'analytics' | 'm
|
|
|
301
407
|
*/
|
|
302
408
|
declare const defaultConsentTheme: _mui_material_styles.Theme;
|
|
303
409
|
|
|
304
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Componente que carrega scripts automaticamente baseado no consentimento.
|
|
412
|
+
* Facilita integração com ferramentas como Google Analytics, Tag Manager, etc.
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
interface ConsentScriptLoaderProps {
|
|
416
|
+
/** Lista de integrações de scripts para carregar baseado no consentimento */
|
|
417
|
+
integrations: ScriptIntegration[];
|
|
418
|
+
/** Se true, força recarregamento se consentimento mudar */
|
|
419
|
+
reloadOnChange?: boolean;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Componente para carregamento automático de scripts baseado no consentimento.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```tsx
|
|
426
|
+
* const integrations = [
|
|
427
|
+
* createGoogleAnalyticsIntegration({ measurementId: 'GA_ID' }),
|
|
428
|
+
* createUserWayIntegration({ accountId: 'USERWAY_ID' })
|
|
429
|
+
* ]
|
|
430
|
+
*
|
|
431
|
+
* <ConsentScriptLoader integrations={integrations} />
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function ConsentScriptLoader({ integrations, reloadOnChange, }: Readonly<ConsentScriptLoaderProps>): null;
|
|
435
|
+
/**
|
|
436
|
+
* Hook para carregamento manual de scripts baseado no consentimento.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```tsx
|
|
440
|
+
* function MyComponent() {
|
|
441
|
+
* const loadConsentScript = useConsentScriptLoader()
|
|
442
|
+
*
|
|
443
|
+
* React.useEffect(() => {
|
|
444
|
+
* loadConsentScript({
|
|
445
|
+
* id: 'my-script',
|
|
446
|
+
* category: 'analytics',
|
|
447
|
+
* src: 'https://example.com/script.js'
|
|
448
|
+
* })
|
|
449
|
+
* }, [])
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function useConsentScriptLoader(): (integration: ScriptIntegration) => Promise<boolean>;
|
|
454
|
+
|
|
455
|
+
export { COMMON_INTEGRATIONS, type Category, type CategoryDefinition, type ConsentCookieOptions, ConsentGate, type ConsentPreferences, ConsentProvider, ConsentScriptLoader, type ConsentState, type ConsentTexts, CookieBanner, FloatingPreferencesButton, type GoogleAnalyticsConfig, type GoogleTagManagerConfig, PreferencesModal, type ScriptIntegration, type UserWayConfig, createGoogleAnalyticsIntegration, createGoogleTagManagerIntegration, createUserWayIntegration, defaultConsentTheme, loadScript, useAllCategories, useConsent, useConsentHydration, useConsentScriptLoader, useConsentTexts, useCustomCategories };
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
ConsentProvider,
|
|
4
4
|
PreferencesModal,
|
|
5
5
|
defaultConsentTheme,
|
|
6
|
+
useAllCategories,
|
|
6
7
|
useConsent,
|
|
7
8
|
useConsentHydration,
|
|
8
|
-
useConsentTexts
|
|
9
|
-
|
|
9
|
+
useConsentTexts,
|
|
10
|
+
useCustomCategories
|
|
11
|
+
} from "./chunk-JTPCDTOQ.js";
|
|
10
12
|
|
|
11
13
|
// src/components/CookieBanner.tsx
|
|
12
14
|
import Button from "@mui/material/Button";
|
|
@@ -216,15 +218,160 @@ function loadScript(id, src, category = null, attrs = {}) {
|
|
|
216
218
|
checkConsent();
|
|
217
219
|
});
|
|
218
220
|
}
|
|
221
|
+
|
|
222
|
+
// src/utils/ConsentScriptLoader.tsx
|
|
223
|
+
import * as React from "react";
|
|
224
|
+
function ConsentScriptLoader({
|
|
225
|
+
integrations,
|
|
226
|
+
reloadOnChange = false
|
|
227
|
+
}) {
|
|
228
|
+
const { preferences, consented } = useConsent();
|
|
229
|
+
const loadedScripts = React.useRef(/* @__PURE__ */ new Set());
|
|
230
|
+
React.useEffect(() => {
|
|
231
|
+
if (!consented) return;
|
|
232
|
+
integrations.forEach(async (integration) => {
|
|
233
|
+
const shouldLoad = preferences[integration.category];
|
|
234
|
+
const alreadyLoaded = loadedScripts.current.has(integration.id);
|
|
235
|
+
if (shouldLoad && (!alreadyLoaded || reloadOnChange)) {
|
|
236
|
+
try {
|
|
237
|
+
await loadScript(
|
|
238
|
+
integration.id,
|
|
239
|
+
integration.src,
|
|
240
|
+
integration.category,
|
|
241
|
+
// Categoria dinâmica
|
|
242
|
+
integration.attrs
|
|
243
|
+
);
|
|
244
|
+
if (integration.init) {
|
|
245
|
+
integration.init();
|
|
246
|
+
}
|
|
247
|
+
loadedScripts.current.add(integration.id);
|
|
248
|
+
console.log(
|
|
249
|
+
`\u2705 Script loaded: ${integration.id} (${integration.category})`
|
|
250
|
+
);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error(`\u274C Failed to load script: ${integration.id}`, error);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}, [preferences, consented, integrations, reloadOnChange]);
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
function useConsentScriptLoader() {
|
|
260
|
+
const { preferences, consented } = useConsent();
|
|
261
|
+
return React.useCallback(
|
|
262
|
+
async (integration) => {
|
|
263
|
+
if (!consented) {
|
|
264
|
+
console.warn(
|
|
265
|
+
`\u26A0\uFE0F Cannot load script ${integration.id}: No consent given`
|
|
266
|
+
);
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const shouldLoad = preferences[integration.category];
|
|
270
|
+
if (!shouldLoad) {
|
|
271
|
+
console.warn(
|
|
272
|
+
`\u26A0\uFE0F Cannot load script ${integration.id}: Category '${integration.category}' not consented`
|
|
273
|
+
);
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
await loadScript(
|
|
278
|
+
integration.id,
|
|
279
|
+
integration.src,
|
|
280
|
+
integration.category,
|
|
281
|
+
// Categoria dinâmica
|
|
282
|
+
integration.attrs
|
|
283
|
+
);
|
|
284
|
+
if (integration.init) {
|
|
285
|
+
integration.init();
|
|
286
|
+
}
|
|
287
|
+
console.log(
|
|
288
|
+
`\u2705 Script loaded: ${integration.id} (${integration.category})`
|
|
289
|
+
);
|
|
290
|
+
return true;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
console.error(`\u274C Failed to load script: ${integration.id}`, error);
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
[preferences, consented]
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/utils/scriptIntegrations.ts
|
|
301
|
+
function createGoogleAnalyticsIntegration(config) {
|
|
302
|
+
return {
|
|
303
|
+
id: "google-analytics",
|
|
304
|
+
category: "analytics",
|
|
305
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${config.measurementId}`,
|
|
306
|
+
init: () => {
|
|
307
|
+
if (typeof window !== "undefined") {
|
|
308
|
+
let gtag2 = function(...args) {
|
|
309
|
+
window.dataLayer.push(arguments);
|
|
310
|
+
};
|
|
311
|
+
var gtag = gtag2;
|
|
312
|
+
window.dataLayer = window.dataLayer || [];
|
|
313
|
+
window.gtag = gtag2;
|
|
314
|
+
gtag2("js", /* @__PURE__ */ new Date());
|
|
315
|
+
gtag2("config", config.measurementId, config.config || {});
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
attrs: { async: "true" }
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function createGoogleTagManagerIntegration(config) {
|
|
322
|
+
return {
|
|
323
|
+
id: "google-tag-manager",
|
|
324
|
+
category: "analytics",
|
|
325
|
+
src: `https://www.googletagmanager.com/gtm.js?id=${config.containerId}`,
|
|
326
|
+
init: () => {
|
|
327
|
+
if (typeof window !== "undefined") {
|
|
328
|
+
const dataLayerName = config.dataLayerName || "dataLayer";
|
|
329
|
+
window[dataLayerName] = window[dataLayerName] || [];
|
|
330
|
+
window[dataLayerName].push({
|
|
331
|
+
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
332
|
+
event: "gtm.js"
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function createUserWayIntegration(config) {
|
|
339
|
+
return {
|
|
340
|
+
id: "userway",
|
|
341
|
+
category: "marketing",
|
|
342
|
+
// ou poderia ser uma categoria 'accessibility'
|
|
343
|
+
src: `https://cdn.userway.org/widget.js`,
|
|
344
|
+
init: () => {
|
|
345
|
+
if (typeof window !== "undefined") {
|
|
346
|
+
window.UserWayWidgetApp = window.UserWayWidgetApp || {};
|
|
347
|
+
window.UserWayWidgetApp.accountId = config.accountId;
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
attrs: { "data-account": config.accountId }
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
var COMMON_INTEGRATIONS = {
|
|
354
|
+
googleAnalytics: createGoogleAnalyticsIntegration,
|
|
355
|
+
googleTagManager: createGoogleTagManagerIntegration,
|
|
356
|
+
userway: createUserWayIntegration
|
|
357
|
+
};
|
|
219
358
|
export {
|
|
359
|
+
COMMON_INTEGRATIONS,
|
|
220
360
|
ConsentGate,
|
|
221
361
|
ConsentProvider,
|
|
362
|
+
ConsentScriptLoader,
|
|
222
363
|
CookieBanner,
|
|
223
364
|
FloatingPreferencesButton,
|
|
224
365
|
PreferencesModal,
|
|
366
|
+
createGoogleAnalyticsIntegration,
|
|
367
|
+
createGoogleTagManagerIntegration,
|
|
368
|
+
createUserWayIntegration,
|
|
225
369
|
defaultConsentTheme,
|
|
226
370
|
loadScript,
|
|
371
|
+
useAllCategories,
|
|
227
372
|
useConsent,
|
|
228
373
|
useConsentHydration,
|
|
229
|
-
|
|
374
|
+
useConsentScriptLoader,
|
|
375
|
+
useConsentTexts,
|
|
376
|
+
useCustomCategories
|
|
230
377
|
};
|