123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- export interface AntDesignXResolverOptions {
- /**
- * exclude components that do not require automatic import
- *
- * @default []
- */
- exclude?: string[]
- /**
- * rename package
- *
- * @default 'ant-design-x-vue'
- */
- packageName?: string
- /**
- * customizable prefix for resolving components
- *
- * @default 'AX'
- */
- prefix?: string
- }
- /**
- * set of components that are contained in the package
- */
- const primitiveNames = new Set<string>([
- 'Attachments',
- 'Bubble',
- 'Conversations',
- 'Prompts',
- 'Sender',
- 'Suggestion',
- 'Theme',
- 'ThoughtChain',
- 'Welcome',
- ])
- function isAntdXVueComponent(name: string) {
- return primitiveNames.has(name)
- }
- // currently unnecessary to add side effects
- // function getSideEffects(
- // componentName: string,
- // options: AntDesignXResolverOptions = {}
- // ) {
- // const { importStyle = true, packageName = 'ant-design-x-vue' } = options
- // if (!importStyle) return
- // return
- // }
- export function AntDesignXVueResolver(
- options: AntDesignXResolverOptions = {}
- ) {
- const {
- prefix = 'AX',
- packageName = 'ant-design-x-vue',
- exclude = []
- } = options
- const resolverInfo = {
- type: 'component',
- resolve: (name: string) => {
- if (!name.startsWith(prefix)) return
- const componentName = name.slice(prefix.length)
- if (
- !isAntdXVueComponent(componentName) || exclude.includes(componentName)
- ) return
- return {
- name: componentName,
- from: packageName,
- as: `${prefix}${componentName}`
- }
- }
- }
- return resolverInfo.resolve
- }
|