Vue kit: Draw's and Import's buttons and glyphs are kit controls

UTILITIES ▸ Draw and Import no longer hand-write a button or a Material
Symbols span. Clear and Import are ghost UiButtons (Draw already was), and
the Draw and Import glyphs are UiIcons that keep pp-icon, with
:size="null" so controls.css still sizes them. Draw's five colour swatches
(in the toolbar and in a drawn shape's row) are ghost UiButtons that keep
role="radio", aria-checked and their own active class; they are not
pressed toggles. A drawn shape's row (its swatch, show/hide, the
application's row actions and fly to) is on the kit too, beside the remove
UiCloseButton it already had; its glyphs are UiIcons with :size="null".
Show/hide keeps naming itself Show … / Hide … rather than becoming a
pressed toggle.

Template refs that now hold a component reach the button through $el:
the swatches' arrow-key focus and Import's focus fallback when the last
imported file goes.

The Street Level panel's controls were already kit controls (its ⤢ ⤡ and
⚠ are text characters), so its template is unchanged; the new guard test
pins it with Draw and Import.

src/ui/kit/drawControls.test.mjs pins it: no hand-written button, select,
checkbox, range or Material span in DrawControls, DrawSwatches,
DrawMarkList, GeoImport or StreetLevelPanel; the kit counts per file;
Draw a pressed toggle with active; the swatches radios rather than
pressed; :size="null" on every glyph; and the $el refs.
docs/VUE-MIGRATION.md describes the surface.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-19 12:24:55 -08:00
1 parent 2796c2547b
commit 35fb3684ba
7 files changed
+162 -14

No files matched your search

