Fixed recursive open of nodes, bumped to v29

This commit is contained in:
Magnus Åhall 2026-06-16 09:59:01 +02:00
parent c36b4ace13
commit d6d8b64bb9
2 changed files with 23 additions and 7 deletions

View file

@ -23,7 +23,7 @@ import (
"text/template"
)
const VERSION = "v28"
const VERSION = "v29"
const CONTEXT_USER = 1
const SYNC_PAGINATION = 200

View file

@ -197,9 +197,8 @@ export class N2Sidebar extends CustomHTMLElement {
this.expandedNodes[UUID] = false
return this.expandedNodes[UUID]
}//}}}
setNodeExpanded(node, value) {//{{{
async setNodeExpanded(node, value) {//{{{
let expanded = this.expandedNodes[node.UUID]
if (expanded === undefined) {
this.expandedNodes[node.UUID] = false
expanded = false
@ -446,14 +445,20 @@ export class N2Sidebar extends CustomHTMLElement {
return currNode
}//}}}
async recursiveExpand(node, state) {//{{{
if (!state) {
await this.setNodeExpanded(node, false)
return
}
if (state)
await this.setNodeExpanded(node, true)
// An expanded node needs to have its children fetched.
if (!node.hasFetchedChildren())
await node.fetchChildren()
for (const child of node.Children)
await this.recursiveExpand(child, state)
if (!state)
await this.setNodeExpanded(node, false)
}//}}}
async makeVisible(node, providedAncestors, dontExpand) {// {{{
const treenode = this.treeNodeComponents[node.UUID]
@ -577,7 +582,7 @@ export class N2TreeNode extends CustomHTMLElement {
this.rendered = false
this.dragNode = null
this.elExpandToggle.addEventListener('click', () => this.sidebar.setNodeExpanded(this.node, !this.sidebar.getNodeExpanded(this.node.UUID)))
this.elExpandToggle.addEventListener('click', event => this.expandNode(event))
this.elName.addEventListener('click', () => _mbus.dispatch('TREE_NODE_SELECTED', this.node))
_mbus.subscribe(`NODE_EXPAND_${node.UUID}`, _state => {
@ -592,6 +597,7 @@ export class N2TreeNode extends CustomHTMLElement {
this.elName.addEventListener('dragenter', event => this.dragEnter(event))
this.elName.addEventListener('dragleave', event => this.dragLeave(event))
}// }}}
dragStart(e) {// {{{
if (this.node.isModified()) {
alert('Save note before moving it.')
@ -654,6 +660,16 @@ export class N2TreeNode extends CustomHTMLElement {
_app.dragIcon.icon('')
this.classList.remove('drag-target')
}// }}}
async expandNode(event) {// {{{
const expanded = _app.sidebar.getNodeExpanded(this.node.UUID)
if (event.shiftKey) {
_app.sidebar.recursiveExpand(this.node, !expanded)
} else {
_app.sidebar.setNodeExpanded(this.node, !expanded)
}
}// }}}
async fetchChildren(force_fetch) {//{{{
if (this.children_populated && !force_fetch)
return