UNPKG

@bernierllc/generic-workflow-ui

Version:

Generic, reusable workflow UI components with linear and graph visualization

63 lines (61 loc) 2.28 kB
"use strict"; /* Copyright (c) 2025 Bernier LLC This file is licensed to the client under a limited-use license. The client may use and modify this code *only within the scope of the project it was delivered for*. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.useWorkflowCanvas = useWorkflowCanvas; const react_1 = require("react"); const linear_to_graph_1 = require("../converters/linear-to-graph"); /** * Hook for managing workflow canvas state */ function useWorkflowCanvas({ workflow, layoutOptions, autoLayout = false, }) { const [graphWorkflow, setGraphWorkflow] = (0, react_1.useState)(null); const [loading, setLoading] = (0, react_1.useState)(false); const [error, setError] = (0, react_1.useState)(null); const refresh = (0, react_1.useCallback)(async () => { setLoading(true); setError(null); try { if (autoLayout) { // Use async layout algorithm const result = await (0, linear_to_graph_1.linearToGraph)(workflow, layoutOptions); if (result.success && result.data) { setGraphWorkflow(result.data); } else { setError(result.error || 'Failed to convert workflow'); } } else { // Use synchronous conversion (no layout) const result = (0, linear_to_graph_1.linearToGraphSync)(workflow); if (result.success && result.data) { setGraphWorkflow(result.data); } else { setError(result.error || 'Failed to convert workflow'); } } } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error'); } finally { setLoading(false); } }, [workflow, layoutOptions, autoLayout]); // Auto-refresh when workflow changes (0, react_1.useEffect)(() => { refresh(); }, [refresh]); return { graphWorkflow, loading, error, refresh, }; }