Skip to content

Commit 7edaf9f

Browse files
committed
Merge current freshness fixes into documentation breadcrumbs
2 parents c594ad1 + 803db81 commit 7edaf9f

29 files changed

Lines changed: 591 additions & 170 deletions

‎.github/workflows/update-tanstack-deps.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: pnpm install --frozen-lockfile
3333

3434
- name: Update TanStack Dependencies
35-
run: pnpm up "@tanstack/*" --latest
35+
run: pnpm up "@tanstack/*" "!@tanstack/ai" "!@tanstack/ai-*" --latest
3636

3737
- name: Check for Changes
3838
id: git-check

‎src/components/LibraryLayout.tsx‎

Lines changed: 26 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ import {
4444
getLibraryLayoutVersion,
4545
getLibraryTabLinkOptions,
4646
getMenuGroupInitialOpenState,
47-
isChartsCatalogTarget,
4847
} from './library-layout-navigation'
48+
import {
49+
customToolTabs,
50+
isCustomToolTarget,
51+
} from '~/libraries/custom-tool-tabs'
4952

5053
// Number of days a doc page is flagged as "New"/"Updated" in the sidebar.
5154
const RECENCY_WINDOW_DAYS = 7
@@ -675,18 +678,6 @@ const useMenuConfig = ({
675678
const currentFramework = useCurrentFramework(frameworks)
676679
const statsAvailable =
677680
getLibrary(libraryId as LibraryId).statsAvailable !== false
678-
const chartsExamplesMenuItems: MenuItem['children'] = [
679-
{
680-
label: 'Examples',
681-
to: '/charts/catalog',
682-
tab: 'home',
683-
},
684-
{
685-
label: 'Examples',
686-
to: '/charts/catalog',
687-
tab: 'examples',
688-
},
689-
]
690681

691682
const localMenu: MenuItem = {
692683
label: 'Menu',
@@ -695,7 +686,6 @@ const useMenuConfig = ({
695686
label: 'Home',
696687
to: '..',
697688
},
698-
...(libraryId === 'charts' ? chartsExamplesMenuItems : []),
699689
{
700690
label: 'Blog',
701691
to: '/$libraryId/$version/docs/blog',
@@ -830,17 +820,7 @@ export function LibraryLayout({
830820
const menuConfig = useMenuConfig({ config, frameworks, repo, libraryId })
831821
const libraryGroupColor = categoryTextColor[categoryOf(libraryId)]
832822

833-
const isExample = matches.some(
834-
(d) =>
835-
d.pathname.includes('/examples/') ||
836-
d.routeId.startsWith('/_library/charts/catalog'),
837-
)
838-
839-
const isThemeEditor = matches.some((d) =>
840-
d.routeId.startsWith('/_library/highlight/$version/theme-editor'),
841-
)
842-
843-
const isNpmStats = matches.some((d) => d.pathname.includes('/docs/npm-stats'))
823+
const docsTab = matches.find((d) => d.staticData.docsTab)?.staticData.docsTab
844824

845825
// The library blog already lists posts, so the "Latest Posts" rail widget is
846826
// redundant there — hide it on the blog while keeping it on other docs pages.
@@ -872,60 +852,17 @@ export function LibraryLayout({
872852
}, [closeMobileMenu, mobileMenuOpen])
873853

874854
const tabbedMenuConfig = React.useMemo(() => {
875-
const tabs = getTabbedMenuConfig(menuConfig)
876-
877-
if (libraryId === 'charts') {
878-
return tabs.map((tab) =>
879-
tab.id === 'examples'
880-
? {
881-
...tab,
882-
firstItem: {
883-
label: 'Examples',
884-
to: '/charts/catalog',
885-
tab: 'examples',
886-
},
887-
}
888-
: tab,
889-
)
890-
}
891-
892-
if (libraryId === 'highlight') {
893-
return [
894-
...tabs,
895-
{
896-
id: 'theme-editor' as const,
897-
label: 'Theme Editor',
898-
groups: [],
899-
firstItem: {
900-
label: 'Theme Editor',
901-
to: '/highlight/$version/theme-editor',
902-
tab: 'theme-editor' as const,
903-
},
904-
},
905-
]
906-
}
907-
908-
return tabs
855+
return getTabbedMenuConfig(menuConfig, customToolTabs[libraryId])
909856
}, [libraryId, menuConfig])
910857

911858
const activeTabId = React.useMemo(() => {
912-
if (isThemeEditor) {
913-
return 'theme-editor' as const
914-
}
915-
916859
return getActiveDocsNavTabId({
917-
isExample,
860+
tabIdOverride: docsTab?.id,
918861
menuConfig,
919862
pathname: lastMatch.pathname,
920863
relativePathname,
921864
})
922-
}, [
923-
isExample,
924-
isThemeEditor,
925-
lastMatch.pathname,
926-
menuConfig,
927-
relativePathname,
928-
])
865+
}, [docsTab?.id, lastMatch.pathname, menuConfig, relativePathname])
929866

930867
const visibleMenuConfig = React.useMemo(() => {
931868
return (
@@ -964,11 +901,12 @@ export function LibraryLayout({
964901

965902
const groupInitialOpenState = React.useMemo(() => {
966903
return getMenuGroupInitialOpenState(
904+
libraryId,
967905
visibleMenuConfig,
968906
_splat,
969907
lastMatch.pathname,
970908
)
971-
}, [lastMatch.pathname, visibleMenuConfig, _splat])
909+
}, [libraryId, lastMatch.pathname, visibleMenuConfig, _splat])
972910

973911
const [openGroups, setOpenGroups] = React.useState(groupInitialOpenState)
974912

@@ -1042,7 +980,7 @@ export function LibraryLayout({
1042980
? ({ libraryId, version } as never)
1043981
: undefined
1044982
const isHomeLink = child.to === '..'
1045-
const isChartsExamplesLink = isChartsCatalogTarget(child.to)
983+
const isCustomToolLink = isCustomToolTarget(libraryId, child.to)
1046984
const frameworkDocsTarget = getFrameworkDocsLinkTarget(child.to)
1047985

1048986
const recency = getDocRecency(child.addedAt, child.updatedAt)
@@ -1130,14 +1068,12 @@ export function LibraryLayout({
11301068
) : (
11311069
<Link
11321070
from={
1133-
isChartsExamplesLink
1134-
? undefined
1135-
: '/$libraryId/$version/docs'
1071+
isCustomToolLink ? undefined : '/$libraryId/$version/docs'
11361072
}
11371073
to={child.to}
11381074
params={linkParams}
11391075
onClick={closeMobileMenu}
1140-
preload={isChartsExamplesLink ? false : 'intent'}
1076+
preload={isCustomToolLink ? false : 'intent'}
11411077
activeOptions={{
11421078
exact: true,
11431079
includeHash: false,
@@ -1244,8 +1180,7 @@ export function LibraryLayout({
12441180
params={linkOptions.params as never}
12451181
onClick={closeMobileMenu}
12461182
preload={
1247-
isChartsCatalogTarget(target.to) ||
1248-
target.to === '/highlight/$version/theme-editor'
1183+
isCustomToolTarget(libraryId, target.to)
12491184
? false
12501185
: 'intent'
12511186
}
@@ -1421,10 +1356,7 @@ export function LibraryLayout({
14211356
to={linkOptions.to as never}
14221357
params={linkOptions.params as never}
14231358
preload={
1424-
isChartsCatalogTarget(target.to) ||
1425-
target.to === '/highlight/$version/theme-editor'
1426-
? false
1427-
: 'intent'
1359+
isCustomToolTarget(libraryId, target.to) ? false : 'intent'
14281360
}
14291361
activeOptions={{
14301362
exact: true,
@@ -1545,18 +1477,21 @@ export function LibraryLayout({
15451477
!isLandingPage && 'px-4 md:px-8',
15461478

15471479
!isLandingPage &&
1548-
!isExample &&
1549-
!isNpmStats &&
1550-
!isThemeEditor &&
1480+
!docsTab?.fullBleed &&
15511481
'mx-auto w-[var(--docs-content-width,900px)]',
15521482
)}
15531483
>
15541484
{landingBreadcrumbItems && (
1555-
<div className="px-4 pt-4 md:px-8">
1556-
<Breadcrumbs
1557-
section="Libraries"
1558-
items={landingBreadcrumbItems}
1559-
/>
1485+
// Overlays the hero's top padding; matches the hero container so it aligns with the logo.
1486+
<div className="pointer-events-none absolute inset-x-0 top-0 z-10">
1487+
<div className="mx-auto w-full max-w-384 px-5 pt-4 md:px-10 lg:px-12 lg:pt-5 2xl:px-20">
1488+
<div className="pointer-events-auto w-fit">
1489+
<Breadcrumbs
1490+
section="Libraries"
1491+
items={landingBreadcrumbItems}
1492+
/>
1493+
</div>
1494+
</div>
15601495
</div>
15611496
)}
15621497
{children}

‎src/components/landing/LibraryLanding.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ export function LibraryLandingShell({
263263
<div
264264
className={
265265
stackHero
266-
? 'grid items-start gap-12'
267-
: 'grid items-start gap-12 xl:min-h-116 xl:grid-cols-[minmax(0,0.82fr)_minmax(0,1.18fr)] xl:gap-10'
266+
? 'grid grid-cols-1 items-start gap-12'
267+
: 'grid grid-cols-1 items-start gap-12 xl:min-h-116 xl:grid-cols-[minmax(0,0.82fr)_minmax(0,1.18fr)] xl:gap-10'
268268
}
269269
>
270270
<div
@@ -324,7 +324,7 @@ export function LibraryLandingShell({
324324
className="hidden h-[18px] w-auto dark:block"
325325
/>
326326
<h1 className="mt-1">
327-
<span className="block bg-[linear-gradient(110deg,var(--landing-headline-start),var(--landing-headline-end))] bg-clip-text pr-1 font-library-name text-ds-display-lg font-normal uppercase text-transparent dark:[filter:drop-shadow(0_4px_4px_rgb(0_0_0/0.25))] sm:text-ds-display-xl 2xl:text-ds-display-2xl">
327+
<span className="block bg-[linear-gradient(110deg,var(--landing-headline-start),var(--landing-headline-end))] bg-clip-text pr-1 font-library-name text-ds-display-sm font-normal uppercase text-transparent dark:[filter:drop-shadow(0_4px_4px_rgb(0_0_0/0.25))] min-[400px]:text-ds-display-lg sm:text-ds-display-xl 2xl:text-ds-display-2xl">
328328
{library.name.replace(/^TanStack\s+/i, '')}
329329
</span>
330330
</h1>

‎src/components/library-layout-navigation.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isCustomToolTarget } from '~/libraries/custom-tool-tabs'
2+
import type { LibraryId } from '~/libraries/ids'
13
import type { MenuItem } from '~/utils/config'
24

35
export function isChartsCatalogTarget(to: string) {
@@ -22,7 +24,7 @@ export function getLibraryTabLinkOptions({
2224
version,
2325
to,
2426
}: {
25-
libraryId: string
27+
libraryId: LibraryId
2628
version: string
2729
to: string
2830
}) {
@@ -34,7 +36,7 @@ export function getLibraryTabLinkOptions({
3436

3537
return {
3638
from:
37-
isHomeTarget || isChartsCatalogTarget(to)
39+
isHomeTarget || isCustomToolTarget(libraryId, to)
3840
? undefined
3941
: '/$libraryId/$version/docs',
4042
to: isHomeTarget ? `/${libraryId}/${version}` : to,
@@ -50,6 +52,7 @@ function normalizeMenuPath(path: string) {
5052
}
5153

5254
export function isMenuTargetActive(
55+
libraryId: LibraryId,
5356
to: string,
5457
relativePathname: string | undefined,
5558
pathname: string,
@@ -59,12 +62,13 @@ export function isMenuTargetActive(
5962
}
6063

6164
return (
62-
isChartsCatalogTarget(to) &&
65+
isCustomToolTarget(libraryId, to) &&
6366
normalizeMenuPath(to) === normalizeMenuPath(pathname)
6467
)
6568
}
6669

6770
export function getMenuGroupInitialOpenState(
71+
libraryId: LibraryId,
6872
groups: MenuItem[],
6973
relativePathname: string | undefined,
7074
pathname: string,
@@ -73,7 +77,7 @@ export function getMenuGroupInitialOpenState(
7377

7478
groups.forEach((group, index) => {
7579
const isChildActive = group.children.some((child) =>
76-
isMenuTargetActive(child.to, relativePathname, pathname),
80+
isMenuTargetActive(libraryId, child.to, relativePathname, pathname),
7781
)
7882
const key = `${index}:${String(group.label)}`
7983

‎src/components/npm-stats/NPMStatsChart.tsx‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { renderChartSvgWithResources } from '@tanstack/charts/svg/resources'
1717
import { tooltip } from '@tanstack/charts/tooltip'
1818
import { Chart } from '@tanstack/charts/react'
1919
import { GIFEncoder, applyPalette, quantize } from 'gifenc'
20+
import { getSvgDimensions } from './svgDimensions'
2021
import {
2122
CheckIcon,
2223
CodeIcon,
@@ -851,18 +852,6 @@ function createLatestBarExportChart({
851852
return svg ?? undefined
852853
}
853854

854-
function getSvgDimensions(svg: SVGSVGElement) {
855-
const box = svg.getBoundingClientRect()
856-
const viewBox = svg.viewBox.baseVal
857-
const width = svg.width.baseVal.value || viewBox.width || box.width || 1
858-
const height = svg.height.baseVal.value || viewBox.height || box.height || 1
859-
860-
return {
861-
width: Math.max(1, Math.ceil(width)),
862-
height: Math.max(1, Math.ceil(height)),
863-
}
864-
}
865-
866855
function isTransparentColor(color: string) {
867856
const normalizedColor = color.trim().toLowerCase()
868857

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SVGLength.SVG_LENGTHTYPE_PERCENTAGE. Inlined so this module does not depend on
2+
// the SVGLength global (unavailable outside the browser).
3+
const SVG_LENGTHTYPE_PERCENTAGE = 2
4+
5+
type AnimatedLengthLike = {
6+
baseVal: { unitType: number; value: number }
7+
}
8+
9+
type SvgLike = {
10+
width: AnimatedLengthLike
11+
height: AnimatedLengthLike
12+
viewBox: { baseVal: { width: number; height: number } | null }
13+
getBoundingClientRect: () => { width: number; height: number }
14+
}
15+
16+
function isNotSupportedError(error: unknown) {
17+
return (
18+
typeof error === 'object' &&
19+
error !== null &&
20+
'name' in error &&
21+
error.name === 'NotSupportedError'
22+
)
23+
}
24+
25+
/**
26+
* Reads an absolute SVG length in user units, returning 0 when the length is
27+
* relative (e.g. `width="100%"`). Browsers throw `NotSupportedError` when a
28+
* relative length cannot be resolved, which happens for SVGs that are not
29+
* attached to the document (such as off-screen animated export frames).
30+
*/
31+
export function readAbsoluteSvgLength(length: AnimatedLengthLike) {
32+
const baseVal = length.baseVal
33+
if (baseVal.unitType === SVG_LENGTHTYPE_PERCENTAGE) return 0
34+
35+
try {
36+
return baseVal.value
37+
} catch (error) {
38+
if (isNotSupportedError(error)) return 0
39+
throw error
40+
}
41+
}
42+
43+
export function getSvgDimensions(svg: SvgLike) {
44+
const box = svg.getBoundingClientRect()
45+
const viewBox = svg.viewBox.baseVal
46+
const width =
47+
readAbsoluteSvgLength(svg.width) || viewBox?.width || box.width || 1
48+
const height =
49+
readAbsoluteSvgLength(svg.height) || viewBox?.height || box.height || 1
50+
51+
return {
52+
width: Math.max(1, Math.ceil(width)),
53+
height: Math.max(1, Math.ceil(height)),
54+
}
55+
}

0 commit comments

Comments
 (0)