mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(ui): render the Cockpit signal rows from a store, keeping focus
The Cockpit controller no longer reconciles the live signal rows by hand. publishCockpitSignals turns its signal items into rows, keyed by the signal and its action target as before, with repeats of a key numbered, and publishes them to the gev-cockpit store; a new CockpitSignalList component renders them with a keyed v-for inside the briefing card. Rows reorder several times a second, and a browser blurs any element it moves. The new v-focus-safe-children directive turns Vue's move of the row holding focus into moves of the rows around it, reaching the same order while the focused row stays connected, and before the focused row is removed it hands focus to the shown briefing page's tab, or the collapse toggle, as the reconciler did. Selection stays with the controller's click listener. The focus test now runs the real components over happy-dom and counts any move or removal of the focused row as a loss, including across 60 random reorders. The Cockpit QA script publishes and waits a frame before reading the rows.
This commit is contained in:
1 parent
a2bca0fb22
commit
58504e370c
12 files changed
+438
-387
No files matched your search
@@ -1,15 +1,15 @@
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import { computed, useTemplateRef } from 'vue';
|
||||
import { createBriefState } from '../../cockpitBriefPages.js';
|
||||
import { useCockpitStore } from '../../stores/cockpit.js';
|
||||
import CockpitRoute from './CockpitRoute.vue';
|
||||
import CockpitSignalList from './CockpitSignalList.vue';
|
||||
|
||||
// The Cockpit briefing card. The Cockpit controller presents its pages,
|
||||
// cycle toggle, regional news and local conditions; until it does, the card
|
||||
// shows the state it starts in. The controls keep the controller's
|
||||
// listeners. The route card renders itself; the signal list keeps its
|
||||
// owner's bindings, so nothing here binds it.
|
||||
// listeners. The route card and the signal rows render themselves.
|
||||
const { brief } = storeToRefs(useCockpitStore());
|
||||
const initial = createBriefState();
|
||||
const b = computed(() => brief.value ?? initial);
|
||||
@@ -18,10 +18,21 @@ const streamState = computed(() => ({
|
||||
'data-brief-page': brief.value?.pageId,
|
||||
'data-regional-status': brief.value?.regionalStatus || undefined,
|
||||
}));
|
||||
// A departed contact cannot stay selectable. Its row hands focus to the
|
||||
// shown page's tab, which stays, so keyboard traversal carries on from the
|
||||
// card's footer instead of the top of the page.
|
||||
const stream = useTemplateRef('stream');
|
||||
function leaveSignals() {
|
||||
const card = stream.value;
|
||||
(
|
||||
card?.querySelector(`[data-cockpit-brief-index="${b.value.pageIndex}"]`) ??
|
||||
card?.querySelector('#cockpit-signal-toggle')
|
||||
)?.focus({ preventScroll: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside id="cockpit-signal-stream" class="cockpit-signal-window" aria-label="Cockpit briefing carousel" hidden data-i18n-aria-label v-bind="streamState">
|
||||
<aside id="cockpit-signal-stream" class="cockpit-signal-window" aria-label="Cockpit briefing carousel" hidden data-i18n-aria-label v-bind="streamState" ref="stream">
|
||||
<CockpitRoute />
|
||||
<header class="cockpit-signal-header">
|
||||
<div class="cockpit-brief-heading">
|
||||
@@ -44,7 +55,7 @@ const streamState = computed(() => ({
|
||||
</header>
|
||||
<div class="cockpit-brief-stage">
|
||||
<section data-cockpit-brief-page="signals" aria-label="Live signals" data-i18n-aria-label :hidden="b.pageId !== 'signals'">
|
||||
<ol id="cockpit-signal-list" class="cockpit-signal-list" aria-live="polite"></ol>
|
||||
<CockpitSignalList :leave="leaveSignals" />
|
||||
</section>
|
||||
<section data-cockpit-brief-page="news" aria-label="Latest regional news" data-i18n-aria-label :hidden="b.pageId !== 'news'">
|
||||
<div id="cockpit-news-status" class="cockpit-brief-status" :hidden="b.news.statusHidden" :data-state="b.news.state ?? undefined">{{ b.news.status }}</div>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import { vFocusSafeChildren } from '../../rail/focusSafeChildren.js';
|
||||
import { useCockpitStore } from '../../stores/cockpit.js';
|
||||
|
||||
// The Cockpit's live signal rows. The Cockpit controller presents them;
|
||||
// until it does, the list is empty. Rows reorder several times a second,
|
||||
// so the list keeps keyboard focus on its row while the others move, and
|
||||
// moves focus to `leave` before the focused row goes. Selection stays with
|
||||
// the controller's click listener. The template is one line: templates keep
|
||||
// whitespace.
|
||||
defineProps({
|
||||
leave: { type: Function, required: true },
|
||||
});
|
||||
const { signals } = storeToRefs(useCockpitStore());
|
||||
const rows = computed(() => signals.value ?? []);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ol id="cockpit-signal-list" v-focus-safe-children="leave" class="cockpit-signal-list" aria-live="polite"><li v-for="row in rows" :key="row.key" :class="row.className" :data-signal-key="row.key"><time>{{ row.time }}</time><div><button v-if="row.target" type="button" class="cockpit-signal-target" :data-signal-layer="row.target.layerId" :data-signal-id="row.target.id" :aria-label="row.target.label"><span class="cockpit-signal-target-label">{{ row.title }}</span><span class="cockpit-signal-target-rule" aria-hidden="true"></span><span class="material-symbols-outlined cockpit-signal-target-chevron" aria-hidden="true">chevron_right</span></button><strong v-else>{{ row.title }}</strong><span>{{ row.detail }}</span></div></li></ol>
|
||||
</template>
|
||||
Reference in new issue
Block a user