@dargmuesli/nuxt-cookie-control 3.0.0-beta.5 → 3.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/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 = "3.0.0-beta.
|
|
5
|
+
const version = "3.0.0-beta.6";
|
|
6
6
|
|
|
7
7
|
const en = {
|
|
8
8
|
acceptAll: "Accept all",
|
|
@@ -87,9 +87,8 @@
|
|
|
87
87
|
getCookieIds(localCookiesEnabled)?.includes(
|
|
88
88
|
getCookieId(cookie)
|
|
89
89
|
) ||
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
) !== 'true' &&
|
|
90
|
+
(getCookie(moduleOptions.cookieNameIsConsentGiven) !==
|
|
91
|
+
'true' &&
|
|
93
92
|
typeof moduleOptions.isIframeBlocked === 'object' &&
|
|
94
93
|
moduleOptions.isIframeBlocked.initialState)
|
|
95
94
|
"
|
|
@@ -162,11 +161,17 @@
|
|
|
162
161
|
</template>
|
|
163
162
|
|
|
164
163
|
<script setup lang="ts">
|
|
165
|
-
import Cookies from 'js-cookie'
|
|
166
164
|
import { ref, computed, onBeforeMount, watch } from 'vue'
|
|
167
165
|
|
|
168
166
|
import { Cookie, CookieType, Locale, Translatable } from '../types'
|
|
169
|
-
import {
|
|
167
|
+
import {
|
|
168
|
+
getCookie,
|
|
169
|
+
getCookieId,
|
|
170
|
+
getCookieIds,
|
|
171
|
+
removeCookie,
|
|
172
|
+
setCookie,
|
|
173
|
+
useResolveTranslatable,
|
|
174
|
+
} from '../methods'
|
|
170
175
|
|
|
171
176
|
import { useCookieControl } from '#imports'
|
|
172
177
|
|
|
@@ -301,7 +306,7 @@ onBeforeMount(async () => {
|
|
|
301
306
|
isColorsSet.value = true
|
|
302
307
|
}
|
|
303
308
|
|
|
304
|
-
if (
|
|
309
|
+
if (getCookie(moduleOptions.cookieNameIsConsentGiven) === 'true') {
|
|
305
310
|
for (const cookieOptional of moduleOptions.cookies.optional) {
|
|
306
311
|
if (
|
|
307
312
|
typeof moduleOptions.isIframeBlocked === 'boolean'
|
|
@@ -319,7 +324,7 @@ watch(
|
|
|
319
324
|
localCookiesEnabled.value = [...(current || [])]
|
|
320
325
|
|
|
321
326
|
if (isConsentGiven.value) {
|
|
322
|
-
|
|
327
|
+
setCookie(
|
|
323
328
|
moduleOptions.cookieNameCookiesEnabledIds,
|
|
324
329
|
getCookieIds(current || []).join(','),
|
|
325
330
|
{
|
|
@@ -335,7 +340,7 @@ watch(
|
|
|
335
340
|
document.getElementsByTagName('head')[0].appendChild(script)
|
|
336
341
|
}
|
|
337
342
|
} else {
|
|
338
|
-
|
|
343
|
+
removeCookie(moduleOptions.cookieNameCookiesEnabledIds)
|
|
339
344
|
}
|
|
340
345
|
|
|
341
346
|
// delete formerly enabled cookies that are now disabled
|
|
@@ -347,7 +352,7 @@ watch(
|
|
|
347
352
|
if (!cookieOptionalDisabled.targetCookieIds) continue
|
|
348
353
|
|
|
349
354
|
for (const cookieOptionalDisabledId of cookieOptionalDisabled.targetCookieIds) {
|
|
350
|
-
|
|
355
|
+
removeCookie(cookieOptionalDisabledId)
|
|
351
356
|
}
|
|
352
357
|
|
|
353
358
|
if (cookieOptionalDisabled.src) {
|
|
@@ -365,9 +370,9 @@ watch(
|
|
|
365
370
|
)
|
|
366
371
|
watch(isConsentGiven, (current, _previous) => {
|
|
367
372
|
if (current === undefined) {
|
|
368
|
-
|
|
373
|
+
removeCookie(moduleOptions.cookieNameIsConsentGiven)
|
|
369
374
|
} else {
|
|
370
|
-
|
|
375
|
+
setCookie(moduleOptions.cookieNameIsConsentGiven, current.toString(), {
|
|
371
376
|
expires,
|
|
372
377
|
})
|
|
373
378
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Cookie, Translatable } from './types';
|
|
2
|
+
export declare const getCookie: (name: string) => any;
|
|
2
3
|
export declare const getCookieId: (cookie: Cookie) => string;
|
|
3
4
|
export declare const getCookieIds: (cookies: Cookie[]) => string[];
|
|
5
|
+
export declare const removeCookie: (name: string) => any;
|
|
6
|
+
export declare const resolveTranslatable: (translatable: Translatable, locale?: import("./types").Locale) => string;
|
|
7
|
+
export declare const setCookie: (name: string, value: string, options: Cookies.CookieAttributes) => any;
|
|
4
8
|
export declare const useResolveTranslatable: (locale?: import("./types").Locale) => (translatable: Translatable) => string;
|
package/dist/runtime/methods.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import Cookies from "js-cookie";
|
|
1
2
|
import slugify from "@sindresorhus/slugify";
|
|
2
3
|
import { LOCALE_DEFAULT } from "./constants.mjs";
|
|
4
|
+
export const getCookie = (name) => Cookies.get(name);
|
|
3
5
|
export const getCookieId = (cookie) => cookie.id || slugify(resolveTranslatable(cookie.name));
|
|
4
6
|
export const getCookieIds = (cookies) => cookies.map((cookie) => getCookieId(cookie));
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
const resolveTranslatable = (translatable, locale = LOCALE_DEFAULT) => {
|
|
7
|
+
export const removeCookie = (name) => Cookies.remove(name);
|
|
8
|
+
export const resolveTranslatable = (translatable, locale = LOCALE_DEFAULT) => {
|
|
9
9
|
if (typeof translatable === "string")
|
|
10
10
|
return translatable;
|
|
11
11
|
if (!locale)
|
|
@@ -15,3 +15,7 @@ const resolveTranslatable = (translatable, locale = LOCALE_DEFAULT) => {
|
|
|
15
15
|
throw new Error(`Could not get translation for locale ${locale}.`);
|
|
16
16
|
return result;
|
|
17
17
|
};
|
|
18
|
+
export const setCookie = (name, value, options) => Cookies.set(name, value, options);
|
|
19
|
+
export const useResolveTranslatable = (locale = LOCALE_DEFAULT) => {
|
|
20
|
+
return (translatable) => resolveTranslatable(translatable, locale);
|
|
21
|
+
};
|