UNPKG

accessibleprimevue

Version:

Note: This is the forked version of the Primefaces/PrimeVue repository. Since V3 has reached its EOL this is use to fix identified accessibility bugs in the v3 version of primevue. PrimeVue is an open source UI library for Vue featuring a rich set of 80+

2 lines (1 loc) 13.1 kB
"use strict";var t=require("primevue/base/style"),e=require("primevue/utils"),n=require("vue"),i=require("primevue/usestyle");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(t);function l(t){return l="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},l(t)}function s(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function u(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?s(Object(n),!0).forEach((function(e){a(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function a(t,e,n){var i;return(e="symbol"==l(i=c(e,"string"))?i:String(i))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t,e){if("object"!=l(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=l(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var p=r.default.extend({name:"common",loadGlobalStyle:function(t){return i.useStyle(t,u({name:"global"},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}))}});function v(t){return v="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},v(t)}function d(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function f(t,e){return b(t)||m(t,e)||g(t,e)||h()}function h(){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 g(t,e){if(t){if("string"==typeof t)return y(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)?y(t,e):void 0}}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function m(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,o,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=(i=r.call(n)).done)&&(s.push(i.value),s.length!==e);u=!0);}catch(t){a=!0,o=t}finally{try{if(!u&&null!=n.return&&(l=n.return(),Object(l)!==l))return}finally{if(a)throw o}}return s}}function b(t){if(Array.isArray(t))return t}function O(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function P(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?O(Object(n),!0).forEach((function(e){_(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function _(t,e,n){var i;return(e="symbol"==v(i=$(e,"string"))?i:String(i))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function $(t,e){if("object"!=v(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=v(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var j={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||(p.loadStyle({nonce:null===(e=this.$primevueConfig)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce}),this.$options.style&&this.$style.loadStyle({nonce:null===(n=this.$primevueConfig)||void 0===n||null===(n=n.csp)||void 0===n?void 0:n.nonce}))}}},beforeCreate:function(){var t,e,n,i,o,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===(i=(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===i||null===(i=i.hooks)||void 0===i||null===(o=i.onBeforeCreate)||void 0===o||o.call(i);var d=null===(r=this.$primevueConfig)||void 0===r||null===(r=r.pt)||void 0===r?void 0:r._usept,f=d?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=(d?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)||f)||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 t;r.default.loadStyle({nonce:null===(t=this.$primevueConfig)||void 0===t||null===(t=t.csp)||void 0===t?void 0:t.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 i=arguments.length,o=new Array(i>1?i-1:0),r=1;r<i;r++)o[r-1]=arguments[r];return e.ObjectUtils.isFunction(t)?t.apply(void 0,o):n.mergeProps.apply(void 0,o)},_loadGlobalStyles:function(){var t,n=this._useGlobalPT(this._getOptionValue,"global.css",this.$params);e.ObjectUtils.isNotEmpty(n)&&p.loadGlobalStyle(n,{nonce:null===(t=this.$primevueConfig)||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]:{},i=e.ObjectUtils.toFlatCase(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"").split("."),o=i.shift();return o?e.ObjectUtils.isObject(t)?this._getOptionValue(e.ObjectUtils.getItemValue(t[Object.keys(t).find((function(t){return e.ObjectUtils.toFlatCase(t)===o}))||""],n),i.join("."),n):void 0:e.ObjectUtils.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]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],r=/./g.test(n)&&!!i[n.split(".")[0]],l=this._getPropValue("ptOptions")||(null===(t=this.$primevueConfig)||void 0===t?void 0:t.ptOptions)||{},s=l.mergeSections,u=void 0===s||s,a=l.mergeProps,c=void 0!==a&&a,p=o?r?this._useGlobalPT(this._getPTClassValue,n,i):this._useDefaultPT(this._getPTClassValue,n,i):void 0,v=r?void 0:this._getPTSelf(e,this._getPTClassValue,n,P(P({},i),{},{global:p||{}})),d=this._getPTDatasets(n);return u||!u&&v?c?this._mergeProps(c,p,v,d):P(P(P({},p),v),d):P(P({},v),d)},_getPTSelf:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length,i=new Array(e>1?e-1:0),o=1;o<e;o++)i[o-1]=arguments[o];return n.mergeProps(this._usePT.apply(this,[this._getPT(t,this.$name)].concat(i)),this._usePT.apply(this,[this.$_attrsPT].concat(i)))},_getPTDatasets:function(){var t,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",o="data-pc-",r="root"===i&&e.ObjectUtils.isNotEmpty(null===(t=this.pt)||void 0===t?void 0:t["data-pc-section"]);return"transition"!==i&&P(P({},"root"===i&&P(_({},"".concat(o,"name"),e.ObjectUtils.toFlatCase(r?null===(n=this.pt)||void 0===n?void 0:n["data-pc-section"]:this.$.type.name)),r&&_({},"".concat(o,"extend"),e.ObjectUtils.toFlatCase(this.$.type.name)))),{},_({},"".concat(o,"section"),e.ObjectUtils.toFlatCase(i)))},_getPTClassValue:function(){var t=this._getOptionValue.apply(this,arguments);return e.ObjectUtils.isString(t)||e.ObjectUtils.isArray(t)?{class:t}:t},_getPT:function(t){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2?arguments[2]:void 0,r=function(t){var r,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=o?o(t):t,u=e.ObjectUtils.toFlatCase(i),a=e.ObjectUtils.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,i,o){var r=function(t){return n(t,i,o)};if(null!=t&&t.hasOwnProperty("_usept")){var l,s=t._usept||(null===(l=this.$primevueConfig)||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),d=r(t.value);if(void 0===v&&void 0===d)return;return e.ObjectUtils.isString(d)?d:e.ObjectUtils.isString(v)?v:a||!a&&d?p?this._mergeProps(p,v,d):P(P({},v),d):d}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]:"",P(P({},this.$params),t))},ptmi:function(){return n.mergeProps(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]:"",P({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]:"",P(P({},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,P(P({},this.$params),e));return[this._getOptionValue(p.inlineStyles,t,P(P({},this.$params),e)),n]}}},computed:{globalPT:function(){var t,n=this;return this._getPT(null===(t=this.$primevueConfig)||void 0===t?void 0:t.pt,void 0,(function(t){return e.ObjectUtils.getItemValue(t,{instance:n})}))},defaultPT:function(){var t,n=this;return this._getPT(null===(t=this.$primevueConfig)||void 0===t?void 0:t.pt,void 0,(function(t){return n._getOptionValue(t,n.$name,P({},n.$params))||e.ObjectUtils.getItemValue(t,P({},n.$params))}))},isUnstyled:function(){var t;return void 0!==this.unstyled?this.unstyled:null===(t=this.$primevueConfig)||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 P(P({classes:void 0,inlineStyles:void 0,loadStyle:function(){},loadCustomStyle:function(){}},(this._getHostInstance(this)||{}).$style),this.$options.style)},$primevueConfig: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=f(t,1)[0];return null==e?void 0:e.startsWith("pt:")})).reduce((function(t,e){var n,i=f(e,2),o=i[1],r=i[0].split(":"),l=(b(n=r)||d(n)||g(n)||h()).slice(1);return null==l||l.reduce((function(t,e,n,i){return!t[e]&&(t[e]=n===i.length-1?o:{}),t[e]}),t),t}),{})},$_attrsNoPT:function(){return Object.entries(this.$attrs||{}).filter((function(t){var e=f(t,1)[0];return!(null!=e&&e.startsWith("pt:"))})).reduce((function(t,e){var n=f(e,2);return t[n[0]]=n[1],t}),{})}}};module.exports=j;