diff --git a/app/components/Package/Versions.vue b/app/components/Package/Versions.vue index 9461da3d8..35ba60c11 100644 --- a/app/components/Package/Versions.vue +++ b/app/components/Package/Versions.vue @@ -17,6 +17,7 @@ const props = defineProps<{ versions: Record distTags: Record time: Record + selectedVersion?: string }>() /** Maximum number of dist-tag rows to show before collapsing into "Other versions" */ @@ -42,6 +43,10 @@ function versionRoute(version: string): RouteLocationRaw { // Version to tags lookup (supports multiple tags per version) const versionToTags = computed(() => buildVersionToTagsMap(props.distTags)) +const effectiveCurrentVersion = computed( + () => props.selectedVersion ?? props.distTags.latest ?? undefined, +) + // All tag rows derived from props (SSR-safe) // Deduplicates so each version appears only once, with all its tags const allTagRows = computed(() => { @@ -298,6 +303,65 @@ function toggleMajorGroup(groupKey: string) { function getTagVersions(tag: string): VersionDisplay[] { return tagVersions.value.get(tag) ?? [] } + +function findClaimingTag(version: string): string | null { + const versionChannel = getPrereleaseChannel(version) + + // First matching tag claims the version + for (const row of allTagRows.value) { + const tagVersion = props.distTags[row.tag] + if (!tagVersion) continue + + const tagChannel = getPrereleaseChannel(tagVersion) + + if (isSameVersionGroup(version, tagVersion) && versionChannel === tagChannel) { + return row.tag + } + } + + return null +} + +// Whether this row should be highlighted for the current version +function rowContainsCurrentVersion(row: (typeof visibleTagRows.value)[0]): boolean { + if (!effectiveCurrentVersion.value) return false + + if (row.primaryVersion.version === effectiveCurrentVersion.value) return true + + if (getTagVersions(row.tag).some(v => v.version === effectiveCurrentVersion.value)) return true + + const claimingTag = findClaimingTag(effectiveCurrentVersion.value) + return claimingTag === row.tag +} + +function otherVersionsContainsCurrent(): boolean { + if (!effectiveCurrentVersion.value) return false + + const claimingTag = findClaimingTag(effectiveCurrentVersion.value) + + // If a tag claims it, check if that tag is in visibleTagRows + if (claimingTag) { + const isInVisibleTags = visibleTagRows.value.some(row => row.tag === claimingTag) + if (!isInVisibleTags) return true + return false + } + + // No tag claims it - it would be in otherMajorGroups + return true +} + +function hiddenRowContainsCurrent(row: (typeof hiddenTagRows.value)[0]): boolean { + if (!effectiveCurrentVersion.value) return false + if (row.primaryVersion.version === effectiveCurrentVersion.value) return true + + const claimingTag = findClaimingTag(effectiveCurrentVersion.value) + return claimingTag === row.tag +} + +function majorGroupContainsCurrent(group: (typeof otherMajorGroups.value)[0]): boolean { + if (!effectiveCurrentVersion.value) return false + return group.versions.some(v => v.version === effectiveCurrentVersion.value) +}