import { Slider, Tabs } from "@mantine/core"; import { MarkerType, ReactFlowProvider } from "@xyflow/react"; import { objectDepth } from "core/utils"; import { useAtom } from "jotai"; import { atomWithStorage } from "jotai/utils"; import { pick, throttle } from "lodash-es"; import { useEffect, useRef, useState } from "react"; import { TbArrowLeft } from "react-icons/tb"; import { Canvas } from "ui/components/canvas/Canvas"; import { Panels } from "ui/components/canvas/panels"; import { Panel } from "ui/components/canvas/panels/Panel"; import { nodeTypes } from "ui/modules/flows/components2/nodes"; import { FlowCanvasProvider, flowToEdges, flowToNodes, useFlowCanvas, useFlowCanvasState, useFlowSelector } from "ui/modules/flows/hooks/use-flow"; import { JsonViewer } from "../../components/code/JsonViewer"; import { routes, useGoBack, useNavigate } from "../../lib/routes"; /** * @todo: AppFlows config must be updated to have fixed ids per task and connection * ideally in array format * */ export function FlowsEdit(props) { return ( ); } function FlowsEditInner() { const ref = useRef(null); const [rect, setRect] = useState(); const $flow = useFlowCanvas(); if (!$flow.data || !$flow.name) return "no flow"; useEffect(() => { // get width and height of ref object console.log("ref", ref.current?.getBoundingClientRect()); setRect(ref.current?.getBoundingClientRect()); }, []); const nodes = flowToNodes($flow.data, $flow.name); const edges = flowToEdges($flow.data) as any; console.log("nodes", nodes); console.log("edges", edges); const triggerHeight = 260; const offset = 50; const viewport = { zoom: 1, x: rect?.width ? rect.width * 0.1 : 0, y: rect?.height ? rect.height / 2 - triggerHeight / 2 - offset : 0 }; return (
{rect && ( <> ({ ...node, type: "select", data: { label: "" } })} onDropNewEdge={(edge) => ({ ...edge, style: { strokeWidth: 2 }, markerEnd: { type: MarkerType.ArrowClosed, width: 10, height: 10 } })} > )}
); } function FlowPanels() { const state = useFlowSelector((s) => pick(s, ["name", "dirty"])); const [navigate] = useNavigate(); const { goBack } = useGoBack(() => navigate(routes.flows.flows.list())); return ( {state.name} {state.dirty ? "*" : ""} ); } /* function PanelsOld() { //console.log("Panels"); const state = useFlowSelector((s) => pick(s, ["name", "dirty"])); const [navigate] = useNavigate(); const { goBack } = useGoBack(() => navigate(routes.flows.flows.list())); const [minimap, setMinimap] = useState(false); const reactFlow = useReactFlow(); const { zoom, x, y } = useViewport(); const percent = Math.round(zoom * 100); const handleZoomIn = async () => await reactFlow.zoomIn(); const handleZoomReset = async () => reactFlow.zoomTo(1); const handleZoomOut = async () => await reactFlow.zoomOut(); function toggleMinimap() { setMinimap((p) => !p); } return ( <> {state.name} {state.dirty ? "*" : ""} {x.toFixed(2)},{y.toFixed(2)} {percent}% {minimap && } ); }*/ type DebuggerTabProps = { tab: string | null; store?: Record; }; const debuggerTabAtom = atomWithStorage("__dev_flow_debugger_tab", { tab: null }); const Debugger = () => { const [_state, _setState] = useAtom(debuggerTabAtom); const $flow = useFlowCanvas(); const state = useFlowCanvasState(); function handleTabChange(tab: string | null) { _setState((prev) => ({ ...prev, tab: prev.tab === tab ? null : tab })); } const expand = _state.store?.expand || 3; return (
_setState((prev) => ({ ...prev, store: { ...prev.store, expand: n } })), 250 )} />
Store
); };