Upgraded Crumbs and Crumb to custom HTML elements.

This commit is contained in:
Magnus Åhall 2026-04-29 15:33:04 +02:00
parent 993bbf59f3
commit 99063d34be

View file

@ -1,4 +1,5 @@
import { ROOT_NODE } from 'node_store' import { ROOT_NODE } from 'node_store'
import { CustomHTMLElement } from './lib/custom_html_element.mjs'
import { N2Tree } from 'tree' import { N2Tree } from 'tree'
import { NodeUINative, Node } from 'node' import { NodeUINative, Node } from 'node'
import { SyncProgress } from 'sync' import { SyncProgress } from 'sync'
@ -7,7 +8,7 @@ export class App {
constructor() {// {{{ constructor() {// {{{
this.currentNode = null this.currentNode = null
this.treeNative = new N2Tree() this.treeNative = new N2Tree()
this.crumbs = new Crumbs() this.crumbs = new N2Crumbs()
this.crumbsElement = document.getElementById('crumbs') this.crumbsElement = document.getElementById('crumbs')
this.nodeUI = new NodeUINative(document.getElementById('note')) this.nodeUI = new NodeUINative(document.getElementById('note'))
@ -196,11 +197,17 @@ export class App {
}//}}} }//}}}
} }
class Crumbs { class N2Crumbs extends CustomHTMLElement {
static {// {{{
this.tmpl = document.createElement('template')
this.tmpl.innerHTML = `
`
}// }}}
constructor() {// {{{ constructor() {// {{{
super()
this.classList.add('crumbs')
this.crumbs = [] this.crumbs = []
this.crumbsDiv = document.createElement('div')
this.crumbsDiv.classList.add('crumbs')
_mbus.subscribe('CRUMBS_SET', event => { _mbus.subscribe('CRUMBS_SET', event => {
this.crumbs = event.detail.data this.crumbs = event.detail.data
@ -208,38 +215,40 @@ class Crumbs {
}// }}} }// }}}
render() {// {{{ render() {// {{{
const crumbs = this.crumbs.map(node => const crumbs = this.crumbs.map(node =>
(new Crumb( new N2Crumb(
node.get('Name'), node.get('Name'),
node.UUID, node.UUID,
)).render() )
) )
const start = (new Crumb('Start', ROOT_NODE)).render() const start = new N2Crumb('Start', ROOT_NODE)
crumbs.push(start) crumbs.push(start)
this.crumbsDiv.replaceChildren(...crumbs.reverse()) this.replaceChildren(...crumbs.reverse())
return this.crumbsDiv return this
}// }}} }// }}}
} }
customElements.define('n2-crumbs', N2Crumbs)
class Crumb { class N2Crumb extends CustomHTMLElement {
static {// {{{
this.tmpl = document.createElement('template')
this.tmpl.innerHTML = `
<a data-el="link"></a>
`
}// }}}
constructor(label, uuid) {// {{{ constructor(label, uuid) {// {{{
super()
this.classList.add('crumb')
this.label = label this.label = label
this.uuid = uuid this.uuid = uuid
}// }}}
render() {// {{{
const crumb = document.createElement('div')
crumb.classList.add('crumb')
const link = document.createElement('a')
link.href = `/notes2#${this.uuid}`
link.innerText = this.label
crumb.appendChild(link)
return crumb
this.elLink.href = `/notes2#${this.uuid}`
this.elLink.innerText = this.label
}// }}} }// }}}
} }
customElements.define('n2-crumb', N2Crumb)
function tmpl(html) {// {{{ function tmpl(html) {// {{{
const el = document.createElement('template') const el = document.createElement('template')