blob: 57f3e3a5469591649e8980468fe000b375bce3a5 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, ViewChild} from "@angular/core";
import {ITextblockError} from "../../../../features/forms/statement-editor/pipes";
import {ITextBlockRenderItem} from "../../model/ITextBlockRenderItem";
import {addTypeToName} from "../../pipes/get-blockdata-array";
@Component({
selector: "app-text-block",
templateUrl: "./text-block.component.html",
styleUrls: ["./text-block.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TextBlockComponent {
@Input()
public appErrors: ITextblockError[] = [];
@Input()
public appShowNewLine = true;
@Input()
public appTitle: string;
@Input()
public appType: "block" | "newline" | "pagebreak" | "text";
@Input()
public appShortMode = false;
@Input()
public appTextBlockData: ITextBlockRenderItem[] = [];
@Input()
public appShowClose = false;
@Input()
public appBlockText;
@Output()
public appTextInput = new EventEmitter<void>();
@Output()
public appNewLine = new EventEmitter<string>();
@Output()
public appButtonPress = new EventEmitter<void>();
@Output()
public appValueChange = new EventEmitter<{ name: string, newValue: string }>();
@Output()
public appChangeText = new EventEmitter<string>();
@ViewChild("inputElement") inputElement: ElementRef;
public editText = false;
public trackByIndex = (index: number) => index;
public addNewLineAfter() {
this.appNewLine.emit(this.appTitle);
}
public valueChange(name: string, newValue: string, type: string) {
this.appValueChange.emit({name: addTypeToName(name, type), newValue});
}
public convertToTextInput() {
this.appTextInput.emit();
this.editText = true;
}
public onInput(value: string) {
this.appChangeText.emit(value);
}
public revert() {
this.appChangeText.emit(this.appType === "text" ? "" : undefined);
this.editText = false;
}
}