import { PatternPropertyBase , PatternPropertyInit } from './property-base' ; import * as Types from '@meetalva/types' ; import uuid = require ( 'uuid' ) ; see Property export class PatternStringProperty extends PatternPropertyBase < string | undefined > { public readonly type = Types . PatternPropertyType . String ; public static Defaults ( mixins ? ) { return { contextId : 'stringProperty' , defaultValue : 'Text' , description : 'A string property' , example : '' , group : '' , hidden : false , id : uuid . v4 ( ) , inputType : Types . PatternPropertyInputType . Default , label : 'String Property' , propertyName : 'stringProperty' , required : false , control : '' , ... mixins } ; } public static from ( serialized ) { return new PatternStringProperty ( { contextId : serialized . contextId , defaultValue : serialized . defaultValue , description : serialized . description , example : serialized . example , group : serialized . group , hidden : serialized . hidden , id : serialized . id , inputType : serialized . inputType , label : serialized . label , propertyName : serialized . propertyName , required : serialized . required , control : serialized . control } ) ; } public static fromDefaults ( mixins ? ) { return new PatternStringProperty ( PatternStringProperty . Defaults ( mixins ) ) ; } public coerceValue ( value ) { if ( typeof value === 'string' ) { return value ; } const empty = this . required ? '' : undefined ; if ( typeof value === 'undefined' || value === null ) { return empty ; } if ( typeof value === 'number' && ! Number . isNaN ( value ) ) { return String ( value ) ; } if ( typeof value === 'boolean' ) { return value ? 'true' : 'false' ; } return empty ; } public toJSON ( ) { return { model : this . model , contextId : this . contextId , control : this . control , defaultValue : this . defaultValue , description : this . description , example : this . example || '' , group : this . group , hidden : this . hidden , id : this . id , inputType : this . inputType , label : this . label , propertyName : this . propertyName , required : this . required , type : this . type } ; } public update ( prop ) { this . contextId = prop . getContextId ( ) ; this . control = prop . getControl ( ) ; this . description = prop . getDescription ( ) ; this . defaultValue = prop . getDefaultValue ( ) ; this . example = prop . getExample ( ) ; this . group = prop . getGroup ( ) ; this . hidden = prop . getHidden ( ) ; this . label = prop . getLabel ( ) ; this . propertyName = prop . getPropertyName ( ) ; this . required = prop . getRequired ( ) ; this . control = prop . getControl ( ) ; } }