@dargmuesli/nuxt-cookie-control 6.0.0 → 6.1.1
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 +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +55 -2
- package/dist/runtime/components/CookieControl.vue +15 -0
- package/dist/runtime/components/CookieIframe.vue +12 -13
- package/dist/runtime/locale/index.mjs +2 -0
- package/dist/runtime/locale/ro.d.ts +3 -0
- package/dist/runtime/locale/ro.mjs +17 -0
- package/dist/runtime/plugin.mjs +3 -1
- package/dist/runtime/types.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
✅ Translated for: ar, az, bg, cs, da, de, en, es, fi, fr, hr, hu, it, ja, ko, lt, nl, no, oc, pt, pl, rs, ru, sk, sv, tr and uk
|
|
7
|
+
✅ Translated for: ar, az, bg, cs, da, de, en, es, fi, fr, hr, hu, it, ja, ko, lt, nl, no, oc, pt, pl, ro, rs, ru, sk, sv, tr and uk
|
|
8
8
|
|
|
9
9
|
✅ Vue 3 support
|
|
10
10
|
|
package/dist/module.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { CookieOptions } from 'nuxt/app';
|
|
3
3
|
|
|
4
|
-
type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
|
|
4
|
+
type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'ro' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
|
|
5
5
|
type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
|
|
6
6
|
type Translatable = string | PartialRecord<Locale, string>;
|
|
7
7
|
interface Cookie {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { createResolver, defineNuxtModule, addPlugin, addImports, addTemplate, extendWebpackConfig, resolvePath } from '@nuxt/kit';
|
|
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 = "6.
|
|
6
|
+
const version = "6.1.1";
|
|
7
7
|
|
|
8
8
|
const en = {
|
|
9
9
|
accept: "Accept",
|
|
@@ -77,6 +77,47 @@ const DEFAULTS = {
|
|
|
77
77
|
localeTexts: { en }
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
+
const execSrcReplacements = (src, replacements) => {
|
|
81
|
+
for (const replacement of replacements) {
|
|
82
|
+
if ((typeof replacement.from === "string" || replacement.from instanceof RegExp) === false) {
|
|
83
|
+
throw new TypeError(
|
|
84
|
+
"[vite-plugin-replace]: The replacement option 'from' is not of type 'string' or 'RegExp'."
|
|
85
|
+
);
|
|
86
|
+
} else if ((typeof replacement.to === "string" || replacement.to instanceof Function) === false) {
|
|
87
|
+
throw new TypeError(
|
|
88
|
+
"[vite-plugin-replace]: The replacement option 'to' is not of type 'string' or 'Function'"
|
|
89
|
+
);
|
|
90
|
+
} else
|
|
91
|
+
src = src.replace(replacement.from, replacement.to);
|
|
92
|
+
}
|
|
93
|
+
return src;
|
|
94
|
+
};
|
|
95
|
+
const replaceCodePlugin = (config) => {
|
|
96
|
+
if (config === void 0) {
|
|
97
|
+
config = {
|
|
98
|
+
replacements: []
|
|
99
|
+
};
|
|
100
|
+
} else if ((typeof config === "object" || config !== null) === false) {
|
|
101
|
+
throw new TypeError(
|
|
102
|
+
"[vite-plugin-replace]: The configuration is not of type 'Object'."
|
|
103
|
+
);
|
|
104
|
+
} else if (Array.isArray(config.replacements) === false) {
|
|
105
|
+
throw new TypeError(
|
|
106
|
+
"[vite-plugin-replace]: The configuration option 'replacement' is not of type 'Array'."
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
name: "transform-file",
|
|
111
|
+
enforce: "pre",
|
|
112
|
+
transform: function(src) {
|
|
113
|
+
return {
|
|
114
|
+
code: execSrcReplacements(src, config.replacements),
|
|
115
|
+
map: null
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
80
121
|
const resolver = createResolver(import.meta.url);
|
|
81
122
|
const runtimeDir = resolver.resolve("./runtime");
|
|
82
123
|
const module = defineNuxtModule({
|
|
@@ -146,6 +187,18 @@ const blockIframes = (moduleOptions) => {
|
|
|
146
187
|
}
|
|
147
188
|
});
|
|
148
189
|
});
|
|
190
|
+
extendViteConfig((config) => {
|
|
191
|
+
config?.plugins?.push(
|
|
192
|
+
replaceCodePlugin({
|
|
193
|
+
replacements: [
|
|
194
|
+
{
|
|
195
|
+
from: /<iframe[^>]*.*|<\/iframe>/g,
|
|
196
|
+
to: (match) => match.includes("cookie-enabled") ? match : match.replace(/<iframe/g, "<CookieIframe").replace(/iframe>/g, "CookieIframe>")
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
});
|
|
149
202
|
}
|
|
150
203
|
};
|
|
151
204
|
const loadLocales = async (moduleOptions) => {
|
|
@@ -212,6 +212,7 @@ const {
|
|
|
212
212
|
isModalActive,
|
|
213
213
|
moduleOptions,
|
|
214
214
|
} = useCookieControl()
|
|
215
|
+
const nuxtApp = useNuxtApp()
|
|
215
216
|
|
|
216
217
|
// data
|
|
217
218
|
const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs)
|
|
@@ -278,6 +279,9 @@ const getName = (name: Translatable) => {
|
|
|
278
279
|
? localeStrings.value?.cookiesFunctional
|
|
279
280
|
: resolveTranslatable(name, props.locale)
|
|
280
281
|
}
|
|
282
|
+
const init = () => {
|
|
283
|
+
nuxtApp.$cookies.locale.value = props.locale
|
|
284
|
+
}
|
|
281
285
|
const onModalClick = () => {
|
|
282
286
|
if (moduleOptions.closeModalOnClickOutside) {
|
|
283
287
|
isModalActive.value = false
|
|
@@ -392,6 +396,7 @@ watch(
|
|
|
392
396
|
},
|
|
393
397
|
{ deep: true },
|
|
394
398
|
)
|
|
399
|
+
|
|
395
400
|
watch(isConsentGiven, (current, _previous) => {
|
|
396
401
|
if (current === undefined) {
|
|
397
402
|
cookieIsConsentGiven.value = undefined
|
|
@@ -400,6 +405,16 @@ watch(isConsentGiven, (current, _previous) => {
|
|
|
400
405
|
}
|
|
401
406
|
})
|
|
402
407
|
|
|
408
|
+
watch(
|
|
409
|
+
() => props.locale,
|
|
410
|
+
(locale) => {
|
|
411
|
+
nuxtApp.$cookies.locale.value = locale
|
|
412
|
+
},
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
// initialization
|
|
416
|
+
init()
|
|
417
|
+
|
|
403
418
|
defineExpose({
|
|
404
419
|
accept,
|
|
405
420
|
acceptPartial,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<iframe
|
|
2
|
+
<ClientOnly>
|
|
3
|
+
<iframe
|
|
4
|
+
v-if="isCookieFunctionalEnabled"
|
|
5
|
+
:cookie-enabled="null"
|
|
6
|
+
v-bind="$attrs"
|
|
7
|
+
/>
|
|
4
8
|
<div v-else class="cookieControl__BlockedIframe">
|
|
5
9
|
<p>
|
|
6
10
|
{{ localeStrings?.iframeBlocked }}
|
|
@@ -11,25 +15,18 @@
|
|
|
11
15
|
/>
|
|
12
16
|
</p>
|
|
13
17
|
</div>
|
|
14
|
-
</
|
|
18
|
+
</ClientOnly>
|
|
15
19
|
</template>
|
|
16
20
|
|
|
17
21
|
<script setup lang="ts">
|
|
18
22
|
import { computed } from 'vue'
|
|
19
23
|
|
|
20
|
-
import {
|
|
21
|
-
import { Cookie, Locale } from '../types'
|
|
24
|
+
import { Cookie } from '../types'
|
|
22
25
|
|
|
23
26
|
import { useCookieControl } from '#imports'
|
|
24
27
|
|
|
25
|
-
export interface Props {
|
|
26
|
-
locale?: Locale
|
|
27
|
-
}
|
|
28
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
29
|
-
locale: LOCALE_DEFAULT,
|
|
30
|
-
})
|
|
31
|
-
|
|
32
28
|
const { cookiesEnabled, isModalActive, moduleOptions } = useCookieControl()
|
|
29
|
+
const nuxtApp = useNuxtApp()
|
|
33
30
|
|
|
34
31
|
// computations
|
|
35
32
|
const isCookieFunctionalEnabled = computed(
|
|
@@ -38,5 +35,7 @@ const isCookieFunctionalEnabled = computed(
|
|
|
38
35
|
(cookieEnabled: Cookie) => cookieEnabled.name === 'functional',
|
|
39
36
|
).length > 0,
|
|
40
37
|
)
|
|
41
|
-
const localeStrings = computed(
|
|
38
|
+
const localeStrings = computed(
|
|
39
|
+
() => moduleOptions.localeTexts[nuxtApp.$cookies.locale.value],
|
|
40
|
+
)
|
|
42
41
|
</script>
|
|
@@ -19,6 +19,7 @@ import no from "./no.mjs";
|
|
|
19
19
|
import oc from "./oc.mjs";
|
|
20
20
|
import pt from "./pt.mjs";
|
|
21
21
|
import pl from "./pl.mjs";
|
|
22
|
+
import ro from "./ro.mjs";
|
|
22
23
|
import rs from "./rs.mjs";
|
|
23
24
|
import ru from "./ru.mjs";
|
|
24
25
|
import sk from "./sk.mjs";
|
|
@@ -47,6 +48,7 @@ export const locales = [
|
|
|
47
48
|
oc,
|
|
48
49
|
pt,
|
|
49
50
|
pl,
|
|
51
|
+
ro,
|
|
50
52
|
rs,
|
|
51
53
|
ru,
|
|
52
54
|
sk,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
accept: "Accept\u0103",
|
|
3
|
+
acceptAll: "Accept\u0103 toate",
|
|
4
|
+
bannerDescription: "Utiliz\u0103m propriile noastre cookie-uri \u0219i cookie-uri ale ter\u021Bilor pentru a afi\u0219a corect acest site web \u0219i pentru a \xEEn\u021Belege mai bine modul \xEEn care este utilizat acest site web, cu scopul de a \xEEmbun\u0103t\u0103\u021Bi serviciile pe care le oferim. Decizia cu privire la permisiunile de utilizare a cookie-urilor poate fi modificat\u0103 \xEEn orice moment folosind butonul de cookie-uri care va ap\u0103rea dup\u0103 ce a\u021Bi f\u0103cut o selec\u021Bie pe aceast\u0103 banner.",
|
|
5
|
+
bannerTitle: "Cookie-uri",
|
|
6
|
+
close: "\xCEnchide",
|
|
7
|
+
cookiesFunctional: "Cookie-uri func\u021Bionale",
|
|
8
|
+
cookiesNecessary: "Cookie-uri necesare",
|
|
9
|
+
cookiesOptional: "Cookie-uri op\u021Bionale",
|
|
10
|
+
decline: "Declin\u0103",
|
|
11
|
+
declineAll: "Declin\u0103 toate",
|
|
12
|
+
here: "aici",
|
|
13
|
+
iframeBlocked: "Pentru a vedea aceasta, activeaz\u0103 cookie-urile func\u021Bionale",
|
|
14
|
+
manageCookies: "Afl\u0103 mai multe \u0219i configureaz\u0103",
|
|
15
|
+
save: "Salveaz\u0103",
|
|
16
|
+
settingsUnsaved: "Ai set\u0103ri nesalvate"
|
|
17
|
+
};
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -26,11 +26,13 @@ export default defineNuxtPlugin((_nuxtApp) => {
|
|
|
26
26
|
);
|
|
27
27
|
const cookiesEnabledIds = ref(cookieCookiesEnabledIds);
|
|
28
28
|
const isModalActive = ref();
|
|
29
|
+
const locale = ref();
|
|
29
30
|
const state = {
|
|
30
|
-
isConsentGiven,
|
|
31
31
|
cookiesEnabled,
|
|
32
32
|
cookiesEnabledIds,
|
|
33
|
+
isConsentGiven,
|
|
33
34
|
isModalActive,
|
|
35
|
+
locale,
|
|
34
36
|
moduleOptions
|
|
35
37
|
};
|
|
36
38
|
return {
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
2
|
import { CookieOptions } from 'nuxt/app';
|
|
3
|
-
export type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
|
|
3
|
+
export type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'ro' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
|
|
4
4
|
export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
|
|
5
5
|
export type Translatable = string | PartialRecord<Locale, string>;
|
|
6
6
|
export declare enum CookieType {
|
|
@@ -61,5 +61,6 @@ export interface State {
|
|
|
61
61
|
cookiesEnabledIds: Ref<string[] | undefined>;
|
|
62
62
|
isConsentGiven: Ref<boolean | undefined>;
|
|
63
63
|
isModalActive: Ref<boolean>;
|
|
64
|
+
locale: Ref<Locale>;
|
|
64
65
|
moduleOptions: ModuleOptions;
|
|
65
66
|
}
|