Skip to content

Commit 9d91b92

Browse files
committed
Enable cell insertion without kernel and improve initial messages
1 parent e57291d commit 9d91b92

File tree

10 files changed

+563
-104
lines changed

10 files changed

+563
-104
lines changed

packages/lexical/src/examples/AppSimple.tsx

Lines changed: 41 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,50 @@ 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 ? 'default' : 'primary'}
73+
onClick={() => toggleKernel(false)}
74+
>
75+
No Runtime
76+
</Button>
77+
<Button
78+
variant={hasKernel ? 'primary' : 'default'}
79+
onClick={() => toggleKernel(true)}
80+
>
81+
With Runtime
82+
</Button>
83+
</ButtonGroup>
84+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
85+
Current mode:{' '}
86+
<strong>{hasKernel ? 'Runtime Connected' : 'No Runtime'}</strong>
87+
</p>
4988
</div>
50-
<Jupyter startDefaultKernel>
89+
<Jupyter startDefaultKernel={hasKernel}>
5190
<LexicalProvider>
5291
<LexicalEditor />
5392
</LexicalProvider>

0 commit comments

Comments
 (0)