@dargmuesli/nuxt-cookie-control 7.4.1 → 8.0.0-beta.2

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
@@ -206,8 +206,7 @@ Every property that includes a `{ en: ... }` value is a translatable property th
206
206
  description: {
207
207
  en: 'This cookie stores preferences.'
208
208
  },
209
- id: 'p', // if unset, `getCookieId(cookie)` returns the cookie's slugified name instead, which e.g. is used to fill the state's `enabledCookieIds` list
210
- // use a short cookie id to save bandwidth!
209
+ id: 'p', // use a short cookie id to save bandwidth and prefixes to separate
211
210
  name: {
212
211
  en: 'Preferences' // you always have to specify a cookie name (in English)
213
212
  },
package/dist/module.d.mts CHANGED
@@ -6,7 +6,7 @@ type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
6
6
  type Translatable = string | PartialRecord<Locale, string>;
7
7
  interface Cookie {
8
8
  description?: Translatable;
9
- id?: string;
9
+ id: string;
10
10
  name: Translatable;
11
11
  links?: Record<string, string | null>;
12
12
  src?: string;
package/dist/module.d.ts CHANGED
@@ -6,7 +6,7 @@ type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
6
6
  type Translatable = string | PartialRecord<Locale, string>;
7
7
  interface Cookie {
8
8
  description?: Translatable;
9
- id?: string;
9
+ id: string;
10
10
  name: Translatable;
11
11
  links?: Record<string, string | null>;
12
12
  src?: string;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "7.4.1",
3
+ "version": "8.0.0-beta.2",
4
4
  "configKey": "cookieControl",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0"
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { pathToFileURL } from 'node:url';
3
3
  import { createResolver, defineNuxtModule, addPlugin, addImports, addTemplate, extendWebpackConfig, extendViteConfig, resolvePath } from '@nuxt/kit';
4
4
 
5
5
  const name = "@dargmuesli/nuxt-cookie-control";
6
- const version = "7.4.1";
6
+ const version = "8.0.0-beta.2";
7
7
 
8
8
  const en = {
9
9
  accept: "Accept",
@@ -165,6 +165,7 @@ export default ${JSON.stringify(
165
165
  const blockIframes = (moduleOptions) => {
166
166
  if (moduleOptions.isIframeBlocked) {
167
167
  const isIframeBlocked = {
168
+ id: "ncc_f",
168
169
  name: "functional"
169
170
  };
170
171
  if (moduleOptions.cookies) {
@@ -95,7 +95,7 @@
95
95
  type="checkbox"
96
96
  :checked="
97
97
  getCookieIds(localCookiesEnabled).includes(
98
- getCookieId(cookie),
98
+ cookie.id,
99
99
  )
100
100
  "
101
101
  @change="toogleCookie(cookie)"
@@ -125,7 +125,7 @@
125
125
  {{
126
126
  'IDs: ' +
127
127
  cookie.targetCookieIds
128
- .map((id: string) => `"${id}"`)
128
+ .map((id) => `"${id}"`)
129
129
  .join(', ')
130
130
  }}
131
131
  </span>
@@ -197,15 +197,14 @@ import {
197
197
  CookieType,
198
198
  type Locale,
199
199
  type Translatable,
200
- } from '../types'
200
+ } from '#cookie-control/types'
201
201
  import {
202
202
  getAllCookieIdsString,
203
- getCookieId,
204
203
  getCookieIds,
205
204
  removeCookie,
206
205
  resolveTranslatable,
207
- } from '../methods'
208
-
206
+ } from '#cookie-control/methods'
207
+ import { COOKIE_ID_SEPARATOR } from '#cookie-control/constants'
209
208
  import setCssVariables from '#cookie-control/set-vars'
210
209
  import { useCookieControl, useCookie, useNuxtApp } from '#imports'
211
210
 
@@ -247,7 +246,8 @@ const isSaved = computed(
247
246
  () =>
248
247
  getCookieIds(cookiesEnabled.value || [])
249
248
  .sort()
250
- .join('|') !== getCookieIds(localCookiesEnabled.value).sort().join('|'),
249
+ .join(COOKIE_ID_SEPARATOR) !==
250
+ getCookieIds(localCookiesEnabled.value).sort().join(COOKIE_ID_SEPARATOR),
251
251
  )
252
252
  const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
253
253
 
@@ -266,7 +266,7 @@ const acceptPartial = () => {
266
266
  cookiesOptionalEnabled: [
267
267
  ...moduleOptions.cookies.necessary,
268
268
  ...moduleOptions.cookies.optional,
269
- ].filter((cookie) => localCookiesEnabledIds.includes(getCookieId(cookie))),
269
+ ].filter((cookie) => localCookiesEnabledIds.includes(cookie.id)),
270
270
  })
271
271
  }
272
272
  const decline = () => {
@@ -325,9 +325,7 @@ const toggleButton = ($event: MouseEvent) => {
325
325
  )?.click()
326
326
  }
327
327
  const toogleCookie = (cookie: Cookie) => {
328
- const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(
329
- getCookieId(cookie),
330
- )
328
+ const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(cookie.id)
331
329
 
332
330
  if (cookieIndex < 0) {
333
331
  localCookiesEnabled.value.push(cookie)
@@ -361,7 +359,9 @@ watch(
361
359
  localCookiesEnabled.value = [...(current || [])]
362
360
 
363
361
  if (isConsentGiven.value) {
364
- cookieCookiesEnabledIds.value = getCookieIds(current || []).join('|')
362
+ cookieCookiesEnabledIds.value = getCookieIds(current || []).join(
363
+ COOKIE_ID_SEPARATOR,
364
+ )
365
365
 
366
366
  for (const cookieEnabled of current || []) {
367
367
  if (!cookieEnabled.src) continue
@@ -1,2 +1,3 @@
1
1
  import type { Locale } from './types';
2
+ export declare const COOKIE_ID_SEPARATOR = "~";
2
3
  export declare const LOCALE_DEFAULT: Locale;
@@ -1 +1,2 @@
1
+ export const COOKIE_ID_SEPARATOR = "~";
1
2
  export const LOCALE_DEFAULT = "en";
@@ -1,7 +1,6 @@
1
1
  import type { Cookie, ModuleOptions, Translatable } from './types';
2
2
  export declare const getAllCookieIdsString: (moduleOptions: ModuleOptions) => string;
3
- export declare const getCookieId: (cookie: Cookie) => string;
4
3
  export declare const getCookieIds: (cookies: Cookie[]) => string[];
5
- export declare const removeCookie: (name: string) => any;
4
+ export declare const removeCookie: (name: string) => undefined;
6
5
  export declare const resolveTranslatable: (translatable: Translatable, locale?: import("./types").Locale) => string;
7
6
  export declare const useResolveTranslatable: (locale?: import("./types").Locale) => (translatable: Translatable) => string;
@@ -1,13 +1,11 @@
1
- import slugify from "@sindresorhus/slugify";
2
1
  import { LOCALE_DEFAULT } from "./constants.mjs";
3
2
  import { useCookie } from "#imports";
4
3
  export const getAllCookieIdsString = (moduleOptions) => getCookieIds([
5
4
  ...moduleOptions.cookies.necessary,
6
5
  ...moduleOptions.cookies.optional
7
6
  ]).join("");
8
- export const getCookieId = (cookie) => cookie.id || slugify(resolveTranslatable(cookie.name));
9
- export const getCookieIds = (cookies) => cookies.map((cookie) => getCookieId(cookie));
10
- export const removeCookie = (name) => useCookie(name, { expires: /* @__PURE__ */ new Date(0) });
7
+ export const getCookieIds = (cookies) => cookies.map((cookie) => cookie.id);
8
+ export const removeCookie = (name) => useCookie(name).value = void 0;
11
9
  export const resolveTranslatable = (translatable, locale = LOCALE_DEFAULT) => {
12
10
  if (typeof translatable === "string")
13
11
  return translatable;
@@ -1,5 +1,6 @@
1
1
  import { ref } from "vue";
2
- import { getAllCookieIdsString, getCookieId } from "./methods.mjs";
2
+ import { COOKIE_ID_SEPARATOR } from "./constants.mjs";
3
+ import { getAllCookieIdsString } from "./methods.mjs";
3
4
  import { defineNuxtPlugin, useCookie } from "#imports";
4
5
  import moduleOptions from "#build/cookie-control-options";
5
6
  const plugin = defineNuxtPlugin((_nuxtApp) => {
@@ -10,17 +11,17 @@ const plugin = defineNuxtPlugin((_nuxtApp) => {
10
11
  const cookieCookiesEnabledIds = useCookie(
11
12
  moduleOptions.cookieNameCookiesEnabledIds,
12
13
  moduleOptions.cookieOptions
13
- ).value?.split("|");
14
+ ).value?.split(COOKIE_ID_SEPARATOR);
14
15
  const isConsentGiven = ref(
15
16
  cookieIsConsentGiven === void 0 ? void 0 : cookieIsConsentGiven.value === getAllCookieIdsString(moduleOptions)
16
17
  );
17
18
  const cookiesEnabled = ref(
18
19
  cookieCookiesEnabledIds === void 0 ? void 0 : [
19
20
  ...moduleOptions.cookies.necessary.filter(
20
- (cookieNecessary) => cookieCookiesEnabledIds.includes(getCookieId(cookieNecessary))
21
+ (cookieNecessary) => cookieCookiesEnabledIds.includes(cookieNecessary.id)
21
22
  ),
22
23
  ...moduleOptions.cookies.optional.filter(
23
- (cookieOptional) => cookieCookiesEnabledIds.includes(getCookieId(cookieOptional))
24
+ (cookieOptional) => cookieCookiesEnabledIds.includes(cookieOptional.id)
24
25
  )
25
26
  ]
26
27
  );
@@ -9,7 +9,7 @@ export declare enum CookieType {
9
9
  }
10
10
  export interface Cookie {
11
11
  description?: Translatable;
12
- id?: string;
12
+ id: string;
13
13
  name: Translatable;
14
14
  links?: Record<string, string | null>;
15
15
  src?: string;
package/package.json CHANGED
@@ -4,8 +4,7 @@
4
4
  "Dario Ferderber <dario.ferderber@broj42.com>"
5
5
  ],
6
6
  "dependencies": {
7
- "@nuxt/kit": "3.11.1",
8
- "@sindresorhus/slugify": "^2.2.1",
7
+ "@nuxt/kit": "^3.8.0",
9
8
  "css-vars-ponyfill": "^2.4.8",
10
9
  "string-replace-loader": "^3.1.0"
11
10
  },
@@ -72,6 +71,7 @@
72
71
  },
73
72
  "scripts": {
74
73
  "build": "nuxt-module-build build",
74
+ "dev": "pnpm --dir playground run dev",
75
75
  "lint": "eslint --ext .js,.ts,.vue . && nuxt typecheck",
76
76
  "lint:fix": "eslint --ext .js,.ts,.vue --fix . && nuxt typecheck --fix",
77
77
  "prepack": "pnpm build",
@@ -79,5 +79,5 @@
79
79
  },
80
80
  "type": "module",
81
81
  "types": "./dist/module.d.ts",
82
- "version": "7.4.1"
82
+ "version": "8.0.0-beta.2"
83
83
  }