feat(xod-client): double click on constant node provides opening of Inspector, focusing and selecting value of the node's PinWidget control

This commit is contained in:
Kirill Shumilov
2018-12-25 12:57:59 +03:00
parent 6f9e1d5e45
commit 577b06c2f5
9 changed files with 59 additions and 0 deletions

View File

@@ -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",

View File

@@ -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);
};

View File

@@ -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

View File

@@ -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';

View File

@@ -691,3 +691,11 @@ export const splitLinksToBuses = () => (dispatch, getState) => {
});
});
};
export const selectConstantNodeValue = (nodeId, patchPath) => ({
type: ActionType.SELECT_CONSTANT_NODE_VALUE,
payload: {
nodeId,
patchPath,
},
});

View File

@@ -353,6 +353,7 @@ const mapDispatchToProps = dispatch => ({
changeArityLevel: ProjectActions.changeArityLevel,
splitLinksToBuses: EditorActions.splitLinksToBuses,
addBusNode: ProjectActions.addBusNode,
selectConstantNodeValue: EditorActions.selectConstantNodeValue,
},
dispatch
),

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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"