MCPcopy Create free account
hub / github.com/TanStack/devtools / SourceInspector

Function SourceInspector

packages/devtools/src/components/source-inspector.tsx:10–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8export const SourceInspector = () => {
9 const { settings } = createDevtoolsSettings()
10 const highlightStateInit = () => ({
11 element: null as HTMLElement | null,
12 bounding: { width: 0, height: 0, left: 0, top: 0 },
13 dataSource: '',
14 })
15
16 const [highlightState, setHighlightState] = createStore(highlightStateInit())
17 const resetHighlight = () => {
18 setHighlightState(() => highlightStateInit())
19 }
20
21 const [nameTagRef, setNameTagRef] = createSignal<HTMLDivElement | null>(null)
22 const nameTagSize = createElementSize(() => nameTagRef())
23
24 const [mousePosition, setMousePosition] = createStore({ x: 0, y: 0 })
25 createEventListener(document, 'mousemove', (e) => {
26 setMousePosition((position) => {
27 position.x = e.clientX
28 position.y = e.clientY
29 })
30 })
31
32 const downList = getKeyDownList()
33
34 const [disabledAfterClick, setDisabledAfterClick] = createSignal(false)
35
36 const isHighlightingKeysHeld = createMemo(() => {
37 return isHotkeyCombinationPressed(downList(), settings().inspectHotkey)
38 })
39
40 createEffect(isHighlightingKeysHeld, (held) => {
41 if (!held) setDisabledAfterClick(false)
42 })
43
44 const isActive = createMemo(
45 () => isHighlightingKeysHeld() && !disabledAfterClick(),
46 )
47
48 createEffect(isActive, (active) => {
49 document.body.style.cursor = active ? 'pointer' : ''
50 })
51
52 createEffect(
53 () => (isActive() ? { x: mousePosition.x, y: mousePosition.y } : null),
54 (point) => {
55 if (!point) {
56 resetHighlight()
57 return
58 }
59
60 const target = document.elementFromPoint(point.x, point.y)
61
62 if (!(target instanceof HTMLElement)) {
63 resetHighlight()
64 return
65 }
66
67 if (target === highlightState.element) {

Callers

nothing calls this directly

Calls 4

createDevtoolsSettingsFunction · 0.90
highlightStateInitFunction · 0.85
resetHighlightFunction · 0.85

Tested by

no test coverage detected