@react-lgpd-consent/mui 0.7.0 → 0.7.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/README.md +6 -1
- package/dist/index.cjs +90 -32
- package/dist/index.d.cts +57 -4
- package/dist/index.d.ts +57 -4
- package/dist/index.js +90 -32
- package/dist/ui.cjs +673 -0
- package/dist/ui.d.cts +9 -0
- package/dist/ui.d.ts +9 -0
- package/dist/ui.js +628 -0
- package/package.json +10 -5
package/dist/ui.cjs
ADDED
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Link = require('@mui/material/Link');
|
|
4
|
+
var Typography = require('@mui/material/Typography');
|
|
5
|
+
var core = require('@react-lgpd-consent/core');
|
|
6
|
+
var React4 = require('react');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var styles = require('@mui/material/styles');
|
|
9
|
+
var Box2 = require('@mui/material/Box');
|
|
10
|
+
var Button = require('@mui/material/Button');
|
|
11
|
+
var Paper = require('@mui/material/Paper');
|
|
12
|
+
var Snackbar = require('@mui/material/Snackbar');
|
|
13
|
+
var Stack = require('@mui/material/Stack');
|
|
14
|
+
var CookieOutlined = require('@mui/icons-material/CookieOutlined');
|
|
15
|
+
var Fab = require('@mui/material/Fab');
|
|
16
|
+
var Tooltip = require('@mui/material/Tooltip');
|
|
17
|
+
var Dialog = require('@mui/material/Dialog');
|
|
18
|
+
var DialogActions = require('@mui/material/DialogActions');
|
|
19
|
+
var DialogContent = require('@mui/material/DialogContent');
|
|
20
|
+
var DialogTitle = require('@mui/material/DialogTitle');
|
|
21
|
+
var FormControlLabel = require('@mui/material/FormControlLabel');
|
|
22
|
+
var FormGroup = require('@mui/material/FormGroup');
|
|
23
|
+
var Switch = require('@mui/material/Switch');
|
|
24
|
+
|
|
25
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
26
|
+
|
|
27
|
+
function _interopNamespace(e) {
|
|
28
|
+
if (e && e.__esModule) return e;
|
|
29
|
+
var n = Object.create(null);
|
|
30
|
+
if (e) {
|
|
31
|
+
Object.keys(e).forEach(function (k) {
|
|
32
|
+
if (k !== 'default') {
|
|
33
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
34
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () { return e[k]; }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
n.default = e;
|
|
42
|
+
return Object.freeze(n);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var Link__default = /*#__PURE__*/_interopDefault(Link);
|
|
46
|
+
var Typography__default = /*#__PURE__*/_interopDefault(Typography);
|
|
47
|
+
var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
|
|
48
|
+
var Box2__default = /*#__PURE__*/_interopDefault(Box2);
|
|
49
|
+
var Button__default = /*#__PURE__*/_interopDefault(Button);
|
|
50
|
+
var Paper__default = /*#__PURE__*/_interopDefault(Paper);
|
|
51
|
+
var Snackbar__default = /*#__PURE__*/_interopDefault(Snackbar);
|
|
52
|
+
var Stack__default = /*#__PURE__*/_interopDefault(Stack);
|
|
53
|
+
var CookieOutlined__default = /*#__PURE__*/_interopDefault(CookieOutlined);
|
|
54
|
+
var Fab__default = /*#__PURE__*/_interopDefault(Fab);
|
|
55
|
+
var Tooltip__default = /*#__PURE__*/_interopDefault(Tooltip);
|
|
56
|
+
var Dialog__default = /*#__PURE__*/_interopDefault(Dialog);
|
|
57
|
+
var DialogActions__default = /*#__PURE__*/_interopDefault(DialogActions);
|
|
58
|
+
var DialogContent__default = /*#__PURE__*/_interopDefault(DialogContent);
|
|
59
|
+
var DialogTitle__default = /*#__PURE__*/_interopDefault(DialogTitle);
|
|
60
|
+
var FormControlLabel__default = /*#__PURE__*/_interopDefault(FormControlLabel);
|
|
61
|
+
var FormGroup__default = /*#__PURE__*/_interopDefault(FormGroup);
|
|
62
|
+
var Switch__default = /*#__PURE__*/_interopDefault(Switch);
|
|
63
|
+
|
|
64
|
+
// @react-lgpd-consent/mui - proxy build
|
|
65
|
+
|
|
66
|
+
var brandingStyles = {
|
|
67
|
+
banner: {
|
|
68
|
+
fontSize: "0.65rem",
|
|
69
|
+
textAlign: "right",
|
|
70
|
+
mt: 1,
|
|
71
|
+
opacity: 0.7,
|
|
72
|
+
fontStyle: "italic",
|
|
73
|
+
width: "100%"
|
|
74
|
+
},
|
|
75
|
+
modal: {
|
|
76
|
+
fontSize: "0.65rem",
|
|
77
|
+
textAlign: "right",
|
|
78
|
+
px: 3,
|
|
79
|
+
pb: 1,
|
|
80
|
+
opacity: 0.7,
|
|
81
|
+
fontStyle: "italic",
|
|
82
|
+
width: "100%"
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var linkStyles = {
|
|
86
|
+
textDecoration: "none",
|
|
87
|
+
fontWeight: 500,
|
|
88
|
+
"&:hover": {
|
|
89
|
+
textDecoration: "underline"
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var Branding = React4__namespace.memo(function Branding2({
|
|
93
|
+
variant,
|
|
94
|
+
hidden = false,
|
|
95
|
+
texts: textsProp,
|
|
96
|
+
language,
|
|
97
|
+
textVariant
|
|
98
|
+
}) {
|
|
99
|
+
const baseTexts = core.useConsentTexts();
|
|
100
|
+
const mergedTexts = React4__namespace.useMemo(
|
|
101
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
102
|
+
[baseTexts, textsProp]
|
|
103
|
+
);
|
|
104
|
+
const texts = React4__namespace.useMemo(
|
|
105
|
+
() => core.resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
106
|
+
[mergedTexts, language, textVariant]
|
|
107
|
+
);
|
|
108
|
+
const designTokens = core.useDesignTokens();
|
|
109
|
+
if (hidden) return null;
|
|
110
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
111
|
+
Typography__default.default,
|
|
112
|
+
{
|
|
113
|
+
variant: "caption",
|
|
114
|
+
sx: (theme) => ({
|
|
115
|
+
...brandingStyles[variant],
|
|
116
|
+
color: designTokens?.colors?.text ?? theme.palette.text.secondary
|
|
117
|
+
}),
|
|
118
|
+
children: [
|
|
119
|
+
texts.brandingPoweredBy || "fornecido por",
|
|
120
|
+
" ",
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
122
|
+
Link__default.default,
|
|
123
|
+
{
|
|
124
|
+
href: "https://www.ledipo.eti.br",
|
|
125
|
+
target: "_blank",
|
|
126
|
+
rel: "noopener noreferrer",
|
|
127
|
+
sx: (theme) => ({
|
|
128
|
+
...linkStyles,
|
|
129
|
+
color: designTokens?.colors?.primary ?? theme.palette.primary.main
|
|
130
|
+
}),
|
|
131
|
+
children: "L\xC9dipO.eti.br"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
function CookieBanner({
|
|
139
|
+
policyLinkUrl,
|
|
140
|
+
termsLinkUrl,
|
|
141
|
+
debug,
|
|
142
|
+
blocking = true,
|
|
143
|
+
hideBranding = false,
|
|
144
|
+
SnackbarProps,
|
|
145
|
+
PaperProps,
|
|
146
|
+
texts: textsProp,
|
|
147
|
+
language,
|
|
148
|
+
textVariant
|
|
149
|
+
}) {
|
|
150
|
+
const { consented, acceptAll, rejectAll, openPreferences } = core.useConsent();
|
|
151
|
+
const baseTexts = core.useConsentTexts();
|
|
152
|
+
const mergedTexts = React4__namespace.useMemo(
|
|
153
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
154
|
+
[baseTexts, textsProp]
|
|
155
|
+
);
|
|
156
|
+
const texts = React4__namespace.useMemo(
|
|
157
|
+
() => core.resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
158
|
+
[mergedTexts, language, textVariant]
|
|
159
|
+
);
|
|
160
|
+
const isHydrated = core.useConsentHydration();
|
|
161
|
+
const designTokens = core.useDesignTokens();
|
|
162
|
+
const open = debug ? true : isHydrated && !consented;
|
|
163
|
+
core.logger.componentRender("CookieBanner", {
|
|
164
|
+
open,
|
|
165
|
+
consented,
|
|
166
|
+
isHydrated,
|
|
167
|
+
blocking,
|
|
168
|
+
hideBranding
|
|
169
|
+
});
|
|
170
|
+
if (!open) return null;
|
|
171
|
+
const bannerStyle = (theme) => ({
|
|
172
|
+
p: designTokens?.spacing?.padding?.banner ?? 2,
|
|
173
|
+
maxWidth: 720,
|
|
174
|
+
mx: "auto",
|
|
175
|
+
backgroundColor: designTokens?.colors?.background ?? theme.palette.background?.paper,
|
|
176
|
+
color: designTokens?.colors?.text ?? theme.palette.text?.primary,
|
|
177
|
+
borderRadius: designTokens?.spacing?.borderRadius?.banner,
|
|
178
|
+
fontFamily: designTokens?.typography?.fontFamily
|
|
179
|
+
});
|
|
180
|
+
const bannerContent = /* @__PURE__ */ jsxRuntime.jsx(Paper__default.default, { elevation: 3, sx: bannerStyle, ...PaperProps, children: /* @__PURE__ */ jsxRuntime.jsxs(Stack__default.default, { spacing: 1, children: [
|
|
181
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Typography__default.default, { variant: "body2", sx: { fontSize: designTokens?.typography?.fontSize?.banner }, children: [
|
|
182
|
+
texts.bannerMessage,
|
|
183
|
+
" ",
|
|
184
|
+
policyLinkUrl && /* @__PURE__ */ jsxRuntime.jsx(
|
|
185
|
+
Link__default.default,
|
|
186
|
+
{
|
|
187
|
+
href: policyLinkUrl,
|
|
188
|
+
underline: "hover",
|
|
189
|
+
target: "_blank",
|
|
190
|
+
rel: "noopener noreferrer",
|
|
191
|
+
sx: { color: designTokens?.colors?.primary },
|
|
192
|
+
children: texts.policyLink ?? "Saiba mais"
|
|
193
|
+
}
|
|
194
|
+
)
|
|
195
|
+
] }),
|
|
196
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Stack__default.default, { direction: { xs: "column", sm: "row" }, spacing: 1, justifyContent: "flex-end", children: [
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
198
|
+
Button__default.default,
|
|
199
|
+
{
|
|
200
|
+
variant: "outlined",
|
|
201
|
+
onClick: () => {
|
|
202
|
+
core.logger.apiUsage("rejectAll", { source: "banner" });
|
|
203
|
+
rejectAll();
|
|
204
|
+
},
|
|
205
|
+
sx: { color: designTokens?.colors?.secondary },
|
|
206
|
+
children: texts.declineAll
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
210
|
+
Button__default.default,
|
|
211
|
+
{
|
|
212
|
+
variant: "contained",
|
|
213
|
+
onClick: () => {
|
|
214
|
+
core.logger.apiUsage("acceptAll", { source: "banner" });
|
|
215
|
+
acceptAll();
|
|
216
|
+
},
|
|
217
|
+
sx: { backgroundColor: designTokens?.colors?.primary },
|
|
218
|
+
children: texts.acceptAll
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
222
|
+
Button__default.default,
|
|
223
|
+
{
|
|
224
|
+
variant: "text",
|
|
225
|
+
onClick: () => {
|
|
226
|
+
core.logger.apiUsage("openPreferences", { source: "banner" });
|
|
227
|
+
openPreferences();
|
|
228
|
+
},
|
|
229
|
+
sx: { color: designTokens?.colors?.text },
|
|
230
|
+
children: texts.preferences
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
] }),
|
|
234
|
+
!hideBranding && /* @__PURE__ */ jsxRuntime.jsx(
|
|
235
|
+
Branding,
|
|
236
|
+
{
|
|
237
|
+
variant: "banner",
|
|
238
|
+
texts: textsProp,
|
|
239
|
+
language,
|
|
240
|
+
textVariant
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
] }) });
|
|
244
|
+
const resolveBannerZIndex = (theme) => designTokens?.layout?.zIndex?.banner ?? theme?.zIndex?.snackbar ?? 1400;
|
|
245
|
+
const positionStyle = (theme) => ({
|
|
246
|
+
position: "fixed",
|
|
247
|
+
zIndex: resolveBannerZIndex(theme),
|
|
248
|
+
...designTokens?.layout?.position === "top" ? { top: 0 } : { bottom: 0 },
|
|
249
|
+
left: 0,
|
|
250
|
+
right: 0,
|
|
251
|
+
width: designTokens?.layout?.width?.desktop ?? "100%",
|
|
252
|
+
p: 2
|
|
253
|
+
});
|
|
254
|
+
const backdropToken = designTokens?.layout?.backdrop;
|
|
255
|
+
const resolveBackdropColor = (theme) => {
|
|
256
|
+
if (backdropToken === false) return "transparent";
|
|
257
|
+
if (typeof backdropToken === "string") {
|
|
258
|
+
if (backdropToken.toLowerCase() === "auto") {
|
|
259
|
+
const isDark2 = theme?.palette?.mode === "dark";
|
|
260
|
+
return isDark2 ? "rgba(255, 255, 255, 0.12)" : "rgba(0, 0, 0, 0.4)";
|
|
261
|
+
}
|
|
262
|
+
return backdropToken;
|
|
263
|
+
}
|
|
264
|
+
const isDark = theme?.palette?.mode === "dark";
|
|
265
|
+
return isDark ? "rgba(255, 255, 255, 0.12)" : "rgba(0, 0, 0, 0.4)";
|
|
266
|
+
};
|
|
267
|
+
const isSafeRoute = (() => {
|
|
268
|
+
try {
|
|
269
|
+
if (globalThis?.window === void 0) return false;
|
|
270
|
+
const current = new URL(globalThis.window.location.href);
|
|
271
|
+
const safeUrls = [policyLinkUrl, termsLinkUrl].filter(Boolean);
|
|
272
|
+
return safeUrls.some((u) => {
|
|
273
|
+
try {
|
|
274
|
+
const target = new URL(u, current.origin);
|
|
275
|
+
return target.pathname === current.pathname;
|
|
276
|
+
} catch {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
} catch {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
})();
|
|
284
|
+
const effectiveBlocking = blocking && !isSafeRoute;
|
|
285
|
+
if (effectiveBlocking) {
|
|
286
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
287
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
288
|
+
Box2__default.default,
|
|
289
|
+
{
|
|
290
|
+
sx: (theme) => ({
|
|
291
|
+
position: "fixed",
|
|
292
|
+
top: 0,
|
|
293
|
+
left: 0,
|
|
294
|
+
right: 0,
|
|
295
|
+
bottom: 0,
|
|
296
|
+
backgroundColor: resolveBackdropColor(theme),
|
|
297
|
+
zIndex: designTokens?.layout?.zIndex?.backdrop ?? (resolveBannerZIndex(theme) ? resolveBannerZIndex(theme) - 1 : 1299)
|
|
298
|
+
}),
|
|
299
|
+
"data-testid": "lgpd-cookie-banner-overlay"
|
|
300
|
+
}
|
|
301
|
+
),
|
|
302
|
+
/* @__PURE__ */ jsxRuntime.jsx(Box2__default.default, { sx: positionStyle, "data-testid": "lgpd-cookie-banner-wrapper", children: bannerContent })
|
|
303
|
+
] });
|
|
304
|
+
}
|
|
305
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
306
|
+
Snackbar__default.default,
|
|
307
|
+
{
|
|
308
|
+
open,
|
|
309
|
+
anchorOrigin: {
|
|
310
|
+
vertical: designTokens?.layout?.position === "top" ? "top" : "bottom",
|
|
311
|
+
horizontal: "center"
|
|
312
|
+
},
|
|
313
|
+
...SnackbarProps,
|
|
314
|
+
children: bannerContent
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
function useThemeWithFallbacks() {
|
|
319
|
+
const theme = styles.useTheme();
|
|
320
|
+
core.logger.themeCompatibility(theme);
|
|
321
|
+
return {
|
|
322
|
+
palette: {
|
|
323
|
+
primary: {
|
|
324
|
+
main: theme?.palette?.primary?.main || "#1976d2",
|
|
325
|
+
dark: theme?.palette?.primary?.dark || "#1565c0"
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
transitions: {
|
|
329
|
+
duration: {
|
|
330
|
+
shortest: theme?.transitions?.duration?.shortest || 150,
|
|
331
|
+
short: theme?.transitions?.duration?.short || 250
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function FloatingPreferencesButtonComponent({
|
|
337
|
+
position = "bottom-right",
|
|
338
|
+
offset = 24,
|
|
339
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(CookieOutlined__default.default, {}),
|
|
340
|
+
tooltip,
|
|
341
|
+
FabProps,
|
|
342
|
+
hideWhenConsented = false,
|
|
343
|
+
texts: textsProp,
|
|
344
|
+
language,
|
|
345
|
+
textVariant
|
|
346
|
+
}) {
|
|
347
|
+
const { openPreferences, consented } = core.useConsent();
|
|
348
|
+
const baseTexts = core.useConsentTexts();
|
|
349
|
+
const mergedTexts = React4__namespace.useMemo(
|
|
350
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
351
|
+
[baseTexts, textsProp]
|
|
352
|
+
);
|
|
353
|
+
const texts = React4__namespace.useMemo(
|
|
354
|
+
() => core.resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
355
|
+
[mergedTexts, language, textVariant]
|
|
356
|
+
);
|
|
357
|
+
const safeTheme = useThemeWithFallbacks();
|
|
358
|
+
const designTokens = core.useDesignTokens();
|
|
359
|
+
const positionStyles = React4__namespace.useMemo(() => {
|
|
360
|
+
const styles = {
|
|
361
|
+
position: "fixed",
|
|
362
|
+
zIndex: 1200
|
|
363
|
+
};
|
|
364
|
+
switch (position) {
|
|
365
|
+
case "bottom-left":
|
|
366
|
+
return { ...styles, bottom: offset, left: offset };
|
|
367
|
+
case "bottom-right":
|
|
368
|
+
return { ...styles, bottom: offset, right: offset };
|
|
369
|
+
case "top-left":
|
|
370
|
+
return { ...styles, top: offset, left: offset };
|
|
371
|
+
case "top-right":
|
|
372
|
+
return { ...styles, top: offset, right: offset };
|
|
373
|
+
default:
|
|
374
|
+
return { ...styles, bottom: offset, right: offset };
|
|
375
|
+
}
|
|
376
|
+
}, [position, offset]);
|
|
377
|
+
core.logger.componentRender("FloatingPreferencesButton", {
|
|
378
|
+
position,
|
|
379
|
+
offset,
|
|
380
|
+
hideWhenConsented,
|
|
381
|
+
consented
|
|
382
|
+
});
|
|
383
|
+
if (hideWhenConsented && consented) {
|
|
384
|
+
core.logger.debug(
|
|
385
|
+
"FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
|
|
386
|
+
);
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
390
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tooltip__default.default, { title: tooltipText, placement: "top", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
391
|
+
Fab__default.default,
|
|
392
|
+
{
|
|
393
|
+
size: "medium",
|
|
394
|
+
color: "primary",
|
|
395
|
+
onClick: openPreferences,
|
|
396
|
+
sx: {
|
|
397
|
+
...positionStyles,
|
|
398
|
+
backgroundColor: designTokens?.colors?.primary ?? safeTheme.palette.primary.main,
|
|
399
|
+
"&:hover": {
|
|
400
|
+
backgroundColor: designTokens?.colors?.primary ? designTokens?.colors?.primary : safeTheme.palette.primary.dark
|
|
401
|
+
},
|
|
402
|
+
transition: `all ${safeTheme.transitions.duration.short}ms`
|
|
403
|
+
},
|
|
404
|
+
"aria-label": tooltipText,
|
|
405
|
+
...FabProps,
|
|
406
|
+
children: icon
|
|
407
|
+
}
|
|
408
|
+
) });
|
|
409
|
+
}
|
|
410
|
+
var FloatingPreferencesButton = React4__namespace.memo(FloatingPreferencesButtonComponent);
|
|
411
|
+
FloatingPreferencesButton.displayName = "FloatingPreferencesButton";
|
|
412
|
+
function PreferencesModal({
|
|
413
|
+
DialogProps: DialogProps2,
|
|
414
|
+
hideBranding = false,
|
|
415
|
+
isModalOpen: isModalOpenProp,
|
|
416
|
+
preferences: preferencesProp,
|
|
417
|
+
setPreferences: setPreferencesProp,
|
|
418
|
+
closePreferences: closePreferencesProp,
|
|
419
|
+
texts: textsProp,
|
|
420
|
+
language,
|
|
421
|
+
textVariant
|
|
422
|
+
}) {
|
|
423
|
+
const hookValue = core.useConsent();
|
|
424
|
+
const preferences = preferencesProp ?? hookValue.preferences;
|
|
425
|
+
const setPreferences = setPreferencesProp ?? hookValue.setPreferences;
|
|
426
|
+
const closePreferences = closePreferencesProp ?? hookValue.closePreferences;
|
|
427
|
+
const isModalOpen = isModalOpenProp ?? hookValue.isModalOpen;
|
|
428
|
+
const baseTexts = core.useConsentTexts();
|
|
429
|
+
const mergedTexts = React4__namespace.useMemo(
|
|
430
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
431
|
+
[baseTexts, textsProp]
|
|
432
|
+
);
|
|
433
|
+
const texts = React4__namespace.useMemo(
|
|
434
|
+
() => core.resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
435
|
+
[mergedTexts, language, textVariant]
|
|
436
|
+
);
|
|
437
|
+
const designTokens = core.useDesignTokens();
|
|
438
|
+
const { toggleableCategories, allCategories } = core.useCategories();
|
|
439
|
+
const getInitialPreferences = React4__namespace.useCallback(() => {
|
|
440
|
+
const syncedPrefs = { necessary: true };
|
|
441
|
+
toggleableCategories.forEach((category) => {
|
|
442
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
443
|
+
});
|
|
444
|
+
return syncedPrefs;
|
|
445
|
+
}, [preferences, toggleableCategories]);
|
|
446
|
+
const [tempPreferences, setTempPreferences] = React4__namespace.useState(getInitialPreferences);
|
|
447
|
+
const wasOpenRef = React4__namespace.useRef(isModalOpen);
|
|
448
|
+
React4__namespace.useEffect(() => {
|
|
449
|
+
const justOpened = isModalOpen && !wasOpenRef.current;
|
|
450
|
+
wasOpenRef.current = isModalOpen;
|
|
451
|
+
if (justOpened) {
|
|
452
|
+
queueMicrotask(() => {
|
|
453
|
+
setTempPreferences(getInitialPreferences());
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}, [isModalOpen, getInitialPreferences]);
|
|
457
|
+
const { open: dialogOpenProp, ...dialogRest } = DialogProps2 ?? {};
|
|
458
|
+
const open = dialogOpenProp ?? isModalOpen ?? false;
|
|
459
|
+
const handleSave = () => {
|
|
460
|
+
setPreferences(tempPreferences);
|
|
461
|
+
};
|
|
462
|
+
const handleCancel = () => {
|
|
463
|
+
setTempPreferences(preferences);
|
|
464
|
+
closePreferences();
|
|
465
|
+
};
|
|
466
|
+
const modalTitleSx = (theme) => ({
|
|
467
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
468
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
469
|
+
});
|
|
470
|
+
const modalContentSx = (theme) => ({
|
|
471
|
+
p: designTokens?.spacing?.padding?.modal ?? void 0,
|
|
472
|
+
backgroundColor: designTokens?.colors?.background ?? theme.palette.background.paper,
|
|
473
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
474
|
+
});
|
|
475
|
+
const resolveModalZIndex = React4__namespace.useCallback(
|
|
476
|
+
(theme) => designTokens?.layout?.zIndex?.modal ?? (theme?.zIndex?.modal ?? 1300) + 10,
|
|
477
|
+
[designTokens?.layout?.zIndex?.modal]
|
|
478
|
+
);
|
|
479
|
+
const modalZIndexToken = designTokens?.layout?.zIndex?.modal;
|
|
480
|
+
const rootSx = [
|
|
481
|
+
DialogProps2?.slotProps?.root && DialogProps2.slotProps.root.sx,
|
|
482
|
+
(theme) => ({ zIndex: resolveModalZIndex(theme) })
|
|
483
|
+
].filter(Boolean);
|
|
484
|
+
const rootSlotProps = {
|
|
485
|
+
...dialogRest?.slotProps?.root,
|
|
486
|
+
sx: rootSx,
|
|
487
|
+
...modalZIndexToken ? { style: { zIndex: modalZIndexToken } } : {},
|
|
488
|
+
"data-testid": dialogRest?.slotProps?.root?.["data-testid"] ?? "lgpd-preferences-modal-root"
|
|
489
|
+
};
|
|
490
|
+
const mergedDialogProps = {
|
|
491
|
+
open,
|
|
492
|
+
fullWidth: true,
|
|
493
|
+
maxWidth: "sm",
|
|
494
|
+
...dialogRest,
|
|
495
|
+
slotProps: {
|
|
496
|
+
...dialogRest?.slotProps,
|
|
497
|
+
root: rootSlotProps
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Dialog__default.default, { "aria-labelledby": "cookie-pref-title", onClose: handleCancel, ...mergedDialogProps, children: [
|
|
501
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle__default.default, { id: "cookie-pref-title", sx: modalTitleSx, children: texts.modalTitle }),
|
|
502
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogContent__default.default, { dividers: true, sx: modalContentSx, children: [
|
|
503
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
504
|
+
Typography__default.default,
|
|
505
|
+
{
|
|
506
|
+
variant: "body2",
|
|
507
|
+
sx: (theme) => ({
|
|
508
|
+
mb: 2,
|
|
509
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
510
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
511
|
+
}),
|
|
512
|
+
children: texts.modalIntro
|
|
513
|
+
}
|
|
514
|
+
),
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsxs(FormGroup__default.default, { children: [
|
|
516
|
+
toggleableCategories.map((category) => {
|
|
517
|
+
const full = allCategories.find((c) => c.id === category.id);
|
|
518
|
+
const namesFromGuidance = full?.cookies ?? [];
|
|
519
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
520
|
+
const descriptors = core.getCookiesInfoForCategory(category.id, used);
|
|
521
|
+
const tableHeaders = texts.cookieDetails?.tableHeaders;
|
|
522
|
+
const toggleDetailsText = texts.cookieDetails?.toggleDetails?.expand ?? "Ver detalhes";
|
|
523
|
+
const scriptLabelPrefix = texts.cookieDetails?.scriptLabelPrefix ?? "(script) ";
|
|
524
|
+
const scriptPurpose = texts.cookieDetails?.scriptPurpose ?? "Script de integra\xE7\xE3o ativo";
|
|
525
|
+
const enrichedDescriptors = descriptors.map((desc) => {
|
|
526
|
+
if (desc.purpose && desc.duration && desc.provider) {
|
|
527
|
+
return desc;
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
name: desc.name,
|
|
531
|
+
purpose: desc.purpose || "-",
|
|
532
|
+
duration: desc.duration || "-",
|
|
533
|
+
provider: desc.provider || "-"
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
const merged = [
|
|
537
|
+
...enrichedDescriptors,
|
|
538
|
+
...namesFromGuidance.filter((n) => !enrichedDescriptors.some((d) => d.name === n)).map((n) => ({ name: n, purpose: "-", duration: "-", provider: "-" }))
|
|
539
|
+
];
|
|
540
|
+
let mergedFinal = merged;
|
|
541
|
+
try {
|
|
542
|
+
if (merged.length === 0) {
|
|
543
|
+
const gmap = globalThis.__LGPD_INTEGRATIONS_MAP__ || {};
|
|
544
|
+
const scriptRows = Object.entries(gmap).filter(([, cat]) => cat === category.id).map(([id]) => ({
|
|
545
|
+
name: `${scriptLabelPrefix}${id}`,
|
|
546
|
+
purpose: scriptPurpose,
|
|
547
|
+
duration: "-",
|
|
548
|
+
provider: "-"
|
|
549
|
+
}));
|
|
550
|
+
if (scriptRows.length > 0) mergedFinal = scriptRows;
|
|
551
|
+
}
|
|
552
|
+
} catch {
|
|
553
|
+
}
|
|
554
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Box2__default.default, { sx: { mb: 1 }, children: [
|
|
555
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
556
|
+
FormControlLabel__default.default,
|
|
557
|
+
{
|
|
558
|
+
control: /* @__PURE__ */ jsxRuntime.jsx(
|
|
559
|
+
Switch__default.default,
|
|
560
|
+
{
|
|
561
|
+
checked: tempPreferences[category.id] ?? false,
|
|
562
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
563
|
+
...prev,
|
|
564
|
+
[category.id]: e.target.checked
|
|
565
|
+
}))
|
|
566
|
+
}
|
|
567
|
+
),
|
|
568
|
+
label: `${category.name} - ${category.description}`
|
|
569
|
+
}
|
|
570
|
+
),
|
|
571
|
+
/* @__PURE__ */ jsxRuntime.jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
572
|
+
/* @__PURE__ */ jsxRuntime.jsx("summary", { children: toggleDetailsText }),
|
|
573
|
+
/* @__PURE__ */ jsxRuntime.jsx(Box2__default.default, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxRuntime.jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
574
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
575
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.name ?? "Cookie" }),
|
|
576
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.purpose ?? "Finalidade" }),
|
|
577
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.duration ?? "Dura\xE7\xE3o" }),
|
|
578
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.provider ?? "Fornecedor" })
|
|
579
|
+
] }) }),
|
|
580
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: mergedFinal.map((d, idx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
581
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.name }),
|
|
582
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.purpose }),
|
|
583
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.duration }),
|
|
584
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.provider })
|
|
585
|
+
] }, d.name + idx)) })
|
|
586
|
+
] }) })
|
|
587
|
+
] })
|
|
588
|
+
] }, category.id);
|
|
589
|
+
}),
|
|
590
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControlLabel__default.default, { control: /* @__PURE__ */ jsxRuntime.jsx(Switch__default.default, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn }),
|
|
591
|
+
/* @__PURE__ */ jsxRuntime.jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
592
|
+
/* @__PURE__ */ jsxRuntime.jsx("summary", { children: texts.cookieDetails?.toggleDetails?.expand ?? "Ver detalhes" }),
|
|
593
|
+
/* @__PURE__ */ jsxRuntime.jsx(Box2__default.default, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxRuntime.jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
594
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
595
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.name ?? "Cookie" }),
|
|
596
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.purpose ?? "Finalidade" }),
|
|
597
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.duration ?? "Dura\xE7\xE3o" }),
|
|
598
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.provider ?? "Fornecedor" })
|
|
599
|
+
] }) }),
|
|
600
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: (() => {
|
|
601
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
602
|
+
const necessaryCookies = core.getCookiesInfoForCategory(
|
|
603
|
+
"necessary",
|
|
604
|
+
used
|
|
605
|
+
);
|
|
606
|
+
return necessaryCookies.map((d, idx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
607
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.name }),
|
|
608
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.purpose || "-" }),
|
|
609
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.duration || "-" }),
|
|
610
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.provider || "-" })
|
|
611
|
+
] }, d.name + idx));
|
|
612
|
+
})() })
|
|
613
|
+
] }) })
|
|
614
|
+
] })
|
|
615
|
+
] })
|
|
616
|
+
] }),
|
|
617
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogActions__default.default, { children: [
|
|
618
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button__default.default, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
619
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button__default.default, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
620
|
+
] }),
|
|
621
|
+
!hideBranding && /* @__PURE__ */ jsxRuntime.jsx(Branding, { variant: "modal", texts: textsProp, language, textVariant })
|
|
622
|
+
] });
|
|
623
|
+
}
|
|
624
|
+
function ConsentProvider({
|
|
625
|
+
disableDefaultModal = false,
|
|
626
|
+
disableDefaultBanner = false,
|
|
627
|
+
disableDefaultFloatingButton = false,
|
|
628
|
+
PreferencesModalComponent,
|
|
629
|
+
CookieBannerComponent,
|
|
630
|
+
FloatingPreferencesButtonComponent: FloatingPreferencesButtonComponent2,
|
|
631
|
+
theme,
|
|
632
|
+
hideBranding,
|
|
633
|
+
cookieBannerProps,
|
|
634
|
+
preferencesModalProps,
|
|
635
|
+
floatingPreferencesButtonProps,
|
|
636
|
+
children,
|
|
637
|
+
...coreProps
|
|
638
|
+
}) {
|
|
639
|
+
const modalComponent = disableDefaultModal ? PreferencesModalComponent : PreferencesModalComponent || PreferencesModal;
|
|
640
|
+
const bannerComponent = disableDefaultBanner ? CookieBannerComponent : CookieBannerComponent || CookieBanner;
|
|
641
|
+
const floatingButtonComponent = disableDefaultFloatingButton ? FloatingPreferencesButtonComponent2 : FloatingPreferencesButtonComponent2 || FloatingPreferencesButton;
|
|
642
|
+
const mergedCookieBannerProps = {
|
|
643
|
+
...cookieBannerProps,
|
|
644
|
+
hideBranding: cookieBannerProps?.hideBranding ?? hideBranding
|
|
645
|
+
};
|
|
646
|
+
const mergedPreferencesModalProps = {
|
|
647
|
+
...preferencesModalProps,
|
|
648
|
+
hideBranding: preferencesModalProps?.hideBranding ?? hideBranding
|
|
649
|
+
};
|
|
650
|
+
const provider = /* @__PURE__ */ jsxRuntime.jsx(
|
|
651
|
+
core.ConsentProvider,
|
|
652
|
+
{
|
|
653
|
+
...coreProps,
|
|
654
|
+
hideBranding,
|
|
655
|
+
cookieBannerProps: mergedCookieBannerProps,
|
|
656
|
+
preferencesModalProps: mergedPreferencesModalProps,
|
|
657
|
+
floatingPreferencesButtonProps,
|
|
658
|
+
CookieBannerComponent: bannerComponent,
|
|
659
|
+
PreferencesModalComponent: modalComponent,
|
|
660
|
+
FloatingPreferencesButtonComponent: floatingButtonComponent,
|
|
661
|
+
children
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
if (!theme) return provider;
|
|
665
|
+
return /* @__PURE__ */ jsxRuntime.jsx(styles.ThemeProvider, { theme, children: provider });
|
|
666
|
+
}
|
|
667
|
+
ConsentProvider.displayName = "ConsentProvider(MUI)";
|
|
668
|
+
|
|
669
|
+
exports.Branding = Branding;
|
|
670
|
+
exports.ConsentProvider = ConsentProvider;
|
|
671
|
+
exports.CookieBanner = CookieBanner;
|
|
672
|
+
exports.FloatingPreferencesButton = FloatingPreferencesButton;
|
|
673
|
+
exports.PreferencesModal = PreferencesModal;
|
package/dist/ui.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Branding, BrandingProps, ConsentProvider, ConsentProviderProps, CookieBanner, CookieBannerProps, FloatingPreferencesButton, FloatingPreferencesButtonProps, PreferencesModal, PreferencesModalProps } from './index.cjs';
|
|
2
|
+
import '@react-lgpd-consent/core';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@mui/material/styles';
|
|
6
|
+
import '@mui/material/Paper';
|
|
7
|
+
import '@mui/material/Snackbar';
|
|
8
|
+
import '@mui/material/Fab';
|
|
9
|
+
import '@mui/material/Dialog';
|
package/dist/ui.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Branding, BrandingProps, ConsentProvider, ConsentProviderProps, CookieBanner, CookieBannerProps, FloatingPreferencesButton, FloatingPreferencesButtonProps, PreferencesModal, PreferencesModalProps } from './index.js';
|
|
2
|
+
import '@react-lgpd-consent/core';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import '@mui/material/styles';
|
|
6
|
+
import '@mui/material/Paper';
|
|
7
|
+
import '@mui/material/Snackbar';
|
|
8
|
+
import '@mui/material/Fab';
|
|
9
|
+
import '@mui/material/Dialog';
|