(props: ExplorerProps)
| 466 | * @returns The tree view. |
| 467 | */ |
| 468 | export default function Explorer(props: ExplorerProps) { |
| 469 | const theme = useTheme() |
| 470 | const css = useQueryDevtoolsContext().shadowDOMTarget |
| 471 | ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget }) |
| 472 | : goober.css |
| 473 | const styles = createMemo(() => { |
| 474 | return theme() === 'dark' ? darkStyles(css) : lightStyles(css) |
| 475 | }) |
| 476 | const queryClient = useQueryDevtoolsContext().client |
| 477 | |
| 478 | const [expanded, setExpanded] = createSignal( |
| 479 | (props.defaultExpanded || []).includes(props.label), |
| 480 | ) |
| 481 | const hasSearchMatchingChild = () => |
| 482 | !!props.search && |
| 483 | [...props.search.match.children.values()].some((child) => child.hasMatch) |
| 484 | const isExpanded = () => expanded() || hasSearchMatchingChild() |
| 485 | const toggleExpanded = () => { |
| 486 | if (!hasSearchMatchingChild()) setExpanded((old) => !old) |
| 487 | } |
| 488 | const [expandedPages, setExpandedPages] = createSignal<Array<number>>([]) |
| 489 | const nativeObjectType = createMemo(() => getNativeObjectType(props.value)) |
| 490 | const childrenEditable = createMemo( |
| 491 | () => |
| 492 | props.editable && |
| 493 | (Array.isArray(props.value) || |
| 494 | nativeObjectType() === 'Map' || |
| 495 | nativeObjectType() === 'Set' || |
| 496 | isPlainObject(props.value)), |
| 497 | ) |
| 498 | |
| 499 | const subEntries = createMemo(() => { |
| 500 | if (props.search) { |
| 501 | return props.search.match.kind === 'branch' |
| 502 | ? (searchEntries(props.value) ?? []) |
| 503 | : [] |
| 504 | } |
| 505 | if (Array.isArray(props.value)) { |
| 506 | return props.value.map((d, i) => ({ |
| 507 | label: i.toString(), |
| 508 | key: i.toString(), |
| 509 | value: d, |
| 510 | })) |
| 511 | } else if (nativeObjectType() === 'Map') { |
| 512 | return Array.from( |
| 513 | Map.prototype.entries.call(props.value), |
| 514 | ([key, val]) => ({ |
| 515 | label: primitiveText(key) ?? '[Object key]', |
| 516 | key, |
| 517 | value: val, |
| 518 | }), |
| 519 | ) |
| 520 | } else if (nativeObjectType() === 'Set') { |
| 521 | return Array.from(Set.prototype.values.call(props.value), (val, i) => ({ |
| 522 | label: i.toString(), |
| 523 | key: i.toString(), |
| 524 | value: val, |
| 525 | })) |
nothing calls this directly
no test coverage detected