Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ wander ~20Å across runs).

## Moorhen integration — THE big lesson: Moorhen is Redux-driven

The client embeds Moorhen 0.23 (real source for reference:
`~/Developer/emsdk/Moorhen/baby-gru/src`). The hardest-won, most reusable lesson:
The client embeds Moorhen 1.0 (`file:moorhen-1.0.0-alpha.3-*.tgz`; real source
for reference: `~/Developer/emsdk/Moorhen/baby-gru/src`). Imports come from the
`moorhen/react-lib` entry (1.0 has an `exports` map; bare `from "moorhen"` no
longer resolves), and `<MoorhenInstanceProvider>` now requires a `menuSystem={new
MoorhenMenuSystem()}` prop — see InspectPage. The hardest-won, most reusable
lesson still holds:

> **Camera origin, map contour level, and map registration are all driven by the
> Redux store. Mutating the imperative `glRef.current.*` / `map.*` properties
Expand Down
Binary file not shown.
25,323 changes: 4,948 additions & 20,375 deletions client/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@rdkit/rdkit": "^2024.3.5-1.0.0",
"@reduxjs/toolkit": "^2.8.2",
"chart.js": "^4.5.1",
"moorhen": "file:moorhen-0.23.1-alpha.0.tgz",
"moorhen": "file:moorhen-1.0.0-alpha.3-dev.g065becee.tgz",
"react": "^19.0.0",
"react-chartjs-2": "^5.3.1",
"react-dom": "^19.0.0",
Expand Down
7 changes: 6 additions & 1 deletion client/src/components/InspectDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { RefObject } from "react";
import { Link as RouterLink } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { addMap, addMolecule, removeMap, removeMolecule } from "moorhen";
import {
addMap,
addMolecule,
removeMap,
removeMolecule,
} from "moorhen/react-lib";
import type { moorhen } from "moorhen/types/moorhen";
import {
Accordion,
Expand Down
12 changes: 6 additions & 6 deletions client/src/moorhen-shim.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Moorhen 0.23.1-alpha.0 has an incomplete/loose type surface for a few things
* we use (setActiveMap action, MoorhenMap/Molecule constructor arities, contour
* control, glRef.setOriginAndZoomAnimated). Rather than fight the alpha's .d.ts,
* we funnel those through thin, explicitly-typed wrappers here. Tighten once the
* upstream types stabilise.
* Moorhen 1.0.0-alpha.3 still has an incomplete/loose type surface for a few
* things we use (setActiveMap action, MoorhenMap/Molecule constructor arities,
* contour control, glRef.setOriginAndZoomAnimated). Rather than fight the
* alpha's .d.ts, we funnel those through thin, explicitly-typed wrappers here.
* Tighten once the upstream types stabilise.
*
* NOTE on constructor signatures: ground truth is the working MoorhenPanddaApp
* prototype (same tgz), which constructs:
Expand All @@ -22,7 +22,7 @@ import {
setRequestDrawScene as _setRequestDrawScene,
showMap as _showMap,
hideMap as _hideMap,
} from "moorhen";
} from "moorhen/react-lib";

// Loosely-typed handles. `any` is deliberate and localised to this shim.
const MoleculeCtor = _Molecule as unknown as new (
Expand Down
15 changes: 12 additions & 3 deletions client/src/pages/InspectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { useDispatch, useSelector } from "react-redux";
import {
MoorhenContainer,
MoorhenInstanceProvider,
MoorhenMenuSystem,
setShownSidePanel,
} from "moorhen";
import type { MoorhenPanel } from "moorhen";
} from "moorhen/react-lib";
import type { MoorhenPanel } from "moorhen/react-lib";
import type { webGL } from "moorhen/types/mgWebGL";
import type { moorhen } from "moorhen/types/moorhen";
import store, { resetMoorhenStore } from "../store";
Expand Down Expand Up @@ -119,8 +120,16 @@ export function InspectPage() {
: {}),
};

// Moorhen 1.0 moved per-instance state into a React context, and
// MoorhenInstanceProvider now REQUIRES a menuSystem (it builds
// `new MoorhenInstance(ref, menuSystem)` from it). One per provider; memoise
// so it isn't rebuilt each render. We manage our own store (store.ts), so we
// wire the provider directly rather than via MoorhenProvider (which would
// create a second, un-memoised store). See migration guide §2.
const menuSystem = useMemo(() => new MoorhenMenuSystem(), []);

return (
<MoorhenInstanceProvider>
<MoorhenInstanceProvider menuSystem={menuSystem}>
<div style={{ position: "absolute", inset: 0 }}>
<MoorhenContainer {...collectedProps} />
</div>
Expand Down
7 changes: 4 additions & 3 deletions client/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
combineReducers,
type Action,
} from "@reduxjs/toolkit";
// Moorhen 0.23 exposes a single combined reducer map. If this import fails with
// a missing 'generalStates', clear node_modules/.vite and restart vite.
import { MoorhenStoreReducers } from "moorhen";
// Moorhen exposes a single combined reducer map (the react-lib entry in 1.0).
// If this import fails with a missing 'generalStates', clear node_modules/.vite
// and restart vite.
import { MoorhenStoreReducers } from "moorhen/react-lib";

if (!MoorhenStoreReducers || !("generalStates" in MoorhenStoreReducers)) {
throw new Error(
Expand Down
10 changes: 10 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
// Moorhen 1.0's package.json `exports` map has no `./types/*` key, so under
// `bundler` resolution `moorhen/types/moorhen` / `moorhen/types/mgWebGL`
// (the still-shipped, deprecated ambient namespaces) no longer resolve.
// Point TS straight at the physical .d.ts files. The bundler never sees
// these type-only imports (erased pre-bundle), so no Vite change is needed.
// See the Moorhen 0.23->1.0 migration guide (module-resolution gotcha).
"baseUrl": ".",
"paths": {
"moorhen/types/*": ["./node_modules/moorhen/types/*"]
},
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down
Loading