feat(InputMenu): new component (#86)

This commit is contained in:
Benjamin Canac
2024-05-06 18:59:49 +02:00
committed by GitHub
parent f409395297
commit 99f20a4154
59 changed files with 3345 additions and 1265 deletions

View File

@@ -1,4 +1,4 @@
import type { FuseResultMatch } from 'fuse.js'
import type { FuseResult, FuseResultMatch } from 'fuse.js'
function truncateHTMLFromStart(html: string, maxLength: number) {
let truncated = ''
@@ -32,7 +32,7 @@ function truncateHTMLFromStart(html: string, maxLength: number) {
return truncated
}
export function highlight(item: { matches?: FuseResultMatch[] }, searchTerm: string, forceKey?: string, omitKeys?: string[]) {
export function highlight<T>(item: T & { matches?: FuseResult<T>['matches'] }, searchTerm: string, forceKey?: string, omitKeys?: string[]) {
const generateHighlightedText = (value: FuseResultMatch['value'], indices: FuseResultMatch['indices'] = []) => {
value = value || ''
let content = ''

View File

@@ -19,6 +19,27 @@ export function omit<Data extends object, Keys extends keyof Data>(data: Data, k
return result as Omit<Data, Keys>
}
export function get(object: Record<string, any>, path: (string | number)[] | string, defaultValue?: any): any {
if (typeof path === 'string') {
path = path.split('.').map((key) => {
const numKey = Number(key)
return Number.isNaN(numKey) ? key : numKey
})
}
let result: any = object
for (const key of path) {
if (result === undefined || result === null) {
return defaultValue
}
result = result[key]
}
return result !== undefined ? result : defaultValue
}
export function looseToNumber(val: any): any {
const n = Number.parseFloat(val)
return Number.isNaN(n) ? val : n