diff --git a/auto-imports.d.ts b/auto-imports.d.ts index d9d86f1..d2bef15 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -8,6 +8,160 @@ export {} declare global { const APP_THEME_MODES: typeof import('./src/stores/app-store')['APP_THEME_MODES'] const EffectScope: typeof import('vue')['EffectScope'] + const NA: typeof import('naive-ui')['NA'] + const NAffix: typeof import('naive-ui')['NAffix'] + const NAlert: typeof import('naive-ui')['NAlert'] + const NAnchor: typeof import('naive-ui')['NAnchor'] + const NAnchorLink: typeof import('naive-ui')['NAnchorLink'] + const NAutoComplete: typeof import('naive-ui')['NAutoComplete'] + const NAvatar: typeof import('naive-ui')['NAvatar'] + const NAvatarGroup: typeof import('naive-ui')['NAvatarGroup'] + const NBackTop: typeof import('naive-ui')['NBackTop'] + const NBadge: typeof import('naive-ui')['NBadge'] + const NBlockquote: typeof import('naive-ui')['NBlockquote'] + const NBreadcrumb: typeof import('naive-ui')['NBreadcrumb'] + const NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem'] + const NButton: typeof import('naive-ui')['NButton'] + const NButtonGroup: typeof import('naive-ui')['NButtonGroup'] + const NCalendar: typeof import('naive-ui')['NCalendar'] + const NCard: typeof import('naive-ui')['NCard'] + const NCarousel: typeof import('naive-ui')['NCarousel'] + const NCarouselItem: typeof import('naive-ui')['NCarouselItem'] + const NCascader: typeof import('naive-ui')['NCascader'] + const NCheckbox: typeof import('naive-ui')['NCheckbox'] + const NCheckboxGroup: typeof import('naive-ui')['NCheckboxGroup'] + const NCode: typeof import('naive-ui')['NCode'] + const NCol: typeof import('naive-ui')['NCol'] + const NCollapse: typeof import('naive-ui')['NCollapse'] + const NCollapseItem: typeof import('naive-ui')['NCollapseItem'] + const NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] + const NColorPicker: typeof import('naive-ui')['NColorPicker'] + const NConfigProvider: typeof import('naive-ui')['NConfigProvider'] + const NCountdown: typeof import('naive-ui')['NCountdown'] + const NDataTable: typeof import('naive-ui')['NDataTable'] + const NDatePicker: typeof import('naive-ui')['NDatePicker'] + const NDescriptions: typeof import('naive-ui')['NDescriptions'] + const NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem'] + const NDialog: typeof import('naive-ui')['NDialog'] + const NDialogProvider: typeof import('naive-ui')['NDialogProvider'] + const NDivider: typeof import('naive-ui')['NDivider'] + const NDrawer: typeof import('naive-ui')['NDrawer'] + const NDrawerContent: typeof import('naive-ui')['NDrawerContent'] + const NDropdown: typeof import('naive-ui')['NDropdown'] + const NDynamicInput: typeof import('naive-ui')['NDynamicInput'] + const NDynamicTags: typeof import('naive-ui')['NDynamicTags'] + const NEl: typeof import('naive-ui')['NEl'] + const NElement: typeof import('naive-ui')['NElement'] + const NEllipsis: typeof import('naive-ui')['NEllipsis'] + const NEmpty: typeof import('naive-ui')['NEmpty'] + const NEquation: typeof import('naive-ui')['NEquation'] + const NFlex: typeof import('naive-ui')['NFlex'] + const NFloatButton: typeof import('naive-ui')['NFloatButton'] + const NFloatButtonGroup: typeof import('naive-ui')['NFloatButtonGroup'] + const NForm: typeof import('naive-ui')['NForm'] + const NFormItem: typeof import('naive-ui')['NFormItem'] + const NFormItemCol: typeof import('naive-ui')['NFormItemCol'] + const NFormItemGi: typeof import('naive-ui')['NFormItemGi'] + const NFormItemGridItem: typeof import('naive-ui')['NFormItemGridItem'] + const NFormItemRow: typeof import('naive-ui')['NFormItemRow'] + const NGi: typeof import('naive-ui')['NGi'] + const NGlobalStyle: typeof import('naive-ui')['NGlobalStyle'] + const NGradientText: typeof import('naive-ui')['NGradientText'] + const NGrid: typeof import('naive-ui')['NGrid'] + const NGridItem: typeof import('naive-ui')['NGridItem'] + const NH1: typeof import('naive-ui')['NH1'] + const NH2: typeof import('naive-ui')['NH2'] + const NH3: typeof import('naive-ui')['NH3'] + const NH4: typeof import('naive-ui')['NH4'] + const NH5: typeof import('naive-ui')['NH5'] + const NH6: typeof import('naive-ui')['NH6'] + const NHeatmap: typeof import('naive-ui')['NHeatmap'] + const NHighlight: typeof import('naive-ui')['NHighlight'] + const NHr: typeof import('naive-ui')['NHr'] + const NIcon: typeof import('naive-ui')['NIcon'] + const NIconWrapper: typeof import('naive-ui')['NIconWrapper'] + const NImage: typeof import('naive-ui')['NImage'] + const NImageGroup: typeof import('naive-ui')['NImageGroup'] + const NImagePreview: typeof import('naive-ui')['NImagePreview'] + const NInfiniteScroll: typeof import('naive-ui')['NInfiniteScroll'] + const NInput: typeof import('naive-ui')['NInput'] + const NInputGroup: typeof import('naive-ui')['NInputGroup'] + const NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel'] + const NInputNumber: typeof import('naive-ui')['NInputNumber'] + const NInputOtp: typeof import('naive-ui')['NInputOtp'] + const NLayout: typeof import('naive-ui')['NLayout'] + const NLayoutContent: typeof import('naive-ui')['NLayoutContent'] + const NLayoutFooter: typeof import('naive-ui')['NLayoutFooter'] + const NLayoutHeader: typeof import('naive-ui')['NLayoutHeader'] + const NLayoutSider: typeof import('naive-ui')['NLayoutSider'] + const NLegacyTransfer: typeof import('naive-ui')['NLegacyTransfer'] + const NLi: typeof import('naive-ui')['NLi'] + const NList: typeof import('naive-ui')['NList'] + const NListItem: typeof import('naive-ui')['NListItem'] + const NLoadingBarProvider: typeof import('naive-ui')['NLoadingBarProvider'] + const NLog: typeof import('naive-ui')['NLog'] + const NMarquee: typeof import('naive-ui')['NMarquee'] + const NMention: typeof import('naive-ui')['NMention'] + const NMenu: typeof import('naive-ui')['NMenu'] + const NMessageProvider: typeof import('naive-ui')['NMessageProvider'] + const NModal: typeof import('naive-ui')['NModal'] + const NModalProvider: typeof import('naive-ui')['NModalProvider'] + const NNotificationProvider: typeof import('naive-ui')['NNotificationProvider'] + const NNumberAnimation: typeof import('naive-ui')['NNumberAnimation'] + const NOl: typeof import('naive-ui')['NOl'] + const NP: typeof import('naive-ui')['NP'] + const NPageHeader: typeof import('naive-ui')['NPageHeader'] + const NPagination: typeof import('naive-ui')['NPagination'] + const NPerformantEllipsis: typeof import('naive-ui')['NPerformantEllipsis'] + const NPopconfirm: typeof import('naive-ui')['NPopconfirm'] + const NPopover: typeof import('naive-ui')['NPopover'] + const NPopselect: typeof import('naive-ui')['NPopselect'] + const NProgress: typeof import('naive-ui')['NProgress'] + const NQrCode: typeof import('naive-ui')['NQrCode'] + const NRadio: typeof import('naive-ui')['NRadio'] + const NRadioButton: typeof import('naive-ui')['NRadioButton'] + const NRadioGroup: typeof import('naive-ui')['NRadioGroup'] + const NRate: typeof import('naive-ui')['NRate'] + const NResult: typeof import('naive-ui')['NResult'] + const NRow: typeof import('naive-ui')['NRow'] + const NScrollbar: typeof import('naive-ui')['NScrollbar'] + const NSelect: typeof import('naive-ui')['NSelect'] + const NSkeleton: typeof import('naive-ui')['NSkeleton'] + const NSlider: typeof import('naive-ui')['NSlider'] + const NSpace: typeof import('naive-ui')['NSpace'] + const NSpin: typeof import('naive-ui')['NSpin'] + const NSplit: typeof import('naive-ui')['NSplit'] + const NStatistic: typeof import('naive-ui')['NStatistic'] + const NStep: typeof import('naive-ui')['NStep'] + const NSteps: typeof import('naive-ui')['NSteps'] + const NSwitch: typeof import('naive-ui')['NSwitch'] + const NTab: typeof import('naive-ui')['NTab'] + const NTabPane: typeof import('naive-ui')['NTabPane'] + const NTable: typeof import('naive-ui')['NTable'] + const NTabs: typeof import('naive-ui')['NTabs'] + const NTag: typeof import('naive-ui')['NTag'] + const NTbody: typeof import('naive-ui')['NTbody'] + const NTd: typeof import('naive-ui')['NTd'] + const NText: typeof import('naive-ui')['NText'] + const NTh: typeof import('naive-ui')['NTh'] + const NThead: typeof import('naive-ui')['NThead'] + const NThing: typeof import('naive-ui')['NThing'] + const NTime: typeof import('naive-ui')['NTime'] + const NTimePicker: typeof import('naive-ui')['NTimePicker'] + const NTimeline: typeof import('naive-ui')['NTimeline'] + const NTimelineItem: typeof import('naive-ui')['NTimelineItem'] + const NTooltip: typeof import('naive-ui')['NTooltip'] + const NTr: typeof import('naive-ui')['NTr'] + const NTransfer: typeof import('naive-ui')['NTransfer'] + const NTree: typeof import('naive-ui')['NTree'] + const NTreeSelect: typeof import('naive-ui')['NTreeSelect'] + const NUl: typeof import('naive-ui')['NUl'] + const NUpload: typeof import('naive-ui')['NUpload'] + const NUploadDragger: typeof import('naive-ui')['NUploadDragger'] + const NUploadFileList: typeof import('naive-ui')['NUploadFileList'] + const NUploadTrigger: typeof import('naive-ui')['NUploadTrigger'] + const NVirtualList: typeof import('naive-ui')['NVirtualList'] + const NWatermark: typeof import('naive-ui')['NWatermark'] const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate'] const arrayToTree: typeof import('utils4u/array')['arrayToTree'] const asyncComputed: typeof import('@vueuse/core')['asyncComputed'] @@ -346,6 +500,160 @@ declare module 'vue' { interface ComponentCustomProperties { readonly APP_THEME_MODES: UnwrapRef readonly EffectScope: UnwrapRef + readonly NA: UnwrapRef + readonly NAffix: UnwrapRef + readonly NAlert: UnwrapRef + readonly NAnchor: UnwrapRef + readonly NAnchorLink: UnwrapRef + readonly NAutoComplete: UnwrapRef + readonly NAvatar: UnwrapRef + readonly NAvatarGroup: UnwrapRef + readonly NBackTop: UnwrapRef + readonly NBadge: UnwrapRef + readonly NBlockquote: UnwrapRef + readonly NBreadcrumb: UnwrapRef + readonly NBreadcrumbItem: UnwrapRef + readonly NButton: UnwrapRef + readonly NButtonGroup: UnwrapRef + readonly NCalendar: UnwrapRef + readonly NCard: UnwrapRef + readonly NCarousel: UnwrapRef + readonly NCarouselItem: UnwrapRef + readonly NCascader: UnwrapRef + readonly NCheckbox: UnwrapRef + readonly NCheckboxGroup: UnwrapRef + readonly NCode: UnwrapRef + readonly NCol: UnwrapRef + readonly NCollapse: UnwrapRef + readonly NCollapseItem: UnwrapRef + readonly NCollapseTransition: UnwrapRef + readonly NColorPicker: UnwrapRef + readonly NConfigProvider: UnwrapRef + readonly NCountdown: UnwrapRef + readonly NDataTable: UnwrapRef + readonly NDatePicker: UnwrapRef + readonly NDescriptions: UnwrapRef + readonly NDescriptionsItem: UnwrapRef + readonly NDialog: UnwrapRef + readonly NDialogProvider: UnwrapRef + readonly NDivider: UnwrapRef + readonly NDrawer: UnwrapRef + readonly NDrawerContent: UnwrapRef + readonly NDropdown: UnwrapRef + readonly NDynamicInput: UnwrapRef + readonly NDynamicTags: UnwrapRef + readonly NEl: UnwrapRef + readonly NElement: UnwrapRef + readonly NEllipsis: UnwrapRef + readonly NEmpty: UnwrapRef + readonly NEquation: UnwrapRef + readonly NFlex: UnwrapRef + readonly NFloatButton: UnwrapRef + readonly NFloatButtonGroup: UnwrapRef + readonly NForm: UnwrapRef + readonly NFormItem: UnwrapRef + readonly NFormItemCol: UnwrapRef + readonly NFormItemGi: UnwrapRef + readonly NFormItemGridItem: UnwrapRef + readonly NFormItemRow: UnwrapRef + readonly NGi: UnwrapRef + readonly NGlobalStyle: UnwrapRef + readonly NGradientText: UnwrapRef + readonly NGrid: UnwrapRef + readonly NGridItem: UnwrapRef + readonly NH1: UnwrapRef + readonly NH2: UnwrapRef + readonly NH3: UnwrapRef + readonly NH4: UnwrapRef + readonly NH5: UnwrapRef + readonly NH6: UnwrapRef + readonly NHeatmap: UnwrapRef + readonly NHighlight: UnwrapRef + readonly NHr: UnwrapRef + readonly NIcon: UnwrapRef + readonly NIconWrapper: UnwrapRef + readonly NImage: UnwrapRef + readonly NImageGroup: UnwrapRef + readonly NImagePreview: UnwrapRef + readonly NInfiniteScroll: UnwrapRef + readonly NInput: UnwrapRef + readonly NInputGroup: UnwrapRef + readonly NInputGroupLabel: UnwrapRef + readonly NInputNumber: UnwrapRef + readonly NInputOtp: UnwrapRef + readonly NLayout: UnwrapRef + readonly NLayoutContent: UnwrapRef + readonly NLayoutFooter: UnwrapRef + readonly NLayoutHeader: UnwrapRef + readonly NLayoutSider: UnwrapRef + readonly NLegacyTransfer: UnwrapRef + readonly NLi: UnwrapRef + readonly NList: UnwrapRef + readonly NListItem: UnwrapRef + readonly NLoadingBarProvider: UnwrapRef + readonly NLog: UnwrapRef + readonly NMarquee: UnwrapRef + readonly NMention: UnwrapRef + readonly NMenu: UnwrapRef + readonly NMessageProvider: UnwrapRef + readonly NModal: UnwrapRef + readonly NModalProvider: UnwrapRef + readonly NNotificationProvider: UnwrapRef + readonly NNumberAnimation: UnwrapRef + readonly NOl: UnwrapRef + readonly NP: UnwrapRef + readonly NPageHeader: UnwrapRef + readonly NPagination: UnwrapRef + readonly NPerformantEllipsis: UnwrapRef + readonly NPopconfirm: UnwrapRef + readonly NPopover: UnwrapRef + readonly NPopselect: UnwrapRef + readonly NProgress: UnwrapRef + readonly NQrCode: UnwrapRef + readonly NRadio: UnwrapRef + readonly NRadioButton: UnwrapRef + readonly NRadioGroup: UnwrapRef + readonly NRate: UnwrapRef + readonly NResult: UnwrapRef + readonly NRow: UnwrapRef + readonly NScrollbar: UnwrapRef + readonly NSelect: UnwrapRef + readonly NSkeleton: UnwrapRef + readonly NSlider: UnwrapRef + readonly NSpace: UnwrapRef + readonly NSpin: UnwrapRef + readonly NSplit: UnwrapRef + readonly NStatistic: UnwrapRef + readonly NStep: UnwrapRef + readonly NSteps: UnwrapRef + readonly NSwitch: UnwrapRef + readonly NTab: UnwrapRef + readonly NTabPane: UnwrapRef + readonly NTable: UnwrapRef + readonly NTabs: UnwrapRef + readonly NTag: UnwrapRef + readonly NTbody: UnwrapRef + readonly NTd: UnwrapRef + readonly NText: UnwrapRef + readonly NTh: UnwrapRef + readonly NThead: UnwrapRef + readonly NThing: UnwrapRef + readonly NTime: UnwrapRef + readonly NTimePicker: UnwrapRef + readonly NTimeline: UnwrapRef + readonly NTimelineItem: UnwrapRef + readonly NTooltip: UnwrapRef + readonly NTr: UnwrapRef + readonly NTransfer: UnwrapRef + readonly NTree: UnwrapRef + readonly NTreeSelect: UnwrapRef + readonly NUl: UnwrapRef + readonly NUpload: UnwrapRef + readonly NUploadDragger: UnwrapRef + readonly NUploadFileList: UnwrapRef + readonly NUploadTrigger: UnwrapRef + readonly NVirtualList: UnwrapRef + readonly NWatermark: UnwrapRef readonly acceptHMRUpdate: UnwrapRef readonly arrayToTree: UnwrapRef readonly asyncComputed: UnwrapRef diff --git a/src/pages/demos/index.page.vue b/src/pages/demos/index.page.vue index 4a8a117..b1f7c04 100644 --- a/src/pages/demos/index.page.vue +++ b/src/pages/demos/index.page.vue @@ -5,13 +5,7 @@ import hljs from 'highlight.js/lib/core'; import json from 'highlight.js/lib/languages/json'; hljs.registerLanguage('json', json); -definePage({ - meta: { - link: true, - title: 'Functional Component Demo', - }, -}); - +definePage({ meta: { link: true } }); const FComponent: FunctionalComponent<{ prop: string }> = (props /* context */) => ( <> diff --git a/vite-plugins/02.unplugin-auto-import.ts b/vite-plugins/02.unplugin-auto-import.ts index e609d63..f9db85a 100644 --- a/vite-plugins/02.unplugin-auto-import.ts +++ b/vite-plugins/02.unplugin-auto-import.ts @@ -22,7 +22,38 @@ import IconsResolver from 'unplugin-icons/resolver'; import { VantResolver } from '@vant/auto-import-resolver'; // <<<<< -export async function loadPlugin(_configEnv: ConfigEnv): Promise { + +import fs from 'node:fs'; +import path from 'node:path'; + +function _getNaiveUiComponentNames() { + // 方法1: 从 web-types.json 读取(推荐) + const webTypesPath = path.resolve('node_modules/naive-ui/web-types.json'); + if (fs.existsSync(webTypesPath)) { + const webTypes = JSON.parse(fs.readFileSync(webTypesPath, 'utf-8')); + const components = webTypes.contributions.html['vue-components']; + const componentNames = components.map((component: { name: string }) => component.name); + console.log('naive-ui components count (from web-types.json):', componentNames.length); + return componentNames; + } + + // 方法2: 从 volar.d.ts 读取(备选) + const volarPath = path.resolve('node_modules/naive-ui/volar.d.ts'); + if (fs.existsSync(volarPath)) { + const volarContent = fs.readFileSync(volarPath, 'utf-8'); + // 匹配类似 "NAffix: (typeof import('naive-ui'))['NAffix']" 的行 + const regex = /^\s+(N\w+):/gm; + const matches = [...volarContent.matchAll(regex)]; + const componentNames = matches.map((match) => match[1]); + console.log('naive-ui components count (from volar.d.ts):', componentNames.length); + return componentNames; + } + + console.warn('Could not find naive-ui component metadata files'); + return []; +} + +export function loadPlugin(_configEnv: ConfigEnv): PluginOption { return [ // https://github.com/antfu/unplugin-auto-import AutoImport({ @@ -43,7 +74,14 @@ export async function loadPlugin(_configEnv: ConfigEnv): Promise { { 'consola/browser': ['consola'], 'vue-router/auto': ['useLink'], - 'naive-ui': ['useModal', 'useDialog', 'useMessage', 'useNotification', 'useLoadingBar'], + 'naive-ui': [ + 'useModal', + 'useDialog', + 'useMessage', + 'useNotification', + 'useLoadingBar', + ..._getNaiveUiComponentNames(), + ], }, ], vueTemplate: true, @@ -53,7 +91,7 @@ export async function loadPlugin(_configEnv: ConfigEnv): Promise { // `__`开头的 excludeNames: [/^__/], // allow auto load markdown components under `./src/components/` - extensions: ['vue', 'md'], + extensions: ['vue', 'md', 'tsx'], // allow auto import and register components used in markdown include: [/\.vue$/, /\.vue\?vue/, /\.md$/], resolvers: [ diff --git a/vite.config.ts b/vite.config.ts index a873f49..5cd80bd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -41,7 +41,7 @@ async function loadPlugins(configEnv: ConfigEnv): Promise { // 优先使用 loadPlugin 函数(接收 configEnv 参数) if (loadPlugin && typeof loadPlugin === 'function') { - const result = await loadPlugin(configEnv); + const result = loadPlugin(configEnv); plugin = result; loadMethod = 'loadPlugin'; } else if (imported.default) {