fix: phones render plain data tables as stacked cards (1.5.8)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
393a31cebe
commit
bc3ce09088
8 files changed
+123
-2
No files matched your search
@@ -2,4 +2,4 @@ package app
|
||||
|
||||
// Version is the release version (SemVer). Release builds may override it with
|
||||
// -ldflags "-X .../internal/app.Version=...".
|
||||
var Version = "1.5.7"
|
||||
var Version = "1.5.8"
|
||||
@@ -2011,6 +2011,39 @@
|
||||
}
|
||||
if (current) { try { current.page.unmount(); } catch (e) { console.error(e); } }
|
||||
var view = $('#view');
|
||||
// Mobile tables: every plain data table of a page gets data-label on its cells (from the header)
|
||||
// and the class "mc"; style.css turns those rows into stacked cards under 768 px. Tables that
|
||||
// already handle phones (stack, tbl-cards, eg-table, ipx-tbl, no-mc) and the sr-only chart tables are skipped.
|
||||
function cardTables() {
|
||||
var tabs = view.querySelectorAll('table:not(.sr-only):not(.stack):not(.tbl-cards):not(.eg-table):not(.ipx-tbl):not(.no-mc):not(.mc)');
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
var tb = tabs[i], hr = tb.querySelector('thead tr');
|
||||
if (!hr) continue;
|
||||
var labels = [].map.call(hr.children, function (c) { return (c.textContent || '').trim(); });
|
||||
[].forEach.call(tb.tBodies, function (body) {
|
||||
[].forEach.call(body.rows, function (r) {
|
||||
var k = 0;
|
||||
[].forEach.call(r.cells, function (c) {
|
||||
if (!c.hasAttribute('data-label')) c.setAttribute('data-label', labels[k] || '');
|
||||
if (c.childNodes.length > 1) { // one flex item per cell, so mixed content flows as text
|
||||
var w = document.createElement('span');
|
||||
w.className = 'mc-v';
|
||||
while (c.firstChild) w.appendChild(c.firstChild);
|
||||
c.appendChild(w);
|
||||
}
|
||||
k += c.colSpan || 1;
|
||||
});
|
||||
});
|
||||
});
|
||||
tb.classList.add('mc');
|
||||
}
|
||||
}
|
||||
var cardQueued = false;
|
||||
new MutationObserver(function () {
|
||||
if (cardQueued) return;
|
||||
cardQueued = true;
|
||||
requestAnimationFrame(function () { cardQueued = false; cardTables(); });
|
||||
}).observe(view, { childList: true, subtree: true });
|
||||
clear(view);
|
||||
state.note = '';
|
||||
var page = pages[id];
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
tb.appendChild(el('tr', null, el('td', { class: 'mono' }, m.method, m.odd ? U.ui.badge(t('hl.pr.odd'), 'warn') : null, el('div', { class: 'hl-brk-m' }, brk)), el('td', { class: 'num' }, U.fmt.num(m.n)), el('td', { class: 'num' }, U.fmt.num(errs)),
|
||||
el('td', { class: 'hl-brk' }, brk)));
|
||||
});
|
||||
pm.body.appendChild(el('div', { class: 'hl-scroll' }, el('table', { class: 'hl-table' },
|
||||
pm.body.appendChild(el('div', { class: 'hl-scroll' }, el('table', { class: 'hl-table no-mc' },
|
||||
el('thead', null, el('tr', null, el('th', null, t('hl.pr.col.method')), el('th', { class: 'num' }, t('hl.pr.col.n')), el('th', { class: 'num' }, t('hl.pr.col.errs')), el('th', { class: 'hl-brk' }, ''))), tb)));
|
||||
}
|
||||
function load() {
|
||||
|
||||
@@ -673,3 +673,20 @@ html, body { overflow-x: clip; }
|
||||
.unban-opt { display: flex; align-items: center; gap: 8px; }
|
||||
.unban-err { color: var(--bad, #b3261e); margin: 8px 0 0; }
|
||||
.unban-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
|
||||
|
||||
/* Plain data tables on phones: rows become stacked cards (labels from data-label, set by cardTables() in app.js). */
|
||||
@media (max-width: 767px) {
|
||||
.an-scroll, .df-scroll, .hl-scroll { overflow-x: hidden; max-width: 100%; }
|
||||
.ig-scroll, .mt-tablewrap { overflow: visible; max-width: 100%; }
|
||||
table.mc { min-width: 0 !important; }
|
||||
table.mc thead { display: none; }
|
||||
table.mc, table.mc tbody, table.mc tr, table.mc td { display: block; width: 100%; box-sizing: border-box; }
|
||||
table.mc tr { margin: 6px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-raised); }
|
||||
table.mc td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 2px 0; text-align: right; min-width: 0; overflow-wrap: anywhere; word-break: normal; white-space: normal; }
|
||||
table.mc td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--ink-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; text-align: left; }
|
||||
table.mc td[data-label=""]::before { display: none; }
|
||||
table.mc td.num, table.mc td.num * { font-variant-numeric: tabular-nums; }
|
||||
table.mc td.an-key, table.mc td .mono { overflow-wrap: anywhere; word-break: break-all; }
|
||||
table.mc td[colspan] { display: block; text-align: left; }
|
||||
}
|
||||
@media (max-width: 767px) { table.mc .mc-v { min-width: 0; overflow-wrap: anywhere; word-break: normal; } }
|
||||
Reference in new issue
Block a user