|
| 1 | +<script setup lang="ts"> |
| 2 | +const props = defineProps<{ |
| 3 | + packageName: string |
| 4 | + dependencies?: Record<string, string> |
| 5 | + peerDependencies?: Record<string, string> |
| 6 | + peerDependenciesMeta?: Record<string, { optional?: boolean }> |
| 7 | +}>() |
| 8 | +
|
| 9 | +// Expanded state for each section |
| 10 | +const depsExpanded = ref(false) |
| 11 | +const peerDepsExpanded = ref(false) |
| 12 | +
|
| 13 | +// Sort dependencies alphabetically |
| 14 | +const sortedDependencies = computed(() => { |
| 15 | + if (!props.dependencies) return [] |
| 16 | + return Object.entries(props.dependencies) |
| 17 | + .sort(([a], [b]) => a.localeCompare(b)) |
| 18 | +}) |
| 19 | +
|
| 20 | +// Sort peer dependencies alphabetically, with required first then optional |
| 21 | +const sortedPeerDependencies = computed(() => { |
| 22 | + if (!props.peerDependencies) return [] |
| 23 | +
|
| 24 | + return Object.entries(props.peerDependencies) |
| 25 | + .map(([name, version]) => ({ |
| 26 | + name, |
| 27 | + version, |
| 28 | + optional: props.peerDependenciesMeta?.[name]?.optional ?? false, |
| 29 | + })) |
| 30 | + .sort((a, b) => { |
| 31 | + // Required first, then optional |
| 32 | + if (a.optional !== b.optional) return a.optional ? 1 : -1 |
| 33 | + return a.name.localeCompare(b.name) |
| 34 | + }) |
| 35 | +}) |
| 36 | +
|
| 37 | +// Check if a version string is "long" (multiple alternatives) |
| 38 | +function isLongVersion(version: string): boolean { |
| 39 | + return version.length > 20 || version.includes('||') |
| 40 | +} |
| 41 | +
|
| 42 | +// Truncate long version strings for display |
| 43 | +function truncateVersion(version: string, maxLength = 20): string { |
| 44 | + if (version.length <= maxLength) return version |
| 45 | + return `${version.slice(0, maxLength)}…` |
| 46 | +} |
| 47 | +</script> |
| 48 | + |
| 49 | +<template> |
| 50 | + <div class="space-y-8"> |
| 51 | + <!-- Dependencies --> |
| 52 | + <section |
| 53 | + v-if="sortedDependencies.length > 0" |
| 54 | + aria-labelledby="dependencies-heading" |
| 55 | + > |
| 56 | + <div class="flex items-center justify-between mb-3"> |
| 57 | + <h2 |
| 58 | + id="dependencies-heading" |
| 59 | + class="text-xs text-fg-subtle uppercase tracking-wider" |
| 60 | + > |
| 61 | + Dependencies ({{ sortedDependencies.length }}) |
| 62 | + </h2> |
| 63 | + <a |
| 64 | + :href="`https://npmgraph.js.org/?q=${packageName}`" |
| 65 | + target="_blank" |
| 66 | + rel="noopener noreferrer" |
| 67 | + class="link-subtle text-fg-subtle" |
| 68 | + aria-label="View dependency graph" |
| 69 | + title="View dependency graph" |
| 70 | + > |
| 71 | + <span class="text-xs uppercase tracking-wider"> |
| 72 | + Graph |
| 73 | + </span> |
| 74 | + </a> |
| 75 | + </div> |
| 76 | + <ul |
| 77 | + class="space-y-1 list-none m-0 p-0" |
| 78 | + aria-label="Package dependencies" |
| 79 | + > |
| 80 | + <li |
| 81 | + v-for="[dep, version] in sortedDependencies.slice(0, depsExpanded ? undefined : 10)" |
| 82 | + :key="dep" |
| 83 | + class="flex items-center justify-between py-1 text-sm gap-2" |
| 84 | + > |
| 85 | + <NuxtLink |
| 86 | + :to="`/package/${dep}`" |
| 87 | + class="font-mono text-fg-muted hover:text-fg transition-colors duration-200 truncate min-w-0" |
| 88 | + > |
| 89 | + {{ dep }} |
| 90 | + </NuxtLink> |
| 91 | + <span |
| 92 | + class="font-mono text-xs text-fg-subtle max-w-[50%] text-right" |
| 93 | + :class="isLongVersion(version) ? 'truncate' : 'shrink-0'" |
| 94 | + :title="isLongVersion(version) ? version : undefined" |
| 95 | + > |
| 96 | + {{ isLongVersion(version) ? truncateVersion(version) : version }} |
| 97 | + </span> |
| 98 | + </li> |
| 99 | + </ul> |
| 100 | + <button |
| 101 | + v-if="sortedDependencies.length > 10 && !depsExpanded" |
| 102 | + type="button" |
| 103 | + class="mt-2 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" |
| 104 | + @click="depsExpanded = true" |
| 105 | + > |
| 106 | + show all {{ sortedDependencies.length }} deps |
| 107 | + </button> |
| 108 | + </section> |
| 109 | + |
| 110 | + <!-- Peer Dependencies --> |
| 111 | + <section |
| 112 | + v-if="sortedPeerDependencies.length > 0" |
| 113 | + aria-labelledby="peer-dependencies-heading" |
| 114 | + > |
| 115 | + <h2 |
| 116 | + id="peer-dependencies-heading" |
| 117 | + class="text-xs text-fg-subtle uppercase tracking-wider mb-3" |
| 118 | + > |
| 119 | + Peer Dependencies ({{ sortedPeerDependencies.length }}) |
| 120 | + </h2> |
| 121 | + <ul |
| 122 | + class="space-y-1 list-none m-0 p-0" |
| 123 | + aria-label="Package peer dependencies" |
| 124 | + > |
| 125 | + <li |
| 126 | + v-for="peer in sortedPeerDependencies.slice(0, peerDepsExpanded ? undefined : 10)" |
| 127 | + :key="peer.name" |
| 128 | + class="flex items-center justify-between py-1 text-sm gap-2" |
| 129 | + > |
| 130 | + <div class="flex items-center gap-2 min-w-0"> |
| 131 | + <NuxtLink |
| 132 | + :to="`/package/${peer.name}`" |
| 133 | + class="font-mono text-fg-muted hover:text-fg transition-colors duration-200 truncate" |
| 134 | + > |
| 135 | + {{ peer.name }} |
| 136 | + </NuxtLink> |
| 137 | + <span |
| 138 | + v-if="peer.optional" |
| 139 | + class="px-1 py-0.5 font-mono text-[10px] text-fg-subtle bg-bg-muted border border-border rounded shrink-0" |
| 140 | + title="Optional peer dependency" |
| 141 | + > |
| 142 | + optional |
| 143 | + </span> |
| 144 | + </div> |
| 145 | + <span |
| 146 | + class="font-mono text-xs text-fg-subtle max-w-[40%] text-right" |
| 147 | + :class="isLongVersion(peer.version) ? 'truncate' : 'shrink-0'" |
| 148 | + :title="isLongVersion(peer.version) ? peer.version : undefined" |
| 149 | + > |
| 150 | + {{ isLongVersion(peer.version) ? truncateVersion(peer.version) : peer.version }} |
| 151 | + </span> |
| 152 | + </li> |
| 153 | + </ul> |
| 154 | + <button |
| 155 | + v-if="sortedPeerDependencies.length > 10 && !peerDepsExpanded" |
| 156 | + type="button" |
| 157 | + class="mt-2 font-mono text-xs text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50" |
| 158 | + @click="peerDepsExpanded = true" |
| 159 | + > |
| 160 | + show all {{ sortedPeerDependencies.length }} peer deps |
| 161 | + </button> |
| 162 | + </section> |
| 163 | + </div> |
| 164 | +</template> |
0 commit comments