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
149 lines (143 loc) • 6.78 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 { extend } from '../../vue';
import { NAME_FORM_INPUT } from '../../constants/components';
import { PROP_TYPE_BOOLEAN, PROP_TYPE_NUMBER_STRING, PROP_TYPE_STRING } from '../../constants/props';
import { arrayIncludes } from '../../utils/array';
import { attemptBlur } from '../../utils/dom';
import { eventOn, eventOff, eventOnOff, stopEvent } from '../../utils/events';
import { sortKeys } from '../../utils/object';
import { makeProp, makePropsConfigurable } from '../../utils/props';
import { formControlMixin, props as formControlProps } from '../../mixins/form-control';
import { formSelectionMixin } from '../../mixins/form-selection';
import { formSizeMixin, props as formSizeProps } from '../../mixins/form-size';
import { formStateMixin, props as formStateProps } from '../../mixins/form-state';
import { formTextMixin, props as formTextProps } from '../../mixins/form-text';
import { formValidityMixin } from '../../mixins/form-validity';
import { idMixin, props as idProps } from '../../mixins/id';
import { listenersMixin } from '../../mixins/listeners';
// --- Constants ---
// Valid supported input types
var TYPES = ['text', 'password', 'email', 'number', 'url', 'tel', 'search', 'range', 'color', 'date', 'time', 'datetime', 'datetime-local', 'month', 'week'];
// --- Props ---
export var props = makePropsConfigurable(sortKeys(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, idProps), formControlProps), formSizeProps), formStateProps), formTextProps), {}, {
list: makeProp(PROP_TYPE_STRING),
max: makeProp(PROP_TYPE_NUMBER_STRING),
min: makeProp(PROP_TYPE_NUMBER_STRING),
// Disable mousewheel to prevent wheel from changing values (i.e. number/date)
noWheel: makeProp(PROP_TYPE_BOOLEAN, false),
step: makeProp(PROP_TYPE_NUMBER_STRING),
type: makeProp(PROP_TYPE_STRING, 'text', function (type) {
return arrayIncludes(TYPES, type);
})
})), NAME_FORM_INPUT);
// --- Main component ---
// @vue/component
export var BFormInput = /*#__PURE__*/extend({
name: NAME_FORM_INPUT,
// Mixin order is important!
mixins: [listenersMixin, idMixin, formControlMixin, formSizeMixin, formStateMixin, formTextMixin, formSelectionMixin, formValidityMixin],
props: props,
computed: {
localType: function localType() {
// We only allow certain types
var type = this.type;
return arrayIncludes(TYPES, type) ? type : 'text';
},
computedAttrs: function computedAttrs() {
var type = this.localType,
name = this.name,
form = this.form,
disabled = this.disabled,
placeholder = this.placeholder,
required = this.required,
min = this.min,
max = this.max,
step = this.step;
return {
id: this.safeId(),
name: name,
form: form,
type: type,
disabled: disabled,
placeholder: placeholder,
required: required,
autocomplete: this.autocomplete || null,
readonly: this.readonly || this.plaintext,
min: min,
max: max,
step: step,
list: type !== 'password' ? this.list : null,
'aria-required': required ? 'true' : null,
'aria-invalid': this.computedAriaInvalid
};
},
computedListeners: function computedListeners() {
return _objectSpread(_objectSpread({}, this.bvListeners), {}, {
input: this.onInput,
change: this.onChange,
blur: this.onBlur
});
}
},
watch: {
noWheel: function noWheel(newValue) {
this.setWheelStopper(newValue);
}
},
mounted: function mounted() {
this.setWheelStopper(this.noWheel);
},
/* istanbul ignore next */deactivated: function deactivated() {
// Turn off listeners when keep-alive component deactivated
/* istanbul ignore next */
this.setWheelStopper(false);
},
/* istanbul ignore next */activated: function activated() {
// Turn on listeners (if no-wheel) when keep-alive component activated
/* istanbul ignore next */
this.setWheelStopper(this.noWheel);
},
beforeDestroy: function beforeDestroy() {
/* istanbul ignore next */
this.setWheelStopper(false);
},
methods: {
setWheelStopper: function setWheelStopper(on) {
var input = this.$el;
// We use native events, so that we don't interfere with propagation
eventOnOff(on, input, 'focus', this.onWheelFocus);
eventOnOff(on, input, 'blur', this.onWheelBlur);
if (!on) {
eventOff(document, 'wheel', this.stopWheel);
}
},
onWheelFocus: function onWheelFocus() {
eventOn(document, 'wheel', this.stopWheel);
},
onWheelBlur: function onWheelBlur() {
eventOff(document, 'wheel', this.stopWheel);
},
stopWheel: function stopWheel(event) {
stopEvent(event, {
propagation: false
});
attemptBlur(this.$el);
}
},
render: function render(h) {
return h('input', {
class: this.computedClass,
attrs: this.computedAttrs,
domProps: {
value: this.localValue
},
on: this.computedListeners,
ref: 'input'
});
}
});