Skip to content

Commit 725706e

Browse files
authored
Merge pull request #8347 from sagemathinc/chat-fix-fontSize-typing
frontend/frame-editor: add typing info to instantiated FrameTreeLeaf
2 parents b280398 + fe57a8a commit 725706e

File tree

38 files changed

+380
-287
lines changed

38 files changed

+380
-287
lines changed

src/packages/frontend/account/editor-settings/color-schemes.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
*/
55

66
import { useIntl } from "react-intl";
7-
import { Map } from "immutable";
7+
8+
import { Button } from "@cocalc/frontend/antd-bootstrap";
89
import { LabeledRow, SelectorInput } from "@cocalc/frontend/components";
9-
import { CodeMirrorStatic } from "@cocalc/frontend/jupyter/codemirror-static";
1010
import { cm_options } from "@cocalc/frontend/frame-editors/codemirror/cm-options";
11-
import { Button } from "@cocalc/frontend/antd-bootstrap";
11+
import { CodeMirrorStatic } from "@cocalc/frontend/jupyter/codemirror-static";
1212
import { AsyncComponent } from "@cocalc/frontend/misc/async-component";
1313
import { EDITOR_COLOR_SCHEMES } from "@cocalc/util/db-schema/accounts";
14+
import { AccountState } from "../types";
1415

