Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | 30x 30x 30x 45x 30x 30x 30x 150x 15x 45x 90x 3112x 3112x 3112x 3112x 3112x 3112x 3112x 4x 1x 4x 4x 9336x 3112x 3x 3x 9336x 3112x 21784x 3226x 3112x 3112x 15560x 3112x 15560x 9336x 123x 123x 123x 123x 369x 615x 3235x 3235x 16175x 3235x 6470x 3142x 3142x 3142x 3142x 3142x 3271x 3532x 3142x 9426x 129x 3079x 3079x 3064x 3064x 3206x 3079x 3206x 18399x 9207x 3079x 9237x 9237x | import { ReactFlowProvider } from "@xyflow/react";
import {
AnimatePresence,
motion,
type Transition,
useReducedMotion,
} from "motion/react";
import type { ReactNode } from "react";
import { useResizable } from "react-resizable-layout";
import { useLocalStorage, useWindowSize } from "usehooks-ts";
import { useSelectedGroup } from "@/hooks/flowsheetObjects";
import { useFlowsheetRevisionPreview } from "@/hooks/flowsheetRevisionPreview";
import ScenarioResult from "../dynamics/ScenarioResult";
import PinchAnalysis from "../pinch-analysis/PinchAnalysis";
import { ProcessGraphLeftTabContent } from "../process-graph/LeftTabContent";
import FlowsheetSurface from "./Canvas/FlowsheetSurface";
import { DiagnosticRevisionPanel } from "./Diagnostics/DiagnosticRevisionPanel";
import FlowsheetObjectsContent from "./LeftSideBar/FlowsheetObjectsContent";
import { ContentTypes } from "./LeftSideBar/LeftSideBarTabDefinitions";
import ProjectContent from "./LeftSideBar/ProjectContent";
import { ScenarioList } from "./LeftSideBar/Scenarios/ScenarioList";
import TasksPanel from "./LeftSideBar/TasksPanel";
import UnitOpContent from "./LeftSideBar/UnitOpContent";
import RightSideBarData from "./PropertiesSidebar/ObjectDetailsPanel";
import { useMonitoringTables } from "./PropertiesSidebar/useMonitoringTables";
import { useResizableGroupRef } from "./ResizableGroupContext";
import ResizableHandle from "./ResizableHandle";
import { ResizablePanel } from "./Resizables";
import { FlowsheetReadStateBoundary } from "./revisions/FlowsheetReadStateBoundary";
import { FlowsheetRevisionPreviewGate } from "./revisions/FlowsheetRevisionPreviewGate";
import { UnavailableRevisionOutput } from "./revisions/UnavailableRevisionOutput";
/** Keep project-panel UI mounted while revision-owned canvas readers remount. */
export function ProjectPanelWorkspace() {
const shouldReduceMotion = useReducedMotion();
const { resizable, middleWidth } = useWorkspaceLayout(true);
const transition = getPanelTransition(shouldReduceMotion);
return (
<>
<WorkspaceSidebar
panelKey={ContentTypes.project}
width={resizable.position}
isDragging={resizable.isDragging}
separatorProps={resizable.separatorProps}
transition={transition}
>
<ProjectContent />
</WorkspaceSidebar>
<FlowsheetReadStateBoundary>
<FlowsheetRevisionPreviewGate>
<RevisionCanvas width={middleWidth} />
</FlowsheetRevisionPreviewGate>
</FlowsheetReadStateBoundary>
</>
);
}
/** Render the active flowsheet sidebar beside its canvas read state. */
export function FlowsheetWorkspace({ activeTab }: { activeTab: ContentTypes }) {
const selectedGroup = useSelectedGroup();
const { isPreview } = useFlowsheetRevisionPreview();
const shouldReduceMotion = useReducedMotion();
const { resizable, middleWidth } = useWorkspaceLayout(
activeTab !== ContentTypes.flowsheet,
);
const {
tables: monitoringTables,
createTable,
deleteTable,
setTableVisibility,
renameTable,
} = useMonitoringTables(selectedGroup?.id);
const handleCreateMonitoringTable = () => {
const existingNumbers = monitoringTables
.map((table) => {
const match = table.title.match(/^Monitoring Table (\d+)$/);
return match ? parseInt(match[1], 10) : 0;
})
.filter((number) => number > 0);
const nextNumber =
existingNumbers.length > 0 ? Math.max(...existingNumbers) + 1 : 1;
createTable(`Monitoring Table ${nextNumber}`);
};
const handleToggleMonitoringTableVisibility = (tableId: number) => {
const table = monitoringTables.find((item) => item.id === tableId);
if (table) {
setTableVisibility(tableId, !table.visible);
return;
}
console.warn(`Table with id ${tableId} not found for toggling visibility`);
};
const leftSidebar =
activeTab == ContentTypes.pinch ? (
<PinchAnalysis />
) : activeTab == ContentTypes.solverLogs ? (
isPreview ? (
<UnavailableRevisionOutput message="Solver logs are not retained in versions." />
) : (
<TasksPanel />
)
) : activeTab == ContentTypes.unitOps ? (
<UnitOpContent />
) : activeTab == ContentTypes.scenarios ? (
<ScenarioList />
) : activeTab == ContentTypes.objectDetails ? (
<RightSideBarData
onCreateMonitoringTable={handleCreateMonitoringTable}
onToggleMonitoringTableVisibility={
handleToggleMonitoringTableVisibility
}
onDeleteMonitoringTable={deleteTable}
monitoringTables={monitoringTables}
/>
) : activeTab == ContentTypes.pGraph ? (
<ProcessGraphLeftTabContent />
) : activeTab == ContentTypes.objectList ? (
<FlowsheetObjectsContent />
) : activeTab == ContentTypes.diagnostic ? (
<DiagnosticRevisionPanel />
) : activeTab == ContentTypes.flowsheet ? null : (
console.warn(
"Unexpected tab/ ContentType:",
activeTab,
"Please add it to FlowsheetWorkspace.tsx or CONTENT_MAP",
)
);
const transition = getPanelTransition(shouldReduceMotion);
return (
<>
{leftSidebar && (
<WorkspaceSidebar
panelKey={activeTab}
width={resizable.position}
isDragging={resizable.isDragging}
separatorProps={resizable.separatorProps}
transition={transition}
>
{leftSidebar}
</WorkspaceSidebar>
)}
<CanvasPane
width={middleWidth}
monitoringTables={monitoringTables}
onHideTable={handleToggleMonitoringTableVisibility}
onRenameTable={renameTable}
/>
</>
);
}
/** Revision-keyed canvas used beside the persistent Projects panel. */
function RevisionCanvas({ width }: { width: number }) {
const selectedGroup = useSelectedGroup();
const {
tables: monitoringTables,
setTableVisibility,
renameTable,
} = useMonitoringTables(selectedGroup?.id);
return (
<CanvasPane
width={width}
monitoringTables={monitoringTables}
onHideTable={(tableId) => {
const table = monitoringTables.find((item) => item.id === tableId);
Iif (table) setTableVisibility(tableId, !table.visible);
}}
onRenameTable={renameTable}
/>
);
}
type CanvasPaneProps = {
width: number;
monitoringTables: ReturnType<typeof useMonitoringTables>["tables"];
onHideTable: (tableId: number) => void;
onRenameTable: (tableId: number, newName: string) => void;
};
function CanvasPane({
width,
monitoringTables,
onHideTable,
onRenameTable,
}: CanvasPaneProps) {
return (
<div className="w-full h-min-screen flex flex-col relative">
<ReactFlowProvider>
<FlowsheetSurface
width={width}
monitoringTables={monitoringTables}
onHideTable={onHideTable}
onRenameTable={onRenameTable}
/>
</ReactFlowProvider>
<ScenarioResult />
</div>
);
}
function useWorkspaceLayout(hasLeftSidebar: boolean) {
const { width = 0 } = useWindowSize();
const resizableGroupRef = useResizableGroupRef();
const [size, setSize] = useLocalStorage("panelsize", 370);
const resizable = useResizable({
axis: "x",
containerRef: resizableGroupRef,
initial: size,
min: 270,
max: 1200,
onResizeEnd: ({ position }) => setSize(position),
});
const middleWidth = hasLeftSidebar
? width - resizable.position - 5 - 55
: width - 55;
return { resizable, middleWidth };
}
function getPanelTransition(shouldReduceMotion: boolean | null): Transition {
return shouldReduceMotion
? { duration: 0 }
: { duration: 0.14, ease: [0.4, 0, 0.2, 1] };
}
type WorkspaceSidebarProps = {
panelKey: ContentTypes;
width: number;
isDragging: boolean;
separatorProps: React.ComponentProps<typeof ResizableHandle>;
transition: Transition;
children: ReactNode;
};
function WorkspaceSidebar({
panelKey,
width,
isDragging,
separatorProps,
transition,
children,
}: WorkspaceSidebarProps) {
return (
<>
<ResizablePanel width={width}>
<AnimatePresence initial={false} mode="wait">
<motion.div
key={panelKey}
className="h-full w-full min-w-0"
initial={{ opacity: 0, x: transition.duration === 0 ? 0 : -10 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: transition.duration === 0 ? 0 : 10 }}
transition={transition}
>
{children}
</motion.div>
</AnimatePresence>
</ResizablePanel>
<ResizableHandle
{...separatorProps}
isDragging={isDragging}
id="left-sidebar-handle"
/>
</>
);
}
|