Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set styles in node #7064

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: set styles in node
DEMAxx committed Dec 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 341cebd660b76541ef5db969198f9005648751de
5 changes: 4 additions & 1 deletion apps/showcase/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -53,7 +53,10 @@ export default defineNuxtConfig({
}
: {
autoImport: true, // When enabled, the module automatically imports PrimeVue components and directives used throughout the application.
importTheme: { from: '@/themes/app-theme.js' }
importTheme: { from: '@/themes/app-theme.js' },
options: {
applicationNode: '__nuxt'
}
},
app: {
baseURL: baseUrl,
2 changes: 1 addition & 1 deletion packages/core/src/basedirective/BaseDirective.js
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ const BaseDirective = {
},
_loadStyles: (el, binding, vnode) => {
const config = BaseDirective._getConfig(binding, vnode);
const useStyleOptions = { nonce: config?.csp?.nonce };
const useStyleOptions = { nonce: config?.csp?.nonce, applicationNode: config?.applicationNode };

BaseDirective._loadCoreStyles(el.$instance, useStyleOptions);
BaseDirective._loadThemeStyles(el.$instance, useStyleOptions);
1 change: 1 addition & 0 deletions packages/core/src/config/PrimeVue.d.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export interface PrimeVueConfiguration {
zIndex?: PrimeVueZIndexOptions;
theme?: any;
unstyled?: boolean;
applicationNode?: string | undefined;
pt?: any;
ptOptions?: any;
csp?: PrimeVueCSPOptions;
1 change: 1 addition & 0 deletions packages/core/src/config/PrimeVue.js
Original file line number Diff line number Diff line change
@@ -144,6 +144,7 @@ export const defaultOptions = {
theme: undefined,
unstyled: false,
pt: undefined,
applicationNode: undefined,
ptOptions: {
mergeSections: true,
mergeProps: false
1 change: 1 addition & 0 deletions packages/core/src/usestyle/UseStyle.d.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ export interface StyleOptions {
media?: string;
nonce?: string;
props?: any;
applicationNode?: string
}

export interface Style {
17 changes: 15 additions & 2 deletions packages/core/src/usestyle/UseStyle.js
Original file line number Diff line number Diff line change
@@ -31,9 +31,16 @@ export function useStyle(css, options = {}) {
onMounted: onStyleMounted = undefined,
onUpdated: onStyleUpdated = undefined,
onLoad: onStyleLoaded = undefined,
props = {}
props = {},
applicationNode = undefined
} = options;

let node;

if(applicationNode){
node = document.getElementById(applicationNode);
}

let stop = () => {};

/* @todo: Improve _options params */
@@ -54,7 +61,13 @@ export function useStyle(css, options = {}) {
media,
nonce: _nonce
});
first ? document.head.prepend(styleRef.value) : document.head.appendChild(styleRef.value);

if(applicationNode){
first ? node.prepend(styleRef.value) : node.appendChild(styleRef.value);
} else {
first ? document.head.prepend(styleRef.value) : document.head.appendChild(styleRef.value)
}

setAttribute(styleRef.value, 'data-primevue-style-id', _name);
setAttributes(styleRef.value, _styleProps);
styleRef.value.onload = (event) => onStyleLoaded?.(event, { name: _name });
812 changes: 382 additions & 430 deletions pnpm-lock.yaml

Large diffs are not rendered by default.