@rkmodules/rules 0.0.25 → 0.0.26
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.js +213 -116
- package/dist/index.js.map +1 -1
- package/dist/lib/Engine/index.d.ts +5 -5
- package/dist/lib/Flow/index.d.ts +6 -1
- package/dist/lib/Flow/types.d.ts +2 -2
- package/dist/lib/hooks/useFlow.d.ts +18 -8
- package/dist/lib/hooks/usePositions.d.ts +1 -1
- package/dist/lib/hooks/useVariable.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
var mathjs = require('mathjs');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var react = require('@xyflow/react');
|
|
6
|
+
var reactDnd = require('react-dnd');
|
|
6
7
|
var katex = require('katex');
|
|
7
8
|
var classNames = require('classnames');
|
|
8
9
|
var zustand = require('zustand');
|
|
9
10
|
var middleware = require('zustand/middleware');
|
|
10
|
-
var reactDnd = require('react-dnd');
|
|
11
11
|
|
|
12
12
|
/******************************************************************************
|
|
13
13
|
Copyright (c) Microsoft Corporation.
|
|
@@ -874,7 +874,7 @@ var listItem = {
|
|
|
874
874
|
// return indices.map((i) => branch[i]);
|
|
875
875
|
// }
|
|
876
876
|
// }),
|
|
877
|
-
item: binaryOnTreeBranch(inputs.list, inputs.index, function (branch, indices) {
|
|
877
|
+
item: binaryOnTreeBranch(inputs.list || {}, inputs.index || {}, function (branch, indices) {
|
|
878
878
|
if (indices) {
|
|
879
879
|
return indices.map(function (i) { return branch[i]; });
|
|
880
880
|
}
|
|
@@ -1172,6 +1172,7 @@ var Engine = /** @class */ (function () {
|
|
|
1172
1172
|
endTime: endTime_1,
|
|
1173
1173
|
duration: endTime_1 - startTime_1,
|
|
1174
1174
|
});
|
|
1175
|
+
console.log("functionReult", name_1, inputs_1, params_1, result_1);
|
|
1175
1176
|
_e.label = 4;
|
|
1176
1177
|
case 4:
|
|
1177
1178
|
_i++;
|
|
@@ -1190,6 +1191,7 @@ var Engine = /** @class */ (function () {
|
|
|
1190
1191
|
endTime: endTime,
|
|
1191
1192
|
duration: endTime - startTime,
|
|
1192
1193
|
});
|
|
1194
|
+
console.log("graph run done", result, context, endTime - startTime);
|
|
1193
1195
|
return [2 /*return*/, result];
|
|
1194
1196
|
}
|
|
1195
1197
|
});
|
|
@@ -1301,11 +1303,12 @@ var Engine = /** @class */ (function () {
|
|
|
1301
1303
|
}
|
|
1302
1304
|
return [2 /*return*/, this.run(builtFn, inputs)];
|
|
1303
1305
|
}
|
|
1304
|
-
console.log("Engine running with inputs", inputs, interpolate(inputs, {}));
|
|
1305
1306
|
mappedInputs = interpolate(inputs, {});
|
|
1307
|
+
console.log("Engine running with inputs", inputs, mappedInputs);
|
|
1306
1308
|
return [4 /*yield*/, ((_a = node.impl) === null || _a === void 0 ? void 0 : _a.call(node, mappedInputs, {}))];
|
|
1307
1309
|
case 1:
|
|
1308
1310
|
result = _b.sent();
|
|
1311
|
+
console.log("Engine run complete", result);
|
|
1309
1312
|
return [2 /*return*/, result];
|
|
1310
1313
|
}
|
|
1311
1314
|
});
|
|
@@ -1315,8 +1318,8 @@ var Engine = /** @class */ (function () {
|
|
|
1315
1318
|
return this.fnIndex[name];
|
|
1316
1319
|
};
|
|
1317
1320
|
// node handlers
|
|
1318
|
-
Engine.prototype.applyNodeDelete = function (
|
|
1319
|
-
var newFn = __assign(__assign({},
|
|
1321
|
+
Engine.prototype.applyNodeDelete = function (oldFn, nodeIds) {
|
|
1322
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1320
1323
|
nodeIds.forEach(function (id) {
|
|
1321
1324
|
delete newFn.body[id];
|
|
1322
1325
|
});
|
|
@@ -1337,8 +1340,8 @@ var Engine = /** @class */ (function () {
|
|
|
1337
1340
|
});
|
|
1338
1341
|
return newFn;
|
|
1339
1342
|
};
|
|
1340
|
-
Engine.prototype.applyEdgeDelete = function (
|
|
1341
|
-
var newFn = __assign(__assign({},
|
|
1343
|
+
Engine.prototype.applyEdgeDelete = function (oldFn, fromNode, toNode, fromField, toField) {
|
|
1344
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1342
1345
|
var from = newFn.body[fromNode];
|
|
1343
1346
|
var to = newFn.body[toNode];
|
|
1344
1347
|
if (!from || !to) {
|
|
@@ -1353,8 +1356,8 @@ var Engine = /** @class */ (function () {
|
|
|
1353
1356
|
}
|
|
1354
1357
|
return newFn;
|
|
1355
1358
|
};
|
|
1356
|
-
Engine.prototype.applyNodeAdd = function (
|
|
1357
|
-
var newFn = __assign(__assign({},
|
|
1359
|
+
Engine.prototype.applyNodeAdd = function (oldFn, nodeName, callback) {
|
|
1360
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1358
1361
|
var id = uid$1();
|
|
1359
1362
|
// ensure unique id
|
|
1360
1363
|
while (newFn.body[id]) {
|
|
@@ -1387,10 +1390,10 @@ var Engine = /** @class */ (function () {
|
|
|
1387
1390
|
callback === null || callback === void 0 ? void 0 : callback(newCall, id);
|
|
1388
1391
|
return topSort(newFn);
|
|
1389
1392
|
};
|
|
1390
|
-
Engine.prototype.applyNodeConnect = function (
|
|
1391
|
-
var newFn = __assign(__assign({},
|
|
1393
|
+
Engine.prototype.applyNodeConnect = function (oldFn, fromNode, toNode, fromField, toField) {
|
|
1394
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1392
1395
|
var from = newFn.body[fromNode];
|
|
1393
|
-
var to = newFn.body[toNode];
|
|
1396
|
+
var to = __assign({}, newFn.body[toNode]);
|
|
1394
1397
|
if (!from || !to) {
|
|
1395
1398
|
console.warn("Invalid nodes for connection");
|
|
1396
1399
|
return newFn;
|
|
@@ -1400,6 +1403,7 @@ var Engine = /** @class */ (function () {
|
|
|
1400
1403
|
}
|
|
1401
1404
|
// add the reference
|
|
1402
1405
|
to.inputs[toField] = "<".concat(fromNode, ".").concat(fromField, ">");
|
|
1406
|
+
newFn.body[toNode] = to;
|
|
1403
1407
|
return topSort(newFn);
|
|
1404
1408
|
};
|
|
1405
1409
|
return Engine;
|
|
@@ -1658,12 +1662,21 @@ var variableStore = zustand.create(function (set, get, api) {
|
|
|
1658
1662
|
},
|
|
1659
1663
|
setVar: function (scope, name, value, persist) {
|
|
1660
1664
|
var _a, _b;
|
|
1665
|
+
var key = "".concat(scope, "|").concat(name);
|
|
1661
1666
|
if (persist) {
|
|
1662
|
-
var
|
|
1667
|
+
var oldData = pget().data;
|
|
1668
|
+
var newValue = typeof value === "function"
|
|
1669
|
+
? value(oldData[key])
|
|
1670
|
+
: value;
|
|
1671
|
+
var data = __assign(__assign({}, oldData), (_a = {}, _a[key] = newValue, _a));
|
|
1663
1672
|
pset({ data: data });
|
|
1664
1673
|
}
|
|
1665
1674
|
else {
|
|
1666
|
-
var
|
|
1675
|
+
var oldData = get().data;
|
|
1676
|
+
var newValue = typeof value === "function"
|
|
1677
|
+
? value(oldData[key])
|
|
1678
|
+
: value;
|
|
1679
|
+
var data = __assign(__assign({}, oldData), (_b = {}, _b[key] = newValue, _b));
|
|
1667
1680
|
set({ data: data });
|
|
1668
1681
|
}
|
|
1669
1682
|
},
|
|
@@ -1699,96 +1712,172 @@ function usePositions(fn) {
|
|
|
1699
1712
|
function useUpdatePositions(fn) {
|
|
1700
1713
|
var _a = __read(usePositions(fn), 2), positions = _a[0], setPositions = _a[1];
|
|
1701
1714
|
return React.useCallback(function (id, position) {
|
|
1702
|
-
|
|
1703
|
-
setPositions(
|
|
1715
|
+
positions[id] = position;
|
|
1716
|
+
setPositions(positions);
|
|
1704
1717
|
}, [positions, setPositions]);
|
|
1705
1718
|
}
|
|
1706
1719
|
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
+
// helpers
|
|
1721
|
+
function updateNodeArguments(node, inputs, params) {
|
|
1722
|
+
return __assign(__assign({}, node), { data: __assign(__assign({}, node.data), { inputs: inputs, params: params }) });
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* flow state stores nodes and edges for the flow graph these can be updated when the function changes
|
|
1726
|
+
* using setFn
|
|
1727
|
+
*/
|
|
1728
|
+
var useFlowState = zustand.create(function (set, get) { return ({
|
|
1729
|
+
engine: null,
|
|
1730
|
+
fn: null,
|
|
1731
|
+
options: {},
|
|
1732
|
+
nodes: [],
|
|
1733
|
+
edges: [],
|
|
1734
|
+
setNodes: function (updater) {
|
|
1735
|
+
set(function (state) { return ({ nodes: updater(state.nodes) }); });
|
|
1736
|
+
},
|
|
1737
|
+
setEdges: function (updater) {
|
|
1738
|
+
set(function (state) { return ({ edges: updater(state.edges) }); });
|
|
1739
|
+
},
|
|
1740
|
+
setFn: function (fn) {
|
|
1741
|
+
// console.log("setFn", fn);
|
|
1742
|
+
var _a = get(), oldFn = _a.fn, nodes = _a.nodes, edges = _a.edges, engine = _a.engine, options = _a.options;
|
|
1743
|
+
// update the graph by shallow comparison
|
|
1744
|
+
if (!engine) {
|
|
1745
|
+
throw new Error("Engine not set");
|
|
1746
|
+
}
|
|
1747
|
+
var oldKeys = Object.keys((oldFn === null || oldFn === void 0 ? void 0 : oldFn.body) || {});
|
|
1748
|
+
var newKeys = Object.keys(fn.body || {});
|
|
1749
|
+
// remove all the nodes that were removed
|
|
1750
|
+
nodes = nodes === null || nodes === void 0 ? void 0 : nodes.filter(function (node) { return newKeys.includes(node.id); });
|
|
1751
|
+
// remove all the edges that were removed
|
|
1752
|
+
edges = edges === null || edges === void 0 ? void 0 : edges.filter(function (edge) {
|
|
1753
|
+
return (newKeys.includes(edge.source) && newKeys.includes(edge.target));
|
|
1754
|
+
});
|
|
1755
|
+
// create the new nodes that were added
|
|
1756
|
+
var addedKeys = newKeys.filter(function (key) { return !oldKeys.includes(key); });
|
|
1757
|
+
addedKeys.forEach(function (key, index) {
|
|
1758
|
+
var _a;
|
|
1759
|
+
var fncall = (_a = fn.body) === null || _a === void 0 ? void 0 : _a[key];
|
|
1760
|
+
// add the node
|
|
1761
|
+
nodes.push(createNode(engine, key, fncall, options));
|
|
1762
|
+
// add edges
|
|
1763
|
+
var refs = getReferences(fncall.inputs || {});
|
|
1764
|
+
refs.forEach(function (ref) {
|
|
1765
|
+
edges.push(createEdge(key, ref));
|
|
1720
1766
|
});
|
|
1721
1767
|
});
|
|
1722
|
-
// update the
|
|
1723
|
-
var
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
(_a = options === null || options === void 0 ? void 0 : options.onChange) === null || _a === void 0 ? void 0 : _a.call(options, updatedFn);
|
|
1728
|
-
// console.log("updated call", fncall);
|
|
1729
|
-
}; };
|
|
1730
|
-
Object.entries(fn.body || {}).forEach(function (_a, index) {
|
|
1731
|
-
var _b = __read(_a, 2), id = _b[0], fncall = _b[1];
|
|
1732
|
-
var calledFn = engine.getFunction(fncall.name);
|
|
1733
|
-
// create a node for each function call
|
|
1734
|
-
nodes.push({
|
|
1735
|
-
id: id,
|
|
1736
|
-
data: {
|
|
1737
|
-
name: fncall.name,
|
|
1738
|
-
caller: fn,
|
|
1739
|
-
inputs: fncall.inputs,
|
|
1740
|
-
params: fncall.params,
|
|
1741
|
-
inputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.inputs) || {},
|
|
1742
|
-
paramDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.params) || {},
|
|
1743
|
-
outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
|
|
1744
|
-
onChange: handleChange(id),
|
|
1745
|
-
},
|
|
1746
|
-
position: (positions === null || positions === void 0 ? void 0 : positions[id]) || { x: 250 * index, y: 0 },
|
|
1747
|
-
dragHandle: options === null || options === void 0 ? void 0 : options.dragHandle,
|
|
1748
|
-
type: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.nodeType) || "Default",
|
|
1768
|
+
// update the changed nodes
|
|
1769
|
+
var changedKeys = newKeys.filter(function (key) {
|
|
1770
|
+
var _a, _b;
|
|
1771
|
+
// shallow comparison
|
|
1772
|
+
return ((_a = fn.body) === null || _a === void 0 ? void 0 : _a[key]) !== ((_b = oldFn === null || oldFn === void 0 ? void 0 : oldFn.body) === null || _b === void 0 ? void 0 : _b[key]);
|
|
1749
1773
|
});
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1774
|
+
// console.log("changed keys", changedKeys);
|
|
1775
|
+
changedKeys.forEach(function (key) {
|
|
1776
|
+
var _a;
|
|
1777
|
+
// update the nodes that were changed
|
|
1778
|
+
var fncall = (_a = fn.body) === null || _a === void 0 ? void 0 : _a[key];
|
|
1779
|
+
nodes = nodes === null || nodes === void 0 ? void 0 : nodes.map(function (n) {
|
|
1780
|
+
if (n.id === key) {
|
|
1781
|
+
return updateNodeArguments(n, fncall.inputs, fncall.params);
|
|
1782
|
+
}
|
|
1783
|
+
return n;
|
|
1784
|
+
});
|
|
1785
|
+
// update incoming edges
|
|
1786
|
+
var refs = getReferences(fncall.inputs || {});
|
|
1787
|
+
// remove all incoming edges
|
|
1788
|
+
edges = edges === null || edges === void 0 ? void 0 : edges.filter(function (e) { return e.target !== key; });
|
|
1789
|
+
// add the edge
|
|
1790
|
+
refs.forEach(function (ref) {
|
|
1791
|
+
edges.push(createEdge(key, ref));
|
|
1759
1792
|
});
|
|
1760
1793
|
});
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
}
|
|
1794
|
+
// console.log("final graph", nodes, edges);
|
|
1795
|
+
// update the function, nodes and edges
|
|
1796
|
+
set({ fn: fn, nodes: nodes, edges: edges });
|
|
1797
|
+
},
|
|
1798
|
+
init: function (fn, engine, options) {
|
|
1799
|
+
// console.log("initing");
|
|
1800
|
+
set({ engine: engine, options: options });
|
|
1801
|
+
get().setFn(fn);
|
|
1802
|
+
},
|
|
1803
|
+
}); });
|
|
1804
|
+
/**
|
|
1805
|
+
* creates a flow state and provides handlers to update nodes and edges
|
|
1806
|
+
*/
|
|
1764
1807
|
function useFlow(fn, engine, options) {
|
|
1765
|
-
var
|
|
1808
|
+
var state = useFlowState();
|
|
1766
1809
|
React.useEffect(function () {
|
|
1767
|
-
|
|
1768
|
-
options.setNodes(nodes);
|
|
1769
|
-
options.setEdges(edges);
|
|
1810
|
+
state.init(fn, engine, options);
|
|
1770
1811
|
}, [engine]);
|
|
1812
|
+
React.useEffect(function () {
|
|
1813
|
+
state.setFn(fn);
|
|
1814
|
+
}, [fn]);
|
|
1815
|
+
return React.useMemo(function () { return ({
|
|
1816
|
+
nodes: state.nodes,
|
|
1817
|
+
edges: state.edges,
|
|
1818
|
+
setNodes: state.setNodes,
|
|
1819
|
+
setEdges: state.setEdges,
|
|
1820
|
+
}); }, [state]);
|
|
1821
|
+
}
|
|
1822
|
+
function createNode(engine, id, fncall, options) {
|
|
1823
|
+
var _a, _b;
|
|
1824
|
+
var calledFn = engine.getFunction(fncall.name);
|
|
1825
|
+
// create a node for each function call
|
|
1826
|
+
return {
|
|
1827
|
+
id: id,
|
|
1828
|
+
data: {
|
|
1829
|
+
name: fncall.name,
|
|
1830
|
+
inputs: fncall.inputs,
|
|
1831
|
+
params: fncall.params,
|
|
1832
|
+
inputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.inputs) || {},
|
|
1833
|
+
paramDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.params) || {},
|
|
1834
|
+
outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
|
|
1835
|
+
onChange: ((_a = options.onDataChange) === null || _a === void 0 ? void 0 : _a.call(options, id)) || (function () { }),
|
|
1836
|
+
},
|
|
1837
|
+
position: ((_b = options.positions) === null || _b === void 0 ? void 0 : _b[id]) || { x: 0, y: 0 },
|
|
1838
|
+
dragHandle: options.dragHandle,
|
|
1839
|
+
type: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.nodeType) || "Default",
|
|
1840
|
+
};
|
|
1841
|
+
}
|
|
1842
|
+
function createEdge(nodeId, ref) {
|
|
1843
|
+
return {
|
|
1844
|
+
id: "".concat(ref.path, "-").concat(nodeId, ".").concat(ref.name),
|
|
1845
|
+
source: ref.refNode,
|
|
1846
|
+
target: nodeId,
|
|
1847
|
+
sourceHandle: "".concat(ref.refNode, "-").concat(ref.refField),
|
|
1848
|
+
targetHandle: "".concat(nodeId, "-").concat(ref.name),
|
|
1849
|
+
};
|
|
1771
1850
|
}
|
|
1772
1851
|
|
|
1773
1852
|
function FlowInner(_a) {
|
|
1774
1853
|
var fn = _a.function, engine = _a.engine, onChange = _a.onChange, onClick = _a.onClick, onSelect = _a.onSelect;
|
|
1775
1854
|
var _b = __read(React.useState(null), 2), instance = _b[0], setInstance = _b[1];
|
|
1776
|
-
var
|
|
1777
|
-
var _c = __read(
|
|
1778
|
-
var
|
|
1779
|
-
|
|
1855
|
+
var updatePosition = useUpdatePositions(fn);
|
|
1856
|
+
var _c = __read(usePositions(fn), 1), positions = _c[0];
|
|
1857
|
+
var handleDataChange = function (id) { return function (newData) {
|
|
1858
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
|
|
1859
|
+
// update the function definition
|
|
1860
|
+
// console.log("before fn call update", Object.keys(fn.body));
|
|
1861
|
+
var body = __assign({}, fn.body);
|
|
1862
|
+
var fncall = __assign(__assign({}, (body[id] || {})), newData);
|
|
1863
|
+
body[id] = fncall;
|
|
1864
|
+
// console.log("after fn call update", Object.keys(body));
|
|
1865
|
+
var updatedFn = __assign(__assign({}, fn), { body: body });
|
|
1866
|
+
return updatedFn;
|
|
1867
|
+
});
|
|
1868
|
+
}; };
|
|
1869
|
+
var _d = useFlow(fn, engine, {
|
|
1780
1870
|
dragHandle: ".".concat(styles.Label),
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
});
|
|
1871
|
+
positions: positions,
|
|
1872
|
+
onDataChange: handleDataChange,
|
|
1873
|
+
}), nodes = _d.nodes, edges = _d.edges, setNodes = _d.setNodes, setEdges = _d.setEdges;
|
|
1785
1874
|
// node selection handler
|
|
1786
|
-
var
|
|
1875
|
+
var handleSelect = React.useCallback(function (_a) {
|
|
1787
1876
|
var nodes = _a.nodes;
|
|
1788
1877
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nodes.map(function (n) { return n.id; }) || []);
|
|
1789
1878
|
}, [onSelect]);
|
|
1790
1879
|
react.useOnSelectionChange({
|
|
1791
|
-
onChange:
|
|
1880
|
+
onChange: handleSelect,
|
|
1792
1881
|
});
|
|
1793
1882
|
// dropping nodes
|
|
1794
1883
|
var _e = __read(reactDnd.useDrop({
|
|
@@ -1797,10 +1886,13 @@ function FlowInner(_a) {
|
|
|
1797
1886
|
var pos = monitor.getClientOffset();
|
|
1798
1887
|
if (instance && pos) {
|
|
1799
1888
|
var position_1 = instance.screenToFlowPosition(pos);
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1889
|
+
// console.log("handle drop", position);
|
|
1890
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
|
|
1891
|
+
return engine.applyNodeAdd(fn, item.name, function (fnCall, id) {
|
|
1892
|
+
// console.log("node added", id, position);
|
|
1893
|
+
updatePosition(id, position_1);
|
|
1894
|
+
});
|
|
1895
|
+
});
|
|
1804
1896
|
}
|
|
1805
1897
|
},
|
|
1806
1898
|
collect: function (monitor) {
|
|
@@ -1809,8 +1901,7 @@ function FlowInner(_a) {
|
|
|
1809
1901
|
};
|
|
1810
1902
|
},
|
|
1811
1903
|
}), 2); _e[0].isOver; var drop = _e[1];
|
|
1812
|
-
//
|
|
1813
|
-
var updatePosition = useUpdatePositions(fn);
|
|
1904
|
+
// connecting nodes
|
|
1814
1905
|
var onConnect = React.useCallback(function (params) {
|
|
1815
1906
|
var _a, _b;
|
|
1816
1907
|
var sourceField = (_a = params.sourceHandle) === null || _a === void 0 ? void 0 : _a.split("-")[1];
|
|
@@ -1819,37 +1910,34 @@ function FlowInner(_a) {
|
|
|
1819
1910
|
console.warn("Invalid connection handles", params);
|
|
1820
1911
|
return;
|
|
1821
1912
|
}
|
|
1822
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(
|
|
1823
|
-
|
|
1824
|
-
}, [setEdges, fn, onChange]);
|
|
1825
|
-
var onNodesDelete = React.useCallback(function (nodesToDelete) {
|
|
1826
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(engine.applyNodeDelete(fn, nodesToDelete.map(function (n) { return n.id; })));
|
|
1827
|
-
setNodes(function (nodesSnapshot) {
|
|
1828
|
-
return nodesSnapshot.filter(function (node) { return !nodesToDelete.some(function (n) { return n.id === node.id; }); });
|
|
1913
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
|
|
1914
|
+
return engine.applyNodeConnect(fn, params.source, params.target, sourceField, targetField);
|
|
1829
1915
|
});
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1916
|
+
}, [fn, onChange]);
|
|
1917
|
+
// deleting nodes
|
|
1918
|
+
var onNodesDelete = React.useCallback(function (nodesToDelete) {
|
|
1919
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
|
|
1920
|
+
return engine.applyNodeDelete(fn, nodesToDelete.map(function (n) { return n.id; }));
|
|
1834
1921
|
});
|
|
1835
|
-
}, [
|
|
1922
|
+
}, [onChange, fn]);
|
|
1923
|
+
// deleting edges
|
|
1836
1924
|
var onEdgesDelete = React.useCallback(function (edgesToDelete) {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
return edgesSnapshot.filter(function (edge) { return !edgesToDelete.some(function (e) { return e.id === edge.id; }); });
|
|
1925
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
|
|
1926
|
+
var newFn = fn;
|
|
1927
|
+
edgesToDelete.forEach(function (edge) {
|
|
1928
|
+
var _a, _b;
|
|
1929
|
+
var sourceField = (_a = edge.sourceHandle) === null || _a === void 0 ? void 0 : _a.split("-")[1];
|
|
1930
|
+
var targetField = (_b = edge.targetHandle) === null || _b === void 0 ? void 0 : _b.split("-")[1];
|
|
1931
|
+
if (!sourceField || !targetField) {
|
|
1932
|
+
console.warn("Invalid connection handles", edge);
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
newFn = engine.applyEdgeDelete(newFn, edge.source, edge.target, sourceField, targetField);
|
|
1936
|
+
});
|
|
1937
|
+
return newFn;
|
|
1851
1938
|
});
|
|
1852
|
-
}, [
|
|
1939
|
+
}, [onChange, fn]);
|
|
1940
|
+
// handle canvas clicks to be able to place nodes
|
|
1853
1941
|
var handleClick = function (e) {
|
|
1854
1942
|
if (instance) {
|
|
1855
1943
|
var position = instance.screenToFlowPosition({
|
|
@@ -1859,6 +1947,16 @@ function FlowInner(_a) {
|
|
|
1859
1947
|
onClick === null || onClick === void 0 ? void 0 : onClick(e, position);
|
|
1860
1948
|
}
|
|
1861
1949
|
};
|
|
1950
|
+
var onNodesChange = React.useCallback(function (changes) {
|
|
1951
|
+
return setNodes(function (nodesSnapshot) {
|
|
1952
|
+
return react.applyNodeChanges(changes, nodesSnapshot);
|
|
1953
|
+
});
|
|
1954
|
+
}, []);
|
|
1955
|
+
var onEdgesChange = React.useCallback(function (changes) {
|
|
1956
|
+
return setEdges(function (edgesSnapshot) {
|
|
1957
|
+
return react.applyEdgeChanges(changes, edgesSnapshot);
|
|
1958
|
+
});
|
|
1959
|
+
}, []);
|
|
1862
1960
|
return (React.createElement(react.ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: nodeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: setInstance, onPaneClick: handleClick, fitView: true,
|
|
1863
1961
|
// panOnDrag={false}
|
|
1864
1962
|
selectionOnDrag: true, minZoom: 0.1, deleteKeyCode: "Delete" },
|
|
@@ -1928,7 +2026,6 @@ exports.Flow = Flow;
|
|
|
1928
2026
|
exports.binaryOnTree = binaryOnTree;
|
|
1929
2027
|
exports.binaryOnTreeBranch = binaryOnTreeBranch;
|
|
1930
2028
|
exports.broadCast = broadCast;
|
|
1931
|
-
exports.createGraph = createGraph;
|
|
1932
2029
|
exports.expandTree = expandTree;
|
|
1933
2030
|
exports.getBranch = getBranch;
|
|
1934
2031
|
exports.getReferences = getReferences;
|