Add UI web components and adjust .gitignore

This commit is contained in:
2026-01-13 00:40:05 -05:00
parent 6f508ed194
commit b67235b93d
6 changed files with 594 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
// Toolbar component logic
class Toolbar extends HTMLElement {
constructor() {
super();
// Attach a shadow root and clone the template defined in toolbar.html
this.attachShadow({ mode: 'open' });
const tmpl = document.getElementById('toolbar-template');
if (!tmpl) {
console.error('Toolbar: template not found in DOM');
return;
}
this.shadowRoot.appendChild(tmpl.content.cloneNode(true));
// Bind internal handlers
this._onColorChange = this._onColorChange.bind(this);
this._onGridChange = this._onGridChange.bind(this);
}
connectedCallback() {
// Listen for events bubbled up from slotted child components
this.addEventListener('colorchange', this._onColorChange);
this.addEventListener('gridchange', this._onGridChange);
}
disconnectedCallback() {
// Clean up listeners when the element is removed
this.removeEventListener('colorchange', this._onColorChange);
this.removeEventListener('gridchange', this._onGridChange);
}
// Forward background color changes as a toolbarspecific event
_onColorChange(e) {
this.dispatchEvent(
new CustomEvent('bgcolorchange', {
detail: e.detail,
bubbles: true,
composed: true,
})
);
}
// Forward grid setting changes as a toolbarspecific event
_onGridChange(e) {
this.dispatchEvent(
new CustomEvent('gridsettingschange', {
detail: e.detail,
bubbles: true,
composed: true,
})
);
}
}
// Register the custom element; the tag name follows kebabcase convention
customElements.define('toolbar-component', Toolbar);