import { noop } from '@google-translate-select/utils' import type { App, AppContext, Directive, Plugin } from 'vue' export type SFCWithInstall = T & Plugin export type SFCInstallWithContext = SFCWithInstall & { _context: AppContext | null } export const withInstall = >( main: T, extra?: E ) => { ;(main as SFCWithInstall).install = (app: any): void => { for (const comp of [main, ...Object.values(extra ?? {})]) { app.component(comp.name, comp) } } if (extra) { for (const [key, comp] of Object.entries(extra)) { ;(main as any)[key] = comp } } return main as SFCWithInstall & E } export const withInstallFunction = (fn: T, name: string) => { ;(fn as SFCWithInstall).install = (app: App) => { ;(fn as SFCInstallWithContext)._context = app._context app.config.globalProperties[name] = fn } return fn as SFCInstallWithContext } export const withInstallDirective = ( directive: T, name: string ) => { ;(directive as SFCWithInstall).install = (app: App): void => { app.directive(name, directive) } return directive as SFCWithInstall } export const withNoopInstall = (component: T) => { ;(component as SFCWithInstall).install = noop return component as SFCWithInstall }