UNPKG

ngx-modialog

Version:
141 lines (140 loc) 5.14 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import { FluentAssign } from './../framework/fluent-assign'; import { extend, arrayUnion } from './../framework/utils'; export const /** @type {?} */ DEFAULT_VALUES = { inElement: false, isBlocking: true, keyboard: [27], supportsKey: function supportsKey(keyCode) { return (/** @type {?} */ (this.keyboard)).indexOf(keyCode) > -1; } }; const /** @type {?} */ DEFAULT_SETTERS = [ 'inElement', 'isBlocking', 'keyboard' ]; export class OverlayContext { /** * @return {?} */ normalize() { if (this.isBlocking !== false) this.isBlocking = true; if (this.keyboard === null) { this.keyboard = []; } else if (typeof this.keyboard === 'number') { this.keyboard = [/** @type {?} */ (this.keyboard)]; } else if (!Array.isArray(/** @type {?} */ (this.keyboard))) { this.keyboard = DEFAULT_VALUES.keyboard; } } } function OverlayContext_tsickle_Closure_declarations() { /** * Describes if the modal is rendered within the container element. * The container element is the ViewContainerRef supplied. * Defaults to false. * @type {?} */ OverlayContext.prototype.inElement; /** * Describes if the modal is blocking modal. * A Blocking modal is not closable by clicking outside of the modal window. * Defaults to false. * @type {?} */ OverlayContext.prototype.isBlocking; /** * Keyboard value/s that close the modal. * Accepts either a single numeric value or an array of numeric values. * A modal closed by a keyboard stroke will result in a 'reject' notification from the promise. * Defaults to 27, set `null` implicitly to disable. * @type {?} */ OverlayContext.prototype.keyboard; } // unsupported: template constraints. /** * A core context builder for a modal window instance, used to define the context upon * a modal choose it's behaviour. * @template T */ export class OverlayContextBuilder extends FluentAssign { /** * @param {?=} defaultValues * @param {?=} initialSetters * @param {?=} baseType */ constructor(defaultValues = undefined, initialSetters = undefined, baseType = undefined) { super(extend(DEFAULT_VALUES, defaultValues || {}), arrayUnion(DEFAULT_SETTERS, initialSetters || []), baseType || /** @type {?} */ (OverlayContext // https://github.com/Microsoft/TypeScript/issues/7234 ) // https://github.com/Microsoft/TypeScript/issues/7234 ); } /** * Returns an new OverlayConfig with a context property representing the data in this builder. * @param {?=} base A base configuration that the result will extend * @return {?} */ toOverlayConfig(base) { return extend(base || {}, { context: this.toJSON() }); } } function OverlayContextBuilder_tsickle_Closure_declarations() { /** * Describes if the modal is rendered within the container element. * The container element is the ViewContainerRef supplied. * Defaults to false. * @type {?} */ OverlayContextBuilder.prototype.inElement; /** * Describes if the modal is blocking modal. * A Blocking modal is not closable by clicking outside of the modal window. * Defaults to false. * @type {?} */ OverlayContextBuilder.prototype.isBlocking; /** * Keyboard value/s that close the modal. * Accepts either a single numeric value or an array of numeric values. * A modal closed by a keyboard stroke will result in a 'reject' notification from the promise. * Defaults to 27, set `null` implicitly to disable. * @type {?} */ OverlayContextBuilder.prototype.keyboard; } /** * @record * @template T */ export function ModalControllingContextBuilder() { } function ModalControllingContextBuilder_tsickle_Closure_declarations() { /** @type {?} */ ModalControllingContextBuilder.prototype.open; } /** * A helper to create an `OverlayConfig` on the fly. * Since `OverlayConfig` requires context it means a builder is needed, this process had some boilerplate. * When a quick, on the fly overlay config is needed use this helper to avoid that boilerplate. * * A builder is used as an API to allow setting the context and providing some operations around the modal. * When a developers knows the context before hand we can skip this step, this is what this factory is for. * * @template T * @param {?} context The context for the modal * @param {?=} baseContextType Optional. The type/class of the context. This is the class used to init a new instance of the context * @param {?=} baseConfig A base configuration that the result will extend * @return {?} */ export function overlayConfigFactory(context, baseContextType, baseConfig) { return new OverlayContextBuilder(/** @type {?} */ (context), undefined, baseContextType).toOverlayConfig(baseConfig); } //# sourceMappingURL=overlay-context.js.map