UNPKG

ngx-ntk-smart-module

Version:

Ntk Cms Modal

564 lines (552 loc) 21.8 kB
import * as i0 from '@angular/core'; import { OnInit, OnDestroy, AfterViewInit, EventEmitter, Type, Component, QueryList, ElementRef, ViewContainerRef, Renderer2, ChangeDetectorRef, ComponentFactoryResolver, ApplicationRef, Injector, TemplateRef, ModuleWithProviders } from '@angular/core'; import * as i2 from '@angular/common'; declare class NtkSmartModalComponent implements OnInit, OnDestroy, AfterViewInit { private _renderer; private _changeDetectorRef; private componentFactoryResolver; private _document; private _platformId; closable: boolean; escapable: boolean; dismissable: boolean; identifier: string; customClass: string; visible: boolean; backdrop: boolean; force: boolean; hideDelay: number; autostart: boolean; target: string; ariaLabel: string | null; ariaLabelledBy: string | null; ariaDescribedBy: string | null; refocus: boolean; visibleChange: EventEmitter<boolean>; onClose: EventEmitter<any>; onCloseFinished: EventEmitter<any>; onDismiss: EventEmitter<any>; onDismissFinished: EventEmitter<any>; onAnyCloseEvent: EventEmitter<any>; onAnyCloseEventFinished: EventEmitter<any>; onOpen: EventEmitter<any>; onOpenFinished: EventEmitter<any>; onEscape: EventEmitter<any>; onDataAdded: EventEmitter<any>; onDataRemoved: EventEmitter<any>; contentComponent: Type<Component>; layerPosition: number; overlayVisible: boolean; openedClass: boolean; createFrom: string; private _data; private nsmContent; nsmDialog: QueryList<ElementRef>; private nsmOverlay; dynamicContentContainer: QueryList<ViewContainerRef>; constructor(_renderer: Renderer2, _changeDetectorRef: ChangeDetectorRef, componentFactoryResolver: ComponentFactoryResolver, _document: any, _platformId: any); ngOnInit(): void; ngAfterViewInit(): void; ngOnDestroy(): void; /** * Open the modal instance * * @param top open the modal top of all other * @returns the modal component */ open(top?: boolean): NtkSmartModalComponent; /** * Close the modal instance * * @returns the modal component */ close(): NtkSmartModalComponent; /** * Dismiss the modal instance * * @param e the event sent by the browser * @returns the modal component */ dismiss(e: any): NtkSmartModalComponent; /** * Toggle visibility of the modal instance * * @param top open the modal top of all other * @returns the modal component */ toggle(top?: boolean): NtkSmartModalComponent; /** * Add a custom class to the modal instance * * @param className the class to add * @returns the modal component */ addCustomClass(className: string): NtkSmartModalComponent; /** * Remove a custom class to the modal instance * * @param className the class to remove * @returns the modal component */ removeCustomClass(className?: string): NtkSmartModalComponent; /** * Returns the visibility state of the modal instance */ isVisible(): boolean; /** * Checks if data is attached to the modal instance */ hasData(): boolean; /** * Attach data to the modal instance * * @param data the data to attach * @param force override potentially attached data * @returns the modal component */ setData(data: any, force?: boolean): NtkSmartModalComponent; /** * Retrieve the data attached to the modal instance */ getData(): any; /** * Remove the data attached to the modal instance * * @returns the modal component */ removeData(): NtkSmartModalComponent; /** * Add body class modal opened * * @returns the modal component */ addBodyClass(): NtkSmartModalComponent; /** * Add body class modal opened * * @returns the modal component */ removeBodyClass(): NtkSmartModalComponent; markForCheck(): void; /** * Listens for window resize event and recalculates modal instance position if it is element-relative */ targetPlacement(): boolean | void; private _sendEvent; /** * Is current platform browser */ private get isBrowser(); /** * Creates content inside provided ViewContainerRef */ private createDynamicContent; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartModalComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<NtkSmartModalComponent, "ntk-smart-modal", never, { "closable": { "alias": "closable"; "required": false; }; "escapable": { "alias": "escapable"; "required": false; }; "dismissable": { "alias": "dismissable"; "required": false; }; "identifier": { "alias": "identifier"; "required": false; }; "customClass": { "alias": "customClass"; "required": false; }; "visible": { "alias": "visible"; "required": false; }; "backdrop": { "alias": "backdrop"; "required": false; }; "force": { "alias": "force"; "required": false; }; "hideDelay": { "alias": "hideDelay"; "required": false; }; "autostart": { "alias": "autostart"; "required": false; }; "target": { "alias": "target"; "required": false; }; "ariaLabel": { "alias": "ariaLabel"; "required": false; }; "ariaLabelledBy": { "alias": "ariaLabelledBy"; "required": false; }; "ariaDescribedBy": { "alias": "ariaDescribedBy"; "required": false; }; "refocus": { "alias": "refocus"; "required": false; }; }, { "visibleChange": "visibleChange"; "onClose": "onClose"; "onCloseFinished": "onCloseFinished"; "onDismiss": "onDismiss"; "onDismissFinished": "onDismissFinished"; "onAnyCloseEvent": "onAnyCloseEvent"; "onAnyCloseEventFinished": "onAnyCloseEventFinished"; "onOpen": "onOpen"; "onOpenFinished": "onOpenFinished"; "onEscape": "onEscape"; "onDataAdded": "onDataAdded"; "onDataRemoved": "onDataRemoved"; }, never, ["*"], false, never>; } declare class ModalInstance { id: string; modal: NtkSmartModalComponent; } declare class NtkSmartModalStackService { private modalStack; constructor(); /** * Add a new modal instance. This step is essential and allows to retrieve any modal at any time. * It stores an object that contains the given modal identifier and the modal itself directly in the `modalStack`. * * @param modalInstance The object that contains the given modal identifier and the modal itself. * @param force Optional parameter that forces the overriding of modal instance if it already exists. * @returns nothing special. */ addModal(modalInstance: ModalInstance, force?: boolean): void; /** * Retrieve a modal instance by its identifier. * * @param id The modal identifier used at creation time. */ getModal(id: string): NtkSmartModalComponent; /** * Retrieve all the created modals. * * @returns an array that contains all modal instances. */ getModalStack(): ModalInstance[]; /** * Retrieve all the opened modals. It looks for all modal instances with their `visible` property set to `true`. * * @returns an array that contains all the opened modals. */ getOpenedModals(): ModalInstance[]; /** * Retrieve the opened modal with highest z-index. * * @returns the opened modal with highest z-index. */ getTopOpenedModal(): NtkSmartModalComponent; /** * Get the higher `z-index` value between all the modal instances. It iterates over the `ModalStack` array and * calculates a higher value (it takes the highest index value between all the modal instances and adds 1). * Use it to make a modal appear foreground. * * @returns a higher index from all the existing modal instances. */ getHigherIndex(): number; /** * It gives the number of modal instances. It's helpful to know if the modal stack is empty or not. * * @returns the number of modal instances. */ getModalStackCount(): number; /** * Remove a modal instance from the modal stack. * * @param id The modal identifier. * @returns the removed modal instance. */ removeModal(id: string): void; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartModalStackService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NtkSmartModalStackService>; } interface INtkSmartModalOptions { closable?: boolean; escapable?: boolean; dismissable?: boolean; customClass?: string; backdrop?: boolean; force?: boolean; hideDelay?: number; autostart?: boolean; target?: string; ariaLabel?: string; ariaLabelledBy?: string; ariaDescribedBy?: string; refocus?: boolean; } type Content<T> = string | TemplateRef<T> | Type<T>; declare class NtkSmartModalService { private _componentFactoryResolver; private _appRef; private _injector; private _modalStack; private applicationRef; private _document; private _platformId; private lastElementFocused; constructor(_componentFactoryResolver: ComponentFactoryResolver, _appRef: ApplicationRef, _injector: Injector, _modalStack: NtkSmartModalStackService, applicationRef: ApplicationRef, _document: any, _platformId: any); /** * Add a new modal instance. This step is essential and allows to retrieve any modal at any time. * It stores an object that contains the given modal identifier and the modal itself directly in the `modalStack`. * * @param modalInstance The object that contains the given modal identifier and the modal itself. * @param force Optional parameter that forces the overriding of modal instance if it already exists. * @returns nothing special. */ addModal(modalInstance: ModalInstance, force?: boolean): void; /** * Retrieve a modal instance by its identifier. * * @param id The modal identifier used at creation time. */ getModal(id: string): NtkSmartModalComponent; /** * Alias of `getModal` to retrieve a modal instance by its identifier. * * @param id The modal identifier used at creation time. */ get(id: string): NtkSmartModalComponent; /** * Open a given modal * * @param id The modal identifier used at creation time. * @param force Tell the modal to open top of all other opened modals */ open(id: string, force?: boolean): boolean; /** * Close a given modal * * @param id The modal identifier used at creation time. */ close(id: string): boolean; /** * Close all opened modals */ closeAll(): void; /** * Toggles a given modal * If the retrieved modal is opened it closes it, else it opens it. * * @param id The modal identifier used at creation time. * @param force Tell the modal to open top of all other opened modals */ toggle(id: string, force?: boolean): boolean; /** * Retrieve all the created modals. * * @returns an array that contains all modal instances. */ getModalStack(): ModalInstance[]; /** * Retrieve all the opened modals. It looks for all modal instances with their `visible` property set to `true`. * * @returns an array that contains all the opened modals. */ getOpenedModals(): ModalInstance[]; /** * Retrieve the opened modal with highest z-index. * * @returns the opened modal with highest z-index. */ getTopOpenedModal(): NtkSmartModalComponent; /** * Get the higher `z-index` value between all the modal instances. It iterates over the `ModalStack` array and * calculates a higher value (it takes the highest index value between all the modal instances and adds 1). * Use it to make a modal appear foreground. * * @returns a higher index from all the existing modal instances. */ getHigherIndex(): number; /** * It gives the number of modal instances. It's helpful to know if the modal stack is empty or not. * * @returns the number of modal instances. */ getModalStackCount(): number; /** * Remove a modal instance from the modal stack. * * @param id The modal identifier. * @returns the removed modal instance. */ removeModal(id: string): void; /** * Associate data to an identified modal. If the modal isn't already associated to some data, it creates a new * entry in the `modalData` array with its `id` and the given `data`. If the modal already has data, it rewrites * them with the new ones. Finally if no modal found it returns an error message in the console and false value * as method output. * * @param data The data you want to associate to the modal. * @param id The modal identifier. * @param force If true, overrides the previous stored data if there was. * @returns true if the given modal exists and the process has been tried, either false. */ setModalData(data: any, id: string, force?: boolean): boolean; /** * Retrieve modal data by its identifier. * * @param id The modal identifier used at creation time. * @returns the associated modal data. */ getModalData(id: string): any; /** * Reset the data attached to a given modal. * * @param id The modal identifier used at creation time. * @returns the removed data or false if modal doesn't exist. */ resetModalData(id: string): any | boolean; /** * Close the latest opened modal if it has been declared as escapable * Using a debounce system because one or more modals could be listening * escape key press event. */ closeLatestModal(): void; /** * Create dynamic NtkSmartModalComponent * @param id The modal identifier used at creation time. * @param content The modal content ( string, templateRef or Component ) */ create<T>(id: string, content: Content<T>, options?: INtkSmartModalOptions): NtkSmartModalComponent; private _addEvents; private _initModal; private _openModal; private _toggleModal; private _closeModal; private _dismissModal; private _deleteModal; /** * Resolve content according to the types * @param content The modal content ( string, templateRef or Component ) */ private _resolveNgContent; /** * Close the latest opened modal if escape key event is emitted * @param event The Keyboard Event */ private _escapeKeyboardEvent; /** * Is current platform browser */ private get isBrowser(); /** * While modal is open, the focus stay on it * @param event The Keyboar dEvent */ private _trapFocusModal; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartModalService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NtkSmartModalService>; } declare class NtkSmartModalModule { /** * Use in AppModule: new instance of NtkSmartModal. */ static forRoot(): ModuleWithProviders<NtkSmartModalModule>; /** * Use in features modules with lazy loading: new instance of NtkSmartModal. */ static forChild(): ModuleWithProviders<NtkSmartModalModule>; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartModalModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<NtkSmartModalModule, [typeof NtkSmartModalComponent], [typeof i2.CommonModule], [typeof NtkSmartModalComponent]>; static ɵinj: i0.ɵɵInjectorDeclaration<NtkSmartModalModule>; } declare class NtkSmartLoaderComponent implements OnInit, OnDestroy { ntkSmartLoaderService: NtkSmartLoaderService; private changeDetectorRef; identifier: string; customClass: string; force: boolean; delayIn: number; delayOut: number; autostart: boolean; onStart: EventEmitter<NtkSmartLoaderComponent>; onStop: EventEmitter<NtkSmartLoaderComponent>; onVisibleChange: EventEmitter<NtkSmartLoaderComponent>; loading: boolean; visible: boolean; layerPosition: number; private privateDebouncer; private privateIsProcessing; private privateLoaderBodyClass; private privateEnterClass; private privateLeaveClass; constructor(ntkSmartLoaderService: NtkSmartLoaderService, changeDetectorRef: ChangeDetectorRef); ngOnInit(): void; ngOnDestroy(): void; start(top?: boolean): void; stop(): void; addCustomClass(className: string): void; removeCustomClass(className?: string): void; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartLoaderComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<NtkSmartLoaderComponent, "ntk-smart-loader", never, { "identifier": { "alias": "identifier"; "required": false; }; "customClass": { "alias": "customClass"; "required": false; }; "force": { "alias": "force"; "required": false; }; "delayIn": { "alias": "delayIn"; "required": false; }; "delayOut": { "alias": "delayOut"; "required": false; }; "autostart": { "alias": "autostart"; "required": false; }; }, { "onStart": "onStart"; "onStop": "onStop"; "onVisibleChange": "onVisibleChange"; }, never, ["*"], false, never>; } declare class LoaderInstance { id: string; component: NtkSmartLoaderComponent; constructor(component: NtkSmartLoaderComponent); } declare class NtkSmartLoaderService { private privateloaderStack; private privateActions; /** * Add a new loader instance. This step is essential and allows to retrieve any loader at any time. * It stores an object that contains the given loader identifier and the loader itself directly in the `loaderStack`. * * @param loaderInstance The object that contains the given loader identifier and the loader itself. * @param force Optional parameter that forces the overriding of loader instance if it already exists. * @returns Returns nothing special. */ addLoader(loaderInstance: LoaderInstance, force?: boolean): void; /** * Remove a loader instance from the loader stack. * * @param id The loader identifier. */ removeLoader(id: string): void; /** * Retrieve all the created loaders. * * @returns Returns an array that contains all loader instances. */ getLoaderStack(): LoaderInstance[]; /** * It gives the number of loader instances. It's helpful to know if the loader stack is empty or not. * * @returns Returns the number of loader instances. */ getLoaderStackCount(): number; /** * Retrieve all the opened loaders. It looks for all loader instances with their `visible` property set to `true`. * * @returns Returns an array that contains all the opened loaders. */ getOpenedLoaders(): LoaderInstance[]; /** * Retrieve all the active loaders. It looks for all loader instances with their `loading` property set to `true`. * * @returns Returns an array that contains all the active loaders. */ getActiveLoaders(): LoaderInstance[]; /** * Get the higher `z-index` value between all the loader instances. It iterates over the `LoaderStack` array and * calculates a higher value (it takes the highest index value between all the loader instances and adds 1). * Use it to make a loader appear foreground. * * @returns Returns a higher index from all the existing loader instances. */ getHigherIndex(): number; /** * Enable loading state to one or several loaders. * * @param id The loader identifier. */ start(id: string | string[]): void; /** * Enable loading state to all loaders. */ startAll(): void; /** * Disable loading state to one or several loaders. * * @param id The loader identifier. */ stop(id: string | string[]): void; /** * Disable loading state to all loaders. */ stopAll(): void; isLoading(id: string | string[]): boolean; /** * Execute an action on loaders * * @param id The loader identifier. * @param action Name of the action. */ executeAction(id: string, action: string): void; /** * Retrieve a loader instance by its identifier. * If there's several loaders with same identifier, the first is returned. * * @param id The loader identifier used at creation time. */ private _getLoader; /** * Adds an action on one or more loaders * * @param id The loader identifier. * @param action Name of the action. */ private _addAction; /** * Remove an action on one or more loaders * * @param id The loader identifier. * @param action Name of the action. */ private _removeAction; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartLoaderService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NtkSmartLoaderService>; } declare class NtkSmartLoaderModule { /** * Use in AppModule: new instance of NtkSmartLoader. */ static forRoot(): ModuleWithProviders<NtkSmartLoaderModule>; /** * Use in features modules with lazy loading: new instance of NtkSmartLoader. */ static forChild(): ModuleWithProviders<NtkSmartLoaderModule>; static ɵfac: i0.ɵɵFactoryDeclaration<NtkSmartLoaderModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<NtkSmartLoaderModule, [typeof NtkSmartLoaderComponent], [typeof i2.CommonModule], [typeof NtkSmartLoaderComponent]>; static ɵinj: i0.ɵɵInjectorDeclaration<NtkSmartLoaderModule>; } export { NtkSmartLoaderComponent, NtkSmartLoaderModule, NtkSmartLoaderService, NtkSmartModalComponent, NtkSmartModalModule, NtkSmartModalService, NtkSmartModalStackService };