@deepkit/api-console-gui
Version:
API Console GUI
102 lines • 3.22 kB
JavaScript
import { __decorate } from "tslib";
import { Component, EventEmitter, forwardRef, input, model, Output } from '@angular/core';
import { isType, ReflectionKind, stringifyType } from '@deepkit/type';
import { OptionDirective, SelectBoxComponent } from '@deepkit/desktop-ui';
import { FormsModule } from '@angular/forms';
import { InputComponent } from './input.component';
let UnionInputComponent = class UnionInputComponent {
constructor() {
this.model = model.required();
this.decoration = input();
this.type = input.required();
this.keyDown = new EventEmitter();
this.items = [];
}
ngOnChanges() {
this.init();
}
ngOnInit() {
this.init();
}
set(e) {
const model = this.model();
if (isType(e)) {
this.subProperty = e;
model.typeIndex = this.type().types.indexOf(e);
}
else {
this.subProperty = undefined;
model.typeIndex = -1;
model.value.set(e);
}
}
init() {
this.items = [];
this.subProperty = undefined;
const type = this.type();
if (!type.types.length)
return;
for (const p of type.types) {
if (p.kind === ReflectionKind.literal) {
this.items.push({ value: p.literal, label: String(p.literal) });
}
else {
const label = stringifyType(p, { showFullDefinition: false });
this.items.push({ type: p, label: label });
}
}
if (this.model().typeIndex >= 0) {
this.subProperty = type.types[this.model().typeIndex];
}
else if (this.model().value() === undefined) {
const first = type.types[0];
if (first.kind === ReflectionKind.literal) {
this.set(first.literal);
}
else {
this.set(first);
}
}
}
};
__decorate([
Output()
], UnionInputComponent.prototype, "keyDown", void 0);
UnionInputComponent = __decorate([
Component({
template: `
<dui-select style="width: 100%" textured
[ngModel]="subProperty || model().value()"
(ngModelChange)="set($event)"
>
(item of items; track $index) {
(!item.type) {
<dui-option [value]="item.value">{{ item.label }}</dui-option>
}
(item.type) {
<dui-option [value]="item.type">{{ item.label }}</dui-option>
}
}
</dui-select>
(subProperty) {
<div class="sub">
<api-console-input [model]="model().getProperty(model().typeIndex)" [type]="subProperty" (keyDown)="keyDown.emit($event)"></api-console-input>
</div>
}
`,
styles: [`
.sub {
margin-top: 3px;
margin-left: 1px;
}
`],
imports: [
SelectBoxComponent,
FormsModule,
forwardRef(() => InputComponent),
OptionDirective,
],
})
], UnionInputComponent);
export { UnionInputComponent };
//# sourceMappingURL=union-input.component.js.map