igniteui-react-core
Version:
Ignite UI React Core.
707 lines (703 loc) • 23.9 kB
JavaScript
import { __extends, __values } from "tslib";
import * as React from 'react';
import { toRect, ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "./componentUtil";
import { ReactRenderer, PortalManager } from "./react-renderer";
import { delegateCombine, delegateRemove } from "./type";
import { Popup } from './Popup';
import { IgrOnPopupEventArgs } from './igr-on-popup-event-args';
import { IgrOnClosedEventArgs } from './igr-on-closed-event-args';
import { IgrFocusEventArgs } from './igr-focus-event-args';
import { PopupDirection_$type } from "./PopupDirection";
import { PopupAlignment_$type } from "./PopupAlignment";
import { PopupAnimationType_$type } from "./PopupAnimationType";
import { PopupPointerPosition_$type } from "./PopupPointerPosition";
import { IgrPopupMeasuringContentSizeEventArgs } from './igr-popup-measuring-content-size-event-args';
var IgrPopup = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrPopup, _super);
function IgrPopup(props) {
var _this = _super.call(this, props) || this;
_this._reactRenderer = null;
_this._implementation = null;
_this.__p = null;
_this._hasUserValues = new Set();
_this._stylingContainer = null;
_this._stylingParent = null;
_this._inStyling = false;
_this._onClosed = null;
_this._onClosed_wrapped = null;
_this._onPopup = null;
_this._onPopup_wrapped = null;
_this._popupGotFocus = null;
_this._popupGotFocus_wrapped = null;
_this._popupLostFocus = null;
_this._popupLostFocus_wrapped = null;
_this._measuringContentSize = null;
_this._measuringContentSize_wrapped = null;
if (_this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
}
_this._implementation = _this.createImplementation();
_this._getMainRef = _this._getMainRef.bind(_this);
if (props) {
_this.initializeProperties();
}
_this._initialized = true;
return _this;
}
Object.defineProperty(IgrPopup.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(IgrPopup.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
});
IgrPopup.prototype._getMainRef = function (ref) {
this._elRef = ref;
this.verifyReferences();
};
IgrPopup.prototype.verifyReferences = function () {
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);
// render needs to fire again after the portalManager is created.
this.requestRender();
this.i.provideRenderer(this._reactRenderer);
}
};
IgrPopup.prototype.render = function () {
var propChildren = this.props.children;
var children = [];
React.Children.forEach(propChildren, function (ch) {
children.push(React.cloneElement(ch));
});
if (this._portalManager)
this._portalManager.onRender(children);
var div = React.createElement("div", {
ref: this._getMainRef,
children: children
});
return div;
};
IgrPopup.prototype.requestRender = function () {
if (this._initialized)
this.setState({});
};
IgrPopup.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;
};
IgrPopup.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
IgrPopup.prototype.updateStyle = function () {
this._styling(this._elRef, this);
};
IgrPopup.prototype.destroy = function () {
this.i.destroy();
if (this._reactRenderer)
this._reactRenderer.destroy();
};
IgrPopup.prototype.componentWillUnmount = function () {
};
IgrPopup.prototype.componentDidMount = function () {
this._elRef.style.width = this._width ? this._width : "";
this._elRef.style.height = this._height ? this._height : "";
this.initializeContent();
};
IgrPopup.prototype.initializeContent = function () {
this._styling(this._elRef, this);
this.updateStyle();
};
IgrPopup.prototype.createImplementation = function () {
return new Popup();
};
Object.defineProperty(IgrPopup.prototype, "i", {
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isFocusable", {
get: function () {
return this.i.as;
},
set: function (v) {
this.i.as = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "animationDuration", {
/**
* Gets or sets the duration of the Popup and Closeup animations in milliseconds.
*/
get: function () {
return this.i.a9;
},
set: function (v) {
this.i.a9 = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "animationEnabled", {
/**
* Gets or sets whether the popup and closeup animations are animated.
*/
get: function () {
return this.i.am;
},
set: function (v) {
this.i.am = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "animationType", {
/**
* Gets or sets the type of animation to use when the popup opens and closes.
*/
get: function () {
return this.i.p;
},
set: function (v) {
this.i.p = ensureEnum(PopupAnimationType_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "elevation", {
/**
* Gets or sets the elevation to use for the button regardless of type.
*/
get: function () {
return this.i.bb;
},
set: function (v) {
this.i.bb = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "actualElevation", {
/**
* Gets or sets the elevation of the border shadow
*/
get: function () {
return this.i.a7;
},
set: function (v) {
this.i.a7 = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isShown", {
/**
* Gets / sets the isShown state of the panel.
*/
get: function () {
return this.i.ax;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "actualUmbraShadowColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.cz);
},
set: function (v) {
this.i.cz = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "actualPenumbraShadowColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.cy);
},
set: function (v) {
this.i.cy = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "actualAmbientShadowColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.cx);
},
set: function (v) {
this.i.cx = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "background", {
/**
* Gets or sets the background color of the popup.
*/
get: function () {
return brushToString(this.i.c0);
},
set: function (v) {
this.i.c0 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "cornerRadius", {
get: function () {
return this.i.a1;
},
set: function (v) {
this.i.a1 = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isHitTestVisible", {
/**
* Gets or sets whether to disable hit testing on the popup.
*/
get: function () {
return this.i.at;
},
set: function (v) {
this.i.at = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "disableHitTestDuringAnimation", {
/**
* Gets or sets whether to disable hit testing during the open and close animations.
*/
get: function () {
return this.i.ao;
},
set: function (v) {
this.i.ao = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isPointerEnabled", {
/**
* Gets or sets whether to show a pointer off the side of the popup towards the popup target.
*/
get: function () {
return this.i.au;
},
set: function (v) {
this.i.au = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "pointerPosition", {
/**
* Gets or sets the pointer position.
*/
get: function () {
return this.i.v;
},
set: function (v) {
this.i.v = ensureEnum(PopupPointerPosition_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "pointerBackground", {
/**
* Gets or sets the pointer background color.
*/
get: function () {
return brushToString(this.i.c4);
},
set: function (v) {
this.i.c4 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "pointerSize", {
/**
* Gets or sets the pointer size.
*/
get: function () {
return this.i.a4;
},
set: function (v) {
this.i.a4 = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isShowing", {
/**
* Gets whether the popup is in the middle of opening or not.
*/
get: function () {
return this.i.av;
},
set: function (v) {
this.i.av = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isClosing", {
/**
* Gets whether the popup is in the middle of closing or not.
*/
get: function () {
return this.i.aq;
},
set: function (v) {
this.i.aq = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "isFixed", {
/**
* Indicates that the popup will position itself relative to the window instead of the document.
*/
get: function () {
return this.i.ar;
},
set: function (v) {
this.i.ar = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "useTopLayer", {
/**
* Indicates that the popup will place itself into the browser top layer.
*/
get: function () {
return this.i.ay;
},
set: function (v) {
this.i.ay = ensureBool(v);
},
enumerable: false,
configurable: true
});
IgrPopup.prototype.findByName = function (name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
return null;
};
Object.defineProperty(IgrPopup.prototype, "hasUserValues", {
get: function () {
return this._hasUserValues;
},
enumerable: false,
configurable: true
});
IgrPopup.prototype.__m = function (propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
};
IgrPopup.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("Popup");
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;
};
/**
* Closes the popup.
*/
IgrPopup.prototype.close = function () {
this.i.b6();
};
IgrPopup.prototype.showRelativeToExclusionRect = function (exclusionRect, popupDirection, popupAlignment) {
this.i.showRelativeToExclusionRect(toRect(exclusionRect), ensureEnum(PopupDirection_$type, popupDirection), ensureEnum(PopupAlignment_$type, popupAlignment));
};
/**
* Exports visual information about the current state of the grid.
*/
IgrPopup.prototype.exportVisualModel = function () {
var iv = this.i.bd();
return (iv);
};
/**
* Returns a serialized copy of the exported visual model
*/
IgrPopup.prototype.exportSerializedVisualModel = function () {
var iv = this.i.bq();
return (iv);
};
Object.defineProperty(IgrPopup.prototype, "onClosed", {
get: function () {
return this._onClosed;
},
set: function (ev) {
var _this = this;
if (this._onClosed_wrapped !== null) {
this.i.onClosed = delegateRemove(this.i.onClosed, this._onClosed_wrapped);
this._onClosed_wrapped = null;
this._onClosed = null;
}
this._onClosed = ev;
this._onClosed_wrapped = function (o, e) {
var outerArgs = new IgrOnClosedEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeOnClosed) {
_this.beforeOnClosed(_this, outerArgs);
}
if (_this._onClosed) {
_this._onClosed(_this, outerArgs);
}
};
this.i.onClosed = delegateCombine(this.i.onClosed, this._onClosed_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "onPopup", {
/**
* Fires when the popup is shown
*/
get: function () {
return this._onPopup;
},
set: function (ev) {
var _this = this;
if (this._onPopup_wrapped !== null) {
this.i.onPopup = delegateRemove(this.i.onPopup, this._onPopup_wrapped);
this._onPopup_wrapped = null;
this._onPopup = null;
}
this._onPopup = ev;
this._onPopup_wrapped = function (o, e) {
var outerArgs = new IgrOnPopupEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeOnPopup) {
_this.beforeOnPopup(_this, outerArgs);
}
if (_this._onPopup) {
_this._onPopup(_this, outerArgs);
}
};
this.i.onPopup = delegateCombine(this.i.onPopup, this._onPopup_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "popupGotFocus", {
/**
* Fired when the open popup gains focus.
*/
get: function () {
return this._popupGotFocus;
},
set: function (ev) {
var _this = this;
if (this._popupGotFocus_wrapped !== null) {
this.i.popupGotFocus = delegateRemove(this.i.popupGotFocus, this._popupGotFocus_wrapped);
this._popupGotFocus_wrapped = null;
this._popupGotFocus = null;
}
this._popupGotFocus = ev;
this._popupGotFocus_wrapped = function (o, e) {
var outerArgs = new IgrFocusEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforePopupGotFocus) {
_this.beforePopupGotFocus(_this, outerArgs);
}
if (_this._popupGotFocus) {
_this._popupGotFocus(_this, outerArgs);
}
};
this.i.popupGotFocus = delegateCombine(this.i.popupGotFocus, this._popupGotFocus_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "popupLostFocus", {
/**
* Fired when the open popup loses focus.
*/
get: function () {
return this._popupLostFocus;
},
set: function (ev) {
var _this = this;
if (this._popupLostFocus_wrapped !== null) {
this.i.popupLostFocus = delegateRemove(this.i.popupLostFocus, this._popupLostFocus_wrapped);
this._popupLostFocus_wrapped = null;
this._popupLostFocus = null;
}
this._popupLostFocus = ev;
this._popupLostFocus_wrapped = function (o, e) {
var outerArgs = new IgrFocusEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforePopupLostFocus) {
_this.beforePopupLostFocus(_this, outerArgs);
}
if (_this._popupLostFocus) {
_this._popupLostFocus(_this, outerArgs);
}
};
this.i.popupLostFocus = delegateCombine(this.i.popupLostFocus, this._popupLostFocus_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrPopup.prototype, "measuringContentSize", {
get: function () {
return this._measuringContentSize;
},
set: function (ev) {
var _this = this;
if (this._measuringContentSize_wrapped !== null) {
this.i.measuringContentSize = delegateRemove(this.i.measuringContentSize, this._measuringContentSize_wrapped);
this._measuringContentSize_wrapped = null;
this._measuringContentSize = null;
}
this._measuringContentSize = ev;
this._measuringContentSize_wrapped = function (o, e) {
var outerArgs = new IgrPopupMeasuringContentSizeEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeMeasuringContentSize) {
_this.beforeMeasuringContentSize(_this, outerArgs);
}
if (_this._measuringContentSize) {
_this._measuringContentSize(_this, outerArgs);
}
};
this.i.measuringContentSize = delegateCombine(this.i.measuringContentSize, this._measuringContentSize_wrapped);
;
},
enumerable: false,
configurable: true
});
return IgrPopup;
}(React.Component));
export { IgrPopup };