Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve component matching #102

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading