react-microspreadsheet
Version:
A pluggable spreadsheet component.
169 lines (142 loc) • 5.35 kB
JavaScript
// Generated by CoffeeScript 1.8.0
var Dispatcher, EventEmitter, Mousetrap, dispatcher,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
if (typeof window !== 'undefined') {
Mousetrap = require('mousetrap');
}
EventEmitter = require('wolfy-eventemitter');
if (EventEmitter.EventEmitter) {
EventEmitter = EventEmitter.EventEmitter;
}
Dispatcher = (function(_super) {
__extends(Dispatcher, _super);
function Dispatcher() {
return Dispatcher.__super__.constructor.apply(this, arguments);
}
Dispatcher.prototype.construct = function() {};
Dispatcher.prototype.replaceCells = function(cellsArray) {
return this.emit('replace-cells', cellsArray);
};
Dispatcher.prototype.handleCellDoubleClicked = function(coord) {
return this.emit('cell-doubleclicked', coord);
};
Dispatcher.prototype.handleCellClicked = function(coord) {
return this.emit('cell-clicked', coord);
};
Dispatcher.prototype.handleCellMouseDown = function(coord) {
return this.emit('cell-mousedown', coord);
};
Dispatcher.prototype.handleMouseDownStrap = function(coord) {
return this.emit('strap-mousedown', coord);
};
Dispatcher.prototype.handleCellMouseUp = function(coord) {
return this.emit('cell-mouseup', coord);
};
Dispatcher.prototype.handleCellMouseEnter = function(coord) {
return this.emit('cell-mouseenter', coord);
};
Dispatcher.prototype.handleCellEdited = function(value) {
return this.emit('new-cell-value', value);
};
Dispatcher.prototype.handleCellInputClicked = function(e) {
return this.emit('input-clicked', e.target);
};
Dispatcher.prototype.handleCellInputDoubleClicked = function(e) {
return this.emit('input-doubleclicked', e.target);
};
Dispatcher.prototype.handleSelectText = function(e) {
return this.emit('input-selecttext', e.target);
};
Dispatcher.prototype.handleSheetClickedOut = function(e) {
return this.emit('sheet-clicked-out', e);
};
Dispatcher.prototype.handleSheetMouseUpOut = function(e) {
return this.emit('sheet-mouseup-out', e);
};
Dispatcher.prototype.handleClipboardChanged = function(value) {
return this.emit('clipboardchanged', value);
};
Dispatcher.prototype.initKeyboardShortcuts = function() {
var eventChannel, keydown, keypress, keyup, shortcut, _fn, _fn1, _results;
keyup = {
'all-down': ['command+down', 'ctrl+down'],
'all-up': ['command+up', 'ctrl+up'],
'all-left': ['command+left', 'ctrl+left'],
'all-right': ['command+right', 'ctrl+right'],
'left-keyup': 'left',
'right-keyup': 'right',
'del': 'del',
'undo': 'ctrl+z',
'redo': 'ctrl+y',
'esc': 'esc',
'after-copypaste': ['ctrl', 'command']
};
_fn = (function(_this) {
return function() {
var channel;
channel = eventChannel;
return Mousetrap.bind(shortcut, function(e, combo) {
return _this.emit(channel, e, combo);
}, 'keyup');
};
})(this);
for (eventChannel in keyup) {
shortcut = keyup[eventChannel];
_fn();
}
keydown = {
'down': ['down', 'enter'],
'up': 'up',
'left': 'left',
'right': 'right',
'tab': 'tab',
'select-down': 'shift+down',
'select-up': 'shift+up',
'select-left': 'shift+left',
'select-right': 'shift+right',
'select-all-down': ['ctrl+shift+down', 'command+shift+down'],
'select-all-up': ['ctrl+shift+up', 'command+shift+up'],
'select-all-left': ['ctrl+shift+left', 'command+shift+left'],
'select-all-right': ['ctrl+shift+right', 'command+shift+right'],
'before-copypaste': ['ctrl', 'command'],
'cutcopy': ['ctrl+c', 'command+c', 'ctrl+x', 'command+x']
};
_fn1 = (function(_this) {
return function() {
var channel;
channel = eventChannel;
return Mousetrap.bind(shortcut, function(e, combo) {
return _this.emit(channel, e, combo);
}, 'keydown');
};
})(this);
for (eventChannel in keydown) {
shortcut = keydown[eventChannel];
_fn1();
}
keypress = {
'letter': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'w', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '=', '.', ',', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'W', 'Y', 'Z']
};
_results = [];
for (eventChannel in keypress) {
shortcut = keypress[eventChannel];
_results.push(((function(_this) {
return function() {
var channel;
channel = eventChannel;
return Mousetrap.bind(shortcut, function(e, combo) {
return _this.emit(channel, e, combo);
}, 'keypress');
};
})(this))());
}
return _results;
};
return Dispatcher;
})(EventEmitter);
dispatcher = new Dispatcher;
if (typeof window !== 'undefined') {
dispatcher.initKeyboardShortcuts();
}
module.exports = dispatcher;