UNPKG

@true-directive/base

Version:

The set of base classes for the TrueDirective Grid

112 lines (111 loc) 3.66 kB
/** * Copyright (c) 2018-2019 Aleksey Melnikov, True Directive Company. * @link https://truedirective.com/ * @license MIT */ var KeyInfo = /** @class */ (function () { function KeyInfo(code, char) { if (char === void 0) { char = ''; } this.code = code; this.char = char; } return KeyInfo; }()); export { KeyInfo }; // @dynamic var Keys = /** @class */ (function () { function Keys() { } Keys.isFunctional = function (keyCode) { return keyCode >= 112 && keyCode <= 123; }; Keys.keyChar = function (e) { if (e === null) { return ''; } // These chars are useless for us.. if (e.keyCode > 0 && e.keyCode < 32) { return ''; } var c = e.char; if (c === undefined) { c = e.key; } return c; }; Keys.generateEvent = function (target, keyCode, keyChar, shift, ctrl) { if (keyChar === void 0) { keyChar = ''; } if (shift === void 0) { shift = false; } if (ctrl === void 0) { ctrl = false; } return { keyCode: keyCode, key: keyChar, char: keyChar, shiftKey: shift, ctrlKey: ctrl, target: target, preventDefault: function (_) { } }; }; // For Android Keys.whichKeyHasBeenPressed = function (txt1, txt2, selStart1, selStart2, selLength) { if (txt1 === txt2 && selStart1 === selStart2 - 1) { return new KeyInfo(Keys.RIGHT); } if (txt1 === txt2 && selStart1 === selStart2 + 1) { return new KeyInfo(Keys.LEFT); } if (selLength === 1) { // if (txt1.substring(0, selStart2) === txt2.substring(0, selStart2)) { if (txt1.substring(selStart2 + 1, txt1.length) === txt2.substring(selStart2, txt2.length)) { return new KeyInfo(Keys.BACKSPACE); } } if (txt1.substring(0, selStart2) === txt2.substring(0, selStart2)) { if (txt1.substring(selStart1 + 1, txt1.length) === txt2.substring(selStart2, txt2.length)) { if (selStart1 === selStart2 + 1) { return new KeyInfo(Keys.BACKSPACE); } } } return new KeyInfo(0, txt2.substring(selStart1, selStart1 + 1)); } // Tes|t -> Te|t if (txt1.substring(0, selStart1 - 1) === txt2.substring(0, selStart1 - 1)) { if (txt1.substring(selStart1, txt1.length) === txt2.substring(selStart1 - 1, txt2.length)) { return new KeyInfo(Keys.BACKSPACE); } } // Te|st -> Te|t if (txt1.substring(0, selStart1) === txt2.substring(0, selStart1)) { if (txt1.substring(selStart1 + 1, txt1.length) === txt2.substring(selStart1, txt2.length)) { return new KeyInfo(Keys.DELETE); } } return new KeyInfo(0, txt2.substring(selStart1, selStart1 + 1)); }; Keys.BACKSPACE = 8; Keys.TAB = 9; Keys.ENTER = 13; Keys.ESCAPE = 27; Keys.SPACE = 32; Keys.PAGE_UP = 33; Keys.PAGE_DOWN = 34; Keys.END = 35; Keys.HOME = 36; Keys.LEFT = 37; Keys.UP = 38; Keys.RIGHT = 39; Keys.DOWN = 40; Keys.INSERT = 45; Keys.DELETE = 46; Keys.A = 65; Keys.C = 67; Keys.V = 86; Keys.X = 88; Keys.Y = 89; Keys.Z = 90; return Keys; }()); export { Keys };