forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallScripts.vue
More file actions
109 lines (104 loc) · 3.92 KB
/
InstallScripts.vue
File metadata and controls
109 lines (104 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<script setup lang="ts">
const props = defineProps<{
packageName: string
installScripts: {
scripts: ('preinstall' | 'install' | 'postinstall')[]
content?: Record<string, string>
npxDependencies: Record<string, string>
}
order: number
}>()
const outdatedNpxDeps = useOutdatedDependencies(() => props.installScripts.npxDependencies)
const hasNpxDeps = computed(() => Object.keys(props.installScripts.npxDependencies).length > 0)
const sortedNpxDeps = computed(() => {
return Object.entries(props.installScripts.npxDependencies).sort(([a], [b]) => a.localeCompare(b))
})
const isExpanded = shallowRef(false)
</script>
<template>
<CollapsibleSection id="install-scripts" :title="$t('package.install_scripts.title')" :order>
<!-- Script list: name as label, content below -->
<dl class="space-y-2 m-0">
<div v-for="scriptName in installScripts.scripts" :key="scriptName">
<dt class="font-mono text-xs text-fg-muted">{{ scriptName }}</dt>
<dd
tabindex="0"
class="font-mono text-sm text-fg-subtle m-0 truncate focus:whitespace-normal focus:overflow-visible cursor-help rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
:title="installScripts.content?.[scriptName]"
>
{{ installScripts.content?.[scriptName] || $t('package.install_scripts.script_label') }}
</dd>
</div>
</dl>
<!-- npx packages (expandable) -->
<div v-if="hasNpxDeps" class="mt-3">
<button
type="button"
class="flex items-center gap-1.5 text-xs text-fg-muted hover:text-fg transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
:aria-expanded="isExpanded"
aria-controls="npx-packages-details"
@click="isExpanded = !isExpanded"
>
<span
class="i-carbon:chevron-right rtl-flip w-3 h-3 transition-transform duration-200"
:class="{ 'rotate-90': isExpanded }"
aria-hidden="true"
/>
{{
$t(
'package.install_scripts.npx_packages',
{ count: sortedNpxDeps.length },
sortedNpxDeps.length,
)
}}
</button>
<ul
v-show="isExpanded"
id="npx-packages-details"
class="mt-2 space-y-1 list-none m-0 p-0 ps-4"
>
<li
v-for="[dep, version] in sortedNpxDeps"
:key="dep"
class="flex items-center justify-between py-0.5 text-sm gap-2"
>
<NuxtLink
:to="{ name: 'package', params: { package: dep.split('/') } }"
class="font-mono text-fg-muted hover:text-fg transition-colors duration-200 truncate min-w-0"
>
{{ dep }}
</NuxtLink>
<span class="flex items-center gap-1">
<span
v-if="
outdatedNpxDeps[dep] &&
outdatedNpxDeps[dep].resolved !== outdatedNpxDeps[dep].latest
"
class="shrink-0"
:class="getVersionClass(outdatedNpxDeps[dep])"
:title="getOutdatedTooltip(outdatedNpxDeps[dep], $t)"
aria-hidden="true"
>
<span class="i-carbon:warning-alt w-3 h-3 block" />
</span>
<span
class="font-mono text-xs text-end truncate"
:class="getVersionClass(outdatedNpxDeps[dep])"
:title="
outdatedNpxDeps[dep]
? outdatedNpxDeps[dep].resolved === outdatedNpxDeps[dep].latest
? $t('package.install_scripts.currently', {
version: outdatedNpxDeps[dep].latest,
})
: getOutdatedTooltip(outdatedNpxDeps[dep], $t)
: version
"
>
{{ version }}
</span>
</span>
</li>
</ul>
</div>
</CollapsibleSection>
</template>