import { Background, Controls, Panel, ReactFlow, ReactFlowProvider, MarkerType, } from '@xyflow/react'; import '@xyflow/react/dist/style.css'; import {useEffect, useState} from "react"; import {useShallow} from 'zustand/react/shallow'; import useProgramStore from "../../utils/programStore.ts"; import {DndToolbar} from './visualProgrammingUI/components/DragDropSidebar.tsx'; import useFlowStore from './visualProgrammingUI/VisProgStores.tsx'; import type {FlowState} from './visualProgrammingUI/VisProgTypes.tsx'; import styles from './VisProg.module.css' import { NodeReduces, NodeTypes } from './visualProgrammingUI/NodeRegistry.ts'; import SaveLoadPanel from './visualProgrammingUI/components/SaveLoadPanel.tsx'; import MonitoringPage from '../MonitoringPage/MonitoringPage.tsx'; // --| config starting params for flow |-- /** * defines how the default edge looks inside the editor */ const DEFAULT_EDGE_OPTIONS = { type: 'default', markerEnd: { type: MarkerType.ArrowClosed, color: '#505050', }, }; /** * defines what functions in the FlowState store map to which names, * @param state */ const selector = (state: FlowState) => ({ nodes: state.nodes, edges: state.edges, onNodesChange: state.onNodesChange, onEdgesDelete: state.onEdgesDelete, onEdgesChange: state.onEdgesChange, onConnect: state.onConnect, onReconnectStart: state.onReconnectStart, onReconnectEnd: state.onReconnectEnd, onReconnect: state.onReconnect, undo: state.undo, redo: state.redo, beginBatchAction: state.beginBatchAction, endBatchAction: state.endBatchAction }); // --| define ReactFlow editor |-- /** * Defines the ReactFlow visual programming editor component * any implementations of editor logic should be encapsulated where possible * so the Component definition stays as readable as possible * @constructor */ const VisProgUI = () => { const { nodes, edges, onNodesChange, onEdgesDelete, onEdgesChange, onConnect, onReconnect, onReconnectStart, onReconnectEnd, undo, redo, beginBatchAction, endBatchAction } = useFlowStore(useShallow(selector)); // instructs the editor to use the corresponding functions from the FlowStore // adds ctrl+z and ctrl+y support to respectively undo and redo actions useEffect(() => { const handler = (e: KeyboardEvent) => { if (e.ctrlKey && e.key === 'z') undo(); if (e.ctrlKey && e.key === 'y') redo(); }; window.addEventListener('keydown', handler); return () => window.removeEventListener('keydown', handler); }); return (