2023-08-21 04:17:16 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								<!DOCTYPE html>  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< html  lang = "en" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< head >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < meta  charset = "utf-8" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < title > JSDoc: Source: widgets/note_context_aware_widget.js< / title > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < script  src = "scripts/prettify/prettify.js" >  < / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < script  src = "scripts/prettify/lang-css.js" >  < / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <!-- [if lt IE 9]>
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < script  src = "//html5shiv.googlecode.com/svn/trunk/html5.js" > < / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <![endif]--> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < link  type = "text/css"  rel = "stylesheet"  href = "styles/prettify-tomorrow.css" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < link  type = "text/css"  rel = "stylesheet"  href = "styles/jsdoc-default.css" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / head >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< body >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = "main" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < h1  class = "page-title" > Source: widgets/note_context_aware_widget.js< / h1 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < article > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < pre  class = "prettyprint source linenums" > < code > import BasicWidget from "./basic_widget.js";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import appContext from "../components/app_context.js";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * This widget allows for changing and updating depending on the active note.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @extends {BasicWidget}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class NoteContextAwareWidget extends BasicWidget {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    isNoteContext(ntxId) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if (Array.isArray(ntxId)) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return this.noteContext & &  ntxId.includes(this.noteContext.ntxId);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return this.noteContext & &  this.noteContext.ntxId === ntxId;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    isActiveNoteContext() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return appContext.tabManager.getActiveContext() === this.noteContext;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    isNote(noteId) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return this.noteId === noteId;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** @returns {FNote|undefined} */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    get note() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return this.noteContext?.note;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** @returns {string|undefined} */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    get noteId() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return this.note?.noteId;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** @returns {string|undefined} */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    get notePath() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return this.noteContext?.notePath;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** @returns {string} */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    get hoistedNoteId() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return this.noteContext?.hoistedNoteId;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    get ntxId() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return this.noteContext?.ntxId;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
									
										
										
										
											2024-12-11 18:31:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * Indicates if the widget is enabled. Widgets are enabled by default. Generally setting this to `false` will cause the widget not to be displayed, however it will still be available on the DOM but hidden.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * < p>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * If the widget is not enabled, it will not receive `refreshWithNote` updates.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 04:17:16 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     * @returns {boolean} true when an active note exists
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    isEnabled() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return !!this.note;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async refresh() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if (this.isEnabled()) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this.toggleInt(true);
							 
						 
					
						
							
								
									
										
										
										
											2024-12-11 18:31:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                await this.refreshWithNote(this.note);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } catch (e) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // Ignore errors when user is refreshing or navigating away.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if (e === "rejected by browser") {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                throw e;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 04:17:16 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this.toggleInt(false);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Override this method to be able to refresh your
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * widget with each note.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {FNote} note
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @returns {Promise< void>}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async refreshWithNote(note) {}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async noteSwitchedEvent({noteContext, notePath}) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // if notePath does not match, then the noteContext has been switched to another note in the meantime
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if (noteContext.notePath === notePath) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await this.noteSwitched();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async noteSwitched() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await this.refresh();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async activeContextChangedEvent({noteContext}) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this.noteContext = noteContext;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await this.activeContextChanged();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async activeContextChanged() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await this.refresh();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // when note is both switched and activated, this should not produce a double refresh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async noteSwitchedAndActivatedEvent({noteContext, notePath}) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this.noteContext = noteContext;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // if notePath does not match, then the noteContext has been switched to another note in the meantime
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if (this.notePath === notePath) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await this.refresh();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    setNoteContextEvent({noteContext}) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /** @var {NoteContext} */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this.noteContext = noteContext;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async noteTypeMimeChangedEvent({noteId}) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if (this.isNote(noteId)) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await this.refresh();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async frocaReloadedEvent() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await this.refresh();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export default NoteContextAwareWidget;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code > < / pre >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < / article > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< nav >  
						 
					
						
							
								
									
										
										
										
											2023-09-25 23:11:24 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    < h2 > < a  href = "index.html" > Home< / a > < / h2 > < h3 > Classes< / h3 > < ul > < li > < a  href = "BasicWidget.html" > BasicWidget< / a > < / li > < li > < a  href = "FAttachment.html" > FAttachment< / a > < / li > < li > < a  href = "FAttribute.html" > FAttribute< / a > < / li > < li > < a  href = "FBranch.html" > FBranch< / a > < / li > < li > < a  href = "FNote.html" > FNote< / a > < / li > < li > < a  href = "FrontendScriptApi.html" > FrontendScriptApi< / a > < / li > < li > < a  href = "NoteContextAwareWidget.html" > NoteContextAwareWidget< / a > < / li > < li > < a  href = "RightPanelWidget.html" > RightPanelWidget< / a > < / li > < / ul > < h3 > Global< / h3 > < ul > < li > < a  href = "global.html#api" > api< / a > < / li > < li > < a  href = "global.html#getJsonContent" > getJsonContent< / a > < / li > < li > < a  href = "global.html#getJsonContentSafely" > getJsonContentSafely< / a > < / li > < / ul > 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 04:17:16 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / nav >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< br  class = "clear" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< footer >  
						 
					
						
							
								
									
										
										
										
											2024-12-15 10:44:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Documentation generated by < a  href = "https://github.com/jsdoc/jsdoc" > JSDoc 4.0.4< / a > 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 04:17:16 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / footer >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< script >  prettyPrint ( ) ;  < / script >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< script  src = "scripts/linenumber.js" >  < / script >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / body >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / html >