Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | 48x | import { html, nothing, type CSSResultGroup, type TemplateResult } from 'lit';
import { FrameElement } from '../base.ts';
import type { BeMusicDOMSelectFrame } from '@be-music/player-skin-sdk';
import { screenStyles } from '../styles/screen.ts';
export class BeMusicSelectScreenElement extends FrameElement<BeMusicDOMSelectFrame> {
static override styles: CSSResultGroup = screenStyles;
private focusPending = false;
private narrow = false;
private filtersOpen = false;
private sizeObserver: ResizeObserver | undefined;
override connectedCallback(): void {
super.connectedCallback();
this.sizeObserver = new ResizeObserver(([entry]) => {
const narrow = entry!.contentRect.width <= 640;
if (this.narrow !== narrow) {
this.narrow = narrow;
this.requestUpdate();
}
});
this.sizeObserver.observe(this);
}
override disconnectedCallback(): void {
this.sizeObserver?.disconnect();
super.disconnectedCallback();
}
public focusSearch(): void {
const search = this.renderRoot.querySelector<HTMLInputElement>('input[type=search]');
if (search) {
search.focus();
search.select();
} else this.focusPending = true;
}
protected override updated(): void {
if (this.focusPending) {
this.focusPending = false;
this.focusSearch();
}
}
protected override render(): TemplateResult | typeof nothing {
const f = this.frame;
if (!f) return nothing;
return html`<section class="screen" part="screen" @pointerdown=${() => this.emit('gesture-request', undefined)}>
<header part="header">
<div class="heading">
<p class="eyebrow" part="eyebrow"><slot name="eyebrow"></slot></p>
<h1 part="title"><slot name="title">Collection</slot></h1>
</div>
<div class="search" part="search">
<input
class="input"
type="search"
aria-label="Search charts"
aria-describedby="search-error"
aria-invalid=${f.searchError !== undefined ? 'true' : 'false'}
placeholder="Search title, artist… (? for a filter)"
.value=${f.searchQuery}
?disabled=${f.launching}
@input=${(e: InputEvent) => {
if (!e.isComposing) this.emit('search-change', { value: (e.currentTarget as HTMLInputElement).value });
}}
@compositionend=${(e: CompositionEvent) => this.emit('search-change', { value: (e.currentTarget as HTMLInputElement).value })}
@keydown=${(e: KeyboardEvent) => {
if (e.isComposing) return;
const input = e.currentTarget as HTMLInputElement;
if (e.key === 'Escape') {
e.preventDefault();
input.value = '';
this.emit('search-change', { value: '' });
input.blur();
} else if (e.key === 'Enter') {
e.preventDefault();
input.blur();
}
}}
/>
<p id="search-error" class="search-error" role="status">${f.searchError ?? ''}</p>
</div>
</header>
<div class="columns" part="columns">
<section class="browse">
<div class="actions folder" part="folder">
<button
class="btn"
data-size="sm"
data-variant="outline"
?disabled=${f.launching}
@click=${() => this.emit('back-request', undefined)}
>
Back
</button>
<p class="muted">${f.folderLabel ?? 'All folders'}</p>
</div>
<details
class="select-filters"
.open=${!this.narrow || this.filtersOpen}
@toggle=${(event: Event) => {
if (this.narrow) this.filtersOpen = (event.currentTarget as HTMLDetailsElement).open;
}}
>
<summary>Play settings & filters</summary>
<be-music-play-options
.options=${f.playOptions}
.choices=${f.playOptionChoices}
.disabled=${f.launching}
></be-music-play-options>
</details>
<be-music-chart-list
exportparts="list,row"
.entries=${f.entries}
.selectedIndex=${f.selectedIndex}
.disabled=${f.launching}
></be-music-chart-list>
</section>
<be-music-chart-details
exportparts="panel:details-panel,title:chart-title"
.entry=${f.entries[f.selectedIndex]}
.launching=${f.launching}
.readmeAvailable=${f.hasReadme}
></be-music-chart-details>
</div>
<slot></slot>
</section>`;
}
}
|