@flowuent-org/diagramming-core 1.0.5 → 1.0.6

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,205 +1,205 @@
1
- import React, { useEffect } from 'react';
2
- import { Button, Card, IconButton, Tab, Tabs } from '@mui/material';
3
- import CloseIcon from '@mui/icons-material/Close';
4
- import {
5
- DiagrammingPage,
6
- DownloadPanel,
7
- NodeForm,
8
- PropertiesPane,
9
- useDiagramEdges,
10
- useDiagramId,
11
- useDiagramNodes,
12
- FunctionSignature,
13
- FunctionParameter,
14
- } from '@flowuent-labs/diagrams';
15
- import { useTabStore } from './tabsStore'; // Import the Zustand store
16
- import { AddNodeView } from './components/AddNodeView';
17
- import { conditionBuilderData } from './node-data';
18
- import DiagramTypes from '../../../packages/diagrams/src/lib/types/diagram-types';
19
- import { AppBar, Toolbar, Box } from '@mui/material';
20
- import HomeIcon from '@mui/icons-material/Home';
21
- import AccountCircleIcon from '@mui/icons-material/AccountCircle';
22
- import { ICardNode } from '../../../packages/diagrams/src/lib/types/card-node';
23
- import { Edge, Node } from '@xyflow/react';
24
- import { Node as ReactFlowNode } from 'reactflow';
25
- import { ICardNodeData } from '../../../packages/diagrams/src/lib/types/card-node';
26
- import {
27
- WorkflowNodeContentType,
28
- RenderAddNodeViewType,
29
- GetDefaultNodeDataType,
30
- OnChangeEventHandler,
31
- ConditionBuilderState,
32
- } from '../../../packages/diagrams/src/lib/contexts/diagramStoreTypes';
33
- import { AvailableVariable } from '../../../packages/diagrams/src/lib/types/available-variables';
34
-
35
- // Define the interface for diagram page props
36
- interface DiagramPageProps {
37
- onChange?: OnChangeEventHandler;
38
- availableFunctions: FunctionSignature[];
39
- availableVariables?: AvailableVariable[];
40
- id: number;
41
- workflowNodeContent?: WorkflowNodeContentType;
42
- renderAddNodeView?: RenderAddNodeViewType;
43
- getDefaultNodeData?: GetDefaultNodeDataType;
44
- conditionBuilderStates?: ConditionBuilderState;
45
- }
46
-
47
- // Generic type for nodes that can be either ICardNode, Node from @xyflow/react, or Node from reactflow
48
- type GenericNode = ICardNode | Node | ReactFlowNode;
49
-
50
- const NodeGetter = () => {
51
- const updateTabData = useTabStore.use.updateTabData();
52
- const nodes = useDiagramNodes();
53
- const edges = useDiagramEdges();
54
- const id = useDiagramId();
55
- useEffect(() => {
56
- //updateTabData(id, nodes, edges);
57
- }, [nodes, edges, id, updateTabData]);
58
-
59
- return <div></div>;
60
- };
61
-
62
- // Transform FunctionObject[] to FunctionSignature[]
63
- const transformFunctions = (functionObjects: Array<{
64
- id: string;
65
- name: string;
66
- args: string[];
67
- code: string;
68
- }>): FunctionSignature[] => {
69
- return functionObjects.map(func => ({
70
- id: func.id,
71
- name: func.name,
72
- code: func.code,
73
- args: func.args.map((arg: string): FunctionParameter => ({
74
- name: arg,
75
- type: 'any'
76
- }))
77
- }));
78
- };
79
-
80
- const DiagramTabs = ({
81
- defaultNodes,
82
- defaultEdges,
83
- children,
84
- diagramType,
85
- diagramPageProps = {},
86
- }: {
87
- defaultNodes: GenericNode[];
88
- defaultEdges: Edge[];
89
- children?: React.ReactNode;
90
- diagramType: DiagramTypes;
91
- diagramPageProps?: Partial<DiagramPageProps>;
92
- }) => {
93
- const {
94
- tabs,
95
- currentTab,
96
- addTab,
97
- removeTab,
98
- availableFunctions,
99
- setCurrentTab,
100
- setTabs,
101
- } = useTabStore();
102
-
103
- // Ensure the first tab is initialized with default nodes/edges
104
- useEffect(() => {
105
- if (
106
- tabs.length === 1 &&
107
- tabs[0].nodes.length === 0 &&
108
- tabs[0].edges.length === 0 &&
109
- (defaultNodes.length > 0 || defaultEdges.length > 0)
110
- ) {
111
- setTabs([
112
- {
113
- ...tabs[0],
114
- nodes: defaultNodes,
115
- edges: defaultEdges,
116
- },
117
- ]);
118
- }
119
- }, [tabs, defaultNodes, defaultEdges, setTabs]);
120
-
121
- // Reset tabs when diagramType changes
122
- useEffect(() => {
123
- setTabs([
124
- {
125
- id: Date.now(),
126
- title: diagramType.charAt(0).toUpperCase() + diagramType.slice(1) + ' Diagram',
127
- nodes: defaultNodes,
128
- edges: defaultEdges,
129
- },
130
- ]);
131
- setCurrentTab(0);
132
- }, [diagramType, defaultNodes, defaultEdges, setTabs, setCurrentTab]);
133
-
134
- return (
135
- <div>
136
- {/* Tab Navigation - now using AppBar */}
137
- <AppBar position="fixed" sx={{ bgcolor: '#1C1616', boxShadow: 2, borderBottom: '1px solid #23232a', top: 0, width: '100%', zIndex: 1000 }}>
138
- <Toolbar sx={{ minHeight: 56, px: 2, display: 'flex', justifyContent: 'space-between' }}>
139
- <Box sx={{ display: 'flex', alignItems: 'center' }}>
140
- <IconButton edge="start" color="inherit" aria-label="home" sx={{ mr: 2 }}>
141
- <HomeIcon sx={{ color: '#fff' }} />
142
- </IconButton>
143
- <Tabs
144
- value={currentTab}
145
- onChange={(_, newValue) => setCurrentTab(newValue)}
146
- textColor="inherit"
147
- indicatorColor="secondary"
148
- sx={{ minHeight: 40, '& .MuiTab-root': { color: '#fff', minWidth: 120, borderRadius: 2, mx: 1, bgcolor: '#23232a', fontWeight: 500 }, '& .Mui-selected': { bgcolor: '#111', color: '#fff' }, }}
149
- >
150
- {tabs.map((tab, index) => (
151
- <Tab
152
- key={tab.id}
153
- label={
154
- <div style={{ display: 'flex', alignItems: 'center' }}>
155
- <span>{tab.title}</span>
156
- <IconButton
157
- size="small"
158
- onClick={(e) => {
159
- e.stopPropagation();
160
- removeTab(index);
161
- }}
162
- style={{ marginLeft: '8px', padding: '2px' }}
163
- >
164
- <CloseIcon fontSize="small" />
165
- </IconButton>
166
- </div>
167
- }
168
- sx={{ textTransform: 'none', fontSize: 16 }}
169
- />
170
- ))}
171
- </Tabs>
172
- <Button onClick={() => addTab(defaultNodes, defaultEdges)} sx={{ ml: 2, bgcolor: '#6B04F1', color: '#fff', borderRadius: 2, px: 2, fontWeight: 600, textTransform: 'none', boxShadow: 'none', '&:hover': { bgcolor: '#a084ff' } }}>
173
- Add Tab
174
- </Button>
175
- </Box>
176
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
177
- <Button variant="contained" sx={{ bgcolor: '#6B04F1', color: '#fff', borderRadius: 2, px: 3, fontWeight: 600, textTransform: 'none', boxShadow: 'none', '&:hover': { bgcolor: '#a084ff' } }}>Share</Button>
178
- <IconButton color="inherit">
179
- <AccountCircleIcon sx={{ color: '#fff' }} />
180
- </IconButton>
181
- </Box>
182
- </Toolbar>
183
- </AppBar>
184
-
185
- {/* Render Active Diagram */}
186
- {tabs.map((tab, index) =>
187
- index === currentTab ? (
188
- <DiagrammingPage
189
- availableFunctions={transformFunctions(availableFunctions)}
190
- id={tab.id}
191
- key={tab.id}
192
- defaultNodes={tab.nodes as ICardNode[]}
193
- defaultEdges={tab.edges}
194
- diagramType={diagramType}
195
- {...diagramPageProps}
196
- >
197
- {children}
198
- </DiagrammingPage>
199
- ) : null,
200
- )}
201
- </div>
202
- );
203
- };
204
-
205
- export default DiagramTabs;
1
+ import React, { useEffect } from 'react';
2
+ import { Button, Card, IconButton, Tab, Tabs } from '@mui/material';
3
+ import CloseIcon from '@mui/icons-material/Close';
4
+ import {
5
+ DiagrammingPage,
6
+ DownloadPanel,
7
+ NodeForm,
8
+ PropertiesPane,
9
+ useDiagramEdges,
10
+ useDiagramId,
11
+ useDiagramNodes,
12
+ FunctionSignature,
13
+ FunctionParameter,
14
+ } from '@flowuent-labs/diagrams';
15
+ import { useTabStore } from './tabsStore'; // Import the Zustand store
16
+ import { AddNodeView } from './components/AddNodeView';
17
+ import { conditionBuilderData } from './node-data';
18
+ import DiagramTypes from '../../../packages/diagrams/src/lib/types/diagram-types';
19
+ import { AppBar, Toolbar, Box } from '@mui/material';
20
+ import HomeIcon from '@mui/icons-material/Home';
21
+ import AccountCircleIcon from '@mui/icons-material/AccountCircle';
22
+ import { ICardNode } from '../../../packages/diagrams/src/lib/types/card-node';
23
+ import { Edge, Node } from '@xyflow/react';
24
+ import { Node as ReactFlowNode } from 'reactflow';
25
+ import { ICardNodeData } from '../../../packages/diagrams/src/lib/types/card-node';
26
+ import {
27
+ WorkflowNodeContentType,
28
+ RenderAddNodeViewType,
29
+ GetDefaultNodeDataType,
30
+ OnChangeEventHandler,
31
+ ConditionBuilderState,
32
+ } from '../../../packages/diagrams/src/lib/contexts/diagramStoreTypes';
33
+ import { AvailableVariable } from '../../../packages/diagrams/src/lib/types/available-variables';
34
+
35
+ // Define the interface for diagram page props
36
+ interface DiagramPageProps {
37
+ onChange?: OnChangeEventHandler;
38
+ availableFunctions: FunctionSignature[];
39
+ availableVariables?: AvailableVariable[];
40
+ id: number;
41
+ workflowNodeContent?: WorkflowNodeContentType;
42
+ renderAddNodeView?: RenderAddNodeViewType;
43
+ getDefaultNodeData?: GetDefaultNodeDataType;
44
+ conditionBuilderStates?: ConditionBuilderState;
45
+ }
46
+
47
+ // Generic type for nodes that can be either ICardNode, Node from @xyflow/react, or Node from reactflow
48
+ type GenericNode = ICardNode | Node | ReactFlowNode;
49
+
50
+ const NodeGetter = () => {
51
+ const updateTabData = useTabStore.use.updateTabData();
52
+ const nodes = useDiagramNodes();
53
+ const edges = useDiagramEdges();
54
+ const id = useDiagramId();
55
+ useEffect(() => {
56
+ //updateTabData(id, nodes, edges);
57
+ }, [nodes, edges, id, updateTabData]);
58
+
59
+ return <div></div>;
60
+ };
61
+
62
+ // Transform FunctionObject[] to FunctionSignature[]
63
+ const transformFunctions = (functionObjects: Array<{
64
+ id: string;
65
+ name: string;
66
+ args: string[];
67
+ code: string;
68
+ }>): FunctionSignature[] => {
69
+ return functionObjects.map(func => ({
70
+ id: func.id,
71
+ name: func.name,
72
+ code: func.code,
73
+ args: func.args.map((arg: string): FunctionParameter => ({
74
+ name: arg,
75
+ type: 'any'
76
+ }))
77
+ }));
78
+ };
79
+
80
+ const DiagramTabs = ({
81
+ defaultNodes,
82
+ defaultEdges,
83
+ children,
84
+ diagramType,
85
+ diagramPageProps = {},
86
+ }: {
87
+ defaultNodes: GenericNode[];
88
+ defaultEdges: Edge[];
89
+ children?: React.ReactNode;
90
+ diagramType: DiagramTypes;
91
+ diagramPageProps?: Partial<DiagramPageProps>;
92
+ }) => {
93
+ const {
94
+ tabs,
95
+ currentTab,
96
+ addTab,
97
+ removeTab,
98
+ availableFunctions,
99
+ setCurrentTab,
100
+ setTabs,
101
+ } = useTabStore();
102
+
103
+ // Ensure the first tab is initialized with default nodes/edges
104
+ useEffect(() => {
105
+ if (
106
+ tabs.length === 1 &&
107
+ tabs[0].nodes.length === 0 &&
108
+ tabs[0].edges.length === 0 &&
109
+ (defaultNodes.length > 0 || defaultEdges.length > 0)
110
+ ) {
111
+ setTabs([
112
+ {
113
+ ...tabs[0],
114
+ nodes: defaultNodes,
115
+ edges: defaultEdges,
116
+ },
117
+ ]);
118
+ }
119
+ }, [tabs, defaultNodes, defaultEdges, setTabs]);
120
+
121
+ // Reset tabs when diagramType changes
122
+ useEffect(() => {
123
+ setTabs([
124
+ {
125
+ id: Date.now(),
126
+ title: diagramType.charAt(0).toUpperCase() + diagramType.slice(1) + ' Diagram',
127
+ nodes: defaultNodes,
128
+ edges: defaultEdges,
129
+ },
130
+ ]);
131
+ setCurrentTab(0);
132
+ }, [diagramType, defaultNodes, defaultEdges, setTabs, setCurrentTab]);
133
+
134
+ return (
135
+ <div>
136
+ {/* Tab Navigation - now using AppBar */}
137
+ <AppBar position="fixed" sx={{ bgcolor: '#1C1616', boxShadow: 2, borderBottom: '1px solid #23232a', top: 0, width: '100%', zIndex: 1000 }}>
138
+ <Toolbar sx={{ minHeight: 56, px: 2, display: 'flex', justifyContent: 'space-between' }}>
139
+ <Box sx={{ display: 'flex', alignItems: 'center' }}>
140
+ <IconButton edge="start" color="inherit" aria-label="home" sx={{ mr: 2 }}>
141
+ <HomeIcon sx={{ color: '#fff' }} />
142
+ </IconButton>
143
+ <Tabs
144
+ value={currentTab}
145
+ onChange={(_, newValue) => setCurrentTab(newValue)}
146
+ textColor="inherit"
147
+ indicatorColor="secondary"
148
+ sx={{ minHeight: 40, '& .MuiTab-root': { color: '#fff', minWidth: 120, borderRadius: 2, mx: 1, bgcolor: '#23232a', fontWeight: 500 }, '& .Mui-selected': { bgcolor: '#111', color: '#fff' }, }}
149
+ >
150
+ {tabs.map((tab, index) => (
151
+ <Tab
152
+ key={tab.id}
153
+ label={
154
+ <div style={{ display: 'flex', alignItems: 'center' }}>
155
+ <span>{tab.title}</span>
156
+ <IconButton
157
+ size="small"
158
+ onClick={(e) => {
159
+ e.stopPropagation();
160
+ removeTab(index);
161
+ }}
162
+ style={{ marginLeft: '8px', padding: '2px' }}
163
+ >
164
+ <CloseIcon fontSize="small" />
165
+ </IconButton>
166
+ </div>
167
+ }
168
+ sx={{ textTransform: 'none', fontSize: 16 }}
169
+ />
170
+ ))}
171
+ </Tabs>
172
+ <Button onClick={() => addTab(defaultNodes, defaultEdges)} sx={{ ml: 2, bgcolor: '#6B04F1', color: '#fff', borderRadius: 2, px: 2, fontWeight: 600, textTransform: 'none', boxShadow: 'none', '&:hover': { bgcolor: '#a084ff' } }}>
173
+ Add Tab
174
+ </Button>
175
+ </Box>
176
+ <Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
177
+ <Button variant="contained" sx={{ bgcolor: '#6B04F1', color: '#fff', borderRadius: 2, px: 3, fontWeight: 600, textTransform: 'none', boxShadow: 'none', '&:hover': { bgcolor: '#a084ff' } }}>Share</Button>
178
+ <IconButton color="inherit">
179
+ <AccountCircleIcon sx={{ color: '#fff' }} />
180
+ </IconButton>
181
+ </Box>
182
+ </Toolbar>
183
+ </AppBar>
184
+
185
+ {/* Render Active Diagram */}
186
+ {tabs.map((tab, index) =>
187
+ index === currentTab ? (
188
+ <DiagrammingPage
189
+ availableFunctions={transformFunctions(availableFunctions)}
190
+ id={tab.id}
191
+ key={tab.id}
192
+ defaultNodes={tab.nodes as ICardNode[]}
193
+ defaultEdges={tab.edges}
194
+ diagramType={diagramType}
195
+ {...diagramPageProps}
196
+ >
197
+ {children}
198
+ </DiagrammingPage>
199
+ ) : null,
200
+ )}
201
+ </div>
202
+ );
203
+ };
204
+
205
+ export default DiagramTabs;
@@ -1,54 +1,55 @@
1
- // Define the structure of the form data
2
- import { FormElementBase } from '@flowuent-labs/diagrams';
3
-
4
- export const sampleWorkflowContent: FormElementBase = {
5
- type: 'Form',
6
- props: {
7
- title: 'User Registration', // Title for the form
8
- children: [
9
- /*{
10
- type: "TextField",
11
- props: {
12
- name: "fullName",
13
- label: "Full Name",
14
- },
15
- },
16
- {
17
- type: "TextField",
18
- props: {
19
- name: "email",
20
- label: "Email Address",
21
- type: "email",
22
- },
23
- },
24
- {
25
- type: "TextField",
26
- props: {
27
- name: "age",
28
- label: "Age",
29
- type: "number",
30
- },
31
- },
32
- {
33
- type: "Switch",
34
- props: {
35
- name: "notifications",
36
- label: "Enable Notifications",
37
- },
38
- },
39
- {
40
- type: "Select",
41
- props: {
42
- name: "country",
43
- label: "Country",
44
- options: [
45
- { value: "us", label: "United States" },
46
- { value: "ca", label: "Canada" },
47
- { value: "uk", label: "United Kingdom" },
48
- { value: "au", label: "Australia" },
49
- ],
50
- },
51
- },*/
52
- ],
53
- },
54
- };
1
+ // Define the structure of the form data
2
+ import { FormElementBase } from '@flowuent-labs/diagrams';
3
+
4
+ export const sampleWorkflowContent: FormElementBase = {
5
+ type: "Form",
6
+ props: {
7
+ title: "User Registration", // Title for the form
8
+ children: [
9
+ /*{
10
+ type: "TextField",
11
+ props: {
12
+ name: "fullName",
13
+ label: "Full Name",
14
+ },
15
+ },
16
+ {
17
+ type: "TextField",
18
+ props: {
19
+ name: "email",
20
+ label: "Email Address",
21
+ type: "email",
22
+ },
23
+ },
24
+ {
25
+ type: "TextField",
26
+ props: {
27
+ name: "age",
28
+ label: "Age",
29
+ type: "number",
30
+ },
31
+ },
32
+ {
33
+ type: "Switch",
34
+ props: {
35
+ name: "notifications",
36
+ label: "Enable Notifications",
37
+ },
38
+ },
39
+ {
40
+ type: "Select",
41
+ props: {
42
+ name: "country",
43
+ label: "Country",
44
+ options: [
45
+ { value: "us", label: "United States" },
46
+ { value: "ca", label: "Canada" },
47
+ { value: "uk", label: "United Kingdom" },
48
+ { value: "au", label: "Australia" },
49
+ ],
50
+ },
51
+ },*/
52
+ ],
53
+ },
54
+ };
55
+