{"version":3,"file":"primeng-terminal.mjs","sources":["../../src/app/components/terminal/terminalservice.ts","../../src/app/components/terminal/terminal.ts","../../src/app/components/terminal/primeng-terminal.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { Subject } from 'rxjs';\n\n@Injectable()\nexport class TerminalService {\n    \n    private commandSource = new Subject<string>();\n    private responseSource = new Subject<string>();\n    \n    commandHandler = this.commandSource.asObservable();\n    responseHandler = this.responseSource.asObservable();\n    \n    sendCommand(command: string) {\n        if (command) {\n            this.commandSource.next(command);\n        }\n    }\n    \n    sendResponse(response: string) {\n        if (response) {\n            this.responseSource.next(response);\n        }\n    }\n}","import {NgModule,Component,AfterViewInit,AfterViewChecked,OnDestroy,Input,ElementRef,ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef} from '@angular/core';\nimport {FormsModule} from '@angular/forms';\nimport {CommonModule} from '@angular/common';\nimport {DomHandler} from 'primeng/dom';\nimport {TerminalService} from './terminalservice';\nimport {Subscription}   from 'rxjs';\n\n@Component({\n    selector: 'p-terminal',\n    template: `\n        <div [ngClass]=\"'p-terminal p-component'\" [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"focus(in)\">\n            <div *ngIf=\"welcomeMessage\">{{welcomeMessage}}</div>\n            <div class=\"p-terminal-content\">\n                <div *ngFor=\"let command of commands\">\n                    <span class=\"p-terminal-prompt\">{{prompt}}</span>\n                    <span class=\"p-terminal-command\">{{command.text}}</span>\n                    <div class=\"p-terminal-response\">{{command.response}}</div>\n                </div>\n            </div>\n            <div class=\"p-terminal-prompt-container\">\n                <span class=\"p-terminal-content-prompt\">{{prompt}}</span>\n                <input #in type=\"text\" [(ngModel)]=\"command\" class=\"p-terminal-input\" autocomplete=\"off\" (keydown)=\"handleCommand($event)\" autofocus>\n            </div>\n        </div>\n    `,\n    changeDetection: ChangeDetectionStrategy.OnPush,\n    encapsulation: ViewEncapsulation.None,\n    styleUrls: ['./terminal.css'],\n    host: {\n        'class': 'p-element'\n    }\n})\nexport class Terminal implements AfterViewInit,AfterViewChecked,OnDestroy {\n\n    @Input() welcomeMessage: string;\n\n    @Input() prompt: string;\n\n    @Input() style: any;\n\n    @Input() styleClass: string;\n\n    commands: any[] = [];\n\n    command: string;\n\n    container: Element;\n\n    commandProcessed: boolean;\n\n    subscription: Subscription;\n\n    constructor(public el: ElementRef, public terminalService: TerminalService, public cd: ChangeDetectorRef) {\n        this.subscription = terminalService.responseHandler.subscribe(response => {\n            this.commands[this.commands.length - 1].response = response;\n            this.commandProcessed = true;\n        });\n    }\n\n    ngAfterViewInit() {\n        this.container = DomHandler.find(this.el.nativeElement, '.p-terminal')[0];\n    }\n\n    ngAfterViewChecked() {\n        if (this.commandProcessed) {\n            this.container.scrollTop = this.container.scrollHeight;\n            this.commandProcessed = false;\n        }\n    }\n\n    @Input()\n    set response(value: string) {\n        if (value) {\n            this.commands[this.commands.length - 1].response = value;\n            this.commandProcessed = true;\n        }\n    }\n\n    handleCommand(event: KeyboardEvent) {\n        if (event.keyCode == 13) {\n            this.commands.push({text: this.command});\n            this.terminalService.sendCommand(this.command);\n            this.command = '';\n        }\n    }\n\n    focus(element: HTMLElement) {\n        element.focus();\n    }\n\n    ngOnDestroy() {\n        if (this.subscription) {\n            this.subscription.unsubscribe();\n        }\n    }\n\n}\n\n@NgModule({\n    imports: [CommonModule,FormsModule],\n    exports: [Terminal],\n    declarations: [Terminal]\n})\nexport class TerminalModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;MAIa,eAAe;IAD5B;QAGY,kBAAa,GAAG,IAAI,OAAO,EAAU,CAAC;QACtC,mBAAc,GAAG,IAAI,OAAO,EAAU,CAAC;QAE/C,mBAAc,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;QACnD,oBAAe,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;KAaxD;IAXG,WAAW,CAAC,OAAe;QACvB,IAAI,OAAO,EA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