import { BaseComponentWrapper , WrappableInterface } from '@ag-grid-community/core' ; import { VueComponentFactory } from './VueComponentFactory' ; interface VueWrappableInterface extends WrappableInterface { overrideProcessing ( methodName ) : boolean ; processMethod ( methodName , args ) : any ; } export class VueFrameworkComponentWrapper extends BaseComponentWrapper < WrappableInterface > { private parent : any | null ; constructor ( parent ) { super ( ) ; this . parent = parent ; } public createWrapper ( component ) { const that = this ; class DynamicComponent extends VueComponent < any , any > implements WrappableInterface { public init ( params ) { super . init ( params ) ; } public hasMethod ( name ) { return wrapper . getFrameworkComponentInstance ( ) [ name ] != null ; } public callMethod ( name , args ) { const componentInstance = this . getFrameworkComponentInstance ( ) ; const frameworkComponentInstance = wrapper . getFrameworkComponentInstance ( ) ; return frameworkComponentInstance [ name ] . apply ( componentInstance , args ) ; } public addMethod ( name , callback ) { ( wrapper as any ) [ name ] = callback ; } public overrideProcessing ( methodName ) { return that . parent ! . autoParamsRefresh && methodName === 'refresh' ; } public processMethod ( methodName , args ) { if ( methodName === 'refresh' ) { this . getFrameworkComponentInstance ( ) . params = args [ 0 ] ; } if ( this . hasMethod ( methodName ) ) { return this . callMethod ( methodName , args ) ; } return methodName === 'refresh' ; } protected createComponent ( params ) { return that . createComponent ( component , params ) ; } } const wrapper = new DynamicComponent ( ) ; return wrapper ; } public createComponent < T > ( component , params ) { return VueComponentFactory . createAndMountComponent ( component , params , this . parent ! ) ; } protected createMethodProxy ( wrapper , methodName , mandatory ) { return function ( ) { if ( wrapper . overrideProcessing ( methodName ) ) { return wrapper . processMethod ( methodName , arguments ) ; } if ( wrapper . hasMethod ( methodName ) ) { return wrapper . callMethod ( methodName , arguments ) ; } if ( mandatory ) { console . warn ( 'AG Grid: Framework component is missing the method ' + methodName + '()' ) ; } return null ; } ; } protected destroy ( ) { this . parent = null ; } } abstract class VueComponent < P , T > { private componentInstance : any ; private element ! : HTMLElement ; private unmount : any ; public getGui ( ) { return this . element ; } public destroy ( ) { if ( this . getFrameworkComponentInstance ( ) && typeof this . getFrameworkComponentInstance ( ) . destroy === 'function' ) { this . getFrameworkComponentInstance ( ) . destroy ( ) ; } this . unmount ( ) ; } public getFrameworkComponentInstance ( ) { return this . componentInstance ; } protected init ( params ) { const { componentInstance , element , destroy : unmount } = this . createComponent ( params ) ; this . componentInstance = componentInstance ; this . unmount = unmount ; this . element = element . firstElementChild ; } protected abstract createComponent ( params ) ; }