@@ -2,7 +2,15 @@ import type { ChangeFn, DocHandle } from "@automerge/automerge-repo";
22import Dialog from "@corvu/dialog" ;
33import { MultiProvider } from "@solid-primitives/context" ;
44import { useNavigate , useParams } from "@solidjs/router" ;
5- import { type Accessor , Match , Switch , createMemo , createResource , useContext } from "solid-js" ;
5+ import {
6+ type Accessor ,
7+ Match ,
8+ Switch ,
9+ createMemo ,
10+ createResource ,
11+ createSignal ,
12+ useContext ,
13+ } from "solid-js" ;
614import invariant from "tiny-invariant" ;
715
816import type { JsonValue , Permissions } from "catcolab-api" ;
@@ -36,7 +44,7 @@ import { type TheoryLibrary, TheoryLibraryContext } from "../stdlib";
3644import type { Theory } from "../theory" ;
3745import { PermissionsButton } from "../user" ;
3846import { type IndexedMap , indexMap } from "../util/indexing" ;
39- import TheorySelector from "./theory_selector" ;
47+ import { TheorySelector } from "./theory_selector" ;
4048import { type ModelDocument , newAnalysisDocument } from "./types" ;
4149
4250import "./model_document_editor.css" ;
@@ -215,6 +223,7 @@ export function ModelPane(props: {
215223} ) {
216224 const theories = useContext ( TheoryLibraryContext ) ;
217225 invariant ( theories , "Library of theories should be provided as context" ) ;
226+ const [ theorySelectorOpen , setTheorySelectorOpen ] = createSignal ( false ) ;
218227
219228 const liveDoc = ( ) => props . liveDoc ;
220229 const doc = ( ) => props . liveDoc . doc ;
@@ -233,24 +242,22 @@ export function ModelPane(props: {
233242 placeholder = "Untitled"
234243 />
235244 </ div >
236- < Dialog
237- initialOpen = { false }
238- modal = { true }
239- closeOnEscapeKeyDown = { true }
240- trapFocus = { true }
241- >
242- < div >
243- < Dialog . Trigger class = "theory-selector-button" >
244- { liveDoc ( ) . theory ( ) ?. name || "Theory" }
245- </ Dialog . Trigger >
246- </ div >
245+ < Dialog open = { theorySelectorOpen ( ) } onOpenChange = { setTheorySelectorOpen } >
246+ < Dialog . Trigger class = "theory-selector-button" >
247+ { liveDoc ( ) . theory ( ) ?. name || "Theory" }
248+ </ Dialog . Trigger >
247249 < Dialog . Portal >
248250 < Dialog . Overlay class = "overlay" />
249251 < Dialog . Content class = "popup" >
250252 < TheorySelector
251- docHandle = { props . liveDoc . docHandle }
253+ theory = { props . liveDoc . theory ( ) ?. id }
254+ setTheory = { ( id ) => {
255+ changeDoc ( ( model ) => {
256+ model . theory = id ;
257+ } ) ;
258+ setTheorySelectorOpen ( false ) ;
259+ } }
252260 theories = { theories }
253- doc = { doc ( ) }
254261 />
255262 </ Dialog . Content >
256263 </ Dialog . Portal >
0 commit comments