mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
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:
1 parent
78b8d8dc78
commit
9e6207d7f2
4 files changed
+55
-14
No files matched your search
@@ -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
|
||||
|
||||
+16
-2
@@ -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.
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user