primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 12.7 kB
JavaScript
import t from"primevue/base/style";import{ObjectUtils as e}from"primevue/utils";import{mergeProps as n}from"vue";import{useStyle as o}from"primevue/usestyle";function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){s(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function s(t,e,n){var o;return(e="symbol"==i(o=u(e,"string"))?o:String(o))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e){if("object"!=i(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!=i(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var a=t.extend({name:"common",loadGlobalStyle:function(t){return o(t,l({name:"global"},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}))}});function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function p(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function v(t,e){return y(t)||g(t,e)||d(t,e)||f()}function f(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(t,e){if(t){if("string"==typeof t)return h(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(t,e):void 0}}function h(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function g(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,i,r,l,s=[],u=!0,a=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;u=!1}else for(;!(u=(o=r.call(n)).done)&&(s.push(o.value),s.length!==e);u=!0);}catch(t){a=!0,i=t}finally{try{if(!u&&null!=n.return&&(l=n.return(),Object(l)!==l))return}finally{if(a)throw i}}return s}}function y(t){if(Array.isArray(t))return t}function m(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?m(Object(n),!0).forEach((function(e){_(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function _(t,e,n){var o;return(e="symbol"==c(o=P(e,"string"))?o:String(o))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function P(t,e){if("object"!=c(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!=c(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var $={name:"BaseComponent",props:{pt:{type:Object,default:void 0},ptOptions:{type:Object,default:void 0},unstyled:{type:Boolean,default:void 0}},inject:{$parentInstance:{default:void 0}},watch:{isUnstyled:{immediate:!0,handler:function(t){var e,n;t||(a.loadStyle({nonce:null===(e=this.$config)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce}),this.$options.style&&this.$style.loadStyle({nonce:null===(n=this.$config)||void 0===n||null===(n=n.csp)||void 0===n?void 0:n.nonce}))}}},beforeCreate:function(){var t,e,n,o,i,r,l,s,u,a,c,p=null===(t=this.pt)||void 0===t?void 0:t._usept,v=p?null===(e=this.pt)||void 0===e||null===(e=e.originalValue)||void 0===e?void 0:e[this.$.type.name]:void 0;null===(o=(p?null===(n=this.pt)||void 0===n||null===(n=n.value)||void 0===n?void 0:n[this.$.type.name]:this.pt)||v)||void 0===o||null===(o=o.hooks)||void 0===o||null===(i=o.onBeforeCreate)||void 0===i||i.call(o);var f=null===(r=this.$config)||void 0===r||null===(r=r.pt)||void 0===r?void 0:r._usept,d=f?null===(l=this.$primevue)||void 0===l||null===(l=l.config)||void 0===l||null===(l=l.pt)||void 0===l?void 0:l.originalValue:void 0;null===(a=(f?null===(s=this.$primevue)||void 0===s||null===(s=s.config)||void 0===s||null===(s=s.pt)||void 0===s?void 0:s.value:null===(u=this.$primevue)||void 0===u||null===(u=u.config)||void 0===u?void 0:u.pt)||d)||void 0===a||null===(a=a[this.$.type.name])||void 0===a||null===(a=a.hooks)||void 0===a||null===(c=a.onBeforeCreate)||void 0===c||c.call(a)},created:function(){this._hook("onCreated")},beforeMount:function(){var e;t.loadStyle({nonce:null===(e=this.$config)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce}),this._loadGlobalStyles(),this._hook("onBeforeMount")},mounted:function(){this._hook("onMounted")},beforeUpdate:function(){this._hook("onBeforeUpdate")},updated:function(){this._hook("onUpdated")},beforeUnmount:function(){this._hook("onBeforeUnmount")},unmounted:function(){this._hook("onUnmounted")},methods:{_hook:function(t){if(!this.$options.hostName){var e=this._usePT(this._getPT(this.pt,this.$.type.name),this._getOptionValue,"hooks.".concat(t)),n=this._useDefaultPT(this._getOptionValue,"hooks.".concat(t));null==e||e(),null==n||n()}},_mergeProps:function(t){for(var o=arguments.length,i=new Array(o>1?o-1:0),r=1;r<o;r++)i[r-1]=arguments[r];return e.isFunction(t)?t.apply(void 0,i):n.apply(void 0,i)},_loadGlobalStyles:function(){var t,n=this._useGlobalPT(this._getOptionValue,"global.css",this.$params);e.isNotEmpty(n)&&a.loadGlobalStyle(n,{nonce:null===(t=this.$config)||void 0===t||null===(t=t.csp)||void 0===t?void 0:t.nonce})},_getHostInstance:function(t){return t?this.$options.hostName?t.$.type.name===this.$options.hostName?t:this._getHostInstance(t.$parentInstance):t.$parentInstance:void 0},_getPropValue:function(t){var e;return this[t]||(null===(e=this._getHostInstance(this))||void 0===e?void 0:e[t])},_getOptionValue:function(t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=e.toFlatCase(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"").split("."),i=o.shift();return i?e.isObject(t)?this._getOptionValue(e.getItemValue(t[Object.keys(t).find((function(t){return e.toFlatCase(t)===i}))||""],n),o.join("."),n):void 0:e.getItemValue(t,n)},_getPTValue:function(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],r=/./g.test(n)&&!!o[n.split(".")[0]],l=this._getPropValue("ptOptions")||(null===(t=this.$config)||void 0===t?void 0:t.ptOptions)||{},s=l.mergeSections,u=void 0===s||s,a=l.mergeProps,c=void 0!==a&&a,p=i?r?this._useGlobalPT(this._getPTClassValue,n,o):this._useDefaultPT(this._getPTClassValue,n,o):void 0,v=r?void 0:this._getPTSelf(e,this._getPTClassValue,n,b(b({},o),{},{global:p||{}})),f=this._getPTDatasets(n);return u||!u&&v?c?this._mergeProps(c,p,v,f):b(b(b({},p),v),f):b(b({},v),f)},_getPTSelf:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length,o=new Array(e>1?e-1:0),i=1;i<e;i++)o[i-1]=arguments[i];return n(this._usePT.apply(this,[this._getPT(t,this.$name)].concat(o)),this._usePT.apply(this,[this.$_attrsPT].concat(o)))},_getPTDatasets:function(){var t,n,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",i="data-pc-",r="root"===o&&e.isNotEmpty(null===(t=this.pt)||void 0===t?void 0:t["data-pc-section"]);return"transition"!==o&&b(b({},"root"===o&&b(_({},"".concat(i,"name"),e.toFlatCase(r?null===(n=this.pt)||void 0===n?void 0:n["data-pc-section"]:this.$.type.name)),r&&_({},"".concat(i,"extend"),e.toFlatCase(this.$.type.name)))),{},_({},"".concat(i,"section"),e.toFlatCase(o)))},_getPTClassValue:function(){var t=this._getOptionValue.apply(this,arguments);return e.isString(t)||e.isArray(t)?{class:t}:t},_getPT:function(t){var n=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2?arguments[2]:void 0,r=function(t){var r,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=i?i(t):t,u=e.toFlatCase(o),a=e.toFlatCase(n.$name);return null!==(r=l?u!==a?null==s?void 0:s[u]:void 0:null==s?void 0:s[u])&&void 0!==r?r:s};return null!=t&&t.hasOwnProperty("_usept")?{_usept:t._usept,originalValue:r(t.originalValue),value:r(t.value)}:r(t,!0)},_usePT:function(t,n,o,i){var r=function(t){return n(t,o,i)};if(null!=t&&t.hasOwnProperty("_usept")){var l,s=t._usept||(null===(l=this.$config)||void 0===l?void 0:l.ptOptions)||{},u=s.mergeSections,a=void 0===u||u,c=s.mergeProps,p=void 0!==c&&c,v=r(t.originalValue),f=r(t.value);if(void 0===v&&void 0===f)return;return e.isString(f)?f:e.isString(v)?v:a||!a&&f?p?this._mergeProps(p,v,f):b(b({},v),f):f}return r(t)},_useGlobalPT:function(t,e,n){return this._usePT(this.globalPT,t,e,n)},_useDefaultPT:function(t,e,n){return this._usePT(this.defaultPT,t,e,n)},ptm:function(){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._getPTValue(this.pt,arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",b(b({},this.$params),t))},ptmi:function(){return n(this.$_attrsNoPT,this.ptm(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}))},ptmo:function(){return this._getPTValue(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",b({instance:this},arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}),!1)},cx:function(){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.isUnstyled?void 0:this._getOptionValue(this.$style.classes,arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",b(b({},this.$params),t))},sx:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!(arguments.length>1&&void 0!==arguments[1])||arguments[1]){var n=this._getOptionValue(this.$style.inlineStyles,t,b(b({},this.$params),e));return[this._getOptionValue(a.inlineStyles,t,b(b({},this.$params),e)),n]}}},computed:{globalPT:function(){var t,n=this;return this._getPT(null===(t=this.$config)||void 0===t?void 0:t.pt,void 0,(function(t){return e.getItemValue(t,{instance:n})}))},defaultPT:function(){var t,n=this;return this._getPT(null===(t=this.$config)||void 0===t?void 0:t.pt,void 0,(function(t){return n._getOptionValue(t,n.$name,b({},n.$params))||e.getItemValue(t,b({},n.$params))}))},isUnstyled:function(){var t;return void 0!==this.unstyled?this.unstyled:null===(t=this.$config)||void 0===t?void 0:t.unstyled},$params:function(){var t=this._getHostInstance(this)||this.$parent;return{instance:this,props:this.$props,state:this.$data,attrs:this.$attrs,parent:{instance:t,props:null==t?void 0:t.$props,state:null==t?void 0:t.$data,attrs:null==t?void 0:t.$attrs},parentInstance:t}},$style:function(){return b(b({classes:void 0,inlineStyles:void 0,loadStyle:function(){},loadCustomStyle:function(){}},(this._getHostInstance(this)||{}).$style),this.$options.style)},$config:function(){var t;return null===(t=this.$primevue)||void 0===t?void 0:t.config},$name:function(){return this.$options.hostName||this.$.type.name},$_attrsPT:function(){return Object.entries(this.$attrs||{}).filter((function(t){var e=v(t,1)[0];return null==e?void 0:e.startsWith("pt:")})).reduce((function(t,e){var n,o=v(e,2),i=o[1],r=o[0].split(":"),l=(y(n=r)||p(n)||d(n)||f()).slice(1);return null==l||l.reduce((function(t,e,n,o){return!t[e]&&(t[e]=n===o.length-1?i:{}),t[e]}),t),t}),{})},$_attrsNoPT:function(){return Object.entries(this.$attrs||{}).filter((function(t){var e=v(t,1)[0];return!(null!=e&&e.startsWith("pt:"))})).reduce((function(t,e){var n=v(e,2);return t[n[0]]=n[1],t}),{})}}};export{$ as default};