Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phosphor-command

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phosphor-command - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

551

lib/index.d.ts
import { ISignal } from 'phosphor-signaling';
/**
* An abstract base class for implementing concrete commands.
* An object which implements the command pattern.
*/
export declare abstract class Command {
export interface ICommand {
/**

@@ -15,102 +15,5 @@ * Execute the command with the specified arguments.

* undefined behavior.
*
* This abstract method must be implemented by a subclass, and the
* implementation **must not** throw an exception.
*/
abstract execute(args: any): void;
execute(args: any): void;
/**
* Get the display text for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The display text for the command.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* use this as the text for the primary DOM node for the command.
*
* The default implementation of this method returns an empty string.
*/
text(args: any): string;
/**
* Get the class name(s) for the command icon.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the command icon node.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* add the class name(s) to the DOM node for the command icon.
*
* Multiple class names can be separated with whitespace.
*
* The default implementation of this method returns an empty string.
*/
icon(args: any): string;
/**
* Get the short caption for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The short caption for the command.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* This value is used by UI elements where displaying a short command
* description is relevant, such as tooltips and command palettes.
*
* The default implementation of this method returns an empty string.
*/
caption(args: any): string;
/**
* Get the category for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The category for the command.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* This value is used by UI elements which group commands together
* based on category, such as toolbars and command palettes.
*
* The default implementation of this method returns an empty string.
*/
category(args: any): string;
/**
* Get the class name(s) for the primary command node.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the primary command node.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* add the class name(s) to the primary DOM node for the command.
*
* Multiple class names can be separated with whitespace.
*
* The default implementation of this method returns an empty string.
*/
className(args: any): string;
/**
* Test whether the command is enabled for its current state.

@@ -124,58 +27,15 @@ *

* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* typically display a non-enabled command as greyed-out.
*
* The default implementation of this method returns `true`.
* If the enabled state changes at runtime, the implementation should
* emit the static [[isEnabledChanged]] signal.
*/
isEnabled(args: any): boolean;
/**
* Test whether the command is visible for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is visible, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* typically not display a non-visible command.
*
* The default implementation of this method returns `true`.
*/
isVisible(args: any): boolean;
/**
* Test whether the command is checked for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* typically add extra class names to the node of a checked command.
*
* The default implementation of this method returns `false`.
*/
isChecked(args: any): boolean;
}
/**
* The namespace for the `Command` class statics.
* The namespace for the `ICommand` interface statics.
*/
export declare namespace Command {
export declare namespace ICommand {
/**
* A signal emitted when a command's state changes.
* A signal emitted when a command's enabled state changes.
*
* #### Notes
* A command should emit this signal when its state changes.
*
* This is a static signal which passes the changed command as the

@@ -185,396 +45,3 @@ * argument for the signal. This reduces the number of connections

*/
const changed: ISignal<typeof Command, Command>;
const isEnabledChanged: ISignal<typeof ICommand, ICommand>;
}
/**
* An options object for initializing a [[SimpleCommand]].
*/
export interface ISimpleCommandOptions {
/**
* The handler function for the command.
*/
handler: (args: any) => void;
/**
* The initial display text for the command.
*/
text?: string;
/**
* The initial icon class for the command.
*/
icon?: string;
/**
* The initial short caption for the command.
*/
caption?: string;
/**
* The initial category for the command.
*/
category?: string;
/**
* The initial extra class name for the command.
*/
className?: string;
/**
* The initial enabled state of the command.
*/
enabled?: boolean;
/**
* The initial visible state of the command.
*/
visible?: boolean;
/**
* The initial checked state of the command.
*/
checked?: boolean;
}
/**
* A concrete implementation of [[Command]].
*
* A `SimpleCommand` is useful for creating commands which do not rely
* on complex state and which can be implemented by a single function.
*
* A `SimpleCommand` should not be used when fine grained control over
* the command state is required. For those cases, the `Command` class
* should be subclassed directly.
*/
export declare class SimpleCommand extends Command {
/**
* Construct a new simple command.
*
* @param options - The options for initializing the command.
*/
constructor(options: ISimpleCommandOptions);
/**
* Get the display text for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The display text for the command.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setText]]
*/
text(args: any): string;
/**
* Get the class name(s) for the command icon.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the command icon node.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setIcon]]
*/
icon(args: any): string;
/**
* Get the short caption for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The short caption for the command.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setCaption]]
*/
caption(args: any): string;
/**
* Get the category for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The category for the command.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setCategory]]
*/
category(args: any): string;
/**
* Get the class name(s) for the primary command node.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the primary command node.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setClassName]]
*/
className(args: any): string;
/**
* Test whether the command is enabled for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is enabled, `false` otherwise.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setEnabled]]
*/
isEnabled(args: any): boolean;
/**
* Test whether the command is visible for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is visible, `false` otherwise.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setVisible]]
*/
isVisible(args: any): boolean;
/**
* Test whether the command is checked for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setChecked]]
*/
isChecked(args: any): boolean;
/**
* Set the text for the command.
*
* @param value - The text for the command.
*
* #### Notes
* If the text changes, the [[changed]] signal will be emitted.
*/
setText(value: string): void;
/**
* Set the icon for the command.
*
* @param value - The icon for the command.
*
* #### Notes
* If the icon changes, the [[changed]] signal will be emitted.
*/
setIcon(value: string): void;
/**
* Set the caption for the command.
*
* @param value - The caption for the command.
*
* #### Notes
* If the caption changes, the [[changed]] signal will be emitted.
*/
setCaption(value: string): void;
/**
* Set the category for the command.
*
* @param value - The category for the command.
*
* #### Notes
* If the category changes, the [[changed]] signal will be emitted.
*/
setCategory(value: string): void;
/**
* Set the class name for the command.
*
* @param value - The class name for the command.
*
* #### Notes
* If the class name changes, the [[changed]] signal will be emitted.
*/
setClassName(value: string): void;
/**
* Set the enabled state for the command.
*
* @param value - The enabled state for the command.
*
* #### Notes
* If the state changes, the [[changed]] signal will be emitted.
*/
setEnabled(value: boolean): void;
/**
* Set the visible state for the command.
*
* @param value - The visible state for the command.
*
* #### Notes
* If the state changes, the [[changed]] signal will be emitted.
*/
setVisible(value: boolean): void;
/**
* Set the checked state for the command.
*
* @param value - The checked state for the command.
*
* #### Notes
* If the state changes, the [[changed]] signal will be emitted.
*/
setChecked(value: boolean): void;
/**
* Execute the command with the specified arguments.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* #### Notes
* Calling `execute` when `isEnabled` returns `false` may result in
* undefined behavior.
*/
execute(args: any): void;
private _text;
private _icon;
private _caption;
private _category;
private _className;
private _enabled;
private _visible;
private _checked;
private _handler;
}
/**
* An options object for initializing a command item.
*/
export interface ICommandItemOptions {
/**
* The command for the command item.
*/
command: Command;
/**
* The arguments for the command.
*/
args?: any;
/**
* The keyboard shortcut decoration.
*/
shortcut?: string;
}
/**
* A read-only object which combines a command and arguments.
*
* #### Notes
* This class is useful for UI controls which render commands for
* a given set of arguments, such as a menu or a command palette.
*
* Even though a command item is read-only, a command may still mutate
* its own state in-place which may change the computed item data. The
* consumer of a command item should connect to the `Command.changed`
* signal if it needs to be notified of command state changes.
*/
export declare class CommandItem {
/**
* Construct a new command item.
*
* @param options - The options for initializing the command item.
*/
constructor(options: ICommandItemOptions);
/**
* Get the command for the command item.
*
* #### Notes
* This is a read-only property.
*/
command: Command;
/**
* Get the arguments for the command.
*
* #### Notes
* This is a read-only property.
*/
args: any;
/**
* Get the keyboard shortcut decoration.
*
* #### Notes
* The keyboard shortcut decoration is data which is explicitly *not*
* derived from or intrinsic to the command. This allows the keyboard
* shortcut to be defined externally as a user preference instead of
* in advance by the author of the command.
*
* This is a read-only property.
*/
shortcut: string;
/**
* Get the display text for the command item.
*
* #### Notes
* This is a read-only property.
*/
text: string;
/**
* Get the class name(s) for the command item icon.
*
* #### Notes
* This is a read-only property.
*/
icon: string;
/**
* Get the short caption for the command item.
*
* #### Notes
* This is a read-only property.
*/
caption: string;
/**
* Get the category for the command item.
*
* #### Notes
* This is a read-only property.
*/
category: string;
/**
* Get the extra class name(s) for the command item.
*
* #### Notes
* This is a read-only property.
*/
className: string;
/**
* Test whether the command item is enabled.
*
* #### Notes
* This is a read-only property.
*/
isEnabled: boolean;
/**
* Test whether the command item is visible.
*
* #### Notes
* This is a read-only property.
*/
isVisible: boolean;
/**
* Test whether the command item is checked.
*
* #### Notes
* This is a read-only property.
*/
isChecked: boolean;
/**
* Execute the command items.
*
* #### Notes
* Calling `execute` when `isEnabled` is `false` may result in
* undefined behavior.
*/
execute(): void;
private _command;
private _args;
private _shortcut;
}

@@ -9,192 +9,12 @@ /*-----------------------------------------------------------------------------

'use strict';
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var phosphor_signaling_1 = require('phosphor-signaling');
/**
* An abstract base class for implementing concrete commands.
* The namespace for the `ICommand` interface statics.
*/
var Command = (function () {
function Command() {
}
var ICommand;
(function (ICommand) {
/**
* Get the display text for the command.
* A signal emitted when a command's enabled state changes.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The display text for the command.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* use this as the text for the primary DOM node for the command.
*
* The default implementation of this method returns an empty string.
*/
Command.prototype.text = function (args) {
return '';
};
/**
* Get the class name(s) for the command icon.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the command icon node.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* add the class name(s) to the DOM node for the command icon.
*
* Multiple class names can be separated with whitespace.
*
* The default implementation of this method returns an empty string.
*/
Command.prototype.icon = function (args) {
return '';
};
/**
* Get the short caption for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The short caption for the command.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* This value is used by UI elements where displaying a short command
* description is relevant, such as tooltips and command palettes.
*
* The default implementation of this method returns an empty string.
*/
Command.prototype.caption = function (args) {
return '';
};
/**
* Get the category for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The category for the command.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* This value is used by UI elements which group commands together
* based on category, such as toolbars and command palettes.
*
* The default implementation of this method returns an empty string.
*/
Command.prototype.category = function (args) {
return '';
};
/**
* Get the class name(s) for the primary command node.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the primary command node.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* add the class name(s) to the primary DOM node for the command.
*
* Multiple class names can be separated with whitespace.
*
* The default implementation of this method returns an empty string.
*/
Command.prototype.className = function (args) {
return '';
};
/**
* Test whether the command is enabled for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is enabled, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* typically display a non-enabled command as greyed-out.
*
* The default implementation of this method returns `true`.
*/
Command.prototype.isEnabled = function (args) {
return true;
};
/**
* Test whether the command is visible for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is visible, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* typically not display a non-visible command.
*
* The default implementation of this method returns `true`.
*/
Command.prototype.isVisible = function (args) {
return true;
};
/**
* Test whether the command is checked for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* A subclass may reimplement this method as needed. If the state
* changes at runtime, the [[changed]] signal should be emitted.
*
* UI elements which have a visual representation of a command will
* typically add extra class names to the node of a checked command.
*
* The default implementation of this method returns `false`.
*/
Command.prototype.isChecked = function (args) {
return false;
};
return Command;
})();
exports.Command = Command;
/**
* The namespace for the `Command` class statics.
*/
var Command;
(function (Command) {
/**
* A signal emitted when a command's state changes.
*
* #### Notes
* A command should emit this signal when its state changes.
*
* This is a static signal which passes the changed command as the

@@ -204,509 +24,3 @@ * argument for the signal. This reduces the number of connections

*/
Command.changed = (new phosphor_signaling_1.Signal()).bind(Command);
})(Command = exports.Command || (exports.Command = {}));
/**
* A concrete implementation of [[Command]].
*
* A `SimpleCommand` is useful for creating commands which do not rely
* on complex state and which can be implemented by a single function.
*
* A `SimpleCommand` should not be used when fine grained control over
* the command state is required. For those cases, the `Command` class
* should be subclassed directly.
*/
var SimpleCommand = (function (_super) {
__extends(SimpleCommand, _super);
/**
* Construct a new simple command.
*
* @param options - The options for initializing the command.
*/
function SimpleCommand(options) {
_super.call(this);
this._text = '';
this._icon = '';
this._caption = '';
this._category = '';
this._className = '';
this._enabled = true;
this._visible = true;
this._checked = false;
this._handler = options.handler;
if (options.text !== void 0) {
this._text = options.text;
}
if (options.icon !== void 0) {
this._icon = options.icon;
}
if (options.caption !== void 0) {
this._caption = options.caption;
}
if (options.category !== void 0) {
this._category = options.category;
}
if (options.className !== void 0) {
this._className = options.className;
}
if (options.enabled !== void 0) {
this._enabled = options.enabled;
}
if (options.visible !== void 0) {
this._visible = options.visible;
}
if (options.checked !== void 0) {
this._checked = options.checked;
}
}
/**
* Get the display text for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The display text for the command.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setText]]
*/
SimpleCommand.prototype.text = function (args) {
return this._text;
};
/**
* Get the class name(s) for the command icon.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the command icon node.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setIcon]]
*/
SimpleCommand.prototype.icon = function (args) {
return this._icon;
};
/**
* Get the short caption for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The short caption for the command.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setCaption]]
*/
SimpleCommand.prototype.caption = function (args) {
return this._caption;
};
/**
* Get the category for the command.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The category for the command.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setCategory]]
*/
SimpleCommand.prototype.category = function (args) {
return this._category;
};
/**
* Get the class name(s) for the primary command node.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns The class name(s) to add to the primary command node.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setClassName]]
*/
SimpleCommand.prototype.className = function (args) {
return this._className;
};
/**
* Test whether the command is enabled for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is enabled, `false` otherwise.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setEnabled]]
*/
SimpleCommand.prototype.isEnabled = function (args) {
return this._enabled;
};
/**
* Test whether the command is visible for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is visible, `false` otherwise.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setVisible]]
*/
SimpleCommand.prototype.isVisible = function (args) {
return this._visible;
};
/**
* Test whether the command is checked for its current state.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* @returns `true` if the command is checked, `false` otherwise.
*
* #### Notes
* This method ignores the command arguments.
*
* **See also** [[setChecked]]
*/
SimpleCommand.prototype.isChecked = function (args) {
return this._checked;
};
/**
* Set the text for the command.
*
* @param value - The text for the command.
*
* #### Notes
* If the text changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setText = function (value) {
if (this._text === value) {
return;
}
this._text = value;
Command.changed.emit(this);
};
/**
* Set the icon for the command.
*
* @param value - The icon for the command.
*
* #### Notes
* If the icon changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setIcon = function (value) {
if (this._icon === value) {
return;
}
this._icon = value;
Command.changed.emit(this);
};
/**
* Set the caption for the command.
*
* @param value - The caption for the command.
*
* #### Notes
* If the caption changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setCaption = function (value) {
if (this._caption === value) {
return;
}
this._caption = value;
Command.changed.emit(this);
};
/**
* Set the category for the command.
*
* @param value - The category for the command.
*
* #### Notes
* If the category changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setCategory = function (value) {
if (this._category === value) {
return;
}
this._category = value;
Command.changed.emit(this);
};
/**
* Set the class name for the command.
*
* @param value - The class name for the command.
*
* #### Notes
* If the class name changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setClassName = function (value) {
if (this._className === value) {
return;
}
this._className = value;
Command.changed.emit(this);
};
/**
* Set the enabled state for the command.
*
* @param value - The enabled state for the command.
*
* #### Notes
* If the state changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setEnabled = function (value) {
if (this._enabled === value) {
return;
}
this._enabled = value;
Command.changed.emit(this);
};
/**
* Set the visible state for the command.
*
* @param value - The visible state for the command.
*
* #### Notes
* If the state changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setVisible = function (value) {
if (this._visible === value) {
return;
}
this._visible = value;
Command.changed.emit(this);
};
/**
* Set the checked state for the command.
*
* @param value - The checked state for the command.
*
* #### Notes
* If the state changes, the [[changed]] signal will be emitted.
*/
SimpleCommand.prototype.setChecked = function (value) {
if (this._checked === value) {
return;
}
this._checked = value;
Command.changed.emit(this);
};
/**
* Execute the command with the specified arguments.
*
* @param args - The arguments for the command. If the command does
* not require arguments, this may be `null`.
*
* #### Notes
* Calling `execute` when `isEnabled` returns `false` may result in
* undefined behavior.
*/
SimpleCommand.prototype.execute = function (args) {
try {
this._handler.call(void 0, args);
}
catch (err) {
console.error(err);
}
};
return SimpleCommand;
})(Command);
exports.SimpleCommand = SimpleCommand;
/**
* A read-only object which combines a command and arguments.
*
* #### Notes
* This class is useful for UI controls which render commands for
* a given set of arguments, such as a menu or a command palette.
*
* Even though a command item is read-only, a command may still mutate
* its own state in-place which may change the computed item data. The
* consumer of a command item should connect to the `Command.changed`
* signal if it needs to be notified of command state changes.
*/
var CommandItem = (function () {
/**
* Construct a new command item.
*
* @param options - The options for initializing the command item.
*/
function CommandItem(options) {
this._command = options.command;
this._args = options.args || null;
this._shortcut = options.shortcut || '';
}
Object.defineProperty(CommandItem.prototype, "command", {
/**
* Get the command for the command item.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "args", {
/**
* Get the arguments for the command.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._args;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "shortcut", {
/**
* Get the keyboard shortcut decoration.
*
* #### Notes
* The keyboard shortcut decoration is data which is explicitly *not*
* derived from or intrinsic to the command. This allows the keyboard
* shortcut to be defined externally as a user preference instead of
* in advance by the author of the command.
*
* This is a read-only property.
*/
get: function () {
return this._shortcut;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "text", {
/**
* Get the display text for the command item.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.text(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "icon", {
/**
* Get the class name(s) for the command item icon.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.icon(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "caption", {
/**
* Get the short caption for the command item.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.caption(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "category", {
/**
* Get the category for the command item.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.category(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "className", {
/**
* Get the extra class name(s) for the command item.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.className(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "isEnabled", {
/**
* Test whether the command item is enabled.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.isEnabled(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "isVisible", {
/**
* Test whether the command item is visible.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.isVisible(this._args);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommandItem.prototype, "isChecked", {
/**
* Test whether the command item is checked.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._command.isChecked(this._args);
},
enumerable: true,
configurable: true
});
/**
* Execute the command items.
*
* #### Notes
* Calling `execute` when `isEnabled` is `false` may result in
* undefined behavior.
*/
CommandItem.prototype.execute = function () {
this._command.execute(this._args);
};
return CommandItem;
})();
exports.CommandItem = CommandItem;
ICommand.isEnabledChanged = (new phosphor_signaling_1.Signal()).bind(ICommand);
})(ICommand = exports.ICommand || (exports.ICommand = {}));

2

package.json
{
"name": "phosphor-command",
"version": "0.8.0",
"version": "0.9.0",
"description": "A module for expressing the command pattern.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc