@covalent/core
Version:
Core Teradata UI Platform for layouts, icons, custom components and themes. This should be added as a dependency for any project that wants to use layouts, icons and themes for Angular Material.
668 lines (657 loc) • 46.3 kB
JavaScript
import * as i0 from '@angular/core';
import { Directive, Component, ContentChildren, ElementRef, ViewChild, Injectable, Inject, EventEmitter, ChangeDetectionStrategy, Input, Output, NgModule } from '@angular/core';
import * as i4 from '@angular/common';
import { DOCUMENT, CommonModule } from '@angular/common';
import * as i6 from '@angular/forms';
import { FormsModule } from '@angular/forms';
import * as i1 from '@angular/material/dialog';
import { MatDialogConfig, MatDialogModule } from '@angular/material/dialog';
import * as i7 from '@angular/material/input';
import { MatInputModule } from '@angular/material/input';
import * as i3 from '@angular/material/button';
import { MatButtonModule } from '@angular/material/button';
import { RIGHT_ARROW, LEFT_ARROW } from '@angular/cdk/keycodes';
import { Subject, fromEvent, takeUntil, merge } from 'rxjs';
import * as i3$1 from '@angular/material/form-field';
import * as i2 from '@angular/cdk/drag-drop';
import * as i1$1 from '@angular/material/toolbar';
import { MatToolbarModule } from '@angular/material/toolbar';
import * as i3$2 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i4$1 from '@angular/material/tooltip';
import { MatTooltipModule } from '@angular/material/tooltip';
class TdDialogTitleDirective {
}
TdDialogTitleDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogTitleDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
TdDialogTitleDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.2", type: TdDialogTitleDirective, selector: "[tdDialogTitle]", ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogTitleDirective, decorators: [{
type: Directive,
args: [{ selector: '[tdDialogTitle]' }]
}] });
class TdDialogContentDirective {
}
TdDialogContentDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogContentDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
TdDialogContentDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.2", type: TdDialogContentDirective, selector: "[tdDialogContent]", ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogContentDirective, decorators: [{
type: Directive,
args: [{ selector: '[tdDialogContent]' }]
}] });
class TdDialogActionsDirective {
}
TdDialogActionsDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogActionsDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
TdDialogActionsDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.2", type: TdDialogActionsDirective, selector: "[tdDialogActions]", ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogActionsDirective, decorators: [{
type: Directive,
args: [{ selector: '[tdDialogActions]' }]
}] });
class TdDialogComponent {
ngAfterContentInit() {
if (this.dialogTitle.length > 1) {
throw new Error('Duplicate td-dialog-title component at in td-dialog.');
}
if (this.dialogContent.length > 1) {
throw new Error('Duplicate td-dialog-content component at in td-dialog.');
}
if (this.dialogActions.length > 1) {
throw new Error('Duplicate td-dialog-actions component at in td-dialog.');
}
}
}
TdDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
TdDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: TdDialogComponent, selector: "td-dialog", queries: [{ propertyName: "dialogTitle", predicate: TdDialogTitleDirective, descendants: true }, { propertyName: "dialogContent", predicate: TdDialogContentDirective, descendants: true }, { propertyName: "dialogActions", predicate: TdDialogActionsDirective, descendants: true }], ngImport: i0, template: "<div class=\"td-dialog-wrapper\">\n <h3 class=\"td-dialog-title\" *ngIf=\"dialogTitle.length > 0\">\n <ng-content select=\"[tdDialogTitle]\"></ng-content>\n </h3>\n <div class=\"td-dialog-content\" *ngIf=\"dialogContent.length > 0\">\n <ng-content select=\"[tdDialogContent]\"></ng-content>\n </div>\n <div class=\"td-dialog-actions\" *ngIf=\"dialogActions.length > 0\">\n <span class=\"td-dialog-spacer\"></span>\n <ng-content select=\"[tdDialogActions]\"></ng-content>\n </div>\n</div>\n", styles: [".td-dialog-title{margin-top:0;margin-bottom:20px}.td-dialog-content{margin-bottom:16px}.td-dialog-actions{position:relative;top:16px;left:16px}::ng-deep [dir=rtl] .td-dialog-actions{right:16px;left:auto}:host{display:block}:host .td-dialog-actions{flex-direction:row;box-sizing:border-box;display:flex}:host .td-dialog-actions .td-dialog-spacer{flex:1}:host .td-dialog-actions ::ng-deep button{text-transform:uppercase;margin-left:8px;padding-left:8px;padding-right:8px;min-width:64px}[dir=rtl] :host .td-dialog-actions ::ng-deep button{margin-right:8px;margin-left:inherit}\n"], directives: [{ type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'td-dialog', template: "<div class=\"td-dialog-wrapper\">\n <h3 class=\"td-dialog-title\" *ngIf=\"dialogTitle.length > 0\">\n <ng-content select=\"[tdDialogTitle]\"></ng-content>\n </h3>\n <div class=\"td-dialog-content\" *ngIf=\"dialogContent.length > 0\">\n <ng-content select=\"[tdDialogContent]\"></ng-content>\n </div>\n <div class=\"td-dialog-actions\" *ngIf=\"dialogActions.length > 0\">\n <span class=\"td-dialog-spacer\"></span>\n <ng-content select=\"[tdDialogActions]\"></ng-content>\n </div>\n</div>\n", styles: [".td-dialog-title{margin-top:0;margin-bottom:20px}.td-dialog-content{margin-bottom:16px}.td-dialog-actions{position:relative;top:16px;left:16px}::ng-deep [dir=rtl] .td-dialog-actions{right:16px;left:auto}:host{display:block}:host .td-dialog-actions{flex-direction:row;box-sizing:border-box;display:flex}:host .td-dialog-actions .td-dialog-spacer{flex:1}:host .td-dialog-actions ::ng-deep button{text-transform:uppercase;margin-left:8px;padding-left:8px;padding-right:8px;min-width:64px}[dir=rtl] :host .td-dialog-actions ::ng-deep button{margin-right:8px;margin-left:inherit}\n"] }]
}], propDecorators: { dialogTitle: [{
type: ContentChildren,
args: [TdDialogTitleDirective, { descendants: true }]
}], dialogContent: [{
type: ContentChildren,
args: [TdDialogContentDirective, { descendants: true }]
}], dialogActions: [{
type: ContentChildren,
args: [TdDialogActionsDirective, { descendants: true }]
}] } });
class TdAlertDialogComponent {
constructor(_dialogRef) {
this._dialogRef = _dialogRef;
this.closeButton = 'CLOSE';
}
close() {
this._dialogRef.close();
}
}
TdAlertDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdAlertDialogComponent, deps: [{ token: i1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
TdAlertDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: TdAlertDialogComponent, selector: "td-alert-dialog", ngImport: i0, template: "<td-dialog>\n <div tdDialogTitle *ngIf=\"title\">\n {{ title }}\n </div>\n <div tdDialogContent>\n <span class=\"td-dialog-message\">{{ message }}</span>\n </div>\n <div tdDialogActions>\n <button mat-button color=\"accent\" (click)=\"close()\">\n {{ closeButton }}\n </button>\n </div>\n</td-dialog>\n", styles: [".td-dialog-message{word-break:break-word}\n"], components: [{ type: TdDialogComponent, selector: "td-dialog" }, { type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: TdDialogTitleDirective, selector: "[tdDialogTitle]" }, { type: TdDialogContentDirective, selector: "[tdDialogContent]" }, { type: TdDialogActionsDirective, selector: "[tdDialogActions]" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdAlertDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'td-alert-dialog', template: "<td-dialog>\n <div tdDialogTitle *ngIf=\"title\">\n {{ title }}\n </div>\n <div tdDialogContent>\n <span class=\"td-dialog-message\">{{ message }}</span>\n </div>\n <div tdDialogActions>\n <button mat-button color=\"accent\" (click)=\"close()\">\n {{ closeButton }}\n </button>\n </div>\n</td-dialog>\n", styles: [".td-dialog-message{word-break:break-word}\n"] }]
}], ctorParameters: function () { return [{ type: i1.MatDialogRef }]; } });
class TdConfirmDialogComponent {
constructor(_dialogRef) {
this._dialogRef = _dialogRef;
this.cancelButton = 'CANCEL';
this.acceptButton = 'ACCEPT';
this.isDestructive = false;
}
cancel() {
this._dialogRef.close(false);
}
accept() {
this._dialogRef.close(true);
}
}
TdConfirmDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdConfirmDialogComponent, deps: [{ token: i1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
TdConfirmDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: TdConfirmDialogComponent, selector: "td-confirm-dialog", ngImport: i0, template: "<td-dialog>\n <div tdDialogTitle *ngIf=\"title\">\n {{ title }}\n </div>\n <div tdDialogContent>\n <span class=\"td-dialog-message\">{{ message }}</span>\n </div>\n <div tdDialogActions>\n <button\n mat-button\n #closeBtn\n (keydown.arrowright)=\"acceptBtn.focus()\"\n (click)=\"cancel()\"\n >\n {{ cancelButton }}\n </button>\n <button\n mat-button\n [color]=\"isDestructive ? 'warn' : 'accent'\"\n #acceptBtn\n (keydown.arrowleft)=\"closeBtn.focus()\"\n (click)=\"accept()\"\n >\n {{ acceptButton }}\n </button>\n </div>\n</td-dialog>\n", styles: [".td-dialog-message{word-break:break-word}\n"], components: [{ type: TdDialogComponent, selector: "td-dialog" }, { type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: TdDialogTitleDirective, selector: "[tdDialogTitle]" }, { type: TdDialogContentDirective, selector: "[tdDialogContent]" }, { type: TdDialogActionsDirective, selector: "[tdDialogActions]" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdConfirmDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'td-confirm-dialog', template: "<td-dialog>\n <div tdDialogTitle *ngIf=\"title\">\n {{ title }}\n </div>\n <div tdDialogContent>\n <span class=\"td-dialog-message\">{{ message }}</span>\n </div>\n <div tdDialogActions>\n <button\n mat-button\n #closeBtn\n (keydown.arrowright)=\"acceptBtn.focus()\"\n (click)=\"cancel()\"\n >\n {{ cancelButton }}\n </button>\n <button\n mat-button\n [color]=\"isDestructive ? 'warn' : 'accent'\"\n #acceptBtn\n (keydown.arrowleft)=\"closeBtn.focus()\"\n (click)=\"accept()\"\n >\n {{ acceptButton }}\n </button>\n </div>\n</td-dialog>\n", styles: [".td-dialog-message{word-break:break-word}\n"] }]
}], ctorParameters: function () { return [{ type: i1.MatDialogRef }]; } });
class TdPromptDialogComponent {
constructor(_ngZone, _dialogRef) {
this._ngZone = _ngZone;
this._dialogRef = _dialogRef;
this.cancelButton = 'CANCEL';
this.acceptButton = 'ACCEPT';
this._destroy$ = new Subject();
}
ngAfterViewInit() {
this._ngZone.runOutsideAngular(() => {
// Note: `element.focus()` causes re-layout and this may lead to frame drop on slower devices.
// `Promise` is a microtask and microtask are executed within the current rendering frame.
// Animation tasks are executed within the next rendering frame.
// We focus input once everything is rendered and good to go.
requestAnimationFrame(() => this._input.nativeElement.focus());
fromEvent(this._input.nativeElement, 'focus')
.pipe(takeUntil(this._destroy$))
.subscribe(() => {
// This is executed when the input is focused, selects all text.
this._input.nativeElement.select();
});
fromEvent(this._closeBtn.nativeElement, 'keydown')
.pipe(takeUntil(this._destroy$))
.subscribe((event) => {
if (event.keyCode === RIGHT_ARROW) {
this._acceptBtn.nativeElement.focus();
}
});
fromEvent(this._acceptBtn.nativeElement, 'keydown')
.pipe(takeUntil(this._destroy$))
.subscribe((event) => {
if (event.keyCode === LEFT_ARROW) {
this._closeBtn.nativeElement.focus();
}
});
});
}
ngOnDestroy() {
this._destroy$.next();
}
cancel() {
this._dialogRef.close();
}
accept() {
this._dialogRef.close(this.value);
}
}
TdPromptDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdPromptDialogComponent, deps: [{ token: i0.NgZone }, { token: i1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
TdPromptDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: TdPromptDialogComponent, selector: "td-prompt-dialog", viewQueries: [{ propertyName: "_input", first: true, predicate: ["input"], descendants: true, static: true }, { propertyName: "_closeBtn", first: true, predicate: ["closeBtn"], descendants: true, read: ElementRef, static: true }, { propertyName: "_acceptBtn", first: true, predicate: ["acceptBtn"], descendants: true, read: ElementRef, static: true }], ngImport: i0, template: "<td-dialog>\n <div tdDialogTitle *ngIf=\"title\">\n {{ title }}\n </div>\n <div tdDialogContent>\n <span class=\"td-dialog-message\">{{ message }}</span>\n <form #form=\"ngForm\" novalidate>\n <div class=\"td-dialog-input-wrapper\">\n <mat-form-field class=\"td-dialog-input\">\n <input\n matInput\n #input\n (keydown.enter)=\"$event.preventDefault(); form.valid && accept()\"\n [(ngModel)]=\"value\"\n name=\"value\"\n required\n />\n </mat-form-field>\n </div>\n </form>\n </div>\n <div tdDialogActions>\n <button mat-button #closeBtn (click)=\"cancel()\">\n {{ cancelButton }}\n </button>\n <button\n mat-button\n color=\"accent\"\n #acceptBtn\n [disabled]=\"!form.valid\"\n (click)=\"accept()\"\n >\n {{ acceptButton }}\n </button>\n </div>\n</td-dialog>\n", styles: [".td-dialog-input-wrapper{flex-direction:row;box-sizing:border-box;display:flex}.td-dialog-input-wrapper .td-dialog-input{flex:1;box-sizing:border-box}.td-dialog-message{word-break:break-word}\n"], components: [{ type: TdDialogComponent, selector: "td-dialog" }, { type: i3$1.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: TdDialogTitleDirective, selector: "[tdDialogTitle]" }, { type: TdDialogContentDirective, selector: "[tdDialogContent]" }, { type: i6.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i6.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i6.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i7.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { type: i6.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i6.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { type: i6.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i6.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: TdDialogActionsDirective, selector: "[tdDialogActions]" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdPromptDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'td-prompt-dialog', template: "<td-dialog>\n <div tdDialogTitle *ngIf=\"title\">\n {{ title }}\n </div>\n <div tdDialogContent>\n <span class=\"td-dialog-message\">{{ message }}</span>\n <form #form=\"ngForm\" novalidate>\n <div class=\"td-dialog-input-wrapper\">\n <mat-form-field class=\"td-dialog-input\">\n <input\n matInput\n #input\n (keydown.enter)=\"$event.preventDefault(); form.valid && accept()\"\n [(ngModel)]=\"value\"\n name=\"value\"\n required\n />\n </mat-form-field>\n </div>\n </form>\n </div>\n <div tdDialogActions>\n <button mat-button #closeBtn (click)=\"cancel()\">\n {{ cancelButton }}\n </button>\n <button\n mat-button\n color=\"accent\"\n #acceptBtn\n [disabled]=\"!form.valid\"\n (click)=\"accept()\"\n >\n {{ acceptButton }}\n </button>\n </div>\n</td-dialog>\n", styles: [".td-dialog-input-wrapper{flex-direction:row;box-sizing:border-box;display:flex}.td-dialog-input-wrapper .td-dialog-input{flex:1;box-sizing:border-box}.td-dialog-message{word-break:break-word}\n"] }]
}], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i1.MatDialogRef }]; }, propDecorators: { _input: [{
type: ViewChild,
args: ['input', { static: true }]
}], _closeBtn: [{
type: ViewChild,
args: ['closeBtn', { static: true, read: ElementRef }]
}], _acceptBtn: [{
type: ViewChild,
args: ['acceptBtn', { static: true, read: ElementRef }]
}] } });
class TdDialogService {
constructor(_document, _dialogService, _dragDrop, rendererFactory) {
this._document = _document;
this._dialogService = _dialogService;
this._dragDrop = _dragDrop;
this.rendererFactory = rendererFactory;
this._renderer2 = rendererFactory.createRenderer(undefined, null);
}
/**
* params:
* - component: ComponentType<T>
* - config: MatDialogConfig
* Wrapper function over the open() method in MatDialog.
* Opens a modal dialog containing the given component.
*/
open(component, config) {
return this._dialogService.open(component, config);
}
/**
* Wrapper function over the closeAll() method in MatDialog.
* Closes all of the currently-open dialogs.
*/
closeAll() {
this._dialogService.closeAll();
}
/**
* params:
* - config: IAlertConfig {
* message: string;
* title?: string;
* viewContainerRef?: ViewContainerRef;
* closeButton?: string;
* }
*
* Opens an alert dialog with the provided config.
* Returns an MatDialogRef<TdAlertDialogComponent> object.
*/
openAlert(config) {
const dialogConfig = this._createConfig(config);
const dialogRef = this._dialogService.open(TdAlertDialogComponent, dialogConfig);
const alertDialogComponent = dialogRef.componentInstance;
alertDialogComponent.title = config.title;
alertDialogComponent.message = config.message;
if (config.closeButton) {
alertDialogComponent.closeButton = config.closeButton;
}
return dialogRef;
}
/**
* params:
* - config: IConfirmConfig {
* message: string;
* title?: string;
* viewContainerRef?: ViewContainerRef;
* acceptButton?: string;
* cancelButton?: string;
* isDestructive?: boolean;
* }
*
* Opens a confirm dialog with the provided config.
* Returns an MatDialogRef<TdConfirmDialogComponent> object.
*/
openConfirm(config) {
const dialogConfig = this._createConfig(config);
const dialogRef = this._dialogService.open(TdConfirmDialogComponent, dialogConfig);
const confirmDialogComponent = dialogRef.componentInstance;
confirmDialogComponent.title = config.title;
confirmDialogComponent.message = config.message;
if (config.acceptButton) {
confirmDialogComponent.acceptButton = config.acceptButton;
}
if (config.isDestructive) {
confirmDialogComponent.isDestructive = config.isDestructive;
}
if (config.cancelButton) {
confirmDialogComponent.cancelButton = config.cancelButton;
}
return dialogRef;
}
/**
* params:
* - config: IPromptConfig {
* message: string;
* title?: string;
* value?: string;
* viewContainerRef?: ViewContainerRef;
* acceptButton?: string;
* cancelButton?: string;
* }
*
* Opens a prompt dialog with the provided config.
* Returns an MatDialogRef<TdPromptDialogComponent> object.
*/
openPrompt(config) {
const dialogConfig = this._createConfig(config);
const dialogRef = this._dialogService.open(TdPromptDialogComponent, dialogConfig);
const promptDialogComponent = dialogRef.componentInstance;
promptDialogComponent.title = config.title;
promptDialogComponent.message = config.message;
promptDialogComponent.value = config.value;
if (config.acceptButton) {
promptDialogComponent.acceptButton = config.acceptButton;
}
if (config.cancelButton) {
promptDialogComponent.cancelButton = config.cancelButton;
}
return dialogRef;
}
/**
* Opens a draggable dialog containing the given component.
*/
openDraggable({ component, config, dragHandleSelectors, draggableClass, }) {
const matDialogRef = this._dialogService.open(component, config);
const dragRefSubject = new Subject();
const CDK_OVERLAY_PANE_SELECTOR = '.cdk-overlay-pane';
const CDK_OVERLAY_CONTAINER_SELECTOR = '.cdk-overlay-container';
matDialogRef.afterOpened().subscribe(() => {
const dialogElement = (this._document.getElementById(matDialogRef.id));
const draggableElement = this._dragDrop.createDrag(dialogElement);
if (draggableClass) {
const childComponent = dialogElement.firstElementChild;
this._renderer2.addClass(childComponent, draggableClass);
}
if (dragHandleSelectors && dragHandleSelectors.length) {
const dragHandles = dragHandleSelectors.reduce((acc, curr) => [
...acc,
...Array.from(dialogElement.querySelectorAll(curr)),
], []);
if (dragHandles.length > 0) {
draggableElement.withHandles(dragHandles);
}
}
const rootElement = dialogElement.closest(CDK_OVERLAY_PANE_SELECTOR);
if (rootElement) {
draggableElement.withRootElement(rootElement);
}
const boundaryElement = dialogElement.closest(CDK_OVERLAY_CONTAINER_SELECTOR);
if (boundaryElement) {
draggableElement.withBoundaryElement(boundaryElement);
}
dragRefSubject.next(draggableElement);
});
return { matDialogRef, dragRefSubject };
}
_createConfig(config) {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '400px';
Object.assign(dialogConfig, config);
return dialogConfig;
}
}
TdDialogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogService, deps: [{ token: DOCUMENT }, { token: i1.MatDialog }, { token: i2.DragDrop }, { token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable });
TdDialogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdDialogService, decorators: [{
type: Injectable
}], ctorParameters: function () {
return [{ type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: i1.MatDialog }, { type: i2.DragDrop }, { type: i0.RendererFactory2 }];
} });
class TdWindowDialogComponent {
constructor() {
this.docked = false;
this.dockToggled = new EventEmitter();
this.closed = new EventEmitter();
this.toolbarHeight = 56;
}
toggleDockedState() {
this.dockToggled.emit(this.docked);
}
}
TdWindowDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdWindowDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
TdWindowDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: TdWindowDialogComponent, selector: "td-window-dialog", inputs: { toolbarColor: "toolbarColor", docked: "docked", title: "title", toggleDockedStateLabel: "toggleDockedStateLabel", closeLabel: "closeLabel" }, outputs: { dockToggled: "dockToggled", closed: "closed" }, ngImport: i0, template: "<mat-toolbar\n [color]=\"toolbarColor\"\n class=\"td-window-dialog-toolbar\"\n [style.min-height.px]=\"toolbarHeight\"\n [style.cursor]=\"docked ? 'inherit' : 'move'\"\n>\n <mat-toolbar-row [style.height.px]=\"toolbarHeight\">\n <div layout=\"row\" layout-align=\"start center\" flex>\n <span class=\"mat-title td-window-dialog-title truncate\" flex>\n {{ title }}\n </span>\n <!-- TODO: Resizing a drag-and-drop element was not working so removed docking/undocking for now-->\n <!-- <button mat-icon-button [matTooltip]=\"toggleDockedStateLabel\" (click)=\"toggleDockedState()\">\n <mat-icon [attr.aria-label]=\"toggleDockedStateLabel\">\n {{ docked ? 'unfold_more' : 'unfold_less' }}\n </mat-icon>\n </button> -->\n\n <button\n mat-icon-button\n [matTooltip]=\"closeLabel ?? ''\"\n (click)=\"closed.emit()\"\n class=\"td-window-dialog-close\"\n [attr.data-test]=\"'close-button'\"\n >\n <mat-icon [attr.aria-label]=\"closeLabel\">close</mat-icon>\n </button>\n </div>\n </mat-toolbar-row>\n</mat-toolbar>\n<ng-content></ng-content>\n", styles: [":host{height:100%;display:flex;flex-direction:column}.truncate{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.td-window-dialog-toolbar{background:none}.td-window-dialog-title{margin-bottom:0}.td-window-dialog-close{margin-right:-8px}::ng-deep .td-window-dialog .mat-dialog-container{padding:0}\n"], components: [{ type: i1$1.MatToolbar, selector: "mat-toolbar", inputs: ["color"], exportAs: ["matToolbar"] }, { type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i3$2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], directives: [{ type: i1$1.MatToolbarRow, selector: "mat-toolbar-row", exportAs: ["matToolbarRow"] }, { type: i4$1.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: TdWindowDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'td-window-dialog', changeDetection: ChangeDetectionStrategy.OnPush, template: "<mat-toolbar\n [color]=\"toolbarColor\"\n class=\"td-window-dialog-toolbar\"\n [style.min-height.px]=\"toolbarHeight\"\n [style.cursor]=\"docked ? 'inherit' : 'move'\"\n>\n <mat-toolbar-row [style.height.px]=\"toolbarHeight\">\n <div layout=\"row\" layout-align=\"start center\" flex>\n <span class=\"mat-title td-window-dialog-title truncate\" flex>\n {{ title }}\n </span>\n <!-- TODO: Resizing a drag-and-drop element was not working so removed docking/undocking for now-->\n <!-- <button mat-icon-button [matTooltip]=\"toggleDockedStateLabel\" (click)=\"toggleDockedState()\">\n <mat-icon [attr.aria-label]=\"toggleDockedStateLabel\">\n {{ docked ? 'unfold_more' : 'unfold_less' }}\n </mat-icon>\n </button> -->\n\n <button\n mat-icon-button\n [matTooltip]=\"closeLabel ?? ''\"\n (click)=\"closed.emit()\"\n class=\"td-window-dialog-close\"\n [attr.data-test]=\"'close-button'\"\n >\n <mat-icon [attr.aria-label]=\"closeLabel\">close</mat-icon>\n </button>\n </div>\n </mat-toolbar-row>\n</mat-toolbar>\n<ng-content></ng-content>\n", styles: [":host{height:100%;display:flex;flex-direction:column}.truncate{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.td-window-dialog-toolbar{background:none}.td-window-dialog-title{margin-bottom:0}.td-window-dialog-close{margin-right:-8px}::ng-deep .td-window-dialog .mat-dialog-container{padding:0}\n"] }]
}], propDecorators: { toolbarColor: [{
type: Input
}], docked: [{
type: Input
}], title: [{
type: Input
}], toggleDockedStateLabel: [{
type: Input
}], closeLabel: [{
type: Input
}], dockToggled: [{
type: Output
}], closed: [{
type: Output
}] } });
const TD_DIALOGS = [
TdAlertDialogComponent,
TdConfirmDialogComponent,
TdPromptDialogComponent,
TdDialogComponent,
TdDialogTitleDirective,
TdDialogActionsDirective,
TdDialogContentDirective,
TdWindowDialogComponent,
TdAlertDialogComponent,
TdConfirmDialogComponent,
TdPromptDialogComponent,
];
class CovalentDialogsModule {
}
CovalentDialogsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: CovalentDialogsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
CovalentDialogsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: CovalentDialogsModule, declarations: [TdAlertDialogComponent,
TdConfirmDialogComponent,
TdPromptDialogComponent,
TdDialogComponent,
TdDialogTitleDirective,
TdDialogActionsDirective,
TdDialogContentDirective,
TdWindowDialogComponent,
TdAlertDialogComponent,
TdConfirmDialogComponent,
TdPromptDialogComponent], imports: [FormsModule,
CommonModule,
MatDialogModule,
MatInputModule,
MatButtonModule,
MatToolbarModule,
MatTooltipModule,
MatIconModule], exports: [TdAlertDialogComponent,
TdConfirmDialogComponent,
TdPromptDialogComponent,
TdDialogComponent,
TdDialogTitleDirective,
TdDialogActionsDirective,
TdDialogContentDirective,
TdWindowDialogComponent,
TdAlertDialogComponent,
TdConfirmDialogComponent,
TdPromptDialogComponent] });
CovalentDialogsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: CovalentDialogsModule, providers: [TdDialogService], imports: [[
FormsModule,
CommonModule,
MatDialogModule,
MatInputModule,
MatButtonModule,
MatToolbarModule,
MatTooltipModule,
MatIconModule,
]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: CovalentDialogsModule, decorators: [{
type: NgModule,
args: [{
imports: [
FormsModule,
CommonModule,
MatDialogModule,
MatInputModule,
MatButtonModule,
MatToolbarModule,
MatTooltipModule,
MatIconModule,
],
declarations: [...TD_DIALOGS],
exports: [...TD_DIALOGS],
providers: [TdDialogService],
}]
}] });
var corners;
(function (corners) {
corners["topRight"] = "topRight";
corners["bottomRight"] = "bottomRight";
corners["bottomLeft"] = "bottomLeft";
corners["topLeft"] = "topLeft";
})(corners || (corners = {}));
var cursors;
(function (cursors) {
cursors["nesw"] = "nesw-resize";
cursors["nwse"] = "nwse-resize";
})(cursors || (cursors = {}));
var verticalAlignment;
(function (verticalAlignment) {
verticalAlignment["top"] = "top";
verticalAlignment["bottom"] = "bottom";
})(verticalAlignment || (verticalAlignment = {}));
var horizontalAlignment;
(function (horizontalAlignment) {
horizontalAlignment["right"] = "right";
horizontalAlignment["left"] = "left";
})(horizontalAlignment || (horizontalAlignment = {}));
const cornerWidth = '16px';
const offset = '0px';
const minWidth = 200;
const minHeight = 200;
function getPixels(sizeString) {
return parseFloat((sizeString || '').replace('px', ''));
}
function clamp(min, num, max) {
return Math.min(Math.max(num, min), max);
}
class ResizableDraggableDialog {
constructor(_document, _renderer2, _dialogRef, _dragRef) {
this._document = _document;
this._renderer2 = _renderer2;
this._dialogRef = _dialogRef;
this._dragRef = _dragRef;
this.cornerElements = [];
this.pointerDownSubs = [];
this._initialPositionReset();
this._attachCorners();
}
attach() {
this.detach();
this._attachCorners();
}
detach() {
this.pointerDownSubs.forEach((sub) => sub.unsubscribe());
this.pointerDownSubs = [];
this.cornerElements.forEach((elem) => this._renderer2.removeChild(this._getDialogWrapper(), elem));
this.cornerElements = [];
}
_getDialogWrapper() {
return (this._document.getElementById(this._dialogRef.id) || {}).parentElement;
}
_getViewportDimensions() {
var _a, _b;
return (_b = (_a = this._getDialogWrapper()) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
}
_getDialogWrapperDimensions() {
const wrapper = this._getDialogWrapper();
if (!wrapper) {
return { width: 0, height: 0 };
}
const dimensions = getComputedStyle(wrapper);
return {
width: getPixels(dimensions.width),
height: getPixels(dimensions.height),
};
}
_initialPositionReset() {
var _a, _b, _c, _d, _e;
const viewportWidth = (_b = (_a = this._getViewportDimensions()) === null || _a === void 0 ? void 0 : _a.right) !== null && _b !== void 0 ? _b : 0;
const viewportHeight = (_d = (_c = this._getViewportDimensions()) === null || _c === void 0 ? void 0 : _c.bottom) !== null && _d !== void 0 ? _d : 0;
const { width, height } = this._getDialogWrapperDimensions();
const wrapperStyle = (_e = this._getDialogWrapper()) === null || _e === void 0 ? void 0 : _e.style;
const originalDialogRight = wrapperStyle === null || wrapperStyle === void 0 ? void 0 : wrapperStyle.marginRight;
const originalDialogLeft = wrapperStyle === null || wrapperStyle === void 0 ? void 0 : wrapperStyle.marginLeft;
const originalDialogBottom = wrapperStyle === null || wrapperStyle === void 0 ? void 0 : wrapperStyle.marginBottom;
const originalDialogTop = wrapperStyle === null || wrapperStyle === void 0 ? void 0 : wrapperStyle.marginTop;
let x;
if (originalDialogLeft) {
x = getPixels(originalDialogLeft);
}
else if (originalDialogRight) {
x = viewportWidth - getPixels(originalDialogRight) - width;
}
else {
x = (viewportWidth - width) / 2;
}
let y;
if (originalDialogTop) {
y = getPixels(originalDialogTop);
}
else if (originalDialogBottom) {
y = viewportHeight - getPixels(originalDialogBottom) - height;
}
else {
y = (viewportHeight - height) / 2;
}
// use drag ref's mechanisms for positioning instead of the dialog's
this._dialogRef.updatePosition({
top: '0px',
right: '0px',
bottom: '0px',
left: '0px',
});
this._dragRef.setFreeDragPosition({ x, y });
}
_attachCorners() {
Object.values(corners).forEach((corner) => {
const element = this._renderer2.createElement('div');
this.cornerElements = [...this.cornerElements, element];
this._renderer2.setStyle(element, 'position', 'absolute');
this._renderer2.setStyle(element, 'width', cornerWidth);
this._renderer2.setStyle(element, 'height', cornerWidth);
this._renderer2.appendChild(this._getDialogWrapper(), element);
let cursor;
let topBottom;
let rightLeft;
if (corner === corners.topRight) {
cursor = cursors.nesw;
topBottom = verticalAlignment.top;
rightLeft = horizontalAlignment.right;
}
else if (corner === corners.bottomRight) {
cursor = cursors.nwse;
topBottom = verticalAlignment.bottom;
rightLeft = horizontalAlignment.right;
const icon = this._renderer2.createElement('i');
this._renderer2.addClass(icon, 'material-icons');
this._renderer2.appendChild(icon, this._renderer2.createText('filter_list'));
this._renderer2.appendChild(element, icon);
this._renderer2.setStyle(icon, 'transform', `rotate(${315}deg) translate(0px, ${offset})`);
this._renderer2.setStyle(icon, 'font-size', cornerWidth);
}
else if (corner === corners.bottomLeft) {
cursor = cursors.nesw;
topBottom = verticalAlignment.bottom;
rightLeft = horizontalAlignment.left;
}
else {
cursor = cursors.nwse;
topBottom = verticalAlignment.top;
rightLeft = horizontalAlignment.left;
}
this._renderer2.setStyle(element, topBottom, offset);
this._renderer2.setStyle(element, rightLeft, offset);
this._renderer2.setStyle(element, 'cursor', cursor);
const pointerDownSub = fromEvent(element, 'pointerdown').subscribe((event) => {
this._handleMouseDown(event, corner);
});
this.pointerDownSubs = [...this.pointerDownSubs, pointerDownSub];
});
}
_handleMouseDown(event, corner) {
var _a, _b, _c, _d, _e, _f, _g;
this._renderer2.setStyle(this._document.body, 'user-select', 'none');
const { width: originalWidth, height: originalHeight } = this._getDialogWrapperDimensions();
const originalMouseX = event.pageX;
const originalMouseY = event.pageY;
const { x: currentTransformX, y: currentTransformY } = this._dragRef.getFreeDragPosition();
const wrapper = (_a = this._getDialogWrapper()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
const distanceFromBottom = (_b = wrapper === null || wrapper === void 0 ? void 0 : wrapper.bottom) !== null && _b !== void 0 ? _b : 0;
const distanceFromRight = (_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.right) !== null && _c !== void 0 ? _c : 0;
const viewportWidth = (_e = (_d = this._getViewportDimensions()) === null || _d === void 0 ? void 0 : _d.right) !== null && _e !== void 0 ? _e : 0;
const viewportHeight = (_g = (_f = this._getViewportDimensions()) === null || _f === void 0 ? void 0 : _f.bottom) !== null && _g !== void 0 ? _g : 0;
const mouseMoveSub = fromEvent(window, 'pointermove').subscribe((e) => {
e.preventDefault(); // prevent highlighting of text when dragging
const yDelta = clamp(0, e.pageY, viewportHeight) - originalMouseY;
const xDelta = clamp(0, e.pageX, viewportWidth) - originalMouseX;
let newHeight;
let newWidth;
let newTransformY = 0;
let newTransformX = 0;
// top right
if (corner === corners.topRight) {
newHeight = clamp(minHeight, originalHeight - yDelta, viewportHeight);
newWidth = clamp(minWidth, originalWidth + xDelta, viewportWidth);
newTransformY = clamp(0, currentTransformY + yDelta, distanceFromBottom - newHeight);
newTransformX = currentTransformX;
}
// bottom right
else if (corner === corners.bottomRight) {
newHeight = clamp(minHeight, originalHeight + yDelta, viewportHeight);
newWidth = clamp(minWidth, originalWidth + xDelta, viewportWidth);
newTransformY = currentTransformY;
newTransformX = currentTransformX;
}
// bottom left
else if (corner === corners.bottomLeft) {
newHeight = clamp(minHeight, originalHeight + yDelta, viewportHeight);
newWidth = clamp(minWidth, originalWidth - xDelta, viewportWidth);
newTransformY = currentTransformY;
newTransformX = clamp(0, currentTransformX + xDelta, distanceFromRight - newWidth);
}
// top left
else {
newHeight = clamp(minHeight, originalHeight - yDelta, viewportHeight);
newWidth = clamp(minWidth, originalWidth - xDelta, viewportWidth);
newTransformX = clamp(0, currentTransformX + xDelta, distanceFromRight - newWidth);
newTransformY = clamp(0, currentTransformY + yDelta, distanceFromBottom - newHeight);
}
this._dialogRef.updateSize(`${newWidth}px`, `${newHeight}px`);
this._dragRef.setFreeDragPosition({
x: newTransformX,
y: newTransformY,
});
});
const mouseUpSub = merge(fromEvent(window, 'pointerup'), fromEvent(window, 'pointercancel')).subscribe(() => {
this._renderer2.removeStyle(this._document.body, 'user-select');
mouseMoveSub.unsubscribe();
mouseUpSub.unsubscribe();
});
}
}
/**
* Generated bundle index. Do not edit.
*/
export { CovalentDialogsModule, ResizableDraggableDialog, TdAlertDialogComponent, TdConfirmDialogComponent, TdDialogActionsDirective, TdDialogComponent, TdDialogContentDirective, TdDialogService, TdDialogTitleDirective, TdPromptDialogComponent, TdWindowDialogComponent };
//# sourceMappingURL=covalent-core-dialogs.mjs.map