From 65b6d415b72092e8ab22372923472c7eb7620682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Thu, 2 Nov 2023 15:56:24 +0100 Subject: [PATCH] fix: find collection properly when icon component includes `:` (#320) * fix: find collection properly when icon includes `:` * chore: cleanup --- examples/vite-vue3/App.vue | 1 + examples/vite-vue3/components.d.ts | 2 +- src/resolver.ts | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/vite-vue3/App.vue b/examples/vite-vue3/App.vue index 6225e327..83c2b727 100644 --- a/examples/vite-vue3/App.vue +++ b/examples/vite-vue3/App.vue @@ -16,6 +16,7 @@ import RawMdiAlarmOff3 from 'virtual:icons/mdi/alarm-off?raw&width=unset&height= + diff --git a/examples/vite-vue3/components.d.ts b/examples/vite-vue3/components.d.ts index 37315d1a..f1120bd8 100644 --- a/examples/vite-vue3/components.d.ts +++ b/examples/vite-vue3/components.d.ts @@ -11,6 +11,7 @@ declare module 'vue' { ICustomCarA: typeof import('~icons/custom/car-a')['default'] ICustomSteeringWheel: typeof import('~icons/custom/steering-wheel')['default'] IFaSolidDiceFive: typeof import('~icons/fa-solid/dice-five')['default'] + 'IHeroiconsOutline:menuAlt2': typeof import('~icons/heroicons-outline/menu-alt2')['default'] IHeroiconsOutlineMenuAlt2: typeof import('~icons/heroicons-outline/menu-alt2')['default'] IIconParkAbnormal: typeof import('~icons/icon-park/abnormal')['default'] IIcTwotone23mp: typeof import('~icons/ic/twotone23mp')['default'] @@ -23,7 +24,6 @@ declare module 'vue' { IMdiAccount: typeof import('~icons/mdi/account')['default'] IMdiDiceD12: typeof import('~icons/mdi/dice-d12')['default'] IMdiLightAlarm: typeof import('~icons/mdi-light/alarm')['default'] - IMdiLightFloodDown: typeof import('~icons/mdi-light/flood-down')['default'] INotoV1FlagForFlagJapan: typeof import('~icons/noto-v1/flag-for-flag-japan')['default'] IParkAbnormal: typeof import('~icons/icon-park/abnormal')['default'] IRiApps2Line: typeof import('~icons/ri/apps2-line')['default'] diff --git a/src/resolver.ts b/src/resolver.ts index c321a608..c9af76a3 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -86,15 +86,14 @@ export default function ComponentsResolver(options: ComponentResolverOption = {} return const slice = collection.slice(prefix.length) - const resolvedCollection = collections.find(i => slice.startsWith(`${i}-`)) || collections.find(i => slice.startsWith(i)) + // find the collection + const resolvedCollection = collections.find(i => slice === i) if (!resolvedCollection) return collection = resolvedCollection icon = camelToKebab(iconSuffix) - if (icon[0] === '-') - icon = icon.slice(1) } else { const kebab = camelToKebab(name) @@ -108,10 +107,11 @@ export default function ComponentsResolver(options: ComponentResolverOption = {} collection = resolvedCollection icon = slice.slice(resolvedCollection.length) - if (icon[0] === '-') - icon = icon.slice(1) } + if (icon[0] === '-') + icon = icon.slice(1) + if (!icon) return