UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

377 lines (376 loc) 13.6 kB
import * as React from 'react'; import { delegateCombine, delegateRemove } from "igniteui-react-core"; import { IgrGridConditionalStylePropertyCollection } from "./igr-grid-conditional-style-property-collection"; import { IgrPropertyUpdatedEventArgs } from "igniteui-react-core"; import { IgrGridConditionFilterStringErrorsParsingEventArgs } from "./igr-grid-condition-filter-string-errors-parsing-event-args"; import { GridConditionalStyle } from "./GridConditionalStyle"; import { TypeRegistrar } from "igniteui-react-core"; import { ContentChildrenManager } from "igniteui-react-core"; import { CollectionAdapter, NamePatcher, getModifiedProps, isValidProp, ensureBool, toSpinal, initializePropertiesFromCss } from "igniteui-react-core"; import { GridConditionalStyleProperty } from "./GridConditionalStyleProperty"; import { NotifyCollectionChangedAction } from "igniteui-react-core"; export class IgrGridConditionalStyle extends React.Component { createImplementation() { return new GridConditionalStyle(); } get nativeElement() { return this._implementation.nativeElement; } /** * @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 = "Igr" + name; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } onImplementationCreated() { } _initializeAdapters() { if (!this._contentChildrenManager) { const resolveNested = ((props, propName, nestedPropName) => { var _a; const prop = props[propName]; if (Array.isArray(prop)) { return prop.map(x => { var _a; return (_a = x[nestedPropName]) !== null && _a !== void 0 ? _a : resolveNested(x.props, propName, nestedPropName); }).join("_"); } else if (prop) { return (_a = prop.props[nestedPropName]) !== null && _a !== void 0 ? _a : resolveNested(prop.props, propName, nestedPropName); } else { return props[nestedPropName]; } }); this._contentChildrenManager = new ContentChildrenManager((ch) => { const key = ch.key || ch.props.name; if (!key) { const type = (ch.type); const instance = new type; const name = instance.i.$type.name; switch (name) { default: return undefined; } } return key; }, (ch) => { const key = ch.key || ch.props.name; if (!key) { const type = (ch.type); const instance = new type; const name = instance.i.$type.name; switch (name) { default: return undefined; } } return key; }, () => { if (this._updateContentChildren) { this._updateContentChildren(); } else if (this._updateAdapters) { this._updateAdapters(); } }); } this._propertiesAdapter = new CollectionAdapter(this.contentProperties, this.i.properties, this.actualProperties, (c) => c.i, (i) => { if (this._initializeElement) { this._initializeElement(i); } }, (i) => { if (this._destroyElement) { this._destroyElement(i); } }); if (super["_initializeAdapters"]) { super["_initializeAdapters"](); } } _updateAdapters() { if (super["_updateAdapters"]) { super["_updateAdapters"](); } let contentChildrenActual = this._contentChildrenManager.contentChildrenActual; this.contentProperties.length = 0; for (var i = 0; i < contentChildrenActual.length; i++) { if ((GridConditionalStyleProperty.$type).isAssignableFrom(contentChildrenActual[i].i.$type)) { this.contentProperties.push(contentChildrenActual[i]); } } if (this._propertiesAdapter != null) { this._propertiesAdapter.notifyContentChanged(); } } constructor(props) { super(props); this.mounted = false; this._properties = null; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; this._propertyUpdated = null; this._propertyUpdated_wrapped = null; this._filterStringErrorsParsing = null; this._filterStringErrorsParsing_wrapped = null; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._implementation = this.createImplementation(); this._implementation.externalObject = this; this.onImplementationCreated(); if (this._initializeAdapters) { this._initializeAdapters(); } } componentDidMount() { this.mounted = true; for (const p of Object.keys(this.props)) { if (isValidProp(this, p)) { this[p] = this.props[p]; } } } shouldComponentUpdate(nextProps, nextState) { const mod = getModifiedProps(this.props, nextProps); for (const p of Object.keys(mod)) { if (isValidProp(this, p)) { this[p] = mod[p]; } } return true; } render() { let children = this._contentChildrenManager.getChildren(this.props.children); let div = React.createElement("div", { children: children }); return div; } get isCompound() { return this.i.s; } get styleKey() { return this.i.ak; } set styleKey(v) { this.i.ak = v; } get isTransitionInEnabled() { return this.i.w; } set isTransitionInEnabled(v) { this.i.w = ensureBool(v); } get actualProperties() { if (!this._actualProperties) { this._actualProperties = []; } return this._actualProperties; } get contentProperties() { if (!this._contentProperties) { this._contentProperties = []; } return this._contentProperties; } get properties() { if (this._properties === null) { let coll = new IgrGridConditionalStylePropertyCollection(); let inner = coll._innerColl; this._properties = coll; inner.addListener((sender, e) => { switch (e.action) { case NotifyCollectionChangedAction.Add: this._propertiesAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0)); break; case NotifyCollectionChangedAction.Remove: this._propertiesAdapter.removeManualItemAt(e.oldStartingIndex); break; case NotifyCollectionChangedAction.Replace: this._propertiesAdapter.removeManualItemAt(e.oldStartingIndex); this._propertiesAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0)); break; case NotifyCollectionChangedAction.Reset: this._propertiesAdapter.clearManualItems(); break; } }); ; } return this._properties; } get conditionString() { return this.i.ae; } set conditionString(v) { this.i.ae = v; } get condition() { return this.i.e; } set condition(v) { this.i.e = v; } get isFieldMinimumNeeded() { return this.i.u; } set isFieldMinimumNeeded(v) { this.i.u = ensureBool(v); } get isFieldMaximumNeeded() { return this.i.t; } set isFieldMaximumNeeded(v) { this.i.t = ensureBool(v); } get isFieldSumNeeded() { return this.i.v; } set isFieldSumNeeded(v) { this.i.v = ensureBool(v); } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.properties != null && this.properties.findByName && this.properties.findByName(name)) { return this.properties.findByName(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("GridConditionalStyle"); 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; } requiresGlobalValues() { let iv = this.i.x(); return (iv); } actualNeedsFieldMinimum() { let iv = this.i.q(); return (iv); } actualNeedsFieldMaximum() { let iv = this.i.p(); return (iv); } actualNeedsFieldSum() { let iv = this.i.r(); return (iv); } get propertyUpdated() { return this._propertyUpdated; } set propertyUpdated(ev) { if (this._propertyUpdated_wrapped !== null) { this.i.propertyUpdated = delegateRemove(this.i.propertyUpdated, this._propertyUpdated_wrapped); this._propertyUpdated_wrapped = null; this._propertyUpdated = null; } this._propertyUpdated = ev; this._propertyUpdated_wrapped = (o, e) => { let outerArgs = new IgrPropertyUpdatedEventArgs(); outerArgs._provideImplementation(e); if (this.beforePropertyUpdated) { this.beforePropertyUpdated(this, outerArgs); } if (this._propertyUpdated) { this._propertyUpdated(this, outerArgs); } }; this.i.propertyUpdated = delegateCombine(this.i.propertyUpdated, this._propertyUpdated_wrapped); ; } get filterStringErrorsParsing() { return this._filterStringErrorsParsing; } set filterStringErrorsParsing(ev) { if (this._filterStringErrorsParsing_wrapped !== null) { this.i.filterStringErrorsParsing = delegateRemove(this.i.filterStringErrorsParsing, this._filterStringErrorsParsing_wrapped); this._filterStringErrorsParsing_wrapped = null; this._filterStringErrorsParsing = null; } this._filterStringErrorsParsing = ev; this._filterStringErrorsParsing_wrapped = (o, e) => { let outerArgs = new IgrGridConditionFilterStringErrorsParsingEventArgs(); outerArgs._provideImplementation(e); if (this.beforeFilterStringErrorsParsing) { this.beforeFilterStringErrorsParsing(this, outerArgs); } if (this._filterStringErrorsParsing) { this._filterStringErrorsParsing(this, outerArgs); } }; this.i.filterStringErrorsParsing = delegateCombine(this.i.filterStringErrorsParsing, this._filterStringErrorsParsing_wrapped); ; } }