react-lgpd-consent 0.4.3 → 0.5.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.
@@ -1,178 +0,0 @@
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 };