Newer
Older
FontElement,
FontProperties,
InputElement,
PositionedElement, PositionProperties,
SurfaceElement,
SurfaceProperties,
UIElement
} from '../../models/uI-element';
import { initFontElement, initPositionedElement, initSurfaceElement } from '../../util/unit-interface-initializer';
export class DropListElement extends InputElement implements PositionedElement, FontElement, SurfaceElement {
onlyOneItem: boolean = false;
connectedTo: string[] = [];
orientation: 'vertical' | 'horizontal' | 'flex' = 'vertical';
itemBackgroundColor: string = '#c9e0e0';
highlightReceivingDropList: boolean = false;
highlightReceivingDropListColor: string = '#006064';
positionProps: PositionProperties;
fontProps: FontProperties;
surfaceProps: SurfaceProperties;
constructor(serializedElement: Partial<UIElement>) {
super(serializedElement);
Object.assign(this, serializedElement);
this.positionProps = initPositionedElement(serializedElement);
this.fontProps = initFontElement(serializedElement);
this.surfaceProps = initSurfaceElement(serializedElement);
this.value =
serializedElement.value !== undefined ? serializedElement.value as DragNDropValueObject[] | null : [];
this.height = serializedElement.height || 100;
this.positionProps.useMinHeight =
serializedElement.positionProps?.useMinHeight !== undefined ?
serializedElement.positionProps.useMinHeight as boolean :
true;
this.surfaceProps.backgroundColor =
serializedElement.surfaceProps?.backgroundColor as string ||
serializedElement.backgroundColor as string ||
this.handleBackwardsCompatibility(serializedElement);
}
handleBackwardsCompatibility(serializedElement: Partial<UIElement>): void {
oldValues = serializedElement.options as string[];
}
if (serializedElement.value instanceof Array &&
serializedElement.value[0] &&
!(serializedElement.value[0] instanceof Object)) {
oldValues = this.value as unknown as string[];
oldValues.forEach((stringValue: string, i: number) => {
(this.value as DragNDropValueObject[]).push({
stringValue: stringValue
});
});
}