Skip to content

Commit 71afd1e

Browse files
committed
refactor(output): show() selects panels by id and tracks the active act
1 parent add0178 commit 71afd1e

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

output-tab.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,17 +2230,25 @@ function renderSubNav(actId) {
22302230
}
22312231

22322232
function show(n, { updateHash = true } = {}) {
2233-
document.querySelectorAll('.tab-btn').forEach(b => b.classList.toggle('active', Number(b.dataset.tab) === n));
2234-
document.querySelectorAll('.tab-content').forEach((c, idx) => c.classList.toggle('active', idx === n));
2235-
// Blueprint canvas mounts lazily on every activation path (click, #hash deep-link, per-repo restore).
2236-
// renderCanvas is idempotent (dataset.mounted guard) and null-safe, so calling it on each show(27) is cheap.
2233+
// Active tab button (in the secondary row) + active panel (by id, not DOM order).
2234+
document.querySelectorAll('.tab-btn').forEach((b) => b.classList.toggle('active', Number(b.dataset.tab) === n));
2235+
document.querySelectorAll('.tab-content').forEach((c) => c.classList.remove('active'));
2236+
document.getElementById(`t${n}`)?.classList.add('active');
2237+
2238+
// Active act: highlight it and render its secondary row (if not already shown).
2239+
const actId = actForTab(n);
2240+
document.querySelectorAll('.act-tab').forEach((b) => b.classList.toggle('active', b.dataset.act === actId));
2241+
const sub = document.getElementById('act-subnav');
2242+
if (sub && sub.dataset.act !== actId) {
2243+
renderSubNav(actId);
2244+
sub.dataset.act = actId || '';
2245+
}
2246+
// Re-mark the active secondary button after a possible re-render.
2247+
document.querySelectorAll('#act-subnav .tab-btn').forEach((b) => b.classList.toggle('active', Number(b.dataset.tab) === n));
2248+
2249+
// Blueprint canvas mounts lazily on every activation path (idempotent + null-safe).
22372250
if (n === 27) renderCanvas(lastData).catch((err) => console.error('[canvas] render failed', err));
2238-
// Reflect the active tab on its parent menu button + close any open menus.
2239-
document.querySelectorAll('.tab-menu').forEach(m => {
2240-
const owns = [...m.querySelectorAll('.tab-btn')].some(b => Number(b.dataset.tab) === n);
2241-
m.querySelector('.tab-menu-btn')?.classList.toggle('active', owns);
2242-
m.classList.remove('open');
2243-
});
2251+
22442252
if (updateHash && TAB_SLUGS[n]) {
22452253
history.replaceState(null, '', `#${TAB_SLUGS[n]}`);
22462254
}

0 commit comments

Comments
 (0)