Refactored tree to sidebar
This commit is contained in:
parent
83abc3f456
commit
b3e5d79403
4 changed files with 25 additions and 25 deletions
|
|
@ -92,7 +92,7 @@ button {
|
|||
border-right: none;
|
||||
}
|
||||
|
||||
n2-tree {
|
||||
n2-sidebar {
|
||||
display: none;
|
||||
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ button {
|
|||
|
||||
border-right: 1px solid var(--line-color);
|
||||
|
||||
n2-tree {
|
||||
n2-sidebar {
|
||||
.el-treenodes {
|
||||
margin: 24px 32px 32px 32px;
|
||||
}
|
||||
|
|
@ -508,7 +508,7 @@ dialog.op {
|
|||
}
|
||||
|
||||
#tree {
|
||||
n2-tree {
|
||||
n2-sidebar {
|
||||
.el-treenodes {
|
||||
height: calc(100vh - 64px - 64px);
|
||||
margin: 0px;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { ROOT_NODE } from 'node_store'
|
||||
import { CustomHTMLElement } from './lib/custom_html_element.mjs'
|
||||
import { N2Tree } from 'tree'
|
||||
import { N2Sidebar } from 'sidebar'
|
||||
import { Node } from 'node'
|
||||
|
||||
export class App {
|
||||
constructor() {// {{{
|
||||
this.currentNode = null
|
||||
this.tree = new N2Tree()
|
||||
this.sidebar = new N2Sidebar() // XXX - rename this.tree
|
||||
this.crumbs = new N2Crumbs()
|
||||
this.crumbsElement = document.getElementById('crumbs')
|
||||
this.nodeUI = document.getElementById('note')
|
||||
|
|
@ -22,7 +22,7 @@ export class App {
|
|||
this.goToNode(startNode.UUID, false, false)
|
||||
})
|
||||
|
||||
document.getElementById('tree').append(await this.tree.render())
|
||||
document.getElementById('tree').append(await this.sidebar.render())
|
||||
document.getElementById('tree-nodes')?.focus()
|
||||
|
||||
if (startNode.UUID == ROOT_NODE)
|
||||
|
|
@ -85,7 +85,7 @@ export class App {
|
|||
if (document.activeElement.id === 'tree-nodes') {
|
||||
this.nodeUI.takeFocus()
|
||||
} else {
|
||||
this.tree.focus()
|
||||
this.sidebar.focus()
|
||||
}
|
||||
break
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ export class App {
|
|||
node.reset() // any modifications are discarded.
|
||||
|
||||
this.currentNode = node
|
||||
this.tree.setSelected(node, dontExpand)
|
||||
this.sidebar.setSelected(node, dontExpand)
|
||||
|
||||
const ancestors = await nodeStore.getNodeAncestry(node)
|
||||
_mbus.dispatch('CRUMBS_SET', ancestors, () => this.crumbsElement.replaceChildren(this.crumbs.render()))
|
||||
|
|
@ -193,7 +193,7 @@ export class App {
|
|||
_mbus.dispatch('TREE_EXPANSION', { expand: false, when: 'narrow' })
|
||||
|
||||
// Scrolls node into view.
|
||||
this.tree.makeVisible(node)
|
||||
this.sidebar.makeVisible(node)
|
||||
}//}}}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,12 +59,12 @@ class TreeExpansionHandler {// {{{
|
|||
}
|
||||
}// }}}
|
||||
|
||||
export class N2Tree extends CustomHTMLElement {
|
||||
export class N2Sidebar extends CustomHTMLElement {
|
||||
static {// {{{
|
||||
this.tmpl = document.createElement('template')
|
||||
this.tmpl.innerHTML = `
|
||||
<style>
|
||||
n2-tree {
|
||||
n2-sidebar {
|
||||
#logo {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr min-content;
|
||||
|
|
@ -464,14 +464,14 @@ export class N2Tree extends CustomHTMLElement {
|
|||
treenode?.scrollIntoView({ block: 'nearest' })
|
||||
}// }}}
|
||||
}
|
||||
customElements.define('n2-tree', N2Tree)
|
||||
customElements.define('n2-sidebar', N2Sidebar)
|
||||
|
||||
export class N2TreeNode extends CustomHTMLElement {
|
||||
static {// {{{
|
||||
this.tmpl = document.createElement('template')
|
||||
this.tmpl.innerHTML = `
|
||||
<style>
|
||||
n2-tree:focus-within {
|
||||
n2-sidebar:focus-within {
|
||||
.el-name {
|
||||
&.selected {
|
||||
span {
|
||||
|
|
@ -503,18 +503,18 @@ export class N2TreeNode extends CustomHTMLElement {
|
|||
`
|
||||
}// }}}
|
||||
|
||||
constructor(tree, node, parent) {//{{{
|
||||
constructor(sidebar, node, parent) {//{{{
|
||||
super()
|
||||
this.classList.add('node')
|
||||
|
||||
this.tree = tree
|
||||
this.sidebar = sidebar
|
||||
this.node = node
|
||||
this.parent = parent
|
||||
|
||||
this.children_populated = false
|
||||
this.rendered = false
|
||||
|
||||
this.elExpandToggle.addEventListener('click', () => this.tree.setNodeExpanded(this.node, !this.tree.getNodeExpanded(this.node.UUID)))
|
||||
this.elExpandToggle.addEventListener('click', () => this.sidebar.setNodeExpanded(this.node, !this.sidebar.getNodeExpanded(this.node.UUID)))
|
||||
this.elName.addEventListener('click', () => _mbus.dispatch('TREE_NODE_SELECTED', this.node))
|
||||
|
||||
_mbus.subscribe(`NODE_CHILDREN_FETCHED_${node.UUID}`, () => {
|
||||
|
|
@ -525,7 +525,7 @@ export class N2TreeNode extends CustomHTMLElement {
|
|||
this.render(true)
|
||||
})
|
||||
|
||||
if (this.node.Level === 0 || this.tree.getNodeExpanded(this.node.UUID))
|
||||
if (this.node.Level === 0 || this.sidebar.getNodeExpanded(this.node.UUID))
|
||||
this.fetchChildren()
|
||||
}// }}}
|
||||
async fetchChildren() {//{{{
|
||||
|
|
@ -537,16 +537,16 @@ export class N2TreeNode extends CustomHTMLElement {
|
|||
return this
|
||||
|
||||
// Fetch the next level of children if the parent tree node is expanded and our children thus will be visible.
|
||||
const expanded = this.node.hasChildren() && this.tree.getNodeExpanded(this.node.UUID)
|
||||
const expanded = this.node.hasChildren() && this.sidebar.getNodeExpanded(this.node.UUID)
|
||||
|
||||
if (!this.children_populated && this.tree.getNodeExpanded(this.parent?.node.UUID)) {
|
||||
if (!this.children_populated && this.sidebar.getNodeExpanded(this.parent?.node.UUID)) {
|
||||
this.node.fetchChildren().then(() => this.children_populated = true)
|
||||
}
|
||||
|
||||
// Update the name and selected status
|
||||
this.elName.querySelector('span').innerText = this.node.get('Name')
|
||||
|
||||
if (this.tree.isSelected(this.node))
|
||||
if (this.sidebar.isSelected(this.node))
|
||||
this.elName.classList.add('selected')
|
||||
else
|
||||
this.elName.classList.remove('selected')
|
||||
|
|
@ -565,7 +565,7 @@ export class N2TreeNode extends CustomHTMLElement {
|
|||
this.setImgSrc(this.elExpand, `/images/${window._VERSION}/icon_home.svg`)
|
||||
else if (!this.node.hasChildren())
|
||||
this.setImgSrc(this.elExpand, `/images/${window._VERSION}/leaf.svg`)
|
||||
else if (this.tree.getNodeExpanded(this.node.UUID))
|
||||
else if (this.sidebar.getNodeExpanded(this.node.UUID))
|
||||
this.setImgSrc(this.elExpand, `/images/${window._VERSION}/expanded.svg`)
|
||||
else
|
||||
this.setImgSrc(this.elExpand, `/images/${window._VERSION}/collapsed.svg`)
|
||||
|
|
@ -575,10 +575,10 @@ export class N2TreeNode extends CustomHTMLElement {
|
|||
let children = []
|
||||
if (expanded)
|
||||
children = this.node.Children.map(node => {
|
||||
let treenode = this.tree.treeNodeComponents[node.UUID]
|
||||
let treenode = this.sidebar.treeNodeComponents[node.UUID]
|
||||
if (treenode === undefined) {
|
||||
treenode = new N2TreeNode(this.tree, node, this)
|
||||
this.tree.treeNodeComponents[node.UUID] = treenode
|
||||
treenode = new N2TreeNode(this.sidebar, node, this)
|
||||
this.sidebar.treeNodeComponents[node.UUID] = treenode
|
||||
_mbus.dispatch(`NODE_COMPONENT_EXIST_${node.UUID}`)
|
||||
}
|
||||
return treenode
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
"crypto": "/js/{{ .VERSION }}/crypto.mjs",
|
||||
"node_store": "/js/{{ .VERSION }}/node_store.mjs",
|
||||
"node": "/js/{{ .VERSION }}/page_node.mjs",
|
||||
"tree": "/js/{{ .VERSION }}/tree.mjs"
|
||||
"sidebar": "/js/{{ .VERSION }}/sidebar.mjs"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue