80 lines
1.8 KiB
TypeScript
Raw Normal View History

import type { Froca } from "../services/froca-interface.js";
2024-07-25 20:36:15 +03:00
export interface FBranchRow {
branchId: string;
noteId: string;
parentNoteId: string;
notePosition: number;
prefix?: string;
isExpanded?: boolean;
fromSearchNote: boolean;
2025-01-28 15:44:15 +02:00
isDeleted?: boolean;
2024-07-25 20:36:15 +03:00
}
/**
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
* parents.
*/
class FBranch {
2024-07-25 20:36:15 +03:00
private froca: Froca;
/**
* primary key
*/
branchId!: string;
noteId!: string;
parentNoteId!: string;
notePosition!: number;
prefix?: string;
isExpanded?: boolean;
fromSearchNote!: boolean;
constructor(froca: Froca, row: FBranchRow) {
2021-04-16 22:57:37 +02:00
this.froca = froca;
2020-01-29 22:32:22 +01:00
this.update(row);
}
2024-07-25 20:36:15 +03:00
update(row: FBranchRow) {
/**
* primary key
*/
this.branchId = row.branchId;
this.noteId = row.noteId;
this.parentNoteId = row.parentNoteId;
this.notePosition = row.notePosition;
this.prefix = row.prefix;
2018-11-26 14:47:46 +01:00
this.isExpanded = !!row.isExpanded;
this.fromSearchNote = !!row.fromSearchNote;
}
async getNote() {
2021-04-16 22:57:37 +02:00
return this.froca.getNote(this.noteId);
}
2020-08-26 16:50:16 +02:00
getNoteFromCache() {
2021-04-16 22:57:37 +02:00
return this.froca.getNoteFromCache(this.noteId);
2020-08-26 16:50:16 +02:00
}
2020-01-12 09:57:28 +01:00
async getParentNote() {
2021-04-16 22:57:37 +02:00
return this.froca.getNote(this.parentNoteId);
2020-01-12 09:57:28 +01:00
}
2024-07-25 20:36:15 +03:00
/** @returns true if it's top level, meaning its parent is the root note */
isTopLevel() {
2025-01-09 18:07:02 +02:00
return this.parentNoteId === "root";
}
get toString() {
return `FBranch(branchId=${this.branchId})`;
}
2022-09-21 23:58:54 +02:00
2024-07-25 20:36:15 +03:00
get pojo(): Omit<FBranch, "froca"> {
2025-01-09 18:07:02 +02:00
const pojo = { ...this } as any;
2022-09-21 23:58:54 +02:00
delete pojo.froca;
return pojo;
}
}
export default FBranch;