ngx-modialog-10
Version:
Modal / Dialog for Angular
1,733 lines (1,718 loc) • 74.4 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 { 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 {?} */
const PRIVATE_PREFIX = '$$';
/** @type {?} */
const 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 {?}
*/
name => RESERVED_REGEX.test(name)))
.map((/**
* @param {?} name
* @return {?}
*/
name => 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
})));
}
/**
* 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 {?}
*/
name => ((/** @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 = false) {
validateMethodName.call(obj, propertyName);
/** @type {?} */
const key = privateKey(propertyName);
objectDefinePropertyValue(obj, propertyName, (/**
* @param {?} value
* @return {?}
*/
(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 = false) {
validateMethodName.call(obj, propertyName);
objectDefinePropertyValue(obj, propertyName, (/**
* @param {?} value
* @return {?}
*/
(value) => {
obj[srcPropertyName](value);
return obj;
}));
if (hard === true) {
/** @type {?} */
const key = privateKey(propertyName);
/** @type {?} */
const srcKey = privateKey(srcPropertyName);
Object.defineProperty(obj, key, (/** @type {?} */ ({
configurable: false,
enumerable: false,
get: (/**
* @return {?}
*/
() => obj[srcKey])
})));
}
}
/**
* @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
*/
class FluentAssignFactory {
/**
* @param {?=} fluentAssign
*/
constructor(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.
* @return {?}
*/
setMethod(name, defaultValue) {
setAssignMethod(this._fluentAssign, name);
if (defaultValue !== undefined) {
((/** @type {?} */ (this._fluentAssign)))[name](defaultValue);
}
return this;
}
/**
* The FluentAssign instance.
* @return {?}
*/
get fluentAssign() {
return this._fluentAssign;
}
}
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
*/
class FluentAssign {
/**
*
* @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.
*/
constructor(defaultValues, initialSetters, baseType) {
if (Array.isArray(defaultValues)) {
((/** @type {?} */ (defaultValues))).forEach((/**
* @param {?} d
* @return {?}
*/
d => applyDefaultValues(this, d)));
}
else if (defaultValues) {
applyDefaultValues(this, defaultValues);
}
if (Array.isArray(initialSetters)) {
initialSetters.forEach((/**
* @param {?} name
* @return {?}
*/
name => setAssignMethod(this, name)));
}
if (baseType) {
this.__fluent$base__ = baseType;
}
}
/**
* 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 {?}
*/
static compose(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.
* @template Z
* @param {?} fluentAssign An instance of FluentAssign<?> or a derived class of FluentAssign<?>.
* @return {?}
*/
static composeWith(fluentAssign) {
return (/** @type {?} */ (new FluentAssignFactory((/** @type {?} */ (fluentAssign)))));
}
/**
* @return {?}
*/
toJSON() {
return getAssignedPropertyNames(this)
.reduce((/**
* @param {?} obj
* @param {?} name
* @return {?}
*/
(obj, name) => {
/** @type {?} */
const key = privateKey(name);
// re-define property descriptors (we dont want their value)
/** @type {?} */
const 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 {?} */ ({})));
}
}
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 {?} */
const m = (/** @type {?} */ ({}));
for (const attr in m1) {
if (m1.hasOwnProperty(attr)) {
((/** @type {?} */ (m)))[attr] = ((/** @type {?} */ (m1)))[attr];
}
}
for (const 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 {?}
*/
v => 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 {?}
*/
k => `${k}:${obj[k]}`))
.join(';');
// let objStr = JSON.stringify(obj);
// return objStr.substr(1, objStr.length - 2)
// .replace(/,/g, ';')
// .replace(/"/g, '');
}
/**
* @template R
*/
class PromiseCompleter {
constructor() {
this.promise = new Promise((/**
* @param {?} res
* @param {?} rej
* @return {?}
*/
(res, rej) => {
this.resolve = res;
this.reject = rej;
}));
}
}
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 {?} */
const injector = instructions.injector || instructions.vcRef.injector;
/** @type {?} */
const 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
*/
class DialogBailOutError extends Error {
/**
* @param {?=} value
*/
constructor(value) {
super();
if (!value) {
value = 'Dialog was forced to close by an unknown source.';
}
this.message = value;
}
}
/**
* @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
*/
class DialogRef {
/**
* @param {?} overlay
* @param {?=} context
*/
constructor(overlay, context) {
this.overlay = overlay;
this.context = context;
this._resultDeferred = new PromiseCompleter();
this._onDestroy = new Subject();
this.onDestroy = this._onDestroy.asObservable();
}
/**
* A Promise that is resolved on a close event and rejected on a dismiss event.
* @return {?}
*/
get result() {
return this._resultDeferred.promise;
}
/**
* Set a close/dismiss guard
* @param {?} guard
* @return {?}
*/
setCloseGuard(guard) {
this.closeGuard = guard;
}
/**
* Close the modal with a return value, i.e: result.
* @param {?=} result
* @return {?}
*/
close(result = null) {
/** @type {?} */
const _close = (/**
* @return {?}
*/
() => {
this.destroy();
this._resultDeferred.resolve(result);
});
this._fireHook('beforeClose')
.then((/**
* @param {?} value
* @return {?}
*/
value => 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.
* @return {?}
*/
dismiss() {
/** @type {?} */
const _dismiss = (/**
* @return {?}
*/
() => {
this.destroy();
this._resultDeferred.promise.catch((/**
* @return {?}
*/
() => { }));
this._resultDeferred.reject();
});
this._fireHook('beforeDismiss')
.then((/**
* @param {?} value
* @return {?}
*/
value => value !== true && _dismiss()))
.catch(_dismiss);
}
/**
* Gracefully close the overlay/dialog with a rejected result.
* Does not trigger canDestroy on the overlay.
* @return {?}
*/
bailOut() {
if (this.destroyed !== true) {
this.destroyed = true;
this._onDestroy.next(null);
this._onDestroy.complete();
this._resultDeferred.reject(new DialogBailOutError());
}
}
/**
* @return {?}
*/
destroy() {
if (this.destroyed !== true) {
this.destroyed = true;
if (typeof this.overlayRef.instance.canDestroy === 'function') {
this.overlayRef.instance.canDestroy()
.catch((/**
* @return {?}
*/
() => { }))
.then((/**
* @return {?}
*/
() => this._destroy()));
}
else {
this._destroy();
}
}
}
/**
* @private
* @return {?}
*/
_destroy() {
this._onDestroy.next(null);
this._onDestroy.complete();
this.overlayRef.destroy();
}
/**
* @private
* @template G
* @param {?} name
* @return {?}
*/
_fireHook(name) {
/** @type {?} */
const guard = this.closeGuard;
/** @type {?} */
const fn = guard && typeof guard[name] === 'function' && guard[name];
return Promise.resolve(fn ? fn.call(guard) : false);
}
}
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} */
const 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
*/
class 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 {?} */
const 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 {?} */
const coll = vcRefCollection[key] || [];
/** @type {?} */
const 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 {?}
*/
const vcRefStore = { getVCRef, setVCRef, 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)
*/
// tslint:disable-next-line:directive-class-suffix
class OverlayDialogBoundary {
/**
* @param {?} el
* @param {?} dialogRef
*/
constructor(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 = () => [
{ type: ElementRef },
{ type: DialogRef }
];
// tslint:disable-next-line:directive-class-suffix
class OverlayTarget {
/**
* @param {?} vcRef
*/
constructor(vcRef) {
this.vcRef = vcRef;
}
/**
* @param {?} value
* @return {?}
*/
set targetKey(value) {
this._targetKey = value;
if (value) {
vcRefStore.setVCRef(value, this.vcRef);
}
}
/**
* @return {?}
*/
ngOnDestroy() {
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 = () => [
{ type: ViewContainerRef }
];
OverlayTarget.propDecorators = {
targetKey: [{ type: Input, args: ['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 {?} */
const BROWSER_PREFIX = ['webkit', 'moz', 'MS', 'o', ''];
/**
* @param {?} eventName
* @param {?} element
* @param {?} cb
* @return {?}
*/
function register(eventName, element, cb) {
BROWSER_PREFIX.forEach((/**
* @param {?} p
* @return {?}
*/
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
*/
class BaseDynamicComponent {
/**
* @param {?} el
* @param {?} renderer
*/
constructor(el, renderer) {
this.el = el;
this.renderer = renderer;
}
/**
* @return {?}
*/
activateAnimationListener() {
if (this.animationEnd) {
return;
}
this.animationEnd = new Subject();
this.animationEnd$ = this.animationEnd.asObservable();
register('TransitionEnd', this.el.nativeElement, (/**
* @param {?} e
* @return {?}
*/
(e) => this.onEnd(e)));
register('AnimationEnd', this.el.nativeElement, (/**
* @param {?} e
* @return {?}
*/
(e) => this.onEnd(e)));
}
/**
* 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}
*/
setStyle(prop, value) {
(/** @type {?} */ (this)).renderer.setStyle((/** @type {?} */ (this)).el.nativeElement, prop, value);
return (/** @type {?} */ (this));
}
/**
* @return {?}
*/
forceReflow() {
this.el.nativeElement.offsetWidth;
}
/**
* @param {?} css
* @param {?=} forceReflow
* @return {?}
*/
addClass(css, forceReflow = false) {
css.split(' ')
.forEach((/**
* @param {?} c
* @return {?}
*/
c => this.renderer.addClass(this.el.nativeElement, c)));
if (forceReflow) {
this.forceReflow();
}
}
/**
* @param {?} css
* @param {?=} forceReflow
* @return {?}
*/
removeClass(css, forceReflow = false) {
css.split(' ')
.forEach((/**
* @param {?} c
* @return {?}
*/
c => this.renderer.removeClass(this.el.nativeElement, c)));
if (forceReflow) {
this.forceReflow();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.animationEnd && !this.animationEnd.closed) {
this.animationEnd.complete();
}
}
/**
* @return {?}
*/
myAnimationEnd$() {
return this.animationEnd$.pipe(filter((/**
* @param {?} e
* @return {?}
*/
e => e.target === this.el.nativeElement)));
}
/**
* Add a component, supply a view container ref.
* Note: The components vcRef will result in a sibling.
* @protected
* @template T
* @param {?} instructions
* @return {?}
*/
_addComponent(instructions) {
/** @type {?} */
const cmpRef = createComponent(instructions);
cmpRef.changeDetectorRef.detectChanges();
return cmpRef;
}
/**
* @private
* @param {?} event
* @return {?}
*/
onEnd(event) {
if (!this.animationEnd.closed) {
this.animationEnd.next(event);
}
}
}
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.
*/
// tslint:disable-next-line:component-class-suffix
class CSSBackdrop extends BaseDynamicComponent {
/**
* @param {?} el
* @param {?} renderer
*/
constructor(el, renderer) {
super(el, renderer);
this.activateAnimationListener();
/** @type {?} */
const style = {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%'
};
Object.keys(style).forEach((/**
* @template THIS
* @this {THIS}
* @param {?} k
* @return {THIS}
*/
k => this.setStyle(k, style[k])));
}
}
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 = () => [
{ type: ElementRef },
{ type: Renderer2 }
];
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.
*/
// tslint:disable-next-line:component-class-suffix
class CSSDialogContainer extends BaseDynamicComponent {
/**
* @param {?} dialog
* @param {?} el
* @param {?} renderer
*/
constructor(dialog, el, renderer) {
super(el, renderer);
this.dialog = dialog;
this.activateAnimationListener();
}
}
CSSDialogContainer.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'css-dialog-container',
host: {
'tabindex': '-1',
'role': 'dialog'
},
encapsulation: ViewEncapsulation.None,
template: `
<ng-content></ng-content>`
}] }
];
/** @nocollapse */
CSSDialogContainer.ctorParameters = () => [
{ type: DialogRef },
{ type: ElementRef },
{ type: Renderer2 }
];
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 {?} */
const isDoc = !(typeof document === 'undefined' || !document);
/**
* @record
*/
function EmbedComponentConfig() { }
if (false) {
/** @type {?} */
EmbedComponentConfig.prototype.component;
/** @type {?|undefined} */
EmbedComponentConfig.prototype.projectableNodes;
}
/**
* Represents the modal overlay.
*/
// tslint:disable-next-line:component-class-suffix
class ModalOverlay extends BaseDynamicComponent {
/**
* @param {?} dialogRef
* @param {?} vcr
* @param {?} el
* @param {?} renderer
*/
constructor(dialogRef, vcr, el, renderer) {
super(el, renderer);
this.dialogRef = dialogRef;
this.vcr = vcr;
this.activateAnimationListener();
}
/**
* \@internal
* @template T
* @param {?} content
* @return {?}
*/
getProjectables(content) {
/** @type {?} */
let 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 {?}
*/
embedComponent(config) {
/** @type {?} */
const ctx = (/** @type {?} */ (config));
return this.vcr.createEmbeddedView(this.template, (/** @type {?} */ ({
$implicit: ctx
})));
}
/**
* @template T
* @param {?} type
* @param {?=} projectableNodes
* @return {?}
*/
addComponent(type, projectableNodes = []) {
return super._addComponent({
component: type,
vcRef: this.innerVcr,
projectableNodes
});
}
/**
* @return {?}
*/
fullscreen() {
/** @type {?} */
const 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}
*/
k => this.setStyle(k, style[k])));
}
/**
* @return {?}
*/
insideElement() {
/** @type {?} */
const 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}
*/
k => 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>
* ```
*
* @template THIS
* @this {THIS}
* @param {?} prop The style key
* @param {?} value The value, undefined to remove
* @return {THIS}
*/
setContainerStyle(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
* @return {?}
*/
setClickBoundary(element) {
/** @type {?} */
let target;
/** @type {?} */
const elListener = (/**
* @param {?} event
* @return {?}
*/
event => target = (/** @type {?} */ (event.target)));
/** @type {?} */
const docListener = (/**
* @param {?} event
* @return {?}
*/
event => {
if (this.dialogRef.context.isBlocking || !this.dialogRef.overlay.isTopMost(this.dialogRef)) {
return;
}
/** @type {?} */
let 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));
this.dialogRef.dismiss();
});
if (isDoc) {
this.dialogRef.onDestroy.subscribe((/**
* @return {?}
*/
() => {
element.removeEventListener('click', elListener, false);
element.removeEventListener('touchstart', elListener, false);
document.removeEventListener('click', docListener, false);
document.removeEventListener('touchend', docListener, false);
}));
setTimeout((/**
* @return {?}
*/
() => {
element.addEventListener('mousedown', elListener, false);
element.addEventListener('touchstart', docListener, false);
document.addEventListener('click', docListener, false);
document.addEventListener('touchend', docListener, false);
}));
}
}
/**
* Temp workaround for animation where destruction of the top level component does not
* trigger child animations. Solution should be found either in animation module or in design
* of the modal component tree.
* @return {?}
*/
canDestroy() {
/** @type {?} */
const completer = new PromiseCompleter();
if (!Array.isArray(this.beforeDestroyHandlers)) {
completer.resolve();
}
else {
// run destroy notification but protect against halt.
/** @type {?} */
let id = setTimeout((/**
* @return {?}
*/
() => {
id = null;
completer.reject();
}), 1000);
/** @type {?} */
const resolve = (/**
* @return {?}
*/
() => {
if (id === null) {
return;
}
clearTimeout(id);
completer.resolve();
});
Promise.all(this.beforeDestroyHandlers.map((/**
* @param {?} fn
* @return {?}
*/
fn => fn())))
.then(resolve)
.catch(resolve);
}
return completer.promise;
}
/**
* A handler running before destruction of the overlay
* use to delay destruction due to animation.
* This is part of the workaround for animation, see canDestroy.
*
* NOTE: There is no guarantee that the listeners will fire, use dialog.onDestory for that.
* @param {?} fn
* @return {?}
*/
beforeDestroy(fn) {
if (!this.beforeDestroyHandlers) {
this.beforeDestroyHandlers = [];
}
this.beforeDestroyHandlers.push(fn);
}
/**
* @param {?} event
* @return {?}
*/
documentKeypress(event) {
// check that this modal is the last in the stack.
if (!this.dialogRef.overlay.isTopMost(this.dialogRef)) {
return;
}
if (supportsKey(event.keyCode, (/** @type {?} */ (this.dialogRef.context.keyboard)))) {
this.dialogRef.dismiss();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
super.ngOnDestroy();
if (this.dialogRef.destroyed !== true) {
// if we're here the overlay is destroyed by an external event that is not user invoked.
// i.e: The user did no call dismiss or close and dialogRef.destroy() did not invoke.
// this will happen when routing or killing an element containing a blocked overlay (ngIf)
// we bail out, i.e gracefully shutting down.
this.dialogRef.bailOut();
}
}
}
ModalOverlay.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'modal-overlay',
encapsulation: ViewEncapsulation.None,
template: "<div #container>\n <ng-template #innerView></ng-template>\n</div>\n<ng-template #template let-ctx>\n <ng-container *ngComponentOutlet=\"ctx.component; injector: ctx.injector; content: ctx.projectableNodes\"></ng-container>\n</ng-template>"
}] }
];
/** @nocollapse */
ModalOverlay.ctorParameters = () => [
{ type: DialogRef },
{ type: ViewContainerRef },
{ type: ElementRef },
{ type: Renderer2 }
];
ModalOverlay.propDecorators = {
container: [{ type: ViewChild, args: ['container', { read: ElementRef, static: true },] }],
innerVcr: [{ type: ViewChild, args: ['innerView', { read: ViewContainerRef, static: true },] }],
template: [{ type: ViewChild, args: ['template', { static: true },] }],
documentKeypress: [{ type: HostListener, args: ['body:keydown', ['$event'],] }]
};
if (false) {
/**
* @type {?}
* @private
*/
ModalOverlay.prototype.beforeDestroyHandlers;
/** @type {?} */
ModalOverlay.prototype.container;
/** @type {?} */
ModalOverlay.prototype.innerVcr;
/** @type {?} */
ModalOverlay.prototype.template;
/**
* @type {?}
* @private
*/
ModalOverlay.prototype.dialogRef;
/**
* @type {?}
* @private
*/
ModalOverlay.prototype.vcr;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/dialog-ref-stack.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const BASKET_GROUP = {};
/**
* A dumb stack implementation over an array.
* @template T
*/
class DialogRefStack {
constructor() {
this._stack = [];
this._stackMap = new Map();
}
/**
* @return {?}
*/
get length() {
return this._stack.length;
}
/**
* @param {?=} result
* @return {?}
*/
closeAll(result = null) {
for (let i = 0, len = this._stack.length; i < len; i++) {
this._stack.pop().close(result);
}
}
/**
* @param {?} dialogRef
* @param {?=} group
* @return {?}
*/
push(dialogRef, group) {
if (this._stack.indexOf(dialogRef) === -1) {
this._stack.push(dialogRef);
this._stackMap.set(dialogRef, group || BASKET_GROUP);
}
}
/**
* Push a DialogRef into the stack and manage it so when it's done
* it will automatically kick itself out of the stack.
* @param {?} dialogRef
* @param {?=} group
* @return {?}
*/
pushManaged(dialogRef, group) {
this.push(dialogRef, group);
dialogRef.onDestroy.subscribe((/**
* @return {?}
*/
() => this.remove(dialogRef)));
}
/**
* @return {?}
*/
pop() {
/** @type {?} */
const dialogRef = this._stack.pop();
this._stackMap.delete(dialogRef);
return dialogRef;
}
/**
* Remove a DialogRef from the stack.
* @param {?} dialogRef
* @return {?}
*/
remove(dialogRef) {
/** @type {?} */
let idx = this.indexOf(dialogRef);
if (idx > -1) {
this._stack.splice(idx, 1);
this._stackMap.delete(dialogRef);
}
}
/**
* @param {?} index
* @return {?}
*/
index(index) {
return this._stack[index];
}
/**
* @param {?} dialogRef
* @return {?}
*/
indexOf(dialogRef) {
return this._stack.indexOf(dialogRef);
}
/**
* @param {?} dialogRef
* @return {?}
*/
groupOf(dialogRef) {
return this._stackMap.get(dialogRef);
}
/**
* @param {?} group
* @return {?}
*/
groupBy(group) {
/** @type {?} */
const arr = [];
if (group) {
this._stackMap.forEach((/**
* @param {?} value
* @param {?} key
* @return {?}
*/
(value, key) => {
if (value === group) {
arr.push(key);
}
}));
}
return arr;
}
/**
* @param {?} group
* @return {?}
*/
groupLength(group) {
/** @type {?} */
let count = 0;
if (group) {
this._stackMap.forEach((/**
* @param {?} value
* @return {?}
*/
(value) => {
if (value === group) {
count++;
}
}));
}
return count;
}
}
if (false) {
/**
* @type {?}
* @private
*/
DialogRefStack.prototype._stack;
/**
* @type {?}
* @private
*/
DialogRefStack.prototype._stackMap;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/overlay/overlay.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const _stack = new DialogRefStack();
class Overlay {
/**
* @param {?} _modalRenderer
* @param {?} injector
*/
constructor(_modalRenderer, injector) {
this._modalRenderer = _modalRenderer;
this.injector = injector;
}
/**
* @return {?}
*/
get stackLength() {
return _stack.length;
}
/**
* Check if a given DialogRef is the top most ref in the stack.
* TODO: distinguish between body modal vs in element modal.
* @param {?} dialogRef
* @return {?}
*/
isTopMost(dialogRef) {
return _stack.indexOf(dialogRef) === _stack.length - 1;
}
/**
* @param {?} dialogRef
* @return {?}
*/
stackPosition(dialogRef) {
return _stack.indexOf(dialogRef);
}
/**
* @param {?} dialogRef
* @return {?}
*/
groupStackLength(dialogRef) {
return _stack.groupLength(_stack.groupOf(dialogRef));
}
/**
* @param {?=} result
* @return {?}
*/
clo