Stories: the button sits left of elements marked data-stories-corner

The corner controls are the ACTIVE STYLE readout and any element marked
with data-stories-corner, looked for again for 20 s after Stories mounts,
in place of an element id this app never has.
This commit is contained in:
Sameh Khamis committed 2026-11-16 14:14:27 -08:00
1 parent 78b8d8dc78
commit 9e6207d7f2
4 files changed
+55 -14

No files matched your search

+22 -2
View File
@@ -1,7 +1,12 @@
import '../testSupport/registerDom.mjs';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
import { creditPlacement, entryPlacement } from '../stories/format.js';
import {
cornerControls,
creditPlacement,
entryPlacement,
} from '../stories/format.js';
const css = readFileSync(
new URL('./styles/stories.css', import.meta.url),
@@ -120,6 +125,20 @@ test('the measured place keeps the credit inside the map and on screen', () => {
assert.match(view, /root\.removeProperty\('--gs-credit-left'\)/);
});
test('the corner controls are the readout and elements marked data-stories-corner', () => {
const root = document.createElement('div');
assert.deepEqual(cornerControls(root), [], 'nothing there yet');
const readout = root.appendChild(document.createElement('div'));
readout.id = 'style-indicator';
const other = root.appendChild(document.createElement('div'));
assert.deepEqual(cornerControls(root), [readout], 'an unmarked element is not');
// A marked element added later counts on the next look.
const marked = root.appendChild(document.createElement('button'));
marked.setAttribute('data-stories-corner', '');
assert.deepEqual(cornerControls(root), [readout, marked]);
assert.ok(other);
});
test('the Stories button sits left of whatever is in the top-right corner', () => {
const box = (left, top, width, height) => ({
left,
@@ -134,7 +153,8 @@ test('the Stories button sits left of whatever is in the top-right corner', () =
top: 24,
right: 270,
});
// An element placed beside the readout; the leftmost wins.
// An element marked with data-stories-corner beside the readout; the
// leftmost wins.
assert.deepEqual(
entryPlacement([box(1650, 24, 220, 60), box(1898, 22, 38, 38)], 1960),
{ top: 24, right: 320 },
+14 -8
View File
@@ -12,7 +12,11 @@ import { storeToRefs } from 'pinia';
import { t } from '../../i18n/index.js';
import { useStoriesStore } from '../stores/stories.js';
import { GEV_LOGO_SYMBOL } from '../../stories/gevLogo.js';
import { creditPlacement, entryPlacement } from '../../stories/format.js';
import {
cornerControls,
creditPlacement,
entryPlacement,
} from '../../stories/format.js';
import { guardStoriesKeyboard } from '../../stories/keyboard.js';
// The screens, their styles and the story data load with Stories (see
@@ -36,15 +40,15 @@ const reduceMotion = () =>
globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
// ── Entry: in GEV's top-right row, left of what sits in the corner ──
// GEV has its ACTIVE STYLE readout there; an element placed in that corner
// (#account-control, with or beside the readout) can come after Stories mounts.
const CORNER = ['style-indicator', 'account-control'];
// GEV has its ACTIVE STYLE readout there; an element marked with
// data-stories-corner (with or beside the readout) can come after Stories
// mounts (cornerControls).
// GEV's phone layout shows neither; the button then sits under this column.
const COLUMN = 'corner-actions';
const entry = ref({ top: 14, right: 14 });
function placeEntry() {
entry.value = entryPlacement(
CORNER.map((id) => document.getElementById(id)?.getBoundingClientRect()),
cornerControls(document).map((el) => el.getBoundingClientRect()),
innerWidth,
document.getElementById(COLUMN)?.getBoundingClientRect() ?? null,
);
@@ -66,15 +70,17 @@ function watchCorner() {
});
}
if (globalThis.ResizeObserver) cornerObserver ??= new ResizeObserver(placeEntry);
for (const id of [...CORNER, COLUMN]) {
const el = document.getElementById(id);
for (const el of [
...cornerControls(document),
document.getElementById(COLUMN),
]) {
if (el && cornerObserver && !observed.has(el)) {
cornerObserver.observe(el);
observed.add(el);
}
}
// Keep looking for a while for a control that mounts late.
if (observed.size < CORNER.length + 1 && ++entryTries < 20)
if (++entryTries < 20)
entryTimer = setTimeout(watchCorner, 1000);
}