igniteui-react-grids
Version:
Ignite UI React grid components.
447 lines (445 loc) • 15.6 kB
JavaScript
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";
export class IgrPropertyEditor extends React.Component {
set height(value) {
this._height = value;
if (this._elRef) {
this._elRef.style.height = value;
this.i.notifySizeChanged();
}
}
get height() {
return this._height;
}
set width(value) {
this._width = value;
if (this._elRef) {
this._elRef.style.height = value;
this.i.notifySizeChanged();
}
}
get width() {
return this._width;
}
_getMainRef(ref) {
this._elRef = ref;
this.verifyReferences();
}
_updateContentChildren() {
this.contentProperties.length = 0;
let contentChildrenActual = this._contentChildrenManager.contentChildrenActual;
for (let 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();
}
}
/**
* A collection of manually added style mappings for the treemap.
*/
get properties() {
if (this._properties === null) {
let coll = new IgrPropertyEditorPropertyDescriptionCollection();
let inner = coll._innerColl;
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;
}
});
this._properties = coll;
}
return this._properties;
}
render() {
let children = this._contentChildrenManager.getChildren(this.props.children);
if (this._portalManager)
this._portalManager.onRender(children);
let div = React.createElement("div", {
ref: this._getMainRef,
className: "ig-property-editor igr-property-editor",
children: children
});
return div;
}
verifyReferences() {
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(() => {
this.i.notifySizeChanged();
});
}
}
requestRender() {
if (this._initialized)
this.setState({});
}
constructor(props) {
super(props);
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((ch) => ch.key || ch.props.name, (ch) => ch.key || ch.props.name, () => this._updateContentChildren());
this._propertiesAdapter = new CollectionAdapter(this.contentProperties, this.i.properties, this.actualProperties, (c) => c.i, (i) => {
if (this._reactRenderer && this._elRef) {
i._styling(this._elRef, this, this);
}
}, (i) => { });
//var multiColumnComboBox = this.i;
//multiColumnComboBox.notifySizeChanged();
if (props) {
this.initializeProperties();
}
this._initialized = true;
}
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;
}
initializeProperties() {
for (const p of Object.keys(this.props)) {
if (isValidProp(this, p)) {
this[p] = this.props[p];
}
}
}
// supports angular themes or custom properties set in CSS
updateStyle() {
this._styling(this._elRef, this);
}
componentWillUnmount() {
this.i.destroy();
if (this._reactRenderer)
this._reactRenderer.destroy();
}
componentDidMount() {
this._elRef.style.width = this._width ? this._width : "";
this._elRef.style.height = this._height ? this._height : "";
this.i.notifySizeChanged();
this.initializeContent();
}
initializeContent() {
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();
}
createImplementation() {
return new PropertyEditor();
}
get i() {
return this._implementation;
}
/**
* Gets the actaul data or data source instance to which to bind the grid.
*/
get actualDataSource() {
if (this._actualDataSource === null) {
let coll = new IgrPropertyEditorPropertyDescriptionCollection();
let innerColl = this.i.actualProperties;
if (!innerColl) {
innerColl = new PropertyEditorPropertyDescriptionCollection_internal();
}
this._actualDataSource = coll._fromInner(innerColl);
this.i.actualProperties = innerColl;
}
return this._actualDataSource;
}
set actualDataSource(v) {
if (this._actualDataSource !== null) {
this._actualDataSource._setSyncTarget(null);
this._actualDataSource = null;
}
let coll = new IgrPropertyEditorPropertyDescriptionCollection();
this._actualDataSource = coll._fromOuter(v);
let syncColl = new SyncableObservableCollection$1(PropertyEditorPropertyDescription.$type);
let innerColl = this.i.actualProperties;
if (!innerColl) {
innerColl = new PropertyEditorPropertyDescriptionCollection_internal();
}
syncColl._inner = innerColl;
syncColl.clear();
this._actualDataSource._setSyncTarget(syncColl);
this.i.actualProperties = innerColl;
}
/**
* Gets or Sets the property name that contains the values.
*/
get filterPlaceholderText() {
return this.i.b9;
}
set filterPlaceholderText(v) {
this.i.b9 = v;
}
/**
* Gets or Sets the property name that contains the values.
*/
get searchInputType() {
return this.i.q;
}
set searchInputType(v) {
this.i.q = ensureEnum(InputGroupDisplayType_$type, v);
}
/**
* Gets or Sets the property name that contains the values.
*/
get rowHeight() {
return this.i.bs;
}
set rowHeight(v) {
this.i.bs = +v;
}
/**
* Gets or Sets the property name that contains the values.
*/
get cellTextStyle() {
if (this.i.ad == null) {
return null;
}
return this.i.ad.fontString;
}
set cellTextStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.ad = fi;
}
/**
* Gets or Sets the property name that contains the values.
*/
get baseTheme() {
return this.i.y;
}
set baseTheme(v) {
this.i.y = ensureEnum(BaseControlTheme_$type, v);
}
/**
* Gets or Sets the property name that contains the values.
*/
get density() {
return this.i.aa;
}
set density(v) {
this.i.aa = ensureEnum(ControlDisplayDensity_$type, v);
}
get actualDescriptionContext() {
return this.i.j;
}
set actualDescriptionContext(v) {
this.i.j = v;
}
get descriptionContext() {
return this.i.k;
}
set descriptionContext(v) {
this.i.k = v;
}
get componentRenderer() {
return this.i.g;
}
set componentRenderer(v) {
this.i.g = v;
}
get target() {
return this.i.bu;
}
set target(v) {
this.i.bu = v;
}
get descriptionType() {
return this.i.b7;
}
set descriptionType(v) {
this.i.b7 = v;
}
get isHorizontal() {
return this.i.ao;
}
set isHorizontal(v) {
this.i.ao = ensureBool(v);
}
get isWrappingEnabled() {
return this.i.aq;
}
set isWrappingEnabled(v) {
this.i.aq = ensureBool(v);
}
get isIndirectModeEnabled() {
return this.i.ap;
}
set isIndirectModeEnabled(v) {
this.i.ap = ensureBool(v);
}
/**
* Gets or sets the color to use for the background of the component.
*/
get backgroundColor() {
return brushToString(this.i.d8);
}
set backgroundColor(v) {
this.i.d8 = stringToBrush(v);
}
/**
* Gets or sets the color to use for the text of the component.
*/
get textColor() {
return brushToString(this.i.ec);
}
set textColor(v) {
this.i.ec = stringToBrush(v);
}
findByName(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;
}
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("PropertyEditor");
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;
}
getDesiredSize() {
let iv = this.i.ed();
return fromSize(iv);
}
notifySetItem(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.
*/
notifyClearItems() {
this.i.dq();
}
notifyInsertItem(index, newItem) {
this.i.dr(index, newItem);
}
notifyRemoveItem(index, oldItem) {
this.i.ds(index, oldItem);
}
}