UNPKG

igniteui-webcomponents-inputs

Version:

Ignite UI Web Components inputs components.

531 lines (530 loc) 20 kB
import { ColorEditor } from "./ColorEditor"; import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, toSpinal, enumToString, getAllPropertyNames, fromSpinal } 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 { TypeRegistrar } from "igniteui-webcomponents-core"; import { RegisterElementHelper } from "igniteui-webcomponents-core"; import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core"; import { BaseControlTheme_$type } from "igniteui-webcomponents-core"; import { IgcHTMLElement } from "igniteui-webcomponents-core"; import { IgcColorEditorPanelSelectedValueChangedEventArgs } from "./igc-color-editor-panel-selected-value-changed-event-args"; import { IgcColorEditorLostFocusEventArgs } from "./igc-color-editor-lost-focus-event-args"; import { IgcColorEditorGotFocusEventArgs } from "./igc-color-editor-got-focus-event-args"; export let IgcColorEditorComponent = /*@__PURE__*/ (() => { class IgcColorEditorComponent extends IgcHTMLElement { constructor() { super(); this._disconnected = false; this._settingAttributes = false; this._attached = false; this._queuedSetAttributes = []; this._updatingFromAttribute = false; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; this._valueChanged = null; this._valueChanged_wrapped = null; this._valueChanging = null; this._valueChanging_wrapped = null; this._gotFocus = null; this._gotFocus_wrapped = null; this._lostFocus = null; this._lostFocus_wrapped = null; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._portalManager = new PortalManager("colorEditorContent"); 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 colorEditor = this.i; this._colorEditor = colorEditor; colorEditor.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._colorEditor.destroy(); this._wrapper.destroy(); } createImplementation() { return new ColorEditor(); } 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-color-editor"); this.classList.add("igc-color-editor"); this.appendChild(this._container.getNativeElement()); this._attached = true; this.style.display = "block"; //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; } /** * @hidden */ static _createFromInternal(internal) { if (!internal) { return null; } if (!internal.$type) { return null; } let name = internal.$type.name; let externalName = "Igc" + name + "Component"; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } _enqueueSetAttribute(attrName, attrValue) { this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue }); } _flushQueuedAttributes() { this._settingAttributes = true; for (let i = 0; i < this._queuedSetAttributes.length; i++) { this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue); } this._settingAttributes = false; this._queuedSetAttributes.length = 0; } _a(attrName, attrValue) { if (this._updatingFromAttribute) { return; } if (attrValue) { attrValue = attrValue.toString(); } this._settingAttributes = true; attrName = toSpinal(attrName); if (this._attached) { this.setAttribute(attrName, attrValue); } else { this._enqueueSetAttribute(attrName, attrValue); } this._settingAttributes = false; } static get observedAttributes() { if (IgcColorEditorComponent._observedAttributesIgcColorEditorComponent == null) { let names = getAllPropertyNames(IgcColorEditorComponent); for (let i = 0; i < names.length; i++) { names[i] = toSpinal(names[i]); } IgcColorEditorComponent._observedAttributesIgcColorEditorComponent = names; } return IgcColorEditorComponent._observedAttributesIgcColorEditorComponent; } attributeChangedCallback(name, oldValue, newValue) { if (this._settingAttributes) { return; } let setName = fromSpinal(name); this._updatingFromAttribute = true; this[setName] = newValue; this._updatingFromAttribute = false; } static register() { if (!IgcColorEditorComponent._isElementRegistered) { IgcColorEditorComponent._isElementRegistered = true; RegisterElementHelper.registerElement(IgcColorEditorComponent.htmlTagName, IgcColorEditorComponent); } } /** * Gets or Sets color value of the editor. */ get value() { return brushToString(this.i.value); } set value(v) { this.i.value = stringToBrush(v); this._a("value", brushToString(this.i.value)); } /** * Gets or Sets the property name that contains the label. */ get label() { return this.i.az; } set label(v) { this.i.az = v; } /** * Gets or sets the color to use for the text. */ get labelTextColor() { return brushToString(this.i.cn); } set labelTextColor(v) { this.i.cn = stringToBrush(v); this._a("labelTextColor", brushToString(this.i.cn)); } /** * Gets or sets the font to use for the input. */ get labelTextStyle() { if (this.i.o == null) { return null; } return this.i.o.fontString; } set labelTextStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.o = fi; this._a("labelTextStyle", this.i.o != null ? this.i.o.fontString : ""); } /** * Gets or sets the display density to use for the date pcicker. */ get density() { return this.i.k; } set density(v) { this.i.k = ensureEnum(ControlDisplayDensity_$type, v); this._a("density", enumToString(ControlDisplayDensity_$type, this.i.k)); } /** * Gets or sets the base built in theme to use for the date picker. */ get baseTheme() { return this.i.i; } set baseTheme(v) { this.i.i = ensureEnum(BaseControlTheme_$type, v); this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.i)); } /** * Gets or sets the font to use for the combobox. */ get textStyle() { if (this.i.p == null) { return null; } return this.i.p.fontString; } set textStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.p = fi; this._a("textStyle", this.i.p != null ? this.i.p.fontString : ""); } /** * Gets or Sets the text color */ get textColor() { return brushToString(this.i.co); } set textColor(v) { this.i.co = stringToBrush(v); this._a("textColor", brushToString(this.i.co)); } /** * Gets or Sets the text color */ get iconColor() { return brushToString(this.i.cm); } set iconColor(v) { this.i.cm = stringToBrush(v); this._a("iconColor", brushToString(this.i.cm)); } /** * Gets or sets the ShowClearButton property to detirmine if the clear button is shown */ get showClearButton() { return this.i.am; } set showClearButton(v) { this.i.am = ensureBool(v); this._a("showClearButton", this.i.am); } /** * Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed */ get allowTextInput() { return this.i.ag; } set allowTextInput(v) { this.i.ag = ensureBool(v); this._a("allowTextInput", this.i.ag); } /** * Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed */ get openOnFocus() { return this.i.ak; } set openOnFocus(v) { this.i.ak = ensureBool(v); this._a("openOnFocus", this.i.ak); } get isDisabled() { return this.i.ah; } set isDisabled(v) { this.i.ah = ensureBool(v); this._a("isDisabled", this.i.ah); } /** * Indicates that the editor dropdown will position itself relative to the window instead of the document. */ get isFixed() { return this.i.ai; } set isFixed(v) { this.i.ai = ensureBool(v); this._a("isFixed", this.i.ai); } /** * Indicates that the dropdown should open as a child of the color editor. */ get openAsChild() { return this.i.aj; } set openAsChild(v) { this.i.aj = ensureBool(v); this._a("openAsChild", this.i.aj); } /** * Indicates that the dropdown will place itself into the browser top layer. */ get useTopLayer() { return this.i.an; } set useTopLayer(v) { this.i.an = ensureBool(v); this._a("useTopLayer", this.i.an); } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } return null; } get hasUserValues() { return this._hasUserValues; } __m(propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } } _styling(container, component, parent) { if (this._inStyling) { return; } this._inStyling = true; this._stylingContainer = container; this._stylingParent = component; let genericPrefix = ""; let typeName = this.i.$type.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } genericPrefix = toSpinal("ColorEditorComponent"); let additionalPrefixes = []; let prefix = toSpinal(typeName); additionalPrefixes.push(prefix + "-"); let b = this.i.$type.baseType; while (b && b.name != "Object" && b.name != "Base" && b.name != "Control" && b.Name != "DependencyObject" && b.Name != "FrameworkElement") { typeName = b.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } let basePrefix = toSpinal(typeName); additionalPrefixes.push(basePrefix + "-"); b = b.baseType; } if (parent) { let parentTypeName = parent.i.$type.name; if (parentTypeName.indexOf("Xam") === 0) { parentTypeName = parentTypeName.substring(3); } let parentPrefix = toSpinal(parentTypeName); additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-"); additionalPrefixes.push(parentPrefix + "-" + prefix + "-"); } initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes); if (this._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; } select() { this.i.b8(); } /** * Called when color is selected. */ get valueChanged() { return this._valueChanged; } set valueChanged(ev) { if (this._valueChanged_wrapped !== null) { this.i.valueChanged = delegateRemove(this.i.valueChanged, this._valueChanged_wrapped); this._valueChanged_wrapped = null; this._valueChanged = null; } this._valueChanged = ev; this._valueChanged_wrapped = (o, e) => { let outerArgs = new IgcColorEditorPanelSelectedValueChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeValueChanged) { this.beforeValueChanged(this, outerArgs); } if (this._valueChanged) { this._valueChanged(this, outerArgs); } }; this.i.valueChanged = delegateCombine(this.i.valueChanged, this._valueChanged_wrapped); ; } /** * Called when color is selected. */ get valueChanging() { return this._valueChanging; } set valueChanging(ev) { if (this._valueChanging_wrapped !== null) { this.i.valueChanging = delegateRemove(this.i.valueChanging, this._valueChanging_wrapped); this._valueChanging_wrapped = null; this._valueChanging = null; } this._valueChanging = ev; this._valueChanging_wrapped = (o, e) => { let outerArgs = new IgcColorEditorPanelSelectedValueChangedEventArgs(); outerArgs._provideImplementation(e); if (this.beforeValueChanging) { this.beforeValueChanging(this, outerArgs); } if (this._valueChanging) { this._valueChanging(this, outerArgs); } }; this.i.valueChanging = delegateCombine(this.i.valueChanging, this._valueChanging_wrapped); ; } get gotFocus() { return this._gotFocus; } set gotFocus(ev) { if (this._gotFocus_wrapped !== null) { this.i.gotFocus = delegateRemove(this.i.gotFocus, this._gotFocus_wrapped); this._gotFocus_wrapped = null; this._gotFocus = null; } this._gotFocus = ev; this._gotFocus_wrapped = (o, e) => { let outerArgs = new IgcColorEditorGotFocusEventArgs(); outerArgs._provideImplementation(e); if (this.beforeGotFocus) { this.beforeGotFocus(this, outerArgs); } if (this._gotFocus) { this._gotFocus(this, outerArgs); } }; this.i.gotFocus = delegateCombine(this.i.gotFocus, this._gotFocus_wrapped); ; } get lostFocus() { return this._lostFocus; } set lostFocus(ev) { if (this._lostFocus_wrapped !== null) { this.i.lostFocus = delegateRemove(this.i.lostFocus, this._lostFocus_wrapped); this._lostFocus_wrapped = null; this._lostFocus = null; } this._lostFocus = ev; this._lostFocus_wrapped = (o, e) => { let outerArgs = new IgcColorEditorLostFocusEventArgs(); outerArgs._provideImplementation(e); if (this.beforeLostFocus) { this.beforeLostFocus(this, outerArgs); } if (this._lostFocus) { this._lostFocus(this, outerArgs); } }; this.i.lostFocus = delegateCombine(this.i.lostFocus, this._lostFocus_wrapped); ; } } IgcColorEditorComponent._observedAttributesIgcColorEditorComponent = null; IgcColorEditorComponent.htmlTagName = "igc-color-editor"; IgcColorEditorComponent._isElementRegistered = false; return IgcColorEditorComponent; })();