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
96 lines (90 loc) • 4.53 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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), 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 { Vue as OurVue } from '../vue';
import { NAME, PROP_NAME } from '../constants/config';
import { cloneDeep } from './clone-deep';
import { getRaw } from './get';
import { isArray, isPlainObject, isString, isUndefined } from './inspect';
import { getOwnPropertyNames } from './object';
import { warn } from './warn';
// Config manager class
var BvConfig = /*#__PURE__*/function () {
function BvConfig() {
_classCallCheck(this, BvConfig);
this.$_config = {};
}
// Method to merge in user config parameters
return _createClass(BvConfig, [{
key: "setConfig",
value: function setConfig() {
var _this = this;
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
/* istanbul ignore next */
if (!isPlainObject(config)) {
return;
}
var configKeys = getOwnPropertyNames(config);
configKeys.forEach(function (key) {
/* istanbul ignore next */
var subConfig = config[key];
if (key === 'breakpoints') {
/* istanbul ignore if */
if (!isArray(subConfig) || subConfig.length < 2 || subConfig.some(function (b) {
return !isString(b) || b.length === 0;
})) {
warn('"breakpoints" must be an array of at least 2 breakpoint names', NAME);
} else {
_this.$_config[key] = cloneDeep(subConfig);
}
} else if (isPlainObject(subConfig)) {
// Component prop defaults
_this.$_config[key] = getOwnPropertyNames(subConfig).reduce(function (config, prop) {
if (!isUndefined(subConfig[prop])) {
config[prop] = cloneDeep(subConfig[prop]);
}
return config;
}, _this.$_config[key] || {});
}
});
}
// Clear the config
}, {
key: "resetConfig",
value: function resetConfig() {
this.$_config = {};
}
// Returns a deep copy of the user config
}, {
key: "getConfig",
value: function getConfig() {
return cloneDeep(this.$_config);
}
// Returns a deep copy of the config value
}, {
key: "getConfigValue",
value: function getConfigValue(key) {
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
return cloneDeep(getRaw(this.$_config, key, defaultValue));
}
}]);
}(); // Method for applying a global config
export var setConfig = function setConfig() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var Vue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : OurVue;
// Ensure we have a `$bvConfig` Object on the Vue prototype
// We set on Vue and OurVue just in case consumer has not set an alias of `vue`
Vue.prototype[PROP_NAME] = OurVue.prototype[PROP_NAME] = Vue.prototype[PROP_NAME] || OurVue.prototype[PROP_NAME] || new BvConfig();
// Apply the config values
Vue.prototype[PROP_NAME].setConfig(config);
};
// Method for resetting the user config
// Exported for testing purposes only
export var resetConfig = function resetConfig() {
if (OurVue.prototype[PROP_NAME] && OurVue.prototype[PROP_NAME].resetConfig) {
OurVue.prototype[PROP_NAME].resetConfig();
}
};