mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	chore(client/ts): port note_paths
This commit is contained in:
		| @@ -38,10 +38,10 @@ const NOTE_TYPE_ICONS = { | |||||||
|  */ |  */ | ||||||
| type NoteType = "file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code" | "mindMap" | "geoMap"; | type NoteType = "file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code" | "mindMap" | "geoMap"; | ||||||
|  |  | ||||||
| interface NotePathRecord { | export interface NotePathRecord { | ||||||
|     isArchived: boolean; |     isArchived: boolean; | ||||||
|     isInHoistedSubTree: boolean; |     isInHoistedSubTree: boolean; | ||||||
|     isSearch: boolean; |     isSearch?: boolean; | ||||||
|     notePath: string[]; |     notePath: string[]; | ||||||
|     isHidden: boolean; |     isHidden: boolean; | ||||||
| } | } | ||||||
| @@ -402,14 +402,14 @@ class FNote { | |||||||
|         return notePaths; |         return notePaths; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     getSortedNotePathRecords(hoistedNoteId = "root") { |     getSortedNotePathRecords(hoistedNoteId = "root"): NotePathRecord[] { | ||||||
|         const isHoistedRoot = hoistedNoteId === "root"; |         const isHoistedRoot = hoistedNoteId === "root"; | ||||||
|  |  | ||||||
|         const notePaths = this.getAllNotePaths().map((path) => ({ |         const notePaths: NotePathRecord[] = this.getAllNotePaths().map((path) => ({ | ||||||
|             notePath: path, |             notePath: path, | ||||||
|             isInHoistedSubTree: isHoistedRoot || path.includes(hoistedNoteId), |             isInHoistedSubTree: isHoistedRoot || path.includes(hoistedNoteId), | ||||||
|             isArchived: path.some((noteId) => froca.notes[noteId].isArchived), |             isArchived: path.some((noteId) => froca.notes[noteId].isArchived), | ||||||
|             isSearch: path.find((noteId) => froca.notes[noteId].type === "search"), |             isSearch: path.some((noteId) => froca.notes[noteId].type === "search"), | ||||||
|             isHidden: path.includes("_hidden") |             isHidden: path.includes("_hidden") | ||||||
|         })); |         })); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ interface NoteRow { | |||||||
| } | } | ||||||
|  |  | ||||||
| interface BranchRow { | interface BranchRow { | ||||||
|  |     noteId?: string; | ||||||
|     branchId: string; |     branchId: string; | ||||||
|     componentId: string; |     componentId: string; | ||||||
|     parentNoteId?: string; |     parentNoteId?: string; | ||||||
|   | |||||||
| @@ -2,6 +2,9 @@ import NoteContextAwareWidget from "../note_context_aware_widget.js"; | |||||||
| import treeService from "../../services/tree.js"; | import treeService from "../../services/tree.js"; | ||||||
| import linkService from "../../services/link.js"; | import linkService from "../../services/link.js"; | ||||||
| import { t } from "../../services/i18n.js"; | import { t } from "../../services/i18n.js"; | ||||||
|  | import type FNote from "../../entities/fnote.js"; | ||||||
|  | import type { NotePathRecord } from "../../entities/fnote.js"; | ||||||
|  | import type { EventData } from "../../components/app_context.js"; | ||||||
| 
 | 
 | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <div class="note-paths-widget"> | <div class="note-paths-widget"> | ||||||
| @@ -37,6 +40,10 @@ const TPL = ` | |||||||
| </div>`;
 | </div>`;
 | ||||||
| 
 | 
 | ||||||
| export default class NotePathsWidget extends NoteContextAwareWidget { | export default class NotePathsWidget extends NoteContextAwareWidget { | ||||||
|  | 
 | ||||||
|  |     private $notePathIntro!: JQuery<HTMLElement>; | ||||||
|  |     private $notePathList!: JQuery<HTMLElement>; | ||||||
|  | 
 | ||||||
|     get name() { |     get name() { | ||||||
|         return "notePaths"; |         return "notePaths"; | ||||||
|     } |     } | ||||||
| @@ -59,13 +66,12 @@ export default class NotePathsWidget extends NoteContextAwareWidget { | |||||||
| 
 | 
 | ||||||
|         this.$notePathIntro = this.$widget.find(".note-path-intro"); |         this.$notePathIntro = this.$widget.find(".note-path-intro"); | ||||||
|         this.$notePathList = this.$widget.find(".note-path-list"); |         this.$notePathList = this.$widget.find(".note-path-list"); | ||||||
|         this.$widget.on("show.bs.dropdown", () => this.renderDropdown()); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async refreshWithNote(note) { |     async refreshWithNote(note: FNote) { | ||||||
|         this.$notePathList.empty(); |         this.$notePathList.empty(); | ||||||
| 
 | 
 | ||||||
|         if (this.noteId === "root") { |         if (!this.note || this.noteId === "root") { | ||||||
|             this.$notePathList.empty().append(await this.getRenderedPath("root")); |             this.$notePathList.empty().append(await this.getRenderedPath("root")); | ||||||
| 
 | 
 | ||||||
|             return; |             return; | ||||||
| @@ -90,7 +96,7 @@ export default class NotePathsWidget extends NoteContextAwareWidget { | |||||||
|         this.$notePathList.empty().append(...renderedPaths); |         this.$notePathList.empty().append(...renderedPaths); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async getRenderedPath(notePath, notePathRecord = null) { |     async getRenderedPath(notePath: string, notePathRecord: NotePathRecord | null = null) { | ||||||
|         const title = await treeService.getNotePathTitle(notePath); |         const title = await treeService.getNotePathTitle(notePath); | ||||||
| 
 | 
 | ||||||
|         const $noteLink = await linkService.createLink(notePath, { title }); |         const $noteLink = await linkService.createLink(notePath, { title }); | ||||||
| @@ -128,8 +134,9 @@ export default class NotePathsWidget extends NoteContextAwareWidget { | |||||||
|         return $("<li>").append($noteLink); |         return $("<li>").append($noteLink); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     entitiesReloadedEvent({ loadResults }) { |     entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { | ||||||
|         if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId) || loadResults.isNoteReloaded(this.noteId)) { |         if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId) || | ||||||
|  |             (this.noteId != null && loadResults.isNoteReloaded(this.noteId))) { | ||||||
|             this.refresh(); |             this.refresh(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
		Reference in New Issue
	
	Block a user