Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
InputElement, InputElementProperties,
UIElementType
} from 'common/models/elements/element';
import {
BasicStyles,
PositionProperties,
PropertyGroupGenerators, PropertyGroupValidators
} from 'common/models/elements/property-group-interfaces';
import { Type } from '@angular/core';
import { ElementComponent } from 'common/directives/element-component.directive';
import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces';
import { TextAreaMathComponent } from 'common/components/input-elements/text-area-math.component';
import { environment } from 'common/environment';
import { InstantiationEror } from 'common/util/errors';
export class TextAreaMathElement extends InputElement implements TextAreaMathProperties {
type: UIElementType = 'text-area-math';
value = '';
rowCount: number = 2;
hasAutoHeight: boolean = false;
position: PositionProperties;
styling: BasicStyles & {
lineHeight: number;
};
constructor(element?: TextAreaMathProperties) {
super(element);
if (element && isValid(element)) {
this.rowCount = element.rowCount;
this.hasAutoHeight = element.hasAutoHeight;
this.position = { ...element.position };
this.styling = { ...element.styling };
} else {
if (environment.strictInstantiation) {
throw new InstantiationEror('Error at TextAreaMath instantiation', element);
}
if (element?.value !== undefined) this.value = element?.value as string;
if (element?.rowCount !== undefined) this.rowCount = element.rowCount;
if (element?.hasAutoHeight !== undefined) this.hasAutoHeight = element.hasAutoHeight;
this.dimensions = PropertyGroupGenerators.generateDimensionProps(element?.dimensions);
this.position = PropertyGroupGenerators.generatePositionProps(element?.position);
this.styling = {
...PropertyGroupGenerators.generateBasicStyleProps(element?.styling),
lineHeight: element?.styling?.lineHeight || 135
};
}
}
getAnswerScheme(): AnswerScheme {
return {
id: this.id,
type: 'string',
format: 'math-ml',
multiple: false,
values: [],
valuesComplete: false
};
}
getElementComponent(): Type<ElementComponent> {
return TextAreaMathComponent;
}
getDuplicate(): TextAreaMathElement {
return new TextAreaMathElement(this);
}
}
export interface TextAreaMathProperties extends InputElementProperties {
rowCount: number;
hasAutoHeight: boolean;
position: PositionProperties;
styling: BasicStyles & {
lineHeight: number;
};
}
function isValid(blueprint?: TextAreaMathProperties): boolean {
if (!blueprint) return false;
return blueprint.rowCount !== undefined &&
blueprint.hasAutoHeight !== undefined &&
PropertyGroupValidators.isValidPosition(blueprint.position) &&
PropertyGroupValidators.isValidBasicStyles(blueprint.styling) &&
blueprint.styling.lineHeight !== undefined;
}