@dargmuesli/nuxt-cookie-control 5.0.0-beta.4 → 5.0.0-beta.6
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 +3 -2
- package/dist/module.d.ts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -3
- package/dist/runtime/components/CookieControl.vue +40 -25
- package/dist/runtime/methods.d.ts +2 -1
- package/dist/runtime/methods.mjs +4 -0
- package/dist/runtime/plugin.mjs +3 -3
- package/dist/runtime/types.d.ts +1 -0
- package/dist/runtime/types.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -141,8 +141,8 @@ cookies: {
|
|
|
141
141
|
cookieExpiryOffsetMs: 1000 * 60 * 60 * 24 * 365, // one year
|
|
142
142
|
|
|
143
143
|
// Names for the cookies that are being set by this module.
|
|
144
|
-
cookieNameIsConsentGiven: '
|
|
145
|
-
cookieNameCookiesEnabledIds: '
|
|
144
|
+
cookieNameIsConsentGiven: 'ncc_c',
|
|
145
|
+
cookieNameCookiesEnabledIds: 'ncc_e',
|
|
146
146
|
|
|
147
147
|
// Switch to toggle the "accept necessary" button.
|
|
148
148
|
isAcceptNecessaryButtonEnabled: true
|
|
@@ -196,6 +196,7 @@ Every property the includes a `{ en: ... }` value is a translatable property tha
|
|
|
196
196
|
en: 'Used for cookie control.'
|
|
197
197
|
},
|
|
198
198
|
id: 'ga', // if unset, `getCookieId(cookie)` returns the cookie's slugified name instead, which e.g. is used to fill the state's `enabledCookieIds` list
|
|
199
|
+
// use a short cookie id to save bandwidth!
|
|
199
200
|
name: {
|
|
200
201
|
en: 'Google Analytics' // you always have to specify a cookie name (in English)
|
|
201
202
|
},
|
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { resolve } from 'node:path';
|
|
|
2
2
|
import { createResolver, defineNuxtModule, addPlugin, addImports, addTemplate, extendWebpackConfig, resolvePath } from '@nuxt/kit';
|
|
3
3
|
|
|
4
4
|
const name = "@dargmuesli/nuxt-cookie-control";
|
|
5
|
-
const version = "5.0.0-beta.
|
|
5
|
+
const version = "5.0.0-beta.6";
|
|
6
6
|
|
|
7
7
|
const en = {
|
|
8
8
|
accept: "Accept",
|
|
@@ -58,8 +58,8 @@ const DEFAULTS = {
|
|
|
58
58
|
},
|
|
59
59
|
cookieExpiryOffsetMs: 1e3 * 60 * 60 * 24 * 365,
|
|
60
60
|
// one year
|
|
61
|
-
cookieNameIsConsentGiven: "
|
|
62
|
-
cookieNameCookiesEnabledIds: "
|
|
61
|
+
cookieNameIsConsentGiven: "ncc_c",
|
|
62
|
+
cookieNameCookiesEnabledIds: "ncc_e",
|
|
63
63
|
isAcceptNecessaryButtonEnabled: true,
|
|
64
64
|
isControlButtonEnabled: true,
|
|
65
65
|
isCookieIdVisible: false,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<section class="cookieControl">
|
|
4
4
|
<transition :name="`cookieControl__Bar--${moduleOptions.barPosition}`">
|
|
5
5
|
<div
|
|
6
|
-
v-if="isConsentGiven
|
|
6
|
+
v-if="!isConsentGiven"
|
|
7
7
|
:class="`cookieControl__Bar cookieControl__Bar--${moduleOptions.barPosition}`"
|
|
8
8
|
>
|
|
9
9
|
<div class="cookieControl__BarContainer">
|
|
@@ -29,9 +29,7 @@
|
|
|
29
29
|
</div>
|
|
30
30
|
</transition>
|
|
31
31
|
<button
|
|
32
|
-
v-if="
|
|
33
|
-
moduleOptions.isControlButtonEnabled && isConsentGiven !== undefined
|
|
34
|
-
"
|
|
32
|
+
v-if="moduleOptions.isControlButtonEnabled && isConsentGiven"
|
|
35
33
|
aria-label="Cookie control"
|
|
36
34
|
class="cookieControl__ControlButton"
|
|
37
35
|
data-testid="nuxt-cookie-control-control-button"
|
|
@@ -95,14 +93,14 @@
|
|
|
95
93
|
) ||
|
|
96
94
|
(getCookie(
|
|
97
95
|
moduleOptions.cookieNameIsConsentGiven
|
|
98
|
-
) !==
|
|
96
|
+
) !== allCookieIdsString &&
|
|
99
97
|
typeof moduleOptions.isIframeBlocked ===
|
|
100
98
|
'object' &&
|
|
101
99
|
moduleOptions.isIframeBlocked.initialState)
|
|
102
100
|
"
|
|
103
101
|
@change="toogleCookie(cookie)"
|
|
104
102
|
/>
|
|
105
|
-
<button @
|
|
103
|
+
<button @click="toggleButton($event)">
|
|
106
104
|
{{ getName(cookie.name) }}
|
|
107
105
|
</button>
|
|
108
106
|
<label
|
|
@@ -121,13 +119,27 @@
|
|
|
121
119
|
cookie.targetCookieIds
|
|
122
120
|
"
|
|
123
121
|
>
|
|
122
|
+
<br />
|
|
124
123
|
{{
|
|
125
|
-
'
|
|
124
|
+
'IDs: ' +
|
|
126
125
|
cookie.targetCookieIds
|
|
127
126
|
.map((id: string) => `"${id}"`)
|
|
128
127
|
.join(', ')
|
|
129
128
|
}}
|
|
130
129
|
</span>
|
|
130
|
+
<template
|
|
131
|
+
v-if="Object.entries(cookie.links || {}).length"
|
|
132
|
+
>
|
|
133
|
+
<span
|
|
134
|
+
v-for="entry in Object.entries(
|
|
135
|
+
cookie.links || {}
|
|
136
|
+
)"
|
|
137
|
+
:key="entry[0]"
|
|
138
|
+
>
|
|
139
|
+
<br />
|
|
140
|
+
<a :href="entry[0]">{{ entry[1] || entry[0] }}</a>
|
|
141
|
+
</span>
|
|
142
|
+
</template>
|
|
131
143
|
</label>
|
|
132
144
|
</div>
|
|
133
145
|
</li>
|
|
@@ -176,6 +188,7 @@ import { ref, computed, onBeforeMount, watch } from 'vue'
|
|
|
176
188
|
|
|
177
189
|
import { Cookie, CookieType, Locale, Translatable } from '../types'
|
|
178
190
|
import {
|
|
191
|
+
getAllCookieIdsString,
|
|
179
192
|
getCookie,
|
|
180
193
|
getCookieId,
|
|
181
194
|
getCookieIds,
|
|
@@ -204,13 +217,14 @@ const {
|
|
|
204
217
|
// data
|
|
205
218
|
const expires = new Date()
|
|
206
219
|
const localCookiesEnabled = ref([...(cookiesEnabled.value || [])])
|
|
220
|
+
const allCookieIdsString = getAllCookieIdsString(moduleOptions)
|
|
207
221
|
|
|
208
222
|
// computations
|
|
209
223
|
const isSaved = computed(
|
|
210
224
|
() =>
|
|
211
225
|
getCookieIds(cookiesEnabled.value || [])
|
|
212
226
|
.sort()
|
|
213
|
-
.join('
|
|
227
|
+
.join('|') !== getCookieIds(localCookiesEnabled.value).sort().join('|')
|
|
214
228
|
)
|
|
215
229
|
const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
|
|
216
230
|
|
|
@@ -287,19 +301,14 @@ const setCookies = ({
|
|
|
287
301
|
? getCookieIds(cookiesEnabled.value)
|
|
288
302
|
: []
|
|
289
303
|
}
|
|
290
|
-
const toggleButton = ($event:
|
|
291
|
-
|
|
292
|
-
(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
)?.click()
|
|
304
|
+
const toggleButton = ($event: MouseEvent) => {
|
|
305
|
+
;(
|
|
306
|
+
($event.target as HTMLButtonElement | null)
|
|
307
|
+
?.nextSibling as HTMLLabelElement | null
|
|
308
|
+
)?.click()
|
|
296
309
|
}
|
|
297
|
-
const toggleLabel = ($event: KeyboardEvent
|
|
298
|
-
if ($event
|
|
299
|
-
if ($event.key === ' ') ($event.target as HTMLLabelElement | null)?.click()
|
|
300
|
-
} else {
|
|
301
|
-
;($event.target as HTMLLabelElement | null)?.click()
|
|
302
|
-
}
|
|
310
|
+
const toggleLabel = ($event: KeyboardEvent) => {
|
|
311
|
+
if ($event.key === ' ') ($event.target as HTMLLabelElement | null)?.click()
|
|
303
312
|
}
|
|
304
313
|
|
|
305
314
|
// lifecycle
|
|
@@ -325,7 +334,9 @@ onBeforeMount(async () => {
|
|
|
325
334
|
}
|
|
326
335
|
}
|
|
327
336
|
|
|
328
|
-
if (
|
|
337
|
+
if (
|
|
338
|
+
getCookie(moduleOptions.cookieNameIsConsentGiven) === allCookieIdsString
|
|
339
|
+
) {
|
|
329
340
|
for (const cookieOptional of moduleOptions.cookies.optional) {
|
|
330
341
|
if (
|
|
331
342
|
typeof moduleOptions.isIframeBlocked === 'boolean'
|
|
@@ -345,7 +356,7 @@ watch(
|
|
|
345
356
|
if (isConsentGiven.value) {
|
|
346
357
|
setCookie(
|
|
347
358
|
moduleOptions.cookieNameCookiesEnabledIds,
|
|
348
|
-
getCookieIds(current || []).join('
|
|
359
|
+
getCookieIds(current || []).join('|'),
|
|
349
360
|
{
|
|
350
361
|
expires,
|
|
351
362
|
}
|
|
@@ -391,9 +402,13 @@ watch(isConsentGiven, (current, _previous) => {
|
|
|
391
402
|
if (current === undefined) {
|
|
392
403
|
removeCookie(moduleOptions.cookieNameIsConsentGiven)
|
|
393
404
|
} else {
|
|
394
|
-
setCookie(
|
|
395
|
-
|
|
396
|
-
|
|
405
|
+
setCookie(
|
|
406
|
+
moduleOptions.cookieNameIsConsentGiven,
|
|
407
|
+
current ? allCookieIdsString : '0',
|
|
408
|
+
{
|
|
409
|
+
expires,
|
|
410
|
+
}
|
|
411
|
+
)
|
|
397
412
|
}
|
|
398
413
|
})
|
|
399
414
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Cookie, Translatable } from './types';
|
|
1
|
+
import { Cookie, ModuleOptions, Translatable } from './types';
|
|
2
|
+
export declare const getAllCookieIdsString: (moduleOptions: ModuleOptions) => string;
|
|
2
3
|
export declare const getCookie: (name: string) => any;
|
|
3
4
|
export declare const getCookieId: (cookie: Cookie) => string;
|
|
4
5
|
export declare const getCookieIds: (cookies: Cookie[]) => string[];
|
package/dist/runtime/methods.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import Cookies from "js-cookie";
|
|
2
2
|
import slugify from "@sindresorhus/slugify";
|
|
3
3
|
import { LOCALE_DEFAULT } from "./constants.mjs";
|
|
4
|
+
export const getAllCookieIdsString = (moduleOptions) => getCookieIds([
|
|
5
|
+
...moduleOptions.cookies.necessary,
|
|
6
|
+
...moduleOptions.cookies.optional
|
|
7
|
+
]).join("");
|
|
4
8
|
export const getCookie = (name) => Cookies.get(name);
|
|
5
9
|
export const getCookieId = (cookie) => cookie.id || slugify(resolveTranslatable(cookie.name));
|
|
6
10
|
export const getCookieIds = (cookies) => cookies.map((cookie) => getCookieId(cookie));
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Cookies from "js-cookie";
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
-
import { getCookieId } from "./methods.mjs";
|
|
3
|
+
import { getAllCookieIdsString, getCookieId } from "./methods.mjs";
|
|
4
4
|
import { defineNuxtPlugin } from "#imports";
|
|
5
5
|
import moduleOptions from "#build/cookie-control-options";
|
|
6
6
|
export default defineNuxtPlugin((_nuxtApp) => {
|
|
@@ -9,9 +9,9 @@ export default defineNuxtPlugin((_nuxtApp) => {
|
|
|
9
9
|
);
|
|
10
10
|
const cookieCookiesEnabledIds = Cookies.get(
|
|
11
11
|
moduleOptions.cookieNameCookiesEnabledIds
|
|
12
|
-
)?.split("
|
|
12
|
+
)?.split("|");
|
|
13
13
|
const isConsentGiven = ref(
|
|
14
|
-
cookieIsConsentGiven === void 0 ? void 0 : cookieIsConsentGiven ===
|
|
14
|
+
cookieIsConsentGiven === void 0 ? void 0 : cookieIsConsentGiven === getAllCookieIdsString(moduleOptions)
|
|
15
15
|
);
|
|
16
16
|
const cookiesEnabled = ref(
|
|
17
17
|
cookieCookiesEnabledIds === void 0 ? void 0 : [
|
package/dist/runtime/types.d.ts
CHANGED
package/dist/runtime/types.mjs
CHANGED
|
@@ -40,8 +40,8 @@ export const DEFAULTS = {
|
|
|
40
40
|
},
|
|
41
41
|
cookieExpiryOffsetMs: 1e3 * 60 * 60 * 24 * 365,
|
|
42
42
|
// one year
|
|
43
|
-
cookieNameIsConsentGiven: "
|
|
44
|
-
cookieNameCookiesEnabledIds: "
|
|
43
|
+
cookieNameIsConsentGiven: "ncc_c",
|
|
44
|
+
cookieNameCookiesEnabledIds: "ncc_e",
|
|
45
45
|
isAcceptNecessaryButtonEnabled: true,
|
|
46
46
|
isControlButtonEnabled: true,
|
|
47
47
|
isCookieIdVisible: false,
|