import Vue from 'vue' ; import { VTComponent , CustomProp } from './types/ComponentSettings' ; import CustomProps from './types/CustomProps' ; import configureDialogGlobals from './utils/configureDialogGlobals' ; const configure = ( component , props ? ) : VTComponent => { const componentProps = component ?. options ?. props ; const componentName = component ?. options ?. name ; if ( componentName === 'TModal' ) { Vue . prototype . $modal = new Vue ( { methods : { show ( name , params = undefined ) { this . $emit ( `show-${ name }` , params ) ; } , hide ( name ) { this . $emit ( `hide-${ name }` ) ; } , } , } ) ; } else if ( componentName === 'TDialog' ) { configureDialogGlobals ( Vue , props ) ; } if ( ! props || ! componentProps ) { return component ; } const customProps = { } ; Object . keys ( props ) . forEach ( ( customPropName ) => { const defaultProp = componentProps [ customPropName ] ; if ( ! defaultProp ) { return ; } const newDefaultValue = props [ customPropName ] ; customProps [ customPropName ] = { type : defaultProp ?. type , default : [ 'object' , 'function' ] . includes ( typeof newDefaultValue ) ? ( ) => newDefaultValue : newDefaultValue , } ; } ) ; return component . extend ( { props : customProps , } ) ; } ; export default configure ;