@@ -165,12 +165,18 @@ export default function Canvas({
165
165
} : Props ) {
166
166
const isMountedRef = useIsMountedRef ( ) ;
167
167
const frame = useFrameContext ( ) ;
168
+ // note -- if a whiteboard is embedded for view purposes, e.g., in TimeTravel,
169
+ // then this is how we know, and in this case the frame.actions are NOT whiteboard
170
+ // actions but something else.
171
+ const isBoard =
172
+ frame . path . endsWith ( ".board" ) || frame . path . endsWith ( ".slides" ) ;
168
173
const editFocus = frame . desc . get ( "editFocus" ) ;
169
174
const canvasScale = scale0 ?? fontSizeToZoom ( font_size ) ;
170
175
if ( ! margin ) {
171
176
margin = getMargin ( mainFrameType , presentation ) ;
172
177
}
173
- const RenderElt = readOnly ? RenderReadOnlyElement : RenderElement ;
178
+ const RenderElt =
179
+ readOnly || ! isBoard ? RenderReadOnlyElement : RenderElement ;
174
180
175
181
const backgroundDivRef = useRef < any > ( null ) ;
176
182
@@ -260,11 +266,11 @@ export default function Canvas({
260
266
// ensure values are in valid range, if possible.
261
267
left = Math . min (
262
268
0 ,
263
- Math . max ( x , - e . offsetWidth * scaleRef . current + rect . width )
269
+ Math . max ( x , - e . offsetWidth * scaleRef . current + rect . width ) ,
264
270
) ;
265
271
top = Math . min (
266
272
0 ,
267
- Math . max ( y , - e . offsetHeight * scaleRef . current + rect . height )
273
+ Math . max ( y , - e . offsetHeight * scaleRef . current + rect . height ) ,
268
274
) ;
269
275
} else {
270
276
// don't bother with ensuring values in valid range; this happens,
@@ -337,13 +343,13 @@ export default function Canvas({
337
343
{
338
344
target : canvasRef ,
339
345
disabled : isNavigator ,
340
- }
346
+ } ,
341
347
) ;
342
348
343
349
const innerCanvasRef = useRef < any > ( null ) ;
344
350
345
351
const transformsRef = useRef < Transforms > (
346
- getTransforms ( elements , margin , presentation )
352
+ getTransforms ( elements , margin , presentation ) ,
347
353
) ;
348
354
349
355
// This must happen before the render, hence the useLayoutEffect
@@ -400,6 +406,7 @@ export default function Canvas({
400
406
} | null > ( null ) ;
401
407
402
408
useEffect ( ( ) => {
409
+ if ( ! isBoard ) return ;
403
410
// clear selection rect when changing pages.
404
411
setSelectRect ( null ) ;
405
412
frame . actions . clearSelection ( frame . id ) ;
@@ -427,12 +434,12 @@ export default function Canvas({
427
434
penCanvasParamsRef . current = {
428
435
scale : getMaxCanvasSizeScale (
429
436
penDPIFactor * rect . width ,
430
- penDPIFactor * rect . height
437
+ penDPIFactor * rect . height ,
431
438
) ,
432
439
rect,
433
440
} ;
434
441
}
435
- if ( presentation ) {
442
+ if ( presentation && isBoard ) {
436
443
// always re-fit to screen on resize in presentation mode.
437
444
frame . actions . fitToScreen ( frame . id , true ) ;
438
445
}
@@ -460,8 +467,8 @@ export default function Canvas({
460
467
461
468
// If no set viewport, fit to screen.
462
469
useEffect ( ( ) => {
463
- if ( isNavigator ) return ;
464
- if ( frame . desc . get ( "viewport" ) == null ) {
470
+ if ( isNavigator || ! isBoard ) return ;
471
+ if ( frame . desc . get ( "viewport" ) == null && isBoard ) {
465
472
// document was never opened before in this browser,
466
473
// so fit to screen.
467
474
frame . actions . fitToScreen ( frame . id , true ) ;
@@ -514,7 +521,7 @@ export default function Canvas({
514
521
// on the page; also set fitToScreen back to false in
515
522
// frame tree data.
516
523
useLayoutEffect ( ( ) => {
517
- if ( isNavigator || ! frame . desc . get ( "fitToScreen" ) ) return ;
524
+ if ( isNavigator || ! frame . desc . get ( "fitToScreen" ) || ! isBoard ) return ;
518
525
try {
519
526
const viewport = getViewportData ( ) ;
520
527
if ( viewport == null ) return ;
@@ -537,7 +544,7 @@ export default function Canvas({
537
544
const s =
538
545
Math . min (
539
546
2 / factor ,
540
- Math . max ( MIN_ZOOM , fitRectToRect ( rect , viewport ) . scale * canvasScale )
547
+ Math . max ( MIN_ZOOM , fitRectToRect ( rect , viewport ) . scale * canvasScale ) ,
541
548
) * factor ;
542
549
scale . set ( s ) ;
543
550
frame . actions . set_font_size ( frame . id , zoomToFontSize ( s ) ) ;
@@ -556,7 +563,9 @@ export default function Canvas({
556
563
} , [ frame . desc . get ( "fitToScreen" ) ] ) ;
557
564
558
565
const edgeStart =
559
- selectedTool == "edge" ? ( frame . desc . getIn ( [ "edgeStart" , "id" ] ) as string | undefined ) : undefined ;
566
+ selectedTool == "edge"
567
+ ? ( frame . desc . getIn ( [ "edgeStart" , "id" ] ) as string | undefined )
568
+ : undefined ;
560
569
561
570
let selectionHandled = false ;
562
571
function processElement ( element , isNavRectangle = false ) {
@@ -586,10 +595,11 @@ export default function Canvas({
586
595
selected = { selection ?. has ( element . id ) }
587
596
previewMode = { previewMode }
588
597
onClick = { ( e ) => {
598
+ if ( ! isBoard ) return ;
589
599
frame . actions . setSelection (
590
600
frame . id ,
591
601
element . id ,
592
- e . altKey || e . shiftKey || e . metaKey ? "add" : "only"
602
+ e . altKey || e . shiftKey || e . metaKey ? "add" : "only" ,
593
603
) ;
594
604
} }
595
605
/>
@@ -751,7 +761,7 @@ export default function Canvas({
751
761
// in the selection.
752
762
// TODO: This could be optimized with better data structures...
753
763
const selectedElements = elements . filter ( ( element ) =>
754
- selection . has ( element . id )
764
+ selection . has ( element . id ) ,
755
765
) ;
756
766
const selectedRects : Element [ ] = [ ] ;
757
767
let multi : undefined | boolean = undefined ;
@@ -796,7 +806,7 @@ export default function Canvas({
796
806
{ ! isAllEdges && (
797
807
< RenderElt element = { element } canvasScale = { canvasScale } focused />
798
808
) }
799
- </ Focused >
809
+ </ Focused > ,
800
810
) ;
801
811
}
802
812
@@ -817,7 +827,7 @@ export default function Canvas({
817
827
elementsMap = { elementsMap }
818
828
transforms = { transformsRef . current }
819
829
zIndex = { 0 }
820
- />
830
+ /> ,
821
831
) ;
822
832
}
823
833
@@ -836,6 +846,7 @@ export default function Canvas({
836
846
onStop = { ( _ , data ) => {
837
847
if ( visible == null ) return ;
838
848
const { x, y } = centerOfRect ( visible ) ;
849
+ if ( ! isBoard ) return ;
839
850
frame . actions . setViewportCenter ( frame . id , {
840
851
x : x + data . x ,
841
852
y : y + data . y ,
@@ -860,10 +871,10 @@ export default function Canvas({
860
871
background : "rgba(200,200,200,0.2)" ,
861
872
} ,
862
873
} ,
863
- true
874
+ true ,
864
875
) }
865
876
</ div >
866
- </ Draggable >
877
+ </ Draggable > ,
867
878
) ;
868
879
}
869
880
}
@@ -890,7 +901,7 @@ export default function Canvas({
890
901
function windowToData ( { x, y } : Point ) : Point {
891
902
return transformsRef . current . windowToDataNoScale (
892
903
x / scaleRef . current ,
893
- y / scaleRef . current
904
+ y / scaleRef . current ,
894
905
) ;
895
906
}
896
907
function dataToWindow ( { x, y } : Point ) : Point {
@@ -991,6 +1002,7 @@ export default function Canvas({
991
1002
const saveViewport = isNavigator
992
1003
? ( ) => { }
993
1004
: useMemo ( ( ) => {
1005
+ if ( ! isBoard ) return ( ) => { } ;
994
1006
return throttle ( ( ) => {
995
1007
const viewport = getViewportData ( ) ;
996
1008
if ( viewport ) {
@@ -1069,7 +1081,7 @@ export default function Canvas({
1069
1081
const p1 = mousePath . current [ 1 ] ;
1070
1082
const rect = pointsToRect (
1071
1083
transformsRef . current . windowToDataNoScale ( p0 . x , p0 . y ) ,
1072
- transformsRef . current . windowToDataNoScale ( p1 . x , p1 . y )
1084
+ transformsRef . current . windowToDataNoScale ( p1 . x , p1 . y ) ,
1073
1085
) ;
1074
1086
if ( selectedTool == "frame" ) {
1075
1087
// make a frame at the selection.
@@ -1085,7 +1097,7 @@ export default function Canvas({
1085
1097
frame . actions . createElement (
1086
1098
frame . id ,
1087
1099
{ ...elt , ...rect , z : transformsRef . current . zMin - 1 } ,
1088
- true
1100
+ true ,
1089
1101
) ;
1090
1102
frame . actions . setSelectedTool ( frame . id , "select" ) ;
1091
1103
// NOTE: we do NOT do "frame.actions.setSelection(frame.id, id);"
@@ -1176,7 +1188,7 @@ export default function Canvas({
1176
1188
data : { path : compressPath ( path ) , ...getToolElement ( "pen" ) . data } ,
1177
1189
type : "pen" ,
1178
1190
} ,
1179
- true
1191
+ true ,
1180
1192
) ;
1181
1193
1182
1194
return ;
@@ -1204,7 +1216,7 @@ export default function Canvas({
1204
1216
e : {
1205
1217
clientX : number ;
1206
1218
clientY : number ;
1207
- } | null
1219
+ } | null ,
1208
1220
) : { x : number ; y : number } | undefined {
1209
1221
if ( e == null ) return ;
1210
1222
const c = canvasRef . current ;
@@ -1291,7 +1303,7 @@ export default function Canvas({
1291
1303
const path : Point [ ] = [ ] ;
1292
1304
const { rect } = penCanvasParamsRef . current ;
1293
1305
for ( const point of penPreviewPath . current . slice (
1294
- penPreviewPath . current . length - 2
1306
+ penPreviewPath . current . length - 2 ,
1295
1307
) ) {
1296
1308
path . push ( {
1297
1309
x : ( point . x - rect . left ) / penDPIFactor ,
@@ -1328,7 +1340,7 @@ export default function Canvas({
1328
1340
if ( point == null ) return ;
1329
1341
const { x, y } = transformsRef . current . windowToDataNoScale (
1330
1342
point . x ,
1331
- point . y
1343
+ point . y ,
1332
1344
) ;
1333
1345
const size = Math . max ( 2 , ERASE_SIZE / scaleRef . current ) ;
1334
1346
const rect = {
@@ -1341,6 +1353,10 @@ export default function Canvas({
1341
1353
}
1342
1354
} ;
1343
1355
1356
+ if ( isNavigator && ! isBoard ) {
1357
+ return null ;
1358
+ }
1359
+
1344
1360
// if (!isNavigator) {
1345
1361
// window.x = {
1346
1362
// scaleDivRef,
@@ -1419,7 +1435,7 @@ export default function Canvas({
1419
1435
const encoded = encodeForCopy ( selectedElements ) ;
1420
1436
event . clipboardData . setData (
1421
1437
"application/x-cocalc-whiteboard" ,
1422
- encoded
1438
+ encoded ,
1423
1439
) ;
1424
1440
}
1425
1441
}
@@ -1437,7 +1453,7 @@ export default function Canvas({
1437
1453
const encoded = encodeForCopy ( selectedElements ) ;
1438
1454
event . clipboardData . setData (
1439
1455
"application/x-cocalc-whiteboard" ,
1440
- encoded
1456
+ encoded ,
1441
1457
) ;
1442
1458
frame . actions . deleteElements ( selectedElements ) ;
1443
1459
frame . actions . clearSelection ( frame . id ) ;
@@ -1449,7 +1465,7 @@ export default function Canvas({
1449
1465
: ( event : ClipboardEvent < HTMLDivElement > ) => {
1450
1466
if ( editFocus ) return ;
1451
1467
const encoded = event . clipboardData . getData (
1452
- "application/x-cocalc-whiteboard"
1468
+ "application/x-cocalc-whiteboard" ,
1453
1469
) ;
1454
1470
if ( encoded ) {
1455
1471
// copy/paste between whiteboards of their own structured data
@@ -1470,7 +1486,7 @@ export default function Canvas({
1470
1486
const ids = frame . actions . insertElements (
1471
1487
frame . id ,
1472
1488
pastedElements ,
1473
- target
1489
+ target ,
1474
1490
) ;
1475
1491
frame . actions . setSelectionMulti ( frame . id , ids ) ;
1476
1492
} else {
@@ -1584,7 +1600,7 @@ function getSelectedElements({
1584
1600
1585
1601
function getMargin (
1586
1602
mainFrameType : MainFrameType ,
1587
- presentation ?: boolean
1603
+ presentation ?: boolean ,
1588
1604
) : number {
1589
1605
if ( presentation ) {
1590
1606
return 0 ;
0 commit comments