(
props: ExplorerProps & { searchKey?: unknown; initialSearch?: string },
)
| 282 | * @returns The search controls and the original data tree. |
| 283 | */ |
| 284 | export function SearchableExplorer( |
| 285 | props: ExplorerProps & { searchKey?: unknown; initialSearch?: string }, |
| 286 | ) { |
| 287 | const theme = useTheme() |
| 288 | const css = useQueryDevtoolsContext().shadowDOMTarget |
| 289 | ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget }) |
| 290 | : goober.css |
| 291 | const styles = createMemo(() => |
| 292 | theme() === 'dark' ? darkStyles(css) : lightStyles(css), |
| 293 | ) |
| 294 | const [term, setTerm] = createSignal('') |
| 295 | const [debouncedTerm, setDebouncedTerm] = createSignal('') |
| 296 | const clear = () => { |
| 297 | setTerm('') |
| 298 | setDebouncedTerm('') |
| 299 | } |
| 300 | const searchKey = createMemo(() => props.searchKey) |
| 301 | createEffect( |
| 302 | on(searchKey, () => { |
| 303 | const initial = props.initialSearch ?? '' |
| 304 | setTerm(initial) |
| 305 | setDebouncedTerm(initial.toLowerCase()) |
| 306 | }), |
| 307 | ) |
| 308 | createEffect(() => { |
| 309 | const next = term().toLowerCase() |
| 310 | if (!next) { |
| 311 | setDebouncedTerm('') |
| 312 | return |
| 313 | } |
| 314 | const timeout = setTimeout(() => setDebouncedTerm(next), 150) |
| 315 | onCleanup(() => clearTimeout(timeout)) |
| 316 | }) |
| 317 | const search = createMemo<ExplorerSearch | undefined>(() => { |
| 318 | const activeTerm = debouncedTerm() |
| 319 | return activeTerm |
| 320 | ? { term: activeTerm, match: searchExplorer(props.value, activeTerm) } |
| 321 | : undefined |
| 322 | }) |
| 323 | const highlightName = `tsqd-data-search-${createUniqueId()}` |
| 324 | const [nativeHighlight, setNativeHighlight] = createSignal<Highlight>() |
| 325 | let root!: HTMLDivElement |
| 326 | onMount(() => { |
| 327 | const view = root.ownerDocument.defaultView! |
| 328 | const registry = view.CSS.highlights |
| 329 | createEffect( |
| 330 | on(search, () => { |
| 331 | const highlight = new view.Highlight() |
| 332 | registry.set(highlightName, highlight) |
| 333 | setNativeHighlight(highlight) |
| 334 | onCleanup(() => { |
| 335 | registry.delete(highlightName) |
| 336 | highlight.clear() |
| 337 | }) |
| 338 | }), |
| 339 | ) |
| 340 | }) |
| 341 | const nativeHighlightStyle = createMemo( |
nothing calls this directly
no test coverage detected