igniteui-webcomponents-inputs
Version:
Ignite UI Web Components inputs components.
764 lines (761 loc) • 26.4 kB
JavaScript
import { __extends, __values } from "tslib";
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";
var requiredStyle = "\n\n";
var pending = [];
var checked = /*@__PURE__*/ new WeakMap(); // TODO why not WeakSet?
function ensureCss() {
if (!document) {
return;
}
if (checked.has(document)) {
return;
}
injectCss(requiredStyle, "data-ig-input-style", function () {
var temp = pending;
pending = null;
temp.forEach(function (v, i, a) {
//v.styleUpdated();
});
});
checked.set(document, true);
}
function injectCss(style, attributeName, onload) {
if (onload === void 0) {
onload = null;
}
for (var i = 0; i < document.head.children.length; i++) {
var child = document.head.children[i];
if (child.tagName &&
child.tagName.toLowerCase() == "style" && child.hasAttribute(attributeName)) {
return;
}
}
var styleEle = document.createElement("style");
styleEle.textContent = style;
styleEle.setAttribute(attributeName, 'true');
if (onload) {
var onloadResolved = function () {
styleEle.onload = null;
onload();
};
styleEle.onload = onloadResolved;
}
document.head.appendChild(styleEle);
}
export var IgcXInputComponent = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgcXInputComponent, _super);
function IgcXInputComponent() {
var _this = _super.call(this) || this;
_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();
var mut = new MutationObserver(function (list) {
var e_1, _b;
try {
for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
var mutation = list_1_1.value;
if (mutation.type == 'childList') {
_this._onChildrenChanged();
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (list_1_1 && !list_1_1.done && (_b = list_1.return))
_b.call(list_1);
}
finally {
if (e_1)
throw e_1.error;
}
}
});
mut.observe(_this, {
childList: true
});
return _this;
//this._renderer.addSizeWatcher(() => {
// this._checkbox.notifySizeChanged();
//});
}
IgcXInputComponent.prototype._onChildrenChanged = function () {
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
IgcXInputComponent.prototype.updateStyle = function () {
this._styling(this, this);
};
IgcXInputComponent.prototype.destroy = function () {
this._input.destroy();
this._wrapper.destroy();
};
IgcXInputComponent.prototype.createImplementation = function () {
return new XInput();
};
IgcXInputComponent.prototype.disconnectedCallback = function () {
this._disconnected = true;
if (this.i) {
this.i.onDetachedFromUI();
}
};
IgcXInputComponent.prototype.connectedCallback = function () {
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();
};
IgcXInputComponent.prototype.afterContentInit = function () {
//this.i.notifySizeChanged();
};
Object.defineProperty(IgcXInputComponent.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent, "observedAttributes", {
get: function () {
if (IgcXInputComponent._observedAttributesIgcXInputComponent == null) {
var names = getAllPropertyNames(IgcXInputComponent);
for (var i = 0; i < names.length; i++) {
names[i] = toSpinal(names[i]);
}
IgcXInputComponent._observedAttributesIgcXInputComponent = names;
}
return IgcXInputComponent._observedAttributesIgcXInputComponent;
},
enumerable: false,
configurable: true
});
IgcXInputComponent.register = function () {
if (!IgcXInputComponent._isElementRegistered) {
IgcXInputComponent._isElementRegistered = true;
RegisterElementHelper.registerElement(IgcXInputComponent.htmlTagName, IgcXInputComponent);
}
};
Object.defineProperty(IgcXInputComponent.prototype, "baseTheme", {
/**
* Gets or sets the base built in theme to use for the button.
*/
get: function () {
return this.i.w;
},
set: function (v) {
this.i.w = ensureEnum(BaseControlTheme_$type, v);
this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.w));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "density", {
/**
* Gets or sets the display density to use for the input.
*/
get: function () {
return this.i.aa;
},
set: function (v) {
this.i.aa = ensureEnum(ControlDisplayDensity_$type, v);
this._a("density", enumToString(ControlDisplayDensity_$type, this.i.aa));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "actualDensity", {
/**
* Gets the actual display density to use for the label.
*/
get: function () {
return this.i.z;
},
set: function (v) {
this.i.z = ensureEnum(ControlDisplayDensity_$type, v);
this._a("actualDensity", enumToString(ControlDisplayDensity_$type, this.i.z));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "mask", {
/**
* Gets/Sets the input mask for the input.
*/
get: function () {
return this.i.ce;
},
set: function (v) {
this.i.ce = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "promptChar", {
/**
* Gets/Sets the character representing a fillable spot in the input mask
*/
get: function () {
return this.i.ci;
},
set: function (v) {
this.i.ci = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "includeLiterals", {
/**
* Specifies if the bound value includes the formatting symbols.
*/
get: function () {
return this.i.au;
},
set: function (v) {
this.i.au = ensureBool(v);
this._a("includeLiterals", this.i.au);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "showSpinner", {
get: function () {
return this.i.a1;
},
set: function (v) {
this.i.a1 = ensureBool(v);
this._a("showSpinner", this.i.a1);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "actualTextColor", {
/**
* Gets the actual color to use for the text color.
*/
get: function () {
return brushToString(this.i.d4);
},
set: function (v) {
this.i.d4 = stringToBrush(v);
this._a("actualTextColor", brushToString(this.i.d4));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "actualHoverTextColor", {
/**
* Gets the actual hover color to use for the text.
*/
get: function () {
return brushToString(this.i.d3);
},
set: function (v) {
this.i.d3 = stringToBrush(v);
this._a("actualHoverTextColor", brushToString(this.i.d3));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "textColor", {
/**
* Gets or sets the color to use for the text.
*/
get: function () {
return brushToString(this.i.d8);
},
set: function (v) {
this.i.d8 = stringToBrush(v);
this._a("textColor", brushToString(this.i.d8));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "textStyle", {
/**
* Gets or sets the use for the button.
*/
get: function () {
if (this.i.af == null) {
return null;
}
return this.i.af.fontString;
},
set: function (v) {
var fi = new FontInfo();
fi.fontString = v;
this.i.af = fi;
this._a("textStyle", this.i.af != null ? this.i.af.fontString : "");
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "inputType", {
/**
* Gets or sets the type to use for the input.
*/
get: function () {
return this.i.b8;
},
set: function (v) {
this.i.b8 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "placeholder", {
/**
* Gets or sets the placeholder to use for the input.
*/
get: function () {
return this.i.cg;
},
set: function (v) {
this.i.cg = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "hoverTextColor", {
/**
* Gets or sets the color to use for the hovered text of the button regardless of type.
*/
get: function () {
return brushToString(this.i.d7);
},
set: function (v) {
this.i.d7 = stringToBrush(v);
this._a("hoverTextColor", brushToString(this.i.d7));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "id", {
/**
* Gets or sets the id to use for the checkbox.
*/
get: function () {
return this.i.b5;
},
set: function (v) {
this.i.b5 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "tabIndex", {
/**
* Gets or sets TabIndex to use for the checkbox.
*/
get: function () {
return this.i.be;
},
set: function (v) {
this.i.be = +v;
this._a("tabIndex", this.i.be);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "for", {
/**
* Gets or sets the for attribute to use for the input.
*/
get: function () {
return this.i.b2;
},
set: function (v) {
this.i.b2 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "ariaLabel", {
/**
* Gets or sets the value of the aria-label attribute.
*/
get: function () {
return this.i.bx;
},
set: function (v) {
this.i.bx = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "isHover", {
/**
* Gets or sets whether the input is hovered.
*/
get: function () {
return this.i.aw;
},
set: function (v) {
this.i.aw = ensureBool(v);
this._a("isHover", this.i.aw);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "value", {
/**
* Gets or sets the value for the input.
*/
get: function () {
return this.i.cq;
},
set: function (v) {
this.i.cq = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "hasValue", {
get: function () {
return this.i.at;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "disabled", {
/**
* Gets or sets whether the checkbox is disabled.
*/
get: function () {
return this.i.disabled;
},
set: function (v) {
this.i.disabled = ensureBool(v);
this._a("disabled", this.i.disabled);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "readonly", {
/**
* Gets or sets whether the checkbox is readonly.
*/
get: function () {
return this.i.readonly;
},
set: function (v) {
this.i.readonly = ensureBool(v);
this._a("readonly", this.i.readonly);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "textAlignment", {
/**
* Gets or sets the alignment of the text.
*/
get: function () {
return this.i.dy;
},
set: function (v) {
this.i.dy = ensureEnum(HorizontalAlignment_$type, v);
this._a("textAlignment", enumToString(HorizontalAlignment_$type, this.i.dy));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "selectionStart", {
/**
* 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: function () {
return this.i.selectionStart;
},
set: function (v) {
this.i.selectionStart = +v;
this._a("selectionStart", this.i.selectionStart);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "selectionEnd", {
/**
* 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: function () {
return this.i.selectionEnd;
},
set: function (v) {
this.i.selectionEnd = +v;
this._a("selectionEnd", this.i.selectionEnd);
},
enumerable: false,
configurable: true
});
IgcXInputComponent.prototype.onDetachedFromUI = function () {
this.i.onDetachedFromUI();
};
IgcXInputComponent.prototype.onAttachedToUI = function () {
this.i.onAttachedToUI();
};
/**
* Exports visual information about the current state of the grid.
*/
IgcXInputComponent.prototype.exportVisualModel = function () {
var iv = this.i.bg();
return (iv);
};
/**
* Returns a serialized copy of the exported visual model
*/
IgcXInputComponent.prototype.exportSerializedVisualModel = function () {
var iv = this.i.b1();
return (iv);
};
IgcXInputComponent.prototype.setSelectionRange = function (selectionStart, selectionEnd) {
this.i.dr(selectionStart, selectionEnd);
};
IgcXInputComponent.prototype.blur = function () {
this.i.ct();
};
IgcXInputComponent.prototype.select = function () {
this.i.dp();
};
Object.defineProperty(IgcXInputComponent.prototype, "keyDown", {
get: function () {
return this._keyDown;
},
set: function (ev) {
var _this = this;
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 = function (o, e) {
var 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);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "keyUp", {
get: function () {
return this._keyUp;
},
set: function (ev) {
var _this = this;
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 = function (o, e) {
var 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);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "keyPress", {
get: function () {
return this._keyPress;
},
set: function (ev) {
var _this = this;
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 = function (o, e) {
var 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);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "change", {
get: function () {
return this._change;
},
set: function (ev) {
var _this = this;
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 = function (o, e) {
var 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);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "changing", {
get: function () {
return this._changing;
},
set: function (ev) {
var _this = this;
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 = function (o, e) {
var 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);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXInputComponent.prototype, "compositionEnd", {
get: function () {
return this._compositionEnd;
},
set: function (ev) {
var _this = this;
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 = function (o, e) {
var 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);
;
},
enumerable: false,
configurable: true
});
IgcXInputComponent._observedAttributesIgcXInputComponent = null;
IgcXInputComponent.htmlTagName = "igc-x-input";
IgcXInputComponent._isElementRegistered = false;
return IgcXInputComponent;
}(IgcXInputGroupItemComponent));