mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 08:29:00 +01:00
fix(tree): type issues & error if active node is empty
This commit is contained in:
parent
cc0646e79c
commit
afa92551ea
26
apps/client/src/types-fancytree.d.ts
vendored
26
apps/client/src/types-fancytree.d.ts
vendored
@ -215,6 +215,30 @@ declare namespace Fancytree {
|
|||||||
enableUpdate(enabled: boolean): void;
|
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. */
|
/** A FancytreeNode represents the hierarchical data model and operations. */
|
||||||
interface FancytreeNode {
|
interface FancytreeNode {
|
||||||
// #region Properties
|
// #region Properties
|
||||||
@ -227,7 +251,7 @@ declare namespace Fancytree {
|
|||||||
/** Display name (may contain HTML) */
|
/** Display name (may contain HTML) */
|
||||||
title: string;
|
title: string;
|
||||||
/** Contains all extra data that was passed on node creation */
|
/** 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. */
|
/** 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[];
|
children: FancytreeNode[];
|
||||||
/** Use isExpanded(), setExpanded() to access this property. */
|
/** Use isExpanded(), setExpanded() to access this property. */
|
||||||
|
|||||||
@ -173,14 +173,6 @@ interface ExpandedSubtreeResponse {
|
|||||||
branchIds: string[];
|
branchIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Node extends Fancytree.NodeData {
|
|
||||||
noteId: string;
|
|
||||||
parentNoteId: string;
|
|
||||||
branchId: string;
|
|
||||||
isProtected: boolean;
|
|
||||||
noteType: NoteType;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RefreshContext {
|
interface RefreshContext {
|
||||||
noteIdsToUpdate: Set<string>;
|
noteIdsToUpdate: Set<string>;
|
||||||
noteIdsToReload: Set<string>;
|
noteIdsToReload: Set<string>;
|
||||||
@ -769,7 +761,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
prepareChildren(parentNote: FNote) {
|
prepareChildren(parentNote: FNote) {
|
||||||
utils.assertArguments(parentNote);
|
utils.assertArguments(parentNote);
|
||||||
|
|
||||||
const noteList: Node[] = [];
|
const noteList: Fancytree.FancytreeNewNode[] = [];
|
||||||
|
|
||||||
const hideArchivedNotes = this.hideArchivedNotes;
|
const hideArchivedNotes = this.hideArchivedNotes;
|
||||||
|
|
||||||
@ -837,7 +829,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
const isFolder = note.isFolder();
|
const isFolder = note.isFolder();
|
||||||
|
|
||||||
const node: Node = {
|
const node: Fancytree.FancytreeNewNode = {
|
||||||
noteId: note.noteId,
|
noteId: note.noteId,
|
||||||
parentNoteId: branch.parentNoteId,
|
parentNoteId: branch.parentNoteId,
|
||||||
branchId: branch.branchId,
|
branchId: branch.branchId,
|
||||||
@ -849,7 +841,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
refKey: note.noteId,
|
refKey: note.noteId,
|
||||||
lazy: true,
|
lazy: true,
|
||||||
folder: isFolder,
|
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
|
key: utils.randomString(12) // this should prevent some "duplicate key" errors
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -911,7 +903,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
return extraClasses.join(" ");
|
return extraClasses.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {FancytreeNode[]} */
|
|
||||||
getSelectedNodes(stopOnParents = false) {
|
getSelectedNodes(stopOnParents = false) {
|
||||||
return this.tree.getSelectedNodes(stopOnParents);
|
return this.tree.getSelectedNodes(stopOnParents);
|
||||||
}
|
}
|
||||||
@ -1532,7 +1523,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
// Automatically expand the hoisted note by default
|
// Automatically expand the hoisted note by default
|
||||||
const node = this.getActiveNode();
|
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);
|
this.setExpanded(node.data.branchId, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user