Skip to content
Snippets Groups Projects
math-field.ts 1.34 KiB
Newer Older
  • Learn to ignore specific revisions
  • rhenck's avatar
    rhenck committed
    import {
    
      AnswerScheme, BasicStyles, InputElement, PositionProperties, UIElement
    
    rhenck's avatar
    rhenck committed
    } from 'common/models/elements/element';
    import { Type } from '@angular/core';
    import { ElementComponent } from 'common/directives/element-component.directive';
    import { MathFieldComponent } from 'common/components/input-elements/math-field.component';
    
    export class MathFieldElement extends InputElement {
      enableModeSwitch: boolean = false;
      position: PositionProperties | undefined;
    
      styling: BasicStyles & {
        lineHeight: number;
      };
    
    rhenck's avatar
    rhenck committed
    
      constructor(element: Partial<MathFieldElement>) {
        super(element);
        if (element.enableModeSwitch !== undefined) this.enableModeSwitch = element.enableModeSwitch;
        this.position = element.position ? UIElement.initPositionProps(element.position) : undefined;
    
        this.styling = {
          ...UIElement.initStylingProps({
            backgroundColor: 'transparent',
            lineHeight: 135,
            ...element.styling
          })
        };
    
    rhenck's avatar
    rhenck committed
      }
    
      hasAnswerScheme(): boolean {
        return Boolean(this.getAnswerScheme);
      }
    
      getAnswerScheme(): AnswerScheme {
        return {
          id: this.id,
          type: 'string',
    
          format: 'latex',
    
    rhenck's avatar
    rhenck committed
          multiple: false,
          nullable: !this.value && this.value !== '',
          values: [],
          valuesComplete: false
        };
      }
    
      getElementComponent(): Type<ElementComponent> {
        return MathFieldComponent;
      }
    }