Skip to content

Commit fccac5b

Browse files
committed
Merge branch 'ref/typescript' of https://github.com/javascriptdata/dnotebook into ref/typescript
2 parents 7828821 + 356463c commit fccac5b

File tree

168 files changed

+16643
-19
lines changed

Some content is hidden

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

168 files changed

+16643
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/frontend/.env
2+
src/server/.env

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,42 @@
1010
- Easily build, train and prototype machine learning models using different tools like Tensorflow.js
1111
- Learn JavaScript in an interactive/visual style. This can hasten learning and understanding.
1212
- Plain Experimentation/Prototyping. Any experimentation performed in JavaScript can run on Dnotebooks.
13+
## Tech stack
14+
* [Next.js](https://nextjs.org/)
15+
* React
16+
* [Material UI](https://mui.com/)
17+
* [Tailwind CSS](https://tailwindcss.com/)
18+
* Express
1319

20+
## Developers
1421

15-
### How to install
16-
Dnotebook is hosted on NPM, and can installed via package managers like npm and yarn
17-
22+
* Clone the repo
1823
```sh
19-
npm install -g dnotebook
24+
git clone https://github.com/javascriptdata/dnotebook.git
25+
cd dnotebook
26+
git checkout ref/typescript
2027
```
2128

22-
### Example usage
23-
After installing dnotebook, you can start the server by running the command `dnotebook` in the terminal. This opens a new notebook in your default browser.
24-
25-
26-
![](assets/test-dnotes.gif)
27-
29+
* Install packages with `yarn`. `yarn` is our preferred package manager
2830

29-
You can download the notebook shown above [here](assets/test-notebook.json). To view and interact with the notebook without installing anything, go to [playnotebook.jsdata.org](https://playnotebook.jsdata.org/demo).
31+
```sh
32+
yarn install
33+
```
34+
* Run the app in dev mode
3035

31-
#### [See the Official Getting Started Guide](https://dnotebook.jsdata.org/getting-started)
36+
```sh
37+
yarn dev
38+
```
3239

40+
* Open your browser and navigate to `http://localhost:3000/`
3341

34-
<!-- ## Documentation
35-
The official documentation can be found [here](https://danfo.jsdata.org) -->
3642

3743
### Discussion and Development
38-
Development discussions take place on our [issues](https://github.com/opensource9ja/dnotebook/issues) tab.
44+
Development discussions take place on our [issues](https://github.com/javascriptdata/dnotebook/issues/10) tab.
3945

4046
### Contributing to Dnotebook
4147
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
4248

4349
#### Licence [MIT](https://github.com/opensource9ja/dnotebook/blob/master/LICENCE)
4450

45-
#### Created by [Rising Odegua](https://github.com/risenW) and [Stephen Oni](https://github.com/steveoni)
4651

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
"contributors": [
77
{
88
"name": "Rising Odegua"
9-
},
10-
{
11-
"name": "Stephen Oni"
129
}
1310
],
1411
"files": [
1512
"dnotebook/"
1613
],
14+
"scripts": {
15+
"install": "cd src/frontend && yarn && cd ../server && yarn",
16+
"build": "cd src/frontend && yarn build && cd ../server && yarn build",
17+
"dev": "cd src/frontend && yarn dev && cd ../server && yarn dev",
18+
"start": "cd src/frontend && yarn start && cd ../server && yarn start"
19+
},
1720
"repository": {
1821
"type": "git",
1922
"url": "git+https://github.com/opensource9ja/dnotebook.git"

src/frontend/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

src/frontend/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules/*
5+
.pnp
6+
.pnp.js
7+
8+
# testing
9+
coverage
10+
11+
# next.js
12+
.next/
13+
out/
14+
15+
# production
16+
build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
36+
# typescript
37+
*.tsbuildinfo

src/frontend/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
```
12+
13+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14+
15+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
16+
17+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
18+
19+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import CellEditor from "../CellEditor";
2+
import CellOutputRenderer from "../CellOutputRenderer";
3+
import { useDispatch, useSelector } from "react-redux";
4+
import { useState } from "react";
5+
import NodejsInterpreter from '../../lib/interpreter/server'
6+
import { outputError, NbCell, AppState } from '../../lib/typings/types'
7+
import IconButton from '@mui/material/IconButton';
8+
import SendIcon from '@mui/icons-material/Send';
9+
import LoadingButton from '@mui/lab/LoadingButton';
10+
import CellOptionsBar from "../MenuBar/cellOptions"
11+
import { updateCells } from "../../lib/state/reducer"
12+
import { cleanErrorMessage } from "../../lib/helpers/utils"
13+
14+
const NoteBookCell = ({ cell }: { cell: NbCell }) => {
15+
const dispatch = useDispatch();
16+
const { notebooks, activeNotebookName, interpreterMode } = useSelector((state: { app: AppState }) => state.app)
17+
const notebook = notebooks[activeNotebookName]
18+
const { cells } = notebook
19+
20+
21+
const [cellIsRunning, setCellIsRunning] = useState(false)
22+
const [output, setOutput] = useState("")
23+
const [outputError, setOutputError] = useState("")
24+
const [hasError, setHasError] = useState(false)
25+
26+
27+
const cellRunCallback = (accumulatedResult: string | outputError, hasErrors: boolean) => {
28+
29+
if (hasErrors) {
30+
setHasError(true)
31+
const fullErrorMessage = cleanErrorMessage(accumulatedResult as outputError)
32+
setOutputError(fullErrorMessage)
33+
34+
const newCurrCell = { ...cell, output: "", outputError: fullErrorMessage }
35+
const newCells = { ...cells, [cell.id]: newCurrCell }
36+
dispatch(updateCells({ newCells, activeNotebookName }))
37+
38+
} else {
39+
setHasError(false)
40+
setOutput(accumulatedResult as string)
41+
42+
const newCurrCell = { ...cell, output: accumulatedResult as string, outputError: "" }
43+
const newCells = { ...cells, [cell.id]: newCurrCell }
44+
dispatch(updateCells({ newCells, activeNotebookName }))
45+
46+
}
47+
48+
setCellIsRunning(false)
49+
50+
}
51+
52+
const handleCellRun = () => {
53+
const content = cell.content
54+
const language = cell.mode
55+
56+
if (!content || content.trim() === '') {
57+
return
58+
}
59+
setCellIsRunning(true)
60+
setOutput("")
61+
setOutputError("")
62+
63+
if (interpreterMode === 'node') {
64+
NodejsInterpreter.exec({ content, language, callback: cellRunCallback, activeNotebookName })
65+
.catch((error) => {
66+
setOutputError({
67+
...error,
68+
})
69+
console.log(error)
70+
setCellIsRunning(false)
71+
})
72+
} else {
73+
//execute in browser context
74+
console.log('browser')
75+
}
76+
}
77+
78+
const handleKeyPress = (e: any) => {
79+
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
80+
handleCellRun()
81+
}
82+
}
83+
84+
return (
85+
<section>
86+
<section className="grid grid-rows-1 text-right">
87+
<CellOptionsBar cell={cell} />
88+
</section>
89+
<section className="grid grid-cols-12">
90+
<div className="col-span-1 text-right">
91+
{
92+
cellIsRunning ? (
93+
<LoadingButton loading ></LoadingButton>
94+
95+
) : (
96+
<IconButton
97+
aria-label="delete"
98+
onClick={() => handleCellRun()}
99+
color="primary"
100+
>
101+
<SendIcon />
102+
</IconButton>
103+
)
104+
}
105+
106+
</div>
107+
108+
<div className="col-span-11"
109+
onKeyPress={handleKeyPress}
110+
>
111+
<CellEditor cell={cell} />
112+
<CellOutputRenderer cell={cell} />
113+
</div>
114+
115+
</section>
116+
</section>
117+
)
118+
}
119+
120+
export default NoteBookCell;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import dynamic from "next/dynamic";
2+
import { useState } from "react";
3+
import { useDispatch, useSelector } from "react-redux";
4+
import { updateCells } from "../../lib/state/reducer"
5+
import { AppState, NbCell } from "../../lib/typings/types";
6+
7+
const AceEditor = dynamic(
8+
async () => {
9+
const editor = await import('react-ace');
10+
const ace = await import('ace-builds/src-noconflict/ace');
11+
/** @ts-ignore */
12+
import('brace/ext/language_tools'); //Add support for auto complete and snippets
13+
ace.config.set("basePath", "/ace-builds-public-export");
14+
return editor;
15+
},
16+
{
17+
loading: () => (
18+
<div></div>
19+
),
20+
ssr: false,
21+
},
22+
);
23+
24+
25+
const Editor = ({ cell }: { cell: NbCell }) => {
26+
const dispatch = useDispatch();
27+
28+
const { notebooks, activeNotebookName, config } = useSelector((state: { app: AppState }) => state.app)
29+
const notebook = notebooks[activeNotebookName]
30+
const { cells } = notebook
31+
32+
const [code, updateCode] = useState(cell?.content);
33+
34+
const handleCodeChange = (newCode: any) => {
35+
updateCode(newCode);
36+
const newCurrCell = { ...cell, content: newCode }
37+
38+
const newCells = { ...cells, [cell.id]: newCurrCell }
39+
dispatch(updateCells({ newCells, activeNotebookName }))
40+
}
41+
42+
return (
43+
<AceEditor
44+
mode={cell.mode}
45+
theme={config.cellTheme}
46+
value={code}
47+
onChange={handleCodeChange}
48+
fontSize={config.cellFontSize}
49+
width={config.width}
50+
style={{
51+
margin: "2px"
52+
}}
53+
maxLines={Infinity}
54+
cursorStart={1}
55+
minLines={4}
56+
wrapEnabled={true}
57+
setOptions={{
58+
enableBasicAutocompletion: config.cellEnableBasicAutocompletion,
59+
enableLiveAutocompletion: config.cellEnableLiveAutocompletion,
60+
enableSnippets: config.cellEnableSnippets,
61+
showLineNumbers: config.cellShowLineNumbers,
62+
tabSize: config.cellTabSize,
63+
}}
64+
/>
65+
);
66+
};
67+
68+
export default Editor;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NbCell } from "../../lib/typings/types";
2+
3+
4+
const cellOutputRenderer = ({ cell }: { cell: NbCell }) => {
5+
return (
6+
<div>
7+
{cell.outputError !== "" ? (
8+
<div className="text-red-400 p-3" dangerouslySetInnerHTML={{ __html: cell.outputError }}></div>
9+
) : (
10+
<div>
11+
<div className="p-3" dangerouslySetInnerHTML={{ __html: cell.output }}></div>
12+
</div>
13+
)}
14+
</div>
15+
)
16+
}
17+
18+
export default cellOutputRenderer;

0 commit comments

Comments
 (0)