Compare commits

...

14 Commits

Author SHA1 Message Date
HugoRCD
c326180f15 Merge remote-tracking branch 'origin/v3' into fix/3394 2025-05-20 14:58:39 +02:00
HugoRCD
d75093a160 revert 2025-05-19 16:05:36 +02:00
HugoRCD
47ed1e0f74 test 2025-05-19 15:56:18 +02:00
HugoRCD
d6a3a65b8e up 2025-05-19 14:14:34 +02:00
HugoRCD
a81d0e55c7 up 2025-05-19 13:35:23 +02:00
HugoRCD
5b172b0fb3 test 2025-05-19 12:48:33 +02:00
HugoRCD
fbf7475e0d up 2025-05-19 12:27:38 +02:00
HugoRCD
0f90645c84 up 2025-05-19 11:31:38 +02:00
HugoRCD
33193d782d up 2025-05-19 11:30:40 +02:00
HugoRCD
d1f2b50033 Merge remote-tracking branch 'origin/v3' into fix/3394 2025-05-19 11:26:00 +02:00
HugoRCD
bd75d2d184 up 2025-05-19 11:25:57 +02:00
HugoRCD
cabad480f9 test 2025-05-19 11:02:36 +02:00
HugoRCD
91d06d4d51 up 2025-05-19 10:49:49 +02:00
HugoRCD
f1128c2450 feat: implement csp, sty-src with nonce 2025-05-19 10:37:46 +02:00
4 changed files with 35 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import icons from './theme/icons'
import { pick } from './runtime/utils'
export const getDefaultUiConfig = (colors?: string[]) => ({
export const getDefaultUiConfig = (colors?: string[], csp?: { nonce?: string }) => ({
colors: pick({
primary: 'green',
secondary: 'blue',
@@ -12,7 +12,10 @@ export const getDefaultUiConfig = (colors?: string[]) => ({
error: 'red',
neutral: 'slate'
}, [...(colors || []), 'neutral' as any]),
icons
icons,
csp: csp || {
nonce: ''
}
})
export const defaultOptions = {
@@ -22,6 +25,9 @@ export const defaultOptions = {
theme: {
colors: undefined,
transitions: true
},
csp: {
nonce: ''
}
}

View File

@@ -28,6 +28,19 @@ export interface ModuleOptions {
*/
colorMode?: boolean
/**
* Configure Content Security Policy for Nuxt UI
* @defaultValue `{ nonce: '' }`
* @link https://ui.nuxt.com/getting-started/installation/nuxt#csp
*/
csp?: {
/**
* Enable nonce for inline styles.
* @defaultValue ``
*/
nonce?: string
}
/**
* Customize how the theme is generated
* @link https://ui.nuxt.com/getting-started/theme
@@ -70,7 +83,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.alias['#ui'] = resolve('./runtime')
nuxt.options.appConfig.ui = defu(nuxt.options.appConfig.ui || {}, getDefaultUiConfig(options.theme.colors))
nuxt.options.appConfig.ui = defu(nuxt.options.appConfig.ui || {}, getDefaultUiConfig(options.theme.colors, options.csp))
// Isolate root node from portaled components
nuxt.options.app.rootAttrs = nuxt.options.app.rootAttrs || {}

View File

@@ -23,6 +23,8 @@ export default defineNuxtPlugin(() => {
const appConfig = useAppConfig()
const nuxtApp = useNuxtApp()
const nonce = computed(() => appConfig.ui?.csp?.nonce)
const root = computed(() => {
const { neutral, ...colors } = appConfig.ui.colors
@@ -44,7 +46,8 @@ export default defineNuxtPlugin(() => {
style: [{
innerHTML: () => root.value,
tagPriority: -2,
id: 'nuxt-ui-colors'
id: 'nuxt-ui-colors',
...(nonce.value ? { nonce: nonce.value } : {})
}]
}
@@ -54,10 +57,15 @@ export default defineNuxtPlugin(() => {
style.innerHTML = root.value
style.setAttribute('data-nuxt-ui-colors', '')
if (nonce.value) {
style.setAttribute('nonce', nonce.value)
}
document.head.appendChild(style)
headData.script = [{
innerHTML: 'document.head.removeChild(document.querySelector(\'[data-nuxt-ui-colors]\'))'
innerHTML: 'document.head.removeChild(document.querySelector(\'[data-nuxt-ui-colors]\'))',
...(nonce.value ? { nonce: nonce.value } : {})
}]
}

View File

@@ -165,6 +165,9 @@ type AppConfigUI = {
}
icons?: Partial<typeof icons>
tv?: typeof defaultConfig
csp?: {
nonce?: string
}
} & TVConfig<typeof ui>
declare module '@nuxt/schema' {