2022-10-24 01:05:59 +00:00
|
|
|
function sheet_insert_comments(sheet/*:WorkSheet*/, comments/*:Array<RawComment>*/, threaded/*:boolean*/, people/*:?Array<any>*/) {
|
|
|
|
var dense = sheet["!data"] != null;
|
2019-04-01 14:25:15 +00:00
|
|
|
var cell/*:Cell*/;
|
2014-01-28 16:38:02 +00:00
|
|
|
comments.forEach(function(comment) {
|
2019-04-01 14:25:15 +00:00
|
|
|
var r = decode_cell(comment.ref);
|
2023-04-12 07:47:45 +00:00
|
|
|
if(r.r < 0 || r.c < 0) return;
|
2017-04-08 06:55:35 +00:00
|
|
|
if(dense) {
|
2022-10-24 01:05:59 +00:00
|
|
|
if(!sheet["!data"][r.r]) sheet["!data"][r.r] = [];
|
|
|
|
cell = sheet["!data"][r.r][r.c];
|
2017-04-08 06:55:35 +00:00
|
|
|
} else cell = sheet[comment.ref];
|
2014-01-28 16:38:02 +00:00
|
|
|
if (!cell) {
|
2019-11-01 03:09:14 +00:00
|
|
|
cell = ({t:"z"}/*:any*/);
|
2022-10-24 01:05:59 +00:00
|
|
|
if(dense) sheet["!data"][r.r][r.c] = cell;
|
2017-04-08 06:55:35 +00:00
|
|
|
else sheet[comment.ref] = cell;
|
2014-06-29 18:29:45 +00:00
|
|
|
var range = safe_decode_range(sheet["!ref"]||"BDWGO1000001:A1");
|
2019-04-01 14:25:15 +00:00
|
|
|
if(range.s.r > r.r) range.s.r = r.r;
|
|
|
|
if(range.e.r < r.r) range.e.r = r.r;
|
|
|
|
if(range.s.c > r.c) range.s.c = r.c;
|
|
|
|
if(range.e.c < r.c) range.e.c = r.c;
|
2014-01-28 16:38:02 +00:00
|
|
|
var encoded = encode_range(range);
|
2022-10-24 01:05:59 +00:00
|
|
|
sheet["!ref"] = encoded;
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 06:09:42 +00:00
|
|
|
if (!cell.c) cell.c = [];
|
2022-03-14 06:51:33 +00:00
|
|
|
var o/*:Comment*/ = ({a: comment.author, t: comment.t, r: comment.r, T: threaded});
|
2014-02-12 06:09:42 +00:00
|
|
|
if(comment.h) o.h = comment.h;
|
2022-03-14 06:51:33 +00:00
|
|
|
|
|
|
|
/* threaded comments always override */
|
|
|
|
for(var i = cell.c.length - 1; i >= 0; --i) {
|
|
|
|
if(!threaded && cell.c[i].T) return;
|
|
|
|
if(threaded && !cell.c[i].T) cell.c.splice(i, 1);
|
|
|
|
}
|
2022-03-16 03:18:09 +00:00
|
|
|
if(threaded && people) for(i = 0; i < people.length; ++i) {
|
2022-03-14 06:51:33 +00:00
|
|
|
if(o.a == people[i].id) { o.a = people[i].name || o.a; break; }
|
|
|
|
}
|
2014-02-12 06:09:42 +00:00
|
|
|
cell.c.push(o);
|
2014-01-28 16:38:02 +00:00
|
|
|
});
|
|
|
|
}
|