@difizen/mana-core
Version:
44 lines • 1.43 kB
JavaScript
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* A command is a unique identifier of a function
* which can be executed by a user via a keyboard shortcut,
* a menu action or directly.
*/
export var Command;
(function (_Command) {
function is(arg) {
return !!arg && arg === Object(arg) && 'id' in arg;
}
_Command.is = is;
function compareCommands(a, b) {
if (a.label && b.label) {
var aCommand = (a.category ? "".concat(a.category, ": ").concat(a.label) : a.label).toLowerCase();
var bCommand = (b.category ? "".concat(b.category, ": ").concat(b.label) : b.label).toLowerCase();
return aCommand.localeCompare(bCommand);
}
return 0;
}
_Command.compareCommands = compareCommands;
function equals(a, b) {
return a.id === b.id && a.label === b.label && a.category === b.category;
}
_Command.equals = equals;
})(Command || (Command = {}));
/**
* A command handler is an implementation of a command.
*
* A command can have multiple handlers
* but they should be active in different contexts,
* otherwise first active will be executed.
*/
/**
* A command handler is an implementation of a command.
*
* A command can have multiple handlers
* but they should be active in different contexts,
* otherwise first active will be executed.
*/
export var CommandService = Symbol('CommandService');
/**
* The command service should be used to execute commands.
*/