@alilc/lowcode-shell
Version:
Shell Layer for AliLowCodeEngine
64 lines (62 loc) • 1.72 kB
JavaScript
import _createClass from "@babel/runtime/helpers/createClass";
import { globalContext } from '@alilc/lowcode-editor-core';
import { hotkeySymbol } from '../symbols';
var innerHotkeySymbol = Symbol('innerHotkey');
export var Hotkey = /*#__PURE__*/function () {
function Hotkey(hotkey, workspaceMode) {
if (workspaceMode === void 0) {
workspaceMode = false;
}
this.workspaceMode = workspaceMode;
this[innerHotkeySymbol] = void 0;
this[innerHotkeySymbol] = hotkey;
}
var _proto = Hotkey.prototype;
/**
* 绑定快捷键
* @param combos 快捷键,格式如:['command + s'] 、['ctrl + shift + s'] 等
* @param callback 回调函数
* @param action
* @returns
*/
_proto.bind = function bind(combos, callback, action) {
var _this = this;
this[hotkeySymbol].bind(combos, callback, action);
return function () {
_this[hotkeySymbol].unbind(combos, callback, action);
};
}
/**
* 给指定窗口绑定快捷键
* @param window 窗口的 window 对象
*/;
_proto.mount = function mount(window) {
return this[hotkeySymbol].mount(window);
};
return _createClass(Hotkey, [{
key: hotkeySymbol,
get: function get() {
if (this.workspaceMode) {
return this[innerHotkeySymbol];
}
var workspace = globalContext.get('workspace');
if (workspace.isActive) {
return workspace.window.innerHotkey;
}
return this[innerHotkeySymbol];
}
}, {
key: "callbacks",
get: function get() {
return this[hotkeySymbol].callBacks;
}
/**
* @deprecated
*/
}, {
key: "callBacks",
get: function get() {
return this.callbacks;
}
}]);
}();