@@ -68,8 +68,20 @@ const headerComponents = {
68
68
} ,
69
69
} ;
70
70
71
+ const colors = [
72
+ 'rgba(255,0,0,0.2)' ,
73
+ 'rgba(0,255,0,0.2)' ,
74
+ 'rgba(0,0,255,0.2)' ,
75
+ 'rgba(255,255,0,0.2)' ,
76
+ 'rgba(0,255,255,0.2)' ,
77
+ 'rgba(255,0,255,0.2)' ,
78
+ ] ;
79
+ let count = 0 ;
80
+
71
81
const DockviewDemo = ( props : { theme ?: string } ) => {
72
- const [ logLines , setLogLines ] = React . useState < any [ ] > ( [ ] ) ;
82
+ const [ logLines , setLogLines ] = React . useState <
83
+ { text : string ; timestamp ?: Date ; backgroundColor ?: string } [ ]
84
+ > ( [ ] ) ;
73
85
74
86
const [ panels , setPanels ] = React . useState < string [ ] > ( [ ] ) ;
75
87
const [ groups , setGroups ] = React . useState < string [ ] > ( [ ] ) ;
@@ -78,16 +90,39 @@ const DockviewDemo = (props: { theme?: string }) => {
78
90
const [ activePanel , setActivePanel ] = React . useState < string > ( ) ;
79
91
const [ activeGroup , setActiveGroup ] = React . useState < string > ( ) ;
80
92
93
+ const [ pending , setPending ] = React . useState <
94
+ { text : string ; timestamp ?: Date } [ ]
95
+ > ( [ ] ) ;
96
+
97
+ const addLogLine = ( message : string ) => {
98
+ setPending ( ( line ) => [
99
+ { text : message , timestamp : new Date ( ) } ,
100
+ ...line ,
101
+ ] ) ;
102
+ } ;
103
+
104
+ React . useLayoutEffect ( ( ) => {
105
+ if ( pending . length === 0 ) {
106
+ return ;
107
+ }
108
+ const color = colors [ count ++ % colors . length ] ;
109
+ setLogLines ( ( lines ) => [
110
+ ...pending . map ( ( _ ) => ( { ..._ , backgroundColor : color } ) ) ,
111
+ ...lines ,
112
+ ] ) ;
113
+ setPending ( [ ] ) ;
114
+ } , [ pending ] ) ;
115
+
81
116
const onReady = ( event : DockviewReadyEvent ) => {
82
117
setApi ( event . api ) ;
83
118
84
119
event . api . onDidAddPanel ( ( event ) => {
85
120
setPanels ( ( _ ) => [ ..._ , event . id ] ) ;
86
- setLogLines ( ( line ) => [ `Panel Added ${ event . id } ` , ... line ] ) ;
121
+ addLogLine ( `Panel Added ${ event . id } ` ) ;
87
122
} ) ;
88
123
event . api . onDidActivePanelChange ( ( event ) => {
89
124
setActivePanel ( event ?. id ) ;
90
- setLogLines ( ( line ) => [ `Panel Activated ${ event ?. id } ` , ... line ] ) ;
125
+ addLogLine ( `Panel Activated ${ event ?. id } ` ) ;
91
126
} ) ;
92
127
event . api . onDidRemovePanel ( ( event ) => {
93
128
setPanels ( ( _ ) => {
@@ -99,12 +134,12 @@ const DockviewDemo = (props: { theme?: string }) => {
99
134
100
135
return next ;
101
136
} ) ;
102
- setLogLines ( ( line ) => [ `Panel Removed ${ event . id } ` , ... line ] ) ;
137
+ addLogLine ( `Panel Removed ${ event . id } ` ) ;
103
138
} ) ;
104
139
105
140
event . api . onDidAddGroup ( ( event ) => {
106
141
setGroups ( ( _ ) => [ ..._ , event . id ] ) ;
107
- setLogLines ( ( line ) => [ `Group Added ${ event . id } ` , ... line ] ) ;
142
+ addLogLine ( `Group Added ${ event . id } ` ) ;
108
143
} ) ;
109
144
110
145
event . api . onDidRemoveGroup ( ( event ) => {
@@ -117,12 +152,12 @@ const DockviewDemo = (props: { theme?: string }) => {
117
152
118
153
return next ;
119
154
} ) ;
120
- setLogLines ( ( line ) => [ `Group Removed ${ event . id } ` , ... line ] ) ;
155
+ addLogLine ( `Group Removed ${ event . id } ` ) ;
121
156
} ) ;
122
157
123
158
event . api . onDidActiveGroupChange ( ( event ) => {
124
159
setActiveGroup ( event ?. id ) ;
125
- setLogLines ( ( line ) => [ `Group Activated ${ event ?. id } ` , ... line ] ) ;
160
+ addLogLine ( `Group Activated ${ event ?. id } ` ) ;
126
161
} ) ;
127
162
128
163
const state = localStorage . getItem ( 'dv-demo-state' ) ;
@@ -167,6 +202,7 @@ const DockviewDemo = (props: { theme?: string }) => {
167
202
overflow : 'hidden' ,
168
203
// flexBasis: 0
169
204
height : 0 ,
205
+ display : 'flex' ,
170
206
} }
171
207
>
172
208
< DockviewReact
@@ -178,33 +214,62 @@ const DockviewDemo = (props: { theme?: string }) => {
178
214
onReady = { onReady }
179
215
className = { props . theme || 'dockview-theme-abyss' }
180
216
/>
181
- </ div >
182
- < div
183
- style = { {
184
- height : '200px' ,
185
- backgroundColor : 'black' ,
186
- color : 'white' ,
187
- overflow : 'auto' ,
188
- } }
189
- >
190
- { logLines . map ( ( line , i ) => {
191
- return (
192
- < div key = { i } >
193
- < span
217
+ < div
218
+ style = { {
219
+ // height: '200px',
220
+ width : '300px' ,
221
+ backgroundColor : 'black' ,
222
+ color : 'white' ,
223
+ overflow : 'auto' ,
224
+ } }
225
+ >
226
+ { logLines . map ( ( line , i ) => {
227
+ return (
228
+ < div
194
229
style = { {
195
- display : 'inline-block' ,
196
- width : '30px' ,
197
- color : 'gray' ,
198
- borderRight : '1px solid gray' ,
199
- marginRight : '4px' ,
230
+ height : '30px' ,
231
+ overflow : 'hidden' ,
232
+ textOverflow : 'ellipsis' ,
233
+ whiteSpace : 'nowrap' ,
234
+ fontSize : '13px' ,
235
+ display : 'flex' ,
236
+ alignItems : 'center' ,
237
+ backgroundColor : line . backgroundColor ,
200
238
} }
239
+ key = { i }
201
240
>
202
- { logLines . length - i }
203
- </ span >
204
- < span > { line } </ span >
205
- </ div >
206
- ) ;
207
- } ) }
241
+ < span
242
+ style = { {
243
+ display : 'inline-block' ,
244
+ width : '20px' ,
245
+ color : 'gray' ,
246
+ borderRight : '1px solid gray' ,
247
+ marginRight : '4px' ,
248
+ paddingLeft : '2px' ,
249
+ height : '100%' ,
250
+ } }
251
+ >
252
+ { logLines . length - i }
253
+ </ span >
254
+ < span >
255
+ { line . timestamp && (
256
+ < span
257
+ style = { {
258
+ fontSize : '0.7em' ,
259
+ padding : '0px 2px' ,
260
+ } }
261
+ >
262
+ { line . timestamp
263
+ . toISOString ( )
264
+ . substring ( 11 , 23 ) }
265
+ </ span >
266
+ ) }
267
+ < span > { line . text } </ span >
268
+ </ span >
269
+ </ div >
270
+ ) ;
271
+ } ) }
272
+ </ div >
208
273
</ div >
209
274
</ div >
210
275
) ;
0 commit comments