mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 01:36:24 +01:00 
			
		
		
		
	script api docs
This commit is contained in:
		| @@ -125,7 +125,7 @@ class BNote extends AbstractBeccaEntity { | ||||
|          * @private */ | ||||
|         this.parents = []; | ||||
|         /** @type {BNote[]} | ||||
|          * @private*/ | ||||
|          * @private */ | ||||
|         this.children = []; | ||||
|         /** @type {BAttribute[]} | ||||
|          * @private */ | ||||
| @@ -135,11 +135,11 @@ class BNote extends AbstractBeccaEntity { | ||||
|          * @private */ | ||||
|         this.__attributeCache = null; | ||||
|         /** @type {BAttribute[]|null} | ||||
|          * @private*/ | ||||
|          * @private */ | ||||
|         this.inheritableAttributeCache = null; | ||||
|  | ||||
|         /** @type {BAttribute[]} | ||||
|          * @private*/ | ||||
|          * @private */ | ||||
|         this.targetRelations = []; | ||||
|  | ||||
|         this.becca.addNote(this.noteId, this); | ||||
| @@ -560,6 +560,20 @@ class BNote extends AbstractBeccaEntity { | ||||
|      */ | ||||
|     hasLabel(name, value) { return this.hasAttribute(LABEL, name, value); } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} name - label name | ||||
|      * @returns {boolean} true if label exists (including inherited) and does not have "false" value. | ||||
|      */ | ||||
|     isLabelTruthy(name) { | ||||
|         const label = this.getLabel(name); | ||||
|  | ||||
|         if (!label) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return label && label.value !== 'false'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} name - label name | ||||
|      * @param {string} [value] - label value | ||||
| @@ -761,6 +775,21 @@ class BNote extends AbstractBeccaEntity { | ||||
|         return this.hasAttribute('label', 'archived'); | ||||
|     } | ||||
|  | ||||
|     areAllNotePathsArchived() { | ||||
|         // there's a slight difference between note being itself archived and all its note paths being archived | ||||
|         // - note is archived when it itself has an archived label or inherits it | ||||
|         // - note does not have or inherit archived label, but each note paths contains a note with (non-inheritable) | ||||
|         //   archived label | ||||
|  | ||||
|         const bestNotePathRecord = this.getSortedNotePathRecords()[0]; | ||||
|  | ||||
|         if (!bestNotePathRecord) { | ||||
|             throw new Error(`No note path available for note '${this.noteId}'`); | ||||
|         } | ||||
|  | ||||
|         return bestNotePathRecord.isArchived; | ||||
|     } | ||||
|  | ||||
|     hasInheritableArchivedLabel() { | ||||
|         for (const attr of this.getAttributes()) { | ||||
|             if (attr.name === 'archived' && attr.type === LABEL && attr.isInheritable) { | ||||
| @@ -1164,6 +1193,8 @@ class BNote extends AbstractBeccaEntity { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Gives all possible note paths leading to this note. Paths containing search note are ignored (could form cycles) | ||||
|      * | ||||
|      * @returns {string[][]} - array of notePaths (each represented by array of noteIds constituting the particular note path) | ||||
|      */ | ||||
|     getAllNotePaths() { | ||||
| @@ -1171,18 +1202,73 @@ class BNote extends AbstractBeccaEntity { | ||||
|             return [['root']]; | ||||
|         } | ||||
|  | ||||
|         const notePaths = []; | ||||
|         const parentNotes = this.getParentNotes(); | ||||
|         let notePaths = []; | ||||
|  | ||||
|         for (const parentNote of this.getParentNotes()) { | ||||
|             for (const parentPath of parentNote.getAllNotePaths()) { | ||||
|                 parentPath.push(this.noteId); | ||||
|                 notePaths.push(parentPath); | ||||
|             } | ||||
|         if (parentNotes.length === 1) { // optimization for most common case | ||||
|             notePaths = parentNotes[0].getAllNotePaths(); | ||||
|         } else { | ||||
|             notePaths = parentNotes.flatMap(parentNote => parentNote.getAllNotePaths()); | ||||
|         } | ||||
|  | ||||
|         for (const notePath of notePaths) { | ||||
|             notePath.push(this.noteId); | ||||
|         } | ||||
|  | ||||
|         return notePaths; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [hoistedNoteId='root'] | ||||
|      * @return {Array<{isArchived: boolean, isInHoistedSubTree: boolean, notePath: Array<string>, isHidden: boolean}>} | ||||
|      */ | ||||
|     getSortedNotePathRecords(hoistedNoteId = 'root') { | ||||
|         const isHoistedRoot = hoistedNoteId === 'root'; | ||||
|  | ||||
|         const notePaths = this.getAllNotePaths().map(path => ({ | ||||
|             notePath: path, | ||||
|             isInHoistedSubTree: isHoistedRoot || path.includes(hoistedNoteId), | ||||
|             isArchived: path.some(noteId => this.becca.notes[noteId].isArchived), | ||||
|             isHidden: path.includes('_hidden') | ||||
|         })); | ||||
|  | ||||
|         notePaths.sort((a, b) => { | ||||
|             if (a.isInHoistedSubTree !== b.isInHoistedSubTree) { | ||||
|                 return a.isInHoistedSubTree ? -1 : 1; | ||||
|             } else if (a.isArchived !== b.isArchived) { | ||||
|                 return a.isArchived ? 1 : -1; | ||||
|             } else if (a.isHidden !== b.isHidden) { | ||||
|                 return a.isHidden ? 1 : -1; | ||||
|             } else { | ||||
|                 return a.notePath.length - b.notePath.length; | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         return notePaths; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns note path considered to be the "best" | ||||
|      * | ||||
|      * @param {string} [hoistedNoteId='root'] | ||||
|      * @return {string[]} array of noteIds constituting the particular note path | ||||
|      */ | ||||
|     getBestNotePath(hoistedNoteId = 'root') { | ||||
|         return this.getSortedNotePathRecords(hoistedNoteId)[0]?.notePath; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns note path considered to be the "best" | ||||
|      * | ||||
|      * @param {string} [hoistedNoteId='root'] | ||||
|      * @return {string} serialized note path (e.g. 'root/a1h315/js725h') | ||||
|      */ | ||||
|     getBestNotePathString(hoistedNoteId = 'root') { | ||||
|         const notePath = this.getBestNotePath(hoistedNoteId); | ||||
|  | ||||
|         return notePath?.join("/"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return boolean - true if there's no non-hidden path, note is not cloned to the visible tree | ||||
|      */ | ||||
| @@ -1196,9 +1282,7 @@ class BNote extends AbstractBeccaEntity { | ||||
|                 return false; | ||||
|             } else if (parentNote.noteId === '_hidden') { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             if (!parentNote.isHiddenCompletely()) { | ||||
|             } else if (!parentNote.isHiddenCompletely()) { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
| @@ -1392,7 +1476,7 @@ class BNote extends AbstractBeccaEntity { | ||||
|  | ||||
|     /** | ||||
|      * @param parentNoteId | ||||
|      * @returns {{success: boolean, message: string}} | ||||
|      * @returns {{success: boolean, message: string, branchId: string, notePath: string}} | ||||
|      */ | ||||
|     cloneTo(parentNoteId) { | ||||
|         const cloningService = require("../../services/cloning"); | ||||
| @@ -1550,7 +1634,7 @@ module.exports = BNote; | ||||
| <br class="clear"> | ||||
|  | ||||
| <footer> | ||||
|     Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a> | ||||
|     Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> | ||||
| </footer> | ||||
|  | ||||
| <script> prettyPrint(); </script> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user