Commit cc4fc4d48b
Unsigned
Layout: unified · split
docs/.vitepress/configs/markdown/tableMore.ts +3 −5
| @@ -110,11 +110,9 @@ function countTableCols(tokens: any[], tableCloseIdx: number): number { | |||
| 110 | function stampTableAnchor(state: any, tokens: any[], tableCloseIdx: number) { | 110 | function stampTableAnchor(state: any, tokens: any[], tableCloseIdx: number) { |
| 111 | const openIdx = findTableOpen(tokens, tableCloseIdx) | 111 | const openIdx = findTableOpen(tokens, tableCloseIdx) |
| 112 | if (openIdx === -1) return | 112 | if (openIdx === -1) return |
| 113 | state.env.__tableMoreCount = (state.env.__tableMoreCount ?? 0) + 1 | 113 | const n = state.env.__tableMoreCount ?? 0 |
| 114 | tokens[openIdx].attrJoin( | 114 | state.env.__tableMoreCount = n + 1 |
| 115 | 'data-table-more', | 115 | tokens[openIdx].attrJoin('data-table-more', String(n)) |
| 116 | `table-more-${state.env.__tableMoreCount}` | ||
| 117 | ) | ||
| 118 | } | 116 | } |
| 119 | 117 | ||
| 120 | export function tableMorePlugin(md: MarkdownIt): void { | 118 | export function tableMorePlugin(md: MarkdownIt): void { |
docs/.vitepress/theme/Layout.vue +26 −5
| @@ -384,8 +384,9 @@ const updateQueryForSelectedTab = async (tabs: HTMLElement) => { | |||
| 384 | if (!tabPath.length) return | 384 | if (!tabPath.length) return |
| 385 | 385 | ||
| 386 | const collapsibles = getOpenCollapsiblePath(tabs) | 386 | const collapsibles = getOpenCollapsiblePath(tabs) |
| 387 | const tables = getOpenTableMorePath(tabs) | ||
| 387 | 388 | ||
| 388 | const nextUrl = buildUrl({ tabs: tabPath, collapsibles }) | 389 | const nextUrl = buildUrl({ tabs: tabPath, collapsibles, tables }) |
| 389 | const currentUrl = | 390 | const currentUrl = |
| 390 | `${window.location.pathname}${window.location.search}${window.location.hash}` | 391 | `${window.location.pathname}${window.location.search}${window.location.hash}` |
| 391 | if (nextUrl === currentUrl) return | 392 | if (nextUrl === currentUrl) return |
| @@ -506,9 +507,11 @@ const updateQueryForCollapsible = async (details: HTMLElement) => { | |||
| 506 | 507 | ||
| 507 | const collapsiblePath = getOpenCollapsiblePath(details) | 508 | const collapsiblePath = getOpenCollapsiblePath(details) |
| 508 | const tabPath = getEnclosingTabPath(details) | 509 | const tabPath = getEnclosingTabPath(details) |
| 510 | const tables = getOpenTableMorePath() | ||
| 509 | 511 | ||
| 510 | const nextUrl = buildUrl({ | 512 | const nextUrl = buildUrl({ |
| 511 | tabs: tabPath.length ? tabPath : [], | 513 | tabs: tabPath.length ? tabPath : [], |
| 514 | tables, | ||
| 512 | collapsibles: collapsiblePath | 515 | collapsibles: collapsiblePath |
| 513 | }) | 516 | }) |
| 514 | const currentUrl = | 517 | const currentUrl = |
| @@ -554,7 +557,19 @@ const queueTableMoreQueryUpdate = (target: EventTarget | null) => { | |||
| 554 | const box = target.closest<HTMLInputElement>('.table-more-checkbox') | 557 | const box = target.closest<HTMLInputElement>('.table-more-checkbox') |
| 555 | if (!box) return | 558 | if (!box) return |
| 556 | const table = box.closest<HTMLElement>('table') | 559 | const table = box.closest<HTMLElement>('table') |
| 557 | if (table) void updateQueryForTableMore(table) | 560 | if (!table) return |
| 561 | if (box.checked) { | ||
| 562 | // Accordion: opening one closes the others so only it stays in the URL. | ||
| 563 | document.querySelectorAll<HTMLTableElement>(TABLE_MORE_SELECTOR).forEach( | ||
| 564 | (other) => { | ||
| 565 | if (other !== table) { | ||
| 566 | const otherBox = getTableMoreCheckbox(other) | ||
| 567 | if (otherBox) otherBox.checked = false | ||
| 568 | } | ||
| 569 | } | ||
| 570 | ) | ||
| 571 | } | ||
| 572 | void updateQueryForTableMore(table) | ||
| 558 | } | 573 | } |
| 559 | 574 | ||
| 560 | const selectCollapsiblesByPath = async (collapsiblePath: string[]) => { | 575 | const selectCollapsiblesByPath = async (collapsiblePath: string[]) => { |
| @@ -606,9 +621,9 @@ const selectTablesByPath = async (anchors: string[]) => { | |||
| 606 | return opened | 621 | return opened |
| 607 | } | 622 | } |
| 608 | 623 | ||
| 609 | const getOpenTableMorePath = () => { | 624 | const getOpenTableMorePath = (root: ParentNode = document) => { |
| 610 | const anchors: string[] = [] | 625 | const anchors: string[] = [] |
| 611 | document.querySelectorAll<HTMLTableElement>(TABLE_MORE_SELECTOR).forEach( | 626 | root.querySelectorAll<HTMLTableElement>(TABLE_MORE_SELECTOR).forEach( |
| 612 | (table) => { | 627 | (table) => { |
| 613 | if (getTableMoreCheckbox(table)?.checked) { | 628 | if (getTableMoreCheckbox(table)?.checked) { |
| 614 | const anchor = table.dataset.tableMore | 629 | const anchor = table.dataset.tableMore |
| @@ -708,7 +723,11 @@ const selectLegacyTabHash = async (hash: string) => { | |||
| 708 | 723 | ||
| 709 | const tabs = button.closest<HTMLElement>('.plugin-tabs') | 724 | const tabs = button.closest<HTMLElement>('.plugin-tabs') |
| 710 | if (tabs) { | 725 | if (tabs) { |
| 711 | window.history.replaceState(null, '', buildUrlWithTabs([hash])) | 726 | window.history.replaceState( |
| 727 | null, | ||
| 728 | '', | ||
| 729 | buildUrl({ tabs: [hash], tables: getOpenTableMorePath(tabs) }) | ||
| 730 | ) | ||
| 712 | } | 731 | } |
| 713 | return tabs | 732 | return tabs |
| 714 | } | 733 | } |
| @@ -1467,6 +1486,7 @@ function setupManualCopyButtons() { | |||
| 1467 | wrapTablesInRoot(node) | 1486 | wrapTablesInRoot(node) |
| 1468 | resetTableMoreInRoot(node) | 1487 | resetTableMoreInRoot(node) |
| 1469 | initCopyButtonsInRoot(node) | 1488 | initCopyButtonsInRoot(node) |
| 1489 | void selectTablesByPath(getRequestedTableMorePath()) | ||
| 1470 | if (faviconsEnabled.value) applyFavicons(node) | 1490 | if (faviconsEnabled.value) applyFavicons(node) |
| 1471 | reapplyHighlightIfNeeded(node) | 1491 | reapplyHighlightIfNeeded(node) |
| 1472 | } else { | 1492 | } else { |
| @@ -1475,6 +1495,7 @@ function setupManualCopyButtons() { | |||
| 1475 | wrapTablesInRoot(panel) | 1495 | wrapTablesInRoot(panel) |
| 1476 | resetTableMoreInRoot(panel) | 1496 | resetTableMoreInRoot(panel) |
| 1477 | initCopyButtonsInRoot(panel) | 1497 | initCopyButtonsInRoot(panel) |
| 1498 | void selectTablesByPath(getRequestedTableMorePath()) | ||
| 1478 | if (faviconsEnabled.value) applyFavicons(panel) | 1499 | if (faviconsEnabled.value) applyFavicons(panel) |
| 1479 | reapplyHighlightIfNeeded(panel) | 1500 | reapplyHighlightIfNeeded(panel) |
| 1480 | } | 1501 | } |