From 577b06c2f57653b2aed6597c1ab21076684eff0b Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Tue, 25 Dec 2018 12:57:59 +0300 Subject: [PATCH] feat(xod-client): double click on constant node provides opening of Inspector, focusing and selecting value of the node's PinWidget control --- packages/xod-client/package.json | 1 + .../src/core/domSideeffectsMiddleware.js | 30 +++++++++++++++++++ packages/xod-client/src/core/middlewares.js | 2 ++ packages/xod-client/src/editor/actionTypes.js | 2 ++ packages/xod-client/src/editor/actions.js | 8 +++++ .../src/editor/containers/Patch/index.jsx | 1 + .../containers/Patch/modes/selecting.jsx | 2 ++ packages/xod-client/src/editor/reducer.js | 8 +++++ yarn.lock | 5 ++++ 9 files changed, 59 insertions(+) create mode 100644 packages/xod-client/src/core/domSideeffectsMiddleware.js diff --git a/packages/xod-client/package.json b/packages/xod-client/package.json index b44e9580..032f5454 100644 --- a/packages/xod-client/package.json +++ b/packages/xod-client/package.json @@ -60,6 +60,7 @@ "url-parse": "^1.1.9", "url-search-params-polyfill": "^2.0.1", "vec-la-fp": "^1.5.2", + "wait-for-element": "^1.0.2", "xod-arduino": "^0.25.2", "xod-func-tools": "^0.25.0", "xod-patch-search": "^0.25.2", diff --git a/packages/xod-client/src/core/domSideeffectsMiddleware.js b/packages/xod-client/src/core/domSideeffectsMiddleware.js new file mode 100644 index 00000000..401e555c --- /dev/null +++ b/packages/xod-client/src/core/domSideeffectsMiddleware.js @@ -0,0 +1,30 @@ +import waitForElement from 'wait-for-element'; +import { SELECT_CONSTANT_NODE_VALUE } from '../editor/actionTypes'; + +export default _ => next => action => { + if (action.type === SELECT_CONSTANT_NODE_VALUE) { + // First of all, do the stuff in reducers to show inspector pane. + const n = next(action); + // Wait for updated Inspector, because it could appeared + // or it changed entirely on new selection + waitForElement('.Inspector-container') + .then(__ => { + // Select widget control with a tricky selector instead of ID, because + // some constant nodes has a generated id of the terminal Node + const ctrl = document.querySelector( + '.PinWidget input, .PinWidget select' + ); + if (!ctrl) return; + if (ctrl.setSelectionRange) + ctrl.setSelectionRange(0, ctrl.value.length); + ctrl.focus(); + }) + .catch(err => { + throw err; + }); + + return n; + } + + return next(action); +}; diff --git a/packages/xod-client/src/core/middlewares.js b/packages/xod-client/src/core/middlewares.js index 40fafb1b..63bcecdd 100644 --- a/packages/xod-client/src/core/middlewares.js +++ b/packages/xod-client/src/core/middlewares.js @@ -6,6 +6,7 @@ import devtoolsMiddleware from '../utils/devtoolsMiddleware'; import sidebarsMiddleware from '../editor/sidebarsMiddleware'; import crashReporter from './crashReporterMiddleware'; import hintingMiddleware from '../hinting/middleware'; +import domSideeffectsMiddleware from './domSideeffectsMiddleware'; export default (extraMiddlewares = []) => compose( @@ -15,6 +16,7 @@ export default (extraMiddlewares = []) => resolveLibsMiddleware, sidebarsMiddleware, hintingMiddleware, + domSideeffectsMiddleware, ...extraMiddlewares ), devtoolsMiddleware diff --git a/packages/xod-client/src/editor/actionTypes.js b/packages/xod-client/src/editor/actionTypes.js index dc8ad9e2..7e7b2a72 100644 --- a/packages/xod-client/src/editor/actionTypes.js +++ b/packages/xod-client/src/editor/actionTypes.js @@ -45,3 +45,5 @@ export const MINIMIZE_PANEL = 'MINIMIZE_PANEL'; export const MAXIMIZE_PANEL = 'MAXIMIZE_PANEL'; export const MOVE_PANEL = 'MOVE_PANEL'; export const TOGGLE_PANEL_AUTOHIDE = 'TOGGLE_PANEL_AUTOHIDE'; + +export const SELECT_CONSTANT_NODE_VALUE = 'SELECT_CONSTANT_NODE_VALUE'; diff --git a/packages/xod-client/src/editor/actions.js b/packages/xod-client/src/editor/actions.js index 7a6beeab..fa0a14c0 100644 --- a/packages/xod-client/src/editor/actions.js +++ b/packages/xod-client/src/editor/actions.js @@ -691,3 +691,11 @@ export const splitLinksToBuses = () => (dispatch, getState) => { }); }); }; + +export const selectConstantNodeValue = (nodeId, patchPath) => ({ + type: ActionType.SELECT_CONSTANT_NODE_VALUE, + payload: { + nodeId, + patchPath, + }, +}); diff --git a/packages/xod-client/src/editor/containers/Patch/index.jsx b/packages/xod-client/src/editor/containers/Patch/index.jsx index 0f31fa72..bfab0fd1 100644 --- a/packages/xod-client/src/editor/containers/Patch/index.jsx +++ b/packages/xod-client/src/editor/containers/Patch/index.jsx @@ -353,6 +353,7 @@ const mapDispatchToProps = dispatch => ({ changeArityLevel: ProjectActions.changeArityLevel, splitLinksToBuses: EditorActions.splitLinksToBuses, addBusNode: ProjectActions.addBusNode, + selectConstantNodeValue: EditorActions.selectConstantNodeValue, }, dispatch ), diff --git a/packages/xod-client/src/editor/containers/Patch/modes/selecting.jsx b/packages/xod-client/src/editor/containers/Patch/modes/selecting.jsx index 0edce6e0..7589af50 100644 --- a/packages/xod-client/src/editor/containers/Patch/modes/selecting.jsx +++ b/packages/xod-client/src/editor/containers/Patch/modes/selecting.jsx @@ -227,6 +227,8 @@ const selectingMode = { onNodeDoubleClick(api, nodeId, patchPath) { if (R.contains(patchPath, R.keys(XP.MANAGED_ATTACHMENT_FILENAMES))) { api.props.actions.openAttachmentEditor(patchPath); + } else if (XP.isConstantNodeType(patchPath)) { + api.props.actions.selectConstantNodeValue(nodeId, api.props.patchPath); } else { api.props.actions.switchPatch(patchPath); } diff --git a/packages/xod-client/src/editor/reducer.js b/packages/xod-client/src/editor/reducer.js index 54fe4fad..deee64c3 100644 --- a/packages/xod-client/src/editor/reducer.js +++ b/packages/xod-client/src/editor/reducer.js @@ -630,6 +630,14 @@ const editorReducer = (state = {}, action) => { state ); + case EAT.SELECT_CONSTANT_NODE_VALUE: + // maximize Inspector panel to focus & select widget's input + return R.assocPath( + ['panels', PANEL_IDS.INSPECTOR, 'maximized'], + true, + state + ); + default: return state; } diff --git a/yarn.lock b/yarn.lock index 1867f1e3..9d21ea4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15732,6 +15732,11 @@ w3c-hr-time@^1.0.1: dependencies: browser-process-hrtime "^0.1.2" +wait-for-element@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wait-for-element/-/wait-for-element-1.0.2.tgz#cbe7e31f157981f56f3bc1080768ef1823792f3d" + integrity sha1-y+fjHxV5gfVvO8EIB2jvGCN5Lz0= + walkdir@^0.0.11: version "0.0.11" resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.0.11.tgz#a16d025eb931bd03b52f308caed0f40fcebe9532"