44 * MIT License
55 */
66
7- import { useState } from 'react' ;
7+ import { useState , useMemo } from 'react' ;
88import { $getRoot } from 'lexical' ;
99import styled from 'styled-components' ;
1010import {
@@ -15,13 +15,15 @@ import {
1515} from '@datalayer/jupyter-lexical' ;
1616import {
1717 useNotebookStore ,
18- Jupyter ,
18+ useJupyter ,
19+ JupyterReactTheme ,
1920 Notebook ,
2021 CellSidebar ,
2122 CellSidebarExtension ,
2223} from '@datalayer/jupyter-react' ;
23- import { Box , Button , UnderlineNav } from '@primer/react' ;
24+ import { Button , UnderlineNav } from '@primer/react' ;
2425import { ThreeBarsIcon } from '@primer/octicons-react' ;
26+ import { Box } from '@datalayer/primer-addons' ;
2527import { JSONTree } from 'react-json-tree' ;
2628import { INotebookContent } from '@jupyterlab/nbformat' ;
2729import { INotebookModel } from '@jupyterlab/notebook' ;
@@ -46,11 +48,18 @@ const StyledNotebook = styled.div`
4648
4749const Tabs = ( ) => {
4850 const { editor } = useLexical ( ) ;
51+ const { serviceManager, defaultKernel } = useJupyter ( {
52+ startDefaultKernel : true ,
53+ } ) ;
4954 const notebookStore = useNotebookStore ( ) ;
5055 const [ tab , setTab ] = useState < TabType > ( 'editor' ) ;
5156 const [ notebookContent , setNotebookContent ] = useState < INotebookContent > (
5257 INITIAL_NBFORMAT_MODEL ,
5358 ) ;
59+ const extensions = useMemo (
60+ ( ) => [ new CellSidebarExtension ( { factory : CellSidebar } ) ] ,
61+ [ ] ,
62+ ) ;
5463 const notebook = notebookStore . selectNotebook ( NOTEBOOK_UID ) ;
5564 const goToTab = (
5665 e : any ,
@@ -84,21 +93,21 @@ const Tabs = () => {
8493 < UnderlineNav . Item
8594 href = ""
8695 aria-current = { tab === 'editor' ? 'page' : undefined }
87- onClick = { ( e : any ) => goToTab ( e , 'editor' , notebook ?. model ) }
96+ // onClick={(e: any) => goToTab(e, 'editor', notebook?.model)}
8897 >
8998 Editor
9099 </ UnderlineNav . Item >
91100 < UnderlineNav . Item
92101 href = ""
93102 aria-current = { tab === 'notebook' ? 'page' : undefined }
94- onClick = { ( e : any ) => goToTab ( e , 'notebook' , notebook ?. model ) }
103+ // onClick={(e: any) => goToTab(e, 'notebook', notebook?.model)}
95104 >
96105 Notebook
97106 </ UnderlineNav . Item >
98107 < UnderlineNav . Item
99108 href = ""
100109 aria-current = { tab === 'nbformat' ? 'page' : undefined }
101- onClick = { ( e : any ) => goToTab ( e , 'nbformat' , notebook ?. model ) }
110+ // onClick={(e: any) => goToTab(e, 'nbformat', notebook?.model)}
102111 >
103112 NbFormat
104113 </ UnderlineNav . Item >
@@ -124,11 +133,15 @@ const Tabs = () => {
124133 { tab === 'notebook' && (
125134 < StyledNotebook >
126135 < Box mb = { 3 } >
127- < Notebook
128- id = { NOTEBOOK_UID }
129- nbformat = { notebookContent }
130- extensions = { [ new CellSidebarExtension ( { factory : CellSidebar } ) ] }
131- />
136+ { serviceManager && defaultKernel && (
137+ < Notebook
138+ id = { NOTEBOOK_UID }
139+ kernel = { defaultKernel }
140+ serviceManager = { serviceManager }
141+ nbformat = { notebookContent }
142+ extensions = { extensions }
143+ />
144+ ) }
132145 < Button
133146 onClick = { ( e : React . MouseEvent ) => {
134147 e . preventDefault ( ) ;
@@ -155,11 +168,11 @@ export function AppNbformat() {
155168 < div className = "App" >
156169 < h1 > Jupyter UI ❤️ Lexical</ h1 >
157170 </ div >
158- < Jupyter startDefaultKernel >
171+ < JupyterReactTheme >
159172 < LexicalProvider >
160173 < Tabs />
161174 </ LexicalProvider >
162- </ Jupyter >
175+ </ JupyterReactTheme >
163176 < div className = "other App" >
164177 < br />
165178 < a href = "https://datalayer.ai" target = "_blank" rel = "noreferrer" >
0 commit comments