import { WidgetModel , PropertyModel } from '../models/models' ; import { WrapperPropertyHandler } from "./wrapper-property" ; import { makeVariableName } from "../utils" ; import { PropertyResolver } from '../resolvers/property-resolver' ; export class WrapperDisablePropertyHandler extends WrapperPropertyHandler { constructor ( propertyResolver ) { super ( propertyResolver , [ { handler : ':disable' , targetProperty : 'value' } ] , 'Disable' , undefined , 9000 ) ; } protected createWrapperWidget ( widget , targetProperty , value , onWrapped ) { const wrapperWidget = { controllers : [ ] , vars : [ ] , formControls : [ ] , properties : [ { dataType : 'object' , value : value , name : 'value' } , { dataType : 'object' , value : 'eventFunction' , name : 'event' } , { dataType : 'function' , name : 'builder' , value : '' , extraData : { parameters : [ { name : 'context' , type : 'BuildContext' } , { name : `event` , type : '' } ] , addReturn : true } } ] , type : this . targetWidgetType , wrappedWidgets : [ widget ] , onResolved : [ ] } ; widget . onResolved . push ( ( w ) => { const firstEvent = this . getfirstEvent ( w ) ; if ( firstEvent ) { wrapperWidget . properties [ 1 ] . value = firstEvent . value ; firstEvent . value = 'event' ; } } ) ; onWrapped . push ( ( wrapper ) => { if ( wrapper . type === 'StreamBuilder' ) { ( wrapper . properties [ 2 ] . extraData as any ) . logic = [ ( wrapper . properties [ 2 ] . extraData as any ) . logic [ 0 ] ] ; } } ) ; return { wrapperWidget , propertyToUpdateAfterBinding : wrapperWidget . properties [ 0 ] } ; } private getfirstEvent ( w ) { const event = w . properties . filter ( a => /^on[A-Z].*$/g . test ( a . name ) ) [ 0 ] ; if ( event ) { return event ; } if ( w . wrappedWidgets [ 0 ] ) { return this . getfirstEvent ( w . wrappedWidgets [ 0 ] ) ; } return null ; } }