@dargmuesli/nuxt-cookie-control 3.0.0-beta.4 → 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
|
|
|
@@ -214,9 +219,14 @@ const acceptNecessary = () => {
|
|
|
214
219
|
})
|
|
215
220
|
}
|
|
216
221
|
const acceptPartial = () => {
|
|
222
|
+
const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value)
|
|
223
|
+
|
|
217
224
|
setCookies({
|
|
218
225
|
isConsentGiven: true,
|
|
219
|
-
cookiesOptionalEnabled:
|
|
226
|
+
cookiesOptionalEnabled: [
|
|
227
|
+
...moduleOptions.cookies?.necessary,
|
|
228
|
+
...moduleOptions.cookies.optional,
|
|
229
|
+
].filter((cookie) => localCookiesEnabledIds.includes(getCookieId(cookie))),
|
|
220
230
|
})
|
|
221
231
|
}
|
|
222
232
|
const declineAll = () => {
|
|
@@ -226,13 +236,14 @@ const declineAll = () => {
|
|
|
226
236
|
})
|
|
227
237
|
}
|
|
228
238
|
const toogleCookie = (cookie: Cookie) => {
|
|
229
|
-
|
|
239
|
+
const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(
|
|
240
|
+
getCookieId(cookie)
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
if (cookieIndex < 0) {
|
|
230
244
|
localCookiesEnabled.value.push(cookie)
|
|
231
245
|
} else {
|
|
232
|
-
localCookiesEnabled.value.splice(
|
|
233
|
-
localCookiesEnabled.value.indexOf(cookie),
|
|
234
|
-
1
|
|
235
|
-
)
|
|
246
|
+
localCookiesEnabled.value.splice(cookieIndex, 1)
|
|
236
247
|
}
|
|
237
248
|
}
|
|
238
249
|
const getDescription = (description: Translatable) =>
|
|
@@ -295,7 +306,7 @@ onBeforeMount(async () => {
|
|
|
295
306
|
isColorsSet.value = true
|
|
296
307
|
}
|
|
297
308
|
|
|
298
|
-
if (
|
|
309
|
+
if (getCookie(moduleOptions.cookieNameIsConsentGiven) === 'true') {
|
|
299
310
|
for (const cookieOptional of moduleOptions.cookies.optional) {
|
|
300
311
|
if (
|
|
301
312
|
typeof moduleOptions.isIframeBlocked === 'boolean'
|
|
@@ -313,7 +324,7 @@ watch(
|
|
|
313
324
|
localCookiesEnabled.value = [...(current || [])]
|
|
314
325
|
|
|
315
326
|
if (isConsentGiven.value) {
|
|
316
|
-
|
|
327
|
+
setCookie(
|
|
317
328
|
moduleOptions.cookieNameCookiesEnabledIds,
|
|
318
329
|
getCookieIds(current || []).join(','),
|
|
319
330
|
{
|
|
@@ -329,7 +340,7 @@ watch(
|
|
|
329
340
|
document.getElementsByTagName('head')[0].appendChild(script)
|
|
330
341
|
}
|
|
331
342
|
} else {
|
|
332
|
-
|
|
343
|
+
removeCookie(moduleOptions.cookieNameCookiesEnabledIds)
|
|
333
344
|
}
|
|
334
345
|
|
|
335
346
|
// delete formerly enabled cookies that are now disabled
|
|
@@ -341,7 +352,7 @@ watch(
|
|
|
341
352
|
if (!cookieOptionalDisabled.targetCookieIds) continue
|
|
342
353
|
|
|
343
354
|
for (const cookieOptionalDisabledId of cookieOptionalDisabled.targetCookieIds) {
|
|
344
|
-
|
|
355
|
+
removeCookie(cookieOptionalDisabledId)
|
|
345
356
|
}
|
|
346
357
|
|
|
347
358
|
if (cookieOptionalDisabled.src) {
|
|
@@ -359,9 +370,9 @@ watch(
|
|
|
359
370
|
)
|
|
360
371
|
watch(isConsentGiven, (current, _previous) => {
|
|
361
372
|
if (current === undefined) {
|
|
362
|
-
|
|
373
|
+
removeCookie(moduleOptions.cookieNameIsConsentGiven)
|
|
363
374
|
} else {
|
|
364
|
-
|
|
375
|
+
setCookie(moduleOptions.cookieNameIsConsentGiven, current.toString(), {
|
|
365
376
|
expires,
|
|
366
377
|
})
|
|
367
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
|
+
};
|