UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

576 lines (574 loc) 21.5 kB
import { __extends, __values } from "tslib"; import * as React from 'react'; import { fromSize, ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core"; import { FontInfo } from "igniteui-react-core"; import { ReactRenderer, PortalManager } from "igniteui-react-core"; import { ContentChildrenManager } from "igniteui-react-core"; import { CollectionAdapter } from "igniteui-react-core"; import { NotifyCollectionChangedAction } from "igniteui-react-core"; import { PropertyEditor } from './PropertyEditor'; import { BaseControlTheme_$type } from "igniteui-react-core"; import { ControlDisplayDensity_$type } from "igniteui-react-core"; import { IgrPropertyEditorPropertyDescriptionCollection } from "igniteui-react-layouts"; import { PropertyEditorPropertyDescriptionCollection as PropertyEditorPropertyDescriptionCollection_internal } from "igniteui-react-layouts"; import { SyncableObservableCollection$1 } from "igniteui-react-core"; import { PropertyEditorPropertyDescription } from "igniteui-react-layouts"; import { InputGroupDisplayType_$type } from "igniteui-react-inputs"; var IgrPropertyEditor = /** @class */ /*@__PURE__*/ (function (_super) { __extends(IgrPropertyEditor, _super); function IgrPropertyEditor(props) { var _this = _super.call(this, props) || this; _this._implementation = null; _this._reactRenderer = null; _this.contentProperties = []; /** * The style mappings actually present in the treemap. Do not directly modify this array. * This array's contents can be modified by causing React to reproject the child content. * Or adding and removing ranges from the manual ranges collection on the ranges property. */ _this.actualProperties = []; _this._properties = null; _this._propertiesAdapter = null; _this._actualDataSource = null; _this.__p = null; _this._hasUserValues = new Set(); _this._stylingContainer = null; _this._stylingParent = null; _this._inStyling = false; if (_this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this)); } _this._implementation = _this.createImplementation(); _this._getMainRef = _this._getMainRef.bind(_this); _this._contentChildrenManager = new ContentChildrenManager(function (ch) { return ch.key || ch.props.name; }, function (ch) { return ch.key || ch.props.name; }, function () { return _this._updateContentChildren(); }); _this._propertiesAdapter = new CollectionAdapter(_this.contentProperties, _this.i.properties, _this.actualProperties, function (c) { return c.i; }, function (i) { if (_this._reactRenderer && _this._elRef) { i._styling(_this._elRef, _this, _this); } }, function (i) { }); //var multiColumnComboBox = this.i; //multiColumnComboBox.notifySizeChanged(); if (props) { _this.initializeProperties(); } _this._initialized = true; return _this; } Object.defineProperty(IgrPropertyEditor.prototype, "height", { get: function () { return this._height; }, set: function (value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; this.i.notifySizeChanged(); } }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "width", { get: function () { return this._width; }, set: function (value) { this._width = value; if (this._elRef) { this._elRef.style.height = value; this.i.notifySizeChanged(); } }, enumerable: false, configurable: true }); IgrPropertyEditor.prototype._getMainRef = function (ref) { this._elRef = ref; this.verifyReferences(); }; IgrPropertyEditor.prototype._updateContentChildren = function () { this.contentProperties.length = 0; var contentChildrenActual = this._contentChildrenManager.contentChildrenActual; for (var i = 0; i < contentChildrenActual.length; i++) { if ((PropertyEditorPropertyDescription.$type).isAssignableFrom(contentChildrenActual[i].i.$type)) { this.contentProperties.push(contentChildrenActual[i]); } } if (this._propertiesAdapter !== null) { this._propertiesAdapter.notifyContentChanged(); } }; Object.defineProperty(IgrPropertyEditor.prototype, "properties", { /** * A collection of manually added style mappings for the treemap. */ get: function () { var _this = this; if (this._properties === null) { var coll = new IgrPropertyEditorPropertyDescriptionCollection(); var inner = coll._innerColl; inner.addListener(function (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; } }); this._properties = coll; } return this._properties; }, enumerable: false, configurable: true }); IgrPropertyEditor.prototype.render = function () { var children = this._contentChildrenManager.getChildren(this.props.children); if (this._portalManager) this._portalManager.onRender(children); var div = React.createElement("div", { ref: this._getMainRef, className: "ig-property-editor igr-property-editor", children: children }); return div; }; IgrPropertyEditor.prototype.verifyReferences = function () { var _this = this; if (this._elRef) { this.requestRender = this.requestRender.bind(this); this._portalManager = new PortalManager("popupContent", this.requestRender); this._reactRenderer = new ReactRenderer(this._elRef, document, true, {}, this._portalManager); if (document) { this._elRef.style.display = "block"; this._elRef.style.width = "100%"; this._elRef.style.height = "100%"; } // render needs to fire again after the portalManager is created. this.requestRender(); this.i.provideContainer(this._reactRenderer); this.i.notifySizeChanged(); this._reactRenderer.addSizeWatcher(function () { _this.i.notifySizeChanged(); }); } }; IgrPropertyEditor.prototype.requestRender = function () { if (this._initialized) this.setState({}); }; IgrPropertyEditor.prototype.shouldComponentUpdate = function (nextProps, nextState) { var e_1, _a; var mod = getModifiedProps(this.props, nextProps); try { for (var _b = __values(Object.keys(mod)), _c = _b.next(); !_c.done; _c = _b.next()) { var p = _c.value; if (isValidProp(this, p)) { this[p] = mod[p]; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return true; }; IgrPropertyEditor.prototype.initializeProperties = function () { var e_2, _a; try { for (var _b = __values(Object.keys(this.props)), _c = _b.next(); !_c.done; _c = _b.next()) { var p = _c.value; if (isValidProp(this, p)) { this[p] = this.props[p]; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_2) throw e_2.error; } } }; // supports angular themes or custom properties set in CSS IgrPropertyEditor.prototype.updateStyle = function () { this._styling(this._elRef, this); }; IgrPropertyEditor.prototype.componentWillUnmount = function () { this.i.destroy(); if (this._reactRenderer) this._reactRenderer.destroy(); }; IgrPropertyEditor.prototype.componentDidMount = function () { this._elRef.style.width = this._width ? this._width : ""; this._elRef.style.height = this._height ? this._height : ""; this.i.notifySizeChanged(); this.initializeContent(); }; IgrPropertyEditor.prototype.initializeContent = function () { this._styling(this._elRef, this); if (this.actualProperties && this.actualProperties.length > 0) { var currProperty = this.actualProperties; for (var i = 0; i < currProperty.length; i++) { currProperty[i]._styling(this._elRef, this, this); } } this._updateContentChildren(); this.updateStyle(); this.i.notifySizeChanged(); }; IgrPropertyEditor.prototype.createImplementation = function () { return new PropertyEditor(); }; Object.defineProperty(IgrPropertyEditor.prototype, "i", { get: function () { return this._implementation; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "actualDataSource", { /** * Gets the actaul data or data source instance to which to bind the grid. */ get: function () { if (this._actualDataSource === null) { var coll = new IgrPropertyEditorPropertyDescriptionCollection(); var innerColl = this.i.actualProperties; if (!innerColl) { innerColl = new PropertyEditorPropertyDescriptionCollection_internal(); } this._actualDataSource = coll._fromInner(innerColl); this.i.actualProperties = innerColl; } return this._actualDataSource; }, set: function (v) { if (this._actualDataSource !== null) { this._actualDataSource._setSyncTarget(null); this._actualDataSource = null; } var coll = new IgrPropertyEditorPropertyDescriptionCollection(); this._actualDataSource = coll._fromOuter(v); var syncColl = new SyncableObservableCollection$1(PropertyEditorPropertyDescription.$type); var innerColl = this.i.actualProperties; if (!innerColl) { innerColl = new PropertyEditorPropertyDescriptionCollection_internal(); } syncColl._inner = innerColl; syncColl.clear(); this._actualDataSource._setSyncTarget(syncColl); this.i.actualProperties = innerColl; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "filterPlaceholderText", { /** * Gets or Sets the property name that contains the values. */ get: function () { return this.i.b9; }, set: function (v) { this.i.b9 = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "searchInputType", { /** * Gets or Sets the property name that contains the values. */ get: function () { return this.i.q; }, set: function (v) { this.i.q = ensureEnum(InputGroupDisplayType_$type, v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "rowHeight", { /** * Gets or Sets the property name that contains the values. */ get: function () { return this.i.bs; }, set: function (v) { this.i.bs = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "cellTextStyle", { /** * Gets or Sets the property name that contains the values. */ get: function () { if (this.i.ad == null) { return null; } return this.i.ad.fontString; }, set: function (v) { var fi = new FontInfo(); fi.fontString = v; this.i.ad = fi; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "baseTheme", { /** * Gets or Sets the property name that contains the values. */ get: function () { return this.i.y; }, set: function (v) { this.i.y = ensureEnum(BaseControlTheme_$type, v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "density", { /** * Gets or Sets the property name that contains the values. */ get: function () { return this.i.aa; }, set: function (v) { this.i.aa = ensureEnum(ControlDisplayDensity_$type, v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "actualDescriptionContext", { get: function () { return this.i.j; }, set: function (v) { this.i.j = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "descriptionContext", { get: function () { return this.i.k; }, set: function (v) { this.i.k = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "componentRenderer", { get: function () { return this.i.g; }, set: function (v) { this.i.g = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "target", { get: function () { return this.i.bu; }, set: function (v) { this.i.bu = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "descriptionType", { get: function () { return this.i.b7; }, set: function (v) { this.i.b7 = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "isHorizontal", { get: function () { return this.i.ao; }, set: function (v) { this.i.ao = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "isWrappingEnabled", { get: function () { return this.i.aq; }, set: function (v) { this.i.aq = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "isIndirectModeEnabled", { get: function () { return this.i.ap; }, set: function (v) { this.i.ap = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "backgroundColor", { /** * Gets or sets the color to use for the background of the component. */ get: function () { return brushToString(this.i.d8); }, set: function (v) { this.i.d8 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrPropertyEditor.prototype, "textColor", { /** * Gets or sets the color to use for the text of the component. */ get: function () { return brushToString(this.i.ec); }, set: function (v) { this.i.ec = stringToBrush(v); }, enumerable: false, configurable: true }); IgrPropertyEditor.prototype.findByName = function (name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.actualDataSource != null && this.actualDataSource.findByName && this.actualDataSource.findByName(name)) { return this.actualDataSource.findByName(name); } if (this.properties != null && this.properties.findByName && this.properties.findByName(name)) { return this.properties.findByName(name); } return null; }; Object.defineProperty(IgrPropertyEditor.prototype, "hasUserValues", { get: function () { return this._hasUserValues; }, enumerable: false, configurable: true }); IgrPropertyEditor.prototype.__m = function (propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } }; IgrPropertyEditor.prototype._styling = function (container, component, parent) { if (this._inStyling) { return; } this._inStyling = true; this._stylingContainer = container; this._stylingParent = component; var genericPrefix = ""; var typeName = this.i.$type.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } genericPrefix = toSpinal("PropertyEditor"); var additionalPrefixes = []; var prefix = toSpinal(typeName); additionalPrefixes.push(prefix + "-"); var 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); } var basePrefix = toSpinal(typeName); additionalPrefixes.push(basePrefix + "-"); b = b.baseType; } if (parent) { var parentTypeName = parent.i.$type.name; if (parentTypeName.indexOf("Xam") === 0) { parentTypeName = parentTypeName.substring(3); } var 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; }; IgrPropertyEditor.prototype.getDesiredSize = function () { var iv = this.i.ed(); return fromSize(iv); }; IgrPropertyEditor.prototype.notifySetItem = function (index, oldItem, newItem) { this.i.dt(index, oldItem, newItem); }; /** * Manually notifies the checkboxlist's grid that the data it has bound to has been cleared and needs to be re-examined. * This should not be called if the data that the grid is bound to is already observable. */ IgrPropertyEditor.prototype.notifyClearItems = function () { this.i.dq(); }; IgrPropertyEditor.prototype.notifyInsertItem = function (index, newItem) { this.i.dr(index, newItem); }; IgrPropertyEditor.prototype.notifyRemoveItem = function (index, oldItem) { this.i.ds(index, oldItem); }; return IgrPropertyEditor; }(React.Component)); export { IgrPropertyEditor };