Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
classes() {
let width = this.width;
let classList = [`${prefixCls}`];
classList.push({
[`${prefixCls}-${width}`]: width,
[`${this.className}`]: !!this.className
});
// let noOtherWidth = width==undefined&&this.flex == undefined;
let lastSize = null;
for (let size of [ 'xl', 'lg', 'md', 'sm', 'xs' ]) {
if (utils.isNumber(this[size])) {
lastSize = this[size];
classList.push(`${prefixCls}-${size}-${this[size]}`);
} else if (lastSize) {
classList.push(`${prefixCls}-${size}-${lastSize}`);
}
}
return classList;
},
styles() {
inserted(el, binding, vnode) {
if (utils.isNumber(binding.value)) {
let total = binding.value;
el.setAttribute('data-alerted', '0');
wordlimit(el, total);
el.addEventListener('input', () => {
wordlimit(el, total, vnode);
});
el.addEventListener('blur', () => {
el.setAttribute('data-alerted', '0');
});
for (let d of vnode.data.directives) {
if (d.name == 'model') {
vnode.context.$watch(d.expression, function () {
wordlimit(el, total);
});
break;
}
setvalue(value, trigger) {
if (this.disabled) return false;
if (this.max !== undefined && value !== null) {
value = Math.min(this.max, value);
}
if (this.min !== undefined && value !== null) {
value = Math.max(this.min, value);
}
if (this.precision && utils.isNumber(value)) {
value = Math.floor(utils.mul(value || 0, Math.pow(10, this.precision))) / Math.pow(10, this.precision);
value = value.toFixed(this.precision);
}
this.valueBak = value;
this.$emit('input', value);
if (trigger != 'input') {
this.editValue = value;
}
if (trigger != 'input') {
this.$emit('change', value);
}
let event = document.createEvent('CustomEvent');
event.initCustomEvent('setvalue', true, true, value);
this.$el.dispatchEvent(event);
}
},
styles() {
let style = {};
let styletype = 'padding';
if (this.flex) {
style.flex = this.flex;
}
if (this.$parent.type == 'flex') {
styletype = 'margin';
}
if (utils.isNumber(this.$parent.space) && this.$parent.space !== 0) {
const leftTop = getHalf(this.$parent.space, true);
const rightBottom = getHalf(this.$parent.space, false);
style[`${styletype}Left`] = leftTop;
style[`${styletype}Right`] = rightBottom;
style[`${styletype}Top`] = leftTop;
style[`${styletype}Bottom`] = rightBottom;
}
if (utils.isNumber(this.$parent.spaceX) && this.$parent.spaceX !== 0) {
style[`${styletype}Left`] = getHalf(this.$parent.spaceX, true);
style[`${styletype}Right`] = getHalf(this.$parent.spaceX, false);
}
if (utils.isNumber(this.$parent.spaceY) && this.$parent.spaceY !== 0) {
style[`${styletype}Top`] = getHalf(this.$parent.spaceY, true);
style[`${styletype}Bottom`] = getHalf(this.$parent.spaceY, false);
if (utils.isNumber(this.$parent.space) && this.$parent.space !== 0) {
const leftTop = getHalf(this.$parent.space, true);
const rightBottom = getHalf(this.$parent.space, false);
style[`${styletype}Left`] = leftTop;
style[`${styletype}Right`] = rightBottom;
style[`${styletype}Top`] = leftTop;
style[`${styletype}Bottom`] = rightBottom;
}
if (utils.isNumber(this.$parent.spaceX) && this.$parent.spaceX !== 0) {
style[`${styletype}Left`] = getHalf(this.$parent.spaceX, true);
style[`${styletype}Right`] = getHalf(this.$parent.spaceX, false);
}
if (utils.isNumber(this.$parent.spaceY) && this.$parent.spaceY !== 0) {
style[`${styletype}Top`] = getHalf(this.$parent.spaceY, true);
style[`${styletype}Bottom`] = getHalf(this.$parent.spaceY, false);
}
return style;
}
}
input(event) {
if (isNaN(Number(event.target.value))) return false;
let value = this.getValue(event.target.value);
if (utils.isNumber(this.value) && Math.abs(value - this.value) <= 1 && this.precision) {
return;
}
this.setvalue(value, 'input');
},
blur(event) {
inserted(el, binding, vnode) {
if (utils.isNumber(binding.value)) {
let total = binding.value;
let wordElement = document.createElement('p');
wordElement.innerHTML = `<span><span class="h-wordcount-remain-size"></span> / <span class="h-wordcount-total-size">${total}</span></span>`;
utils.addClass(wordElement, 'h-wordcount');
let parent = el.parentNode;
parent.insertBefore(wordElement, el);
let remainDom = parent.querySelector('.h-wordcount-remain-size');
el.remainDom = remainDom;
wordcount(total, el, remainDom);
el.addEventListener('input', () => {
wordcount(total, el, remainDom);
});
for (let d of vnode.data.directives) {
if (d.name == 'model') {
vnode.context.$watch(d.expression, function () {
wordcount(total, el, remainDom);
style.flex = this.flex;
}
if (this.$parent.type == 'flex') {
styletype = 'margin';
}
if (utils.isNumber(this.$parent.space) && this.$parent.space !== 0) {
const leftTop = getHalf(this.$parent.space, true);
const rightBottom = getHalf(this.$parent.space, false);
style[`${styletype}Left`] = leftTop;
style[`${styletype}Right`] = rightBottom;
style[`${styletype}Top`] = leftTop;
style[`${styletype}Bottom`] = rightBottom;
}
if (utils.isNumber(this.$parent.spaceX) && this.$parent.spaceX !== 0) {
style[`${styletype}Left`] = getHalf(this.$parent.spaceX, true);
style[`${styletype}Right`] = getHalf(this.$parent.spaceX, false);
}
if (utils.isNumber(this.$parent.spaceY) && this.$parent.spaceY !== 0) {
style[`${styletype}Top`] = getHalf(this.$parent.spaceY, true);
style[`${styletype}Bottom`] = getHalf(this.$parent.spaceY, false);
}
return style;
}
}