feat(import): render the file import in a GeoImport view

The file import no longer looks up or listens on the Import button, the
picker or the list, and no longer restores focus itself. It connects
importGeoFiles, toggleGeoImport, flyToGeoImport and removeGeoImport to
the display store. A new GeoImport view owns the button, the picker, the
rows and the hint: it opens the picker once the import has presented
itself, sends the pick and the row buttons' actions, and hands keyboard
focus on with v-focus-safe-children before a focused row goes, to the
next row's same button, else the previous row's, else Import.
This commit is contained in:
Sameh Khamis committed 2026-11-01 10:23:35 -08:00
1 parent a6e85db8be
commit 42c3cc12b1
11 files changed
+303 -322

No files matched your search

+6 -15
View File
@@ -6,14 +6,15 @@ import { vPanelState } from '../../rail/panelState.js';
import PanelCollapseButton from '../../rail/PanelCollapseButton.vue';
import { vRangeValue } from '../../rail/rangeValue.js';
import UiSegmented from '../../kit/UiSegmented.vue';
import GeoImport from './GeoImport.vue';
import { useDisplayStore } from '../../stores/display.js';
// The Display panel. VisualSettings presents the HUD, Sonar, Scope,
// Celestial, detection, bloom and sharpen, AircraftDisplay the 3D group, the
// draw tool its controls and the file import its list, and each publishes
// them; until they do, the panel shows its initial markup.
// Celestial, detection, bloom and sharpen, AircraftDisplay the 3D group and
// the draw tool its controls, and each publishes them; until they do, the
// panel shows its initial markup. GeoImport renders the file import.
const display = useDisplayStore();
const { view, models3d, draw, geoImport } = storeToRefs(display);
const { view, models3d, draw } = storeToRefs(display);
// A control's change goes to its owner (DisplayBindings or the draw tool).
const act = (name, ...args) => display.act(name, ...args);
const integer = (event) => parseInt(event.target.value, 10);
@@ -48,8 +49,6 @@ const allocationOptions = [
{ value: 'ELASTIC', label: t('Elastic'), attrs: { id: 'detection-allocation-elastic', 'data-allocation': 'ELASTIC' } },
{ value: 'WEIGHTED', label: t('Weighted'), attrs: { id: 'detection-allocation-weighted', 'data-allocation': 'WEIGHTED' } },
];
const geoRows = computed(() => geoImport.value?.rows ?? []);
const geoListed = computed(() => geoRows.value.length > 0);
</script>
<template>
@@ -187,15 +186,7 @@ const geoListed = computed(() => geoRows.value.length > 0);
<span class="draw-hint" id="draw-hint" aria-live="polite">{{ draw?.hint ?? '' }}</span>
</div>
</div>
<div class="pp-toggle-group" id="geo-import-group">
<button class="pp-toggle-btn" id="geo-import-button" type="button" title="Show your own GeoJSON, KML, KMZ or GPX files on the globe (or drop them onto it). File bytes stay on this device; overlays can appear in map screenshots shared with voice." data-i18n-title>
<span class="pp-icon material-symbols-outlined" aria-hidden="true">upload_file</span>
<span class="pp-label" data-i18n>Import</span>
</button>
<input type="file" id="geo-import-input" accept=".geojson,.json,.kml,.kmz,.gpx" multiple hidden aria-label="Choose GeoJSON, KML, KMZ or GPX files" data-i18n-aria-label>
<ul class="geo-import-list" :class="{ visible: geoListed }" id="geo-import-list" aria-label="Imported files" data-i18n-aria-label><li v-for="row in geoRows" :key="row.id" class="geo-import-row" :data-import-id="row.id"><span :class="['geo-import-swatch', { 'own-styles': row.ownStyles }]" :style="row.ownStyles ? null : { background: row.color }"></span><span class="geo-import-name" :title="row.title">{{ row.name }}</span><button v-for="item in row.actions" :key="item.action" type="button" class="geo-import-action" :data-action="item.action" :title="item.label" :aria-label="item.label" :aria-pressed="item.pressed"><span class="material-symbols-outlined" aria-hidden="true">{{ item.icon }}</span></button></li></ul>
<span class="draw-hint geo-import-hint" id="geo-import-hint" aria-live="polite">{{ geoImport?.hint ?? '' }}</span>
</div>
<GeoImport />
<div class="pp-toggle-group">
<button class="pp-toggle-btn" :class="{ active: celestial?.active }" id="celestial-toggle" @click="act('toggleCelestial')" :title="celestialTitle" :aria-pressed="String(celestial?.active ?? false)" :disabled="celestial ? !celestial.supported : undefined" :aria-disabled="celestial ? String(!celestial.supported) : undefined">
<span class="pp-icon material-symbols-outlined" aria-hidden="true">flare</span>
+154
View File
@@ -0,0 +1,154 @@
// src/ui/views/panels/GeoImport.test.mjs — DISPLAY ▸ Import renders the file
// import's rows, sends a pick and the row buttons through the display store,
// and keeps keyboard focus on a row that stays when the focused one goes.
import '../../../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createApp, nextTick } from 'vue';
import { createPinia } from 'pinia';
import { GEO_FILE_ACCEPT } from '../../../data/geoFileImport.js';
import { useDisplayStore } from '../../stores/display.js';
import GeoImport from './GeoImport.vue';
function mount(t) {
document.body.replaceChildren();
const pinia = createPinia();
const store = useDisplayStore(pinia);
const calls = [];
const record =
(name) =>
(...args) =>
calls.push([name, ...args]);
store.connect({
importGeoFiles: record('importGeoFiles'),
toggleGeoImport: record('toggleGeoImport'),
flyToGeoImport: record('flyToGeoImport'),
removeGeoImport: record('removeGeoImport'),
});
const app = createApp(GeoImport).use(pinia);
app.mount(document.body.appendChild(document.createElement('div')));
t.after(() => app.unmount());
return { store, calls };
}
const $ = (id) => document.getElementById(id);
const row = (id) => ({
id,
name: `${id}.geojson`,
ownStyles: false,
color: '#39d0ff',
title: id,
actions: ['toggle', 'fly', 'remove'].map((action) => ({
icon: action,
label: `${action} ${id}`,
action,
pressed: action === 'toggle' ? 'true' : undefined,
})),
});
async function show(store, ids, hint = '') {
store.publishGeoImport({ rows: ids.map(row), hint });
await nextTick();
}
const button = (id, action) =>
document.querySelector(
`[data-import-id="${id}"] button[data-action="${action}"]`,
);
test('the Import button opens the picker, and a pick goes to the file import', async (t) => {
const { store, calls } = mount(t);
const picker = $('geo-import-input');
assert.equal(picker.getAttribute('accept'), GEO_FILE_ACCEPT);
let opened = 0;
picker.click = () => (opened += 1);
$('geo-import-button').click();
assert.equal(opened, 0, 'not before the file import presents itself');
await show(store, []);
$('geo-import-button').click();
assert.equal(opened, 1);
let cleared = false;
Object.defineProperty(picker, 'value', {
configurable: true,
get: () => '',
set: (value) => (cleared = value === ''),
});
const files = [new File(['{}'], 'a.geojson'), new File(['{}'], 'b.kml')];
Object.defineProperty(picker, 'files', { value: files, configurable: true });
picker.dispatchEvent(new Event('change'));
assert.equal(calls.length, 1);
assert.equal(calls[0][0], 'importGeoFiles');
assert.deepEqual(
calls[0][1].map((file) => file.name),
['a.geojson', 'b.kml'],
);
assert.ok(cleared, 'the selection clears, so the same file can be picked again');
Object.defineProperty(picker, 'files', { value: [], configurable: true });
picker.dispatchEvent(new Event('change'));
assert.equal(calls.length, 1, 'an empty pick sends nothing');
});
test('rows render what the file import publishes and their buttons call it', async (t) => {
const { store, calls } = mount(t);
assert.equal($('geo-import-list').classList.contains('visible'), false);
await show(store, ['a', 'b'], 'Added 2 files.');
assert.ok($('geo-import-list').classList.contains('visible'));
assert.equal($('geo-import-hint').textContent, 'Added 2 files.');
assert.equal(button('a', 'toggle').getAttribute('aria-pressed'), 'true');
assert.equal(button('a', 'toggle').getAttribute('aria-label'), 'toggle a');
button('a', 'toggle').click();
button('b', 'fly').click();
button('a', 'remove').click();
assert.deepEqual(calls, [
['toggleGeoImport', 'a'],
['flyToGeoImport', 'b'],
['removeGeoImport', 'a'],
]);
});
test('focus goes to the next row’s same button, then the previous, then Import', async (t) => {
const { store } = mount(t);
await show(store, ['a', 'b', 'c']);
button('b', 'fly').focus();
await show(store, ['a', 'c']);
assert.equal(document.activeElement, button('c', 'fly'), 'the next row');
await show(store, ['a']);
assert.equal(document.activeElement, button('a', 'fly'), 'the previous row');
await show(store, []);
assert.equal(document.activeElement, $('geo-import-button'));
});
test('two rows gone in one render leave focus on the first one’s next row', async (t) => {
const { store } = mount(t);
await show(store, ['a', 'b', 'c', 'd', 'e']);
button('b', 'remove').focus();
await show(store, ['a', 'c', 'e']);
assert.equal(document.activeElement, button('c', 'remove'));
});
test('focus outside the removed row stays where it is', async (t) => {
const { store } = mount(t);
await show(store, ['a', 'b']);
button('b', 'toggle').focus();
await show(store, ['b']);
assert.equal(document.activeElement, button('b', 'toggle'));
$('geo-import-button').focus();
await show(store, []);
assert.equal(document.activeElement, $('geo-import-button'));
});
test('focus passes through a neighbour that goes in the same render', async (t) => {
const { store } = mount(t);
await show(store, ['a', 'b', 'c', 'd']);
button('b', 'fly').focus();
await show(store, ['a', 'd']);
assert.equal(document.activeElement, button('d', 'fly'));
});
test('a row without the same button gives focus to its first one', async (t) => {
const { store } = mount(t);
const short = { ...row('b'), actions: row('b').actions.slice(1) };
store.publishGeoImport({ rows: [row('a'), short], hint: '' });
await nextTick();
button('a', 'toggle').focus();
store.publishGeoImport({ rows: [short], hint: '' });
await nextTick();
assert.equal(document.activeElement, button('b', 'fly'));
});
+68
View File
@@ -0,0 +1,68 @@
<script setup>
import { storeToRefs } from 'pinia';
import { computed, ref } from 'vue';
import { vFocusSafeChildren } from '../../rail/focusSafeChildren.js';
import { useDisplayStore } from '../../stores/display.js';
// DISPLAY ▸ Import: the button, the hidden picker, the imported files and
// the hint. The file import publishes the rows and hint; until it does, the
// list is empty. A pick and the row buttons call its actions. Before the
// row holding keyboard focus goes, focus moves to the next row's same
// button, else the previous row's, else the Import button. The list's
// template is one line: templates keep whitespace.
const display = useDisplayStore();
const { geoImport } = storeToRefs(display);
const rows = computed(() => geoImport.value?.rows ?? []);
// No `>` in the template: the catalog reads its tags with a regex.
const listed = computed(() => rows.value.length > 0);
const importButton = ref(null);
const picker = ref(null);
const ROW_ACTIONS = {
toggle: 'toggleGeoImport',
fly: 'flyToGeoImport',
remove: 'removeGeoImport',
};
// The picker opens once the file import has presented itself, so a pick
// always has somewhere to go.
function openPicker() {
if (geoImport.value) picker.value.click();
}
function pick() {
const files = [...(picker.value.files || [])];
// Clear the selection so choosing the same file again fires `change`.
picker.value.value = '';
if (files.length) display.act('importGeoFiles', files);
}
function leave() {
const active = document.activeElement;
const row = active?.closest('[data-import-id]');
const action = active?.dataset.action;
const others = [];
for (let next = row?.nextElementSibling; next; next = next.nextElementSibling)
others.push(next);
for (let prev = row?.previousElementSibling; prev; prev = prev.previousElementSibling)
others.push(prev);
for (const other of others) {
const target =
other.querySelector(`button[data-action="${action}"]`) ||
other.querySelector('button');
if (target) return target.focus();
}
importButton.value?.focus();
}
</script>
<template>
<div class="pp-toggle-group" id="geo-import-group">
<button ref="importButton" class="pp-toggle-btn" id="geo-import-button" type="button" @click="openPicker" title="Show your own GeoJSON, KML, KMZ or GPX files on the globe (or drop them onto it). File bytes stay on this device; overlays can appear in map screenshots shared with voice." data-i18n-title>
<span class="pp-icon material-symbols-outlined" aria-hidden="true">upload_file</span>
<span class="pp-label" data-i18n>Import</span>
</button>
<input ref="picker" type="file" id="geo-import-input" accept=".geojson,.json,.kml,.kmz,.gpx" multiple hidden @change="pick" aria-label="Choose GeoJSON, KML, KMZ or GPX files" data-i18n-aria-label>
<ul class="geo-import-list" :class="{ visible: listed }" id="geo-import-list" v-focus-safe-children="leave" aria-label="Imported files" data-i18n-aria-label><li v-for="row in rows" :key="row.id" class="geo-import-row" :data-import-id="row.id"><span :class="['geo-import-swatch', { 'own-styles': row.ownStyles }]" :style="row.ownStyles ? null : { background: row.color }"></span><span class="geo-import-name" :title="row.title">{{ row.name }}</span><button v-for="item in row.actions" :key="item.action" type="button" class="geo-import-action" :data-action="item.action" :title="item.label" :aria-label="item.label" :aria-pressed="item.pressed" @click="display.act(ROW_ACTIONS[item.action], row.id)"><span class="material-symbols-outlined" aria-hidden="true">{{ item.icon }}</span></button></li></ul>
<span class="draw-hint geo-import-hint" id="geo-import-hint" aria-live="polite">{{ geoImport?.hint ?? '' }}</span>
</div>
</template>