@@ -2,53 +2,12 @@ import type { HTMLProps } from 'react'
2
2
import { css } from '../../utils/css'
3
3
import type { DevToolsInfoPropsCore } from '../errors/dev-tools-indicator/dev-tools-info/dev-tools-info'
4
4
import { DevToolsInfo } from '../errors/dev-tools-indicator/dev-tools-info/dev-tools-info'
5
- import { cx } from '../../utils/cx'
6
5
import {
7
6
type SegmentNode ,
8
7
useSegmentTreeClientState ,
9
8
} from '../../../../shared/lib/devtool/app-segment-tree'
10
9
import type { Trie , TrieNode } from '../../../../shared/lib/devtool/trie'
11
10
12
- const IconLayout = ( props : React . SVGProps < SVGSVGElement > ) => {
13
- return (
14
- < svg
15
- { ...props }
16
- viewBox = "0 0 16 16"
17
- fill = "none"
18
- xmlns = "http://www.w3.org/2000/svg"
19
- >
20
- < path
21
- d = "M16 12.5L15.9873 12.7559C15.8677 13.9323 14.9323 14.8677 13.7559 14.9873L13.5 15H2.5L2.24414 14.9873C1.06772 14.8677 0.132274 13.9323 0.0126953 12.7559L0 12.5V1H16V12.5ZM1.5 6.25488V12.5C1.5 13.0523 1.94772 13.5 2.5 13.5H4.99512V6.25488H1.5ZM6.24512 6.25488V13.5H13.5C14.0523 13.5 14.5 13.0523 14.5 12.5V6.25488H6.24512ZM1.5 5.00488H14.5V2.5H1.5V5.00488Z"
22
- fill = "currentColor"
23
- />
24
- </ svg >
25
- )
26
- }
27
-
28
- const IconPage = ( props : React . SVGProps < SVGSVGElement > ) => {
29
- return (
30
- < svg
31
- { ...props }
32
- viewBox = "0 0 16 16"
33
- fill = "none"
34
- strokeLinejoin = "round"
35
- xmlns = "http://www.w3.org/2000/svg"
36
- >
37
- < path
38
- fillRule = "evenodd"
39
- clipRule = "evenodd"
40
- d = "M14.5 6.5V13.5C14.5 14.8807 13.3807 16 12 16H4C2.61929 16 1.5 14.8807 1.5 13.5V1.5V0H3H8H9.08579C9.351 0 9.60536 0.105357 9.79289 0.292893L14.2071 4.70711C14.3946 4.89464 14.5 5.149 14.5 5.41421V6.5ZM13 6.5V13.5C13 14.0523 12.5523 14.5 12 14.5H4C3.44772 14.5 3 14.0523 3 13.5V1.5H8V5V6.5H9.5H13ZM9.5 2.12132V5H12.3787L9.5 2.12132Z"
41
- fill = "currentColor"
42
- />
43
- </ svg >
44
- )
45
- }
46
-
47
- const ICONS = {
48
- layout : < IconLayout width = { 16 } /> ,
49
- page : < IconPage width = { 16 } /> ,
50
- }
51
-
52
11
function PageSegmentTree ( { tree } : { tree : Trie < SegmentNode > | undefined } ) {
53
12
if ( ! tree ) {
54
13
return null
@@ -63,6 +22,7 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
63
22
node = { tree . getRoot ( ) }
64
23
level = { 0 }
65
24
segment = ""
25
+ parentSegment = ""
66
26
/>
67
27
</ div >
68
28
)
@@ -71,19 +31,22 @@ function PageSegmentTree({ tree }: { tree: Trie<SegmentNode> | undefined }) {
71
31
function PageSegmentTreeLayerPresentation ( {
72
32
tree,
73
33
segment,
34
+ parentSegment,
74
35
node,
75
36
level,
76
37
} : {
77
38
tree : Trie < SegmentNode >
78
39
segment : string
40
+ parentSegment : string
79
41
node : TrieNode < SegmentNode >
80
42
level : number
81
43
} ) {
82
44
const pagePath = node . value ?. pagePath || ''
83
45
const nodeName = node . value ?. type
46
+ const isFile = ! ! nodeName
84
47
85
48
const segments = pagePath . split ( '/' ) || [ ]
86
- const fileName = segments . pop ( ) || ''
49
+ const fileName = isFile ? segments . pop ( ) || '' : ''
87
50
const childrenKeys = Object . keys ( node . children )
88
51
89
52
const sortedChildrenKeys = childrenKeys . sort ( ( a , b ) => {
@@ -97,65 +60,64 @@ function PageSegmentTreeLayerPresentation({
97
60
return a . localeCompare ( b )
98
61
} )
99
62
63
+ // check if it has file children
64
+ const hasFileChildren = sortedChildrenKeys . some ( ( key ) => {
65
+ const childNode = node . children [ key ]
66
+ return ! ! childNode ?. value ?. type
67
+ } )
68
+
69
+ // If it's the 1st level and contains a file, use 'app' as the folder name
70
+ const folderName = level === 1 && isFile ? 'app' : parentSegment
71
+
100
72
return (
101
- < div
102
- className = "segment-explorer-item"
103
- data-nextjs-devtool-segment-explorer-segment = { segment }
104
- >
105
- { fileName ? (
106
- < div className = { cx ( 'segment-explorer-item-row' ) } >
107
- < div className = "segment-explorer-line" >
108
- < div className = { `segment-explorer-line-text-${ nodeName } ` } >
109
- < span
110
- className = { cx (
111
- 'segment-explorer-line-icon' ,
112
- `segment-explorer-line-icon-${ nodeName } `
113
- ) }
114
- >
115
- { nodeName === 'layout' ? ICONS . layout : ICONS . page }
116
- </ span >
117
- < span className = "segment-explorer-filename-path" > { fileName } </ span >
118
- </ div >
119
- </ div >
120
- </ div >
121
- ) : segment ? (
122
- < div className = { 'segment-explorer-item-row' } >
123
- < div className = "segment-explorer-line" >
124
- < div className = { `segment-explorer-line-text-${ nodeName } ` } >
125
- < span
126
- className = { cx (
127
- 'segment-explorer-line-icon' ,
128
- `segment-explorer-line-icon-${ nodeName } `
129
- ) }
130
- > </ span >
131
- < span className = "segment-explorer-filename-path" >
132
- { `${ segment } /` }
133
- </ span >
73
+ < >
74
+ { isFile ? (
75
+ < div
76
+ className = "segment-explorer-item"
77
+ data-nextjs-devtool-segment-explorer-segment = { segment }
78
+ >
79
+ < div
80
+ className = "segment-explorer-item-row"
81
+ style = { {
82
+ // If it's children levels, show indents if there's any file at that level.
83
+ // Otherwise it's empty folder, no need to show indents.
84
+ ...( level > 0 && isFile && { paddingLeft : `${ level * 8 } px` } ) ,
85
+ } }
86
+ >
87
+ < div className = "segment-explorer-line" >
88
+ < div className = { `segment-explorer-line-text-${ nodeName } ` } >
89
+ < div className = "segment-explorer-filename" >
90
+ { folderName && (
91
+ < span className = "segment-explorer-filename--path" >
92
+ { folderName }
93
+ </ span >
94
+ ) }
95
+ < span className = "segment-explorer-filename--name" >
96
+ { fileName }
97
+ </ span >
98
+ </ div >
99
+ </ div >
134
100
</ div >
135
101
</ div >
136
102
</ div >
137
103
) : null }
138
-
139
- < div
140
- className = "segment-explorer-segment-children"
141
- data-nextjs-devtool-segment-explorer-level = { level }
142
- >
143
- { sortedChildrenKeys . map ( ( childSegment ) => {
144
- const child = node . children [ childSegment ]
145
- return (
146
- child && (
147
- < PageSegmentTreeLayerPresentation
148
- key = { childSegment }
149
- segment = { childSegment }
150
- tree = { tree }
151
- node = { child }
152
- level = { level + 1 }
153
- />
154
- )
155
- )
156
- } ) }
157
- </ div >
158
- </ div >
104
+ { sortedChildrenKeys . map ( ( childSegment ) => {
105
+ const child = node . children [ childSegment ]
106
+ if ( ! child ) {
107
+ return null
108
+ }
109
+ return (
110
+ < PageSegmentTreeLayerPresentation
111
+ key = { childSegment }
112
+ segment = { childSegment }
113
+ parentSegment = { segment }
114
+ tree = { tree }
115
+ node = { child }
116
+ level = { hasFileChildren ? level + 1 : level }
117
+ />
118
+ )
119
+ } ) }
120
+ </ >
159
121
)
160
122
}
161
123
@@ -177,47 +139,46 @@ export function SegmentsExplorer(
177
139
export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css `
178
140
.segment-explorer-content {
179
141
overflow-y : auto;
180
- padding : 0 12px ;
181
142
font-size : var (--size-14 );
143
+ margin : -12px -8px ;
144
+ }
145
+
146
+ .segment-explorer-item {
147
+ margin : 4px 0 ;
148
+ }
149
+
150
+ .segment-explorer-item : nth-child (odd) {
151
+ background-color : var (--color-gray-100 );
182
152
}
183
153
184
154
.segment-explorer-item-row {
185
155
display : flex;
186
156
align-items : center;
187
- gap : 8 px ;
188
- padding : 2 px 0 ;
157
+ padding : 4 px 24 px ;
158
+ border-radius : 6 px ;
189
159
}
190
160
191
- [data-nextjs-devtool-segment-explorer-level ].segment-explorer-segment-children {
192
- padding-left : 20px ;
193
- }
194
- [data-nextjs-devtool-segment-explorer-level = '0' ].segment-explorer-segment-children {
195
- padding-left : 0px ;
161
+ .segment-explorer-children--intended {
162
+ padding-left : 16px ;
196
163
}
197
164
198
- .segment-explorer-filename-path {
199
- display : inline-block ;
165
+ .segment-explorer-filename-- path {
166
+ margin-right : 8 px ;
200
167
}
201
-
202
- .segment-explorer-filename-path a {
203
- color : inherit;
204
- text-decoration : inherit;
168
+ .segment-explorer-filename--name {
169
+ color : var (--color-gray-800 );
205
170
}
206
171
207
172
.segment-explorer-line {
208
173
white-space : pre;
209
174
cursor : default;
210
175
}
211
176
212
- .segment-explorer-line-icon {
213
- margin-right : 4px ;
214
- }
215
- .segment-explorer-line-icon-page {
216
- color : inherit;
177
+ .segment-explorer-line {
178
+ color : var (--color-gray-1000 );
217
179
}
218
180
219
- .segment-explorer-line-text-page {
220
- color : var (--color-gray-1000 );
221
- font-weight : 500 ;
181
+ [data-nextjs-devtool-segment-explorer-level = 'odd' ] {
182
+ background-color : var (--color-gray-100 );
222
183
}
223
184
`
0 commit comments