From 9e6207d7f277577a5fe1488bea525d801938b6d5 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:14:27 -0800 Subject: [PATCH] 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. --- docs/CURRENT-STATE.md | 5 +++-- src/stories/format.js | 18 ++++++++++++++++-- src/ui/storiesCredit.test.mjs | 24 ++++++++++++++++++++++-- src/ui/views/StoriesView.vue | 22 ++++++++++++++-------- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 7a6a56a88..72bbd4914 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -780,8 +780,9 @@ Inside an inline embed Stories is not offered: the URL and history are the host's. The Stories button sits left of whatever holds GEV's top-right corner: the -ACTIVE STYLE readout, or an element placed in that corner (`#account-control`, -with or beside the readout). On GEV's phone layout, +ACTIVE STYLE readout (`#style-indicator`), or an element marked with +`data-stories-corner` (with or beside the readout; one added after Stories +mounts is found within 20 s). On GEV's phone layout, where neither shows, it is icon-only under the corner-actions column (`#corner-actions`), aligned with its right edge. The first-visit popup is a labelled region that does not take focus. The story page's rail offers diff --git a/src/stories/format.js b/src/stories/format.js index 20a99bed3..f960c5882 100644 --- a/src/stories/format.js +++ b/src/stories/format.js @@ -30,10 +30,24 @@ export function creditPlacement({ map, feed, width, height }) { }; } +/** + * The controls in GEV's top-right corner: the ACTIVE STYLE readout + * (`#style-indicator`) and any element marked with `data-stories-corner`. + * @param {Document|Element} root Where to look. + * @returns {Element[]} + */ +export function cornerControls(root) { + return [ + root.querySelector('#style-indicator'), + ...root.querySelectorAll('[data-stories-corner]'), + ].filter(Boolean); +} + /** * Where the Stories button sits: just left of the leftmost visible control - * in GEV's top-right corner — the ACTIVE STYLE readout, or an element placed - * in that corner (with or beside the readout) — top-aligned with it. + * in GEV's top-right corner — the ACTIVE STYLE readout, or an element marked + * with `data-stories-corner` (with or beside the readout) — top-aligned with + * it. * Where none of those shows (GEV's phone layout, whose top row of icon * buttons spans the corner), it goes icon-only just under the right-hand * column of corner actions, aligned with its right edge. diff --git a/src/ui/storiesCredit.test.mjs b/src/ui/storiesCredit.test.mjs index c77accb01..803ee62cd 100644 --- a/src/ui/storiesCredit.test.mjs +++ b/src/ui/storiesCredit.test.mjs @@ -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 }, diff --git a/src/ui/views/StoriesView.vue b/src/ui/views/StoriesView.vue index e3740402e..1c3ce552e 100644 --- a/src/ui/views/StoriesView.vue +++ b/src/ui/views/StoriesView.vue @@ -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); }