('[data-toolbar-option]'));
const active = items[this._activeIndex];
active?.scrollIntoView?.({block: 'nearest'});
});
}
getActiveIndex() {
return this._activeIndex;
}
private _onClickItem = (e: MouseEvent) => {
const target = e.currentTarget as HTMLElement | null;
if (!target) return;
const idx = parseInt(target.dataset.index || '-1', 10);
if (Number.isNaN(idx)) return;
this.setActiveIndex(idx);
const item = this.results?.[idx];
if (!item) return;
this.dispatchEvent(new CustomEvent('zn-format-select', {
bubbles: true,
composed: true,
detail: {icon: item.icon, label: item.label, format: item.format, value: item.value, key: item.key}
}));
}
protected willUpdate(changed: PropertyValues) {
if (changed.has('results')) {
// Reset active index when results change
this._activeIndex = this.results?.length ? 0 : -1;
}
}
render() {
return html`
${Array.isArray(this.results) && this.results.length > 0 ? (
this.results.slice(0, 20).map((res, i) => html`
`)
) : html`
${this.query ? 'No results' : 'Type something'}
`}
`;
}
}
ContextMenuComponent.define('zn-context-menu');