2 Star 0 Fork 0

mirrors_jprichardson/ethercalc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sc.js 19.88 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
// Generated by LiveScript 1.2.0
(function(){
var vm, fs, path, bootSC, argv, IsThreaded, Worker, e, replace$ = ''.replace;
vm = require('vm');
fs = require('fs');
path = require('path');
bootSC = fs.readFileSync(path.dirname(fs.realpathSync(__filename)) + "/SocialCalcModule.js", 'utf8');
global.SC == null && (global.SC = {});
argv = (function(){
try {
return require('optimist').boolean(['vm', 'polling']).argv;
} catch (e$) {}
}()) || {};
bootSC += ";(" + function(){
var Node;
Node = (function(){
Node.displayName = 'Node';
var prototype = Node.prototype, constructor = Node;
function Node(tag, attrs, style, elems, raw){
this.tag = tag != null ? tag : "div";
this.attrs = attrs != null
? attrs
: {};
this.style = style != null
? style
: {};
this.elems = elems != null
? elems
: [];
this.raw = raw != null ? raw : '';
}
Object.defineProperty(prototype, 'id', {
set: function(id){
this.attrs.id = id;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'width', {
set: function(width){
this.attrs.width = width;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'height', {
set: function(height){
this.attrs.height = height;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'className', {
set: function($class){
this.attrs['class'] = $class;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'colSpan', {
set: function(colspan){
this.attrs.colspan = colspan;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'rowSpan', {
set: function(rowspan){
this.attrs.rowspan = rowspan;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'title', {
set: function(title){
this.attrs.title = title;
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'innerHTML', {
set: function(raw){
this.raw = raw;
},
get: function(){
var e;
return this.raw || (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = this.elems).length; i$ < len$; ++i$) {
e = ref$[i$];
results$.push(e.outerHTML);
}
return results$;
}.call(this)).join("\n");
},
configurable: true,
enumerable: true
});
Object.defineProperty(prototype, 'outerHTML', {
get: function(){
var tag, attrs, style, css, k, v;
tag = this.tag, attrs = this.attrs, style = this.style;
css = style.cssText || (function(){
var ref$, results$ = [];
for (k in ref$ = style) {
v = ref$[k];
results$.push(k.replace(/[A-Z]/g, '-$&').toLowerCase() + ":" + v);
}
return results$;
}()).join(";");
if (css) {
attrs.style = css;
} else {
delete attrs.style;
}
return "<" + tag + (function(){
var ref$, results$ = [];
for (k in ref$ = attrs) {
v = ref$[k];
results$.push(" " + k + "=\"" + v + "\"");
}
return results$;
}()).join('') + ">" + this.innerHTML + "</" + tag + ">";
},
configurable: true,
enumerable: true
});
prototype.appendChild = function(it){
return this.elems.push(it);
};
return Node;
}());
return SocialCalc.document.createElement = function(it){
return new Node(it);
};
} + ")();";
IsThreaded = true;
Worker = (function(){
try {
if (argv.vm) {
throw 'vm';
}
console.log("Starting backend using webworker-threads");
return require('webworker-threads').Worker;
} catch (e$) {
e = e$;
console.log("Falling back to vm.CreateContext backend");
return IsThreaded = false;
}
}());
Worker || (Worker = (function(){
Worker.displayName = 'Worker';
var prototype = Worker.prototype, constructor = Worker;
function Worker(code){
var cxt, sandbox, this$ = this;
cxt = {
console: console,
self: {
onmessage: function(){}
}
};
cxt.window = {
setTimeout: function(cb, ms){
return process.nextTick(cb);
},
clearTimeout: function(){}
};
this.postMessage = function(data){
return sandbox.self.onmessage({
data: data
});
};
this.thread = cxt.thread = {
nextTick: function(cb){
return process.nextTick(cb);
},
eval: function(src, cb){
var rv, e;
try {
rv = vm.runInContext(src, sandbox);
return typeof cb === 'function' ? cb(null, rv) : void 8;
} catch (e$) {
e = e$;
console.log("e " + e);
return typeof cb === 'function' ? cb(e) : void 8;
}
}
};
this.terminate = function(){};
this.sandbox = sandbox = vm.createContext(cxt);
sandbox.postMessage = function(data){
return typeof this$.onmessage === 'function' ? this$.onmessage({
data: data
}) : void 8;
};
if (code) {
vm.runInContext("(" + code + ")()", sandbox);
}
return this;
}
return Worker;
}()));
this.include = function(){
var DB, EXPIRE;
DB = this.include('db');
EXPIRE = this.EXPIRE;
SC.csvToSave = function(csv, cb){
var w;
w = new Worker;
return w.thread.eval(bootSC, function(){
return w.thread.eval("SocialCalc.ConvertOtherFormatToSave(" + JSON.stringify(csv) + ", 'csv')", function(arg$, rv){
return cb(rv);
});
});
};
SC._get = function(room, io, cb){
var ref$, this$ = this;
if ((ref$ = SC[room]) != null && ref$._snapshot) {
return cb({
snapshot: SC[room]._snapshot
});
}
return DB.multi().get("snapshot-" + room).lrange("log-" + room, 0, -1).exec(function(arg$, arg1$){
var snapshot, log;
snapshot = arg1$[0], log = arg1$[1];
if (EXPIRE) {
DB.expire("snapshot-" + room, EXPIRE);
}
if ((snapshot || log.length) && io) {
SC[room] = SC._init(snapshot, log, DB, room, io);
}
return cb({
log: log,
snapshot: snapshot
});
});
};
SC._put = function(room, snapshot, cb){
var this$ = this;
if (!snapshot) {
return typeof cb === 'function' ? cb() : void 8;
}
return DB.multi().set("snapshot-" + room, snapshot).del(["log-" + room, "chat-" + room, "ecell-" + room, "audit-" + room]).bgsave().exec(function(){
if (EXPIRE) {
DB.expire("snapshot-" + room, EXPIRE);
}
return typeof cb === 'function' ? cb() : void 8;
});
};
SC._init = function(snapshot, log, DB, room, io){
var w, this$ = this;
log == null && (log = []);
if (SC[room] != null) {
SC[room]._doClearCache();
return SC[room];
}
w = new Worker(function(){
return self.onmessage = function(arg$){
var ref$, type, ref, snapshot, command, room, log, ref1$, csv, ss, parts, cmdstr, line;
ref$ = arg$.data, type = ref$.type, ref = ref$.ref, snapshot = ref$.snapshot, command = ref$.command, room = ref$.room, log = (ref1$ = ref$.log) != null
? ref1$
: [];
switch (type) {
case 'cmd':
return window.ss.ExecuteCommand(command);
case 'recalc':
return SocialCalc.RecalcLoadedSheet(ref, snapshot, true);
case 'clearCache':
return SocialCalc.Formula.SheetCache.sheets = {};
case 'exportSave':
return postMessage({
type: 'save',
save: window.ss.CreateSheetSave()
});
case 'exportHTML':
return postMessage({
type: 'html',
html: window.ss.CreateSheetHTML()
});
case 'exportCSV':
csv = window.ss.SocialCalc.ConvertSaveToOtherFormat(window.ss.CreateSheetSave(), 'csv');
return postMessage({
type: 'csv',
csv: csv
});
case 'exportCells':
return postMessage({
type: 'cells',
cells: window.ss.cells
});
case 'init':
SocialCalc.SaveEditorSettings = function(){
return "";
};
SocialCalc.CreateAuditString = function(){
return "";
};
SocialCalc.CalculateEditorPositions = function(){};
SocialCalc.Popup.Types.List.Create = function(){};
SocialCalc.Popup.Types.ColorChooser.Create = function(){};
SocialCalc.Popup.Initialize = function(){};
SocialCalc.RecalcInfo.LoadSheet = function(ref){
ref = (ref + "").replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
postMessage({
type: 'load-sheet',
ref: ref
});
return true;
};
window.setTimeout = function(cb, ms){
return thread.nextTick(cb);
};
window.clearTimeout = function(){};
window.ss = ss = new SocialCalc.SpreadsheetControl;
ss.SocialCalc = SocialCalc;
ss._room = room;
if (snapshot) {
parts = ss.DecodeSpreadsheetSave(snapshot);
}
ss.editor.StatusCallback.EtherCalc = {
func: function(editor, status, arg){
var newSnapshot;
if (status !== 'doneposcalc') {
return;
}
newSnapshot = ss.CreateSpreadsheetSave();
if (ss._snapshot === newSnapshot) {
return;
}
ss._snapshot = newSnapshot;
return postMessage({
type: 'snapshot',
snapshot: newSnapshot
});
}
};
if (parts != null && parts.sheet) {
ss.sheet.ResetSheet();
ss.ParseSheetSave(snapshot.substring(parts.sheet.start, parts.sheet.end));
}
cmdstr = (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = log).length; i$ < len$; ++i$) {
line = ref$[i$];
if (!/^re(calc|display)$/.test(line)) {
results$.push(line);
}
}
return results$;
}()).join("\n");
if (cmdstr.length) {
cmdstr += "\n";
}
return ss.context.sheetobj.ScheduleSheetCommands("set sheet defaulttextvalueformat text-wiki\n" + cmdstr + "recalc\n", false, true);
}
};
});
w._snapshot = snapshot;
w.onSnapshot = function(newSnapshot){
var this$ = this;
io.sockets['in']("recalc." + room).emit('data', {
type: 'recalc',
snapshot: newSnapshot,
force: true,
room: room
});
w._snapshot = newSnapshot;
return DB.multi().set("snapshot-" + room, newSnapshot).del("log-" + room).bgsave().exec(function(){
console.log("==> Regenerated snapshot for " + room);
if (EXPIRE) {
return DB.expire("snapshot-" + room, EXPIRE);
}
});
};
w.onerror = function(it){
return console.log(it);
};
w.onmessage = function(arg$){
var ref$, type, snapshot, html, csv, ref, parts, save;
ref$ = arg$.data, type = ref$.type, snapshot = ref$.snapshot, html = ref$.html, csv = ref$.csv, ref = ref$.ref, parts = ref$.parts, save = ref$.save;
switch (type) {
case 'snapshot':
return w.onSnapshot(snapshot);
case 'save':
return w.onSave(save);
case 'html':
return w.onHtml(html);
case 'csv':
return w.onCsv(csv);
case 'load-sheet':
return SC._get(ref, io, function(){
if (SC[ref]) {
return SC[ref].exportSave(function(save){
return w.postMessage({
type: 'recalc',
ref: ref,
snapshot: save
});
});
} else {
return w.postMessage({
type: 'recalc',
ref: ref,
snapshot: ''
});
}
});
}
};
w._doClearCache = function(){
return this.postMessage({
type: 'clearCache'
});
};
w.ExecuteCommand = function(command){
return this.postMessage({
type: 'cmd',
command: command
});
};
w.exportHTML = function(cb){
return w.thread.eval("window.ss.CreateSheetHTML()", function(arg$, html){
return cb(html);
});
};
w.exportCSV = function(cb){
return w.thread.eval("window.ss.SocialCalc.ConvertSaveToOtherFormat(\n window.ss.CreateSheetSave(), \"csv\"\n)", function(arg$, csv){
return cb(csv);
});
};
if (IsThreaded) {
w.exportHTML = function(cb){
var x, this$ = this;
x = new Worker(function(){
return this.onmessage = function(arg$){
var ref$, snapshot, log, ref1$, parts, save, ss, cmdstr, line, e;
ref$ = arg$.data, snapshot = ref$.snapshot, log = (ref1$ = ref$.log) != null
? ref1$
: [];
try {
parts = SocialCalc.SpreadsheetControlDecodeSpreadsheetSave("", snapshot);
save = snapshot.substring(parts.sheet.start, parts.sheet.end);
window.setTimeout = function(cb, ms){
return thread.nextTick(cb);
};
window.clearTimeout = function(){};
window.ss = ss = new SocialCalc.SpreadsheetControl;
ss.sheet.ResetSheet();
ss.ParseSheetSave(save);
if (log != null && log.length) {
cmdstr = (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = log).length; i$ < len$; ++i$) {
line = ref$[i$];
if (!/^re(calc|display)$/.test(line) && line !== "set sheet defaulttextvalueformat text-wiki") {
results$.push(line);
}
}
return results$;
}()).join("\n");
if (cmdstr.length) {
cmdstr += "\n";
}
ss.editor.StatusCallback.EtherCalc = {
func: function(editor, status, arg){
if (status !== 'doneposcalc') {
return;
}
return postMessage(ss.CreateSheetHTML());
}
};
return ss.context.sheetobj.ScheduleSheetCommands(cmdstr, false, true);
} else {
return postMessage(ss.CreateSheetHTML());
}
} catch (e$) {
e = e$;
return postMessage("ERROR: " + e);
}
};
});
x.onmessage = function(arg$){
var data;
data = arg$.data;
x.thread.destroy();
return cb(data);
};
DB.lrange("log-" + room, 0, -1, function(arg$, log){
return x.thread.eval(bootSC, function(){
return x.postMessage({
snapshot: w._snapshot,
log: log
});
});
});
};
}
if (IsThreaded) {
w.exportCSV = function(cb){
var x, this$ = this;
x = new Worker(function(){
return this.onmessage = function(arg$){
var ref$, snapshot, log, ref1$, parts, save, cmdstr, line, ss, e;
ref$ = arg$.data, snapshot = ref$.snapshot, log = (ref1$ = ref$.log) != null
? ref1$
: [];
try {
parts = SocialCalc.SpreadsheetControlDecodeSpreadsheetSave("", snapshot);
save = snapshot.substring(parts.sheet.start, parts.sheet.end);
if (log != null && log.length) {
cmdstr = (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = log).length; i$ < len$; ++i$) {
line = ref$[i$];
if (!/^re(calc|display)$/.test(line) && line !== "set sheet defaulttextvalueformat text-wiki") {
results$.push(line);
}
}
return results$;
}()).join("\n");
if (cmdstr.length) {
cmdstr += "\n";
}
window.setTimeout = function(cb, ms){
return thread.nextTick(cb);
};
window.clearTimeout = function(){};
window.ss = ss = new SocialCalc.SpreadsheetControl;
ss.sheet.ResetSheet();
ss.ParseSheetSave(save);
ss.editor.StatusCallback.EtherCalc = {
func: function(editor, status, arg){
var save;
if (status !== 'doneposcalc') {
return;
}
save = ss.CreateSheetSave();
return postMessage(SocialCalc.ConvertSaveToOtherFormat(save, 'csv'));
}
};
return ss.context.sheetobj.ScheduleSheetCommands(cmdstr, false, true);
} else {
return postMessage(SocialCalc.ConvertSaveToOtherFormat(save, 'csv'));
}
} catch (e$) {
e = e$;
return postMessage("ERROR: " + e);
}
};
});
x.onmessage = function(arg$){
var data;
data = arg$.data;
x.thread.destroy();
return cb(data);
};
DB.lrange("log-" + room, 0, -1, function(arg$, log){
return x.thread.eval(bootSC, function(){
return x.postMessage({
snapshot: w._snapshot,
log: log
});
});
});
};
}
w.exportSave = function(cb){
return w.thread.eval("window.ss.CreateSheetSave()", function(arg$, save){
return cb(save);
});
};
w.exportCell = function(coord, cb){
return w.thread.eval("JSON.stringify(window.ss.sheet.cells[" + (replace$.call(JSON.stringify(coord), /\s/g, '')) + "])", function(arg$, cell){
if (cell === 'undefined') {
return cb('null');
} else {
return cb(cell);
}
});
};
w.exportCells = function(cb){
return w.thread.eval("JSON.stringify(window.ss.sheet.cells)", function(arg$, cells){
return cb(cells);
});
};
w.thread.eval(bootSC, function(){
return w.postMessage({
type: 'init',
room: room,
log: log,
snapshot: snapshot
});
});
return w;
};
return SC;
};
}).call(this);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_jprichardson/ethercalc.git
git@gitee.com:mirrors_jprichardson/ethercalc.git
mirrors_jprichardson
ethercalc
ethercalc
master

搜索帮助