@@ -7,29 +7,32 @@ import {
77 SchemaNode ,
88 SchemaNodeKind ,
99} from '@stoplight/json-schema-tree' ;
10- import { Box , Flex , Icon , Select , VStack } from '@stoplight/mosaic' ;
11- import { useUpdateAtom } from 'jotai/utils' ;
10+ import { Box , Flex , Icon , Select , SpaceVals , VStack } from '@stoplight/mosaic' ;
11+ import { useAtomValue , useUpdateAtom } from 'jotai/utils' ;
1212import last from 'lodash/last.js' ;
1313import * as React from 'react' ;
1414
1515import { COMBINER_NAME_MAP } from '../../consts' ;
1616import { useJSVOptionsContext } from '../../contexts' ;
1717import { calculateChildrenToShow , isFlattenableNode , isPropertyRequired } from '../../tree' ;
18- import { pathCrumbsAtom } from '../PathCrumbs' ;
1918import { Caret , Description , Format , getValidationsFromSchema , Types , Validations } from '../shared' ;
2019import { ChildStack } from '../shared/ChildStack' ;
21- import { Properties } from '../shared/Properties' ;
20+ import { Properties , useHasProperties } from '../shared/Properties' ;
21+ import { hoveredNodeAtom , isNodeHoveredAtom } from './state' ;
2222import { useChoices } from './useChoices' ;
2323
2424export interface SchemaRowProps {
2525 schemaNode : SchemaNode ;
2626 nestingLevel : number ;
27+ pl ?: SpaceVals ;
2728}
2829
29- export const SchemaRow : React . FunctionComponent < SchemaRowProps > = ( { schemaNode, nestingLevel } ) => {
30+ export const SchemaRow : React . FunctionComponent < SchemaRowProps > = React . memo ( ( { schemaNode, nestingLevel, pl } ) => {
3031 const { defaultExpandedDepth, renderRowAddon, onGoToRef, hideExamples, renderRootTreeLines } = useJSVOptionsContext ( ) ;
3132
32- const setPathCrumbs = useUpdateAtom ( pathCrumbsAtom ) ;
33+ const setHoveredNode = useUpdateAtom ( hoveredNodeAtom ) ;
34+ const isHovering = useAtomValue ( isNodeHoveredAtom ( schemaNode ) ) ;
35+
3336 const [ isExpanded , setExpanded ] = React . useState < boolean > (
3437 ! isMirroredNode ( schemaNode ) && nestingLevel <= defaultExpandedDepth ,
3538 ) ;
@@ -62,13 +65,20 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = ({ schemaNode,
6265 const isCollapsible = childNodes . length > 0 ;
6366 const isRootLevel = nestingLevel < rootLevel ;
6467
68+ const required = isPropertyRequired ( schemaNode ) ;
69+ const deprecated = isRegularNode ( schemaNode ) && schemaNode . deprecated ;
70+ const validations = isRegularNode ( schemaNode ) ? schemaNode . validations : { } ;
71+ const hasProperties = useHasProperties ( { required, deprecated, validations } ) ;
72+
6573 return (
6674 < >
6775 < Flex
6876 maxW = "full"
77+ pl = { pl }
78+ py = { 2 }
6979 onMouseEnter = { ( e : any ) => {
7080 e . stopPropagation ( ) ;
71- setPathCrumbs ( selectedChoice . type ) ;
81+ setHoveredNode ( selectedChoice . type ) ;
7282 } }
7383 >
7484 { ! isRootLevel && < Box borderT w = { isCollapsible ? 1 : 3 } ml = { - 3 } mr = { 3 } mt = { 2 } /> }
@@ -82,7 +92,7 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = ({ schemaNode,
8292 >
8393 { isCollapsible ? < Caret isExpanded = { isExpanded } /> : null }
8494
85- < Flex alignItems = "baseline" fontSize = "base" flex = { 1 } pos = "sticky" top = { 0 } >
95+ < Flex alignItems = "baseline" fontSize = "base" >
8696 { schemaNode . subpath . length > 0 && shouldShowPropertyName ( schemaNode ) && (
8797 < Box mr = { 2 } fontFamily = "mono" fontWeight = "semibold" >
8898 { last ( schemaNode . subpath ) }
@@ -136,11 +146,9 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = ({ schemaNode,
136146 ) }
137147 </ Flex >
138148
139- < Properties
140- required = { isPropertyRequired ( schemaNode ) }
141- deprecated = { isRegularNode ( schemaNode ) && schemaNode . deprecated }
142- validations = { isRegularNode ( schemaNode ) ? schemaNode . validations : { } }
143- />
149+ { hasProperties && < Box bg = { isHovering ? 'canvas-200' : undefined } h = "px" flex = { 1 } mx = { 3 } /> }
150+
151+ < Properties required = { required } deprecated = { deprecated } validations = { validations } />
144152 </ Flex >
145153
146154 { typeof description === 'string' && description . length > 0 && < Description value = { description } /> }
@@ -159,10 +167,12 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = ({ schemaNode,
159167 { renderRowAddon ? < Box > { renderRowAddon ( { schemaNode, nestingLevel } ) } </ Box > : null }
160168 </ Flex >
161169
162- { isCollapsible && isExpanded ? < ChildStack childNodes = { childNodes } currentNestingLevel = { nestingLevel } /> : null }
170+ { isCollapsible && isExpanded ? (
171+ < ChildStack schemaNode = { schemaNode } childNodes = { childNodes } currentNestingLevel = { nestingLevel } />
172+ ) : null }
163173 </ >
164174 ) ;
165- } ;
175+ } ) ;
166176
167177function shouldShowPropertyName ( schemaNode : SchemaNode ) {
168178 return (
0 commit comments