diff --git a/src/viewer/app/i18n/ru.ts b/src/viewer/app/i18n/ru.ts index edebc54..147ed61 100644 --- a/src/viewer/app/i18n/ru.ts +++ b/src/viewer/app/i18n/ru.ts @@ -579,7 +579,9 @@ export const RU: Record = { // ⚙️ the navbar switches once more (ui/LookSettings.tsx) 'User preferences': 'Настройки пользователя', 'The language of the app': 'Язык приложения', - 'Scrollbars of the tables, in the margins around the card; none: scroll with the wheel or a finger': 'Полосы прокрутки таблиц, в отступах вокруг карточки; без них таблица листается колесом или пальцем', + 'Scrollbars of the page and the tables, in the margins around the cards, and the seconds they stay after a scroll; no side: scroll with the wheel or a finger': 'Полосы прокрутки страницы и таблиц, в отступах вокруг карточек, и сколько секунд они видны после прокрутки; без сторон листайте колесом или пальцем', + 'Seconds the scrollbars stay after a scroll': 'Сколько секунд полосы видны после прокрутки', + '{n} s': '{n} с', 'Scrollbars': 'Полосы прокрутки', 'Right': 'Справа', 'Below': 'Снизу', diff --git a/src/viewer/app/scroll-shown.test.ts b/src/viewer/app/scroll-shown.test.ts new file mode 100644 index 0000000..f98eba2 --- /dev/null +++ b/src/viewer/app/scroll-shown.test.ts @@ -0,0 +1,25 @@ +/// +/// +import { expect, test } from 'bun:test'; +import { parseShown, saveShown, scrollShown, shownMs } from './scroll-shown'; + +test('3 s by default, only the offered choices are read back', () => { + expect(parseShown(null)).toBe(3); + expect(parseShown(undefined)).toBe(3); + expect(parseShown('')).toBe(3); + expect(parseShown('10')).toBe(10); + expect(parseShown('1')).toBe(1); + expect(parseShown('7')).toBe(3); + expect(parseShown('abc')).toBe(3); +}); + +test('a choice holds at once and is kept as the number of seconds', () => { + const kept: Record = {}; + saveShown(5, { setItem: (k, v) => { kept[k] = v; } }); + expect(scrollShown.get()).toBe(5); + expect(shownMs()).toBe(5000); + expect(kept['accounts.scrollbarSeconds']).toBe('5'); + saveShown(4, { setItem: (k, v) => { kept[k] = v; } }); + expect(scrollShown.get()).toBe(3); + saveShown(3, undefined); +}); diff --git a/src/viewer/app/scroll-shown.ts b/src/viewer/app/scroll-shown.ts new file mode 100644 index 0000000..8b5b0cc --- /dev/null +++ b/src/viewer/app/scroll-shown.ts @@ -0,0 +1,30 @@ +/// +import { createStore } from '../../shared/store'; + +/** + * How long the scrollbars stay after a scroll stops, chosen in ⚙️ Settings on the line of the gutters (owner 2026-12-03: + * "add in settings time configuration how many seconds it will be visible after moving", "right after a [the sides] in + * the same line"): a few fixed choices, 3 s by default (owner 2026-12-02: "3 seconds after stopped"). It holds for every + * scrollbar of the app: the page's, the tables' in the gutters (ui/GutterScrollbars.tsx) and every other box + * (ui/scrollbars.ts). Kept in this browser as the number of seconds + */ +export const SHOWN_SECONDS: readonly number[] = [1, 2, 3, 5, 10]; +export const DEFAULT_SHOWN = 3; +export const SHOWN_KEY = 'accounts.scrollbarSeconds'; + +/** the stored text back to seconds: nothing stored or a value not offered = the default */ +export function parseShown(raw: string | null | undefined): number { + const n = Number(raw); + return raw && SHOWN_SECONDS.indexOf(n) >= 0 ? n : DEFAULT_SHOWN; +} + +const storage = (): Storage | undefined => { try { return globalThis.localStorage; } catch { return undefined; } }; +const read = (): number => { try { return parseShown(storage()?.getItem(SHOWN_KEY)); } catch { return DEFAULT_SHOWN; } }; +export const scrollShown = createStore(read()); +/** the time in milliseconds, read at each scroll, so a new choice holds at once */ +export const shownMs = (): number => scrollShown.get() * 1000; +export function saveShown(seconds: number, to: Pick | undefined = storage()): void { + const s = parseShown(String(seconds)); + scrollShown.set(s); + try { to?.setItem(SHOWN_KEY, String(s)); } catch { /* private window */ } +} diff --git a/src/viewer/app/scrollbar-room.test.ts b/src/viewer/app/scrollbar-room.test.ts deleted file mode 100644 index 2436939..0000000 --- a/src/viewer/app/scrollbar-room.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// -/// -import { expect, test } from 'bun:test'; -import { scrollbarRoom } from './scrollbar-room'; - -test('a classic scrollbar takes its width, an overlay one nothing', () => { - // a mouse on a Mac: 15 px kept for the bar - expect(scrollbarRoom(1452, 1437)).toBe(15); - // a trackpad or a phone: the bar floats over the content - expect(scrollbarRoom(1452, 1452)).toBe(0); - // zoomed pages give fractions; a box never reports less inside than outside - expect(scrollbarRoom(1452.4, 1437)).toBe(15); - expect(scrollbarRoom(100, 101)).toBe(0); -}); diff --git a/src/viewer/app/scrollbar-room.ts b/src/viewer/app/scrollbar-room.ts deleted file mode 100644 index 83c5a2f..0000000 --- a/src/viewer/app/scrollbar-room.ts +++ /dev/null @@ -1,9 +0,0 @@ -/// -// The room a box's own scrollbar takes at its right side (owner 2026-12-03: the cards ended further from the right edge -// than the navbar, "we should always have same spacing no matter if there are scroll or not"). A mouse on a Mac, Windows -// and Linux give a classic scrollbar about 15 px wide that stays in the box even while transparent; a trackpad and a phone -// draw it over the content, 0 px. The scrolling part of the page takes that room off its right padding (ui/App.tsx), so -// the cards end on the navbar's line, the scrollbar in the middle of the gutter - -/** the scrollbar's width from a box's outer and inner widths (no borders on the box): never below 0 */ -export const scrollbarRoom = (offsetWidth: number, clientWidth: number): number => Math.max(0, Math.round(offsetWidth - clientWidth)); diff --git a/src/viewer/ui/App.tsx b/src/viewer/ui/App.tsx index f4d77f3..e02b988 100644 --- a/src/viewer/ui/App.tsx +++ b/src/viewer/ui/App.tsx @@ -28,11 +28,11 @@ import { Positions } from './Positions'; import { EdgeScrollRow } from './EdgeScrollRow'; import { SettingsPanel, SettingsTools } from './SettingsPanel'; import { SlidePanel } from './SlidePanel'; -import { useScrollbarRoom } from './useScrollbarRoom'; import { TabLine } from './TabLine'; import { Summary } from './Summary'; import { animate } from './animate'; import { readTime } from './format'; +import { GutterScrollbars } from './GutterScrollbars'; import { useStore } from './useStore'; import { useTheme } from './useTheme'; import { PHONE_QUERY, useMedia } from './useMedia'; @@ -138,7 +138,6 @@ export function App() { const flow = phone && openTab !== 'positions' && !!ds; const page = useRef(null); const scrollBox = useRef(null); - useScrollbarRoom(scrollBox, !flow); const tabsBox = useRef(null); const [past, setPast] = useState(false); useEffect(() => { @@ -249,11 +248,12 @@ export function App() { - {/* the right gutter less the room of its own scrollbar, kept even when nothing scrolls (stable), so the cards end on the - navbar's line with or without a scrollbar (owner 2026-12-03, app/scrollbar-room.ts); what is left of the gutter is - split in two, half a margin outside the bar and half a padding inside, so the bar runs in the middle of the - gutter (owner 2026-12-03: "can we have scroll be in a middle of our gap?"), like the bars of the tables */} -
+ {/* the page scrolls in this box; its own scrollbar is hidden and ours runs in the middle of the gutter right of the + cards (and left of them if chosen), like the bars of the tables, for the seconds chosen in ⚙️ Settings (owner + 2026-12-03: "vertical scroll is hiding too fast and its not in a mid of here", "our configuration should be + applied to the whole site and all its pages"); the browser's own bar stood at the window's edge and a Mac hid it + after a second. The cards end on the navbar's line, the frame of the bars is the tabs panel */} +
{/* the page tabs get a panel of their own under the navbar, in its look (owner 2026-11-24: "lets add same panel as our navbar, but it will contains only tabs"): the tabs on the left, our read time on the right ("As of": Fidelity's own keeps the page load time after Refresh Positions); the gap above is the gutter, like between the cards, and it is @@ -315,6 +315,8 @@ export function App() { + {/* the page's own scrollbar in the gutters (see the scrolling box above); on a phone the whole page scrolls instead */} + {!flow && }
); } diff --git a/src/viewer/ui/GutterScrollbars.tsx b/src/viewer/ui/GutterScrollbars.tsx index 5d87d3e..f97f31b 100644 --- a/src/viewer/ui/GutterScrollbars.tsx +++ b/src/viewer/ui/GutterScrollbars.tsx @@ -3,13 +3,14 @@ import { useEffect, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; import { gutterBars, movedAxes, scrollFor, type Bar } from '../app/gutter-bars'; import { gutterSides, type GutterSide } from '../app/gutter-sides'; -import { SCROLL_SHOWN_MS } from './scrollbars'; +import { shownMs } from '../app/scroll-shown'; import { useStore } from './useStore'; -// The scrollbars of a table box drawn in the page's gutters, outside the card (app/gutter-bars.ts says where): the box -// carries `scrollbar-hidden`, so its own bars take no room and cover no value. Like the bars of the rest of the page they -// show while the box scrolls and 3 s after (only the bars of the way it moved: a scroll down shows no sideways bar), and while the pointer is over them; the thumb drags, a press on the track -// moves the thumb there. `frame`: the card around the box (default: the closest .card) +// The scrollbars of a table box, and of the page itself (ui/App.tsx), drawn in the page's gutters, outside the card +// (app/gutter-bars.ts says where): the box carries `scrollbar-hidden`, so its own bars take no room and cover no value. +// They show while the box scrolls and the seconds chosen in ⚙️ Settings after (app/scroll-shown.ts; only the bars of the +// way it moved: a scroll down shows no sideways bar), and while the pointer is over them; the thumb drags, a press on the +// track moves the thumb there. `frame`: the card around the box (default: the closest .card) type Dir = 'v' | 'l' | 'h' | 't'; // the right and left gutters scroll down, the bottom and top ones sideways const across = (d: Dir): boolean => d === 'h' || d === 't'; // the side chosen in ⚙️ Settings for each bar (app/gutter-sides.ts) @@ -29,8 +30,9 @@ export function GutterScrollbars({ box, frame }: { box: React.RefObject { const el = box.current; if (!el) return undefined; - // inside a ⤢ window the bars go into the window, above its dimmed page - setHost(el.closest('[role="dialog"]') ?? document.body); + // inside a ⤢ window the bars go into the window, above its dimmed page; inside a sliding panel (⚙️ Settings) into + // its layer, above the page and its halo + setHost(el.closest('[role="dialog"]') ?? el.closest('[data-overlay]') ?? document.body); let frameId = 0; const measure = (): void => { frameId = 0; @@ -45,7 +47,7 @@ export function GutterScrollbars({ box, frame }: { box: React.RefObject { setShown((s) => (s[way] ? s : { ...s, [way]: true })); if (hide[way] !== undefined) clearTimeout(hide[way]); - hide[way] = setTimeout(() => setShown((s) => ({ ...s, [way]: false })), SCROLL_SHOWN_MS); + hide[way] = setTimeout(() => setShown((s) => ({ ...s, [way]: false })), shownMs()); }; const onScroll = (): void => { soon(); diff --git a/src/viewer/ui/LookSettings.tsx b/src/viewer/ui/LookSettings.tsx index 510fc7e..99713a1 100644 --- a/src/viewer/ui/LookSettings.tsx +++ b/src/viewer/ui/LookSettings.tsx @@ -2,6 +2,7 @@ import type { ThemeMode } from '../../shared/theme'; import { GUTTER_SIDES, gutterSides, saveSides, toggleSide, type GutterSide } from '../app/gutter-sides'; import { t } from '../app/i18n'; +import { SHOWN_SECONDS, saveShown, scrollShown } from '../app/scroll-shown'; import { LangButton, ThemeButton, WatchButton } from './IconButtons'; import { PILL_GAP, pillClass, pillStyle } from './Pills'; import { SettingRow } from './SettingRow'; @@ -28,18 +29,31 @@ export function WatchSetting({ userscript }: { userscript: string | null }) { ); } -/** the gutters that carry the tables' scrollbars (app/gutter-sides.ts): a chip a side, any number on, none = no bars */ +/** + * The gutters that carry the scrollbars of the page and the tables (app/gutter-sides.ts): a chip a side, any number on, + * none = no bars; right after them on the same line the seconds they stay after a scroll, one chosen + * (app/scroll-shown.ts; owner 2026-12-03: "right after a [the sides] in the same line") + */ export function ScrollbarsSetting() { const sides = useStore(gutterSides); + const seconds = useStore(scrollShown); const name: Record = { right: t('Right'), bottom: t('Below'), left: t('Left'), top: t('Above') }; return ( - {GUTTER_SIDES.map((s) => { - const on = sides.indexOf(s) >= 0; - return ; - })} +
+
+ {GUTTER_SIDES.map((s) => { + const on = sides.indexOf(s) >= 0; + return ; + })} +
+
+ {SHOWN_SECONDS.map((n) => { + const on = n === seconds; + return ; + })} +
- }>{t('Scrollbars of the tables, in the margins around the card; none: scroll with the wheel or a finger')}
+ }>{t('Scrollbars of the page and the tables, in the margins around the cards, and the seconds they stay after a scroll; no side: scroll with the wheel or a finger')} ); } diff --git a/src/viewer/ui/SlidePanel.tsx b/src/viewer/ui/SlidePanel.tsx index 228bad8..9c55249 100644 --- a/src/viewer/ui/SlidePanel.tsx +++ b/src/viewer/ui/SlidePanel.tsx @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'; import { t } from '../app/i18n'; import { panelRoom, pressCloses } from '../app/overlay'; +import { GutterScrollbars } from './GutterScrollbars'; // A panel that slides down under the toolbar and back up (pattern slide-down-panels, its overlay form): it lies OVER the // page (owner 2026-12-03: "do not move whole page content when we open settings ... slide down like now, but on top of @@ -11,6 +12,7 @@ import { panelRoom, pressCloses } from '../app/overlay'; // (the Settings resets, owner 2026-11-24). Above the gutter scrollbars (z 40), under the ⤢ windows and the 🔔 popups (z 50) export function SlidePanel({ open, title, onClose, id, children, tools }: { open: boolean; title: string; onClose: () => void; id: string; children: React.ReactNode; tools?: React.ReactNode }) { const box = useRef(null); + const body = useRef(null); const [room, setRoom] = useState(undefined); const close = useRef(onClose); close.current = onClose; @@ -76,7 +78,10 @@ export function SlidePanel({ open, title, onClose, id, children, tools }: { open
-
{children}
+ {/* its scrollbar runs in the gutter right of the panel, like the page's and the tables' (owner 2026-12-03: "our + configuration should be applied to the whole site"), drawn in this layer so the halo does not cover it */} +
{children}
+ {open && } diff --git a/src/viewer/ui/scrollbars.test.ts b/src/viewer/ui/scrollbars.test.ts index 1145291..572220c 100644 --- a/src/viewer/ui/scrollbars.test.ts +++ b/src/viewer/ui/scrollbars.test.ts @@ -53,3 +53,18 @@ test('the real timers work when called through the default (a method call of set expect(box.classList.contains('is-scrolling')).toBe(false); stop(); }); + +test('the time is read at each scroll, so a new choice in ⚙️ Settings holds at once', () => { + const asked: number[] = []; + const set = ((_fn: () => void, ms: number) => { asked.push(ms); return asked.length; }) as unknown as typeof setTimeout; + const clear = (() => undefined) as unknown as typeof clearTimeout; + let seconds = 3; + const box = document.createElement('div'); + document.body.appendChild(box); + const stop = revealScrollbars(document, () => seconds * 1000, { set, clear }); + box.dispatchEvent(new Event('scroll')); + seconds = 10; + box.dispatchEvent(new Event('scroll')); + expect(asked).toEqual([3000, 10000]); + stop(); +}); diff --git a/src/viewer/ui/scrollbars.ts b/src/viewer/ui/scrollbars.ts index e45d9e8..fa93bea 100644 --- a/src/viewer/ui/scrollbars.ts +++ b/src/viewer/ui/scrollbars.ts @@ -1,15 +1,17 @@ /// +import { shownMs } from '../app/scroll-shown'; + /** - * Scrollbars show only while a box scrolls and for 3 s after it stops (owner 2026-12-02: "show scrolls H and V only when - * we start scrolling and 3 seconds after stopped ... hide but do not change a page structure and spacing", "on all pages - * where we have them"): a scroll anywhere (one capturing listener on the document, so boxes drawn later count too) marks + * Scrollbars show only while a box scrolls and for a few seconds after it stops, 3 s unless ⚙️ Settings says otherwise + * (app/scroll-shown.ts; owner 2026-12-02: "show scrolls H and V only when we start scrolling and 3 seconds after + * stopped ... hide but do not change a page structure and spacing", "on all pages where we have them"): a scroll anywhere (one capturing listener on the document, so boxes drawn later count too) marks * that box `is-scrolling` and a timer per box takes the mark off. index.css paints a marked box's scrollbar in the * theme's colour and every other one transparent; the scrollbar keeps its room, so nothing moves */ -export const SCROLL_SHOWN_MS = 3000; // the browser's timers wrapped: called as a method of another object setTimeout throws "Illegal invocation" const BROWSER_TIMERS = { set: ((fn: () => void, ms: number) => setTimeout(fn, ms)) as unknown as typeof setTimeout, clear: ((t: ReturnType) => clearTimeout(t)) as unknown as typeof clearTimeout }; -export function revealScrollbars(doc: Document, ms = SCROLL_SHOWN_MS, timers: { set: typeof setTimeout; clear: typeof clearTimeout } = BROWSER_TIMERS): () => void { +/** `ms`: the time to stay, a number or read at each scroll (the setting) */ +export function revealScrollbars(doc: Document, ms: number | (() => number) = shownMs, timers: { set: typeof setTimeout; clear: typeof clearTimeout } = BROWSER_TIMERS): () => void { const pending = new WeakMap>(); const onScroll = (e: Event): void => { const box = e.target === doc ? doc.documentElement : e.target instanceof Element ? e.target : null; @@ -17,7 +19,7 @@ export function revealScrollbars(doc: Document, ms = SCROLL_SHOWN_MS, timers: { box.classList.add('is-scrolling'); const before = pending.get(box); if (before !== undefined) timers.clear(before); - pending.set(box, timers.set(() => { box.classList.remove('is-scrolling'); pending.delete(box); }, ms)); + pending.set(box, timers.set(() => { box.classList.remove('is-scrolling'); pending.delete(box); }, typeof ms === 'number' ? ms : ms())); }; doc.addEventListener('scroll', onScroll, { capture: true, passive: true }); return () => doc.removeEventListener('scroll', onScroll, { capture: true }); diff --git a/src/viewer/ui/useScrollbarRoom.ts b/src/viewer/ui/useScrollbarRoom.ts deleted file mode 100644 index 68fc63a..0000000 --- a/src/viewer/ui/useScrollbarRoom.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// -import { useEffect } from 'react'; -import { scrollbarRoom } from '../app/scrollbar-room'; - -// Puts the width of a box's own scrollbar into its `--bar` (app/scrollbar-room.ts), measured again whenever the box -// changes size (a window resize, a zoom, a mouse plugged in); its CSS takes that off the right padding -export function useScrollbarRoom(box: React.RefObject, on: boolean): void { - useEffect(() => { - const el = box.current; - if (!el || !on) return undefined; - const measure = (): void => { el.style.setProperty('--bar', `${scrollbarRoom(el.offsetWidth, el.clientWidth)}px`); }; - measure(); - const seen = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure); - seen?.observe(el); - window.addEventListener('resize', measure); - return () => { seen?.disconnect(); window.removeEventListener('resize', measure); el.style.removeProperty('--bar'); }; - }, [box, on]); -}