// SPDX-License-Identifier: AGPL-3.0-or-later import { LitElement, html, css, } from "//shared.localhost:8888/third_party/lit/lit-all.min.js"; import { SearchController } from "//shared.localhost:8888/search/controller.js"; export class UrlBarOverlay extends LitElement { static properties = { open: { type: Boolean, reflect: true }, url: { type: String }, groups: { state: true }, onNavigate: { type: Function }, onSelectWebView: { type: Function }, }; static styles = css` @import url(//system.localhost:8888/url_bar_overlay.css); `; constructor() { super(); this.open = false; this.url = ""; this.groups = []; this.onNavigate = null; this.onSelectWebView = null; this.controller = new SearchController({ onNavigate: (url) => this.navigateTo(url), onSelectWebView: (windowId, webviewId) => this.selectWebView(windowId, webviewId), onResultsChanged: (results, groups) => { this.groups = groups; }, }); } updated(changedProperties) { if (changedProperties.has("open") && this.open) { // Focus and select the input when opening this.updateComplete.then(() => { const input = this.shadowRoot.querySelector(".search-input"); if (input) { input.focus(); input.select(); } }); // Initial query with current URL this.controller.queryImmediate(this.url); } } handleBackdropClick() { this.close(); } handleKeydown(e) { if (e.key === "Escape") { e.preventDefault(); this.close(); } else if (e.key === "Enter") { e.preventDefault(); const input = this.shadowRoot.querySelector(".search-input"); this.controller.handleSubmit(input?.value || ""); } } handleInput(e) { this.controller.query(e.target.value); } handleResultClick(e, result) { e.preventDefault(); this.controller.handleResultClick(result); } navigateTo(url) { if (this.onNavigate) { this.onNavigate(url); } this.close(); } selectWebView(windowId, webviewId) { if (this.onSelectWebView) { this.onSelectWebView(windowId, webviewId); } this.close(); } close() { this.open = false; this.groups = []; this.controller.clear(); this.dispatchEvent(new CustomEvent("close")); } render() { return html`
${this.groups.map( (group) => html`
${group.providerIcon ? html`` : null}
${group.items.map( (result) => html`
this.handleResultClick(e, result)} > ${result.kind === "link" || result.kind === "webview" ? html`${result.value.title}` : html`${result.value}`}
` )}
` )}
`; } } customElements.define("url-bar-overlay", UrlBarOverlay);