feat(nodes): allow multiple handles

This commit is contained in:
moklick
2019-09-11 17:58:18 +02:00
parent 46bf04f88d
commit 7958022ded
6 changed files with 85 additions and 32 deletions
+20 -10
View File
@@ -13,20 +13,31 @@ const isHandle = e => (
);
const getHandleBounds = (sel, nodeElement, parentBounds, k) => {
const handle = nodeElement.querySelector(sel);
const handles = nodeElement.querySelectorAll(sel);
if (!handle) {
if (!handles || !handles.length) {
return null;
}
const bounds = handle.getBoundingClientRect();
const dimensions = getDimensions(handle);
return [].map.call(handles, (handle) => {
const bounds = handle.getBoundingClientRect();
const dimensions = getDimensions(handle);
const nodeIdAttr = handle.getAttribute('data-nodeid');
const nodeIdSplitted = nodeIdAttr.split('__');
return {
x: (bounds.x - parentBounds.x) * (1 / k),
y: (bounds.y - parentBounds.y) * (1 / k),
...dimensions
};
let handleId = null;
if (nodeIdSplitted) {
handleId = nodeIdSplitted.length ? nodeIdSplitted[1] : nodeIdSplitted;
}
return {
id: handleId,
x: (bounds.x - parentBounds.x) * (1 / k),
y: (bounds.y - parentBounds.y) * (1 / k),
...dimensions
};
});
};
const onStart = (evt, { setOffset, onClick, id, type, data, position, transform }) => {
@@ -92,7 +103,6 @@ export default NodeComponent => {
source: getHandleBounds('.source', nodeElement.current, bounds, transform[2]),
target: getHandleBounds('.target', nodeElement.current, bounds, transform[2])
};
store.dispatch.updateNodeData({ id, ...dimensions, handleBounds });
}, []);