UNPKG

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

236 lines (233 loc) 19.3 kB
import BaseStyle from 'primevue/base/style'; import { ObjectUtils } from 'primevue/utils'; import { mergeProps } from 'vue'; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { 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 _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var BaseDirective = { _getMeta: function _getMeta() { return [ObjectUtils.isObject(arguments.length <= 0 ? undefined : arguments[0]) ? undefined : arguments.length <= 0 ? undefined : arguments[0], ObjectUtils.getItemValue(ObjectUtils.isObject(arguments.length <= 0 ? undefined : arguments[0]) ? arguments.length <= 0 ? undefined : arguments[0] : arguments.length <= 1 ? undefined : arguments[1])]; }, _getConfig: function _getConfig(binding, vnode) { var _ref, _binding$instance, _vnode$ctx; return (_ref = (binding === null || binding === void 0 || (_binding$instance = binding.instance) === null || _binding$instance === void 0 ? void 0 : _binding$instance.$primevue) || (vnode === null || vnode === void 0 || (_vnode$ctx = vnode.ctx) === null || _vnode$ctx === void 0 || (_vnode$ctx = _vnode$ctx.appContext) === null || _vnode$ctx === void 0 || (_vnode$ctx = _vnode$ctx.config) === null || _vnode$ctx === void 0 || (_vnode$ctx = _vnode$ctx.globalProperties) === null || _vnode$ctx === void 0 ? void 0 : _vnode$ctx.$primevue)) === null || _ref === void 0 ? void 0 : _ref.config; }, _getOptionValue: function _getOptionValue(options) { var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var fKeys = ObjectUtils.toFlatCase(key).split('.'); var fKey = fKeys.shift(); return fKey ? ObjectUtils.isObject(options) ? BaseDirective._getOptionValue(ObjectUtils.getItemValue(options[Object.keys(options).find(function (k) { return ObjectUtils.toFlatCase(k) === fKey; }) || ''], params), fKeys.join('.'), params) : undefined : ObjectUtils.getItemValue(options, params); }, _getPTValue: function _getPTValue() { var _instance$binding, _instance$$config; var instance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var obj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; var searchInDefaultPT = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; var getValue = function getValue() { var value = BaseDirective._getOptionValue.apply(BaseDirective, arguments); return ObjectUtils.isString(value) || ObjectUtils.isArray(value) ? { "class": value } : value; }; var datasetPrefix = 'data-pc-'; var _ref2 = ((_instance$binding = instance.binding) === null || _instance$binding === void 0 || (_instance$binding = _instance$binding.value) === null || _instance$binding === void 0 ? void 0 : _instance$binding.ptOptions) || ((_instance$$config = instance.$config) === null || _instance$$config === void 0 ? void 0 : _instance$$config.ptOptions) || {}, _ref2$mergeSections = _ref2.mergeSections, mergeSections = _ref2$mergeSections === void 0 ? true : _ref2$mergeSections, _ref2$mergeProps = _ref2.mergeProps, useMergeProps = _ref2$mergeProps === void 0 ? false : _ref2$mergeProps; var global = searchInDefaultPT ? BaseDirective._useDefaultPT(instance, instance.defaultPT(), getValue, key, params) : undefined; var self = BaseDirective._usePT(instance, BaseDirective._getPT(obj, instance.$name), getValue, key, _objectSpread(_objectSpread({}, params), {}, { global: global || {} })); var datasets = _objectSpread(_objectSpread({}, key === 'root' && _defineProperty({}, "".concat(datasetPrefix, "name"), ObjectUtils.toFlatCase(instance.$name))), {}, _defineProperty({}, "".concat(datasetPrefix, "section"), ObjectUtils.toFlatCase(key))); return mergeSections || !mergeSections && self ? useMergeProps ? mergeProps(global, self, datasets) : _objectSpread(_objectSpread(_objectSpread({}, global), self), datasets) : _objectSpread(_objectSpread({}, self), datasets); }, _getPT: function _getPT(pt) { var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var callback = arguments.length > 2 ? arguments[2] : undefined; var getValue = function getValue(value) { var _computedValue$_key; var computedValue = callback ? callback(value) : value; var _key = ObjectUtils.toFlatCase(key); return (_computedValue$_key = computedValue === null || computedValue === void 0 ? void 0 : computedValue[_key]) !== null && _computedValue$_key !== void 0 ? _computedValue$_key : computedValue; }; return pt !== null && pt !== void 0 && pt.hasOwnProperty('_usept') ? { _usept: pt['_usept'], originalValue: getValue(pt.originalValue), value: getValue(pt.value) } : getValue(pt); }, _usePT: function _usePT() { var instance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var pt = arguments.length > 1 ? arguments[1] : undefined; var callback = arguments.length > 2 ? arguments[2] : undefined; var key = arguments.length > 3 ? arguments[3] : undefined; var params = arguments.length > 4 ? arguments[4] : undefined; var fn = function fn(value) { return callback(value, key, params); }; if (pt !== null && pt !== void 0 && pt.hasOwnProperty('_usept')) { var _instance$$config2; var _ref4 = pt['_usept'] || ((_instance$$config2 = instance.$config) === null || _instance$$config2 === void 0 ? void 0 : _instance$$config2.ptOptions) || {}, _ref4$mergeSections = _ref4.mergeSections, mergeSections = _ref4$mergeSections === void 0 ? true : _ref4$mergeSections, _ref4$mergeProps = _ref4.mergeProps, useMergeProps = _ref4$mergeProps === void 0 ? false : _ref4$mergeProps; var originalValue = fn(pt.originalValue); var value = fn(pt.value); if (originalValue === undefined && value === undefined) return undefined;else if (ObjectUtils.isString(value)) return value;else if (ObjectUtils.isString(originalValue)) return originalValue; return mergeSections || !mergeSections && value ? useMergeProps ? mergeProps(originalValue, value) : _objectSpread(_objectSpread({}, originalValue), value) : value; } return fn(pt); }, _useDefaultPT: function _useDefaultPT() { var instance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var defaultPT = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var callback = arguments.length > 2 ? arguments[2] : undefined; var key = arguments.length > 3 ? arguments[3] : undefined; var params = arguments.length > 4 ? arguments[4] : undefined; return BaseDirective._usePT(instance, defaultPT, callback, key, params); }, _hook: function _hook(directiveName, hookName, el, binding, vnode, prevVnode) { var _binding$value, _config$pt; var name = "on".concat(ObjectUtils.toCapitalCase(hookName)); var config = BaseDirective._getConfig(binding, vnode); var instance = el === null || el === void 0 ? void 0 : el.$instance; var selfHook = BaseDirective._usePT(instance, BaseDirective._getPT(binding === null || binding === void 0 || (_binding$value = binding.value) === null || _binding$value === void 0 ? void 0 : _binding$value.pt, directiveName), BaseDirective._getOptionValue, "hooks.".concat(name)); var defaultHook = BaseDirective._useDefaultPT(instance, config === null || config === void 0 || (_config$pt = config.pt) === null || _config$pt === void 0 || (_config$pt = _config$pt.directives) === null || _config$pt === void 0 ? void 0 : _config$pt[directiveName], BaseDirective._getOptionValue, "hooks.".concat(name)); var options = { el: el, binding: binding, vnode: vnode, prevVnode: prevVnode }; selfHook === null || selfHook === void 0 || selfHook(instance, options); defaultHook === null || defaultHook === void 0 || defaultHook(instance, options); }, _extend: function _extend(name) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var handleHook = function handleHook(hook, el, binding, vnode, prevVnode) { var _el$$instance$hook, _el$$instance7; el._$instances = el._$instances || {}; var config = BaseDirective._getConfig(binding, vnode); var $prevInstance = el._$instances[name] || {}; var $options = ObjectUtils.isEmpty($prevInstance) ? _objectSpread(_objectSpread({}, options), options === null || options === void 0 ? void 0 : options.methods) : {}; el._$instances[name] = _objectSpread(_objectSpread({}, $prevInstance), {}, { /* new instance variables to pass in directive methods */ $name: name, $host: el, $binding: binding, $modifiers: binding === null || binding === void 0 ? void 0 : binding.modifiers, $value: binding === null || binding === void 0 ? void 0 : binding.value, $el: $prevInstance['$el'] || el || undefined, $style: _objectSpread({ classes: undefined, inlineStyles: undefined, loadStyle: function loadStyle() {} }, options === null || options === void 0 ? void 0 : options.style), $config: config, /* computed instance variables */ defaultPT: function defaultPT() { return BaseDirective._getPT(config === null || config === void 0 ? void 0 : config.pt, undefined, function (value) { var _value$directives; return value === null || value === void 0 || (_value$directives = value.directives) === null || _value$directives === void 0 ? void 0 : _value$directives[name]; }); }, isUnstyled: function isUnstyled() { var _el$$instance, _el$$instance2; return ((_el$$instance = el.$instance) === null || _el$$instance === void 0 || (_el$$instance = _el$$instance.$binding) === null || _el$$instance === void 0 || (_el$$instance = _el$$instance.value) === null || _el$$instance === void 0 ? void 0 : _el$$instance.unstyled) !== undefined ? (_el$$instance2 = el.$instance) === null || _el$$instance2 === void 0 || (_el$$instance2 = _el$$instance2.$binding) === null || _el$$instance2 === void 0 || (_el$$instance2 = _el$$instance2.value) === null || _el$$instance2 === void 0 ? void 0 : _el$$instance2.unstyled : config === null || config === void 0 ? void 0 : config.unstyled; }, /* instance's methods */ ptm: function ptm() { var _el$$instance3; var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return BaseDirective._getPTValue(el.$instance, (_el$$instance3 = el.$instance) === null || _el$$instance3 === void 0 || (_el$$instance3 = _el$$instance3.$binding) === null || _el$$instance3 === void 0 || (_el$$instance3 = _el$$instance3.value) === null || _el$$instance3 === void 0 ? void 0 : _el$$instance3.pt, key, _objectSpread({}, params)); }, ptmo: function ptmo() { var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return BaseDirective._getPTValue(el.$instance, obj, key, params, false); }, cx: function cx() { var _el$$instance4, _el$$instance5; var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return !((_el$$instance4 = el.$instance) !== null && _el$$instance4 !== void 0 && _el$$instance4.isUnstyled()) ? BaseDirective._getOptionValue((_el$$instance5 = el.$instance) === null || _el$$instance5 === void 0 || (_el$$instance5 = _el$$instance5.$style) === null || _el$$instance5 === void 0 ? void 0 : _el$$instance5.classes, key, _objectSpread({}, params)) : undefined; }, sx: function sx() { var _el$$instance6; var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var when = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return when ? BaseDirective._getOptionValue((_el$$instance6 = el.$instance) === null || _el$$instance6 === void 0 || (_el$$instance6 = _el$$instance6.$style) === null || _el$$instance6 === void 0 ? void 0 : _el$$instance6.inlineStyles, key, _objectSpread({}, params)) : undefined; } }, $options); el.$instance = el._$instances[name]; // pass instance data to hooks (_el$$instance$hook = (_el$$instance7 = el.$instance)[hook]) === null || _el$$instance$hook === void 0 || _el$$instance$hook.call(_el$$instance7, el, binding, vnode, prevVnode); // handle hook in directive implementation BaseDirective._hook(name, hook, el, binding, vnode, prevVnode); // handle hooks during directive uses (global and self-definition) }; return { created: function created(el, binding, vnode, prevVnode) { handleHook('created', el, binding, vnode, prevVnode); }, beforeMount: function beforeMount(el, binding, vnode, prevVnode) { var _config$csp, _el$$instance8, _el$$instance9, _config$csp2; var config = BaseDirective._getConfig(binding, vnode); BaseStyle.loadStyle(undefined, { nonce: config === null || config === void 0 || (_config$csp = config.csp) === null || _config$csp === void 0 ? void 0 : _config$csp.nonce }); !((_el$$instance8 = el.$instance) !== null && _el$$instance8 !== void 0 && _el$$instance8.isUnstyled()) && ((_el$$instance9 = el.$instance) === null || _el$$instance9 === void 0 || (_el$$instance9 = _el$$instance9.$style) === null || _el$$instance9 === void 0 ? void 0 : _el$$instance9.loadStyle(undefined, { nonce: config === null || config === void 0 || (_config$csp2 = config.csp) === null || _config$csp2 === void 0 ? void 0 : _config$csp2.nonce })); handleHook('beforeMount', el, binding, vnode, prevVnode); }, mounted: function mounted(el, binding, vnode, prevVnode) { handleHook('mounted', el, binding, vnode, prevVnode); }, beforeUpdate: function beforeUpdate(el, binding, vnode, prevVnode) { handleHook('beforeUpdate', el, binding, vnode, prevVnode); }, updated: function updated(el, binding, vnode, prevVnode) { handleHook('updated', el, binding, vnode, prevVnode); }, beforeUnmount: function beforeUnmount(el, binding, vnode, prevVnode) { handleHook('beforeUnmount', el, binding, vnode, prevVnode); }, unmounted: function unmounted(el, binding, vnode, prevVnode) { handleHook('unmounted', el, binding, vnode, prevVnode); } }; }, extend: function extend() { var _BaseDirective$_getMe = BaseDirective._getMeta.apply(BaseDirective, arguments), _BaseDirective$_getMe2 = _slicedToArray(_BaseDirective$_getMe, 2), name = _BaseDirective$_getMe2[0], options = _BaseDirective$_getMe2[1]; return _objectSpread({ extend: function extend() { var _BaseDirective$_getMe3 = BaseDirective._getMeta.apply(BaseDirective, arguments), _BaseDirective$_getMe4 = _slicedToArray(_BaseDirective$_getMe3, 2), _name = _BaseDirective$_getMe4[0], _options = _BaseDirective$_getMe4[1]; return BaseDirective.extend(_name, _objectSpread(_objectSpread(_objectSpread({}, options), options === null || options === void 0 ? void 0 : options.methods), _options)); } }, BaseDirective._extend(name, options)); } }; export { BaseDirective as default };