feat: remove lodash-es (#648)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Younes Barrad
2023-09-14 17:47:09 +01:00
committed by GitHub
parent 5fc44b97c6
commit d6476d17f9
39 changed files with 173 additions and 91 deletions

View File

@@ -68,7 +68,7 @@ import type { ComputedRef, PropType, ComponentPublicInstance } from 'vue'
import { useDebounceFn } from '@vueuse/core'
import { useFuse } from '@vueuse/integrations/useFuse'
import { twMerge, twJoin } from 'tailwind-merge'
import { groupBy, map, omit } from 'lodash-es'
import { omit } from '../../utils/lodash'
import { defu } from 'defu'
import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
import type { Group, Command } from '../../types/command-palette'
@@ -214,32 +214,50 @@ export default defineComponent({
matchAllWhenSearchEmpty: true
}))
const commands = computed(() => props.groups.filter(group => !group.search).reduce((acc, group) => {
return acc.concat(group.commands.map(command => ({ ...command, group: group.key })))
}, [] as Command[]))
const commands = computed(() => {
const commands: Command[] = []
for (const group of props.groups) {
if (!group.search) {
commands.push(...group.commands.map(command => ({ ...command, group: group.key })))
}
}
return commands
})
const searchResults = ref<{ [key: string]: any }>({})
const { results } = useFuse(query, commands, options)
const groups = computed(() => ([
...map(groupBy(results.value, command => command.item.group), (results, key) => {
const commands = results.map((result) => {
const groups = computed(() => {
const groups: Group[] = []
const groupedCommands: Record<string, typeof results['value']> = {}
for (const command of results.value) {
groupedCommands[command.item.group] ||= []
groupedCommands[command.item.group].push(command)
}
for (const key in groupedCommands) {
const group = props.groups.find(group => group.key === key)
const commands = groupedCommands[key].slice(0, options.value.resultLimit).map((result) => {
const { item, ...data } = result
return {
...item,
...data
}
} as Command
})
return {
...props.groups.find(group => group.key === key),
commands: commands.slice(0, options.value.resultLimit)
} as Group
}),
...props.groups.filter(group => !!group.search).map(group => ({ ...group, commands: (searchResults.value[group.key] || []).slice(0, options.value.resultLimit) })).filter(group => group.commands.length)
]))
groups.push({ ...group, commands })
}
for (const group of props.groups) {
if (group.search && searchResults.value[group.key]?.length) {
groups.push({ ...group, commands: (searchResults.value[group.key] || []).slice(0, options.value.resultLimit) })
}
}
return groups
})
const debouncedSearch = useDebounceFn(async () => {
const searchableGroups = props.groups.filter(group => !!group.search)

View File

@@ -42,7 +42,7 @@
<script lang="ts">
import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue'
import { omit } from 'lodash-es'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UButton from '../elements/Button.vue'
import { defuTwMerge } from '../../utils'

View File

@@ -52,7 +52,7 @@ import { ref, computed, watch, onMounted, defineComponent } from 'vue'
import type { PropType } from 'vue'
import { TabGroup as HTabGroup, TabList as HTabList, Tab as HTab, TabPanels as HTabPanels, TabPanel as HTabPanel } from '@headlessui/vue'
import { useResizeObserver } from '@vueuse/core'
import { omit } from 'lodash-es'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import { defuTwMerge } from '../../utils'
import type { TabItem } from '../../types/tabs'

View File

@@ -40,7 +40,7 @@
<script lang="ts">
import { computed, defineComponent } from 'vue'
import type { PropType } from 'vue'
import { omit } from 'lodash-es'
import { omit } from '../../utils/lodash'
import { twMerge } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue'