2023-03-21 12:05:24 +00:00
|
|
|
<script>
|
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-05-10 11:49:54 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2023-03-21 12:05:24 +00:00
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
const inlineStyles = {
|
|
|
|
hiddenAccessible: {
|
|
|
|
border: '0',
|
|
|
|
clip: 'rect(0 0 0 0)',
|
|
|
|
height: '1px',
|
|
|
|
margin: '-1px',
|
|
|
|
overflow: 'hidden',
|
|
|
|
padding: '0',
|
|
|
|
position: 'absolute',
|
|
|
|
width: '1px'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-21 12:05:24 +00:00
|
|
|
export default {
|
2023-03-31 21:51:41 +00:00
|
|
|
name: 'BaseComponent',
|
2023-03-21 12:05:24 +00:00
|
|
|
props: {
|
|
|
|
pt: {
|
|
|
|
type: Object,
|
2023-04-26 08:57:02 +00:00
|
|
|
default: undefined
|
2023-05-16 10:29:56 +00:00
|
|
|
},
|
|
|
|
unstyled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: undefined
|
2023-03-21 12:05:24 +00:00
|
|
|
}
|
|
|
|
},
|
2023-05-30 09:59:17 +00:00
|
|
|
inject: {
|
|
|
|
$parentInstance: {
|
|
|
|
default: undefined
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
isUnstyled: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newValue) {
|
|
|
|
!newValue && this.$options.css && this.$css.loadStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-03-21 12:05:24 +00:00
|
|
|
methods: {
|
2023-06-08 11:16:48 +00:00
|
|
|
_getHostInstance(instance) {
|
|
|
|
return instance ? (this.$options.hostName ? (instance.$.type.name === this.$options.hostName ? instance : this._getHostInstance(instance.$parentInstance)) : instance.$parentInstance) : undefined;
|
|
|
|
},
|
2023-05-25 12:47:40 +00:00
|
|
|
_getOptionValue(options, key = '', params = {}) {
|
2023-05-23 21:10:36 +00:00
|
|
|
const fKeys = ObjectUtils.convertToFlatCase(key).split('.');
|
|
|
|
const fKey = fKeys.shift();
|
2023-04-03 00:12:25 +00:00
|
|
|
|
2023-05-23 23:40:14 +00:00
|
|
|
return fKey
|
|
|
|
? ObjectUtils.isObject(options)
|
2023-05-25 12:47:40 +00:00
|
|
|
? this._getOptionValue(ObjectUtils.getItemValue(options[Object.keys(options).find((k) => ObjectUtils.convertToFlatCase(k) === fKey) || ''], params), fKeys.join('.'), params)
|
2023-05-23 23:40:14 +00:00
|
|
|
: undefined
|
|
|
|
: ObjectUtils.getItemValue(options, params);
|
2023-04-03 00:12:25 +00:00
|
|
|
},
|
2023-06-08 11:16:48 +00:00
|
|
|
_getPTValue(obj = {}, key = '', params = {}, searchInDefaultPT = true) {
|
2023-05-24 00:59:42 +00:00
|
|
|
const datasetPrefix = 'data-pc-';
|
2023-05-25 12:47:40 +00:00
|
|
|
const self = this._getOptionValue(obj, key, params);
|
2023-06-08 11:16:48 +00:00
|
|
|
const globalPT = searchInDefaultPT ? this._getOptionValue(this.defaultPT, key, params) : undefined;
|
2023-05-24 00:59:42 +00:00
|
|
|
const merged = mergeProps(self, globalPT, {
|
2023-05-24 01:03:54 +00:00
|
|
|
...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.convertToFlatCase(this.$.type.name) }),
|
2023-05-24 00:59:42 +00:00
|
|
|
[`${datasetPrefix}section`]: ObjectUtils.convertToFlatCase(key)
|
|
|
|
});
|
2023-04-25 11:36:01 +00:00
|
|
|
|
2023-05-10 11:49:54 +00:00
|
|
|
return merged;
|
|
|
|
/*
|
|
|
|
* @todo: The 'class' option in self can always be more powerful to style the component easily.
|
|
|
|
*
|
|
|
|
* return self && self['class'] ? { ...merged, ...{ class: self['class'] } } : merged;
|
|
|
|
*/
|
2023-04-25 11:36:01 +00:00
|
|
|
},
|
2023-03-21 12:05:24 +00:00
|
|
|
ptm(key = '', params = {}) {
|
2023-05-25 12:47:40 +00:00
|
|
|
return this._getPTValue(this.pt, key, { props: this.$props, state: this.$data, ...params });
|
2023-03-22 12:11:03 +00:00
|
|
|
},
|
|
|
|
ptmo(obj = {}, key = '', params = {}) {
|
2023-06-08 11:16:48 +00:00
|
|
|
return this._getPTValue(obj, key, params, false);
|
2023-05-19 10:32:44 +00:00
|
|
|
},
|
2023-05-19 11:14:50 +00:00
|
|
|
cx(key = '', params = {}) {
|
2023-05-30 09:59:17 +00:00
|
|
|
return !this.isUnstyled ? this._getOptionValue(this.$css.classes, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params }) : undefined;
|
2023-05-23 09:15:04 +00:00
|
|
|
},
|
2023-05-19 11:14:50 +00:00
|
|
|
sx(key = '', when = true, params = {}) {
|
2023-05-19 10:32:44 +00:00
|
|
|
if (when) {
|
2023-05-30 09:59:17 +00:00
|
|
|
const self = this._getOptionValue(this.$css.inlineStyles, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params });
|
|
|
|
const base = this._getOptionValue(inlineStyles, key, { instance: this, props: this.$props, state: this.$data, parentInstance: this.$parentInstance, ...params });
|
2023-05-19 10:32:44 +00:00
|
|
|
|
|
|
|
return [base, self];
|
|
|
|
}
|
|
|
|
|
2023-06-07 13:50:56 +00:00
|
|
|
return undefined;
|
2023-03-21 12:05:24 +00:00
|
|
|
}
|
2023-05-10 11:49:54 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
defaultPT() {
|
2023-05-30 09:59:17 +00:00
|
|
|
return this._getOptionValue(this.$primevue.config.pt, this.$.type.name, { instance: this });
|
2023-05-16 10:29:56 +00:00
|
|
|
},
|
|
|
|
isUnstyled() {
|
|
|
|
return this.unstyled !== undefined ? this.unstyled : this.$primevue.config.unstyled;
|
2023-05-30 09:59:17 +00:00
|
|
|
},
|
|
|
|
$css() {
|
2023-06-08 11:16:48 +00:00
|
|
|
return { classes: undefined, inlineStyles: undefined, loadStyle: () => {}, ...(this._getHostInstance(this) || {}).$css, ...this.$options.css };
|
2023-05-10 11:49:54 +00:00
|
|
|
}
|
2023-03-21 12:05:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|