@dargmuesli/nuxt-cookie-control 5.0.0-beta.3 → 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 CHANGED
@@ -118,6 +118,7 @@ colors: {
118
118
  controlButtonHoverBackground: '#000',
119
119
  controlButtonIconColor: '#000',
120
120
  controlButtonIconHoverColor: '#fff',
121
+ focusRingColor: '#808080',
121
122
  modalBackground: '#fff',
122
123
  modalButtonBackground: '#000',
123
124
  modalButtonColor: '#fff',
@@ -140,8 +141,8 @@ cookies: {
140
141
  cookieExpiryOffsetMs: 1000 * 60 * 60 * 24 * 365, // one year
141
142
 
142
143
  // Names for the cookies that are being set by this module.
143
- cookieNameIsConsentGiven: 'cookie_control_is_consent_given',
144
- cookieNameCookiesEnabledIds: 'cookie_control_cookies_enabled_ids',
144
+ cookieNameIsConsentGiven: 'ncc_c',
145
+ cookieNameCookiesEnabledIds: 'ncc_e',
145
146
 
146
147
  // Switch to toggle the "accept necessary" button.
147
148
  isAcceptNecessaryButtonEnabled: true
@@ -195,6 +196,7 @@ Every property the includes a `{ en: ... }` value is a translatable property tha
195
196
  en: 'Used for cookie control.'
196
197
  },
197
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!
198
200
  name: {
199
201
  en: 'Google Analytics' // you always have to specify a cookie name (in English)
200
202
  },
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.5",
4
4
  "configKey": "cookieControl",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0"
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.3";
5
+ const version = "5.0.0-beta.5";
6
6
 
7
7
  const en = {
8
8
  accept: "Accept",
@@ -41,6 +41,7 @@ const DEFAULTS = {
41
41
  controlButtonHoverBackground: "#000",
42
42
  controlButtonIconColor: "#000",
43
43
  controlButtonIconHoverColor: "#fff",
44
+ focusRingColor: "#808080",
44
45
  modalBackground: "#fff",
45
46
  modalButtonBackground: "#000",
46
47
  modalButtonColor: "#fff",
@@ -57,8 +58,8 @@ const DEFAULTS = {
57
58
  },
58
59
  cookieExpiryOffsetMs: 1e3 * 60 * 60 * 24 * 365,
59
60
  // one year
60
- cookieNameIsConsentGiven: "cookie_control_is_consent_given",
61
- cookieNameCookiesEnabledIds: "cookie_control_cookies_enabled_ids",
61
+ cookieNameIsConsentGiven: "ncc_c",
62
+ cookieNameCookiesEnabledIds: "ncc_e",
62
63
  isAcceptNecessaryButtonEnabled: true,
63
64
  isControlButtonEnabled: true,
64
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 === undefined"
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,20 +93,23 @@
95
93
  ) ||
96
94
  (getCookie(
97
95
  moduleOptions.cookieNameIsConsentGiven
98
- ) !== 'true' &&
96
+ ) !== allCookieIdsString &&
99
97
  typeof moduleOptions.isIframeBlocked ===
100
98
  'object' &&
101
99
  moduleOptions.isIframeBlocked.initialState)
102
100
  "
103
101
  @change="toogleCookie(cookie)"
104
102
  />
103
+ <button @click="toggleButton($event)">
104
+ {{ getName(cookie.name) }}
105
+ </button>
105
106
  <label
107
+ class="cookieControl__ModalCookieName"
106
108
  :for="resolveTranslatable(cookie.name, props.locale)"
109
+ tabindex="0"
110
+ @keydown="toggleLabel($event)"
107
111
  >
108
112
  {{ getName(cookie.name) }}
109
- </label>
110
- <span class="cookieControl__ModalCookieName">
111
- {{ getName(cookie.name) }}
112
113
  <span v-if="cookie.description">
113
114
  {{ getDescription(cookie.description) }}
114
115
  </span>
@@ -125,7 +126,7 @@
125
126
  .join(', ')
126
127
  }}
