@@ -4,17 +4,26 @@ import { Notebook } from '@jupyter-kit/react';
44import { python as pythonHighlight } from '@jupyter-kit/core/langs/python' ;
55import { createEditorPlugin } from '@jupyter-kit/editor-codemirror' ;
66import { createKatexPlugin } from '@jupyter-kit/katex' ;
7+ import { createWidgetsPlugin } from '@jupyter-kit/widgets' ;
78import {
89 createPyodideExecutor ,
910 type PyodideStatus ,
1011} from '@jupyter-kit/executor-pyodide' ;
1112import { python as pythonEditor } from '@codemirror/lang-python' ;
1213
1314import showcase from '@jupyter-kit/fixtures/ipynb/showcase' ;
15+ import lorenz from '@jupyter-kit/fixtures/ipynb/Lorenz' ;
16+ import widgetsGallery from '@jupyter-kit/fixtures/ipynb/widgets-gallery' ;
1417import '@jupyter-kit/theme-default/default.css' ;
1518import '@jupyter-kit/theme-default/syntax/one-dark.css' ;
1619import 'katex/dist/katex.min.css' ;
1720
21+ const FIXTURES : Record < string , unknown > = {
22+ showcase,
23+ Lorenz : lorenz ,
24+ 'widgets-gallery' : widgetsGallery ,
25+ } ;
26+
1827const meta : Meta = {
1928 title : 'Executor / Pyodide' ,
2029 component : Notebook ,
@@ -24,10 +33,16 @@ export default meta;
2433const Template = ( preinstall : string [ ] = [ ] ) =>
2534 function Story ( ) {
2635 const [ status , setStatus ] = useState < PyodideStatus > ( 'idle' ) ;
36+ const [ fixture , setFixture ] = useState < string > ( 'showcase' ) ;
2737 const executor = useMemo (
2838 ( ) =>
2939 createPyodideExecutor ( {
30- packages : preinstall ,
40+ // `ipywidgets` is a pyodide-bundled package but `loadPackagesFromImports`
41+ // only sees it when `import ipywidgets` appears literally in the cell
42+ // source (the widgets-gallery fixture writes `from ipywidgets import ...`,
43+ // and the scanner catches that — but we preload anyway so the comm shim
44+ // is wired up before any cell runs).
45+ packages : [ 'ipywidgets' , ...preinstall ] ,
3146 autoloadImports : true ,
3247 onStatus : setStatus ,
3348 } ) ,
@@ -36,6 +51,7 @@ const Template = (preinstall: string[] = []) =>
3651 const plugins = useMemo (
3752 ( ) => [
3853 createKatexPlugin ( ) ,
54+ createWidgetsPlugin ( ) ,
3955 createEditorPlugin ( { languages : { python : pythonEditor ( ) } } ) ,
4056 ] ,
4157 [ ] ,
@@ -44,16 +60,32 @@ const Template = (preinstall: string[] = []) =>
4460 < div >
4561 < div
4662 style = { {
63+ display : 'flex' ,
64+ gap : 12 ,
65+ alignItems : 'center' ,
4766 padding : '8px 12px' ,
4867 fontFamily : 'monospace' ,
4968 fontSize : 12 ,
50- opacity : 0.7 ,
5169 } }
5270 >
53- pyodide: { status }
71+ < label >
72+ fixture:{ ' ' }
73+ < select
74+ value = { fixture }
75+ onChange = { ( e ) => setFixture ( e . target . value ) }
76+ style = { { fontFamily : 'inherit' , fontSize : 12 } }
77+ >
78+ { Object . keys ( FIXTURES ) . map ( ( k ) => (
79+ < option key = { k } value = { k } >
80+ { k }
81+ </ option >
82+ ) ) }
83+ </ select >
84+ </ label >
85+ < span style = { { opacity : 0.7 } } > pyodide: { status } </ span >
5486 </ div >
5587 < Notebook
56- ipynb = { showcase as never }
88+ ipynb = { FIXTURES [ fixture ] as never }
5789 language = "python"
5890 languages = { [ pythonHighlight ] }
5991 plugins = { plugins }
0 commit comments