import * as i0 from '@angular/core'; import { Injectable, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, NgModule } from '@angular/core'; import * as i3 from '@angular/forms'; import { FormsModule } from '@angular/forms'; import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import { DomHandler } from 'primeng/dom'; import { Subject } from 'rxjs'; class TerminalService { constructor() { this.commandSource = new Subject(); this.responseSource = new Subject(); this.commandHandler = this.commandSource.asObservable(); this.responseHandler = this.responseSource.asObservable(); } sendCommand(command) { if (command) { this.commandSource.next(command); } } sendResponse(response) { if (response) { this.responseSource.next(response); } } } TerminalService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); TerminalService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalService }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalService, decorators: [{ type: Injectable }] }); class Terminal { constructor(el, terminalService, cd) { this.el = el; this.terminalService = terminalService; this.cd = cd; this.commands = []; this.subscription = terminalService.responseHandler.subscribe(response => { this.commands[this.commands.length - 1].response = response; this.commandProcessed = true; }); } ngAfterViewInit() { this.container = DomHandler.find(this.el.nativeElement, '.p-terminal')[0]; } ngAfterViewChecked() { if (this.commandProcessed) { this.container.scrollTop = this.container.scrollHeight; this.commandProcessed = false; } } set response(value) { if (value) { this.commands[this.commands.length - 1].response = value; this.commandProcessed = true; } } handleCommand(event) { if (event.keyCode == 13) { this.commands.push({ text: this.command }); this.terminalService.sendCommand(this.command); this.command = ''; } } focus(element) { element.focus(); } ngOnDestroy() { if (this.subscription) { this.subscription.unsubscribe(); } } } Terminal.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Terminal, deps: [{ token: i0.ElementRef }, { token: TerminalService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); Terminal.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: Terminal, selector: "p-terminal", inputs: { welcomeMessage: "welcomeMessage", prompt: "prompt", style: "style", styleClass: "styleClass", response: "response" }, host: { classAttribute: "p-element" }, ngImport: i0, template: `
{{welcomeMessage}}
{{prompt}} {{command.text}}
{{command.response}}
{{prompt}}
`, isInline: true, styles: [".p-terminal{height:18rem;overflow:auto}.p-terminal-prompt-container{display:flex;align-items:center}.p-terminal-input{flex:1 1 auto;border:0 none;background-color:transparent;color:inherit;padding:0;outline:0 none}.p-terminal-input::-ms-clear{display:none}\n"], directives: [{ type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i3.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: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Terminal, decorators: [{ type: Component, args: [{ selector: 'p-terminal', template: `
{{welcomeMessage}}
{{prompt}} {{command.text}}
{{command.response}}
{{prompt}}
`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: { 'class': 'p-element' }, styles: [".p-terminal{height:18rem;overflow:auto}.p-terminal-prompt-container{display:flex;align-items:center}.p-terminal-input{flex:1 1 auto;border:0 none;background-color:transparent;color:inherit;padding:0;outline:0 none}.p-terminal-input::-ms-clear{display:none}\n"] }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: TerminalService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { welcomeMessage: [{ type: Input }], prompt: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], response: [{ type: Input }] } }); class TerminalModule { } TerminalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); TerminalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalModule, declarations: [Terminal], imports: [CommonModule, FormsModule], exports: [Terminal] }); TerminalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalModule, imports: [[CommonModule, FormsModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TerminalModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, FormsModule], exports: [Terminal], declarations: [Terminal] }] }] }); /** * Generated bundle index. Do not edit. */ export { Terminal, TerminalModule, TerminalService };