+126
View File
@@ -0,0 +1,126 @@
// UTILITIES ▸ Draw (its toggle, Clear, the colour swatches and the drawn
// shapes' rows), Import and the Street Level panel are on the kit: none of
// them hand-writes a <button>, a Material Symbols span, a select, a checkbox
// or a range. The Draw toggle is a pressed toggle with `active`. The colour
// swatches are `role="radio"` buttons: they say they are chosen with
// `aria-checked` and their own `active` class, never `aria-pressed`. A drawn
// shape's show/hide renames itself (Show …, Hide …) rather than being pressed.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
const source = (file) =>
readFileSync(new URL(`../views/panels/${file}`, import.meta.url), 'utf8');
/** A view's template block: everything outside script, style and comments. */
const template = (file) =>
source(file)
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
// A tag's attributes, read past quoted values so a handler's `=>` does not
// end the tag early.
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tag = (pattern, flags = '') =>
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
const tags = (markup, name) =>
markup.match(tag(String.raw`<${name}\bATTRS>`, 'g')) ?? [];
const views = {
// Draw and Clear.
'DrawControls.vue': { buttons: 2, icons: 1, closes: 0 },
// The five colours, one v-for.
'DrawSwatches.vue': { buttons: 1, icons: 0, closes: 0 },
// A row's swatch, show/hide, the application's actions and fly to; remove
// is a UiCloseButton.
'DrawMarkList.vue': { buttons: 4, icons: 3, closes: 1 },
// Import and a file's row actions.
'GeoImport.vue': { buttons: 2, icons: 2, closes: 0 },
// The status toggle, EXPAND and the nearest-imagery button; the viewer's
// close. EXPAND's ⤢ ⤡ and the errors' ⚠ are text, not Material symbols.
'StreetLevelPanel.vue': { buttons: 3, icons: 0, closes: 1 },
};
const markup = Object.fromEntries(
Object.keys(views).map((file) => [file, template(file)]),
);
test('the Draw, Import and Street Level views hand-write no button', () => {
for (const [file, { buttons, closes }] of Object.entries(views)) {
const html = markup[file];
assert.deepEqual(html.match(/<button\b/gi) ?? [], [], file);
assert.deepEqual(html.match(/<component\b/gi) ?? [], [], file);
assert.equal(tags(html, 'UiButton').length, buttons, file);
assert.equal(tags(html, 'UiCloseButton').length, closes, file);
}
});
test('they hand-write no select, checkbox or range', () => {
for (const [file, html] of Object.entries(markup)) {
assert.deepEqual(html.match(/<select\b/gi) ?? [], [], file);
assert.doesNotMatch(
html,
tag(String.raw`<input\bATTRS\stype="(?:checkbox|range)"`),
file,
);
}
// SINCE is the kit's range.
assert.equal(tags(markup['StreetLevelPanel.vue'], 'UiSlider').length, 1);
});
test('they hand-write no Material glyph; each is a UiIcon sized by the site', () => {
for (const [file, { icons }] of Object.entries(views)) {
const html = markup[file];
assert.deepEqual(html.match(/material-symbols-outlined/g) ?? [], [], file);
const found = tags(html, 'UiIcon');
assert.equal(found.length, icons, file);
// Without it the kit writes an 18px size that beats the site rules.
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
}
// Draw's and Import's glyphs keep pp-icon, which sizes them.
for (const file of ['DrawControls.vue', 'GeoImport.vue']) {
const [icon] = tags(markup[file], 'UiIcon');
assert.match(icon, /\sclass="pp-icon"/, file);
}
});
test('no tag hand-writes aria-pressed; Draw is a pressed toggle with active', () => {
for (const [file, html] of Object.entries(markup))
assert.doesNotMatch(
html,
tag(String.raw`<\w+\bATTRS\s:?aria-pressed`),
file,
);
const [draw] = tags(markup['DrawControls.vue'], 'UiButton').filter((b) =>
/\sid="draw-toggle"/.test(b),
);
assert.match(draw, /\s:pressed="draw\?\.active \?\? false"/);
assert.match(draw, /\spressed-class="active"/);
const [clear] = tags(markup['DrawControls.vue'], 'UiButton').filter((b) =>
/\sid="draw-clear"/.test(b),
);
assert.doesNotMatch(clear, /\s:pressed=/);
// A shape's show/hide says what it does in its name, not by being pressed.
for (const button of tags(markup['DrawMarkList.vue'], 'UiButton'))
assert.doesNotMatch(button, /\s:pressed=/);
});
test('the colour swatches are radios chosen by aria-checked, never pressed', () => {
const [swatch] = tags(markup['DrawSwatches.vue'], 'UiButton');
assert.match(swatch, /\srole="radio"/);
assert.match(
swatch,
/\s:aria-checked="String\(color === props\.modelValue\)"/,
);
assert.match(swatch, /\s:class="\{ active: color === props\.modelValue \}"/);
assert.doesNotMatch(swatch, /\s:pressed=|\spressed-class=/);
});
test('code that focuses a converted button reaches its element', () => {
// A template ref on a component holds the component, not the button.
assert.match(
source('DrawSwatches.vue'),
/:ref="\(swatch\) => \(buttons\[index\] = swatch\?\.\$el\)"/,
);
assert.match(
source('GeoImport.vue'),
/importButton\.value\?\.\$el\.focus\(\)/,
);
});
+3 -2
View File
@@ -3,6 +3,7 @@ import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import { t } from '../../../i18n/index.js';
import UiButton from '../../kit/UiButton.vue';
import UiIcon from '../../kit/UiIcon.vue';
import UiSegmented from '../../kit/UiSegmented.vue';
import { useDisplayStore } from '../../stores/display.js';
import DrawMarkList from './DrawMarkList.vue';
@@ -27,7 +28,7 @@ const shapeOptions = computed(() => [
<template>
<div class="pp-toggle-group" id="draw-group">
<UiButton class="pp-toggle-btn" :pressed="draw?.active ?? false" pressed-class="active" id="draw-toggle" @click="act('toggleDraw')" :title="t('Draw on the world — click vertices, double-click or Enter to finish, Esc to cancel')">
<span class="pp-icon material-symbols-outlined" aria-hidden="true">draw</span>
<UiIcon class="pp-icon" name="draw" :size="null" />
<span class="pp-label">{{ t('Draw') }}</span>
</UiButton>
<div class="pp-slider-row" :class="{ visible: draw?.active }" id="draw-mode-row">
@@ -36,7 +37,7 @@ const shapeOptions = computed(() => [
</div>
<div class="pp-slider-row" :class="{ visible: draw?.active }" id="draw-label-row">
<span class="draw-hint" id="draw-hint" aria-live="polite">{{ draw?.hint ?? '' }}</span>
<button class="pp-mode-btn draw-clear-btn" id="draw-clear" type="button" @click="act('clearDraw')" :title="t('Remove every mark from the board')">{{ t('Clear') }}</button>
<UiButton class="pp-mode-btn draw-clear-btn" id="draw-clear" @click="act('clearDraw')" :title="t('Remove every mark from the board')">{{ t('Clear') }}</UiButton>
</div>
<DrawMarkList />
</div>
+3 -1
View File
@@ -6,7 +6,9 @@ import { DRAW_COLOR_CSS } from '../../../annotations/drawMarks.js';
import { vFieldValue } from '../../rail/fieldValue.js';
import { vFocusSafeChildren } from '../../rail/focusSafeChildren.js';
import DrawSwatches from './DrawSwatches.vue';
import UiButton from '../../kit/UiButton.vue';
import UiCloseButton from '../../kit/UiCloseButton.vue';
import UiIcon from '../../kit/UiIcon.vue';
import { useDisplayStore } from '../../stores/display.js';
// UTILITIES ▸ Draw's shapes, one row each like Import's files: the colour
@@ -100,5 +102,5 @@ function leave() {
</script>
<template>
<ul class="geo-import-list draw-mark-list" :class="{ visible: listed }" id="draw-mark-list" v-focus-safe-children="leave" :aria-label="t('Drawn shapes')"><li v-for="row in rows" :key="row.id" class="geo-import-row draw-mark-row" :class="{ 'hidden-mark': row.hidden }" :data-mark-id="row.id" @keydown="onRowKey(row, $event)"><button type="button" class="geo-import-swatch draw-mark-swatch" data-control="swatch" :style="{ background: DRAW_COLOR_CSS[row.color] }" :title="row.labels.swatch" :aria-label="row.labels.swatch" :aria-expanded="String(picking === row.id)" :aria-controls="`draw-mark-colors-${row.id}`" @click="picking = picking === row.id ? null : row.id"></button><DrawSwatches v-if="picking === row.id" :id="`draw-mark-colors-${row.id}`" class="draw-mark-colors" data-control="picker" autofocus :label="row.labels.colors" :model-value="row.color" @update:model-value="recolor(row, $event)" @choose="closePicker(row.id)" /><input type="text" class="geo-import-name draw-mark-name" data-control="name" maxlength="120" autocomplete="off" spellcheck="false" v-field-value="row.name" :placeholder="row.placeholder" :aria-label="row.labels.name" @keydown="onNameKey(row, $event)" @focusout="commit(row, $event.currentTarget)"><button type="button" class="geo-import-action" data-control="toggle" :title="row.labels.toggle" :aria-label="row.labels.toggle" @click="display.act('toggleDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">{{ row.hidden ? 'visibility_off' : 'visibility' }}</span></button><button v-for="action in row.actions" :key="action.id" type="button" class="geo-import-action draw-mark-action" :data-control="`action-${action.id}`" :data-action="action.id" :title="action.label" :aria-label="action.label" :aria-disabled="String(row.busy)" @click="display.act('runDrawMarkAction', row.id, action.id)"><span class="material-symbols-outlined" aria-hidden="true">{{ action.icon }}</span></button><button type="button" class="geo-import-action" data-control="fly" :title="row.labels.fly" :aria-label="row.labels.fly" @click="display.act('flyToDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">my_location</span></button><UiCloseButton class="geo-import-action" glyph="icon" data-control="remove" :title="row.labels.remove" :label="row.labels.remove" @click="display.act('removeDrawMark', row.id)" /><span v-if="row.actions.length" class="draw-mark-note" role="status" :aria-busy="String(row.busy)">{{ row.busy ? '…' : row.note }}</span></li></ul>
<ul class="geo-import-list draw-mark-list" :class="{ visible: listed }" id="draw-mark-list" v-focus-safe-children="leave" :aria-label="t('Drawn shapes')"><li v-for="row in rows" :key="row.id" class="geo-import-row draw-mark-row" :class="{ 'hidden-mark': row.hidden }" :data-mark-id="row.id" @keydown="onRowKey(row, $event)"><UiButton class="geo-import-swatch draw-mark-swatch" data-control="swatch" :style="{ background: DRAW_COLOR_CSS[row.color] }" :label="row.labels.swatch" :aria-expanded="String(picking === row.id)" :aria-controls="`draw-mark-colors-${row.id}`" @click="picking = picking === row.id ? null : row.id" /><DrawSwatches v-if="picking === row.id" :id="`draw-mark-colors-${row.id}`" class="draw-mark-colors" data-control="picker" autofocus :label="row.labels.colors" :model-value="row.color" @update:model-value="recolor(row, $event)" @choose="closePicker(row.id)" /><input type="text" class="geo-import-name draw-mark-name" data-control="name" maxlength="120" autocomplete="off" spellcheck="false" v-field-value="row.name" :placeholder="row.placeholder" :aria-label="row.labels.name" @keydown="onNameKey(row, $event)" @focusout="commit(row, $event.currentTarget)"><UiButton class="geo-import-action" data-control="toggle" :label="row.labels.toggle" @click="display.act('toggleDrawMark', row.id)"><UiIcon :name="row.hidden ? 'visibility_off' : 'visibility'" :size="null" /></UiButton><UiButton v-for="action in row.actions" :key="action.id" class="geo-import-action draw-mark-action" :data-control="`action-${action.id}`" :data-action="action.id" :label="action.label" :aria-disabled="String(row.busy)" @click="display.act('runDrawMarkAction', row.id, action.id)"><UiIcon :name="action.icon" :size="null" /></UiButton><UiButton class="geo-import-action" data-control="fly" :label="row.labels.fly" @click="display.act('flyToDrawMark', row.id)"><UiIcon name="my_location" :size="null" /></UiButton><UiCloseButton class="geo-import-action" glyph="icon" data-control="remove" :title="row.labels.remove" :label="row.labels.remove" @click="display.act('removeDrawMark', row.id)" /><span v-if="row.actions.length" class="draw-mark-note" role="status" :aria-busy="String(row.busy)">{{ row.busy ? '…' : row.note }}</span></li></ul>
</template>
+5 -1
View File
@@ -6,11 +6,15 @@ import {
DRAW_COLOR_CSS,
DRAW_COLOR_NAMES,
} from '../../../annotations/drawMarks.js';
import UiButton from '../../kit/UiButton.vue';
// Draw's five colours as one radio group: the next shape's colour and a
// drawn shape's picker. Only the checked colour is a tab stop; the arrows,
// Home and End move to and choose another, as a radio group's do. Each swatch
// shows its colour from DRAW_COLOR_CSS, the same value the shape is drawn in.
// The swatches are ghost UiButtons with role="radio": they say they are
// chosen with aria-checked and their own `active` class, never aria-pressed,
// and `buttons` keeps their elements for the arrows.
// The template is one line: templates keep whitespace.
const props = defineProps({
modelValue: { type: String, default: 'primary' },
@@ -44,5 +48,5 @@ onMounted(() => {
</script>
<template>
<div class="draw-colors" role="radiogroup" :aria-label="props.label" @keydown="onKey"><button v-for="(color, index) in DRAW_COLORS" :key="color" :ref="(el) => (buttons[index] = el)" type="button" class="draw-color" :class="{ active: color === props.modelValue }" role="radio" :data-color="color" :data-control="`color-${color}`" :aria-checked="String(color === props.modelValue)" :tabindex="color === props.modelValue ? 0 : -1" :style="{ background: DRAW_COLOR_CSS[color] }" :title="t(DRAW_COLOR_NAMES[color])" :aria-label="t(DRAW_COLOR_NAMES[color])" @click="emit('update:modelValue', color), emit('choose', color)"></button></div>
<div class="draw-colors" role="radiogroup" :aria-label="props.label" @keydown="onKey"><UiButton v-for="(color, index) in DRAW_COLORS" :key="color" :ref="(swatch) => (buttons[index] = swatch?.$el)" class="draw-color" :class="{ active: color === props.modelValue }" role="radio" :data-color="color" :data-control="`color-${color}`" :aria-checked="String(color === props.modelValue)" :tabindex="color === props.modelValue ? 0 : -1" :style="{ background: DRAW_COLOR_CSS[color] }" :label="t(DRAW_COLOR_NAMES[color])" @click="emit('update:modelValue', color), emit('choose', color)" /></div>
</template>
+4 -4
View File
@@ -56,16 +56,16 @@ function leave() {
other.querySelector('button');
if (target) return target.focus();
}
importButton.value?.focus();
importButton.value?.$el.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="t('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.')">
<span class="pp-icon material-symbols-outlined" aria-hidden="true">upload_file</span>
<UiButton ref="importButton" class="pp-toggle-btn" id="geo-import-button" @click="openPicker" :title="t('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.')">
<UiIcon class="pp-icon" name="upload_file" :size="null" />
<span class="pp-label">{{ t('Import') }}</span>
</button>
</UiButton>
<input ref="picker" type="file" id="geo-import-input" accept=".geojson,.json,.kml,.kmz,.gpx" multiple hidden @change="pick" :aria-label="t('Choose GeoJSON, KML, KMZ or GPX files')">
<ul class="geo-import-list" :class="{ visible: listed }" id="geo-import-list" v-focus-safe-children="leave" :aria-label="t('Imported files')"><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><UiButton v-for="item in row.actions" :key="item.action" class="geo-import-action" :data-action="item.action" :label="item.label" :pressed="item.pressed" @click="display.act(ROW_ACTIONS[item.action], row.id)"><UiIcon :name="item.icon" :size="null" /></UiButton></li></ul>
<span class="draw-hint geo-import-hint" id="geo-import-hint" aria-live="polite">{{ geoImport?.hint ?? '' }}</span>