import * as _ from 'lodash' ; import * as Mobx from 'mobx' ; import * as Types from '@meetalva/types' ; import * as uuid from 'uuid' ; export interface PatternPropertyInit < T > { contextId : string ; defaultValue ? : T ; description ? : string ; example ? : string ; group ? : string ; hidden ? : boolean ; id ? : string ; inputType : Types . PatternPropertyInputType ; label : string ; propertyName : string ; required ? : boolean ; control ? : string ; focused ? : boolean ; } export abstract class PatternPropertyBase < T > { public readonly model = Types . ModelName . PatternProperty ; @ Mobx . observable protected contextId : string ; @ Mobx . observable protected defaultValue : T | undefined ; @ Mobx . observable protected description ? : string ; @ Mobx . observable protected example : string ; @ Mobx . observable protected group : string ; @ Mobx . observable protected hidden : boolean = false ; @ Mobx . observable protected id : string ; @ Mobx . observable protected inputType : Types . PatternPropertyInputType ; @ Mobx . observable protected label : string ; @ Mobx . observable protected propertyName : string ; @ Mobx . observable protected required : boolean = false ; @ Mobx . observable protected control : string ; @ Mobx . observable protected focused : boolean = false ; @ Mobx . observable public type : Types . PatternPropertyType = Types . PatternPropertyType . Unknown ; public constructor ( init ) { this . contextId = init . contextId ; this . id = init . id || uuid . v4 ( ) ; this . inputType = init . inputType ; this . label = init . label ; this . propertyName = init . propertyName ; if ( typeof init . description !== 'undefined' ) { this . description = init . description ; } if ( typeof init . hidden !== 'undefined' ) { this . hidden = init . hidden ; } if ( typeof init . required !== 'undefined' ) { this . required = init . required ; } if ( typeof init . focused !== 'undefined' ) { this . focused = init . focused ; } this . example = init . example || '' ; this . group = init . group || '' ; this . control = init . control || '' ; this . defaultValue = init . defaultValue ; } public abstract coerceValue ( value ) ; public equals ( b ) { return _ . isEqual ( this . toJSON ( ) , b . toJSON ( ) ) ; } public hasDefault ( ) { return typeof this . defaultValue !== 'undefined' ; } public getContextId ( ) { return this . contextId ; } public getControl ( ) { return this . control ; } public getDefaultValue ( ) { return this . coerceValue ( this . defaultValue ) ; } public getDescription ( ) { return this . description ; } public getExample ( ) { return this . example ; } public getGroup ( ) { return this . group ; } public getHidden ( ) { return this . hidden ; } public getId ( ) { return this . id ; } public getInputType ( ) { return this . inputType ; } public getLabel ( ) { return this . label ; } public getPropertyName ( ) { return this . propertyName ; } public getRequired ( ) { return this . required ; } public getType ( ) { return this . type ; } public getFocused ( ) { return this . focused ; } @ Mobx . action public setFocused ( focused ) { this . focused = focused ; } public abstract toJSON ( ) ; public abstract update ( patternProperty ) ; }