@dargmuesli/nuxt-cookie-control 6.1.0 → 6.1.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/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "configKey": "cookieControl",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0"
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.1.0";
6
+ const version = "6.1.2";
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) => {
@@ -186,6 +186,7 @@
186
186
  <script setup lang="ts">
187
187
  import { ref, computed, onBeforeMount, watch } from 'vue'
188
188
 
189
+ import { useNuxtApp } from '#app'
189
190
  import { Cookie, CookieType, Locale, Translatable } from '../types'
190
191
  import {
191
192
  getAllCookieIdsString,
@@ -212,6 +213,7 @@ const {
212
213
  isModalActive,
213
214
  moduleOptions,
214
215
  } = useCookieControl()
216
+ const nuxtApp = useNuxtApp()
215
217
 
216
218
  // data
217
219
  const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs)
@@ -278,6 +280,9 @@ const getName = (name: Translatable) => {
278
280
  ? localeStrings.value?.cookiesFunctional
279
281
  : resolveTranslatable(name, props.locale)
280
282
  }
283
+ const init = () => {
284
+ nuxtApp.$cookies.locale.value = props.locale
285
+ }
281
286
  const onModalClick = () => {
282
287
  if (moduleOptions.closeModalOnClickOutside) {
283
288
  isModalActive.value = false
@@ -392,6 +397,7 @@ watch(
392
397
  },
393
398
  { deep: true },
394
399
  )
400
+
395
401
  watch(isConsentGiven, (current, _previous) => {
396
402
  if (current === undefined) {
397
403
  cookieIsConsentGiven.value = undefined
@@ -400,6 +406,16 @@ watch(isConsentGiven, (current, _previous) => {
400
406
  }
401
407
  })
402
408
 
409
+ watch(
410
+ () => props.locale,
411
+ (locale) => {
412
+ nuxtApp.$cookies.locale.value = locale
413
+ },
414
+ )
415
+
416
+ // initialization
417
+ init()
418
+
403
419
  defineExpose({
404
420
  accept,
405
421
  acceptPartial,
@@ -1,6 +1,10 @@
1
1
  <template>
2
- <client-only>
3
- <iframe v-if="isCookieFunctionalEnabled" />
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
- </client-only>
18
+ </ClientOnly>
15
19
  </template>
16
20
 
17
21
  <script setup lang="ts">
18
22
  import { computed } from 'vue'
19
23
 
20
- import { LOCALE_DEFAULT } from '../constants'
21
- import { Cookie, Locale } from '../types'
22
-
24
+ import { useNuxtApp } from '#app'
25
+ import { Cookie } from '../types'
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(() => moduleOptions.localeTexts[props.locale])
38
+ const localeStrings = computed(
39
+ () => moduleOptions.localeTexts[nuxtApp.$cookies.locale.value],
40
+ )
42
41
  </script>
@@ -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 {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "description": "Nuxt Cookie Control Module",
5
5
  "author": "Dario Ferderber <dario.ferderber@broj42.com>",
6
6
  "maintainers": [
@@ -18,7 +18,7 @@
18
18
  "engines": {
19
19
  "node": ">=16"
20
20
  },
21
- "packageManager": "pnpm@8.6.7",
21
+ "packageManager": "pnpm@8.6.9",
22
22
  "exports": {
23
23
  ".": {
24
24
  "import": "./dist/module.mjs",
@@ -40,28 +40,28 @@
40
40
  "prepare": "husky install"
41
41
  },
42
42
  "dependencies": {
43
- "@nuxt/kit": "3.6.2",
43
+ "@nuxt/kit": "3.6.3",
44
44
  "@sindresorhus/slugify": "2.2.1",
45
45
  "css-vars-ponyfill": "2.4.8",
46
46
  "string-replace-loader": "3.1.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@commitlint/cli": "17.6.6",
50
- "@commitlint/config-conventional": "17.6.6",
49
+ "@commitlint/cli": "17.6.7",
50
+ "@commitlint/config-conventional": "17.6.7",
51
51
  "@dargmuesli/nuxt-cookie-control": "link:.",
52
52
  "@nuxt/module-builder": "0.4.0",
53
53
  "@nuxtjs/eslint-config-typescript": "12.0.0",
54
- "eslint": "8.44.0",
54
+ "eslint": "8.45.0",
55
55
  "eslint-config-prettier": "8.8.0",
56
56
  "eslint-plugin-prettier": "5.0.0",
57
57
  "husky": "8.0.3",
58
58
  "lint-staged": "13.2.3",
59
- "nuxt": "3.6.2",
59
+ "nuxt": "3.6.3",
60
60
  "prettier": "3.0.0",
61
61
  "typescript": "5.1.6",
62
62
  "vue": "3.3.4",
63
- "vue-tsc": "1.8.4",
64
- "webpack": "5.88.1"
63
+ "vue-tsc": "1.8.5",
64
+ "webpack": "5.88.2"
65
65
  },
66
66
  "publishConfig": {
67
67
  "access": "public"