1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@angular/common'), require('primeng/dom'), require('rxjs')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/terminal', ['exports', '@angular/core', '@angular/forms', '@angular/common', 'primeng/dom', 'rxjs'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.terminal = {}), global.ng.core, global.ng.forms, global.ng.common, global.primeng.dom, global.rxjs));
|
5 | }(this, (function (exports, core, forms, common, dom, rxjs) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var TerminalService = (function () {
|
14 | function TerminalService() {
|
15 | this.commandSource = new rxjs.Subject();
|
16 | this.responseSource = new rxjs.Subject();
|
17 | this.commandHandler = this.commandSource.asObservable();
|
18 | this.responseHandler = this.responseSource.asObservable();
|
19 | }
|
20 | TerminalService.prototype.sendCommand = function (command) {
|
21 | if (command) {
|
22 | this.commandSource.next(command);
|
23 | }
|
24 | };
|
25 | TerminalService.prototype.sendResponse = function (response) {
|
26 | if (response) {
|
27 | this.responseSource.next(response);
|
28 | }
|
29 | };
|
30 | TerminalService = __decorate([
|
31 | core.Injectable()
|
32 | ], TerminalService);
|
33 | return TerminalService;
|
34 | }());
|
35 |
|
36 | var __decorate$1 = (this && this.__decorate) || function (decorators, target, key, desc) {
|
37 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
38 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
39 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
40 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
41 | };
|
42 | var Terminal = (function () {
|
43 | function Terminal(el, terminalService) {
|
44 | var _this = this;
|
45 | this.el = el;
|
46 | this.terminalService = terminalService;
|
47 | this.commands = [];
|
48 | this.subscription = terminalService.responseHandler.subscribe(function (response) {
|
49 | _this.commands[_this.commands.length - 1].response = response;
|
50 | _this.commandProcessed = true;
|
51 | });
|
52 | }
|
53 | Terminal.prototype.ngAfterViewInit = function () {
|
54 | this.container = dom.DomHandler.find(this.el.nativeElement, '.ui-terminal')[0];
|
55 | };
|
56 | Terminal.prototype.ngAfterViewChecked = function () {
|
57 | if (this.commandProcessed) {
|
58 | this.container.scrollTop = this.container.scrollHeight;
|
59 | this.commandProcessed = false;
|
60 | }
|
61 | };
|
62 | Object.defineProperty(Terminal.prototype, "response", {
|
63 | set: function (value) {
|
64 | if (value) {
|
65 | this.commands[this.commands.length - 1].response = value;
|
66 | this.commandProcessed = true;
|
67 | }
|
68 | },
|
69 | enumerable: true,
|
70 | configurable: true
|
71 | });
|
72 | Terminal.prototype.handleCommand = function (event) {
|
73 | if (event.keyCode == 13) {
|
74 | this.commands.push({ text: this.command });
|
75 | this.terminalService.sendCommand(this.command);
|
76 | this.command = '';
|
77 | }
|
78 | };
|
79 | Terminal.prototype.focus = function (element) {
|
80 | element.focus();
|
81 | };
|
82 | Terminal.prototype.ngOnDestroy = function () {
|
83 | if (this.subscription) {
|
84 | this.subscription.unsubscribe();
|
85 | }
|
86 | };
|
87 | Terminal.ctorParameters = function () { return [
|
88 | { type: core.ElementRef },
|
89 | { type: TerminalService }
|
90 | ]; };
|
91 | __decorate$1([
|
92 | core.Input()
|
93 | ], Terminal.prototype, "welcomeMessage", void 0);
|
94 | __decorate$1([
|
95 | core.Input()
|
96 | ], Terminal.prototype, "prompt", void 0);
|
97 | __decorate$1([
|
98 | core.Input()
|
99 | ], Terminal.prototype, "style", void 0);
|
100 | __decorate$1([
|
101 | core.Input()
|
102 | ], Terminal.prototype, "styleClass", void 0);
|
103 | __decorate$1([
|
104 | core.Input()
|
105 | ], Terminal.prototype, "response", null);
|
106 | Terminal = __decorate$1([
|
107 | core.Component({
|
108 | selector: 'p-terminal',
|
109 | template: "\n <div [ngClass]=\"'ui-terminal ui-widget ui-widget-content ui-corner-all'\" [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"focus(in)\">\n <div *ngIf=\"welcomeMessage\">{{welcomeMessage}}</div>\n <div class=\"ui-terminal-content\">\n <div *ngFor=\"let command of commands\">\n <span>{{prompt}}</span>\n <span class=\"ui-terminal-command\">{{command.text}}</span>\n <div>{{command.response}}</div>\n </div>\n </div>\n <div>\n <span class=\"ui-terminal-content-prompt\">{{prompt}}</span>\n <input #in type=\"text\" [(ngModel)]=\"command\" class=\"ui-terminal-input\" autocomplete=\"off\" (keydown)=\"handleCommand($event)\" autofocus>\n </div>\n </div>\n ",
|
110 | changeDetection: core.ChangeDetectionStrategy.Default
|
111 | })
|
112 | ], Terminal);
|
113 | return Terminal;
|
114 | }());
|
115 | var TerminalModule = (function () {
|
116 | function TerminalModule() {
|
117 | }
|
118 | TerminalModule = __decorate$1([
|
119 | core.NgModule({
|
120 | imports: [common.CommonModule, forms.FormsModule],
|
121 | exports: [Terminal],
|
122 | declarations: [Terminal]
|
123 | })
|
124 | ], TerminalModule);
|
125 | return TerminalModule;
|
126 | }());
|
127 |
|
128 | exports.Terminal = Terminal;
|
129 | exports.TerminalModule = TerminalModule;
|
130 | exports.TerminalService = TerminalService;
|
131 |
|
132 | Object.defineProperty(exports, '__esModule', { value: true });
|
133 |
|
134 | })));
|
135 |
|