@dargmuesli/nuxt-cookie-control 6.1.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/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.1.
|
|
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>
|
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