Notes/src/services/hoisted_note.ts

41 lines
914 B
TypeScript
Raw Normal View History

import cls from "./cls.js";
import becca from "../becca/becca.js";
2022-11-26 14:57:39 +01:00
function getHoistedNoteId() {
return cls.getHoistedNoteId();
}
function isHoistedInHiddenSubtree() {
const hoistedNoteId = getHoistedNoteId();
if (hoistedNoteId === 'root') {
return false;
2022-12-21 16:11:00 +01:00
} else if (hoistedNoteId === '_hidden') {
2022-12-16 16:00:49 +01:00
return true;
2022-11-26 14:57:39 +01:00
}
const hoistedNote = becca.getNote(hoistedNoteId);
if (!hoistedNote) {
2023-05-04 22:16:18 +02:00
throw new Error(`Cannot find hoisted note '${hoistedNoteId}'`);
2022-11-26 14:57:39 +01:00
}
2023-01-27 16:57:23 +01:00
return hoistedNote.isHiddenCompletely();
2022-11-26 14:57:39 +01:00
}
2022-12-23 15:07:48 +01:00
function getWorkspaceNote() {
2023-04-14 16:49:06 +02:00
const hoistedNote = becca.getNote(cls.getHoistedNoteId());
2022-12-23 15:07:48 +01:00
2024-02-18 00:22:46 +02:00
if (hoistedNote && (hoistedNote.isRoot() || hoistedNote.hasLabel('workspace'))) {
2022-12-23 15:07:48 +01:00
return hoistedNote;
} else {
return becca.getRoot();
}
}
export default {
2022-11-26 14:57:39 +01:00
getHoistedNoteId,
2022-12-23 15:07:48 +01:00
getWorkspaceNote,
2022-11-26 14:57:39 +01:00
isHoistedInHiddenSubtree
};