fix(tree): type issues & error if active node is empty

This commit is contained in:
Elian Doran 2025-11-09 11:16:35 +02:00
parent cc0646e79c
commit afa92551ea
No known key found for this signature in database
2 changed files with 29 additions and 14 deletions

View File

@ -215,6 +215,30 @@ declare namespace Fancytree {
enableUpdate(enabled: boolean): void;
}
interface FancytreeNodeData {
noteId: string;
parentNoteId: string;
branchId: string;
isProtected: boolean;
noteType: NoteType;
}
interface FancytreeNewNode extends FancytreeNodeData {
title: string;
extraClasses: string;
icon: string;
refKey: string;
/** True if this node is loaded on demand, i.e. on first expansion. */
lazy: boolean;
/** Folder nodes have different default icons and click behavior. Note: Also non-folders may have children. */
folder: boolean;
/** Use isExpanded(), setExpanded() to access this property. */
expanded: boolean;
/** Node id (must be unique inside the tree) */
key: string;
children?: FancytreeNewNode[];
}
/** A FancytreeNode represents the hierarchical data model and operations. */
interface FancytreeNode {
// #region Properties
@ -227,7 +251,7 @@ declare namespace Fancytree {
/** Display name (may contain HTML) */
title: string;
/** Contains all extra data that was passed on node creation */
data: any;
data: FancytreeNodeData;
/** Array of child nodes. For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array to define a node that has no children. */
children: FancytreeNode[];
/** Use isExpanded(), setExpanded() to access this property. */

View File

@ -173,14 +173,6 @@ interface ExpandedSubtreeResponse {
branchIds: string[];
}
interface Node extends Fancytree.NodeData {
noteId: string;
parentNoteId: string;
branchId: string;
isProtected: boolean;
noteType: NoteType;
}
interface RefreshContext {
noteIdsToUpdate: Set<string>;
noteIdsToReload: Set<string>;
@ -769,7 +761,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
prepareChildren(parentNote: FNote) {
utils.assertArguments(parentNote);
const noteList: Node[] = [];
const noteList: Fancytree.FancytreeNewNode[] = [];
const hideArchivedNotes = this.hideArchivedNotes;
@ -837,7 +829,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
const isFolder = note.isFolder();
const node: Node = {
const node: Fancytree.FancytreeNewNode = {
noteId: note.noteId,
parentNoteId: branch.parentNoteId,
branchId: branch.branchId,
@ -849,7 +841,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
refKey: note.noteId,
lazy: true,
folder: isFolder,
expanded: branch.isExpanded && note.type !== "search",
expanded: !!branch.isExpanded && note.type !== "search",
key: utils.randomString(12) // this should prevent some "duplicate key" errors
};
@ -911,7 +903,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
return extraClasses.join(" ");
}
/** @returns {FancytreeNode[]} */
getSelectedNodes(stopOnParents = false) {
return this.tree.getSelectedNodes(stopOnParents);
}
@ -1532,7 +1523,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
// Automatically expand the hoisted note by default
const node = this.getActiveNode();
if (node?.data.noteId === this.noteContext.hoistedNoteId){
if (node && node.data.noteId === this.noteContext.hoistedNoteId){
this.setExpanded(node.data.branchId, true);
}
}