UNPKG

@fast-china/utils

Version:

Fast 工具库.

1 lines 1.73 kB
{"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":[],"mappings":"AAKA,MAAM,OAAO,MAAY;AAAC;AAEb,MAAA,cAAc,CAAmC,MAAS,UAAqC;AAC1G,OAA2B,UAAU,CAAC,QAAc;AACzC,eAAA,QAAQ,CAAC,MAAM,GAAG,OAAO,OAAO,SAAS,CAAE,CAAA,CAAC,GAAG;AACrD,UAAA,UAAU,KAAK,MAAM,IAAI;AAAA,IAAA;AAAA,EAE/B;AAEA,MAAI,OAAO;AACV,eAAW,CAAC,KAAK,IAAI,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC/C,WAAa,GAAG,IAAI;AAAA,IAAA;AAAA,EACtB;AAEM,SAAA;AACR;AAEa,MAAA,kBAAkB,CAAI,cAAoC;AACrE,YAAgC,UAAU;AAEpC,SAAA;AACR;AAEa,MAAA,uBAAuB,CAAsB,WAAc,SAAoC;AAC1G,YAAgC,UAAU,CAAC,QAAmB;AAC1D,QAAA,UAAU,MAAM,SAAS;AAAA,EAC9B;AAEO,SAAA;AACR;"}