UNPKG

bootstrap-view

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

151 lines (136 loc) 7.28 kB
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 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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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); } import { mergeData } from '../../vue'; import { NAME_COL } from '../../constants/components'; import { PROP_TYPE_BOOLEAN, PROP_TYPE_BOOLEAN_NUMBER_STRING, PROP_TYPE_NUMBER_STRING, PROP_TYPE_STRING } from '../../constants/props'; import { RX_COL_CLASS } from '../../constants/regex'; import { arrayIncludes } from '../../utils/array'; import { getBreakpointsUpCached } from '../../utils/config'; import { identity } from '../../utils/identity'; import { isUndefinedOrNull } from '../../utils/inspect'; import { memoize } from '../../utils/memoize'; import { assign, create, keys, sortKeys } from '../../utils/object'; import { makeProp, makePropsConfigurable, suffixPropName } from '../../utils/props'; import { lowerCase } from '../../utils/string'; // --- Constants --- var ALIGN_SELF_VALUES = ['auto', 'start', 'end', 'center', 'baseline', 'stretch']; // --- Helper methods --- // Compute a breakpoint class name var computeBreakpoint = function computeBreakpoint(type, breakpoint, value) { var className = type; if (isUndefinedOrNull(value) || value === false) { return undefined; } if (breakpoint) { className += "-".concat(breakpoint); } // Handling the boolean style prop when accepting `[Boolean, String, Number]` // means Vue will not convert `<b-col sm></b-col>` to `sm: true` for us // Since the default is `false`, '' indicates the prop's presence if (type === 'col' && (value === '' || value === true)) { // .col-md return lowerCase(className); } // .order-md-6 className += "-".concat(value); return lowerCase(className); }; // Memoized function for better performance on generating class names var computeBreakpointClass = memoize(computeBreakpoint); // Cached copy of the breakpoint prop names var breakpointPropMap = create(null); // --- Props --- // Prop generator for lazy generation of props export var generateProps = function generateProps() { // Grab the breakpoints from the cached config (exclude the '' (xs) breakpoint) var breakpoints = getBreakpointsUpCached().filter(identity); // i.e. 'col-sm', 'col-md-6', 'col-lg-auto', ... var breakpointCol = breakpoints.reduce(function (props, breakpoint) { props[breakpoint] = makeProp(PROP_TYPE_BOOLEAN_NUMBER_STRING); return props; }, create(null)); // i.e. 'offset-md-1', 'offset-lg-12', ... var breakpointOffset = breakpoints.reduce(function (props, breakpoint) { props[suffixPropName(breakpoint, 'offset')] = makeProp(PROP_TYPE_NUMBER_STRING); return props; }, create(null)); // i.e. 'order-md-1', 'order-lg-12', ... var breakpointOrder = breakpoints.reduce(function (props, breakpoint) { props[suffixPropName(breakpoint, 'order')] = makeProp(PROP_TYPE_NUMBER_STRING); return props; }, create(null)); // For loop doesn't need to check `.hasOwnProperty()` // when using an object created from `null` breakpointPropMap = assign(create(null), { col: keys(breakpointCol), offset: keys(breakpointOffset), order: keys(breakpointOrder) }); // Return the generated props return makePropsConfigurable(sortKeys(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, breakpointCol), breakpointOffset), breakpointOrder), {}, { // Flex alignment alignSelf: makeProp(PROP_TYPE_STRING, null, function (value) { return arrayIncludes(ALIGN_SELF_VALUES, value); }), // Generic flexbox 'col' (xs) col: makeProp(PROP_TYPE_BOOLEAN, false), // i.e. 'col-1', 'col-2', 'col-auto', ... cols: makeProp(PROP_TYPE_NUMBER_STRING), offset: makeProp(PROP_TYPE_NUMBER_STRING), order: makeProp(PROP_TYPE_NUMBER_STRING), tag: makeProp(PROP_TYPE_STRING, 'div') })), NAME_COL); }; // --- Main component --- // We do not use extend here as that would evaluate the props // immediately, which we do not want to happen // @vue/component export var BCol = { name: NAME_COL, functional: true, get props() { // Allow props to be lazy evaled on first access and // then they become a non-getter afterwards. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#Smart_self-overwriting_lazy_getters delete this.props; // eslint-disable-next-line no-return-assign return this.props = generateProps(); }, render: function render(h, _ref) { var props = _ref.props, data = _ref.data, children = _ref.children; var cols = props.cols, offset = props.offset, order = props.order, alignSelf = props.alignSelf; var classList = []; // Loop through `col`, `offset`, `order` breakpoint props for (var type in breakpointPropMap) { // Returns colSm, offset, offsetSm, orderMd, etc. var _keys = breakpointPropMap[type]; for (var i = 0; i < _keys.length; i++) { // computeBreakpoint(col, colSm => Sm, value=[String, Number, Boolean]) var c = computeBreakpointClass(type, _keys[i].replace(type, ''), props[_keys[i]]); // If a class is returned, push it onto the array. if (c) { classList.push(c); } } } var hasColClasses = classList.some(function (className) { return RX_COL_CLASS.test(className); }); classList.push(_defineProperty(_defineProperty(_defineProperty(_defineProperty({ // Default to .col if no other col-{bp}-* classes generated nor `cols` specified. col: props.col || !hasColClasses && !cols }, "col-".concat(cols), cols), "offset-".concat(offset), offset), "order-".concat(order), order), "align-self-".concat(alignSelf), alignSelf)); return h(props.tag, mergeData(data, { class: classList }), children); } };