1010import * as React from 'react' ;
1111import { Fragment , useContext , useMemo , useState } from 'react' ;
1212import Store from 'react-devtools-shared/src/devtools/store' ;
13- import Badge from './Badge' ;
1413import ButtonIcon from '../ButtonIcon' ;
15- import { createRegExp } from '../utils' ;
1614import { TreeDispatcherContext , TreeStateContext } from './TreeContext' ;
1715import { SettingsContext } from '../Settings/SettingsContext' ;
1816import { StoreContext } from '../context' ;
1917import { useSubscription } from '../hooks' ;
2018import { logEvent } from 'react-devtools-shared/src/Logger' ;
19+ import IndexableElementBadges from './IndexableElementBadges' ;
20+ import IndexableDisplayName from './IndexableDisplayName' ;
2121
2222import type { ItemData } from './Tree' ;
2323import type { Element as ElementType } from 'react-devtools-shared/src/frontend/types' ;
@@ -121,7 +121,7 @@ export default function Element({data, index, style}: Props): React.Node {
121121 hocDisplayNames,
122122 isStrictModeNonCompliant,
123123 key,
124- type ,
124+ compiledWithForget ,
125125 } = element ;
126126
127127 // Only show strict mode non-compliance badges for top level elements.
@@ -155,11 +155,11 @@ export default function Element({data, index, style}: Props): React.Node {
155155 // We must use padding rather than margin/left because of the selected background color.
156156 transform : `translateX(calc(${ depth } * var(--indentation-size)))` ,
157157 } } >
158- { ownerID === null ? (
158+ { ownerID === null && (
159159 < ExpandCollapseToggle element = { element } store = { store } />
160- ) : null }
160+ ) }
161161
162- < DisplayName displayName = { displayName } id = { ( ( id : any ) : number ) } />
162+ < IndexableDisplayName displayName = { displayName } id = { id } />
163163
164164 { key && (
165165 < Fragment >
@@ -174,14 +174,12 @@ export default function Element({data, index, style}: Props): React.Node {
174174 </ Fragment >
175175 ) }
176176
177- { hocDisplayNames !== null && hocDisplayNames . length > 0 ? (
178- < Badge
179- className = { styles . Badge }
180- hocDisplayNames = { hocDisplayNames }
181- type = { type } >
182- < DisplayName displayName = { hocDisplayNames [ 0 ] } id = { id } />
183- </ Badge >
184- ) : null }
177+ < IndexableElementBadges
178+ hocDisplayNames = { hocDisplayNames }
179+ compiledWithForget = { compiledWithForget }
180+ elementID = { id }
181+ className = { styles . BadgesBlock }
182+ />
185183
186184 { showInlineWarningsAndErrors && errorCount > 0 && (
187185 < Icon
@@ -262,47 +260,3 @@ function ExpandCollapseToggle({element, store}: ExpandCollapseToggleProps) {
262260 </ div >
263261 ) ;
264262}
265-
266- type DisplayNameProps = {
267- displayName : string | null ,
268- id : number ,
269- } ;
270-
271- function DisplayName ( { displayName, id} : DisplayNameProps ) {
272- const { searchIndex, searchResults, searchText} = useContext ( TreeStateContext ) ;
273- const isSearchResult = useMemo ( ( ) => {
274- return searchResults . includes ( id ) ;
275- } , [ id , searchResults ] ) ;
276- const isCurrentResult =
277- searchIndex !== null && id === searchResults [ searchIndex ] ;
278-
279- if ( ! isSearchResult || displayName === null ) {
280- return displayName ;
281- }
282-
283- const match = createRegExp ( searchText ) . exec ( displayName ) ;
284-
285- if ( match === null ) {
286- return displayName ;
287- }
288-
289- const startIndex = match . index ;
290- const stopIndex = startIndex + match [ 0 ] . length ;
291-
292- const children = [ ] ;
293- if ( startIndex > 0 ) {
294- children . push ( < span key = "begin" > { displayName . slice ( 0 , startIndex ) } </ span > ) ;
295- }
296- children . push (
297- < mark
298- key = "middle"
299- className = { isCurrentResult ? styles . CurrentHighlight : styles . Highlight } >
300- { displayName . slice ( startIndex , stopIndex ) }
301- </ mark > ,
302- ) ;
303- if ( stopIndex < displayName . length ) {
304- children . push ( < span key = "end" > { displayName . slice ( stopIndex ) } </ span > ) ;
305- }
306-
307- return children ;
308- }
0 commit comments