@open-mercato/core 0.6.4-develop.3944.1.4100aa7fbe → 0.6.4-develop.3962.1.70f30e284c

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/workflows/components/WorkflowGraph.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport { useCallback, useMemo, useEffect, useState } from 'react'\nimport {\n ReactFlow,\n Node,\n Edge,\n Controls,\n Background,\n BackgroundVariant,\n MiniMap,\n Panel,\n useNodesState,\n useEdgesState,\n addEdge,\n Connection,\n ConnectionMode,\n MarkerType,\n} from '@xyflow/react'\nimport {StartNode, EndNode, UserTaskNode, AutomatedNode, SubWorkflowNode, WaitForSignalNode, WaitForTimerNode} from './nodes'\nimport { WorkflowTransitionEdge } from './WorkflowTransitionEdge'\nimport { STATUS_COLORS } from '../lib/status-colors'\nimport { Alert, AlertDescription } from '@open-mercato/ui/primitives/alert'\nimport { Edit3 } from 'lucide-react'\nimport { useTheme } from '@open-mercato/ui/theme'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\n\n// NOTE: ReactFlow styles should be imported in the page that uses this component\n// or in a global CSS file. Import: '@xyflow/react/dist/style.css'\n\nexport interface WorkflowGraphProps {\n initialNodes?: Node[]\n initialEdges?: Edge[]\n onNodesChange?: (changes: any[]) => void\n onEdgesChange?: (changes: any[]) => void\n onNodeClick?: (event: React.MouseEvent, node: Node) => void\n onEdgeClick?: (event: React.MouseEvent, edge: Edge) => void\n onConnect?: (connection: Connection) => void\n editable?: boolean\n className?: string\n height?: string\n}\n\n/**\n * WorkflowGraph - ReactFlow wrapper component for workflow visualization\n *\n * Provides a graph-based view of workflow definitions with:\n * - Pan and zoom controls\n * - Background grid\n * - Mini-map for navigation\n * - Optional editing capabilities\n */\nexport function WorkflowGraph({\n initialNodes = [],\n initialEdges = [],\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n onNodeClick: onNodeClickProp,\n onEdgeClick: onEdgeClickProp,\n onConnect: onConnectProp,\n editable = false,\n className = '',\n height = '600px',\n}: WorkflowGraphProps) {\n const t = useT()\n // Use ReactFlow hooks for node and edge state management\n const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes)\n const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges)\n\n // Get theme for dark mode support\n const { resolvedTheme } = useTheme()\n const isDark = resolvedTheme === 'dark'\n const backgroundDotColor = isDark ? '#374151' : '#e5e7eb'\n const [isCompactViewport, setIsCompactViewport] = useState(false)\n\n useEffect(() => {\n if (typeof window === 'undefined') return\n const mediaQuery = window.matchMedia('(max-width: 1279px)')\n const updateViewportMode = () => setIsCompactViewport(mediaQuery.matches)\n\n updateViewportMode()\n mediaQuery.addEventListener('change', updateViewportMode)\n\n return () => {\n mediaQuery.removeEventListener('change', updateViewportMode)\n }\n }, [])\n\n // Sync internal state when external state changes (e.g., when parent adds nodes)\n useEffect(() => {\n setNodes(initialNodes)\n }, [initialNodes, setNodes])\n\n useEffect(() => {\n setEdges(initialEdges)\n }, [initialEdges, setEdges])\n\n // Handle connection between nodes (when user drags from one node to another)\n const onConnect = useCallback(\n (connection: Connection) => {\n if (onConnectProp) {\n // Let parent handle the connection\n onConnectProp(connection)\n } else {\n // Fallback: handle internally if no parent callback\n const newEdge = {\n ...connection,\n type: 'workflowTransition',\n animated: false,\n markerEnd: {\n type: MarkerType.ArrowClosed,\n width: 16,\n height: 16,\n color: '#9ca3af',\n },\n }\n setEdges((eds) => addEdge(newEdge, eds))\n }\n },\n [setEdges, onConnectProp]\n )\n\n // Notify parent when nodes change\n const handleNodesChange = useCallback(\n (changes: any) => {\n onNodesChange(changes)\n if (onNodesChangeProp) {\n onNodesChangeProp(changes)\n }\n },\n [onNodesChange, onNodesChangeProp]\n )\n\n // Notify parent when edges change\n const handleEdgesChange = useCallback(\n (changes: any) => {\n onEdgesChange(changes)\n if (onEdgesChangeProp) {\n onEdgesChangeProp(changes)\n }\n },\n [onEdgesChange, onEdgesChangeProp]\n )\n\n // Register custom node types\n const nodeTypes = useMemo(\n () => ({\n start: StartNode,\n end: EndNode,\n userTask: UserTaskNode,\n automated: AutomatedNode,\n subWorkflow: SubWorkflowNode,\n waitForSignal: WaitForSignalNode,\n waitForTimer: WaitForTimerNode,\n }),\n []\n )\n\n // Register custom edge types\n const edgeTypes = useMemo(\n () => ({\n workflowTransition: WorkflowTransitionEdge,\n }),\n []\n )\n\n return (\n <div className={`workflow-graph-container ${className}`} style={{ height }}>\n <ReactFlow\n nodes={nodes}\n edges={edges}\n nodeTypes={nodeTypes}\n edgeTypes={edgeTypes}\n onNodesChange={handleNodesChange}\n onEdgesChange={handleEdgesChange}\n onConnect={editable ? onConnect : undefined}\n onNodeClick={onNodeClickProp}\n onEdgeClick={onEdgeClickProp}\n connectionMode={ConnectionMode.Loose}\n fitView\n fitViewOptions={{\n padding: 0.2,\n maxZoom: isCompactViewport ? 0.9 : 1,\n }}\n minZoom={0.1}\n maxZoom={2}\n defaultEdgeOptions={{\n type: 'workflowTransition',\n animated: false,\n markerEnd: {\n type: MarkerType.ArrowClosed,\n width: 16,\n height: 16,\n color: '#9ca3af',\n },\n }}\n nodesDraggable={editable}\n nodesConnectable={editable}\n elementsSelectable={editable}\n proOptions={{ hideAttribution: true }}\n >\n {/* Background grid for visual reference */}\n <Background\n variant={BackgroundVariant.Dots}\n gap={16}\n size={1}\n color={backgroundDotColor}\n />\n\n {/* Zoom and pan controls */}\n <Controls\n showZoom={true}\n showFitView={true}\n showInteractive={false}\n position={isCompactViewport ? 'bottom-right' : 'top-right'}\n className={`!bg-card !border-border !shadow-md [&>button]:!bg-card [&>button]:!border-border [&>button]:!fill-foreground [&>button:hover]:!bg-muted ${isCompactViewport ? 'scale-90 origin-bottom-right' : ''}`}\n />\n\n {/* Mini-map for navigation in large workflows */}\n {!isCompactViewport && (\n <MiniMap\n nodeStrokeWidth={3}\n nodeColor={(node) => {\n // Color nodes by status - using status-based colors\n const status = (node.data?.status || 'not_started') as keyof typeof STATUS_COLORS\n return STATUS_COLORS[status]?.hex || STATUS_COLORS.not_started.hex\n }}\n maskColor=\"rgba(0, 0, 0, 0.1)\"\n position=\"bottom-left\"\n className=\"!bg-card !border !border-border !rounded-lg\"\n />\n )}\n\n {/* Info panel */}\n {!editable && !isCompactViewport && (\n <Panel position=\"top-left\" style={{ margin: 10 }}>\n <div className=\"bg-card rounded-lg shadow-sm border border-border px-4 py-2\">\n <p className=\"text-sm text-muted-foreground font-medium\">\n {t('workflows.graph.visualization')}\n </p>\n </div>\n </Panel>\n )}\n\n {editable && !isCompactViewport && (\n <Panel position=\"top-left\" style={{ margin: 10 }}>\n <Alert variant=\"info\" className=\"max-w-sm\">\n <Edit3 className=\"size-4\" />\n <AlertDescription className=\"font-medium\">\n {t('workflows.graph.editModeInfo')}\n </AlertDescription>\n </Alert>\n </Panel>\n )}\n </ReactFlow>\n </div>\n )\n}\n\n/**\n * WorkflowGraphReadOnly - Read-only version for viewing workflow execution\n */\nexport function WorkflowGraphReadOnly({\n nodes,\n edges,\n className = '',\n height = '500px',\n}: {\n nodes: Node[]\n edges: Edge[]\n className?: string\n height?: string\n}) {\n return (\n <WorkflowGraph\n initialNodes={nodes}\n initialEdges={edges}\n editable={false}\n className={className}\n height={height}\n />\n )\n}\n"],
5
- "mappings": ";AA0MQ,cA4CI,YA5CJ;AAxMR,SAAS,aAAa,SAAS,WAAW,gBAAgB;AAC1D;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAQ,WAAW,SAAS,cAAc,eAAe,iBAAiB,mBAAmB,wBAAuB;AACpH,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAC9B,SAAS,OAAO,wBAAwB;AACxC,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,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A,EACpC;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,SAAS;AACX,GAKG;AACD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAc;AAAA,MACd,cAAc;AAAA,MACd,UAAU;AAAA,MACV;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;",
4
+ "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport type { Node, Edge, Connection } from '@xyflow/react'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport interface WorkflowGraphProps {\n initialNodes?: Node[]\n initialEdges?: Edge[]\n onNodesChange?: (changes: any[]) => void\n onEdgesChange?: (changes: any[]) => void\n onNodeClick?: (event: React.MouseEvent, node: Node) => void\n onEdgeClick?: (event: React.MouseEvent, edge: Edge) => void\n onConnect?: (connection: Connection) => void\n editable?: boolean\n className?: string\n height?: string\n}\n\nconst WorkflowGraphImpl = dynamic(() => import('./WorkflowGraphImpl'), {\n ssr: false,\n loading: () => null,\n})\n\nfunction WorkflowGraphPlaceholder({ height }: { height: string }) {\n return (\n <div\n className=\"workflow-graph-container flex items-center justify-center rounded-lg border border-border bg-muted/30\"\n style={{ height }}\n >\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n )\n}\n\n/**\n * WorkflowGraph \u2014 lazy-loaded ReactFlow wrapper.\n *\n * @xyflow/react is loaded via next/dynamic({ ssr: false }) so the ~12 MB\n * package only enters the Turbopack module graph when this component\n * actually renders.\n */\nexport function WorkflowGraph(props: WorkflowGraphProps) {\n const { height = '600px' } = props\n // Track impl-chunk readiness so the loading placeholder respects the\n // caller's `height` prop (next/dynamic's `loading` cannot access props).\n // The browser caches the module, so the duplicate `import()` is free.\n const [isImplReady, setIsImplReady] = React.useState(false)\n React.useEffect(() => {\n let cancelled = false\n void import('./WorkflowGraphImpl').then(() => {\n if (!cancelled) setIsImplReady(true)\n })\n return () => {\n cancelled = true\n }\n }, [])\n\n if (!isImplReady) return <WorkflowGraphPlaceholder height={height} />\n return <WorkflowGraphImpl {...props} />\n}\n\n/**\n * WorkflowGraphReadOnly \u2014 read-only viewer that reuses WorkflowGraph.\n */\nexport function WorkflowGraphReadOnly({\n nodes,\n edges,\n className = '',\n height = '500px',\n}: {\n nodes: Node[]\n edges: Edge[]\n className?: string\n height?: string\n}) {\n return (\n <WorkflowGraph\n initialNodes={nodes}\n initialEdges={edges}\n editable={false}\n className={className}\n height={height}\n />\n )\n}\n"],
5
+ "mappings": ";AA+BM;AA7BN,YAAY,WAAW;AACvB,OAAO,aAAa;AAEpB,SAAS,eAAe;AAexB,MAAM,oBAAoB,QAAQ,MAAM,OAAO,qBAAqB,GAAG;AAAA,EACrE,KAAK;AAAA,EACL,SAAS,MAAM;AACjB,CAAC;AAED,SAAS,yBAAyB,EAAE,OAAO,GAAuB;AAChE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,OAAO,EAAE,OAAO;AAAA,MAEhB,8BAAC,WAAQ,WAAU,iCAAgC;AAAA;AAAA,EACrD;AAEJ;AASO,SAAS,cAAc,OAA2B;AACvD,QAAM,EAAE,SAAS,QAAQ,IAAI;AAI7B,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAS,KAAK;AAC1D,QAAM,UAAU,MAAM;AACpB,QAAI,YAAY;AAChB,SAAK,OAAO,qBAAqB,EAAE,KAAK,MAAM;AAC5C,UAAI,CAAC,UAAW,gBAAe,IAAI;AAAA,IACrC,CAAC;AACD,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,MAAI,CAAC,YAAa,QAAO,oBAAC,4BAAyB,QAAgB;AACnE,SAAO,oBAAC,qBAAmB,GAAG,OAAO;AACvC;AAKO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,SAAS;AACX,GAKG;AACD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAc;AAAA,MACd,cAAc;AAAA,MACd,UAAU;AAAA,MACV;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,196 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import "@xyflow/react/dist/style.css";
4
+ import { useCallback, useMemo, useEffect, useState } from "react";
5
+ import {
6
+ ReactFlow,
7
+ Controls,
8
+ Background,
9
+ BackgroundVariant,
10
+ MiniMap,
11
+ Panel,
12
+ useNodesState,
13
+ useEdgesState,
14
+ addEdge,
15
+ ConnectionMode,
16
+ MarkerType
17
+ } from "@xyflow/react";
18
+ import { StartNode, EndNode, UserTaskNode, AutomatedNode, SubWorkflowNode, WaitForSignalNode, WaitForTimerNode } from "./nodes/index.js";
19
+ import { WorkflowTransitionEdge } from "./WorkflowTransitionEdge.js";
20
+ import { STATUS_COLORS } from "../lib/status-colors.js";
21
+ import { Alert, AlertDescription } from "@open-mercato/ui/primitives/alert";
22
+ import { Edit3 } from "lucide-react";
23
+ import { useTheme } from "@open-mercato/ui/theme";
24
+ import { useT } from "@open-mercato/shared/lib/i18n/context";
25
+ function WorkflowGraphImpl({
26
+ initialNodes = [],
27
+ initialEdges = [],
28
+ onNodesChange: onNodesChangeProp,
29
+ onEdgesChange: onEdgesChangeProp,
30
+ onNodeClick: onNodeClickProp,
31
+ onEdgeClick: onEdgeClickProp,
32
+ onConnect: onConnectProp,
33
+ editable = false,
34
+ className = "",
35
+ height = "600px"
36
+ }) {
37
+ const t = useT();
38
+ const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
39
+ const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
40
+ const { resolvedTheme } = useTheme();
41
+ const isDark = resolvedTheme === "dark";
42
+ const backgroundDotColor = isDark ? "#374151" : "#e5e7eb";
43
+ const [isCompactViewport, setIsCompactViewport] = useState(false);
44
+ useEffect(() => {
45
+ if (typeof window === "undefined") return;
46
+ const mediaQuery = window.matchMedia("(max-width: 1279px)");
47
+ const updateViewportMode = () => setIsCompactViewport(mediaQuery.matches);
48
+ updateViewportMode();
49
+ mediaQuery.addEventListener("change", updateViewportMode);
50
+ return () => {
51
+ mediaQuery.removeEventListener("change", updateViewportMode);
52
+ };
53
+ }, []);
54
+ useEffect(() => {
55
+ setNodes(initialNodes);
56
+ }, [initialNodes, setNodes]);
57
+ useEffect(() => {
58
+ setEdges(initialEdges);
59
+ }, [initialEdges, setEdges]);
60
+ const onConnect = useCallback(
61
+ (connection) => {
62
+ if (onConnectProp) {
63
+ onConnectProp(connection);
64
+ } else {
65
+ const newEdge = {
66
+ ...connection,
67
+ type: "workflowTransition",
68
+ animated: false,
69
+ markerEnd: {
70
+ type: MarkerType.ArrowClosed,
71
+ width: 16,
72
+ height: 16,
73
+ color: "#9ca3af"
74
+ }
75
+ };
76
+ setEdges((eds) => addEdge(newEdge, eds));
77
+ }
78
+ },
79
+ [setEdges, onConnectProp]
80
+ );
81
+ const handleNodesChange = useCallback(
82
+ (changes) => {
83
+ onNodesChange(changes);
84
+ if (onNodesChangeProp) {
85
+ onNodesChangeProp(changes);
86
+ }
87
+ },
88
+ [onNodesChange, onNodesChangeProp]
89
+ );
90
+ const handleEdgesChange = useCallback(
91
+ (changes) => {
92
+ onEdgesChange(changes);
93
+ if (onEdgesChangeProp) {
94
+ onEdgesChangeProp(changes);
95
+ }
96
+ },
97
+ [onEdgesChange, onEdgesChangeProp]
98
+ );
99
+ const nodeTypes = useMemo(
100
+ () => ({
101
+ start: StartNode,
102
+ end: EndNode,
103
+ userTask: UserTaskNode,
104
+ automated: AutomatedNode,
105
+ subWorkflow: SubWorkflowNode,
106
+ waitForSignal: WaitForSignalNode,
107
+ waitForTimer: WaitForTimerNode
108
+ }),
109
+ []
110
+ );
111
+ const edgeTypes = useMemo(
112
+ () => ({
113
+ workflowTransition: WorkflowTransitionEdge
114
+ }),
115
+ []
116
+ );
117
+ return /* @__PURE__ */ jsx("div", { className: `workflow-graph-container ${className}`, style: { height }, children: /* @__PURE__ */ jsxs(
118
+ ReactFlow,
119
+ {
120
+ nodes,
121
+ edges,
122
+ nodeTypes,
123
+ edgeTypes,
124
+ onNodesChange: handleNodesChange,
125
+ onEdgesChange: handleEdgesChange,
126
+ onConnect: editable ? onConnect : void 0,
127
+ onNodeClick: onNodeClickProp,
128
+ onEdgeClick: onEdgeClickProp,
129
+ connectionMode: ConnectionMode.Loose,
130
+ fitView: true,
131
+ fitViewOptions: {
132
+ padding: 0.2,
133
+ maxZoom: isCompactViewport ? 0.9 : 1
134
+ },
135
+ minZoom: 0.1,
136
+ maxZoom: 2,
137
+ defaultEdgeOptions: {
138
+ type: "workflowTransition",
139
+ animated: false,
140
+ markerEnd: {
141
+ type: MarkerType.ArrowClosed,
142
+ width: 16,
143
+ height: 16,
144
+ color: "#9ca3af"
145
+ }
146
+ },
147
+ nodesDraggable: editable,
148
+ nodesConnectable: editable,
149
+ elementsSelectable: editable,
150
+ proOptions: { hideAttribution: true },
151
+ children: [
152
+ /* @__PURE__ */ jsx(
153
+ Background,
154
+ {
155
+ variant: BackgroundVariant.Dots,
156
+ gap: 16,
157
+ size: 1,
158
+ color: backgroundDotColor
159
+ }
160
+ ),
161
+ /* @__PURE__ */ jsx(
162
+ Controls,
163
+ {
164
+ showZoom: true,
165
+ showFitView: true,
166
+ showInteractive: false,
167
+ position: isCompactViewport ? "bottom-right" : "top-right",
168
+ className: `!bg-card !border-border !shadow-md [&>button]:!bg-card [&>button]:!border-border [&>button]:!fill-foreground [&>button:hover]:!bg-muted ${isCompactViewport ? "scale-90 origin-bottom-right" : ""}`
169
+ }
170
+ ),
171
+ !isCompactViewport && /* @__PURE__ */ jsx(
172
+ MiniMap,
173
+ {
174
+ nodeStrokeWidth: 3,
175
+ nodeColor: (node) => {
176
+ const status = node.data?.status || "not_started";
177
+ return STATUS_COLORS[status]?.hex || STATUS_COLORS.not_started.hex;
178
+ },
179
+ maskColor: "rgba(0, 0, 0, 0.1)",
180
+ position: "bottom-left",
181
+ className: "!bg-card !border !border-border !rounded-lg"
182
+ }
183
+ ),
184
+ !editable && !isCompactViewport && /* @__PURE__ */ jsx(Panel, { position: "top-left", style: { margin: 10 }, children: /* @__PURE__ */ jsx("div", { className: "bg-card rounded-lg shadow-sm border border-border px-4 py-2", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground font-medium", children: t("workflows.graph.visualization") }) }) }),
185
+ editable && !isCompactViewport && /* @__PURE__ */ jsx(Panel, { position: "top-left", style: { margin: 10 }, children: /* @__PURE__ */ jsxs(Alert, { variant: "info", className: "max-w-sm", children: [
186
+ /* @__PURE__ */ jsx(Edit3, { className: "size-4" }),
187
+ /* @__PURE__ */ jsx(AlertDescription, { className: "font-medium", children: t("workflows.graph.editModeInfo") })
188
+ ] }) })
189
+ ]
190
+ }
191
+ ) });
192
+ }
193
+ export {
194
+ WorkflowGraphImpl as default
195
+ };
196
+ //# sourceMappingURL=WorkflowGraphImpl.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/workflows/components/WorkflowGraphImpl.tsx"],
4
+ "sourcesContent": ["'use client'\n\nimport '@xyflow/react/dist/style.css'\n\nimport { useCallback, useMemo, useEffect, useState } from 'react'\nimport {\n ReactFlow,\n Node,\n Edge,\n Controls,\n Background,\n BackgroundVariant,\n MiniMap,\n Panel,\n useNodesState,\n useEdgesState,\n addEdge,\n Connection,\n ConnectionMode,\n MarkerType,\n} from '@xyflow/react'\nimport {StartNode, EndNode, UserTaskNode, AutomatedNode, SubWorkflowNode, WaitForSignalNode, WaitForTimerNode} from './nodes'\nimport { WorkflowTransitionEdge } from './WorkflowTransitionEdge'\nimport { STATUS_COLORS } from '../lib/status-colors'\nimport { Alert, AlertDescription } from '@open-mercato/ui/primitives/alert'\nimport { Edit3 } from 'lucide-react'\nimport { useTheme } from '@open-mercato/ui/theme'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\n\nexport interface WorkflowGraphImplProps {\n initialNodes?: Node[]\n initialEdges?: Edge[]\n onNodesChange?: (changes: any[]) => void\n onEdgesChange?: (changes: any[]) => void\n onNodeClick?: (event: React.MouseEvent, node: Node) => void\n onEdgeClick?: (event: React.MouseEvent, edge: Edge) => void\n onConnect?: (connection: Connection) => void\n editable?: boolean\n className?: string\n height?: string\n}\n\nexport default function WorkflowGraphImpl({\n initialNodes = [],\n initialEdges = [],\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n onNodeClick: onNodeClickProp,\n onEdgeClick: onEdgeClickProp,\n onConnect: onConnectProp,\n editable = false,\n className = '',\n height = '600px',\n}: WorkflowGraphImplProps) {\n const t = useT()\n const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes)\n const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges)\n\n const { resolvedTheme } = useTheme()\n const isDark = resolvedTheme === 'dark'\n const backgroundDotColor = isDark ? '#374151' : '#e5e7eb'\n const [isCompactViewport, setIsCompactViewport] = useState(false)\n\n useEffect(() => {\n if (typeof window === 'undefined') return\n const mediaQuery = window.matchMedia('(max-width: 1279px)')\n const updateViewportMode = () => setIsCompactViewport(mediaQuery.matches)\n\n updateViewportMode()\n mediaQuery.addEventListener('change', updateViewportMode)\n\n return () => {\n mediaQuery.removeEventListener('change', updateViewportMode)\n }\n }, [])\n\n useEffect(() => {\n setNodes(initialNodes)\n }, [initialNodes, setNodes])\n\n useEffect(() => {\n setEdges(initialEdges)\n }, [initialEdges, setEdges])\n\n const onConnect = useCallback(\n (connection: Connection) => {\n if (onConnectProp) {\n onConnectProp(connection)\n } else {\n const newEdge = {\n ...connection,\n type: 'workflowTransition',\n animated: false,\n markerEnd: {\n type: MarkerType.ArrowClosed,\n width: 16,\n height: 16,\n color: '#9ca3af',\n },\n }\n setEdges((eds) => addEdge(newEdge, eds))\n }\n },\n [setEdges, onConnectProp]\n )\n\n const handleNodesChange = useCallback(\n (changes: any) => {\n onNodesChange(changes)\n if (onNodesChangeProp) {\n onNodesChangeProp(changes)\n }\n },\n [onNodesChange, onNodesChangeProp]\n )\n\n const handleEdgesChange = useCallback(\n (changes: any) => {\n onEdgesChange(changes)\n if (onEdgesChangeProp) {\n onEdgesChangeProp(changes)\n }\n },\n [onEdgesChange, onEdgesChangeProp]\n )\n\n const nodeTypes = useMemo(\n () => ({\n start: StartNode,\n end: EndNode,\n userTask: UserTaskNode,\n automated: AutomatedNode,\n subWorkflow: SubWorkflowNode,\n waitForSignal: WaitForSignalNode,\n waitForTimer: WaitForTimerNode,\n }),\n []\n )\n\n const edgeTypes = useMemo(\n () => ({\n workflowTransition: WorkflowTransitionEdge,\n }),\n []\n )\n\n return (\n <div className={`workflow-graph-container ${className}`} style={{ height }}>\n <ReactFlow\n nodes={nodes}\n edges={edges}\n nodeTypes={nodeTypes}\n edgeTypes={edgeTypes}\n onNodesChange={handleNodesChange}\n onEdgesChange={handleEdgesChange}\n onConnect={editable ? onConnect : undefined}\n onNodeClick={onNodeClickProp}\n onEdgeClick={onEdgeClickProp}\n connectionMode={ConnectionMode.Loose}\n fitView\n fitViewOptions={{\n padding: 0.2,\n maxZoom: isCompactViewport ? 0.9 : 1,\n }}\n minZoom={0.1}\n maxZoom={2}\n defaultEdgeOptions={{\n type: 'workflowTransition',\n animated: false,\n markerEnd: {\n type: MarkerType.ArrowClosed,\n width: 16,\n height: 16,\n color: '#9ca3af',\n },\n }}\n nodesDraggable={editable}\n nodesConnectable={editable}\n elementsSelectable={editable}\n proOptions={{ hideAttribution: true }}\n >\n <Background\n variant={BackgroundVariant.Dots}\n gap={16}\n size={1}\n color={backgroundDotColor}\n />\n\n <Controls\n showZoom={true}\n showFitView={true}\n showInteractive={false}\n position={isCompactViewport ? 'bottom-right' : 'top-right'}\n className={`!bg-card !border-border !shadow-md [&>button]:!bg-card [&>button]:!border-border [&>button]:!fill-foreground [&>button:hover]:!bg-muted ${isCompactViewport ? 'scale-90 origin-bottom-right' : ''}`}\n />\n\n {!isCompactViewport && (\n <MiniMap\n nodeStrokeWidth={3}\n nodeColor={(node) => {\n const status = (node.data?.status || 'not_started') as keyof typeof STATUS_COLORS\n return STATUS_COLORS[status]?.hex || STATUS_COLORS.not_started.hex\n }}\n maskColor=\"rgba(0, 0, 0, 0.1)\"\n position=\"bottom-left\"\n className=\"!bg-card !border !border-border !rounded-lg\"\n />\n )}\n\n {!editable && !isCompactViewport && (\n <Panel position=\"top-left\" style={{ margin: 10 }}>\n <div className=\"bg-card rounded-lg shadow-sm border border-border px-4 py-2\">\n <p className=\"text-sm text-muted-foreground font-medium\">\n {t('workflows.graph.visualization')}\n </p>\n </div>\n </Panel>\n )}\n\n {editable && !isCompactViewport && (\n <Panel position=\"top-left\" style={{ margin: 10 }}>\n <Alert variant=\"info\" className=\"max-w-sm\">\n <Edit3 className=\"size-4\" />\n <AlertDescription className=\"font-medium\">\n {t('workflows.graph.editModeInfo')}\n </AlertDescription>\n </Alert>\n </Panel>\n )}\n </ReactFlow>\n </div>\n )\n}\n"],
5
+ "mappings": ";AAqLQ,cAwCI,YAxCJ;AAnLR,OAAO;AAEP,SAAS,aAAa,SAAS,WAAW,gBAAgB;AAC1D;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAQ,WAAW,SAAS,cAAc,eAAe,iBAAiB,mBAAmB,wBAAuB;AACpH,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAC9B,SAAS,OAAO,wBAAwB;AACxC,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,YAAY;AAeN,SAAR,kBAAmC;AAAA,EACxC,eAAe,CAAC;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,eAAe;AAAA,EACf,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,WAAW;AAAA,EACX,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,SAAS;AACX,GAA2B;AACzB,QAAM,IA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YAC3B,KAAK;AAAA,YACL,MAAM;AAAA,YACN,OAAO;AAAA;AAAA,QACT;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACC,UAAU;AAAA,YACV,aAAa;AAAA,YACb,iBAAiB;AAAA,YACjB,UAAU,oBAAoB,iBAAiB;AAAA,YAC/C,WAAW,2IAA2I,oBAAoB,iCAAiC,EAAE;AAAA;AAAA,QAC/M;AAAA,QAEC,CAAC,qBACA;AAAA,UAAC;AAAA;AAAA,YACC,iBAAiB;AAAA,YACjB,WAAW,CAAC,SAAS;AACnB,oBAAM,SAAU,KAAK,MAAM,UAAU;AACrC,qBAAO,cAAc,MAAM,GAAG,OAAO,cAAc,YAAY;AAAA,YACjE;AAAA,YACA,WAAU;AAAA,YACV,UAAS;AAAA,YACT,WAAU;AAAA;AAAA,QACZ;AAAA,QAGD,CAAC,YAAY,CAAC,qBACb,oBAAC,SAAM,UAAS,YAAW,OAAO,EAAE,QAAQ,GAAG,GAC7C,8BAAC,SAAI,WAAU,+DACb,8BAAC,OAAE,WAAU,6CACV,YAAE,+BAA+B,GACpC,GACF,GACF;AAAA,QAGD,YAAY,CAAC,qBACZ,oBAAC,SAAM,UAAS,YAAW,OAAO,EAAE,QAAQ,GAAG,GAC7C,+BAAC,SAAM,SAAQ,QAAO,WAAU,YAC9B;AAAA,8BAAC,SAAM,WAAU,UAAS;AAAA,UAC1B,oBAAC,oBAAiB,WAAU,eACzB,YAAE,8BAA8B,GACnC;AAAA,WACF,GACF;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/core",
3
- "version": "0.6.4-develop.3944.1.4100aa7fbe",
3
+ "version": "0.6.4-develop.3962.1.70f30e284c",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -243,16 +243,16 @@
243
243
  "zod": "^4.4.3"
244
244
  },
245
245
  "peerDependencies": {
246
- "@open-mercato/ai-assistant": "0.6.4-develop.3944.1.4100aa7fbe",
247
- "@open-mercato/shared": "0.6.4-develop.3944.1.4100aa7fbe",
248
- "@open-mercato/ui": "0.6.4-develop.3944.1.4100aa7fbe",
246
+ "@open-mercato/ai-assistant": "0.6.4-develop.3962.1.70f30e284c",
247
+ "@open-mercato/shared": "0.6.4-develop.3962.1.70f30e284c",
248
+ "@open-mercato/ui": "0.6.4-develop.3962.1.70f30e284c",
249
249
  "react": "^19.0.0",
250
250
  "react-dom": "^19.0.0"
251
251
  },
252
252
  "devDependencies": {
253
- "@open-mercato/ai-assistant": "0.6.4-develop.3944.1.4100aa7fbe",
254
- "@open-mercato/shared": "0.6.4-develop.3944.1.4100aa7fbe",
255
- "@open-mercato/ui": "0.6.4-develop.3944.1.4100aa7fbe",
253
+ "@open-mercato/ai-assistant": "0.6.4-develop.3962.1.70f30e284c",
254
+ "@open-mercato/shared": "0.6.4-develop.3962.1.70f30e284c",
255
+ "@open-mercato/ui": "0.6.4-develop.3962.1.70f30e284c",
256
256
  "@testing-library/dom": "^10.4.1",
257
257
  "@testing-library/jest-dom": "^6.9.1",
258
258
  "@testing-library/react": "^16.3.1",
@@ -0,0 +1,9 @@
1
+ // Ambient module declarations for the @open-mercato/core TypeScript context.
2
+ //
3
+ // Next.js apps get these declarations via `next-env.d.ts`, but workspace
4
+ // packages need them locally because they may import CSS side-effects from
5
+ // .tsx files (e.g. `import 'pkg/dist/style.css'` inside a lazy-loaded
6
+ // client component).
7
+
8
+ declare module '*.css'
9
+ declare module '*.scss'
@@ -103,7 +103,12 @@ async function loadVariantSnapshot(
103
103
  ): Promise<VariantSnapshot | null> {
104
104
  const record = await em.findOne(CatalogProductVariant, { id, deletedAt: null })
105
105
  if (!record) return null
106
- const prices = options.includePrices ? await loadVariantPriceSnapshots(em, record.id) : null
106
+ const prices = options.includePrices
107
+ ? await loadVariantPriceSnapshots(em, record.id, {
108
+ tenantId: record.tenantId,
109
+ organizationId: record.organizationId,
110
+ })
111
+ : null
107
112
  const custom = await loadCustomFieldSnapshot(em, {
108
113
  entityId: E.catalog.catalog_product_variant,
109
114
  recordId: record.id,
@@ -223,14 +228,15 @@ type VariantPriceSnapshot = {
223
228
 
224
229
  async function loadVariantPriceSnapshots(
225
230
  em: EntityManager,
226
- variantId: string
231
+ variantId: string,
232
+ scope: { tenantId: string; organizationId: string }
227
233
  ): Promise<VariantPriceSnapshot[]> {
228
234
  const prices = await findWithDecryption(
229
235
  em,
230
236
  CatalogProductPrice,
231
- { variant: variantId },
237
+ { variant: variantId, tenantId: scope.tenantId, organizationId: scope.organizationId },
232
238
  { populate: ['priceKind', 'product', 'offer'] },
233
- { tenantId: null, organizationId: null },
239
+ { tenantId: scope.tenantId, organizationId: scope.organizationId },
234
240
  )
235
241
  const snapshots: VariantPriceSnapshot[] = []
236
242
  for (const price of prices) {
@@ -904,7 +910,10 @@ const deleteVariantCommand: CommandHandler<
904
910
  const priceSnapshots =
905
911
  snapshot?.prices && snapshot.prices.length
906
912
  ? snapshot.prices
907
- : await loadVariantPriceSnapshots(baseEm, id)
913
+ : await loadVariantPriceSnapshots(baseEm, id, {
914
+ tenantId: record.tenantId,
915
+ organizationId: record.organizationId,
916
+ })
908
917
 
909
918
  if (priceSnapshots.length) {
910
919
  await em.nativeDelete(CatalogProductPrice, { id: { $in: priceSnapshots.map((price) => price.id) } })