From c4024c84f1ed99dc184c4d01c8f530bbbf86fd69 Mon Sep 17 00:00:00 2001 From: Maksim Kostromin Date: Sat, 5 Dec 2026 03:29:43 -0500 Subject: [PATCH] feat(guide): in-app guide with how it works and the column reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A 📖 button right before ☰ opens a modal Guide: short topics in the order a newcomer meets the page and a reference of every catalog column read from FUND_FILTER_COLUMNS with the header type badge and tooltip, the Watchlist columns, the detail tab tooltips and the filter grammar. One search over both. Shared ui-std block, ported by guide.ts. --- README.md | 2 +- src/index.css | 20 ++++ src/index.html | 15 +++ src/main.tsx | 315 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 351 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbc5667e..a7e4eee8 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The published application is available at ="2024-06-15 09:30"`) diff --git a/src/index.css b/src/index.css index 02d202d5..864da049 100644 --- a/src/index.css +++ b/src/index.css @@ -498,3 +498,23 @@ textarea.ui-input{height:auto;padding:.5rem .75rem;line-height:1.4} .am-sep{height:1px;margin:.25rem .125rem;background:var(--ui-line-soft);flex:none} @media (prefers-reduced-motion:reduce){.am-panel{transition:none}} .am-upload.dz-active{background:var(--ui-accent-soft);box-shadow:none;outline:1px dashed var(--ui-accent-ring);outline-offset:-1px} + +/* ui-std guide: start (guide.css, owner 2026-12-04, pattern in-app-guide): the 📖 Guide is a .ui-modal of the spec (page gutters, fixed head with + the title, the search and ✕, the body scrolls); 📖 sits in .am-root right before ☰, so .am-root lines its buttons up like the hub's 🔍 and ☰ */ +.am-bar > .am-root{display:inline-flex;align-items:center;gap:var(--ui-gap)} +/* below lg the search leaves room for the three squares of the hub (🔍 📖 ☰, 134px plus the gap) on its line */ +@media (max-width:63.999rem){.am-bar:not(.flex-col):has(> .am-root > #guide-btn) > .am-row{flex-basis:calc(100% - 9.5rem)}} +.guide-search{flex:1 1 auto;min-width:0} +/* the head keeps the 60px of the first panel with the 38px search in it (spec: head 60px, 12px 16px for 30px controls) */ +#guide-panel .ui-modal-head{padding-top:calc((var(--ui-head-h) - var(--ui-h-md) - 1px) / 2);padding-bottom:calc((var(--ui-head-h) - var(--ui-h-md) - 1px) / 2)} +.guide-body > *{max-width:80rem} +.guide-h2{margin:1.25rem 0 .5rem} +.guide-h2:first-child{margin-top:0} +.guide-topic,.guide-group{margin-bottom:1rem} +.guide-h3{display:flex;align-items:center;gap:.5rem;margin:.75rem 0 .35rem;font-size:var(--ui-fs-md);line-height:1.25rem;font-weight:700;color:var(--ui-text)} +.guide-topic p{margin:.3rem 0;color:var(--ui-text-2)} +.guide-item{padding:.5rem 0;border-top:1px solid var(--ui-line-soft)} +.guide-name{display:flex;align-items:center;gap:.5rem;font-weight:600;color:var(--ui-text)} +.guide-item p{margin:.2rem 0 0;color:var(--ui-muted)} +.guide-badge{cursor:default;opacity:1} +/* ui-std guide: end */ diff --git a/src/index.html b/src/index.html index db25cdd6..45560240 100644 --- a/src/index.html +++ b/src/index.html @@ -87,6 +87,7 @@

Sticky #:off
+ + + diff --git a/src/main.tsx b/src/main.tsx index 77a71ce5..0cd3aa73 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -4709,6 +4709,321 @@ document.querySelectorAll('a[data-feed-link]').forEach(link => { (link as HTMLAnchorElement).href = new URL(link.getAttribute('data-feed-link') || '', document.baseURI).href; }); +// ---- ui-std guide: start (ui-std guide-block.tsx and the app part, ported by guide.ts) ---- +// ========================================================================= +// ui-std guide (owner 2026-12-04: "similarly to Stocks or investments we must add a guide ... and we will be doing the same +// everywhere"; pattern in-app-guide): the 📖 Guide, "How it works" and the column reference read from the definitions the +// table is drawn from, found by one search. Shared block .claude/tools/etfs/ui-std/guide-block.tsx, ported by guide.ts; the +// app part right below it (guide-brand.tsx or guide-hub.tsx) says what this app has: guideTopics() and guideReference() +// ========================================================================= + +type GuideTopic = { id: string; title: string; body: string[] }; +type GuideItem = { name: string; about: string; type?: ColType }; +type GuideGroup = { id: string; title: string; items: GuideItem[] }; + +// ---- guide: pure search (ui-std/guide.test.ts cuts this part out and runs it) ---- + +/** The words of a query, lower case; an empty query has none and matches everything. */ +function guideQueryWords(query: string): string[] { + return String(query || '').toLowerCase().split(/\s+/).filter(Boolean); +} + +/** The texts hold every word of the query, in any order and case, inside words too. */ +function guideMatches(words: string[], texts: Array): boolean { + if (!words.length) return true; + const hay = texts.filter(Boolean).join(' ').toLowerCase(); + return words.every(word => hay.indexOf(word) >= 0); +} + +/** What the Guide shows for a query: the matching topics, and the groups with their matching items (empty groups dropped). */ +function filterGuide(query: string, topics: GuideTopic[], groups: GuideGroup[]): { topics: GuideTopic[]; groups: GuideGroup[] } { + const words = guideQueryWords(query); + return { + topics: topics.filter(topic => guideMatches(words, [topic.title].concat(topic.body))), + groups: groups + .map(group => ({ id: group.id, title: group.title, items: group.items.filter(item => guideMatches(words, [group.title, item.name, item.about])) })) + .filter(group => group.items.length > 0), + }; +} + +// ---- guide: end of pure search ---- + +/** The header tooltip of a column (COLUMN_TOOLTIPS, case-insensitive like the header); empty when the column has none. */ +function guideTip(label: string): string { + if (COLUMN_TOOLTIPS[label]) return COLUMN_TOOLTIPS[label]; + const wanted = String(label).toLowerCase(); + const keys = Object.keys(COLUMN_TOOLTIPS); + for (let i = 0; i < keys.length; i++) if (keys[i].toLowerCase() === wanted) return COLUMN_TOOLTIPS[keys[i]]; + return ''; +} + +/** The header tooltips no listed group has yet: the columns of the detail tab sheets, whose headers come with each fund's files. */ +function guideOtherTips(listed: GuideGroup[], typeOf: (label: string) => ColType | undefined): GuideItem[] { + const seen: Record = {}; + listed.forEach(group => group.items.forEach(item => { seen[item.name.toLowerCase()] = true; })); + return Object.keys(COLUMN_TOOLTIPS) + .filter(label => !seen[label.toLowerCase()]) + .map(label => ({ name: label, about: COLUMN_TOOLTIPS[label], type: typeOf(label) })); +} + +/** The filter grammar of every column type (block 3b), one item per type with its badge. */ +function guideGrammarGroup(): GuideGroup { + return { + id: 'grammar', + title: 'Filter grammar', + items: ALL_COL_TYPES.map(type => ({ name: COL_TYPE_NAMES[type].charAt(0).toUpperCase() + COL_TYPE_NAMES[type].slice(1), about: COL_TYPE_HELP[type], type })), + }; +} + +/** Topics that read the same in every app of the family (the app part puts them in its order). */ +function guideCommonTopics(): Record { + const panel: any = document.getElementById('actions-panel'); + const items: any[] = panel ? Array.from(panel.querySelectorAll('[role="menuitem"]')) : []; + const said: Record = { + 'copy-btn': 'copies the tickers of the rows the table shows, after the search and the filters.', + 'export-csv-btn': 'downloads the shown rows as a CSV file, in the shown order, starting with the # column.', + 'export-txt-btn': 'downloads the tickers of the shown rows as a text file, one per line.', + }; + const lines = items.map(item => { + const label = String(item.textContent || '').replace(/\s+/g, ' ').trim(); + const about = said[item.id] || String(item.getAttribute('title') || '').trim(); + return about ? `${label}: ${about}` : label; + }); + return { + filters: { + id: 'filters', + title: 'Column filters and types', + body: [ + 'The row of inputs under the headers filters each column. Filters of different columns add up (AND), the search applies on top, and Copy Tickers and the exports take the filtered rows. Filters: on or off shows or hides that row, Clear filters empties it.', + 'Inside one filter a space means AND, a comma OR, a leading ! NOT, ? an empty value and !? a value that is there. Numbers take >10, 10..50 and K M B T suffixes (>1B), text takes =exact, ^starts, ends$ and /regex/, dates take 2024, 2024-06, today and -7d. The grammar of every type is in the reference below.', + 'The badge next to a header is the column type: ABC text, 123 number, % percentage, $ money, D date, DT date and time, T time. It is detected from the cells; a click cycles it, Shift+click goes back to the detected one. Filters and types are remembered in this browser.', + ], + }, + columns: { + id: 'columns', + title: 'Columns menu', + body: [ + 'Columns lists every column of the catalog table in table order, with a search and All, Clear, Toggle, Reset and Only. Use and Ticker are always shown.', + 'A hidden column only hides its cells: the sort, the filters, the exports and Copy Tickers still use it. The choice is remembered in this browser.', + ], + }, + sort: { + id: 'sort', + title: 'Sort and Sticky #', + body: [ + 'A click on a header sorts by that column, a second click turns the order around. The catalog starts sorted by Net Assets, largest first; a missing value is a dash, never a zero, and sorts last both ways.', + 'Sticky #: on numbers the rows by their rank in the sorted table before the column filters, so a filtered fund keeps its rank and the numbers keep gaps (1, 4, 7). Off, # counts the shown rows 1..N.', + ], + }, + actions: { + id: 'actions', + title: '☰ actions menu', + body: [`☰ at the right end of the toolbar opens the actions: ${items.map(item => String(item.textContent || '').replace(/\s+/g, ' ').trim()).join(', ')}. Enter, Space or the down arrow opens it, the arrows move, Esc or a click outside closes it.`].concat(lines), + }, + advice: { + id: 'advice', + title: 'Not investment advice', + body: [ + 'The numbers are copied or computed from public issuer pages, SEC filings and Yahoo Finance; they can be late, incomplete or wrong, and a dash means the value is not available. Nothing here says what to buy or sell: check the issuer\'s own page before you trade.', + ], + }, + }; +} + +let guideOpen = false; +let guideData: { topics: GuideTopic[]; groups: GuideGroup[] } = { topics: [], groups: [] }; +let guideRootOverflow = ''; + +/** The column type badge as in the header (same classes), without its click. */ +function guideBadgeHtml(type?: ColType): string { + return type ? `${COL_TYPE_LABELS[type]}` : ''; +} + +/** The body for the search typed: the topics, then the reference groups with a count each, or "Nothing found". */ +function renderGuide(): void { + const body: any = document.getElementById('guide-body'); + const input: any = document.getElementById('guide-search'); + if (!body || !input) return; + const shown = filterGuide(String(input.value || ''), guideData.topics, guideData.groups); + const topicHtml = shown.topics.map(topic => `

