Skip to content

Commit 33eef9e

Browse files
committed
Merge branch 'master' into npm-upd-ts-20240723
2 parents 651ed61 + 504f6cc commit 33eef9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2076
-8393
lines changed

src/compute/pnpm-lock.yaml

Lines changed: 226 additions & 5549 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/frontend/_jupyter.sass

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6+
// I just noticed there is another version of this file in jupyter/_jupyter.sass
7+
// They need to be carefully merged into one! But not today.
8+
69
.smc-jupyter-nbviewer-content
710
border: 1px solid lightgray
811

@@ -108,6 +111,18 @@
108111
.MathJax_SVG_Display
109112
padding-right: 1em
110113

114+
// the following helps a lot with inline math, esp labels in jupyter widgets
115+
.MathJax_SVG
116+
padding: 0 2.5px
117+
.katex
118+
padding: 0 2.5px
119+
120+
// this seems to be missing from jupyter widgets, but is used to implement the according
121+
// https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#accordion
122+
// I.e., without this css rule, accordian is just broken.
123+
.lm-Widget.lm-mod-hidden
124+
display: none !important
125+
111126
.cc-jupyter-buttonbar-dropdown
112127
.ant-dropdown-menu-item
113128
color: $COL_GRAY_D !important

src/packages/frontend/account/ssh-keys/fingerprint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import md5 from "md5";
1111
const colons = (s: string) => s.replace(/(.{2})(?=.)/g, "$1:");
1212

1313
export function compute_fingerprint(pub: string): string {
14-
const pubbuffer = new Buffer(pub, "base64");
14+
const pubbuffer = Buffer.from(pub, "base64");
1515
const key = md5(pubbuffer);
1616
return colons(key);
1717
}

src/packages/frontend/client/project.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,22 @@ export class ProjectClient {
506506
path: string,
507507
model_id: string,
508508
buffer_path: string,
509+
useHttp?: boolean, // ONLY works for home base, NOT compute servers!
509510
): Promise<ArrayBuffer> {
510-
const url = ipywidgetsGetBufferUrl(project_id, path, model_id, buffer_path);
511-
return await (await fetch(url)).arrayBuffer();
511+
if (useHttp) {
512+
const url = ipywidgetsGetBufferUrl(
513+
project_id,
514+
path,
515+
model_id,
516+
buffer_path,
517+
);
518+
return await (await fetch(url)).arrayBuffer();
519+
}
520+
const actions = redux.getEditorActions(project_id, path);
521+
return await actions.jupyter_actions.ipywidgetsGetBuffer(
522+
model_id,
523+
buffer_path,
524+
);
512525
}
513526

514527
// getting, setting, editing, deleting, etc., the api keys for a project

src/packages/frontend/jupyter/_jupyter.sass

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6+
// I just noticed there is another version of this file in ../_jupyter.sass
7+
// They need to be carefully merged into one! But not today.
8+
69
.cocalc-jupyter-rendered
710
img
811
max-width: 100%
@@ -101,3 +104,10 @@
101104
.cocalc-jupyter-menu
102105
.ant-dropdown-trigger:hover
103106
background-color: white
107+
108+
// Make it so the widgets container has position relative,
109+
// which is assumed by some widgets, e.g.,
110+
// %matplotlib widgets
111+
// from pylab import plot; plot([1,2],[3,4])
112+
cocalc-lumino-adapter
113+
position: relative

src/packages/frontend/jupyter/browser-actions.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
} from "../misc/local-storage";
3636
import { parse_headings } from "./contents";
3737
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";
3840

3941
export class JupyterActions extends JupyterActions0 {
4042
public widget_manager?: WidgetManager;
@@ -107,10 +109,10 @@ export class JupyterActions extends JupyterActions0 {
107109
if (ipywidgets_state == null) {
108110
throw Error("bug -- ipywidgets_state must be defined");
109111
}
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+
});
114116
// Stupid hack for now -- this just causes some activity so
115117
// that the syncdb syncs.
116118
// This should not be necessary, and may indicate a bug in the sync layer?
@@ -314,20 +316,6 @@ export class JupyterActions extends JupyterActions0 {
314316
// this.deprecated("focus_unlock");
315317
};
316318

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-
331319
protected close_client_only(): void {
332320
const account = this.redux.getStore("account");
333321
if (account != null) {
@@ -461,11 +449,43 @@ export class JupyterActions extends JupyterActions0 {
461449
this.deprecated("command", name);
462450
};
463451

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);
467477
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+
);
469489

