feat(toolbar): new Toolbar to enable reactive state synchronization (#3983)

This commit is contained in:
Alireza authored and GitHub committed 2024-03-27 16:01:32 -04:00
1 parent 79d5c36bda
commit 566b25a544
155 files changed
+6311 -6577

No files matched your search

@@ -8,7 +8,6 @@ describe('CommandsManager', () => {
contextName = 'VTK',
command = {
commandFn: jest.fn().mockReturnValue(true),
storeContexts: ['viewers'],
options: { passMeToCommandFn: ':wave:' },
},
commandsManagerConfig = {
@@ -139,7 +138,6 @@ describe('CommandsManager', () => {
it('Logs a warning if command definition does not have a commandFn', () => {
const commandWithNoCommmandFn = {
commandFn: undefined,
storeContexts: [],
options: {},
};
+26 -10
View File
@@ -1,5 +1,5 @@
import log from '../log.js';
import { Command, Commands } from '../types/Command';
import { Command, Commands, ComplexCommand } from '../types/Command';
/**
* The definition of a command
@@ -167,28 +167,44 @@ export class CommandsManager {
* Run one or more commands with specified extra options.
* Returns the result of the last command run.
*
* @param toRun - A specification of one or more commands
* @param toRun - A specification of one or more commands,
* typically an object of { commandName, commandOptions, context }
* or an array of such objects. It can also be a single commandName as string
* if no options are needed.
* @param options - to include in the commands run beyond
* the commandOptions specified in the base.
*/
public run(
toRun: Command | Commands | Command[] | undefined,
toRun: Command | Commands | Command[] | string | undefined,
options?: Record<string, unknown>
): unknown {
if (!toRun) {
return;
}
const commands =
(Array.isArray(toRun) && toRun) ||
((toRun as Command).commandName && [toRun]) ||
(Array.isArray((toRun as Commands).commands) && (toRun as Commands).commands);
if (!commands) {
// Normalize `toRun` to an array of `ComplexCommand`
let commands: ComplexCommand[] = [];
if (typeof toRun === 'string') {
commands = [{ commandName: toRun }];
} else if ('commandName' in toRun) {
commands = [toRun as ComplexCommand];
} else if ('commands' in toRun) {
const commandsInput = (toRun as Commands).commands;
commands = Array.isArray(commandsInput)
? commandsInput.map(cmd => (typeof cmd === 'string' ? { commandName: cmd } : cmd))
: [{ commandName: commandsInput }];
} else if (Array.isArray(toRun)) {
commands = toRun.map(cmd => (typeof cmd === 'string' ? { commandName: cmd } : cmd));
}
if (commands.length === 0) {
console.log("Command isn't runnable", toRun);
return;
}
let result;
(commands as Command[]).forEach(({ commandName, commandOptions, context }) => {
// Execute each command in the array
let result: unknown;
commands.forEach(({ commandName, commandOptions, context }) => {
if (commandName) {
result = this.runCommand(
commandName,
@@ -1,5 +1,4 @@
import objectHash from 'object-hash';
import log from '../log.js';
import { hotkeys } from '../utils';
import isequal from 'lodash.isequal';
import Hotkey from './Hotkey';
@@ -276,10 +275,3 @@ export class HotkeysManager {
}
export default HotkeysManager;
// Commands Contexts:
// --> Name and Priority
// GLOBAL: 0
// VIEWER::CORNERSTONE: 1
// VIEWER::VTK: 1