Das Feld steht in den Einstellungen aller Widgets und je Karte und Merkmal. Es trägt nur die Zeichnung des gewählten Symbols; der Katalog mit allen Zeichnungen kommt beim Öffnen in einer Anfrage (nur Redaktion und Katalogverwaltung). Mit Tastatur bedienbar. Dazu Katalog-Dokumentation, Tokens und Abnahme mit Screenshots (lokal geprüft, nicht auf luf-test). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
124 lines
7.6 KiB
PHP
124 lines
7.6 KiB
PHP
{{-- Symbolwähler (Symbolbibliothek): Vorschau und Raster mit Gruppen und Suche. Katalog und Bilder werden erst beim Öffnen geladen. --}}
|
|
@php
|
|
$statePath = $getStatePath();
|
|
$wert = $getState();
|
|
$titel = is_string($wert) && $wert !== '' ? (\App\Support\Brand\SymbolCatalog::title($wert) ?? $wert) : null;
|
|
$muss = $field->isRequired();
|
|
$id = 'symbolfeld-'.md5($statePath);
|
|
// Die Zeichnung des gewählten Symbols steht schon im Formular; der Katalog mit allen anderen wird erst beim Öffnen geladen.
|
|
$start = is_string($wert) && $wert !== '' && array_key_exists($wert, \App\Support\Brand\SymbolCatalog::options()) ? (string) \App\Support\Brand\Symbols::symbol($wert) : '';
|
|
@endphp
|
|
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
|
|
<div class="vw-symbolfeld" data-start-key="{{ $wert }}" data-start-titel="{{ $titel }}"
|
|
x-data="{
|
|
state: $wire.{{ $field->applyStateBindingModifiers("\$entangle('{$statePath}')") }},
|
|
offen: false,
|
|
suche: '',
|
|
gruppen: null,
|
|
fehler: false,
|
|
katalogUrl: @js(route('editorial.symbols', absolute: false)),
|
|
// Der Ausdruck in x-data bleibt bei jeder Antwort des Servers gleich, sonst baut Livewire das Feld neu auf und es vergisst
|
|
// den geladenen Katalog und das offene Raster. Was der Server wechselt, steht in data-Attributen und einer Vorlage.
|
|
eintrag(key) {
|
|
for (const g of (this.gruppen ?? [])) {
|
|
const t = g.items.find((i) => i.key === key);
|
|
if (t) return t;
|
|
}
|
|
return null;
|
|
},
|
|
zeichnung(key) {
|
|
if (!key) { return ''; }
|
|
return this.eintrag(key)?.svg ?? (key === this.$root.dataset.startKey ? this.$refs.start.innerHTML : '');
|
|
},
|
|
titel(key) {
|
|
if (!key) { return ''; }
|
|
return this.eintrag(key)?.title ?? (key === this.$root.dataset.startKey ? this.$root.dataset.startTitel : key);
|
|
},
|
|
gefiltert() {
|
|
const q = this.suche.trim().toLowerCase();
|
|
return (this.gruppen ?? [])
|
|
.map((g) => ({ name: g.name, items: q === '' ? g.items : g.items.filter((i) => i.search.includes(q)) }))
|
|
.filter((g) => g.items.length > 0);
|
|
},
|
|
anzahl() { return this.gefiltert().reduce((n, g) => n + g.items.length, 0); },
|
|
async oeffnen() {
|
|
this.offen = true;
|
|
this.fehler = false;
|
|
// Die Suche nimmt Eingaben sofort an, auch wenn der Katalog noch lädt.
|
|
this.$nextTick(() => this.$refs.suche?.focus());
|
|
if (this.gruppen === null) {
|
|
try {
|
|
window.lufSymbolKatalog ??= fetch(this.katalogUrl, { headers: { Accept: 'application/json' }, credentials: 'same-origin' })
|
|
.then((r) => { if (!r.ok) { throw new Error(); } return r.json(); });
|
|
this.gruppen = (await window.lufSymbolKatalog).groups;
|
|
} catch (e) {
|
|
window.lufSymbolKatalog = undefined;
|
|
this.fehler = true;
|
|
}
|
|
}
|
|
},
|
|
schliessen(zurueck = true) {
|
|
this.offen = false;
|
|
this.suche = '';
|
|
if (zurueck) { this.$nextTick(() => this.$refs.ausloeser?.focus()); }
|
|
},
|
|
waehlen(key) { this.state = key; this.schliessen(); },
|
|
entfernen() { this.state = null; this.$refs.ausloeser?.focus(); },
|
|
taste(e) {
|
|
const kacheln = [...this.$refs.raster.querySelectorAll('[data-kachel]')];
|
|
const i = kacheln.indexOf(document.activeElement);
|
|
if (i < 0) { return; }
|
|
const spalten = Math.max(1, getComputedStyle(document.activeElement.closest('[data-kacheln]')).gridTemplateColumns.split(' ').length);
|
|
const ziel = { ArrowRight: i + 1, ArrowLeft: i - 1, ArrowDown: i + spalten, ArrowUp: i - spalten, Home: 0, End: kacheln.length - 1 }[e.key];
|
|
if (ziel === undefined) { return; }
|
|
e.preventDefault();
|
|
kacheln[Math.min(Math.max(ziel, 0), kacheln.length - 1)]?.focus();
|
|
},
|
|
}"
|
|
x-on:keydown.escape.stop="if (offen) { schliessen(); }"
|
|
x-on:click.outside="if (offen) { schliessen(false); }">
|
|
<div class="vw-symbolfeld-wahl">
|
|
<span class="vw-symbolfeld-vorschau" aria-hidden="true" x-html="zeichnung(state)">{!! $start !!}</span>
|
|
<template x-ref="start">{!! $start !!}</template>
|
|
<span class="vw-symbolfeld-name" aria-live="polite">
|
|
<span x-show="state" x-text="titel(state)">{{ $titel }}</span>
|
|
<span class="vw-symbolfeld-leer" x-show="!state" @if (filled($wert)) x-cloak @endif>{{ $muss ? 'Noch kein Symbol gewählt.' : 'Kein Symbol.' }}</span>
|
|
</span>
|
|
<button type="button" class="vw-symbolfeld-knopf" x-ref="ausloeser" x-on:click="offen ? schliessen() : oeffnen()"
|
|
:aria-expanded="offen ? 'true' : 'false'" aria-controls="{{ $id }}-panel">
|
|
<span x-text="state ? 'Anderes Symbol wählen' : 'Symbol wählen'">{{ filled($wert) ? 'Anderes Symbol wählen' : 'Symbol wählen' }}</span>
|
|
</button>
|
|
@unless ($muss)
|
|
<button type="button" class="vw-symbolfeld-knopf is-leise" x-show="state" x-on:click="entfernen()" @if (blank($wert)) x-cloak @endif>Entfernen</button>
|
|
@endunless
|
|
</div>
|
|
|
|
<div class="vw-symbolfeld-panel" id="{{ $id }}-panel" x-show="offen" x-cloak x-ref="raster" x-on:keydown="taste($event)">
|
|
<label class="vw-sr" for="{{ $id }}-suche">Symbol suchen</label>
|
|
<input id="{{ $id }}-suche" class="vw-symbolfeld-suche" type="search" x-ref="suche" x-model="suche" autocomplete="off"
|
|
placeholder="Suchen, zum Beispiel Film" x-on:keydown.enter.prevent="$refs.raster.querySelector('[data-kachel]')?.focus()">
|
|
<p class="vw-symbolfeld-status" role="status">
|
|
<span x-show="gruppen === null && !fehler">Symbole werden geladen …</span>
|
|
<span x-show="fehler" x-cloak>Die Symbole konnten nicht geladen werden. Bitte erneut öffnen.</span>
|
|
<span x-show="gruppen !== null" x-cloak x-text="anzahl() === 0 ? 'Kein Symbol gefunden. Prüfe die Schreibweise.' : anzahl() + (anzahl() === 1 ? ' Symbol' : ' Symbole')"></span>
|
|
</p>
|
|
<div class="vw-symbolfeld-gruppen">
|
|
<template x-for="gruppe in gefiltert()" :key="gruppe.name">
|
|
<section class="vw-symbolfeld-gruppe">
|
|
<h4 x-text="gruppe.name"></h4>
|
|
<div class="vw-symbolfeld-kacheln" data-kacheln>
|
|
<template x-for="item in gruppe.items" :key="item.key">
|
|
<button type="button" class="vw-symbolfeld-kachel" data-kachel :class="{ 'is-gewaehlt': state === item.key }"
|
|
:aria-pressed="state === item.key ? 'true' : 'false'" x-on:click="waehlen(item.key)">
|
|
<span class="vw-symbolfeld-bild" aria-hidden="true" x-html="item.svg"></span>
|
|
<span x-text="item.title"></span>
|
|
</button>
|
|
</template>
|
|
</div>
|
|
</section>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</x-dynamic-component>
|