-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.tsx
More file actions
69 lines (60 loc) · 2.17 KB
/
index.tsx
File metadata and controls
69 lines (60 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import dynamic from "next/dynamic";
import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { updateCells, setNotebookSavingStatus } from "../../lib/state/reducer"
import { AppState, NbCell } from "../../lib/typings/types";
const AceEditor = dynamic(
async () => {
const editor = await import('react-ace');
const ace = await import('ace-builds/src-noconflict/ace');
/** @ts-ignore */
import('brace/ext/language_tools'); //Add support for auto complete and snippets
ace.config.set("basePath", "/ace-builds-public-export");
return editor;
},
{
loading: () => (
<div></div>
),
ssr: false,
},
);
const Editor = ({ cell }: { cell: NbCell }) => {
const dispatch = useDispatch();
const { notebooks, activeNotebookName, config } = useSelector((state: { app: AppState }) => state.app)
const notebook = notebooks[activeNotebookName]
const { cells } = notebook
const [code, updateCode] = useState(cell?.content);
const handleCodeChange = (newCode: any) => {
dispatch(setNotebookSavingStatus("unsaved"))
updateCode(newCode);
const newCurrCell = { ...cell, content: newCode }
const newCells = { ...cells, [cell.id]: newCurrCell }
dispatch(updateCells({ newCells, activeNotebookName }))
}
return (
<AceEditor
mode={cell.mode}
theme={config.cellTheme}
value={code}
onChange={handleCodeChange}
fontSize={config.cellFontSize}
width={config.width}
style={{
margin: "2px"
}}
maxLines={Infinity}
cursorStart={1}
minLines={4}
wrapEnabled={true}
setOptions={{
enableBasicAutocompletion: config.cellEnableBasicAutocompletion,
enableLiveAutocompletion: config.cellEnableLiveAutocompletion,
enableSnippets: config.cellEnableSnippets,
showLineNumbers: config.cellShowLineNumbers,
tabSize: config.cellTabSize,
}}
/>
);
};
export default Editor;