You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.5 KiB
196 lines
6.5 KiB
4 years ago
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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; }
|
||
|
|
||
|
import OurVue from '../vue';
|
||
|
import { setConfig } from './config-set';
|
||
|
import { hasWindowSupport, isJSDOM } from './env';
|
||
|
import { warn } from './warn';
|
||
|
/**
|
||
|
* Checks if there are multiple instances of Vue, and warns (once) about possible issues.
|
||
|
* @param {object} Vue
|
||
|
*/
|
||
|
|
||
|
export var checkMultipleVue = function () {
|
||
|
var checkMultipleVueWarned = false;
|
||
|
var MULTIPLE_VUE_WARNING = ['Multiple instances of Vue detected!', 'You may need to set up an alias for Vue in your bundler config.', 'See: https://bootstrap-vue.org/docs#using-module-bundlers'].join('\n');
|
||
|
return function (Vue) {
|
||
|
/* istanbul ignore next */
|
||
|
if (!checkMultipleVueWarned && OurVue !== Vue && !isJSDOM) {
|
||
|
warn(MULTIPLE_VUE_WARNING);
|
||
|
}
|
||
|
|
||
|
checkMultipleVueWarned = true;
|
||
|
};
|
||
|
}();
|
||
|
/**
|
||
|
* Plugin install factory function.
|
||
|
* @param {object} { components, directives }
|
||
|
* @returns {function} plugin install function
|
||
|
*/
|
||
|
|
||
|
export var installFactory = function installFactory() {
|
||
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
||
|
components = _ref.components,
|
||
|
directives = _ref.directives,
|
||
|
plugins = _ref.plugins;
|
||
|
|
||
|
var install = function install(Vue) {
|
||
|
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||
|
|
||
|
if (install.installed) {
|
||
|
/* istanbul ignore next */
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
install.installed = true;
|
||
|
checkMultipleVue(Vue);
|
||
|
setConfig(config, Vue);
|
||
|
registerComponents(Vue, components);
|
||
|
registerDirectives(Vue, directives);
|
||
|
registerPlugins(Vue, plugins);
|
||
|
};
|
||
|
|
||
|
install.installed = false;
|
||
|
return install;
|
||
|
};
|
||
|
/**
|
||
|
* Plugin install factory function (no plugin config option).
|
||
|
* @param {object} { components, directives }
|
||
|
* @returns {function} plugin install function
|
||
|
*/
|
||
|
|
||
|
export var installFactoryNoConfig = function installFactoryNoConfig() {
|
||
|
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
||
|
components = _ref2.components,
|
||
|
directives = _ref2.directives,
|
||
|
plugins = _ref2.plugins;
|
||
|
|
||
|
var install = function install(Vue) {
|
||
|
if (install.installed) {
|
||
|
/* istanbul ignore next */
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
install.installed = true;
|
||
|
checkMultipleVue(Vue);
|
||
|
registerComponents(Vue, components);
|
||
|
registerDirectives(Vue, directives);
|
||
|
registerPlugins(Vue, plugins);
|
||
|
};
|
||
|
|
||
|
install.installed = false;
|
||
|
return install;
|
||
|
};
|
||
|
/**
|
||
|
* Plugin object factory function.
|
||
|
* @param {object} { components, directives, plugins }
|
||
|
* @returns {object} plugin install object
|
||
|
*/
|
||
|
|
||
|
export var pluginFactory = function pluginFactory() {
|
||
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||
|
var extend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||
|
return _objectSpread(_objectSpread({}, extend), {}, {
|
||
|
install: installFactory(options)
|
||
|
});
|
||
|
};
|
||
|
/**
|
||
|
* Plugin object factory function (no config option).
|
||
|
* @param {object} { components, directives, plugins }
|
||
|
* @returns {object} plugin install object
|
||
|
*/
|
||
|
|
||
|
export var pluginFactoryNoConfig = function pluginFactoryNoConfig() {
|
||
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||
|
var extend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||
|
return _objectSpread(_objectSpread({}, extend), {}, {
|
||
|
install: installFactoryNoConfig(options)
|
||
|
});
|
||
|
};
|
||
|
/**
|
||
|
* Load a group of plugins.
|
||
|
* @param {object} Vue
|
||
|
* @param {object} Plugin definitions
|
||
|
*/
|
||
|
|
||
|
export var registerPlugins = function registerPlugins(Vue) {
|
||
|
var plugins = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||
|
|
||
|
for (var plugin in plugins) {
|
||
|
if (plugin && plugins[plugin]) {
|
||
|
Vue.use(plugins[plugin]);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Load a component.
|
||
|
* @param {object} Vue
|
||
|
* @param {string} Component name
|
||
|
* @param {object} Component definition
|
||
|
*/
|
||
|
|
||
|
export var registerComponent = function registerComponent(Vue, name, def) {
|
||
|
if (Vue && name && def) {
|
||
|
Vue.component(name, def);
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Load a group of components.
|
||
|
* @param {object} Vue
|
||
|
* @param {object} Object of component definitions
|
||
|
*/
|
||
|
|
||
|
export var registerComponents = function registerComponents(Vue) {
|
||
|
var components = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||
|
|
||
|
for (var component in components) {
|
||
|
registerComponent(Vue, component, components[component]);
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Load a directive.
|
||
|
* @param {object} Vue
|
||
|
* @param {string} Directive name
|
||
|
* @param {object} Directive definition
|
||
|
*/
|
||
|
|
||
|
export var registerDirective = function registerDirective(Vue, name, def) {
|
||
|
if (Vue && name && def) {
|
||
|
// Ensure that any leading V is removed from the
|
||
|
// name, as Vue adds it automatically
|
||
|
Vue.directive(name.replace(/^VB/, 'B'), def);
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Load a group of directives.
|
||
|
* @param {object} Vue
|
||
|
* @param {object} Object of directive definitions
|
||
|
*/
|
||
|
|
||
|
export var registerDirectives = function registerDirectives(Vue) {
|
||
|
var directives = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||
|
|
||
|
for (var directive in directives) {
|
||
|
registerDirective(Vue, directive, directives[directive]);
|
||
|
}
|
||
|
};
|
||
|
/**
|
||
|
* Install plugin if window.Vue available
|
||
|
* @param {object} Plugin definition
|
||
|
*/
|
||
|
|
||
|
export var vueUse = function vueUse(VuePlugin) {
|
||
|
/* istanbul ignore next */
|
||
|
if (hasWindowSupport && window.Vue) {
|
||
|
window.Vue.use(VuePlugin);
|
||
|
}
|
||
|
/* istanbul ignore next */
|
||
|
|
||
|
|
||
|
if (hasWindowSupport && VuePlugin.NAME) {
|
||
|
window[VuePlugin.NAME] = VuePlugin;
|
||
|
}
|
||
|
};
|