react-lgpd-consent 0.4.1 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +150 -3
- package/QUICKSTART.md +254 -0
- package/README.en.md +6 -0
- package/README.md +20 -0
- package/dist/FloatingPreferencesButton-4AGBXNHH.cjs +11 -0
- package/dist/FloatingPreferencesButton-IY7TFD7D.js +2 -0
- package/dist/PreferencesModal-5KNHWW57.js +2 -0
- package/dist/PreferencesModal-YBCWCVUI.cjs +11 -0
- package/dist/chunk-25XEI2DZ.cjs +193 -0
- package/dist/chunk-FJKRAERJ.cjs +119 -0
- package/dist/chunk-N3QOW4SA.js +178 -0
- package/dist/chunk-ORI4PLVG.cjs +1899 -0
- package/dist/chunk-PJFGQMCI.js +92 -0
- package/dist/{chunk-VOQUCGOA.js → chunk-RWT2ORFE.js} +340 -522
- package/dist/index.cjs +177 -2286
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +10 -98
- package/package.json +47 -41
- package/dist/PreferencesModal-RNRD3JKB.js +0 -6
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkORI4PLVG_cjs = require('./chunk-ORI4PLVG.cjs');
|
|
4
|
+
var Box = require('@mui/material/Box');
|
|
5
|
+
var Button = require('@mui/material/Button');
|
|
6
|
+
var Dialog = require('@mui/material/Dialog');
|
|
7
|
+
var DialogActions = require('@mui/material/DialogActions');
|
|
8
|
+
var DialogContent = require('@mui/material/DialogContent');
|
|
9
|
+
var DialogTitle = require('@mui/material/DialogTitle');
|
|
10
|
+
var FormControlLabel = require('@mui/material/FormControlLabel');
|
|
11
|
+
var FormGroup = require('@mui/material/FormGroup');
|
|
12
|
+
var Switch = require('@mui/material/Switch');
|
|
13
|
+
var Typography = require('@mui/material/Typography');
|
|
14
|
+
var react = require('react');
|
|
15
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
16
|
+
|
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
|
|
19
|
+
var Box__default = /*#__PURE__*/_interopDefault(Box);
|
|
20
|
+
var Button__default = /*#__PURE__*/_interopDefault(Button);
|
|
21
|
+
var Dialog__default = /*#__PURE__*/_interopDefault(Dialog);
|
|
22
|
+
var DialogActions__default = /*#__PURE__*/_interopDefault(DialogActions);
|
|
23
|
+
var DialogContent__default = /*#__PURE__*/_interopDefault(DialogContent);
|
|
24
|
+
var DialogTitle__default = /*#__PURE__*/_interopDefault(DialogTitle);
|
|
25
|
+
var FormControlLabel__default = /*#__PURE__*/_interopDefault(FormControlLabel);
|
|
26
|
+
var FormGroup__default = /*#__PURE__*/_interopDefault(FormGroup);
|
|
27
|
+
var Switch__default = /*#__PURE__*/_interopDefault(Switch);
|
|
28
|
+
var Typography__default = /*#__PURE__*/_interopDefault(Typography);
|
|
29
|
+
|
|
30
|
+
// react-lgpd-consent - Tree-shakeable ESM build
|
|
31
|
+
function PreferencesModal({
|
|
32
|
+
DialogProps: DialogProps2,
|
|
33
|
+
hideBranding = false
|
|
34
|
+
}) {
|
|
35
|
+
const { preferences, setPreferences, closePreferences, isModalOpen } = chunkORI4PLVG_cjs.useConsent();
|
|
36
|
+
const texts = chunkORI4PLVG_cjs.useConsentTexts();
|
|
37
|
+
const designTokens = chunkORI4PLVG_cjs.useDesignTokens();
|
|
38
|
+
const { toggleableCategories, allCategories } = chunkORI4PLVG_cjs.useCategories();
|
|
39
|
+
const [tempPreferences, setTempPreferences] = react.useState(() => {
|
|
40
|
+
const initialPrefs = { necessary: true };
|
|
41
|
+
toggleableCategories.forEach((category) => {
|
|
42
|
+
initialPrefs[category.id] = preferences[category.id] ?? false;
|
|
43
|
+
});
|
|
44
|
+
return initialPrefs;
|
|
45
|
+
});
|
|
46
|
+
react.useEffect(() => {
|
|
47
|
+
if (isModalOpen) {
|
|
48
|
+
const syncedPrefs = { necessary: true };
|
|
49
|
+
toggleableCategories.forEach((category) => {
|
|
50
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
51
|
+
});
|
|
52
|
+
setTempPreferences(syncedPrefs);
|
|
53
|
+
}
|
|
54
|
+
}, [isModalOpen, preferences, toggleableCategories]);
|
|
55
|
+
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
56
|
+
const handleSave = () => {
|
|
57
|
+
setPreferences(tempPreferences);
|
|
58
|
+
};
|
|
59
|
+
const handleCancel = () => {
|
|
60
|
+
setTempPreferences(preferences);
|
|
61
|
+
closePreferences();
|
|
62
|
+
};
|
|
63
|
+
const modalTitleSx = (theme) => ({
|
|
64
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
65
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
66
|
+
});
|
|
67
|
+
const modalContentSx = (theme) => ({
|
|
68
|
+
p: designTokens?.spacing?.padding?.modal ?? void 0,
|
|
69
|
+
backgroundColor: designTokens?.colors?.background ?? theme.palette.background.paper,
|
|
70
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
71
|
+
});
|
|
72
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Dialog__default.default, { "aria-labelledby": "cookie-pref-title", open, onClose: handleCancel, ...DialogProps2, children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle__default.default, { id: "cookie-pref-title", sx: modalTitleSx, children: texts.modalTitle }),
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogContent__default.default, { dividers: true, sx: modalContentSx, children: [
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
76
|
+
Typography__default.default,
|
|
77
|
+
{
|
|
78
|
+
variant: "body2",
|
|
79
|
+
sx: (theme) => ({
|
|
80
|
+
mb: 2,
|
|
81
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
82
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
83
|
+
}),
|
|
84
|
+
children: texts.modalIntro
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsxs(FormGroup__default.default, { children: [
|
|
88
|
+
toggleableCategories.map((category) => {
|
|
89
|
+
const full = allCategories.find((c) => c.id === category.id);
|
|
90
|
+
const namesFromGuidance = full?.cookies ?? [];
|
|
91
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
92
|
+
const descriptors = chunkORI4PLVG_cjs.getCookiesInfoForCategory(category.id, used);
|
|
93
|
+
const enrichedDescriptors = descriptors.map((desc) => {
|
|
94
|
+
if (desc.purpose && desc.duration && desc.provider) {
|
|
95
|
+
return desc;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
name: desc.name,
|
|
99
|
+
purpose: desc.purpose || "-",
|
|
100
|
+
duration: desc.duration || "-",
|
|
101
|
+
provider: desc.provider || "-"
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
const merged = [
|
|
105
|
+
...enrichedDescriptors,
|
|
106
|
+
...namesFromGuidance.filter((n) => !enrichedDescriptors.find((d) => d.name === n)).map((n) => ({ name: n, purpose: "-", duration: "-", provider: "-" }))
|
|
107
|
+
];
|
|
108
|
+
let mergedFinal = merged;
|
|
109
|
+
try {
|
|
110
|
+
if (merged.length === 0) {
|
|
111
|
+
const gmap = globalThis.__LGPD_INTEGRATIONS_MAP__ || {};
|
|
112
|
+
const scriptRows = Object.entries(gmap).filter(([, cat]) => cat === category.id).map(([id]) => ({
|
|
113
|
+
name: `(script) ${id}`,
|
|
114
|
+
purpose: "Script de integra\xE7\xE3o ativo",
|
|
115
|
+
duration: "-",
|
|
116
|
+
provider: "-"
|
|
117
|
+
}));
|
|
118
|
+
if (scriptRows.length > 0) mergedFinal = scriptRows;
|
|
119
|
+
}
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, { sx: { mb: 1 }, children: [
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
124
|
+
FormControlLabel__default.default,
|
|
125
|
+
{
|
|
126
|
+
control: /* @__PURE__ */ jsxRuntime.jsx(
|
|
127
|
+
Switch__default.default,
|
|
128
|
+
{
|
|
129
|
+
checked: tempPreferences[category.id] ?? false,
|
|
130
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
131
|
+
...prev,
|
|
132
|
+
[category.id]: e.target.checked
|
|
133
|
+
}))
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
label: `${category.name} - ${category.description}`
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ jsxRuntime.jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx("summary", { children: "Ver detalhes" }),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsx(Box__default.default, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxRuntime.jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
145
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
146
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
147
|
+
] }) }),
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: mergedFinal.map((d, idx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.name }),
|
|
150
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.purpose }),
|
|
151
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.duration }),
|
|
152
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.provider })
|
|
153
|
+
] }, d.name + idx)) })
|
|
154
|
+
] }) })
|
|
155
|
+
] })
|
|
156
|
+
] }, category.id);
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControlLabel__default.default, { control: /* @__PURE__ */ jsxRuntime.jsx(Switch__default.default, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn }),
|
|
159
|
+
/* @__PURE__ */ jsxRuntime.jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
160
|
+
/* @__PURE__ */ jsxRuntime.jsx("summary", { children: "Ver detalhes" }),
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx(Box__default.default, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxRuntime.jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
163
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
164
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
165
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
166
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
167
|
+
] }) }),
|
|
168
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: (() => {
|
|
169
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
170
|
+
const necessaryCookies = chunkORI4PLVG_cjs.getCookiesInfoForCategory(
|
|
171
|
+
"necessary",
|
|
172
|
+
used
|
|
173
|
+
);
|
|
174
|
+
return necessaryCookies.map((d, idx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
175
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.name }),
|
|
176
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.purpose || "-" }),
|
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.duration || "-" }),
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { children: d.provider || "-" })
|
|
179
|
+
] }, d.name + idx));
|
|
180
|
+
})() })
|
|
181
|
+
] }) })
|
|
182
|
+
] })
|
|
183
|
+
] })
|
|
184
|
+
] }),
|
|
185
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogActions__default.default, { children: [
|
|
186
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button__default.default, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button__default.default, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
188
|
+
] }),
|
|
189
|
+
!hideBranding && /* @__PURE__ */ jsxRuntime.jsx(chunkORI4PLVG_cjs.Branding, { variant: "modal" })
|
|
190
|
+
] });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
exports.PreferencesModal = PreferencesModal;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkORI4PLVG_cjs = require('./chunk-ORI4PLVG.cjs');
|
|
4
|
+
var CookieOutlined = require('@mui/icons-material/CookieOutlined');
|
|
5
|
+
var Fab = require('@mui/material/Fab');
|
|
6
|
+
var Tooltip = require('@mui/material/Tooltip');
|
|
7
|
+
var styles = require('@mui/material/styles');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var CookieOutlined__default = /*#__PURE__*/_interopDefault(CookieOutlined);
|
|
32
|
+
var Fab__default = /*#__PURE__*/_interopDefault(Fab);
|
|
33
|
+
var Tooltip__default = /*#__PURE__*/_interopDefault(Tooltip);
|
|
34
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
35
|
+
|
|
36
|
+
// react-lgpd-consent - Tree-shakeable ESM build
|
|
37
|
+
function useThemeWithFallbacks() {
|
|
38
|
+
const theme = styles.useTheme();
|
|
39
|
+
chunkORI4PLVG_cjs.logger.themeCompatibility(theme);
|
|
40
|
+
return {
|
|
41
|
+
palette: {
|
|
42
|
+
primary: {
|
|
43
|
+
main: theme?.palette?.primary?.main || "#1976d2",
|
|
44
|
+
dark: theme?.palette?.primary?.dark || "#1565c0"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
transitions: {
|
|
48
|
+
duration: {
|
|
49
|
+
shortest: theme?.transitions?.duration?.shortest || 150,
|
|
50
|
+
short: theme?.transitions?.duration?.short || 250
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var FloatingPreferencesButton = React__namespace.memo(function FloatingPreferencesButton2({
|
|
56
|
+
position = "bottom-right",
|
|
57
|
+
offset = 24,
|
|
58
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(CookieOutlined__default.default, {}),
|
|
59
|
+
tooltip,
|
|
60
|
+
FabProps,
|
|
61
|
+
hideWhenConsented = false
|
|
62
|
+
}) {
|
|
63
|
+
const { openPreferences, consented } = chunkORI4PLVG_cjs.useConsent();
|
|
64
|
+
const texts = chunkORI4PLVG_cjs.useConsentTexts();
|
|
65
|
+
const safeTheme = useThemeWithFallbacks();
|
|
66
|
+
const designTokens = chunkORI4PLVG_cjs.useDesignTokens();
|
|
67
|
+
const positionStyles = React__namespace.useMemo(() => {
|
|
68
|
+
const styles = {
|
|
69
|
+
position: "fixed",
|
|
70
|
+
zIndex: 1200
|
|
71
|
+
};
|
|
72
|
+
switch (position) {
|
|
73
|
+
case "bottom-left":
|
|
74
|
+
return { ...styles, bottom: offset, left: offset };
|
|
75
|
+
case "bottom-right":
|
|
76
|
+
return { ...styles, bottom: offset, right: offset };
|
|
77
|
+
case "top-left":
|
|
78
|
+
return { ...styles, top: offset, left: offset };
|
|
79
|
+
case "top-right":
|
|
80
|
+
return { ...styles, top: offset, right: offset };
|
|
81
|
+
default:
|
|
82
|
+
return { ...styles, bottom: offset, right: offset };
|
|
83
|
+
}
|
|
84
|
+
}, [position, offset]);
|
|
85
|
+
chunkORI4PLVG_cjs.logger.componentRender("FloatingPreferencesButton", {
|
|
86
|
+
position,
|
|
87
|
+
offset,
|
|
88
|
+
hideWhenConsented,
|
|
89
|
+
consented
|
|
90
|
+
});
|
|
91
|
+
if (hideWhenConsented && consented) {
|
|
92
|
+
chunkORI4PLVG_cjs.logger.debug(
|
|
93
|
+
"FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
|
|
94
|
+
);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
98
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tooltip__default.default, { title: tooltipText, placement: "top", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
99
|
+
Fab__default.default,
|
|
100
|
+
{
|
|
101
|
+
size: "medium",
|
|
102
|
+
color: "primary",
|
|
103
|
+
onClick: openPreferences,
|
|
104
|
+
sx: {
|
|
105
|
+
...positionStyles,
|
|
106
|
+
backgroundColor: designTokens?.colors?.primary ?? safeTheme.palette.primary.main,
|
|
107
|
+
"&:hover": {
|
|
108
|
+
backgroundColor: designTokens?.colors?.primary ? designTokens?.colors?.primary : safeTheme.palette.primary.dark
|
|
109
|
+
},
|
|
110
|
+
transition: `all ${safeTheme.transitions.duration.short}ms`
|
|
111
|
+
},
|
|
112
|
+
"aria-label": tooltipText,
|
|
113
|
+
...FabProps,
|
|
114
|
+
children: icon
|
|
115
|
+
}
|
|
116
|
+
) });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
exports.FloatingPreferencesButton = FloatingPreferencesButton;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { useConsent, useConsentTexts, useDesignTokens, useCategories, getCookiesInfoForCategory, Branding } from './chunk-RWT2ORFE.js';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import Button from '@mui/material/Button';
|
|
4
|
+
import Dialog from '@mui/material/Dialog';
|
|
5
|
+
import DialogActions from '@mui/material/DialogActions';
|
|
6
|
+
import DialogContent from '@mui/material/DialogContent';
|
|
7
|
+
import DialogTitle from '@mui/material/DialogTitle';
|
|
8
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
9
|
+
import FormGroup from '@mui/material/FormGroup';
|
|
10
|
+
import Switch from '@mui/material/Switch';
|
|
11
|
+
import Typography from '@mui/material/Typography';
|
|
12
|
+
import { useState, useEffect } from 'react';
|
|
13
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
// react-lgpd-consent - Tree-shakeable ESM build
|
|
16
|
+
function PreferencesModal({
|
|
17
|
+
DialogProps: DialogProps2,
|
|
18
|
+
hideBranding = false
|
|
19
|
+
}) {
|
|
20
|
+
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
21
|
+
const texts = useConsentTexts();
|
|
22
|
+
const designTokens = useDesignTokens();
|
|
23
|
+
const { toggleableCategories, allCategories } = useCategories();
|
|
24
|
+
const [tempPreferences, setTempPreferences] = useState(() => {
|
|
25
|
+
const initialPrefs = { necessary: true };
|
|
26
|
+
toggleableCategories.forEach((category) => {
|
|
27
|
+
initialPrefs[category.id] = preferences[category.id] ?? false;
|
|
28
|
+
});
|
|
29
|
+
return initialPrefs;
|
|
30
|
+
});
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (isModalOpen) {
|
|
33
|
+
const syncedPrefs = { necessary: true };
|
|
34
|
+
toggleableCategories.forEach((category) => {
|
|
35
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
36
|
+
});
|
|
37
|
+
setTempPreferences(syncedPrefs);
|
|
38
|
+
}
|
|
39
|
+
}, [isModalOpen, preferences, toggleableCategories]);
|
|
40
|
+
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
41
|
+
const handleSave = () => {
|
|
42
|
+
setPreferences(tempPreferences);
|
|
43
|
+
};
|
|
44
|
+
const handleCancel = () => {
|
|
45
|
+
setTempPreferences(preferences);
|
|
46
|
+
closePreferences();
|
|
47
|
+
};
|
|
48
|
+
const modalTitleSx = (theme) => ({
|
|
49
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
50
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
51
|
+
});
|
|
52
|
+
const modalContentSx = (theme) => ({
|
|
53
|
+
p: designTokens?.spacing?.padding?.modal ?? void 0,
|
|
54
|
+
backgroundColor: designTokens?.colors?.background ?? theme.palette.background.paper,
|
|
55
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
56
|
+
});
|
|
57
|
+
return /* @__PURE__ */ jsxs(Dialog, { "aria-labelledby": "cookie-pref-title", open, onClose: handleCancel, ...DialogProps2, children: [
|
|
58
|
+
/* @__PURE__ */ jsx(DialogTitle, { id: "cookie-pref-title", sx: modalTitleSx, children: texts.modalTitle }),
|
|
59
|
+
/* @__PURE__ */ jsxs(DialogContent, { dividers: true, sx: modalContentSx, children: [
|
|
60
|
+
/* @__PURE__ */ jsx(
|
|
61
|
+
Typography,
|
|
62
|
+
{
|
|
63
|
+
variant: "body2",
|
|
64
|
+
sx: (theme) => ({
|
|
65
|
+
mb: 2,
|
|
66
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
67
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
68
|
+
}),
|
|
69
|
+
children: texts.modalIntro
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
73
|
+
toggleableCategories.map((category) => {
|
|
74
|
+
const full = allCategories.find((c) => c.id === category.id);
|
|
75
|
+
const namesFromGuidance = full?.cookies ?? [];
|
|
76
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
77
|
+
const descriptors = getCookiesInfoForCategory(category.id, used);
|
|
78
|
+
const enrichedDescriptors = descriptors.map((desc) => {
|
|
79
|
+
if (desc.purpose && desc.duration && desc.provider) {
|
|
80
|
+
return desc;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
name: desc.name,
|
|
84
|
+
purpose: desc.purpose || "-",
|
|
85
|
+
duration: desc.duration || "-",
|
|
86
|
+
provider: desc.provider || "-"
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
const merged = [
|
|
90
|
+
...enrichedDescriptors,
|
|
91
|
+
...namesFromGuidance.filter((n) => !enrichedDescriptors.find((d) => d.name === n)).map((n) => ({ name: n, purpose: "-", duration: "-", provider: "-" }))
|
|
92
|
+
];
|
|
93
|
+
let mergedFinal = merged;
|
|
94
|
+
try {
|
|
95
|
+
if (merged.length === 0) {
|
|
96
|
+
const gmap = globalThis.__LGPD_INTEGRATIONS_MAP__ || {};
|
|
97
|
+
const scriptRows = Object.entries(gmap).filter(([, cat]) => cat === category.id).map(([id]) => ({
|
|
98
|
+
name: `(script) ${id}`,
|
|
99
|
+
purpose: "Script de integra\xE7\xE3o ativo",
|
|
100
|
+
duration: "-",
|
|
101
|
+
provider: "-"
|
|
102
|
+
}));
|
|
103
|
+
if (scriptRows.length > 0) mergedFinal = scriptRows;
|
|
104
|
+
}
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { mb: 1 }, children: [
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
FormControlLabel,
|
|
110
|
+
{
|
|
111
|
+
control: /* @__PURE__ */ jsx(
|
|
112
|
+
Switch,
|
|
113
|
+
{
|
|
114
|
+
checked: tempPreferences[category.id] ?? false,
|
|
115
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
116
|
+
...prev,
|
|
117
|
+
[category.id]: e.target.checked
|
|
118
|
+
}))
|
|
119
|
+
}
|
|
120
|
+
),
|
|
121
|
+
label: `${category.name} - ${category.description}`
|
|
122
|
+
}
|
|
123
|
+
),
|
|
124
|
+
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
125
|
+
/* @__PURE__ */ jsx("summary", { children: "Ver detalhes" }),
|
|
126
|
+
/* @__PURE__ */ jsx(Box, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
127
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
128
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
129
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
130
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
131
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
132
|
+
] }) }),
|
|
133
|
+
/* @__PURE__ */ jsx("tbody", { children: mergedFinal.map((d, idx) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
134
|
+
/* @__PURE__ */ jsx("td", { children: d.name }),
|
|
135
|
+
/* @__PURE__ */ jsx("td", { children: d.purpose }),
|
|
136
|
+
/* @__PURE__ */ jsx("td", { children: d.duration }),
|
|
137
|
+
/* @__PURE__ */ jsx("td", { children: d.provider })
|
|
138
|
+
] }, d.name + idx)) })
|
|
139
|
+
] }) })
|
|
140
|
+
] })
|
|
141
|
+
] }, category.id);
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ jsx(FormControlLabel, { control: /* @__PURE__ */ jsx(Switch, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn }),
|
|
144
|
+
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
145
|
+
/* @__PURE__ */ jsx("summary", { children: "Ver detalhes" }),
|
|
146
|
+
/* @__PURE__ */ jsx(Box, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
147
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
148
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
149
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
150
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
151
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
152
|
+
] }) }),
|
|
153
|
+
/* @__PURE__ */ jsx("tbody", { children: (() => {
|
|
154
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
155
|
+
const necessaryCookies = getCookiesInfoForCategory(
|
|
156
|
+
"necessary",
|
|
157
|
+
used
|
|
158
|
+
);
|
|
159
|
+
return necessaryCookies.map((d, idx) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
160
|
+
/* @__PURE__ */ jsx("td", { children: d.name }),
|
|
161
|
+
/* @__PURE__ */ jsx("td", { children: d.purpose || "-" }),
|
|
162
|
+
/* @__PURE__ */ jsx("td", { children: d.duration || "-" }),
|
|
163
|
+
/* @__PURE__ */ jsx("td", { children: d.provider || "-" })
|
|
164
|
+
] }, d.name + idx));
|
|
165
|
+
})() })
|
|
166
|
+
] }) })
|
|
167
|
+
] })
|
|
168
|
+
] })
|
|
169
|
+
] }),
|
|
170
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [
|
|
171
|
+
/* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
172
|
+
/* @__PURE__ */ jsx(Button, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
173
|
+
] }),
|
|
174
|
+
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "modal" })
|
|
175
|
+
] });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { PreferencesModal };
|