UNPKG

@deepkit/api-console-gui

Version:

API Console GUI

58 lines (57 loc) 1.77 kB
import { __decorate } from "tslib"; import { Component, EventEmitter, input, Output } from '@angular/core'; import { getSerializeFunction, ReflectionKind, serializer } from '@deepkit/type'; import { InputComponent } from '@deepkit/desktop-ui'; import { FormsModule } from '@angular/forms'; let JsonInputComponent = class JsonInputComponent { constructor() { this.model = input.required(); this.decoration = input(); this.type = input.required(); this.keyDown = new EventEmitter(); this.jsonContent = ''; } getType() { const type = this.type(); if (type.kind === ReflectionKind.number || type.kind === ReflectionKind.bigint) return 'number'; return 'text'; } jsonDone() { try { const obj = JSON.parse(this.jsonContent); this.model().value.set(getSerializeFunction(this.type(), serializer.deserializeRegistry)(obj)); } catch (error) { } } }; __decorate([ Output() ], JsonInputComponent.prototype, "keyDown", void 0); JsonInputComponent = __decorate([ Component({ template: ` <dui-input lightFocus type="textarea" style="width: 100%" [(ngModel)]="jsonContent" (ngModelChange)="jsonDone()"></dui-input> `, styles: [` .json-editor { height: 100%; padding: 0 12px; display: flex; flex-direction: column; } .json-editor dui-input { margin-top: 15px; width: 100%; flex: 1; } `], imports: [ InputComponent, FormsModule, ], }) ], JsonInputComponent); export { JsonInputComponent }; //# sourceMappingURL=json-input.component.js.map