470490
// NOTE: someday move this to the frame-tree actions, since it would
471491
// be generically useful!
@@ -780,9 +800,7 @@ export class JupyterActions extends JupyterActions0 {
780800
}
781801

782802
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");
786804
}
787805

788806
/* Wait until the syncdb is ready *and* there is at

src/packages/frontend/jupyter/cell-output.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function OutputColumn({
144144
}
145145
return (
146146
<CellOutputMessages
147-
scrolled={cell.get("scrolled", true)}
147+
scrolled={cell.get("scrolled")}
148148
output={output}
149149
project_id={project_id}
150150
directory={directory}
@@ -196,7 +196,7 @@ function ControlColumn({ actions, cell, id }) {
196196
<OutputToggle
197197
actions={actions}
198198
id={id}
199-
scrolled={cell.get("scrolled", true)}
199+
scrolled={cell.get("scrolled")}
200200
>
201201
{prompt}
202202
</OutputToggle>

src/packages/frontend/jupyter/cell.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
251251
function getCellStyle(): CSS {
252252
const color = getBorderColor();
253253

254+
// 30px -- make room for InsertCell(above)
255+
const marginTop = props.isFirst
256+
? "30px"
257+
: props.actions != null
258+
? "10px"
259+
: "20px";
260+
254261
const style: React.CSSProperties = {
255262
border: `1px solid ${color}`,
256263
borderLeft: `10px solid ${color}`,
@@ -267,26 +274,23 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
267274
? {
268275
padding: "2px",
269276
margin:
270-
props.actions != null ? "10px 15px 2px 5px" : "20px 15px 2px 5px",
277+
props.actions != null
278+
? `${marginTop} 15px 2px 5px`
279+
: `${marginTop} 15px 2px 5px`,
271280
}
272281
: {
273282
padding: "2px 2px 15px 2px",
274283
margin:
275284
props.actions != null
276-
? "10px 15px -15px 5px"
277-
: "20px 15px -15px 5px",
285+
? `${marginTop} 15px -15px 5px`
286+
: `${marginTop} 15px -15px 5px`,
278287
}),
279288
};
280289

281290
if (props.is_selected) {
282291
style.background = "#e3f2fd";
283292
}
284293

285-
if (props.isFirst) {
286-
// make room for InsertCell(above)
287-
style.marginTop = "30px";
288-
}
289-
290294
return style;
291295
}
292296

src/packages/frontend/jupyter/codemirror-editor.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,11 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
623623
options0.extraKeys["PageDown"] = page_down_key;
624624
options0.extraKeys["Cmd-/"] = "toggleComment";
625625
options0.extraKeys["Ctrl-/"] = "toggleComment";
626-
options0.extraKeys["Ctrl-Enter"] = () => {}; // ignore control+enter, since there's a shortcut
626+
// ignore shift+enter, control+enter, alt+enter and meta+enter since there's a shortcut
627+
options0.extraKeys["Shift-Enter"] = () => {};
628+
options0.extraKeys["Ctrl-Enter"] = () => {};
629+
options0.extraKeys["Alt-Enter"] = () => {};
630+
options0.extraKeys["Cmd-Enter"] = () => {};
627631
/*
628632
Disabled for now since fold state isn't preserved.
629633
if (options0.foldGutter) {

src/packages/frontend/jupyter/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ export function commands(actions: AllActions): {
764764
// on a mac). https://github.com/sagemathinc/cocalc/issues/7000
765765
"run cell": {
766766
i: "play",
767-
m: "Run Selected Cells and Do not Advance",
767+
m: "Run Selected Cells and Do Not Advance",
768768
b: "Stay",
769769
t: "Run all cells that are currently selected. Do not move the selection.",
770770
k: [

0 commit comments

Comments
 (0)