Skip to content

Commit

Permalink
feat: Improve component matching (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolking authored Apr 20, 2024
1 parent 391a6b1 commit 7e9f9d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export const libraryName = 'element-plus'

export const iconLibraryName = '@element-plus/icons-vue'

const allComponents = Object.values(AllComponents).reduce<string[]>((all, item) => {
if (isVueComponent(item) && /^El[A-Z]\w+/.test((item as Component).name ?? '')) {
all.push((item as Component).name!)
const allComponents = Object.entries(AllComponents).reduce<string[]>((all, [key, item]) => {
const regExp = /^El[A-Z]\w+/
if (isVueComponent(item) && regExp.test(key) && regExp.test((item as Component).name ?? '')) {
all.push(key)
}
return all
}, [] as string[])
}, [])

export const allIcons = Object.keys(AllIcons)

Expand All @@ -29,6 +30,8 @@ const allImports: PresetImport[] = allImportsWithStyle

const allNoStylesComponents: string[] = [
'ElAutoResizer',
'ElCollection',
'ElCollectionItem',
'ElTooltipV2'
]

Expand All @@ -45,11 +48,13 @@ const allSubComponents: Record<string, string[]> = {
ElCarousel: ['ElCarouselItem'],
ElCheckbox: ['ElCheckboxButton', 'ElCheckboxGroup'],
ElCollapse: ['ElCollapseItem'],
ElCollection: ['ElCollectionItem'],
ElContainer: ['ElAside', 'ElFooter', 'ElHeader', 'ElMain'],
ElDescriptions: ['ElDescriptionsItem'],
ElDropdown: ['ElDropdownItem', 'ElDropdownMenu'],
ElForm: ['ElFormItem'],
ElMenu: ['ElMenuItem', 'ElMenuItemGroup', 'ElSubMenu'],
ElPopper: ['ElPopperArrow', 'ElPopperContent', 'ElPopperTrigger'],
ElRadio: ['ElRadioGroup', 'ElRadioButton'],
ElSkeleton: ['ElSkeletonItem'],
ElSelect: ['ElOption', 'ElOptionGroup'],
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function isArray (value: any): value is any[] {
}

export function isVueComponent (value: any): value is Component {
return typeof value === 'object' && (value.name || value.props || value.emits || value.setup || value.render)
return typeof value === 'object' && value.name && (value.props || value.emits || value.setup || value.render)
}

export function toArray<T extends any | any[]> (
Expand Down

0 comments on commit 7e9f9d4

Please sign in to comment.