@@ -21,8 +21,6 @@ import {
21
21
useRef ,
22
22
} from "react" ;
23
23
import { Virtuoso , VirtuosoHandle } from "react-virtuoso" ;
24
- import { useDebounce } from "use-debounce" ;
25
-
26
24
import { CSS , React , useIsMountedRef } from "@cocalc/frontend/app-framework" ;
27
25
import { Loading } from "@cocalc/frontend/components" ;
28
26
import {
@@ -38,7 +36,6 @@ import { JupyterActions } from "./browser-actions";
38
36
import { Cell } from "./cell" ;
39
37
import HeadingTagComponent from "./heading-tag" ;
40
38
interface StableHtmlContextType {
41
- iframeDivRef ?: MutableRefObject < any > ;
42
39
cellListDivRef ?: MutableRefObject < any > ;
43
40
iframeOnScrolls ?: { [ key : string ] : ( ) => void } ;
44
41
}
@@ -51,7 +48,6 @@ export const useStableHtmlContext: () => StableHtmlContextType = () => {
51
48
// - iframe cell (hidden at top)
52
49
// - style cell (hidden at top)
53
50
// - padding (at the bottom)
54
- const EXTRA_TOP_CELLS = 2 ;
55
51
const EXTRA_BOTTOM_CELLS = 1 ;
56
52
57
53
const CELL_VISIBLE_THRESH = 50 ;
@@ -67,11 +63,6 @@ const BOTTOM_PADDING_CELL = (
67
63
> </ div >
68
64
) ;
69
65
70
- const ITEM_STYLE : CSS = {
71
- height : "1px" ,
72
- overflow : "hidden" ,
73
- } ;
74
-
75
66
interface CellListProps {
76
67
actions ?: JupyterActions ; // if not defined, then everything is read only
77
68
cell_list : immutable . List < string > ; // list of ids of cells in order
@@ -284,9 +275,6 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
284
275
}
285
276
286
277
function scrollCellListVirtuoso ( scroll : Scroll ) {
287
- // NOTE: below we add EXTRA_TOP_CELLS to the index to compensate
288
- // for the first fixed hidden cell that contains all
289
- // of the output iframes!
290
278
if ( typeof scroll == "number" ) {
291
279
// scroll to a number is not meaningful for virtuoso; it might
292
280
// be requested maybe (?) due to scroll restore and switching
@@ -304,7 +292,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
304
292
// We ONLY scroll if the cell is not in the visible, since
305
293
// react-virtuoso's "scrollIntoView" aggressively scrolls, even
306
294
// if the item is in view.
307
- const n = index + EXTRA_TOP_CELLS ;
295
+ const n = index ;
308
296
let isNotVisible = false ;
309
297
let align : "start" | "center" | "end" = "start" ;
310
298
if ( n < virtuosoRangeRef . current . startIndex ) {
@@ -346,40 +334,40 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
346
334
}
347
335
} else if ( scroll == "cell top" ) {
348
336
virtuosoRef . current ?. scrollToIndex ( {
349
- index : index + EXTRA_TOP_CELLS ,
337
+ index,
350
338
} ) ;
351
339
// hack which seems necessary for jupyter at least.
352
340
requestAnimationFrame (
353
341
( ) =>
354
342
virtuosoRef . current ?. scrollToIndex ( {
355
- index : index + EXTRA_TOP_CELLS ,
343
+ index,
356
344
} ) ,
357
345
) ;
358
346
}
359
347
} else if ( scroll . startsWith ( "list" ) ) {
360
348
if ( scroll == "list up" ) {
361
349
const index = virtuosoRangeRef . current ?. startIndex ;
362
350
virtuosoRef . current ?. scrollToIndex ( {
363
- index : index + EXTRA_TOP_CELLS ,
351
+ index,
364
352
align : "end" ,
365
353
} ) ;
366
354
requestAnimationFrame (
367
355
( ) =>
368
356
virtuosoRef . current ?. scrollToIndex ( {
369
- index : index + EXTRA_TOP_CELLS ,
357
+ index,
370
358
align : "end" ,
371
359
} ) ,
372
360
) ;
373
361
} else if ( scroll == "list down" ) {
374
362
const index = virtuosoRangeRef . current ?. endIndex ;
375
363
virtuosoRef . current ?. scrollToIndex ( {
376
- index : index + EXTRA_TOP_CELLS ,
364
+ index,
377
365
align : "start" ,
378
366
} ) ;
379
367
requestAnimationFrame (
380
368
( ) =>
381
369
virtuosoRef . current ?. scrollToIndex ( {
382
- index : index + EXTRA_TOP_CELLS ,
370
+ index,
383
371
align : "start" ,
384
372
} ) ,
385
373
) ;
@@ -515,7 +503,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
515
503
onScroll : ( scrollState ) => {
516
504
lastScrollStateRef . current = {
517
505
...scrollState ,
518
- id : cellListRef . current ?. get ( scrollState . index - EXTRA_TOP_CELLS ) ,
506
+ id : cellListRef . current ?. get ( scrollState . index ) ,
519
507
} ;
520
508
for ( const key in iframeOnScrolls ) {
521
509
iframeOnScrolls [ key ] ( ) ;
@@ -539,16 +527,13 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
539
527
if ( index == null ) {
540
528
return ;
541
529
}
542
- // index + EXTRA_TOP_CELLS because of iframe and style cells
543
- // the offset+1 is I think compensating for a bug maybe in
544
- // virtuoso or our use of it.
545
530
virtuosoRef . current ?. scrollToIndex ( {
546
- index : index + EXTRA_TOP_CELLS ,
531
+ index,
547
532
offset : offset + 1 ,
548
533
} ) ;
549
534
requestAnimationFrame ( ( ) => {
550
535
virtuosoRef . current ?. scrollToIndex ( {
551
- index : index + EXTRA_TOP_CELLS ,
536
+ index,
552
537
offset : offset + 1 ,
553
538
} ) ;
554
539
} ) ;
@@ -564,62 +549,26 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
564
549
}
565
550
} , [ cells ] ) ;
566
551
567
- // allStyles -- the CSS in <style> blocks in text/html outputs
568
- // of all cells. We gather this and place it in a special cell
569
- // at the top, since that such css doesn't disappear when the cells
570
- // that produced it are scrolled off the screen. See
571
- // https://github.com/sagemathinc/cocalc/issues/5943
572
- // We only update allStyles with a debounce of 1s, since it
573
- // can be time consuming as it involves a scan of the entire notebook.
574
- const [ debouncedCells ] = useDebounce ( cells , 1000 ) ;
575
- const allStyles = useMemo ( ( ) => {
576
- if ( ! use_windowed_list ) return "" ;
577
- let value = "" ;
578
- cell_list . forEach ( ( id ) => {
579
- ( debouncedCells . getIn ( [ id , "output" ] ) as any ) ?. forEach ( ( output ) => {
580
- // I hit a case in prod of output not being defined. Given the
581
- // debounce and how debouncedCells might not match up with cell_list,
582
- // and how output is going from markdown cells or maybe cleared cells,
583
- // it seems plausible output could contain an undefined entry.
584
- const html = output ?. getIn ( [ "data" , "text/html" ] ) ;
585
- if ( html ?. includes ( "style" ) ) {
586
- // parse out and include style tags
587
- for ( const x of $ ( "<div>" + html + "</div>" ) . find ( "style" ) ) {
588
- value += x . innerHTML . trim ( ) + "\n\n" ;
589
- }
590
- }
591
- } ) ;
592
- } ) ;
593
- return value ;
594
- } , [ debouncedCells , use_windowed_list ] ) ;
595
-
596
552
const fileContext = useFileContext ( ) ;
597
553
598
554
let body ;
599
555
600
- const iframeDivRef = useRef < HTMLDivElement > ( null ) ;
601
556
const cellListDivRef = useRef < HTMLDivElement > ( null ) ;
602
557
const virtuosoHeightsRef = useRef < { [ index : number ] : number } > ( { } ) ;
603
558
if ( use_windowed_list ) {
604
559
body = (
605
- < StableHtmlContext . Provider
606
- value = { { iframeDivRef, cellListDivRef, iframeOnScrolls } }
607
- >
560
+ < StableHtmlContext . Provider value = { { cellListDivRef, iframeOnScrolls } } >
608
561
< div ref = { cellListDivRef } className = "smc-vfill" >
609
562
< Virtuoso
610
563
ref = { virtuosoRef }
611
564
onClick = { actions != null && complete != null ? on_click : undefined }
612
- topItemCount = { EXTRA_TOP_CELLS }
565
+ topItemCount = { 0 }
613
566
style = { {
614
567
fontSize : `${ font_size } px` ,
615
568
flex : 1 ,
616
569
overflowX : "hidden" ,
617
570
} }
618
- totalCount = {
619
- cell_list . size +
620
- EXTRA_TOP_CELLS /* +EXTRA_TOP_CELLS due to the iframe cell and style cell at the top */ +
621
- EXTRA_BOTTOM_CELLS
622
- }
571
+ totalCount = { cell_list . size + EXTRA_BOTTOM_CELLS }
623
572
itemSize = { ( el ) => {
624
573
// We capture measured heights -- see big coment above the
625
574
// the DivTempHeight component below for why this is needed
@@ -637,29 +586,17 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
637
586
return h ;
638
587
} }
639
588
itemContent = { ( index ) => {
640
- if ( index == 0 ) {
641
- return (
642
- < div key = "iframes" ref = { iframeDivRef } style = { ITEM_STYLE } >
643
- iframes here
644
- </ div >
645
- ) ;
646
- } else if ( index == 1 ) {
647
- return (
648
- < div key = "styles" ref = { iframeDivRef } style = { ITEM_STYLE } >
649
- < style > { allStyles } </ style >
650
- </ div >
651
- ) ;
652
- } else if ( index == cell_list . size + EXTRA_TOP_CELLS ) {
589
+ if ( index == cell_list . size ) {
653
590
return BOTTOM_PADDING_CELL ;
654
591
}
655
- const id = cell_list . get ( index - EXTRA_TOP_CELLS ) ;
592
+ const id = cell_list . get ( index ) ;
656
593
if ( id == null ) return null ;
657
594
const h = virtuosoHeightsRef . current [ index ] ;
658
595
if ( actions == null ) {
659
596
return render_cell ( {
660
597
id,
661
598
isScrolling : false ,
662
- index : index - EXTRA_TOP_CELLS ,
599
+ index,
663
600
} ) ;
664
601
}
665
602
return (
@@ -668,7 +605,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
668
605
{ render_cell ( {
669
606
id,
670
607
isScrolling : false ,
671
- index : index - EXTRA_TOP_CELLS ,
608
+ index,
672
609
isFirst : id === cell_list . get ( 0 ) ,
673
610
isLast : id === cell_list . get ( - 1 ) ,
674
611
} ) }
0 commit comments