Search in my panel
The kit's search ranks any list by weighted keys, a typo's nearest last, with the letters that matched: in an editor panel, a shop of your own, a help screen.
tsx
// in src/editor/spells.tsx
import type { EditorPanelDef, EditorPanelProps } from '@v12-engine/editor'
import { Highlight } from '@v12-engine/client/kit'
import { createMemo, For } from 'solid-js'
function SpellsPanel(props: EditorPanelProps) {
const filter = props.panel.filter({ placeholder: 'Find a spell: flash, #movement' }) // Ctrl+F or / in the panel
const spells = createMemo(() => props.editor.registry.abilities.all())
// the best first, a typo's nearest last (`flsh` finds Flash), by name first, then id, then tags
const shown = createMemo(() => filter.find(spells(), [{ name: 'name', weight: 3 }, 'id', { name: 'tags', weight: 2 }]))
return (
<div class='grid gap-1 p-2'>
<filter.Field />
<For each={shown()}>
{(hit) => (
<div>
<Highlight text={hit.item.name} query={filter()} /> <span class='opacity-60'>{hit.item.tags?.join(', ')}</span>
</div>
)}
</For>
</div>
)
}
export const spellsPanel: EditorPanelDef = { id: 'mygame.spells', name: 'Spells', side: 'right', component: SpellsPanel, searchFuzzy: true }Done: a Spells panel with a search field that finds Flash from flsh, marks the letters it matched, and lists the rest by how well they match. filter({ fuzzy: false }) takes the words as typed (for codes and paths, where a near miss is another thing).
Outside the editor
ts
import { createSearch, searchItems } from '@v12-engine/client/kit'
const search = createSearch(spells, { keys: [{ name: 'name', weight: 3 }, 'id', { name: 'description', words: true }], limit: 20 })
search.search('brnd') // hits: { item, rank, matches }
searchItems(registry, '#crit blade', { tier: 'legendary' }) // items by name, stats, tags and callings; #tag the tag alonekit.highlight(text, ranges) marks the letters in plain DOM. Search has the ranks, the options and where the search runs; Make an editor panel the rest of a panel.