@motiadev/workbench 0.5.11-beta.120-357906 → 0.5.11-beta.120-207545

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 CHANGED
@@ -26,22 +26,6 @@
26
26
  optOut: true,
27
27
  })
28
28
  </script>
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', source: 'internal' })
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
29
 
46
30
  <script>
47
31
  const importFile = async (path) => {
@@ -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>;
@@ -18,7 +18,24 @@ const processCwdPlugin = () => {
18
18
  },
19
19
  };
20
20
  };
21
- const applyMiddleware = async (app) => {
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: "[--xy-background-color-dots:theme(colors.muted.DEFAULT)] [--xy-background-color:theme(colors.background)]" }), _jsx(NodeOrganizer, { onInitialized: onInitialized })] })] }));
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
- export const NodeOrganizer = ({ onInitialized }) => {
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 && !initialized.current) {
9
- initialized.current = true;
10
- // const nodes = getNodes() as Node<EventNodeData | ApiNodeData>[]
11
- // const edges = getEdges() as Edge<EdgeData>[]
12
- // const organizedNodes = organizeNodes(nodes, edges)
13
- // setNodes(organizedNodes)
14
- onInitialized();
15
- setTimeout(async () => {
16
- await fitView();
17
- }, 1);
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-sky-500 outline-sky-500',
8
- debug: 'bg-sky-500 outline-sky-500',
9
- error: 'bg-rose-500 outline-rose-500',
10
- fatal: 'bg-rose-500 outline-rose-500',
11
- warn: 'bg-amber-500 outline-amber-500',
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 === 'right' ? Position.Right : Position.Bottom;
6
- const targetPosition = data.nodeConfig?.targetHandlePosition === 'left' ? Position.Left : Position.Top;
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
  };