127
128
  </span>
128
- </span>
129
+ </label>
129
130
  </div>
130
131
  </li>
131
132
  </ul>
@@ -173,6 +174,7 @@ import { ref, computed, onBeforeMount, watch } from 'vue'
173
174
 
174
175
  import { Cookie, CookieType, Locale, Translatable } from '../types'
175
176
  import {
177
+ getAllCookieIdsString,
176
178
  getCookie,
177
179
  getCookieId,
178
180
  getCookieIds,
@@ -201,13 +203,14 @@ const {
201
203
  // data
202
204
  const expires = new Date()
203
205
  const localCookiesEnabled = ref([...(cookiesEnabled.value || [])])
206
+ const allCookieIdsString = getAllCookieIdsString(moduleOptions)
204
207
 
205
208
  // computations
206
209
  const isSaved = computed(
207
210
  () =>
208
211
  getCookieIds(cookiesEnabled.value || [])
209
212
  .sort()
210
- .join(',') !== getCookieIds(localCookiesEnabled.value).sort().join(',')
213
+ .join('|') !== getCookieIds(localCookiesEnabled.value).sort().join('|')
211
214
  )
212
215
  const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
213
216
 
@@ -284,6 +287,15 @@ const setCookies = ({
284
287
  ? getCookieIds(cookiesEnabled.value)
285
288
  : []
286
289
  }
290
+ const toggleButton = ($event: MouseEvent) => {
291
+ ;(
292
+ ($event.target as HTMLButtonElement | null)
293
+ ?.nextSibling as HTMLLabelElement | null
294
+ )?.click()
295
+ }
296
+ const toggleLabel = ($event: KeyboardEvent) => {
297
+ if ($event.key === ' ') ($event.target as HTMLLabelElement | null)?.click()
298
+ }
287
299
 
288
300
  // lifecycle
289
301
  onBeforeMount(async () => {
@@ -308,7 +320,9 @@ onBeforeMount(async () => {
308
320
  }
309
321
  }
310
322
 
311
- if (getCookie(moduleOptions.cookieNameIsConsentGiven) === 'true') {
323
+ if (
324
+ getCookie(moduleOptions.cookieNameIsConsentGiven) === allCookieIdsString
325
+ ) {
312
326
  for (const cookieOptional of moduleOptions.cookies.optional) {
313
327
  if (
314
328
  typeof moduleOptions.isIframeBlocked === 'boolean'
@@ -328,7 +342,7 @@ watch(
328
342
  if (isConsentGiven.value) {
329
343
  setCookie(
330
344
  moduleOptions.cookieNameCookiesEnabledIds,
331
- getCookieIds(current || []).join(','),
345
+ getCookieIds(current || []).join('|'),
332
346
  {
333
347
  expires,
334
348
  }
@@ -374,9 +388,13 @@ watch(isConsentGiven, (current, _previous) => {
374
388
  if (current === undefined) {
375
389
  removeCookie(moduleOptions.cookieNameIsConsentGiven)
376
390
  } else {
377
- setCookie(moduleOptions.cookieNameIsConsentGiven, current.toString(), {
378
- expires,
379
- })
391
+ setCookie(
392
+ moduleOptions.cookieNameIsConsentGiven,
393
+ current ? allCookieIdsString : '0',
394
+ {
395
+ expires,
396
+ }
397
+ )
380
398
  }
381
399
  })
382
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[];
@@ -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));
@@ -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 === "true"
14
+ cookieIsConsentGiven === void 0 ? void 0 : cookieIsConsentGiven === getAllCookieIdsString(moduleOptions)
15
15
  );
16
16
  const cookiesEnabled = ref(
17
17
  cookieCookiesEnabledIds === void 0 ? void 0 : [
@@ -86,6 +86,9 @@
86
86
  color: var(--cookie-control-barButtonHoverColor);
87
87
  background-color: var(--cookie-control-barButtonHoverBackground);
88
88
  }
89
+ .cookieControl__Bar button:focus{
90
+ box-shadow: 0 0 0 3px var(--cookie-control-focusRingColor);
91
+ }
89
92
  .cookieControl__Bar button + button {
90
93
  margin-left: 10px;
91
94
  }
@@ -184,6 +187,9 @@
184
187
  color: var(--cookie-control-modalButtonHoverColor);
185
188
  background-color: var(--cookie-control-modalButtonHoverBackground);
186
189
  }
190
+ .cookieControl__Modal button:focus {
191
+ box-shadow: 0 0 0 3px var(--cookie-control-focusRingColor);
192
+ }
187
193
  .cookieControl__ModalContent {
188
194
  position: relative;
189
195
  width: 100%;
@@ -227,20 +233,20 @@
227
233
  .cookieControl__ModalContent input {
228
234
  display: none;
229
235
  }
230
- .cookieControl__ModalContent input:checked + label {
236
+ .cookieControl__ModalContent input:checked + button {
231
237
  background-color: var(--cookie-control-checkboxActiveBackground);
232
238
  }
233
- .cookieControl__ModalContent input:checked + label:before {
239
+ .cookieControl__ModalContent input:checked + button:before {
234
240
  background-color: var(--cookie-control-checkboxActiveCircleBackground);
235
241
  transform: translate3d(100%, -50%, 0);
236
242
  }
237
- .cookieControl__ModalContent input:checked:disabled + label {
243
+ .cookieControl__ModalContent input:checked:disabled + button {
238
244
  background-color: var(--cookie-control-checkboxDisabledBackground);
239
245
  }
240
- .cookieControl__ModalContent input:checked:disabled + label:before {
246
+ .cookieControl__ModalContent input:checked:disabled + button:before {
241
247
  background-color: var(--cookie-control-checkboxDisabledCircleBackground);
242
248
  }
243
- .cookieControl__ModalContent label {
249
+ .cookieControl__ModalContent input + button {
244
250
  position: relative;
245
251
  min-width: 36px;
246
252
  min-height: 20px;
@@ -252,7 +258,7 @@
252
258
  transition: background-color 200ms;
253
259
  background-color: var(--cookie-control-checkboxInactiveBackground);
254
260
  }
255
- .cookieControl__ModalContent label:before {
261
+ .cookieControl__ModalContent input + button:before {
256
262
  position: absolute;
257
263
  content: '';
258
264
  top: 50%;
@@ -23,6 +23,7 @@ export const DEFAULTS = {
23
23
  controlButtonHoverBackground: "#000",
24
24
  controlButtonIconColor: "#000",
25
25
  controlButtonIconHoverColor: "#fff",
26
+ focusRingColor: "#808080",
26
27
  modalBackground: "#fff",
27
28
  modalButtonBackground: "#000",
28
29
  modalButtonColor: "#fff",
@@ -39,8 +40,8 @@ export const DEFAULTS = {
39
40
  },
40
41
  cookieExpiryOffsetMs: 1e3 * 60 * 60 * 24 * 365,
41
42
  // one year
42
- cookieNameIsConsentGiven: "cookie_control_is_consent_given",
43
- cookieNameCookiesEnabledIds: "cookie_control_cookies_enabled_ids",
43
+ cookieNameIsConsentGiven: "ncc_c",
44
+ cookieNameCookiesEnabledIds: "ncc_e",
44
45
  isAcceptNecessaryButtonEnabled: true,
45
46
  isControlButtonEnabled: true,
46
47
  isCookieIdVisible: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.5",
4
4
  "description": "Nuxt Cookies Control Module",
5
5
  "author": "Dario Ferderber <dario.ferderber@broj42.com>",
6
6
  "maintainers": [