@@ -8,12 +8,38 @@ import { DockLayout, Widget } from '@lumino/widgets';
8
8
9
9
import { IVariableInspector } from './tokens' ;
10
10
11
+ import {
12
+ DataGrid as WebDataGrid ,
13
+ DataGridRow ,
14
+ DataGridCell ,
15
+ provideJupyterDesignSystem ,
16
+ Select ,
17
+ Option ,
18
+ TextField ,
19
+ Button ,
20
+ jpDataGrid ,
21
+ jpDataGridRow ,
22
+ jpDataGridCell ,
23
+ jpTextField ,
24
+ jpOption ,
25
+ jpSelect ,
26
+ jpButton
27
+ } from '@jupyter/web-components' ;
28
+ provideJupyterDesignSystem ( ) . register (
29
+ jpDataGrid ( ) ,
30
+ jpDataGridRow ( ) ,
31
+ jpDataGridCell ( ) ,
32
+ jpTextField ( ) ,
33
+ jpOption ( ) ,
34
+ jpSelect ( ) ,
35
+ jpButton ( )
36
+ ) ;
37
+
11
38
import wildcardMatch from 'wildcard-match' ;
12
39
13
40
const TITLE_CLASS = 'jp-VarInspector-title' ;
14
41
const PANEL_CLASS = 'jp-VarInspector' ;
15
42
const TABLE_CLASS = 'jp-VarInspector-table' ;
16
- const TABLE_BODY_CLASS = 'jp-VarInspector-content' ;
17
43
const TABLE_ROW_CLASS = 'jp-VarInspector-table-row' ;
18
44
const TABLE_ROW_HIDDEN_CLASS = 'jp-VarInspector-table-row-hidden' ;
19
45
const TABLE_TYPE_CLASS = 'jp-VarInspector-type' ;
@@ -34,8 +60,8 @@ export class VariableInspectorPanel
34
60
implements IVariableInspector
35
61
{
36
62
private _source : IVariableInspector . IInspectable | null = null ;
63
+ private _table : WebDataGrid ;
37
64
private _filteredTable : HTMLDivElement ;
38
- private _table : HTMLTableElement ;
39
65
private _title : HTMLElement ;
40
66
private _filtered : { type : Array < string > ; name : Array < string > } ;
41
67
@@ -58,13 +84,13 @@ export class VariableInspectorPanel
58
84
protected intializeFilteredTable ( ) {
59
85
const filterType = this . _filteredTable . querySelector (
60
86
'.' + FILTER_TYPE_CLASS
61
- ) as HTMLSelectElement ;
87
+ ) as Select ;
62
88
const filterInput = this . _filteredTable . querySelector (
63
89
'.' + FILTER_INPUT_CLASS
64
- ) as HTMLInputElement ;
90
+ ) as TextField ;
65
91
const filterButton = this . _filteredTable . querySelector (
66
92
'.' + FILTER_BUTTON_CLASS
67
- ) as HTMLButtonElement ;
93
+ ) as Button ;
68
94
filterButton . addEventListener ( 'click' , ( ) => {
69
95
this . onFilterChange (
70
96
filterType . value as FILTER_TYPES ,
@@ -137,14 +163,14 @@ export class VariableInspectorPanel
137
163
protected addFilteredOutRows ( ) {
138
164
const rows = this . _table . querySelectorAll (
139
165
'.' + TABLE_ROW_HIDDEN_CLASS
140
- ) as NodeListOf < HTMLTableRowElement > ;
166
+ ) as NodeListOf < DataGridRow > ;
141
167
for ( let i = 0 ; i < rows . length ; i ++ ) {
142
168
const rowName = rows [ i ] . querySelector (
143
169
'.' + TABLE_NAME_CLASS
144
- ) as HTMLTableCellElement ;
170
+ ) as DataGridCell ;
145
171
const rowType = rows [ i ] . querySelector (
146
172
'.' + TABLE_TYPE_CLASS
147
- ) as HTMLTableCellElement ;
173
+ ) as DataGridCell ;
148
174
if (
149
175
! this . stringInFilter ( rowName . innerHTML , 'name' ) &&
150
176
! this . _filtered [ 'type' ] . includes ( rowType . innerHTML )
@@ -161,14 +187,14 @@ export class VariableInspectorPanel
161
187
protected filterOutTable ( ) {
162
188
const rows = this . _table . querySelectorAll (
163
189
'.' + TABLE_ROW_CLASS
164
- ) as NodeListOf < HTMLTableRowElement > ;
190
+ ) as NodeListOf < DataGridRow > ;
165
191
for ( let i = 0 ; i < rows . length ; i ++ ) {
166
192
const rowName = rows [ i ] . querySelector (
167
193
'.' + TABLE_NAME_CLASS
168
- ) as HTMLTableCellElement ;
194
+ ) as DataGridCell ;
169
195
const rowType = rows [ i ] . querySelector (
170
196
'.' + TABLE_TYPE_CLASS
171
- ) as HTMLTableCellElement ;
197
+ ) as DataGridCell ;
172
198
if (
173
199
this . stringInFilter ( rowName . innerHTML , 'name' ) ||
174
200
this . _filtered [ 'type' ] . includes ( rowType . innerHTML )
@@ -178,6 +204,24 @@ export class VariableInspectorPanel
178
204
}
179
205
}
180
206
207
+ /*
208
+ Goes through each row and if it finds a variable with name 'name', then it deletes it
209
+ */
210
+ protected removeRow ( name : string ) {
211
+ const rows = this . _table . querySelectorAll (
212
+ '.' + TABLE_ROW_CLASS
213
+ ) as NodeListOf < DataGridRow > ;
214
+ for ( let i = 0 ; i < rows . length ; i ++ ) {
215
+ const cell = rows [ i ] . querySelector (
216
+ '.' + TABLE_NAME_CLASS
217
+ ) as DataGridCell ;
218
+ if ( cell . innerHTML === name ) {
219
+ rows [ i ] . remove ( ) ;
220
+ return ;
221
+ }
222
+ }
223
+ }
224
+
181
225
get source ( ) : IVariableInspector . IInspectable | null {
182
226
return this . _source ;
183
227
}
@@ -230,18 +274,28 @@ export class VariableInspectorPanel
230
274
" Inspecting '" + title . kernelName + "' " + title . contextName ;
231
275
}
232
276
277
+ this . _table . innerHTML = '' ;
278
+ const headerRow = document . createElement ( 'jp-data-grid-row' ) as DataGridRow ;
279
+ headerRow . className = 'sticky-header' ;
280
+ const columns = [ ' ' , ' ' , 'NAME' , 'TYPE' , 'SIZE' , 'SHAPE' , 'CONTENT' ] ;
281
+ for ( let i = 0 ; i < columns . length ; i ++ ) {
282
+ const headerCell = document . createElement (
283
+ 'jp-data-grid-cell'
284
+ ) as DataGridCell ;
285
+ headerCell . className = 'column-header' ;
286
+ headerCell . textContent = columns [ i ] ;
287
+ headerCell . gridColumn = ( i + 1 ) . toString ( ) ;
288
+ headerRow . appendChild ( headerCell ) ;
289
+ }
290
+ this . _table . appendChild ( headerRow ) ;
291
+
233
292
//Render new variable state
234
- let row : HTMLTableRowElement ;
235
- this . _table . deleteTFoot ( ) ;
236
- this . _table . createTFoot ( ) ;
237
- this . _table . tFoot ! . className = TABLE_BODY_CLASS ;
238
293
for ( let index = 0 ; index < args . length ; index ++ ) {
239
294
const item = args [ index ] ;
240
-
241
295
const name = item . varName ;
242
296
const varType = item . varType ;
243
297
244
- row = this . _table . tFoot ! . insertRow ( ) ;
298
+ const row = document . createElement ( 'jp-data-grid-row' ) as DataGridRow ;
245
299
row . className = TABLE_ROW_CLASS ;
246
300
if ( this . _filtered [ 'type' ] . includes ( varType ) ) {
247
301
row . className = TABLE_ROW_HIDDEN_CLASS ;
@@ -250,48 +304,67 @@ export class VariableInspectorPanel
250
304
}
251
305
252
306
// Add delete icon and onclick event
253
- let cell = row . insertCell ( 0 ) ;
307
+ let cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
254
308
cell . title = 'Delete Variable' ;
255
309
cell . className = 'jp-VarInspector-deleteButton' ;
310
+ cell . gridColumn = '1' ;
311
+ const closeButton = document . createElement ( 'jp-button' ) as Button ;
312
+ closeButton . appearance = 'stealth' ;
256
313
const ico = closeIcon . element ( ) ;
314
+ ico . className = 'icon-button' ;
257
315
ico . onclick = ( ev : MouseEvent ) : any => {
258
- this . source ?. performDelete ( name ) ;
316
+ this . removeRow ( name ) ;
259
317
} ;
260
- cell . append ( ico ) ;
318
+ closeButton . append ( ico ) ;
319
+ cell . append ( closeButton ) ;
320
+ row . appendChild ( cell ) ;
261
321
262
322
// Add onclick event for inspection
263
- cell = row . insertCell ( 1 ) ;
323
+ cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
264
324
if ( item . isMatrix ) {
265
325
cell . title = 'View Contents' ;
266
326
cell . className = 'jp-VarInspector-inspectButton' ;
327
+ const searchButton = document . createElement ( 'jp-button' ) as Button ;
328
+ searchButton . appearance = 'stealth' ;
267
329
const ico = searchIcon . element ( ) ;
330
+ ico . className = 'icon-button' ;
268
331
ico . onclick = ( ev : MouseEvent ) : any => {
269
- console . log ( 'Click on ' + name ) ;
270
332
this . _source
271
- ?. performMatrixInspection ( name )
333
+ ?. performMatrixInspection ( item . varName )
272
334
. then ( ( model : DataModel ) => {
273
- this . _showMatrix ( model , name , varType ) ;
335
+ this . _showMatrix ( model , item . varName , item . varType ) ;
274
336
} ) ;
275
337
} ;
276
- cell . append ( ico ) ;
338
+ searchButton . append ( ico ) ;
339
+ cell . append ( searchButton ) ;
277
340
} else {
278
341
cell . innerHTML = '' ;
279
342
}
343
+ cell . gridColumn = '2' ;
344
+ row . appendChild ( cell ) ;
280
345
281
- cell = row . insertCell ( 2 ) ;
346
+ cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
282
347
cell . className = TABLE_NAME_CLASS ;
283
348
cell . innerHTML = name ;
349
+ cell . gridColumn = '3' ;
350
+ row . appendChild ( cell ) ;
284
351
285
352
// Add remaining cells
286
- cell = row . insertCell ( 3 ) ;
353
+ cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
287
354
cell . innerHTML = varType ;
288
355
cell . className = TABLE_TYPE_CLASS ;
289
- cell = row . insertCell ( 4 ) ;
356
+ cell . gridColumn = '4' ;
357
+ row . appendChild ( cell ) ;
358
+ cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
290
359
cell . innerHTML = item . varSize ;
291
- cell = row . insertCell ( 5 ) ;
360
+ cell . gridColumn = '5' ;
361
+ row . appendChild ( cell ) ;
362
+ cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
292
363
cell . innerHTML = item . varShape ;
293
- cell = row . insertCell ( 6 ) ;
364
+ cell . gridColumn = '6' ;
365
+ row . appendChild ( cell ) ;
294
366
367
+ cell = document . createElement ( 'jp-data-grid-cell' ) as DataGridCell ;
295
368
const rendermime = this . _source ?. rendermime ;
296
369
if ( item . isWidget && rendermime ) {
297
370
const model = new OutputAreaModel ( { trusted : true } ) ;
@@ -304,6 +377,9 @@ export class VariableInspectorPanel
304
377
'</br>'
305
378
) ;
306
379
}
380
+ cell . gridColumn = '7' ;
381
+ row . appendChild ( cell ) ;
382
+ this . _table . appendChild ( row ) ;
307
383
}
308
384
}
309
385
@@ -356,25 +432,10 @@ namespace Private {
356
432
) ;
357
433
}
358
434
359
- export function createTable ( ) : HTMLTableElement {
360
- const table = document . createElement ( 'table' ) ;
361
- table . createTHead ( ) ;
362
- const hrow = table . tHead ! . insertRow ( 0 ) as HTMLTableRowElement ;
363
-
364
- const cell1 = hrow . insertCell ( 0 ) ;
365
- cell1 . innerHTML = '' ;
366
- const cell2 = hrow . insertCell ( 1 ) ;
367
- cell2 . innerHTML = '' ;
368
- const cell3 = hrow . insertCell ( 2 ) ;
369
- cell3 . innerHTML = 'Name' ;
370
- const cell4 = hrow . insertCell ( 3 ) ;
371
- cell4 . innerHTML = 'Type' ;
372
- const cell5 = hrow . insertCell ( 4 ) ;
373
- cell5 . innerHTML = 'Size' ;
374
- const cell6 = hrow . insertCell ( 5 ) ;
375
- cell6 . innerHTML = 'Shape' ;
376
- const cell7 = hrow . insertCell ( 6 ) ;
377
- cell7 . innerHTML = 'Content' ;
435
+ export function createTable ( ) : WebDataGrid {
436
+ const table = document . createElement ( 'jp-data-grid' ) as WebDataGrid ;
437
+ table . generateHeader = 'sticky' ;
438
+ table . gridTemplateColumns = '1fr 1fr 6fr 4fr 4fr 5fr 16fr' ;
378
439
return table ;
379
440
}
380
441
@@ -387,27 +448,27 @@ namespace Private {
387
448
export function createFilterTable ( ) : HTMLDivElement {
388
449
const container = document . createElement ( 'div' ) ;
389
450
container . className = 'filter-container' ;
390
- const filterType = document . createElement ( 'select' ) ;
451
+ const filterType = document . createElement ( 'jp- select' ) as Select ;
391
452
filterType . className = FILTER_TYPE_CLASS ;
392
453
filterType . selectedIndex = 0 ;
393
- const varTypeOption = document . createElement ( 'option' ) ;
454
+ const varTypeOption = document . createElement ( 'jp- option' ) as Option ;
394
455
varTypeOption . value = 'type' ;
395
456
varTypeOption . innerHTML = 'Type' ;
396
- const nameOption = document . createElement ( 'option' ) ;
457
+ const nameOption = document . createElement ( 'jp- option' ) as Option ;
397
458
nameOption . value = 'name' ;
398
459
nameOption . innerHTML = 'Name' ;
399
460
filterType . appendChild ( varTypeOption ) ;
400
461
filterType . appendChild ( nameOption ) ;
401
462
const searchContainer = document . createElement ( 'div' ) ;
402
463
searchContainer . className = 'jp-InputGroup filter-search-container' ;
403
- const input = document . createElement ( 'input' ) ;
464
+ const input = document . createElement ( 'jp-text-field' ) as TextField ;
404
465
input . setAttribute ( 'type' , 'text' ) ;
405
466
input . setAttribute ( 'placeholder' , 'Filter out variable' ) ;
406
467
input . className = FILTER_INPUT_CLASS ;
407
- const filterButton = document . createElement ( 'button' ) ;
408
- const buttonText = document . createTextNode ( 'Filter' ) ;
409
- filterButton . appendChild ( buttonText ) ;
468
+ const filterButton = document . createElement ( 'jp-button' ) as Button ;
469
+ filterButton . textContent = 'Filter' ;
410
470
filterButton . className = FILTER_BUTTON_CLASS ;
471
+ filterButton . appearance = 'accent' ;
411
472
const list = document . createElement ( 'ul' ) ;
412
473
list . className = FILTER_LIST_CLASS ;
413
474
@@ -423,18 +484,22 @@ namespace Private {
423
484
export function createFilteredButton (
424
485
filterName : string ,
425
486
filterType : FILTER_TYPES
426
- ) : HTMLButtonElement {
427
- const filteredButton = document . createElement ( 'button' ) ;
487
+ ) : Button {
488
+ const filteredButton = document . createElement ( 'jp- button' ) as Button ;
428
489
filteredButton . value = filterType ;
429
490
filteredButton . title = filterType ;
491
+ filteredButton . className = FILTERED_BUTTON_CLASS ;
492
+ const filterButtonContent = document . createElement ( 'div' ) ;
493
+ filterButtonContent . className = 'filter-button-content' ;
430
494
const buttonText = document . createElement ( 'div' ) ;
431
495
buttonText . className = 'filtered-variable-button-text' ;
432
496
buttonText . innerHTML = filterName ;
433
497
const icon = closeIcon . element ( {
434
- container : filteredButton
498
+ container : filterButtonContent
435
499
} ) ;
436
- filteredButton . appendChild ( buttonText ) ;
437
- filteredButton . appendChild ( icon ) ;
500
+ filterButtonContent . appendChild ( buttonText ) ;
501
+ filterButtonContent . appendChild ( icon ) ;
502
+ filteredButton . appendChild ( filterButtonContent ) ;
438
503
filteredButton . className = FILTERED_BUTTON_CLASS ;
439
504
return filteredButton ;
440
505
}
0 commit comments