| 
									
										
										
										
											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"; | 
					
						
							| 
									
										
										
										
											2025-02-08 21:42:12 +02:00
										 |  |  | import type BasicWidget from "./basic_widget.js"; | 
					
						
							|  |  |  | import type { EventData } from "../components/app_context.js"; | 
					
						
							|  |  |  | import type NoteContext from "../components/note_context.js"; | 
					
						
							| 
									
										
										
										
											2025-02-08 21:49:30 +02:00
										 |  |  | import type FNote from "../entities/fnote.js"; | 
					
						
							| 
									
										
										
										
											2025-03-05 17:12:14 +02:00
										 |  |  | import { getLocaleById } from "../services/i18n.js"; | 
					
						
							| 
									
										
										
										
											2025-02-08 21:42:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class NoteWrapperWidget extends FlexContainer<BasicWidget> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private noteContext?: NoteContext; | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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-02-08 21:42:12 +02:00
										 |  |  |     setNoteContextEvent({ noteContext }: EventData<"setNoteContext">) { | 
					
						
							| 
									
										
										
										
											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-02-08 21:49:30 +02:00
										 |  |  |         this.$widget.toggleClass("full-content-width", this.#isFullWidthNote(note)); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2025-03-05 17:12:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const noteLanguage = note?.getLabelValue("language"); | 
					
						
							|  |  |  |         const locale = getLocaleById(noteLanguage); | 
					
						
							|  |  |  |         this.$widget.toggleClass("rtl", !!locale?.rtl); | 
					
						
							| 
									
										
										
										
											2021-11-24 21:27:55 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-05-22 14:24:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-08 21:49:30 +02:00
										 |  |  |     #isFullWidthNote(note: FNote) { | 
					
						
							|  |  |  |         if (["image", "mermaid", "book", "render", "canvas", "webView", "mindMap", "geoMap"].includes(note.type)) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-26 19:30:16 +02:00
										 |  |  |         if (note.type === "file" && (note.mime === "application/pdf" || note.mime.startsWith("video/"))) { | 
					
						
							| 
									
										
										
										
											2025-02-08 21:49:30 +02:00
										 |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return !!note?.isLabelTruthy("fullContentWidth"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-08 21:42:12 +02:00
										 |  |  |     async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } |