@lumino/commands
Advanced tools
Comparing version 1.20.1 to 1.21.0
@@ -8,3 +8,28 @@ import { ArrayExt } from '@lumino/algorithm'; | ||
// Copyright (c) Jupyter Development Team. | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
/** | ||
@@ -148,2 +173,13 @@ * An object which manages a collection of commands. | ||
/** | ||
* Get the description for a specific command. | ||
* | ||
* @param id - The id of the command of interest. | ||
* | ||
* @returns The description for the command. | ||
*/ | ||
CommandRegistry.prototype.describedBy = function (id) { | ||
var cmd = this._commands[id]; | ||
return cmd ? cmd.describedBy || { args: null } : { args: null }; | ||
}; | ||
/** | ||
* Get the display label for a specific command. | ||
@@ -672,22 +708,33 @@ * | ||
/** | ||
* Format a keystroke for display on the local system. | ||
* Format keystrokes for display on the local system. | ||
* | ||
* If a list of keystrokes is provided, it will be displayed as | ||
* a comma-separated string | ||
* | ||
* @param keystroke The keystrokes to format | ||
* @returns The keystrokes representation | ||
*/ | ||
function formatKeystroke(keystroke) { | ||
var mods = []; | ||
var separator = Platform.IS_MAC ? ' ' : '+'; | ||
var parts = parseKeystroke(keystroke); | ||
if (parts.ctrl) { | ||
mods.push('Ctrl'); | ||
return typeof keystroke === 'string' | ||
? formatSingleKey(keystroke) | ||
: keystroke.map(formatSingleKey).join(', '); | ||
function formatSingleKey(key) { | ||
var mods = []; | ||
var separator = Platform.IS_MAC ? ' ' : '+'; | ||
var parts = parseKeystroke(key); | ||
if (parts.ctrl) { | ||
mods.push('Ctrl'); | ||
} | ||
if (parts.alt) { | ||
mods.push('Alt'); | ||
} | ||
if (parts.shift) { | ||
mods.push('Shift'); | ||
} | ||
if (Platform.IS_MAC && parts.cmd) { | ||
mods.push('Cmd'); | ||
} | ||
mods.push(parts.key); | ||
return mods.map(Private.formatKey).join(separator); | ||
} | ||
if (parts.alt) { | ||
mods.push('Alt'); | ||
} | ||
if (parts.shift) { | ||
mods.push('Shift'); | ||
} | ||
if (Platform.IS_MAC && parts.cmd) { | ||
mods.push('Cmd'); | ||
} | ||
mods.push(parts.key); | ||
return mods.map(Private.formatKey).join(separator); | ||
} | ||
@@ -770,2 +817,3 @@ CommandRegistry.formatKeystroke = formatKeystroke; | ||
execute: options.execute, | ||
describedBy: __assign({ args: null }, options.describedBy), | ||
label: asFunc(options.label, emptyStringFunc), | ||
@@ -772,0 +820,0 @@ mnemonic: asFunc(options.mnemonic, negativeOneFunc), |
@@ -7,3 +7,28 @@ (function (global, factory) { | ||
// Copyright (c) Jupyter Development Team. | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
/** | ||
@@ -147,2 +172,13 @@ * An object which manages a collection of commands. | ||
/** | ||
* Get the description for a specific command. | ||
* | ||
* @param id - The id of the command of interest. | ||
* | ||
* @returns The description for the command. | ||
*/ | ||
CommandRegistry.prototype.describedBy = function (id) { | ||
var cmd = this._commands[id]; | ||
return cmd ? cmd.describedBy || { args: null } : { args: null }; | ||
}; | ||
/** | ||
* Get the display label for a specific command. | ||
@@ -671,22 +707,33 @@ * | ||
/** | ||
* Format a keystroke for display on the local system. | ||
* Format keystrokes for display on the local system. | ||
* | ||
* If a list of keystrokes is provided, it will be displayed as | ||
* a comma-separated string | ||
* | ||
* @param keystroke The keystrokes to format | ||
* @returns The keystrokes representation | ||
*/ | ||
function formatKeystroke(keystroke) { | ||
var mods = []; | ||
var separator = domutils.Platform.IS_MAC ? ' ' : '+'; | ||
var parts = parseKeystroke(keystroke); | ||
if (parts.ctrl) { | ||
mods.push('Ctrl'); | ||
return typeof keystroke === 'string' | ||
? formatSingleKey(keystroke) | ||
: keystroke.map(formatSingleKey).join(', '); | ||
function formatSingleKey(key) { | ||
var mods = []; | ||
var separator = domutils.Platform.IS_MAC ? ' ' : '+'; | ||
var parts = parseKeystroke(key); | ||
if (parts.ctrl) { | ||
mods.push('Ctrl'); | ||
} | ||
if (parts.alt) { | ||
mods.push('Alt'); | ||
} | ||
if (parts.shift) { | ||
mods.push('Shift'); | ||
} | ||
if (domutils.Platform.IS_MAC && parts.cmd) { | ||
mods.push('Cmd'); | ||
} | ||
mods.push(parts.key); | ||
return mods.map(Private.formatKey).join(separator); | ||
} | ||
if (parts.alt) { | ||
mods.push('Alt'); | ||
} | ||
if (parts.shift) { | ||
mods.push('Shift'); | ||
} | ||
if (domutils.Platform.IS_MAC && parts.cmd) { | ||
mods.push('Cmd'); | ||
} | ||
mods.push(parts.key); | ||
return mods.map(Private.formatKey).join(separator); | ||
} | ||
@@ -769,2 +816,3 @@ CommandRegistry.formatKeystroke = formatKeystroke; | ||
execute: options.execute, | ||
describedBy: __assign({ args: null }, options.describedBy), | ||
label: asFunc(options.label, emptyStringFunc), | ||
@@ -771,0 +819,0 @@ mnemonic: asFunc(options.mnemonic, negativeOneFunc), |
@@ -1,2 +0,16 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@lumino/algorithm"),require("@lumino/coreutils"),require("@lumino/disposable"),require("@lumino/domutils"),require("@lumino/keyboard"),require("@lumino/signaling")):"function"==typeof define&&define.amd?define(["exports","@lumino/algorithm","@lumino/coreutils","@lumino/disposable","@lumino/domutils","@lumino/keyboard","@lumino/signaling"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).lumino_commands={},e.lumino_algorithm,e.lumino_coreutils,e.lumino_disposable,e.lumino_domutils,e.lumino_keyboard,e.lumino_signaling)}(this,(function(e,t,n,i,o,r,a){"use strict";var s;e.CommandRegistry=function(){function e(){this._timerID=0,this._replaying=!1,this._keystrokes=[],this._keydownEvents=[],this._keyBindings=[],this._exactKeyMatch=null,this._commands=Object.create(null),this._commandChanged=new a.Signal(this),this._commandExecuted=new a.Signal(this),this._keyBindingChanged=new a.Signal(this)}return Object.defineProperty(e.prototype,"commandChanged",{get:function(){return this._commandChanged},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"commandExecuted",{get:function(){return this._commandExecuted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keyBindingChanged",{get:function(){return this._keyBindingChanged},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keyBindings",{get:function(){return this._keyBindings},enumerable:!0,configurable:!0}),e.prototype.listCommands=function(){return Object.keys(this._commands)},e.prototype.hasCommand=function(e){return e in this._commands},e.prototype.addCommand=function(e,t){var n=this;if(e in this._commands)throw new Error("Command '"+e+"' already registered.");return this._commands[e]=s.createCommand(t),this._commandChanged.emit({id:e,type:"added"}),new i.DisposableDelegate((function(){delete n._commands[e],n._commandChanged.emit({id:e,type:"removed"})}))},e.prototype.notifyCommandChanged=function(e){if(void 0!==e&&!(e in this._commands))throw new Error("Command '"+e+"' is not registered.");this._commandChanged.emit({id:e,type:e?"changed":"many-changed"})},e.prototype.label=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.label.call(void 0,t):""},e.prototype.mnemonic=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.mnemonic.call(void 0,t):-1},e.prototype.icon=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.icon.call(void 0,t):""},e.prototype.iconClass=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.iconClass.call(void 0,t):""},e.prototype.iconLabel=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.iconLabel.call(void 0,t):""},e.prototype.caption=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.caption.call(void 0,t):""},e.prototype.usage=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.usage.call(void 0,t):""},e.prototype.className=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.className.call(void 0,t):""},e.prototype.dataset=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.dataset.call(void 0,t):{}},e.prototype.isEnabled=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return!!i&&i.isEnabled.call(void 0,t)},e.prototype.isToggled=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return!!i&&i.isToggled.call(void 0,t)},e.prototype.isToggleable=function(e,t){var n=this._commands[e];return!!n&&n.isToggleable},e.prototype.isVisible=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return!!i&&i.isVisible.call(void 0,t)},e.prototype.execute=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i,o=this._commands[e];if(!o)return Promise.reject(new Error("Command '"+e+"' not registered."));try{i=o.execute.call(void 0,t)}catch(e){i=Promise.reject(e)}var r=Promise.resolve(i);return this._commandExecuted.emit({id:e,args:t,result:r}),r},e.prototype.addKeyBinding=function(e){var n=this,o=s.createKeyBinding(e);return this._keyBindings.push(o),this._keyBindingChanged.emit({binding:o,type:"added"}),new i.DisposableDelegate((function(){t.ArrayExt.removeFirstOf(n._keyBindings,o),n._keyBindingChanged.emit({binding:o,type:"removed"})}))},e.prototype.processKeydownEvent=function(t){if(!this._replaying&&!e.isModifierKeyPressed(t)){var n=e.keystrokeForKeydownEvent(t);if(!n)return this._replayKeydownEvents(),void this._clearPendingState();this._keystrokes.push(n);var i=s.matchKeyBinding(this._keyBindings,this._keystrokes,t),o=i.exact,r=i.partial;if(!o&&!r)return this._replayKeydownEvents(),void this._clearPendingState();if(t.preventDefault(),t.stopPropagation(),o&&!r)return this._executeKeyBinding(o),void this._clearPendingState();o&&(this._exactKeyMatch=o),this._keydownEvents.push(t),this._startTimer()}},e.prototype._startTimer=function(){var e=this;this._clearTimer(),this._timerID=window.setTimeout((function(){e._onPendingTimeout()}),s.CHORD_TIMEOUT)},e.prototype._clearTimer=function(){0!==this._timerID&&(clearTimeout(this._timerID),this._timerID=0)},e.prototype._replayKeydownEvents=function(){0!==this._keydownEvents.length&&(this._replaying=!0,this._keydownEvents.forEach(s.replayKeyEvent),this._replaying=!1)},e.prototype._executeKeyBinding=function(e){var t=e.command,n=e.args;if(this.hasCommand(t)&&this.isEnabled(t,n))this.execute(t,n);else{var i=this.hasCommand(t)?"enabled":"registered",o="Cannot execute key binding '"+e.keys.join(", ")+"':",r="command '"+t+"' is not "+i+".";console.warn(o+" "+r)}},e.prototype._clearPendingState=function(){this._clearTimer(),this._exactKeyMatch=null,this._keystrokes.length=0,this._keydownEvents.length=0},e.prototype._onPendingTimeout=function(){this._timerID=0,this._exactKeyMatch?this._executeKeyBinding(this._exactKeyMatch):this._replayKeydownEvents(),this._clearPendingState()},e}(),function(e){function t(e){for(var t="",n=!1,i=!1,r=!1,a=!1,s=0,c=e.split(/\s+/);s<c.length;s++){var l=c[s];"Accel"===l?o.Platform.IS_MAC?i=!0:r=!0:"Alt"===l?n=!0:"Cmd"===l?i=!0:"Ctrl"===l?r=!0:"Shift"===l?a=!0:l.length>0&&(t=l)}return{cmd:i,ctrl:r,alt:n,shift:a,key:t}}function n(e){var n="",i=t(e);return i.ctrl&&(n+="Ctrl "),i.alt&&(n+="Alt "),i.shift&&(n+="Shift "),i.cmd&&o.Platform.IS_MAC&&(n+="Cmd "),n+i.key}e.parseKeystroke=t,e.normalizeKeystroke=n,e.normalizeKeys=function(e){return(o.Platform.IS_WIN?e.winKeys||e.keys:o.Platform.IS_MAC?e.macKeys||e.keys:e.linuxKeys||e.keys).map(n)},e.formatKeystroke=function(e){var n=[],i=o.Platform.IS_MAC?" ":"+",r=t(e);return r.ctrl&&n.push("Ctrl"),r.alt&&n.push("Alt"),r.shift&&n.push("Shift"),o.Platform.IS_MAC&&r.cmd&&n.push("Cmd"),n.push(r.key),n.map(s.formatKey).join(i)},e.isModifierKeyPressed=function(e){var t=r.getKeyboardLayout(),n=t.keyForKeydownEvent(e);return t.isModifierKey(n)},e.keystrokeForKeydownEvent=function(e){var t=r.getKeyboardLayout(),n=t.keyForKeydownEvent(e);if(!n||t.isModifierKey(n))return"";var i=[];return e.ctrlKey&&i.push("Ctrl"),e.altKey&&i.push("Alt"),e.shiftKey&&i.push("Shift"),e.metaKey&&o.Platform.IS_MAC&&i.push("Cmd"),i.push(n),i.join(" ")}}(e.CommandRegistry||(e.CommandRegistry={})),function(t){t.CHORD_TIMEOUT=1e3,t.createCommand=function(e){var t,n;return e.icon&&"string"!=typeof e.icon?(n=u(e.iconClass,a),t=u(e.icon,m)):t=n=u(e.iconClass||e.icon,a),{execute:e.execute,label:u(e.label,a),mnemonic:u(e.mnemonic,s),icon:t,iconClass:n,iconLabel:u(e.iconLabel,a),caption:u(e.caption,a),usage:u(e.usage,a),className:u(e.className,a),dataset:u(e.dataset,d),isEnabled:e.isEnabled||c,isToggled:e.isToggled||l,isToggleable:e.isToggleable||!!e.isToggled,isVisible:e.isVisible||c}},t.createKeyBinding=function(t){return{keys:e.CommandRegistry.normalizeKeys(t),selector:y(t),command:t.command,args:t.args||n.JSONExt.emptyObject}},t.matchKeyBinding=function(e,t,n){for(var i=null,r=!1,a=1/0,s=0,c=0,l=e.length;c<l;++c){var d=e[c],m=h(d.keys,t);if(0!==m)if(2!==m){var u=p(d.selector,n);if(!(-1===u||u>a)){var y=o.Selector.calculateSpecificity(d.selector);(!i||u<a||y>=s)&&(i=d,a=u,s=y)}}else r||-1===p(d.selector,n)||(r=!0)}return{exact:i,partial:r}},t.replayKeyEvent=function(e){e.target.dispatchEvent(function(e){var t=document.createEvent("Event"),n=e.bubbles||!0,i=e.cancelable||!0;return t.initEvent(e.type||"keydown",n,i),t.key=e.key||"",t.keyCode=e.keyCode||0,t.which=e.keyCode||0,t.ctrlKey=e.ctrlKey||!1,t.altKey=e.altKey||!1,t.shiftKey=e.shiftKey||!1,t.metaKey=e.metaKey||!1,t.view=e.view||window,t}(e))},t.formatKey=function(e){return o.Platform.IS_MAC?i.hasOwnProperty(e)?i[e]:e:r.hasOwnProperty(e)?r[e]:e};var i={Backspace:"⌫",Tab:"⇥",Enter:"↩",Shift:"⇧",Ctrl:"⌃",Alt:"⌥",Escape:"⎋",PageUp:"⇞",PageDown:"⇟",End:"↘",Home:"↖",ArrowLeft:"←",ArrowUp:"↑",ArrowRight:"→",ArrowDown:"↓",Delete:"⌦",Cmd:"⌘"},r={Escape:"Esc",PageUp:"Page Up",PageDown:"Page Down",ArrowLeft:"Left",ArrowUp:"Up",ArrowRight:"Right",ArrowDown:"Down",Delete:"Del"},a=function(){return""},s=function(){return-1},c=function(){return!0},l=function(){return!1},d=function(){return{}},m=function(){};function u(e,t){return void 0===e?t:"function"==typeof e?e:function(){return e}}function y(e){if(-1!==e.selector.indexOf(","))throw new Error("Selector cannot contain commas: "+e.selector);if(!o.Selector.isValid(e.selector))throw new Error("Invalid selector: "+e.selector);return e.selector}function h(e,t){if(e.length<t.length)return 0;for(var n=0,i=t.length;n<i;++n)if(e[n]!==t[n])return 0;return e.length>t.length?2:1}function p(e,t){for(var n=t.target,i=t.currentTarget,r=0;null!==n;n=n.parentElement,++r){if(n.hasAttribute("data-lm-suppress-shortcuts"))return-1;if(n.hasAttribute("data-p-suppress-shortcuts"))return-1;if(o.Selector.matches(n,e))return r;if(n===i)return-1}return-1}}(s||(s={})),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@lumino/algorithm"),require("@lumino/coreutils"),require("@lumino/disposable"),require("@lumino/domutils"),require("@lumino/keyboard"),require("@lumino/signaling")):"function"==typeof define&&define.amd?define(["exports","@lumino/algorithm","@lumino/coreutils","@lumino/disposable","@lumino/domutils","@lumino/keyboard","@lumino/signaling"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).lumino_commands={},e.lumino_algorithm,e.lumino_coreutils,e.lumino_disposable,e.lumino_domutils,e.lumino_keyboard,e.lumino_signaling)}(this,(function(e,t,n,i,o,r,a){"use strict"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var s,c=function(){return c=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};e.CommandRegistry=function(){function e(){this._timerID=0,this._replaying=!1,this._keystrokes=[],this._keydownEvents=[],this._keyBindings=[],this._exactKeyMatch=null,this._commands=Object.create(null),this._commandChanged=new a.Signal(this),this._commandExecuted=new a.Signal(this),this._keyBindingChanged=new a.Signal(this)}return Object.defineProperty(e.prototype,"commandChanged",{get:function(){return this._commandChanged},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"commandExecuted",{get:function(){return this._commandExecuted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keyBindingChanged",{get:function(){return this._keyBindingChanged},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keyBindings",{get:function(){return this._keyBindings},enumerable:!0,configurable:!0}),e.prototype.listCommands=function(){return Object.keys(this._commands)},e.prototype.hasCommand=function(e){return e in this._commands},e.prototype.addCommand=function(e,t){var n=this;if(e in this._commands)throw new Error("Command '"+e+"' already registered.");return this._commands[e]=s.createCommand(t),this._commandChanged.emit({id:e,type:"added"}),new i.DisposableDelegate((function(){delete n._commands[e],n._commandChanged.emit({id:e,type:"removed"})}))},e.prototype.notifyCommandChanged=function(e){if(void 0!==e&&!(e in this._commands))throw new Error("Command '"+e+"' is not registered.");this._commandChanged.emit({id:e,type:e?"changed":"many-changed"})},e.prototype.describedBy=function(e){var t=this._commands[e];return t&&t.describedBy||{args:null}},e.prototype.label=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.label.call(void 0,t):""},e.prototype.mnemonic=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.mnemonic.call(void 0,t):-1},e.prototype.icon=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.icon.call(void 0,t):""},e.prototype.iconClass=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.iconClass.call(void 0,t):""},e.prototype.iconLabel=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.iconLabel.call(void 0,t):""},e.prototype.caption=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.caption.call(void 0,t):""},e.prototype.usage=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.usage.call(void 0,t):""},e.prototype.className=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.className.call(void 0,t):""},e.prototype.dataset=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return i?i.dataset.call(void 0,t):{}},e.prototype.isEnabled=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return!!i&&i.isEnabled.call(void 0,t)},e.prototype.isToggled=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return!!i&&i.isToggled.call(void 0,t)},e.prototype.isToggleable=function(e,t){var n=this._commands[e];return!!n&&n.isToggleable},e.prototype.isVisible=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i=this._commands[e];return!!i&&i.isVisible.call(void 0,t)},e.prototype.execute=function(e,t){void 0===t&&(t=n.JSONExt.emptyObject);var i,o=this._commands[e];if(!o)return Promise.reject(new Error("Command '"+e+"' not registered."));try{i=o.execute.call(void 0,t)}catch(e){i=Promise.reject(e)}var r=Promise.resolve(i);return this._commandExecuted.emit({id:e,args:t,result:r}),r},e.prototype.addKeyBinding=function(e){var n=this,o=s.createKeyBinding(e);return this._keyBindings.push(o),this._keyBindingChanged.emit({binding:o,type:"added"}),new i.DisposableDelegate((function(){t.ArrayExt.removeFirstOf(n._keyBindings,o),n._keyBindingChanged.emit({binding:o,type:"removed"})}))},e.prototype.processKeydownEvent=function(t){if(!this._replaying&&!e.isModifierKeyPressed(t)){var n=e.keystrokeForKeydownEvent(t);if(!n)return this._replayKeydownEvents(),void this._clearPendingState();this._keystrokes.push(n);var i=s.matchKeyBinding(this._keyBindings,this._keystrokes,t),o=i.exact,r=i.partial;if(!o&&!r)return this._replayKeydownEvents(),void this._clearPendingState();if(t.preventDefault(),t.stopPropagation(),o&&!r)return this._executeKeyBinding(o),void this._clearPendingState();o&&(this._exactKeyMatch=o),this._keydownEvents.push(t),this._startTimer()}},e.prototype._startTimer=function(){var e=this;this._clearTimer(),this._timerID=window.setTimeout((function(){e._onPendingTimeout()}),s.CHORD_TIMEOUT)},e.prototype._clearTimer=function(){0!==this._timerID&&(clearTimeout(this._timerID),this._timerID=0)},e.prototype._replayKeydownEvents=function(){0!==this._keydownEvents.length&&(this._replaying=!0,this._keydownEvents.forEach(s.replayKeyEvent),this._replaying=!1)},e.prototype._executeKeyBinding=function(e){var t=e.command,n=e.args;if(this.hasCommand(t)&&this.isEnabled(t,n))this.execute(t,n);else{var i=this.hasCommand(t)?"enabled":"registered",o="Cannot execute key binding '"+e.keys.join(", ")+"':",r="command '"+t+"' is not "+i+".";console.warn(o+" "+r)}},e.prototype._clearPendingState=function(){this._clearTimer(),this._exactKeyMatch=null,this._keystrokes.length=0,this._keydownEvents.length=0},e.prototype._onPendingTimeout=function(){this._timerID=0,this._exactKeyMatch?this._executeKeyBinding(this._exactKeyMatch):this._replayKeydownEvents(),this._clearPendingState()},e}(),function(e){function t(e){for(var t="",n=!1,i=!1,r=!1,a=!1,s=0,c=e.split(/\s+/);s<c.length;s++){var l=c[s];"Accel"===l?o.Platform.IS_MAC?i=!0:r=!0:"Alt"===l?n=!0:"Cmd"===l?i=!0:"Ctrl"===l?r=!0:"Shift"===l?a=!0:l.length>0&&(t=l)}return{cmd:i,ctrl:r,alt:n,shift:a,key:t}}function n(e){var n="",i=t(e);return i.ctrl&&(n+="Ctrl "),i.alt&&(n+="Alt "),i.shift&&(n+="Shift "),i.cmd&&o.Platform.IS_MAC&&(n+="Cmd "),n+i.key}e.parseKeystroke=t,e.normalizeKeystroke=n,e.normalizeKeys=function(e){return(o.Platform.IS_WIN?e.winKeys||e.keys:o.Platform.IS_MAC?e.macKeys||e.keys:e.linuxKeys||e.keys).map(n)},e.formatKeystroke=function(e){return"string"==typeof e?n(e):e.map(n).join(", ");function n(e){var n=[],i=o.Platform.IS_MAC?" ":"+",r=t(e);return r.ctrl&&n.push("Ctrl"),r.alt&&n.push("Alt"),r.shift&&n.push("Shift"),o.Platform.IS_MAC&&r.cmd&&n.push("Cmd"),n.push(r.key),n.map(s.formatKey).join(i)}},e.isModifierKeyPressed=function(e){var t=r.getKeyboardLayout(),n=t.keyForKeydownEvent(e);return t.isModifierKey(n)},e.keystrokeForKeydownEvent=function(e){var t=r.getKeyboardLayout(),n=t.keyForKeydownEvent(e);if(!n||t.isModifierKey(n))return"";var i=[];return e.ctrlKey&&i.push("Ctrl"),e.altKey&&i.push("Alt"),e.shiftKey&&i.push("Shift"),e.metaKey&&o.Platform.IS_MAC&&i.push("Cmd"),i.push(n),i.join(" ")}}(e.CommandRegistry||(e.CommandRegistry={})),function(t){t.CHORD_TIMEOUT=1e3,t.createCommand=function(e){var t,n;return e.icon&&"string"!=typeof e.icon?(n=y(e.iconClass,a),t=y(e.icon,m)):t=n=y(e.iconClass||e.icon,a),{execute:e.execute,describedBy:c({args:null},e.describedBy),label:y(e.label,a),mnemonic:y(e.mnemonic,s),icon:t,iconClass:n,iconLabel:y(e.iconLabel,a),caption:y(e.caption,a),usage:y(e.usage,a),className:y(e.className,a),dataset:y(e.dataset,u),isEnabled:e.isEnabled||l,isToggled:e.isToggled||d,isToggleable:e.isToggleable||!!e.isToggled,isVisible:e.isVisible||l}},t.createKeyBinding=function(t){return{keys:e.CommandRegistry.normalizeKeys(t),selector:h(t),command:t.command,args:t.args||n.JSONExt.emptyObject}},t.matchKeyBinding=function(e,t,n){for(var i=null,r=!1,a=1/0,s=0,c=0,l=e.length;c<l;++c){var d=e[c],u=p(d.keys,t);if(0!==u)if(2!==u){var m=f(d.selector,n);if(!(-1===m||m>a)){var y=o.Selector.calculateSpecificity(d.selector);(!i||m<a||y>=s)&&(i=d,a=m,s=y)}}else r||-1===f(d.selector,n)||(r=!0)}return{exact:i,partial:r}},t.replayKeyEvent=function(e){e.target.dispatchEvent(function(e){var t=document.createEvent("Event"),n=e.bubbles||!0,i=e.cancelable||!0;return t.initEvent(e.type||"keydown",n,i),t.key=e.key||"",t.keyCode=e.keyCode||0,t.which=e.keyCode||0,t.ctrlKey=e.ctrlKey||!1,t.altKey=e.altKey||!1,t.shiftKey=e.shiftKey||!1,t.metaKey=e.metaKey||!1,t.view=e.view||window,t}(e))},t.formatKey=function(e){return o.Platform.IS_MAC?i.hasOwnProperty(e)?i[e]:e:r.hasOwnProperty(e)?r[e]:e};var i={Backspace:"⌫",Tab:"⇥",Enter:"↩",Shift:"⇧",Ctrl:"⌃",Alt:"⌥",Escape:"⎋",PageUp:"⇞",PageDown:"⇟",End:"↘",Home:"↖",ArrowLeft:"←",ArrowUp:"↑",ArrowRight:"→",ArrowDown:"↓",Delete:"⌦",Cmd:"⌘"},r={Escape:"Esc",PageUp:"Page Up",PageDown:"Page Down",ArrowLeft:"Left",ArrowUp:"Up",ArrowRight:"Right",ArrowDown:"Down",Delete:"Del"},a=function(){return""},s=function(){return-1},l=function(){return!0},d=function(){return!1},u=function(){return{}},m=function(){};function y(e,t){return void 0===e?t:"function"==typeof e?e:function(){return e}}function h(e){if(-1!==e.selector.indexOf(","))throw new Error("Selector cannot contain commas: "+e.selector);if(!o.Selector.isValid(e.selector))throw new Error("Invalid selector: "+e.selector);return e.selector}function p(e,t){if(e.length<t.length)return 0;for(var n=0,i=t.length;n<i;++n)if(e[n]!==t[n])return 0;return e.length>t.length?2:1}function f(e,t){for(var n=t.target,i=t.currentTarget,r=0;null!==n;n=n.parentElement,++r){if(n.hasAttribute("data-lm-suppress-shortcuts"))return-1;if(n.hasAttribute("data-p-suppress-shortcuts"))return-1;if(o.Selector.matches(n,e))return r;if(n===i)return-1}return-1}}(s||(s={})),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@lumino/commands", | ||
"version": "1.20.1", | ||
"version": "1.21.0", | ||
"description": "Lumino Commands", | ||
@@ -58,7 +58,7 @@ "homepage": "https://github.com/jupyterlab/lumino", | ||
"@lumino/coreutils": "^1.12.1", | ||
"@lumino/disposable": "^1.10.2", | ||
"@lumino/disposable": "^1.10.3", | ||
"@lumino/domutils": "^1.8.2", | ||
"@lumino/keyboard": "^1.8.2", | ||
"@lumino/signaling": "^1.10.2", | ||
"@lumino/virtualdom": "^1.14.2" | ||
"@lumino/signaling": "^1.11.0", | ||
"@lumino/virtualdom": "^1.14.3" | ||
}, | ||
@@ -65,0 +65,0 @@ "devDependencies": { |
@@ -155,2 +155,14 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
* Get the description for a specific command. | ||
* | ||
* @param id - The id of the command of interest. | ||
* | ||
* @returns The description for the command. | ||
*/ | ||
describedBy(id: string): { args: ReadonlyJSONObject | null } { | ||
let cmd = this._commands[id]; | ||
return cmd ? cmd.describedBy || { args: null } : { args: null }; | ||
} | ||
/** | ||
* Get the display label for a specific command. | ||
@@ -698,2 +710,11 @@ * | ||
/** | ||
* JSON Schemas describing the command. | ||
* | ||
* #### Notes | ||
* For now, the command arguments are the only one that can be | ||
* described. | ||
*/ | ||
describedBy?: { args?: ReadonlyJSONObject }; | ||
/** | ||
* The label for the command. | ||
@@ -1174,22 +1195,36 @@ * | ||
/** | ||
* Format a keystroke for display on the local system. | ||
* Format keystrokes for display on the local system. | ||
* | ||
* If a list of keystrokes is provided, it will be displayed as | ||
* a comma-separated string | ||
* | ||
* @param keystroke The keystrokes to format | ||
* @returns The keystrokes representation | ||
*/ | ||
export function formatKeystroke(keystroke: string): string { | ||
let mods = []; | ||
let separator = Platform.IS_MAC ? ' ' : '+'; | ||
let parts = parseKeystroke(keystroke); | ||
if (parts.ctrl) { | ||
mods.push('Ctrl'); | ||
export function formatKeystroke( | ||
keystroke: string | readonly string[] | ||
): string { | ||
return typeof keystroke === 'string' | ||
? formatSingleKey(keystroke) | ||
: keystroke.map(formatSingleKey).join(', '); | ||
function formatSingleKey(key: string) { | ||
let mods = []; | ||
let separator = Platform.IS_MAC ? ' ' : '+'; | ||
let parts = parseKeystroke(key); | ||
if (parts.ctrl) { | ||
mods.push('Ctrl'); | ||
} | ||
if (parts.alt) { | ||
mods.push('Alt'); | ||
} | ||
if (parts.shift) { | ||
mods.push('Shift'); | ||
} | ||
if (Platform.IS_MAC && parts.cmd) { | ||
mods.push('Cmd'); | ||
} | ||
mods.push(parts.key); | ||
return mods.map(Private.formatKey).join(separator); | ||
} | ||
if (parts.alt) { | ||
mods.push('Alt'); | ||
} | ||
if (parts.shift) { | ||
mods.push('Shift'); | ||
} | ||
if (Platform.IS_MAC && parts.cmd) { | ||
mods.push('Cmd'); | ||
} | ||
mods.push(parts.key); | ||
return mods.map(Private.formatKey).join(separator); | ||
} | ||
@@ -1266,2 +1301,3 @@ | ||
readonly execute: CommandFunc<any>; | ||
readonly describedBy: { args: ReadonlyJSONObject | null }; | ||
readonly label: CommandFunc<string>; | ||
@@ -1315,2 +1351,3 @@ readonly mnemonic: CommandFunc<number>; | ||
execute: options.execute, | ||
describedBy: { args: null, ...options.describedBy }, | ||
label: asFunc(options.label, emptyStringFunc), | ||
@@ -1317,0 +1354,0 @@ mnemonic: asFunc(options.mnemonic, negativeOneFunc), |
@@ -81,2 +81,12 @@ import { ReadonlyJSONObject, ReadonlyPartialJSONObject } from '@lumino/coreutils'; | ||
/** | ||
* Get the description for a specific command. | ||
* | ||
* @param id - The id of the command of interest. | ||
* | ||
* @returns The description for the command. | ||
*/ | ||
describedBy(id: string): { | ||
args: ReadonlyJSONObject | null; | ||
}; | ||
/** | ||
* Get the display label for a specific command. | ||
@@ -360,2 +370,12 @@ * | ||
/** | ||
* JSON Schemas describing the command. | ||
* | ||
* #### Notes | ||
* For now, the command arguments are the only one that can be | ||
* described. | ||
*/ | ||
describedBy?: { | ||
args?: ReadonlyJSONObject; | ||
}; | ||
/** | ||
* The label for the command. | ||
@@ -735,5 +755,11 @@ * | ||
/** | ||
* Format a keystroke for display on the local system. | ||
* Format keystrokes for display on the local system. | ||
* | ||
* If a list of keystrokes is provided, it will be displayed as | ||
* a comma-separated string | ||
* | ||
* @param keystroke The keystrokes to format | ||
* @returns The keystrokes representation | ||
*/ | ||
function formatKeystroke(keystroke: string): string; | ||
function formatKeystroke(keystroke: string | readonly string[]): string; | ||
/** | ||
@@ -740,0 +766,0 @@ * Check if `'keydown'` event is caused by pressing a modifier key that should be ignored. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
412810
4449
0
Updated@lumino/disposable@^1.10.3
Updated@lumino/signaling@^1.11.0
Updated@lumino/virtualdom@^1.14.3