File tree 3 files changed +17
-18
lines changed
3 files changed +17
-18
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " egraph-visualizer" ,
3
- "version" : " 1.0.3 " ,
3
+ "version" : " 1.1.0 " ,
4
4
"repository" : {
5
5
"type" : " git" ,
6
6
"url" : " git+https://github.com/saulshanabrook/egraph-visualizer.git"
Original file line number Diff line number Diff line change @@ -701,7 +701,7 @@ function LayoutFlow({
701
701
) ;
702
702
}
703
703
704
- function Visualizer ( { egraph } : { egraph : string } ) {
704
+ function Visualizer ( { egraph, height = null , resize = false } : { egraph : string ; height ?: string | null ; resize ?: boolean } ) {
705
705
const [ outerElem , setOuterElem ] = useState < HTMLDivElement | null > ( null ) ;
706
706
const [ innerElem , setInnerElem ] = useState < HTMLDivElement | null > ( null ) ;
707
707
@@ -713,7 +713,7 @@ function Visualizer({ egraph }: { egraph: string }) {
713
713
}
714
714
} , [ rootElem ] ) ;
715
715
return (
716
- < div className = " w-full h-full" ref = { setRootElem } >
716
+ < div className = { ` w-full ${ resize ? "resize-y" : "" } ` } style = { { height : height || "100%" } } ref = { setRootElem } >
717
717
{ /* Hidden node to measure text size */ }
718
718
< div className = "invisible absolute" >
719
719
< ENode outerRef = { setOuterElem } innerRef = { setInnerElem } />
Original file line number Diff line number Diff line change 1
- import { useSyncExternalStore } from "react" ;
2
1
import { createRoot } from "react-dom/client" ;
3
2
import "./index.css" ;
4
3
import { DOMWidgetModel } from "@jupyter-widgets/base" ;
5
4
import Visualizer from "./Visualizer.tsx" ;
6
-
7
- // eslint-disable-next-line react-refresh/only-export-components
8
- function ModelApp ( { model } : { model : DOMWidgetModel } ) {
9
- const egraph : string = useSyncExternalStore (
10
- ( callback ) => {
11
- model . on ( "change:egraph" , callback ) ;
12
- return ( ) => model . off ( "change:egraph" , callback ) ;
13
- } ,
14
- ( ) => model . get ( "egraph" )
15
- ) ;
16
- return < Visualizer egraph = { egraph } /> ;
17
- }
5
+ import { startTransition } from "react" ;
18
6
19
7
function render ( { model, el } : { el : HTMLElement ; model : DOMWidgetModel } ) {
20
8
const root = createRoot ( el ) ;
21
- root . render ( < ModelApp model = { model } /> ) ;
22
- return ( ) => root . unmount ( ) ;
9
+ const height = model . has ( "height" ) ? model . get ( "height" ) : "600px" ;
10
+ function render ( ) {
11
+ startTransition ( ( ) => {
12
+ root . render ( < Visualizer egraph = { model . get ( "egraph" ) } height = { height } resize /> ) ;
13
+ } ) ;
14
+ }
15
+ render ( ) ;
16
+ model . on ( "change:egraph" , render ) ;
17
+
18
+ return ( ) => {
19
+ model . off ( "change:egraph" , render ) ;
20
+ root . unmount ( ) ;
21
+ } ;
23
22
}
24
23
25
24
export default { render } ;
You can’t perform that action at this time.
0 commit comments