schyma 1.0.3 → 1.0.5
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/components/App.d.ts +2 -7
- package/dist/cjs/components/App.js +4 -2
- package/dist/cjs/components/App.js.map +1 -1
- package/dist/cjs/components/Nodes.js +76 -83
- package/dist/cjs/components/Nodes.js.map +1 -1
- package/dist/cjs/constants/node.d.ts +2 -0
- package/dist/cjs/constants/node.js +6 -0
- package/dist/cjs/constants/node.js.map +1 -0
- package/dist/cjs/style.css +2 -1
- package/dist/cjs/types.d.ts +17 -21
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/dagreUtils.d.ts +5 -0
- package/dist/cjs/utils/dagreUtils.js +33 -0
- package/dist/cjs/utils/dagreUtils.js.map +1 -0
- package/dist/cjs/utils/reusables.d.ts +3 -2
- package/dist/cjs/utils/reusables.js +37 -38
- package/dist/cjs/utils/reusables.js.map +1 -1
- package/dist/esm/components/App.d.ts +2 -7
- package/dist/esm/components/App.js +4 -2
- package/dist/esm/components/App.js.map +1 -1
- package/dist/esm/components/Nodes.js +76 -83
- package/dist/esm/components/Nodes.js.map +1 -1
- package/dist/esm/constants/node.d.ts +2 -0
- package/dist/esm/constants/node.js +3 -0
- package/dist/esm/constants/node.js.map +1 -0
- package/dist/esm/style.css +2 -1
- package/dist/esm/types.d.ts +17 -21
- package/dist/esm/types.js +3 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/dagreUtils.d.ts +5 -0
- package/dist/esm/utils/dagreUtils.js +28 -0
- package/dist/esm/utils/dagreUtils.js.map +1 -0
- package/dist/esm/utils/reusables.d.ts +3 -2
- package/dist/esm/utils/reusables.js +36 -38
- package/dist/esm/utils/reusables.js.map +1 -1
- package/package.json +7 -9
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
title: string;
|
|
5
|
-
description: string;
|
|
6
|
-
schema: JSONSchema7Object;
|
|
7
|
-
}
|
|
8
|
-
declare function Schyma({ title, description, schema }: Default): React.JSX.Element;
|
|
2
|
+
import { ISchyma } from "../types";
|
|
3
|
+
declare function Schyma({ title, description, schema }: ISchyma): React.JSX.Element;
|
|
9
4
|
export default Schyma;
|
|
@@ -6,18 +6,20 @@ const Panel_1 = tslib_1.__importDefault(require("./Panel"));
|
|
|
6
6
|
const react_2 = require("react");
|
|
7
7
|
const Nodes_1 = tslib_1.__importDefault(require("./Nodes"));
|
|
8
8
|
const ajv_1 = tslib_1.__importDefault(require("ajv"));
|
|
9
|
+
const reusables_1 = require("../utils/reusables");
|
|
9
10
|
function Schyma({ title, description, schema }) {
|
|
10
11
|
const ajv = new ajv_1.default();
|
|
11
12
|
const [currentNode, setCurrentNode] = (0, react_2.useState)();
|
|
12
13
|
const [nNodes, setnNodes] = (0, react_2.useState)({});
|
|
13
14
|
const [render, setRender] = (0, react_2.useState)(false);
|
|
14
15
|
const position = { x: 0, y: 0 };
|
|
16
|
+
const properties = (0, reusables_1.propMerge)(schema, "");
|
|
15
17
|
const initialNode = {
|
|
16
18
|
id: '1',
|
|
17
19
|
data: {
|
|
18
20
|
label: title,
|
|
19
21
|
description,
|
|
20
|
-
properties:
|
|
22
|
+
properties: properties,
|
|
21
23
|
relations: {},
|
|
22
24
|
},
|
|
23
25
|
position,
|
|
@@ -30,7 +32,7 @@ function Schyma({ title, description, schema }) {
|
|
|
30
32
|
}, [validate]);
|
|
31
33
|
return (react_1.default.createElement("div", null, render ? react_1.default.createElement("div", { className: "body-wrapper" },
|
|
32
34
|
react_1.default.createElement("div", { className: "node-container" },
|
|
33
|
-
react_1.default.createElement(Nodes_1.default, { setnNodes: setnNodes,
|
|
35
|
+
react_1.default.createElement(Nodes_1.default, { setnNodes: setnNodes, setCurrentNode: setCurrentNode, nNodes: nNodes, initialNode: initialNode, schema: schema })),
|
|
34
36
|
react_1.default.createElement(Panel_1.default, { title: title, description: description, node: currentNode, nodes: nNodes })) : react_1.default.createElement("div", null, "loading")));
|
|
35
37
|
}
|
|
36
38
|
exports.default = Schyma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.js","sourceRoot":"","sources":["../../../src/components/App.tsx"],"names":[],"mappings":";;;AAAA,uDAAyC;AAEzC,4DAA4B;AAC5B,iCAAiC;AACjC,4DAA4B;
|
|
1
|
+
{"version":3,"file":"App.js","sourceRoot":"","sources":["../../../src/components/App.tsx"],"names":[],"mappings":";;;AAAA,uDAAyC;AAEzC,4DAA4B;AAC5B,iCAAiC;AACjC,4DAA4B;AAC5B,sDAAsB;AACtB,kDAA+C;AAG/C,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAW;IACrD,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAC;IACtB,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,GAAQ,CAAC;IACvD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAE,GAAG,IAAA,gBAAQ,EAAsB,EAAE,CAAC,CAAC;IAC/D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAChC,MAAM,UAAU,GAAG,IAAA,qBAAS,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzC,MAAM,WAAW,GAAS;QACxB,EAAE,EAAE,GAAG;QACP,IAAI,EAAE;YACJ,KAAK,EAAE,KAAK;YACZ,WAAW;YACX,UAAU,EAAE,UAAU;YACtB,SAAS,EAAE,EAAE;SACd;QACD,QAAQ;KACT,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAE5C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAG,QAAQ,EAAC;YACV,SAAS,CAAC,IAAI,CAAC,CAAA;SAChB;IACH,CAAC,EAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;IACb,OAAO,CACL,2CACG,MAAM,CAAC,CAAC,CAAC,uCAAK,SAAS,EAAC,cAAc;QACrC,uCAAK,SAAS,EAAC,gBAAgB;YAC7B,8BAAC,eAAK,IAAC,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAI,CACrH;QACN,8BAAC,eAAK,IACJ,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,GACb,CACE,CAAC,CAAC,CAAC,qDAAkB,CACvB,CACP,CAAC;AACJ,CAAC;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
/* eslint-disable import/no-anonymous-default-export */
|
|
5
4
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
5
|
const react_flow_smart_edge_1 = require("@tisoap/react-flow-smart-edge");
|
|
7
|
-
const reactflow_1 =
|
|
8
|
-
const dagre_1 = tslib_1.__importDefault(require("dagre"));
|
|
6
|
+
const reactflow_1 = require("reactflow");
|
|
9
7
|
const reusables_1 = require("../utils/reusables");
|
|
10
|
-
const
|
|
8
|
+
const dagreUtils_1 = require("../utils/dagreUtils");
|
|
9
|
+
const position = { x: 0, y: 0, zoom: 0.2 };
|
|
11
10
|
const initialEdges = [
|
|
12
11
|
{
|
|
13
12
|
id: 'edges-e5-7',
|
|
@@ -17,102 +16,91 @@ const initialEdges = [
|
|
|
17
16
|
labelBgPadding: [8, 4],
|
|
18
17
|
labelBgBorderRadius: 4,
|
|
19
18
|
animated: true,
|
|
19
|
+
type: 'smart',
|
|
20
20
|
markerEnd: {
|
|
21
21
|
type: reactflow_1.MarkerType.ArrowClosed,
|
|
22
22
|
},
|
|
23
23
|
},
|
|
24
24
|
];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const nodeWidth = 172;
|
|
28
|
-
const nodeHeight = 36;
|
|
29
|
-
const getLayoutedElements = (nodes, edges, direction = 'LR') => {
|
|
30
|
-
dagreGraph.setGraph({ rankdir: direction });
|
|
31
|
-
nodes.forEach(node => {
|
|
32
|
-
dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });
|
|
33
|
-
});
|
|
34
|
-
edges.forEach((edge) => {
|
|
35
|
-
dagreGraph.setEdge(edge.source, edge.target);
|
|
36
|
-
});
|
|
37
|
-
dagre_1.default.layout(dagreGraph);
|
|
38
|
-
nodes.forEach((node) => {
|
|
39
|
-
const nodeId = node.id;
|
|
40
|
-
const nodeWithPosition = dagreGraph.node(nodeId);
|
|
41
|
-
node.sourcePosition = reactflow_1.Position.Right;
|
|
42
|
-
node.targetPosition = reactflow_1.Position.Left;
|
|
43
|
-
node.position = {
|
|
44
|
-
x: nodeWithPosition.x - nodeWidth / 3,
|
|
45
|
-
y: nodeWithPosition.y - nodeHeight / 3,
|
|
46
|
-
};
|
|
47
|
-
return node;
|
|
48
|
-
});
|
|
49
|
-
return { nodes, edges };
|
|
50
|
-
};
|
|
51
|
-
const Nodes = ({ setCurrentNode, setnNodes, initialNode, nNodes, schema }) => {
|
|
52
|
-
const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements([initialNode], initialEdges);
|
|
53
|
-
const { setCenter } = (0, reactflow_1.useReactFlow)();
|
|
25
|
+
function Flow({ initialNode, nNodes, setnNodes, setCurrentNode, schema }) {
|
|
26
|
+
const { nodes: layoutedNodes, edges: layoutedEdges } = (0, dagreUtils_1.getLayoutedElements)([initialNode], initialEdges);
|
|
54
27
|
const [nodes, setNodes, onNodesChange] = (0, reactflow_1.useNodesState)(layoutedNodes);
|
|
55
28
|
const [edges, setEdges, onEdgesChange] = (0, reactflow_1.useEdgesState)(layoutedEdges);
|
|
29
|
+
const { setCenter } = (0, reactflow_1.useReactFlow)();
|
|
56
30
|
const onConnect = (0, react_1.useCallback)((connection) => setEdges((eds) => (0, reactflow_1.addEdge)(Object.assign(Object.assign({}, connection), { type: reactflow_1.ConnectionLineType.SmoothStep, animated: true }), eds)),
|
|
57
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
32
|
[]);
|
|
59
|
-
const
|
|
60
|
-
const length = children.length;
|
|
61
|
-
let middleChild;
|
|
62
|
-
if (length % 2 === 0) {
|
|
63
|
-
const middleIndex = length / 2;
|
|
64
|
-
middleChild = children[middleIndex];
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const middleIndex = Math.floor(length / 2);
|
|
68
|
-
middleChild = children[middleIndex];
|
|
69
|
-
}
|
|
70
|
-
setCenter(middleChild.position.x, middleChild.position.y, { zoom, duration: 1000 });
|
|
71
|
-
};
|
|
72
|
-
let initialNodes = [initialNode];
|
|
73
|
-
const extractChildren = (props, parent) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const extractChildren = (props, parent) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
74
34
|
const children = [];
|
|
75
35
|
for (const prop in props) {
|
|
76
36
|
const id = String(Math.floor(Math.random() * 1000000));
|
|
77
37
|
if (props[prop].$ref) {
|
|
78
38
|
const res = yield (0, reusables_1.resolveRef)(props[prop].$ref, schema);
|
|
79
|
-
children.push(
|
|
39
|
+
children.push({
|
|
40
|
+
id,
|
|
41
|
+
type: 'input',
|
|
42
|
+
data: Object.assign(Object.assign(Object.assign(Object.assign({}, props[prop]), { label: prop, parent: parent.id, relations: Object.assign(Object.assign({}, parent.relations), { [parent.id]: 'node' }) }), res), { children: [] }),
|
|
43
|
+
position: position,
|
|
44
|
+
sourcePosition: reactflow_1.Position.Right,
|
|
45
|
+
targetPosition: reactflow_1.Position.Left,
|
|
46
|
+
});
|
|
80
47
|
}
|
|
81
48
|
else {
|
|
82
|
-
children.push(
|
|
49
|
+
children.push({
|
|
50
|
+
id,
|
|
51
|
+
type: 'input',
|
|
52
|
+
data: Object.assign(Object.assign({}, props[prop]), { label: prop, id, parent: parent.id, relations: Object.assign(Object.assign({}, parent.relations), { [parent.id]: 'node' }), children: [] }),
|
|
53
|
+
position: position,
|
|
54
|
+
sourcePosition: reactflow_1.Position.Right,
|
|
55
|
+
targetPosition: reactflow_1.Position.Left,
|
|
56
|
+
});
|
|
83
57
|
}
|
|
84
58
|
}
|
|
85
59
|
return children;
|
|
86
60
|
});
|
|
87
61
|
(0, react_1.useEffect)(() => {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
const
|
|
62
|
+
const fetchInitialChildren = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const newNodes = [];
|
|
64
|
+
const properties = initialNode.data.properties;
|
|
65
|
+
const children = yield extractChildren(properties, initialNode);
|
|
91
66
|
newNodes.push({
|
|
92
|
-
id:
|
|
93
|
-
type:
|
|
67
|
+
id: initialNode.id,
|
|
68
|
+
type: 'input',
|
|
94
69
|
data: {
|
|
95
70
|
children,
|
|
96
|
-
label:
|
|
97
|
-
description:
|
|
98
|
-
properties:
|
|
99
|
-
relations:
|
|
71
|
+
label: initialNode.data.label,
|
|
72
|
+
description: initialNode.data.description,
|
|
73
|
+
properties: initialNode.data.properties,
|
|
74
|
+
relations: initialNode.data.relations,
|
|
100
75
|
},
|
|
101
76
|
position: { x: 0, y: 0 },
|
|
102
77
|
sourcePosition: reactflow_1.Position.Right,
|
|
103
78
|
targetPosition: reactflow_1.Position.Left,
|
|
104
79
|
});
|
|
105
|
-
|
|
106
|
-
|
|
80
|
+
setNodes(newNodes);
|
|
81
|
+
});
|
|
82
|
+
fetchInitialChildren();
|
|
107
83
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
108
84
|
}, []);
|
|
109
|
-
|
|
85
|
+
// Node focus when clicked
|
|
86
|
+
const focusNode = (children, zoom) => {
|
|
87
|
+
if (children.length === 0)
|
|
88
|
+
return;
|
|
89
|
+
let middleChild = children[Math.floor(children.length / 2)];
|
|
90
|
+
const middleChildWithLatestPosition = nodes.filter((a) => a.id == middleChild.id)[0];
|
|
91
|
+
if (middleChildWithLatestPosition) {
|
|
92
|
+
middleChild = middleChildWithLatestPosition;
|
|
93
|
+
}
|
|
94
|
+
setCenter(middleChild.position.x, middleChild.position.y, { zoom, duration: 1000 });
|
|
95
|
+
};
|
|
96
|
+
// On Node Click
|
|
97
|
+
const nodeClick = (_event, node) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
110
98
|
const findChildren = nodes.filter((item) => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.parent) === node.id; });
|
|
111
99
|
if (!findChildren.length) {
|
|
112
100
|
const itemChildren = node.data.children;
|
|
113
101
|
const newEdges = [
|
|
114
102
|
...edges,
|
|
115
|
-
...
|
|
103
|
+
...itemChildren.map((item) => {
|
|
116
104
|
var _a;
|
|
117
105
|
return {
|
|
118
106
|
id: String(Math.floor(Math.random() * 1000000)),
|
|
@@ -125,8 +113,8 @@ const Nodes = ({ setCurrentNode, setnNodes, initialNode, nNodes, schema }) => {
|
|
|
125
113
|
}),
|
|
126
114
|
];
|
|
127
115
|
//TODO: Fix nodes type error
|
|
128
|
-
const newNodes = nodes.concat(
|
|
129
|
-
const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(newNodes, newEdges,
|
|
116
|
+
const newNodes = nodes.concat(itemChildren);
|
|
117
|
+
const { nodes: layoutedNodes, edges: layoutedEdges } = (0, dagreUtils_1.getLayoutedElements)(newNodes, newEdges, 'LR');
|
|
130
118
|
setNodes([...layoutedNodes]);
|
|
131
119
|
setEdges([...layoutedEdges]);
|
|
132
120
|
if (itemChildren.length > 0) {
|
|
@@ -135,35 +123,42 @@ const Nodes = ({ setCurrentNode, setnNodes, initialNode, nNodes, schema }) => {
|
|
|
135
123
|
}
|
|
136
124
|
else {
|
|
137
125
|
const newNodes = (0, reusables_1.removeElementsByParent)(nodes, node.id);
|
|
138
|
-
|
|
126
|
+
const newEdges = (0, reusables_1.removeEdgesByParent)(edges, node.id);
|
|
127
|
+
const { nodes: layoutedNodes, edges: layoutedEdges } = (0, dagreUtils_1.getLayoutedElements)(newNodes, newEdges, 'LR');
|
|
128
|
+
setNodes([...layoutedNodes]);
|
|
129
|
+
setEdges([...layoutedEdges]);
|
|
130
|
+
focusNode([node], 0.9);
|
|
139
131
|
}
|
|
140
132
|
});
|
|
133
|
+
//On Node Hover
|
|
141
134
|
function handleMouseEnter(_e, node) {
|
|
142
135
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
143
136
|
if (!nNodes[node.id]) {
|
|
144
137
|
const itemChildren = [];
|
|
145
|
-
|
|
138
|
+
const nodeChildren = node.data.children;
|
|
139
|
+
yield Promise.all(nodeChildren.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
146
140
|
let children = [];
|
|
147
|
-
const
|
|
141
|
+
const label = item.data.label;
|
|
142
|
+
const extractProps = (0, reusables_1.propMerge)(item.data, label);
|
|
148
143
|
if (Object.keys(extractProps).length > 0) {
|
|
149
144
|
const res = yield extractChildren(extractProps, item);
|
|
150
145
|
children = res;
|
|
151
146
|
}
|
|
147
|
+
const relations = Object.assign(Object.assign({}, node.data.relations), item.data.relations);
|
|
152
148
|
itemChildren.push({
|
|
153
149
|
id: item.id,
|
|
154
|
-
type: (children === null || children === void 0 ? void 0 : children.length) > 0 ?
|
|
150
|
+
type: (children === null || children === void 0 ? void 0 : children.length) > 0 ? 'default' : 'output',
|
|
155
151
|
data: {
|
|
156
|
-
label: item.label,
|
|
152
|
+
label: item.data.label,
|
|
157
153
|
children: children,
|
|
158
|
-
parent: item.parent,
|
|
159
|
-
examples: item.examples,
|
|
160
|
-
description: item.description,
|
|
161
|
-
relations:
|
|
154
|
+
parent: item.data.parent,
|
|
155
|
+
examples: item.data.examples,
|
|
156
|
+
description: item.data.description,
|
|
157
|
+
relations: relations,
|
|
162
158
|
},
|
|
163
159
|
position: position,
|
|
164
160
|
sourcePosition: reactflow_1.Position.Right,
|
|
165
161
|
targetPosition: reactflow_1.Position.Left,
|
|
166
|
-
draggable: false,
|
|
167
162
|
});
|
|
168
163
|
})));
|
|
169
164
|
node.data.children = itemChildren;
|
|
@@ -176,13 +171,11 @@ const Nodes = ({ setCurrentNode, setnNodes, initialNode, nNodes, schema }) => {
|
|
|
176
171
|
const edgeTypes = {
|
|
177
172
|
smart: react_flow_smart_edge_1.SmartBezierEdge,
|
|
178
173
|
};
|
|
179
|
-
return (react_1.default.createElement(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
// eslint-disable-next-line react/display-name
|
|
174
|
+
return (react_1.default.createElement(reactflow_1.ReactFlow, { nodes: nodes, edges: edges, edgeTypes: edgeTypes, onNodesChange: onNodesChange, connectionLineType: reactflow_1.ConnectionLineType.SmoothStep, onEdgesChange: onEdgesChange, onConnect: onConnect, onNodeMouseEnter: handleMouseEnter, onNodeClick: nodeClick, fitView: true, defaultViewport: { x: 1, y: 1, zoom: 0.9 } },
|
|
175
|
+
react_1.default.createElement(reactflow_1.MiniMap, null),
|
|
176
|
+
react_1.default.createElement(reactflow_1.Controls, null),
|
|
177
|
+
react_1.default.createElement(reactflow_1.Background, null)));
|
|
178
|
+
}
|
|
186
179
|
exports.default = ({ setCurrentNode, setnNodes, nNodes, initialNode, schema }) => (react_1.default.createElement(reactflow_1.ReactFlowProvider, null,
|
|
187
|
-
react_1.default.createElement(
|
|
180
|
+
react_1.default.createElement(Flow, { setnNodes: setnNodes, nNodes: nNodes, setCurrentNode: setCurrentNode, initialNode: initialNode, schema: schema })));
|
|
188
181
|
//# sourceMappingURL=Nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Nodes.js","sourceRoot":"","sources":["../../../src/components/Nodes.tsx"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Nodes.js","sourceRoot":"","sources":["../../../src/components/Nodes.tsx"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,yEAA+D;AAC/D,yCAgBkB;AAClB,kDAAuG;AAGvG,oDAAyD;AAUzD,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;AAC1C,MAAM,YAAY,GAAW;IAC3B;QACE,EAAE,EAAE,YAAY;QAChB,MAAM,EAAE,GAAG;QACX,MAAM,EAAE,GAAG;QACX,KAAK,EAAE,GAAG;QACV,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACtB,mBAAmB,EAAE,CAAC;QACtB,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,OAAO;QACb,SAAS,EAAE;YACT,IAAI,EAAE,sBAAU,CAAC,WAAW;SAC7B;KACF;CACF,CAAA;AAED,SAAS,IAAI,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAa;IACjF,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,IAAA,gCAAmB,EAAC,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAA;IACvG,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,CAAC,GAAG,IAAA,yBAAa,EAAC,aAAa,CAAC,CAAA;IACrE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,CAAC,GAAG,IAAA,yBAAa,EAAC,aAAa,CAAC,CAAA;IACrE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAA;IACpC,MAAM,SAAS,GAAG,IAAA,mBAAW,EAC3B,CAAC,UAAsB,EAAE,EAAE,CACzB,Q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
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/constants/node.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,GAAG,CAAA;AACf,QAAA,UAAU,GAAG,EAAE,CAAA"}
|
package/dist/cjs/style.css
CHANGED
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
parent: number;
|
|
5
|
-
description: string;
|
|
6
|
-
children: Array<Node>;
|
|
7
|
-
$ref?: string;
|
|
1
|
+
import { JSONSchema7Object } from "json-schema";
|
|
2
|
+
import { Node } from "reactflow";
|
|
3
|
+
export interface ISchyma {
|
|
8
4
|
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
schema: JSONSchema7Object;
|
|
7
|
+
}
|
|
8
|
+
export interface IObject {
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export interface NodeData {
|
|
9
12
|
label: string;
|
|
10
|
-
targetPosition?: string;
|
|
11
|
-
sourcePosition?: string;
|
|
12
|
-
position?: object;
|
|
13
|
-
data?: NodeType;
|
|
14
|
-
};
|
|
15
|
-
export type EdgeType = {
|
|
16
13
|
id: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
14
|
+
children: Node[];
|
|
15
|
+
description?: string;
|
|
16
|
+
properties?: any;
|
|
17
|
+
relations: any;
|
|
18
|
+
examples?: any;
|
|
19
|
+
parent: string;
|
|
20
|
+
}
|
package/dist/cjs/types.js
CHANGED
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;AAwBA,wCAAwC;AACxC,mBAAmB;AACnB,IAAI"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLayoutedElements = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const reactflow_1 = require("reactflow");
|
|
6
|
+
const node_1 = require("../constants/node");
|
|
7
|
+
const dagre_1 = tslib_1.__importDefault(require("@dagrejs/dagre"));
|
|
8
|
+
const getLayoutedElements = (nodes, edges, direction = 'LR') => {
|
|
9
|
+
const dagreGraph = new dagre_1.default.graphlib.Graph();
|
|
10
|
+
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
|
11
|
+
dagreGraph.setGraph({ rankdir: direction });
|
|
12
|
+
nodes.forEach((node) => {
|
|
13
|
+
dagreGraph.setNode(node.id, { width: node_1.nodeWidth, height: node_1.nodeHeight });
|
|
14
|
+
});
|
|
15
|
+
edges.forEach((edge) => {
|
|
16
|
+
dagreGraph.setEdge(edge.source, edge.target);
|
|
17
|
+
});
|
|
18
|
+
dagre_1.default.layout(dagreGraph);
|
|
19
|
+
nodes.forEach((node) => {
|
|
20
|
+
const nodeId = node.id;
|
|
21
|
+
const nodeWithPosition = dagreGraph.node(nodeId);
|
|
22
|
+
node.sourcePosition = reactflow_1.Position.Right;
|
|
23
|
+
node.targetPosition = reactflow_1.Position.Left;
|
|
24
|
+
node.position = {
|
|
25
|
+
x: nodeWithPosition.x - node_1.nodeWidth / 3,
|
|
26
|
+
y: nodeWithPosition.y - node_1.nodeHeight / 3,
|
|
27
|
+
};
|
|
28
|
+
return node;
|
|
29
|
+
});
|
|
30
|
+
return { nodes, edges };
|
|
31
|
+
};
|
|
32
|
+
exports.getLayoutedElements = getLayoutedElements;
|
|
33
|
+
//# sourceMappingURL=dagreUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dagreUtils.js","sourceRoot":"","sources":["../../../src/utils/dagreUtils.ts"],"names":[],"mappings":";;;;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ACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzB,CAAC,CAAA;AA7BY,QAAA,mBAAmB,uBA6B/B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare function resolveRef(ref: string, schema: any): Promise<JSONSchema>;
|
|
2
|
-
export declare function nameFromRef(
|
|
3
|
-
export declare function propMerge(schema: any, label: string):
|
|
2
|
+
export declare function nameFromRef(ref: string): string;
|
|
3
|
+
export declare function propMerge(schema: any, label: string): Record<string, unknown>;
|
|
4
4
|
export declare function arrayToProps(props: any, label: string): any;
|
|
5
5
|
export declare function removeElementsByParent(nodes: any, id: any): any;
|
|
6
|
+
export declare function removeEdgesByParent(edges: any, id: any): any;
|
|
6
7
|
export declare function retrieveObj(theObject: any, key: string | undefined): any;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retrieveObj = exports.removeElementsByParent = exports.arrayToProps = exports.propMerge = exports.nameFromRef = exports.resolveRef = void 0;
|
|
3
|
+
exports.retrieveObj = exports.removeEdgesByParent = exports.removeElementsByParent = exports.arrayToProps = exports.propMerge = exports.nameFromRef = exports.resolveRef = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const reference_resolver_1 = tslib_1.__importDefault(require("@json-schema-tools/reference-resolver"));
|
|
6
|
+
const memoizedNameFromRef = {};
|
|
6
7
|
function resolveRef(ref, schema) {
|
|
7
8
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
8
9
|
const resolver = yield reference_resolver_1.default.resolve(ref, schema);
|
|
@@ -10,34 +11,36 @@ function resolveRef(ref, schema) {
|
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
exports.resolveRef = resolveRef;
|
|
13
|
-
function nameFromRef(
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
function nameFromRef(ref) {
|
|
15
|
+
if (memoizedNameFromRef[ref]) {
|
|
16
|
+
return memoizedNameFromRef[ref];
|
|
17
|
+
}
|
|
18
|
+
const match = ref.match(/[^/]+$/);
|
|
19
|
+
const name = match ? match[0].split('.')[0] : '';
|
|
20
|
+
memoizedNameFromRef[ref] = name;
|
|
21
|
+
return name;
|
|
16
22
|
}
|
|
17
23
|
exports.nameFromRef = nameFromRef;
|
|
18
24
|
function propMerge(schema, label) {
|
|
19
25
|
let mergedProps = {};
|
|
20
26
|
const { properties, patternProperties, additionalProperties, items, oneOf, allOf, anyOf, not } = schema;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
mergedProps = Object.assign(Object.assign({}, mergedProps), props);
|
|
25
|
-
};
|
|
26
|
-
if (schema.patternProperties) {
|
|
27
|
-
mergedProps = Object.assign(Object.assign({}, mergedProps), patternProperties);
|
|
27
|
+
const combinedOf = oneOf || anyOf || not;
|
|
28
|
+
if (patternProperties) {
|
|
29
|
+
Object.assign(mergedProps, patternProperties);
|
|
28
30
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
+
if (properties) {
|
|
32
|
+
Object.assign(mergedProps, properties);
|
|
31
33
|
}
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
if (oneOf || allOf || anyOf) {
|
|
35
|
-
const items = oneOf || anyOf || not;
|
|
36
|
-
|
|
34
|
+
if (additionalProperties || items) {
|
|
35
|
+
const arrWithObject = additionalProperties || items;
|
|
36
|
+
if (arrWithObject.oneOf || arrWithObject.allOf || arrWithObject.anyOf) {
|
|
37
|
+
const items = arrWithObject.oneOf || arrWithObject.anyOf || arrWithObject.not;
|
|
38
|
+
const props = arrayToProps(items, label);
|
|
39
|
+
Object.assign(mergedProps, props);
|
|
37
40
|
}
|
|
38
41
|
if (arrWithObject.$ref) {
|
|
39
42
|
const name = nameFromRef(arrWithObject.$ref);
|
|
40
|
-
mergedProps
|
|
43
|
+
mergedProps[name] = arrWithObject;
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
// handling allOf case seperatly
|
|
@@ -46,7 +49,7 @@ function propMerge(schema, label) {
|
|
|
46
49
|
for (let i = 0; i < allOf.length; i++) {
|
|
47
50
|
if (allOf[i].type === 'object') {
|
|
48
51
|
if (allOf[i].properties) {
|
|
49
|
-
propObj = allOf[i].properties;
|
|
52
|
+
propObj = Object.assign(Object.assign({}, propObj), allOf[i].properties);
|
|
50
53
|
}
|
|
51
54
|
else {
|
|
52
55
|
propObj[allOf[i].type] = allOf[i];
|
|
@@ -60,11 +63,11 @@ function propMerge(schema, label) {
|
|
|
60
63
|
propObj[allOf[i].type] = allOf[i];
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
Object.assign(mergedProps, propObj);
|
|
64
67
|
}
|
|
65
|
-
if (
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
+
if (combinedOf) {
|
|
69
|
+
const props = arrayToProps(combinedOf, label);
|
|
70
|
+
Object.assign(mergedProps, props);
|
|
68
71
|
}
|
|
69
72
|
return mergedProps;
|
|
70
73
|
}
|
|
@@ -105,6 +108,16 @@ function removeElementsByParent(nodes, id) {
|
|
|
105
108
|
return result;
|
|
106
109
|
}
|
|
107
110
|
exports.removeElementsByParent = removeElementsByParent;
|
|
111
|
+
function removeEdgesByParent(edges, id) {
|
|
112
|
+
const result = edges.filter((edge) => {
|
|
113
|
+
if (edge.source === id) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
});
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
exports.removeEdgesByParent = removeEdgesByParent;
|
|
108
121
|
function retrieveObj(theObject, key) {
|
|
109
122
|
var result = null;
|
|
110
123
|
if (theObject instanceof Array) {
|
|
@@ -132,18 +145,4 @@ function retrieveObj(theObject, key) {
|
|
|
132
145
|
return result;
|
|
133
146
|
}
|
|
134
147
|
exports.retrieveObj = retrieveObj;
|
|
135
|
-
// export function typeCheck(data: any): boolean {
|
|
136
|
-
// switch (true) {
|
|
137
|
-
// case !!data.oneOf:
|
|
138
|
-
// case !!data.anyOf:
|
|
139
|
-
// case !!data.allOf:
|
|
140
|
-
// case !!data.items:
|
|
141
|
-
// case !! data.patternProperties:
|
|
142
|
-
// case data.additionalProperties !== undefined && data.additionalProperties !== true:
|
|
143
|
-
// case data.additionalItems !== undefined && data.additionalItems !== true:
|
|
144
|
-
// return true;
|
|
145
|
-
// default:
|
|
146
|
-
// return false;
|
|
147
|
-
// }
|
|
148
|
-
// }
|
|
149
148
|
//# sourceMappingURL=reusables.js.map
|