UNPKG

bootstrap-vue

Version:

With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens

122 lines (94 loc) 6.65 kB
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } import Vue from 'vue'; import { mergeData } from 'vue-functional-data-merge'; // --- Constants --- var COMPONENT_UID_KEY = '_uid'; var isVue3 = Vue.version.startsWith('3'); export var REF_FOR_KEY = isVue3 ? 'ref_for' : 'refInFor'; var ALLOWED_FIELDS_IN_DATA = ['class', 'staticClass', 'style', 'attrs', 'props', 'domProps', 'on', 'nativeOn', 'directives', 'scopedSlots', 'slot', 'key', 'ref', 'refInFor']; var extend = Vue.extend.bind(Vue); if (isVue3) { var originalExtend = Vue.extend; var KNOWN_COMPONENTS = ['router-link', 'transition', 'transition-group']; var originalVModelDynamicCreated = Vue.vModelDynamic.created; var originalVModelDynamicBeforeUpdate = Vue.vModelDynamic.beforeUpdate; // See https://github.com/vuejs/vue-next/pull/4121 for details Vue.vModelDynamic.created = function (el, binding, vnode) { originalVModelDynamicCreated.call(this, el, binding, vnode); if (!el._assign) { el._assign = function () {}; } }; Vue.vModelDynamic.beforeUpdate = function (el, binding, vnode) { originalVModelDynamicBeforeUpdate.call(this, el, binding, vnode); if (!el._assign) { el._assign = function () {}; } }; extend = function patchedBootstrapVueExtend(definition) { if (_typeof(definition) === 'object' && definition.render && !definition.__alreadyPatched) { var originalRender = definition.render; definition.__alreadyPatched = true; definition.render = function (h) { var patchedH = function patchedH(tag, dataObjOrChildren, rawSlots) { var slots = rawSlots === undefined ? [] : [Array.isArray(rawSlots) ? rawSlots.filter(Boolean) : rawSlots]; var isTag = typeof tag === 'string' && !KNOWN_COMPONENTS.includes(tag); var isSecondArgumentDataObject = dataObjOrChildren && _typeof(dataObjOrChildren) === 'object' && !Array.isArray(dataObjOrChildren); if (!isSecondArgumentDataObject) { return h.apply(void 0, [tag, dataObjOrChildren].concat(slots)); } var attrs = dataObjOrChildren.attrs, props = dataObjOrChildren.props, restData = _objectWithoutProperties(dataObjOrChildren, ["attrs", "props"]); var normalizedData = _objectSpread(_objectSpread({}, restData), {}, { attrs: attrs, props: isTag ? {} : props }); if (tag === 'router-link' && !normalizedData.slots && !normalizedData.scopedSlots) { // terrible workaround to fix router-link rendering with compat vue-router normalizedData.scopedSlots = { $hasNormal: function $hasNormal() {} }; } return h.apply(void 0, [tag, normalizedData].concat(slots)); }; if (definition.functional) { var _ctx$children, _ctx$children$default; var ctx = arguments[1]; var patchedCtx = _objectSpread({}, ctx); patchedCtx.data = { attrs: _objectSpread({}, ctx.data.attrs || {}), props: _objectSpread({}, ctx.data.props || {}) }; Object.keys(ctx.data || {}).forEach(function (key) { if (ALLOWED_FIELDS_IN_DATA.includes(key)) { patchedCtx.data[key] = ctx.data[key]; } else if (key in ctx.props) { patchedCtx.data.props[key] = ctx.data[key]; } else if (!key.startsWith('on')) { patchedCtx.data.attrs[key] = ctx.data[key]; } }); var IGNORED_CHILDREN_KEYS = ['_ctx']; var children = ((_ctx$children = ctx.children) === null || _ctx$children === void 0 ? void 0 : (_ctx$children$default = _ctx$children.default) === null || _ctx$children$default === void 0 ? void 0 : _ctx$children$default.call(_ctx$children)) || ctx.children; if (children && Object.keys(patchedCtx.children).filter(function (k) { return !IGNORED_CHILDREN_KEYS.includes(k); }).length === 0) { delete patchedCtx.children; } else { patchedCtx.children = children; } patchedCtx.data.on = ctx.listeners; return originalRender.call(this, patchedH, patchedCtx); } return originalRender.call(this, patchedH); }; } return originalExtend.call(this, definition); }.bind(Vue); } var nextTick = Vue.nextTick; export { COMPONENT_UID_KEY, Vue, mergeData, isVue3, nextTick, extend };