@orka-js/react 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Orka Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Node, Edge } from '@xyflow/react';
|
|
3
|
+
|
|
4
|
+
interface OrkaGraphExecution {
|
|
5
|
+
/** Currently executing node ID */
|
|
6
|
+
currentNode?: string;
|
|
7
|
+
/** IDs of completed nodes */
|
|
8
|
+
completedNodes?: string[];
|
|
9
|
+
/** IDs of nodes that failed */
|
|
10
|
+
failedNodes?: string[];
|
|
11
|
+
}
|
|
12
|
+
interface OrkaGraphProps {
|
|
13
|
+
/**
|
|
14
|
+
* The workflow to visualize.
|
|
15
|
+
* Accepts GraphWorkflow or StateGraph instances from @orka-js/graph.
|
|
16
|
+
*/
|
|
17
|
+
workflow: {
|
|
18
|
+
getNodes(): Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}>;
|
|
23
|
+
getEdges(): Array<{
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
}>;
|
|
28
|
+
};
|
|
29
|
+
/** Live execution state for highlighting */
|
|
30
|
+
execution?: OrkaGraphExecution;
|
|
31
|
+
/** Called when user clicks a node */
|
|
32
|
+
onNodeClick?: (nodeId: string, metadata?: unknown) => void;
|
|
33
|
+
theme?: 'light' | 'dark';
|
|
34
|
+
width?: number | string;
|
|
35
|
+
height?: number | string;
|
|
36
|
+
/** Custom CSS class name */
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Visual graph component for OrkaJS workflows.
|
|
42
|
+
*
|
|
43
|
+
* Renders a GraphWorkflow or StateGraph as an interactive React Flow diagram.
|
|
44
|
+
* Highlights currently running, completed, and failed nodes based on the
|
|
45
|
+
* optional `execution` prop.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* import { OrkaGraph } from '@orka-js/react';
|
|
50
|
+
*
|
|
51
|
+
* function App() {
|
|
52
|
+
* return (
|
|
53
|
+
* <OrkaGraph
|
|
54
|
+
* workflow={myGraphWorkflow}
|
|
55
|
+
* execution={{ currentNode: 'step2', completedNodes: ['step1'] }}
|
|
56
|
+
* height={500}
|
|
57
|
+
* />
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function OrkaGraph({ workflow, execution, onNodeClick, theme, width, height, className, }: OrkaGraphProps): react_jsx_runtime.JSX.Element;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts OrkaJS workflow nodes/edges to React Flow format.
|
|
66
|
+
* Applies a simple left-to-right auto-layout.
|
|
67
|
+
*/
|
|
68
|
+
declare function useGraph(workflow: OrkaGraphProps['workflow'], execution?: OrkaGraphExecution, theme?: 'light' | 'dark'): {
|
|
69
|
+
nodes: Node[];
|
|
70
|
+
edges: Edge[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { OrkaGraph, type OrkaGraphExecution, type OrkaGraphProps, useGraph };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useMemo, useCallback } from 'react';
|
|
2
|
+
import { ReactFlow, Background, Controls, MiniMap } from '@xyflow/react';
|
|
3
|
+
import '@xyflow/react/dist/style.css';
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/OrkaGraph.tsx
|
|
7
|
+
var NODE_STATUS_COLORS = {
|
|
8
|
+
running: "#3b82f6",
|
|
9
|
+
completed: "#10b981",
|
|
10
|
+
failed: "#ef4444",
|
|
11
|
+
pending: "#64748b"
|
|
12
|
+
};
|
|
13
|
+
var NODE_TYPE_SHAPES = {
|
|
14
|
+
start: "#1d4ed8",
|
|
15
|
+
end: "#059669",
|
|
16
|
+
condition: "#d97706",
|
|
17
|
+
default: "#334155"
|
|
18
|
+
};
|
|
19
|
+
function getNodeStatus(id, execution) {
|
|
20
|
+
if (execution?.currentNode === id) return "running";
|
|
21
|
+
if (execution?.completedNodes?.includes(id)) return "completed";
|
|
22
|
+
if (execution?.failedNodes?.includes(id)) return "failed";
|
|
23
|
+
return "pending";
|
|
24
|
+
}
|
|
25
|
+
function useGraph(workflow, execution, theme = "dark") {
|
|
26
|
+
return useMemo(() => {
|
|
27
|
+
const rawNodes = workflow.getNodes();
|
|
28
|
+
const rawEdges = workflow.getEdges();
|
|
29
|
+
const indegree = /* @__PURE__ */ new Map();
|
|
30
|
+
const adjList = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const n of rawNodes) {
|
|
32
|
+
indegree.set(n.id, 0);
|
|
33
|
+
adjList.set(n.id, []);
|
|
34
|
+
}
|
|
35
|
+
for (const e of rawEdges) {
|
|
36
|
+
indegree.set(e.to, (indegree.get(e.to) ?? 0) + 1);
|
|
37
|
+
adjList.get(e.from)?.push(e.to);
|
|
38
|
+
}
|
|
39
|
+
const layers = /* @__PURE__ */ new Map();
|
|
40
|
+
const queue = [];
|
|
41
|
+
for (const [id, deg] of indegree.entries()) {
|
|
42
|
+
if (deg === 0) queue.push(id);
|
|
43
|
+
}
|
|
44
|
+
let head = 0;
|
|
45
|
+
while (head < queue.length) {
|
|
46
|
+
const id = queue[head++];
|
|
47
|
+
const layer = layers.get(id) ?? 0;
|
|
48
|
+
for (const next of adjList.get(id) ?? []) {
|
|
49
|
+
layers.set(next, Math.max(layers.get(next) ?? 0, layer + 1));
|
|
50
|
+
indegree.set(next, (indegree.get(next) ?? 1) - 1);
|
|
51
|
+
if ((indegree.get(next) ?? 0) <= 0) queue.push(next);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const layerCounts = /* @__PURE__ */ new Map();
|
|
55
|
+
const nodePositions = /* @__PURE__ */ new Map();
|
|
56
|
+
const H_GAP = 200;
|
|
57
|
+
const V_GAP = 100;
|
|
58
|
+
for (const n of rawNodes) {
|
|
59
|
+
const layer = layers.get(n.id) ?? 0;
|
|
60
|
+
const row = layerCounts.get(layer) ?? 0;
|
|
61
|
+
nodePositions.set(n.id, { x: layer * H_GAP, y: row * V_GAP });
|
|
62
|
+
layerCounts.set(layer, row + 1);
|
|
63
|
+
}
|
|
64
|
+
const isDark = theme === "dark";
|
|
65
|
+
const bg = isDark ? "#1e293b" : "#f8fafc";
|
|
66
|
+
const textColor = isDark ? "#e2e8f0" : "#0f172a";
|
|
67
|
+
const borderColor = isDark ? "#334155" : "#cbd5e1";
|
|
68
|
+
const nodes = rawNodes.map((n) => {
|
|
69
|
+
const status = getNodeStatus(n.id, execution);
|
|
70
|
+
const statusColor = NODE_STATUS_COLORS[status];
|
|
71
|
+
const typeColor = NODE_TYPE_SHAPES[n.type ?? "default"] ?? NODE_TYPE_SHAPES.default;
|
|
72
|
+
const pos = nodePositions.get(n.id) ?? { x: 0, y: 0 };
|
|
73
|
+
return {
|
|
74
|
+
id: n.id,
|
|
75
|
+
position: pos,
|
|
76
|
+
type: "default",
|
|
77
|
+
data: { label: n.id, metadata: n },
|
|
78
|
+
style: {
|
|
79
|
+
background: bg,
|
|
80
|
+
border: `2px solid ${status !== "pending" ? statusColor : typeColor ?? borderColor}`,
|
|
81
|
+
borderRadius: n.type === "condition" ? "4px" : "8px",
|
|
82
|
+
color: textColor,
|
|
83
|
+
fontSize: "13px",
|
|
84
|
+
padding: "8px 12px",
|
|
85
|
+
minWidth: "80px",
|
|
86
|
+
textAlign: "center",
|
|
87
|
+
boxShadow: status === "running" ? `0 0 12px ${statusColor}66` : void 0
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
const edgeColor = isDark ? "#475569" : "#94a3b8";
|
|
92
|
+
const edges = rawEdges.map((e, i) => ({
|
|
93
|
+
id: `e-${e.from}-${e.to}-${i}`,
|
|
94
|
+
source: e.from,
|
|
95
|
+
target: e.to,
|
|
96
|
+
label: e.label,
|
|
97
|
+
style: { stroke: edgeColor },
|
|
98
|
+
labelStyle: { fill: edgeColor, fontSize: "11px" }
|
|
99
|
+
}));
|
|
100
|
+
return { nodes, edges };
|
|
101
|
+
}, [workflow, execution, theme]);
|
|
102
|
+
}
|
|
103
|
+
function OrkaGraph({
|
|
104
|
+
workflow,
|
|
105
|
+
execution,
|
|
106
|
+
onNodeClick,
|
|
107
|
+
theme = "dark",
|
|
108
|
+
width = "100%",
|
|
109
|
+
height = 500,
|
|
110
|
+
className
|
|
111
|
+
}) {
|
|
112
|
+
const { nodes, edges } = useGraph(workflow, execution, theme);
|
|
113
|
+
const handleNodeClick = useCallback(
|
|
114
|
+
(_event, node) => {
|
|
115
|
+
onNodeClick?.(node.id, node.data?.metadata);
|
|
116
|
+
},
|
|
117
|
+
[onNodeClick]
|
|
118
|
+
);
|
|
119
|
+
const bgColor = theme === "dark" ? "#0f1117" : "#f8fafc";
|
|
120
|
+
const dotColor = theme === "dark" ? "#1e293b" : "#e2e8f0";
|
|
121
|
+
return /* @__PURE__ */ jsx(
|
|
122
|
+
"div",
|
|
123
|
+
{
|
|
124
|
+
className,
|
|
125
|
+
style: { width, height, background: bgColor, borderRadius: "8px", overflow: "hidden" },
|
|
126
|
+
children: /* @__PURE__ */ jsxs(
|
|
127
|
+
ReactFlow,
|
|
128
|
+
{
|
|
129
|
+
nodes,
|
|
130
|
+
edges,
|
|
131
|
+
onNodeClick: handleNodeClick,
|
|
132
|
+
fitView: true,
|
|
133
|
+
fitViewOptions: { padding: 0.3 },
|
|
134
|
+
colorMode: theme,
|
|
135
|
+
proOptions: { hideAttribution: true },
|
|
136
|
+
children: [
|
|
137
|
+
/* @__PURE__ */ jsx(Background, { color: dotColor, gap: 20 }),
|
|
138
|
+
/* @__PURE__ */ jsx(Controls, {}),
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
MiniMap,
|
|
141
|
+
{
|
|
142
|
+
nodeColor: (node) => node.style?.borderColor ?? "#475569",
|
|
143
|
+
style: { background: theme === "dark" ? "#0a0e1a" : "#f1f5f9" }
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { OrkaGraph, useGraph };
|
|
154
|
+
//# sourceMappingURL=index.js.map
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/use-graph.ts","../src/OrkaGraph.tsx"],"names":[],"mappings":";;;;;;AAIA,IAAM,kBAAA,GAAqB;AAAA,EACzB,OAAA,EAAS,SAAA;AAAA,EACT,SAAA,EAAW,SAAA;AAAA,EACX,MAAA,EAAQ,SAAA;AAAA,EACR,OAAA,EAAS;AACX,CAAA;AAEA,IAAM,gBAAA,GAA2C;AAAA,EAC/C,KAAA,EAAO,SAAA;AAAA,EACP,GAAA,EAAK,SAAA;AAAA,EACL,SAAA,EAAW,SAAA;AAAA,EACX,OAAA,EAAS;AACX,CAAA;AAEA,SAAS,aAAA,CACP,IACA,SAAA,EACgD;AAChD,EAAA,IAAI,SAAA,EAAW,WAAA,KAAgB,EAAA,EAAI,OAAO,SAAA;AAC1C,EAAA,IAAI,SAAA,EAAW,cAAA,EAAgB,QAAA,CAAS,EAAE,GAAG,OAAO,WAAA;AACpD,EAAA,IAAI,SAAA,EAAW,WAAA,EAAa,QAAA,CAAS,EAAE,GAAG,OAAO,QAAA;AACjD,EAAA,OAAO,SAAA;AACT;AAMO,SAAS,QAAA,CACd,QAAA,EACA,SAAA,EACA,KAAA,GAA0B,MAAA,EACQ;AAClC,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,MAAM,QAAA,GAAW,SAAS,QAAA,EAAS;AACnC,IAAA,MAAM,QAAA,GAAW,SAAS,QAAA,EAAS;AAGnC,IAAA,MAAM,QAAA,uBAAe,GAAA,EAAoB;AACzC,IAAA,MAAM,OAAA,uBAAc,GAAA,EAAsB;AAC1C,IAAA,KAAA,MAAW,KAAK,QAAA,EAAU;AACxB,MAAA,QAAA,CAAS,GAAA,CAAI,CAAA,CAAE,EAAA,EAAI,CAAC,CAAA;AACpB,MAAA,OAAA,CAAQ,GAAA,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,EAAE,eAAA,EAAiB,IAAA,EAAK;AAAA,UAEpC,QAAA,EAAA;AAAA,4BAAA,GAAA,CAAC,UAAA,EAAA,EAAW,KAAA,EAAO,QAAA,EAAU,GAAA,EAAK,EAAA,EAAI,CAAA;AAAA,gCACrC,QAAA,EAAA,EAAS,CAAA;AAAA,4BACV,GAAA;AAAA,cAAC,OAAA;AAAA,cAAA;AAAA,gBACC,SAAA,EAAW,CAAC,IAAA,KAAU,IAAA,CAAK,OAAO,WAAA,IAA0B,SAAA;AAAA,gBAC5D,OAAO,EAAE,UAAA,EAAY,KAAA,KAAU,MAAA,GAAS,YAAY,SAAA;AAAU;AAAA;AAChE;AAAA;AAAA;AACF;AAAA,GACF;AAEJ","file":"index.js","sourcesContent":["import { useMemo } from 'react';\nimport type { Node, Edge } from '@xyflow/react';\nimport type { OrkaGraphProps, OrkaGraphExecution } from './types.js';\n\nconst NODE_STATUS_COLORS = {\n running: '#3b82f6',\n completed: '#10b981',\n failed: '#ef4444',\n pending: '#64748b',\n};\n\nconst NODE_TYPE_SHAPES: Record<string, string> = {\n start: '#1d4ed8',\n end: '#059669',\n condition: '#d97706',\n default: '#334155',\n};\n\nfunction getNodeStatus(\n id: string,\n execution?: OrkaGraphExecution,\n): 'running' | 'completed' | 'failed' | 'pending' {\n if (execution?.currentNode === id) return 'running';\n if (execution?.completedNodes?.includes(id)) return 'completed';\n if (execution?.failedNodes?.includes(id)) return 'failed';\n return 'pending';\n}\n\n/**\n * Converts OrkaJS workflow nodes/edges to React Flow format.\n * Applies a simple left-to-right auto-layout.\n */\nexport function useGraph(\n workflow: OrkaGraphProps['workflow'],\n execution?: OrkaGraphExecution,\n theme: 'light' | 'dark' = 'dark',\n): { nodes: Node[]; edges: Edge[] } {\n return useMemo(() => {\n const rawNodes = workflow.getNodes();\n const rawEdges = workflow.getEdges();\n\n // Simple auto-layout: rank nodes by graph depth (BFS from sources)\n const indegree = new Map<string, number>();\n const adjList = new Map<string, string[]>();\n for (const n of rawNodes) {\n indegree.set(n.id, 0);\n adjList.set(n.id, []);\n }\n for (const e of rawEdges) {\n indegree.set(e.to, (indegree.get(e.to) ?? 0) + 1);\n adjList.get(e.from)?.push(e.to);\n }\n\n // Topological BFS for layer assignment\n const layers = new Map<string, number>();\n const queue: string[] = [];\n for (const [id, deg] of indegree.entries()) {\n if (deg === 0) queue.push(id);\n }\n let head = 0;\n while (head < queue.length) {\n const id = queue[head++];\n const layer = layers.get(id) ?? 0;\n for (const next of adjList.get(id) ?? []) {\n layers.set(next, Math.max(layers.get(next) ?? 0, layer + 1));\n indegree.set(next, (indegree.get(next) ?? 1) - 1);\n if ((indegree.get(next) ?? 0) <= 0) queue.push(next);\n }\n }\n\n // Position nodes by layer\n const layerCounts = new Map<number, number>();\n const nodePositions = new Map<string, { x: number; y: number }>();\n const H_GAP = 200;\n const V_GAP = 100;\n\n for (const n of rawNodes) {\n const layer = layers.get(n.id) ?? 0;\n const row = layerCounts.get(layer) ?? 0;\n nodePositions.set(n.id, { x: layer * H_GAP, y: row * V_GAP });\n layerCounts.set(layer, row + 1);\n }\n\n const isDark = theme === 'dark';\n const bg = isDark ? '#1e293b' : '#f8fafc';\n const textColor = isDark ? '#e2e8f0' : '#0f172a';\n const borderColor = isDark ? '#334155' : '#cbd5e1';\n\n const nodes: Node[] = rawNodes.map(n => {\n const status = getNodeStatus(n.id, execution);\n const statusColor = NODE_STATUS_COLORS[status];\n const typeColor = NODE_TYPE_SHAPES[n.type ?? 'default'] ?? NODE_TYPE_SHAPES.default;\n const pos = nodePositions.get(n.id) ?? { x: 0, y: 0 };\n\n return {\n id: n.id,\n position: pos,\n type: 'default',\n data: { label: n.id, metadata: n },\n style: {\n background: bg,\n border: `2px solid ${status !== 'pending' ? statusColor : (typeColor ?? borderColor)}`,\n borderRadius: n.type === 'condition' ? '4px' : '8px',\n color: textColor,\n fontSize: '13px',\n padding: '8px 12px',\n minWidth: '80px',\n textAlign: 'center',\n boxShadow: status === 'running' ? `0 0 12px ${statusColor}66` : undefined,\n },\n };\n });\n\n const edgeColor = isDark ? '#475569' : '#94a3b8';\n const edges: Edge[] = rawEdges.map((e, i) => ({\n id: `e-${e.from}-${e.to}-${i}`,\n source: e.from,\n target: e.to,\n label: e.label,\n style: { stroke: edgeColor },\n labelStyle: { fill: edgeColor, fontSize: '11px' },\n }));\n\n return { nodes, edges };\n }, [workflow, execution, theme]);\n}\n","import { useCallback } from 'react';\nimport {\n ReactFlow,\n Background,\n Controls,\n MiniMap,\n type NodeMouseHandler,\n} from '@xyflow/react';\nimport '@xyflow/react/dist/style.css';\nimport { useGraph } from './use-graph.js';\nimport type { OrkaGraphProps } from './types.js';\n\n/**\n * Visual graph component for OrkaJS workflows.\n *\n * Renders a GraphWorkflow or StateGraph as an interactive React Flow diagram.\n * Highlights currently running, completed, and failed nodes based on the\n * optional `execution` prop.\n *\n * @example\n * ```tsx\n * import { OrkaGraph } from '@orka-js/react';\n *\n * function App() {\n * return (\n * <OrkaGraph\n * workflow={myGraphWorkflow}\n * execution={{ currentNode: 'step2', completedNodes: ['step1'] }}\n * height={500}\n * />\n * );\n * }\n * ```\n */\nexport function OrkaGraph({\n workflow,\n execution,\n onNodeClick,\n theme = 'dark',\n width = '100%',\n height = 500,\n className,\n}: OrkaGraphProps) {\n const { nodes, edges } = useGraph(workflow, execution, theme);\n\n const handleNodeClick = useCallback<NodeMouseHandler>(\n (_event, node) => {\n onNodeClick?.(node.id, node.data?.metadata);\n },\n [onNodeClick],\n );\n\n const bgColor = theme === 'dark' ? '#0f1117' : '#f8fafc';\n const dotColor = theme === 'dark' ? '#1e293b' : '#e2e8f0';\n\n return (\n <div\n className={className}\n style={{ width, height, background: bgColor, borderRadius: '8px', overflow: 'hidden' }}\n >\n <ReactFlow\n nodes={nodes}\n edges={edges}\n onNodeClick={handleNodeClick}\n fitView\n fitViewOptions={{ padding: 0.3 }}\n colorMode={theme}\n proOptions={{ hideAttribution: true }}\n >\n <Background color={dotColor} gap={20} />\n <Controls />\n <MiniMap\n nodeColor={(node) => (node.style?.borderColor as string) ?? '#475569'}\n style={{ background: theme === 'dark' ? '#0a0e1a' : '#f1f5f9' }}\n />\n </ReactFlow>\n </div>\n );\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orka-js/react",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "React component for visualizing OrkaJS graph workflows",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@xyflow/react": "^12.0.0",
|
|
19
|
+
"@orka-js/core": "1.5.0",
|
|
20
|
+
"@orka-js/graph": "1.4.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=18.0.0",
|
|
24
|
+
"react-dom": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^18.3.1",
|
|
28
|
+
"@types/react-dom": "^18.3.0",
|
|
29
|
+
"react": "^18.3.1",
|
|
30
|
+
"react-dom": "^18.3.1",
|
|
31
|
+
"vitest": "^1.6.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"dev": "tsup --watch",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"test": "vitest run"
|
|
38
|
+
}
|
|
39
|
+
}
|