2022-03-14 06:51:33 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function sheet_insert_comments(sheet, comments/*:Array<RawComment>*/, threaded/*:boolean*/, people/*:?Array<any>*/) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-08 06:55:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									var dense = Array.isArray(sheet);
							 | 
						
					
						
							
								
									
										
										
										
											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);
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-08 06:55:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if(dense) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											if(!sheet[r.r]) sheet[r.r] = [];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											cell = sheet[r.r][r.c];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										} 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*/);
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-08 06:55:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											if(dense) sheet[r.r][r.c] = cell;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											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);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											if (encoded !== sheet["!ref"]) sheet["!ref"] = encoded;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 |