ngx-modialog-7
Version:
Modal / Dialog for Angular
1,667 lines (1,653 loc) • 94.2 kB
JavaScript
import { ComponentFactoryResolver, Directive, ElementRef, ViewContainerRef, Input, Component, ViewEncapsulation, Renderer2, TemplateRef, ViewChild, HostListener, Injectable, Injector, ApplicationRef, ANALYZE_FOR_ENTRY_COMPONENTS, NgModule } from '@angular/core';
import { __extends } from 'tslib';
import { Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { CommonModule } from '@angular/common';
import { EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
/**
* @fileoverview added by tsickle
* Generated from: lib/framework/fluent-assign.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var PRIVATE_PREFIX = '$$';
/** @type {?} */
var RESERVED_REGEX = /^(\$\$).*/;
/**
* @param {?} name
* @return {?}
*/
function validateMethodName(name) {
if (!name) {
throw new Error("Illegal method name. Empty method name is not allowed");
}
else if (name in this) {
throw new Error("A member name '" + name + "' already defined.");
}
}
/**
* Returns a list of assigned property names (non private)
* @param {?} subject
* @return {?}
*/
function getAssignedPropertyNames(subject) {
return Object.getOwnPropertyNames(subject)
.filter((/**
* @param {?} name
* @return {?}
*/
function (name) { return RESERVED_REGEX.test(name); }))
.map((/**
* @param {?} name
* @return {?}
*/
function (name) { return name.substr(2); }));
}
/**
* @param {?} name
* @return {?}
*/
function privateKey(name) {
return PRIVATE_PREFIX + name;
}
/**
* @param {?} obj
* @param {?} propertyName
* @param {?} value
* @return {?}
*/
function objectDefinePropertyValue(obj, propertyName, value) {
Object.defineProperty(obj, propertyName, (/** @type {?} */ ({
configurable: false,
enumerable: false,
writable: false,
value: value
})));
}
/**
* Given a FluentAssign instance, apply all of the supplied default values so calling
* instance.toJSON will return those values (does not create a setter function)
* @param {?} instance
* @param {?} defaultValues
* @return {?}
*/
function applyDefaultValues(instance, defaultValues) {
Object.getOwnPropertyNames(defaultValues)
.forEach((/**
* @param {?} name
* @return {?}
*/
function (name) { return ((/** @type {?} */ (instance)))[privateKey(name)] = ((/** @type {?} */ (defaultValues)))[name]; }));
}
/**
* Create a function for setting a value for a property on a given object.
* @template T
* @param {?} obj The object to apply the key & setter on.
* @param {?} propertyName The name of the property on the object
* @param {?=} writeOnce If true will allow writing once (default: false)
*
* Example:
* let obj = new FluentAssign<any>;
* setAssignMethod(obj, 'myProp');
* obj.myProp('someValue');
* const result = obj.toJSON();
* console.log(result); //{ myProp: 'someValue' }
*
*
* let obj = new FluentAssign<any>;
* setAssignMethod(obj, 'myProp', true); // applying writeOnce
* obj.myProp('someValue');
* obj.myProp('someValue'); // ERROR: Overriding config property 'myProp' is not allowed.
* @return {?}
*/
function setAssignMethod(obj, propertyName, writeOnce) {
var _this = this;
if (writeOnce === void 0) { writeOnce = false; }
validateMethodName.call(obj, propertyName);
/** @type {?} */
var key = privateKey(propertyName);
objectDefinePropertyValue(obj, propertyName, (/**
* @param {?} value
* @return {?}
*/
function (value) {
if (writeOnce && _this.hasOwnProperty(key)) {
throw new Error("Overriding config property '" + propertyName + "' is not allowed.");
}
obj[key] = value;
return obj;
}));
}
/**
* Create a function for setting a value that is an alias to an other setter function.
* @template T
* @param {?} obj The object to apply the key & setter on.
* @param {?} propertyName The name of the property on the object
* @param {?} srcPropertyName The name of the property on the object this alias points to
* @param {?=} hard If true, will set a readonly property on the object that returns
* the value of the source property. Default: false
*
* Example:
* let obj = new FluentAssign<any> ;
* setAssignMethod(obj, 'myProp');
* setAssignAlias(obj, 'myPropAlias', 'myProp');
* obj.myPropAlias('someValue');
* const result = obj.toJSON();
* console.log(result); //{ myProp: 'someValue' }
* result.myPropAlias // undefined
*
*
* let obj = new FluentAssign<any> ;
* setAssignMethod(obj, 'myProp');
* setAssignAlias(obj, 'myPropAlias', 'myProp', true); // setting a hard alias.
* obj.myPropAlias('someValue');
* const result = obj.toJSON();
* console.log(result); //{ myProp: 'someValue' }
* result.myPropAlias // someValue
* @return {?}
*/
function setAssignAlias(obj, propertyName, srcPropertyName, hard) {
if (hard === void 0) { hard = false; }
validateMethodName.call(obj, propertyName);
objectDefinePropertyValue(obj, propertyName, (/**
* @param {?} value
* @return {?}
*/
function (value) {
obj[srcPropertyName](value);
return obj;
}));
if (hard === true) {
/** @type {?} */
var key = privateKey(propertyName);
/** @type {?} */
var srcKey_1 = privateKey(srcPropertyName);
Object.defineProperty(obj, key, (/** @type {?} */ ({
configurable: false,
enumerable: false,
get: (/**
* @return {?}
*/
function () { return obj[srcKey_1]; })
})));
}
}
/**
* @record
* @template Z
*/
function IFluentAssignFactory() { }
if (false) {
/** @type {?} */
IFluentAssignFactory.prototype.fluentAssign;
/**
* @param {?} name
* @param {?=} defaultValue
* @return {?}
*/
IFluentAssignFactory.prototype.setMethod = function (name, defaultValue) { };
}
/**
* Represent a fluent API factory wrapper for defining FluentAssign instances.
* @template T
*/
var /**
* Represent a fluent API factory wrapper for defining FluentAssign instances.
* @template T
*/
FluentAssignFactory = /** @class */ (function () {
function FluentAssignFactory(fluentAssign) {
this._fluentAssign =
fluentAssign instanceof FluentAssign ? fluentAssign : (/** @type {?} */ (new FluentAssign()));
}
/**
* Create a setter method on the FluentAssign instance.
* @param name The name of the setter function.
* @param defaultValue If set (not undefined) set's the value on the instance immediately.
*/
/**
* Create a setter method on the FluentAssign instance.
* @param {?} name The name of the setter function.
* @param {?=} defaultValue If set (not undefined) set's the value on the instance immediately.
* @return {?}
*/
FluentAssignFactory.prototype.setMethod = /**
* Create a setter method on the FluentAssign instance.
* @param {?} name The name of the setter function.
* @param {?=} defaultValue If set (not undefined) set's the value on the instance immediately.
* @return {?}
*/
function (name, defaultValue) {
setAssignMethod(this._fluentAssign, name);
if (defaultValue !== undefined) {
((/** @type {?} */ (this._fluentAssign)))[name](defaultValue);
}
return this;
};
Object.defineProperty(FluentAssignFactory.prototype, "fluentAssign", {
/**
* The FluentAssign instance.
*/
get: /**
* The FluentAssign instance.
* @return {?}
*/
function () {
return this._fluentAssign;
},
enumerable: true,
configurable: true
});
return FluentAssignFactory;
}());
if (false) {
/**
* @type {?}
* @private
*/
FluentAssignFactory.prototype._fluentAssign;
}
/**
* Represent an object where every property is a function representing an assignment function.
* Calling each function with a value will assign the value to the object and return the object.
* Calling 'toJSON' returns an object with the same properties but this time representing the
* assigned values.
*
* This allows setting an object in a fluent API manner.
* Example:
* let fluent = new FluentAssign<any>(undefined, ['some', 'went']);
* fluent.some('thing').went('wrong').toJSON();
* // { some: 'thing', went: 'wrong' }
* @template T
*/
var /**
* Represent an object where every property is a function representing an assignment function.
* Calling each function with a value will assign the value to the object and return the object.
* Calling 'toJSON' returns an object with the same properties but this time representing the
* assigned values.
*
* This allows setting an object in a fluent API manner.
* Example:
* let fluent = new FluentAssign<any>(undefined, ['some', 'went']);
* fluent.some('thing').went('wrong').toJSON();
* // { some: 'thing', went: 'wrong' }
* @template T
*/
FluentAssign = /** @class */ (function () {
/**
*
* @param defaultValues An object representing default values for the underlying object.
* @param initialSetters A list of initial setters for this FluentAssign.
* @param baseType the class/type to create a new base. optional, {} is used if not supplied.
*/
function FluentAssign(defaultValues, initialSetters, baseType) {
var _this = this;
if (Array.isArray(defaultValues)) {
((/** @type {?} */ (defaultValues))).forEach((/**
* @param {?} d
* @return {?}
*/
function (d) { return applyDefaultValues(_this, d); }));
}
else if (defaultValues) {
applyDefaultValues(this, defaultValues);
}
if (Array.isArray(initialSetters)) {
initialSetters.forEach((/**
* @param {?} name
* @return {?}
*/
function (name) { return setAssignMethod(_this, name); }));
}
if (baseType) {
this.__fluent$base__ = baseType;
}
}
/**
* Returns a FluentAssignFactory<FluentAssign<T>> ready to define a FluentAssign type.
* @param defaultValues An object representing default values for the instance.
* @param initialSetters A list of initial setters for the instance.
*/
/**
* Returns a FluentAssignFactory<FluentAssign<T>> ready to define a FluentAssign type.
* @template T
* @param {?=} defaultValues An object representing default values for the instance.
* @param {?=} initialSetters A list of initial setters for the instance.
* @return {?}
*/
FluentAssign.compose = /**
* Returns a FluentAssignFactory<FluentAssign<T>> ready to define a FluentAssign type.
* @template T
* @param {?=} defaultValues An object representing default values for the instance.
* @param {?=} initialSetters A list of initial setters for the instance.
* @return {?}
*/
function (defaultValues, initialSetters) {
return (/** @type {?} */ (FluentAssign.composeWith(new FluentAssign(defaultValues, initialSetters))));
};
/**
* Returns a FluentAssignFactory<Z> where Z is an instance of FluentAssign<?> or a derived
* class of it.
* @param fluentAssign An instance of FluentAssign<?> or a derived class of FluentAssign<?>.
*/
/**
* Returns a FluentAssignFactory<Z> where Z is an instance of FluentAssign<?> or a derived
* class of it.
* @template Z
* @param {?} fluentAssign An instance of FluentAssign<?> or a derived class of FluentAssign<?>.
* @return {?}
*/
FluentAssign.composeWith = /**
* Returns a FluentAssignFactory<Z> where Z is an instance of FluentAssign<?> or a derived
* class of it.
* @template Z
* @param {?} fluentAssign An instance of FluentAssign<?> or a derived class of FluentAssign<?>.
* @return {?}
*/
function (fluentAssign) {
return (/** @type {?} */ (new FluentAssignFactory((/** @type {?} */ (fluentAssign)))));
};
/**
* @return {?}
*/
FluentAssign.prototype.toJSON = /**
* @return {?}
*/
function () {
var _this = this;
return getAssignedPropertyNames(this)
.reduce((/**
* @param {?} obj
* @param {?} name
* @return {?}
*/
function (obj, name) {
/** @type {?} */
var key = privateKey(name);
// re-define property descriptors (we dont want their value)
/** @type {?} */
var propDesc = Object.getOwnPropertyDescriptor(_this, key);
if (propDesc) {
Object.defineProperty(obj, name, propDesc);
}
else {
((/** @type {?} */ (obj)))[name] = ((/** @type {?} */ (_this)))[key];
}
return obj;
}), this.__fluent$base__ ? new this.__fluent$base__() : (/** @type {?} */ ({})));
};
return FluentAssign;
}());
if (false) {
/**
* @type {?}
* @private
*/
FluentAssign.prototype.__fluent$base__;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/framework/utils.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Simple object extend
* @template T
* @param {?} m1
* @param {?} m2
* @return {?}
*/
function extend(m1, m2) {
/** @type {?} */
var m = (/** @type {?} */ ({}));
for (var attr in m1) {
if (m1.hasOwnProperty(attr)) {
((/** @type {?} */ (m)))[attr] = ((/** @type {?} */ (m1)))[attr];
}
}
for (var attr in m2) {
if (m2.hasOwnProperty(attr)) {
((/** @type {?} */ (m)))[attr] = ((/** @type {?} */ (m2)))[attr];
}
}
return m;
}
/**
* Simple, not optimized, array union of unique values.
* @template T
* @param {?} arr1
* @param {?} arr2
* @return {?}
*/
function arrayUnion(arr1, arr2) {
return arr1
.concat(arr2.filter((/**
* @param {?} v
* @return {?}
*/
function (v) { return arr1.indexOf(v) === -1; })));
}
/**
* Returns true if the config supports a given key.
* @param {?} keyCode
* @param {?} config
* @return {?}
*/
function supportsKey(keyCode, config) {
if (!Array.isArray(config)) {
return config !== null;
}
return config.indexOf(keyCode) > -1;
}
/**
* Given an object representing a key/value map of css properties, returns a valid css string
* representing the object.
* Example:
* console.log(toStyleString({
* position: 'absolute',
* width: '100%',
* height: '100%',
* top: '0',
* left: '0',
* right: '0',
* bottom: '0'
* }));
* // position:absolute;width:100%;height:100%;top:0;left:0;right:0;bottom:0
* @param {?} obj
* @return {?}
*/
function toStyleString(obj) {
return Object.getOwnPropertyNames(obj)
.map((/**
* @param {?} k
* @return {?}
*/
function (k) { return k + ":" + obj[k]; }))
.join(';');
// let objStr = JSON.stringify(obj);
// return objStr.substr(1, objStr.length - 2)
// .replace(/,/g, ';')
// .replace(/"/g, '');
}
/**
* @template R
*/
var /**
* @template R
*/
PromiseCompleter = /** @class */ (function () {
function PromiseCompleter() {
var _this = this;
this.promise = new Promise((/**
* @param {?} res
* @param {?} rej
* @return {?}
*/
function (res, rej) {
_this.resolve = res;
_this.reject = rej;
}));
}
return PromiseCompleter;
}());
if (false) {
/** @type {?} */
PromiseCompleter.prototype.promise;
/** @type {?} */
PromiseCompleter.prototype.resolve;
/** @type {?} */
PromiseCompleter.prototype.reject;
}
/**
* @return {?}
*/
function noop() {
}
/**
* @fileoverview added by tsickle
* Generated from: lib/framework/createComponent.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function CreateComponentArgs() { }
if (false) {
/** @type {?} */
CreateComponentArgs.prototype.component;
/** @type {?} */
CreateComponentArgs.prototype.vcRef;
/** @type {?|undefined} */
CreateComponentArgs.prototype.injector;
/** @type {?|undefined} */
CreateComponentArgs.prototype.projectableNodes;
}
/**
* @param {?} instructions
* @return {?}
*/
function createComponent(instructions) {
/** @type {?} */
var injector = instructions.injector || instructions.vcRef.injector;
/** @type {?} */
var cmpFactory = injector.get(ComponentFactoryResolver).resolveComponentFactory(instructions.component);
if (instructions.vcRef) {
return instructions.vcRef.createComponent(cmpFactory, instructions.vcRef.length, injector, instructions.projectableNodes);
}
else {
return cmpFactory.create(injector);
}
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/errors.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DialogBailOutError = /** @class */ (function (_super) {
__extends(DialogBailOutError, _super);
function DialogBailOutError(value) {
var _this = _super.call(this) || this;
if (!value) {
value = 'Dialog was forced to close by an unknown source.';
}
_this.message = value;
return _this;
}
return DialogBailOutError;
}(Error));
/**
* @fileoverview added by tsickle
* Generated from: lib/models/dialog-ref.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* API to an open modal window.
* @template T
*/
var /**
* API to an open modal window.
* @template T
*/
DialogRef = /** @class */ (function () {
function DialogRef(overlay, context) {
this.overlay = overlay;
this.context = context;
this._resultDeferred = new PromiseCompleter();
this._onDestroy = new Subject();
this.onDestroy = this._onDestroy.asObservable();
}
Object.defineProperty(DialogRef.prototype, "result", {
/**
* A Promise that is resolved on a close event and rejected on a dismiss event.
*/
get: /**
* A Promise that is resolved on a close event and rejected on a dismiss event.
* @return {?}
*/
function () {
return this._resultDeferred.promise;
},
enumerable: true,
configurable: true
});
/**
* Set a close/dismiss guard
* @param guard
*/
/**
* Set a close/dismiss guard
* @param {?} guard
* @return {?}
*/
DialogRef.prototype.setCloseGuard = /**
* Set a close/dismiss guard
* @param {?} guard
* @return {?}
*/
function (guard) {
this.closeGuard = guard;
};
/**
* Close the modal with a return value, i.e: result.
*/
/**
* Close the modal with a return value, i.e: result.
* @param {?=} result
* @return {?}
*/
DialogRef.prototype.close = /**
* Close the modal with a return value, i.e: result.
* @param {?=} result
* @return {?}
*/
function (result) {
var _this = this;
if (result === void 0) { result = null; }
/** @type {?} */
var _close = (/**
* @return {?}
*/
function () {
_this.destroy();
_this._resultDeferred.resolve(result);
});
this._fireHook('beforeClose')
.then((/**
* @param {?} value
* @return {?}
*/
function (value) { return value !== true && _close(); }))
.catch(_close);
};
/**
* Close the modal without a return value, i.e: cancelled.
* This call is automatically invoked when a user either:
* - Presses an exit keyboard key (if configured).
* - Clicks outside of the modal window (if configured).
* Usually, dismiss represent a Cancel button or a X button.
*/
/**
* Close the modal without a return value, i.e: cancelled.
* This call is automatically invoked when a user either:
* - Presses an exit keyboard key (if configured).
* - Clicks outside of the modal window (if configured).
* Usually, dismiss represent a Cancel button or a X button.
* @return {?}
*/
DialogRef.prototype.dismiss = /**
* Close the modal without a return value, i.e: cancelled.
* This call is automatically invoked when a user either:
* - Presses an exit keyboard key (if configured).
* - Clicks outside of the modal window (if configured).
* Usually, dismiss represent a Cancel button or a X button.
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var _dismiss = (/**
* @return {?}
*/
function () {
_this.destroy();
_this._resultDeferred.promise.catch((/**
* @return {?}
*/
function () { }));
_this._resultDeferred.reject();
});
this._fireHook('beforeDismiss')
.then((/**
* @param {?} value
* @return {?}
*/
function (value) { return value !== true && _dismiss(); }))
.catch(_dismiss);
};
/**
* Gracefully close the overlay/dialog with a rejected result.
* Does not trigger canDestroy on the overlay.
*/
/**
* Gracefully close the overlay/dialog with a rejected result.
* Does not trigger canDestroy on the overlay.
* @return {?}
*/
DialogRef.prototype.bailOut = /**
* Gracefully close the overlay/dialog with a rejected result.
* Does not trigger canDestroy on the overlay.
* @return {?}
*/
function () {
if (this.destroyed !== true) {
this.destroyed = true;
this._onDestroy.next(null);
this._onDestroy.complete();
this._resultDeferred.reject(new DialogBailOutError());
}
};
/**
* @return {?}
*/
DialogRef.prototype.destroy = /**
* @return {?}
*/
function () {
var _this = this;
if (this.destroyed !== true) {
this.destroyed = true;
if (typeof this.overlayRef.instance.canDestroy === 'function') {
this.overlayRef.instance.canDestroy()
.catch((/**
* @return {?}
*/
function () { }))
.then((/**
* @return {?}
*/
function () { return _this._destroy(); }));
}
else {
this._destroy();
}
}
};
/**
* @private
* @return {?}
*/
DialogRef.prototype._destroy = /**
* @private
* @return {?}
*/
function () {
this._onDestroy.next(null);
this._onDestroy.complete();
this.overlayRef.destroy();
};
/**
* @private
* @template G
* @param {?} name
* @return {?}
*/
DialogRef.prototype._fireHook = /**
* @private
* @template G
* @param {?} name
* @return {?}
*/
function (name) {
/** @type {?} */
var guard = this.closeGuard;
/** @type {?} */
var fn = guard && typeof guard[name] === 'function' && guard[name];
return Promise.resolve(fn ? fn.call(guard) : false);
};
return DialogRef;
}());
if (false) {
/**
* Reference to the overlay component ref.
* @type {?}
*/
DialogRef.prototype.overlayRef;
/**
* States if the modal is inside a specific element.
* @type {?}
*/
DialogRef.prototype.inElement;
/** @type {?} */
DialogRef.prototype.destroyed;
/**
* Fired before dialog is destroyed.
* No need to unsubscribe, done automatically.
* Note: Always called.
* When called, overlayRef might or might not be destroyed.
* @type {?}
*/
DialogRef.prototype.onDestroy;
/**
* @type {?}
* @private
*/
DialogRef.prototype._resultDeferred;
/**
* @type {?}
* @private
*/
DialogRef.prototype._onDestroy;
/**
* @type {?}
* @private
*/
DialogRef.prototype.closeGuard;
/** @type {?} */
DialogRef.prototype.overlay;
/** @type {?} */
DialogRef.prototype.context;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/tokens.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var DROP_IN_TYPE = {
alert: 0,
prompt: 1,
confirm: 2,
};
DROP_IN_TYPE[DROP_IN_TYPE.alert] = 'alert';
DROP_IN_TYPE[DROP_IN_TYPE.prompt] = 'prompt';
DROP_IN_TYPE[DROP_IN_TYPE.confirm] = 'confirm';
/**
* @record
*/
function OverlayConfig() { }
if (false) {
/**
* The context for the modal, attached to the dialog instance, DialogRef.context.
* Default: {}
* @type {?|undefined}
*/
OverlayConfig.prototype.context;
/** @type {?|undefined} */
OverlayConfig.prototype.injector;
/**
* The element to block using the modal.
* @type {?|undefined}
*/
OverlayConfig.prototype.viewContainer;
/** @type {?|undefined} */
OverlayConfig.prototype.renderer;
/**
* Not used yet.
* @type {?|undefined}
*/
OverlayConfig.prototype.overlayPlugins;
}
/**
* @record
* @template T
*/
function ModalComponent() { }
if (false) {
/** @type {?} */
ModalComponent.prototype.dialog;
}
/**
* @record
*/
function CloseGuard() { }
if (false) {
/**
* Invoked before a modal is dismissed.
* @return {?}
*/
CloseGuard.prototype.beforeDismiss = function () { };
/**
* Invoked before a modal is closed.
* @return {?}
*/
CloseGuard.prototype.beforeClose = function () { };
}
/**
* @abstract
*/
var /**
* @abstract
*/
OverlayRenderer = /** @class */ (function () {
function OverlayRenderer() {
}
return OverlayRenderer;
}());
if (false) {
/**
* @abstract
* @param {?} dialogRef
* @param {?} vcRef
* @param {?=} injector
* @return {?}
*/
OverlayRenderer.prototype.render = function (dialogRef, vcRef, injector) { };
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/vc-ref-store.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var vcRefCollection = {};
/**
* @param {?} key
* @return {?}
*/
function getVCRef(key) {
return vcRefCollection[key] ? vcRefCollection[key].slice() : [];
}
/**
* @param {?} key
* @param {?} vcRef
* @return {?}
*/
function setVCRef(key, vcRef) {
if (!vcRefCollection.hasOwnProperty(key)) {
vcRefCollection[key] = [];
}
vcRefCollection[key].push(vcRef);
}
/**
* @param {?} key
* @param {?=} vcRef
* @return {?}
*/
function delVCRef(key, vcRef) {
if (!vcRef) {
vcRefCollection[key] = [];
}
else {
/** @type {?} */
var coll = vcRefCollection[key] || [];
/** @type {?} */
var idx = coll.indexOf(vcRef);
if (idx > -1) {
coll.splice(idx, 1);
}
}
}
/**
* A Simple store that holds a reference to ViewContainerRef instances by a user defined key.
* This, with the OverlayTarget directive makes it easy to block the overlay inside an element
* without having to use the angular query boilerplate.
* @type {?}
*/
var vcRefStore = { getVCRef: getVCRef, setVCRef: setVCRef, delVCRef: delVCRef };
/**
* @fileoverview added by tsickle
* Generated from: lib/overlay/overlay.directives.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* A directive use to signal the overlay that the host of this directive
* is a dialog boundary, i.e: over click outside of the element should close the modal
* (if non blocking)
*/
var OverlayDialogBoundary = /** @class */ (function () {
function OverlayDialogBoundary(el, dialogRef) {
if (dialogRef && el.nativeElement) {
dialogRef.overlayRef.instance.setClickBoundary(el.nativeElement);
}
}
OverlayDialogBoundary.decorators = [
{ type: Directive, args: [{
// tslint:disable-next-line:directive-selector
selector: '[overlayDialogBoundary]'
},] }
];
/** @nocollapse */
OverlayDialogBoundary.ctorParameters = function () { return [
{ type: ElementRef },
{ type: DialogRef }
]; };
return OverlayDialogBoundary;
}());
var OverlayTarget = /** @class */ (function () {
function OverlayTarget(vcRef) {
this.vcRef = vcRef;
}
Object.defineProperty(OverlayTarget.prototype, "targetKey", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._targetKey = value;
if (value) {
vcRefStore.setVCRef(value, this.vcRef);
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
OverlayTarget.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this._targetKey) {
vcRefStore.delVCRef(this._targetKey, this.vcRef);
}
};
OverlayTarget.decorators = [
{ type: Directive, args: [{
// tslint:disable-next-line:directive-selector
selector: '[overlayTarget]'
},] }
];
/** @nocollapse */
OverlayTarget.ctorParameters = function () { return [
{ type: ViewContainerRef }
]; };
OverlayTarget.propDecorators = {
targetKey: [{ type: Input, args: ['overlayTarget',] }]
};
return OverlayTarget;
}());
if (false) {
/**
* @type {?}
* @private
*/
OverlayTarget.prototype._targetKey;
/**
* @type {?}
* @private
*/
OverlayTarget.prototype.vcRef;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/components/base-dynamic-component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var BROWSER_PREFIX = ['webkit', 'moz', 'MS', 'o', ''];
/**
* @param {?} eventName
* @param {?} element
* @param {?} cb
* @return {?}
*/
function register(eventName, element, cb) {
BROWSER_PREFIX.forEach((/**
* @param {?} p
* @return {?}
*/
function (p) {
element.addEventListener(p ? p + eventName : eventName.toLowerCase(), cb, false);
}));
}
/**
* A base class for supporting dynamic components.
* There are 3 main support areas:
* 1 - Easy wrapper for dynamic styling via CSS classes and inline styles.
* 2 - Easy wrapper for interception of transition/animation end events.
* 3 - Easy wrapper for component creation and injection.
*
* Dynamic css is done via direct element manipulation (via renderer), it does not use change detection
* or binding. This is to allow better control over animation.
*
* Animation support is limited, only transition/keyframes END even are notified.
* The animation support is needed since currently the angular animation module is limited as well and
* does not support CSS animation that are not pre-parsed and are not in the styles metadata of a component.
*
* Capabilities: Add/Remove styls, Add/Remove classes, listen to animation/transition end event,
* add components
*/
var /**
* A base class for supporting dynamic components.
* There are 3 main support areas:
* 1 - Easy wrapper for dynamic styling via CSS classes and inline styles.
* 2 - Easy wrapper for interception of transition/animation end events.
* 3 - Easy wrapper for component creation and injection.
*
* Dynamic css is done via direct element manipulation (via renderer), it does not use change detection
* or binding. This is to allow better control over animation.
*
* Animation support is limited, only transition/keyframes END even are notified.
* The animation support is needed since currently the angular animation module is limited as well and
* does not support CSS animation that are not pre-parsed and are not in the styles metadata of a component.
*
* Capabilities: Add/Remove styls, Add/Remove classes, listen to animation/transition end event,
* add components
*/
BaseDynamicComponent = /** @class */ (function () {
function BaseDynamicComponent(el, renderer) {
this.el = el;
this.renderer = renderer;
}
/**
* @return {?}
*/
BaseDynamicComponent.prototype.activateAnimationListener = /**
* @return {?}
*/
function () {
var _this = this;
if (this.animationEnd) {
return;
}
this.animationEnd = new Subject();
this.animationEnd$ = this.animationEnd.asObservable();
register('TransitionEnd', this.el.nativeElement, (/**
* @param {?} e
* @return {?}
*/
function (e) { return _this.onEnd(e); }));
register('AnimationEnd', this.el.nativeElement, (/**
* @param {?} e
* @return {?}
*/
function (e) { return _this.onEnd(e); }));
};
/**
* Set a specific inline style on the overlay host element.
* @param prop The style key
* @param value The value, undefined to remove
*/
/**
* Set a specific inline style on the overlay host element.
* @template THIS
* @this {THIS}
* @param {?} prop The style key
* @param {?} value The value, undefined to remove
* @return {THIS}
*/
BaseDynamicComponent.prototype.setStyle = /**
* Set a specific inline style on the overlay host element.
* @template THIS
* @this {THIS}
* @param {?} prop The style key
* @param {?} value The value, undefined to remove
* @return {THIS}
*/
function (prop, value) {
(/** @type {?} */ (this)).renderer.setStyle((/** @type {?} */ (this)).el.nativeElement, prop, value);
return (/** @type {?} */ (this));
};
/**
* @return {?}
*/
BaseDynamicComponent.prototype.forceReflow = /**
* @return {?}
*/
function () {
this.el.nativeElement.offsetWidth;
};
/**
* @param {?} css
* @param {?=} forceReflow
* @return {?}
*/
BaseDynamicComponent.prototype.addClass = /**
* @param {?} css
* @param {?=} forceReflow
* @return {?}
*/
function (css, forceReflow) {
var _this = this;
if (forceReflow === void 0) { forceReflow = false; }
css.split(' ')
.forEach((/**
* @param {?} c
* @return {?}
*/
function (c) { return _this.renderer.addClass(_this.el.nativeElement, c); }));
if (forceReflow) {
this.forceReflow();
}
};
/**
* @param {?} css
* @param {?=} forceReflow
* @return {?}
*/
BaseDynamicComponent.prototype.removeClass = /**
* @param {?} css
* @param {?=} forceReflow
* @return {?}
*/
function (css, forceReflow) {
var _this = this;
if (forceReflow === void 0) { forceReflow = false; }
css.split(' ')
.forEach((/**
* @param {?} c
* @return {?}
*/
function (c) { return _this.renderer.removeClass(_this.el.nativeElement, c); }));
if (forceReflow) {
this.forceReflow();
}
};
/**
* @return {?}
*/
BaseDynamicComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.animationEnd && !this.animationEnd.closed) {
this.animationEnd.complete();
}
};
/**
* @return {?}
*/
BaseDynamicComponent.prototype.myAnimationEnd$ = /**
* @return {?}
*/
function () {
var _this = this;
return this.animationEnd$.pipe(filter((/**
* @param {?} e
* @return {?}
*/
function (e) { return e.target === _this.el.nativeElement; })));
};
/**
* Add a component, supply a view container ref.
* Note: The components vcRef will result in a sibling.
*/
/**
* Add a component, supply a view container ref.
* Note: The components vcRef will result in a sibling.
* @protected
* @template T
* @param {?} instructions
* @return {?}
*/
BaseDynamicComponent.prototype._addComponent = /**
* Add a component, supply a view container ref.
* Note: The components vcRef will result in a sibling.
* @protected
* @template T
* @param {?} instructions
* @return {?}
*/
function (instructions) {
/** @type {?} */
var cmpRef = createComponent(instructions);
cmpRef.changeDetectorRef.detectChanges();
return cmpRef;
};
/**
* @private
* @param {?} event
* @return {?}
*/
BaseDynamicComponent.prototype.onEnd = /**
* @private
* @param {?} event
* @return {?}
*/
function (event) {
if (!this.animationEnd.closed) {
this.animationEnd.next(event);
}
};
return BaseDynamicComponent;
}());
if (false) {
/** @type {?} */
BaseDynamicComponent.prototype.animationEnd$;
/**
* @type {?}
* @protected
*/
BaseDynamicComponent.prototype.animationEnd;
/**
* @type {?}
* @protected
*/
BaseDynamicComponent.prototype.el;
/**
* @type {?}
* @protected
*/
BaseDynamicComponent.prototype.renderer;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/components/css-backdrop.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Represents the modal backdrop shaped by CSS.
*/
var CSSBackdrop = /** @class */ (function (_super) {
__extends(CSSBackdrop, _super);
function CSSBackdrop(el, renderer) {
var _this = _super.call(this, el, renderer) || this;
_this.activateAnimationListener();
/** @type {?} */
var style = {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%'
};
Object.keys(style).forEach((/**
* @template THIS
* @this {THIS}
* @param {?} k
* @return {THIS}
*/
function (k) { return _this.setStyle(k, style[k]); }));
return _this;
}
CSSBackdrop.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'css-backdrop',
host: {
'[attr.class]': 'cssClass',
'[attr.style]': 'styleStr'
},
encapsulation: ViewEncapsulation.None,
template: ""
}] }
];
/** @nocollapse */
CSSBackdrop.ctorParameters = function () { return [
{ type: ElementRef },
{ type: Renderer2 }
]; };
return CSSBackdrop;
}(BaseDynamicComponent));
if (false) {
/** @type {?} */
CSSBackdrop.prototype.cssClass;
/** @type {?} */
CSSBackdrop.prototype.styleStr;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/components/css-dialog-container.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* A component that acts as a top level container for an open modal window.
*/
var CSSDialogContainer = /** @class */ (function (_super) {
__extends(CSSDialogContainer, _super);
function CSSDialogContainer(dialog, el, renderer) {
var _this = _super.call(this, el, renderer) || this;
_this.dialog = dialog;
_this.activateAnimationListener();
return _this;
}
CSSDialogContainer.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'css-dialog-container',
host: {
'tabindex': '-1',
'role': 'dialog'
},
encapsulation: ViewEncapsulation.None,
template: "\n <ng-content></ng-content>"
}] }
];
/** @nocollapse */
CSSDialogContainer.ctorParameters = function () { return [
{ type: DialogRef },
{ type: ElementRef },
{ type: Renderer2 }
]; };
return CSSDialogContainer;
}(BaseDynamicComponent));
if (false) {
/** @type {?} */
CSSDialogContainer.prototype.dialog;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/components/index.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: lib/overlay/overlay.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// TODO: use DI factory for this.
// TODO: consolidate dup code
/** @type {?} */
var isDoc = !(typeof document === 'undefined' || !document);
/**
* @record
*/
function EmbedComponentConfig() { }
if (false) {
/** @type {?} */
EmbedComponentConfig.prototype.component;
/** @type {?|undefined} */
EmbedComponentConfig.prototype.projectableNodes;
}
/**
* Represents the modal overlay.
*/
var ModalOverlay = /** @class */ (function (_super) {
__extends(ModalOverlay, _super);
function ModalOverlay(dialogRef, vcr, el, renderer) {
var _this = _super.call(this, el, renderer) || this;
_this.dialogRef = dialogRef;
_this.vcr = vcr;
_this.activateAnimationListener();
return _this;
}
/**
* @internal
*/
/**
* \@internal
* @template T
* @param {?} content
* @return {?}
*/
ModalOverlay.prototype.getProjectables = /**
* \@internal
* @template T
* @param {?} content
* @return {?}
*/
function (content) {
/** @type {?} */
var nodes;
if (typeof content === 'string') {
nodes = [[this.renderer.createText("" + content)]];
}
else if (content instanceof TemplateRef) {
nodes = [this.vcr.createEmbeddedView(content, { $implicit: this.dialogRef.context, dialogRef: this.dialogRef }).rootNodes];
}
else {
nodes = [this.embedComponent({ component: content }).rootNodes];
}
return nodes;
};
/**
* @param {?} config
* @return {?}
*/
ModalOverlay.prototype.embedComponent = /**
* @param {?} config
* @return {?}
*/
function (config) {
/** @type {?} */
var ctx = (/** @type {?} */ (config));
return this.vcr.createEmbeddedView(this.template, (/** @type {?} */ ({
$implicit: ctx
})));
};
/**
* @template T
* @param {?} type
* @param {?=} projectableNodes
* @return {?}
*/
ModalOverlay.prototype.addComponent = /**
* @template T
* @param {?} type
* @param {?=} projectableNodes
* @return {?}
*/
function (type, projectableNodes) {
if (projectableNodes === void 0) { projectableNodes = []; }
return _super.prototype._addComponent.call(this, {
component: type,
vcRef: this.innerVcr,
projectableNodes: projectableNodes
});
};
/**
* @return {?}
*/
ModalOverlay.prototype.fullscreen = /**
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var style = {
position: 'fixed',
top: 0,
left: 0,
bottom: 0,
right: 0,
'z-index': 1500
};
Object.keys(style).forEach((/**
* @template THIS
* @this {THIS}
* @param {?} k
* @return {THIS}
*/
function (k) { return _this.setStyle(k, style[k]); }));
};
/**
* @return {?}
*/
ModalOverlay.prototype.insideElement = /**
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var style = {
position: 'absolute',
overflow: 'hidden',
width: '100%',
height: '100%',
top: 0,
left: 0,
bottom: 0,
right: 0
};
Object.keys(style).forEach((/**
* @template THIS
* @this {THIS}
* @param {?} k
* @return {THIS}
*/
function (k) { return _this.setStyle(k, style[k]); }));
};
/**
* Set a specific inline style for the container of the whole dialog component
* The dialog component root element is the host of this component, it contains only 1 direct
* child which is the container.
*
* Structure:
*
* ```html
* <modal-overlay>
* <div>
* <!-- BACKDROP ELEMENT -->
* <!-- DIALOG CONTAINER ELEMENT -->
* </div>
* </modal-overlay>
* ```
*
* @param prop The style key
* @param value The value, undefined to remove
*/
/**
* Set a specific inline style for the container of the whole dialog component
* The dialog component root element is the host of this component, it contains only 1 direct
* child which is the container.
*
* Structure:
*
* ```html
* <modal-overlay>
* <div>
* <!-- BACKDROP ELEMENT -->
* <!-- DIALOG CONTAINER ELEMENT -->
* </div>
* </modal-overlay>
* ```
*
* @template THIS
* @this {THIS}
* @param {?} prop The style key
* @param {?} value The value, undefined to remove
* @return {THIS}
*/
ModalOverlay.prototype.setContainerStyle = /**
* Set a specific inline style for the container of the whole dialog component
* The dialog component root element is the host of this component, it contains only 1 direct
* child which is the container.
*
* Structure:
*
* ```html
* <modal-overlay>
* <div>
* <!-- BACKDROP ELEMENT -->
* <!-- DIALOG CONTAINER ELEMENT -->
* </div>
* </modal-overlay>
* ```
*
* @template THIS
* @this {THIS}
* @param {?} prop The style key
* @param {?} value The value, undefined to remove
* @return {THIS}
*/
function (prop, value) {
(/** @type {?} */ (this)).renderer.setStyle((/** @type {?} */ (this)).container.nativeElement, prop, value);
return (/** @type {?} */ (this));
};
/**
* Define an element that click inside it will not trigger modal close.
* Since events bubble, clicking on a dialog will bubble up to the overlay, a plugin
* must define an element that represent the dialog, the overlay will make sure no to close when
* it was clicked.
* @param element
*/
/**
* Define an element that click inside it will not trigger modal close.
* Since events bubble, clicking on a dialog will bubble up to the overlay, a plugin
* must define an element that represent the dialog, the overlay will make sure no to close when
* it was clicked.
* @param {?} element
* @return {?}
*/
ModalOverlay.prototype.setClickBoundary = /**
* Define an element that click inside it will not trigger modal close.
* Since events bubble, clicking on a dialog will bubble up to the overlay, a plugin
* must define an element that represent the dialog, the overlay will make sure no to close when
* it was clicked.
* @param {?} element
* @return {?}
*/
function (element) {
var _this = this;
/** @type {?} */
var target;
/** @type {?} */
var elListener = (/**
* @param {?} event
* @return {?}
*/
function (event) { return target = (/** @type {?} */ (event.target)); });
/** @type {?} */
var docListener = (/**
* @param {?} event
* @return {?}
*/
function (event) {
if (_this.dialogRef.context.isBlocking || !_this.dialogRef.overlay.isTopMost(_this.dialogRef)) {
return;
}
/** @type {?} */
var current = event.target;
// on click, this will hit.
if (current === target) {
return;
}
// on mouse down -> drag -> release the current might not be 'target', it might be
// a sibling or a child (i.e: not part of the tree-up direction). It might also be a release
// outside the dialog... so we compare to the boundary element
do {
if (current === element) {
return;
}
} while (current.parentNode && (current = current.parentNode));