|
|
@ -222,7 +222,10 @@ by maintaining indexes in rowsOrder and colsOrder
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var makeRemoveElement = Render.makeRemoveElement = function (id) {
|
|
|
|
var makeRemoveElement = Render.makeRemoveElement = function (id) {
|
|
|
|
return ['SPAN', { 'data-rt-id': id, }, ['x']];
|
|
|
|
return ['SPAN', {
|
|
|
|
|
|
|
|
'data-rt-id': id,
|
|
|
|
|
|
|
|
class: 'remove',
|
|
|
|
|
|
|
|
}, ['✖']];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var makeHeadingCell = Render.makeHeadingCell = function (cell) {
|
|
|
|
var makeHeadingCell = Render.makeHeadingCell = function (cell) {
|
|
|
@ -236,16 +239,45 @@ by maintaining indexes in rowsOrder and colsOrder
|
|
|
|
return ['TD', cell, []];
|
|
|
|
return ['TD', cell, []];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var clone = function (o) {
|
|
|
|
|
|
|
|
return JSON.parse(JSON.stringify(o));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var makeCheckbox = Render.makeCheckbox = function (cell) {
|
|
|
|
|
|
|
|
var attrs = clone(cell);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME
|
|
|
|
|
|
|
|
attrs.id = cell['data-rt-id'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var labelClass = 'cover';
|
|
|
|
|
|
|
|
if (cell.checked) {
|
|
|
|
|
|
|
|
labelClass += ' yes';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ['TD', {class:"checkbox-cell"}, [
|
|
|
|
|
|
|
|
['DIV', {class: 'checkbox-contain'}, [
|
|
|
|
|
|
|
|
['INPUT', attrs, []],
|
|
|
|
|
|
|
|
['SPAN', {class: labelClass}, []],
|
|
|
|
|
|
|
|
['LABEL', {
|
|
|
|
|
|
|
|
for: attrs.id,
|
|
|
|
|
|
|
|
'data-rt-id': attrs.id,
|
|
|
|
|
|
|
|
}, []]
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
]];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var makeBodyCell = Render.makeBodyCell = function (cell) {
|
|
|
|
var makeBodyCell = Render.makeBodyCell = function (cell) {
|
|
|
|
if (cell.type === 'text') {
|
|
|
|
if (cell.type === 'text') {
|
|
|
|
return ['TD', {}, [
|
|
|
|
return ['TD', {}, [
|
|
|
|
|
|
|
|
['DIV', {class: 'text-cell'}, [
|
|
|
|
['INPUT', cell, []],
|
|
|
|
['INPUT', cell, []],
|
|
|
|
makeRemoveElement(cell['data-rt-id'])
|
|
|
|
makeRemoveElement(cell['data-rt-id'])
|
|
|
|
|
|
|
|
]]
|
|
|
|
]];
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cell.type === 'checkbox') {
|
|
|
|
if (cell.type === 'checkbox') {
|
|
|
|
return ['TD', {}, [ ['INPUT', cell, []] ]];
|
|
|
|
return makeCheckbox(cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ['TD', cell, []];
|
|
|
|
return ['TD', cell, []];
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -258,7 +290,7 @@ by maintaining indexes in rowsOrder and colsOrder
|
|
|
|
if (!matrix || !matrix.length) { return; }
|
|
|
|
if (!matrix || !matrix.length) { return; }
|
|
|
|
var head = ['THEAD', {}, [ ['TR', {}, matrix[0].map(makeHeadingCell)] ]];
|
|
|
|
var head = ['THEAD', {}, [ ['TR', {}, matrix[0].map(makeHeadingCell)] ]];
|
|
|
|
var body = ['TBODY', {}, matrix.slice(1).map(makeBodyRow)];
|
|
|
|
var body = ['TBODY', {}, matrix.slice(1).map(makeBodyRow)];
|
|
|
|
return ['TABLE', {}, [head, body]];
|
|
|
|
return ['TABLE', {id:'table'}, [head, body]];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var asHTML = Render.asHTML = function (obj) {
|
|
|
|
var asHTML = Render.asHTML = function (obj) {
|
|
|
@ -278,12 +310,15 @@ by maintaining indexes in rowsOrder and colsOrder
|
|
|
|
var preserveCursor = Render.preserveCursor = function (info) {
|
|
|
|
var preserveCursor = Render.preserveCursor = function (info) {
|
|
|
|
if (['modifyValue', 'modifyAttribute'].indexOf(info.diff.action) !== -1) {
|
|
|
|
if (['modifyValue', 'modifyAttribute'].indexOf(info.diff.action) !== -1) {
|
|
|
|
var element = info.node;
|
|
|
|
var element = info.node;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof(element.selectionStart) !== 'number') { return; }
|
|
|
|
|
|
|
|
|
|
|
|
var o = info.oldValue || '';
|
|
|
|
var o = info.oldValue || '';
|
|
|
|
var n = info.newValue || '';
|
|
|
|
var n = info.newValue || '';
|
|
|
|
var op = TextPatcher.diff(o, n);
|
|
|
|
var op = TextPatcher.diff(o, n);
|
|
|
|
|
|
|
|
|
|
|
|
info.selection = ['selectionStart', 'selectionEnd'].map(function (attr) {
|
|
|
|
info.selection = ['selectionStart', 'selectionEnd'].map(function (attr) {
|
|
|
|
var before = info.node[attr];
|
|
|
|
var before = element[attr];
|
|
|
|
var after = TextPatcher.transformCursor(element[attr], op);
|
|
|
|
var after = TextPatcher.transformCursor(element[attr], op);
|
|
|
|
return after;
|
|
|
|
return after;
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -291,10 +326,15 @@ by maintaining indexes in rowsOrder and colsOrder
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var recoverCursor = Render.recoverCursor = function (info) {
|
|
|
|
var recoverCursor = Render.recoverCursor = function (info) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (info.selection && info.node) {
|
|
|
|
if (info.selection && info.node) {
|
|
|
|
info.node.selectionStart = info.selection[0];
|
|
|
|
info.node.selectionStart = info.selection[0];
|
|
|
|
info.node.selectionEnd = info.selection[1];
|
|
|
|
info.node.selectionEnd = info.selection[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
//console.log(info.node);
|
|
|
|
|
|
|
|
//console.error(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var diffOptions = {
|
|
|
|
var diffOptions = {
|
|
|
|