Skip to content

Commit 2140f8a

Browse files
committed
frontend/frame-editors: nail down types of each frame editor spec description
1 parent fe02256 commit 2140f8a

File tree

9 files changed

+313
-248
lines changed

9 files changed

+313
-248
lines changed

src/packages/frontend/frame-editors/code-editor/editor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ export const SHELLS = {
3131
ml: "ocaml",
3232
pl: "perl",
3333
rb: "ruby",
34-
};
34+
} as const;
3535

36-
export const cm = {
36+
export const cm: EditorDescription = {
37+
type: "code",
3738
short: "Code",
3839
name: "Source Code",
3940
icon: "code",
@@ -65,13 +66,13 @@ export const cm = {
6566
},
6667
},
6768
},
68-
} as EditorDescription;
69+
} as const;
6970

7071
const EDITOR_SPEC = {
7172
cm,
7273
terminal,
7374
time_travel,
74-
};
75+
} as const;
7576

7677
export const Editor = createEditor({
7778
format_bar: false,

src/packages/frontend/frame-editors/frame-tree/frame-tree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { copy, hidden_meta_file, is_different } from "@cocalc/util/misc";
3232
import { delay } from "awaiting";
3333
import { Map, Set } from "immutable";
3434
import React from "react";
35+
3536
import {
3637
ReactDOM,
3738
redux,
@@ -290,8 +291,7 @@ export const FrameTree: React.FC<FrameTreeProps> = React.memo(
290291
let name_leaf = name;
291292
let actions_leaf = actions;
292293
if (
293-
typeof spec.name != "string" &&
294-
spec.name?.id === "labels.timetravel" &&
294+
spec.type === "timetravel" &&
295295
!(actions instanceof TimeTravelActions)
296296
) {
297297
if (path_leaf.slice(path_leaf.length - 12) != ".time-travel") {

src/packages/frontend/frame-editors/frame-tree/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,28 @@ export type ErrorStyles = undefined | "monospace";
3535

3636
export type ConnectionStatus = "disconnected" | "connected" | "connecting";
3737

38+
// Each editor gets its own unique type. This is useful to check which editor it is.
39+
// e.g. #7787 was caused by merely checking on the name, which had changed.
40+
type EditorType =
41+
| "settings"
42+
| "maarkdown-toc"
43+
| "markdown"
44+
| "introspect"
45+
| "jupyter_json_view"
46+
| "jupyter_json_edit"
47+
| "jupyter-toc"
48+
| "timetravel"
49+
| "slate"
50+
| "jupyter"
51+
| "latex"
52+
| "wiki"
53+
| "cm"
54+
| "snippets"
55+
| "slideshow-revealjs";
56+
3857
// Editor spec
3958
export interface EditorDescription {
59+
type: EditorType;
4060
short: string | IntlMessage; // short description of the editor
4161
name: string | IntlMessage; // slightly longer description
4262
icon: IconName;

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 93 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -54,81 +54,102 @@ const jupyterCommands = set([
5454
"compute_server",
5555
]);
5656

57-
export const EDITOR_SPEC = {
58-
jupyter_cell_notebook: {
59-
short: "Jupyter",
60-
name: "Jupyter Notebook",
61-
icon: "ipynb",
62-
component: CellNotebook,
63-
commands: jupyterCommands,
64-
buttons: set([
65-
"jupyter-insert-cell",
66-
"jupyter-run current cell and select next",
67-
"jupyter-interrupt kernel",
68-
"jupyter-restart",
69-
"jupyter-cell-type",
70-
"jupyter-cell-format",
71-
"jupyter-cell-toolbar",
72-
"jupyter-nbgrader validate",
73-
]),
74-
customizeCommands: {
75-
guide: {
76-
label: "Snippets",
77-
icon: SNIPPET_ICON_NAME,
78-
title: "Open a panel containing code snippets.",
79-
},
80-
shell: {
81-
label: jupyter.editor.console_label,
82-
icon: "ipynb",
83-
title: jupyter.editor.console_title,
84-
},
57+
const jupyter_cell_notebook: EditorDescription = {
58+
type: "jupyter",
59+
short: "Jupyter",
60+
name: "Jupyter Notebook",
61+
icon: "ipynb",
62+
component: CellNotebook,
63+
commands: jupyterCommands,
64+
buttons: set([
65+
"jupyter-insert-cell",
66+
"jupyter-run current cell and select next",
67+
"jupyter-interrupt kernel",
68+
"jupyter-restart",
69+
"jupyter-cell-type",
70+
"jupyter-cell-format",
71+
"jupyter-cell-toolbar",
72+
"jupyter-nbgrader validate",
73+
]),
74+
customizeCommands: {
75+
guide: {
76+
label: "Snippets",
77+
icon: SNIPPET_ICON_NAME,
78+
title: "Open a panel containing code snippets.",
79+
},
80+
shell: {
81+
label: jupyter.editor.console_label,
82+
icon: "ipynb",
83+
title: jupyter.editor.console_title,
8584
},
86-
} as EditorDescription,
87-
commands_guide: {
88-
short: labels.snippets,
89-
name: labels.snippets,
90-
icon: SNIPPET_ICON_NAME,
91-
component: JupyterSnippets,
92-
commands: set(["decrease_font_size", "increase_font_size"]),
93-
} as EditorDescription,
94-
jupyter_slideshow_revealjs: {
95-
short: "Slideshow",
96-
name: "Slideshow (Reveal.js)",
97-
icon: "slides",
98-
component: Slideshow,
99-
commands: set(["build"]),
100-
} as EditorDescription,
101-
jupyter_table_of_contents: {
102-
short: editor.table_of_contents_short,
103-
name: editor.table_of_contents_name,
104-
icon: "align-right",
105-
component: TableOfContents,
106-
commands: set(["decrease_font_size", "increase_font_size"]),
107-
} as EditorDescription,
108-
introspect: {
109-
short: "Introspect",
110-
name: "Introspection",
111-
icon: "info",
112-
component: Introspect,
113-
commands: set(["decrease_font_size", "increase_font_size"]),
114-
} as EditorDescription,
85+
},
86+
} as const;
87+
88+
const commands_guide: EditorDescription = {
89+
type: "snippets",
90+
short: labels.snippets,
91+
name: labels.snippets,
92+
icon: SNIPPET_ICON_NAME,
93+
component: JupyterSnippets,
94+
commands: set(["decrease_font_size", "increase_font_size"]),
95+
} as const;
96+
97+
const jupyter_slideshow_revealjs: EditorDescription = {
98+
type: "slideshow-revealjs",
99+
short: "Slideshow",
100+
name: "Slideshow (Reveal.js)",
101+
icon: "slides",
102+
component: Slideshow,
103+
commands: set(["build"]),
104+
} as const;
105+
106+
const jupyter_table_of_contents: EditorDescription = {
107+
type: "jupyter-toc",
108+
short: editor.table_of_contents_short,
109+
name: editor.table_of_contents_name,
110+
icon: "align-right",
111+
component: TableOfContents,
112+
commands: set(["decrease_font_size", "increase_font_size"]),
113+
} as const;
114+
115+
const introspect: EditorDescription = {
116+
type: "introspect",
117+
short: "Introspect",
118+
name: "Introspection",
119+
icon: "info",
120+
component: Introspect,
121+
commands: set(["decrease_font_size", "increase_font_size"]),
122+
} as const;
123+
124+
const jupyter_json: EditorDescription = {
125+
type: "jupyter_json_view",
126+
short: "JSON view",
127+
name: "Raw JSON viewer",
128+
icon: "js-square",
129+
component: JSONIPynb,
130+
commands: set(["decrease_font_size", "increase_font_size"]),
131+
} as const;
132+
133+
const jupyter_raw: EditorDescription = {
134+
type: "jupyter_json_edit",
135+
short: "JSON edit",
136+
name: "Raw JSON editor",
137+
icon: "markdown",
138+
component: RawIPynb,
139+
commands: set(["decrease_font_size", "increase_font_size"]),
140+
} as const;
141+
142+
export const EDITOR_SPEC = {
143+
jupyter_cell_notebook,
144+
commands_guide,
145+
jupyter_slideshow_revealjs,
146+
jupyter_table_of_contents,
147+
introspect,
115148
terminal,
116149
time_travel,
117-
jupyter_json: {
118-
short: "JSON view",
119-
name: "Raw JSON viewer",
120-
icon: "js-square",
121-
component: JSONIPynb,
122-
commands: set(["decrease_font_size", "increase_font_size"]),
123-
} as EditorDescription,
124-
jupyter_raw: {
125-
short: "JSON edit",
126-
name: "Raw JSON editor",
127-
icon: "markdown",
128-
component: RawIPynb,
129-
commands: set(["decrease_font_size", "increase_font_size"]),
130-
} as EditorDescription,
131-
};
150+
jupyter_json,
151+
jupyter_raw,
152+
} as const;
132153

133154
const JUPYTER_MENUS = {
134155
file: {

0 commit comments

Comments
 (0)