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
115 lines (105 loc) • 6.32 kB
JavaScript
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 { PROP_TYPE_ANY } from '../constants/props';
import { cloneDeep } from './clone-deep';
import { getComponentConfig } from './config';
import { identity } from './identity';
import { isArray, isFunction, isObject, isUndefined } from './inspect';
import { clone, hasOwnProperty, keys } from './object';
import { lowerFirst, upperFirst } from './string';
// Prefix a property
export var prefixPropName = function prefixPropName(prefix, value) {
return prefix + upperFirst(value);
};
// Remove a prefix from a property
export var unprefixPropName = function unprefixPropName(prefix, value) {
return lowerFirst(value.replace(prefix, ''));
};
// Suffix can be a falsey value so nothing is appended to string
// (helps when looping over props & some shouldn't change)
// Use data last parameters to allow for currying
export var suffixPropName = function suffixPropName(suffix, value) {
return value + (suffix ? upperFirst(suffix) : '');
};
// Generates a prop object
export var makeProp = function makeProp() {
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : PROP_TYPE_ANY;
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
var requiredOrValidator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
var validator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
var required = requiredOrValidator === true;
validator = required ? validator : requiredOrValidator;
return _objectSpread(_objectSpread(_objectSpread({}, type ? {
type: type
} : {}), required ? {
required: required
} : isUndefined(value) ? {} : {
default: isObject(value) ? function () {
return value;
} : value
}), isUndefined(validator) ? {} : {
validator: validator
});
};
// Copies props from one array/object to a new array/object
// Prop values are also cloned as new references to prevent possible
// mutation of original prop object values
// Optionally accepts a function to transform the prop name
export var copyProps = function copyProps(props) {
var transformFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : identity;
if (isArray(props)) {
return props.map(transformFn);
}
var copied = {};
for (var prop in props) {
/* istanbul ignore else */
if (hasOwnProperty(props, prop)) {
// If the prop value is an object, do a shallow clone
// to prevent potential mutations to the original object
copied[transformFn(prop)] = isObject(props[prop]) ? clone(props[prop]) : props[prop];
}
}
return copied;
};
// Given an array of properties or an object of property keys,
// plucks all the values off the target object, returning a new object
// that has props that reference the original prop values
export var pluckProps = function pluckProps(keysToPluck, objToPluck) {
var transformFn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : identity;
return (isArray(keysToPluck) ? keysToPluck.slice() : keys(keysToPluck)).reduce(function (memo, prop) {
memo[transformFn(prop)] = objToPluck[prop];
return memo;
}, {});
};
// Make a prop object configurable by global configuration
// Replaces the current `default` key of each prop with a `getComponentConfig()`
// call that falls back to the current default value of the prop
export var makePropConfigurable = function makePropConfigurable(prop, key, componentKey) {
return _objectSpread(_objectSpread({}, cloneDeep(prop)), {}, {
default: function bvConfigurablePropDefault() {
var value = getComponentConfig(componentKey, key, prop.default);
return isFunction(value) ? value() : value;
}
});
};
// Make a props object configurable by global configuration
// Replaces the current `default` key of each prop with a `getComponentConfig()`
// call that falls back to the current default value of the prop
export var makePropsConfigurable = function makePropsConfigurable(props, componentKey) {
return keys(props).reduce(function (result, key) {
return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, key, makePropConfigurable(props[key], key, componentKey)));
}, {});
};
// Get function name we use in `makePropConfigurable()`
// for the prop default value override to compare
// against in `hasPropFunction()`
var configurablePropDefaultFnName = makePropConfigurable({}, '', '').default.name;
// Detect wether the given value is currently a function
// and isn't the props default function
export var hasPropFunction = function hasPropFunction(fn) {
return isFunction(fn) && fn.name && fn.name !== configurablePropDefaultFnName;
};