This commit is contained in:
HugoRCD
2025-05-19 12:24:08 +02:00
parent 0f90645c84
commit fbf7475e0d
3 changed files with 4 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import icons from './theme/icons'
import { pick } from './runtime/utils' import { pick } from './runtime/utils'
export const getDefaultUiConfig = (colors?: string[]) => ({ export const getDefaultUiConfig = (colors?: string[], csp?: { nonce?: string }) => ({
colors: pick({ colors: pick({
primary: 'green', primary: 'green',
secondary: 'blue', secondary: 'blue',
@@ -13,7 +13,7 @@ export const getDefaultUiConfig = (colors?: string[]) => ({
neutral: 'slate' neutral: 'slate'
}, [...(colors || []), 'neutral' as any]), }, [...(colors || []), 'neutral' as any]),
icons, icons,
csp: { csp: csp || {
nonce: '' nonce: ''
} }
}) })

View File

@@ -83,8 +83,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.alias['#ui'] = resolve('./runtime') 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))
nuxt.options.appConfig.ui.csp = defu(nuxt.options.appConfig.ui.csp || {}, options.csp)
// Isolate root node from portaled components // Isolate root node from portaled components
nuxt.options.app.rootAttrs = nuxt.options.app.rootAttrs || {} nuxt.options.app.rootAttrs = nuxt.options.app.rootAttrs || {}

View File

@@ -23,7 +23,7 @@ export default defineNuxtPlugin(() => {
const appConfig = useAppConfig() const appConfig = useAppConfig()
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
const nonce = computed(() => (appConfig.ui as any)?.csp?.nonce as string | undefined) const nonce = computed(() => appConfig.ui?.csp?.nonce)
const root = computed(() => { const root = computed(() => {
const { neutral, ...colors } = appConfig.ui.colors const { neutral, ...colors } = appConfig.ui.colors
@@ -42,7 +42,6 @@ export default defineNuxtPlugin(() => {
}) })
// Head // Head
console.log('head nonce', nonce.value)
const headData: UseHeadInput = { const headData: UseHeadInput = {
style: [{ style: [{
innerHTML: () => root.value, innerHTML: () => root.value,
@@ -59,7 +58,6 @@ export default defineNuxtPlugin(() => {
style.innerHTML = root.value style.innerHTML = root.value
style.setAttribute('data-nuxt-ui-colors', '') style.setAttribute('data-nuxt-ui-colors', '')
console.log('SPA nonce', nonce.value)
if (nonce.value) { if (nonce.value) {
style.setAttribute('nonce', nonce.value) style.setAttribute('nonce', nonce.value)
} }