@motiadev/workbench 0.6.1-beta.124 → 0.6.2-beta.126
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/dist/index.html +0 -16
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.js +20 -2
- package/dist/src/components/flow/flow-view.js +1 -1
- package/dist/src/components/flow/node-organizer.d.ts +4 -0
- package/dist/src/components/flow/node-organizer.js +73 -12
- package/dist/src/components/logs/log-level-dot.js +5 -5
- package/dist/src/hooks/use-update-handle-positions.js +2 -2
- package/dist/src/publicComponents/base-node/base-node.js +1 -1
- package/dist/tsconfig.app.tsbuildinfo +1 -1
- package/dist/tsconfig.node.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/src/components/flow/hooks/use-organize-nodes.d.ts +0 -3
- package/dist/src/components/flow/hooks/use-organize-nodes.js +0 -43
package/dist/index.html
CHANGED
|
@@ -27,22 +27,6 @@
|
|
|
27
27
|
})
|
|
28
28
|
</script>
|
|
29
29
|
|
|
30
|
-
<!-- Start of Reo Javascript -->
|
|
31
|
-
<script type="text/javascript">
|
|
32
|
-
!(function () {
|
|
33
|
-
var e, t, n
|
|
34
|
-
;(e = 'd8f0ce9cae8ae64'),
|
|
35
|
-
(t = function () {
|
|
36
|
-
Reo.init({ clientID: 'd8f0ce9cae8ae64' })
|
|
37
|
-
}),
|
|
38
|
-
((n = document.createElement('script')).src = 'https://static.reo.dev/' + e + '/reo.js'),
|
|
39
|
-
(n.defer = !0),
|
|
40
|
-
(n.onload = t),
|
|
41
|
-
document.head.appendChild(n)
|
|
42
|
-
})()
|
|
43
|
-
</script>
|
|
44
|
-
<!-- End of Reo Javascript -->
|
|
45
|
-
|
|
46
30
|
<script>
|
|
47
31
|
const importFile = async (path) => {
|
|
48
32
|
// Normalize the path for cross-platform compatibility
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Express } from 'express';
|
|
2
|
-
export declare const applyMiddleware: (app: Express) => Promise<void>;
|
|
2
|
+
export declare const applyMiddleware: (app: Express, port: number) => Promise<void>;
|
package/dist/middleware.js
CHANGED
|
@@ -18,7 +18,24 @@ const processCwdPlugin = () => {
|
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
const
|
|
21
|
+
const reoPlugin = () => {
|
|
22
|
+
return {
|
|
23
|
+
name: 'html-transform',
|
|
24
|
+
transformIndexHtml(html) {
|
|
25
|
+
const isAnalyticsEnabled = process.env.MOTIA_ANALYTICS_DISABLED !== 'true';
|
|
26
|
+
if (!isAnalyticsEnabled) {
|
|
27
|
+
return html;
|
|
28
|
+
}
|
|
29
|
+
// inject before </head>
|
|
30
|
+
return html.replace('</head>', `
|
|
31
|
+
<script type="text/javascript">
|
|
32
|
+
!function(){var e,t,n;e="d8f0ce9cae8ae64",t=function(){Reo.init({clientID:"d8f0ce9cae8ae64", source: "internal"})},(n=document.createElement("script")).src="https://static.reo.dev/"+e+"/reo.js",n.defer=!0,n.onload=t,document.head.appendChild(n)}();
|
|
33
|
+
</script>
|
|
34
|
+
</head>`);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const applyMiddleware = async (app, port) => {
|
|
22
39
|
const vite = await (0, vite_1.createServer)({
|
|
23
40
|
appType: 'spa',
|
|
24
41
|
root: __dirname,
|
|
@@ -26,6 +43,7 @@ const applyMiddleware = async (app) => {
|
|
|
26
43
|
middlewareMode: true,
|
|
27
44
|
allowedHosts: true,
|
|
28
45
|
host: true,
|
|
46
|
+
hmr: { port: 21678 + port },
|
|
29
47
|
fs: {
|
|
30
48
|
allow: [
|
|
31
49
|
__dirname, // workbench root
|
|
@@ -37,7 +55,7 @@ const applyMiddleware = async (app) => {
|
|
|
37
55
|
resolve: {
|
|
38
56
|
alias: { '@': path_1.default.resolve(__dirname, './src') },
|
|
39
57
|
},
|
|
40
|
-
plugins: [(0, plugin_react_1.default)(), processCwdPlugin()],
|
|
58
|
+
plugins: [(0, plugin_react_1.default)(), processCwdPlugin(), reoPlugin()],
|
|
41
59
|
});
|
|
42
60
|
app.use(vite.middlewares);
|
|
43
61
|
app.use('*', async (req, res, next) => {
|
|
@@ -17,5 +17,5 @@ export const FlowView = ({ flow, flowConfig }) => {
|
|
|
17
17
|
if (!nodeTypes) {
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
|
-
return (_jsxs("div", { className: "w-full h-full relative", children: [!initialized && _jsx(FlowLoader, {}), _jsxs(ReactFlow, { nodes: nodes, edges: edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChangeHandler, onEdgesChange: onEdgesChange, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 50, size: 2, className: "
|
|
20
|
+
return (_jsxs("div", { className: "w-full h-full relative", children: [!initialized && _jsx(FlowLoader, {}), _jsxs(ReactFlow, { minZoom: 0.1, nodes: nodes, edges: edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChangeHandler, onEdgesChange: onEdgesChange, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 50, size: 2, className: "bg-canvas-background!" }), _jsx(NodeOrganizer, { onInitialized: onInitialized, nodes: nodes, edges: edges })] })] }));
|
|
21
21
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { EdgeData, NodeData } from '@/types/flow';
|
|
2
|
+
import { Edge, Node } from '@xyflow/react';
|
|
1
3
|
import React from 'react';
|
|
2
4
|
type Props = {
|
|
3
5
|
onInitialized: () => void;
|
|
6
|
+
nodes: Node<NodeData>[];
|
|
7
|
+
edges: Edge<EdgeData>[];
|
|
4
8
|
};
|
|
5
9
|
export declare const NodeOrganizer: React.FC<Props>;
|
|
6
10
|
export {};
|
|
@@ -1,21 +1,82 @@
|
|
|
1
1
|
import { useNodesInitialized, useReactFlow } from '@xyflow/react';
|
|
2
|
+
import dagre from 'dagre';
|
|
3
|
+
import isEqual from 'fast-deep-equal';
|
|
2
4
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
|
|
5
|
+
const organizeNodes = (nodes, edges) => {
|
|
6
|
+
const dagreGraph = new dagre.graphlib.Graph({ directed: true, compound: false, multigraph: false });
|
|
7
|
+
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
|
8
|
+
dagreGraph.setGraph({ rankdir: 'LR', ranksep: 0, nodesep: 20, edgesep: 0 });
|
|
9
|
+
nodes.forEach((node) => {
|
|
10
|
+
if (node.position.x !== 0 || node.position.y !== 0) {
|
|
11
|
+
dagreGraph.setNode(node.id, {
|
|
12
|
+
width: node.measured?.width,
|
|
13
|
+
height: node.measured?.height,
|
|
14
|
+
x: node.position.x,
|
|
15
|
+
y: node.position.y,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
dagreGraph.setNode(node.id, {
|
|
20
|
+
width: node.measured?.width,
|
|
21
|
+
height: node.measured?.height,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
edges.forEach((edge) => {
|
|
26
|
+
if (typeof edge.label === 'string') {
|
|
27
|
+
dagreGraph.setEdge(edge.source, edge.target, {
|
|
28
|
+
label: edge.label ?? '',
|
|
29
|
+
width: edge.label.length * 40, // Add width for the label
|
|
30
|
+
height: 30, // Add height for the label
|
|
31
|
+
labelpos: 'c', // Position label in center
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
dagreGraph.setEdge(edge.source, edge.target);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
dagre.layout(dagreGraph);
|
|
39
|
+
return nodes.map((node) => {
|
|
40
|
+
if (node.position.x !== 0 || node.position.y !== 0) {
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
43
|
+
const { x, y } = dagreGraph.node(node.id);
|
|
44
|
+
const position = {
|
|
45
|
+
x: x - (node.measured?.width ?? 0) / 2,
|
|
46
|
+
y: y - (node.measured?.height ?? 0) / 2,
|
|
47
|
+
};
|
|
48
|
+
return { ...node, position };
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export const NodeOrganizer = ({ onInitialized, nodes, edges }) => {
|
|
4
52
|
const { setNodes, getNodes, getEdges, fitView } = useReactFlow();
|
|
5
53
|
const nodesInitialized = useNodesInitialized();
|
|
6
54
|
const initialized = useRef(false);
|
|
55
|
+
const lastNodesRef = useRef([]);
|
|
56
|
+
const lastEdgesRef = useRef([]);
|
|
7
57
|
useEffect(() => {
|
|
8
|
-
if (nodesInitialized
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
58
|
+
if (nodesInitialized) {
|
|
59
|
+
if (isEqual(lastNodesRef.current, nodes) && isEqual(lastEdgesRef.current, edges)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
lastNodesRef.current = nodes;
|
|
63
|
+
lastEdgesRef.current = edges;
|
|
64
|
+
try {
|
|
65
|
+
const nodesToOrganize = nodes.some((node) => node.position.x === 0 && node.position.y === 0);
|
|
66
|
+
if (nodesToOrganize) {
|
|
67
|
+
const organizedNodes = organizeNodes(nodes, edges);
|
|
68
|
+
setNodes(organizedNodes);
|
|
69
|
+
}
|
|
70
|
+
if (!initialized.current) {
|
|
71
|
+
initialized.current = true;
|
|
72
|
+
onInitialized();
|
|
73
|
+
setTimeout(() => fitView(), 1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('Error organizing nodes:', error);
|
|
78
|
+
}
|
|
18
79
|
}
|
|
19
|
-
}, [nodesInitialized, onInitialized, setNodes, getNodes, getEdges, fitView]);
|
|
80
|
+
}, [nodesInitialized, onInitialized, setNodes, getNodes, getEdges, fitView, nodes, edges]);
|
|
20
81
|
return null;
|
|
21
82
|
};
|
|
@@ -4,11 +4,11 @@ const badgeVariants = cva('text-xs font-medium tracking-wide rounded-full h-[6px
|
|
|
4
4
|
variants: {
|
|
5
5
|
variant: {
|
|
6
6
|
info: 'bg-[#2862FE] outline-[#2862FE]/20',
|
|
7
|
-
trace: 'bg-
|
|
8
|
-
debug: 'bg-
|
|
9
|
-
error: 'bg-
|
|
10
|
-
fatal: 'bg-
|
|
11
|
-
warn: 'bg-
|
|
7
|
+
trace: 'bg-[#2862FE] outline-[#2862FE]/20',
|
|
8
|
+
debug: 'bg-[#2862FE] outline-[#2862FE]/20',
|
|
9
|
+
error: 'bg-[#E22A6D] outline-[#E22A6D]/20',
|
|
10
|
+
fatal: 'bg-[#E22A6D] outline-[#E22A6D]/20',
|
|
11
|
+
warn: 'bg-[#F59F0B] outline-[#F59F0B]/20',
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
14
|
});
|
|
@@ -2,8 +2,8 @@ import { Position, useReactFlow, useUpdateNodeInternals } from '@xyflow/react';
|
|
|
2
2
|
export const useHandlePositions = (data) => {
|
|
3
3
|
const reactFlow = useReactFlow();
|
|
4
4
|
const updateNodeInternals = useUpdateNodeInternals();
|
|
5
|
-
const sourcePosition = data.nodeConfig?.sourceHandlePosition === '
|
|
6
|
-
const targetPosition = data.nodeConfig?.targetHandlePosition === '
|
|
5
|
+
const sourcePosition = data.nodeConfig?.sourceHandlePosition === 'bottom' ? Position.Bottom : Position.Right;
|
|
6
|
+
const targetPosition = data.nodeConfig?.targetHandlePosition === 'top' ? Position.Top : Position.Left;
|
|
7
7
|
const updateSourcePosition = (position) => {
|
|
8
8
|
reactFlow.updateNode(data.id, {
|
|
9
9
|
data: { ...data, nodeConfig: { ...data.nodeConfig, sourceHandlePosition: position } },
|
|
@@ -24,7 +24,7 @@ export const BaseNode = ({ title, variant, children, disableSourceHandle, disabl
|
|
|
24
24
|
}, [data.id, isOpen, fetchContent]);
|
|
25
25
|
return (_jsxs("div", { className: cn('p-1 rounded-lg max-w-[350px]', {
|
|
26
26
|
'bg-muted-foreground/20': isOpen,
|
|
27
|
-
}), children: [_jsx("div", { className: "rounded-lg bg-background border-1 border-muted-foreground/30 border-solid", "data-testid": `node-${title?.toLowerCase().replace(/ /g, '-')}`, children: _jsxs("div", { className: "group relative", children: [_jsx(NodeHeader, { text: title, variant: variant, className: "border-b-2 border-muted-foreground/10", children: _jsx("div", { className: "flex justify-end", children: _jsx(Button, { "data-testid": `open-code-preview-button-${title?.toLowerCase()}`, variant: "ghost", className: "h-5 p-0.5", onClick: () => setIsOpen(true), children: _jsx(ScanSearch, { className: "w-4 h-4" }) }) }) }), subtitle && _jsx("div", { className: "py-4 px-6 text-sm text-muted-foreground", children: subtitle }), children && (_jsx("div", { className: "p-2", children: _jsx("div", { className: cn('space-y-3 p-4 text-sm text-muted-foreground', {
|
|
27
|
+
}), children: [_jsx("div", { className: "rounded-lg dark:bg-[#222] bg-background border-1 border-muted-foreground/30 border-solid", "data-testid": `node-${title?.toLowerCase().replace(/ /g, '-')}`, children: _jsxs("div", { className: "group relative", children: [_jsx(NodeHeader, { text: title, variant: variant, className: "border-b-2 border-muted-foreground/10", children: _jsx("div", { className: "flex justify-end", children: _jsx(Button, { "data-testid": `open-code-preview-button-${title?.toLowerCase()}`, variant: "ghost", className: "h-5 p-0.5", onClick: () => setIsOpen(true), children: _jsx(ScanSearch, { className: "w-4 h-4" }) }) }) }), subtitle && _jsx("div", { className: "py-4 px-6 text-sm text-muted-foreground", children: subtitle }), children && (_jsx("div", { className: "p-2", children: _jsx("div", { className: cn('space-y-3 p-4 text-sm text-muted-foreground', {
|
|
28
28
|
'bg-card': variant !== 'noop',
|
|
29
29
|
}), children: children }) })), !disableTargetHandle && (_jsx(BaseHandle, { type: "target", position: targetPosition, onTogglePosition: toggleTargetPosition })), !disableSourceHandle && (_jsx(BaseHandle, { type: "source", position: sourcePosition, onTogglePosition: toggleSourcePosition }))] }) }), content && (_jsx(NodeSidebar, { features: features, content: content, title: title, subtitle: subtitle, variant: variant, language: language, isOpen: isOpen, onClose: () => setIsOpen(false) }))] }));
|
|
30
30
|
};
|