UNPKG

igniteui-webcomponents-inputs

Version:

Ignite UI Web Components inputs components.

604 lines (600 loc) 20.7 kB
import { XInput } from "./XInput"; import { ensureEnum, brushToString, stringToBrush, ensureBool, NamePatcher, toSpinal, enumToString, getAllPropertyNames } from "igniteui-webcomponents-core"; import { FontInfo } from "igniteui-webcomponents-core"; import { WebComponentRenderer, PortalManager } from "igniteui-webcomponents-core"; import { delegateCombine, delegateRemove } from "igniteui-webcomponents-core"; import { RegisterElementHelper } from "igniteui-webcomponents-core"; import { IgcXInputGroupItemComponent } from './igc-x-input-group-item-component'; import { IgcInputChangeEventArgs } from './igc-input-change-event-args'; import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core"; import { IgcKeyEventArgs } from "igniteui-webcomponents-core"; import { BaseControlTheme_$type } from "igniteui-webcomponents-core"; import { HorizontalAlignment_$type } from "igniteui-webcomponents-core"; let requiredStyle = ` `; let pending = []; let checked = /*@__PURE__*/ new WeakMap(); // TODO why not WeakSet? function ensureCss() { if (!document) { return; } if (checked.has(document)) { return; } injectCss(requiredStyle, "data-ig-input-style", () => { let temp = pending; pending = null; temp.forEach((v, i, a) => { //v.styleUpdated(); }); }); checked.set(document, true); } function injectCss(style, attributeName, onload = null) { for (let i = 0; i < document.head.children.length; i++) { let child = document.head.children[i]; if (child.tagName && child.tagName.toLowerCase() == "style" && child.hasAttribute(attributeName)) { return; } } let styleEle = document.createElement("style"); styleEle.textContent = style; styleEle.setAttribute(attributeName, 'true'); if (onload) { const onloadResolved = () => { styleEle.onload = null; onload(); }; styleEle.onload = onloadResolved; } document.head.appendChild(styleEle); } let IgcXInputComponent = /*@__PURE__*/ (() => { class IgcXInputComponent extends IgcXInputGroupItemComponent { constructor() { super(); this._disconnected = false; this._keyDown = null; this._keyDown_wrapped = null; this._keyUp = null; this._keyUp_wrapped = null; this._keyPress = null; this._keyPress_wrapped = null; this._change = null; this._change_wrapped = null; this._changing = null; this._changing_wrapped = null; this._compositionEnd = null; this._compositionEnd_wrapped = null; ensureCss(); if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._portalManager = new PortalManager("inputContent"); this._renderer = new WebComponentRenderer(this, document, true, {}, this._portalManager); this._container = this._renderer.createElement("div"); this._renderer.updateRoot(this._container); this._implementation = this.createImplementation(); this._implementation.externalObject = this; //this._container.setStyleProperty("width", "100%"); //this._container.setStyleProperty("height", "100%"); var root; root = this._container; if (this._container.getNativeElement() != null) { root = this._container.getNativeElement(); } this._wrapper = this._renderer; var input = this.i; this._input = input; input.provideContainer(this._renderer); this._onChildrenChanged(); //Checkbox.notifySizeChanged(); let mut = new MutationObserver((list) => { for (var mutation of list) { if (mutation.type == 'childList') { this._onChildrenChanged(); } } }); mut.observe(this, { childList: true }); //this._renderer.addSizeWatcher(() => { // this._checkbox.notifySizeChanged(); //}); } _onChildrenChanged() { var children = []; for (var i = 0; i < this.childNodes.length; i++) { var child = this.childNodes[i]; if (child !== this._container.getNativeElement()) { children.push(child); } } this._portalManager.onChildrenChanged(children); } // supports angular themes or custom properties set in CSS updateStyle() { this._styling(this, this); } destroy() { this._input.destroy(); this._wrapper.destroy(); } createImplementation() { return new XInput(); } disconnectedCallback() { this._disconnected = true; if (this.i) { this.i.onDetachedFromUI(); } } connectedCallback() { if (this._disconnected) { this._disconnected = false; if (this.i) { this.i.onAttachedToUI(); } return; } this.classList.add("ig-x-input"); this.classList.add("igc-x-input"); this.appendChild(this._container.getNativeElement()); this._attached = true; this.style.display = "inline-block"; this.style.verticalAlign = "middle"; //this.style.height = this._height; //this.style.width = this._width; this._flushQueuedAttributes(); // supports themes or custom properties set in CSS this._styling(this, this); this.afterContentInit(); } afterContentInit() { //this.i.notifySizeChanged(); } /** * @hidden */ get i() { return this._implementation; } static get observedAttributes() { if (IgcXInputComponent._observedAttributesIgcXInputComponent == null) { let names = getAllPropertyNames(IgcXInputComponent); for (let i = 0; i < names.length; i++) { names[i] = toSpinal(names[i]); } IgcXInputComponent._observedAttributesIgcXInputComponent = names; } return IgcXInputComponent._observedAttributesIgcXInputComponent; } static register() { if (!IgcXInputComponent._isElementRegistered) { IgcXInputComponent._isElementRegistered = true; RegisterElementHelper.registerElement(IgcXInputComponent.htmlTagName, IgcXInputComponent); } } /** * Gets or sets the base built in theme to use for the button. */ get baseTheme() { return this.i.w; } set baseTheme(v) { this.i.w = ensureEnum(BaseControlTheme_$type, v); this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.w)); } /** * Gets or sets the display density to use for the input. */ get density() { return this.i.aa; } set density(v) { this.i.aa = ensureEnum(ControlDisplayDensity_$type, v); this._a("density", enumToString(ControlDisplayDensity_$type, this.i.aa)); } /** * Gets the actual display density to use for the label. */ get actualDensity() { return this.i.z; } set actualDensity(v) { this.i.z = ensureEnum(ControlDisplayDensity_$type, v); this._a("actualDensity", enumToString(ControlDisplayDensity_$type, this.i.z)); } /** * Gets/Sets the input mask for the input. */ get mask() { return this.i.ce; } set mask(v) { this.i.ce = v; } /** * Gets/Sets the character representing a fillable spot in the input mask */ get promptChar() { return this.i.ci; } set promptChar(v) { this.i.ci = v; } /** * Specifies if the bound value includes the formatting symbols. */ get includeLiterals() { return this.i.au; } set includeLiterals(v) { this.i.au = ensureBool(v); this._a("includeLiterals", this.i.au); } get showSpinner() { return this.i.a1; } set showSpinner(v) { this.i.a1 = ensureBool(v); this._a("showSpinner", this.i.a1); } /** * Gets the actual color to use for the text color. */ get actualTextColor() { return brushToString(this.i.d4); } set actualTextColor(v) { this.i.d4 = stringToBrush(v); this._a("actualTextColor", brushToString(this.i.d4)); } /** * Gets the actual hover color to use for the text. */ get actualHoverTextColor() { return brushToString(this.i.d3); } set actualHoverTextColor(v) { this.i.d3 = stringToBrush(v); this._a("actualHoverTextColor", brushToString(this.i.d3)); } /** * Gets or sets the color to use for the text. */ get textColor() { return brushToString(this.i.d8); } set textColor(v) { this.i.d8 = stringToBrush(v); this._a("textColor", brushToString(this.i.d8)); } /** * Gets or sets the use for the button. */ get textStyle() { if (this.i.af == null) { return null; } return this.i.af.fontString; } set textStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.af = fi; this._a("textStyle", this.i.af != null ? this.i.af.fontString : ""); } /** * Gets or sets the type to use for the input. */ get inputType() { return this.i.b8; } set inputType(v) { this.i.b8 = v; } /** * Gets or sets the placeholder to use for the input. */ get placeholder() { return this.i.cg; } set placeholder(v) { this.i.cg = v; } /** * Gets or sets the color to use for the hovered text of the button regardless of type. */ get hoverTextColor() { return brushToString(this.i.d7); } set hoverTextColor(v) { this.i.d7 = stringToBrush(v); this._a("hoverTextColor", brushToString(this.i.d7)); } /** * Gets or sets the id to use for the checkbox. */ get id() { return this.i.b5; } set id(v) { this.i.b5 = v; } /** * Gets or sets TabIndex to use for the checkbox. */ get tabIndex() { return this.i.be; } set tabIndex(v) { this.i.be = +v; this._a("tabIndex", this.i.be); } /** * Gets or sets the for attribute to use for the input. */ get for() { return this.i.b2; } set for(v) { this.i.b2 = v; } /** * Gets or sets the value of the aria-label attribute. */ get ariaLabel() { return this.i.bx; } set ariaLabel(v) { this.i.bx = v; } /** * Gets or sets whether the input is hovered. */ get isHover() { return this.i.aw; } set isHover(v) { this.i.aw = ensureBool(v); this._a("isHover", this.i.aw); } /** * Gets or sets the value for the input. */ get value() { return this.i.cq; } set value(v) { this.i.cq = v; } get hasValue() { return this.i.at; } /** * Gets or sets whether the checkbox is disabled. */ get disabled() { return this.i.disabled; } set disabled(v) { this.i.disabled = ensureBool(v); this._a("disabled", this.i.disabled); } /** * Gets or sets whether the checkbox is readonly. */ get readonly() { return this.i.readonly; } set readonly(v) { this.i.readonly = ensureBool(v); this._a("readonly", this.i.readonly); } /** * Gets or sets the alignment of the text. */ get textAlignment() { return this.i.dy; } set textAlignment(v) { this.i.dy = ensureEnum(HorizontalAlignment_$type, v); this._a("textAlignment", enumToString(HorizontalAlignment_$type, this.i.dy)); } /** * Returns / Sets the beginning index of the selected text. When nothing is selected, this returns the position of the text input cursor (caret) inside of the input. */ get selectionStart() { return this.i.selectionStart; } set selectionStart(v) { this.i.selectionStart = +v; this._a("selectionStart", this.i.selectionStart); } /** * Returns / Sets the end index of the selected text. When nothing is selected, this returns the position of the text input cursor (caret) inside of the input. */ get selectionEnd() { return this.i.selectionEnd; } set selectionEnd(v) { this.i.selectionEnd = +v; this._a("selectionEnd", this.i.selectionEnd); } onDetachedFromUI() { this.i.onDetachedFromUI(); } onAttachedToUI() { this.i.onAttachedToUI(); } /** * Exports visual information about the current state of the grid. */ exportVisualModel() { let iv = this.i.bg(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.b1(); return (iv); } setSelectionRange(selectionStart, selectionEnd) { this.i.dr(selectionStart, selectionEnd); } blur() { this.i.ct(); } select() { this.i.dp(); } get keyDown() { return this._keyDown; } set keyDown(ev) { if (this._keyDown_wrapped !== null) { this.i.keyDown = delegateRemove(this.i.keyDown, this._keyDown_wrapped); this._keyDown_wrapped = null; this._keyDown = null; } this._keyDown = ev; this._keyDown_wrapped = (o, e) => { let outerArgs = new IgcKeyEventArgs(); outerArgs._provideImplementation(e); if (this.beforeKeyDown) { this.beforeKeyDown(this, outerArgs); } if (this._keyDown) { this._keyDown(this, outerArgs); } }; this.i.keyDown = delegateCombine(this.i.keyDown, this._keyDown_wrapped); ; } get keyUp() { return this._keyUp; } set keyUp(ev) { if (this._keyUp_wrapped !== null) { this.i.keyUp = delegateRemove(this.i.keyUp, this._keyUp_wrapped); this._keyUp_wrapped = null; this._keyUp = null; } this._keyUp = ev; this._keyUp_wrapped = (o, e) => { let outerArgs = new IgcKeyEventArgs(); outerArgs._provideImplementation(e); if (this.beforeKeyUp) { this.beforeKeyUp(this, outerArgs); } if (this._keyUp) { this._keyUp(this, outerArgs); } }; this.i.keyUp = delegateCombine(this.i.keyUp, this._keyUp_wrapped); ; } get keyPress() { return this._keyPress; } set keyPress(ev) { if (this._keyPress_wrapped !== null) { this.i.keyPress = delegateRemove(this.i.keyPress, this._keyPress_wrapped); this._keyPress_wrapped = null; this._keyPress = null; } this._keyPress = ev; this._keyPress_wrapped = (o, e) => { let outerArgs = new IgcKeyEventArgs(); outerArgs._provideImplementation(e); if (this.beforeKeyPress) { this.beforeKeyPress(this, outerArgs); } if (this._keyPress) { this._keyPress(this, outerArgs); } }; this.i.keyPress = delegateCombine(this.i.keyPress, this._keyPress_wrapped); ; } get change() { return this._change; } set change(ev) { if (this._change_wrapped !== null) { this.i.change = delegateRemove(this.i.change, this._change_wrapped); this._change_wrapped = null; this._change = null; } this._change = ev; this._change_wrapped = (o, e) => { let outerArgs = new IgcInputChangeEventArgs(); outerArgs._provideImplementation(e); if (this.beforeChange) { this.beforeChange(this, outerArgs); } if (this._change) { this._change(this, outerArgs); } }; this.i.change = delegateCombine(this.i.change, this._change_wrapped); ; } get changing() { return this._changing; } set changing(ev) { if (this._changing_wrapped !== null) { this.i.changing = delegateRemove(this.i.changing, this._changing_wrapped); this._changing_wrapped = null; this._changing = null; } this._changing = ev; this._changing_wrapped = (o, e) => { let outerArgs = new IgcInputChangeEventArgs(); outerArgs._provideImplementation(e); if (this.beforeChanging) { this.beforeChanging(this, outerArgs); } if (this._changing) { this._changing(this, outerArgs); } }; this.i.changing = delegateCombine(this.i.changing, this._changing_wrapped); ; } get compositionEnd() { return this._compositionEnd; } set compositionEnd(ev) { if (this._compositionEnd_wrapped !== null) { this.i.compositionEnd = delegateRemove(this.i.compositionEnd, this._compositionEnd_wrapped); this._compositionEnd_wrapped = null; this._compositionEnd = null; } this._compositionEnd = ev; this._compositionEnd_wrapped = (o, e) => { let outerArgs = new IgcInputChangeEventArgs(); outerArgs._provideImplementation(e); if (this.beforeCompositionEnd) { this.beforeCompositionEnd(this, outerArgs); } if (this._compositionEnd) { this._compositionEnd(this, outerArgs); } }; this.i.compositionEnd = delegateCombine(this.i.compositionEnd, this._compositionEnd_wrapped); ; } } IgcXInputComponent._observedAttributesIgcXInputComponent = null; IgcXInputComponent.htmlTagName = "igc-x-input"; IgcXInputComponent._isElementRegistered = false; return IgcXInputComponent; })(); export { IgcXInputComponent };