igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
157 lines • 5.36 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { html } from 'lit';
import { property } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { watch } from '../common/decorators/watch.js';
import { registerComponent } from '../common/definitions/register.js';
import { partNameMap } from '../common/util.js';
import { IgcMaskInputBaseComponent, } from './mask-input-base.js';
import { maskValidators } from './validators.js';
class IgcMaskInputComponent extends IgcMaskInputBaseComponent {
constructor() {
super(...arguments);
this._value = '';
this.valueMode = 'raw';
}
static register() {
registerComponent(IgcMaskInputComponent);
}
get __validators() {
return maskValidators;
}
get value() {
return this.valueMode !== 'raw' ? this.maskedValue : this._value;
}
set value(string) {
this._value = string ?? '';
this.maskedValue = this.parser.apply(this._value);
this.updateMaskedValue();
this.updateFormValue();
}
get mask() {
return this._mask;
}
set mask(value) {
this._mask = value;
this.parser.mask = value;
if (this.value) {
this.maskedValue = this.parser.apply(this._value);
}
}
connectedCallback() {
super.connectedCallback();
this.updateValidity();
}
setDefaultValue() {
this._defaultValue = this._value;
}
updateFormValue() {
this.valueMode === 'raw'
? this.setFormValue(this.value || null, this.value)
: this.setFormValue(this.maskedValue || null, this.maskedValue);
this.updateValidity();
this.setInvalidState();
}
promptChange() {
this.parser.prompt = this.prompt;
if (this.value) {
this.maskedValue = this.parser.apply(this._value);
}
}
async updateInput(string, range) {
const { value, end } = this.parser.replace(this.maskedValue, string, range.start, range.end);
this.maskedValue = value;
this._value = this.parser.parse(value);
this.updateFormValue();
this.requestUpdate();
if (range.start !== this.mask.length) {
this.emitEvent('igcInput', { detail: this.value });
}
await this.updateComplete;
this.input.setSelectionRange(end, end);
}
handleDragEnter() {
if (!this.focused && !this._value) {
this.maskedValue = this.emptyMask;
}
}
handleDragLeave() {
if (!this.focused) {
this.updateMaskedValue();
}
}
async handleFocus() {
this.focused = true;
if (this.readOnly) {
return;
}
if (!this._value) {
this.maskedValue = this.emptyMask;
await this.updateComplete;
this.select();
}
}
handleBlur() {
this.focused = false;
this.updateMaskedValue();
this.invalid = !this.checkValidity();
}
handleChange() {
this.emitEvent('igcChange', { detail: this.value });
}
updateMaskedValue() {
if (this.maskedValue === this.emptyMask) {
this.maskedValue = '';
}
}
_updateSetRangeTextValue() {
this.value = this.parser.parse(this.maskedValue);
}
renderInput() {
return html `
<input
type="text"
part=${partNameMap(this.resolvePartNames('input'))}
name=${ifDefined(this.name)}
.value=${live(this.maskedValue)}
.placeholder=${live(this.placeholder ?? this.parser.escapedMask)}
?readonly=${this.readOnly}
?disabled=${this.disabled}
=${this.handleDragEnter}
=${this.handleDragLeave}
=${this.handleDragStart}
=${this.handleBlur}
=${this.handleFocus}
=${this.handleCut}
=${this.handleChange}
=${this.handleClick}
=${this.handleCompositionStart}
=${this.handleCompositionEnd}
=${this.handleInput}
aria-invalid=${this.invalid ? 'true' : 'false'}
=${this.handleKeydown}
/>
`;
}
}
IgcMaskInputComponent.tagName = 'igc-mask-input';
export default IgcMaskInputComponent;
__decorate([
property({ attribute: 'value-mode' })
], IgcMaskInputComponent.prototype, "valueMode", void 0);
__decorate([
property()
], IgcMaskInputComponent.prototype, "value", null);
__decorate([
property()
], IgcMaskInputComponent.prototype, "mask", null);
__decorate([
watch('prompt')
], IgcMaskInputComponent.prototype, "promptChange", null);
//# sourceMappingURL=mask-input.js.map