sample-ui-component-library 0.0.45-dev → 0.0.47-dev
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/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -2
- package/rollup.config.mjs +8 -2
- package/src/components/BehavioralGraphBuilder/BehavioralGraphBuilder.jsx +46 -38
- package/src/components/BehavioralGraphBuilder/BehavioralGraphBuilder.scss +1 -1
- package/src/components/BehavioralGraphBuilder/helper.js +2 -3
- package/src/stories/BehavioralGraphBuilder.stories.js +3 -3
- package/src/stories/components/ToolBar/ToolBar.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sample-ui-component-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47-dev",
|
|
4
4
|
"description": "A library which contains sample UI elements that can be used for populating layouts.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -46,11 +46,13 @@
|
|
|
46
46
|
"@storybook/test": "^8.6.11",
|
|
47
47
|
"@storybook/theming": "^8.6.11",
|
|
48
48
|
"css-loader": "^7.1.2",
|
|
49
|
+
"dal-engine-core-js-lib-dev": "^0.0.4",
|
|
49
50
|
"gh-pages": "^6.3.0",
|
|
50
51
|
"prop-types": "^15.8.1",
|
|
51
52
|
"raw-loader": "^4.0.2",
|
|
52
53
|
"react": "^18.2.0",
|
|
53
54
|
"react-dom": "^18.2.0",
|
|
55
|
+
"reaflow": "^5.4.1",
|
|
54
56
|
"rollup": "^4.37.0",
|
|
55
57
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
56
58
|
"rollup-plugin-postcss": "^4.0.2",
|
|
@@ -69,7 +71,6 @@
|
|
|
69
71
|
"@dagrejs/dagre": "^1.1.4",
|
|
70
72
|
"@monaco-editor/react": "^4.7.0",
|
|
71
73
|
"@xyflow/react": "^12.6.0",
|
|
72
|
-
"dal-engine-core-js-lib-dev": "^0.0.4",
|
|
73
74
|
"react-bootstrap-icons": "^1.11.5"
|
|
74
75
|
}
|
|
75
76
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import resolve from '@rollup/plugin-node-resolve';
|
|
2
2
|
import commonjs from '@rollup/plugin-commonjs';
|
|
3
3
|
import terser from '@rollup/plugin-terser';
|
|
4
|
-
import
|
|
4
|
+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
|
5
5
|
import postcss from 'rollup-plugin-postcss';
|
|
6
6
|
import json from '@rollup/plugin-json';
|
|
7
7
|
import { babel } from '@rollup/plugin-babel';
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
10
|
input: 'src/index.js',
|
|
11
|
+
external: [
|
|
12
|
+
'react',
|
|
13
|
+
'react-dom',
|
|
14
|
+
'@dnd-kit/core',
|
|
15
|
+
"reaflow"
|
|
16
|
+
],
|
|
11
17
|
output: [
|
|
12
18
|
{
|
|
13
19
|
file: 'dist/cjs/index.js',
|
|
@@ -21,7 +27,7 @@ export default {
|
|
|
21
27
|
},
|
|
22
28
|
],
|
|
23
29
|
plugins: [
|
|
24
|
-
|
|
30
|
+
peerDepsExternal(),
|
|
25
31
|
resolve({
|
|
26
32
|
extensions: ['.js', '.jsx'],
|
|
27
33
|
}),
|
|
@@ -28,15 +28,12 @@ export const BehavioralGraphBuilder = forwardRef(({connectBehaviors, deleteTrans
|
|
|
28
28
|
return () => observer.disconnect();
|
|
29
29
|
}, []);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// States
|
|
32
32
|
const [edges, setEdges] = useState([]);
|
|
33
33
|
const [nodes, setNodes] = useState([]);
|
|
34
34
|
const [selections, setSelections] = useState([]);
|
|
35
|
-
'1'
|
|
36
|
-
const onNodeLink =(_event, from, to) => {
|
|
37
|
-
connectBehaviors(from, to);
|
|
38
|
-
}
|
|
39
35
|
|
|
36
|
+
// API Methods and Imperative Handle
|
|
40
37
|
const updateEngine = useCallback((engine) => {
|
|
41
38
|
if (engine) {
|
|
42
39
|
const { nodes, edges } = designToNodes(engine);
|
|
@@ -53,50 +50,59 @@ export const BehavioralGraphBuilder = forwardRef(({connectBehaviors, deleteTrans
|
|
|
53
50
|
|
|
54
51
|
useImperativeHandle(ref, () => api, [api]);
|
|
55
52
|
|
|
53
|
+
|
|
54
|
+
// Callbacks
|
|
56
55
|
const handleWheel = useCallback((e) => {
|
|
57
|
-
if (
|
|
58
|
-
canvasRef.current.zoomIn()
|
|
59
|
-
} else {
|
|
60
|
-
canvasRef.current.zoomOut();
|
|
56
|
+
if (canvasRef.current) {
|
|
57
|
+
(e.deltaY < 0)?canvasRef.current.zoomIn():canvasRef.current.zoomOut();
|
|
61
58
|
}
|
|
62
59
|
}, [canvasRef]);
|
|
63
60
|
|
|
61
|
+
const nodeClick = useCallback((e, node) => {
|
|
62
|
+
setSelections([node.id]);
|
|
63
|
+
selectBehavior(node.id);
|
|
64
|
+
}, [selectBehavior]);
|
|
65
|
+
|
|
66
|
+
const nodeRemove = useCallback((e, node) => {
|
|
67
|
+
deleteBehavior(node);
|
|
68
|
+
setSelections([]);
|
|
69
|
+
}, [deleteBehavior]);
|
|
70
|
+
|
|
71
|
+
const edgeClick = useCallback((e, edge) => {
|
|
72
|
+
setSelections([edge.id]);
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
const edgeRemove = useCallback((e, edge) => {
|
|
76
|
+
deleteTransition(edge);
|
|
77
|
+
setSelections([]);
|
|
78
|
+
}, [deleteTransition]);
|
|
79
|
+
|
|
80
|
+
const canvasClick = useCallback((e) => {
|
|
81
|
+
selectBehavior(null);
|
|
82
|
+
setSelections([]);
|
|
83
|
+
}, [selectBehavior]);
|
|
84
|
+
|
|
85
|
+
const nodeLink = useCallback((e, from, to) => {
|
|
86
|
+
if (!to) return;
|
|
87
|
+
connectBehaviors(from, to);
|
|
88
|
+
}, [connectBehaviors]);
|
|
89
|
+
|
|
64
90
|
return (
|
|
65
91
|
<div onWheel={handleWheel} ref={containerRef} className="canvas-wrapper">
|
|
66
92
|
<Canvas
|
|
93
|
+
panType="drag"
|
|
94
|
+
fit
|
|
95
|
+
center
|
|
67
96
|
ref={canvasRef}
|
|
68
97
|
nodes={nodes}
|
|
69
98
|
edges={edges}
|
|
70
99
|
width={size.width}
|
|
71
100
|
height={size.height}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
setSelections([node.id]);
|
|
78
|
-
selectBehavior(node.id);
|
|
79
|
-
}}
|
|
80
|
-
onRemove={(event, node) => {
|
|
81
|
-
deleteBehavior(node);
|
|
82
|
-
setSelections([]);
|
|
83
|
-
}}
|
|
84
|
-
/>
|
|
85
|
-
}
|
|
86
|
-
edge={
|
|
87
|
-
<Edge
|
|
88
|
-
onClick={(event, edge) => {
|
|
89
|
-
setSelections([edge.id]);
|
|
90
|
-
}}
|
|
91
|
-
onRemove={(event, edge) => {
|
|
92
|
-
deleteTransition(edge);
|
|
93
|
-
setSelections([]);
|
|
94
|
-
}}
|
|
95
|
-
/>
|
|
96
|
-
}
|
|
97
|
-
onCanvasClick={(event) => {setSelections([]);}}
|
|
98
|
-
fit
|
|
99
|
-
center
|
|
101
|
+
selections={selections}
|
|
102
|
+
onNodeLink={nodeLink}
|
|
103
|
+
node={ <Node onClick={nodeClick} onRemove={nodeRemove} /> }
|
|
104
|
+
edge={ <Edge onClick={edgeClick} onRemove={edgeRemove}/> }
|
|
105
|
+
onCanvasClick={canvasClick}
|
|
100
106
|
/>
|
|
101
107
|
</div>
|
|
102
108
|
)
|
|
@@ -104,5 +110,7 @@ export const BehavioralGraphBuilder = forwardRef(({connectBehaviors, deleteTrans
|
|
|
104
110
|
|
|
105
111
|
BehavioralGraphBuilder.propTypes = {
|
|
106
112
|
connectBehaviors: PropTypes.func.isRequired,
|
|
107
|
-
|
|
113
|
+
deleteTransition: PropTypes.func.isRequired,
|
|
114
|
+
deleteBehavior: PropTypes.func.isRequired,
|
|
115
|
+
selectBehavior: PropTypes.func.isRequired,
|
|
108
116
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* Converts a DAL design specification object into
|
|
4
|
-
* @param {Object} design
|
|
3
|
+
* Converts a DAL design specification object into nodes and edges for reaflow.
|
|
4
|
+
* @param {Object} engine - The engine instance containing the design specification.
|
|
5
5
|
* @returns {Object} An object containing nodes and edges for React Flow
|
|
6
6
|
*/
|
|
7
7
|
export const designToNodes = (engine) => {
|
|
8
|
-
|
|
9
8
|
let edges = [];
|
|
10
9
|
let nodes = [];
|
|
11
10
|
|
|
@@ -46,19 +46,19 @@ const Template = (args) => {
|
|
|
46
46
|
activeTool: activeTool,
|
|
47
47
|
design: design,
|
|
48
48
|
});
|
|
49
|
-
}, []);
|
|
49
|
+
}, [activeTool, design]);
|
|
50
50
|
|
|
51
51
|
useEffect(() => {
|
|
52
52
|
if (editorRef.current) {
|
|
53
53
|
const engine = new DALEngine({ name: "testEngine" });
|
|
54
|
-
// engine.deserialize(JSON.stringify(design));
|
|
55
54
|
setEngine(engine);
|
|
56
55
|
editorRef.current.updateEngine(engine);
|
|
57
|
-
setTimeout(() => {
|
|
56
|
+
const timerId = setTimeout(() => {
|
|
58
57
|
engine.addNode("testBehavior", []);
|
|
59
58
|
engine.addNode("testBehavior2", []);
|
|
60
59
|
editorRef.current.updateEngine(engine);
|
|
61
60
|
}, 4000);
|
|
61
|
+
return () => clearTimeout(timerId);
|
|
62
62
|
}
|
|
63
63
|
}, [design, editorRef]);
|
|
64
64
|
|
|
@@ -30,12 +30,13 @@ export function ToolBar({ onSelectTool }) {
|
|
|
30
30
|
className="icon"
|
|
31
31
|
/>
|
|
32
32
|
</div>
|
|
33
|
-
<div className="toolbarContainer bottom"
|
|
33
|
+
<div className="toolbarContainer bottom">
|
|
34
34
|
<Floppy
|
|
35
35
|
onClick={(e) => selectTool("save")}
|
|
36
36
|
title="Save Design"
|
|
37
37
|
className="icon"
|
|
38
38
|
/>
|
|
39
|
+
</div>
|
|
39
40
|
</div>
|
|
40
41
|
);
|
|
41
42
|
}
|