${escapeHtml(topic.title)}

${topic.body.map(line => `

${escapeHtml(line)}

`).join('')}
`).join(''); + const groupHtml = shown.groups.map(group => `

${escapeHtml(group.title)}${group.items.length}

${group.items.map(item => `
${guideBadgeHtml(item.type)}${escapeHtml(item.name)}
${item.about ? `

${escapeHtml(item.about)}

` : ''}
`).join('')}
`).join(''); + body.innerHTML = topicHtml || groupHtml + ? `${topicHtml ? `

How it works

${topicHtml}` : ''}${groupHtml ? `

Column reference

${groupHtml}` : ''}` + : '

Nothing found

'; +} + +/** Open: the topics and the reference read now (the table may have changed), a fresh search, the focus in it; close: the focus back on 📖. */ +function setGuideOpen(open: boolean): void { + const panel: any = document.getElementById('guide-panel'); + const button: any = document.getElementById('guide-btn'); + const input: any = document.getElementById('guide-search'); + const body: any = document.getElementById('guide-body'); + if (!panel || !button || !input || !body || open === guideOpen) return; + guideOpen = open; + panel.hidden = !open; + button.setAttribute('aria-expanded', String(open)); + if (open) { + guideRootOverflow = document.documentElement.style.overflow; + document.documentElement.style.overflow = 'hidden'; + guideData = { topics: guideTopics(), groups: guideReference() }; + input.value = ''; + renderGuide(); + body.scrollTop = 0; + input.focus(); + } else { + document.documentElement.style.overflow = guideRootOverflow; + button.focus(); + } +} + +function setupGuide(): void { + const panel: any = document.getElementById('guide-panel'); + const button: any = document.getElementById('guide-btn'); + const input: any = document.getElementById('guide-search'); + const close: any = document.getElementById('guide-close'); + if (!panel || !button || !input || !close) return; + button.addEventListener('click', () => setGuideOpen(!guideOpen)); + close.addEventListener('click', () => setGuideOpen(false)); + // a press on the dim page around the window closes it + panel.addEventListener('click', (event: any) => { if (event.target === panel) setGuideOpen(false); }); + input.addEventListener('input', renderGuide); + document.addEventListener('keydown', (event: any) => { + if (!guideOpen) return; + if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); setGuideOpen(false); return; } + if (event.key !== 'Tab') return; + // Tab stays inside the window: the search field and ✕ + const stops: any[] = Array.from(panel.querySelectorAll('input, button, a[href]')); + const at = stops.indexOf(document.activeElement); + const next = at < 0 ? 0 : (at + (event.shiftKey ? stops.length - 1 : 1)) % stops.length; + event.preventDefault(); + if (stops[next]) stops[next].focus(); + }, true); +} + +// ---- ui-std guide, the app part of a brand (ui-std/guide-brand.tsx): what this page has, read from its own definitions ---- + +const GUIDE_APP = { brand: 'WisdomTree', source: 'WisdomTree product table + SEC EDGAR N-PORT-P + Yahoo Finance' }; // the one line per repo: brand and sources of etf-std/registry.json, written by guide.ts + +/** Types of the columns of a table as its header shows them (the last render of the scope), else detected from `rows` the same way; none without data. */ +function guideColumnTypes(scope: string, columns: FilterColumn[], rows: any[]): Array { + const info = filterInfo[scope]; + if (info && info.columns === columns) return info.types.slice(); + if (!rows.length) return columns.map(() => undefined); + return columns.map(col => { + const texts: string[] = []; + for (let i = 0; i < rows.length && texts.length < TYPE_SAMPLE_SIZE; i++) { + const text = col.text(rows[i]); + if (!isEmptyCell(text)) texts.push(text); + } + return typeOverrideFor(scope, col.key) || detectColType(texts); + }); +} + +/** The type of a detail tab column, when a sheet with that header was shown in this visit. */ +function guideSheetType(label: string): ColType | undefined { + const scopes = ['holdings', 'history', 'distributions']; + for (let s = 0; s < scopes.length; s++) { + const info = filterInfo[scopes[s]]; + if (!info) continue; + for (let i = 0; i < info.columns.length; i++) if (info.columns[i].label.toLowerCase() === label.toLowerCase()) return info.types[i]; + } + return undefined; +} + +function guideColumnItems(scope: string, columns: FilterColumn[], rows: any[]): GuideItem[] { + const types = guideColumnTypes(scope, columns, rows); + return columns.map((col, i) => ({ name: col.label, about: guideTip(col.label), type: types[i] })); +} + +/** The reference: the catalog columns (FUND_FILTER_COLUMNS, the header, the filter row and the Columns menu read them), the Watchlist columns, the detail tab tooltips, the filter grammar. */ +function guideReference(): GuideGroup[] { + const lead: GuideItem[] = ['#', 'Use'].map(label => ({ name: label, about: guideTip(label) })); + const groups: GuideGroup[] = [ + { id: 'catalog', title: 'ETF catalog', items: lead.concat(guideColumnItems('catalog', FUND_FILTER_COLUMNS, state.funds)) }, + { id: 'watchlist', title: 'Watchlist', items: guideColumnItems('watchlist', WATCHLIST_FILTER_COLUMNS, []) }, + ]; + const other = guideOtherTips(groups, guideSheetType); + if (other.length) groups.push({ id: 'detail', title: `Detail tabs (${DETAIL_TABS.map(tab => tab.label).join(', ')}), when a fund's files have the column`, items: other }); + groups.push(guideGrammarGroup()); + return groups; +} + +/** "How it works" in the order a newcomer meets the page; a topic or a line shows only when this app has the feature. */ +function guideTopics(): GuideTopic[] { + const common = guideCommonTopics(); + const categories = uniqueCategories().map(categoryLabel); + const feed = String(INDEX_URL).replace(/^\.\//, ''); + const generated = state.generatedAt ? new Date(state.generatedAt).toLocaleString() : ''; + const allToggle = document.getElementById('select-all-toggle'); + const classes: GuideTopic = categories.length > 1 + ? { + id: 'classes', + title: 'All ETFs and Asset classes', + body: [ + `All ETFs shows the whole catalog except the blacklist${allToggle ? '; its checkbox selects or deselects every fund' : ''}.`, + `Asset classes narrows the table to the ticked classes (${categories.length} here: ${categories.join(', ')}). All are ticked at first, unticking every class is All ETFs again, and the All ETFs pill is lit only while nothing narrows the table. The choice is remembered in this browser.`, + ], + } + : { + id: 'classes', + title: 'All ETFs', + body: [`The catalog shows every fund except the blacklist. This brand has one asset class${categories.length ? ` (${categories[0]})` : ''}, so there is no Asset classes menu.`], + }; + return [ + { + id: 'what', + title: 'What this page shows', + body: [ + `The ETFs of ${GUIDE_APP.brand} in one table: ${state.funds.length.toLocaleString('en-US')} funds, one row each, with costs, yields, returns, the 52-week range and holdings counts.`, + 'Tick funds to merge their holdings in the Watchlist or open a fund\'s own tabs. The ETFs Hub shows the funds of every brand in one table with the same columns.', + ], + }, + { + id: 'search', + title: 'Search', + body: [ + 'The search box keeps the rows that contain what you type: on the catalog the ticker, the fund name, the category and other fields of a fund, on the Watchlist and the detail tabs the cells of their rows. ✕ clears it.', + 'Every tab keeps its own search, so the catalog query stays while you look at a fund\'s holdings.', + ], + }, + classes, + common.filters, + common.columns, + common.sort, + common.actions, + { + id: 'selected', + title: 'Selected funds and their tabs', + body: [ + `Tick Use on a row to select a fund; the selection is remembered. The first panel then shows Watchlist and the tabs of the active fund: ${DETAIL_TABS.map(tab => tab.label).join(', ')}, each with its row count.`, + 'Watchlist merges the holdings of every selected fund into one row per security: # ETFs counts the funds that hold it, Weight Sum adds their weights, Max Weight is the largest one. Copy Tickers there copies the tickers of those rows.', + 'The count chip on the right says how many funds the table shows; hover or click it for where the data comes from. On wide screens the line next to the title names the selected funds.', + ], + }, + { + id: 'data', + title: 'Where the data comes from and how fresh it is', + body: [ + `The table reads ${feed} and the per-fund files of the same static feed, which the updater of this repository builds from: ${GUIDE_APP.source}.`, + `${generated ? `This copy of the feed was generated ${generated} (your time). ` : ''}The data workflow refreshes it every workday at 9:37 and 20:17 New York time.`, + 'As Of is the date of a fund\'s NAV and net assets, Return As Of the date its returns are calculated as of; issuers publish at different times, so the dates can differ between funds.', + ], + }, + { + id: 'theme', + title: 'Theme and what this browser keeps', + body: [ + 'The 🌙 or ☀️ button switches the dark and light theme.', + `The theme, the selection, the searches, the sort, the filters, the columns, the asset classes and the blacklist are kept in this browser (localStorage keys starting with ${FILTER_STORAGE_PREFIX}-); the funds' data is not stored. ☰ Clear resets them, the theme is kept.`, + ], + }, + common.advice, + ]; +} + +setupGuide(); +// ---- ui-std guide: end ---- + // keep init() the last statement: it reads top-level let/const bindings from all over this file, and started in the middle a reload // with a saved selection threw "Cannot access ... before initialization" (the catalog never loaded) init();