turbogui-angular
Version:
A library that tries to help with the most common user interface elements on several frameworks and platforms
496 lines • 25.5 kB
TypeScript
import { Type, Injector, ApplicationRef, RendererFactory2, ViewContainerRef, EnvironmentInjector } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { BusyStateBaseComponent } from '../view/components/busy-state-base/busy-state-base.component';
import { DialogBaseComponent } from '../view/components/dialog-base/dialog-base.component';
import { DialogErrorComponent } from '../view/components/dialog-error/dialog-error.component';
import { SingletoneStrictClass } from '../model/classes/SingletoneStrictClass';
import { DialogSingleOptionComponent } from '../view/components/dialog-single-option/dialog-single-option.component';
import * as i0 from "@angular/core";
/**
* Defines a File object that may contain its data loaded.
*/
export interface FileWithData extends File {
data?: any;
}
/**
* Manages the application modal and non modal floating elements
*/
export declare class DialogService extends SingletoneStrictClass {
private readonly matSnackBar;
private readonly matDialog;
private readonly injector;
private readonly applicationRef;
private readonly environmentInjector;
/**
* Used to modify the busy state component that is shown by default by the addModalBusyState() method.
*
* @see this.addModalBusyState()
*/
customBusyStateComponentClass: Type<BusyStateBaseComponent>;
/**
* Check public getter for docs
*/
private _isEnabled;
/**
* Tells if the main application is currently showing a busy state that blocks all user interaction
*/
private _isShowingBusyState;
/**
* A reference to the modal busy state component that is initialized only the first time it is called.
*
* (To append the busy state dynamically, we use the Portal concept from the angular material library)
*/
private _componentPortal;
/**
* A reference to the modal busy state container where the component will be added
*/
private _modalBusyStateHost;
/**
* Used to store the previous document body overflow values when scroll locks are added
*/
private readonly _scrollLockSavedOverflowStates;
/**
* Tells if the manager is currently showing a snackbar element or not
*/
private _isShowingSnackBar;
/**
* Contains a list of the dialogs (MODAL AND NON MODAL) that are currently visible to the user.
* Each item in this list is a hash that is computed when dialog is created to uniquely identify it.
*
* Empty list means no dialogs are currently visible
*/
private _activeDialogs;
/**
* Contains a list with all the MatDialog instances that are currently visible to the user.
* The list uses the same order as the list of _activeDialogs hash values
*/
private _activeDialogInstances;
/**
* Counts the number of dialogs that are currently open and that can be closed by the user by navigating with the browser
*/
private _activeCloseableDialogs;
/**
* Used to store the initialized Renderer 2 instance that is used by this class
*/
private readonly _renderer;
/**
* Method that is used to delete the window beforeunload event listener once not used anymore
*/
private _windowBeforeUnloadUnListen;
/**
* Method that is used to delete the document keydown event listener once not used anymore
*/
private _documentKeydownUnlisten;
/**
* Method that is used to delete the document mousedown event listener once not used anymore
*/
private _documentMousedownUnlisten;
/**
* Method that is used to delete the document pointerdown event listener once not used anymore
*/
private _documentPointerdownUnlisten;
constructor(rendererFactory: RendererFactory2, matSnackBar: MatSnackBar, matDialog: MatDialog, injector: Injector, applicationRef: ApplicationRef, environmentInjector: EnvironmentInjector);
/**
* Tells if this dialog service is enabled or not. If dialog service is disabled, none of it's features will work
* This is used to block all dialog features normally when shutting down the application
*
* Use with caution. When this is set to false, dialog service stops working.
*/
set isEnabled(v: boolean);
/**
* Enables a warning that will be shown to the user when he/she tries to close the application.
* This warning will prompt the user to continue with the exit process or cancel it.
* The specific texts of this message are a generic ones and cannot be changed.
*
* IMPORTANT: This method must be called after the main application has been initialized in order to work,
* otherwise it will do nothing.
*/
addCloseApplicationWarning(): void;
/**
* Remove the close application warning message if previously assigned
*/
removeCloseApplicationWarning(): void;
/**
* Disable application scroll by setting document body overflow to hidden.
* Each call to this method must be matched with a call to removeScrollLock() to restore it back to previous state.
* If multiple calls to addScrollLock() are done, multiple calls to removeScrollLock() will be required to restore
* the original scroll state.
*/
addScrollLock(): void;
/**
* Restore application scroll by restoring document body overflow to the value it had before
* the last call to addScrollLock().
* Each call to this method will restore one level of scroll lock. If multiple calls to addScrollLock()
* were done, multiple calls to removeScrollLock() will be required to restore the original scroll state.
*/
removeScrollLock(): void;
/**
* Change the application visual appearance so the user perceives that the application is
* currently busy. While modal busy state is enabled, no user input is possible neither via
* keyboard, mouse or touch. Use this state when performing server requests or operations that
* must block the user interaction with the application. To allow user interaction again, you must
* call removeModalBusyState()
*
* Notice: We can modify the busy state visual component that is shown by this method. To do it, we must
* set this.customBusyStateComponentClass property with our own custom busy state component class. (We can do it at
* our main application component constructor for example). Our custom component must extend the
* BusyStateBaseComponent one to add its own visual appearance.
*
* @see this.customBusyStateComponentClass
*/
addModalBusyState(): void;
/**
* Tells if the application is currently locked in a modal busy state (caused by an addModalBusyState() call)
*/
get isShowingBusyState(): boolean;
/**
* Cancel the application busy state and restore it back to normal so user interaction is allowed again
*/
removeModalBusyState(): void;
/**
* TODO - adapt from TS version
*/
addToolTip(): void;
/**
* Show a non modal snackbar notification to the user (Only one snack-bar can ever be opened at the same time).
*
* Snackbars inform users of a process that an app has performed or will perform. They appear temporarily, towards the bottom or top of the screen.
* They shouldn’t interrupt the user experience, and they don’t require user input to disappear.
*
* @param config A MatSnackBarConfig instance with the customizations we want for this snackbar
* @param message The message to show on the snackbar
* @param action If not empty, the text to place on the snackbar confirmation button
* @param actionCallback A method to execute once the user clicks into the action button.
*
* @return A promise that will be resolved once the snackbar is closed.
*/
addSnackBar(config: MatSnackBarConfig, message: string, action?: string): Promise<unknown>;
/**
* Tells if the application is currently showing a snackbar or not
*/
get isShowingSnackBar(): boolean;
/**
* Force the removal of the snack bar dialog if it exists.
*
* If no snackbar is currently visible, this method will do nothing
*/
removeSnackBar(): void;
/**
* Show a dialog with one or more options that can be used to close it. We can use any of the predefined dialog types that are bundled with
* this library or extend DialogBaseComponent to create our own custom ones.
*
* @param dialogComponentClass A class for a component that extends DialogBaseComponent, which will be the dialog that is shown to the user.
* @param properties An object containing the different visual and textual options that this dialog allows.
* IMPORTANT: texts, options and data values need to be read at the dialog component by declaring "@Inject(MAT_DIALOG_DATA) public data: any"
* at the dialog component constructor. This data object will contain the texts, options and data properties
*
* - id: The html unique identifier that the dialog will have once created. If not specified, no id will be explicitly set
* - width: 50% by default. Specify the css value for the default dialog width. As the dialog is responsive, the value will be automatically
* reduced if the available screen is not enough, and will reach the desired value otherwise. We can set any css unit like pixels,
* %, vh, vw, or any other. For example: '400px', '50%', etc.
* - maxWidth: Defines the maximum width that the dialog will have. We can specify it in % or vw, just like is done in
* css. By default it is defined as 96vw, which will fit 96% of the viewport on small devices
* - height: Unset by default. Specify the css value for the dialog height.
* - maxHeight: Defines the maximum height that the dialog will have. We can specify it in % or vh, just like is done in
* css. By default it is defined as 96vh, which will fit 96% of the viewport
* - scrollLock: (False by default) disables the background scroll to prevent the user from scrolling the document body when the dialog is visible
* - modal: (False default) if the dialog can be closed without interaction or true if selecting an option is mandatory to close it
* by the user clicking outside it
* - closeOnNavigation: Tells if the dialog should be closed when the user navigates with the browser. By default is true for non modal and false for modal dialogs.
* - texts: A list with strings containing the dialog texts, sorted by importance. When dialog has a title, this should
* be placed first, subtitle second and so (Each dialog may accept a different custom number of texts).
* (add "@Inject(MAT_DIALOG_DATA) public data: any" to dialog constructor and read it with data.texts)
* - options: A list of strings that will be used as button captions for each one of the accepted dialog options
* (add "@Inject(MAT_DIALOG_DATA) public data: any" to dialog constructor and read it with data.options)
* - data: An object to pass any extra data we want to the dialog.
* (add "@Inject(MAT_DIALOG_DATA) public data: any" to dialog constructor and read it with data.data)
* - viewContainerRef: This is important if we want to propagate providers from a parent component to this dialog. We must specify
* this reference to make sure the same services injected on the parent are available too at the child dialog
*
* @return A promise that will be resolved once the dialog is closed.
* The promise will receive a selection object with two properties which will correspond to the index and value from the options
* array that's selected by the user. If no option selected, index will be -1 and value null
*/
addDialog(dialogComponentClass: Type<DialogBaseComponent>, properties: {
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
closeOnNavigation?: boolean;
texts?: string[];
options?: string[];
data?: any;
viewContainerRef?: ViewContainerRef;
}): Promise<{
index: number;
value?: any;
}>;
/**
* Shows a native OS file browser dialog to let the user select a single file from their local file system.
*
* @param options An object containing options for the file browser dialog:
* - accept: A string that defines the file types the file input should accept. For example: '.csv,.xlsx', 'image/*', '.pdf', 'image/jpeg, image/png'.
* - maxFileSize: (Optional) The maximum file size in bytes allowed for the selected file. If the selected file exceeds this size, the promise will be rejected with an error
* - loadData: (Optional) Defines how the file content should be read and returned.
* 'no' (default): Returns the raw File object without its data.
* 'ArrayBuffer': Returns the File object with its content read as a raw binary `ArrayBuffer` in the `data` property.
* 'text': Returns the File object with its content read as a text string in the `data` property.
* 'base64': Returns the File object with its content read as a Base64 encoded string in the `data` property.
*
* @returns A Promise that resolves with the selected `File` object (which may have an added `data` property), or `null` if the user cancels the dialog.
* The promise will be rejected with an Error if the selected file exceeds the specified size limits.
*/
addFileBrowserDialog(options: {
accept: string;
maxFileSize?: number;
loadData?: 'no' | 'ArrayBuffer' | 'text' | 'base64';
}): Promise<FileWithData | null>;
/**
* Shows a native OS file browser dialog to let the user select one or more files from their local file system.
*
* @param options An object containing options for the file browser dialog:
* - accept: A string that defines the file types the file input should accept. For example: '.csv,.xlsx', 'image/*', '.pdf', 'image/jpeg, image/png'.
* - maxFileSize: (Optional) The maximum file size in bytes allowed for any single selected file. If a selected file exceeds this size, the promise will be rejected with an error.
* - maxTotalSize: (Optional) The maximum total size in bytes for all selected files combined. If the total size of all files exceeds this limit, the promise will be rejected with an error.
* - loadData: (Optional) Defines how the file content should be read and returned.
* 'no' (default): Returns an array of `File` objects without their data.
* 'ArrayBuffer': Returns an array of `File` objects, each with its content read as a raw binary `ArrayBuffer` in the `data` property.
* 'text': Returns an array of `File` objects, each with its content read as a text string in the `data` property.
* 'base64': Returns an array of `File` objects, each with its content read as a Base64 encoded string in the `data` property.
*
* @returns A Promise that resolves with an array of `File` objects (which may have an added `data` property), or `null` if the user cancels the dialog.
* The promise will be rejected with an Error if the selected files exceed the specified size limits.
*/
addFilesBrowserDialog(options: {
accept: string;
maxFileSize?: number;
maxTotalSize?: number;
loadData?: 'no' | 'ArrayBuffer' | 'text' | 'base64';
}): Promise<FileWithData[] | null>;
/**
* Auxiliary method that combines the logic for addFileBrowserDialog and addFilesBrowserDialog
*/
private _addFileBrowserDialogInternal;
/**
* Show a native OS file download dialog to let the user download a file from a provided binary blob data.
*
* @param blob The binary data containing the file to download. It must be a Blob object
* @param fileName The file name to be shown in the download dialog
*
* @returns void
*/
addFileDownloadBlobDialog(blob: Blob, fileName: string): void;
/**
* Show a dialog with an iframe inside it, to show external web pages or web applications.
*
* This method is a shortcut for addDialog() method using DialogIFrameComponent as the dialog component class
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - url (mandatory): The url to load in the iframe
* - title: The title to show at the top of the dialog
* - id: see addDialog() docs
* - width: see addDialog() docs
* - maxWidth: see addDialog() docs
* - height: see addDialog() docs
* - maxHeight: see addDialog() docs
* - scrollLock: addDialog() docs
* - modal: see addDialog() docs
*
* @returns A Promise that resolves once the user closes the dialog
*/
addIFrameDialog(properties: {
url: string;
title?: string;
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
}): Promise<null>;
/**
* Show a dialog with an image inside it, to load image files from a url.
*
* This method is a shortcut for addDialog() method using DialogImageComponent as the dialog component class
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - url (mandatory): The url to load in the image
* - title: The title to show at the top of the dialog
* - id: see addDialog() docs
* - width: see addDialog() docs
* - maxWidth: see addDialog() docs
* - height: see addDialog() docs
* - maxHeight: see addDialog() docs
* - scrollLock: addDialog() docs
* - modal: see addDialog() docs
*
* @returns A Promise that resolves once the user closes the dialog
*/
addImageDialog(properties: {
url: string;
title?: string;
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
}): Promise<null>;
/**
* Show a dialog with a pdf from a binary blob data.
*
* This method is a shortcut for addDialog() method using DialogBlobComponent as the dialog component class, using the received blob
* data with a mime type of 'application/pdf'
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - blob (mandatory): The binary data containing the pdf file to show. It can be a Blob, an ArrayBuffer or a raw binary string
* - title: The title to show at the top of the dialog
* - id: see addDialog() docs
* - width: see addDialog() docs
* - maxWidth: see addDialog() docs
* - height: see addDialog() docs
* - maxHeight: see addDialog() docs
* - scrollLock: addDialog() docs
* - modal: see addDialog() docs
*
* @returns A Promise that resolves once the user closes the dialog
*/
addPdfDialog(properties: {
blob: any;
title?: string;
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
}): Promise<null>;
/**
* Show a dialog with a calendar to let the user pick a date.
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - id: see addDialog() docs
* - width: see addDialog() docs
* - maxWidth: see addDialog() docs
* - height: see addDialog() docs
* - maxHeight: see addDialog() docs
* - scrollLock: addDialog() docs
* - modal: see addDialog() docs
* - title: The title to show at the top of the dialog
* - viewContainerRef: MANDATORY! or the component won't render. see addDialog() docs
*
* @returns A Promise that resolves to a Date() object selected by the user or null if no selection was made
*/
addDateSelectionDialog(properties: {
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
title?: string;
viewContainerRef: ViewContainerRef;
}): Promise<Date | null>;
/**
* Show a dialog with an error message and a single option button to close it.
*
* This method is a shortcut for addDialog() method using DialogErrorComponent as the dialog component class
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - title (mandatory): The dialog title
* - option (mandatory): The text to place on the single option button
* - description: An optional description text to show below the title
* - id: see addDialog() docs
* - width: see addDialog() docs
* - maxWidth: see addDialog() docs
* - height: see addDialog() docs
* - maxHeight: see addDialog() docs
* - scrollLock: addDialog() docs
* - modal: see addDialog() docs
* - dialogClass: A custom component class to use instead of the default DialogErrorComponent.
* This custom class must extend DialogErrorComponent
*
* @returns A Promise that resolves once the user selects the button with the option caption
*/
addErrorDialog(properties: {
title: string;
option: string;
description?: string;
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
dialogClass?: Type<DialogErrorComponent>;
}): Promise<null>;
/**
* Show a dialog with a message and a single option button to close it.
*
* This method is a shortcut for addDialog() method using DialogSingleOptionComponent as the dialog component class
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - title (mandatory): The dialog title
* - option (mandatory): The text to place on the single option button
* - description: An optional description text to show below the title
* - id: see addDialog() docs
* - width: see addDialog() docs
* - maxWidth: see addDialog() docs
* - height: see addDialog() docs
* - maxHeight: see addDialog() docs
* - scrollLock: addDialog() docs
* - modal: see addDialog() docs
* - dialogClass: A custom component class to use instead of the default DialogSingleOptionComponent.
* This custom class must extend DialogSingleOptionComponent
*
* @returns A Promise that resolves once the user selects the button with the option caption
*/
addMessageDialog(properties: {
title: string;
option: string;
description?: string;
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
scrollLock?: boolean;
modal?: boolean;
dialogClass?: Type<DialogSingleOptionComponent>;
}): Promise<null>;
/**
* Force the removal of all the dialogs that are currently visible.
*
* If no dialogs are currently visible, this method will do nothing
*/
removeAllDialogs(): void;
/**
* TODO - translate from TS version
*/
/**
* TODO - translate from TS version
*/
/**
* TODO - translate from TS version
*/
/**
* Block all the user interactions with the application (keyboard, touch, mouse, ...)
*/
private _disableUserInteraction;
/**
* Restore the user interactions that were previously disabled with _disableUserInteraction method
*/
private _enableUserInteraction;
static ɵfac: i0.ɵɵFactoryDeclaration<DialogService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DialogService>;
}
//# sourceMappingURL=dialog.service.d.ts.map