UNPKG

bootstrap-vue-next

Version:

BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.

1 lines 5.99 kB
{"version":3,"file":"index-ccPEtOvp.mjs","sources":["../src/resolvers/index.ts"],"sourcesContent":["import type {ComponentResolver} from 'unplugin-vue-components'\nimport {\n componentNames,\n componentsWithExternalPath,\n type ComponentType,\n type ConfigurationOption,\n directiveNames,\n directivesWithExternalPath,\n type DirectiveType,\n} from '../types/BootstrapVueOptions'\n\nconst bvKey = 'bootstrap-vue-next'\n\nconst parseActiveImports = <Type extends string, Base extends ConfigurationOption<Type>>(\n options: Readonly<Base>,\n values: readonly Type[]\n): Type[] => {\n const {all, ...others} = options\n const valuesCopy: Partial<Record<keyof Base, boolean>> = {}\n if (all) {\n values.forEach((el) => {\n valuesCopy[el] = all\n })\n }\n const merge: Record<string, boolean> = {...valuesCopy, ...others}\n return (\n Object.entries(merge)\n // filtering possible invalid keys\n .filter(([name, value]) => !!value && values.includes(name as Type))\n .map(([name]) => name as Type)\n )\n}\n\nconst usedComponents = new Set<string>()\nconst usedDirectives = new Set<string>()\n\n/**\n * Resolver for unplugin-vue-components\n *\n * Contains two hidden properties `__usedComponents` and `__usedDirectives` (both are `Set<string>`)\n * which are used to get the list of used components and directives.. You can use this list of used components.\n * It may not be fully accurate. It can be used to get a list of stuff to trim down, like css\n * @example\n * ```ts\n * const bootstrapVueNextResolver = BootstrapVueNextResolver()\n * console.info(bootstrapVueNextResolver.__usedComponents)\n * console.info(bootstrapVueNextResolver.__usedDirectives)\n *\n * // ... blah blah blah, `plugins: [Components({resolvers: [bootstrapVueNextResolver]})]` ...\n * ```\n */\nexport const BootstrapVueNextResolver = Object.assign(\n ({\n aliases = {},\n directives = true,\n components = true,\n }: Readonly<{\n components?: boolean | ConfigurationOption<ComponentType>\n directives?: boolean | ConfigurationOption<DirectiveType>\n aliases?: Record<string, ComponentType>\n }> = {}): ComponentResolver[] => {\n const selectedComponents = typeof components === 'boolean' ? {all: components} : components\n // <ComponentType, ImportPath>\n const compImports = parseActiveImports(selectedComponents, componentNames).reduce(\n (map, name) => {\n map.set(name, `${bvKey}${componentsWithExternalPath[name]}`)\n return map\n },\n new Map<string, string>()\n )\n\n const selectedDirectives = typeof directives === 'boolean' ? {all: directives} : directives\n // <DirectiveType, ImportPath>\n const dirImports = parseActiveImports(selectedDirectives, directiveNames).reduce(\n (map, directive) => {\n const key = (\n directive.toLowerCase().startsWith('v') ? directive : `v${directive}`\n ) as DirectiveType\n map.set(key, `${bvKey}${directivesWithExternalPath[key]}`)\n return map\n },\n new Map<string, string>()\n )\n\n const resolvers: ComponentResolver[] = [\n {\n type: 'component',\n resolve(name) {\n const destination = compImports.get(name)\n const aliasDestination = compImports.get(aliases[name])\n if (aliasDestination) {\n const val = aliases[name]\n usedComponents.add(val)\n return {\n name: val,\n from: aliasDestination,\n }\n }\n\n if (destination) {\n usedComponents.add(name)\n return {\n name,\n from: destination,\n }\n }\n },\n },\n {\n type: 'directive',\n resolve(name) {\n const prefixedName = `v${name}`\n const destination = dirImports.get(prefixedName)\n if (destination) {\n usedDirectives.add(prefixedName)\n return {\n name: prefixedName,\n from: destination,\n }\n }\n },\n },\n ]\n return resolvers\n },\n {\n __usedComponents: usedComponents,\n __usedDirectives: usedDirectives,\n }\n)\n"],"names":[],"mappings":";AAWA,MAAM,QAAQ;AAEd,MAAM,qBAAqB,CACzB,SACA,WACW;AACX,QAAM,EAAC,KAAK,GAAG,OAAA,IAAU;AACzB,QAAM,aAAmD,CAAA;AACzD,MAAI,KAAK;AACP,WAAO,QAAQ,CAAC,OAAO;AACrB,iBAAW,EAAE,IAAI;AAAA,IACnB,CAAC;AAAA,EACH;AACA,QAAM,QAAiC,EAAC,GAAG,YAAY,GAAG,OAAA;AAC1D,SACE,OAAO,QAAQ,KAAK,EAEjB,OAAO,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,SAAS,OAAO,SAAS,IAAY,CAAC,EAClE,IAAI,CAAC,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