1 var _typeof = typeof Symbol ===
"function" && typeof Symbol.iterator ===
"symbol" ?
function (obj) {
return typeof obj; } :
function (obj) {
return obj && typeof Symbol ===
"function" && obj.constructor === Symbol && obj !== Symbol.prototype ?
"symbol" : typeof obj; };
5 var Keybindings =
function Keybindings(table) {
8 this.pressedKeys = null;
9 this.keyupBinding =
false;
10 this.keydownBinding =
false;
13 Keybindings.prototype.initialize =
function () {
14 var bindings = this.table.options.keybindings,
18 this.pressedKeys = [];
20 if (bindings !==
false) {
22 for (var key in this.bindings) {
23 mergedBindings[key] = this.bindings[key];
26 if (Object.keys(bindings).length) {
28 for (var _key in bindings) {
29 mergedBindings[_key] = bindings[_key];
33 this.mapBindings(mergedBindings);
38 Keybindings.prototype.mapBindings =
function (bindings) {
43 var _loop =
function _loop(key) {
45 if (_this.actions[key]) {
49 if (_typeof(bindings[key]) !==
"object") {
50 bindings[key] = [bindings[key]];
53 bindings[key].forEach(
function (binding) {
54 self.mapBinding(key, binding);
58 console.warn(
"Key Binding Error - no such action:", key);
62 for (var key in bindings) {
67 Keybindings.prototype.mapBinding =
function (action, symbolsList) {
71 action: this.actions[action],
77 var symbols = symbolsList.toString().toLowerCase().split(
" ").join(
"").split(
"+");
79 symbols.forEach(
function (symbol) {
90 symbol = parseInt(symbol);
91 binding.keys.push(symbol);
93 if (!
self.watchKeys[symbol]) {
94 self.watchKeys[symbol] = [];
97 self.watchKeys[symbol].push(binding);
102 Keybindings.prototype.bindEvents =
function () {
105 this.keyupBinding =
function (e) {
106 var code = e.keyCode;
107 var bindings =
self.watchKeys[code];
111 self.pressedKeys.push(code);
113 bindings.forEach(
function (binding) {
114 self.checkBinding(e, binding);
119 this.keydownBinding =
function (e) {
120 var code = e.keyCode;
121 var bindings =
self.watchKeys[code];
125 var index =
self.pressedKeys.indexOf(code);
128 self.pressedKeys.splice(index, 1);
133 this.table.element.addEventListener(
"keydown", this.keyupBinding);
135 this.table.element.addEventListener(
"keyup", this.keydownBinding);
138 Keybindings.prototype.clearBindings =
function () {
139 if (this.keyupBinding) {
140 this.table.element.removeEventListener(
"keydown", this.keyupBinding);
143 if (this.keydownBinding) {
144 this.table.element.removeEventListener(
"keyup", this.keydownBinding);
148 Keybindings.prototype.checkBinding =
function (e, binding) {
152 if (e.ctrlKey == binding.ctrl && e.shiftKey == binding.shift) {
153 binding.keys.forEach(
function (key) {
154 var index =
self.pressedKeys.indexOf(key);
162 binding.action.call(
self, e);
172 Keybindings.prototype.bindings = {
173 navPrev:
"shift + 9",
183 copyToClipboard:
"ctrl + 67"
187 Keybindings.prototype.actions = {
188 keyBlock:
function keyBlock(e) {
192 scrollPageUp:
function scrollPageUp(e) {
193 var rowManager = this.table.rowManager,
194 newPos = rowManager.scrollTop - rowManager.height,
195 scrollMax = rowManager.element.scrollHeight;
199 if (rowManager.displayRowsCount) {
201 rowManager.element.scrollTop = newPos;
203 rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
207 this.table.element.focus();
209 scrollPageDown:
function scrollPageDown(e) {
210 var rowManager = this.table.rowManager,
211 newPos = rowManager.scrollTop + rowManager.height,
212 scrollMax = rowManager.element.scrollHeight;
216 if (rowManager.displayRowsCount) {
217 if (newPos <= scrollMax) {
218 rowManager.element.scrollTop = newPos;
220 rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
224 this.table.element.focus();
226 scrollToStart:
function scrollToStart(e) {
227 var rowManager = this.table.rowManager;
231 if (rowManager.displayRowsCount) {
232 rowManager.scrollToRow(rowManager.getDisplayRows()[0]);
235 this.table.element.focus();
237 scrollToEnd:
function scrollToEnd(e) {
238 var rowManager = this.table.rowManager;
242 if (rowManager.displayRowsCount) {
243 rowManager.scrollToRow(rowManager.getDisplayRows()[rowManager.displayRowsCount - 1]);
246 this.table.element.focus();
248 navPrev:
function navPrev(e) {
251 if (this.table.modExists(
"edit")) {
252 cell = this.table.modules.edit.currentCell;
261 navNext:
function navNext(e) {
263 var newRow = this.table.options.tabEndNewRow;
266 if (this.table.modExists(
"edit")) {
267 cell = this.table.modules.edit.currentCell;
276 if (newRow ===
true) {
277 newRow = this.table.addRow({});
279 if (typeof newRow ==
"function") {
280 newRow = this.table.addRow(newRow(cell.row.getComponent()));
282 newRow = this.table.addRow(newRow);
286 newRow.then(
function () {
295 navLeft:
function navLeft(e) {
298 if (this.table.modExists(
"edit")) {
299 cell = this.table.modules.edit.currentCell;
308 navRight:
function navRight(e) {
311 if (this.table.modExists(
"edit")) {
312 cell = this.table.modules.edit.currentCell;
321 navUp:
function navUp(e) {
324 if (this.table.modExists(
"edit")) {
325 cell = this.table.modules.edit.currentCell;
334 navDown:
function navDown(e) {
337 if (this.table.modExists(
"edit")) {
338 cell = this.table.modules.edit.currentCell;
347 undo:
function undo(e) {
349 if (this.table.options.history &&
this.table.modExists(
"history") && this.table.modExists(
"edit")) {
351 cell = this.table.modules.edit.currentCell;
355 this.table.modules.history.undo();
360 redo:
function redo(e) {
362 if (this.table.options.history &&
this.table.modExists(
"history") && this.table.modExists(
"edit")) {
364 cell = this.table.modules.edit.currentCell;
368 this.table.modules.history.redo();
373 copyToClipboard:
function copyToClipboard(e) {
374 if (!this.table.modules.edit.currentCell) {
375 if (this.table.modExists(
"clipboard",
true)) {
376 this.table.modules.clipboard.copy(!this.table.options.selectable ||
this.table.options.selectable ==
"highlight" ?
"active" :
"selected", null, null, null,
true);
382 Tabulator.prototype.registerModule(
"keybindings", Keybindings);