-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathExecute.vue
More file actions
110 lines (100 loc) · 3.63 KB
/
Execute.vue
File metadata and controls
110 lines (100 loc) · 3.63 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
110
<script setup lang="ts">
import type { JsrPackageInfo } from '#shared/types/jsr'
import type { PackageManagerId } from '~/utils/install-command'
/**
* A terminal-style execute command display for binary-only packages.
* Renders all package manager variants with CSS-based visibility.
*/
const props = defineProps<{
packageName: string
jsrInfo?: JsrPackageInfo | null
isCreatePackage?: boolean
}>()
const selectedPM = useSelectedPackageManager()
const { polite } = useAnnouncer()
// Generate execute command parts for a specific package manager
function getExecutePartsForPM(pmId: PackageManagerId) {
return getExecuteCommandParts({
packageName: props.packageName,
packageManager: pmId,
jsrInfo: props.jsrInfo,
isBinaryOnly: true,
isCreatePackage: props.isCreatePackage,
})
}
// Full execute command for copying (uses current selected PM)
function getFullExecuteCommand() {
return getExecuteCommand({
packageName: props.packageName,
packageManager: selectedPM.value,
jsrInfo: props.jsrInfo,
isBinaryOnly: true,
isCreatePackage: props.isCreatePackage,
})
}
// Copy handler
const { copied: executeCopied, copy: copyExecute } = useClipboard({ copiedDuring: 2000 })
const copyExecuteCommand = () => {
copyExecute(getFullExecuteCommand())
polite($t('package.command.copied_execute'))
}
</script>
<template>
<div class="relative group">
<!-- Terminal-style execute command -->
<div class="bg-bg-subtle border border-border rounded-lg overflow-hidden">
<div class="flex gap-1.5 px-3 pt-2 sm:px-4 sm:pt-3">
<span class="w-2.5 h-2.5 rounded-full bg-fg-subtle" />
<span class="w-2.5 h-2.5 rounded-full bg-fg-subtle" />
<span class="w-2.5 h-2.5 rounded-full bg-fg-subtle" />
</div>
<div class="px-3 pt-2 pb-3 sm:px-4 sm:pt-3 sm:pb-4 space-y-1">
<!-- Execute command - render all PM variants, CSS controls visibility -->
<div
v-for="pm in packageManagers"
:key="`execute-${pm.id}`"
:data-pm-cmd="pm.id"
class="flex items-center gap-2 group/executecmd"
>
<span class="text-fg-subtle font-mono text-sm select-none shrink-0">$</span>
<code class="font-mono text-sm"
><span
v-for="(part, i) in getExecutePartsForPM(pm.id)"
:key="i"
:class="i === 0 ? 'text-fg' : 'text-fg-muted'"
>{{ i > 0 ? ' ' : '' }}{{ part }}</span
></code
>
<ButtonBase
type="button"
size="icon"
class="text-fg-muted bg-bg-subtle/80 border-border media-mouse:opacity-0 media-mouse:group-hover/executecmd:opacity-100 media-mouse:focus-within:opacity-100 active:scale-95 focus-visible:opacity-100 select-none"
:aria-label="$t('package.get_started.copy_command')"
:classicon="executeCopied ? 'i-lucide:check' : 'i-lucide:copy'"
@click.stop="copyExecuteCommand"
/>
</div>
</div>
</div>
</div>
</template>
<style>
/* Hide all variants by default when preference is set */
:root[data-pm] [data-pm-cmd] {
display: none;
}
/* Show only the matching package manager command */
:root[data-pm='npm'] [data-pm-cmd='npm'],
:root[data-pm='pnpm'] [data-pm-cmd='pnpm'],
:root[data-pm='yarn'] [data-pm-cmd='yarn'],
:root[data-pm='bun'] [data-pm-cmd='bun'],
:root[data-pm='deno'] [data-pm-cmd='deno'],
:root[data-pm='vlt'] [data-pm-cmd='vlt'],
:root[data-pm='vp'] [data-pm-cmd='vp'] {
display: flex;
}
/* Fallback: when no data-pm is set (SSR initial), show npm as default */
:root:not([data-pm]) [data-pm-cmd]:not([data-pm-cmd='npm']) {
display: none;
}
</style>