@dargmuesli/nuxt-cookie-control 2.0.0-beta.1 → 2.0.0-beta.3
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.d.ts +66 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +184 -4
- package/dist/runtime/composables.d.ts +1 -0
- package/dist/runtime/composables.mjs +1 -0
- package/dist/runtime/constants.d.ts +2 -0
- package/dist/runtime/constants.mjs +2 -0
- package/dist/runtime/locale/ar.d.ts +3 -0
- package/dist/runtime/locale/ar.mjs +16 -0
- package/dist/runtime/locale/de.d.ts +3 -0
- package/dist/runtime/locale/de.mjs +16 -0
- package/dist/runtime/locale/en.d.ts +3 -0
- package/dist/runtime/locale/en.mjs +16 -0
- package/dist/runtime/locale/es.d.ts +3 -0
- package/dist/runtime/locale/es.mjs +16 -0
- package/dist/runtime/locale/fr.d.ts +3 -0
- package/dist/runtime/locale/fr.mjs +16 -0
- package/dist/runtime/locale/hr.d.ts +3 -0
- package/dist/runtime/locale/hr.mjs +16 -0
- package/dist/runtime/locale/hu.d.ts +3 -0
- package/dist/runtime/locale/hu.mjs +16 -0
- package/dist/runtime/locale/index.d.ts +1 -0
- package/dist/runtime/locale/index.mjs +15 -0
- package/dist/runtime/locale/it.d.ts +3 -0
- package/dist/runtime/locale/it.mjs +16 -0
- package/dist/runtime/locale/ja.d.ts +3 -0
- package/dist/runtime/locale/ja.mjs +16 -0
- package/dist/runtime/locale/nl.d.ts +3 -0
- package/dist/runtime/locale/nl.mjs +16 -0
- package/dist/runtime/locale/no.d.ts +3 -0
- package/dist/runtime/locale/no.mjs +16 -0
- package/dist/runtime/locale/pt.d.ts +3 -0
- package/dist/runtime/locale/pt.mjs +16 -0
- package/dist/runtime/locale/ru.d.ts +3 -0
- package/dist/runtime/locale/ru.mjs +16 -0
- package/dist/runtime/locale/uk.d.ts +3 -0
- package/dist/runtime/locale/uk.mjs +16 -0
- package/dist/runtime/methods.d.ts +16 -0
- package/dist/runtime/methods.mjs +117 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.mjs +27 -0
- package/dist/runtime/types.d.ts +73 -0
- package/dist/runtime/types.mjs +66 -0
- package/dist/types.d.ts +2 -9
- package/package.json +4 -8
- package/dist/runtime/composables.ts +0 -1
- package/dist/runtime/constants.ts +0 -3
- package/dist/runtime/locale/ar.ts +0 -19
- package/dist/runtime/locale/de.ts +0 -20
- package/dist/runtime/locale/en.ts +0 -19
- package/dist/runtime/locale/es.ts +0 -19
- package/dist/runtime/locale/fr.ts +0 -19
- package/dist/runtime/locale/hr.ts +0 -20
- package/dist/runtime/locale/hu.ts +0 -20
- package/dist/runtime/locale/index.ts +0 -16
- package/dist/runtime/locale/it.ts +0 -19
- package/dist/runtime/locale/ja.ts +0 -19
- package/dist/runtime/locale/nl.ts +0 -20
- package/dist/runtime/locale/no.ts +0 -20
- package/dist/runtime/locale/pt.ts +0 -20
- package/dist/runtime/locale/ru.ts +0 -19
- package/dist/runtime/locale/uk.ts +0 -19
- package/dist/runtime/methods.ts +0 -190
- package/dist/runtime/plugin.ts +0 -35
- package/dist/runtime/types.ts +0 -132
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { LocaleStrings } from '../types'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
acceptAll: 'Прийняти усі',
|
|
5
|
-
acceptNecessary: 'Приймаю необхідне',
|
|
6
|
-
barDescription:
|
|
7
|
-
'Ми використовуємо власні файли cookie та сторонні файли cookie, щоб ми могли показати вам цей веб-сайт і краще зрозуміти, як ви ним користуєтеся, з метою покращення пропонованих нами послуг. Якщо ви продовжуєте перегляд, ми вважаємо, що ви прийняли файли cookie.',
|
|
8
|
-
barTitle: 'Файли cookie',
|
|
9
|
-
blockedIframe: 'Щоб побачити це, увімкніть функціональні файли cookie',
|
|
10
|
-
close: 'Закрити',
|
|
11
|
-
declineAll: 'Видалити усі',
|
|
12
|
-
functional: 'Функціональні файли cookie',
|
|
13
|
-
here: 'тут',
|
|
14
|
-
manageCookies: 'Керувати файлами cookie',
|
|
15
|
-
necessary: 'Необхідні файли cookie',
|
|
16
|
-
optional: 'Факультативні файли cookie',
|
|
17
|
-
save: 'Зберегти',
|
|
18
|
-
unsaved: 'У вас є незбережені налаштування',
|
|
19
|
-
} as LocaleStrings
|
package/dist/runtime/methods.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import Cookies from 'js-cookie'
|
|
2
|
-
// import { NuxtApp } from 'nuxt/dist/app/nuxt'
|
|
3
|
-
import slugify from 'slugify'
|
|
4
|
-
import { Ref } from 'vue'
|
|
5
|
-
|
|
6
|
-
import { useCookieControl } from './composables'
|
|
7
|
-
import { LOCALE_DEFAULT } from './constants'
|
|
8
|
-
import { Cookie, Locale, ModuleOptions, Translatable } from './types'
|
|
9
|
-
|
|
10
|
-
export const useAcceptNecessary = () => {
|
|
11
|
-
const { cookiesEnabled, isConsentGiven, moduleOptions } = useCookieControl()
|
|
12
|
-
// const nuxtApp = useNuxtApp()
|
|
13
|
-
|
|
14
|
-
return () =>
|
|
15
|
-
acceptNecessary(
|
|
16
|
-
// nuxtApp,
|
|
17
|
-
cookiesEnabled,
|
|
18
|
-
isConsentGiven,
|
|
19
|
-
moduleOptions.cookies?.necessary
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const acceptNecessary = (
|
|
24
|
-
// nuxtApp: NuxtApp,
|
|
25
|
-
enabled: Ref<Cookie[]>,
|
|
26
|
-
consent: Ref<boolean>,
|
|
27
|
-
necessaryCookies: Cookie[] = []
|
|
28
|
-
) => {
|
|
29
|
-
const expires = new Date()
|
|
30
|
-
expires.setFullYear(expires.getFullYear() + 1)
|
|
31
|
-
|
|
32
|
-
const necessaryCookieIds = necessaryCookies.map((necessaryCookie) =>
|
|
33
|
-
getCookieId(necessaryCookie)
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
Cookies.set('cookie_control_enabled_cookies', necessaryCookieIds.join(','), {
|
|
37
|
-
expires,
|
|
38
|
-
})
|
|
39
|
-
Cookies.set('cookie_control_consent', 'true', { expires })
|
|
40
|
-
|
|
41
|
-
consent.value = true
|
|
42
|
-
|
|
43
|
-
if (process.client) {
|
|
44
|
-
setHead(/* nuxtApp, */ enabled.value)
|
|
45
|
-
// callAcceptedFunctions(nuxtApp, enabled.value)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const useResolveTranslatable = (locale = LOCALE_DEFAULT) => {
|
|
50
|
-
return (translatable: Translatable) =>
|
|
51
|
-
resolveTranslatable(translatable, locale)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const resolveTranslatable = (translatable: Translatable, locale?: Locale) => {
|
|
55
|
-
if (typeof translatable === 'string') return translatable
|
|
56
|
-
|
|
57
|
-
if (!locale)
|
|
58
|
-
throw new Error('No locale given for translatable that is not a string.')
|
|
59
|
-
|
|
60
|
-
const result = translatable[locale]
|
|
61
|
-
|
|
62
|
-
if (!result)
|
|
63
|
-
throw new Error(`Could not get translation for locale ${locale}.`)
|
|
64
|
-
|
|
65
|
-
return result
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const useSetConsent = () => {
|
|
69
|
-
const { isConsentGiven, moduleOptions, cookiesEnabled, cookiesEnabledIds } =
|
|
70
|
-
useCookieControl()
|
|
71
|
-
// const nuxtApp = useNuxtApp()
|
|
72
|
-
return () =>
|
|
73
|
-
setConsent({
|
|
74
|
-
isInit: false,
|
|
75
|
-
// nuxtApp,
|
|
76
|
-
isConsentGiven,
|
|
77
|
-
moduleOptions,
|
|
78
|
-
cookiesEnabled,
|
|
79
|
-
cookiesEnabledIds,
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const setConsent = ({
|
|
84
|
-
isInit = false,
|
|
85
|
-
// nuxtApp,
|
|
86
|
-
isConsentGiven,
|
|
87
|
-
moduleOptions,
|
|
88
|
-
cookiesEnabled,
|
|
89
|
-
cookiesEnabledIds,
|
|
90
|
-
}: {
|
|
91
|
-
isInit: boolean
|
|
92
|
-
// nuxtApp: NuxtApp
|
|
93
|
-
isConsentGiven: Ref<boolean | undefined>
|
|
94
|
-
moduleOptions: ModuleOptions
|
|
95
|
-
cookiesEnabled: Ref<Cookie[]>
|
|
96
|
-
cookiesEnabledIds: Ref<string[]>
|
|
97
|
-
}) => {
|
|
98
|
-
isConsentGiven.value = Cookies.get('cookie_control_consent') === 'true'
|
|
99
|
-
cookiesEnabled.value = []
|
|
100
|
-
cookiesEnabledIds.value = []
|
|
101
|
-
|
|
102
|
-
if (isConsentGiven.value) {
|
|
103
|
-
const enabledFromCookie = Cookies.get('cookie_control_enabled_cookies')
|
|
104
|
-
|
|
105
|
-
cookiesEnabled.value.push(
|
|
106
|
-
...moduleOptions.cookies.optional.filter((cookieOptional) => {
|
|
107
|
-
return enabledFromCookie?.includes(getCookieId(cookieOptional))
|
|
108
|
-
})
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (moduleOptions.cookies?.necessary)
|
|
113
|
-
cookiesEnabled.value.push(
|
|
114
|
-
...moduleOptions.cookies.necessary.filter((c) => {
|
|
115
|
-
return c.src // || c.onAccept
|
|
116
|
-
})
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
cookiesEnabledIds.value = cookiesEnabled.value.map((cookieEnabled) =>
|
|
120
|
-
getCookieId(cookieEnabled)
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
if (process.client && !isInit) {
|
|
124
|
-
setHead(/* nuxtApp, */ cookiesEnabled.value)
|
|
125
|
-
clearCookies(
|
|
126
|
-
// nuxtApp,
|
|
127
|
-
cookiesEnabledIds.value,
|
|
128
|
-
moduleOptions.cookies.optional
|
|
129
|
-
)
|
|
130
|
-
// callAcceptedFunctions(nuxtApp, cookiesEnabled.value)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export const getCookieId = (cookie: Cookie) =>
|
|
135
|
-
cookie.id || slugify(resolveTranslatable(cookie.name))
|
|
136
|
-
|
|
137
|
-
export const clearCookies = (
|
|
138
|
-
// nuxtApp: NuxtApp,
|
|
139
|
-
cookiesEnabledIds: string[],
|
|
140
|
-
cookiesOptional: Cookie[]
|
|
141
|
-
) => {
|
|
142
|
-
const cookiesDisabled = cookiesOptional.filter(
|
|
143
|
-
(cookieOptional) => !cookiesEnabledIds.includes(getCookieId(cookieOptional))
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
for (const cookieDisabled of cookiesDisabled) {
|
|
147
|
-
// if (cookieDisabled.onDecline) cookieDisabled.onDecline().call(nuxtApp)
|
|
148
|
-
if (!cookieDisabled.targetCookieIds) continue
|
|
149
|
-
|
|
150
|
-
for (const cookieDisabledId of cookieDisabled.targetCookieIds) {
|
|
151
|
-
Cookies.remove(cookieDisabledId)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (cookieDisabled.src) {
|
|
155
|
-
for (const s of [
|
|
156
|
-
...document.head.querySelectorAll(
|
|
157
|
-
`script[src="${cookieDisabled.src}"]`
|
|
158
|
-
),
|
|
159
|
-
]) {
|
|
160
|
-
s.parentNode?.removeChild(s)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export const setHead = (/* nuxtApp: NuxtApp, */ enabledCookies: Cookie[]) => {
|
|
167
|
-
const head = document.getElementsByTagName('head')[0]
|
|
168
|
-
|
|
169
|
-
for (const cookieEnabled of enabledCookies) {
|
|
170
|
-
if (!cookieEnabled.src) continue
|
|
171
|
-
|
|
172
|
-
const script = document.createElement('script')
|
|
173
|
-
script.src = cookieEnabled.src
|
|
174
|
-
// script.addEventListener('load', () => {
|
|
175
|
-
// if (cookieEnabled.onAccept) cookieEnabled.onAccept().call(nuxtApp)
|
|
176
|
-
// })
|
|
177
|
-
head.appendChild(script)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// export const callAcceptedFunctions = (
|
|
182
|
-
// nuxtApp: NuxtApp,
|
|
183
|
-
// cookiesEnabled: Cookie[]
|
|
184
|
-
// ) => {
|
|
185
|
-
// for (const cookieEnabled of cookiesEnabled) {
|
|
186
|
-
// if (!cookieEnabled.onAccept) continue
|
|
187
|
-
|
|
188
|
-
// cookieEnabled.onAccept().call(nuxtApp)
|
|
189
|
-
// }
|
|
190
|
-
// }
|
package/dist/runtime/plugin.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { setConsent } from './methods'
|
|
2
|
-
import { Cookie, State } from './types'
|
|
3
|
-
|
|
4
|
-
import moduleOptions from '#build/cookie-control-options'
|
|
5
|
-
|
|
6
|
-
export default defineNuxtPlugin((_nuxtApp) => {
|
|
7
|
-
// const nuxtApp = useNuxtApp()
|
|
8
|
-
const isConsentGiven = ref<boolean>()
|
|
9
|
-
const cookiesEnabled = ref<Cookie[]>([])
|
|
10
|
-
const cookiesEnabledIds = ref<string[]>([])
|
|
11
|
-
const isModalActive = ref<boolean>()
|
|
12
|
-
|
|
13
|
-
const state = {
|
|
14
|
-
isConsentGiven,
|
|
15
|
-
cookiesEnabled,
|
|
16
|
-
cookiesEnabledIds,
|
|
17
|
-
isModalActive,
|
|
18
|
-
moduleOptions,
|
|
19
|
-
} as State
|
|
20
|
-
|
|
21
|
-
setConsent({
|
|
22
|
-
isInit: !process.client,
|
|
23
|
-
// nuxtApp,
|
|
24
|
-
isConsentGiven,
|
|
25
|
-
moduleOptions,
|
|
26
|
-
cookiesEnabled,
|
|
27
|
-
cookiesEnabledIds,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
provide: {
|
|
32
|
-
cookies: state,
|
|
33
|
-
},
|
|
34
|
-
}
|
|
35
|
-
})
|
package/dist/runtime/types.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Ref } from 'vue'
|
|
2
|
-
|
|
3
|
-
import en from './locale/en'
|
|
4
|
-
|
|
5
|
-
export enum Locale {
|
|
6
|
-
AR = 'ar',
|
|
7
|
-
DE = 'de',
|
|
8
|
-
EN = 'en',
|
|
9
|
-
ES = 'es',
|
|
10
|
-
FR = 'fr',
|
|
11
|
-
HR = 'hr',
|
|
12
|
-
HU = 'hu',
|
|
13
|
-
IT = 'it',
|
|
14
|
-
JA = 'ja',
|
|
15
|
-
NL = 'nl',
|
|
16
|
-
NO = 'no',
|
|
17
|
-
PT = 'pt',
|
|
18
|
-
RU = 'ru',
|
|
19
|
-
UK = 'uk',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>
|
|
23
|
-
|
|
24
|
-
export type Translatable = string | PartialRecord<Locale, string>
|
|
25
|
-
|
|
26
|
-
export enum CookieType {
|
|
27
|
-
NECESSARY = 'necessary',
|
|
28
|
-
OPTIONAL = 'optional',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface Cookie {
|
|
32
|
-
description?: Translatable
|
|
33
|
-
id?: string
|
|
34
|
-
name: Translatable
|
|
35
|
-
// onAccept?: Function
|
|
36
|
-
// onDecline?: Function
|
|
37
|
-
src?: string
|
|
38
|
-
targetCookieIds?: string[]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface LocaleStrings {
|
|
42
|
-
acceptAll: string
|
|
43
|
-
acceptNecessary: string
|
|
44
|
-
barDescription: string
|
|
45
|
-
barTitle: string
|
|
46
|
-
blockedIframe: string
|
|
47
|
-
close: string
|
|
48
|
-
declineAll: string
|
|
49
|
-
functional: string
|
|
50
|
-
here: string
|
|
51
|
-
manageCookies: string
|
|
52
|
-
necessary: string
|
|
53
|
-
optional: string
|
|
54
|
-
save: string
|
|
55
|
-
unsaved: string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface ModuleOptions {
|
|
59
|
-
barPosition?:
|
|
60
|
-
| 'top-left'
|
|
61
|
-
| 'top-right'
|
|
62
|
-
| 'top-full'
|
|
63
|
-
| 'bottom-left'
|
|
64
|
-
| 'bottom-right'
|
|
65
|
-
| 'bottom-full'
|
|
66
|
-
colors?: false | Record<string, any>
|
|
67
|
-
cookies: {
|
|
68
|
-
necessary: Cookie[]
|
|
69
|
-
optional: Cookie[]
|
|
70
|
-
}
|
|
71
|
-
isAcceptNecessaryButtonEnabled?: boolean
|
|
72
|
-
isControlButtonEnabled?: boolean
|
|
73
|
-
isCssEnabled?: boolean
|
|
74
|
-
isCssPolyfillEnabled?: boolean
|
|
75
|
-
isDashInDescriptionEnabled?: boolean
|
|
76
|
-
isIframeBlocked?: boolean | { initialState: boolean }
|
|
77
|
-
domain?: string
|
|
78
|
-
locales: Locale[]
|
|
79
|
-
localeTexts: PartialRecord<Locale, LocaleStrings>
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const DEFAULTS: Required<ModuleOptions> = {
|
|
83
|
-
barPosition: 'bottom-full',
|
|
84
|
-
colors: {
|
|
85
|
-
barBackground: '#000',
|
|
86
|
-
barButtonBackground: '#fff',
|
|
87
|
-
barButtonColor: '#000',
|
|
88
|
-
barButtonHoverBackground: '#333',
|
|
89
|
-
barButtonHoverColor: '#fff',
|
|
90
|
-
barTextColor: '#fff',
|
|
91
|
-
checkboxActiveBackground: '#000',
|
|
92
|
-
checkboxActiveCircleBackground: '#fff',
|
|
93
|
-
checkboxDisabledBackground: '#ddd',
|
|
94
|
-
checkboxDisabledCircleBackground: '#fff',
|
|
95
|
-
checkboxInactiveBackground: '#000',
|
|
96
|
-
checkboxInactiveCircleBackground: '#fff',
|
|
97
|
-
controlButtonBackground: '#fff',
|
|
98
|
-
controlButtonHoverBackground: '#000',
|
|
99
|
-
controlButtonIconColor: '#000',
|
|
100
|
-
controlButtonIconHoverColor: '#fff',
|
|
101
|
-
modalBackground: '#fff',
|
|
102
|
-
modalButtonBackground: '#000',
|
|
103
|
-
modalButtonColor: '#fff',
|
|
104
|
-
modalButtonHoverBackground: '#333',
|
|
105
|
-
modalButtonHoverColor: '#fff',
|
|
106
|
-
modalOverlay: '#000',
|
|
107
|
-
modalOverlayOpacity: 0.8,
|
|
108
|
-
modalTextColor: '#000',
|
|
109
|
-
modalUnsavedColor: '#fff',
|
|
110
|
-
},
|
|
111
|
-
cookies: {
|
|
112
|
-
necessary: [],
|
|
113
|
-
optional: [],
|
|
114
|
-
},
|
|
115
|
-
isAcceptNecessaryButtonEnabled: true,
|
|
116
|
-
isControlButtonEnabled: true,
|
|
117
|
-
isCssEnabled: true,
|
|
118
|
-
isCssPolyfillEnabled: true,
|
|
119
|
-
isDashInDescriptionEnabled: true,
|
|
120
|
-
isIframeBlocked: false,
|
|
121
|
-
domain: '',
|
|
122
|
-
locales: [Locale.EN],
|
|
123
|
-
localeTexts: { en },
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface State {
|
|
127
|
-
cookiesEnabled: Ref<Cookie[]>
|
|
128
|
-
cookiesEnabledIds: Ref<string[]>
|
|
129
|
-
isConsentGiven: Ref<boolean>
|
|
130
|
-
isModalActive: Ref<boolean>
|
|
131
|
-
moduleOptions: ModuleOptions
|
|
132
|
-
}
|