Skip to content

Commit 59649e9

Browse files
authored
Enable cell insertion without kernel and improve initial messages (#419)
* Enable cell insertion without kernel and improve initial messages * Handle undefined state when kernel terminates
1 parent 6f27be3 commit 59649e9

File tree

11 files changed

+599
-105
lines changed

11 files changed

+599
-105
lines changed

packages/lexical/src/examples/AppSimple.tsx

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* MIT License
55
*/
66

7-
import { Button } from '@primer/react';
7+
import { useState } from 'react';
8+
import { Button, ButtonGroup } from '@primer/react';
89
import { Box } from '@datalayer/primer-addons';
910
import { ThreeBarsIcon } from '@primer/octicons-react';
1011
import { Jupyter } from '@datalayer/jupyter-react';
@@ -42,12 +43,66 @@ const LexicalEditor = () => {
4243
};
4344

4445
export const AppSimple = () => {
46+
// Get initial state from URL or localStorage
47+
const getInitialKernelState = () => {
48+
const urlParams = new URLSearchParams(window.location.search);
49+
const kernelParam = urlParams.get('kernel');
50+
if (kernelParam !== null) {
51+
return kernelParam === 'true';
52+
}
53+
const stored = localStorage.getItem('hasKernel');
54+
return stored === 'true';
55+
};
56+
57+
const [hasKernel] = useState(getInitialKernelState);
58+
59+
const toggleKernel = (newValue: boolean) => {
60+
localStorage.setItem('hasKernel', String(newValue));
61+
const url = new URL(window.location.href);
62+
url.searchParams.set('kernel', String(newValue));
63+
window.location.href = url.toString();
64+
};
65+
4566
return (
4667
<>
4768
<div className="App">
4869
<h1>Jupyter UI ❤️ Lexical</h1>
70+
<ButtonGroup>
71+
<Button
72+
variant={!hasKernel ? 'primary' : 'default'}
73+
onClick={() => toggleKernel(false)}
74+
sx={{
75+
fontWeight: !hasKernel ? 'bold' : 'normal',
76+
backgroundColor: !hasKernel ? '#0969da' : 'transparent',
77+
color: !hasKernel ? 'white' : 'inherit',
78+
'&:hover': {
79+
backgroundColor: !hasKernel ? '#0860ca' : '#f3f4f6',
80+
},
81+
}}
82+
>
83+
No Runtime
84+
</Button>
85+
<Button
86+
variant={hasKernel ? 'primary' : 'default'}
87+
onClick={() => toggleKernel(true)}
88+
sx={{
89+
fontWeight: hasKernel ? 'bold' : 'normal',
90+
backgroundColor: hasKernel ? '#0969da' : 'transparent',
91+
color: hasKernel ? 'white' : 'inherit',
92+
'&:hover': {
93+
backgroundColor: hasKernel ? '#0860ca' : '#f3f4f6',
94+
},
95+
}}
96+
>
97+
With Runtime
98+
</Button>
99+
</ButtonGroup>
100+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
101+
Current mode:{' '}
102+
<strong>{hasKernel ? 'Runtime Connected' : 'No Runtime'}</strong>
103+
</p>
49104
</div>
50-
<Jupyter startDefaultKernel>
105+
<Jupyter startDefaultKernel={hasKernel}>
51106
<LexicalProvider>
52107
<LexicalEditor />
53108
</LexicalProvider>

0 commit comments

Comments
 (0)