From eb60b414e1a984b3658e65a68720e7ae37037d06 Mon Sep 17 00:00:00 2001 From: Izhaki Date: Mon, 20 Jan 2020 00:14:35 +0000 Subject: [PATCH] [editor] Base multiTool logic on edit policies Addresses #2 --- .../editor/chip-editor/getDomainTarget.js | 11 +--------- .../editor/chip-editor/tools/multiTool.js | 21 +++++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/examples/editor/chip-editor/getDomainTarget.js b/examples/editor/chip-editor/getDomainTarget.js index d30b757..53d062c 100644 --- a/examples/editor/chip-editor/getDomainTarget.js +++ b/examples/editor/chip-editor/getDomainTarget.js @@ -13,8 +13,6 @@ export default (element, { nodes }) => { type, port, id, - draggable: true, - selectable: false, }; } @@ -22,8 +20,6 @@ export default (element, { nodes }) => { return { type, id: element.id, - draggable: true, - selectable: true, }; } @@ -31,14 +27,9 @@ export default (element, { nodes }) => { return { type, id: element.getAttribute('data-target-id'), - draggable: false, - selectable: true, }; } default: - return { - draggable: false, - selectable: false, - }; + return {}; } }; diff --git a/examples/editor/chip-editor/tools/multiTool.js b/examples/editor/chip-editor/tools/multiTool.js index eacb20b..595ca61 100644 --- a/examples/editor/chip-editor/tools/multiTool.js +++ b/examples/editor/chip-editor/tools/multiTool.js @@ -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': { @@ -36,7 +29,7 @@ export default store => { case 'mouseUp': { if (currentTool) { const result = currentTool(next)(action); - currentTool = null; + currentTool = defaultToll; return result; } break;