173 lines
8.9 KiB
JavaScript
173 lines
8.9 KiB
JavaScript
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 {
|
|
commandSource = new Subject();
|
|
responseSource = new Subject();
|
|
commandHandler = this.commandSource.asObservable();
|
|
responseHandler = this.responseSource.asObservable();
|
|
sendCommand(command) {
|
|
if (command) {
|
|
this.commandSource.next(command);
|
|
}
|
|
}
|
|
sendResponse(response) {
|
|
if (response) {
|
|
this.responseSource.next(response);
|
|
}
|
|
}
|
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: TerminalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: TerminalService });
|
|
}
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: TerminalService, decorators: [{
|
|
type: Injectable
|
|
}] });
|
|
|
|
/**
|
|
* Terminal is a text based user interface.
|
|
* @group Components
|
|
*/
|
|
class Terminal {
|
|
el;
|
|
terminalService;
|
|
cd;
|
|
/**
|
|
* Initial text to display on terminal.
|
|
* @group Props
|
|
*/
|
|
welcomeMessage;
|
|
/**
|
|
* Prompt text for each command.
|
|
* @group Props
|
|
*/
|
|
prompt;
|
|
/**
|
|
* Inline style of the component.
|
|
* @group Props
|
|
*/
|
|
style;
|
|
/**
|
|
* Style class of the component.
|
|
* @group Props
|
|
*/
|
|
styleClass;
|
|
commands = [];
|
|
command;
|
|
container;
|
|
commandProcessed;
|
|
subscription;
|
|
constructor(el, terminalService, cd) {
|
|
this.el = el;
|
|
this.terminalService = terminalService;
|
|
this.cd = cd;
|
|
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();
|
|
}
|
|
}
|
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Terminal, deps: [{ token: i0.ElementRef }, { token: TerminalService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.7", type: Terminal, selector: "p-terminal", inputs: { welcomeMessage: "welcomeMessage", prompt: "prompt", style: "style", styleClass: "styleClass", response: "response" }, host: { classAttribute: "p-element" }, ngImport: i0, template: `
|
|
<div [ngClass]="'p-terminal p-component'" [ngStyle]="style" [class]="styleClass" (click)="focus(in)">
|
|
<div *ngIf="welcomeMessage">{{ welcomeMessage }}</div>
|
|
<div class="p-terminal-content">
|
|
<div *ngFor="let command of commands">
|
|
<span class="p-terminal-prompt">{{ prompt }}</span>
|
|
<span class="p-terminal-command">{{ command.text }}</span>
|
|
<div class="p-terminal-response" [attr.aria-live]="'polite'">{{ command.response }}</div>
|
|
</div>
|
|
</div>
|
|
<div class="p-terminal-prompt-container">
|
|
<span class="p-terminal-content-prompt">{{ prompt }}</span>
|
|
<input #in type="text" [(ngModel)]="command" class="p-terminal-input" autocomplete="off" (keydown)="handleCommand($event)" autofocus />
|
|
</div>
|
|
</div>
|
|
`, isInline: true, styles: ["@layer primeng{.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"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", 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]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", 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: "17.3.7", ngImport: i0, type: Terminal, decorators: [{
|
|
type: Component,
|
|
args: [{ selector: 'p-terminal', template: `
|
|
<div [ngClass]="'p-terminal p-component'" [ngStyle]="style" [class]="styleClass" (click)="focus(in)">
|
|
<div *ngIf="welcomeMessage">{{ welcomeMessage }}</div>
|
|
<div class="p-terminal-content">
|
|
<div *ngFor="let command of commands">
|
|
<span class="p-terminal-prompt">{{ prompt }}</span>
|
|
<span class="p-terminal-command">{{ command.text }}</span>
|
|
<div class="p-terminal-response" [attr.aria-live]="'polite'">{{ command.response }}</div>
|
|
</div>
|
|
</div>
|
|
<div class="p-terminal-prompt-container">
|
|
<span class="p-terminal-content-prompt">{{ prompt }}</span>
|
|
<input #in type="text" [(ngModel)]="command" class="p-terminal-input" autocomplete="off" (keydown)="handleCommand($event)" autofocus />
|
|
</div>
|
|
</div>
|
|
`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
class: 'p-element'
|
|
}, styles: ["@layer primeng{.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: () => [{ 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 {
|
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: TerminalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: TerminalModule, declarations: [Terminal], imports: [CommonModule, FormsModule], exports: [Terminal] });
|
|
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: TerminalModule, imports: [CommonModule, FormsModule] });
|
|
}
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", 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 };
|
|
//# sourceMappingURL=primeng-terminal.mjs.map
|