| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  | import FlexContainer from "./containers/flex_container.js"; | 
					
						
							| 
									
										
										
										
											2022-08-02 17:33:52 +02:00
										 |  |  | import utils from "../services/utils.js"; | 
					
						
							|  |  |  | import attributeService from "../services/attributes.js"; | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class NoteWrapperWidget extends FlexContainer { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         super("column"); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.css("flex-grow", "1").collapsible(); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     setNoteContextEvent({ noteContext }) { | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |         this.noteContext = noteContext; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.refresh(); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |     noteSwitchedAndActivatedEvent() { | 
					
						
							|  |  |  |         this.refresh(); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |     noteSwitchedEvent() { | 
					
						
							|  |  |  |         this.refresh(); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |     activeContextChangedEvent() { | 
					
						
							|  |  |  |         this.refresh(); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |     refresh() { | 
					
						
							| 
									
										
										
										
											2022-09-07 23:39:35 +02:00
										 |  |  |         const isHiddenExt = this.isHiddenExt(); // preserve through class reset
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-02 17:33:52 +02:00
										 |  |  |         this.$widget.removeClass(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 23:39:35 +02:00
										 |  |  |         this.toggleExt(!isHiddenExt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.addClass("component note-split"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |         const note = this.noteContext?.note; | 
					
						
							| 
									
										
										
										
											2022-08-02 17:33:52 +02:00
										 |  |  |         if (!note) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$widget.toggleClass("full-content-width", ["image", "mermaid", "book", "render", "canvas", "webView", "mindMap"].includes(note.type) || !!note?.isLabelTruthy("fullContentWidth")); | 
					
						
							| 
									
										
										
										
											2022-08-02 17:33:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.addClass(note.getCssClass()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.addClass(utils.getNoteTypeClass(note.type)); | 
					
						
							|  |  |  |         this.$widget.addClass(utils.getMimeTypeClass(note.mime)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.toggleClass("protected", note.isProtected); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     async entitiesReloadedEvent({ loadResults }) { | 
					
						
							| 
									
										
										
										
											2022-08-02 17:33:52 +02:00
										 |  |  |         // listening on changes of note.type and CSS class
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const noteId = this.noteContext?.noteId; | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         if ( | 
					
						
							|  |  |  |             loadResults.isNoteReloaded(noteId) || | 
					
						
							|  |  |  |             loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "cssClass" && attributeService.isAffecting(attr, this.noteContext?.note)) | 
					
						
							|  |  |  |         ) { | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  |             this.refresh(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  | } |