Theming API: update `mergeKeys` method for presets
parent
51110b585a
commit
9bdabd8530
|
@ -49,6 +49,9 @@ export default {
|
|||
handler(newValue) {
|
||||
if (newValue) {
|
||||
this._loadScopedThemeStyles(newValue);
|
||||
this._themeChangeListener(() => this._loadScopedThemeStyles(newValue));
|
||||
} else {
|
||||
this._unloadScopedThemeStyles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +94,7 @@ export default {
|
|||
this._hook('onBeforeUnmount');
|
||||
},
|
||||
unmounted() {
|
||||
this.scopedStyleEl?.value?.remove();
|
||||
this._unloadScopedThemeStyles();
|
||||
this._hook('onUnmounted');
|
||||
},
|
||||
methods: {
|
||||
|
@ -185,6 +188,9 @@ export default {
|
|||
|
||||
this.scopedStyleEl = scopedStyle.el;
|
||||
},
|
||||
_unloadScopedThemeStyles() {
|
||||
this.scopedStyleEl?.value?.remove();
|
||||
},
|
||||
_themeChangeListener(callback = () => {}) {
|
||||
Base.clearLoadedStyleNames();
|
||||
ThemeService.on('theme:change', callback);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import Theme, { SharedUtils } from 'primevue/themes';
|
||||
|
||||
export default (preset1, preset2) => {
|
||||
const VARIABLE = Theme.defaults.variable;
|
||||
const newPreset = SharedUtils.object.mergeKeysByRegex(preset1, preset2, VARIABLE.excludedKeyRegex);
|
||||
const newPreset = SharedUtils.object.mergeKeys(preset1, preset2);
|
||||
|
||||
Theme.setPreset(newPreset);
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import Theme, { SharedUtils } from 'primevue/themes';
|
||||
|
||||
export default (preset) => {
|
||||
const VARIABLE = Theme.defaults.variable;
|
||||
const newPreset = SharedUtils.object.mergeKeysByRegex(Theme.getPreset(), preset, VARIABLE.excludedKeyRegex);
|
||||
const newPreset = SharedUtils.object.mergeKeys(Theme.getPreset(), preset);
|
||||
|
||||
Theme.setPreset(newPreset);
|
||||
|
||||
|
|
|
@ -61,6 +61,19 @@ export default {
|
|||
|
||||
return mergedObj;
|
||||
},
|
||||
mergeKeys(target = {}, source = {}) {
|
||||
const mergedObj = { ...target };
|
||||
|
||||
Object.keys(source).forEach((key) => {
|
||||
if (this.isObject(source[key]) && key in target && this.isObject(target[key])) {
|
||||
mergedObj[key] = this.mergeKeys(target[key], source[key]);
|
||||
} else {
|
||||
mergedObj[key] = source[key];
|
||||
}
|
||||
});
|
||||
|
||||
return mergedObj;
|
||||
},
|
||||
getItemValue(obj, ...params) {
|
||||
return this.isFunction(obj) ? obj(...params) : obj;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue