@dargmuesli/nuxt-cookie-control 5.0.0-beta.4 → 5.0.0-beta.5
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.json +1 -1
- package/dist/module.mjs +3 -3
- package/dist/runtime/components/CookieControl.vue +25 -24
- 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.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.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.5";
|
|
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
|
|
@@ -176,6 +174,7 @@ import { ref, computed, onBeforeMount, watch } from 'vue'
|
|
|
176
174
|
|
|
177
175
|
import { Cookie, CookieType, Locale, Translatable } from '../types'
|
|
178
176
|
import {
|
|
177
|
+
getAllCookieIdsString,
|
|
179
178
|
getCookie,
|
|
180
179
|
getCookieId,
|
|
181
180
|
getCookieIds,
|
|
@@ -204,13 +203,14 @@ const {
|
|
|
204
203
|
// data
|
|
205
204
|
const expires = new Date()
|
|
206
205
|
const localCookiesEnabled = ref([...(cookiesEnabled.value || [])])
|
|
206
|
+
const allCookieIdsString = getAllCookieIdsString(moduleOptions)
|
|
207
207
|
|
|
208
208
|
// computations
|
|
209
209
|
const isSaved = computed(
|
|
210
210
|
() =>
|
|
211
211
|
getCookieIds(cookiesEnabled.value || [])
|
|
212
212
|
.sort()
|
|
213
|
-
.join('
|
|
213
|
+
.join('|') !== getCookieIds(localCookiesEnabled.value).sort().join('|')
|
|
214
214
|
)
|
|
215
215
|
const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
|
|
216
216
|
|
|
@@ -287,19 +287,14 @@ const setCookies = ({
|
|
|
287
287
|
? getCookieIds(cookiesEnabled.value)
|
|
288
288
|
: []
|
|
289
289
|
}
|
|
290
|
-
const toggleButton = ($event:
|
|
291
|
-
|
|
292
|
-
(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
)?.click()
|
|
290
|
+
const toggleButton = ($event: MouseEvent) => {
|
|
291
|
+
;(
|
|
292
|
+
($event.target as HTMLButtonElement | null)
|
|
293
|
+
?.nextSibling as HTMLLabelElement | null
|
|
294
|
+
)?.click()
|
|
296
295
|
}
|
|
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
|
-
}
|
|
296
|
+
const toggleLabel = ($event: KeyboardEvent) => {
|
|
297
|
+
if ($event.key === ' ') ($event.target as HTMLLabelElement | null)?.click()
|
|
303
298
|
}
|
|
304
299
|
|
|
305
300
|
// lifecycle
|
|
@@ -325,7 +320,9 @@ onBeforeMount(async () => {
|
|
|
325
320
|
}
|
|
326
321
|
}
|
|
327
322
|
|
|
328
|
-
if (
|
|
323
|
+
if (
|
|
324
|
+
getCookie(moduleOptions.cookieNameIsConsentGiven) === allCookieIdsString
|
|
325
|
+
) {
|
|
329
326
|
for (const cookieOptional of moduleOptions.cookies.optional) {
|
|
330
327
|
if (
|
|
331
328
|
typeof moduleOptions.isIframeBlocked === 'boolean'
|
|
@@ -345,7 +342,7 @@ watch(
|
|
|
345
342
|
if (isConsentGiven.value) {
|
|
346
343
|
setCookie(
|
|
347
344
|
moduleOptions.cookieNameCookiesEnabledIds,
|
|
348
|
-
getCookieIds(current || []).join('
|
|
345
|
+
getCookieIds(current || []).join('|'),
|
|
349
346
|
{
|
|
350
347
|
expires,
|
|
351
348
|
}
|
|
@@ -391,9 +388,13 @@ watch(isConsentGiven, (current, _previous) => {
|
|
|
391
388
|
if (current === undefined) {
|
|
392
389
|
removeCookie(moduleOptions.cookieNameIsConsentGiven)
|
|
393
390
|
} else {
|
|
394
|
-
setCookie(
|
|
395
|
-
|
|
396
|
-
|
|
391
|
+
setCookie(
|
|
392
|
+
moduleOptions.cookieNameIsConsentGiven,
|
|
393
|
+
current ? allCookieIdsString : '0',
|
|
394
|
+
{
|
|
395
|
+
expires,
|
|
396
|
+
}
|
|
397
|
+
)
|
|
397
398
|
}
|
|
398
399
|
})
|
|
399
400
|
|
|
@@ -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.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,
|