@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 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: 'cookie_control_is_consent_given',
145
- cookieNameCookiesEnabledIds: 'cookie_control_cookies_enabled_ids',
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
@@ -7,6 +7,7 @@ interface Cookie {
7
7
  description?: Translatable;
8
8
  id?: string;
9
9
  name: Translatable;
10
+ links?: Record<string, string | null>;
10
11
  src?: string;
11
12
  targetCookieIds?: string[];
12
13
  }
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.6",
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.4";
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: "cookie_control_is_consent_given",
62
- cookieNameCookiesEnabledIds: "cookie_control_cookies_enabled_ids",
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 === 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,14 +93,14 @@
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
  />
105
- <button @keydown="toggleButton($event)">
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
- ' IDs: ' +
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(',') !== getCookieIds(localCookiesEnabled.value).sort().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: KeyboardEvent) => {
291
- if ($event.key === ' ')
292
- (
293
- ($event.target as HTMLButtonElement | null)
294
- ?.nextSibling as HTMLLabelElement | null
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 | MouseEvent) => {
298
- if ($event instanceof KeyboardEvent) {
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 (getCookie(moduleOptions.cookieNameIsConsentGiven) === 'true') {
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(moduleOptions.cookieNameIsConsentGiven, current.toString(), {
395
- expires,
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[];
@@ -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 : [
@@ -10,6 +10,7 @@ export interface Cookie {
10
10
  description?: Translatable;
11
11
  id?: string;
12
12
  name: Translatable;
13
+ links?: Record<string, string | null>;
13
14
  src?: string;
14
15
  targetCookieIds?: string[];
15
16
  }
@@ -40,8 +40,8 @@ export const DEFAULTS = {
40
40
  },
41
41
  cookieExpiryOffsetMs: 1e3 * 60 * 60 * 24 * 365,
42
42
  // one year
43
- cookieNameIsConsentGiven: "cookie_control_is_consent_given",
44
- cookieNameCookiesEnabledIds: "cookie_control_cookies_enabled_ids",
43
+ cookieNameIsConsentGiven: "ncc_c",
44
+ cookieNameCookiesEnabledIds: "ncc_e",
45
45
  isAcceptNecessaryButtonEnabled: true,
46
46
  isControlButtonEnabled: true,
47
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.4",
3
+ "version": "5.0.0-beta.6",
4
4
  "description": "Nuxt Cookies Control Module",
5
5
  "author": "Dario Ferderber <dario.ferderber@broj42.com>",
6
6
  "maintainers": [