Skip to content

Commit

Permalink
[editor] Base multiTool logic on edit policies
Browse files Browse the repository at this point in the history
Addresses #2
  • Loading branch information
Izhaki committed Jan 20, 2020
1 parent beb6150 commit eb60b41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
11 changes: 1 addition & 10 deletions examples/editor/chip-editor/getDomainTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,23 @@ export default (element, { nodes }) => {
type,
port,
id,
draggable: true,
selectable: false,
};
}

case 'node': {
return {
type,
id: element.id,
draggable: true,
selectable: true,
};
}

case 'connection': {
return {
type,
id: element.getAttribute('data-target-id'),
draggable: false,
selectable: true,
};
}
default:
return {
draggable: false,
selectable: false,
};
return {};
}
};
21 changes: 7 additions & 14 deletions examples/editor/chip-editor/tools/multiTool.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import connectionTool from './connectionTool';
import selectionTool from './selectionTool';
import getEditPolicies from '../editPolicies';

export default store => {
let currentTool = null;

const tools = {
connection: connectionTool(store),
selection: selectionTool(store),
};

const targetTypeToTool = {
input: tools.connection,
output: tools.connection,
node: tools.selection,
};
const defaultToll = tools.selection;
let currentTool = defaultToll;

return next => action => {
switch (action.type) {
case 'mouseDown': {
tools.selection(next)(action);
const { target } = action.event;
if (target.draggable) {
currentTool = targetTypeToTool[target.type];
return currentTool(next)(action);
}
break;
const { connection: connectionPolicy } = getEditPolicies(target);
currentTool = connectionPolicy ? tools.connection : defaultToll;
return currentTool(next)(action);
}

case 'mouseMove': {
Expand All @@ -36,7 +29,7 @@ export default store => {
case 'mouseUp': {
if (currentTool) {
const result = currentTool(next)(action);
currentTool = null;
currentTool = defaultToll;
return result;
}
break;
Expand Down

0 comments on commit eb60b41

Please sign in to comment.