Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client-ts: Port services/hoisted_note.js
Elian Doranf1896c3f5f68
diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.tssimilarity index 69%rename from src/public/app/services/hoisted_note.jsrename to src/public/app/services/hoisted_note.tsindex d6a3916de7..8ef8d28795 100644--- a/src/public/app/services/hoisted_note.js+++ b/src/public/app/services/hoisted_note.ts@@ -1,7 +1,8 @@import appContext from "../components/app_context.js";-import treeService from "./tree.js";+import treeService, { Node } from "./tree.js";import dialogService from "./dialog.js";import froca from "./froca.js";+import NoteContext from "../components/note_context.js";function getHoistedNoteId() {const activeNoteContext = appContext.tabManager.getActiveContext();@@ -17,11 +18,11 @@ async function unhoist() {}}-function isTopLevelNode(node) {+function isTopLevelNode(node: Node) {return isHoistedNode(node.getParent());}-function isHoistedNode(node) {+function isHoistedNode(node: Node) {// even though check for 'root' should not be necessary, we keep it just in casereturn node.data.noteId === "root"|| node.data.noteId === getHoistedNoteId();@@ -35,10 +36,10 @@ async function isHoistedInHiddenSubtree() {}const hoistedNote = await froca.getNote(hoistedNoteId);- return hoistedNote.isHiddenCompletely();+ return hoistedNote?.isHiddenCompletely();}-async function checkNoteAccess(notePath, noteContext) {+async function checkNoteAccess(notePath: string, noteContext: NoteContext) {const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId);if (!resolvedNotePath) {@@ -49,11 +50,15 @@ async function checkNoteAccess(notePath, noteContext) {const hoistedNoteId = noteContext.hoistedNoteId;if (!resolvedNotePath.includes(hoistedNoteId) && (!resolvedNotePath.includes('_hidden') || resolvedNotePath.includes('_lbBookmarks'))) {- const requestedNote = await froca.getNote(treeService.getNoteIdFromUrl(resolvedNotePath));+ const noteId = treeService.getNoteIdFromUrl(resolvedNotePath);+ if (!noteId) {+ return false;+ }+ const requestedNote = await froca.getNote(noteId);const hoistedNote = await froca.getNote(hoistedNoteId);- if ((!hoistedNote.hasAncestor('_hidden') || resolvedNotePath.includes('_lbBookmarks'))- && !await dialogService.confirm(`Requested note '${requestedNote.title}' is outside of hoisted note '${hoistedNote.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) {+ if ((!hoistedNote?.hasAncestor('_hidden') || resolvedNotePath.includes('_lbBookmarks'))+ && !await dialogService.confirm(`Requested note '${requestedNote?.title}' is outside of hoisted note '${hoistedNote?.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) {return false;}