@@ -8,9 +8,10 @@ const AUTO_OPEN_DEPTH = 2;
88const MAX_STRING = 80 ;
99
1010/**
11- * A clickable, syntax-colored JSON tree for the smart-column sample. Clicking a
12- * key (or array index) fills the JSON path field via `onSelectPath`; the value
13- * currently at `activePath` is highlighted.
11+ * A clickable, syntax-colored JSON tree for the smart-column sample. Only leaf
12+ * values are selectable: clicking one fills the JSON path field via
13+ * `onSelectPath` and highlights it. Object/array rows only expand and collapse,
14+ * so you drill into a container and pick a leaf inside it.
1415 */
1516export function SmartColumnSample ( {
1617 value,
@@ -59,39 +60,23 @@ function JsonNode({
5960 const [ open , setOpen ] = useState ( depth < AUTO_OPEN_DEPTH ) ;
6061 const isObject = value !== null && typeof value === "object" ;
6162 const selected = path === activePath ;
63+ const keyLabel = name === undefined ? null : typeof name === "number" ? name : `"${ name } "` ;
6264
63- const keyButton =
64- name !== undefined ? (
65- < button
66- type = "button"
67- onClick = { ( ) => onSelectPath ( path ) }
68- className = { cn (
69- "rounded px-0.5 text-sky-300 hover:bg-blue-500/20" ,
70- selected && "bg-blue-500/30 text-sky-200"
71- ) }
72- >
73- { typeof name === "number" ? name : `"${ name } "` }
74- </ button >
75- ) : depth === 0 && ! isObject ? (
65+ if ( ! isObject ) {
66+ const target = name === undefined ? "$" : path ;
67+ return (
7668 < button
7769 type = "button"
78- onClick = { ( ) => onSelectPath ( "$" ) }
70+ onClick = { ( ) => onSelectPath ( target ) }
7971 className = { cn (
80- "rounded px-0.5 text-text-dimmed hover:bg-blue-500/20 " ,
81- selected && "bg-blue-500/30 "
72+ "flex w-full items-baseline whitespace-pre rounded px-0.5 text-left hover:bg-blue-500/15 " ,
73+ selected && "bg-blue-500/25 "
8274 ) }
8375 >
84- $
85- </ button >
86- ) : null ;
87-
88- if ( ! isObject ) {
89- return (
90- < div className = "whitespace-pre" >
91- { keyButton }
92- { keyButton && < span className = "text-text-dimmed" > : </ span > }
76+ { keyLabel !== null && < span className = "text-sky-300" > { keyLabel } </ span > }
77+ { keyLabel !== null && < span className = "text-text-dimmed" > : </ span > }
9378 < PrimitiveValue value = { value } />
94- </ div >
79+ </ button >
9580 ) ;
9681 }
9782
@@ -105,25 +90,24 @@ function JsonNode({
10590
10691 return (
10792 < div >
108- < div className = "flex items-start whitespace-pre" >
109- < button
110- type = "button"
111- onClick = { ( ) => setOpen ( ( o ) => ! o ) }
112- aria-label = { open ? "Collapse" : "Expand" }
113- className = "mr-1 w-3 shrink-0 text-text-dimmed hover:text-text-bright"
114- >
115- { open ? "▾" : "▸" }
116- </ button >
117- { keyButton }
118- { keyButton && < span className = "text-text-dimmed" > : </ span > }
93+ < button
94+ type = "button"
95+ onClick = { ( ) => setOpen ( ( o ) => ! o ) }
96+ aria-label = { open ? "Collapse" : "Expand" }
97+ aria-expanded = { open }
98+ className = "flex w-full items-start whitespace-pre rounded px-0.5 text-left hover:bg-charcoal-750"
99+ >
100+ < span className = "mr-1 w-3 shrink-0 text-text-dimmed" > { open ? "▾" : "▸" } </ span >
101+ { keyLabel !== null && < span className = "text-sky-300" > { keyLabel } </ span > }
102+ { keyLabel !== null && < span className = "text-text-dimmed" > : </ span > }
119103 < span className = "text-text-dimmed" >
120104 { openBrace }
121105 { ! open && `… ${ closeBrace } ` }
122106 { ! open && entries . length > 0 && (
123107 < span className = "ml-1 text-faint" > { `${ entries . length } ${ isArray ? "items" : "keys" } ` } </ span >
124108 ) }
125109 </ span >
126- </ div >
110+ </ button >
127111 { open && (
128112 < div className = "ml-[0.4rem] border-l border-grid-dimmed/50 pl-3" >
129113 { shown . map ( ( [ key , childValue ] ) => (
0 commit comments