mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 00:42:36 +00:00
Refactor #5502
This commit is contained in:
parent
5671752903
commit
e896552ccb
5 changed files with 33 additions and 20 deletions
|
@ -15,7 +15,7 @@ export default defineNuxtModule({
|
|||
layerOrder: 'tailwind-base, primevue, tailwind-utilities',
|
||||
importPT: undefined,
|
||||
importTheme: undefined,
|
||||
unstyled: false,
|
||||
unstyled: undefined,
|
||||
options: {},
|
||||
components: {
|
||||
prefix: '',
|
||||
|
@ -41,7 +41,7 @@ export default defineNuxtModule({
|
|||
const resolver = createResolver(import.meta.url);
|
||||
const registered = register(moduleOptions);
|
||||
const { importPT, importTheme, options, unstyled } = moduleOptions;
|
||||
const hasTheme = importTheme && !unstyled;
|
||||
const hasTheme = importTheme && unstyled !== true && !options.unstyled;
|
||||
|
||||
nuxt.options.runtimeConfig.public.primevue = {
|
||||
...moduleOptions,
|
||||
|
@ -103,7 +103,7 @@ export default defineNuxtPlugin(({ vueApp }) => {
|
|||
const pt = ${importPT ? `{ pt: ${importPT.as} }` : `{}`};
|
||||
const theme = ${hasTheme ? `{ theme: ${importTheme.as} }` : `{}`};
|
||||
|
||||
usePrimeVue && vueApp.use(${unstyled ? 'PrimeVueUnstyled' : 'PrimeVueStyled'}, { ...options, ...pt, ...theme });
|
||||
usePrimeVue && vueApp.use(${unstyled === true ? 'PrimeVueUnstyled' : unstyled === false ? 'PrimeVueStyled' : 'PrimeVue'}, { ...options, ...pt, ...theme });
|
||||
${registered.services.map((service) => `vueApp.use(${service.as});`).join('\n')}
|
||||
${registered.directives.map((directive) => `vueApp.directive('${directive.name}', ${directive.as});`).join('\n')}
|
||||
});
|
||||
|
|
|
@ -17,20 +17,26 @@ function registerItems(items = [], options = {}, params) {
|
|||
});
|
||||
}
|
||||
|
||||
function registerConfig(resolvePath, unstyled = false) {
|
||||
return [
|
||||
unstyled
|
||||
? {
|
||||
name: 'PrimeVueUnstyled',
|
||||
as: 'PrimeVueUnstyled',
|
||||
from: resolvePath({ name: 'PrimeVueUnstyled', as: 'PrimeVueUnstyled', from: `primevue/unstyled`, type: 'config' })
|
||||
}
|
||||
: {
|
||||
name: 'PrimeVueStyled',
|
||||
as: 'PrimeVueStyled',
|
||||
from: resolvePath({ name: 'PrimeVueStyled', as: 'PrimeVueStyled', from: `primevue/styled`, type: 'config' })
|
||||
}
|
||||
];
|
||||
function registerConfig(resolvePath, moduleOptions) {
|
||||
const configs = [];
|
||||
|
||||
if (moduleOptions.unstyled === true) {
|
||||
configs.push({
|
||||
name: 'PrimeVueUnstyled',
|
||||
as: 'PrimeVueUnstyled',
|
||||
from: resolvePath({ name: 'PrimeVueUnstyled', as: 'PrimeVueUnstyled', from: `primevue/unstyled`, type: 'config' })
|
||||
});
|
||||
} else if (moduleOptions.unstyled === false) {
|
||||
configs.push({
|
||||
name: 'PrimeVueStyled',
|
||||
as: 'PrimeVueStyled',
|
||||
from: resolvePath({ name: 'PrimeVueStyled', as: 'PrimeVueStyled', from: `primevue/styled`, type: 'config' })
|
||||
});
|
||||
} else {
|
||||
configs.push({ name: 'PrimeVue', as: 'PrimeVue', from: resolvePath({ name: 'PrimeVue', as: 'PrimeVue', from: `primevue/config`, type: 'config' }) });
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
function registerComponents(resolvePath, options = {}) {
|
||||
|
@ -140,7 +146,7 @@ function registerInjectStylesAsString(moduleOptions) {
|
|||
export function register(moduleOptions) {
|
||||
const resolvePath = (resolveOptions) => Utils.object.getPath(moduleOptions.resolvePath, resolveOptions);
|
||||
|
||||
const config = registerConfig(resolvePath, moduleOptions.unstyled);
|
||||
const config = registerConfig(resolvePath, moduleOptions);
|
||||
const components = registerComponents(resolvePath, moduleOptions.components);
|
||||
const directives = registerDirectives(resolvePath, moduleOptions.directives);
|
||||
const composables = registerComposables(resolvePath, moduleOptions.composables);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue