@fast-china/utils
Version:
Fast 工具库.
1 lines • 1.74 kB
Source Map (JSON)
{"version":3,"file":"install.mjs","sources":["../../../../src/vue/install.ts"],"sourcesContent":["import type { App, Directive, Plugin } from \"vue\";\n\nexport type TSXWithInstall<T> = T & Plugin;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nconst NOOP = (): void => {};\n\nexport const withInstall = <T, E extends Record<string, any>>(main: T, extra?: E): TSXWithInstall<T> & E => {\n\t(main as TSXWithInstall<T>).install = (app): void => {\n\t\tfor (const comp of [main, ...Object.values(extra ?? {})]) {\n\t\t\tapp.component(comp.name, comp);\n\t\t}\n\t};\n\n\tif (extra) {\n\t\tfor (const [key, comp] of Object.entries(extra)) {\n\t\t\t(main as any)[key] = comp;\n\t\t}\n\t}\n\treturn main as TSXWithInstall<T> & E;\n};\n\nexport const withNoopInstall = <T>(component: T): TSXWithInstall<T> => {\n\t(component as TSXWithInstall<T>).install = NOOP;\n\n\treturn component as TSXWithInstall<T>;\n};\n\nexport const withInstallDirective = <T extends Directive>(directive: T, name: string): TSXWithInstall<T> => {\n\t(directive as TSXWithInstall<T>).install = (app: App): void => {\n\t\tapp.directive(name, directive);\n\t};\n\n\treturn directive as TSXWithInstall<T>;\n};\n"],"names":["NOOP","withInstall","main","extra","install","app","comp","Object","values","component","name","key","entries","withNoopInstall","withInstallDirective","directive"],"mappings":"AAKA,MAAMA,EAAO,OAEAC,EAAc,CAAmCC,EAASC,KAOtE,GANCD,EAA2BE,QAAWC,IACtC,IAAA,MAAWC,IAAQ,CAACJ,KAASK,OAAOC,OAAOL,GAAS,CAAA,IACnDE,EAAII,UAAUH,EAAKI,KAAMJ,IAIvBH,EACH,IAAA,MAAYQ,EAAKL,KAASC,OAAOK,QAAQT,GACvCD,EAAaS,GAAOL,EAGvB,OAAOJ,GAGKW,EAAsBJ,IACjCA,EAAgCL,QAAUJ,EAEpCS,GAGKK,EAAuB,CAAsBC,EAAcL,KACtEK,EAAgCX,QAAWC,IAC3CA,EAAIU,UAAUL,EAAMK,IAGdA"}