import {NOOP} from '@vue/shared' import type {App} from 'vue' import type {SFCInstallWithContext, SFCWithInstall} from './typescript' // 单个 export const withInstall = >( main: T, extra?: E ) => { ;(main as SFCWithInstall).install = (app): 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 } // group组 export const withNoopInstall = (component: T) => { ;(component as SFCWithInstall).install = NOOP return component as SFCWithInstall } 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 }*/