Skip to content
Snippets Groups Projects
drop-list.ts 2.37 KiB
Newer Older
  • Learn to ignore specific revisions
  •   DragNDropValueObject,
    
      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);
    
    
    rhenck's avatar
    rhenck committed
        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 {
    
    rhenck's avatar
    rhenck committed
        let oldValues: string[] = [];
    
        if (serializedElement.options) {
    
    rhenck's avatar
    rhenck committed
          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[];
    
    rhenck's avatar
    rhenck committed
        if (oldValues.length > 0) {
    
          this.value = [];
    
    rhenck's avatar
    rhenck committed
          oldValues.forEach((stringValue: string, i: number) => {
    
            (this.value as DragNDropValueObject[]).push({
    
    rhenck's avatar
    rhenck committed
              id: `${this.id}_value_${i}`,
    
              stringValue: stringValue
            });
          });
        }