@el7ven/cookie-kit 0.3.2 → 0.3.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/package.json +1 -1
- package/src/core/index.js +8 -7
- package/src/vue/CookieConsent.vue +4 -12
package/package.json
CHANGED
package/src/core/index.js
CHANGED
|
@@ -225,8 +225,9 @@ export class CookieKitCore {
|
|
|
225
225
|
const next = {}
|
|
226
226
|
Object.keys(this.config.categories).forEach(id => {
|
|
227
227
|
const category = this.config.categories[id]
|
|
228
|
-
if (category?.enabled
|
|
229
|
-
|
|
228
|
+
if (category?.enabled === true) {
|
|
229
|
+
// For enabled categories, set to required status OR false if not required
|
|
230
|
+
next[id] = category.required === true
|
|
230
231
|
}
|
|
231
232
|
})
|
|
232
233
|
return next
|
|
@@ -239,7 +240,7 @@ export class CookieKitCore {
|
|
|
239
240
|
const normalized = this.getDefaultCategoriesState()
|
|
240
241
|
Object.keys(categories || {}).forEach(id => {
|
|
241
242
|
if (Object.prototype.hasOwnProperty.call(normalized, id)) {
|
|
242
|
-
normalized[id] = !!categories[id] ||
|
|
243
|
+
normalized[id] = !!categories[id] || this.config.categories[id]?.required === true
|
|
243
244
|
}
|
|
244
245
|
})
|
|
245
246
|
|
|
@@ -270,7 +271,7 @@ export class CookieKitCore {
|
|
|
270
271
|
acceptAll(source = 'banner') {
|
|
271
272
|
const categories = {}
|
|
272
273
|
Object.keys(this.config.categories).forEach(id => {
|
|
273
|
-
if (this.config.categories[id]?.enabled
|
|
274
|
+
if (this.config.categories[id]?.enabled === true) {
|
|
274
275
|
categories[id] = true
|
|
275
276
|
}
|
|
276
277
|
})
|
|
@@ -281,7 +282,7 @@ export class CookieKitCore {
|
|
|
281
282
|
const categories = {}
|
|
282
283
|
Object.keys(this.config.categories).forEach(id => {
|
|
283
284
|
const category = this.config.categories[id]
|
|
284
|
-
if (category?.enabled
|
|
285
|
+
if (category?.enabled === true) {
|
|
285
286
|
categories[id] = !!category.required
|
|
286
287
|
}
|
|
287
288
|
})
|
|
@@ -293,8 +294,8 @@ export class CookieKitCore {
|
|
|
293
294
|
const categories = {}
|
|
294
295
|
Object.keys(this.config.categories).forEach(id => {
|
|
295
296
|
const category = this.config.categories[id]
|
|
296
|
-
if (category?.enabled
|
|
297
|
-
categories[id] = selectedSet.has(id) ||
|
|
297
|
+
if (category?.enabled === true) {
|
|
298
|
+
categories[id] = selectedSet.has(id) || category.required === true
|
|
298
299
|
}
|
|
299
300
|
})
|
|
300
301
|
return this.saveConsent(categories, source)
|
|
@@ -42,7 +42,7 @@ const mergedConfig = computed(() => deepMerge(DEFAULT_CONFIG, props.config))
|
|
|
42
42
|
const {
|
|
43
43
|
core,
|
|
44
44
|
consent,
|
|
45
|
-
categories
|
|
45
|
+
categories,
|
|
46
46
|
acceptAll,
|
|
47
47
|
rejectAll,
|
|
48
48
|
acceptSelected,
|
|
@@ -57,9 +57,6 @@ const isSettingsMode = ref(false)
|
|
|
57
57
|
const currentTab = ref('privacy')
|
|
58
58
|
const drawerRef = ref(null)
|
|
59
59
|
|
|
60
|
-
// Category state (reactive, for toggles)
|
|
61
|
-
const categories = ref(buildCategoryState(mergedConfig.value.categories))
|
|
62
|
-
|
|
63
60
|
// Computed
|
|
64
61
|
const consentVersion = computed(() => mergedConfig.value.version || 'v2')
|
|
65
62
|
const capabilities = computed(() => mergedConfig.value.capabilities || {})
|
|
@@ -207,7 +204,9 @@ const handleSelectTab = (tabId) => {
|
|
|
207
204
|
const handleToggleCategory = (categoryId) => {
|
|
208
205
|
const cat = mergedConfig.value.categories[categoryId]
|
|
209
206
|
if (cat && !cat.disabled && !cat.required) {
|
|
210
|
-
|
|
207
|
+
// Toggle the category state
|
|
208
|
+
const current = categories.value[categoryId]
|
|
209
|
+
categories.value[categoryId] = !current
|
|
211
210
|
}
|
|
212
211
|
}
|
|
213
212
|
|
|
@@ -245,13 +244,6 @@ defineExpose({
|
|
|
245
244
|
})
|
|
246
245
|
|
|
247
246
|
// Helpers
|
|
248
|
-
function buildCategoryState(cats) {
|
|
249
|
-
if (!cats) return {}
|
|
250
|
-
return Object.fromEntries(
|
|
251
|
-
Object.keys(cats).map(id => [id, !!cats[id].enabled])
|
|
252
|
-
)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
247
|
function deepMerge(target, source) {
|
|
256
248
|
const result = { ...target }
|
|
257
249
|
for (const key of Object.keys(source)) {
|