mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-15 12:39:35 +01:00
Compare commits
14 Commits
feat/custo
...
fix/3394
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c326180f15 | ||
|
|
d75093a160 | ||
|
|
47ed1e0f74 | ||
|
|
d6a3a65b8e | ||
|
|
a81d0e55c7 | ||
|
|
5b172b0fb3 | ||
|
|
fbf7475e0d | ||
|
|
0f90645c84 | ||
|
|
33193d782d | ||
|
|
d1f2b50033 | ||
|
|
bd75d2d184 | ||
|
|
cabad480f9 | ||
|
|
91d06d4d51 | ||
|
|
f1128c2450 |
@@ -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: ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 || {}
|
||||
|
||||
@@ -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 } : {})
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
@@ -165,6 +165,9 @@ type AppConfigUI = {
|
||||
}
|
||||
icons?: Partial<typeof icons>
|
||||
tv?: typeof defaultConfig
|
||||
csp?: {
|
||||
nonce?: string
|
||||
}
|
||||
} & TVConfig<typeof ui>
|
||||
|
||||
declare module '@nuxt/schema' {
|
||||
|
||||
Reference in New Issue
Block a user