1516
interface Props {
1617
theme: string;
@@ -71,7 +72,10 @@ def is_prime_lucas_lehmer(p):
7172
// bundle. This probably doesn't work so well yet though.
7273
const CodeMirrorPreview = AsyncComponent(async () => {
7374
await import("@cocalc/frontend/codemirror/init");
74-
return (props: { editor_settings: Map<string, any>; font_size?: number }) => {
75+
return (props: {
76+
editor_settings: AccountState["editor_settings"];
77+
font_size?: number;
78+
}) => {
7579
// Ensure that we load all the codemirror plugins, modes, etc., so that
7680
// we can show the codemirror preview of the current theme, fonts, etc.
7781
import("@cocalc/frontend/codemirror/init");

src/packages/frontend/account/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export interface AccountState {
3636
editor_settings: TypedMap<{
3737
jupyter_classic?: boolean;
3838
jupyter?: { kernel: string };
39+
theme?: string;
40+
physical_keyboard?: string;
41+
keyboard_variant?: string;
3942
}>;
4043
font_size: number;
4144
other_settings: TypedMap<{

src/packages/frontend/chat/chatroom.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Icon, Loading } from "@cocalc/frontend/components";
2020
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
2121
import { FrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
2222
import { hoursToTimeIntervalHuman } from "@cocalc/util/misc";
23-
import type { ChatActions } from "./actions";
23+
import { EditorComponentProps } from "../frame-editors/frame-tree/types";
2424
import { ChatLog } from "./chat-log";
2525
import Filter from "./filter";
2626
import { FoldAllThreads } from "./fold-threads";
@@ -65,23 +65,14 @@ const CHAT_LOG_STYLE: React.CSSProperties = {
6565
position: "relative",
6666
} as const;
6767

68-
interface Props {
69-
actions: ChatActions;
70-
project_id: string;
71-
path: string;
72-
is_visible?: boolean;
73-
font_size: number;
74-
desc?;
75-
}
76-
7768
export function ChatRoom({
7869
actions,
7970
project_id,
8071
path,
8172
is_visible,
8273
font_size,
8374
desc,
84-
}: Props) {
75+
}: EditorComponentProps) {
8576
const useEditor = useEditorRedux<ChatState>({ project_id, path });
8677
const [input, setInput] = useState("");
8778
const search = desc?.get("data-search") ?? "";

src/packages/frontend/chat/side-chat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Button, Flex, Space, Tooltip } from "antd";
2-
import { CSSProperties, useCallback, useEffect, useRef, useState } from "react";
2+
import { useCallback, useEffect, useRef, useState } from "react";
33

44
import {
5+
CSS,
56
redux,
67
useActions,
78
useRedux,
@@ -26,7 +27,7 @@ import VideoChatButton from "./video/launch-button";
2627
interface Props {
2728
project_id: string;
2829
path: string;
29-
style?: CSSProperties;
30+
style?: CSS;
3031
fontSize?: number;
3132
actions?: ChatActions;
3233
desc?;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createElement } from "react";
1111

1212
import { ChatRoom } from "@cocalc/frontend/chat/chatroom";
1313
import { createEditor } from "@cocalc/frontend/frame-editors/frame-tree/editor";
14-
import type { EditorDescription } from "@cocalc/frontend/frame-editors/frame-tree/types";
14+
import type { EditorComponentProps, EditorDescription } from "@cocalc/frontend/frame-editors/frame-tree/types";
1515
import { terminal } from "@cocalc/frontend/frame-editors/terminal-editor/editor";
1616
import { time_travel } from "@cocalc/frontend/frame-editors/time-travel-editor/editor";
1717
import { set } from "@cocalc/util/misc";
@@ -22,7 +22,7 @@ const chatroom: EditorDescription = {
2222
short: "Chatroom",
2323
name: "Chatroom",
2424
icon: "comment",
25-
component: (props) => {
25+
component: (props: EditorComponentProps) => {
2626
const actions = props.actions.getChatActions(props.id);
2727
return createElement(ChatRoom, {
2828
...props,

src/packages/frontend/frame-editors/code-editor/codemirror-editor.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,64 @@ trigger actions when certain props change. This manages the state of a single
1212
codemirror editor instance mainly for use in a frame tree.
1313
*/
1414

15-
import { SAVE_DEBOUNCE_MS } from "./const";
16-
import { Map, Set } from "immutable";
1715
import * as CodeMirror from "codemirror";
16+
import { Map, Set } from "immutable";
17+
1818
import {
19+
CSS,
1920
React,
2021
ReactDOM,
2122
Rendered,
22-
CSS,
2323
useEffect,
2424
useIsMountedRef,
2525
useRef,
2626
useState,
27-
} from "../../app-framework";
28-
import { debounce, throttle, isEqual } from "lodash";
27+
} from "@cocalc/frontend/app-framework";
28+
import { initFold, saveFold } from "@cocalc/frontend/codemirror/util";
2929
import { Cursors } from "@cocalc/frontend/jupyter/cursors";
30+
import { debounce, isEqual, throttle } from "lodash";
3031
import { cm_options } from "../codemirror/cm-options";
31-
import { init_style_hacks } from "../codemirror/util";
3232
import { get_state, set_state } from "../codemirror/codemirror-state";
33-
import { has_doc, set_doc, get_linked_doc } from "./doc";
34-
import { GutterMarkers } from "./codemirror-gutter-markers";
35-
import { Actions } from "./actions";
36-
import { EditorState } from "../frame-tree/types";
33+
import { init_style_hacks } from "../codemirror/util";
3734
import { Path } from "../frame-tree/path";
38-
import { initFold, saveFold } from "@cocalc/frontend/codemirror/util";
35+
import { EditorState } from "../frame-tree/types";
36+
import { Actions } from "./actions";
37+
import { GutterMarkers } from "./codemirror-gutter-markers";
38+
import { SAVE_DEBOUNCE_MS } from "./const";
39+
import { get_linked_doc, has_doc, set_doc } from "./doc";
40+
import { AccountState } from "../../account/types";
3941

40-
const STYLE = {
42+
const STYLE: CSS = {
4143
width: "100%",
4244
overflow: "auto",
43-
marginbottom: "1ex",
44-
minheight: "2em",
45+
// marginbottom: "1ex",
46+
// minheight: "2em",
4547
border: "0px",
4648
background: "#fff",
47-
} as CSS;
49+
} as const;
4850

4951
export interface Props {
5052
id: string;
5153
actions: any;
5254
path: string;
5355
project_id: string;
5456
font_size: number;
55-
cursors: Map<string, any>;
57+
cursors?: Map<string, any>;
5658
editor_state: EditorState;
5759
read_only: boolean;
5860
is_current: boolean;
5961
is_public: boolean;
6062
value?: string; // if defined and is_public, use this static value and editor is read-only (TODO: public was deprecated years ago)
61-
misspelled_words: Set<string> | string; // **or** show these words as not spelled correctly
63+
misspelled_words?: Set<string> | string; // **or** show these words as not spelled correctly
6264
resize: number;
63-
gutters: string[];
64-
gutter_markers: Map<string, any>;
65-
editor_settings: Map<string, any>;
65+
gutters?: string[];
66+
gutter_markers?: Map<string, any>;
67+
editor_settings: AccountState["editor_settings"];
6668
is_subframe?: boolean;
6769
placeholder?: string;
6870
}
6971

70-
export const CodemirrorEditor: React.FC<Props> = React.memo((props) => {
72+
export const CodemirrorEditor: React.FC<Props> = React.memo((props: Props) => {
7173
const [has_cm, set_has_cm] = useState<boolean>(false);
7274

7375
const cmRef = useRef<CodeMirror.Editor | undefined>(undefined);
@@ -139,7 +141,7 @@ export const CodemirrorEditor: React.FC<Props> = React.memo((props) => {
139141

140142
function cm_highlight_misspelled_words(): void {
141143
const words = props.misspelled_words;
142-
if (cmRef.current == null) return;
144+
if (cmRef.current == null || words == null) return;
143145
if (words == "browser") {
144146
// just ensure browser spellcheck is enabled
145147
cmRef.current.setOption("spellcheck", true);
@@ -286,7 +288,7 @@ export const CodemirrorEditor: React.FC<Props> = React.memo((props) => {
286288
const foldKey = `${props.path}\\${props.id}`;
287289
const saveFoldState = () => {
288290
if (cmRef.current != null) {
289-
saveFold(cmRef.current,foldKey);
291+
saveFold(cmRef.current, foldKey);
290292
}
291293
};
292294
cmRef.current.on("fold" as any, saveFoldState);

src/packages/frontend/frame-editors/codemirror/cm-options.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Compute the codemirror options for file with given name,
88
using the given editor settings.
99
*/
1010

11+
import { EDITOR_COLOR_SCHEMES } from "@cocalc/util/db-schema/accounts";
12+
import { path_split } from "@cocalc/util/misc";
1113
import * as CodeMirror from "codemirror";
12-
import { file_associations } from "../../file-associations";
1314
import * as feature from "../../feature";
14-
import { path_split } from "@cocalc/util/misc";
15+
import { file_associations } from "../../file-associations";
1516
import { get_editor_settings } from "../generic/client";
16-
import { EDITOR_COLOR_SCHEMES } from "@cocalc/util/db-schema/accounts";
1717

18-
import { filename_extension_notilde, defaults } from "@cocalc/util/misc";
18+
import { defaults, filename_extension_notilde } from "@cocalc/util/misc";
1919

2020
import { extra_alt_keys } from "./mobile";
21-
import { Map } from "immutable";
2221

22+
import { AccountState } from "../../account/types";
2323
import { valid_indent } from "./util";
2424

2525
function save(cm) {
@@ -36,17 +36,17 @@ export function default_opts(filename) {
3636

3737
export function cm_options(
3838
filename: string, // extension determines editor mode
39-
editor_settings: Map<string, any>,
39+
editor_settings: AccountState["editor_settings"],
4040
gutters: string[] = [], // array of extra gutters
4141
editor_actions: any = undefined,
4242
frame_tree_actions: any = undefined,
43-
frame_id: string = ""
43+
frame_id: string = "",
4444
) {
45-
let theme = editor_settings.get("theme");
45+
let theme = editor_settings?.get("theme");
4646
// if we do not know the theme, fallback to default
47-
if (EDITOR_COLOR_SCHEMES[theme] == null) {
47+
if (!theme || EDITOR_COLOR_SCHEMES[theme] == null) {
4848
console.warn(
49-
`codemirror theme '${theme}' not known -- fallback to 'Default'`
49+
`codemirror theme '${theme}' not known -- fallback to 'Default'`,
5050
);
5151
theme = "default";
5252
}
@@ -57,7 +57,7 @@ export function cm_options(
5757
mode: "txt",
5858
show_trailing_whitespace: editor_settings.get(
5959
"show_trailing_whitespace",
60-
true
60+
true,
6161
),
6262
allow_javascript_eval: true, // if false, the one use of eval isn't allowed.
6363
line_numbers: editor_settings.get("line_numbers", true),
@@ -132,7 +132,7 @@ export function cm_options(
132132
} else {
133133
if (get_editor_settings().get("show_exec_warning")) {
134134
frame_tree_actions.set_error(
135-
"You can evaluate code in a file with the extension 'sagews' or 'ipynb'. Please create a Sage Worksheet or Jupyter notebook instead."
135+
"You can evaluate code in a file with the extension 'sagews' or 'ipynb'. Please create a Sage Worksheet or Jupyter notebook instead.",
136136
);
137137
}
138138
}

src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,37 @@ This is some slightly complicated code to avoid needless duplication.
88
99
It's a bit more complicated than you might expect partly due to the fact
1010
we have to insert these course tab components as frame in a frame tree,
11-
so there is no commoon containing react component that we control...
11+
so there is no common containing react component that we control...
1212
*/
1313

14+
import { Map } from "immutable";
15+
1416
import {
17+
AppRedux,
1518
React,
1619
Rendered,
1720
redux,
18-
AppRedux,
1921
useEditorRedux,
2022
useRedux,
2123
useTypedRedux,
2224
} from "@cocalc/frontend/app-framework";
23-
import { Loading, ActivityDisplay } from "@cocalc/frontend/components";
25+
import { ActivityDisplay, Loading } from "@cocalc/frontend/components";
2426
import ShowError from "@cocalc/frontend/components/error";
27+
import Modals from "@cocalc/frontend/course/modals";
28+
import { PayBanner } from "@cocalc/frontend/course/pay-banner";
2529
import {
2630
AssignmentsMap,
2731
CourseSettingsRecord,
28-
StudentsMap,
32+
CourseStore,
2933
HandoutsMap,
34+
StudentsMap,
3035
} from "@cocalc/frontend/course/store";
31-
import { Map } from "immutable";
32-
import { ProjectMap, UserMap } from "../../todo-types";
33-
import { CourseActions, course_redux_name } from "./course-actions";
36+
import { getScale } from "@cocalc/frontend/frame-editors/frame-tree/hooks";
37+
import { ProjectMap, UserMap } from "@cocalc/frontend/todo-types";
3438
import { values } from "@cocalc/util/misc";
35-
import { CourseTabBar } from "./course-tab-bar";
3639
import type { CourseEditorActions, CourseEditorState } from "./actions";
37-
import { CourseStore } from "@cocalc/frontend/course/store";
38-
import { PayBanner } from "@cocalc/frontend/course/pay-banner";
39-
import Modals from "@cocalc/frontend/course/modals";
40-
import { getScale } from "@cocalc/frontend/frame-editors/frame-tree/hooks";
40+
import { CourseActions, course_redux_name } from "./course-actions";
41+
import { CourseTabBar } from "./course-tab-bar";
4142

4243
export interface FrameProps {
4344
id: string;

0 commit comments

Comments
 (0)