@@ -35,6 +35,8 @@ import {
35
35
} from "../misc/local-storage" ;
36
36
import { parse_headings } from "./contents" ;
37
37
import { webapp_client } from "@cocalc/frontend/webapp-client" ;
38
+ import { bufferToBase64 , base64ToBuffer } from "@cocalc/util/base64" ;
39
+ import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
38
40
39
41
export class JupyterActions extends JupyterActions0 {
40
42
public widget_manager ?: WidgetManager ;
@@ -107,10 +109,10 @@ export class JupyterActions extends JupyterActions0 {
107
109
if ( ipywidgets_state == null ) {
108
110
throw Error ( "bug -- ipywidgets_state must be defined" ) ;
109
111
}
110
- this . widget_manager = new WidgetManager (
111
- ipywidgets_state ,
112
- this . setWidgetModelIdState . bind ( this ) ,
113
- ) ;
112
+ this . widget_manager = new WidgetManager ( {
113
+ ipywidgets_state : ipywidgets_state ! ,
114
+ actions : this ,
115
+ } ) ;
114
116
// Stupid hack for now -- this just causes some activity so
115
117
// that the syncdb syncs.
116
118
// This should not be necessary, and may indicate a bug in the sync layer?
@@ -314,20 +316,6 @@ export class JupyterActions extends JupyterActions0 {
314
316
// this.deprecated("focus_unlock");
315
317
} ;
316
318
317
- private setWidgetModelIdState (
318
- model_id : string ,
319
- state : string | null , // '' = good; 'nonempty' = bad; null=delete
320
- ) : void {
321
- let widgetModelIdState : Map < string , string > =
322
- this . store . get ( "widgetModelIdState" ) ;
323
- if ( state === null ) {
324
- widgetModelIdState = widgetModelIdState . delete ( model_id ) ;
325
- } else {
326
- widgetModelIdState = widgetModelIdState . set ( model_id , state ) ;
327
- }
328
- this . setState ( { widgetModelIdState } ) ;
329
- }
330
-
331
319
protected close_client_only ( ) : void {
332
320
const account = this . redux . getStore ( "account" ) ;
333
321
if ( account != null ) {
@@ -461,11 +449,43 @@ export class JupyterActions extends JupyterActions0 {
461
449
this . deprecated ( "command" , name ) ;
462
450
} ;
463
451
464
- public send_comm_message_to_kernel ( comm_id : string , data : any ) : string {
465
- const msg_id = uuid ( ) ;
466
- this . api_call ( "comm" , [ msg_id , comm_id , data ] ) ;
452
+ send_comm_message_to_kernel = async ( {
453
+ msg_id,
454
+ comm_id,
455
+ target_name,
456
+ data,
457
+ buffers,
458
+ } : {
459
+ msg_id ?: string ;
460
+ comm_id : string ;
461
+ target_name : string ;
462
+ data : unknown ;
463
+ buffers ?: ArrayBuffer [ ] | ArrayBufferView [ ] ;
464
+ } ) : Promise < string > => {
465
+ if ( ! msg_id ) {
466
+ msg_id = uuid ( ) ;
467
+ }
468
+ let buffers64 ;
469
+ if ( buffers != null ) {
470
+ buffers64 = buffers . map ( bufferToBase64 ) ;
471
+ } else {
472
+ buffers64 = [ ] ;
473
+ }
474
+ const msg = { msg_id, target_name, comm_id, data, buffers64 } ;
475
+ await this . api_call ( "comm" , msg ) ;
476
+ // console.log("send_comm_message_to_kernel", "sent", msg);
467
477
return msg_id ;
468
- }
478
+ } ;
479
+
480
+ ipywidgetsGetBuffer = reuseInFlight (
481
+ async ( model_id : string , buffer_path : string ) : Promise < ArrayBuffer > => {
482
+ const { buffer64 } = await this . api_call ( "ipywidgets-get-buffer" , {
483
+ model_id,
484
+ buffer_path,
485
+ } ) ;
486
+ return base64ToBuffer ( buffer64 ) ;
487
+ } ,
488
+ ) ;
469
489
470
490
// NOTE: someday move this to the frame-tree actions, since it would
471
491
// be generically useful!
@@ -780,9 +800,7 @@ export class JupyterActions extends JupyterActions0 {
780
800
}
781
801
782
802
public custom_jupyter_kernel_docs ( ) : void {
783
- open_new_tab (
784
- "https://doc.cocalc.com/howto/custom-jupyter-kernel.html" ,
785
- ) ;
803
+ open_new_tab ( "https://doc.cocalc.com/howto/custom-jupyter-kernel.html" ) ;
786
804
}
787
805
788
806
/* Wait until the syncdb is ready *and* there is at
0 commit comments