mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
docs/VUE-MIGRATION.md says every select is a UiSelect, every close button a UiCloseButton and (nearly) every pressed toggle a UiButton. Make those true in code, correct the sentences that were not, and pin them. Selects: Story Explore's sort, the chat's layer picker and a layer row's range ends are UiSelects. The range ends take `hold`, since the layer panel repaints the row on a later frame. Close buttons: the space mission replay's Cancel is a bare UiCloseButton. An imported file's row actions (show or hide, fly to, remove) are icon UiButtons drawing the icon the file import names, so Remove stays one of them; the presenter's `pressed` is now a boolean. Pressed toggles: the tilt-map button, the scene action buttons, the chat and voice panels' dock (and its minimize), the Context header's search and expand, Recent Imagery's day chips, SWAP and ZOOM IN, the rail row lists and the rail cards' action chips are UiButtons with `pressed` (and `pressed-class="active"` where their active class came from the same state). Their Material glyphs, and the rail chips' icons, are UiIcons with `:size="null"`. Bhote Koshi's cinematic button keeps the attributes its layer writes, and Explore's story cards stay role="button" elements. Docs: the kit list gains UiPanelToggle and UiPanelEdge; the pressed-toggle, chips, Stories search fields, role="dialog", close button, range and source-reading-tests sentences now say what the code does. Tests: src/ui/kit/viewControls.test.mjs walks every .vue outside the kit and fails on a raw select, a hand-written aria-pressed on a button, UiButton or role="button" element (outside the two documented exceptions), or a hand-written close glyph button. closeButtons.test.mjs also catches a × inside a span. Co-authored-by: Manjunath Paparaju <[email protected]>
83 lines
3.6 KiB
JavaScript
83 lines
3.6 KiB
JavaScript
// Every close, dismiss and clear button in a Vue view is a UiCloseButton: no
|
||
// SFC template hand-writes a button whose only content is × (bare or in a
|
||
// span) or the Material `close` symbol. Buttons built in script are not read
|
||
// here.
|
||
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { readFileSync, readdirSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const SRC_ROOT = fileURLToPath(new URL('../../', import.meta.url));
|
||
const REPO_ROOT = path.resolve(SRC_ROOT, '..');
|
||
|
||
/** Every SFC under src. */
|
||
function sfcFiles(directory = SRC_ROOT) {
|
||
const files = [];
|
||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||
const absolute = path.join(directory, entry.name);
|
||
if (entry.isDirectory()) files.push(...sfcFiles(absolute));
|
||
else if (entry.isFile() && entry.name.endsWith('.vue'))
|
||
files.push(absolute);
|
||
}
|
||
return files.sort();
|
||
}
|
||
|
||
/** The template block: everything outside script and style. */
|
||
function template(source) {
|
||
return source.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '');
|
||
}
|
||
|
||
// An opening tag's attributes, quoted values may hold `>` (`() => x`).
|
||
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
|
||
const BUTTON = String.raw`(button|UiButton)`;
|
||
const TIMES = String.raw`×|×|×|×`;
|
||
const CLOSE_GLYPH = [
|
||
TIMES,
|
||
String.raw`<span\b${ATTRS}>\s*(?:${TIMES})\s*</span\s*>`,
|
||
String.raw`<span\b[^>]*\bmaterial-symbols-outlined\b[^>]*>\s*close\s*</span\s*>`,
|
||
String.raw`<UiIcon${ATTRS}\bname="close"${ATTRS}/>`,
|
||
].join('|');
|
||
const HAND_WRITTEN_CLOSE = new RegExp(
|
||
String.raw`<${BUTTON}\b${ATTRS}>\s*(?:${CLOSE_GLYPH})\s*</\1\s*>`,
|
||
'gi',
|
||
);
|
||
|
||
/** Hand-written close buttons in an SFC's template. */
|
||
function handWrittenCloses(source) {
|
||
return [...template(source).matchAll(HAND_WRITTEN_CLOSE)].map((m) =>
|
||
m[0].replace(/\s+/g, ' '),
|
||
);
|
||
}
|
||
|
||
test('the scan finds each hand-written close glyph', () => {
|
||
for (const markup of [
|
||
'<template><button type="button" @click="emit(\'close\')">×</button></template>',
|
||
'<template><button\n class="x"\n :title="a > b ? 1 : 2"\n >×</button\n></template>',
|
||
'<template><UiButton class="x" :label="l">×</UiButton></template>',
|
||
'<template><button type="button" class="x">\n <span class="material-symbols-outlined" aria-hidden="true">close</span>\n</button></template>',
|
||
'<template><UiButton class="x"><UiIcon name="close" :size="14" /></UiButton></template>',
|
||
'<template><button type="button" :aria-label="l"><span aria-hidden="true">×</span></button></template>',
|
||
'<template><UiButton class="x">\n <span class="glyph">×</span>\n</UiButton></template>',
|
||
])
|
||
assert.equal(handWrittenCloses(markup).length, 1, markup);
|
||
for (const markup of [
|
||
'<template><UiCloseButton class="x" :label="l" /></template>',
|
||
'<template><button type="button">{{ name }} ×</button></template>',
|
||
'<template><button type="button"><span>{{ name }}</span> ×</button></template>',
|
||
'<template><button type="button">On<span class="material-symbols-outlined">close</span></button></template>',
|
||
'<template><button type="button"><span class="material-symbols-outlined">close_fullscreen</span></button></template>',
|
||
])
|
||
assert.equal(handWrittenCloses(markup).length, 0, markup);
|
||
});
|
||
|
||
test('no SFC hand-writes a close button; each is a UiCloseButton', () => {
|
||
const found = [];
|
||
for (const file of sfcFiles()) {
|
||
const relative = path.relative(REPO_ROOT, file).split(path.sep).join('/');
|
||
for (const markup of handWrittenCloses(readFileSync(file, 'utf8')))
|
||
found.push(`${relative}: ${markup}`);
|
||
}
|
||
assert.deepEqual(found, []);
|
||
});
|