* OHIF-330: Update Modal Styles * feat/ohif-332: finish raw ui * feat/ohif-332: update mode configuration strategy * feat/ohif-332: fix hotkey errors * feat/ohif-332: update hotkey logic with recent merged changes * feat/ohif-322: wrap * feat/ohif-322: add disable state * ohif-332: cr updates * ohif-332: disable * ohif-332: cr updates * ohif-332: extract header component * ohif-332: cr update to fix merge conflicts and design issue Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import { hotkeysValidators } from './hotkeysValidators';
|
|
|
|
/**
|
|
* Split hotkeys definitions and create hotkey related tuples
|
|
*
|
|
* @param {array} hotkeyDefinitions
|
|
* @returns {array} array of tuples consisted of command name and hotkey definition
|
|
*/
|
|
const splitHotkeyDefinitionsAndCreateTuples = hotkeyDefinitions => {
|
|
const splitedHotkeys = [];
|
|
const arrayHotkeys = Object.entries(hotkeyDefinitions);
|
|
|
|
if (arrayHotkeys.length) {
|
|
const halfwayThrough = Math.ceil(arrayHotkeys.length / 2);
|
|
splitedHotkeys.push(arrayHotkeys.slice(0, halfwayThrough));
|
|
splitedHotkeys.push(
|
|
arrayHotkeys.slice(halfwayThrough, arrayHotkeys.length)
|
|
);
|
|
}
|
|
|
|
return splitedHotkeys;
|
|
};
|
|
|
|
/**
|
|
* Validate a hotkey change
|
|
*
|
|
* @param {Object} arguments
|
|
* @param {string} arguments.commandName command name or id
|
|
* @param {array} arguments.pressedKeys new keys
|
|
* @param {array} arguments.hotkeys current hotkeys
|
|
* @returns {Object} {error} validation error
|
|
*/
|
|
const validate = ({ commandName, pressedKeys, hotkeys }) => {
|
|
for (const validator of hotkeysValidators) {
|
|
const validation = validator({
|
|
commandName,
|
|
pressedKeys,
|
|
hotkeys,
|
|
});
|
|
|
|
if (validation && validation.error) {
|
|
return validation;
|
|
}
|
|
}
|
|
|
|
return { error: undefined };
|
|
};
|
|
|
|
export {
|
|
validate,
|
|
splitHotkeyDefinitionsAndCreateTuples
|
|
};
|